erp-platform/ui/src/views/supplychain/components/OrderManagementForm.tsx

744 lines
31 KiB
TypeScript
Raw Normal View History

2025-09-15 21:42:39 +00:00
import React, { useEffect, useState } from 'react'
import { useParams, useNavigate } from 'react-router-dom'
2025-09-15 09:31:47 +00:00
import {
FaArrowLeft,
FaSave,
FaTimes,
FaShoppingCart,
FaCalendar,
FaDollarSign,
FaPlus,
FaTrash,
FaMapMarkerAlt,
FaUser,
2025-09-15 21:42:39 +00:00
} from 'react-icons/fa'
import { MmPurchaseOrder, OrderStatusEnum, MmPurchaseOrderItem } from '../../../types/mm'
import { mockMaterials } from '../../../mocks/mockMaterials'
import { mockBusinessParties } from '../../../mocks/mockBusinessParties'
import { mockPurchaseOrders } from '../../../mocks/mockPurchaseOrders'
import { Address, PaymentTerms } from '../../../types/common'
import { Container } from '@/components/shared'
2025-09-16 12:33:57 +00:00
import { ROUTES_ENUM } from '@/routes/route.constant'
2025-09-17 09:46:58 +00:00
import { getOrderStatusText, getPaymentTermsText } from '@/utils/erp'
import { mockCurrencies } from '@/mocks/mockCurrencies'
2025-09-15 09:31:47 +00:00
const OrderManagementForm: React.FC = () => {
2025-09-15 21:42:39 +00:00
const { id } = useParams<{ id: string }>()
const navigate = useNavigate()
const isEdit = id !== undefined && id !== 'new'
const isView = window.location.pathname.includes('/view/')
2025-09-15 09:31:47 +00:00
// Yeni sipariş için başlangıç şablonu
const newOrderDefaults: Partial<MmPurchaseOrder> = {
2025-09-15 21:42:39 +00:00
orderNumber: '',
supplierId: '',
2025-09-15 09:31:47 +00:00
orderDate: new Date(),
deliveryDate: new Date(),
status: OrderStatusEnum.Draft,
paymentTerms: PaymentTerms.Net30,
2025-09-15 21:42:39 +00:00
currency: 'TRY',
2025-09-15 09:31:47 +00:00
exchangeRate: 1,
subtotal: 0,
taxAmount: 0,
totalAmount: 0,
items: [],
deliveryAddress: {
2025-09-15 21:42:39 +00:00
street: '',
city: '',
state: '',
postalCode: '',
country: 'Türkiye',
2025-09-15 09:31:47 +00:00
},
2025-09-15 21:42:39 +00:00
terms: '',
notes: '',
2025-09-15 09:31:47 +00:00
receipts: [],
2025-09-15 21:42:39 +00:00
}
2025-09-15 09:31:47 +00:00
// İlk state (isEdit vs new)
const [formData, setFormData] = useState<Partial<MmPurchaseOrder>>(() => {
if (isEdit) {
2025-09-15 21:42:39 +00:00
const po = mockPurchaseOrders.find((o) => o.id === id)
return { ...po }
2025-09-15 09:31:47 +00:00
}
2025-09-15 21:42:39 +00:00
return { ...newOrderDefaults }
})
2025-09-15 09:31:47 +00:00
// id değişirse formu güncelle
useEffect(() => {
if (isEdit) {
2025-09-15 21:42:39 +00:00
const po = mockPurchaseOrders.find((o) => o.id === id)
setFormData(po ? { ...po } : { ...newOrderDefaults })
2025-09-15 09:31:47 +00:00
} else {
2025-09-15 21:42:39 +00:00
setFormData({ ...newOrderDefaults })
2025-09-15 09:31:47 +00:00
}
// eslint-disable-next-line react-hooks/exhaustive-deps
2025-09-15 21:42:39 +00:00
}, [id, isEdit])
2025-09-15 09:31:47 +00:00
const handleInputChange = (
2025-09-15 21:42:39 +00:00
e: React.ChangeEvent<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement>,
2025-09-15 09:31:47 +00:00
) => {
2025-09-15 21:42:39 +00:00
const { name, value, type } = e.target
2025-09-15 09:31:47 +00:00
setFormData((prev) => ({
...prev,
[name]:
2025-09-15 21:42:39 +00:00
type === 'number' ? parseFloat(value) || 0 : type === 'date' ? new Date(value) : value,
}))
}
2025-09-15 09:31:47 +00:00
const handleAddressChange = (field: keyof Address, value: string) => {
setFormData((prev) => ({
...prev,
deliveryAddress: {
...prev.deliveryAddress!,
[field]: value,
},
2025-09-15 21:42:39 +00:00
}))
}
2025-09-15 09:31:47 +00:00
const addOrderItem = () => {
const newItem: MmPurchaseOrderItem = {
id: `item-${Date.now()}`,
2025-09-15 21:42:39 +00:00
orderId: formData.id || '',
materialId: '',
description: '',
2025-09-15 09:31:47 +00:00
quantity: 0,
unitPrice: 0,
totalPrice: 0,
deliveryDate: new Date(),
receivedQuantity: 0,
deliveredQuantity: 0,
remainingQuantity: 0,
2025-09-15 21:42:39 +00:00
unit: '',
}
2025-09-15 09:31:47 +00:00
setFormData((prev) => ({
...prev,
items: [...(prev.items || []), newItem],
2025-09-15 21:42:39 +00:00
}))
}
2025-09-15 09:31:47 +00:00
const removeOrderItem = (index: number) => {
setFormData((prev) => ({
...prev,
items: prev.items?.filter((_, i) => i !== index) || [],
2025-09-15 21:42:39 +00:00
}))
calculateTotals()
}
2025-09-15 09:31:47 +00:00
const updateOrderItem = (
index: number,
field: keyof MmPurchaseOrderItem,
2025-09-15 21:42:39 +00:00
value: string | number | Date | undefined,
2025-09-15 09:31:47 +00:00
) => {
setFormData((prev) => {
const updatedItems =
prev.items?.map((item, i) => {
if (i === index) {
2025-09-15 21:42:39 +00:00
const updatedItem = { ...item, [field]: value }
2025-09-15 09:31:47 +00:00
// Auto-calculate total amount when quantity or unit price changes
2025-09-15 21:42:39 +00:00
if (field === 'quantity' || field === 'unitPrice') {
updatedItem.totalPrice = (updatedItem.quantity || 0) * (updatedItem.unitPrice || 0)
2025-09-15 09:31:47 +00:00
updatedItem.remainingQuantity =
2025-09-15 21:42:39 +00:00
updatedItem.quantity - (updatedItem.receivedQuantity || 0)
2025-09-15 09:31:47 +00:00
}
2025-09-15 21:42:39 +00:00
return updatedItem
2025-09-15 09:31:47 +00:00
}
2025-09-15 21:42:39 +00:00
return item
}) || []
2025-09-15 09:31:47 +00:00
return {
...prev,
items: updatedItems,
2025-09-15 21:42:39 +00:00
}
})
2025-09-15 09:31:47 +00:00
// Recalculate totals
2025-09-15 21:42:39 +00:00
setTimeout(calculateTotals, 0)
}
2025-09-15 09:31:47 +00:00
const calculateTotals = () => {
2025-09-15 21:42:39 +00:00
const subtotal = formData.items?.reduce((sum, item) => sum + (item.totalPrice || 0), 0) || 0
const taxAmount = subtotal * 0.18 // %18 KDV
const totalAmount = subtotal + taxAmount
2025-09-15 09:31:47 +00:00
setFormData((prev) => ({
...prev,
subtotal,
taxAmount,
totalAmount,
2025-09-15 21:42:39 +00:00
}))
}
2025-09-15 09:31:47 +00:00
const handleSubmit = (e: React.FormEvent) => {
2025-09-15 21:42:39 +00:00
e.preventDefault()
2025-09-15 09:31:47 +00:00
// TODO: Implement save logic
2025-09-15 21:42:39 +00:00
console.log('Saving purchase order:', formData)
2025-09-16 12:33:57 +00:00
navigate(ROUTES_ENUM.protected.supplychain.orders)
2025-09-15 21:42:39 +00:00
}
2025-09-15 09:31:47 +00:00
const handleCancel = () => {
2025-09-16 12:33:57 +00:00
navigate(ROUTES_ENUM.protected.supplychain.orders)
2025-09-15 21:42:39 +00:00
}
2025-09-15 09:31:47 +00:00
2025-09-15 21:42:39 +00:00
const isReadOnly = isView
2025-09-15 09:31:47 +00:00
const pageTitle = isEdit
2025-09-15 21:42:39 +00:00
? 'Satınalma Siparişini Düzenle'
2025-09-15 09:31:47 +00:00
: isView
2025-09-15 21:42:39 +00:00
? 'Satınalma Siparişi Detayları'
: 'Yeni Satınalma Siparişi'
2025-09-15 09:31:47 +00:00
return (
2025-09-15 21:42:39 +00:00
<Container>
<div className="space-y-2">
2025-09-15 09:31:47 +00:00
{/* Header */}
<div className="bg-white rounded-lg shadow-md p-2 mb-2">
<div className="flex items-center justify-between">
<div className="flex items-center">
<button
onClick={handleCancel}
className="mr-2 p-1.5 text-gray-400 hover:text-gray-600"
>
<FaArrowLeft />
</button>
2025-09-15 21:02:48 +00:00
<h2 className="text-2xl font-bold text-gray-900">{pageTitle}</h2>
2025-09-15 09:31:47 +00:00
</div>
<div className="flex space-x-2">
<button
onClick={handleCancel}
className="px-3 py-1.5 border border-gray-300 rounded-md text-gray-700 hover:bg-gray-50 flex items-center"
>
<FaTimes className="mr-2" />
2025-09-15 21:42:39 +00:00
{isView ? 'Kapat' : 'İptal'}
2025-09-15 09:31:47 +00:00
</button>
{!isView && (
<button
onClick={handleSubmit}
className="px-3 py-1.5 bg-blue-600 text-white rounded-md hover:bg-blue-700 flex items-center"
>
<FaSave className="mr-2" />
Kaydet
</button>
)}
</div>
</div>
</div>
<form onSubmit={handleSubmit}>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-4">
{/* Ana İçerik */}
<div className="lg:col-span-2">
{/* Sipariş Bilgileri */}
<div className="bg-white rounded-lg shadow-md p-4 mb-4">
<h3 className="text-base font-medium text-gray-900 mb-3 flex items-center">
<FaShoppingCart className="mr-2 text-blue-600" />
Sipariş Bilgileri
</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
<div>
<label className="block text-sm font-medium text-gray-700">
Sipariş Numarası
</label>
<input
type="text"
name="orderNumber"
2025-09-15 21:42:39 +00:00
value={formData.orderNumber || ''}
2025-09-15 09:31:47 +00:00
onChange={handleInputChange}
readOnly={isReadOnly || isEdit}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
<label className="flex items-center text-sm font-medium text-gray-700">
<FaUser className="mr-1" />
Tedarikçi
</label>
<select
name="supplierId"
2025-09-15 21:42:39 +00:00
value={formData.supplierId || ''}
2025-09-15 09:31:47 +00:00
onChange={handleInputChange}
disabled={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
required
>
<option value="">Tedarikçi Seçiniz</option>
{mockBusinessParties.map((supplier) => (
<option key={supplier.id} value={supplier.id}>
{supplier.name} ({supplier.code})
</option>
))}
</select>
</div>
<div>
<label className="flex items-center text-sm font-medium text-gray-700">
<FaCalendar className="mr-1" />
Sipariş Tarihi
</label>
<input
type="date"
name="orderDate"
value={
formData.orderDate
2025-09-15 21:42:39 +00:00
? new Date(formData.orderDate).toISOString().split('T')[0]
: ''
2025-09-15 09:31:47 +00:00
}
onChange={handleInputChange}
readOnly={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
<label className="flex items-center text-sm font-medium text-gray-700">
<FaCalendar className="mr-1" />
Teslimat Tarihi
</label>
<input
type="date"
name="deliveryDate"
value={
formData.deliveryDate
2025-09-15 21:42:39 +00:00
? new Date(formData.deliveryDate).toISOString().split('T')[0]
: ''
2025-09-15 09:31:47 +00:00
}
onChange={handleInputChange}
readOnly={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
<label className="block text-sm font-medium text-gray-700">
Ödeme Koşulları
</label>
<select
name="paymentTerms"
value={formData.paymentTerms || PaymentTerms.Net30}
onChange={handleInputChange}
disabled={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
>
2025-09-17 09:46:58 +00:00
{Object.values(PaymentTerms).map((term) => (
<option key={term} value={term}>
{getPaymentTermsText(term)}
</option>
))}
2025-09-15 09:31:47 +00:00
</select>
</div>
<div>
2025-09-15 21:42:39 +00:00
<label className="block text-sm font-medium text-gray-700">Para Birimi</label>
2025-09-15 09:31:47 +00:00
<select
name="currency"
2025-09-15 21:42:39 +00:00
value={formData.currency || 'TRY'}
2025-09-15 09:31:47 +00:00
onChange={handleInputChange}
disabled={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
>
2025-09-17 09:46:58 +00:00
{mockCurrencies.map((currency) => (
<option key={currency.value} value={currency.value}>
{currency.value} - {currency.label}
</option>
))}
2025-09-15 09:31:47 +00:00
</select>
</div>
<div className="md:col-span-2">
<label className="block text-sm font-medium text-gray-700">
Şartlar ve Koşullar
</label>
<textarea
name="terms"
2025-09-15 21:42:39 +00:00
value={formData.terms || ''}
2025-09-15 09:31:47 +00:00
onChange={handleInputChange}
readOnly={isReadOnly}
rows={2}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div className="md:col-span-2">
2025-09-15 21:42:39 +00:00
<label className="block text-sm font-medium text-gray-700">Notlar</label>
2025-09-15 09:31:47 +00:00
<textarea
name="notes"
2025-09-15 21:42:39 +00:00
value={formData.notes || ''}
2025-09-15 09:31:47 +00:00
onChange={handleInputChange}
readOnly={isReadOnly}
rows={1}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
</div>
</div>
{/* Teslimat Adresi */}
<div className="bg-white rounded-lg shadow-md p-4 mb-4">
<h3 className="text-base font-medium text-gray-900 mb-3 flex items-center">
<FaMapMarkerAlt className="mr-2 text-green-600" />
Teslimat Adresi
</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
<div className="md:col-span-2">
2025-09-15 21:42:39 +00:00
<label className="block text-sm font-medium text-gray-700">Adres</label>
2025-09-15 09:31:47 +00:00
<input
type="text"
2025-09-15 21:42:39 +00:00
value={formData.deliveryAddress?.street || ''}
onChange={(e) => handleAddressChange('street', e.target.value)}
2025-09-15 09:31:47 +00:00
readOnly={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
2025-09-15 21:42:39 +00:00
<label className="block text-sm font-medium text-gray-700">Şehir</label>
2025-09-15 09:31:47 +00:00
<input
type="text"
2025-09-15 21:42:39 +00:00
value={formData.deliveryAddress?.city || ''}
onChange={(e) => handleAddressChange('city', e.target.value)}
2025-09-15 09:31:47 +00:00
readOnly={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
2025-09-15 21:42:39 +00:00
<label className="block text-sm font-medium text-gray-700">İl/Bölge</label>
2025-09-15 09:31:47 +00:00
<input
type="text"
2025-09-15 21:42:39 +00:00
value={formData.deliveryAddress?.state || ''}
onChange={(e) => handleAddressChange('state', e.target.value)}
2025-09-15 09:31:47 +00:00
readOnly={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
2025-09-15 21:42:39 +00:00
<label className="block text-sm font-medium text-gray-700">Posta Kodu</label>
2025-09-15 09:31:47 +00:00
<input
type="text"
2025-09-15 21:42:39 +00:00
value={formData.deliveryAddress?.postalCode || ''}
onChange={(e) => handleAddressChange('postalCode', e.target.value)}
2025-09-15 09:31:47 +00:00
readOnly={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
2025-09-15 21:42:39 +00:00
<label className="block text-sm font-medium text-gray-700">Ülke</label>
2025-09-15 09:31:47 +00:00
<input
type="text"
2025-09-15 21:42:39 +00:00
value={formData.deliveryAddress?.country || ''}
onChange={(e) => handleAddressChange('country', e.target.value)}
2025-09-15 09:31:47 +00:00
readOnly={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
</div>
</div>
{/* Sipariş Kalemleri */}
<div className="bg-white rounded-lg shadow-md p-4">
<div className="flex items-center justify-between mb-4">
2025-09-15 21:42:39 +00:00
<h3 className="text-lg font-medium text-gray-900">Sipariş Kalemleri</h3>
2025-09-15 09:31:47 +00:00
{!isReadOnly && (
<button
type="button"
onClick={addOrderItem}
className="px-2.5 py-1.5 bg-blue-600 text-white rounded-md hover:bg-blue-700 flex items-center"
>
<FaPlus className="mr-2" />
Kalem Ekle
</button>
)}
</div>
<div className="space-y-3">
{formData.items?.map((item, index) => (
2025-09-15 21:42:39 +00:00
<div key={item.id} className="border rounded-lg p-3 bg-gray-50">
2025-09-15 09:31:47 +00:00
<div className="flex items-center justify-between mb-2">
2025-09-15 21:42:39 +00:00
<span className="text-sm font-medium text-gray-700">Kalem {index + 1}</span>
2025-09-15 09:31:47 +00:00
{!isReadOnly && (
<button
type="button"
onClick={() => removeOrderItem(index)}
className="text-red-600 hover:text-red-800"
>
<FaTrash />
</button>
)}
</div>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-2">
<div>
2025-09-15 21:42:39 +00:00
<label className="block text-xs font-medium text-gray-600">Malzeme</label>
2025-09-15 09:31:47 +00:00
<select
value={item.materialId}
2025-09-15 21:42:39 +00:00
onChange={(e) => updateOrderItem(index, 'materialId', e.target.value)}
2025-09-15 09:31:47 +00:00
disabled={isReadOnly}
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
>
<option value="">Malzeme Seçiniz</option>
{mockMaterials.map((material) => (
<option key={material.id} value={material.id}>
{material.name} ({material.code})
</option>
))}
</select>
</div>
<div className="lg:col-span-2">
<label className="block text-xs font-medium text-gray-600">
ıklama
</label>
<input
type="text"
value={item.description}
2025-09-15 21:42:39 +00:00
onChange={(e) => updateOrderItem(index, 'description', e.target.value)}
2025-09-15 09:31:47 +00:00
readOnly={isReadOnly}
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
2025-09-15 21:42:39 +00:00
<label className="block text-xs font-medium text-gray-600">Miktar</label>
2025-09-15 09:31:47 +00:00
<input
type="number"
value={item.quantity}
onChange={(e) =>
2025-09-15 21:42:39 +00:00
updateOrderItem(index, 'quantity', parseFloat(e.target.value) || 0)
2025-09-15 09:31:47 +00:00
}
readOnly={isReadOnly}
min="0"
step="0.01"
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
<label className="block text-xs font-medium text-gray-600">
Birim Fiyat
</label>
<input
type="number"
value={item.unitPrice}
onChange={(e) =>
2025-09-15 21:42:39 +00:00
updateOrderItem(index, 'unitPrice', parseFloat(e.target.value) || 0)
2025-09-15 09:31:47 +00:00
}
readOnly={isReadOnly}
min="0"
step="0.01"
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
<label className="block text-xs font-medium text-gray-600">
Toplam Tutar
</label>
<input
type="number"
value={item.totalPrice}
readOnly
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 bg-gray-100"
/>
</div>
<div>
<label className="block text-xs font-medium text-gray-600">
Teslimat Tarihi
</label>
<input
type="date"
value={
item.deliveryDate
2025-09-15 21:42:39 +00:00
? new Date(item.deliveryDate).toISOString().split('T')[0]
: ''
2025-09-15 09:31:47 +00:00
}
onChange={(e) =>
2025-09-15 21:42:39 +00:00
updateOrderItem(index, 'deliveryDate', new Date(e.target.value))
2025-09-15 09:31:47 +00:00
}
readOnly={isReadOnly}
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
<label className="block text-xs font-medium text-gray-600">
Teslim Alınan Miktar
</label>
<input
type="number"
value={item.receivedQuantity}
onChange={(e) =>
updateOrderItem(
index,
2025-09-15 21:42:39 +00:00
'receivedQuantity',
parseFloat(e.target.value) || 0,
2025-09-15 09:31:47 +00:00
)
}
readOnly={isReadOnly}
min="0"
step="0.01"
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div>
<label className="block text-xs font-medium text-gray-600">
Kalan Miktar
</label>
<input
type="number"
value={item.remainingQuantity}
readOnly
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 bg-gray-100"
/>
</div>
<div className="md:col-span-2 lg:col-span-3">
<label className="block text-xs font-medium text-gray-600">
Spesifikasyonlar
</label>
<input
type="text"
2025-09-15 21:42:39 +00:00
value={item.specifications || ''}
2025-09-15 09:31:47 +00:00
onChange={(e) =>
2025-09-15 21:42:39 +00:00
updateOrderItem(index, 'specifications', e.target.value)
2025-09-15 09:31:47 +00:00
}
readOnly={isReadOnly}
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
<div className="md:col-span-2 lg:col-span-3">
<label className="block text-xs font-medium text-gray-600">
Kalite Gereksinimleri
</label>
<input
type="text"
2025-09-15 21:42:39 +00:00
value={item.qualityRequirements || ''}
2025-09-15 09:31:47 +00:00
onChange={(e) =>
2025-09-15 21:42:39 +00:00
updateOrderItem(index, 'qualityRequirements', e.target.value)
2025-09-15 09:31:47 +00:00
}
readOnly={isReadOnly}
className="mt-1 block w-full text-sm border border-gray-300 rounded-md px-2 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
</div>
</div>
))}
{formData.items?.length === 0 && (
<div className="text-center text-gray-500 text-sm py-6">
Henüz sipariş kalemi eklenmedi
</div>
)}
</div>
</div>
</div>
{/* Yan Panel */}
<div className="space-y-4">
{/* Durum ve Tutar */}
<div className="bg-white rounded-lg shadow-md p-4">
2025-09-15 21:42:39 +00:00
<h3 className="text-lg font-medium text-gray-900 mb-3">Durum Bilgileri</h3>
2025-09-15 09:31:47 +00:00
<div className="space-y-4">
<div>
2025-09-15 21:42:39 +00:00
<label className="block text-sm font-medium text-gray-700">Durum</label>
2025-09-15 09:31:47 +00:00
<select
name="status"
value={formData.status || OrderStatusEnum.Draft}
onChange={handleInputChange}
disabled={isReadOnly}
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
>
2025-09-17 09:46:58 +00:00
{Object.values(OrderStatusEnum).map((status) => (
<option key={status} value={status}>
{getOrderStatusText(status)}
</option>
))}
2025-09-15 09:31:47 +00:00
</select>
</div>
<div>
2025-09-15 21:42:39 +00:00
<label className="block text-sm font-medium text-gray-700">Döviz Kuru</label>
2025-09-15 09:31:47 +00:00
<input
type="number"
name="exchangeRate"
value={formData.exchangeRate || 1}
onChange={handleInputChange}
readOnly={isReadOnly}
min="0"
step="0.0001"
className="mt-1 block w-full border border-gray-300 rounded-md px-2.5 py-1.5 focus:outline-none focus:ring-1 focus:ring-blue-500"
/>
</div>
</div>
</div>
{/* Tutar Özeti */}
<div className="bg-white rounded-lg shadow-md p-4">
<h3 className="text-base font-medium text-gray-900 mb-3 flex items-center">
<FaDollarSign className="mr-2 text-green-600" />
Tutar Özeti
</h3>
<div className="space-y-2">
<div className="flex justify-between">
<span className="text-sm text-gray-600">Ara Toplam:</span>
<span className="text-sm font-medium">
{formData.subtotal?.toLocaleString()} {formData.currency}
</span>
</div>
<div className="flex justify-between">
<span className="text-sm text-gray-600">KDV (%18):</span>
<span className="text-sm font-medium">
{formData.taxAmount?.toLocaleString()} {formData.currency}
</span>
</div>
<div className="border-t pt-2">
<div className="flex justify-between">
2025-09-15 21:42:39 +00:00
<span className="text-lg font-medium text-gray-900">Genel Toplam:</span>
2025-09-15 09:31:47 +00:00
<span className="text-lg font-bold text-green-600">
2025-09-15 21:42:39 +00:00
{formData.totalAmount?.toLocaleString()} {formData.currency}
2025-09-15 09:31:47 +00:00
</span>
</div>
</div>
</div>
</div>
{/* Sipariş Geçmişi (sadece görüntüleme) */}
{isView && formData.receipts && formData.receipts.length > 0 && (
<div className="bg-white rounded-lg shadow-md p-4">
2025-09-15 21:42:39 +00:00
<h3 className="text-base font-medium text-gray-900 mb-3">Teslimat Geçmişi</h3>
2025-09-15 09:31:47 +00:00
<div className="space-y-2">
{formData.receipts.map((receipt) => (
2025-09-15 21:42:39 +00:00
<div key={receipt.id} className="border-l-4 border-green-500 pl-4">
2025-09-15 09:31:47 +00:00
<div className="text-sm font-medium text-gray-900">
{receipt.receiptNumber}
</div>
<div className="text-xs text-gray-500">
2025-09-15 21:42:39 +00:00
{new Date(receipt.receiptDate).toLocaleDateString('tr-TR')}
2025-09-15 09:31:47 +00:00
</div>
2025-09-15 21:42:39 +00:00
<div className="text-xs text-gray-600">Durumu: {receipt.status}</div>
2025-09-15 09:31:47 +00:00
</div>
))}
</div>
</div>
)}
</div>
</div>
</form>
</div>
2025-09-15 21:42:39 +00:00
</Container>
)
}
2025-09-15 09:31:47 +00:00
2025-09-15 21:42:39 +00:00
export default OrderManagementForm