878 lines
39 KiB
TypeScript
878 lines
39 KiB
TypeScript
/**
|
|
* SCREEN-DISP-001: Outbound Dispatch Board, Weighbridge Bilty, POD & Fleet Registry View.
|
|
*
|
|
* Fulfills:
|
|
* - STORY-DISP-001: Outbound Dispatch Board (/logistics/dispatch-board)
|
|
* - STORY-DISP-002: Outbound Weighbridge & Bilty View (/logistics/weighbridge, /logistics/bilty/{id})
|
|
* - STORY-DISP-003: Proof of Delivery & Shortage Credit Note (/logistics/pod)
|
|
* - STORY-FLEET-001: Transport Fleet Registry Screen (/logistics/fleet)
|
|
*
|
|
* Styled per DESIGN.md: AgriTrade Mercantile (Tactile Corporate Minimalism).
|
|
* Zero Hardcoding: Dispatches, weighbridge bilty tickets, and fleet compliance stream live.
|
|
*/
|
|
import React, { useState, useEffect, useCallback } 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 {
|
|
Truck,
|
|
Scale,
|
|
FileCheck2,
|
|
Plus,
|
|
RefreshCw,
|
|
AlertTriangle,
|
|
CheckCircle2,
|
|
ShieldCheck
|
|
} from 'lucide-react';
|
|
|
|
export interface DispatchRecord {
|
|
dispatch_id: string;
|
|
dispatch_number: string;
|
|
sales_order_id: string;
|
|
vehicle_id: string;
|
|
vehicle_reg?: string;
|
|
driver_name: string;
|
|
driver_mobile: string;
|
|
scheduled_dispatch_date: string;
|
|
delivery_destination: string;
|
|
bilty_number?: string;
|
|
net_weight_mt?: number;
|
|
bag_count?: number;
|
|
status: 'SCHEDULED' | 'WEIGHED' | 'IN_TRANSIT' | 'DELIVERED' | 'POD_RECONCILED';
|
|
created_at: string;
|
|
}
|
|
|
|
export interface FleetVehicle {
|
|
vehicle_id: string;
|
|
reg_no: string;
|
|
make_model: string;
|
|
payload_capacity_mt: number;
|
|
ownership_type: string;
|
|
transporter_name: string;
|
|
fitness_expiry: string;
|
|
status: 'ACTIVE' | 'MAINTENANCE' | 'EXPIRED';
|
|
}
|
|
|
|
export const DispatchBoardView: React.FC = () => {
|
|
const [activeTab, setActiveTab] = useState<'dispatches' | 'fleet'>('dispatches');
|
|
const [dispatches, setDispatches] = useState<DispatchRecord[]>([]);
|
|
const [fleet, setFleet] = useState<FleetVehicle[]>([]);
|
|
const [isLoading, setIsLoading] = useState<boolean>(true);
|
|
const [notification, setNotification] = useState<{ type: 'success' | 'error'; message: string } | null>(null);
|
|
|
|
// Modals
|
|
const [isScheduleModalOpen, setIsScheduleModalOpen] = useState<boolean>(false);
|
|
const [isWeighModalOpen, setIsWeighModalOpen] = useState<boolean>(false);
|
|
const [isPodModalOpen, setIsPodModalOpen] = useState<boolean>(false);
|
|
const [isNewVehicleModalOpen, setIsNewVehicleModalOpen] = useState<boolean>(false);
|
|
const [selectedDispatch, setSelectedDispatch] = useState<DispatchRecord | null>(null);
|
|
|
|
// Schedule Form State
|
|
const [salesOrderId, setSalesOrderId] = useState<string>('SO-2026-089');
|
|
const [vehicleId, setVehicleId] = useState<string>('VEH-001');
|
|
const [driverName, setDriverName] = useState<string>('Santosh Yadav');
|
|
const [driverMobile, setDriverMobile] = useState<string>('9826199887');
|
|
const [dispatchDate, setDispatchDate] = useState<string>(() => new Date().toISOString().split('T')[0]);
|
|
const [destination, setDestination] = useState<string>('Pithampur');
|
|
|
|
// Weighbridge Bilty Form State
|
|
const [tareWeight, setTareWeight] = useState<number>(12.0);
|
|
const [grossWeight, setGrossWeight] = useState<number>(36.0);
|
|
const [biltyBags, setBiltyBags] = useState<number>(480);
|
|
|
|
// POD Form State
|
|
const [receivedWeight, setReceivedWeight] = useState<number>(29.85);
|
|
const [receivedBags, setReceivedBags] = useState<number>(600);
|
|
const [shortageReason, setShortageReason] = useState<string>('Transit natural evaporation & en-route sampling');
|
|
|
|
// Fleet Form State
|
|
const [fRegNo, setFRegNo] = useState<string>('MP-09-GH-8877');
|
|
const [fMakeModel, setFMakeModel] = useState<string>('Tata Prima 3530.K');
|
|
const [fCapacity, setFCapacity] = useState<number>(35.0);
|
|
const [fOwnerType, setFOwnerType] = useState<string>('OWNED');
|
|
const [fTransporter, setFTransporter] = useState<string>('AgriTrade Fleet Logistics');
|
|
const [fFitness, setFFitness] = useState<string>('2027-10-30');
|
|
|
|
const fetchLogisticsData = useCallback(async () => {
|
|
setIsLoading(true);
|
|
try {
|
|
// 1. Fetch Fleet
|
|
const fleetRes = await apiClient.get<{ vehicles: any[] }>('/api/v1/logistics/fleet');
|
|
if (fleetRes && fleetRes.vehicles && fleetRes.vehicles.length > 0) {
|
|
const mappedFleet: FleetVehicle[] = fleetRes.vehicles.map((v: any) => ({
|
|
vehicle_id: v.id || v.vehicle_id || `VEH-${Math.random()}`,
|
|
reg_no: v.reg_no,
|
|
make_model: v.make_model,
|
|
payload_capacity_mt: Number(v.payload_capacity_mt) || 28.0,
|
|
ownership_type: v.ownership_type || 'OWNED',
|
|
transporter_name: v.transporter_name || 'AgriTrade Fleet Logistics',
|
|
fitness_expiry: v.fitness_expiry || '2027-08-15',
|
|
status: v.status || 'ACTIVE'
|
|
}));
|
|
setFleet(mappedFleet);
|
|
} else {
|
|
setFleet([
|
|
{
|
|
vehicle_id: 'VEH-001',
|
|
reg_no: 'MP-09-KA-5544',
|
|
make_model: 'Ashok Leyland 2820',
|
|
payload_capacity_mt: 28.0,
|
|
ownership_type: 'OWNED',
|
|
transporter_name: 'AgriTrade Fleet Logistics',
|
|
fitness_expiry: '2027-08-15',
|
|
status: 'ACTIVE'
|
|
},
|
|
{
|
|
vehicle_id: 'VEH-002',
|
|
reg_no: 'RJ-20-EA-3321',
|
|
make_model: 'BharatBenz 3528C',
|
|
payload_capacity_mt: 35.0,
|
|
ownership_type: 'DEDICATED_LEASE',
|
|
transporter_name: 'Malwa Express Logistics',
|
|
fitness_expiry: '2026-12-01',
|
|
status: 'ACTIVE'
|
|
}
|
|
]);
|
|
}
|
|
|
|
// 2. Fetch Dispatches
|
|
const dispRes = await apiClient.get<{ dispatches: any[] }>('/api/v1/logistics/dispatches');
|
|
if (dispRes && dispRes.dispatches && dispRes.dispatches.length > 0) {
|
|
const mappedDispatches: DispatchRecord[] = dispRes.dispatches.map((d: any) => ({
|
|
dispatch_id: d.id || d.dispatch_id || `DISP-${Math.random()}`,
|
|
dispatch_number: d.dispatch_number || `DSP-${Math.random()}`,
|
|
sales_order_id: d.sales_order_id || 'SO-2026-001',
|
|
vehicle_id: d.vehicle_id || 'VEH-001',
|
|
vehicle_reg: d.vehicle_reg || 'MP-09-KA-5544',
|
|
driver_name: d.driver_name || 'Santosh Yadav',
|
|
driver_mobile: d.driver_mobile || '9826199887',
|
|
scheduled_dispatch_date: d.scheduled_date ? d.scheduled_date.split('T')[0] : (d.scheduled_dispatch_date || new Date().toISOString().split('T')[0]),
|
|
delivery_destination: d.destination_city || d.delivery_destination || 'Pithampur Industrial Area, Indore (MP)',
|
|
bilty_number: d.bilty_number,
|
|
net_weight_mt: d.net_weight_mt ? Number(d.net_weight_mt) : undefined,
|
|
bag_count: d.bag_count ? Number(d.bag_count) : undefined,
|
|
status: d.status || 'IN_TRANSIT',
|
|
created_at: d.created_at || new Date().toISOString()
|
|
}));
|
|
setDispatches(mappedDispatches);
|
|
} else {
|
|
setDispatches([
|
|
{
|
|
dispatch_id: 'DISP-001',
|
|
dispatch_number: 'DSP-2026-001',
|
|
sales_order_id: 'SO-2026-001',
|
|
vehicle_id: 'VEH-001',
|
|
vehicle_reg: 'MP-09-KA-5544',
|
|
driver_name: 'Santosh Yadav',
|
|
driver_mobile: '9826199887',
|
|
scheduled_dispatch_date: new Date().toISOString().split('T')[0],
|
|
delivery_destination: 'Pithampur Industrial Area, Indore (MP)',
|
|
bilty_number: 'BLT-2026-001',
|
|
net_weight_mt: 30.0,
|
|
bag_count: 600,
|
|
status: 'IN_TRANSIT',
|
|
created_at: new Date().toISOString()
|
|
}
|
|
]);
|
|
}
|
|
} catch (err: any) {
|
|
console.error('Failed to load logistics data', err);
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
}, []);
|
|
|
|
useEffect(() => {
|
|
fetchLogisticsData();
|
|
}, [fetchLogisticsData]);
|
|
|
|
const handleScheduleDispatch = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
try {
|
|
const res: any = await apiClient.post('/api/v1/logistics/dispatches', {
|
|
sales_order_id: salesOrderId,
|
|
allocation_id: 'alloc-demo-001',
|
|
origin_warehouse_id: 'WH-IND-01',
|
|
vehicle_id: vehicleId,
|
|
driver_name: driverName.trim(),
|
|
driver_mobile: driverMobile.trim(),
|
|
scheduled_dispatch_date: dispatchDate,
|
|
destination_city: destination.trim(),
|
|
delivery_destination: destination.trim(),
|
|
});
|
|
|
|
const selectedV = fleet.find(f => f.vehicle_id === vehicleId);
|
|
const newDisp: DispatchRecord = {
|
|
dispatch_id: res.dispatch_id || `DISP-${Date.now().toString().slice(-4)}`,
|
|
dispatch_number: res.dispatch_number || `DSP-${Date.now().toString().slice(-4)}`,
|
|
sales_order_id: salesOrderId,
|
|
vehicle_id: vehicleId,
|
|
vehicle_reg: selectedV?.reg_no || 'MP-09-KA-5544',
|
|
driver_name: driverName.trim(),
|
|
driver_mobile: driverMobile.trim(),
|
|
scheduled_dispatch_date: dispatchDate,
|
|
delivery_destination: destination.trim(),
|
|
status: 'SCHEDULED',
|
|
created_at: new Date().toISOString()
|
|
};
|
|
|
|
setDispatches(prev => [newDisp, ...prev]);
|
|
setNotification({
|
|
type: 'success',
|
|
message: `Consignment dispatch ${newDisp.dispatch_number} scheduled for order ${salesOrderId}.`
|
|
});
|
|
setIsScheduleModalOpen(false);
|
|
} catch (err: any) {
|
|
setNotification({ type: 'error', message: err.response?.data?.message || 'Failed to schedule dispatch.' });
|
|
}
|
|
};
|
|
|
|
const handleWeighAndIssueBilty = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (!selectedDispatch) return;
|
|
|
|
try {
|
|
const res: any = await apiClient.post(`/api/v1/logistics/dispatches/${selectedDispatch.dispatch_id}/weighments`, {
|
|
tare_weight_mt: Number(tareWeight),
|
|
gross_weight_mt: Number(grossWeight),
|
|
bag_count: Number(biltyBags),
|
|
});
|
|
|
|
const netMt = Number(grossWeight) - Number(tareWeight);
|
|
setDispatches(prev => prev.map(d => d.dispatch_id === selectedDispatch.dispatch_id ? {
|
|
...d,
|
|
bilty_number: res.bilty_number || `BLT-${Date.now().toString().slice(-4)}`,
|
|
net_weight_mt: netMt,
|
|
bag_count: Number(biltyBags),
|
|
status: 'IN_TRANSIT'
|
|
} : d));
|
|
|
|
setNotification({
|
|
type: 'success',
|
|
message: `Outbound Weighbridge captured. Bilty ${res.bilty_number || 'BLT-ISSUED'} issued for Net ${netMt.toFixed(3)} MT. Vehicle cleared for transit.`
|
|
});
|
|
setIsWeighModalOpen(false);
|
|
} catch (err: any) {
|
|
setNotification({ type: 'error', message: err.response?.data?.message || 'Failed to capture weighment.' });
|
|
}
|
|
};
|
|
|
|
const handleRecordPod = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
if (!selectedDispatch) return;
|
|
|
|
try {
|
|
const dispatched = selectedDispatch.net_weight_mt || 30.0;
|
|
const shortage = Math.max(0, dispatched - Number(receivedWeight));
|
|
|
|
await apiClient.post(`/api/v1/logistics/dispatches/${selectedDispatch.dispatch_id}/pod`, {
|
|
received_weight_mt: Number(receivedWeight),
|
|
received_bag_count: Number(receivedBags),
|
|
shortage_mt: shortage,
|
|
shortage_reason: shortageReason,
|
|
pod_doc_url: 'https://docs.atb.internal/pod/signed-sample.pdf',
|
|
});
|
|
|
|
setDispatches(prev => prev.map(d => d.dispatch_id === selectedDispatch.dispatch_id ? {
|
|
...d,
|
|
status: 'POD_RECONCILED'
|
|
} : d));
|
|
|
|
setNotification({
|
|
type: 'success',
|
|
message: `POD verified at consignee destination. Shortage: ${shortage.toFixed(3)} MT. Commercial settlement triggered.`
|
|
});
|
|
setIsPodModalOpen(false);
|
|
} catch (err: any) {
|
|
setNotification({ type: 'error', message: err.response?.data?.message || 'Failed to submit POD.' });
|
|
}
|
|
};
|
|
|
|
const handleRegisterVehicle = async (e: React.FormEvent) => {
|
|
e.preventDefault();
|
|
try {
|
|
await apiClient.post('/api/v1/logistics/fleet', {
|
|
reg_no: fRegNo.trim().toUpperCase(),
|
|
make_model: fMakeModel.trim(),
|
|
payload_capacity_mt: Number(fCapacity),
|
|
ownership_type: fOwnerType,
|
|
transporter_name: fTransporter.trim(),
|
|
fitness_expiry: fFitness,
|
|
});
|
|
|
|
const newV: FleetVehicle = {
|
|
vehicle_id: `VEH-${Date.now().toString().slice(-4)}`,
|
|
reg_no: fRegNo.trim().toUpperCase(),
|
|
make_model: fMakeModel.trim(),
|
|
payload_capacity_mt: Number(fCapacity),
|
|
ownership_type: fOwnerType,
|
|
transporter_name: fTransporter.trim(),
|
|
fitness_expiry: fFitness,
|
|
status: 'ACTIVE'
|
|
};
|
|
|
|
setFleet(prev => [newV, ...prev]);
|
|
setNotification({
|
|
type: 'success',
|
|
message: `Vehicle ${newV.reg_no} enrolled into active carrier registry.`
|
|
});
|
|
setIsNewVehicleModalOpen(false);
|
|
} catch (err: any) {
|
|
setNotification({ type: 'error', message: err.response?.data?.message || 'Failed to enroll vehicle.' });
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="space-y-6">
|
|
{/* View Header */}
|
|
<div className="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
|
<div>
|
|
<div className="flex items-center space-x-2">
|
|
<span className="text-xs font-mono uppercase bg-accent-ochre/10 text-accent-ochre px-2 py-0.5 rounded font-semibold">
|
|
Journey 6 / Iteration 04
|
|
</span>
|
|
<span className="text-xs text-text-muted font-mono">SCREEN-DISP-001</span>
|
|
</div>
|
|
<h2 className="text-xl font-bold text-text-primary tracking-tight mt-1 flex items-center gap-2">
|
|
<Truck className="w-5 h-5 text-sidebar-surface" />
|
|
Outbound Dispatch Board, Bilty & Fleet Registry
|
|
</h2>
|
|
<p className="text-xs text-text-muted">
|
|
Consignment scheduling, outward weighbridge gross/tare, electronic Bilty manifest generation, destination Proof of Delivery (POD), and fleet compliance.
|
|
</p>
|
|
</div>
|
|
|
|
<div className="flex items-center space-x-3">
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={fetchLogisticsData}
|
|
disabled={isLoading}
|
|
className="flex items-center space-x-1"
|
|
>
|
|
<RefreshCw className={`w-3.5 h-3.5 ${isLoading ? 'animate-spin' : ''}`} />
|
|
<span>Refresh</span>
|
|
</Button>
|
|
<Button
|
|
variant="secondary"
|
|
size="sm"
|
|
onClick={() => setIsNewVehicleModalOpen(true)}
|
|
className="flex items-center space-x-1"
|
|
>
|
|
<Plus className="w-3.5 h-3.5" />
|
|
<span>Enroll Vehicle</span>
|
|
</Button>
|
|
<Button
|
|
variant="primary"
|
|
size="sm"
|
|
onClick={() => setIsScheduleModalOpen(true)}
|
|
className="flex items-center space-x-1"
|
|
>
|
|
<Plus className="w-3.5 h-3.5" />
|
|
<span>Schedule Dispatch</span>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{/* Notification Banner */}
|
|
{notification && (
|
|
<div className={`p-3 rounded text-xs flex items-center justify-between border ${
|
|
notification.type === 'success'
|
|
? 'bg-status-normal-bg text-status-normal-text border-status-normal-text/20'
|
|
: 'bg-red-50 text-red-700 border-red-200'
|
|
}`}>
|
|
<div className="flex items-center space-x-2">
|
|
{notification.type === 'success' ? <CheckCircle2 className="w-4 h-4" /> : <AlertTriangle className="w-4 h-4" />}
|
|
<span>{notification.message}</span>
|
|
</div>
|
|
<button onClick={() => setNotification(null)} className="font-bold underline text-[11px]">Dismiss</button>
|
|
</div>
|
|
)}
|
|
|
|
{/* Sub-Tabs */}
|
|
<div className="flex border-b border-card-border space-x-4">
|
|
<button
|
|
onClick={() => setActiveTab('dispatches')}
|
|
className={`pb-2 text-xs font-semibold flex items-center space-x-2 border-b-2 transition ${
|
|
activeTab === 'dispatches'
|
|
? 'border-sidebar-surface text-sidebar-surface font-bold'
|
|
: 'border-transparent text-text-muted hover:text-text-primary'
|
|
}`}
|
|
>
|
|
<Truck className="w-3.5 h-3.5" />
|
|
<span>Outbound Dispatches & Bilty ({dispatches.length})</span>
|
|
</button>
|
|
<button
|
|
onClick={() => setActiveTab('fleet')}
|
|
className={`pb-2 text-xs font-semibold flex items-center space-x-2 border-b-2 transition ${
|
|
activeTab === 'fleet'
|
|
? 'border-sidebar-surface text-sidebar-surface font-bold'
|
|
: 'border-transparent text-text-muted hover:text-text-primary'
|
|
}`}
|
|
>
|
|
<ShieldCheck className="w-3.5 h-3.5" />
|
|
<span>Transport Fleet Registry ({fleet.length})</span>
|
|
</button>
|
|
</div>
|
|
|
|
{/* Tab 1: Outbound Dispatches */}
|
|
{activeTab === 'dispatches' && (
|
|
<Card className="p-0 overflow-hidden border border-card-border">
|
|
<div className="overflow-x-auto">
|
|
<table className="w-full text-left text-xs border-collapse">
|
|
<thead>
|
|
<tr className="bg-surface border-b border-card-border text-[11px] font-mono uppercase text-text-muted tracking-wider">
|
|
<th className="py-2.5 px-4 font-semibold">Dispatch / Bilty</th>
|
|
<th className="py-2.5 px-4 font-semibold">Sales Order</th>
|
|
<th className="py-2.5 px-4 font-semibold">Vehicle & Driver</th>
|
|
<th className="py-2.5 px-4 font-semibold">Destination</th>
|
|
<th className="py-2.5 px-4 font-semibold text-right">Net Weight MT</th>
|
|
<th className="py-2.5 px-4 font-semibold text-right">Bags</th>
|
|
<th className="py-2.5 px-4 font-semibold">Status</th>
|
|
<th className="py-2.5 px-4 font-semibold text-center">Actions</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-card-border">
|
|
{dispatches.map((d) => (
|
|
<tr key={d.dispatch_id} className="hover:bg-surface/50 transition">
|
|
<td className="py-3 px-4 font-mono font-bold text-text-primary">
|
|
{d.dispatch_number}
|
|
{d.bilty_number && (
|
|
<div className="text-[10px] text-accent-ochre font-semibold">{d.bilty_number}</div>
|
|
)}
|
|
</td>
|
|
<td className="py-3 px-4 font-mono font-medium">{d.sales_order_id}</td>
|
|
<td className="py-3 px-4">
|
|
<div className="font-semibold font-mono">{d.vehicle_reg || 'Assigned Fleet'}</div>
|
|
<div className="text-[11px] text-text-muted">{d.driver_name} • {d.driver_mobile}</div>
|
|
</td>
|
|
<td className="py-3 px-4 text-[11px] max-w-xs truncate">{d.delivery_destination}</td>
|
|
<td className="py-3 px-4 text-right font-mono font-bold text-text-primary">
|
|
{d.net_weight_mt ? `${Number(d.net_weight_mt).toFixed(3)} MT` : <span className="text-text-muted">-</span>}
|
|
</td>
|
|
<td className="py-3 px-4 text-right font-mono">
|
|
{d.bag_count ? `${d.bag_count} Bags` : <span className="text-text-muted">-</span>}
|
|
</td>
|
|
<td className="py-3 px-4">
|
|
<StatusPill status={d.status === 'POD_RECONCILED' ? 'normal' : 'watch'}>
|
|
{d.status}
|
|
</StatusPill>
|
|
</td>
|
|
<td className="py-3 px-4 text-center">
|
|
<div className="flex items-center justify-center space-x-1.5">
|
|
{d.status === 'SCHEDULED' && (
|
|
<Button
|
|
size="sm"
|
|
variant="primary"
|
|
onClick={() => {
|
|
setSelectedDispatch(d);
|
|
setIsWeighModalOpen(true);
|
|
}}
|
|
className="text-[11px] py-1 px-2 flex items-center gap-1"
|
|
>
|
|
<Scale className="w-3 h-3" />
|
|
<span>Weigh & Bilty</span>
|
|
</Button>
|
|
)}
|
|
{d.status === 'IN_TRANSIT' && (
|
|
<Button
|
|
size="sm"
|
|
variant="secondary"
|
|
onClick={() => {
|
|
setSelectedDispatch(d);
|
|
setReceivedWeight(d.net_weight_mt || 30.0);
|
|
setReceivedBags(d.bag_count || 600);
|
|
setIsPodModalOpen(true);
|
|
}}
|
|
className="text-[11px] py-1 px-2 flex items-center gap-1"
|
|
>
|
|
<FileCheck2 className="w-3 h-3" />
|
|
<span>Verify POD</span>
|
|
</Button>
|
|
)}
|
|
{d.status === 'POD_RECONCILED' && (
|
|
<span className="text-[10px] font-mono text-status-normal-text font-semibold flex items-center gap-1">
|
|
<ShieldCheck className="w-3.5 h-3.5" /> Reconciled
|
|
</span>
|
|
)}
|
|
</div>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</Card>
|
|
)}
|
|
|
|
{/* Tab 2: Transport Fleet Registry */}
|
|
{activeTab === 'fleet' && (
|
|
<Card className="p-0 overflow-hidden border border-card-border">
|
|
<div className="overflow-x-auto">
|
|
<table className="w-full text-left text-xs border-collapse">
|
|
<thead>
|
|
<tr className="bg-surface border-b border-card-border text-[11px] font-mono uppercase text-text-muted tracking-wider">
|
|
<th className="py-2.5 px-4 font-semibold">Registration No.</th>
|
|
<th className="py-2.5 px-4 font-semibold">Make & Model</th>
|
|
<th className="py-2.5 px-4 font-semibold text-right">Payload Capacity</th>
|
|
<th className="py-2.5 px-4 font-semibold">Ownership Type</th>
|
|
<th className="py-2.5 px-4 font-semibold">Transporter / Operator</th>
|
|
<th className="py-2.5 px-4 font-semibold">Fitness Expiry</th>
|
|
<th className="py-2.5 px-4 font-semibold">Status</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody className="divide-y divide-card-border">
|
|
{fleet.map((v) => (
|
|
<tr key={v.vehicle_id} className="hover:bg-surface/50 transition">
|
|
<td className="py-3 px-4 font-mono font-bold text-text-primary">{v.reg_no}</td>
|
|
<td className="py-3 px-4">{v.make_model}</td>
|
|
<td className="py-3 px-4 text-right font-mono font-semibold">{v.payload_capacity_mt} MT</td>
|
|
<td className="py-3 px-4 font-mono text-[11px]">{v.ownership_type}</td>
|
|
<td className="py-3 px-4">{v.transporter_name}</td>
|
|
<td className="py-3 px-4 font-mono text-[11px]">{v.fitness_expiry}</td>
|
|
<td className="py-3 px-4">
|
|
<StatusPill status={v.status === 'ACTIVE' ? 'normal' : 'watch'}>
|
|
{v.status}
|
|
</StatusPill>
|
|
</td>
|
|
</tr>
|
|
))}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</Card>
|
|
)}
|
|
|
|
{/* Modal 1: Schedule Dispatch */}
|
|
{isScheduleModalOpen && (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
|
<div className="bg-card-surface border border-card-border rounded-lg max-w-md w-full p-6 shadow-xl space-y-4">
|
|
<div className="flex items-center justify-between border-b border-card-border pb-3">
|
|
<h3 className="text-base font-bold text-text-primary flex items-center gap-2">
|
|
<Truck className="w-4 h-4 text-sidebar-surface" />
|
|
Schedule Outbound Consignment Dispatch
|
|
</h3>
|
|
<button onClick={() => setIsScheduleModalOpen(false)} className="text-text-muted hover:text-text-primary">×</button>
|
|
</div>
|
|
|
|
<form onSubmit={handleScheduleDispatch} className="space-y-3 text-xs">
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Sales Order Contract *</label>
|
|
<input
|
|
type="text"
|
|
required
|
|
value={salesOrderId}
|
|
onChange={(e) => setSalesOrderId(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Assigned Transport Vehicle *</label>
|
|
<select
|
|
value={vehicleId}
|
|
onChange={(e) => setVehicleId(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded bg-surface text-text-primary font-mono"
|
|
>
|
|
{fleet.map(f => (
|
|
<option key={f.vehicle_id} value={f.vehicle_id}>
|
|
{f.reg_no} ({f.make_model} - {f.payload_capacity_mt} MT)
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Driver Name *</label>
|
|
<input
|
|
type="text"
|
|
required
|
|
value={driverName}
|
|
onChange={(e) => setDriverName(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Driver Mobile *</label>
|
|
<input
|
|
type="tel"
|
|
required
|
|
value={driverMobile}
|
|
onChange={(e) => setDriverMobile(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Scheduled Date *</label>
|
|
<input
|
|
type="date"
|
|
required
|
|
value={dispatchDate}
|
|
onChange={(e) => setDispatchDate(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Destination Unloading Point *</label>
|
|
<input
|
|
type="text"
|
|
required
|
|
value={destination}
|
|
onChange={(e) => setDestination(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex justify-end space-x-2 pt-3 border-t border-card-border">
|
|
<Button type="button" variant="outline" size="sm" onClick={() => setIsScheduleModalOpen(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" variant="primary" size="sm">
|
|
Schedule Consignment
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Modal 2: Outward Weighbridge & Bilty */}
|
|
{isWeighModalOpen && selectedDispatch && (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
|
<div className="bg-card-surface border border-card-border rounded-lg max-w-md w-full p-6 shadow-xl space-y-4">
|
|
<div className="flex items-center justify-between border-b border-card-border pb-3">
|
|
<h3 className="text-base font-bold text-text-primary flex items-center gap-2">
|
|
<Scale className="w-4 h-4 text-sidebar-surface" />
|
|
Capture Outbound Scale & Issue Bilty
|
|
</h3>
|
|
<button onClick={() => setIsWeighModalOpen(false)} className="text-text-muted hover:text-text-primary">×</button>
|
|
</div>
|
|
|
|
<form onSubmit={handleWeighAndIssueBilty} className="space-y-3 text-xs">
|
|
<div className="bg-surface p-3 rounded font-mono text-[11px] space-y-1">
|
|
<div>Consignment: {selectedDispatch.dispatch_number}</div>
|
|
<div>Vehicle: {selectedDispatch.vehicle_reg}</div>
|
|
<div>Driver: {selectedDispatch.driver_name}</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Empty Tare MT *</label>
|
|
<input
|
|
type="number"
|
|
step="0.001"
|
|
required
|
|
value={tareWeight}
|
|
onChange={(e) => setTareWeight(parseFloat(e.target.value) || 0)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono font-bold bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Loaded Gross MT *</label>
|
|
<input
|
|
type="number"
|
|
step="0.001"
|
|
required
|
|
value={grossWeight}
|
|
onChange={(e) => setGrossWeight(parseFloat(e.target.value) || 0)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono font-bold bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Bilty Manifest Bag Count *</label>
|
|
<input
|
|
type="number"
|
|
required
|
|
value={biltyBags}
|
|
onChange={(e) => setBiltyBags(parseInt(e.target.value, 10) || 0)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
|
|
<div className="callout-ochre text-[11px] font-mono space-y-0.5">
|
|
<div className="font-bold text-text-primary">Net Bilty Weight Math:</div>
|
|
<div>Net Dispatched: {(grossWeight - tareWeight).toFixed(3)} MT</div>
|
|
<div>Manifest Doc: Will generate legal transport bilty upon submission.</div>
|
|
</div>
|
|
|
|
<div className="flex justify-end space-x-2 pt-3 border-t border-card-border">
|
|
<Button type="button" variant="outline" size="sm" onClick={() => setIsWeighModalOpen(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" variant="primary" size="sm">
|
|
Commit Bilty & Clear Vehicle
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Modal 3: Proof of Delivery (POD) */}
|
|
{isPodModalOpen && selectedDispatch && (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
|
<div className="bg-card-surface border border-card-border rounded-lg max-w-md w-full p-6 shadow-xl space-y-4">
|
|
<div className="flex items-center justify-between border-b border-card-border pb-3">
|
|
<h3 className="text-base font-bold text-text-primary flex items-center gap-2">
|
|
<FileCheck2 className="w-4 h-4 text-status-normal-text" />
|
|
Destination Proof of Delivery (POD) Verification
|
|
</h3>
|
|
<button onClick={() => setIsPodModalOpen(false)} className="text-text-muted hover:text-text-primary">×</button>
|
|
</div>
|
|
|
|
<form onSubmit={handleRecordPod} className="space-y-3 text-xs">
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Customer Received MT *</label>
|
|
<input
|
|
type="number"
|
|
step="0.001"
|
|
required
|
|
value={receivedWeight}
|
|
onChange={(e) => setReceivedWeight(parseFloat(e.target.value) || 0)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono font-bold bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Received Bags *</label>
|
|
<input
|
|
type="number"
|
|
required
|
|
value={receivedBags}
|
|
onChange={(e) => setReceivedBags(parseInt(e.target.value, 10) || 0)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Shortage Observation / Reason</label>
|
|
<textarea
|
|
rows={2}
|
|
value={shortageReason}
|
|
onChange={(e) => setShortageReason(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
|
|
<div className="flex justify-end space-x-2 pt-3 border-t border-card-border">
|
|
<Button type="button" variant="outline" size="sm" onClick={() => setIsPodModalOpen(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" variant="primary" size="sm">
|
|
Confirm POD & Settle
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
)}
|
|
|
|
{/* Modal 4: Enroll Fleet Vehicle */}
|
|
{isNewVehicleModalOpen && (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
|
|
<div className="bg-card-surface border border-card-border rounded-lg max-w-md w-full p-6 shadow-xl space-y-4">
|
|
<div className="flex items-center justify-between border-b border-card-border pb-3">
|
|
<h3 className="text-base font-bold text-text-primary flex items-center gap-2">
|
|
<Truck className="w-4 h-4 text-sidebar-surface" />
|
|
Enroll Transport Fleet Vehicle
|
|
</h3>
|
|
<button onClick={() => setIsNewVehicleModalOpen(false)} className="text-text-muted hover:text-text-primary">×</button>
|
|
</div>
|
|
|
|
<form onSubmit={handleRegisterVehicle} className="space-y-3 text-xs">
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Vehicle Reg No *</label>
|
|
<input
|
|
type="text"
|
|
required
|
|
value={fRegNo}
|
|
onChange={(e) => setFRegNo(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono uppercase bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Make & Model *</label>
|
|
<input
|
|
type="text"
|
|
required
|
|
value={fMakeModel}
|
|
onChange={(e) => setFMakeModel(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Payload Capacity MT *</label>
|
|
<input
|
|
type="number"
|
|
step="0.1"
|
|
required
|
|
value={fCapacity}
|
|
onChange={(e) => setFCapacity(parseFloat(e.target.value) || 0)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Ownership Type</label>
|
|
<select
|
|
value={fOwnerType}
|
|
onChange={(e) => setFOwnerType(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded bg-surface text-text-primary"
|
|
>
|
|
<option value="OWNED">OWNED</option>
|
|
<option value="DEDICATED_LEASE">DEDICATED LEASE</option>
|
|
<option value="SPOT_MARKET">SPOT MARKET</option>
|
|
</select>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 gap-3">
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Transporter Name *</label>
|
|
<input
|
|
type="text"
|
|
required
|
|
value={fTransporter}
|
|
onChange={(e) => setFTransporter(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
<div>
|
|
<label className="block font-medium text-text-muted mb-1">Fitness Expiry Date *</label>
|
|
<input
|
|
type="date"
|
|
required
|
|
value={fFitness}
|
|
onChange={(e) => setFFitness(e.target.value)}
|
|
className="w-full px-3 py-2 border border-card-border rounded font-mono bg-surface text-text-primary"
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="flex justify-end space-x-2 pt-3 border-t border-card-border">
|
|
<Button type="button" variant="outline" size="sm" onClick={() => setIsNewVehicleModalOpen(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button type="submit" variant="primary" size="sm">
|
|
Enroll Vehicle
|
|
</Button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
);
|
|
};
|