1import{W as be,r as l,N as e,bQ as Fe,cA as Te,bP as Ae,hv as Ee,a3 as oe,a4 as F,b5 as T,bR as A,bS as z,fJ as ge,cP as Le,Q as g,U as qe,V as Ie,bA as Be,bU as Me}from"./vendor-B37zWZef.js";import{aT as xe,C as ve,a as We,g as K,ae as Ve,ad as De,p as Pe,z as E,c as ae,aq as pe,M as ze,T as ne,am as Oe}from"./index-CvrbYQit.js";import{C as Ue}from"./CustomContainer-BC8L5667.js";import{g as fe,R as Ge}from"./GateEntry-CC35tGh8.js";import{S as Qe}from"./Subheading-DuK1xyO8.js";import{T as $e}from"./TruckNumberWrapper-2sbAcc1a.js";import{u as He}from"./useTruckVerification-BlN4J8w5.js";import{S as le}from"./StyledSelect-C0xCJyrr.js";import{F as Ye}from"./fieldStyles-B03nNltY.js";import{D as Je}from"./Driver-BTqvqsfS.js";import"./vendor-lottie-qO2cA9l8.js";import"./compressImage-EoI29Vu7.js";import"./Alert-CpB0fhn1.js";import"./VehicleNumberPlate-BTyLl_nP.js";import"./Transporter-Cqiki9ev.js";import"./BulkerIcon-sPu7X0Tg.js";import"./Description-DJXVWYxs.js";import"./RefreshBtn-B3jcDHSF.js";import"./FormField-BNg2y4Td.js";import"./StatusBadge-BRqTHHTc.js";import"./TruckIcon-DWhFWiVp.js";const Ke=({driverData:t,inquiry:u,selectedTransporter:c,onGatePassGenerated:j,modalOpenedByButton:L,activeStep:s,isCustomerTruckFlow:M})=>{const{inquiryId:q,driverId:X}=be(),p=M??xe(u),f=r=>r==null?"":String(r).trim(),N=r=>f(r?.gps_device_id_value||r?.gps_device_id||r?.device_id||""),W=new Date().getFullYear(),Z=[W.toString(),(W+1).toString()],[x,ee]=l.useState(t?.empty_weight||0),[O,d]=l.useState(t?.capture_mode||"Manual"),U=localStorage.getItem("user"),I=U?JSON.parse(U):null,[o,C]=l.useState({soNumber:u?.inquiry_source?.number||"",soYear:Z[0],vehicleNumber:t?.truck_number||"",deviceId:N(t),driverName:t?.driver_name||"",driverContact:t?.driver_mobile||"",driverLicense:t?.license_number||"",isVerified:t?.is_verified||null,transporter:p?"N/A":c?.organization_name||"",vehicleType:p?"N/A":c?.truck_type||""}),[re,V]=l.useState(!1),[te,G]=l.useState(!1),[a,i]=l.useState([]),[n,_]=l.useState(t?.loaded_weight?t.loaded_weight.toString():""),[h,k]=l.useState(""),[y,Q]=l.useState(""),[S,$]=l.useState(!1),{isVerified:de,verificationLoading:_e,vehicleInfo:ce,verificationStatus:ye,verificationError:je,verifyTruck:ke}=He({onSuccess:r=>{}});l.useEffect(()=>{t&&(C(r=>({...r,vehicleNumber:t.truck_number||r.vehicleNumber,deviceId:N(t),driverName:t.driver_name||r.driverName,driverContact:t.driver_mobile||r.driverContact,driverLicense:t.license_number||r.driverLicense})),ee(t.empty_weight||0),k(t.empty_weight?"MT":""),Q(t.loaded_weight?"MT":""),d(t.capture_mode||"Manual"),_(t.loaded_weight?t.loaded_weight.toString():""))},[t]),l.useEffect(()=>{u&&C(r=>({...r,soNumber:u?.inquiry_source?.number||r.soNumber,transporter:p?"N/A":c?.organization_name||r.transporter,vehicleType:p?"N/A":c?.truck_type||r.vehicleType}))},[u,c]);const we=()=>{ke(o.vehicleNumber)},ue=t?.loaded_weight!==null&&t?.loaded_weight!==void 0||!!t?.final_weight_timestamp,D={...Ye};l.useEffect(()=>{(async()=>{try{const m=(await K("/gps-devices?offset=0&limit=1000&search=&order=asc"))?.data,w=m?.trackingDeviceListing||m?.gpsDeviceListing||m?.GPSDeviceListing||m?.rows||(Array.isArray(m)?m:[]);i((w||[]).map(b=>({...b,device_id:f(b?.device_id||b?.gps_device_id||b?.gps_device_id_value)})))}catch{i([])}})()},[]);const me=t?.status||"",P=f(o.deviceId),se=a.find(r=>f(r?.id)===P||f(r?.device_id)===P),R=se?f(se.id):P,Ne=a.some(r=>f(r?.id)===R),B=se?.id||"",H=r=>{const{name:v,value:m}=r.target;let w=m;v==="truckNumber"?w=pe.truck(m):v==="driverContact"&&(w=pe.mobile(m)),C({...o,[v]:w})},he=async r=>{r&&r.preventDefault&&r.preventDefault();const v=s===2||s===1;if(s===0){if(!o.vehicleNumber||!o.driverName||!o.driverContact){g.error("Please fill all required fields");return}if(!Ve.test(o.driverContact)){g.error("Please enter a valid 10-digit mobile number starting with 6-9");return}if(!De.test(o.vehicleNumber)){g.error("Please enter a valid truck number (e.g., MH12AB1234)");return}if(!q&&(!u||!p&&!c)){g.error("Inquiry or Transporter details are missing. Please try again.");return}if(!p&&(!u?.hired_transporter_details&&!q||!Array.isArray(u?.hired_transporter_details)&&!q)){g.error("Inquiry is missing hired transporter details");return}}if(s===1){if(!x){g.error("Tare weight is required.");return}if(!h){g.error("Please select a unit for Tare weight.");return}}if(s===2){if(!n){g.error("Gross weight is required.");return}if(!y){g.error("Please select a unit for Gross weight.");return}const m=y==="kg"?parseFloat(n)/1e3:parseFloat(n),w=parseFloat(x);if(m<w){g.error("Gross weight should be more than tare Weight.");return}}if(s===3){g.error("The Truck is already dispatched.");return}if((s===1||s===2)&&!S){$(!0);return}try{S&&$(!1),V(!0);const m=t?"delivery/updateStatusManually":"truckDetails/add-driver-at-gate";
1if(v){const Y="truckDetails/update-driver-at-gate",Se={truck_number:o.vehicleNumber,driver_name:o.driverName,driver_mobile:o.driverContact,license_number:o.driverLicense,...B?{gps_device_id:B}:{},additional_information:"",empty_weight:s===1&&h==="kg"?parseFloat(x)/1e3:parseFloat(x),...s===2&&{loaded_weight:s===2&&y==="kg"?parseFloat(n)/1e3:parseFloat(n)},id:t.id,inquiry_id:Number(u.id),...!p&&{quote_id:Number(c?.quote_id),transporter_id:c?.transporter_id}},ie=await Pe(E.createUrl(Y),Se);if(!ie||ie.error){g.error("Error: "+(ie?.message||"Failed to save driver details"));return}const Re={inquiry_id:Number(u?.id),driver_id:t?.id,update_status:s===1?"Loading":"Dispatch",no_of_truck:p?1:c?.no_of_truck,...!p&&{quote_id:Number(c?.quote_id)}},J=await ae(E.createUrl("delivery/updateStatusManually"),Re);if(!J||J.error){g.error("Error: "+(J?.message||"Failed to save driver details"));return}g.success(J?.message||"Final submit Successfully."),j&&j(!0);return}const w=t?s===0?{inquiry_id:Number(u.id),update_status:"Truck Arrived",driver_id:t.id,...B?{gps_device_id:B}:{},is_verified:de,vahan_data:ce,...!p&&{quote_id:Number(c?.quote_id),no_of_truck:c?.no_of_truck}}:{no_of_truck:p?1:c?.no_of_truck,update_status:"Loading",inquiry_id:Number(u.id),quote_id:p?null:Number(c?.quote_id),driver_id:t?.id||c?.driver_id,empty_weight:s===1&&h==="kg"?parseFloat(x)/1e3:parseFloat(x),capture_mode:O,operator_id:I?.id}:{truck_number:o.vehicleNumber,driver_name:o.driverName,driver_mobile:o.driverContact,license_number:o.driverLicense||"",...B?{gps_device_id:B}:{},is_verified:de,vahan_data:ce,inquiry_id:q||Number(u?.id),...!p&&c&&{quote_id:Number(c?.quote_id),transporter_id:c?.transporter_id}},b=await ae(E.createUrl(m),w);if(!b||b.error){g.error("Error: "+(b?.message||"Failed to save driver details"));return}if(g.success(b?.message||"Truck Arrived Successfully."),j){const Y=b.data?.id||b.data?.driver_id||b.data?.truck_id||b.id;console.log("GateEntry response:",b,"newId:",Y),j(Y)}}catch(m){console.error("Error saving driver details:",m)}finally{V(!1)}},Ce=async r=>{try{const v={token:r,no_of_truck:c?.no_of_truck,update_status:"Truck Arrived",driver_id:t?.id},m=await ae(E.createUrl("/delivery/updateStatusbyQR-erp"),v);m.error?g.error(m.message||"Failed to process QR code"):(g.success("Truck Arrived Successfully."),G(!1),j&&j(!0))}catch(v){console.error("QR scan error:",v)}};return e.jsxs("div",{children:[e.jsx(Fe,{onSubmit:he,children:e.jsxs("div",{className:"mb-4 px-2",children:[e.jsx(Qe,{children:"Gate Entry & Vehicle Registration"}),e.jsx("h6",{className:"pb-2 mb-3 fw-semibold",children:"Register Vehicle and Driver Details"}),e.jsx(Te,{children:e.jsxs(Ae,{children:[e.jsxs("div",{style:fe.header,children:[e.jsx(Ee,{}),e.jsx("p",{style:fe.headerTitle,children:"Vehicle & Driver Details"})]}),e.jsxs(oe,{className:"mt-2",children:[e.jsx(F,{md:6,children:e.jsxs(T,{children:[e.jsx(A,{children:"Vehicle Number *"}),e.jsx($e,{name:"vehicleNumber",isDisabled:s!==0,inputValue:o.vehicleNumber,handleCarriageInputChange:H,verificationStatus:ye||o?.isVerified,verifyTruck:we,verificationError:je,verificationLoading:_e,truckError:null})]})}),e.jsx(F,{md:6,children:e.jsxs(T,{children:[e.jsx(A,{children:"Driver Name *"}),e.jsx(z,{name:"driverName",style:D,value:o.driverName,onChange:H,disabled:!!t?.truck_arrived_timestamp,required:!0})]})})]}),e.jsxs(oe,{children:[e.jsx(F,{md:6,children:e.jsxs(T,{children:[e.jsx(A,{children:"Driver Contact *"}),e.jsx(z,{name:"driverContact",style:D,value:o.driverContact,onChange:H,disabled:!!t?.truck_arrived_timestamp,required:!0})]})}),e.jsx(F,{md:6,children:e.jsxs(T,{children:[e.jsx(A,{children:"Driver License"}),e.jsx(z,{name:"driverLicense",style:D,value:o.driverLicense,onChange:H,disabled:!!t?.truck_arrived_timestamp,required:!0})]})}),s===0&&e.jsx(F,{md:6,children:e.jsxs(T,{children:[e.jsx(A,{children:"Device ID"}),e.jsx(le,{options:[...R&&!Ne?[{value:R,label:P||"N/A"}]:[],...a.map(r=>({value:f(r.id),label:f(r.device_id)||"N/A"}))],value:R?{value:R,label:a.find(r=>f(r.id)===R)&&(f(a.find(r=>f(r.id)===R)?.device_id)||"N/A")||P||"N/A"}:null,onChange:r=>C(v=>({...v,deviceId:r?.value||""})),placeholder:"Select Device ID",isDisabled:!!t?.truck_arrived_timestamp})]})})]}),e.jsxs(oe,{children:[s>0&&e.jsx(F,{md:6,children:e.jsxs(T,{children:[e.jsx(A,{className:"fw-bold text-dark mb-1",children:"Tare Weight *"}),e.jsxs(ge,{style:{borderRadius:"12px",overflow:"hidden"},children:[e.jsx(z,{name:"empty_weight",style:{...D,borderTopRightRadius:0,borderBottomRightRadius:0,borderRight:"none",padding:"0.6rem 1rem"},value:x,onChange:r=>ee(r.target.value),disabled:t?.empty_weight,required:!0,placeholder:"0.00"}),e.jsx("div",{style:{flex:"0 0 140px",borderLeft:"none"},children:e.jsx(le,{options:[{value:"MT",label:"MT"},{value:"kg",label:"kg"}],value:h?{value:h,label:h}:null,onChange:r=>k(r?.value||""),placeholder:"Select Unit",isDisabled:t?.empty_weight,customStyles:{control:r=>({...r,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeft:"none",border:"1px solid var(--border-color, #E4E5E8)",backgroundColor:"#F9FAFB",minHeight:"45px",boxShadow:"none","&:hover":{borderColor:"var(--border-color, #E4E5E8)"}})}})})]})]})}),s>1&&e.jsx(F,{md:6,children:e.jsxs(T,{children:[e.jsx(A,{className:"fw-bold text-dark mb-1",children:"Gross Weight *"}),e.jsxs(ge,{style:{borderRadius:"12px",overflow:"hidden"},children:[e.jsx(z,{name:"grossWeight",value:n,style:{...D,borderTopRightRadius:0,borderBottomRightRadius:0,borderRight:"none",padding:"0.6rem 1rem",he
1ight:"45px"},onChange:r=>_(r.target.value),placeholder:"0.00",disabled:ue,required:!0}),e.jsx("div",{style:{flex:"0 0 140px",borderLeft:"none"},children:e.jsx(le,{options:[{value:"MT",label:"MT"},{value:"kg",label:"kg"}],value:y?{value:y,label:y}:null,onChange:r=>Q(r?.value||""),placeholder:"Select Unit",isDisabled:ue,customStyles:{control:r=>({...r,borderTopLeftRadius:0,borderBottomLeftRadius:0,borderLeft:"none",border:"1px solid var(--border-color, #E4E5E8)",backgroundColor:"#F9FAFB",minHeight:"45px",boxShadow:"none","&:hover":{borderColor:"var(--border-color, #E4E5E8)"}})}})})]})]})})]}),e.jsx("div",{className:"d-flex justify-content-end gap-2 mt-4",children:e.jsx(ve,{variant:"submit",type:"submit",label:s===0?"Register Driver":s===1?"Add Tare Weight":"Add Gross Weight",loading:re,disabled:me!==null&&me!==""&&s===0||s===1&&t?.empty_weight||s===2&&t?.loaded_weight||s===3})})]})})]},"0")}),e.jsx(Ge,{isOpen:te,toggle:()=>G(!1),onScan:Ce,title:"Gate Entry QR Scanner"}),e.jsx(We,{isOpen:S,toggle:()=>$(!1),title:"Confirm Weight Details",primaryAction:{label:"Confirm & Submit",onClick:()=>{he()},variant:"submit"},secondaryAction:{label:"Cancel",onClick:()=>$(!1)},isLoading:re,children:e.jsxs("div",{className:"text-center p-3",children:[e.jsx(Le,{size:48,className:"text-success mb-3"}),e.jsx("h5",{className:"mb-2",children:"Verify Weight Information"}),e.jsx("p",{className:"text-muted mb-4",children:"Please confirm the following weight details before submitting:"}),e.jsxs("div",{className:"bg-light p-4 rounded-3 text-start border",children:[e.jsxs("div",{className:"d-flex justify-content-between mb-3",children:[e.jsx("span",{className:"text-muted",children:"Step:"}),e.jsx("span",{className:"fw-bold text-dark",children:s===1?"Tare Weight (Loading)":"Gross Weight (Dispatch)"})]}),e.jsxs("div",{className:"d-flex justify-content-between mb-3",children:[e.jsx("span",{className:"text-muted",children:"Entered Value:"}),e.jsxs("span",{className:"fw-bold text-dark",children:[s===1?x:n," ",s===1?h:y]})]}),(s===1&&h==="kg"||s===2&&y==="kg")&&e.jsxs("div",{className:"d-flex justify-content-between text-primary mt-3 pt-3 border-top",children:[e.jsx("span",{className:"fw-semibold",children:"Converted to MT:"}),e.jsxs("span",{className:"fw-bold",children:[(parseFloat(s===1?x:n)/1e3).toFixed(4)," MT"]})]}),(s===1&&h==="MT"||s===2&&y==="MT")&&e.jsxs("div",{className:"d-flex justify-content-between text-primary mt-3 pt-3 border-top",children:[e.jsx("span",{className:"fw-semibold",children:"Processing as:"}),e.jsxs("span",{className:"fw-bold",children:[s===1?x:n," MT"]})]})]}),e.jsx("div",{className:"mt-4 small text-muted italic",children:"* Once confirmed, weights will be saved and the process will proceed to the next step."})]})})]})},_r=()=>{const{inquiryId:t,driverId:u}=be(),j=qe().state?.quoteId,L=Ie(),[s,M]=l.useState(0),[q,X]=l.useState(!0),[p,f]=l.useState(null),[N,W]=l.useState(null),[Z,x]=l.useState(null),[ee,O]=l.useState(null),[d,U]=l.useState(window.innerWidth<768);l.useEffect(()=>{const a=()=>U(window.innerWidth<768);return window.addEventListener("resize",a),()=>window.removeEventListener("resize",a)},[]);const I=[...E.checkPermission("Truck Arrived","create")?[{label:"Gate Entry",subtitle:"Truck arrival"}]:[],...E.checkPermission("Tare Weight","create")?[{label:"Loading",subtitle:"Load material"}]:[],...E.checkPermission("Loading","create")?[{label:"Dispatch",subtitle:"Dispatch truck"}]:[]];l.useEffect(()=>{o()},[t,u]);const o=async()=>{try{X(!0);const i=(await K(`/inquiry/listing-hired-before-today?id=${t}`)).data?.inquiryListing?.[0];if(!i){L("/gate-pass");return}const n=i.hired_transporter_details||[],_=j&&n.find(h=>h.quote_id==j)||n[0];if(f(i),x(_),!u)W(null),O({gate_pass_number:"N/A",truck_number:"",so_number:i?.inquiry_source?.number||"N/A"}),M(0);
1else{const k=(await K(`/truckDetails/getTruckByInquiryAndQuote?inquiry_id=${t}`)).data?.trucks?.find(S=>S.id==u);if(!k){L("/gate-pass");return}const y=i.hired_transporter_details?.find(S=>S.quote_id==(j||k.quote_id));y&&x(y),W(k),O({gate_pass_number:k.gate_pass_no||"N/A",truck_number:k.truck_number,so_number:i?.inquiry_source?.number||"N/A"});const Q=C(k.status);M(Q)}}catch(a){console.error("Error fetching data:",a),L("/gate-pass")}finally{X(!1)}},C=a=>{if(!a)return 0;const i=a.toLowerCase();return i.includes("dispatch")?3:i.includes("loading")?2:i.includes("truck arrived")?1:0},V=(a=>C(a))(N?.status),te=xe(p),G=async()=>{await o()};return q?e.jsx(Be,{className:"d-flex justify-content-center align-items-center",style:{minHeight:"50vh"},children:e.jsx(ze,{className:"mx-auto"})}):e.jsx(Ue,{children:e.jsx("div",{children:e.jsxs("div",{className:d?"d-flex flex-column":"d-flex",children:[e.jsx("div",{className:d?"hide-scrollbar":"",style:{width:d?"100%":"250px",height:d?"auto":"92vh",flexShrink:0,position:d?"relative":"sticky",top:0,alignSelf:"flex-start",borderRight:d?"none":`1px solid ${ne.borderColor||"var(--border-color, #dee2e6)"}`,borderBottom:d?`1px solid ${ne.borderColor||"var(--border-color, #dee2e6)"}`:"none",backgroundColor:"var(--body-bg, transparent)",overflowX:d?"auto":"visible"},children:e.jsx("div",{className:d?"d-flex flex-row align-items-center py-2 px-3":"d-flex flex-column",children:I.map((a,i)=>{const n=i===s,_=i<V,h=i<=V;return e.jsxs("div",{className:d?"d-flex align-items-center flex-shrink-0":"",children:[e.jsxs("div",{className:"d-flex align-items-center",style:{padding:d?"8px 16px":"16px 12px",cursor:h?"pointer":"default",backgroundColor:n?"var(--stepper-active-bg, rgba(31, 105, 241, 0.15))":"transparent",borderRadius:d?"24px":"0",borderTopLeftRadius:!d&&i===0?"0.25rem":void 0,borderTopRightRadius:!d&&i===0?"0.25rem":void 0,borderBottomLeftRadius:!d&&i===I.length-1?"0.25rem":void 0,borderBottomRightRadius:!d&&i===I.length-1?"0.25rem":void 0},onClick:()=>h&&M(i),children:[e.jsx("div",{className:"rounded-circle d-flex align-items-center justify-content-center flex-shrink-0",style:{width:"32px",height:"32px",fontSize:"14px",fontWeight:"bold",backgroundColor:n?"var(--primary, #1F69F1)":_?"var(--success, #019A5A)":"var(--stepper-border-color, #E4E5E8)",color:n||_?"#FFFFFF":"var(--text-muted, #6B7280)"},children:_?e.jsx(Me,{size:16}):i+1}),e.jsxs("div",{className:"ms-3",children:[e.jsx("div",{style:{fontSize:"14px",color:n?"var(--primary, #1F69F1)":_?"var(--heading-color, #333)":"var(--text-muted, #ACB0BA)",fontWeight:"700"},children:a.label}),a.subtitle&&e.jsx("div",{className:d?"d-none":"",style:{fontSize:"12px",color:n?"var(--primary, #1F69F1)":_?"var(--text-muted, #6B7280)":"var(--text-muted, #ACB0BA)",fontWeight:"500"},children:a.subtitle})]})]}),i<I.length-1&&e.jsx("div",{style:d?{width:"24px",height:"2px",backgroundColor:"#dee2e6",margin:"0 8px",flexShrink:0}:{width:"1px",height:"24px",backgroundColor:"#dee2e6",marginLeft:"27px"}})]},i)})})}),e.jsxs("div",{style:{backgroundColor:ne.cardbg2,flex:1,width:d?"100%":"calc(100% - 250px)"},children:[e.jsxs("div",{className:"d-flex justify-content-between mb-3 py-2 px-3 py-md-2 px-md-4",style:{backgroundColor:"var(--card-header-bg, rgba(255, 255, 255, 0.70))"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[e.jsx(Je,{width:40,height:40}),u?e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:"14px",fontWeight:"700",color:"var(--heading-color, #111827)",marginBottom:"1px"},children:N?.driver_name}),e.jsx("div",{style:{fontSize:"12px",color:"var(--text-muted, #6B7280)",fontWeight:"500"},children:Oe(N?.truck_number)})]}):"Adding Driver"]}),e.jsx(ve,{label:"Cancel",variant:"cancel",onClick:()=>L("/gate-pass/view/"+t)})]}),e.jsx("div",{className:"flex-grow-1 px-3 px-md-4 pb-4",children:e.jsx(Ke,{driverData:N,inquiry:p,activeStep:s,selectedTransporter:Z,onGatePassGenerated:async a=>{if(u)G();else{const n=(await K(`/truckDetails/getTruckByInquiryAndQuote?inquiry_id=${t}`)).data?.trucks||[],_=n.length?n[0]:null,h=a||_?.id;h&&L(`/gate-pass/workflow-manual/${t}/${h}`,{replace:!0,state:{quoteId:j}})}},modalOpenedByButton:"edit",isCustomerTruckFlow:te})})]})]})})})};export{_r as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.