hotfix-add subgroup customer
This commit is contained in:
@@ -7,6 +7,11 @@ import {
|
||||
} from '@/db/schema';
|
||||
import { db } from '@/lib/db';
|
||||
import { AuthError } from '@/lib/auth/session';
|
||||
import {
|
||||
formatPdfCurrency,
|
||||
formatPdfDate,
|
||||
normalizePdfmeTable
|
||||
} from '@/features/crm/quotations/document/server/pdfme-transforms';
|
||||
import type {
|
||||
DocumentTemplateDetail,
|
||||
DocumentTemplateFilters,
|
||||
@@ -682,12 +687,18 @@ function applyFormatMask(value: unknown, formatMask?: string | null) {
|
||||
return value;
|
||||
}
|
||||
|
||||
if (formatMask === 'currency' && typeof value === 'number') {
|
||||
return value.toLocaleString();
|
||||
if (formatMask === 'currency' || formatMask?.startsWith('currency_')) {
|
||||
const currencyCode =
|
||||
formatMask === 'currency' ? 'THB' : formatMask.replace('currency_', '');
|
||||
return formatPdfCurrency(value as number | string, currencyCode);
|
||||
}
|
||||
|
||||
if (formatMask === 'date' && typeof value === 'string') {
|
||||
return new Date(value).toLocaleDateString();
|
||||
if (formatMask === 'date' || formatMask === 'date_en') {
|
||||
return formatPdfDate(value as string, 'en');
|
||||
}
|
||||
|
||||
if (formatMask === 'date_th') {
|
||||
return formatPdfDate(value as string, 'th');
|
||||
}
|
||||
|
||||
return value;
|
||||
@@ -704,16 +715,32 @@ export function mapDocumentDataToTemplateInput(
|
||||
|
||||
if (mapping.dataType === 'table') {
|
||||
const rows = Array.isArray(rawValue) ? rawValue : [];
|
||||
result[mapping.placeholderKey] = rows.map((row) => {
|
||||
const rowRecord = row as Record<string, unknown>;
|
||||
return mapping.columns.reduce<Record<string, unknown>>((accumulator, column) => {
|
||||
accumulator[column.columnName] = applyFormatMask(
|
||||
rowRecord[column.sourceField],
|
||||
column.formatMask
|
||||
);
|
||||
return accumulator;
|
||||
}, {});
|
||||
});
|
||||
|
||||
if (rows.length === 0) {
|
||||
result[mapping.placeholderKey] = normalizePdfmeTable([]);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (rows.every((row) => Array.isArray(row))) {
|
||||
result[mapping.placeholderKey] = normalizePdfmeTable(rows);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mapping.columns.length) {
|
||||
const normalizedRows = rows.map((row) => {
|
||||
const rowRecord = row as Record<string, unknown>;
|
||||
|
||||
return mapping.columns.map((column) => {
|
||||
const formattedValue = applyFormatMask(rowRecord[column.sourceField], column.formatMask);
|
||||
return String(formattedValue ?? '-').trim() || '-';
|
||||
});
|
||||
});
|
||||
|
||||
result[mapping.placeholderKey] = normalizePdfmeTable(normalizedRows);
|
||||
continue;
|
||||
}
|
||||
|
||||
result[mapping.placeholderKey] = normalizePdfmeTable(rows);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -743,7 +770,7 @@ export function mapDocumentDataToTemplateInput(
|
||||
}
|
||||
|
||||
result[mapping.placeholderKey] =
|
||||
applyFormatMask(rawValue, mapping.formatMask) ?? mapping.defaultValue ?? '';
|
||||
applyFormatMask(rawValue, mapping.formatMask) ?? mapping.defaultValue ?? '-';
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user