Skip to content

Commit

Permalink
fix: allow just ready to assign as inflow category (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesusantguerrero authored Mar 10, 2024
1 parent 9cf0b52 commit d2fa8d8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 15 deletions.
26 changes: 26 additions & 0 deletions app/Listeners/UpdateBudgetAvailable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace App\Listeners;

use App\Events\BudgetAssigned;
use Illuminate\Contracts\Queue\ShouldQueue;
use App\Domains\Budget\Services\BudgetCategoryService;
use App\Domains\Budget\Services\BudgetRolloverService;

class UpdateBudgetAvailable implements ShouldQueue
{
protected $formData;


public function __construct()
{

}

public function handle($event)
{
$teamId = $event->transaction->team_id;
$date = $event->transaction->date;
(new BudgetRolloverService(new BudgetCategoryService()))->startFrom($teamId, substr($date, 0, 7));
}
}
13 changes: 7 additions & 6 deletions app/Providers/EventServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
use App\Listeners\CreateBudgetCategory;
use App\Listeners\CreateBudgetMovement;
use App\Listeners\CreateStartingBalance;
use App\Listeners\UpdateBudgetAvailable;
use Insane\Journal\Events\AccountCreated;
use Insane\Journal\Events\AccountUpdated;
use Laravel\Jetstream\Events\TeamCreated;
use Laravel\Jetstream\Events\TeamDeleted;
use App\Listeners\HandleTransactionCreated;
use App\Listeners\CreateOccurrenceAutomation;
use Insane\Journal\Events\TransactionCreated;
use Insane\Journal\Events\TransactionDeleted;
use Insane\Journal\Events\TransactionUpdated;
use Laravel\Jetstream\Events\TeamMemberAdded;
use Insane\Journal\Listeners\CreateTeamAccounts;
use App\Listeners\CreateBudgetTransactionMovement;
use App\Domains\Transaction\Listeners\UpdateOpenReconciliations;
Expand Down Expand Up @@ -54,28 +58,25 @@ class EventServiceProvider extends ServiceProvider
AccountCreated::class => [
CreateBudgetCategory::class,
CreateStartingBalance::class,
CreateBudgetMovement::class,
],
AccountUpdated::class => [
CreateBudgetCategory::class,
CreateBudgetMovement::class,
],
TransactionCreated::class => [
CreateBudgetTransactionMovement::class,
HandleTransactionCreated::class,
CheckOccurrence::class,
UpdateOpenReconciliations::class,
CreateBudgetMovement::class,
UpdateBudgetAvailable::class,
],
TransactionUpdated::class => [
CreateBudgetTransactionMovement::class,
CreateBudgetMovement::class,
UpdateBudgetAvailable::class,
],
TransactionDeleted::class => [
CreateBudgetTransactionMovement::class,
CreateBudgetMovement::class,
UpdateBudgetAvailable::class,
],
// App events
AppCreated::class => [
ShowInApp::class,
],
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Components/atoms/LogerButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export type ButtonVariants = keyof typeof variants;
const props = withDefaults(defineProps<{
variant: ButtonVariants,
as?: Object| string,
processing: boolean,
processing?: boolean,
disabled?: boolean
icon?: string | Object
}>(), {
Expand Down
30 changes: 22 additions & 8 deletions resources/js/domains/transactions/components/TransactionItems.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<script setup lang="ts">
import { reactive, computed, inject, ref } from "vue";
// @ts-expect-error: no definitions
import { AtField } from "atmosphere-ui";
import { NSelect } from "naive-ui";
Expand All @@ -11,6 +10,7 @@ import CategoryPicker from "./CategoryPicker.vue";
import { IAccount, ICategory } from "../models";
import { formatMoney } from "@/utils";
import LogerInput from "@/Components/atoms/LogerInput.vue";
import { TRANSACTION_DIRECTIONS } from "..";
interface SplitItem {
payee_id: null|number,
Expand All @@ -20,16 +20,18 @@ interface SplitItem {
category_id: null|number,
counter_account_id: null|number,
account_id: null|number,
amount: number,
history: string|number[]
amount: string,
history: string|number[];
concept: string;
}
const props = defineProps<{
items: SplitItem[],
categories: ICategory[],
accounts: IAccount[],
isTransfer: boolean
fullHeight: boolean
fullHeight: boolean;
mode?: string;
}>();
const accountLabel = computed(() => {
return !props.isTransfer ? "Account" : "Source";
Expand All @@ -46,7 +48,15 @@ const categoryOptions = inject("categoryOptions", []);
const accountsOptions = inject("accountsOptions", []);
const categoryAccounts = computed(() => {
return props.isTransfer ? accountsOptions : categoryOptions;
if (props.isTransfer) {
return accountsOptions;
} else {
return categoryOptions.filter((category) => {
const isInflow = props.mode == TRANSACTION_DIRECTIONS.DEPOSIT;
return (isInflow && category.display_id == "inflow") || !isInflow;
});
}
});
const splits = reactive<SplitItem[]>(props.items ?? []);
Expand All @@ -65,8 +75,8 @@ const defaultRow = {
};
const splitsTotal = computed(() =>
splits.reduce((total: number, splitItem: Record<string, string>): number => {
return total + parseFloat(splitItem.amount ?? 0);
splits.reduce((total: number, splitItem): number => {
return total + parseFloat(splitItem.amount ?? "0");
}, 0)
)
Expand Down Expand Up @@ -205,7 +215,11 @@ const isPickerOpen = ref(false);
</footer>
</section>

<LogerButton variant="neutral" @click="addSplit()" v-if="!isTransfer">
<LogerButton
v-if="!isTransfer"
variant="neutral"
@click="addSplit()"
>
<IMdiCallSplit />
Add split
</LogerButton>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ const saveText = computed(() => {
ref="gridSplitsRef"
:items="splits"
:is-transfer="isTransfer"
:mode="form.direction"
:categories="categoryOptions"
:accounts="accountOptions"
:full-height="fullHeight"
Expand Down

0 comments on commit d2fa8d8

Please sign in to comment.