diff --git a/src/stores/utils/index.ts b/src/stores/utils/index.ts index 98d1ab2d..22146493 100644 --- a/src/stores/utils/index.ts +++ b/src/stores/utils/index.ts @@ -14,6 +14,9 @@ import { getRole } from 'src/services/keycloak'; import GlobalDialog from 'components/GlobalDialog.vue'; import DialogDuplicateData from 'components/DialogDuplicateData.vue'; +import useOptionStore from '../options'; +import { CustomerBranch } from '../customer/types'; +import { CustomerBranchRelation } from '../quotations'; export const baseUrl = import.meta.env.VITE_API_BASE_URL; @@ -53,6 +56,7 @@ export function dialogWarningClose( t: ComposerTranslation, opts: { message?: string; + actionText?: string; action?: (...args: unknown[]) => unknown; cancel?: (...args: unknown[]) => unknown; }, @@ -61,7 +65,7 @@ export function dialogWarningClose( color: 'warning', icon: 'mdi-alert', title: t('form.warning.title'), - actionText: t('dialog.action.close'), + actionText: opts.actionText || t('dialog.action.close'), message: opts.message || t('dialog.message.warningClose'), action: async () => { if (opts.action) opts.action(); @@ -542,3 +546,28 @@ export function changeMode(mode: string) { export function capitalizeFirstLetter(val: string) { return String(val).charAt(0).toUpperCase() + String(val).slice(1); } + +export function getCustomerName( + record: CustomerBranch | CustomerBranchRelation, + opts?: { + locale?: string; + noCode?: boolean; + }, +) { + const customer = record; + + return ( + { + ['CORP']: { + ['eng']: customer.registerNameEN, + ['tha']: customer.registerName, + }[opts?.locale || 'eng'], + ['PERS']: + { + ['eng']: `${useOptionStore().mapOption(customer?.namePrefix || '')} ${customer?.firstNameEN} ${customer?.lastNameEN}`, + ['tha']: `${useOptionStore().mapOption(customer?.namePrefix || '')} ${customer?.firstName} ${customer?.lastName}`, + }[opts?.locale || 'eng'] || '-', + }[customer.customer.customerType] + + (opts?.noCode ? '' : ' ' + `(${customer.code})`) + ); +}