Files
MKM/app/DataObjects/CreateBalanceDTO.php
Jp 207f4c1609 feat(client): add financial reports and ledger management
- Add trial balance and general ledger pages to client resource with interactive tables
- Implement sales and expenses relation managers for client-specific transactions
- Enhance transaction handling with proper tax and withholding calculations
- Add date casting to Transaction model and define client relationships
- Configure super admin role bypass in AppServiceProvider
- Update Filament components and fix JavaScript formatting issues
2026-02-09 16:20:55 +08:00

42 lines
1.2 KiB
PHP

<?php
namespace App\DataObjects;
use App\Models\Account;
use Spatie\LaravelData\Data;
class CreateBalanceDTO extends Data
{
public int $balance;
public function __construct(
public float $amount,
public bool $is_starting,
public ?int $id = null,
public ?int $ledger_id = null,
public ?int $account_id = null,
public ?int $branch_id = null,
public string $type = 'debit'
) {
$account = Account::with('accountType')->where('id', $this->account_id)->first();
$currentBalance = $account ? $account->current_balance : 0;
$normalBalance = strtolower($account->accountType->normal_balance ?? 'debit');
$transactionType = strtolower($this->type);
if ($transactionType === 'debit') {
if ($normalBalance === 'debit') {
$this->balance = $currentBalance + $this->amount;
} else {
$this->balance = $currentBalance - $this->amount;
}
} else { // credit
if ($normalBalance === 'credit') {
$this->balance = $currentBalance + $this->amount;
} else {
$this->balance = $currentBalance - $this->amount;
}
}
}
}