refs #1408 Fixed bill total discount feature..

This commit is contained in:
Cihan Şentürk
2020-04-20 04:06:20 +03:00
parent e3240fa43b
commit e244d15480
7 changed files with 44 additions and 5 deletions

View File

@ -179,6 +179,11 @@ class CreateBill extends Job
}
foreach ((array) $this->request['items'] as $item) {
$item['global_discount'] = 0;
if (!empty($this->request['discount'])) {
$item['global_discount'] = $this->request['discount'];
}
$bill_item = $this->dispatch(new CreateBillItem($item, $this->bill));

View File

@ -38,11 +38,16 @@ class CreateBillItem extends Job
$item_discounted_amount = $item_amount;
// Apply discount to amount
// Apply line discount to amount
if (!empty($this->request['discount'])) {
$item_discounted_amount = $item_amount -= ($item_amount * ($this->request['discount'] / 100));
}
// Apply global discount to amount
if (!empty($this->request['global_discount'])) {
$item_discounted_amount = $item_amount - ($item_amount * ($this->request['global_discount'] / 100));
}
$tax_amount = 0;
$item_taxes = [];
$item_tax_total = 0;

View File

@ -193,6 +193,11 @@ class UpdateBill extends Job
$this->deleteRelationships($this->bill, ['items', 'item_taxes']);
foreach ((array) $this->request['items'] as $item) {
$item['global_discount'] = 0;
if (!empty($this->request['discount'])) {
$item['global_discount'] = $this->request['discount'];
}
$bill_item = $this->dispatch(new CreateBillItem($item, $this->bill));

View File

@ -118,6 +118,31 @@ class BillItem extends Model
return $text;
}
/**
* Get the formatted discount.
*
* @return string
*/
public function getDiscountRateAttribute($value = 0)
{
$discount_rate = 0;
switch (setting('localisation.discount_location', 'total')) {
case 'no':
case 'total':
$discount_rate = 0;
break;
case 'item':
$discount_rate = $value;
break;
case 'both':
$discount_rate = $value;
break;
}
return $discount_rate;
}
/**
* Convert tax to Array.
*