fix: installments split
This commit is contained in:
parent
af243af3bf
commit
913671aa5a
1 changed files with 22 additions and 5 deletions
|
|
@ -138,12 +138,15 @@ watch(
|
||||||
const totalAmount = summaryPrice.value.finalPrice;
|
const totalAmount = summaryPrice.value.finalPrice;
|
||||||
|
|
||||||
if (newCount > oldCount) {
|
if (newCount > oldCount) {
|
||||||
const installmentAmount = totalAmount / newCount;
|
// Calculate the base installment amount for all except the last installment
|
||||||
|
const installmentAmount = +(totalAmount / newCount).toFixed(2);
|
||||||
|
|
||||||
paySplit.value.forEach((payment, index) => {
|
// Update existing installments
|
||||||
|
paySplit.value.forEach((payment) => {
|
||||||
payment.amount = installmentAmount;
|
payment.amount = installmentAmount;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Add new installments
|
||||||
for (let i = oldCount; i < newCount; i++) {
|
for (let i = oldCount; i < newCount; i++) {
|
||||||
paySplit.value.push({
|
paySplit.value.push({
|
||||||
no: i + 1,
|
no: i + 1,
|
||||||
|
|
@ -152,13 +155,27 @@ watch(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else if (newCount < oldCount) {
|
} else if (newCount < oldCount) {
|
||||||
|
// Remove extra installments
|
||||||
paySplit.value.splice(newCount, oldCount - newCount);
|
paySplit.value.splice(newCount, oldCount - newCount);
|
||||||
|
|
||||||
const installmentAmount = totalAmount / newCount;
|
// Recalculate the base installment amount for remaining installments
|
||||||
|
const installmentAmount = +(totalAmount / newCount).toFixed(2);
|
||||||
paySplit.value.forEach((payment) => {
|
paySplit.value.forEach((payment) => {
|
||||||
payment.amount = installmentAmount;
|
payment.amount = installmentAmount;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calculate the amount for the last installment
|
||||||
|
if (paySplit.value.length > 0) {
|
||||||
|
const totalPreviousPayments = paySplit.value
|
||||||
|
.slice(0, -1)
|
||||||
|
.reduce((sum, payment) => sum + payment.amount, 0);
|
||||||
|
|
||||||
|
// Set the last installment to cover the remaining balance, rounded to 2 decimal places
|
||||||
|
const remainingAmount = totalAmount - totalPreviousPayments;
|
||||||
|
paySplit.value[paySplit.value.length - 1].amount =
|
||||||
|
+remainingAmount.toFixed(2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ deep: true },
|
{ deep: true },
|
||||||
|
|
@ -349,7 +366,7 @@ watch(
|
||||||
:label="$t('quotation.callDueDate')"
|
:label="$t('quotation.callDueDate')"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<q-select
|
<!-- <q-select
|
||||||
outlined
|
outlined
|
||||||
clearable
|
clearable
|
||||||
use-input
|
use-input
|
||||||
|
|
@ -421,7 +438,7 @@ watch(
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
</template>
|
</template>
|
||||||
</q-select>
|
</q-select> -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue