fix: multi-carrier shipping label support for Delhivery & require assigned carrier before label generation
This commit is contained in:
parent
d5b3595b21
commit
e966c83fd3
2 changed files with 115 additions and 109 deletions
|
|
@ -86,9 +86,11 @@ export const OrderDetailView: React.FC<OrderDetailViewProps> = ({ order, onBack,
|
|||
<button onClick={() => onReschedule(order)} className="button is-rounded" style={{ height: '44px', padding: '0 1.25rem', fontWeight: 600, backgroundColor: '#f6f3f2', color: '#1c1b1b', border: 'none', transition: 'all 0.2s', whiteSpace: 'nowrap' }}>
|
||||
Reschedule Courier
|
||||
</button>
|
||||
<button onClick={() => onPrintLabel(order)} className="button is-rounded is-flex is-align-items-center gap-2 shadow-sm" style={{ height: '44px', padding: '0 1.5rem', fontWeight: 600, backgroundColor: '#5a0118', color: '#ffffff', border: 'none', transition: 'all 0.2s', whiteSpace: 'nowrap' }}>
|
||||
<Printer size={18} /> Print Shipping Label
|
||||
</button>
|
||||
{order.awbNumber && order.awbNumber !== 'Pending' && order.awbNumber !== 'N/A' && order.status !== 'new' && order.status !== 'accepted' && (
|
||||
<button onClick={() => onPrintLabel(order)} className="button is-rounded is-flex is-align-items-center gap-2 shadow-sm" style={{ height: '44px', padding: '0 1.5rem', fontWeight: 600, backgroundColor: '#5a0118', color: '#ffffff', border: 'none', transition: 'all 0.2s', whiteSpace: 'nowrap' }}>
|
||||
<Printer size={18} /> Print Shipping Label
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
|||
|
|
@ -173,6 +173,10 @@ export const OrdersPage: React.FC = () => {
|
|||
};
|
||||
|
||||
const handleFetchPrintLabel = async (ord: OrderItem) => {
|
||||
if (!ord.awbNumber || ord.awbNumber === 'Pending' || ord.awbNumber === 'N/A' || ord.status === 'new' || ord.status === 'accepted') {
|
||||
alert('Shipping label can only be generated after a carrier is assigned to the order. Please mark the order Ready to Ship first.');
|
||||
return;
|
||||
}
|
||||
setIsLoading(true);
|
||||
try {
|
||||
const res = await getOrderLabel(ord.id);
|
||||
|
|
@ -551,14 +555,6 @@ export const OrdersPage: React.FC = () => {
|
|||
>
|
||||
<CheckCircle2 size={14} className="mr-1" /> Accept
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleFetchPrintLabel(ord)}
|
||||
className="button is-small is-rounded is-light"
|
||||
disabled={isLoading}
|
||||
title="Print Shipping Label & Pack"
|
||||
>
|
||||
<Printer size={14} className="mr-1" /> Print Label
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleRejectOrder(ord)}
|
||||
className="button is-small is-rounded is-danger is-light"
|
||||
|
|
@ -586,14 +582,6 @@ export const OrdersPage: React.FC = () => {
|
|||
>
|
||||
<Send size={14} className="mr-1" /> Track
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleFetchPrintLabel(ord)}
|
||||
className="button is-small is-rounded is-light"
|
||||
disabled={isLoading}
|
||||
title="Print Shipping Label & Pack"
|
||||
>
|
||||
<Printer size={14} className="mr-1" /> Print Label
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleRejectOrder(ord)}
|
||||
className="button is-small is-rounded is-danger is-light"
|
||||
|
|
@ -694,106 +682,122 @@ export const OrdersPage: React.FC = () => {
|
|||
</div>
|
||||
|
||||
{/* MODAL: Thermal Shipping Label View */}
|
||||
{selectedOrderForLabel && (
|
||||
<div className="modal is-active">
|
||||
<div className="modal-background" onClick={() => setSelectedOrderForLabel(null)}></div>
|
||||
<div className="modal-card" style={{ maxWidth: '480px' }}>
|
||||
<header className="modal-card-head" style={{ background: '#ffffff', borderBottom: '1px solid var(--trad-border)' }}>
|
||||
<p className="modal-card-title is-size-6 has-text-weight-bold">
|
||||
Shadowfax 360 Official Shipping Label (4x6)
|
||||
</p>
|
||||
<button className="delete" aria-label="close" onClick={() => setSelectedOrderForLabel(null)}></button>
|
||||
</header>
|
||||
<section className="modal-card-body p-4 has-text-centered" style={{ background: '#EAEAEA' }}>
|
||||
<div id="printable-shadowfax-label" className="thermal-label-container has-text-left" style={{ background: '#ffffff', border: '2px solid #000', padding: '14px', borderRadius: '4px', fontFamily: 'Arial, sans-serif', color: '#000' }}>
|
||||
|
||||
{/* Header Bar */}
|
||||
<div className="is-flex is-justify-content-space-between is-align-items-center mb-1 pb-1" style={{ borderBottom: '2px solid #000' }}>
|
||||
<span className="has-text-weight-black is-size-7" style={{ color: '#006b3e' }}>SHADOWFAX 360</span>
|
||||
<span className="has-text-weight-black is-size-6">
|
||||
{selectedOrderForLabel.package_details?.payment_mode || selectedOrderForLabel.payment_mode || (selectedOrderForLabel.package_details?.collectible_amount === 0 ? 'PREPAID' : 'COD')}
|
||||
</span>
|
||||
<span className="has-text-weight-bold is-size-7">Tradhox</span>
|
||||
</div>
|
||||
{selectedOrderForLabel && (() => {
|
||||
const carrierStr = (selectedOrderForLabel.carrier || '').toLowerCase();
|
||||
const awbStr = String(selectedOrderForLabel.awb_number || '').trim();
|
||||
const isDelhivery = carrierStr.includes('delhivery') || (/^(698|179|139|142|12|14)/.test(awbStr) && awbStr.length >= 12);
|
||||
const payMode = selectedOrderForLabel.package_details?.payment_mode || selectedOrderForLabel.payment_mode || (selectedOrderForLabel.package_details?.collectible_amount === 0 ? 'PREPAID' : 'COD');
|
||||
const sortCode = selectedOrderForLabel.sort_code || (isDelhivery ? 'CHE/TMP' : 'S46');
|
||||
const destHub = selectedOrderForLabel.destination_hub || (isDelhivery ? 'Chennai' : 'BLR/CTL');
|
||||
|
||||
{/* Top Barcode & AWB */}
|
||||
<div className="mb-2 has-text-centered py-1" style={{ borderBottom: '2px solid #000' }}>
|
||||
{selectedOrderForLabel.barcode_url ? (
|
||||
<img src={selectedOrderForLabel.barcode_url} alt="AWB Barcode" style={{ width: '180px', height: '50px', objectFit: 'contain' }} className="mx-auto" />
|
||||
) : (
|
||||
<div className="is-flex is-justify-content-center py-2" style={{ background: '#000', height: '36px', letterSpacing: '4px', color: '#fff', fontSize: '10px', alignItems: 'center' }}>
|
||||
||||||| | ||||| |||| || |||||| | ||||| ||||
|
||||
</div>
|
||||
)}
|
||||
<div className="is-flex is-justify-content-space-between is-align-items-center px-1" style={{ fontSize: '11px', fontWeight: 'bold' }}>
|
||||
<span>#Box: 1</span>
|
||||
<span style={{ fontSize: '13px', letterSpacing: '1px' }}>{selectedOrderForLabel.awb_number || 'SF42056592007'}</span>
|
||||
<span>BLR/CTL</span>
|
||||
return (
|
||||
<div className="modal is-active">
|
||||
<div className="modal-background" onClick={() => setSelectedOrderForLabel(null)}></div>
|
||||
<div className="modal-card" style={{ maxWidth: '480px' }}>
|
||||
<header className="modal-card-head" style={{ background: '#ffffff', borderBottom: '1px solid var(--trad-border)' }}>
|
||||
<p className="modal-card-title is-size-6 has-text-weight-bold">
|
||||
{isDelhivery ? 'Delhivery B2C Official Shipping Label (4x6)' : 'Shadowfax 360 Official Shipping Label (4x6)'}
|
||||
</p>
|
||||
<button className="delete" aria-label="close" onClick={() => setSelectedOrderForLabel(null)}></button>
|
||||
</header>
|
||||
<section className="modal-card-body p-4 has-text-centered" style={{ background: '#EAEAEA' }}>
|
||||
<div id="printable-thermal-label" className="thermal-label-container has-text-left" style={{ background: '#ffffff', border: '2px solid #000', padding: '14px', borderRadius: '4px', fontFamily: 'Arial, sans-serif', color: '#000' }}>
|
||||
|
||||
{/* Header Bar */}
|
||||
<div className="is-flex is-justify-content-space-between is-align-items-center mb-1 pb-1" style={{ borderBottom: '2px solid #000' }}>
|
||||
<span className="has-text-weight-black is-size-7" style={{ color: isDelhivery ? '#D32F2F' : '#006b3e', letterSpacing: '1px' }}>
|
||||
{isDelhivery ? 'DELHIVERY SURFACE' : 'SHADOWFAX 360'}
|
||||
</span>
|
||||
<span className="has-text-weight-black is-size-6">
|
||||
{payMode}
|
||||
</span>
|
||||
<span className="has-text-weight-bold is-size-7">Tradhox</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Huge Black Banner */}
|
||||
<div className="has-text-centered py-1 mb-2" style={{ background: '#000', color: '#fff', fontSize: '24px', fontWeight: '900', letterSpacing: '2px' }}>
|
||||
SF360
|
||||
</div>
|
||||
{/* Top Barcode & AWB */}
|
||||
<div className="mb-2 has-text-centered py-1" style={{ borderBottom: '2px solid #000' }}>
|
||||
{selectedOrderForLabel.barcode_url ? (
|
||||
<img src={selectedOrderForLabel.barcode_url} alt="AWB Barcode" style={{ width: '220px', height: '52px', objectFit: 'contain' }} className="mx-auto" />
|
||||
) : (
|
||||
<div className="is-flex is-justify-content-center py-2" style={{ background: '#000', height: '36px', letterSpacing: '4px', color: '#fff', fontSize: '10px', alignItems: 'center' }}>
|
||||
||||||| | ||||| |||| || |||||| | ||||| ||||
|
||||
</div>
|
||||
)}
|
||||
<div className="is-flex is-justify-content-space-between is-align-items-center px-1" style={{ fontSize: '11px', fontWeight: 'bold' }}>
|
||||
<span>#Box: 1</span>
|
||||
<span style={{ fontSize: '13px', letterSpacing: '1px' }}>{awbStr || 'Pending'}</span>
|
||||
<span>{destHub}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* QR Code & Sorting Hub Code */}
|
||||
<div className="is-flex is-align-items-center is-justify-content-center gap-4 mb-2 pb-2" style={{ borderBottom: '2px solid #000' }}>
|
||||
<img src={`https://api.qrserver.com/v1/create-qr-code/?data=${selectedOrderForLabel.awb_number || 'SF42056592007'}&size=70x70`} alt="2D QR Code" style={{ width: '60px', height: '60px' }} />
|
||||
<span style={{ fontSize: '32px', fontWeight: '900' }}>S46</span>
|
||||
</div>
|
||||
{/* Huge Carrier Banner */}
|
||||
<div className="has-text-centered py-1 mb-2" style={{ background: isDelhivery ? '#D32F2F' : '#000', color: '#fff', fontSize: isDelhivery ? '18px' : '24px', fontWeight: '900', letterSpacing: '2px' }}>
|
||||
{isDelhivery ? 'DELHIVERY B2C' : 'SF360'}
|
||||
</div>
|
||||
|
||||
{/* Seller & Customer Details */}
|
||||
<div className="mb-2 pb-2" style={{ borderBottom: '1px solid #000', fontSize: '11px', lineHeight: '1.35' }}>
|
||||
<div><strong>Seller:</strong> {selectedOrderForLabel.sender?.name || 'tradhox'} (Ph: {selectedOrderForLabel.sender?.phone || '9123456789'})</div>
|
||||
<div><strong>(Seller GSTIN: 33AWRPV3071D1ZC)</strong></div>
|
||||
<div>{selectedOrderForLabel.sender?.address || '154-sabestian illam, irumbuliyur, arul nagar, east tambaram'}</div>
|
||||
<div className="mt-1"><strong>Customer:</strong> {selectedOrderForLabel.recipient?.name || 'Customer'} (Ph: {selectedOrderForLabel.recipient?.phone || 'N/A'})</div>
|
||||
<div>{selectedOrderForLabel.recipient?.address || 'Customer Address Line 1, Bengaluru - 560038'}</div>
|
||||
</div>
|
||||
{/* QR Code & Sorting Hub Code */}
|
||||
<div className="is-flex is-align-items-center is-justify-content-center gap-4 mb-2 pb-2" style={{ borderBottom: '2px solid #000' }}>
|
||||
<img src={`https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(awbStr)}&size=70x70`} alt="2D QR Code" style={{ width: '60px', height: '60px' }} />
|
||||
<div className="has-text-centered">
|
||||
<span style={{ fontSize: '28px', fontWeight: '900', display: 'block', lineHeight: 1 }}>{sortCode}</span>
|
||||
<span style={{ fontSize: '10px', fontWeight: 'bold', color: '#555' }}>ROUTING HUB</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Client Order ID Barcode */}
|
||||
<div className="mb-2 has-text-centered pb-2" style={{ borderBottom: '1px solid #000' }}>
|
||||
<img src={`https://api.qrserver.com/v1/create-qr-code/?data=${selectedOrderForLabel.order_id || '3-14'}&size=140x40`} alt="Order ID Barcode" style={{ width: '150px', height: '35px', objectFit: 'contain' }} className="mx-auto" />
|
||||
<div style={{ fontSize: '11px', fontWeight: 'bold' }}>COID: {selectedOrderForLabel.order_id || '3-14'}</div>
|
||||
</div>
|
||||
{/* Seller & Customer Details */}
|
||||
<div className="mb-2 pb-2" style={{ borderBottom: '1px solid #000', fontSize: '11px', lineHeight: '1.35' }}>
|
||||
<div><strong>Seller:</strong> {selectedOrderForLabel.sender?.name || 'test store'} (Ph: {selectedOrderForLabel.sender?.phone || '9600494039'})</div>
|
||||
<div><strong>(Seller GSTIN: 33AWRPV3071D1ZC)</strong></div>
|
||||
<div>{selectedOrderForLabel.sender?.address || '154-sabestian illam, irumbuliyur, arul nagar, east tambaram'}</div>
|
||||
<div className="mt-1"><strong>Customer (Ship To):</strong> {selectedOrderForLabel.recipient?.name || 'Customer'} (Ph: {selectedOrderForLabel.recipient?.phone || 'N/A'})</div>
|
||||
<div>{selectedOrderForLabel.recipient?.address || 'Customer Address'}</div>
|
||||
</div>
|
||||
|
||||
{/* Return Origin */}
|
||||
<div className="mb-1 pb-1" style={{ fontSize: '10px', lineHeight: '1.3' }}>
|
||||
<strong>Return Address:</strong> {selectedOrderForLabel.sender?.address || '154-sabestian illam, irumbuliyur, arul nagar, east tambaram, Chennai-600059'}
|
||||
</div>
|
||||
{/* Client Order ID Barcode */}
|
||||
<div className="mb-2 has-text-centered pb-2" style={{ borderBottom: '1px solid #000' }}>
|
||||
<img src={`https://api.qrserver.com/v1/create-qr-code/?data=${encodeURIComponent(selectedOrderForLabel.order_id || '')}&size=140x40`} alt="Order ID Barcode" style={{ width: '150px', height: '35px', objectFit: 'contain' }} className="mx-auto" />
|
||||
<div style={{ fontSize: '11px', fontWeight: 'bold' }}>COID: {selectedOrderForLabel.order_id || ''}</div>
|
||||
</div>
|
||||
|
||||
{/* Declaration */}
|
||||
<div style={{ fontSize: '9px', fontStyle: 'italic', borderTop: '1px solid #ccc', paddingTop: '4px' }}>
|
||||
Declaration: Contents of this package are being purchased for personal purpose and not for resale
|
||||
</div>
|
||||
{/* Return Origin */}
|
||||
<div className="mb-1 pb-1" style={{ fontSize: '10px', lineHeight: '1.3' }}>
|
||||
<strong>Return Address:</strong> {selectedOrderForLabel.sender?.address || '154-sabestian illam, irumbuliyur, arul nagar, east tambaram, Chennai-600059'}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
<footer className="modal-card-foot" style={{ background: '#ffffff', borderTop: '1px solid var(--trad-border)', justifyContent: 'space-between' }}>
|
||||
<button className="button is-small is-rounded" onClick={() => setSelectedOrderForLabel(null)}>Close</button>
|
||||
<div className="is-flex gap-2">
|
||||
<button
|
||||
className="button is-small is-rounded is-info is-light"
|
||||
onClick={() => {
|
||||
const awb = selectedOrderForLabel.awb_number || '';
|
||||
const cId = selectedOrderForLabel.order_id || '';
|
||||
const url = `http://localhost:8002/label/?awb=${encodeURIComponent(awb)}&order_id=${encodeURIComponent(cId)}&auto_print=1`;
|
||||
window.open(url, '_blank');
|
||||
}}
|
||||
>
|
||||
<Printer size={14} className="mr-1" />
|
||||
<span>Open Full PDF / HTML</span>
|
||||
</button>
|
||||
<button className="button is-trad-primary is-small is-rounded" onClick={() => window.print()}>
|
||||
<Printer size={14} className="mr-1" />
|
||||
<span>Print 4x6 Label</span>
|
||||
</button>
|
||||
</div>
|
||||
</footer>
|
||||
{/* Declaration */}
|
||||
<div style={{ fontSize: '9px', fontStyle: 'italic', borderTop: '1px solid #ccc', paddingTop: '4px' }}>
|
||||
Declaration: Contents of this package are being purchased for personal purpose and not for resale
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</section>
|
||||
<footer className="modal-card-foot" style={{ background: '#ffffff', borderTop: '1px solid var(--trad-border)', justifyContent: 'space-between' }}>
|
||||
<button className="button is-small is-rounded" onClick={() => setSelectedOrderForLabel(null)}>Close</button>
|
||||
<div className="is-flex gap-2">
|
||||
<button
|
||||
className="button is-small is-rounded is-info is-light"
|
||||
onClick={() => {
|
||||
if (selectedOrderForLabel.pdf_url) {
|
||||
window.open(selectedOrderForLabel.pdf_url, '_blank');
|
||||
} else {
|
||||
window.print();
|
||||
}
|
||||
}}
|
||||
title={selectedOrderForLabel.pdf_url ? 'Download Official Carrier PDF' : 'Print Thermal Label'}
|
||||
>
|
||||
<Printer size={14} className="mr-1" />
|
||||
<span>{selectedOrderForLabel.pdf_url ? 'Open Official PDF' : 'Print Preview'}</span>
|
||||
</button>
|
||||
<button className="button is-trad-primary is-small is-rounded" onClick={() => window.print()}>
|
||||
<Printer size={14} className="mr-1" />
|
||||
<span>Print 4x6 Label</span>
|
||||
</button>
|
||||
</div>
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
);
|
||||
})()}
|
||||
|
||||
{/* MODAL: Live Shipment Tracking */}
|
||||
{trackingInfo && (
|
||||
|
|
|
|||
Loading…
Reference in a new issue