Merge branch 'develop'

This commit is contained in:
Methapon2001 2025-01-23 16:07:38 +07:00
commit dc163e6e97
13 changed files with 273 additions and 109 deletions

View file

@ -57,7 +57,6 @@ const currentBtnOpen = ref<{ title: string; opened: boolean[] }[]>([
]);
function calcPrice(c: (typeof rows.value)[number]) {
console.log(c);
const originalPrice = c.pricePerUnit;
const finalPriceWithVat = precisionRound(
originalPrice + originalPrice * (config.value?.vat || 0.07),

View file

@ -71,7 +71,7 @@ watch(
(newValue) => {
if (newValue !== undefined && typeof newValue === 'string') {
const numericValue = newValue.replace(/,/g, '');
wageRateText.value = ThaiBahtText(numericValue);
wageRateText.value = ThaiBahtText(numericValue) || 'ศูนย์บาทถ้วน';
wageRate.value = parseFloat(numericValue);
}
},

View file

@ -704,18 +704,22 @@ function handleUpdateProductTable(
newInstallmentNo: number;
},
) {
handleChangePayType(quotationFormData.value.payCondition);
// calc price
const calc = (c: QuotationPayload['productServiceList'][number]) => {
const pricePerUnit = c.pricePerUnit || 0;
const discount = c.discount || 0;
return (
pricePerUnit * c.amount -
discount +
(c.product.calcVat
? (pricePerUnit * c.amount - discount) * (config.value?.vat || 0.07)
: 0)
const originalPrice = c.pricePerUnit || 0;
const finalPriceWithVat = precisionRound(
originalPrice * (1 + (config.value?.vat || 0.07)),
);
const finalPriceNoVat =
finalPriceWithVat / (1 + (config.value?.vat || 0.07));
const price = finalPriceNoVat * c.amount;
const vat = c.product.calcVat
? (finalPriceNoVat * c.amount - (c.discount || 0)) *
(config.value?.vat || 0.07)
: 0;
return precisionRound(price + vat);
};
// installment
@ -2057,23 +2061,20 @@ watch(
<div class="surface-1 q-pa-md flex" style="gap: var(--size-2)">
<SelectInput
style="max-width: 250px"
class="q-mr-xl"
incremental
class="q-mr-sm"
v-model="templateForm"
id="quotation-branch"
:option="templateFormOption"
:label="$t('quotation.templateForm')"
:option-label="locale === 'eng' ? 'labelEN' : 'label'"
/>
<MainButton
<!-- <MainButton
outlined
icon="mdi-play-box-outline"
color="207 96% 32%"
@click="storeDataLocal"
>
{{ $t('general.view', { msg: $t('general.example') }) }}
</MainButton>
</MainButton> -->
<MainButton
solid
icon="mdi-pencil-outline"

View file

@ -448,7 +448,7 @@ function print() {
class="column set-width bg-color full-height"
style="padding: 12px"
>
({{ ThaiBahtText(summaryPrice.finalPrice) }})
({{ ThaiBahtText(summaryPrice.finalPrice) || 'ศูนย์บาทถ้วน' }})
</div>
<div
class="row text-right border-5 items-center"

View file

@ -93,7 +93,7 @@ async function triggerTaskOrder(opts: {
window.location.origin,
);
if (pageState.currentTab === 'Pending') {
if (pageState.currentTab === 'Pending' && opts.statusDialog === 'edit') {
url.searchParams.append('edit', String(opts.statusDialog === 'edit'));
}

View file

@ -22,6 +22,18 @@ const emit = defineEmits<{
}>();
const props = defineProps<{
taskListGroup?: {
product: RequestWork['productService']['product'];
list: (RequestWork & {
_template?: {
id: string;
templateName: string;
templateStepName: string;
step: number;
responsibleInstitution: (string | { group: string })[];
} | null;
})[];
}[];
creditNote?: boolean;
fetchParams?: Parameters<typeof requestListStore.getRequestWorkList>[0];
}>();
@ -39,6 +51,20 @@ const taskList = defineModel<
});
const open = defineModel<boolean>('open', { default: false });
const tempGroupEdit = defineModel<
{
product: RequestWork['productService']['product'];
list: (RequestWork & {
_template?: {
id: string;
templateName: string;
templateStepName: string;
step: number;
responsibleInstitution: (string | { group: string })[];
} | null;
})[];
}[]
>('tempGroupEdit', { default: [] });
const selectedEmployee = ref<
(RequestWork & {
taskStatus: TaskStatus;
@ -56,15 +82,28 @@ let group = computed(() =>
data.value.reduce<
{
product: RequestWork['productService']['product'];
list: RequestWork[];
list: (RequestWork & {
_template?: {
id: string;
templateName: string;
templateStepName: string;
step: number;
responsibleInstitution: (string | { group: string })[];
} | null;
})[];
}[]
>((acc, curr) => {
let exist = acc.find(
(item) => curr.productService.productId == item.product.id,
);
if (exist) exist.list.push(curr);
else acc.push({ product: curr.productService.product, list: [curr] });
if (exist) exist.list.push({ ...curr, _template: getTemplateData(curr) });
else
acc.push({
product: curr.productService.product,
// list: [curr],
list: [{ ...curr, _template: getTemplateData(curr) }],
});
return acc;
}, []),
@ -74,7 +113,12 @@ let state = reactive({
search: '',
});
onMounted(getList);
onMounted(async () => {
await getList();
if (tempGroupEdit.value.length === 0) {
tempGroupEdit.value = JSON.parse(JSON.stringify(group.value));
}
});
watch(() => state.search, getList);
async function getList() {
@ -90,35 +134,11 @@ async function getList() {
data.value = res.result;
}
// function toggle(item: RequestWork) {
// switch (selected(item)) {
// case true:
// return deselect(item);
// case false:
// return select(item);
// }
// }
// function select(item: RequestWork) {
// if (selected(item)) return;
// selectedEmployee.value = selectedEmployee.value
// ? selectedEmployee.value.concat(item)
// : [item];
// }
// function deselect(item: RequestWork) {
// const idx = selectedEmployee.value?.findIndex((v) => v.id === item.id);
// if (idx !== -1) selectedEmployee.value?.splice(idx, 1);
// }
// function selected(item: RequestWork): boolean {
// return !!selectedEmployee.value?.some((v) => v.id === item.id);
// }
//
function getStep(requestWork: RequestWork) {
const target = requestWork.stepStatus.find(
(v) => v.workStatus === RequestWorkStatus.Ready,
(v) =>
v.workStatus === RequestWorkStatus.Ready ||
v.workStatus === RequestWorkStatus.InProgress,
);
return target?.step || 0;
}
@ -135,6 +155,7 @@ function getTemplateData(requestWork: RequestWork) {
step: step.order,
templateName: flow.name,
templateStepName: step.name || '-',
responsibleInstitution: step.responsibleInstitution || [],
};
}
@ -149,17 +170,22 @@ function submit() {
const curr = v.stepStatus.find(
(s) =>
s.workStatus ===
(props.creditNote
? RequestWorkStatus.Canceled
: RequestWorkStatus.Ready),
(props.creditNote
? RequestWorkStatus.Canceled
: RequestWorkStatus.Ready) ||
s.workStatus ===
(props.creditNote
? RequestWorkStatus.Canceled
: RequestWorkStatus.InProgress),
);
if (curr) {
const task: Task = {
...curr,
attributes: curr.attributes,
workStatus: props.creditNote
? RequestWorkStatus.Canceled
: RequestWorkStatus.Ready,
workStatus:
curr.workStatus || props.creditNote
? RequestWorkStatus.Ready
: RequestWorkStatus.Canceled,
taskOrderId: '',
requestWork: selectedEmployee.value[i],
};
@ -183,9 +209,13 @@ function close() {
}
function onDialogOpen() {
// assign selected to group
!props.creditNote && assignTempGroup();
// match group to check
selectedEmployee.value = [];
if (taskList.value.length === 0) return;
const matchingItems = group.value
const matchingItems = tempGroupEdit.value
.flatMap((g) => g.list)
.filter((l) =>
l.stepStatus.some((s) =>
@ -194,6 +224,28 @@ function onDialogOpen() {
);
selectedEmployee.value = JSON.parse(JSON.stringify(matchingItems));
}
function assignTempGroup() {
if (!props.taskListGroup) return;
props.taskListGroup.forEach((newGroup) => {
const existingGroup = tempGroupEdit.value.find(
(g) => g.product.id === newGroup.product.id,
);
if (existingGroup) {
newGroup.list.forEach((newItem) => {
if (!existingGroup.list.some((item) => item.id === newItem.id)) {
existingGroup.list.push(newItem);
}
});
} else {
tempGroupEdit.value.push({
...newGroup,
list: [...newGroup.list], // Ensure a new reference
});
}
});
}
</script>
<template>
@ -205,9 +257,9 @@ function onDialogOpen() {
</template>
<section class="col column full-width no-wrap surface-2 scroll">
<template v-if="group.length > 0">
<template v-if="tempGroupEdit.length > 0">
<div
v-for="{ product, list } in group"
v-for="{ product, list } in tempGroupEdit"
:key="product.id"
class="bordered-b"
>

View file

@ -23,6 +23,7 @@ import {
import { useRoute } from 'vue-router';
import { useTaskOrderStore } from 'src/stores/task-order';
import { RequestWork } from 'src/stores/request-list';
import { convertTemplate } from 'src/utils/string-template';
const route = useRoute();
const taskOrder = useTaskOrderStore();
@ -105,6 +106,12 @@ function getHeight(el: HTMLElement) {
const STORAGE_KEY = 'task-order-preview';
const taskListGroup = ref<
{
product: RequestWork['productService']['product'];
list: (RequestWork & { _status: TaskStatus })[];
}[]
>([]);
onMounted(async () => {
if (route.params['id'] && typeof route.params['id'] === 'string') {
viewType.value = route.name as 'docOrder' | 'docReceive';
@ -132,7 +139,7 @@ onMounted(async () => {
branch.value = jsonObject.registeredBranch;
}
const taskListGroup = data.value?.taskList.reduce<
const _taskListGroup = data.value?.taskList.reduce<
{
product: RequestWork['productService']['product'];
list: (RequestWork & { _status: TaskStatus })[];
@ -172,14 +179,14 @@ onMounted(async () => {
}, []);
product.value = [];
summaryPrice.value = taskListGroup
taskListGroup.value = _taskListGroup;
summaryPrice.value = _taskListGroup
.flatMap((v) => {
const list = v.list.filter(
(item) => item._status === TaskStatus.Complete,
);
if (viewType.value === 'docReceive' && list.length === 0) {
return [];
}
const list =
(viewType.value === 'docReceive'
? v.list.filter((item) => item._status === TaskStatus.Complete)
: v.list) || [];
return {
product: v.product,
pricePerUnit: v.product.serviceCharge,
@ -374,7 +381,7 @@ function print() {
class="column set-width bg-color full-height"
style="padding: 12px"
>
({{ ThaiBahtText(summaryPrice.finalPrice) }})
({{ ThaiBahtText(summaryPrice.finalPrice) || 'ศูนย์บาทถ้วน' }})
</div>
<div
class="row text-right border-5 items-center"
@ -415,7 +422,34 @@ function print() {
}"
/>
<article style="height: 5.8in"></article>
<span
class="q-mb-sm q-mt-md"
style="
font-weight: 800;
font-size: 16px;
color: var(--main);
display: block;
border-bottom: 2px solid var(--main);
"
>
{{ $t('general.remark') }}
</span>
<div
class="border-5 surface-0 detail-note q-mb-md"
style="width: 100%; padding: 8px 16px; white-space: pre-wrap"
>
<div
v-html="
convertTemplate(data?.remark || '', {
'order-detail': {
items: taskListGroup,
itemsDiscount: data.taskProduct || [],
},
}) || '-'
"
></div>
</div>
<ViewFooter
:data="{

View file

@ -24,6 +24,7 @@ export const useTaskOrderForm = defineStore('task-order-form', () => {
contactTel: '',
contactName: '',
taskName: '',
remark: '#[order-detail]',
};
const state = ref<{
@ -103,7 +104,10 @@ export const useTaskOrderForm = defineStore('task-order-form', () => {
}
if (state.value.mode === 'edit' && !!currentFormData.value.id) {
const res = await taskOrderStore.editTaskOrder(currentFormData.value);
const res = await taskOrderStore.editTaskOrder({
...currentFormData.value,
taskProduct: opt?.taskProduct,
});
if (res) {
succeed = true;
}

View file

@ -20,6 +20,7 @@ import {
MainButton,
EditButton,
UndoButton,
CancelButton,
} from 'src/components/button';
import FormGroupHead from 'src/pages/08_request-list/FormGroupHead.vue';
import FailRemarkDialog from '../receive_view/FailRemarkDialog.vue';
@ -75,6 +76,20 @@ const taskStatusRecords = ref<
failedType?: string;
}[]
>([]);
const tempGroupEdit = ref<
{
product: RequestWork['productService']['product'];
list: (RequestWork & {
_template?: {
id: string;
templateName: string;
templateStepName: string;
step: number;
responsibleInstitution: (string | { group: string })[];
} | null;
})[];
}[]
>([]);
const pageState = reactive({
productDialog: false,
@ -856,7 +871,7 @@ watch([currentFormData.value.taskStatus], () => {
"
>
<DocumentExpansion
:readonly="state.mode !== 'create'"
:readonly="!['create', 'edit'].includes(state.mode || '')"
v-model:registered-branch-id="currentFormData.registeredBranchId"
v-model:institution-id="currentFormData.institutionId"
v-model:task-name="currentFormData.taskName"
@ -891,11 +906,11 @@ watch([currentFormData.value.taskStatus], () => {
/>
<AdditionalFileExpansion
:readonly="!['create', 'edit'].includes(state.mode || '')"
v-if="
view === TaskOrderStatus.Pending ||
view === TaskOrderStatus.Complete
"
:readonly="!['create', 'edit'].includes(state.mode || '')"
v-model:file-data="fileData"
:transform-url="
async (url: string) => {
@ -916,28 +931,34 @@ watch([currentFormData.value.taskStatus], () => {
@upload="
async (f) => {
fileList = f;
fileData = [];
Array.from(f).forEach((el) => {
fileData.push({
name: el.name,
progress: 1,
loaded: 0,
total: el.size,
placeholder: true,
url: fileToUrl(el),
if (!currentFormData.id) {
fileData = [];
Array.from(f).forEach((el) => {
fileData.push({
name: el.name,
progress: 1,
loaded: 0,
total: el.size,
placeholder: true,
url: fileToUrl(el),
});
});
});
if (!currentFormData.id) return;
await uploadFile(currentFormData.id, f);
} else {
await uploadFile(currentFormData.id, f);
}
}
"
@remove="
async (n) => {
if (!currentFormData.id) return;
await remove(currentFormData.id, n);
if (!currentFormData.id) {
const attIndex = fileData.findIndex((v) => v.name === n);
fileData.splice(attIndex, 1);
} else {
await remove(currentFormData.id, n);
}
}
"
/>
@ -947,7 +968,8 @@ watch([currentFormData.value.taskStatus], () => {
view === TaskOrderStatus.Pending ||
view === TaskOrderStatus.Complete
"
:readonly="false"
v-model:remark="currentFormData.remark"
:readonly="!['create', 'edit'].includes(state.mode || '')"
/>
<template
@ -1185,7 +1207,11 @@ watch([currentFormData.value.taskStatus], () => {
/>
</template>
<SaveButton
v-if="state.mode !== 'create' && view === TaskOrderStatus.Validate"
v-if="
state.mode !== 'create' &&
view === TaskOrderStatus.Validate &&
fullTaskOrder?.taskOrderStatus !== TaskOrderStatus.Pending
"
:disabled="
!fullTaskOrder?.taskList.some((t) =>
[
@ -1228,9 +1254,11 @@ watch([currentFormData.value.taskStatus], () => {
<!-- SEC: Dialog -->
<SelectReadyRequestWork
:task-list-group="taskListGroup"
:fetch-params="{ readyToTask: true }"
v-model:open="pageState.productDialog"
v-model:task-list="currentFormData.taskList"
v-model:temp-group-edit="tempGroupEdit"
@after-submit="
() => {
taskProduct = [];

View file

@ -674,32 +674,36 @@ onMounted(async () => {
@upload="
async (f) => {
attachmentList = f;
attachmentData = [];
Array.from(f).forEach((el) => {
attachmentData.push({
name: el.name,
progress: 1,
loaded: 0,
total: el.size,
placeholder: true,
url: fileToUrl(el),
if (!creditNoteData) {
attachmentData = [];
Array.from(f).forEach((el) => {
attachmentData.push({
name: el.name,
progress: 1,
loaded: 0,
total: el.size,
placeholder: true,
url: fileToUrl(el),
});
});
});
if (!creditNoteData) return;
await uploadFile(creditNoteData.id, f);
} else {
await uploadFile(creditNoteData.id, f);
}
}
"
@remove="
async (n) => {
const attIndex = attachmentData.findIndex((v) => v.name === n);
if (!creditNoteData) {
const attIndex = attachmentData.findIndex(
(v) => v.name === n,
);
attachmentData.splice(attIndex, 1);
if (!creditNoteData) return;
await remove(creditNoteData.id, n);
attachmentData.splice(attIndex, 1);
} else {
await remove(creditNoteData.id, n);
}
}
"
/>

View file

@ -104,6 +104,10 @@ export const useTaskOrderStore = defineStore('taskorder-store', () => {
async function editTaskOrder(body: TaskOrderPayload) {
const res = await api.put<TaskOrder>(`/task-order/${body.id}`, {
taskProduct: body.taskProduct?.map((v) => ({
productId: v.productId,
discount: v.discount,
})),
taskList: body.taskList.map((v) => ({
step: v.step,
requestWorkId: v.requestWorkId,
@ -113,6 +117,7 @@ export const useTaskOrderStore = defineStore('taskorder-store', () => {
contactName: body.contactName,
taskStatus: body.taskStatus,
taskName: body.taskName,
remark: body.remark,
});
if (res.status < 400) {

View file

@ -56,6 +56,7 @@ export interface TaskOrder {
code: string;
id: string;
userTask: UserTask[];
remark?: string;
}
export interface UserTask {
@ -176,6 +177,7 @@ export interface TaskOrderPayload {
registeredBranchId?: string;
id?: string;
code?: string;
remark?: string;
}
export interface ProductService {

View file

@ -1,3 +1,4 @@
import { RequestWork } from 'src/stores/request-list';
import { formatNumberDecimal } from 'src/stores/utils';
const templates = {
@ -40,6 +41,40 @@ const templates = {
}
},
},
'order-detail': {
converter: (context?: {
items: {
product: RequestWork['productService']['product'];
list: RequestWork[];
}[];
itemsDiscount?: {
productId: string;
discount?: number;
}[];
}) => {
return context?.items.flatMap((item) => {
const price = formatNumberDecimal(
item.product.serviceCharge -
(context.itemsDiscount?.find((v) => v.productId === item.product.id)
?.discount || 0),
);
const list = item.list.map((v, i) => {
const employee = v.request.employee;
const branch = v.request.quotation.customerBranch;
return (
`${i + 1}. ` +
`${employee.namePrefix}. ${employee.firstNameEN} ${employee.lastNameEN} `.toUpperCase() +
`(${branch.customer.customerType === 'PERS' ? `นายจ้าง ${branch.namePrefix}. ${branch.firstNameEN} ${branch.lastNameEN} `.toUpperCase() : branch.registerName})`
);
});
return [`- ${item.product.name} ราคา ${price} บาท`, '', ...list].join(
'<br />',
);
});
},
},
} as const;
type Template = typeof templates;