refactor: add value

This commit is contained in:
Thanaphon Frappet 2024-10-10 13:35:28 +07:00
parent 5fc9a9a6c6
commit 5f852b977b

View file

@ -16,7 +16,7 @@ export type ProductTree = {
amount: number; amount: number;
serviceId?: string; serviceId?: string;
service?: QuotationFull['productServiceList'][number]['service']; service?: QuotationFull['productServiceList'][number]['service'];
workId: string; workId?: string;
work?: QuotationFull['productServiceList'][number]['work']; work?: QuotationFull['productServiceList'][number]['work'];
productId: string; productId: string;
product: QuotationFull['productServiceList'][number]['product']; product: QuotationFull['productServiceList'][number]['product'];
@ -26,6 +26,10 @@ export type ProductTree = {
export function quotationProductTree( export function quotationProductTree(
list: { list: {
vat: number;
pricePerUnit: number;
discount: number;
amount: number;
service?: QuotationFull['productServiceList'][number]['service']; service?: QuotationFull['productServiceList'][number]['service'];
work?: QuotationFull['productServiceList'][number]['work']; work?: QuotationFull['productServiceList'][number]['work'];
product: QuotationFull['productServiceList'][number]['product']; product: QuotationFull['productServiceList'][number]['product'];
@ -50,21 +54,35 @@ export function quotationProductTree(
children: service.work.flatMap((work) => { children: service.work.flatMap((work) => {
const mapper = ( const mapper = (
relation: (typeof work)['productOnWork'][number], relation: (typeof work)['productOnWork'][number],
) => ({ ): ProductTree[number] => {
id: relation.product.id, return {
title: relation.product.name, id: relation.product.id,
subtitle: relation.product.code, title: relation.product.name,
opened: true, subtitle: relation.product.code,
checked: !!list.find( opened: true,
(v) => checked: !!list.find(
v.service?.id === service.id && (v) =>
v.work?.id === work.id && v.service?.id === service.id &&
v.product.id === relation.product.id, v.work?.id === work.id &&
), v.product.id === relation.product.id,
icon: 'mdi-shopping-outline', ),
bg: 'hsla(var(--teal-10-hsl)/0.1)', value: {
fg: 'var(--teal-10)', vat: current.vat,
}); pricePerUnit: current.pricePerUnit,
discount: current.discount,
amount: current.amount,
serviceId: service.id,
service: service,
workId: work.id,
work: work,
productId: relation.product.id,
product: relation.product,
},
icon: 'mdi-shopping-outline',
bg: 'hsla(var(--teal-10-hsl)/0.1)',
fg: 'var(--teal-10)',
};
};
if (!!work.name) { if (!!work.name) {
return { return {
@ -95,6 +113,14 @@ export function quotationProductTree(
subtitle: current.product.code, subtitle: current.product.code,
opened: true, opened: true,
checked: true, checked: true,
value: {
vat: current.vat,
pricePerUnit: current.pricePerUnit,
discount: current.discount,
amount: current.amount,
productId: current.product.id,
product: current.product,
},
icon: 'mdi-shopping-outline', icon: 'mdi-shopping-outline',
bg: 'hsla(var(--teal-10-hsl)/0.1)', bg: 'hsla(var(--teal-10-hsl)/0.1)',
fg: 'var(--teal-10)', fg: 'var(--teal-10)',