akaunting/app/Models/Expense/BillItem.php

70 lines
1.3 KiB
PHP
Raw Normal View History

2017-09-14 22:21:00 +03:00
<?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
*/
2019-01-07 18:38:34 +03:00
protected $fillable = ['company_id', 'bill_id', 'item_id', 'name', 'sku', 'quantity', 'price', 'total', 'tax'];
2017-09-14 22:21:00 +03:00
public function bill()
{
return $this->belongsTo('App\Models\Expense\Bill');
}
public function item()
{
2018-06-10 02:48:51 +03:00
return $this->belongsTo('App\Models\Common\Item');
2017-09-14 22:21:00 +03:00
}
2019-01-07 18:38:34 +03:00
public function taxes()
2018-10-22 16:57:35 +03:00
{
return $this->hasMany('App\Models\Expense\BillItemTax', 'bill_item_id', 'id');
}
2017-10-21 14:23:57 +03:00
/**
* Convert price to double.
*
* @param string $value
* @return void
*/
public function setPriceAttribute($value)
{
$this->attributes['price'] = (double) $value;
2017-10-21 14:23:57 +03: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 14:23:57 +03:00
}
2017-09-14 22:21:00 +03:00
}