2 lines
18 KiB
JavaScript
2 lines
18 KiB
JavaScript
import{j as u,a5 as j,aj as S,an as w,ay as X,az as Y,aA as _,aX as J,ac as lu,T as z,ak as nu,al as Q,am as Z,B as W,ao as su,b8 as iu,d as cu,aM as du,I as hu,b3 as Cu,aq as pu,b7 as K,as as H,at as q,b as yu}from"./mui-vendor-D_SVL-Dx.js";import{L,j as T,h as f,A as M,u as eu,a0 as m,b6 as B,W as R,b7 as mu,c as ru,V as k,b8 as U,G as I,S as O,b9 as xu}from"./index-D80MdVQn.js";import{r as y}from"./react-vendor-CmFgShSM.js";import{a as P,u as D,f as V}from"./redux-vendor-CfkcHgWN.js";import{C as Au}from"./CarPelak-BUqZflo3.js";import{a as vu}from"./index.esm-C1-dCPnj.js";import{d as _u}from"./Tune-BBzxV8DK.js";import{d as ju}from"./EditOutlined-CdYoJAhn.js";import{d as fu}from"./DeleteOutline-DhriepRs.js";import{R as uu}from"./ResponsiveTable-bUYl0qDM.js";import{c as G}from"./checkPathStartsWith-DedybDvj.js";import"./FilterAlt-DZsHj-WQ.js";import"./styled-components.browser.esm-gS9mh05b.js";const Fu=P("PROVINCE_REGISTER_CAR_SERVICE",async(r,{dispatch:a})=>{try{a(L());const{data:t,status:i}=await T.post("kill_house_driver/",r);return a(f()),{data:t,status:i}}catch(t){return a(f()),{error:t.response.data.result}}}),gu=P("PROVINCE_EDIT_CAR_SERVICE",async(r,{dispatch:a})=>{try{a(L());const{data:t,status:i}=await T.put("kill_house_driver/0/",r);return a(f()),{data:t,status:i}}catch(t){return a(f()),{error:t.response.data.result}}}),bu=ru({driver_mobile:k().required("شماره موبایل راننده الزامی است"),last_name:k().required("نام خانوادگی الزامی است"),first_name:k().required("نام الزامی است"),city_name:k().required("نام شهر الزامی است"),type_car:k().required("نوع خودرو الزامی است"),pelak:k().required("پلاک الزامی است"),capocity:k().required("ظرفیت الزامی است"),health_code:k().required("کد سلامت الزامی است")}),tu=({first_name:r,last_name:a,driver_mobile:t,city_name:i,type_car:C,pelak:x,capocity:h,health_code:s,driverKey:l,type:o})=>{const c=D(),[p]=y.useContext(M),{provinceGetCities:g}=V(n=>n.provinceSlice),e=eu({initialValues:{driver_mobile:t,last_name:a,first_name:r,city_name:i,type_car:C,pelak:"",capocity:h,health_code:s,type:o||"exclusive"},validationSchema:bu,onSubmit:()=>{v()}}),[F,A]=y.useState([]);y.useEffect(()=>{if(x){const n=x.split(" ");A(n)}},[x]),y.useEffect(()=>{e.setFieldValue("pelak",F.length?F.join(" ").trim():"")},[F]);const v=()=>{const{values:n,errors:b}=e;b!=null&&b.length||(l?c(gu({driver_mobile:n.driver_mobile,last_name:n.last_name,first_name:n.first_name,city_name:n.city_name,type_car:n.type_car,pelak:F.join(" "),capocity:n.capocity,health_code:n.health_code,role:m(),driver_key:l,type:n.type})).then(E=>{E.payload.error?p({vertical:"top",horizontal:"center",msg:E.payload.error,severity:"error"}):(c(B()),c(R({right:!1,bottom:!1,content:null})),p({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))}):c(Fu({driver_mobile:n.driver_mobile,last_name:n.last_name,first_name:n.first_name,city_name:n.city_name,type_car:n.type_car,pelak:F.join(" "),capocity:n.capocity,health_code:n.health_code,role:m(),type:n.type})).then(E=>{E.payload.error?p({vertical:"top",horizontal:"center",msg:E.payload.error,severity:"error"}):(c(B()),c(R({right:!1,bottom:!1,content:null})),p({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))}))},d=(n,b,E,N)=>{A([n,b,E,N])};return y.useEffect(()=>{c(mu()).then(()=>e.setFieldValue("city_name",i))},[]),u.jsx("form",{onSubmit:e.handleSubmit,children:u.jsxs(j,{container:!0,spacing:2,children:[u.jsx(j,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(w,{id:"first_name",name:"first_name",label:"نام",value:e.values.first_name,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.first_name&&!!e.errors.first_name,helperText:e.touched.first_name&&e.errors.first_name})})}),u.jsx(j,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(w,{id:"last_name",name:"last_name",label:"نام خانوادگی",value:e.values.last_name,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.last_name&&!!e.errors.last_name,helperText:e.touched.last_name&&e.errors.last_name})})}),u.jsx(j,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(w,{id:"driver_mobile",name:"driver_mobile",label:"شماره موبایل راننده",value:e.values.driver_mobile,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.driver_mobile&&!!e.errors.driver_mobile,helperText:e.touched.driver_mobile&&e.errors.driver_mobile})})}),(g==null?void 0:g.length)&&u.jsx(j,{item:!0,xs:12,children:u.jsxs(S,{fullWidth:!0,children:[u.jsx(X,{id:"demo-simple-select-label",children:"شهر"}),u.jsxs(Y,{id:"city_name",name:"city_name",onChange:e.handleChange,label:"شهر",onBlur:e.handleBlur,value:e.values.city_name,error:e.touched.city_name&&!!e.errors.city_name,renderValue:n=>n||"نام شهر",children:[u.jsx(_,{value:"",disabled:!0,children:"نام شهر"}),g.map(n=>u.jsx(_,{value:n.name,children:n.name},n.id))]}),e.touched.city_name&&e.errors.city_name&&u.jsx(J,{error:!0,children:e.errors.city_name})]})}),u.jsx(j,{item:!0,xs:12,children:u.jsxs(S,{fullWidth:!0,children:[u.jsx(X,{id:"demo-simple-select-label",children:"نوع خودرو"}),u.jsxs(Y,{id:"type_car",name:"type_car",label:"نوع خودرو",value:e.values.type_car,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.type_car&&!!e.errors.type_car,renderValue:n=>n||"انتخاب نوع خودرو",children:[u.jsx(_,{value:"",disabled:!0,children:"انتخاب نوع خودرو"}),u.jsx(_,{value:"ایسوزو",children:"ایسوزو"}),u.jsx(_,{value:"نیسان",children:"نیسان"}),u.jsx(_,{value:"وانت",children:"وانت"}),u.jsx(_,{value:"اف ام",children:"اف ام"}),u.jsx(_,{value:"کامیون",children:"کامیون"}),u.jsx(_,{value:"هیوندا کروس",children:"هیوندا کروس"}),u.jsx(_,{value:"بادسان",children:"بادسان"}),u.jsx(_,{value:"هیوندا",children:"هیوندا"}),u.jsx(_,{value:"کامیونت ایسوزو",children:"کامیونت ایسوزو"}),u.jsx(_,{value:"خاور بنز",children:"خاور بنز"})]}),e.touched.type_car&&e.errors.type_car&&u.jsx(J,{error:!0,children:e.errors.type_car})]})}),u.jsx(j,{item:!0,xs:12,alignItems:"center",justifyContent:"center",children:u.jsx(Au,{width:"100%",pelakState:F,handleChange:d})}),u.jsx(j,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(w,{id:"capocity",name:"capocity",label:"ظرفیت",type:"number",InputProps:{endAdornment:u.jsx(lu,{position:"start",children:"کیلوگرم"})},value:e.values.capocity,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.capocity&&!!e.errors.capocity,helperText:e.touched.capocity&&e.errors.capocity})})}),u.jsx(j,{item:!0,xs:12,children:u.jsx(S,{fullWidth:!0,children:u.jsx(w,{id:"health_code",name:"health_code",label:"کد بهداشتی",value:e.values.health_code,onChange:e.handleChange,onBlur:e.handleBlur,error:e.touched.health_code&&!!e.errors.health_code,helperText:e.touched.health_code&&e.errors.health_code})})}),u.jsxs(j,{item:!0,xs:12,children:[u.jsx(z,{children:"ماهیت خودرو"}),u.jsx(S,{component:"fieldset",disabled:m()==="ProvinceOperator"||m()==="SuperAdmin"||m()==="AdminX"?!1:o?o==="rental":!1,children:u.jsxs(nu,{name:"type",value:e.values.type,onChange:e.handleChange,children:[(m()==="ProvinceOperator"||m()==="SuperAdmin"||m()==="AdminX")&&u.jsx(Q,{value:"rental",control:u.jsx(Z,{}),label:u.jsx(j,{container:!0,children:u.jsxs(z,{children:["اجاره ای"," ",u.jsx(z,{variant:"caption",children:"(نمایش برای تمام کشتارگاه ها)"})]})})}),u.jsx(Q,{value:"exclusive",control:u.jsx(Z,{}),label:"اختصاصی"})]})})]}),u.jsx(j,{item:!0,xs:12,children:u.jsx(W,{fullWidth:!0,variant:"contained",color:"primary",type:"submit",children:"ارسال"})})]})})},Eu=P("PROVINCE_REMOVE_CAR",async r=>{const{data:a,status:t}=await T.delete("kill_house_driver/0/?key="+r);return{data:a,status:t}}),ku=P("PROVINCE_ADD_CAR_TO_KILLHOUSE_SERVICE",async(r,{dispatch:a})=>{try{a(L());const{data:t,status:i}=await T.post("kill_house_add_car/",{...r,role:m()});return a(f()),{data:t,status:i}}catch(t){return a(f()),{error:t.response.data.result}}}),Su=P("PROVINCE_REMOVE_CAR_FROM_KILLHOUSE_SERVICE",async(r,{dispatch:a})=>{try{a(L());const{data:t,status:i}=await T.delete("kill_house_add_car/0/",{params:r});return a(f()),{data:t,status:i}}catch(t){return a(f()),{error:t.response.data.result}}}),Ru=ru().shape({autocompleteField:k().required("This field is required")}),Iu=({killHouseList:r,driverKey:a})=>{const[t]=y.useContext(M),i=eu({initialValues:{autocompleteField:""},validationSchema:Ru,onSubmit:l=>{if(!(l!=null&&l.autocompleteField)||!a){t({vertical:"top",horizontal:"center",msg:"لطفا تمام فیلدها را پر کنید",severity:"error"});return}C(ku({kill_house_key:l.autocompleteField,driver_key:a})).then(o=>{var c;(c=o==null?void 0:o.payload)!=null&&c.error?t({vertical:"top",horizontal:"center",msg:o.payload.error,severity:"error"}):(C(B()),C(R({right:!1,bottom:!1,content:null})),t({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})}}),C=D(),[x,h]=y.useState([]),{provinceGetOnlyKillHouses:s}=V(l=>l.provinceSlice);return y.useEffect(()=>{m()==="KillHouse"?C(U("self_kill_houses")):C(U("role=ProvinceOperator"))},[]),y.useEffect(()=>{if(!s||!Array.isArray(s)){h([]);return}const l=s.map(o=>{if(!o)return null;let c;return o.killer?c="کشتارکن":c="کشتارگاه",{title:`${c} ${(o==null?void 0:o.name)||""}`,value:(o==null?void 0:o.key)||""}}).filter(o=>o!==null&&o.value);h(l||[])},[s]),u.jsxs(I,{children:[u.jsx("form",{onSubmit:i.handleSubmit,children:u.jsxs(I,{container:!0,direction:"column",gap:O.TINY,mb:O.SMALL,children:[u.jsx(su,{id:"autocompleteField",options:x||[],getOptionLabel:l=>(l==null?void 0:l.title)||"",renderInput:l=>u.jsx(w,{...l,label:"انتخاب کشتارگاه",variant:"outlined",fullWidth:!0,error:i.touched.autocompleteField&&!!i.errors.autocompleteField,helperText:i.touched.autocompleteField&&i.errors.autocompleteField}),onChange:(l,o)=>i.setFieldValue("autocompleteField",(o==null?void 0:o.value)||""),value:x==null?void 0:x.find(l=>l.value===i.values.autocompleteField)}),u.jsx(W,{fullWidth:!0,variant:"contained",type:"submit",children:"ثبت"})]})}),u.jsx(z,{variant:"body1",fontWeight:"bold",children:"کشتارگاه های خودرو"}),r&&Array.isArray(r)&&r.length>0?r.map((l,o)=>l?u.jsxs(I,{container:!0,gap:O.TINY,alignItems:"center",justifyContent:"space-between",style:{borderBottom:"1px solid #DDD"},children:[u.jsxs(z,{children:[o+1,". ",(l==null?void 0:l.killHouseName)||""]}),u.jsx(W,{color:"error",onClick:()=>{if(!(l!=null&&l.killHouseKey)||!a){t({vertical:"top",horizontal:"center",msg:"اطلاعات ناقص است",severity:"error"});return}C(Su({kill_house_key:l.killHouseKey,driver_key:a})).then(c=>{var p;(p=c==null?void 0:c.payload)!=null&&p.error?t({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(C(B()),C(R({right:!1,bottom:!1,content:null})),t({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:"حذف"})]},l.killHouseKey||o):null):null]})},Tu=P("UPDATE_CAR_STATE_SERVICE",async(r,{dispatch:a})=>{try{a(L());const{data:t,status:i}=await T.put("kill_house_driver/0/",r);return a(f()),{data:t,status:i}}catch(t){return a(f()),{error:t.response.data.result}}}),Bu=({item:r})=>{const[a]=y.useContext(M),t=D(),[i,C]=y.useState(m()==="KillHouse"?r.addCarActiveState:r.driverActiveState),x=s=>{let l;m()==="KillHouse"?l={add_car_key:r.addCarKey,add_car_change_activation:s.target.checked}:l={driver_key:r.key,change_activation:s.target.checked},t(Tu(l)).then(o=>{var c,p;(c=o==null?void 0:o.payload)!=null&&c.error?a({vertical:"top",horizontal:"center",msg:(p=o==null?void 0:o.payload)==null?void 0:p.error,severity:"error"}):(t(B()),a({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))}),C(s.target.checked)};let h=!1;return r.driverType==="rental"&&(h=!0),u.jsxs(u.Fragment,{children:[u.jsx(iu,{checked:i,onChange:x,name:"mySwitch",color:"primary",disabled:h}),i?u.jsx("label",{htmlFor:"mySwitch",children:"فعال"}):u.jsx("label",{htmlFor:"mySwitch",children:"غیرفعال"})]})},Lu=P("CARS_DASHBOARD",async(r,{dispatch:a})=>{a(L());const{data:t,status:i}=await T.get("kill_house_driver_total_dashboard",{params:{role:m(),...t}});return a(f()),{data:t,status:i}}),Pu=()=>{var c,p,g,e,F,A;const r=D(),[a,t]=y.useState([]),[i]=y.useContext(M),{provinceCars:C}=V(v=>v.provinceSlice),x=V(v=>v.userSlice.userProfile.key),h=V(v=>v.userSlice.selectedSubUser);y.useEffect(()=>{r(B({role_key:G("province")&&(h==null?void 0:h.key)||""}))},[h==null?void 0:h.key]);const[s,l]=y.useState([]);y.useEffect(()=>{r(Lu({role_key:G("province")&&(h==null?void 0:h.key)||""})).then(v=>{l(v.payload.data)})},[r,C,h==null?void 0:h.key]),y.useEffect(()=>{const v=C==null?void 0:C.map((d,n)=>{var N;let b="-";d.type==="rental"?b="اجاره ای":d.type==="exclusive"&&(b="اختصاصی");const E=d.type==="rental"?"همه کشتارگاه ها/کشتارکن ها":(N=d==null?void 0:d.killHouseList)==null?void 0:N.map(($,au)=>{const ou=au+1===d.killHouseList.length?"":" - ";return($==null?void 0:$.killHouseName)+ou});return[n+1,d.typeCar,b,d.pelak,d.capocity,parseInt(d.healthCode),d.driverName,d.driverMobile,E,u.jsx(Bu,{item:d},d.key),u.jsx(wu,{item:d,openNotif:i},`car-action-${d.key}`)]});t(v)},[C,r,i]);const[o]=y.useState(["ردیف","مدل خودرو","ماهیت","پلاک","ظرفیت","کد بهداشتی","نام راننده","موبایل راننده","کشتارگاه ها/کشتارکن ها","وضعیت","عملیات"]);return u.jsx(u.Fragment,{children:u.jsxs(I,{container:!0,alignItems:"center",justifyContent:"space-between",gap:O.SMALL,xs:12,children:[u.jsx(W,{variant:"contained",onClick:()=>{r(R({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"افزودن خودرو",content:u.jsx(tu,{})}))},children:"افزودن خودرو"}),u.jsx(cu,{title:"خروجی اکسل",children:u.jsx("a",{href:`${T.defaults.baseURL}car_province_excel/?key=${x}&role=${m()}${G("province")?`&role_key=${h==null?void 0:h.key}`:""}`,rel:"noreferrer",children:u.jsx(W,{color:"success",children:u.jsx(vu,{size:32})})})}),u.jsxs(du,{sx:{width:"100%"},children:[u.jsx(I,{container:!0,mt:2,mb:4,isDashboard:!0,xs:12,children:u.jsx(uu,{noPagination:!0,isDashboard:!0,columns:["تعداد خودرو ها","اختصاصی","اجاره ای","فعال","غیر فعال","معلق"],data:[[(c=s==null?void 0:s.total)==null?void 0:c.toLocaleString(),(p=s==null?void 0:s.exclusive)==null?void 0:p.toLocaleString(),(g=s==null?void 0:s.rental)==null?void 0:g.toLocaleString(),(e=s==null?void 0:s.active)==null?void 0:e.toLocaleString(),(F=s==null?void 0:s.inactive)==null?void 0:F.toLocaleString(),(A=s==null?void 0:s.suspended)==null?void 0:A.toLocaleString()]],title:"خلاصه اطلاعات"})}),u.jsx(uu,{paginated:!0,title:"خودروها",columns:o,data:a})]})]})})},wu=({item:r,openNotif:a})=>{var v;const t=D(),[i,C]=y.useState(null),x=!(m()==="ProvinceOperator"||m()==="SuperAdmin"||m()==="AdminX"),h=(v=r.killHouseList)==null?void 0:v.some(d=>!d.allowState),s=!x||!h,l=r.type==="rental",o=!!i,c=o?`province-cars-popover-${r.key}`:void 0,p=()=>C(null),g=()=>{p(),t(R({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"تخصیص/حذف کشتارگاه",content:u.jsx(Iu,{driverKey:r.key,killHouseList:r.killHouseList})}))},e=()=>{p(),t(R({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ویرایش خودرو",content:u.jsx(tu,{first_name:r.firstName,pelak:r.pelak,city_name:r.city,type_car:r.typeCar,last_name:r.lastName,capocity:r.capocity,health_code:r.healthCode,driver_mobile:r.driverMobile,driverKey:r==null?void 0:r.key,type:r==null?void 0:r.type})}))},F=()=>{p(),t(L()),t(Eu(r.key)).then(d=>{d.error?d.error.message.includes("403")?a({vertical:"top",horizontal:"center",msg:"امکان حذف بدلیل تخصیص بار فعال به خودرو وجود ندارد!",severity:"error"}):a({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است!",severity:"error"}):(t(R({right:!1,bottom:!1,content:null})),t(B()),a({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})),t(f())})},A=!s||x&&l;return u.jsxs("div",{children:[u.jsx(hu,{"aria-describedby":c,color:"primary",size:"small",onClick:d=>C(d.currentTarget),disabled:!s,children:u.jsx(_u,{})}),u.jsx(Cu,{id:c,anchorEl:i,open:o,onClose:p,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},disableRestoreFocus:!0,PaperProps:{sx:{p:2}},children:u.jsxs(pu,{sx:{py:0},children:[u.jsxs(K,{onClick:g,disabled:A,children:[u.jsx(H,{children:u.jsx(xu,{fontSize:"small",color:A?"disabled":"primary"})}),u.jsx(q,{primary:"تخصیص به کشتارگاه",primaryTypographyProps:{variant:"body2",color:A?"text.secondary":"primary"}})]}),u.jsxs(K,{onClick:e,disabled:A,children:[u.jsx(H,{children:u.jsx(ju,{fontSize:"small",color:A?"disabled":"primary"})}),u.jsx(q,{primary:"ویرایش",primaryTypographyProps:{variant:"body2",color:A?"text.secondary":"primary"}})]}),u.jsxs(K,{onClick:F,disabled:A,children:[u.jsx(H,{children:u.jsx(fu,{fontSize:"small",color:A?"disabled":"error"})}),u.jsx(q,{primary:"حذف",primaryTypographyProps:{variant:"body2",color:A?"text.secondary":"error"}})]})]})})]})},Yu=()=>u.jsx(yu,{display:"flex",justifyContent:"center",children:u.jsx(I,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,my:O.MEDIUM,children:u.jsx(I,{container:!0,justifyContent:"space-between",gap:O.SMALL,children:u.jsx(I,{xs:12,children:u.jsx(Pu,{})})})})});export{Yu as default};
|