{
payBillDate: data.payBillDate ? new Date(data.payBillDate) : undefined,
paySplit: data.paySplit.map((p, index) => ({
no: index + 1,
- invoice: p.invoice,
+ invoiceId: p.invoiceId,
amount: p.amount,
})),
worker: data.worker.map((v) =>
diff --git a/src/stores/payment/types.ts b/src/stores/payment/types.ts
index 549bb904..c5c68d7e 100644
--- a/src/stores/payment/types.ts
+++ b/src/stores/payment/types.ts
@@ -6,7 +6,7 @@ export type Invoice = {
amount: number;
- productServiceList: QuotationFull['productServiceList'];
+ installements: QuotationFull['paySplit'];
quotation: Quotation;
@@ -18,8 +18,6 @@ export type Invoice = {
export type InvoicePayload = {
quotationId: string;
amount: number;
- // NOTE: For individual list that will be include in the quotation
- productServiceListId?: string[];
// NOTE: Will be pulled from quotation
installmentNo?: number[];
};
diff --git a/src/stores/quotations/index.ts b/src/stores/quotations/index.ts
index 56d91b0a..0de9adcf 100644
--- a/src/stores/quotations/index.ts
+++ b/src/stores/quotations/index.ts
@@ -72,6 +72,9 @@ export const useQuotationStore = defineStore('quotation-store', () => {
const res = await api.post('/quotation', {
...payload,
+ paySplit: data.paySplit.map((v) => ({
+ amount: v.amount,
+ })),
productServiceList: data.productServiceList.map((v) => ({
vat: v.vat,
amount: v.amount,
@@ -104,6 +107,9 @@ export const useQuotationStore = defineStore('quotation-store', () => {
const { _count, ...payload } = data;
const res = await api.put(`/quotation/${data.id}`, {
...payload,
+ paySplit: data.paySplit.map((v) => ({
+ amount: v.amount,
+ })),
productServiceList: payload.productServiceList.map((v) => ({
vat: v.vat,
amount: v.amount,
diff --git a/src/stores/quotations/types.ts b/src/stores/quotations/types.ts
index c71975c8..cf843a13 100644
--- a/src/stores/quotations/types.ts
+++ b/src/stores/quotations/types.ts
@@ -1,6 +1,7 @@
import { CustomerType } from '../customer/types';
import { District, Province, SubDistrict } from '../address';
import { CreatedBy, Status, UpdatedBy } from '../types';
+import { Invoice } from '../payment/types';
export type QuotationStatus =
| 'Issued'
@@ -204,7 +205,7 @@ export type Quotation = {
paySplitCount: number;
paySplit: {
no: number;
- invoice: boolean;
+ invoiceId: string;
amount: number;
}[];
payCondition:
@@ -286,7 +287,12 @@ export type QuotationFull = {
urgent: boolean;
payBillDate: string | Date | null;
paySplitCount: number | null;
- paySplit: { no: number; amount: number; invoice: boolean }[];
+ paySplit: {
+ no: number;
+ amount: number;
+ invoice: Invoice;
+ invoiceId: string;
+ }[];
payCondition:
| 'Full'
| 'Split'
@@ -397,6 +403,8 @@ export type ProductGroup = {
};
export type QuotationPaymentData = {
+ invoiceId: string;
+ createdAt: Date;
paymentStatus: string;
amount: number;
remark: string;
diff --git a/src/utils/datetime.ts b/src/utils/datetime.ts
index 038a3043..ce0cb6e1 100644
--- a/src/utils/datetime.ts
+++ b/src/utils/datetime.ts
@@ -9,11 +9,52 @@ export function setLocale(locale: string) {
moment.locale(locale);
}
+export function dateFormatJS(opts: {
+ date: string | Date | null;
+ locale?: string;
+ dayStyle?: 'numeric' | '2-digit';
+ monthStyle?: 'numeric' | '2-digit' | 'long' | 'short';
+ timeStyle?: 'full' | 'long' | 'medium' | 'short';
+}) {
+ const dateObject = opts.date ? new Date(opts.date) : new Date();
+
+ const dateFormat = new Date(
+ Date.UTC(
+ dateObject.getUTCFullYear(),
+ dateObject.getUTCMonth(),
+ dateObject.getUTCDate(),
+ dateObject.getUTCHours(),
+ dateObject.getUTCMinutes(),
+ dateObject.getUTCSeconds(),
+ ),
+ );
+
+ let formattedDate = new Intl.DateTimeFormat(opts.locale || 'en-US', {
+ day: opts.dayStyle,
+ month: opts.monthStyle,
+ timeStyle: opts.timeStyle,
+ year: 'numeric',
+ }).format(dateFormat);
+
+ if (opts.locale === 'th-Th') {
+ formattedDate = formattedDate.replace(/(\d{4})/, (year) =>
+ (parseInt(year) - 543).toString(),
+ );
+ }
+
+ return formattedDate;
+}
+
+/**
+ * @deprecated Please use dateFormatJS.
+ */
+
export function dateFormat(
date?: string | Date | null,
fullmonth = false,
time = false,
number = false,
+ days = false,
) {
const m = moment(date);
@@ -27,7 +68,7 @@ export function dateFormat(
const monthFormat = fullmonth ? 'MMMM' : 'MMM';
const formattedDate = m.format(
- `DD ${monthFormat} YYYY ${time ? ' HH:mm' : ''}`,
+ ` ${days ? '' : 'DD'} ${monthFormat} YYYY ${time ? ' HH:mm' : ''}`,
);
return formattedDate;