diff --git a/src/components/estimate/Estimate.jsx b/src/components/estimate/Estimate.jsx index 27a3f37f..9b0bbd5c 100644 --- a/src/components/estimate/Estimate.jsx +++ b/src/components/estimate/Estimate.jsx @@ -562,7 +562,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 @@ -696,98 +696,61 @@ export default function Estimate({ params }) { useEffect(() => { if (itemChangeYn) { - let totAmount = 0 - let totVolKw = 0 - let supplyPrice = 0 - let vatPrice = 0 - let totPrice = 0 - let addSupplyPrice = 0 - let pkgTotPrice = 0 - if (estimateContextState.estimateType === 'YJOD') { - estimateContextState.itemList.sort((a, b) => { - return a.dispOrder - b.dispOrder - }) - // console.log('YJOD 토탈만들어주기::::::::::', estimateContextState.itemList) + let totals = { + totAmount: 0, + totVolKw: 0, + supplyPrice: 0, + vatPrice: 0, + totPrice: 0, + addSupplyPrice: 0, + pkgTotPrice: 0, + } - //아이템에서 제품관련 특이사항 중복제거해서 만드는 함수 - makeUniqueSpecialNoteCd(estimateContextState.itemList) + const calculateYJODTotals = (itemList) => { + itemList.sort((a, b) => a.dispOrder - b.dispOrder) + makeUniqueSpecialNoteCd(itemList) - estimateContextState.itemList.map((item) => { + itemList.forEach((item) => { delete item.showSalePrice delete item.showSaleTotPrice if (item.delFlg === '0') { - 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 - } + let amount = Number(item.amount?.replace(/[^0-9]/g, '').replaceAll(',', '')) || 0 + let price = Number(item.saleTotPrice?.replaceAll(',', '')) || 0 + if (item.moduleFlg === '1') { - //용량(Kw)은 모듈플래그 1만 합산 const volKw = (item.pnowW * amount) / 1000 - // const volKw = item.pnowW * amount - totVolKw += volKw + totals.totVolKw += volKw } - // const price - totAmount += amount - supplyPrice += price + totals.totAmount += amount + totals.supplyPrice += price } }) - vatPrice = supplyPrice * 0.1 - totPrice = supplyPrice + vatPrice + totals.vatPrice = totals.supplyPrice * 0.1 + totals.totPrice = totals.supplyPrice + totals.vatPrice + } - setEstimateContextState({ - totAmount: totAmount, - totVolKw: totVolKw.toFixed(3), - supplyPrice: supplyPrice.toFixed(3), - vatPrice: vatPrice.toFixed(3), - totPrice: totPrice.toFixed(3), - }) - } else { - //아이템에서 제품관련 특이사항 중복제거해서 만드는 함수 - makeUniqueSpecialNoteCd(estimateContextState.itemList) - //YJSS - // console.log('YJSS 토탈만들어주기::::::::::', estimateContextState.itemList) - estimateContextState.itemList.sort((a, b) => { - return a.dispOrder - b.dispOrder - }) - estimateContextState.itemList.map((item) => { + const calculateYJSSTotals = (itemList) => { + itemList.sort((a, b) => a.dispOrder - b.dispOrder) + makeUniqueSpecialNoteCd(itemList) + + itemList.forEach((item) => { if (item.delFlg === '0') { - let amount = Number(item.amount?.replace(/[^0-9]/g, '').replaceAll(',', '')) - let salePrice = Number(item.salePrice?.replaceAll(',', '')) - let saleTotPrice = Number(item.saleTotPrice?.replaceAll(',', '')) + let amount = Number(item.amount?.replace(/[^0-9]/g, '').replaceAll(',', '')) || 0 + let salePrice = Number(item.salePrice?.replaceAll(',', '')) || 0 - if (isNaN(amount)) { - amount = '0' - } - - if (isNaN(saleTotPrice)) { - saleTotPrice = 0 - } - - if (isNaN(salePrice)) { - salePrice = 0 - } if (item.moduleFlg === '1') { - //용량(Kw)은 모듈플래그 1만 합산 const volKw = (item.pnowW * amount) / 1000 - totVolKw += volKw + totals.totVolKw += volKw } - // const saleTotPrice - totAmount += amount + totals.totAmount += amount if (item.pkgMaterialFlg === '1') { const saleTotPrice = amount * salePrice - //다시계산하기 - //YJSS는 PKG제외상품들만(1) 모아서 수량 * 단가를 공급가액(supplyPrice)에 추가로 더해줌 - addSupplyPrice += saleTotPrice + totals.addSupplyPrice += saleTotPrice } if (!item.paDispOrder) { - //paDispOrder if (item.pkgMaterialFlg === '0') { item.showSalePrice = '0' item.showSaleTotPrice = '0' @@ -795,34 +758,40 @@ export default function Estimate({ params }) { } } }) - pkgTotPrice = estimateContextState.pkgAsp.replaceAll(',', '') * totVolKw * 1000 - setEstimateContextState({ - pkgTotPrice: pkgTotPrice, - }) - supplyPrice = addSupplyPrice + pkgTotPrice - vatPrice = supplyPrice * 0.1 - totPrice = supplyPrice + vatPrice + totals.pkgTotPrice = Number(estimateContextState.pkgAsp.replaceAll(',', '')) * totals.totVolKw * 1000 + totals.supplyPrice = totals.addSupplyPrice + totals.pkgTotPrice + totals.vatPrice = totals.supplyPrice * 0.1 + totals.totPrice = totals.supplyPrice + totals.vatPrice + } + + if (estimateContextState.estimateType === 'YJOD') { + calculateYJODTotals(estimateContextState.itemList) setEstimateContextState({ - totAmount: totAmount, - totVolKw: totVolKw.toFixed(3), - supplyPrice: supplyPrice.toFixed(3), - vatPrice: vatPrice.toFixed(3), - totPrice: totPrice.toFixed(3), + totAmount: totals.totAmount, + totVolKw: totals.totVolKw.toFixed(3), + supplyPrice: totals.supplyPrice.toFixed(3), + vatPrice: totals.vatPrice.toFixed(3), + totPrice: totals.totPrice.toFixed(3), + }) + } else if (estimateContextState.estimateType === 'YJSS') { + calculateYJSSTotals(estimateContextState.itemList) + setEstimateContextState({ + pkgTotPrice: totals.pkgTotPrice, + totAmount: totals.totAmount, + totVolKw: totals.totVolKw.toFixed(3), + supplyPrice: totals.supplyPrice.toFixed(3), + vatPrice: totals.vatPrice.toFixed(3), + totPrice: totals.totPrice.toFixed(3), }) } setItemChangeYn(false) } else { - estimateContextState.itemList.map((item) => { - if (estimateContextState.estimateType === 'YJSS') { - if (!item.paDispOrder) { - //paDispOrder - if (item.pkgMaterialFlg === '0') { - item.showSalePrice = '0' - item.showSaleTotPrice = '0' - } - } + estimateContextState.itemList.forEach((item) => { + if (estimateContextState.estimateType === 'YJSS' && !item.paDispOrder && item.pkgMaterialFlg === '0') { + item.showSalePrice = '0' + item.showSaleTotPrice = '0' } }) } @@ -1160,13 +1129,7 @@ export default function Estimate({ params }) { {specialNoteList.length > 0 && specialNoteList.map((row) => { return ( -