This commit is contained in:
David Bomba 2019-09-03 13:39:35 +10:00
parent 47cdeef258
commit 28a214a9bc
4 changed files with 76 additions and 7 deletions

View File

@ -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;
}

View File

@ -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 = '<table class="table table-hover table-striped">';
$data .= '<thead><tr class="heading">';
@ -233,17 +235,30 @@ trait MakesInvoiceValues
foreach($columns as $column)
$data .= '<td>' . ctrans('texts.column') . '</td>';
$data .= '</tr></thead>';
$data .= '</tr></thead>';
$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 .= '<tr class="item">';
foreach($columns as $column)
$data .= '<td>{$item->column}</td>';
$data .= '<td>'. $item->{$column} . '</td>';
$data .= '</tr>';
}
$data .= '</table>';
}

View File

@ -163,14 +163,22 @@
</table>
{{--
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']) }}
<table cellpadding="0" cellspacing="0">

View File

@ -0,0 +1,36 @@
<?php
namespace Tests\Unit;
use Tests\TestCase;
/**
* @test
* @covers App\Utils\Traits\MakesInvoiceValues
*/
class MakesInvoiceValuesTest extends TestCase
{
public function testStrReplaceArray()
{
$columns = ['custom_invoice_label3'];
$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);
$this->assertTrue(in_array("custom_invoice_value3", $columns));
}
}