Merge pull request #565 from cuneytsenturk/1.3-dev
Invoice/Bill Items: Multiple tax rate
This commit is contained in:
@ -82,6 +82,11 @@ class Bill extends Model
|
||||
return $this->hasMany('App\Models\Expense\BillItem');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillItemTax');
|
||||
}
|
||||
|
||||
public function payments()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillPayment');
|
||||
|
@ -29,6 +29,11 @@ class BillItem extends Model
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Expense\BillItemTax', 'bill_item_id', 'id');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
@ -66,4 +71,23 @@ class BillItem extends Model
|
||||
{
|
||||
$this->attributes['tax'] = (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tax to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function getTaxIdAttribute($value)
|
||||
{
|
||||
$tax_ids = [];
|
||||
|
||||
if (!empty($value)) {
|
||||
$tax_ids[] = $value;
|
||||
|
||||
return $tax_ids;
|
||||
}
|
||||
|
||||
return $this->itemTaxes->pluck('tax_id');
|
||||
}
|
||||
}
|
||||
|
47
app/Models/Expense/BillItemTax.php
Normal file
47
app/Models/Expense/BillItemTax.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class BillItemTax extends Model
|
||||
{
|
||||
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'bill_item_taxes';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'bill_id', 'bill_item_id', 'tax_id', 'name', 'amount'];
|
||||
|
||||
public function bill()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Expense\Bill');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert amount to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function setAmountAttribute($value)
|
||||
{
|
||||
$this->attributes['amount'] = (double) $value;
|
||||
}
|
||||
}
|
@ -83,6 +83,11 @@ class Invoice extends Model
|
||||
return $this->hasMany('App\Models\Income\InvoiceItem');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceItemTax');
|
||||
}
|
||||
|
||||
public function histories()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceHistory');
|
||||
|
@ -29,6 +29,11 @@ class InvoiceItem extends Model
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function itemTaxes()
|
||||
{
|
||||
return $this->hasMany('App\Models\Income\InvoiceItemTax', 'invoice_item_id', 'id');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
@ -66,4 +71,23 @@ class InvoiceItem extends Model
|
||||
{
|
||||
$this->attributes['tax'] = (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert tax to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function getTaxIdAttribute($value)
|
||||
{
|
||||
$tax_ids = [];
|
||||
|
||||
if (!empty($value)) {
|
||||
$tax_ids[] = $value;
|
||||
|
||||
return $tax_ids;
|
||||
}
|
||||
|
||||
return $this->itemTaxes->pluck('tax_id');
|
||||
}
|
||||
}
|
||||
|
47
app/Models/Income/InvoiceItemTax.php
Normal file
47
app/Models/Income/InvoiceItemTax.php
Normal file
@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Traits\Currencies;
|
||||
|
||||
class InvoiceItemTax extends Model
|
||||
{
|
||||
|
||||
use Currencies;
|
||||
|
||||
protected $table = 'invoice_item_taxes';
|
||||
|
||||
/**
|
||||
* Attributes that should be mass-assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['company_id', 'invoice_id', 'invoice_item_id', 'tax_id', 'name', 'amount'];
|
||||
|
||||
public function invoice()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Income\Invoice');
|
||||
}
|
||||
|
||||
public function item()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Common\Item');
|
||||
}
|
||||
|
||||
public function tax()
|
||||
{
|
||||
return $this->belongsTo('App\Models\Setting\Tax');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert amount to double.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function setAmountAttribute($value)
|
||||
{
|
||||
$this->attributes['amount'] = (double) $value;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user