import React, { useMemo } from "react"; import { useParams, useNavigate } from "react-router-dom"; import { useQuery } from "@tanstack/react-query"; import { mockProductionOrders } from "../../../mocks/mockProductionOrders"; import { MrpProductionOrder, MrpProductionOrderMaterial, } from "../../../types/mrp"; import { FaCog, FaCalendarAlt, FaClipboardList, FaTruck, FaMoneyBillWave, FaArrowLeft, FaExclamationTriangle, } from "react-icons/fa"; import StatusBadge from "../../../components/common/StatusBadge"; import { getPriorityColor } from "../../../utils/erp"; const ProductionOrderView: React.FC = () => { const { id } = useParams(); const navigate = useNavigate(); const { data: productionOrder, isLoading } = useQuery({ queryKey: ["production-order", id], queryFn: async () => { await new Promise((r) => setTimeout(r, 200)); return mockProductionOrders.find((p) => p.id === id) as | MrpProductionOrder | undefined; }, enabled: !!id, }); const materials: MrpProductionOrderMaterial[] = useMemo( () => productionOrder?.materials || [], [productionOrder] ); if (isLoading) { return (

Üretim emri yükleniyor...

); } if (!productionOrder) { return (

Üretim Emri Bulunamadı

İstenen üretim emri mevcut değil veya silinmiş olabilir.

); } const getProgressPercentage = () => { if (productionOrder.plannedQuantity === 0) return 0; return Math.round( (productionOrder.confirmedQuantity / productionOrder.plannedQuantity) * 100 ); }; return (
{/* Header */}

Üretim Emri Detayları

{productionOrder.orderNumber} - Detaylı bilgiler

{/* Order Header Card */}
Üretim Emri No
{productionOrder.orderNumber}
Durum
Öncelik
{productionOrder.priority}
Tür
{productionOrder.orderType}
İlerleme
{getProgressPercentage()}%
{/* Progress Bar */}
Üretim İlerlemesi
{productionOrder.confirmedQuantity} /{" "} {productionOrder.plannedQuantity} adet
{productionOrder.customerRequirement && (
Müşteri Talebi

{productionOrder.customerRequirement}

)}
{/* Info Cards Grid */}
{/* Quantities Card */}

Miktar Bilgileri

Planlanan: {productionOrder.plannedQuantity}
Üretilen: {productionOrder.confirmedQuantity}
Gereken: {productionOrder.requiredQuantity}
Fire: {productionOrder.scrapQuantity}
{/* Schedule Card */}

Zamanlama

Plan Başlangıç
{new Date(productionOrder.plannedStartDate).toLocaleDateString( "tr-TR", { weekday: "long", year: "numeric", month: "long", day: "numeric", } )}
Plan Bitiş
{new Date(productionOrder.plannedEndDate).toLocaleDateString( "tr-TR", { weekday: "long", year: "numeric", month: "long", day: "numeric", } )}
{productionOrder.actualStartDate && (
Gerçek Başlangıç
{new Date(productionOrder.actualStartDate).toLocaleDateString( "tr-TR", { weekday: "long", year: "numeric", month: "long", day: "numeric", } )}
)} {productionOrder.actualEndDate && (
Gerçek Bitiş
{new Date(productionOrder.actualEndDate).toLocaleDateString( "tr-TR", { weekday: "long", year: "numeric", month: "long", day: "numeric", } )}
)}
{/* Costs Card */}

Maliyet Bilgileri

Planlanan Maliyet
{new Intl.NumberFormat("tr-TR", { style: "currency", currency: productionOrder.currency, }).format(productionOrder.plannedCost)}
Gerçekleşen Maliyet
{new Intl.NumberFormat("tr-TR", { style: "currency", currency: productionOrder.currency, }).format(productionOrder.actualCost)}
Para Birimi
{productionOrder.currency}
{/* Metadata Card */}

Sistem Bilgileri

Oluşturulma
{new Date(productionOrder.creationTime).toLocaleDateString( "tr-TR", { year: "numeric", month: "short", day: "numeric" } )}
Son Güncelleme
{new Date( productionOrder.lastModificationTime ).toLocaleDateString("tr-TR", { year: "numeric", month: "short", day: "numeric", })}
{/* Materials List */}

Malzemeler

Üretim emrine bağlı malzeme satırları

{materials.length}
Malzeme
{materials.length === 0 ? (

Bu üretim emrine bağlı malzeme bulunmamaktadır.

) : (
{materials.map((m: MrpProductionOrderMaterial) => (
{m.salesOrder?.orderNumber || m.salesOrder?.id}
{m.material?.code || m.materialId} {" - "} {m.material?.name || "Malzeme adı bulunamadı"}
{m.customerRequirement && (
"{m.customerRequirement}"
)}
Planlanan
{m.plannedQuantity}
Üretilen
{m.confirmedQuantity}
Gereken
{m.requiredQuantity}
Fire
{m.scrapQuantity}
))}
)}
); }; export default ProductionOrderView;