798 lines
36 KiB
TypeScript
798 lines
36 KiB
TypeScript
/**
|
|
* SCREEN-PROC-001: Purchase Sauda Booking Register & Costing View.
|
|
*
|
|
* Fulfills FR-PROCUREMENTCONTRACTS-001..004 & SCREEN-PROC-001.md (Iteration 03 / UC-004).
|
|
* Styled per DESIGN.md: AgriTrade Mercantile (Tactile Corporate Minimalism).
|
|
*/
|
|
import React, { useState } from 'react';
|
|
import { Card } from '../../components/ui/Card';
|
|
import { Button } from '../../components/ui/Button';
|
|
import { StatusPill } from '../../components/ui/StatusPill';
|
|
import { apiClient } from '../../services/api';
|
|
import {
|
|
ShoppingCart,
|
|
Plus,
|
|
AlertTriangle,
|
|
CheckCircle2,
|
|
Calculator,
|
|
Search,
|
|
Filter
|
|
} from 'lucide-react';
|
|
|
|
export interface SaudaContract {
|
|
id: string;
|
|
sauda_number: string;
|
|
contract_date: string;
|
|
delivery_due_date: string;
|
|
supplier_name: string;
|
|
mandi_hub: string;
|
|
commodity_name: string;
|
|
variety: string;
|
|
grade: string;
|
|
booked_quantity_mt: number;
|
|
estimated_bags: number;
|
|
trade_rate_per_qtl: number;
|
|
gross_value: number;
|
|
landed_value: number;
|
|
mandi_cess: number;
|
|
krishi_kalyan: number;
|
|
brokerage: number;
|
|
credit_days: number;
|
|
fulfilled_pct: number;
|
|
status: 'ACTIVE' | 'PENDING' | 'CLOSED' | 'REJECTED';
|
|
}
|
|
|
|
const DEFAULT_SAUDAS: SaudaContract[] = [
|
|
{
|
|
id: 'sda-rec-01',
|
|
sauda_number: 'SDA-2026-001',
|
|
contract_date: '2026-10-15',
|
|
delivery_due_date: '2026-10-22',
|
|
supplier_name: 'Rameshwar Patidar (Farmer / Arhatiya - Neemuch)',
|
|
mandi_hub: 'Indore APMC',
|
|
commodity_name: 'Soyabean',
|
|
variety: 'Yellow Desi',
|
|
grade: 'FAQ',
|
|
booked_quantity_mt: 25.0,
|
|
estimated_bags: 500,
|
|
trade_rate_per_qtl: 4850.0,
|
|
gross_value: 1212500.0,
|
|
mandi_cess: 18187.5,
|
|
krishi_kalyan: 6062.5,
|
|
brokerage: 12125.0,
|
|
landed_value: 1248875.0,
|
|
credit_days: 7,
|
|
fulfilled_pct: 0.0,
|
|
status: 'ACTIVE'
|
|
},
|
|
{
|
|
id: 'sda-rec-02',
|
|
sauda_number: 'SDA-26-00142',
|
|
contract_date: '2026-10-14',
|
|
delivery_due_date: '2026-10-20',
|
|
supplier_name: 'Kisan Agro Traders (SUP-0042)',
|
|
mandi_hub: 'Kota APMC',
|
|
commodity_name: 'Soyabean',
|
|
variety: 'Yellow Desi',
|
|
grade: 'FAQ',
|
|
booked_quantity_mt: 50.0,
|
|
estimated_bags: 1000,
|
|
trade_rate_per_qtl: 4750.0,
|
|
gross_value: 2375000.0,
|
|
mandi_cess: 35625.0,
|
|
krishi_kalyan: 11875.0,
|
|
brokerage: 23750.0,
|
|
landed_value: 2446250.0,
|
|
credit_days: 15,
|
|
fulfilled_pct: 60.0,
|
|
status: 'ACTIVE'
|
|
},
|
|
{
|
|
id: 'sda-rec-03',
|
|
sauda_number: 'SDA-26-00143',
|
|
contract_date: '2026-10-13',
|
|
delivery_due_date: '2026-10-18',
|
|
supplier_name: 'Mewar Krishi Sangh',
|
|
mandi_hub: 'Unjha APMC',
|
|
commodity_name: 'Cumin/Jeera',
|
|
variety: 'Special Bold',
|
|
grade: 'FAQ',
|
|
booked_quantity_mt: 20.0,
|
|
estimated_bags: 400,
|
|
trade_rate_per_qtl: 24500.0,
|
|
gross_value: 4900000.0,
|
|
mandi_cess: 73500.0,
|
|
krishi_kalyan: 24500.0,
|
|
brokerage: 49000.0,
|
|
landed_value: 5047000.0,
|
|
credit_days: 5,
|
|
fulfilled_pct: 0.0,
|
|
status: 'PENDING'
|
|
},
|
|
{
|
|
id: 'sda-rec-04',
|
|
sauda_number: 'SDA-26-00144',
|
|
contract_date: '2026-10-11',
|
|
delivery_due_date: '2026-10-16',
|
|
supplier_name: 'Malwa Agro Corp',
|
|
mandi_hub: 'Indore APMC',
|
|
commodity_name: 'Wheat',
|
|
variety: 'Lokwan',
|
|
grade: 'FAQ',
|
|
booked_quantity_mt: 100.0,
|
|
estimated_bags: 2000,
|
|
trade_rate_per_qtl: 2420.0,
|
|
gross_value: 2420000.0,
|
|
mandi_cess: 36300.0,
|
|
krishi_kalyan: 12100.0,
|
|
brokerage: 24200.0,
|
|
landed_value: 2492600.0,
|
|
credit_days: 10,
|
|
fulfilled_pct: 100.0,
|
|
status: 'CLOSED'
|
|
}
|
|
];
|
|
|
|
const BENCHMARK_MODAL_RATE = 4800.0; // Indore APMC Soybean modal clearing rate benchmark
|
|
|
|
export const SaudaProcurementView: React.FC = () => {
|
|
const [saudas, setSaudas] = useState<SaudaContract[]>(DEFAULT_SAUDAS);
|
|
const [searchQuery, setSearchQuery] = useState<string>('');
|
|
const [statusFilter, setStatusFilter] = useState<string>('ALL');
|
|
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
|
|
const [notification, setNotification] = useState<{ type: 'success' | 'error'; message: string } | null>(null);
|
|
|
|
// Form State matching Playbook Journey 1
|
|
const [contractDate, setContractDate] = useState<string>('2026-10-15');
|
|
const [sourcingMandi, setSourcingMandi] = useState<string>('Indore APMC, Madhya Pradesh');
|
|
const [tradeType, setTradeType] = useState<string>('MANDI_AUCTION');
|
|
const [supplierName, setSupplierName] = useState<string>('Rameshwar Patidar (Farmer / Arhatiya - Neemuch)');
|
|
const [commodity, setCommodity] = useState<string>('Soyabean (SOY)');
|
|
const [variety, setVariety] = useState<string>('Yellow FAQ');
|
|
const [bookedMt, setBookedMt] = useState<number>(25.0);
|
|
const [tradeRate, setTradeRate] = useState<number>(4850.0);
|
|
const [creditDays, setCreditDays] = useState<number>(7);
|
|
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
|
|
const [varianceConfirmed, setVarianceConfirmed] = useState<boolean>(false);
|
|
|
|
// Computed Bags: MT * 1000 / 50kg = MT * 20
|
|
const estimatedBags = Math.round(bookedMt * 20);
|
|
|
|
// Computed Payment Due Date
|
|
const computeDueDate = (dateStr: string, days: number): string => {
|
|
try {
|
|
const d = new Date(dateStr);
|
|
d.setDate(d.getDate() + days);
|
|
return d.toISOString().split('T')[0];
|
|
} catch {
|
|
return dateStr;
|
|
}
|
|
};
|
|
const paymentDueDate = computeDueDate(contractDate, creditDays);
|
|
|
|
// Rate Variance calculation: ((tradeRate - benchmark) / benchmark) * 100
|
|
const rateVariancePct = ((tradeRate - BENCHMARK_MODAL_RATE) / BENCHMARK_MODAL_RATE) * 100;
|
|
const isVarianceExceeded = rateVariancePct > 5.0;
|
|
|
|
// Commercial Math per NFR-001 (Dual UOM, Statutory Rounding)
|
|
// Base Value = MT * 10 Qtl/MT * Rate/Qtl
|
|
const grossTradeValue = bookedMt * 10 * tradeRate;
|
|
const mandiCess = grossTradeValue * 0.015; // 1.50%
|
|
const krishiKalyan = grossTradeValue * 0.005; // 0.50%
|
|
const brokerage = grossTradeValue * 0.01; // 1.00%
|
|
const totalLandedValue = grossTradeValue + mandiCess + krishiKalyan + brokerage;
|
|
|
|
const handleBookSauda = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (isVarianceExceeded && !varianceConfirmed) {
|
|
return;
|
|
}
|
|
|
|
setIsSubmitting(true);
|
|
setNotification(null);
|
|
|
|
const generatedSaudaNumber = `SDA-2026-${String(saudas.length + 1).padStart(3, '0')}`;
|
|
|
|
try {
|
|
const payload = {
|
|
sauda_number: generatedSaudaNumber,
|
|
contract_date: contractDate,
|
|
delivery_due_date: paymentDueDate,
|
|
supplier_id: 'sup-patidar-01',
|
|
mandi_id: 'mandi-indore-01',
|
|
trade_type: tradeType,
|
|
commodity_id: 'SOY',
|
|
variety: variety,
|
|
grade: 'FAQ',
|
|
booked_quantity_mt: bookedMt,
|
|
trade_rate_per_qtl: tradeRate,
|
|
rate_variance_pct: rateVariancePct,
|
|
variance_acknowledged: isVarianceExceeded ? varianceConfirmed : false,
|
|
credit_period_days: creditDays,
|
|
payment_due_date: paymentDueDate,
|
|
mandi_cess_pct: 1.5,
|
|
krishi_kalyan_pct: 0.5,
|
|
brokerage_rate_pct: 1.0,
|
|
gross_value: grossTradeValue,
|
|
landed_value: totalLandedValue
|
|
};
|
|
|
|
const resp = await apiClient('/api/v1/procurement/sauda', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify(payload)
|
|
});
|
|
if (resp.error) {
|
|
// Log non-blocking backend response while preserving offline mock UI state
|
|
console.warn('Backend sauda booking response:', resp.error);
|
|
}
|
|
|
|
const newContract: SaudaContract = {
|
|
id: `sda-${Date.now()}`,
|
|
sauda_number: generatedSaudaNumber,
|
|
contract_date: contractDate,
|
|
delivery_due_date: paymentDueDate,
|
|
supplier_name: supplierName,
|
|
mandi_hub: sourcingMandi.split(',')[0],
|
|
commodity_name: commodity.split(' ')[0],
|
|
variety: variety,
|
|
grade: 'FAQ',
|
|
booked_quantity_mt: bookedMt,
|
|
estimated_bags: estimatedBags,
|
|
trade_rate_per_qtl: tradeRate,
|
|
gross_value: grossTradeValue,
|
|
landed_value: totalLandedValue,
|
|
mandi_cess: mandiCess,
|
|
krishi_kalyan: krishiKalyan,
|
|
brokerage: brokerage,
|
|
credit_days: creditDays,
|
|
fulfilled_pct: 0.0,
|
|
status: 'ACTIVE'
|
|
};
|
|
|
|
setSaudas([newContract, ...saudas]);
|
|
setNotification({
|
|
type: 'success',
|
|
message: `Sauda Contract ${generatedSaudaNumber} locked successfully! Landed value ₹ ${totalLandedValue.toLocaleString('en-IN', { minimumFractionDigits: 2 })} booked for ${supplierName}.`
|
|
});
|
|
|
|
setIsModalOpen(false);
|
|
// Reset form
|
|
setBookedMt(25.0);
|
|
setTradeRate(4850.0);
|
|
setVarianceConfirmed(false);
|
|
} catch (err: any) {
|
|
setNotification({
|
|
type: 'error',
|
|
message: `Failed to book sauda: ${err.message}`
|
|
});
|
|
} finally {
|
|
setIsSubmitting(false);
|
|
}
|
|
};
|
|
|
|
// Filtered saudas
|
|
const filteredSaudas = saudas.filter(s => {
|
|
const matchesSearch = s.sauda_number.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
|
s.supplier_name.toLowerCase().includes(searchQuery.toLowerCase()) ||
|
|
s.commodity_name.toLowerCase().includes(searchQuery.toLowerCase());
|
|
const matchesStatus = statusFilter === 'ALL' || s.status === statusFilter;
|
|
return matchesSearch && matchesStatus;
|
|
});
|
|
|
|
const activeCount = saudas.filter(s => s.status === 'ACTIVE').length;
|
|
const totalOpenMt = saudas
|
|
.filter(s => s.status === 'ACTIVE')
|
|
.reduce((acc, s) => acc + (s.booked_quantity_mt * (1 - s.fulfilled_pct / 100)), 0);
|
|
const totalExposure = saudas
|
|
.filter(s => s.status === 'ACTIVE')
|
|
.reduce((acc, s) => acc + s.landed_value, 0);
|
|
|
|
return (
|
|
<div className="space-y-6 max-w-7xl mx-auto">
|
|
{/* Top Banner Alert / Notification */}
|
|
{notification && (
|
|
<div
|
|
className={`p-3 rounded text-xs font-mono flex items-center justify-between border ${
|
|
notification.type === 'success'
|
|
? 'bg-status-normal-bg text-status-normal-text border-status-normal-text/30'
|
|
: 'bg-status-watch-bg text-status-watch-text border-accent-ochre'
|
|
}`}
|
|
>
|
|
<div className="flex items-center space-x-2">
|
|
{notification.type === 'success' ? (
|
|
<CheckCircle2 className="w-4 h-4 text-status-normal-text flex-shrink-0" />
|
|
) : (
|
|
<AlertTriangle className="w-4 h-4 text-accent-ochre flex-shrink-0" />
|
|
)}
|
|
<span>{notification.message}</span>
|
|
</div>
|
|
<button
|
|
onClick={() => setNotification(null)}
|
|
className="text-xs uppercase font-semibold underline ml-4 hover:opacity-80"
|
|
>
|
|
Dismiss
|
|
</button>
|
|
</div>
|
|
)}
|
|
|
|
{/* Summary KPI Cards */}
|
|
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
|
<div className="bg-card-surface border border-card-border rounded p-4">
|
|
<div className="text-[10px] uppercase font-semibold text-text-muted font-mono tracking-wider mb-1">
|
|
Active Sauda Contracts
|
|
</div>
|
|
<div className="flex items-baseline space-x-2">
|
|
<span className="text-2xl font-bold font-mono text-text-primary">{activeCount}</span>
|
|
<span className="text-xs text-text-muted font-mono">Contracts</span>
|
|
</div>
|
|
<div className="text-[11px] text-text-muted font-mono mt-1">
|
|
Indore & Kota Mandis
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-card-surface border border-card-border rounded p-4">
|
|
<div className="text-[10px] uppercase font-semibold text-text-muted font-mono tracking-wider mb-1">
|
|
Open Balance Position
|
|
</div>
|
|
<div className="flex items-baseline space-x-2">
|
|
<span className="text-2xl font-bold font-mono text-text-primary">
|
|
{totalOpenMt.toFixed(2)}
|
|
</span>
|
|
<span className="text-xs text-text-muted font-mono">MT Pending Receiving</span>
|
|
</div>
|
|
<div className="text-[11px] text-text-muted font-mono mt-1">
|
|
~{Math.round(totalOpenMt * 20).toLocaleString('en-IN')} Bags Scheduled
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-card-surface border border-card-border rounded p-4">
|
|
<div className="text-[10px] uppercase font-semibold text-text-muted font-mono tracking-wider mb-1">
|
|
Committed Procurement Exposure
|
|
</div>
|
|
<div className="flex items-baseline space-x-2">
|
|
<span className="text-2xl font-bold font-mono text-text-primary">
|
|
₹ {(totalExposure / 100000).toFixed(2)}
|
|
</span>
|
|
<span className="text-xs text-text-muted font-mono">Lakhs</span>
|
|
</div>
|
|
<div className="text-[11px] text-text-muted font-mono mt-1">
|
|
Landed including statutory cess
|
|
</div>
|
|
</div>
|
|
|
|
<div className="bg-card-surface border border-card-border rounded p-4">
|
|
<div className="text-[10px] uppercase font-semibold text-text-muted font-mono tracking-wider mb-1">
|
|
Indore Benchmark Modal
|
|
</div>
|
|
<div className="flex items-baseline space-x-2">
|
|
<span className="text-2xl font-bold font-mono text-accent-ochre">
|
|
₹ {BENCHMARK_MODAL_RATE.toLocaleString('en-IN', { minimumFractionDigits: 2 })}
|
|
</span>
|
|
<span className="text-xs text-text-muted font-mono">/ Qtl</span>
|
|
</div>
|
|
<div className="text-[11px] text-status-normal-text font-mono mt-1">
|
|
Real-time Market Desk Peg
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Main Register Filter & Action Bar */}
|
|
<div className="bg-card-surface border border-card-border rounded p-4 flex flex-wrap items-center justify-between gap-4">
|
|
<div className="flex items-center space-x-3 flex-1 min-w-[280px]">
|
|
<div className="relative flex-1">
|
|
<Search className="w-4 h-4 text-text-muted absolute left-3 top-2.5" />
|
|
<input
|
|
type="text"
|
|
placeholder="Search contract, supplier, or commodity..."
|
|
value={searchQuery}
|
|
onChange={(e) => setSearchQuery(e.target.value)}
|
|
className="w-full pl-9 pr-3 py-1.5 rounded bg-white border border-card-border text-xs text-text-primary focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex items-center space-x-1.5">
|
|
<Filter className="w-3.5 h-3.5 text-text-muted" />
|
|
<select
|
|
value={statusFilter}
|
|
onChange={(e) => setStatusFilter(e.target.value)}
|
|
className="py-1.5 px-2.5 rounded bg-white border border-card-border text-xs font-mono text-text-primary focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
>
|
|
<option value="ALL">All Statuses</option>
|
|
<option value="ACTIVE">Active</option>
|
|
<option value="PENDING">Pending</option>
|
|
<option value="CLOSED">Closed</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<Button
|
|
variant="primary"
|
|
size="sm"
|
|
onClick={() => setIsModalOpen(true)}
|
|
className="flex items-center space-x-2 font-semibold text-xs py-2 px-4 shadow-none"
|
|
>
|
|
<Plus className="w-4 h-4 text-accent-ochre" />
|
|
<span>Book New Sauda</span>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Sauda Contracts Table (SCREEN-PROC-001) */}
|
|
<Card
|
|
title="Purchase Sauda Contracts Register"
|
|
subtitle="Binding commercial procurement contracts with multi-tier statutory cess and landed costing"
|
|
action={
|
|
<span className="text-xs font-mono text-text-muted uppercase">
|
|
SCREEN-PROC-001 • UC-004
|
|
</span>
|
|
}
|
|
>
|
|
<div className="overflow-x-auto">
|
|
<table className="w-full text-left text-xs divide-y divide-card-border">
|
|
<thead className="bg-surface-low font-mono text-[11px] uppercase tracking-wider text-text-muted">
|
|
<tr>
|
|
<th className="py-3 px-4">Contract ID</th>
|
|
<th className="py-3 px-4">Date</th>
|
|
<th className="py-3 px-4">Supplier / Arhatiya</th>
|
|
<th className="py-3 px-4">Mandi Hub</th>
|
|
<th className="py-3 px-4">Commodity</th>
|
|
<th className="py-3 px-4 text-right">Booked MT</th>
|
|
<th className="py-3 px-4 text-right">Agreed Rate</th>
|
|
<th className="py-3 px-4 text-right">Base Value</th>
|
|
<th className="py-3 px-4 text-right font-bold text-text-primary">Landed Value</th>
|
|
<th className="py-3 px-4 text-center">Fulfilled</th>
|
|
<th className="py-3 px-4 text-center">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-card-border bg-white font-sans">
|
|
{filteredSaudas.length === 0 ? (
|
|
<tr>
|
|
<td colSpan={11} className="py-8 text-center text-xs text-text-muted font-mono">
|
|
No sauda contracts found matching criteria.
|
|
</td>
|
|
</tr>
|
|
) : (
|
|
filteredSaudas.map((sauda) => (
|
|
<tr key={sauda.id} className="hover:bg-surface-bright transition-colors">
|
|
<td className="py-3.5 px-4 font-mono font-semibold text-text-primary">
|
|
{sauda.sauda_number}
|
|
</td>
|
|
<td className="py-3.5 px-4 font-mono text-text-muted">
|
|
{sauda.contract_date}
|
|
</td>
|
|
<td className="py-3.5 px-4 font-medium text-text-primary">
|
|
{sauda.supplier_name}
|
|
</td>
|
|
<td className="py-3.5 px-4 font-mono text-text-muted">
|
|
{sauda.mandi_hub}
|
|
</td>
|
|
<td className="py-3.5 px-4">
|
|
<span className="font-semibold">{sauda.commodity_name}</span>{' '}
|
|
<span className="text-text-muted font-mono text-[11px]">({sauda.variety})</span>
|
|
</td>
|
|
<td className="py-3.5 px-4 text-right font-mono text-text-primary font-medium">
|
|
{sauda.booked_quantity_mt.toFixed(3)} MT
|
|
<div className="text-[10px] text-text-muted">{sauda.estimated_bags} bags</div>
|
|
</td>
|
|
<td className="py-3.5 px-4 text-right font-mono text-text-muted">
|
|
₹ {sauda.trade_rate_per_qtl.toLocaleString('en-IN', { minimumFractionDigits: 2 })}
|
|
</td>
|
|
<td className="py-3.5 px-4 text-right font-mono text-text-muted">
|
|
₹ {sauda.gross_value.toLocaleString('en-IN', { minimumFractionDigits: 2 })}
|
|
</td>
|
|
<td className="py-3.5 px-4 text-right font-mono font-bold text-text-primary bg-surface-low/50">
|
|
₹ {sauda.landed_value.toLocaleString('en-IN', { minimumFractionDigits: 2 })}
|
|
</td>
|
|
<td className="py-3.5 px-4 text-center font-mono text-xs">
|
|
<span className={sauda.fulfilled_pct === 100 ? 'text-status-normal-text font-bold' : 'text-text-muted'}>
|
|
{sauda.fulfilled_pct.toFixed(1)} %
|
|
</span>
|
|
</td>
|
|
<td className="py-3.5 px-4 text-center">
|
|
<StatusPill
|
|
status={sauda.status === 'ACTIVE' ? 'normal' : sauda.status === 'PENDING' ? 'watch' : 'neutral'}
|
|
label={sauda.status}
|
|
/>
|
|
</td>
|
|
</tr>
|
|
))
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</Card>
|
|
|
|
{/* Book New Sauda Modal Dialog (SCREEN-PROC-001 / Sales Demo Journey 1) */}
|
|
{isModalOpen && (
|
|
<div className="fixed z-50 inset-0 overflow-y-auto">
|
|
<div className="flex items-center justify-center min-h-screen px-4 text-center sm:p-0">
|
|
<div
|
|
className="fixed inset-0 bg-sidebar-surface/40 transition-opacity"
|
|
onClick={() => setIsModalOpen(false)}
|
|
/>
|
|
|
|
<div className="inline-block bg-card-surface rounded border border-card-border p-6 text-left overflow-hidden shadow-tactile transform transition-all sm:max-w-2xl sm:w-full z-10">
|
|
<div className="flex items-center justify-between pb-3 border-b border-card-border mb-4">
|
|
<div className="flex items-center space-x-2">
|
|
<ShoppingCart className="w-5 h-5 text-accent-ochre" />
|
|
<h3 className="text-sm font-bold text-text-primary tracking-tight">
|
|
Book Purchase Sauda Contract (Mandi Auction / Direct Purchase)
|
|
</h3>
|
|
</div>
|
|
<button
|
|
type="button"
|
|
onClick={() => setIsModalOpen(false)}
|
|
className="text-text-muted hover:text-text-primary text-xs font-mono"
|
|
>
|
|
✕
|
|
</button>
|
|
</div>
|
|
|
|
<form onSubmit={handleBookSauda} className="space-y-4 text-xs font-sans">
|
|
{/* Contract Dates & Sourcing Yard */}
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block text-[11px] font-semibold uppercase tracking-wider text-text-muted font-mono mb-1">
|
|
Contract Date*:
|
|
</label>
|
|
<input
|
|
type="date"
|
|
value={contractDate}
|
|
onChange={(e) => setContractDate(e.target.value)}
|
|
className="w-full py-1.5 px-2.5 rounded bg-white border border-card-border text-text-primary text-xs font-mono focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[11px] font-semibold uppercase tracking-wider text-text-muted font-mono mb-1">
|
|
Sourcing Mandi*:
|
|
</label>
|
|
<select
|
|
value={sourcingMandi}
|
|
onChange={(e) => setSourcingMandi(e.target.value)}
|
|
className="w-full py-1.5 px-2.5 rounded bg-white border border-card-border text-text-primary text-xs font-mono focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
>
|
|
<option value="Indore APMC, Madhya Pradesh">Indore APMC, Madhya Pradesh</option>
|
|
<option value="Kota APMC, Rajasthan">Kota APMC, Rajasthan</option>
|
|
<option value="Unjha APMC, Gujarat">Unjha APMC, Gujarat</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Supplier & Trade Type */}
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block text-[11px] font-semibold uppercase tracking-wider text-text-muted font-mono mb-1">
|
|
Supplier / Arhatiya*:
|
|
</label>
|
|
<select
|
|
value={supplierName}
|
|
onChange={(e) => setSupplierName(e.target.value)}
|
|
className="w-full py-1.5 px-2.5 rounded bg-white border border-card-border text-text-primary text-xs font-mono focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
>
|
|
<option value="Rameshwar Patidar (Farmer / Arhatiya - Neemuch)">
|
|
Rameshwar Patidar (Farmer / Arhatiya - Neemuch)
|
|
</option>
|
|
<option value="Kisan Agro Traders (SUP-0042 - 24ABCDE1234F1Z5)">
|
|
Kisan Agro Traders (SUP-0042)
|
|
</option>
|
|
<option value="Mewar Krishi Sangh">Mewar Krishi Sangh</option>
|
|
<option value="Malwa Agro Corp">Malwa Agro Corp</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[11px] font-semibold uppercase tracking-wider text-text-muted font-mono mb-1">
|
|
Trade Type*:
|
|
</label>
|
|
<select
|
|
value={tradeType}
|
|
onChange={(e) => setTradeType(e.target.value)}
|
|
className="w-full py-1.5 px-2.5 rounded bg-white border border-card-border text-text-primary text-xs font-mono focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
>
|
|
<option value="MANDI_AUCTION">Mandi APMC Auction</option>
|
|
<option value="DIRECT_FARMER">Direct Farmer Purchase</option>
|
|
<option value="COMMERCIAL_TRADER">Commercial Trader Sauda</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Commodity, Variety & Grade */}
|
|
<div className="grid grid-cols-3 gap-3">
|
|
<div>
|
|
<label className="block text-[11px] font-semibold uppercase tracking-wider text-text-muted font-mono mb-1">
|
|
Commodity*:
|
|
</label>
|
|
<select
|
|
value={commodity}
|
|
onChange={(e) => setCommodity(e.target.value)}
|
|
className="w-full py-1.5 px-2.5 rounded bg-white border border-card-border text-text-primary text-xs font-mono focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
>
|
|
<option value="Soyabean (SOY)">Soyabean (SOY)</option>
|
|
<option value="Chana (CHN)">Chana (CHN)</option>
|
|
<option value="Wheat (WHT)">Wheat (WHT)</option>
|
|
<option value="Mustard (MST)">Mustard (MST)</option>
|
|
</select>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[11px] font-semibold uppercase tracking-wider text-text-muted font-mono mb-1">
|
|
Variety*:
|
|
</label>
|
|
<input
|
|
type="text"
|
|
value={variety}
|
|
onChange={(e) => setVariety(e.target.value)}
|
|
className="w-full py-1.5 px-2.5 rounded bg-white border border-card-border text-text-primary text-xs font-mono focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[11px] font-semibold uppercase tracking-wider text-text-muted font-mono mb-1">
|
|
Commercial Grade*:
|
|
</label>
|
|
<input
|
|
type="text"
|
|
disabled
|
|
value="FAQ (Fair Average Quality)"
|
|
className="w-full py-1.5 px-2.5 rounded bg-surface-low border border-card-border text-text-muted text-xs font-mono"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Trade Quantity & Pricing with Dual-UOM */}
|
|
<div className="p-3.5 bg-surface-low rounded border border-card-border space-y-3">
|
|
<div className="text-[10px] uppercase font-semibold text-text-muted font-mono tracking-wider flex items-center justify-between">
|
|
<span>Trade Quantity & Pricing Alignment</span>
|
|
<span className="text-accent-ochre">Benchmark Modal: ₹ {BENCHMARK_MODAL_RATE.toLocaleString('en-IN')}/Qtl</span>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-3 gap-3">
|
|
<div>
|
|
<label className="block text-[10px] font-mono text-text-muted mb-0.5">
|
|
Booked Quantity (MT)*:
|
|
</label>
|
|
<input
|
|
type="number"
|
|
step="0.001"
|
|
min="0.1"
|
|
value={bookedMt}
|
|
onChange={(e) => setBookedMt(parseFloat(e.target.value) || 0)}
|
|
className="w-full py-1.5 px-2.5 rounded bg-white border border-card-border text-text-primary text-xs font-mono font-bold focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[10px] font-mono text-text-muted mb-0.5">
|
|
Estimated Bags (50kg)*:
|
|
</label>
|
|
<input
|
|
type="text"
|
|
disabled
|
|
value={`${estimatedBags} Bags`}
|
|
className="w-full py-1.5 px-2.5 rounded bg-surface-container border border-card-border text-text-primary text-xs font-mono font-medium"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block text-[10px] font-mono text-text-muted mb-0.5">
|
|
Agreed Rate (₹/Qtl)*:
|
|
</label>
|
|
<input
|
|
type="number"
|
|
step="0.5"
|
|
min="1"
|
|
value={tradeRate}
|
|
onChange={(e) => setTradeRate(parseFloat(e.target.value) || 0)}
|
|
className="w-full py-1.5 px-2.5 rounded bg-white border border-card-border text-text-primary text-xs font-mono font-bold focus:outline-none focus:ring-1 focus:ring-accent-ochre"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Price Variance Safeguard Banner per Playbook Journey 1 */}
|
|
{isVarianceExceeded ? (
|
|
<div className="p-3 rounded bg-status-watch-bg border-l-[3px] border-accent-ochre text-status-watch-text text-xs space-y-2 font-mono">
|
|
<div className="flex items-center space-x-2 font-semibold">
|
|
<AlertTriangle className="w-4 h-4 text-accent-ochre flex-shrink-0" />
|
|
<span>
|
|
Price variance (+{rateVariancePct.toFixed(2)}%) exceeds 5.0% benchmark threshold!
|
|
</span>
|
|
</div>
|
|
<p className="text-[11px] text-text-primary">
|
|
Agreed rate (₹ {tradeRate.toFixed(2)}) is higher than Indore APMC clearing rate (₹ {BENCHMARK_MODAL_RATE.toFixed(2)}). Mandatory confirmation required before locking.
|
|
</p>
|
|
<label className="flex items-center space-x-2 text-xs text-text-primary cursor-pointer pt-1">
|
|
<input
|
|
type="checkbox"
|
|
checked={varianceConfirmed}
|
|
onChange={(e) => setVarianceConfirmed(e.target.checked)}
|
|
className="rounded border-card-border text-accent-ochre focus:ring-accent-ochre"
|
|
/>
|
|
<span className="font-semibold">
|
|
I confirm this rate is justified due to premium high-oil specification (FAQ+).
|
|
</span>
|
|
</label>
|
|
</div>
|
|
) : (
|
|
<div className="text-[10px] text-status-normal-text font-mono flex items-center space-x-1">
|
|
<CheckCircle2 className="w-3.5 h-3.5 text-status-normal-text inline flex-shrink-0" />
|
|
<span>
|
|
Rate Variance: {rateVariancePct >= 0 ? `+${rateVariancePct.toFixed(2)}%` : `${rateVariancePct.toFixed(2)}%`} (Safely within 5.0% benchmark threshold)
|
|
</span>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{/* Commercial Terms & Statutory Levies Calculator */}
|
|
<div className="p-3.5 bg-surface-low rounded border border-card-border space-y-2 font-mono">
|
|
<div className="flex flex-wrap items-center justify-between text-[10px] uppercase font-semibold text-text-muted tracking-wider pb-2 border-b border-card-border gap-2">
|
|
<span className="flex items-center space-x-1">
|
|
<Calculator className="w-3.5 h-3.5 text-accent-ochre" />
|
|
<span>Instant Landed Cost Breakdown (NFR-001 Dual-UOM)</span>
|
|
</span>
|
|
<div className="flex items-center space-x-2">
|
|
<span>Terms:</span>
|
|
<select
|
|
value={creditDays}
|
|
onChange={(e) => setCreditDays(parseInt(e.target.value) || 0)}
|
|
className="py-0.5 px-1.5 rounded bg-white border border-card-border text-[11px] font-mono text-text-primary"
|
|
>
|
|
<option value={0}>Spot (0d)</option>
|
|
<option value={7}>7 Days Credit</option>
|
|
<option value={15}>15 Days Credit</option>
|
|
<option value={30}>30 Days Credit</option>
|
|
</select>
|
|
<span className="text-text-primary">Due: {paymentDueDate}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="space-y-1 text-xs text-text-primary pt-1">
|
|
<div className="flex justify-between">
|
|
<span className="text-text-muted">Base Value ({bookedMt.toFixed(3)} MT • 10 Qtl/MT • ₹ {tradeRate}):</span>
|
|
<span className="font-semibold">₹ {grossTradeValue.toLocaleString('en-IN', { minimumFractionDigits: 2 })}</span>
|
|
</div>
|
|
<div className="flex justify-between">
|
|
<span className="text-text-muted">APMC Mandi Cess (1.50%):</span>
|
|
<span>₹ {mandiCess.toLocaleString('en-IN', { minimumFractionDigits: 2 })}</span>
|
|
</div>
|
|
<div className="flex justify-between">
|
|
<span className="text-text-muted">Krishi Kalyan Cess (0.50%):</span>
|
|
<span>₹ {krishiKalyan.toLocaleString('en-IN', { minimumFractionDigits: 2 })}</span>
|
|
</div>
|
|
<div className="flex justify-between">
|
|
<span className="text-text-muted">Brokerage / Arhat (1.00%):</span>
|
|
<span>₹ {brokerage.toLocaleString('en-IN', { minimumFractionDigits: 2 })}</span>
|
|
</div>
|
|
<div className="flex justify-between pt-2 border-t border-card-border text-sm font-bold text-text-primary">
|
|
<span>Total Landed Sauda Value:</span>
|
|
<span className="text-accent-ochre">₹ {totalLandedValue.toLocaleString('en-IN', { minimumFractionDigits: 2 })}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Modal Action Buttons */}
|
|
<div className="flex items-center justify-end space-x-3 pt-3 border-t border-card-border">
|
|
<Button
|
|
type="button"
|
|
variant="secondary"
|
|
size="sm"
|
|
onClick={() => setIsModalOpen(false)}
|
|
className="font-mono text-xs"
|
|
>
|
|
Cancel
|
|
</Button>
|
|
<Button
|
|
type="submit"
|
|
variant="primary"
|
|
size="sm"
|
|
disabled={isSubmitting || (isVarianceExceeded && !varianceConfirmed)}
|
|
className="font-mono text-xs"
|
|
>
|
|
{isSubmitting ? 'Booking...' : 'Confirm & Issue Sauda'}
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|