feat: updates on expenses
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Actions\Transactions;
|
||||
|
||||
use App\Actions\Balances\CreateBalanceAction;
|
||||
use App\Actions\BaseAction;
|
||||
use App\Actions\Ledgers\CreateLedgerAction;
|
||||
use App\DataObjects\CreateLedgerDTO;
|
||||
@@ -21,6 +22,8 @@ class CreateTransactionAction extends BaseAction
|
||||
|
||||
$this->withHoldingAccountLedger($payload);
|
||||
|
||||
$this->cashAccountLedger($payload);
|
||||
|
||||
return $next($payload);
|
||||
}
|
||||
|
||||
@@ -56,6 +59,7 @@ class CreateTransactionAction extends BaseAction
|
||||
{
|
||||
return Pipeline::send(passable: $ledgerPayload)->through([
|
||||
CreateLedgerAction::class,
|
||||
CreateBalanceAction::class,
|
||||
])->thenReturn();
|
||||
}
|
||||
|
||||
@@ -82,10 +86,27 @@ class CreateTransactionAction extends BaseAction
|
||||
|
||||
$ledgerPayload = new CreateLedgerDTO(
|
||||
branch_id: $payload->transactionable->branch_id,
|
||||
amount: $payload->transaction->payable_withholding_tax,
|
||||
amount: $payload->transaction->payable_withholding_tax ?? 0.00,
|
||||
transaction: $payload->transaction,
|
||||
account: $withholdingAccount,
|
||||
);
|
||||
$this->ledgerPipe($ledgerPayload);
|
||||
}
|
||||
|
||||
public function cashAccountLedger($payload): void
|
||||
{
|
||||
$cashAccount = Account::query()->where('account', 'Cash')->whereHas('balances', function ($balance) use ($payload) {
|
||||
return $balance->where('branch_id', $payload->transactionable->branch_id);
|
||||
})->first();
|
||||
|
||||
$amount = $payload->transaction->gross_amount - $payload->transaction->creditable_withholding_tax;
|
||||
|
||||
$ledgerPayload = new CreateLedgerDTO(
|
||||
branch_id: $payload->transactionable->branch_id,
|
||||
amount: $amount ?? 0.00,
|
||||
transaction: $payload->transaction,
|
||||
account: $cashAccount,
|
||||
);
|
||||
$this->ledgerPipe($ledgerPayload);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user