46 lines
1.2 KiB
PHP
46 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace Modules\Accounting\Domain;
|
|
|
|
class FinancialPostingRequest
|
|
{
|
|
public function __construct(
|
|
public int $businessId,
|
|
public int $userId,
|
|
public string $sourceType,
|
|
public int|string $sourceId,
|
|
public string $note,
|
|
public array $lines,
|
|
public ?string $operationDate = null,
|
|
public ?int $costCenterId = null,
|
|
public ?int $projectId = null,
|
|
public ?int $holdingEntityId = null,
|
|
public ?int $transactionId = null,
|
|
public ?int $transactionPaymentId = null,
|
|
public string $mappingType = 'journal_entry',
|
|
public ?string $refNo = null,
|
|
) {}
|
|
|
|
public function postingKey(): string
|
|
{
|
|
return $this->businessId.':'.$this->sourceType.':'.$this->sourceId;
|
|
}
|
|
|
|
public function isBalanced(float $tolerance = 0.01): bool
|
|
{
|
|
$debit = 0.0;
|
|
$credit = 0.0;
|
|
|
|
foreach ($this->lines as $line) {
|
|
if (($line['type'] ?? '') === 'debit') {
|
|
$debit += (float) ($line['amount'] ?? 0);
|
|
}
|
|
if (($line['type'] ?? '') === 'credit') {
|
|
$credit += (float) ($line['amount'] ?? 0);
|
|
}
|
|
}
|
|
|
|
return abs($debit - $credit) <= $tolerance;
|
|
}
|
|
}
|