mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 05:34:34 -04:00
set defaults for line items (#3029)
This commit is contained in:
parent
13e104c1d9
commit
aad22f607e
@ -31,7 +31,7 @@ class BaseSettings
|
|||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static function castAttribute($key, $value)
|
public static function castAttribute($key, $value)
|
||||||
{
|
{
|
||||||
switch ($key)
|
switch ($key)
|
||||||
{
|
{
|
||||||
|
@ -14,39 +14,64 @@ namespace App\DataMapper;
|
|||||||
class InvoiceItem
|
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',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace App\Helpers\Invoice;
|
namespace App\Helpers\Invoice;
|
||||||
|
|
||||||
|
use App\DataMapper\BaseSettings;
|
||||||
|
use App\DataMapper\InvoiceItem;
|
||||||
use App\Helpers\Invoice\Discounter;
|
use App\Helpers\Invoice\Discounter;
|
||||||
use App\Helpers\Invoice\Taxer;
|
use App\Helpers\Invoice\Taxer;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
@ -77,7 +79,8 @@ class InvoiceItemSum
|
|||||||
{
|
{
|
||||||
foreach($this->invoice->line_items as $this->item)
|
foreach($this->invoice->line_items as $this->item)
|
||||||
{
|
{
|
||||||
$this->sumLineItem()
|
$this->cleanLineItem()
|
||||||
|
->sumLineItem()
|
||||||
->setDiscount()
|
->setDiscount()
|
||||||
->calcTaxes()
|
->calcTaxes()
|
||||||
->push();
|
->push();
|
||||||
@ -266,4 +269,24 @@ class InvoiceItemSum
|
|||||||
$this->setTotalTaxes($item_tax);
|
$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;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user