Files
MKM/app/DataObjects/CreateLedgerDTO.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

60 lines
1.7 KiB
PHP

<?php
namespace App\DataObjects;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Spatie\LaravelData\Attributes\Computed;
use Spatie\LaravelData\Data;
class CreateLedgerDTO extends Data
{
#[Computed]
public array $data;
#[Computed]
public ?int $transaction_id = null;
#[Computed]
public ?int $journal_id = null;
#[Computed]
public int $account_id;
#[Computed]
public int $client_id;
#[Computed]
public ?string $description;
#[Computed]
public float $credit_amount;
#[Computed]
public float $debit_amount;
public function __construct(
public int $branch_id,
public float $amount,
public ?Model $ledger = null,
public ?Model $transaction = null,
public ?Model $journal = null,
public ?Model $account = null,
public ?CreateBalanceDTO $balanceDTO = null,
public ?string $type = null, // 'debit' or 'credit'
) {
$this->transaction_id = $this->transaction?->id;
$this->journal_id = $this->journal?->id;
$this->account_id = $this->account->id;
$this->client_id = $this->transaction?->branch->client_id ?? $this->journal?->client_id;
$accountType = $this->type ? strtolower($this->type) : strtolower($this->transaction?->account_type);
$this->credit_amount = $accountType == 'credit' ? $this->amount : 0.00;
$this->debit_amount = $accountType == 'debit' ? $this->amount : 0.00;
$this->description = $this->transaction?->description ?? $this->journal?->description;
$this->data = Arr::except($this->toArray(), ['transaction', 'journal', 'ledger', 'account', 'amount', 'type']);
}
}