Files
MKM/app/DataObjects/CreateLedgerDTO.php
2024-08-15 20:11:21 +08:00

50 lines
1.3 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;
#[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 $account = null,
) {
$this->transaction_id = $this->transaction->id;
$this->account_id = $this->account->id;
$this->client_id = $this->transaction->branch->client_id;
$this->credit_amount = $this->transaction->account_type == 'credit' ? $this->amount : 0.00;
$this->debit_amount = $this->transaction->account_type == 'debit' ? $this->amount : 0.00;
$this->description = $this->transaction->description;
$this->data = Arr::except($this->toArray(), ['transaction', 'ledger', 'account', 'amount']);
}
}