diff --git a/frontend/pages/incomingInvoices/[mode]/[id].vue b/frontend/pages/incomingInvoices/[mode]/[id].vue index fdc8ff3..1efd87d 100644 --- a/frontend/pages/incomingInvoices/[mode]/[id].vue +++ b/frontend/pages/incomingInvoices/[mode]/[id].vue @@ -194,6 +194,16 @@ const totalCalculated = computed(() => { const hasAmount = (value) => value !== null && value !== undefined && value !== "" const hasValidNumber = (value) => hasAmount(value) && Number.isFinite(Number(value)) const isDepreciationItem = (item) => isDepreciationBookingMode(item?.bookingMode) +const getCalculatedTax = (item) => { + const taxRate = Number(taxOptions.value.find((tax) => tax.key === item.taxType)?.percentage || 0) + + return Number((Number(item.amountNet || 0) * (taxRate / 100)).toFixed(2)) +} +const hasManualTaxDifference = (item) => { + if (!hasValidNumber(item.amountTax) || !hasValidNumber(item.amountNet)) return false + + return Math.abs(Number(item.amountTax) - getCalculatedTax(item)) >= 0.005 +} const updateBookingMode = (item) => { ensureDepreciationDefaults(item, itemInfo.value.date) @@ -216,6 +226,14 @@ const recalculateItem = (item, source) => { calculateFromNet() } else if (source === 'gross') { calculateFromGross() + } else if (source === 'tax') { + if(!hasValidNumber(item.amountTax)) return + + if((useNetMode.value || !hasAmount(item.amountGross)) && hasAmount(item.amountNet)) { + item.amountGross = Number((Number(item.amountNet) + Number(item.amountTax)).toFixed(2)) + } else if(hasAmount(item.amountGross)) { + item.amountNet = Number((Number(item.amountGross) - Number(item.amountTax)).toFixed(2)) + } } else if (source === 'taxType' || source === 'manual') { if(hasAmount(item.amountNet)) calculateFromNet() else if(hasAmount(item.amountGross)) calculateFromGross() @@ -871,13 +889,30 @@ const hasBlockingIncomingInvoiceErrors = computed(() => blockingIncomingInvoiceE