feat: add installments validate

This commit is contained in:
Methapon2001 2024-12-20 09:40:16 +07:00
parent 85e27613e8
commit 1e660682a6
6 changed files with 35 additions and 31 deletions

View file

@ -23,6 +23,7 @@ const props = defineProps<{
readonly?: boolean; readonly?: boolean;
separator?: boolean; separator?: boolean;
treeView?: boolean; treeView?: boolean;
installments?: number;
priceDisplay?: { priceDisplay?: {
price: boolean; price: boolean;
@ -188,9 +189,10 @@ watch(
:key="work.id" :key="work.id"
:index="index" :index="index"
:length="workItems.length" :length="workItems.length"
:workIndex="index" :work-index="index"
:readonly="readonly" :readonly
:priceDisplay="priceDisplay" :price-display
:installments
v-model:work-name="workItems[index].name" v-model:work-name="workItems[index].name"
v-model:product-items="work.product" v-model:product-items="work.product"
v-model:attributes="work.attributes" v-model:attributes="work.attributes"

View file

@ -18,7 +18,7 @@ const optionStore = useOptionStore();
const workflowStore = useWorkflowTemplate(); const workflowStore = useWorkflowTemplate();
const { fetchListOfWork } = productServiceStore; const { fetchListOfWork } = productServiceStore;
const { splitPay, workNameItems } = storeToRefs(productServiceStore); const { workNameItems } = storeToRefs(productServiceStore);
const { data: workflowData } = storeToRefs(workflowStore); const { data: workflowData } = storeToRefs(workflowStore);
@ -28,6 +28,7 @@ const props = withDefaults(
length: number; length: number;
index: number; index: number;
readonly?: boolean; readonly?: boolean;
installments?: number;
priceDisplay?: { priceDisplay?: {
price: boolean; price: boolean;
@ -445,7 +446,7 @@ watch(
<q-input <q-input
v-if="!readonly && $q.screen.gt.xs" v-if="!readonly && $q.screen.gt.xs"
outlined outlined
:max="splitPay" :max="installments"
input-class="text-right no-padding" input-class="text-right no-padding"
for="input-bankbook" for="input-bankbook"
hide-bottom-space hide-bottom-space
@ -454,12 +455,6 @@ watch(
type="number" type="number"
v-model="product.installmentNo" v-model="product.installmentNo"
min="0" min="0"
@update:model-value="
(v) => {
if (Number(v) > splitPay)
product.installmentNo = splitPay;
}
"
/> />
</span> </span>
</span> </span>

View file

@ -1026,6 +1026,8 @@ export default {
'An error has occurred, causing the system to be unable to function. Please try again later.', 'An error has occurred, causing the system to be unable to function. Please try again later.',
invalideData: 'The information is incorrect. Please try again later.', invalideData: 'The information is incorrect. Please try again later.',
authFailed: 'Authentication Failed. Please try again later. ', authFailed: 'Authentication Failed. Please try again later. ',
installmentsValidateFailed:
'Validation failed. Each installment must include at least one product. Please review and update the installments accordingly.',
}, },
}, },

View file

@ -1012,6 +1012,8 @@ export default {
'เกิดข้อผิดพลาดทำให้ระบบไม่สามารถทำงานได้ กรุณาลองใหม่ในภายหลัง', 'เกิดข้อผิดพลาดทำให้ระบบไม่สามารถทำงานได้ กรุณาลองใหม่ในภายหลัง',
invalideData: 'ข้อมูลไม่ถูกต้อง กรุณาตรวจสอบใหม่อีกครั้ง', invalideData: 'ข้อมูลไม่ถูกต้อง กรุณาตรวจสอบใหม่อีกครั้ง',
authFailed: 'การยืนยันตัวตนล้มเหลว กรุณาลองใหม่ในภายหลัง', authFailed: 'การยืนยันตัวตนล้มเหลว กรุณาลองใหม่ในภายหลัง',
installmentsValidateFailed:
'ข้อมูลงวดไม่ถูกต้อง กรุณาตรวจสอบและยืนยันว่าแต่ละงวดมีสินค้าอย่างน้อยหนึ่งรายการ',
}, },
}, },

View file

@ -97,7 +97,7 @@ const {
deleteWork, deleteWork,
} = productServiceStore; } = productServiceStore;
const { workNameItems, splitPay } = storeToRefs(productServiceStore); const { workNameItems } = storeToRefs(productServiceStore);
const allStat = ref<{ mode: string; count: number }[]>([]); const allStat = ref<{ mode: string; count: number }[]>([]);
const stat = ref< const stat = ref<
{ {
@ -916,7 +916,7 @@ const prevService = ref<ServiceCreate>({
const currentService = ref<ServiceById>(); const currentService = ref<ServiceById>();
async function assignFormDataProductService(id: string) { async function assignFormService(id: string) {
const res = await fetchListServiceById(id); const res = await fetchListServiceById(id);
if (res) { if (res) {
@ -942,6 +942,7 @@ async function assignFormDataProductService(id: string) {
status: res.status, status: res.status,
productGroupId: res.productGroupId, productGroupId: res.productGroupId,
selectedImage: res.selectedImage, selectedImage: res.selectedImage,
installments: res.installments,
}; };
formService.value = { ...prevService.value }; formService.value = { ...prevService.value };
@ -962,13 +963,6 @@ async function assignFormDataProductService(id: string) {
formService.value.work = prevService.value.work; formService.value.work = prevService.value.work;
workItems.value = res.work.map((item) => { workItems.value = res.work.map((item) => {
const maxInstallmentsNo = item.productOnWork.map(
(productOnWorkItem) => productOnWorkItem.installmentNo || 0,
);
if (splitPay.value < Math.max(...maxInstallmentsNo))
splitPay.value = Math.max(...maxInstallmentsNo);
return { return {
id: item.id, id: item.id,
name: item.name, name: item.name,
@ -1085,7 +1079,6 @@ function clearFormService() {
productGroupId: '', productGroupId: '',
}; };
tempWorkItems.value = []; tempWorkItems.value = [];
splitPay.value = 0;
workItems.value = []; workItems.value = [];
selectProduct.value = []; selectProduct.value = [];
dialogService.value = false; dialogService.value = false;
@ -1151,16 +1144,19 @@ async function submitService(notClose = false) {
if (res) { if (res) {
allStat.value[1].count = allStat.value[1].count + 1; allStat.value[1].count = allStat.value[1].count + 1;
stat.value[1].count = stat.value[1].count + 1; stat.value[1].count = stat.value[1].count + 1;
} else {
return;
} }
totalService.value = totalService.value + 1; totalService.value = totalService.value + 1;
productAndServiceTab.value = 'service'; productAndServiceTab.value = 'service';
} }
if (dialogServiceEdit.value) { if (dialogServiceEdit.value) {
await editService(currentIdService.value, { const res = await editService(currentIdService.value, {
...formService.value, ...formService.value,
status: statusToggle.value ? formService.value.status : 'INACTIVE', status: statusToggle.value ? formService.value.status : 'INACTIVE',
}); });
if (!res) return;
} }
if (!notClose) clearFormService(); if (!notClose) clearFormService();
@ -1191,17 +1187,21 @@ async function submitProduct(notClose = false) {
if (res) { if (res) {
allStat.value[2].count = allStat.value[2].count + 1; allStat.value[2].count = allStat.value[2].count + 1;
stat.value[2].count = stat.value[2].count + 1; stat.value[2].count = stat.value[2].count + 1;
} else {
return;
} }
productAndServiceTab.value = 'product'; productAndServiceTab.value = 'product';
} }
if (dialogProductEdit.value) { if (dialogProductEdit.value) {
await editProduct(currentIdProduct.value, { const res = await editProduct(currentIdProduct.value, {
...formProduct.value, ...formProduct.value,
status: statusToggle.value ? 'ACTIVE' : 'INACTIVE', status: statusToggle.value ? 'ACTIVE' : 'INACTIVE',
document: formProductDocument.value, document: formProductDocument.value,
}); });
if (!res) return;
} }
totalProduct.value = totalProduct.value + 1; totalProduct.value = totalProduct.value + 1;
if (!notClose) clearFormProduct(); if (!notClose) clearFormProduct();
@ -1246,7 +1246,7 @@ function submitAddWorkProduct() {
if (!productExists) { if (!productExists) {
workItems.value[currentWorkIndex.value].product.push({ workItems.value[currentWorkIndex.value].product.push({
...i, ...i,
installmentNo: splitPay.value > 0 ? 1 : 0, installmentNo: !!formService.value.installments ? 1 : 0,
nameEn: '', nameEn: '',
}); });
workItems.value[currentWorkIndex.value].attributes.workflowStep.forEach( workItems.value[currentWorkIndex.value].attributes.workflowStep.forEach(
@ -2896,7 +2896,7 @@ watch(
if (props.row.type === 'service') { if (props.row.type === 'service') {
currentIdService = props.row.id; currentIdService = props.row.id;
infoServiceEdit = false; infoServiceEdit = false;
assignFormDataProductService(props.row.id); assignFormService(props.row.id);
dialogServiceEdit = true; dialogServiceEdit = true;
} }
} }
@ -2915,7 +2915,7 @@ watch(
if (props.row.type === 'service') { if (props.row.type === 'service') {
currentIdService = props.row.id; currentIdService = props.row.id;
infoServiceEdit = false; infoServiceEdit = false;
assignFormDataProductService(props.row.id); assignFormService(props.row.id);
dialogServiceEdit = true; dialogServiceEdit = true;
} }
} }
@ -2931,7 +2931,7 @@ watch(
if (props.row.type === 'service') { if (props.row.type === 'service') {
currentIdService = props.row.id; currentIdService = props.row.id;
infoServiceEdit = true; infoServiceEdit = true;
assignFormDataProductService(props.row.id); assignFormService(props.row.id);
dialogServiceEdit = true; dialogServiceEdit = true;
} }
} }
@ -2986,7 +2986,7 @@ watch(
if (row.type === 'service') { if (row.type === 'service') {
currentIdService = row.id; currentIdService = row.id;
infoServiceEdit = false; infoServiceEdit = false;
assignFormDataProductService(row.id); assignFormService(row.id);
dialogServiceEdit = true; dialogServiceEdit = true;
} }
} }
@ -3002,7 +3002,7 @@ watch(
if (row.type === 'service') { if (row.type === 'service') {
currentIdService = row.id; currentIdService = row.id;
infoServiceEdit = true; infoServiceEdit = true;
assignFormDataProductService(row.id); assignFormService(row.id);
dialogServiceEdit = true; dialogServiceEdit = true;
} }
} }
@ -4082,7 +4082,7 @@ watch(
class="split-pay q-mx-sm" class="split-pay q-mx-sm"
input-class="text-caption text-right" input-class="text-caption text-right"
type="number" type="number"
v-model="splitPay" v-model="formService.installments"
/> />
{{ $t('quotation.receiptDialog.installments') }} {{ $t('quotation.receiptDialog.installments') }}
</span> </span>
@ -4158,6 +4158,7 @@ watch(
v-model:workflow="currWorkflow" v-model:workflow="currWorkflow"
:tree-view="serviceTreeView" :tree-view="serviceTreeView"
:service="formService" :service="formService"
:installments="formService.installments"
dense dense
@add-product=" @add-product="
async (index) => { async (index) => {
@ -4513,7 +4514,7 @@ watch(
class="split-pay q-mx-sm" class="split-pay q-mx-sm"
input-class="text-caption text-right" input-class="text-caption text-right"
type="number" type="number"
v-model="splitPay" v-model="formService.installments"
/> />
{{ $t('quotation.receiptDialog.installments') }} {{ $t('quotation.receiptDialog.installments') }}
</span> </span>
@ -4547,6 +4548,7 @@ watch(
:service="formService" :service="formService"
:tree-view="serviceTreeView" :tree-view="serviceTreeView"
:readonly="!infoServiceEdit" :readonly="!infoServiceEdit"
:installments="formService.installments"
:price-display="priceDisplay" :price-display="priceDisplay"
dense dense
@add-product=" @add-product="

View file

@ -124,6 +124,7 @@ export interface ServiceById {
productGroupId: string; productGroupId: string;
selectedImage: string; selectedImage: string;
registeredBranchId: string; registeredBranchId: string;
installments: number;
} }
export interface ProductOnWork { export interface ProductOnWork {