diff --git a/app/Factory/InvoiceItemFactory.php b/app/Factory/InvoiceItemFactory.php index 80c0a1e9b981..d30f89bb19a4 100644 --- a/app/Factory/InvoiceItemFactory.php +++ b/app/Factory/InvoiceItemFactory.php @@ -11,12 +11,14 @@ namespace App\Factory; +use Illuminate\Support\Carbon; + class InvoiceItemFactory { public static function create() :\stdClass { $item = new \stdClass; - $item->qty = 0; + $item->quantity = 0; $item->cost = 0; $item->product_key = ''; $item->notes = ''; @@ -28,9 +30,13 @@ class InvoiceItemFactory $item->tax_rate2 = 0; $item->sort_id = 0; $item->line_total = 0; - $item->invoice_item_type_id = 0; - + $item->date = Carbon::now(); + $item->custom_value1 = NULL; + $item->custom_value2 = NULL; + $item->custom_value3 = NULL; + $item->custom_value4 = NULL; + return $item; + } } - diff --git a/app/Utils/Traits/MakesInvoiceValues.php b/app/Utils/Traits/MakesInvoiceValues.php index bc15ae6a4d2a..20709e7e4368 100644 --- a/app/Utils/Traits/MakesInvoiceValues.php +++ b/app/Utils/Traits/MakesInvoiceValues.php @@ -226,7 +226,6 @@ trait MakesInvoiceValues */ public function table(array $columns) :string { - //need to transform taxes and custom labels between the header column and value columns $data = ''; @@ -237,17 +236,11 @@ trait MakesInvoiceValues $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); + $columns = $this->transformColumns($columns); - foreach($this->line_items as $item) + $items = $this->transformLineItems($this->line_items); + + foreach($items as $item) { $data .= ''; @@ -262,4 +255,35 @@ trait MakesInvoiceValues $data .= '
'; } + /** + * Transform the column headers into invoice variables + * @param array $columns The column header values + * @return array The invoice variables + */ + private function transformColumns(array $columns) :array + { + return str_replace(['custom_invoice_label1', + 'custom_invoice_label2', + 'custom_invoice_label3', + 'custom_invoice_label4', + 'tax_name1', + 'tax_name2'], + ['custom_invoice_value1', + 'custom_invoice_value2', + 'custom_invoice_value3', + 'custom_invoice_value4', + 'tax_rate1', + 'tax_rate2'], + $columns); + } + + /** + * Formats the line items for display + * @param array $items The array of invoice items + * @return array The formatted array of invoice items + */ + private function transformLineItems(array $items) :array + { + + } } \ No newline at end of file diff --git a/resources/views/pdf/design1.blade.php b/resources/views/pdf/design1.blade.php index 344199300fc3..24adadbad9cc 100644 --- a/resources/views/pdf/design1.blade.php +++ b/resources/views/pdf/design1.blade.php @@ -171,7 +171,8 @@ notes cost quantity - taxes (tax_name1, tax_name2, tax_rate1, tax_rate2) + tax_name1 + tax_name2 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 ) diff --git a/tests/Unit/MakesInvoiceValuesTest.php b/tests/Unit/MakesInvoiceValuesTest.php index 48f9a2407137..ef79b1fadeb3 100644 --- a/tests/Unit/MakesInvoiceValuesTest.php +++ b/tests/Unit/MakesInvoiceValuesTest.php @@ -28,7 +28,7 @@ class MakesInvoiceValuesTest extends TestCase $this->assertTrue(in_array("custom_invoice_value3", $columns)); - + $this->assertFalse(in_array("custom_invoice_value1", $columns)); }