From 28a214a9bcf990e747cc4e9f296ae0f623448ffa Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 3 Sep 2019 13:39:35 +1000 Subject: [PATCH] Tests --- app/DataMapper/InvoiceItem.php | 12 ++++++++- app/Utils/Traits/MakesInvoiceValues.php | 19 +++++++++++-- resources/views/pdf/design1.blade.php | 16 ++++++++--- tests/Unit/MakesInvoiceValuesTest.php | 36 +++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 7 deletions(-) create mode 100644 tests/Unit/MakesInvoiceValuesTest.php diff --git a/app/DataMapper/InvoiceItem.php b/app/DataMapper/InvoiceItem.php index 435222c2ed4f..59b0edf1ba88 100644 --- a/app/DataMapper/InvoiceItem.php +++ b/app/DataMapper/InvoiceItem.php @@ -14,7 +14,7 @@ namespace App\DataMapper; class InvoiceItem { - private $qty; + private $quantity; private $cost; @@ -38,5 +38,15 @@ class InvoiceItem private $line_total; + private $date; + + private $custom_value1; + + private $custom_value2; + + private $custom_value3; + + private $custom_value4; + } diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index e3080aaa3458..bc15ae6a4d2a 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -226,6 +226,8 @@ trait MakesInvoiceValues */ public function table(array $columns) :string { + //need to transform taxes and custom labels between the header column and value columns + $data = ''; $data .= ''; @@ -233,17 +235,30 @@ trait MakesInvoiceValues foreach($columns as $column) $data .= ''; - $data .= ''; + $data .= ''; + + $columns = str_replace(['custom_invoice_label1', + 'custom_invoice_label2', + 'custom_invoice_label3', + 'custom_invoice_label4'], + ['custom_invoice_value1', + 'custom_invoice_value2', + 'custom_invoice_value3', + 'custom_invoice_value4'], + $columns); foreach($this->line_items as $item) { + $data .= ''; foreach($columns as $column) - $data .= ''; + $data .= ''; $data .= ''; + } + $data .= '
' . ctrans('texts.column') . '
{$item->column}'. $item->{$column} . '
'; } diff --git a/resources/views/pdf/design1.blade.php b/resources/views/pdf/design1.blade.php index cfa3b5a410b7..344199300fc3 100644 --- a/resources/views/pdf/design1.blade.php +++ b/resources/views/pdf/design1.blade.php @@ -163,14 +163,22 @@ {{-- column variables: + + date + discount + product_key item - description + notes cost quantity - taxes - subtotal + taxes (tax_name1, tax_name2, tax_rate1, tax_rate2) + line_total + custom_label1 ( will show as the following parameter as its value -> custom_invoice_value1 ) + custom_label2 ( will show as the following parameter as its value -> custom_invoice_value2 ) + custom_label3 ( will show as the following parameter as its value -> custom_invoice_value3 ) + custom_label4 ( will show as the following parameter as its value -> custom_invoice_value4 ) --}} - {{ $invoice->table(['item','description','cost','quantity', 'taxes', 'subtotal']) }} + {{ $invoice->table(['item','description','cost','quantity', 'tax_name1', 'line_total']) }} diff --git a/tests/Unit/MakesInvoiceValuesTest.php b/tests/Unit/MakesInvoiceValuesTest.php new file mode 100644 index 000000000000..48f9a2407137 --- /dev/null +++ b/tests/Unit/MakesInvoiceValuesTest.php @@ -0,0 +1,36 @@ +assertTrue(in_array("custom_invoice_value3", $columns)); + + } + + + +}