diff --git a/app/DataMapper/InvoiceItem.php b/app/DataMapper/InvoiceItem.php index 0ea1e9ba8228..7f80d86eb9b3 100644 --- a/app/DataMapper/InvoiceItem.php +++ b/app/DataMapper/InvoiceItem.php @@ -44,6 +44,8 @@ class InvoiceItem public $line_total = 0; public $gross_line_total = 0; + + public $gross_tax_total = 0; public $date = ''; @@ -75,6 +77,7 @@ class InvoiceItem 'sort_id' => 'string', 'line_total' => 'float', 'gross_line_total' => 'float', + 'gross_tax_total' => 'float', 'date' => 'string', 'custom_value1' => 'string', 'custom_value2' => 'string', diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 8e3b702d7f6f..d77f9a30c895 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -30,6 +30,8 @@ class InvoiceItemSum private $gross_line_total; + private $gross_tax_total; + private $currency; private $total_taxes; @@ -111,14 +113,10 @@ class InvoiceItemSum $this->setLineTotal($this->getLineTotal() - $this->formatValue($this->item->discount, $this->currency->precision)); } else { - /*Test 16-08-2021*/ $discount = ($this->item->line_total * ($this->item->discount / 100)); + $this->setLineTotal($this->formatValue(($this->getLineTotal() - $discount), $this->currency->precision)); - /*Test 16-08-2021*/ - //replaces the following - - // $this->setLineTotal($this->getLineTotal() - $this->formatValue(round($this->item->line_total * ($this->item->discount / 100), 2), $this->currency->precision)); } $this->item->is_amount_discount = $this->invoice->is_amount_discount; @@ -160,6 +158,8 @@ class InvoiceItemSum $this->item->gross_line_total = $this->getLineTotal() + $item_tax; + $this->item->gross_tax_total = $item_tax; + return $this; } diff --git a/app/Helpers/Invoice/InvoiceItemSumInclusive.php b/app/Helpers/Invoice/InvoiceItemSumInclusive.php index 213600d3501f..6985c72ef42e 100644 --- a/app/Helpers/Invoice/InvoiceItemSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceItemSumInclusive.php @@ -40,6 +40,8 @@ class InvoiceItemSumInclusive private $tax_collection; + private $gross_tax_total; + public function __construct($invoice) { $this->tax_collection = collect([]); @@ -144,6 +146,8 @@ class InvoiceItemSumInclusive $this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total); } + $this->item->gross_tax_total = $this->formatValue($item_tax, $this->currency->precision); + $this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision)); return $this; diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 24583def9ec0..443c1b377229 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -485,6 +485,7 @@ class HtmlEngine $data['$product.tax_name3'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$product.line_total'] = ['value' => '', 'label' => ctrans('texts.line_total')]; $data['$product.gross_line_total'] = ['value' => '', 'label' => ctrans('texts.gross_line_total')]; + $data['$product.gross_tax_total'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$product.description'] = ['value' => '', 'label' => ctrans('texts.description')]; $data['$product.unit_cost'] = ['value' => '', 'label' => ctrans('texts.unit_cost')]; $data['$product.product1'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'product1')]; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index 1c30b237b0fc..5bc4b3fccc1a 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -161,8 +161,6 @@ trait MakesInvoiceValues if (strlen($user_columns) > 1) { foreach ($items as $key => $item) { -// $tmp = str_replace(array_keys($data), array_values($data), $user_columns); -// $tmp = str_replace(array_keys($item), array_values($item), $tmp); $tmp = strtr($user_columns, $data); $tmp = strtr($tmp, $item); @@ -178,8 +176,6 @@ trait MakesInvoiceValues $table_row .= ''; foreach ($items as $key => $item) { - // $tmp = str_replace(array_keys($item), array_values($item), $table_row); - // $tmp = str_replace(array_keys($data), array_values($data), $tmp); $tmp = strtr($table_row, $item); $tmp = strtr($tmp, $data); @@ -210,11 +206,13 @@ trait MakesInvoiceValues 'tax_name1', 'tax_name2', 'tax_name3', + 'gross_tax_total', ], [ 'tax', 'tax', 'tax', + 'tax', ], $columns ); @@ -329,6 +327,12 @@ trait MakesInvoiceValues $data[$key][$table_type.'.gross_line_total'] = ''; } + if (property_exists($item, 'gross_tax_total')) { + $data[$key][$table_type.'.gross_tax_total'] = ($item->gross_tax_total == 0) ? '' : Number::formatMoney($item->gross_tax_total, $entity); + } else { + $data[$key][$table_type.'.gross_tax_total'] = ''; + } + if (isset($item->discount) && $item->discount > 0) { if ($item->is_amount_discount) { $data[$key][$table_type.'.discount'] = Number::formatMoney($item->discount, $entity); diff --git a/app/Utils/VendorHtmlEngine.php b/app/Utils/VendorHtmlEngine.php index b373db554589..2b14951499c2 100644 --- a/app/Utils/VendorHtmlEngine.php +++ b/app/Utils/VendorHtmlEngine.php @@ -355,6 +355,7 @@ class VendorHtmlEngine $data['$product.tax_name3'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$product.line_total'] = ['value' => '', 'label' => ctrans('texts.line_total')]; $data['$product.gross_line_total'] = ['value' => '', 'label' => ctrans('texts.gross_line_total')]; + $data['$product.gross_tax_total'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$product.description'] = ['value' => '', 'label' => ctrans('texts.description')]; $data['$product.unit_cost'] = ['value' => '', 'label' => ctrans('texts.unit_cost')]; $data['$product.product1'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'product1')];