feat: 밸브 분류 시스템 및 구매 관리 시스템 기초 구현
✅ 밸브 분류 시스템: - VALVE 상세 정보 저장 로직 추가 (backend/app/routers/files.py) - 프론트엔드 밸브 사양서 표시 로직 추가 (MaterialsPage.jsx) - 밸브 분류기 테스트 스크립트 및 데이터 (test_valve_classifier.py, test_valve_bom.csv) 🛒 구매 관리 시스템: - 구매 관리 테이블 스키마 (08_create_purchase_tables.sql) - 구매확정 페이지 컴포넌트 (PurchaseConfirmationPage.jsx) - MaterialsPage에 구매확정 버튼 추가 🎯 주요 기능: - 밸브 타입, 연결방식, 압력등급, 재질 분류 - 구매 품목 마스터, 주문 관리, 리비전 추적 - 파이프 절단손실 및 6M 단위 계산 준비
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
Divider
|
||||
} from '@mui/material';
|
||||
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
|
||||
import ShoppingCart from '@mui/icons-material/ShoppingCart';
|
||||
import { api } from '../api';
|
||||
|
||||
const MaterialsPage = () => {
|
||||
@@ -412,6 +413,67 @@ const MaterialsPage = () => {
|
||||
unit: 'EA',
|
||||
isLength: false
|
||||
};
|
||||
} else if (category === 'VALVE') {
|
||||
// VALVE: 타입 + 연결방식 + 압력등급 + 재질 + 사이즈
|
||||
const main_nom = material.main_nom || '';
|
||||
const valve_type = material.valve_details?.valve_type || 'VALVE';
|
||||
const valve_subtype = material.valve_details?.valve_subtype || '';
|
||||
const connection_method = material.valve_details?.connection_method || '';
|
||||
const pressure_rating = material.valve_details?.pressure_rating || '';
|
||||
const body_material = material.valve_details?.body_material || material.material_grade || '';
|
||||
const actuator_type = material.valve_details?.actuator_type || 'MANUAL';
|
||||
const fire_safe = material.valve_details?.fire_safe || false;
|
||||
|
||||
// 밸브 스펙 생성
|
||||
const valve_spec_parts = [];
|
||||
|
||||
// 밸브 타입 (GATE_VALVE, BALL_VALVE 등)
|
||||
if (valve_type && valve_type !== 'UNKNOWN') {
|
||||
valve_spec_parts.push(valve_type.replace('_', ' '));
|
||||
}
|
||||
|
||||
// 연결 방식 (FLANGED, THREADED, SOCKET_WELD 등)
|
||||
if (connection_method && connection_method !== 'UNKNOWN') {
|
||||
valve_spec_parts.push(connection_method.replace('_', ' '));
|
||||
}
|
||||
|
||||
// 압력 등급 (150LB, 300LB 등)
|
||||
if (pressure_rating && pressure_rating !== 'UNKNOWN') {
|
||||
valve_spec_parts.push(pressure_rating);
|
||||
}
|
||||
|
||||
// 작동 방식 (수동이 아닌 경우만 표시)
|
||||
if (actuator_type && actuator_type !== 'MANUAL' && actuator_type !== 'UNKNOWN') {
|
||||
valve_spec_parts.push(actuator_type.replace('_', ' '));
|
||||
}
|
||||
|
||||
// 특수 기능 (Fire Safe 등)
|
||||
if (fire_safe) {
|
||||
valve_spec_parts.push('FIRE SAFE');
|
||||
}
|
||||
|
||||
if (valve_subtype && valve_subtype !== 'UNKNOWN') {
|
||||
valve_spec_parts.push(valve_subtype);
|
||||
}
|
||||
|
||||
const full_valve_spec = valve_spec_parts.join(', ');
|
||||
|
||||
specKey = `${category}|${full_valve_spec}|${body_material}|${main_nom}`;
|
||||
specData = {
|
||||
category: 'VALVE',
|
||||
valve_type,
|
||||
valve_subtype,
|
||||
connection_method,
|
||||
pressure_rating,
|
||||
body_material,
|
||||
actuator_type,
|
||||
fire_safe,
|
||||
full_valve_spec,
|
||||
size_display: main_nom,
|
||||
main_nom,
|
||||
unit: 'EA',
|
||||
isLength: false
|
||||
};
|
||||
} else {
|
||||
// 기타 자재: 기본 분류
|
||||
const material_spec = material.material_grade || '';
|
||||
@@ -515,14 +577,30 @@ const MaterialsPage = () => {
|
||||
<Box sx={{ maxWidth: 1400, mx: 'auto', mt: 4, px: 2 }}>
|
||||
{/* 헤더 */}
|
||||
<Box sx={{ mb: 3 }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
startIcon={<ArrowBackIcon />}
|
||||
onClick={() => navigate(-1)}
|
||||
sx={{ mb: 2 }}
|
||||
>
|
||||
뒤로가기
|
||||
</Button>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', mb: 2 }}>
|
||||
<Button
|
||||
variant="outlined"
|
||||
startIcon={<ArrowBackIcon />}
|
||||
onClick={() => navigate(-1)}
|
||||
>
|
||||
뒤로가기
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="contained"
|
||||
color="success"
|
||||
size="large"
|
||||
startIcon={<ShoppingCart />}
|
||||
onClick={() => {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
navigate(`/purchase-confirmation?${params.toString()}`);
|
||||
}}
|
||||
disabled={materialSpecs.length === 0}
|
||||
sx={{ minWidth: 150 }}
|
||||
>
|
||||
구매 확정
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
<Typography variant="h4" component="h1" gutterBottom>
|
||||
📋 자재 사양서
|
||||
@@ -644,7 +722,18 @@ const MaterialsPage = () => {
|
||||
<TableCell align="right"><strong>수량</strong></TableCell>
|
||||
</>
|
||||
)}
|
||||
{!['PIPE', 'FITTING', 'FLANGE', 'GASKET', 'BOLT', 'INSTRUMENT'].includes(category) && (
|
||||
{category === 'VALVE' && (
|
||||
<>
|
||||
<TableCell><strong>밸브 타입</strong></TableCell>
|
||||
<TableCell><strong>연결방식</strong></TableCell>
|
||||
<TableCell><strong>압력등급</strong></TableCell>
|
||||
<TableCell><strong>재질</strong></TableCell>
|
||||
<TableCell><strong>사이즈</strong></TableCell>
|
||||
<TableCell><strong>작동방식</strong></TableCell>
|
||||
<TableCell align="right"><strong>수량</strong></TableCell>
|
||||
</>
|
||||
)}
|
||||
{!['PIPE', 'FITTING', 'FLANGE', 'GASKET', 'BOLT', 'INSTRUMENT', 'VALVE'].includes(category) && (
|
||||
<>
|
||||
<TableCell><strong>재질</strong></TableCell>
|
||||
<TableCell><strong>사이즈</strong></TableCell>
|
||||
@@ -787,7 +876,47 @@ const MaterialsPage = () => {
|
||||
</TableCell>
|
||||
</>
|
||||
)}
|
||||
{(!['PIPE', 'FITTING', 'FLANGE', 'GASKET', 'BOLT', 'INSTRUMENT'].includes(category)) && (
|
||||
{category === 'VALVE' && (
|
||||
<>
|
||||
<TableCell>
|
||||
<Typography variant="body2" sx={{ fontWeight: 'bold' }}>
|
||||
{spec.valve_type?.replace('_', ' ') || 'VALVE'}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography variant="body2">
|
||||
{spec.connection_method?.replace('_', ' ') || 'Unknown'}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography variant="body2">
|
||||
{spec.pressure_rating || 'Unknown'}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography variant="body2">
|
||||
{spec.body_material || 'Unknown'}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography variant="body2">
|
||||
{spec.size_display || 'Unknown'}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography variant="body2">
|
||||
{spec.actuator_type?.replace('_', ' ') || 'MANUAL'}
|
||||
{spec.fire_safe && ' + FIRE SAFE'}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
<TableCell align="right">
|
||||
<Typography variant="body2" fontWeight="bold">
|
||||
{spec.totalQuantity} {spec.unit}
|
||||
</Typography>
|
||||
</TableCell>
|
||||
</>
|
||||
)}
|
||||
{(!['PIPE', 'FITTING', 'FLANGE', 'GASKET', 'BOLT', 'INSTRUMENT', 'VALVE'].includes(category)) && (
|
||||
<>
|
||||
<TableCell>{spec.material_spec || 'Unknown'}</TableCell>
|
||||
<TableCell>{spec.size_display || 'Unknown'}</TableCell>
|
||||
|
||||
391
frontend/src/pages/PurchaseConfirmationPage.jsx
Normal file
391
frontend/src/pages/PurchaseConfirmationPage.jsx
Normal file
@@ -0,0 +1,391 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { useLocation, useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
Box,
|
||||
Card,
|
||||
CardContent,
|
||||
Typography,
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableContainer,
|
||||
TableHead,
|
||||
TableRow,
|
||||
Paper,
|
||||
Button,
|
||||
TextField,
|
||||
Chip,
|
||||
Alert,
|
||||
IconButton,
|
||||
Dialog,
|
||||
DialogTitle,
|
||||
DialogContent,
|
||||
DialogActions,
|
||||
Grid,
|
||||
Divider
|
||||
} from '@mui/material';
|
||||
import {
|
||||
ArrowBack,
|
||||
Edit,
|
||||
Check,
|
||||
Close,
|
||||
ShoppingCart,
|
||||
CompareArrows,
|
||||
Warning
|
||||
} from '@mui/icons-material';
|
||||
import { api } from '../api';
|
||||
|
||||
const PurchaseConfirmationPage = () => {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
const [purchaseItems, setPurchaseItems] = useState([]);
|
||||
const [revisionComparison, setRevisionComparison] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [editingItem, setEditingItem] = useState(null);
|
||||
const [confirmDialog, setConfirmDialog] = useState(false);
|
||||
|
||||
// URL에서 job_no, revision 정보 가져오기
|
||||
const searchParams = new URLSearchParams(location.search);
|
||||
const jobNo = searchParams.get('job_no');
|
||||
const revision = searchParams.get('revision');
|
||||
const filename = searchParams.get('filename');
|
||||
const previousRevision = searchParams.get('prev_revision');
|
||||
|
||||
useEffect(() => {
|
||||
if (jobNo && revision) {
|
||||
loadPurchaseItems();
|
||||
if (previousRevision) {
|
||||
loadRevisionComparison();
|
||||
}
|
||||
}
|
||||
}, [jobNo, revision, previousRevision]);
|
||||
|
||||
const loadPurchaseItems = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await api.get('/purchase/items/calculate', {
|
||||
params: { job_no: jobNo, revision: revision }
|
||||
});
|
||||
setPurchaseItems(response.data.items || []);
|
||||
} catch (error) {
|
||||
console.error('구매 품목 로딩 실패:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const loadRevisionComparison = async () => {
|
||||
try {
|
||||
const response = await api.get('/purchase/revision-diff', {
|
||||
params: {
|
||||
job_no: jobNo,
|
||||
current_revision: revision,
|
||||
previous_revision: previousRevision
|
||||
}
|
||||
});
|
||||
setRevisionComparison(response.data.comparison);
|
||||
} catch (error) {
|
||||
console.error('리비전 비교 실패:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const updateItemQuantity = async (itemId, field, value) => {
|
||||
try {
|
||||
await api.patch(`/purchase/items/${itemId}`, {
|
||||
[field]: parseFloat(value)
|
||||
});
|
||||
|
||||
// 로컬 상태 업데이트
|
||||
setPurchaseItems(prev =>
|
||||
prev.map(item =>
|
||||
item.id === itemId
|
||||
? { ...item, [field]: parseFloat(value) }
|
||||
: item
|
||||
)
|
||||
);
|
||||
|
||||
setEditingItem(null);
|
||||
} catch (error) {
|
||||
console.error('수량 업데이트 실패:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const confirmPurchase = async () => {
|
||||
try {
|
||||
const response = await api.post('/purchase/orders/create', {
|
||||
job_no: jobNo,
|
||||
revision: revision,
|
||||
items: purchaseItems.map(item => ({
|
||||
purchase_item_id: item.id,
|
||||
ordered_quantity: item.calculated_qty,
|
||||
required_date: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000) // 30일 후
|
||||
}))
|
||||
});
|
||||
|
||||
alert('구매 주문이 생성되었습니다!');
|
||||
navigate('/materials', {
|
||||
state: { message: '구매 주문 생성 완료' }
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('구매 주문 생성 실패:', error);
|
||||
alert('구매 주문 생성에 실패했습니다.');
|
||||
}
|
||||
};
|
||||
|
||||
const getCategoryColor = (category) => {
|
||||
const colors = {
|
||||
'PIPE': 'primary',
|
||||
'FITTING': 'secondary',
|
||||
'VALVE': 'success',
|
||||
'FLANGE': 'warning',
|
||||
'BOLT': 'info',
|
||||
'GASKET': 'error',
|
||||
'INSTRUMENT': 'purple'
|
||||
};
|
||||
return colors[category] || 'default';
|
||||
};
|
||||
|
||||
const formatPipeInfo = (item) => {
|
||||
if (item.category !== 'PIPE') return null;
|
||||
|
||||
return (
|
||||
<Box sx={{ mt: 1 }}>
|
||||
<Typography variant="caption" color="textSecondary">
|
||||
절단손실: {item.cutting_loss || 0}mm |
|
||||
구매: {item.pipes_count || 0}본 |
|
||||
여유분: {item.waste_length || 0}mm
|
||||
</Typography>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ p: 3 }}>
|
||||
{/* 헤더 */}
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', mb: 3 }}>
|
||||
<IconButton onClick={() => navigate(-1)} sx={{ mr: 2 }}>
|
||||
<ArrowBack />
|
||||
</IconButton>
|
||||
<Box sx={{ flex: 1 }}>
|
||||
<Typography variant="h4" gutterBottom>
|
||||
🛒 구매 확정
|
||||
</Typography>
|
||||
<Typography variant="h6" color="primary">
|
||||
Job: {jobNo} | {filename} | {revision}
|
||||
</Typography>
|
||||
</Box>
|
||||
<Button
|
||||
variant="contained"
|
||||
startIcon={<ShoppingCart />}
|
||||
onClick={() => setConfirmDialog(true)}
|
||||
size="large"
|
||||
disabled={purchaseItems.length === 0}
|
||||
>
|
||||
구매 주문 생성
|
||||
</Button>
|
||||
</Box>
|
||||
|
||||
{/* 리비전 비교 알림 */}
|
||||
{revisionComparison && (
|
||||
<Alert
|
||||
severity={revisionComparison.has_changes ? "warning" : "info"}
|
||||
sx={{ mb: 3 }}
|
||||
icon={<CompareArrows />}
|
||||
>
|
||||
<Typography variant="body2">
|
||||
<strong>리비전 변경사항:</strong> {revisionComparison.summary}
|
||||
</Typography>
|
||||
{revisionComparison.additional_items && (
|
||||
<Typography variant="body2" sx={{ mt: 1 }}>
|
||||
추가 구매 필요: {revisionComparison.additional_items}개 품목
|
||||
</Typography>
|
||||
)}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
{/* 구매 품목 테이블 */}
|
||||
{purchaseItems.map(item => (
|
||||
<Card key={item.id} sx={{ mb: 2 }}>
|
||||
<CardContent>
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
|
||||
<Chip
|
||||
label={item.category}
|
||||
color={getCategoryColor(item.category)}
|
||||
sx={{ mr: 2 }}
|
||||
/>
|
||||
<Typography variant="h6" sx={{ flex: 1 }}>
|
||||
{item.specification}
|
||||
</Typography>
|
||||
{item.is_additional && (
|
||||
<Chip
|
||||
label="추가 구매"
|
||||
color="warning"
|
||||
variant="outlined"
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
|
||||
<Grid container spacing={3}>
|
||||
{/* BOM 수량 */}
|
||||
<Grid item xs={12} md={3}>
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
BOM 필요량
|
||||
</Typography>
|
||||
<Typography variant="h6">
|
||||
{item.bom_quantity} {item.unit}
|
||||
</Typography>
|
||||
{formatPipeInfo(item)}
|
||||
</Grid>
|
||||
|
||||
{/* 구매 수량 */}
|
||||
<Grid item xs={12} md={3}>
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
구매 수량
|
||||
</Typography>
|
||||
{editingItem === item.id ? (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
<TextField
|
||||
value={item.calculated_qty}
|
||||
onChange={(e) =>
|
||||
setPurchaseItems(prev =>
|
||||
prev.map(i =>
|
||||
i.id === item.id
|
||||
? { ...i, calculated_qty: parseFloat(e.target.value) || 0 }
|
||||
: i
|
||||
)
|
||||
)
|
||||
}
|
||||
size="small"
|
||||
type="number"
|
||||
sx={{ width: 100 }}
|
||||
/>
|
||||
<IconButton
|
||||
size="small"
|
||||
color="primary"
|
||||
onClick={() => updateItemQuantity(item.id, 'calculated_qty', item.calculated_qty)}
|
||||
>
|
||||
<Check />
|
||||
</IconButton>
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={() => setEditingItem(null)}
|
||||
>
|
||||
<Close />
|
||||
</IconButton>
|
||||
</Box>
|
||||
) : (
|
||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
|
||||
<Typography variant="h6" color="primary">
|
||||
{item.calculated_qty} {item.unit}
|
||||
</Typography>
|
||||
<IconButton
|
||||
size="small"
|
||||
onClick={() => setEditingItem(item.id)}
|
||||
>
|
||||
<Edit />
|
||||
</IconButton>
|
||||
</Box>
|
||||
)}
|
||||
</Grid>
|
||||
|
||||
{/* 이미 구매한 수량 */}
|
||||
{previousRevision && (
|
||||
<Grid item xs={12} md={3}>
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
기구매 수량
|
||||
</Typography>
|
||||
<Typography variant="h6">
|
||||
{item.purchased_quantity || 0} {item.unit}
|
||||
</Typography>
|
||||
</Grid>
|
||||
)}
|
||||
|
||||
{/* 추가 구매 필요량 */}
|
||||
{previousRevision && (
|
||||
<Grid item xs={12} md={3}>
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
추가 구매 필요
|
||||
</Typography>
|
||||
<Typography
|
||||
variant="h6"
|
||||
color={item.additional_needed > 0 ? "error" : "success"}
|
||||
>
|
||||
{Math.max(item.additional_needed || 0, 0)} {item.unit}
|
||||
</Typography>
|
||||
</Grid>
|
||||
)}
|
||||
</Grid>
|
||||
|
||||
{/* 여유율 및 최소 주문 정보 */}
|
||||
<Box sx={{ mt: 2, p: 2, bgcolor: 'grey.50', borderRadius: 1 }}>
|
||||
<Grid container spacing={2}>
|
||||
<Grid item xs={6} md={3}>
|
||||
<Typography variant="caption" color="textSecondary">
|
||||
여유율
|
||||
</Typography>
|
||||
<Typography variant="body2">
|
||||
{((item.safety_factor || 1) - 1) * 100}%
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={6} md={3}>
|
||||
<Typography variant="caption" color="textSecondary">
|
||||
최소 주문
|
||||
</Typography>
|
||||
<Typography variant="body2">
|
||||
{item.min_order_qty || 0} {item.unit}
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={6} md={3}>
|
||||
<Typography variant="caption" color="textSecondary">
|
||||
예상 여유분
|
||||
</Typography>
|
||||
<Typography variant="body2">
|
||||
{(item.calculated_qty - item.bom_quantity).toFixed(1)} {item.unit}
|
||||
</Typography>
|
||||
</Grid>
|
||||
<Grid item xs={6} md={3}>
|
||||
<Typography variant="caption" color="textSecondary">
|
||||
활용률
|
||||
</Typography>
|
||||
<Typography variant="body2">
|
||||
{((item.bom_quantity / item.calculated_qty) * 100).toFixed(1)}%
|
||||
</Typography>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Box>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
|
||||
{/* 구매 주문 확인 다이얼로그 */}
|
||||
<Dialog open={confirmDialog} onClose={() => setConfirmDialog(false)}>
|
||||
<DialogTitle>구매 주문 생성 확인</DialogTitle>
|
||||
<DialogContent>
|
||||
<Typography variant="body2" sx={{ mb: 2 }}>
|
||||
총 {purchaseItems.length}개 품목에 대한 구매 주문을 생성하시겠습니까?
|
||||
</Typography>
|
||||
|
||||
{revisionComparison && revisionComparison.has_changes && (
|
||||
<Alert severity="warning" sx={{ mb: 2 }}>
|
||||
리비전 변경으로 인한 추가 구매가 포함되어 있습니다.
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
<Typography variant="body2" color="textSecondary">
|
||||
구매 주문 생성 후에는 수량 변경이 제한됩니다.
|
||||
</Typography>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button onClick={() => setConfirmDialog(false)}>
|
||||
취소
|
||||
</Button>
|
||||
<Button onClick={confirmPurchase} variant="contained">
|
||||
주문 생성
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default PurchaseConfirmationPage;
|
||||
Reference in New Issue
Block a user