Akaunting/app/Models/Sale/InvoiceItem.php

77 lines
1.5 KiB
PHP
Raw Normal View History

2017-09-14 19:21:00 +00:00
<?php
2019-12-31 12:49:09 +00:00
namespace App\Models\Sale;
2017-09-14 19:21:00 +00:00
2019-11-16 07:21:14 +00:00
use App\Abstracts\Model;
2017-09-14 19:21:00 +00:00
use App\Traits\Currencies;
2019-11-16 07:21:14 +00:00
use Bkwld\Cloner\Cloneable;
2017-09-14 19:21:00 +00:00
class InvoiceItem extends Model
{
2019-11-16 07:21:14 +00:00
use Cloneable, Currencies;
2017-09-14 19:21:00 +00:00
protected $table = 'invoice_items';
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
2019-11-16 07:21:14 +00:00
protected $fillable = ['company_id', 'invoice_id', 'item_id', 'name', 'quantity', 'price', 'total', 'tax'];
/**
* Clonable relationships.
*
* @var array
*/
public $cloneable_relations = ['taxes'];
2017-09-14 19:21:00 +00:00
public function invoice()
{
2019-12-31 12:49:09 +00:00
return $this->belongsTo('App\Models\Sale\Invoice');
2017-09-14 19:21:00 +00:00
}
public function item()
{
2020-01-20 19:58:49 +00:00
return $this->belongsTo('App\Models\Common\Item')->withDefault(['name' => trans('general.na')]);
2017-09-14 19:21:00 +00:00
}
2019-01-07 15:38:34 +00:00
public function taxes()
2018-10-22 13:14:17 +00:00
{
2019-12-31 12:49:09 +00:00
return $this->hasMany('App\Models\Sale\InvoiceItemTax', 'invoice_item_id', 'id');
2018-10-22 13:14:17 +00:00
}
2017-10-21 11:23:57 +00:00
/**
* Convert price to double.
*
* @param string $value
* @return void
*/
public function setPriceAttribute($value)
{
$this->attributes['price'] = (double) $value;
2017-10-21 11:23:57 +00:00
}
/**
* Convert total to double.
*
* @param string $value
* @return void
*/
public function setTotalAttribute($value)
{
$this->attributes['total'] = (double) $value;
}
/**
* Convert tax to double.
*
* @param string $value
* @return void
*/
public function setTaxAttribute($value)
{
$this->attributes['tax'] = (double) $value;
2017-10-21 11:23:57 +00:00
}
2017-09-14 19:21:00 +00:00
}