feat: 견적 품목 추가 시 단가 자동 조회 기능
- fetchItemPrices 클라이언트 API 함수 추가 (items.ts) - 품목 선택 시 /api/proxy/quotes/items/prices를 통해 단가 조회 - 조회된 단가로 견적금액요약에 즉시 반영
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
import { useState, useMemo, useEffect } from "react";
|
||||
import { Package, Settings, Plus, Trash2, Loader2, Calculator, Save } from "lucide-react";
|
||||
import { getItemCategoryTree, type ItemCategoryNode } from "./actions";
|
||||
import { fetchItemPrices } from "@/lib/api/items";
|
||||
|
||||
import { Badge } from "../ui/badge";
|
||||
import { Button } from "../ui/button";
|
||||
@@ -724,21 +725,32 @@ export function LocationDetailPanel({
|
||||
<ItemSearchModal
|
||||
open={itemSearchOpen}
|
||||
onOpenChange={setItemSearchOpen}
|
||||
onSelectItem={(item) => {
|
||||
onSelectItem={async (item) => {
|
||||
if (!location) return;
|
||||
|
||||
const currentTab = detailTabs.find((t) => t.value === activeTab);
|
||||
const categoryCode = activeTab;
|
||||
const categoryLabel = currentTab?.label || activeTab;
|
||||
|
||||
// 단가 조회 (클라이언트 API 호출)
|
||||
let unitPrice = 0;
|
||||
try {
|
||||
const priceResult = await fetchItemPrices([item.code]);
|
||||
unitPrice = priceResult[item.code]?.unit_price || 0;
|
||||
} catch (error) {
|
||||
console.error('[품목 추가] 단가 조회 실패:', error);
|
||||
}
|
||||
|
||||
const totalPrice = unitPrice * 1; // quantity = 1
|
||||
|
||||
const newItem: BomCalculationResultItem & { category_code?: string; is_manual?: boolean } = {
|
||||
item_code: item.code,
|
||||
item_name: item.name,
|
||||
specification: item.specification || "",
|
||||
unit: "EA",
|
||||
quantity: 1,
|
||||
unit_price: 0,
|
||||
total_price: 0,
|
||||
unit_price: unitPrice,
|
||||
total_price: totalPrice,
|
||||
process_group: categoryLabel,
|
||||
category_code: categoryCode,
|
||||
is_manual: true,
|
||||
@@ -789,8 +801,13 @@ export function LocationDetailPanel({
|
||||
grand_total: updatedGrandTotal,
|
||||
};
|
||||
|
||||
onUpdateLocation(location.id, { bomResult: updatedBomResult });
|
||||
console.log(`[품목 추가] ${item.code} - ${item.name} → ${categoryLabel} (${categoryCode})`);
|
||||
// unitPrice, totalPrice도 함께 업데이트
|
||||
onUpdateLocation(location.id, {
|
||||
bomResult: updatedBomResult,
|
||||
unitPrice: updatedGrandTotal,
|
||||
totalPrice: updatedGrandTotal * location.quantity,
|
||||
});
|
||||
console.log(`[품목 추가] ${item.code} - ${item.name} → ${categoryLabel} (${categoryCode}), 단가: ${unitPrice}`);
|
||||
}}
|
||||
tabLabel={detailTabs.find((t) => t.value === activeTab)?.label}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user