update/ledger #1
@@ -71,15 +71,21 @@ class CreateTransactionAction extends BaseAction
|
||||
{
|
||||
$accountName = $isExpense ? 'Input Tax' : 'Output Tax';
|
||||
$type = $isExpense ? 'debit' : 'credit';
|
||||
$clientId = $payload->transactionable->branch->client_id;
|
||||
|
||||
$taxAccount = Account::query()->where('account', $accountName)->whereHas('balances', function ($balance) use ($payload) {
|
||||
return $balance->where('branch_id', $payload->transactionable->branch_id);
|
||||
})->first();
|
||||
$taxAccount = Account::query()
|
||||
->where('account', $accountName)
|
||||
->where('client_id', $clientId)
|
||||
->first();
|
||||
|
||||
if ($taxAccount) {
|
||||
$amount = $isExpense
|
||||
? ($payload->transactionable->input_tax ?? 0.00)
|
||||
: ($payload->transactionable->output_tax ?? 0.00);
|
||||
|
||||
if ($taxAccount && $amount > 0) {
|
||||
$ledgerPayload = new CreateLedgerDTO(
|
||||
branch_id: $payload->transactionable->branch_id,
|
||||
amount: $payload->transactionable->input_tax ?? 0.00, // Assuming input_tax holds the tax amount for both? Or output_tax?
|
||||
amount: $amount,
|
||||
transaction: $payload->transaction,
|
||||
account: $taxAccount,
|
||||
type: $type,
|
||||
@@ -93,15 +99,19 @@ class CreateTransactionAction extends BaseAction
|
||||
$isExpense = $payload->transactionable instanceof \App\Models\Expense;
|
||||
$accountName = $isExpense ? 'Payable Withholding Tax' : 'Creditable Withholding Tax';
|
||||
$type = $isExpense ? 'credit' : 'debit';
|
||||
$clientId = $payload->transactionable->branch->client_id;
|
||||
|
||||
$withholdingAccount = Account::query()->where('account', $accountName)->whereHas('balances', function ($balance) use ($payload) {
|
||||
return $balance->where('branch_id', $payload->transactionable->branch_id);
|
||||
})->first();
|
||||
$withholdingAccount = Account::query()
|
||||
->where('account', $accountName)
|
||||
->where('client_id', $clientId)
|
||||
->first();
|
||||
|
||||
if ($withholdingAccount) {
|
||||
$amount = $payload->transaction->payable_withholding_tax ?? 0.00;
|
||||
|
||||
if ($withholdingAccount && $amount > 0) {
|
||||
$ledgerPayload = new CreateLedgerDTO(
|
||||
branch_id: $payload->transactionable->branch_id,
|
||||
amount: $payload->transaction->payable_withholding_tax ?? 0.00,
|
||||
amount: $amount,
|
||||
transaction: $payload->transaction,
|
||||
account: $withholdingAccount,
|
||||
type: $type,
|
||||
@@ -116,12 +126,14 @@ class CreateTransactionAction extends BaseAction
|
||||
$type = $isExpense ? 'credit' : 'debit';
|
||||
$wht = $isExpense ? ($payload->transaction->payable_withholding_tax ?? 0) : ($payload->transaction->creditable_withholding_tax ?? 0);
|
||||
$amount = ($payload->transaction->gross_amount ?? 0) - $wht;
|
||||
$clientId = $payload->transactionable->branch->client_id;
|
||||
|
||||
$cashAccount = Account::query()->where('account', 'Cash')->whereHas('balances', function ($balance) use ($payload) {
|
||||
return $balance->where('branch_id', $payload->transactionable->branch_id);
|
||||
})->first();
|
||||
$cashAccount = Account::query()
|
||||
->where('account', 'Cash')
|
||||
->where('client_id', $clientId)
|
||||
->first();
|
||||
|
||||
if ($cashAccount) {
|
||||
if ($cashAccount && $amount > 0) {
|
||||
$ledgerPayload = new CreateLedgerDTO(
|
||||
branch_id: $payload->transactionable->branch_id,
|
||||
amount: $amount,
|
||||
|
||||
@@ -37,7 +37,7 @@ class AccountsRelationManager extends RelationManager
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('account')->description(fn (Account $record): string => $record->description ?? ''),
|
||||
Tables\Columns\TextColumn::make('accountType.type'),
|
||||
Tables\Columns\TextColumn::make('accountType.normal_balance'),
|
||||
Tables\Columns\TextColumn::make('accountType.normal_balance')->label('Normal Balance'),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Filament\Resources\ClientResource\RelationManagers;
|
||||
|
||||
use App\Actions\Transactions\CreateTransactionAction;
|
||||
use App\Commands\Expenses\GenerateVoucher;
|
||||
use App\DataObjects\CreateTransactionDTO;
|
||||
use App\Models\Account;
|
||||
use App\Models\Branch;
|
||||
|
||||
@@ -35,7 +35,7 @@ class JournalsRelationManager extends RelationManager
|
||||
->schema([
|
||||
Select::make('branch_id')
|
||||
->label('Branch')
|
||||
->options(fn () => Branch::where('client_id', $this->getOwnerRecord()->id)->pluck('name', 'id'))
|
||||
->options(fn () => Branch::where('client_id', $this->getOwnerRecord()->id)->pluck('code', 'id'))
|
||||
->required()
|
||||
->default(fn () => Branch::where('client_id', $this->getOwnerRecord()->id)->first()?->id),
|
||||
|
||||
|
||||
@@ -73,4 +73,9 @@ class Client extends Model
|
||||
{
|
||||
return $this->hasManyThrough(Expense::class, Branch::class);
|
||||
}
|
||||
|
||||
public function journals(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(Journal::class, Branch::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user