From 1b4555f0af8f814106d72fdda38d642bc0dff605 Mon Sep 17 00:00:00 2001 From: DDD1542 Date: Thu, 9 Apr 2026 18:38:08 +0900 Subject: [PATCH] 11 --- .../purchase/purchase-item/page.tsx | 70 +++++++++++++------ .../COMPANY_16/purchase/supplier/page.tsx | 68 +++++++++++++----- .../COMPANY_16/sales/sales-item/page.tsx | 70 +++++++++++++------ 3 files changed, 147 insertions(+), 61 deletions(-) diff --git a/frontend/app/(main)/COMPANY_16/purchase/purchase-item/page.tsx b/frontend/app/(main)/COMPANY_16/purchase/purchase-item/page.tsx index 9141103c..55f87c4a 100644 --- a/frontend/app/(main)/COMPANY_16/purchase/purchase-item/page.tsx +++ b/frontend/app/(main)/COMPANY_16/purchase/purchase-item/page.tsx @@ -518,7 +518,7 @@ export default function PurchaseItemPage() { }, [selectedItem?.item_number, priceCategoryOptions]); // eslint-disable-line react-hooks/exhaustive-deps // 공급업체 검색 - const searchSuppliers = async () => { + const searchSuppliers = useCallback(async () => { setSuppSearchLoading(true); try { const filters: any[] = []; @@ -533,7 +533,14 @@ export default function PurchaseItemPage() { const existing = new Set(supplierItems.map((c: any) => c.supplier_id || c.supplier_code)); setSuppSearchResults(all.filter((c: any) => !existing.has(c.supplier_code))); } catch { /* skip */ } finally { setSuppSearchLoading(false); } - }; + }, [suppSearchKeyword, supplierItems]); + + // 실시간 검색 (2글자 이상) + useEffect(() => { + if (!suppSelectOpen) return; + if (suppSearchKeyword.length > 0 && suppSearchKeyword.length < 2) return; + searchSuppliers(); + }, [suppSearchKeyword, suppSelectOpen]); // eslint-disable-line react-hooks/exhaustive-deps // 공급업체 선택 → 상세 모달로 이동 const goToSuppDetail = () => { @@ -727,7 +734,7 @@ export default function PurchaseItemPage() { } catch { /* skip */ } const priceRows = (suppPrices[custKey] || []).filter((p) => - (p.base_price && Number(p.base_price) > 0) || p.start_date + p.base_price || p.start_date || p.currency_code || p.base_price_type ); for (const price of priceRows) { await apiClient.post(`/table-management/tables/supplier_item_prices/add`, { @@ -763,7 +770,7 @@ export default function PurchaseItemPage() { } const priceRows = (suppPrices[custKey] || []).filter((p) => - (p.base_price && Number(p.base_price) > 0) || p.start_date + p.base_price || p.start_date || p.currency_code || p.base_price_type ); for (const price of priceRows) { await apiClient.post(`/table-management/tables/supplier_item_prices/add`, { @@ -794,42 +801,63 @@ export default function PurchaseItemPage() { } }; - // 우측: 공급업체 매핑 삭제 + // 우측: 공급업체 매핑 해제 (소프트 삭제 — item_id를 null 처리) const handleSupplierMappingDelete = async () => { if (supplierCheckedIds.length === 0) return; - const ok = await confirm(`선택한 ${supplierCheckedIds.length}개 공급업체 매핑을 삭제하시겠습니까?`, { - description: "관련된 단가 정보도 함께 삭제됩니다.", - variant: "destructive", confirmText: "삭제", + const ok = await confirm(`선택한 ${supplierCheckedIds.length}개 공급업체의 연결을 해제하시겠습니까?`, { + description: "해당 공급업체의 품목 연결이 해제됩니다. (데이터는 유지)", + variant: "destructive", confirmText: "해제", }); if (!ok) return; try { - // 관련 단가 삭제 - for (const mappingId of supplierCheckedIds) { + const supplierCodes = supplierCheckedIds.map((mid) => { + const group = Object.values(supplierGroups).find((g) => g.master.id === mid); + return group?.master.supplier_id || group?.master.supplier_code || ""; + }).filter(Boolean); + + for (const suppCode of supplierCodes) { + // 해당 공급업체의 모든 매핑 조회 → item_id null 처리 + const mapRes = await apiClient.post(`/table-management/tables/${MAPPING_TABLE}/data`, { + page: 1, size: 500, + dataFilter: { enabled: true, filters: [ + { columnName: "item_id", operator: "equals", value: selectedItem!.item_number }, + { columnName: "supplier_id", operator: "equals", value: suppCode }, + ]}, autoFilter: true, + }); + const allMappings = mapRes.data?.data?.data || mapRes.data?.data?.rows || []; + for (const m of allMappings) { + await apiClient.put(`/table-management/tables/${MAPPING_TABLE}/edit`, { + originalData: { id: m.id }, + updatedData: { item_id: null }, + }); + } + + // 해당 공급업체의 모든 단가 조회 → item_id null 처리 try { const priceRes = await apiClient.post(`/table-management/tables/supplier_item_prices/data`, { page: 1, size: 500, - dataFilter: { enabled: true, filters: [{ columnName: "mapping_id", operator: "equals", value: mappingId }] }, - autoFilter: true, + dataFilter: { enabled: true, filters: [ + { columnName: "item_id", operator: "equals", value: selectedItem!.item_number }, + { columnName: "supplier_id", operator: "equals", value: suppCode }, + ]}, autoFilter: true, }); const prices = priceRes.data?.data?.data || priceRes.data?.data?.rows || []; - if (prices.length > 0) { - await apiClient.delete(`/table-management/tables/supplier_item_prices/delete`, { - data: prices.map((p: any) => ({ id: p.id })), + for (const p of prices) { + await apiClient.put(`/table-management/tables/supplier_item_prices/edit`, { + originalData: { id: p.id }, + updatedData: { item_id: null }, }); } } catch { /* skip */ } } - // 매핑 삭제 - await apiClient.delete(`/table-management/tables/${MAPPING_TABLE}/delete`, { - data: supplierCheckedIds.map((id) => ({ id })), - }); - toast.success(`${supplierCheckedIds.length}개 공급업체 매핑이 삭제되었습니다.`); + + toast.success(`${supplierCheckedIds.length}개 공급업체의 연결이 해제되었습니다.`); setSupplierCheckedIds([]); const sid = selectedItemId; setSelectedItemId(null); setTimeout(() => setSelectedItemId(sid), 50); } catch { - toast.error("삭제에 실패했습니다."); + toast.error("연결 해제에 실패했습니다."); } }; diff --git a/frontend/app/(main)/COMPANY_16/purchase/supplier/page.tsx b/frontend/app/(main)/COMPANY_16/purchase/supplier/page.tsx index 521f770e..20c70b57 100644 --- a/frontend/app/(main)/COMPANY_16/purchase/supplier/page.tsx +++ b/frontend/app/(main)/COMPANY_16/purchase/supplier/page.tsx @@ -807,7 +807,7 @@ export default function SupplierManagementPage() { }; // 품목 검색 - const searchItems = async () => { + const searchItems = useCallback(async () => { setItemSearchLoading(true); try { const filters: any[] = []; @@ -827,7 +827,14 @@ export default function SupplierManagementPage() { return divCodes.some((code: string) => PURCHASE_CODES.includes(code)); })); } catch { /* skip */ } finally { setItemSearchLoading(false); } - }; + }, [itemSearchKeyword, priceItems]); + + // 실��간 검색 (2글자 이상) + useEffect(() => { + if (!itemSelectOpen) return; + if (itemSearchKeyword.length > 0 && itemSearchKeyword.length < 2) return; + searchItems(); + }, [itemSearchKeyword, itemSelectOpen]); // eslint-disable-line react-hooks/exhaustive-deps // 품목 선택 완료 → 상세 입력 모달로 전환 const goToItemDetail = () => { @@ -1090,7 +1097,7 @@ export default function SupplierManagementPage() { // 단가 upsert const priceRows = (itemPrices[itemKey] || []).filter((p) => - (p.base_price && Number(p.base_price) > 0) || p.start_date + p.base_price || p.start_date || p.currency_code || p.base_price_type ); const usedPriceIds = new Set(); for (let pi = 0; pi < priceRows.length; pi++) { @@ -1160,7 +1167,7 @@ export default function SupplierManagementPage() { } const priceRows = (itemPrices[itemKey] || []).filter((p) => - (p.base_price && Number(p.base_price) > 0) || p.start_date + p.base_price || p.start_date || p.currency_code || p.base_price_type ); for (const price of priceRows) { await apiClient.post(`/table-management/tables/${PRICE_TABLE}/add`, { @@ -1192,40 +1199,63 @@ export default function SupplierManagementPage() { } }; - // 품목 매핑 삭제 + // 품목 매핑 해제 (소프트 삭제 — supplier_id를 null 처리) const handlePriceItemDelete = async () => { if (priceCheckedIds.length === 0) return; - const ok = await confirm(`선택한 ${priceCheckedIds.length}개 품목 매핑을 삭제하시겠습니까?`, { - description: "관련된 단가 정보도 함께 삭제됩니다.", - variant: "destructive", confirmText: "삭제", + const ok = await confirm(`선택한 ${priceCheckedIds.length}개 품목의 연결을 해제하시겠습니까?`, { + description: "해당 품목의 공급업체 연결이 해제됩니다. (데이터는 유지)", + variant: "destructive", confirmText: "해제", }); if (!ok) return; try { - for (const mappingId of priceCheckedIds) { + const itemIds = priceCheckedIds.map((mid) => { + const group = Object.values(priceGroups).find((g) => g.master.id === mid); + return group?.master.item_id || group?.master.item_number || ""; + }).filter(Boolean); + + for (const itemId of itemIds) { + // 해당 품목의 모든 매핑 조회 → supplier_id null 처리 + const mapRes = await apiClient.post(`/table-management/tables/${MAPPING_TABLE}/data`, { + page: 1, size: 500, + dataFilter: { enabled: true, filters: [ + { columnName: "supplier_id", operator: "equals", value: selectedSupplier!.supplier_code }, + { columnName: "item_id", operator: "equals", value: itemId }, + ]}, autoFilter: true, + }); + const allMappings = mapRes.data?.data?.data || mapRes.data?.data?.rows || []; + for (const m of allMappings) { + await apiClient.put(`/table-management/tables/${MAPPING_TABLE}/edit`, { + originalData: { id: m.id }, + updatedData: { supplier_id: null }, + }); + } + + // 해당 품목의 모든 단가 조회 → supplier_id null 처리 try { const priceRes = await apiClient.post(`/table-management/tables/${PRICE_TABLE}/data`, { page: 1, size: 500, - dataFilter: { enabled: true, filters: [{ columnName: "mapping_id", operator: "equals", value: mappingId }] }, - autoFilter: true, + dataFilter: { enabled: true, filters: [ + { columnName: "supplier_id", operator: "equals", value: selectedSupplier!.supplier_code }, + { columnName: "item_id", operator: "equals", value: itemId }, + ]}, autoFilter: true, }); const prices = priceRes.data?.data?.data || priceRes.data?.data?.rows || []; - if (prices.length > 0) { - await apiClient.delete(`/table-management/tables/${PRICE_TABLE}/delete`, { - data: prices.map((p: any) => ({ id: p.id })), + for (const p of prices) { + await apiClient.put(`/table-management/tables/${PRICE_TABLE}/edit`, { + originalData: { id: p.id }, + updatedData: { supplier_id: null }, }); } } catch { /* skip */ } } - await apiClient.delete(`/table-management/tables/${MAPPING_TABLE}/delete`, { - data: priceCheckedIds.map((id) => ({ id })), - }); - toast.success(`${priceCheckedIds.length}개 품목 매핑이 삭제되었습니다.`); + + toast.success(`${priceCheckedIds.length}개 품목의 연결이 해제되었습니다.`); setPriceCheckedIds([]); const cid = selectedSupplierId; setSelectedSupplierId(null); setTimeout(() => setSelectedSupplierId(cid), 50); } catch { - toast.error("삭제에 실패했습니다."); + toast.error("연결 해제에 실패했습니다."); } }; diff --git a/frontend/app/(main)/COMPANY_16/sales/sales-item/page.tsx b/frontend/app/(main)/COMPANY_16/sales/sales-item/page.tsx index 8ea80afc..de4c1950 100644 --- a/frontend/app/(main)/COMPANY_16/sales/sales-item/page.tsx +++ b/frontend/app/(main)/COMPANY_16/sales/sales-item/page.tsx @@ -456,7 +456,7 @@ export default function SalesItemPage() { }, [selectedItem?.item_number, priceCategoryOptions]); // eslint-disable-line react-hooks/exhaustive-deps // 거래처 검색 - const searchCustomers = async () => { + const searchCustomers = useCallback(async () => { setCustSearchLoading(true); try { const filters: any[] = []; @@ -471,7 +471,14 @@ export default function SalesItemPage() { const existing = new Set(customerItems.map((c: any) => c.customer_id || c.customer_code)); setCustSearchResults(all.filter((c: any) => !existing.has(c.customer_code))); } catch { /* skip */ } finally { setCustSearchLoading(false); } - }; + }, [custSearchKeyword, customerItems]); + + // 실시간 검색 (2글자 이상) + useEffect(() => { + if (!custSelectOpen) return; + if (custSearchKeyword.length > 0 && custSearchKeyword.length < 2) return; + searchCustomers(); + }, [custSearchKeyword, custSelectOpen]); // eslint-disable-line react-hooks/exhaustive-deps // 거래처 선택 → 상세 모달로 이동 const goToCustDetail = () => { @@ -691,7 +698,7 @@ export default function SalesItemPage() { } catch { /* skip */ } const priceRows = (custPrices[custKey] || []).filter((p) => - (p.base_price && Number(p.base_price) > 0) || p.start_date + p.base_price || p.start_date || p.currency_code || p.base_price_type ); for (const price of priceRows) { await apiClient.post(`/table-management/tables/customer_item_prices/add`, { @@ -727,7 +734,7 @@ export default function SalesItemPage() { } const priceRows = (custPrices[custKey] || []).filter((p) => - (p.base_price && Number(p.base_price) > 0) || p.start_date + p.base_price || p.start_date || p.currency_code || p.base_price_type ); for (const price of priceRows) { await apiClient.post(`/table-management/tables/customer_item_prices/add`, { @@ -822,42 +829,63 @@ export default function SalesItemPage() { } }; - // 우측: 거래처 매핑 삭제 + // 우측: 거래처 매핑 해제 (소프트 삭제 — item_id를 null 처리) const handleCustomerMappingDelete = async () => { if (customerCheckedIds.length === 0) return; - const ok = await confirm(`선택한 ${customerCheckedIds.length}개 거래처 매핑을 삭제하시겠습니까?`, { - description: "관련된 단가 정보도 함께 삭제됩니다.", - variant: "destructive", confirmText: "삭제", + const ok = await confirm(`선택한 ${customerCheckedIds.length}개 거래처의 연결을 해제하시겠습니까?`, { + description: "해당 거래처의 품목 연결이 해제됩니다. (데이터는 유지)", + variant: "destructive", confirmText: "해제", }); if (!ok) return; try { - // 관련 단가 삭제 - for (const mappingId of customerCheckedIds) { + const customerCodes = customerCheckedIds.map((mid) => { + const group = Object.values(priceGroups).find((g) => g.master.id === mid); + return group?.master.customer_id || group?.master.customer_code || ""; + }).filter(Boolean); + + for (const custCode of customerCodes) { + // 해당 거래처의 모든 매핑 조회 → item_id null 처리 + const mapRes = await apiClient.post(`/table-management/tables/${MAPPING_TABLE}/data`, { + page: 1, size: 500, + dataFilter: { enabled: true, filters: [ + { columnName: "item_id", operator: "equals", value: selectedItem!.item_number }, + { columnName: "customer_id", operator: "equals", value: custCode }, + ]}, autoFilter: true, + }); + const allMappings = mapRes.data?.data?.data || mapRes.data?.data?.rows || []; + for (const m of allMappings) { + await apiClient.put(`/table-management/tables/${MAPPING_TABLE}/edit`, { + originalData: { id: m.id }, + updatedData: { item_id: null }, + }); + } + + // 해당 거래처의 모든 단가 조회 → item_id null 처리 try { const priceRes = await apiClient.post(`/table-management/tables/customer_item_prices/data`, { page: 1, size: 500, - dataFilter: { enabled: true, filters: [{ columnName: "mapping_id", operator: "equals", value: mappingId }] }, - autoFilter: true, + dataFilter: { enabled: true, filters: [ + { columnName: "item_id", operator: "equals", value: selectedItem!.item_number }, + { columnName: "customer_id", operator: "equals", value: custCode }, + ]}, autoFilter: true, }); const prices = priceRes.data?.data?.data || priceRes.data?.data?.rows || []; - if (prices.length > 0) { - await apiClient.delete(`/table-management/tables/customer_item_prices/delete`, { - data: prices.map((p: any) => ({ id: p.id })), + for (const p of prices) { + await apiClient.put(`/table-management/tables/customer_item_prices/edit`, { + originalData: { id: p.id }, + updatedData: { item_id: null }, }); } } catch { /* skip */ } } - // 매핑 삭제 - await apiClient.delete(`/table-management/tables/${MAPPING_TABLE}/delete`, { - data: customerCheckedIds.map((id) => ({ id })), - }); - toast.success(`${customerCheckedIds.length}개 거래처 매핑이 삭제되었습니다.`); + + toast.success(`${customerCheckedIds.length}개 거래처의 연결이 해제되었습니다.`); setCustomerCheckedIds([]); const sid = selectedItemId; setSelectedItemId(null); setTimeout(() => setSelectedItemId(sid), 50); } catch { - toast.error("삭제에 실패했습니다."); + toast.error("연결 해제에 실패했습니다."); } };