1import{V as Y,U as J,r as c,N as e,bY as Z,cP as ee,cI as se,bA as re,a3 as d,a4 as a,ay as te,az as ne,aB as ae,b5 as j,bR as g,bS as f,aC as ie,ax as M,Q as p}from"./vendor-B37zWZef.js";import{C as le}from"./CustomContainer-BC8L5667.js";import{D as oe}from"./DataTable-DQR0H7y3.js";import{A as ce,a as E}from"./ActionListDropdown-D7U6sCxP.js";import{A as de,T as m,W as me,M as B,g as he,z as pe,c as xe}from"./index-CvrbYQit.js";import{S as V}from"./StatusBadge-BRqTHHTc.js";import"./vendor-lottie-qO2cA9l8.js";import"./RefreshBtn-B3jcDHSF.js";import"./Footer-CMVWua_O.js";import"./StyledSelect-C0xCJyrr.js";import"./NoData-CyETu043.js";const Ee=()=>{document.title="Trip Exception Approval Dashboard | LogystiX";const y=Y(),L=J(),v=new URLSearchParams(window.location.search),F=parseInt(v.get("page"),10)||1,A=parseInt(v.get("pageSize"),10)||10,G=v.get("status")!==null?v.get("status"):"",[S,R]=c.useState(null),[O,D]=c.useState(0),[h,w]=c.useState({offset:(F-1)*A,limit:A,search:"",status:G}),[P,b]=c.useState(!1),[t,k]=c.useState(null),[K,u]=c.useState(!1),[l,U]=c.useState(""),[z,T]=c.useState(!1),[N,H]=c.useState(""),[i,_]=c.useState({new_driver_name:"",new_driver_contact:"",new_license:"",new_vehicle_number:""}),x=async(s=!0,r=null)=>{let n=r||{...h};s&&(n.offset=0),w(n),b(!0);try{const o=await he(pe.createUrl("/trip-exception/approvals",n));if(o?.error){p.error(o?.message);return}R(o?.data||[]),D(o?.pagination?.total||o?.total||0),b(!1)}catch(o){R([]),D(0),b(!1),console.error("getExceptionListingData error => ",o)}};c.useEffect(()=>{x(!1)},[]);const q=s=>{const r=new URLSearchParams(L.search);Object.entries(s).forEach(([n,o])=>{o!=null&&o!==""?r.set(n,o):r.delete(n)}),r.set("page","1"),y("?"+r.toString(),{replace:!0})},W=s=>{const r={...h,limit:parseInt(s),offset:0};w(r),x(!1,r)},$=s=>{const r={...h,offset:(s-1)*h.limit};w(r),x(!1,r)},I=s=>{const r={...h,status:s,offset:0};w(r),x(!1,r),q({status:s})},C=(s,r)=>{k(s),U(r),H(""),_({new_driver_name:s.new_driver_name||"",new_driver_contact:s.new_driver_contact||s.new_contact_number||"",new_license:s.new_license||"",new_vehicle_number:s.new_vehicle_number||""}),u(!0)},Q=async()=>{if(l==="reject"&&!N.trim()){p.error("Please provide rejection remarks.");return}if(l==="approve"){const s=t?.type;if(s==="DRIVER_CHANGE"||s==="BOTH_CHANGE"||s==="DRIVER_RAISED"){if(!i.new_driver_name.trim()||!i.new_driver_contact.trim()){p.error("New Driver Name and Contact Number are required.");return}const r=t?.old_driver_contact_number||t?.driver_contact_number||"";if(r&&i.new_driver_contact.trim()===r.trim()){p.error("New driver contact number cannot be the same as the old driver contact number.");return}}if((s==="VEHICLE_CHANGE"||s==="BOTH_CHANGE")&&!i.new_vehicle_number.trim()){p.error("New Vehicle Number is required.");return}}T(!0);try{const s=`/trip-exception/${t.id}/${l}`;let r={};l==="reject"?r={rejection_reason:N}:r={new_driver_name:i.new_driver_name,new_driver_contact:i.new_driver_contact,new_license:i.new_license,new_vehicle_number:i.new_vehicle_number};const n=await xe(s,r);n?.error?p.error(n?.message||`Failed to ${l} exception`):(p.success(n?.message||`Exception ${l}d successfully`),u(!1),x(!1))}catch(s){console.error(`Error performing ${l}:`,s);const r=s.response?.data?.message;p.error(r||`An error occurred while trying to ${l} exception.`),s.response?.status===409&&(u(!1),x(!1))}finally{T(!1)}},X=c.useMemo(()=>[{header:"TR No.",accessorKey:"inquiry_id",enableColumnFilter:!1,size:120,cell:s=>e.jsx("span",{style:{color:"#2B63A8",textDecoration:"underline",cursor:"pointer",fontWeight:600},onClick:()=>y(`/transport-request/view/${s.row.original?.inquiry_id}`),children:s.row.original?.inquiry_id})},{header:"Type",accessorKey:"type",enableColumnFilter:!1,size:150,cell:s=>{const r=s.row.original?.type||"Unknown";return e.jsx("span",{children:r.replace(/_/g," ")})}},{header:"Reason",accessorKey:"reason",enableColumnFilter:!1,size:200,cell:s=>e.jsx(de,{text:s.row.original?.reason,children:e.jsx("div",{style:{whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:"180px"},children:s.row.original?.reason||s.row.original?.reason_code||"N/A"})})},{header:"Driver",accessorKey:"driver_name",enableColumnFilter:!1,size:200,cell:s=>{const r=s.row.original,n=r.new_driver_name&&(r.type==="DRIVER_CHANGE"||r.type==="BOTH_CHANGE"||r.type==="DRIVER_RAISED");return e.jsxs("div",{className:"d-flex flex-column",children:[e.jsxs("div",{className:"d-flex flex-column mb-1",children:[e.jsx("span",{style:{fontSize:"11px",color:m.textMuted},children:"Old"}),e.jsx("span",{style:{fontWeight:500,fontSize:"13px",lineHeight:"1.2"},children:r.old_driver_name||r.driver_name||"N/A"}),e.jsx("span",{style:{fontSize:"12px",color:m.textMuted},children:r.old_driver_contact_number||r.driver_contact_number||"N/A"})]}),n&&e.jsxs("div",{className:"d-flex flex-column pt-1",style:{borderTop:"1px dashed #E5E7EB"},children:[e.jsx("span",{style:{fontSize:"11px",color:m.success},children:"New"}),e.jsx("span",{style:{fontWeight:500,fontSize:"13px",lineHeight:"1.2"},children:r.new_driver_name}),e.jsx("span",{style:{fontSize:"12px",color:m.textMuted},children:r.new_driver_contact||r.new_contact_number})]})]})}},{header:"Vehicle",accessorKey:"vehicle_number",enableColumnFilter:!1,size:160,cell:s=>{const r=s.row.original,n=r.new_vehicle_number&&(r.type==="VEHICLE_CHANGE"||r.type==="BOTH_CHANGE");return e.jsxs("div",{className:"d-flex flex-column",children:[e.jsxs("div",{className:"d-flex flex-column mb-1",children:[e.jsx("span",{style:{fontSize:"11px",color:m.textMuted},children:"Old"}),e.jsx("span",{style:{fontSize:"13px",lineHeight:"1.2"},children:r.old_vehicle_number||r.vehicle_number||"N/A"})]}),n&&e.jsxs("div",{className:"d-flex flex-column pt-1",style:{borderTop:"1px dashed #E5E7EB"},children:[e.jsx("span",{style:{fontSize:"11px",color:m.success},children:"New"}),e.jsx("span",{style:{fontSize:"13px",lineHeight:"1.2"},children:r.new_vehicle_number})]})]})}},{header:"Plant",accessorKey:"plant_name",enableColumnFilter:!1,size:150,cell:s=>e.jsx("span",{children:s.row.original?.plant_name||"N/A"})},{header:"Created At",accessorKey:"created_at",enableColumnFilter:!1,size:150,cell:s=>e.jsx("span",{children:me(s.row.original?.created_at)})},{header:"Status",accessorKey:"status",size:150,enableColumnFilter:!1,cell:s=>e.jsx(V,{status:s.row.original?.status})},{header:"Action",accessorKey:"action",enableColumnFilter:!1,size:100,cell:s=>{const r=s.row.original;return e.jsx("div",{className:"d-flex justify-content-center align-items-center",children:e.jsxs(ce,{children:[e.jsx(E,{label:"View Details",icon:e.jsx(Z,{size:16,style:{color:m.headingColor}}),onClick:n=>{n.stopPropagation(),C(r,"view")}}),r.status==="SUBMITTED"&&e.jsxs(e.Fragment,{children:[e.jsx(E,{label:"Approve",icon:e.jsx(ee,{size:16,style:{color:m.success}}),hoverColor:m.success,onClick:n=>{n.stopPropagation(),C(r,"approve")}}),e.jsx(E,{label:"Reject",danger:!0,icon:e.jsx(se,{size:16,style:{color:m.danger}}),onClick:n=>{n.stopPropagation(),C(r,"reject")}})]})]})})}}],[y]);return e.jsxs(le,{children:[e.jsx("div",{className:"container-fluid",children:S==null?e.jsx(re,{children:e.jsx(d,{className:"justify-content-center align-items-center",style:{height:"80vh"},children:e.jsx(a,{className:"text-center",children:e.jsx(B,{className:"mx-auto"})})})}):e.jsx(d,{children:e.jsx(a,{lg:"12",children:e.jsx(oe,{title:"Trip Exception Approval Dashboard",columns:X,data:S,enableColumnResizing:!0,enableColumnVisibility:!0,totalRecords:O,handleRefreshButton:()=>
1x(!0),isPagination:!0,isCustomPageSize:!0,handlePageSizeChange:W,currentPage:Math.floor(h.offset/h.limit)+1,pageSize:h.limit,handlePageChange:$,handleStatusFilterChange:I,pagination:"pagination",isTableLoadingData:P,searchPlaceholder:"Search Exception...",statusTabs:{options:[{value:"",label:"All"},{value:"SUBMITTED",label:"Submitted"},{value:"REJECTED",label:"Rejected"},{value:"AWAITING_RESUME",label:"Awaiting Resume"},{value:"COMPLETED",label:"Completed"}],value:h.status,onChange:I,visibleCount:6}})})})}),e.jsxs(te,{isOpen:K,toggle:()=>u(!1),size:"lg",children:[e.jsx(ne,{toggle:()=>u(!1),children:l==="approve"?"Approve Exception":l==="reject"?"Reject Exception":"Exception Details"}),e.jsx(ae,{children:t&&e.jsxs("div",{children:[e.jsxs(d,{className:"mb-3",children:[e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"TR No:"})," ",t.inquiry_id]}),e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"Status:"})," ",e.jsx(V,{status:t.status})]})]}),e.jsxs(d,{className:"mb-3",children:[e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"Exception Type:"})," ",t.type?.replace(/_/g," ")]}),e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"Source:"})," ",t.source?.replace(/_/g," ")]})]}),e.jsxs(d,{className:"mb-3",children:[e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"Reason Code:"})," ",t.reason_code||"N/A"]}),e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"Reason:"})," ",t.reason||"N/A"]})]}),e.jsx("hr",{}),e.jsxs(d,{className:"mb-3",children:[e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"Old Driver:"})," ",t.old_driver_name||t.driver_name||"N/A"," (",t.old_driver_contact_number||t.driver_contact_number||"N/A",")"]}),e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"Old Vehicle:"})," ",t.old_vehicle_number||t.vehicle_number||"N/A"]})]}),(t.type==="DRIVER_CHANGE"||t.type==="BOTH_CHANGE")&&e.jsxs(d,{className:"mb-3",children:[e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"New Driver:"})," ",t.new_driver_name||"N/A"]}),e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"New Contact:"})," ",t.new_driver_contact||"N/A"]})]}),(t.type==="VEHICLE_CHANGE"||t.type==="BOTH_CHANGE")&&e.jsx(d,{className:"mb-3",children:e.jsxs(a,{md:6,children:[e.jsx("strong",{children:"New Vehicle:"})," ",t.new_vehicle_number||"N/A"]})}),l==="approve"&&e.jsxs("div",{className:"mt-4",children:[e.jsx("hr",{}),e.jsx("h6",{className:"fw-bold mb-3",children:"New Assignment Details"}),(t.type==="DRIVER_CHANGE"||t.type==="BOTH_CHANGE"||t.type==="DRIVER_RAISED")&&e.jsxs(e.Fragment,{children:[e.jsxs(d,{className:"mb-3",children:[e.jsx(a,{md:6,children:e.jsxs(j,{children:[e.jsxs(g,{style:{fontSize:"13px",fontWeight:600},children:["New Driver Name ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(f,{type:"text",placeholder:"e.g. Suresh Kumar",value:i.new_driver_name,onChange:s=>_({...i,new_driver_name:s.target.value})})]})}),e.jsx(a,{md:6,children:e.jsxs(j,{children:[e.jsxs(g,{style:{fontSize:"13px",fontWeight:600},children:["Contact Number ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(f,{type:"text",placeholder:"10-digit mobile",value:i.new_driver_contact,onChange:s=>_({...i,new_driver_contact:s.target.value})})]})})]}),e.jsx(d,{className:"mb-3",children:e.jsx(a,{md:6,children:e.jsxs(j,{children:[e.jsx(g,{style:{fontSize:"13px",fontWeight:600},children:"License Details"}),e.jsx(f,{type:"text",placeholder:"e.g. KA2345298234123",value:i.new_license,onChange:s=>_({...i,new_license:s.target.value})})]})})})]}),(t.type==="VEHICLE_CHANGE"||t.type==="BOTH_CHANGE")&&e.jsx(d,{className:"mb-3",children:e.jsx(a,{md:6,children:e.jsxs(j,{children:[e.jsxs(g,{style:{fontSize:"13px",fontWeight:600},children:["New Vehicle Number ",e.jsx("span",{className:"text-danger",children:"*"})]}),e.jsx(f,{type:"text",placeholder:"MH-12-AB-3421",value:i.new_vehicle_number,onChange:s=>_({...i,new_vehicle_number:s.target.value.toUpperCase()}),style:{textTransform:"uppercase"}})]})})})]}),l==="reject"&&e.jsx("div",{className:"mt-4",children:e.jsxs(j,{children:[e.jsx(g,{for:"remarks",children:"Rejection Remarks (Required)"}),e.jsx(f,{type:"textarea",id:"remarks",rows:"3",placeholder:"Enter reject remarks...",value:N,onChange:s=>H(s.target.value)})]})})]})}),e.jsxs(ie,{children:[l!=="view"&&e.jsx(M,{color:l==="approve"?"success":"danger",onClick:Q,disabled:z,children:z?e.jsx(B,{size:16}):`Confirm ${l==="approve"?"Approval":"Rejection"}`}),e.jsx(M,{color:"secondary",onClick:()=>u(!1),children:"Close"})]})]})]})};export{Ee 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.