fix: error handling for arithmetic operations and improve calculations in Document and TaxSummary classes. Added checks for division and modulo by zero, and adjusted percentage calculation logic to handle zero sub-total cases.
This commit is contained in:
parent
b5d8499ac7
commit
b56a3bda56
|
|
@ -546,11 +546,19 @@ abstract class Report
|
||||||
|
|
||||||
public function divArithmeticAmount(&$current, $amount)
|
public function divArithmeticAmount(&$current, $amount)
|
||||||
{
|
{
|
||||||
|
if ($amount == 0) {
|
||||||
|
throw new \InvalidArgumentException('Division by zero is not allowed');
|
||||||
|
}
|
||||||
|
|
||||||
$current = $current / $amount;
|
$current = $current / $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function modArithmeticAmount(&$current, $amount)
|
public function modArithmeticAmount(&$current, $amount)
|
||||||
{
|
{
|
||||||
|
if ($amount == 0) {
|
||||||
|
throw new \InvalidArgumentException('Modulo by zero is not allowed');
|
||||||
|
}
|
||||||
|
|
||||||
$current = $current % $amount;
|
$current = $current % $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -355,7 +355,11 @@ class Document extends Model
|
||||||
if ($discount) {
|
if ($discount) {
|
||||||
$sub_total = $this->totals->where('code', 'sub_total')->makeHidden('title')->pluck('amount')->first();
|
$sub_total = $this->totals->where('code', 'sub_total')->makeHidden('title')->pluck('amount')->first();
|
||||||
|
|
||||||
$percent = number_format((($discount * 100) / $sub_total), 0);
|
if ($sub_total && $sub_total > 0) {
|
||||||
|
$percent = number_format((($discount * 100) / $sub_total), 0);
|
||||||
|
} else {
|
||||||
|
$percent = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $percent;
|
return $percent;
|
||||||
|
|
@ -423,7 +427,7 @@ class Document extends Model
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($transaction->reconciled) {
|
if ($transaction->reconciled) {
|
||||||
$reconciled_amount = +$amount;
|
$reconciled_amount += $amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,12 @@ class TaxSummary extends Report
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($date_field == 'paid_at') {
|
if ($date_field == 'paid_at') {
|
||||||
$rate = ($item->amount * 100) / $type_item->amount;
|
if ($type_item->amount != 0) {
|
||||||
$item_amount = ($item_total->amount / 100) * $rate;
|
$rate = ($item->amount * 100) / $type_item->amount;
|
||||||
|
$item_amount = ($item_total->amount / 100) * $rate;
|
||||||
|
} else {
|
||||||
|
$item_amount = $item_total->amount;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$item_amount = $item_total->amount;
|
$item_amount = $item_total->amount;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue