diff --git a/src/components/common/font/FontSetting.jsx b/src/components/common/font/FontSetting.jsx index b48f3882..4ebdcfeb 100644 --- a/src/components/common/font/FontSetting.jsx +++ b/src/components/common/font/FontSetting.jsx @@ -1,10 +1,11 @@ import WithDraggable from '@/components/common/draggable/WithDraggable' import QSelectBox from '@/components/common/select/QSelectBox' import { usePopup } from '@/hooks/usePopup' -import { useState } from 'react' +import { useEffect, useState } from 'react' import { useMessage } from '@/hooks/useMessage' import { useRecoilValue } from 'recoil' import { contextPopupPositionState } from '@/store/popupAtom' +import { useCanvasSetting } from '@/hooks/option/useCanvasSetting' const fonts = [ { id: 1, name: 'MS PGothic', value: 'MS PGothic' }, @@ -12,7 +13,6 @@ const fonts = [ { id: 3, name: 'Yu Gothic', value: 'Yu Gothic' }, { id: 4, name: '@Yu Gothic UI', value: '@Yu Gothic UI' }, { id: 5, name: 'Yu Gothic UI', value: 'Yu Gothic UI' }, - 3, ] const fontSizes = [ @@ -36,14 +36,11 @@ export default function FontSetting(props) { const [selectedFontWeight, setSelectedFontWeight] = useState(font.fontWeight) const [selectedFontSize, setSelectedFontSize] = useState(font.fontSize) const [selectedFontColor, setSelectedFontColor] = useState(font.fontColor) + const fontOptions = [ { id: 'normal', name: getMessage('font.style.normal'), value: 'normal' }, { id: 'italic', name: getMessage('font.style.italic'), value: 'italic' }, - { - id: 'bold', - name: getMessage('font.style.bold'), - value: 'bold', - }, + { id: 'bold', name: getMessage('font.style.bold'), value: 'bold' }, { id: 'boldAndItalic', name: getMessage('font.style.bold.italic'), value: 'boldAndItalic' }, ] const fontColors = [ @@ -57,12 +54,30 @@ export default function FontSetting(props) { { id: 'gold', name: getMessage('color.gold'), value: 'gold' }, { id: 'darkblue', name: getMessage('color.darkblue'), value: 'darkblue' }, ] + useEffect(() => { + if (font.fontFamily) { + setSelectedFont(fonts.filter((data) => data.value === font.fontFamily)[0]) + } + + if (font.fontWeight) { + setSelectedFontWeight(fontOptions.filter((data) => data.value === font.fontWeight)[0]) + } + + if (font.fontSize) { + setSelectedFontSize(fontSizes.filter((data) => data.value === font.fontSize)[0]) + } + + if (font.fontColor) { + setSelectedFontColor(fontColors.filter((data) => data.value === font.fontColor)[0]) + } + }, []) + const handleSaveBtn = () => { onSave({ fontFamily: selectedFont, + fontWeight: selectedFontWeight, fontSize: selectedFontSize, fontColor: selectedFontColor, - fontWeight: selectedFontWeight, }) if (setIsShow) setIsShow(false) closePopup(id, isConfig) @@ -117,9 +132,9 @@ export default function FontSetting(props) { diff --git a/src/components/estimate/Estimate.jsx b/src/components/estimate/Estimate.jsx index 4f578b5e..1846b2d5 100644 --- a/src/components/estimate/Estimate.jsx +++ b/src/components/estimate/Estimate.jsx @@ -15,11 +15,12 @@ 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' export default function Estimate({ params }) { + const [specialNoteFirstFlg, setSpecialNoteFirstFlg] = useState(false) const fixedKey = 'itemKey' const [itemChangeYn, setItemChangeYn] = useState(false) const { session } = useContext(SessionContext) @@ -102,44 +103,97 @@ export default function Estimate({ params }) { useEffect(() => { //견적특이사항 API호출 //여러개 선택하면 구분자로 (、) - let url = `/api/estimate/special-note-list` - get({ url: url }).then((res) => { - if (isNotEmptyArray(res)) { - if (estimateContextState?.estimateOption) { - res.map((row) => { - let estimateOption = estimateContextState?.estimateOption?.split('、') - row.check = false - estimateOption.map((row2) => { - if (row2 === row.code) { + if (!specialNoteFirstFlg) { + let url = `/api/estimate/special-note-list` + get({ url: url }).then((res) => { + if (isNotEmptyArray(res)) { + if (estimateContextState?.estimateOption) { + res.map((row) => { + let estimateOption = estimateContextState?.estimateOption?.split('、') + row.check = false + estimateOption.map((row2) => { + if (row2 === row.code) { + row.check = true + } + }) + //detail과 상관없이 디폴트 체크목록 + //ATTR003,ATTR007 + if (row.code === 'ATTR003') { + row.check = true + } + if (row.code === 'ATTR007') { row.check = true } }) - //detail과 상관없이 디폴트 체크목록 - //ATTR003,ATTR007 - if (row.code === 'ATTR003') { - row.check = true - } - if (row.code === 'ATTR007') { - row.check = true - } - }) - setSpecialNoteList(res) + + setSpecialNoteList(res) + + setSpecialNoteFirstFlg(true) + } } - } - }) + }) + } }, [estimateContextState?.estimateOption]) + //변경버전 + // useEffect(() => { + // //견적특이사항 API호출 + // //여러개 선택하면 구분자로 (、) + // let url = `/api/estimate/special-note-title-list` + // // let url = `/api/estimate/special-note-list` + // get({ url: url }).then((res) => { + // if (isNotEmptyArray(res)) { + // if (estimateContextState?.estimateOption) { + // res.map((row) => { + // // console.log('API결과:::', row) + // //ATTR001、ATTR002、ATTR009、ATTR010 + // let estimateOption = estimateContextState?.estimateOption?.split('、') + // row.check = false + // estimateOption.map((row2) => { + // if (row.pkgYn === '0') { + // if (row2 === row.code) { + // row.check = true + // } + // } else { + // if (row.code.includes(row2)) { + // row.check = true + // return + // } + // } + // }) + // //detail과 상관없이 디폴트 체크목록 + // //ATTR003,ATTR007 + // if (row.code === 'ATTR003') { + // row.check = true + // } + // if (row.code === 'ATTR007') { + // row.check = true + // } + // }) + + // setSpecialNoteList(res) + // } + // } + // }) + // }, [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 }) + if (begin === 1) { + setEstimateContextState({ estimateDate: estimateDate }) + } }, [startDate]) - //API데이터로 견적일 셋팅 - useEffect(() => { - setStartDate(estimateContextState?.estimateDate) - }, [estimateContextState?.estimateDate]) - useEffect(() => { //선택된 견적특이사항 setEstimateContextState if (isNotEmptyArray(specialNoteList)) { @@ -231,6 +285,15 @@ export default function Estimate({ params }) { } }) } + + //비워주기 + setEstimateContextState({ + pkgAsp: '0', + pkgTotPrice: '0', + }) + + //YJOD로 돌아가도 UNIT_PRICE로 프라이싱 실행해서 정가로 셋팅 + handlePricing('UNIT_PRICE') } setItemChangeYn(true) @@ -296,9 +359,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) @@ -309,7 +371,11 @@ export default function Estimate({ params }) { data.data2.map((item2) => { if (item2) { if (item2.itemId === item.itemId) { - updateList.push({ ...item, salePrice: item2.unitPrice, saleTotPrice: (item.amount * item2.unitPrice).toString() }) + updateList.push({ + ...item, + salePrice: item2.unitPrice === null ? '0' : item2.unitPrice, + saleTotPrice: (item.amount * item2.unitPrice).toString(), + }) checkYn = true } } @@ -319,7 +385,6 @@ export default function Estimate({ params }) { updateList.push({ ...item, salePrice: '0', saleTotPrice: '0' }) } }) - setEstimateContextState({ priceCd: showPriceCd, itemList: updateList, @@ -333,6 +398,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 +441,13 @@ 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) + } else { } } @@ -392,7 +475,6 @@ export default function Estimate({ params }) { return item } }) - setEstimateContextState({ itemList: updateList, }) @@ -429,7 +511,7 @@ export default function Estimate({ params }) { setItemChangeYn(true) } - // 아이템 자동완성 검색시 아이템 변경 + // 아이템 자동완성 검색시 아이템 추가/변경시 const onChangeDisplayItem = (itemId, dispOrder, index) => { const param = { itemId: itemId, @@ -438,7 +520,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 +542,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 +555,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 } @@ -475,8 +564,21 @@ export default function Estimate({ params }) { //paDispOrder if (bomList) { bomList.map((bomItem, index) => { - let newItemDispOrder = Math.max(...estimateContextState.itemList.map((item) => item.dispOrder)) - bomItem.dispOrder = index + 1 + newItemDispOrder + let maxItemDispOrder = Math.max(...estimateContextState.itemList.map((item) => item.dispOrder)) + if (maxItemDispOrder == dispOrder) { + bomItem.dispOrder = (index + 1 + maxItemDispOrder).toString() + bomItem.paDispOrder = dispOrder + bomItem.salePrice = '0' + //unitPrice는?? + bomItem.saleTotPrice = '0' + } else { + bomItem.dispOrder = (index + 1 + Number(dispOrder)).toString() + bomItem.paDispOrder = dispOrder + bomItem.salePrice = '0' + //unitPrice는?? + bomItem.saleTotPrice = '0' + } + bomItem.delFlg = '0' bomItem.objectNo = objectNo bomItem.planNo = planNo @@ -539,21 +641,31 @@ 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') { + console.log('YJOD 토탈만들어주기::::::::::', estimateContextState.itemList) + + 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(',', '')) - + let amount = Number(item?.amount?.replace(/[^0-9]/g, '').replaceAll(',', '')) + if (isNaN(amount)) { + amount = 0 + } + let price = Number(item?.saleTotPrice?.replaceAll(',', '')) + if (isNaN(price)) { + price = 0 + } if (item.moduleFlg === '1') { //용량(Kw)은 모듈플래그 1만 합산 const volKw = (item.pnowW * amount) / 1000 @@ -577,32 +689,55 @@ 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(',', '')) + let amount = Number(item.amount?.replace(/[^0-9]/g, '').replaceAll(',', '')) + let price = Number(item.saleTotPrice?.replaceAll(',', '')) + let salePrice = Number(item.salePrice?.replaceAll(',', '')) + if (isNaN(amount)) { + amount = 0 + } + + if (isNaN(price)) { + price = 0 + } + + if (isNaN(salePrice)) { + salePrice = 0 + } if (item.moduleFlg === '1') { //용량(Kw)은 모듈플래그 1만 합산 const volKw = (item.pnowW * amount) / 1000 totVolKw += volKw } - if (item.pkgMaterialFlg === '1') { - const pkgPrice = amount * salePrice - //YJSS는 PKG제외상품들만 모아서 수량 * 단가를 공급가액에 추가로 더해줌 - addPkgPrice += pkgPrice - } // const price - totAmount += amount supplyPrice += price + totAmount += amount + if (item.pkgMaterialFlg === '1') { + const pkgPrice = amount * salePrice + //다시계산하기 + //YJSS는 PKG제외상품들만(1) 모아서 수량 * 단가를 공급가액(supplyPrice)에 추가로 더해줌 + addSupplyPrice += pkgPrice + } + 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 +980,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 + } + }) + } + } }} />