From 397b050eaeb67b6c8dd895e804240dd89efaff72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Tue, 10 Mar 2020 17:25:22 +0300 Subject: [PATCH] close #1340 Fixed: Missing edit invoice and bill item taxes. --- app/Models/Purchase/BillItem.php | 25 +++++++++++++++++++++++++ app/Models/Sale/InvoiceItem.php | 25 +++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/app/Models/Purchase/BillItem.php b/app/Models/Purchase/BillItem.php index 76ae399e0..774d2784b 100644 --- a/app/Models/Purchase/BillItem.php +++ b/app/Models/Purchase/BillItem.php @@ -27,6 +27,15 @@ class BillItem extends Model */ public $cloneable_relations = ['taxes']; + public static function boot() + { + parent::boot(); + + static::retrieved(function($model) { + $model->setTaxIds(); + }); + } + public function bill() { return $this->belongsTo('App\Models\Purchase\Bill'); @@ -74,4 +83,20 @@ class BillItem extends Model { $this->attributes['tax'] = (double) $value; } + + /** + * Convert tax to Array. + * + * @return void + */ + public function setTaxIds() + { + $tax_ids = []; + + foreach ($this->taxes as $tax) { + $tax_ids[] = (string) $tax->tax_id; + } + + $this->setAttribute('tax_id', $tax_ids); + } } diff --git a/app/Models/Sale/InvoiceItem.php b/app/Models/Sale/InvoiceItem.php index b9bd13a43..8fac300a2 100644 --- a/app/Models/Sale/InvoiceItem.php +++ b/app/Models/Sale/InvoiceItem.php @@ -26,6 +26,15 @@ class InvoiceItem extends Model */ public $cloneable_relations = ['taxes']; + public static function boot() + { + parent::boot(); + + static::retrieved(function($model) { + $model->setTaxIds(); + }); + } + public function invoice() { return $this->belongsTo('App\Models\Sale\Invoice'); @@ -73,4 +82,20 @@ class InvoiceItem extends Model { $this->attributes['tax'] = (double) $value; } + + /** + * Convert tax to Array. + * + * @return void + */ + public function setTaxIds() + { + $tax_ids = []; + + foreach ($this->taxes as $tax) { + $tax_ids[] = (string) $tax->tax_id; + } + + $this->setAttribute('tax_id', $tax_ids); + } }