refactor: remove date from installments
This commit is contained in:
parent
0570dc2677
commit
da8dc33b15
3 changed files with 18 additions and 60 deletions
|
|
@ -134,8 +134,14 @@ const workerList = ref<Employee[]>([]);
|
|||
const selectedProductGroup = ref('');
|
||||
const selectedInstallmentNo = ref<number[]>([]);
|
||||
const agentPrice = ref(false);
|
||||
const summaryPrice = computed(() =>
|
||||
productServiceList.value.reduce(
|
||||
|
||||
function getPrice(
|
||||
list: typeof productServiceList.value,
|
||||
filterHook?: (arg: (typeof productServiceList.value)[number]) => boolean,
|
||||
) {
|
||||
if (filterHook) list = list.filter(filterHook);
|
||||
|
||||
return list.reduce(
|
||||
(a, c) => {
|
||||
if (
|
||||
selectedInstallmentNo.value.length > 0 &&
|
||||
|
|
@ -172,8 +178,10 @@ const summaryPrice = computed(() =>
|
|||
vatExcluded: 0,
|
||||
finalPrice: 0,
|
||||
},
|
||||
),
|
||||
);
|
||||
);
|
||||
}
|
||||
|
||||
const summaryPrice = computed(() => getPrice(productServiceList.value));
|
||||
|
||||
const payBank = ref('');
|
||||
|
||||
|
|
|
|||
|
|
@ -51,9 +51,9 @@ const payType = defineModel<'Full' | 'Split' | 'BillFull' | 'BillSplit'>(
|
|||
const paySplitCount = defineModel<number | null>('paySplitCount', {
|
||||
default: 1,
|
||||
});
|
||||
const paySplit = defineModel<
|
||||
{ no: number; date: string | Date | null; amount: number }[]
|
||||
>('paySplit', { required: true });
|
||||
const paySplit = defineModel<{ no: number; amount: number }[]>('paySplit', {
|
||||
required: true,
|
||||
});
|
||||
const summaryPrice = defineModel<{
|
||||
totalPrice: number;
|
||||
totalDiscount: number;
|
||||
|
|
@ -82,14 +82,6 @@ const payTypeOpion = computed(() => [
|
|||
value: 'Split',
|
||||
label: t('quotation.type.installmentsCash'),
|
||||
},
|
||||
// {
|
||||
// value: 'BillFull',
|
||||
// label: t('quotation.type.fullAmountBill'),
|
||||
// },
|
||||
// {
|
||||
// value: 'BillSplit',
|
||||
// label: t('quotation.type.installmentsBill'),
|
||||
// },
|
||||
]);
|
||||
const amount4Show = ref<string[]>([]);
|
||||
|
||||
|
|
@ -117,7 +109,6 @@ function calculateInstallments(param: {
|
|||
for (let i = param.oldCount; i < param.newCount; i++) {
|
||||
paySplit.value.push({
|
||||
no: i + 1,
|
||||
date: null,
|
||||
amount: installmentAmount,
|
||||
});
|
||||
amount4Show.value.push(installmentAmount.toString());
|
||||
|
|
@ -157,28 +148,6 @@ function calculateInstallments(param: {
|
|||
}
|
||||
}
|
||||
|
||||
function installmentsDate(date: Date | string) {
|
||||
const firstPayDateObj = new Date(date);
|
||||
|
||||
paySplit.value = paySplit.value.map((pay, index) => {
|
||||
if (index === 0) {
|
||||
return pay;
|
||||
}
|
||||
|
||||
let updatedDate = new Date(firstPayDateObj);
|
||||
updatedDate.setMonth(updatedDate.getMonth() + index);
|
||||
|
||||
if (updatedDate.getDate() !== firstPayDateObj.getDate()) {
|
||||
updatedDate.setDate(0);
|
||||
}
|
||||
|
||||
return {
|
||||
...pay,
|
||||
date: updatedDate.toISOString(),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
watch(
|
||||
() => payType.value,
|
||||
(v) => {
|
||||
|
|
@ -202,23 +171,9 @@ watch(
|
|||
)
|
||||
return;
|
||||
calculateInstallments({ newCount: newCount || 0, oldCount: oldCount || 0 });
|
||||
if (paySplit.value.length > 0 && !paySplit.value[0].date)
|
||||
paySplit.value[0].date = new Date();
|
||||
if (newCount !== oldCount) {
|
||||
paySplit.value[0].date && installmentsDate(paySplit.value[0].date);
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
watch(
|
||||
() => paySplit.value[0]?.date,
|
||||
(firstPayDate, beforeDate) => {
|
||||
if (firstPayDate && firstPayDate !== beforeDate) {
|
||||
installmentsDate(firstPayDate);
|
||||
}
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -332,12 +287,6 @@ watch(
|
|||
<q-icon name="mdi-cash" color="primary" />
|
||||
</template>
|
||||
</q-input>
|
||||
<DatePicker
|
||||
:readonly
|
||||
v-model="period.date"
|
||||
class="col-5"
|
||||
:label="$t('quotation.payDueDate')"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -201,7 +201,8 @@ export type Quotation = {
|
|||
payBillDate: string | Date;
|
||||
paySplitCount: number;
|
||||
paySplit: {
|
||||
date: string | Date;
|
||||
no: number;
|
||||
invoice: boolean;
|
||||
amount: number;
|
||||
}[];
|
||||
payCondition: 'Full' | 'Split' | 'BillFull' | 'BillSplit';
|
||||
|
|
@ -277,7 +278,7 @@ export type QuotationFull = {
|
|||
urgent: boolean;
|
||||
payBillDate: string | Date | null;
|
||||
paySplitCount: number | null;
|
||||
paySplit: { no: number; date: string | Date; amount: number }[];
|
||||
paySplit: { no: number; amount: number }[];
|
||||
payCondition: 'Full' | 'Split' | 'BillFull' | 'BillSplit';
|
||||
date: string | Date;
|
||||
dueDate: string | Date;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue