fixed document tax calculate issue
This commit is contained in:
parent
2beba59bb1
commit
f9b3d9ebfa
|
|
@ -238,11 +238,11 @@ class CreateDocumentItemsAndTotals extends Job implements HasOwner, HasSource, S
|
||||||
// Set taxes
|
// Set taxes
|
||||||
foreach ((array) $document_item->item_taxes as $item_tax) {
|
foreach ((array) $document_item->item_taxes as $item_tax) {
|
||||||
if (array_key_exists($item_tax['tax_id'], $taxes)) {
|
if (array_key_exists($item_tax['tax_id'], $taxes)) {
|
||||||
$taxes[$item_tax['tax_id']]['amount'] += $item_tax['amount'];
|
$taxes[$item_tax['tax_id']]['amount'] += number_format($item_tax['amount'], $this->document->currency->precision);
|
||||||
} else {
|
} else {
|
||||||
$taxes[$item_tax['tax_id']] = [
|
$taxes[$item_tax['tax_id']] = [
|
||||||
'name' => $item_tax['name'],
|
'name' => $item_tax['name'],
|
||||||
'amount' => $item_tax['amount'],
|
'amount' => number_format($item_tax['amount'], $this->document->currency->precision),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -461,7 +461,7 @@ const app = new Vue({
|
||||||
if (inclusives.length) {
|
if (inclusives.length) {
|
||||||
inclusives.forEach(function(inclusive) {
|
inclusives.forEach(function(inclusive) {
|
||||||
item.tax_ids[inclusive.tax_index].name = inclusive.tax_name;
|
item.tax_ids[inclusive.tax_index].name = inclusive.tax_name;
|
||||||
item.tax_ids[inclusive.tax_index].price = item.grand_total - (item.grand_total / (1 + inclusive.tax_rate / 100));
|
item.tax_ids[inclusive.tax_index].price = this.numberFormat(item.grand_total - (item.grand_total / (1 + inclusive.tax_rate / 100)), this.currency.precision);
|
||||||
|
|
||||||
inclusive_tax_total += item.tax_ids[inclusive.tax_index].price;
|
inclusive_tax_total += item.tax_ids[inclusive.tax_index].price;
|
||||||
|
|
||||||
|
|
@ -474,7 +474,7 @@ const app = new Vue({
|
||||||
if (fixed.length) {
|
if (fixed.length) {
|
||||||
fixed.forEach(function(fixed) {
|
fixed.forEach(function(fixed) {
|
||||||
item.tax_ids[fixed.tax_index].name = fixed.tax_name;
|
item.tax_ids[fixed.tax_index].name = fixed.tax_name;
|
||||||
item.tax_ids[fixed.tax_index].price = fixed.tax_rate * calculationToQuantity(item.quantity);
|
item.tax_ids[fixed.tax_index].price = this.numberFormat(fixed.tax_rate * calculationToQuantity(item.quantity), this.currency.precision);
|
||||||
|
|
||||||
total_tax_amount += item.tax_ids[fixed.tax_index].price;
|
total_tax_amount += item.tax_ids[fixed.tax_index].price;
|
||||||
|
|
||||||
|
|
@ -491,7 +491,7 @@ const app = new Vue({
|
||||||
if (normal.length) {
|
if (normal.length) {
|
||||||
normal.forEach(function(normal) {
|
normal.forEach(function(normal) {
|
||||||
item.tax_ids[normal.tax_index].name = normal.tax_name;
|
item.tax_ids[normal.tax_index].name = normal.tax_name;
|
||||||
item.tax_ids[normal.tax_index].price = price_for_tax * (normal.tax_rate / 100);
|
item.tax_ids[normal.tax_index].price = this.numberFormat((price_for_tax * (normal.tax_rate / 100)), this.currency.precision);
|
||||||
|
|
||||||
total_tax_amount += item.tax_ids[normal.tax_index].price;
|
total_tax_amount += item.tax_ids[normal.tax_index].price;
|
||||||
|
|
||||||
|
|
@ -502,7 +502,7 @@ const app = new Vue({
|
||||||
if (withholding.length) {
|
if (withholding.length) {
|
||||||
withholding.forEach(function(withholding) {
|
withholding.forEach(function(withholding) {
|
||||||
item.tax_ids[withholding.tax_index].name = withholding.tax_name;
|
item.tax_ids[withholding.tax_index].name = withholding.tax_name;
|
||||||
item.tax_ids[withholding.tax_index].price = -(price_for_tax * (withholding.tax_rate / 100));
|
item.tax_ids[withholding.tax_index].price = -this.numberFormat((price_for_tax * (withholding.tax_rate / 100)), this.currency.precision);
|
||||||
|
|
||||||
total_tax_amount += item.tax_ids[withholding.tax_index].price;
|
total_tax_amount += item.tax_ids[withholding.tax_index].price;
|
||||||
|
|
||||||
|
|
@ -515,7 +515,7 @@ const app = new Vue({
|
||||||
if (compounds.length) {
|
if (compounds.length) {
|
||||||
compounds.forEach(function(compound) {
|
compounds.forEach(function(compound) {
|
||||||
item.tax_ids[compound.tax_index].name = compound.tax_name;
|
item.tax_ids[compound.tax_index].name = compound.tax_name;
|
||||||
item.tax_ids[compound.tax_index].price = (item.grand_total / 100) * compound.tax_rate;
|
item.tax_ids[compound.tax_index].price = this.numberFormat((item.grand_total / 100) * compound.tax_rate, this.currency.precision);
|
||||||
|
|
||||||
totals_taxes = this.calculateTotalsTax(totals_taxes, compound.tax_id, compound.tax_name, item.tax_ids[compound.tax_index].price);
|
totals_taxes = this.calculateTotalsTax(totals_taxes, compound.tax_id, compound.tax_name, item.tax_ids[compound.tax_index].price);
|
||||||
|
|
||||||
|
|
@ -887,6 +887,26 @@ const app = new Vue({
|
||||||
|
|
||||||
this.onSubmit();
|
this.onSubmit();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
numberFormat(number, decimals = 0, decPoint = '.', thousandsSep = ',') {
|
||||||
|
number = parseFloat(number);
|
||||||
|
|
||||||
|
if (isNaN(number)) return '0';
|
||||||
|
|
||||||
|
// Ondalık basamakları ayarla
|
||||||
|
number = number.toFixed(decimals);
|
||||||
|
|
||||||
|
// Sayıyı parçalara ayır
|
||||||
|
let parts = number.split('.');
|
||||||
|
let integerPart = parts[0];
|
||||||
|
let decimalPart = parts[1] || '';
|
||||||
|
|
||||||
|
// Binlik ayıracı ekle
|
||||||
|
integerPart = integerPart.replace(/\B(?=(\d{3})+(?!\d))/g, thousandsSep);
|
||||||
|
|
||||||
|
// Sonucu birleştir
|
||||||
|
return decimals > 0 ? parseFloat(integerPart + decPoint + decimalPart) : parseFloat(integerPart);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
created() {
|
created() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue