From 587601ce7d7ee2c299623fe0ec83314bac445784 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 23 Apr 2018 12:44:23 +0300 Subject: [PATCH] Report fixes --- app/Models/InvoiceItem.php | 23 ++++++++++++++----- app/Ninja/Reports/ProductReport.php | 5 +--- .../views/reports/report_builder.blade.php | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/Models/InvoiceItem.php b/app/Models/InvoiceItem.php index 6d96e7201ec1..8b11498426ce 100644 --- a/app/Models/InvoiceItem.php +++ b/app/Models/InvoiceItem.php @@ -75,7 +75,7 @@ class InvoiceItem extends EntityModel return $this->belongsTo('App\Models\Account'); } - public function amount() + public function getPreTaxAmount() { $amount = $this->cost * $this->qty; @@ -83,21 +83,32 @@ class InvoiceItem extends EntityModel if ($this->invoice->is_amount_discount) { $amount -= $this->discount; } else { - $amount -= $amount * $this->discount / 100; + $amount -= round($amount * $this->discount / 100, 4); } } - $preTaxAmount = $amount; + return $amount; + } + + public function getTaxAmount() + { + $tax = 0; + $preTaxAmount = $this->getPreTaxAmount(); if ($this->tax_rate1) { - $amount += $preTaxAmount * $this->tax_rate1 / 100; + $tax += round($preTaxAmount * $this->tax_rate1 / 100, 2); } if ($this->tax_rate2) { - $amount += $preTaxAmount * $this->tax_rate2 / 100; + $tax += round($preTaxAmount * $this->tax_rate2 / 100, 2); } - return $amount; + return $tax; + } + + public function amount() + { + return $this->getPreTaxAmount() + $this->getTaxAmount(); } public function markFeePaid() diff --git a/app/Ninja/Reports/ProductReport.php b/app/Ninja/Reports/ProductReport.php index 8aaf5ef12a33..2696036add3d 100644 --- a/app/Ninja/Reports/ProductReport.php +++ b/app/Ninja/Reports/ProductReport.php @@ -75,10 +75,7 @@ class ProductReport extends AbstractReport ]; if ($account->invoice_item_taxes) { - $row[] = $item->present()->tax1; - if ($account->enable_second_tax_rate) { - $row[] = $item->present()->tax2; - } + $row[] = Utils::roundSignificant($item->getTaxAmount(), 2); } if ($account->customLabel('product1')) { diff --git a/resources/views/reports/report_builder.blade.php b/resources/views/reports/report_builder.blade.php index b51a3b904377..d034074c6fc3 100644 --- a/resources/views/reports/report_builder.blade.php +++ b/resources/views/reports/report_builder.blade.php @@ -702,7 +702,7 @@ var txt = $(this).find("td").eq(i).text(); subtotal += convertStringToNumber(txt) || 0; }); - $cell.find(".group-count").append(' - ' + label + ': ' + roundToTwo(subtotal, true)); + $cell.find(".group-count").append(' | ' + label + ': ' + roundToTwo(subtotal, true)); } }, }