import React, { useState, useEffect } from "react"; import { FaTimes, FaSave, FaCreditCard, FaStar } from "react-icons/fa"; import { SupplierCardTypeEnum, SupplierTypeEnum } from "../../../types/mm"; import { mockBusinessPartyNew } from "../../../mocks/mockBusinessParties"; import { BusinessParty, PartyType, PaymentTerms } from "../../../types/common"; interface SupplierCardModalProps { isOpen: boolean; onClose: () => void; onSave: (supplierCard: BusinessParty) => void; supplierCard?: BusinessParty | null; mode: "create" | "view" | "edit"; } const SupplierCardModal: React.FC = ({ isOpen, onClose, onSave, supplierCard, mode, }) => { const [formData, setFormData] = useState>(mockBusinessPartyNew); useEffect(() => { if (mode === "create") { setFormData(mockBusinessPartyNew); } else if (supplierCard) { setFormData(supplierCard); } }, [supplierCard, mode]); const handleInputChange = ( e: React.ChangeEvent< HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement > ) => { const { name, value, type } = e.target; setFormData((prev) => ({ ...prev, [name]: type === "number" ? parseFloat(value) || 0 : type === "checkbox" ? (e.target as HTMLInputElement).checked : value, })); }; const handleSpecialConditionsChange = (value: string) => { const conditions = value .split("\n") .filter((condition) => condition.trim() !== ""); setFormData((prev) => ({ ...prev, specialConditions: conditions, })); }; const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (mode !== "view") { const newSupplierCard: BusinessParty = { id: supplierCard?.id || `SC-${Date.now()}`, code: formData.code || "", cardNumber: formData.cardNumber || `SC-${new Date().getFullYear()}-${Date.now().toString().slice(-3)}`, cardType: formData.cardType || SupplierCardTypeEnum.Standard, validFrom: formData.validFrom || new Date(), validTo: formData.validTo, creditLimit: formData.creditLimit || 0, currentBalance: formData.currentBalance || 0, paymentTerms: formData.paymentTerms || PaymentTerms.Net30, discountRate: formData.discountRate, specialConditions: formData.specialConditions || [], isActive: formData.isActive ?? true, lastOrderDate: formData.lastOrderDate, performanceMetrics: formData.performanceMetrics || { deliveryPerformance: 0, qualityRating: 0, priceCompetitiveness: 0, responsiveness: 0, complianceRating: 0, overallScore: 0, lastEvaluationDate: new Date(), }, creationTime: supplierCard?.creationTime || new Date(), lastModificationTime: new Date(), supplierType: SupplierTypeEnum.Material, name: "", currency: "", certifications: [], bankAccounts: [], contacts: [], partyType: PartyType.Supplier, }; onSave(newSupplierCard); } onClose(); }; if (!isOpen) return null; const isReadOnly = mode === "view"; const modalTitle = mode === "create" ? "Yeni Tedarikçi Kartı" : mode === "edit" ? "Tedarikçi Kartını Düzenle" : "Tedarikçi Kartı Detayları"; return (

{modalTitle}

{/* Temel Bilgiler */}

Temel Bilgiler

{/* Mali Bilgiler */}

Mali Bilgiler

{/* Özel Koşullar */}

Özel Koşullar