fixed document line discount calculation issue

This commit is contained in:
Cihan Şentürk 2025-02-27 13:00:24 +03:00 committed by GitHub
parent a8adeff326
commit 805dbb8a71
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 41 additions and 10 deletions

View File

@ -47,10 +47,12 @@ class CreateDocumentItem extends Job implements HasOwner, HasSource, ShouldCreat
// Apply total discount to amount
if (! empty($this->request['global_discount'])) {
if ($this->request['global_discount_type'] === 'percentage') {
$item_discounted_amount -= $item_discounted_amount * ($this->request['global_discount'] / 100);
$global_discount = $item_discounted_amount * ($this->request['global_discount'] / 100);
} else {
$item_discounted_amount -= $this->request['global_discount'];
$global_discount = $this->request['global_discount'];
}
$item_discounted_amount -= $global_discount;
}
$tax_amount = 0;
@ -153,6 +155,12 @@ class CreateDocumentItem extends Job implements HasOwner, HasSource, ShouldCreat
}
}
if (! empty($global_discount)) {
$actual_price_item += $global_discount;
$item_amount += $global_discount;
$item_discounted_amount += $global_discount;
}
$this->request['company_id'] = $this->document->company_id;
$this->request['type'] = $this->document->type;
$this->request['document_id'] = $this->document->id;

View File

@ -70,7 +70,8 @@ class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, S
if (! empty($this->request['discount'])) {
if ($this->request['discount_type'] === 'percentage') {
$discount_total = ($sub_total - $discount_amount_total) * ($this->request['discount'] / 100);
//$discount_total = ($sub_total - $discount_amount_total) * ($this->request['discount'] / 100);
$discount_total = $sub_total * ($this->request['discount'] / 100);
} else {
$discount_total = $this->request['discount'];
}
@ -173,17 +174,16 @@ class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, S
foreach ((array) $this->request['items'] as $key => $item) {
$item['global_discount'] = 0;
/* // Disable this lines for global discount issue fixed ( https://github.com/akaunting/akaunting/issues/2797 )
// Disable this lines for global discount issue fixed ( https://github.com/akaunting/akaunting/issues/2797 )
if (! empty($this->request['discount'])) {
if (isset($for_fixed_discount)) {
$item['global_discount'] = ($for_fixed_discount[$key] / ($for_fixed_discount['total'] / 100)) * ($this->request['discount'] / 100);
$item['global_discount_type'] = '';
$item['global_discount_type'] = $this->request['discount_type'];
} else {
$item['global_discount'] = $this->request['discount'];
$item['global_discount_type'] = $this->request['discount_type'];
}
}
*/
$item['created_from'] = $this->request['created_from'];
$item['created_by'] = $this->request['created_by'];
@ -211,7 +211,9 @@ class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, S
$document_item = $this->dispatch(new CreateDocumentItem($this->document, $item));
$item_amount = (double) $item['price'] * (double) $item['quantity'];
# This line changed for discount calcualter issue
//$item_amount = (double) $item['price'] * (double) $item['quantity'];
$item_amount = $document_item->total;
$discount_amount = 0;

View File

@ -50,6 +50,7 @@ class DocumentItem extends Model
'price' => 'double',
'total' => 'double',
'tax' => 'double',
'discount_rate' => 'double',
'deleted_at' => 'datetime',
];
@ -132,7 +133,7 @@ class DocumentItem extends Model
return $text;
}
public function getDiscountRateAttribute(int $value = 0)
public function getDiscountRateAttribute($value = 0)
{
$discount_rate = 0;

View File

@ -321,6 +321,10 @@
]
]
])}}"
:option_field="{{ json_encode([
'key' => 'id',
'value' => 'title'
]) }}"
@interface="row_tax.id = $event"
@change="onCalculateTotal()"
@new="dynamic_taxes.push($event)"
@ -331,7 +335,7 @@
<template #option="{option}">
<span class="tax-group flex items-center">
<span class="float-left">
@{{ option.value }}
@{{ option.option.title }}
</span>
<span
@ -424,6 +428,10 @@
]
]
])}}"
:option_field="{{ json_encode([
'key' => 'id',
'value' => 'title'
]) }}"
@interface="tax_id = $event"
@visible-change="onSelectedTax(index)"
@new="dynamic_taxes.push($event)"
@ -434,7 +442,7 @@
<template #option="{option}">
<span class="tax-group flex items-center">
<span class="float-left">
@{{ option.value }}
@{{ option.option.title }}
</span>
<span

View File

@ -346,6 +346,10 @@
<div class="col-40 float-right text-right">
@foreach ($document->totals_sorted as $total)
@if ($total->code == 'item_discount')
@continue
@endif
@if ($total->code != 'total')
@stack($total->code . '_total_tr_start')
<div class="text border-bottom-dashed py-1">

View File

@ -317,6 +317,10 @@
<div class="col-40 float-right text-right">
@foreach ($document->totals_sorted as $total)
@if ($total->code == 'item_discount')
@continue
@endif
@if ($total->code != 'total')
@stack($total->code . '_total_tr_start')
<div class="text border-bottom-1 py-1">

View File

@ -313,6 +313,10 @@
<div class="col-40 float-right text-right">
@foreach ($document->totals_sorted as $total)
@if ($total->code == 'item_discount')
@continue
@endif
@if ($total->code != 'total')
@stack($total->code . '_total_tr_start')
<div class="text">