feat: show quotation / invoice code on enter

This commit is contained in:
Methapon Metanipat 2024-11-07 15:32:57 +07:00
parent 850782a44d
commit f41fc7656c
2 changed files with 32 additions and 10 deletions

View file

@ -22,7 +22,7 @@ import {
dialog, dialog,
} from 'src/stores/utils'; } from 'src/stores/utils';
import { useReceipt } from 'stores/payment'; import { useInvoice, useReceipt } from 'stores/payment';
import useCustomerStore from 'stores/customer'; import useCustomerStore from 'stores/customer';
import useOptionStore from 'stores/options'; import useOptionStore from 'stores/options';
import { useQuotationForm } from './form'; import { useQuotationForm } from './form';
@ -104,6 +104,7 @@ const employeeFormStore = useEmployeeForm();
const customerStore = useCustomerStore(); const customerStore = useCustomerStore();
const quotationForm = useQuotationForm(); const quotationForm = useQuotationForm();
const quotationStore = useQuotationStore(); const quotationStore = useQuotationStore();
const invoiceStore = useInvoice();
const optionStore = useOptionStore(); const optionStore = useOptionStore();
const { t, locale } = useI18n(); const { t, locale } = useI18n();
const ocrStore = useOcrStore(); const ocrStore = useOcrStore();
@ -291,13 +292,13 @@ async function fetchStatus() {
title: 'Issued', title: 'Issued',
status: getStatus(quotationFormData.value.quotationStatus, 0, -1), status: getStatus(quotationFormData.value.quotationStatus, 0, -1),
active: () => view.value === View.Quotation, active: () => view.value === View.Quotation,
handler: () => (view.value = View.Quotation), handler: () => ((view.value = View.Quotation), (code.value = '')),
}, },
{ {
title: 'Accepted', title: 'Accepted',
status: getStatus(quotationFormData.value.quotationStatus, 1, 0), status: getStatus(quotationFormData.value.quotationStatus, 1, 0),
active: () => view.value === View.Accepted, active: () => view.value === View.Accepted,
handler: () => (view.value = View.Accepted), handler: () => ((view.value = View.Accepted), (code.value = '')),
}, },
{ {
title: 'Invoice', title: 'Invoice',
@ -313,6 +314,13 @@ async function fetchStatus() {
quotationFormData.value.payCondition === 'BillFull' quotationFormData.value.payCondition === 'BillFull'
? View.Invoice ? View.Invoice
: View.InvoicePre; : View.InvoicePre;
if (
quotationFormData.value.payCondition === 'Full' ||
quotationFormData.value.payCondition === 'BillFull'
) {
getInvoiceCodeFullPay();
}
}, },
}, },
{ {
@ -335,6 +343,7 @@ async function fetchStatus() {
handler: () => { handler: () => {
fetchReceipt(); fetchReceipt();
view.value = View.Receipt; view.value = View.Receipt;
code.value = '';
}, },
}, },
{ {
@ -1034,6 +1043,18 @@ enum View {
} }
const view = ref<View>(View.Quotation); const view = ref<View>(View.Quotation);
const code = ref<string>('');
async function getInvoiceCode(invoiceId: string) {
const ret = await invoiceStore.getInvoice(invoiceId);
if (ret) code.value = ret.code;
}
async function getInvoiceCodeFullPay() {
const ret = await invoiceStore.getInvoiceList();
if (ret) code.value = ret.result.at(0)?.code || '';
}
</script> </script>
<template> <template>
@ -1050,12 +1071,8 @@ const view = ref<View>(View.Quotation);
<q-img src="/icons/favicon-512x512.png" width="3rem" /> <q-img src="/icons/favicon-512x512.png" width="3rem" />
</a> </a>
<span class="column text-h6 text-bold q-ml-md"> <span class="column text-h6 text-bold q-ml-md">
{{ $t('quotation.title') }}
{{ {{ code || quotationFormState.source?.code || '' }}
$t(
`quotation.status.${view === View.InvoicePre || view === View.Invoice ? 'Invoice' : view === View.Payment ? 'PaymentInProcess' : view === View.Receipt ? 'Receipt' : 'Issued'}`,
)
}}
<span class="text-caption text-regular app-text-muted"> <span class="text-caption text-regular app-text-muted">
{{ {{
$t('quotation.processOn', { $t('quotation.processOn', {
@ -1578,9 +1595,11 @@ const view = ref<View>(View.Quotation);
:class="{ 'cursor-pointer': props.row.invoiceId }" :class="{ 'cursor-pointer': props.row.invoiceId }"
:props="props" :props="props"
@click=" @click="
() => { async () => {
if (props.row.invoiceId) { if (props.row.invoiceId) {
// TODO: get invoice code // TODO: get invoice code
await getInvoiceCode(props.row.invoiceId);
selectedInstallmentNo = selectedInstallmentNo =
quotationFormState.source?.paySplit quotationFormState.source?.paySplit
.filter( .filter(

View file

@ -4,6 +4,8 @@ import { CreatedBy } from '../types';
export type Invoice = { export type Invoice = {
id: string; id: string;
code: string;
amount: number; amount: number;
installements: QuotationFull['paySplit']; installements: QuotationFull['paySplit'];
@ -23,6 +25,7 @@ export type InvoicePayload = {
}; };
export type Payment = { export type Payment = {
code?: string;
paymentStatus: string; paymentStatus: string;
date: Date; date: Date;
amount: number; amount: number;