10, 'order_number' => 10, 'vendor_name' => 10, 'vendor_email' => 5, 'vendor_phone' => 2, 'vendor_address' => 1, 'notes' => 2, ]; /** * Clonable relationships. * * @var array */ protected $cloneable_relations = ['items', 'totals']; public function vendor() { return $this->belongsTo('App\Models\Expense\Vendor'); } public function currency() { return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code'); } public function status() { return $this->belongsTo('App\Models\Expense\BillStatus', 'bill_status_code', 'code'); } public function items() { return $this->hasMany('App\Models\Expense\BillItem'); } public function totals() { return $this->hasMany('App\Models\Expense\BillTotal'); } public function payments() { return $this->hasMany('App\Models\Expense\BillPayment'); } public function histories() { return $this->hasMany('App\Models\Expense\BillHistory'); } public function scopeDue($query, $date) { return $query->where('due_at', '=', $date); } public function scopeLatest($query) { return $query->orderBy('paid_at', 'desc'); } public function scopeAccrued($query) { return $query->where('bill_status_code', '!=', 'new'); } public function onCloning($src, $child = null) { $this->bill_status_code = 'draft'; } /** * Convert amount to double. * * @param string $value * @return void */ public function setAmountAttribute($value) { $this->attributes['amount'] = (double) $value; } /** * Convert currency rate to double. * * @param string $value * @return void */ public function setCurrencyRateAttribute($value) { $this->attributes['currency_rate'] = (double) $value; } /** * Get the current balance. * * @return string */ public function getAttachmentAttribute($value) { if (!empty($value) && !$this->hasMedia('attachment')) { return $value; } elseif (!$this->hasMedia('attachment')) { return false; } return $this->getMedia('attachment')->last(); } }