akaunting/app/Models/Expense/BillItem.php
2019-01-07 18:38:34 +03:00

70 lines
1.3 KiB
PHP

<?php
namespace App\Models\Expense;
use App\Models\Model;
use App\Traits\Currencies;
class BillItem extends Model
{
use Currencies;
protected $table = 'bill_items';
/**
* Attributes that should be mass-assignable.
*
* @var array
*/
protected $fillable = ['company_id', 'bill_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax'];
public function bill()
{
return $this->belongsTo('App\Models\Expense\Bill');
}
public function item()
{
return $this->belongsTo('App\Models\Common\Item');
}
public function taxes()
{
return $this->hasMany('App\Models\Expense\BillItemTax', 'bill_item_id', 'id');
}
/**
* Convert price to double.
*
* @param string $value
* @return void
*/
public function setPriceAttribute($value)
{
$this->attributes['price'] = (double) $value;
}
/**
* 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;
}
}