1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

set defaults for line items (#3029)

This commit is contained in:
David Bomba 2019-10-29 22:44:54 +11:00 committed by GitHub
parent 13e104c1d9
commit aad22f607e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 19 deletions

View File

@ -31,7 +31,7 @@ class BaseSettings
return $obj;
}
protected static function castAttribute($key, $value)
public static function castAttribute($key, $value)
{
switch ($key)
{

View File

@ -14,39 +14,64 @@ namespace App\DataMapper;
class InvoiceItem
{
private $quantity;
public $quantity = 0;
private $cost;
public $cost = 0;
private $product_key;
public $product_key = '';
private $notes;
public $notes = '';
private $discount;
public $discount = 0;
private $is_amount_discount;
public $is_amount_discount = false;
private $tax_name1;
public $tax_name1 = '';
private $tax_rate1;
public $tax_rate1 = 0;
private $tax_name2;
public $tax_name2 = '';
private $tax_rate2;
public $tax_rate2 = 0;
private $sort_id;
public $tax_name3 = '';
private $line_total;
public $tax_rate3 = 0;
private $date;
public $sort_id = 0;
private $custom_value1;
public $line_total = 0;
private $custom_value2;
public $date = '';
private $custom_value3;
public $custom_value1 = '';
private $custom_value4;
public $custom_value2 = '';
public $custom_value3 = '';
public $custom_value4 = '';
public static $casts = [
'quantity' => 'float',
'cost' => 'float',
'product_key' => 'string',
'notes' => 'string',
'discount' => 'float',
'is_amount_discount' => 'bool',
'tax_name1' => 'string',
'tax_name2' => 'string',
'tax_name3' => 'string',
'tax_rate1' => 'float',
'tax_rate2' => 'float',
'tax_rate3' => 'float',
'sort_id' => 'int',
'line_total' => 'float',
'date' => 'string',
'custom_value1' => 'string',
'custom_value2' => 'string',
'custom_value3' => 'string',
'custom_value4' => 'string',
];
}

View File

@ -11,6 +11,8 @@
namespace App\Helpers\Invoice;
use App\DataMapper\BaseSettings;
use App\DataMapper\InvoiceItem;
use App\Helpers\Invoice\Discounter;
use App\Helpers\Invoice\Taxer;
use App\Models\Invoice;
@ -77,7 +79,8 @@ class InvoiceItemSum
{
foreach($this->invoice->line_items as $this->item)
{
$this->sumLineItem()
$this->cleanLineItem()
->sumLineItem()
->setDiscount()
->calcTaxes()
->push();
@ -266,4 +269,24 @@ class InvoiceItemSum
$this->setTotalTaxes($item_tax);
}
/**
* Sets default values for the line_items
* @return $this
*/
private function cleanLineItem()
{
$invoice_item = (object)get_class_vars(InvoiceItem::class);
unset($invoice_item->casts);
foreach($invoice_item as $key => $value)
{
if(!property_exists($this->item, $key))
$this->item->{$key} = BaseSettings::castAttribute(InvoiceItem::$casts[$key], $value);
}
return $this;
}
}