diff --git a/app/Abstracts/Report.php b/app/Abstracts/Report.php index 65a6e2375..c4d744f2d 100644 --- a/app/Abstracts/Report.php +++ b/app/Abstracts/Report.php @@ -546,11 +546,19 @@ abstract class Report public function divArithmeticAmount(&$current, $amount) { + if ($amount == 0) { + throw new \InvalidArgumentException('Division by zero is not allowed'); + } + $current = $current / $amount; } public function modArithmeticAmount(&$current, $amount) { + if ($amount == 0) { + throw new \InvalidArgumentException('Modulo by zero is not allowed'); + } + $current = $current % $amount; } diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index bb4c94fd8..9bc22c0da 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -355,7 +355,11 @@ class Document extends Model if ($discount) { $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; diff --git a/app/Reports/TaxSummary.php b/app/Reports/TaxSummary.php index 5c47fbe40..d2db1aa3f 100644 --- a/app/Reports/TaxSummary.php +++ b/app/Reports/TaxSummary.php @@ -126,8 +126,12 @@ class TaxSummary extends Report } if ($date_field == 'paid_at') { - $rate = ($item->amount * 100) / $type_item->amount; - $item_amount = ($item_total->amount / 100) * $rate; + if ($type_item->amount != 0) { + $rate = ($item->amount * 100) / $type_item->amount; + $item_amount = ($item_total->amount / 100) * $rate; + } else { + $item_amount = $item_total->amount; + } } else { $item_amount = $item_total->amount; }