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 selectedProductGroup = ref('');
|
||||||
const selectedInstallmentNo = ref<number[]>([]);
|
const selectedInstallmentNo = ref<number[]>([]);
|
||||||
const agentPrice = ref(false);
|
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) => {
|
(a, c) => {
|
||||||
if (
|
if (
|
||||||
selectedInstallmentNo.value.length > 0 &&
|
selectedInstallmentNo.value.length > 0 &&
|
||||||
|
|
@ -172,8 +178,10 @@ const summaryPrice = computed(() =>
|
||||||
vatExcluded: 0,
|
vatExcluded: 0,
|
||||||
finalPrice: 0,
|
finalPrice: 0,
|
||||||
},
|
},
|
||||||
),
|
);
|
||||||
);
|
}
|
||||||
|
|
||||||
|
const summaryPrice = computed(() => getPrice(productServiceList.value));
|
||||||
|
|
||||||
const payBank = ref('');
|
const payBank = ref('');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,9 @@ const payType = defineModel<'Full' | 'Split' | 'BillFull' | 'BillSplit'>(
|
||||||
const paySplitCount = defineModel<number | null>('paySplitCount', {
|
const paySplitCount = defineModel<number | null>('paySplitCount', {
|
||||||
default: 1,
|
default: 1,
|
||||||
});
|
});
|
||||||
const paySplit = defineModel<
|
const paySplit = defineModel<{ no: number; amount: number }[]>('paySplit', {
|
||||||
{ no: number; date: string | Date | null; amount: number }[]
|
required: true,
|
||||||
>('paySplit', { required: true });
|
});
|
||||||
const summaryPrice = defineModel<{
|
const summaryPrice = defineModel<{
|
||||||
totalPrice: number;
|
totalPrice: number;
|
||||||
totalDiscount: number;
|
totalDiscount: number;
|
||||||
|
|
@ -82,14 +82,6 @@ const payTypeOpion = computed(() => [
|
||||||
value: 'Split',
|
value: 'Split',
|
||||||
label: t('quotation.type.installmentsCash'),
|
label: t('quotation.type.installmentsCash'),
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// value: 'BillFull',
|
|
||||||
// label: t('quotation.type.fullAmountBill'),
|
|
||||||
// },
|
|
||||||
// {
|
|
||||||
// value: 'BillSplit',
|
|
||||||
// label: t('quotation.type.installmentsBill'),
|
|
||||||
// },
|
|
||||||
]);
|
]);
|
||||||
const amount4Show = ref<string[]>([]);
|
const amount4Show = ref<string[]>([]);
|
||||||
|
|
||||||
|
|
@ -117,7 +109,6 @@ function calculateInstallments(param: {
|
||||||
for (let i = param.oldCount; i < param.newCount; i++) {
|
for (let i = param.oldCount; i < param.newCount; i++) {
|
||||||
paySplit.value.push({
|
paySplit.value.push({
|
||||||
no: i + 1,
|
no: i + 1,
|
||||||
date: null,
|
|
||||||
amount: installmentAmount,
|
amount: installmentAmount,
|
||||||
});
|
});
|
||||||
amount4Show.value.push(installmentAmount.toString());
|
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(
|
watch(
|
||||||
() => payType.value,
|
() => payType.value,
|
||||||
(v) => {
|
(v) => {
|
||||||
|
|
@ -202,23 +171,9 @@ watch(
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
calculateInstallments({ newCount: newCount || 0, oldCount: oldCount || 0 });
|
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 },
|
{ deep: true },
|
||||||
);
|
);
|
||||||
|
|
||||||
watch(
|
|
||||||
() => paySplit.value[0]?.date,
|
|
||||||
(firstPayDate, beforeDate) => {
|
|
||||||
if (firstPayDate && firstPayDate !== beforeDate) {
|
|
||||||
installmentsDate(firstPayDate);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
@ -332,12 +287,6 @@ watch(
|
||||||
<q-icon name="mdi-cash" color="primary" />
|
<q-icon name="mdi-cash" color="primary" />
|
||||||
</template>
|
</template>
|
||||||
</q-input>
|
</q-input>
|
||||||
<DatePicker
|
|
||||||
:readonly
|
|
||||||
v-model="period.date"
|
|
||||||
class="col-5"
|
|
||||||
:label="$t('quotation.payDueDate')"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
||||||
|
|
@ -201,7 +201,8 @@ export type Quotation = {
|
||||||
payBillDate: string | Date;
|
payBillDate: string | Date;
|
||||||
paySplitCount: number;
|
paySplitCount: number;
|
||||||
paySplit: {
|
paySplit: {
|
||||||
date: string | Date;
|
no: number;
|
||||||
|
invoice: boolean;
|
||||||
amount: number;
|
amount: number;
|
||||||
}[];
|
}[];
|
||||||
payCondition: 'Full' | 'Split' | 'BillFull' | 'BillSplit';
|
payCondition: 'Full' | 'Split' | 'BillFull' | 'BillSplit';
|
||||||
|
|
@ -277,7 +278,7 @@ export type QuotationFull = {
|
||||||
urgent: boolean;
|
urgent: boolean;
|
||||||
payBillDate: string | Date | null;
|
payBillDate: string | Date | null;
|
||||||
paySplitCount: number | null;
|
paySplitCount: number | null;
|
||||||
paySplit: { no: number; date: string | Date; amount: number }[];
|
paySplit: { no: number; amount: number }[];
|
||||||
payCondition: 'Full' | 'Split' | 'BillFull' | 'BillSplit';
|
payCondition: 'Full' | 'Split' | 'BillFull' | 'BillSplit';
|
||||||
date: string | Date;
|
date: string | Date;
|
||||||
dueDate: string | Date;
|
dueDate: string | Date;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue