fix: [quotes] QuoteCalculationReport items → locations 프로퍼티 매핑 수정

- QuoteFormDataV2에 맞춰 quote.items를 quote.locations로 전환
- bomMaterials를 locations[].bomResult.materials에서 추출하도록 변경
- 미사용 BomMaterial import 제거
This commit is contained in:
김보곤
2026-02-23 17:13:14 +09:00
parent bc2b852f98
commit bf857b2820

View File

@@ -5,7 +5,6 @@
*/ */
import { QuoteFormDataV2 } from "./QuoteRegistration"; import { QuoteFormDataV2 } from "./QuoteRegistration";
import type { BomMaterial } from "./types";
import type { CompanyFormData } from "@/components/settings/CompanyInfoManagement/types"; import type { CompanyFormData } from "@/components/settings/CompanyInfoManagement/types";
interface QuoteCalculationReportProps { interface QuoteCalculationReportProps {
@@ -34,17 +33,18 @@ export function QuoteCalculationReport({
return `${date.getFullYear()}${String(date.getMonth() + 1).padStart(2, '0')}${String(date.getDate()).padStart(2, '0')}`; return `${date.getFullYear()}${String(date.getMonth() + 1).padStart(2, '0')}${String(date.getDate()).padStart(2, '0')}`;
}; };
// 총 금액 계산 (totalAmount > unitPrice * quantity > inspectionFee 우선순위) // 총 금액 계산 (totalPrice > unitPrice * quantity > inspectionFee 우선순위)
const totalAmount = quote.items?.reduce((sum, item) => { const totalAmount = quote.locations?.reduce((sum, loc) => {
const itemTotal = item.totalAmount || const locTotal = loc.totalPrice ||
(item.unitPrice || 0) * (item.quantity || 1) || (loc.unitPrice || 0) * (loc.quantity || 1) ||
(item.inspectionFee || 0) * (item.quantity || 1); (loc.inspectionFee || 0) * (loc.quantity || 1);
return sum + itemTotal; return sum + locTotal;
}, 0) || 0; }, 0) || 0;
// 소요자재 내역 - BOM 자재 목록 (quote.bomMaterials)에서 가져옴 // 소요자재 내역 - BOM 자재 목록 (locations[].bomResult.materials)에서 가져옴
// bomMaterials가 없으면 빈 배열 (BOM 계산 데이터 없음) const materialItems = (quote.locations || []).flatMap(loc =>
const materialItems = (quote.bomMaterials || []).map((material, index) => ({ (loc.bomResult?.materials || [])
).map((material, index) => ({
no: index + 1, no: index + 1,
itemCode: material.itemCode || '-', itemCode: material.itemCode || '-',
name: material.itemName || '-', name: material.itemName || '-',
@@ -310,7 +310,7 @@ export function QuoteCalculationReport({
</tr> </tr>
<tr> <tr>
<th></th> <th></th>
<td>{quote.items?.[0]?.productName || '-'}</td> <td>{quote.locations?.[0]?.productName || '-'}</td>
<th></th> <th></th>
<td>{quote.contact || '-'}</td> <td>{quote.contact || '-'}</td>
</tr> </tr>
@@ -364,7 +364,7 @@ export function QuoteCalculationReport({
</div> </div>
{/* 세부 산출내역서 */} {/* 세부 산출내역서 */}
{showDetailedBreakdown && quote.items && quote.items.length > 0 && ( {showDetailedBreakdown && quote.locations && quote.locations.length > 0 && (
<div className="page-break-after"> <div className="page-break-after">
<div className="section-title"> </div> <div className="section-title"> </div>
@@ -381,20 +381,18 @@ export function QuoteCalculationReport({
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{quote.items.map((item, index) => { {quote.locations.map((loc, index) => {
// 단가: unitPrice > inspectionFee 우선순위 const unitPrice = loc.unitPrice || loc.inspectionFee || 0;
const unitPrice = item.unitPrice || item.inspectionFee || 0; const locTotal = loc.totalPrice || unitPrice * (loc.quantity || 1);
// 금액: totalAmount > unitPrice * quantity 우선순위
const itemTotal = item.totalAmount || unitPrice * (item.quantity || 1);
return ( return (
<tr key={item.id || `item-${index}`}> <tr key={loc.id || `loc-${index}`}>
<td style={{ textAlign: 'center' }}>{index + 1}</td> <td style={{ textAlign: 'center' }}>{index + 1}</td>
<td>{item.productName}</td> <td>{loc.productName}</td>
<td style={{ fontSize: '11px' }}>{`${item.openWidth}×${item.openHeight}mm`}</td> <td style={{ fontSize: '11px' }}>{`${loc.openWidth}×${loc.openHeight}mm`}</td>
<td style={{ textAlign: 'right' }}>{Math.floor(item.quantity || 0)}</td> <td style={{ textAlign: 'right' }}>{Math.floor(loc.quantity || 0)}</td>
<td style={{ textAlign: 'center' }}>{item.unit || 'SET'}</td> <td style={{ textAlign: 'center' }}>SET</td>
<td style={{ textAlign: 'right' }}>{formatAmount(unitPrice)}</td> <td style={{ textAlign: 'right' }}>{formatAmount(unitPrice)}</td>
<td style={{ textAlign: 'right', fontWeight: '600' }}>{formatAmount(itemTotal)}</td> <td style={{ textAlign: 'right', fontWeight: '600' }}>{formatAmount(locTotal)}</td>
</tr> </tr>
); );
})} })}
@@ -421,19 +419,19 @@ export function QuoteCalculationReport({
<tbody> <tbody>
<tr> <tr>
<th></th> <th></th>
<td>{quote.items?.[0]?.productCategory === 'steel' ? '철재' : '스크린'}</td> <td>{quote.locations?.[0]?.itemCategory === 'steel' ? '철재' : '스크린'}</td>
<th></th> <th></th>
<td>{quote.items?.[0]?.code || '-'}</td> <td>{quote.locations?.[0]?.code || '-'}</td>
</tr> </tr>
<tr> <tr>
<th></th> <th></th>
<td>W {quote.items?.[0]?.openWidth || '-'} × H {quote.items?.[0]?.openHeight || '-'} (mm)</td> <td>W {quote.locations?.[0]?.openWidth || '-'} × H {quote.locations?.[0]?.openHeight || '-'} (mm)</td>
<th></th> <th></th>
<td>W {Number(quote.items?.[0]?.openWidth || 0) + 100} × H {Number(quote.items?.[0]?.openHeight || 0) + 100} (mm)</td> <td>W {Number(quote.locations?.[0]?.openWidth || 0) + 100} × H {Number(quote.locations?.[0]?.openHeight || 0) + 100} (mm)</td>
</tr> </tr>
<tr> <tr>
<th></th> <th></th>
<td>{Math.floor(quote.items?.[0]?.quantity || 1)} {quote.items?.[0]?.unit || 'SET'}</td> <td>{Math.floor(quote.locations?.[0]?.quantity || 1)} SET</td>
<th></th> <th></th>
<td>2438 × 550 (mm)</td> <td>2438 × 550 (mm)</td>
</tr> </tr>