From 33c05b1ad02e0f0c20b0c7229f4311fa82c18857 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 15 Sep 2021 09:02:25 +1000 Subject: [PATCH 1/9] Add exclusive taxes to line items --- app/DataMapper/InvoiceItem.php | 3 ++ app/Helpers/Invoice/InvoiceItemSum.php | 18 ++++++++++ app/Helpers/Invoice/InvoiceSum.php | 17 +++++++++- app/Utils/HtmlEngine.php | 1 + tests/Unit/InvoiceItemTest.php | 46 ++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) diff --git a/app/DataMapper/InvoiceItem.php b/app/DataMapper/InvoiceItem.php index 48eb8aaa326a..70a6e9d6bf2c 100644 --- a/app/DataMapper/InvoiceItem.php +++ b/app/DataMapper/InvoiceItem.php @@ -43,6 +43,8 @@ class InvoiceItem public $line_total = 0; + public $gross_line_total = 0; + public $date = ''; public $custom_value1 = ''; @@ -72,6 +74,7 @@ class InvoiceItem 'tax_rate3' => 'float', 'sort_id' => 'string', 'line_total' => 'float', + 'gross_line_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 a542c017c926..e796e98aea4c 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -28,6 +28,8 @@ class InvoiceItemSum private $line_total; + private $gross_line_total; + private $currency; private $total_taxes; @@ -38,6 +40,8 @@ class InvoiceItemSum private $sub_total; + private $gross_sub_total; + private $total_discount; private $tax_collection; @@ -83,6 +87,8 @@ class InvoiceItemSum { $this->sub_total += $this->getLineTotal(); + $this->gross_sub_total += $this->getGrossLineTotal(); + $this->line_items[] = $this->item; return $this; @@ -148,6 +154,8 @@ class InvoiceItemSum $this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision)); + $this->item->gross_line_total = $this->getLineTotal() + $item_tax; + return $this; } @@ -186,6 +194,11 @@ class InvoiceItemSum return $this->item->line_total; } + public function getGrossLineTotal() + { + return $this->item->gross_line_total; + } + public function getLineItems() { return $this->line_items; @@ -208,6 +221,11 @@ class InvoiceItemSum return $this->sub_total; } + public function getGrossSubTotal() + { + return $this->gross_line_total; + } + public function setSubTotal($value) { $this->sub_total = $value; diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index 53012df09105..a66a04d912f1 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -42,6 +42,8 @@ class InvoiceSum private $sub_total; + private $gross_sub_total; + /** * Constructs the object with Invoice and Settings object. * @@ -75,7 +77,8 @@ class InvoiceSum $this->invoice->line_items = $this->invoice_items->getLineItems(); $this->total = $this->invoice_items->getSubTotal(); $this->setSubTotal($this->invoice_items->getSubTotal()); - + $this->setGrossSubTotal($this->invoice_items->getGrossSubTotal()); + return $this; } @@ -266,6 +269,18 @@ class InvoiceSum return $this; } + public function getGrossSubTotal() + { + return $this->gross_sub_total; + } + + public function setGrossSubTotal($value) + { + $this->gross_sub_total = $value; + + return $this; + } + public function getTotalDiscount() { return $this->total_discount; diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index 5621c0c00704..f8cd26f91acb 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -175,6 +175,7 @@ class HtmlEngine $data['$invoice.discount'] = ['value' => Number::formatMoney($this->entity_calc->getTotalDiscount(), $this->client) ?: ' ', 'label' => ctrans('texts.discount')]; $data['$discount'] = &$data['$invoice.discount']; $data['$subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')]; + $data['$gross_subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getGrossSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')]; if($this->entity->uses_inclusive_taxes) $data['$net_subtotal'] = ['value' => Number::formatMoney(($this->entity_calc->getSubTotal() - $this->entity->total_taxes), $this->client) ?: ' ', 'label' => ctrans('texts.net_subtotal')]; diff --git a/tests/Unit/InvoiceItemTest.php b/tests/Unit/InvoiceItemTest.php index 6a75f97c602d..7b6f8e5621c6 100644 --- a/tests/Unit/InvoiceItemTest.php +++ b/tests/Unit/InvoiceItemTest.php @@ -51,6 +51,29 @@ class InvoiceItemTest extends TestCase $this->assertEquals($item_calc->getLineTotal(), 10); } + public function testInvoiceItemTotalSimpleWithGrossTaxes() + { + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 10; + $item->is_amount_discount = true; + $item->tax_rate1 = 10; + + $settings = new \stdClass; + $settings->inclusive_taxes = false; + $settings->precision = 2; + + $this->invoice->line_items = [$item]; + + $item_calc = new InvoiceItemSum($this->invoice, $settings); + $item_calc->process(); + + $this->assertEquals($item_calc->getLineTotal(), 10); + $this->assertEquals($item_calc->getGrossLineTotal(), 11); + } + + + public function testInvoiceItemTotalSimpleWithDiscount() { $item = InvoiceItemFactory::create(); @@ -71,6 +94,29 @@ class InvoiceItemTest extends TestCase $this->assertEquals($item_calc->getLineTotal(), 8); } + public function testInvoiceItemTotalSimpleWithDiscountAndGrossLineTotal() + { + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = 10; + $item->is_amount_discount = true; + $item->discount = 2; + $item->tax_rate1 = 10; + + $this->invoice->line_items = [$item]; + + $settings = new \stdClass; + $settings->inclusive_taxes = false; + $settings->precision = 2; + + $item_calc = new InvoiceItemSum($this->invoice, $settings); + $item_calc->process(); + + $this->assertEquals($item_calc->getLineTotal(), 8); + $this->assertEquals($item_calc->getGrossLineTotal(), 8.8); + + } + public function testInvoiceItemTotalSimpleWithDiscountWithPrecision() { $item = InvoiceItemFactory::create(); From 618027dcd80ec657920a84c50c27519cf3f8e398 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 15 Sep 2021 10:00:29 +1000 Subject: [PATCH 2/9] Add gross line and subtotals --- app/DataMapper/CompanySettings.php | 3 +++ app/Helpers/Invoice/InvoiceItemSum.php | 4 ++-- app/Helpers/Invoice/InvoiceItemSumInclusive.php | 5 +++++ app/Utils/HtmlEngine.php | 2 ++ app/Utils/Traits/MakesInvoiceValues.php | 1 + tests/Unit/InvoiceTest.php | 2 ++ 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/DataMapper/CompanySettings.php b/app/DataMapper/CompanySettings.php index 288a0a60a8d0..8b7bf4c6ff30 100644 --- a/app/DataMapper/CompanySettings.php +++ b/app/DataMapper/CompanySettings.php @@ -654,6 +654,7 @@ class CompanySettings extends BaseSettings '$product.discount', '$product.tax', '$product.line_total', + '$product.gross_line_total', ], 'task_columns' =>[ '$task.service', @@ -663,9 +664,11 @@ class CompanySettings extends BaseSettings '$task.discount', '$task.tax', '$task.line_total', + '$task.gross_line_total', ], 'total_columns' => [ '$net_subtotal', + '$gross_subtotal', '$subtotal', '$discount', '$custom_surcharge1', diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index e796e98aea4c..ba20fb2712b1 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -150,7 +150,6 @@ class InvoiceItemSum if($item_tax_rate3_total != 0) $this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total); - $this->setTotalTaxes($this->formatValue($item_tax, $this->currency->precision)); @@ -223,7 +222,7 @@ class InvoiceItemSum public function getGrossSubTotal() { - return $this->gross_line_total; + return $this->gross_sub_total; } public function setSubTotal($value) @@ -281,6 +280,7 @@ class InvoiceItemSum if ($item_tax_rate3_total != 0) { $this->groupTax($this->item->tax_name3, $this->item->tax_rate3, $item_tax_rate3_total); } + } $this->setTotalTaxes($item_tax); diff --git a/app/Helpers/Invoice/InvoiceItemSumInclusive.php b/app/Helpers/Invoice/InvoiceItemSumInclusive.php index c65d0a520a9f..469603f9cbe3 100644 --- a/app/Helpers/Invoice/InvoiceItemSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceItemSumInclusive.php @@ -199,6 +199,11 @@ class InvoiceItemSumInclusive return $this->sub_total; } + public function getGrossSubTotal() + { + return $this->sub_total; + } + public function setSubTotal($value) { $this->sub_total = $value; diff --git a/app/Utils/HtmlEngine.php b/app/Utils/HtmlEngine.php index f8cd26f91acb..a678ce62721e 100644 --- a/app/Utils/HtmlEngine.php +++ b/app/Utils/HtmlEngine.php @@ -381,6 +381,7 @@ class HtmlEngine $data['$product.tax_name2'] = ['value' => '', 'label' => ctrans('texts.tax')]; $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.line_total')]; $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')]; @@ -400,6 +401,7 @@ class HtmlEngine $data['$task.tax_name2'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$task.tax_name3'] = ['value' => '', 'label' => ctrans('texts.tax')]; $data['$task.line_total'] = ['value' => '', 'label' => ctrans('texts.line_total')]; + $data['$task.gross_line_total'] = ['value' => '', 'label' => ctrans('texts.line_total')]; $data['$task.service'] = ['value' => '', 'label' => ctrans('texts.service')]; $data['$task.task1'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'task1')]; $data['$task.task2'] = ['value' => '', 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'task2')]; diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index c51486aa3237..f9813ef96595 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -311,6 +311,7 @@ trait MakesInvoiceValues $data[$key][$table_type.'.cost'] = Number::formatMoney($item->cost, $this->client); $data[$key][$table_type.'.line_total'] = Number::formatMoney($item->line_total, $this->client); + $data[$key][$table_type.'.gross_line_total'] = Number::formatMoney($item->gross_line_total, $this->client); if (isset($item->discount) && $item->discount > 0) { if ($item->is_amount_discount) { diff --git a/tests/Unit/InvoiceTest.php b/tests/Unit/InvoiceTest.php index 034d27a16c7c..233403634f28 100644 --- a/tests/Unit/InvoiceTest.php +++ b/tests/Unit/InvoiceTest.php @@ -123,6 +123,7 @@ class InvoiceTest extends TestCase $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); + // $this->assertEquals($this->invoice_calc->getGrossSubTotal(), 22); //$this->assertEquals($this->invoice_calc->getTotal(), 21.5); //$this->assertEquals($this->invoice_calc->getBalance(), 21.5); //$this->assertEquals($this->invoice_calc->getTotalTaxes(), 1.5); @@ -216,6 +217,7 @@ class InvoiceTest extends TestCase $this->invoice_calc->build(); $this->assertEquals($this->invoice_calc->getSubTotal(), 20); + $this->assertEquals($this->invoice_calc->getGrossSubTotal(), 22); //$this->assertEquals($this->invoice_calc->getTotal(), 26); //$this->assertEquals($this->invoice_calc->getBalance(), 26); //$this->assertEquals($this->invoice_calc->getTotalTaxes(), 4); From bc473439fee3364997e8dd46ce43c91aa1a8f187 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 15 Sep 2021 10:15:14 +1000 Subject: [PATCH 3/9] Add user agent into meta tags --- app/Http/Controllers/BaseController.php | 1 + resources/views/index/index.blade.php | 1 + 2 files changed, 2 insertions(+) diff --git a/app/Http/Controllers/BaseController.php b/app/Http/Controllers/BaseController.php index 466cd559525f..b4cfa4aabf4a 100644 --- a/app/Http/Controllers/BaseController.php +++ b/app/Http/Controllers/BaseController.php @@ -738,6 +738,7 @@ class BaseController extends Controller //pass referral code to front end $data['rc'] = request()->has('rc') ? request()->input('rc') : ''; $data['build'] = request()->has('build') ? request()->input('build') : ''; + $data['user_agent'] = request()->server('HTTP_USER_AGENT'); $data['path'] = $this->setBuild(); diff --git a/resources/views/index/index.blade.php b/resources/views/index/index.blade.php index 178ffca48b76..4cd0f0818271 100644 --- a/resources/views/index/index.blade.php +++ b/resources/views/index/index.blade.php @@ -6,6 +6,7 @@ Invoice Ninja +