diff --git a/src/components/estimate/Estimate.jsx b/src/components/estimate/Estimate.jsx index 4f578b5e..c165c55e 100644 --- a/src/components/estimate/Estimate.jsx +++ b/src/components/estimate/Estimate.jsx @@ -15,7 +15,7 @@ import { useCommonCode } from '@/hooks/common/useCommonCode' import { useEstimateController } from '@/hooks/floorPlan/estimate/useEstimateController' import { SessionContext } from '@/app/SessionProvider' import Select, { components } from 'react-select' -import { convertNumberToPriceDecimal } from '@/util/common-utils' +import { convertNumberToPriceDecimal, convertNumberToPriceDecimalToFixed } from '@/util/common-utils' import ProductFeaturesPop from './popup/ProductFeaturesPop' import { v4 as uuidv4 } from 'uuid' @@ -129,17 +129,21 @@ export default function Estimate({ params }) { }) }, [estimateContextState?.estimateOption]) + //API데이터로 견적일 셋팅 + let begin = 1 + useEffect(() => { + if (begin === 1) { + setStartDate(estimateContextState?.estimateDate) + begin++ + } + }, [estimateContextState?.estimateDate]) + //견적일 set useEffect(() => { let estimateDate = dayjs(startDate).format('YYYY-MM-DD') setEstimateContextState({ estimateDate: estimateDate }) }, [startDate]) - //API데이터로 견적일 셋팅 - useEffect(() => { - setStartDate(estimateContextState?.estimateDate) - }, [estimateContextState?.estimateDate]) - useEffect(() => { //선택된 견적특이사항 setEstimateContextState if (isNotEmptyArray(specialNoteList)) { @@ -296,9 +300,8 @@ export default function Estimate({ params }) { //기존itemList랑 프라이싱결과랑 비교해서 단가만 업뎃 서로 갯수가 안맞을 수 있음 없는 itemId면 unitPrice 0으로 //itemId로 비교해서 salePrice만 업데이트 if (data.result.code === 200) { - console.log('data::확인해서 넣기:::::::::', data.data.pkgUnitPrice) setEstimateContextState({ - pkgAsp: data.data.pkgUnitPrice, + pkgAsp: data?.data?.pkgUnitPrice, }) //주택PKG단가 체인지 이벤트 발생시키기 onChangePkgAsp(data.data.pkgUnitPrice) @@ -333,6 +336,24 @@ export default function Estimate({ params }) { }) } + const getAbledItems = (items) => { + return items.filter((items) => items.paDispOrder === null) + } + + const onChangeSelectAll = (e) => { + if (e.target.checked) { + const allCheckedSelection = new Set(getAbledItems(estimateContextState.itemList).map((item) => item.dispOrder)) + + setSelection(allCheckedSelection) + } else { + setSelection(new Set()) + } + } + + const isSelectedAll = () => { + return selection.size === getAbledItems(estimateContextState.itemList).length + } + //row 체크박스 컨트롤 const onChangeSelect = (dispOrder) => { const newSelection = new Set(selection) @@ -358,13 +379,12 @@ export default function Estimate({ params }) { let totVolKw = estimateContextState.totVolKw * 1000 let pkgTotPrice = pkgAsp.replaceAll(',', '') * totVolKw - setEstimateContextState({ pkgAsp: pkgAsp, pkgTotPrice: pkgTotPrice.toFixed(3), }) //아이템들 중 조건에 맞는애들 뽑아서 상단 공급가액 부가세 총액 수정 - // setItemChangeYn(true) + setItemChangeYn(true) } } @@ -392,7 +412,6 @@ export default function Estimate({ params }) { return item } }) - setEstimateContextState({ itemList: updateList, }) @@ -429,7 +448,7 @@ export default function Estimate({ params }) { setItemChangeYn(true) } - // 아이템 자동완성 검색시 아이템 변경 + // 아이템 자동완성 검색시 아이템 추가/변경시 const onChangeDisplayItem = (itemId, dispOrder, index) => { const param = { itemId: itemId, @@ -438,7 +457,7 @@ export default function Estimate({ params }) { let updateList = [] let updates = {} get({ url: apiUrl }).then((res) => { - // console.log('아이템상세정보:::::::', res) + console.log('아이템디테일::::::::', res) updates.objectNo = objectNo updates.planNo = planNo updates.itemId = res.itemId @@ -460,6 +479,12 @@ export default function Estimate({ params }) { updates.delFlg = '0' // 삭제플래그 0 updates.saleTotPrice = (res.salePrice * estimateContextState.itemList[index].amount).toString() + if (estimateContextState.estimateType === 'YJSS') { + if (res.pkgMaterialFlg === '0') { + updates.showSalePrice = '0' + updates.showSaleTotPrice = '0' + } + } //104671 let bomList = res.itemBomList @@ -467,7 +492,8 @@ export default function Estimate({ params }) { if (item.dispOrder === dispOrder) { return { ...item, ...updates } } else if (item.paDispOrder === dispOrder) { - return { ...item, delFlg: '1' } + return { ...item, delFlg: '0' } + // return { ...item, delFlg: '1' } } else { return item } @@ -476,7 +502,14 @@ export default function Estimate({ params }) { if (bomList) { bomList.map((bomItem, index) => { let newItemDispOrder = Math.max(...estimateContextState.itemList.map((item) => item.dispOrder)) - bomItem.dispOrder = index + 1 + newItemDispOrder + if (newItemDispOrder == dispOrder) { + bomItem.dispOrder = (index + 1 + newItemDispOrder).toString() + bomItem.paDispOrder = dispOrder + } else { + bomItem.dispOrder = (index + 1 + Number(dispOrder)).toString() + bomItem.paDispOrder = dispOrder + } + bomItem.delFlg = '0' bomItem.objectNo = objectNo bomItem.planNo = planNo @@ -539,20 +572,26 @@ export default function Estimate({ params }) { useEffect(() => { if (itemChangeYn) { - console.log(' 토탈만들어주기::::::::::', estimateContextState.itemList) - let totAmount = 0 let totVolKw = 0 let supplyPrice = 0 let vatPrice = 0 let totPrice = 0 - let addPkgPrice = 0 + let addSupplyPrice = 0 if (estimateContextState.estimateType === 'YJOD') { - estimateContextState.itemList.map((item) => { - if (item.delFlg === '0') { - const amount = Number(item.amount.replace(/[^0-9]/g, '').replaceAll(',', '')) + console.log('YJOD 토탈만들어주기::::::::::', estimateContextState.itemList) - const price = Number(item.saleTotPrice.replaceAll(',', '')) + estimateContextState.itemList.sort((a, b) => { + return a.dispOrder - b.dispOrder + }) + + estimateContextState.itemList.map((item) => { + delete item.showSalePrice + delete item.showSaleTotPrice + if (item.delFlg === '0') { + const amount = Number(item?.amount?.replace(/[^0-9]/g, '').replaceAll(',', '')) + + const price = Number(item?.saleTotPrice?.replaceAll(',', '')) if (item.moduleFlg === '1') { //용량(Kw)은 모듈플래그 1만 합산 @@ -567,7 +606,6 @@ export default function Estimate({ params }) { vatPrice = supplyPrice * 0.1 totPrice = supplyPrice + vatPrice - setEstimateContextState({ totAmount: totAmount, totVolKw: totVolKw.toFixed(3), @@ -577,11 +615,15 @@ export default function Estimate({ params }) { }) } else { //YJSS + console.log('YJSS 토탈만들어주기::::::::::', estimateContextState.itemList) + estimateContextState.itemList.sort((a, b) => { + return a.dispOrder - b.dispOrder + }) estimateContextState.itemList.map((item) => { if (item.delFlg === '0') { - const amount = Number(item.amount.replace(/[^0-9]/g, '').replaceAll(',', '')) - const price = Number(item.saleTotPrice.replaceAll(',', '')) - const salePrice = Number(item.salePrice.replaceAll(',', '')) + const amount = Number(item.amount?.replace(/[^0-9]/g, '').replaceAll(',', '')) + const price = Number(item.saleTotPrice?.replaceAll(',', '')) + const salePrice = Number(item.salePrice?.replaceAll(',', '')) if (item.moduleFlg === '1') { //용량(Kw)은 모듈플래그 1만 합산 @@ -590,19 +632,27 @@ export default function Estimate({ params }) { } if (item.pkgMaterialFlg === '1') { const pkgPrice = amount * salePrice - //YJSS는 PKG제외상품들만 모아서 수량 * 단가를 공급가액에 추가로 더해줌 - addPkgPrice += pkgPrice + //YJSS는 PKG제외상품들만(1) 모아서 수량 * 단가를 공급가액(supplyPrice)에 추가로 더해줌 + addSupplyPrice += pkgPrice + supplyPrice += price } // const price totAmount += amount - supplyPrice += price + + if (!item.paDispOrder) { + //paDispOrder + if (item.pkgMaterialFlg === '0') { + item.showSalePrice = '0' + item.showSaleTotPrice = '0' + } + } } }) + supplyPrice += addSupplyPrice vatPrice = supplyPrice * 0.1 totPrice = supplyPrice + vatPrice - setEstimateContextState({ totAmount: totAmount, totVolKw: totVolKw.toFixed(3), @@ -845,6 +895,23 @@ export default function Estimate({ params }) { setEstimateContextState({ fileFlg: e.target.checked ? '1' : '0', }) + if (e.target.checked) { + if (specialNoteList.length > 0) { + specialNoteList.map((item) => { + if (item.code === 'ATTR019') { + item.check = true + } + }) + } + } else { + if (specialNoteList.length > 0) { + specialNoteList.map((item) => { + if (item.code === 'ATTR019') { + item.check = false + } + }) + } + } }} />