feat: updates on expenses
This commit is contained in:
30
app/DataObjects/CreateBalanceDTO.php
Normal file
30
app/DataObjects/CreateBalanceDTO.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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
|
||||
) {
|
||||
$account = Account::query()->where('id', $this->account_id)->first();
|
||||
|
||||
$currentBalance = $account ? $account->current_balance : 0;
|
||||
|
||||
if ($account->normal_balance == 'credit') {
|
||||
$this->balance = $currentBalance - $this->amount;
|
||||
} else {
|
||||
$this->balance = $currentBalance + $this->amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user