bill scopes

This commit is contained in:
denisdulici 2020-01-20 23:50:29 +03:00
parent a3372aeb63
commit 04173eae78
3 changed files with 14 additions and 4 deletions

View File

@ -117,6 +117,11 @@ class Bill extends Model
return $query->where('status', '<>', 'paid'); return $query->where('status', '<>', 'paid');
} }
public function scopeNumber($query, $number)
{
return $query->where('bill_number', '=', $number);
}
public function onCloning($src, $child = null) public function onCloning($src, $child = null)
{ {
$this->status = 'draft'; $this->status = 'draft';

View File

@ -34,7 +34,7 @@ class BillItem extends Model
public function item() public function item()
{ {
return $this->belongsTo('App\Models\Common\Item'); return $this->belongsTo('App\Models\Common\Item')->withDefault(['name' => trans('general.na')]);
} }
public function taxes() public function taxes()

View File

@ -4,11 +4,11 @@ namespace App\Models\Purchase;
use App\Abstracts\Model; use App\Abstracts\Model;
use App\Traits\Currencies; use App\Traits\Currencies;
use Znck\Eloquent\Traits\BelongsToThrough;
class BillItemTax extends Model class BillItemTax extends Model
{ {
use Currencies, BelongsToThrough;
use Currencies;
protected $table = 'bill_item_taxes'; protected $table = 'bill_item_taxes';
@ -24,9 +24,14 @@ class BillItemTax extends Model
return $this->belongsTo('App\Models\Purchase\Bill'); return $this->belongsTo('App\Models\Purchase\Bill');
} }
public function item()
{
return $this->belongsToThrough('App\Models\Common\Item', 'App\Models\Purchase\BillItem', 'bill_item_id');
}
public function tax() public function tax()
{ {
return $this->belongsTo('App\Models\Setting\Tax'); return $this->belongsTo('App\Models\Setting\Tax')->withDefault(['name' => trans('general.na')]);
} }
/** /**