Files
dailygrubs_console_build/build/static/js/1113.dda4f3a8.chunk.js

1 line
15 KiB
JavaScript

(self.webpackChunkmantis_material_react=self.webpackChunkmantis_material_react||[]).push([[1113],{62180:function(e,r,n){"use strict";n.d(r,{y:function(){return o}});var t=n(90842),o=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2e3;(0,t.yv)(e,{variant:r,anchorOrigin:{vertical:"top",horizontal:"right"},autoHideDuration:n})}},25218:function(e,r,n){"use strict";n.r(r),n.d(r,{default:function(){return te}});var t,o=n(29439),i=n(4942),l=n(47313),s=n(70501),a=n(61113),c=n(42832),d=n(57829),u=n(61689),h=n(69099),f=n(51629),v=n(66835),m=n(23477),p=n(24076),x=n(67478),g=n(57861),b=n(66212),j=n(22539),y=n(13997),w=n.n(y),k=n(48737),C=n(74165),Z=n(15861),R=function(e){return null===e||void 0===e?"":String(e).trim().toLowerCase().replace(/\s+/g,"")},S=[{key:"receivername",label:"Receiver Name*",required:!0,example:"Dhivya",help:"Person receiving the delivery."},{key:"receiverphone",label:"Receiver Phone*",required:!0,example:"7358856373",help:"10-digit Indian mobile. Used to match an existing customer."},{key:"receiveraddress",label:"Receiver Address*",required:!0,example:"Gopala Krishna Complex, Joshua St, Puthukudierupu, Nagercoil 629001",help:"Full delivery address."},{key:"itemdescription",label:"Item Description*",required:!0,example:"Medicines",help:"What is being delivered."},{key:"quantity",label:"Quantity",required:!1,default:1,example:"1",help:"Whole number. Defaults to 1."},{key:"collectcash",label:"Collect Cash",required:!1,default:0,example:"0",help:"Amount to collect on delivery. 0 for pay-later."},{key:"receiverlat",label:"Receiver Latitude",required:!1,example:"8.1877496",help:"Optional. Improves routing."},{key:"receiverlong",label:"Receiver Longitude",required:!1,example:"77.4241515",help:"Optional. Improves routing."},{key:"notes",label:"Notes",required:!1,example:"",help:"Anything the rider should know."}],z=S.filter((function(e){return e.required})).map((function(e){return e.key})),W=S.reduce((function(e,r){return e[R(r.label)]=r.key,e[R(r.key)]=r.key,e}),{}),q={deliverycustomer:"receivername",deliverycontactno:"receiverphone",deliveryaddress:"receiveraddress",deliverylat:"receiverlat",deliverylong:"receiverlong",ordernotes:"notes","receivername*":"receivername",receiverfulladdress:"receiveraddress",receiverlatitude:"receiverlat",receiverlongitude:"receiverlong","itemdescription*":"itemdescription",collectcash:"collectcash"},I=function(e){var r=R(e);return W[r]||q[r]||""},M=function(){return[S.map((function(e){return e.label})),S.map((function(e){return e.example}))]},N=function(){var e=(0,Z.Z)((0,C.Z)().mark((function e(){var r,t,o,i,l=arguments;return(0,C.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=l.length>0&&void 0!==l[0]?l[0]:"Weekly_Order_Intake_Template.xlsx",e.next=3,Promise.resolve().then(n.bind(n,48737));case 3:t=e.sent,(o=t.utils.aoa_to_sheet(M()))["!cols"]=S.map((function(e){return{wch:Math.max(e.label.length+2,16)}})),i=t.utils.book_new(),t.utils.book_append_sheet(i,o,"Orders"),t.writeFile(i,r);case 9:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),_=n(27162),A="ok",L="needs-review",O="rejected",E=S.reduce((function(e,r){return e[r.key]=r,e}),{}),F=function(e){return null===e||void 0===e?"":String(e).trim()},T=function(e){return F(e).replace(/^[\d.\s]+/,"").trim()},D=function(e){var r=F(e).replace(/\D/g,"");return 12===r.length&&r.startsWith("91")?r=r.slice(2):11===r.length&&r.startsWith("0")&&(r=r.slice(1)),10!==r.length?null:/^[6-9]/.test(r)?r:null},K=function(e,r){var n=F(e);if(""===n)return r;var t=Number(n);return Number.isFinite(t)?t:null},H=function(e,r){var n=function(e){return e*Math.PI/180},t=n(r.lat-e.lat),o=n(r.lng-e.lng),i=Math.pow(Math.sin(t/2),2)+Math.cos(n(e.lat))*Math.cos(n(r.lat))*Math.pow(Math.sin(o/2),2);return 12742*Math.asin(Math.sqrt(i))},P=function(e){return z.every((function(r){return""===F(e[r])}))},U=function(e){return"".concat(e.receiverphone||"","|").concat(F(e.receiveraddress).toLowerCase().replace(/[^a-z0-9]/g,""))},V=n(62180),B=n(46417),G="#662582",Q="#0f172a",J="#64748b",$="#94a3b8",X="#e2e8f0",Y="#f8fafc",ee=(t={},(0,i.Z)(t,A,{label:"Ready",color:"#2c6b45",bg:"#dcece2",Icon:j.ZSR}),(0,i.Z)(t,L,{label:"Review",color:"#8a5600",bg:"#f8ead2",Icon:j.ESo}),(0,i.Z)(t,O,{label:"Rejected",color:"#b3261e",bg:"#fae4e2",Icon:j.wr$}),t),re={lat:8.1841265,lng:77.4318002},ne=function(e){var r=e.label,n=e.value,t=e.tone;return(0,B.jsxs)(s.Z,{elevation:0,sx:{flex:"1 1 120px",minWidth:120,px:1.75,py:1.25,borderRadius:2,border:"1px solid",borderColor:X,bgcolor:"#fff"},children:[(0,B.jsx)(a.Z,{sx:{fontSize:10,letterSpacing:.6,textTransform:"uppercase",color:$,fontWeight:700},children:r}),(0,B.jsx)(a.Z,{sx:{fontSize:26,fontWeight:700,lineHeight:1.2,color:t||Q,fontVariantNumeric:"tabular-nums"},children:n})]})};function te(){var e=(0,l.useState)(null),r=(0,o.Z)(e,2),n=r[0],t=r[1],i=(0,l.useState)(""),y=(0,o.Z)(i,2),C=y[0],Z=y[1],W=(0,l.useRef)(null),q=function(e,r,n){return(0,V.y)(e,r,n)},M=function(e,r){var n=function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=r.serviceCentre,t=void 0===n?null:n,o=r.serviceRadiusKm,i=void 0===o?25:o,l=r.knownRunKeys,s=void 0===l?null:l,a=Array.isArray(e)?e:[];if(!a.length)return{missingColumns:[],unknownColumns:[],rows:[],summary:{total:0,ok:0,needsReview:0,rejected:0}};var c=Object.keys(a[0]),d={},u=[];c.forEach((function(e){var r=I(e);r?d[e]=r:""!==R(e)&&u.push(e)}));var h=new Set(Object.values(d)),f=z.filter((function(e){return!h.has(e)})).map((function(e){return E[e].label})),v=new Map,m=[];return a.forEach((function(e,r){var n={};if(Object.keys(e).forEach((function(r){var t=d[r];t&&(n[t]=e[r])})),!P(n)){var o=[],l={notes:F(n.notes)};l.receivername=T(n.receivername),l.receivername||o.push({level:"reject",field:"receivername",message:"Receiver name is empty."}),l.receiverphone=D(n.receiverphone),l.receiverphone||o.push({level:"reject",field:"receiverphone",message:F(n.receiverphone)?'"'.concat(F(n.receiverphone),'" is not a 10-digit Indian mobile.'):"Receiver phone is empty."}),l.receiveraddress=F(n.receiveraddress),l.receiveraddress||o.push({level:"reject",field:"receiveraddress",message:"Receiver address is empty."}),l.itemdescription=F(n.itemdescription),l.itemdescription||o.push({level:"reject",field:"itemdescription",message:"Item description is empty."});var a=K(n.quantity,1);null===a||!Number.isInteger(a)||a<1?(o.push({level:"reject",field:"quantity",message:'Quantity must be a whole number of 1 or more, got "'.concat(F(n.quantity),'".')}),l.quantity=null):l.quantity=a;var c=K(n.collectcash,0);null===c||c<0?(o.push({level:"reject",field:"collectcash",message:'Collect Cash must be zero or more, got "'.concat(F(n.collectcash),'".')}),l.collectcash=null):l.collectcash=c;var u=K(n.receiverlat,null),h=K(n.receiverlong,null),f=null!==u&&null!==h;if(null===u!==(null===h)&&o.push({level:"review",field:"receiverlat",message:"Only one of latitude/longitude is present; both are needed to route."}),f&&(Math.abs(u)>90||Math.abs(h)>180))o.push({level:"reject",field:"receiverlat",message:"Coordinates ".concat(u,", ").concat(h," are not a valid point on earth.")});else if(f&&t){var p=H(t,{lat:u,lng:h});p>i&&o.push({level:"reject",field:"receiverlat",message:"Drop is ".concat(p.toFixed(1)," km from the hub, beyond the ").concat(i," km service radius.")}),l.distanceKm=Number(p.toFixed(2))}l.receiverlat=f?u:null,l.receiverlong=f?h:null,f||o.push({level:"review",field:"receiverlat",message:"No coordinates \u2014 the address will need geocoding before routing."}),((0,_.rC)(l.receiveraddress)||(0,_.rC)(l.receivername))&&o.push({level:"review",field:"receiveraddress",message:"Contains non-Latin script; the same place may already exist under a Latin spelling."});var x=U(l),g=r+2;l.receiverphone&&(v.has(x)?o.push({level:"review",field:"receiverphone",message:"Same phone and address as row ".concat(v.get(x),".")}):v.set(x,g),s&&s.has(x)&&o.push({level:"reject",field:"receiverphone",message:"Already created in an earlier run \u2014 this row would be a duplicate order."}));var b=o.some((function(e){return"reject"===e.level}));m.push({index:r,sheetRow:g,raw:e,normalised:l,fingerprint:x,reasons:o,status:b?O:o.length?L:A})}})),{missingColumns:f,unknownColumns:u,rows:m,summary:{total:m.length,ok:m.filter((function(e){return e.status===A})).length,needsReview:m.filter((function(e){return e.status===L})).length,rejected:m.filter((function(e){return e.status===O})).length}}}(e,{serviceCentre:re,serviceRadiusKm:25});t(n),Z(r);var o=function(e){if(!e)return"No file parsed.";if(e.missingColumns.length)return"Missing required column(s): ".concat(e.missingColumns.join(", "),".");var r=e.summary,n=r.total,t=r.ok,o=r.needsReview,i=r.rejected;return n?"".concat(n," rows \u2014 ").concat(t," ready, ").concat(o," need review, ").concat(i," rejected."):"The file has no data rows."}(n);q(o,n.missingColumns.length||n.summary.rejected?"warning":"success",4e3)},te=null===n||void 0===n?void 0:n.summary;return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(s.Z,{elevation:0,sx:{p:{xs:1.5,md:2},mb:1.5,borderRadius:2,border:"1px solid",borderColor:X,bgcolor:"#fff"},children:(0,B.jsxs)(c.Z,{direction:{xs:"column",md:"row"},spacing:1.5,alignItems:{md:"center"},justifyContent:"space-between",children:[(0,B.jsxs)(d.Z,{children:[(0,B.jsx)(a.Z,{sx:{fontSize:20,fontWeight:800,color:Q,lineHeight:1.25},children:"Weekly Order Intake"}),(0,B.jsx)(a.Z,{sx:{fontSize:12.5,color:J},children:C?"Checked ".concat(C):"Dry run \u2014 check a weekly file before anything is created"})]}),(0,B.jsxs)(c.Z,{direction:"row",spacing:1,flexWrap:"wrap",useFlexGap:!0,children:[(0,B.jsx)(u.Z,{title:"Download the blank intake template",arrow:!0,children:(0,B.jsx)(h.Z,{onClick:function(){return N()},variant:"outlined",size:"small",disableElevation:!0,startIcon:(0,B.jsx)(j.uKn,{size:15}),sx:{height:34,px:1.5,borderRadius:1.5,textTransform:"none",fontSize:12.5,fontWeight:700,bgcolor:"#fff",borderColor:X,color:Q,"&:hover":{bgcolor:"#fff",borderColor:G,color:G}},children:"Template"})}),n&&(0,B.jsx)(h.Z,{onClick:function(){t(null),Z("")},variant:"outlined",size:"small",disableElevation:!0,startIcon:(0,B.jsx)(j.zq9,{size:15}),sx:{height:34,px:1.5,borderRadius:1.5,textTransform:"none",fontSize:12.5,fontWeight:700,bgcolor:"#fff",borderColor:X,color:Q,"&:hover":{bgcolor:"#fff",borderColor:G,color:G}},children:"Clear"}),(0,B.jsx)(h.Z,{onClick:function(){var e;return null===(e=W.current)||void 0===e?void 0:e.click()},variant:"contained",size:"small",disableElevation:!0,startIcon:(0,B.jsx)(j.UKH,{size:15}),sx:{height:34,px:1.75,borderRadius:1.5,textTransform:"none",fontSize:12.5,fontWeight:700,bgcolor:G,"&:hover":{bgcolor:"#9255AB"}},children:"Check a file"}),(0,B.jsx)("input",{ref:W,type:"file",accept:".csv,.xls,.xlsx",onChange:function(e){var r,n=null===(r=e.target.files)||void 0===r?void 0:r[0];if(n){var t=n.name.toLowerCase(),o=t.endsWith(".csv"),i=t.endsWith(".xls")||t.endsWith(".xlsx");if(o||i){if(o)w().parse(n,{header:!0,skipEmptyLines:!0,complete:function(e){return M(e.data||[],n.name)},error:function(e){return q("Could not read the file: ".concat(e.message),"error",4e3)}});else{var l=new FileReader;l.onload=function(e){try{var r=k.read(e.target.result,{type:"array"});M(k.utils.sheet_to_json(r.Sheets[r.SheetNames[0]],{defval:""}),n.name)}catch(t){q("Could not read the workbook: ".concat(t.message),"error",4e3)}},l.readAsArrayBuffer(n)}e.target.value=""}else q("Upload a .csv, .xls or .xlsx file.","warning",3e3)}},"data-testid":"intake-file",style:{display:"none"}})]})]})}),(0,B.jsx)(s.Z,{elevation:0,sx:{px:1.75,py:1.25,mb:1.5,borderRadius:2,border:"1px solid",borderColor:X,borderLeft:"3px solid ".concat(G),bgcolor:"#fff"},children:(0,B.jsxs)(a.Z,{sx:{fontSize:12.5,color:J,lineHeight:1.6},children:[(0,B.jsx)("strong",{style:{color:Q},children:"This screen never creates orders."})," It reads the file and reports what would happen to each row. Creating orders needs customer matching and a pickup slot, which are not built yet."]})}),n?(0,B.jsxs)(c.Z,{spacing:1.5,children:[(0,B.jsxs)(c.Z,{direction:"row",spacing:1,flexWrap:"wrap",useFlexGap:!0,children:[(0,B.jsx)(ne,{label:"Rows",value:te.total}),(0,B.jsx)(ne,{label:"Ready",value:te.ok,tone:ee[A].color}),(0,B.jsx)(ne,{label:"Need review",value:te.needsReview,tone:ee[L].color}),(0,B.jsx)(ne,{label:"Rejected",value:te.rejected,tone:ee[O].color})]}),n.missingColumns.length>0&&(0,B.jsxs)(s.Z,{elevation:0,sx:{p:1.5,borderRadius:2,border:"1px solid",borderColor:"#f3c6c2",borderLeft:"3px solid #b3261e",bgcolor:"#fff"},children:[(0,B.jsx)(a.Z,{sx:{fontSize:13,fontWeight:700,color:"#b3261e"},children:"Missing required columns"}),(0,B.jsxs)(a.Z,{sx:{fontSize:12.5,color:J,mt:.25},children:[n.missingColumns.join(", ")," \u2014 no row can be created until these are present."]})]}),n.unknownColumns.length>0&&(0,B.jsxs)(s.Z,{elevation:0,sx:{p:1.5,borderRadius:2,border:"1px solid",borderColor:X,borderLeft:"3px solid #8a5600",bgcolor:"#fff"},children:[(0,B.jsxs)(a.Z,{sx:{fontSize:13,fontWeight:700,color:"#8a5600"},children:[n.unknownColumns.length," column",1===n.unknownColumns.length?"":"s"," not recognised \u2014 ignored"]}),(0,B.jsx)(a.Z,{sx:{fontSize:12,color:J,mt:.25,wordBreak:"break-word"},children:n.unknownColumns.join(", ")})]}),(0,B.jsx)(f.Z,{component:s.Z,elevation:0,sx:{borderRadius:2,border:"1px solid",borderColor:X,bgcolor:"#fff"},children:(0,B.jsxs)(v.Z,{size:"small",sx:{minWidth:820},children:[(0,B.jsx)(m.Z,{children:(0,B.jsx)(p.Z,{sx:{bgcolor:Y},children:["Row","Status","Receiver","Phone","Address","Item","Qty","What needs attention"].map((function(e){return(0,B.jsx)(x.Z,{sx:{fontSize:10,letterSpacing:.5,textTransform:"uppercase",color:$,fontWeight:700},children:e},e)}))})}),(0,B.jsx)(g.Z,{children:n.rows.map((function(e){var r,n=ee[e.status],t=e.normalised;return(0,B.jsxs)(p.Z,{hover:!0,children:[(0,B.jsx)(x.Z,{sx:{fontSize:12,color:$,fontVariantNumeric:"tabular-nums"},children:e.sheetRow}),(0,B.jsx)(x.Z,{children:(0,B.jsx)(b.Z,{label:n.label,size:"small",sx:{height:20,fontSize:10.5,fontWeight:700,bgcolor:n.bg,color:n.color,"& .MuiChip-label":{px:.9}}})}),(0,B.jsx)(x.Z,{sx:{fontSize:12.5,fontWeight:600},children:t.receivername||(0,B.jsx)("span",{style:{color:$},children:"\u2014"})}),(0,B.jsx)(x.Z,{sx:{fontSize:12.5,fontVariantNumeric:"tabular-nums"},children:t.receiverphone||(0,B.jsx)("span",{style:{color:$},children:"\u2014"})}),(0,B.jsx)(x.Z,{sx:{fontSize:12,color:J,maxWidth:240},children:t.receiveraddress||"\u2014"}),(0,B.jsx)(x.Z,{sx:{fontSize:12.5},children:t.itemdescription||(0,B.jsx)("span",{style:{color:$},children:"\u2014"})}),(0,B.jsx)(x.Z,{sx:{fontSize:12.5,fontVariantNumeric:"tabular-nums"},children:null!==(r=t.quantity)&&void 0!==r?r:"\u2014"}),(0,B.jsx)(x.Z,{sx:{fontSize:12,color:J,maxWidth:300},children:0===e.reasons.length?(0,B.jsx)("span",{style:{color:$},children:"Nothing"}):e.reasons.map((function(r,n){return(0,B.jsxs)(d.Z,{sx:{mb:n<e.reasons.length-1?.5:0},children:[(0,B.jsx)(d.Z,{component:"span",sx:{color:"reject"===r.level?"#b3261e":"#8a5600",fontWeight:700,mr:.5},children:"reject"===r.level?"Blocked:":"Check:"}),r.message]},n)}))})]},e.index)}))})]})})]}):(0,B.jsxs)(s.Z,{elevation:0,sx:{p:4,borderRadius:2,border:"1px dashed",borderColor:X,bgcolor:"#fff",textAlign:"center"},children:[(0,B.jsx)(j.UKH,{size:32,color:$}),(0,B.jsx)(a.Z,{sx:{fontSize:15,fontWeight:700,color:Q,mt:1},children:"No file checked yet"}),(0,B.jsxs)(a.Z,{sx:{fontSize:13,color:J,mt:.5,maxWidth:480,mx:"auto"},children:["Upload the week\u2019s CSV or Excel file. Required columns are"," ",S.filter((function(e){return e.required})).map((function(e){return e.label})).join(", "),"."]})]})]})}},20067:function(){}}]);