Adding discount as an amount #kbcqjv
This commit is contained in:
@ -43,16 +43,13 @@ class CreateDocumentItem extends Job
|
||||
|
||||
// Apply line discount to amount
|
||||
if (!empty($this->request['discount'])) {
|
||||
$discount += $this->request['discount'];
|
||||
$discount = $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'])) {
|
||||
$discount += $this->request['global_discount'];
|
||||
|
||||
$item_discounted_amount = $item_amount - ($item_amount * ($this->request['global_discount'] / 100));
|
||||
if ($this->request['discount_type'] === 'normal') {
|
||||
$item_discounted_amount = $item_amount -= ($item_amount * ($this->request['discount'] / 100));
|
||||
} else {
|
||||
$item_discounted_amount = $item_amount -= $this->request['discount'];
|
||||
}
|
||||
}
|
||||
|
||||
$tax_amount = 0;
|
||||
@ -153,7 +150,11 @@ class CreateDocumentItem extends Job
|
||||
$item_tax_total += $tax_amount;
|
||||
}
|
||||
|
||||
$item_amount = ($item_amount - $item_tax_total) / (1 - $discount / 100);
|
||||
if (!empty($this->request['discount_type']) && $this->request['discount_type'] === 'normal') {
|
||||
$item_amount = ($item_amount - $item_tax_total) / (1 - $discount / 100);
|
||||
} else {
|
||||
$item_amount = ($item_amount - $item_tax_total) - $discount;
|
||||
}
|
||||
}
|
||||
|
||||
if ($compounds) {
|
||||
@ -185,6 +186,7 @@ class CreateDocumentItem extends Job
|
||||
$this->request['quantity'] = (double) $this->request['quantity'];
|
||||
$this->request['price'] = round($this->request['price'], $precision);
|
||||
$this->request['tax'] = round($item_tax_total, $precision);
|
||||
$this->request['discount_type'] = !empty($this->request['discount_type']) ? $this->request['discount_type'] : 'normal';
|
||||
$this->request['discount_rate'] = !empty($this->request['discount']) ? $this->request['discount'] : 0;
|
||||
$this->request['total'] = round($item_amount, $precision);
|
||||
|
||||
|
@ -67,15 +67,17 @@ class CreateDocumentItemsAndTotals extends Job
|
||||
'sort_order' => $sort_order,
|
||||
]);
|
||||
|
||||
$this->request['amount'] -= $discount_amount_total;
|
||||
|
||||
$sort_order++;
|
||||
}
|
||||
|
||||
if (!empty($this->request['discount'])) {
|
||||
$discount_total = ($sub_total - $discount_amount_total) * ($this->request['discount'] / 100);
|
||||
if ($this->request['discount_type'] === 'normal') {
|
||||
$discount_total = $sub_total * ($this->request['discount'] / 100);
|
||||
} else {
|
||||
$discount_total = $this->request['discount'];
|
||||
}
|
||||
|
||||
DocumentTotal::create([
|
||||
DocumentTotal::create([
|
||||
'company_id' => $this->document->company_id,
|
||||
'type' => $this->document->type,
|
||||
'document_id' => $this->document->id,
|
||||
@ -193,11 +195,15 @@ class CreateDocumentItemsAndTotals extends Job
|
||||
$discount_amount = 0;
|
||||
|
||||
if (!empty($item['discount'])) {
|
||||
$discount_amount = ($item_amount * ($item['discount'] / 100));
|
||||
if ($item['discount_type'] === 'normal') {
|
||||
$discount_amount = ($item_amount * ($item['discount'] / 100));
|
||||
} else {
|
||||
$discount_amount = $item['discount'];
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate totals
|
||||
$sub_total += $document_item->total + $discount_amount;
|
||||
$sub_total += $document_item->total;
|
||||
|
||||
$discount_amount_total += $discount_amount;
|
||||
|
||||
|
Reference in New Issue
Block a user