mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 05:02:36 +01:00
Custom values for invoice templates
This commit is contained in:
parent
28a214a9bc
commit
f9a5bd3444
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 = '<table class="table table-hover table-striped">';
|
||||
|
||||
@ -237,17 +236,11 @@ trait MakesInvoiceValues
|
||||
|
||||
$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);
|
||||
$columns = $this->transformColumns($columns);
|
||||
|
||||
foreach($this->line_items as $item)
|
||||
$items = $this->transformLineItems($this->line_items);
|
||||
|
||||
foreach($items as $item)
|
||||
{
|
||||
|
||||
$data .= '<tr class="item">';
|
||||
@ -262,4 +255,35 @@ trait MakesInvoiceValues
|
||||
$data .= '</table>';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -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 )
|
||||
|
@ -28,7 +28,7 @@ class MakesInvoiceValuesTest extends TestCase
|
||||
|
||||
|
||||
$this->assertTrue(in_array("custom_invoice_value3", $columns));
|
||||
|
||||
$this->assertFalse(in_array("custom_invoice_value1", $columns));
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user