Files
Rasadyar_FrontEnd/build/assets/ChainBarManagement-BrSz4Hwe.js

2 lines
32 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{j as r,T as g,am as Yu,ak as j,ag as wu,bi as Gu,ah as Ku,ai as $u,aj as Nu,av as Uu,aw as Xu,ax as Qu,B as z,I as xu,b0 as Zu,an as Ju,b4 as mu,ap as u0,aq as e0,a3 as gu,d as Fu,p as fu,b2 as r0,b3 as Su}from"./mui-vendor-CkIVaoQP.js";import{r as C,b as Bu,f as a0}from"./react-vendor-CmFgShSM.js";import{L as V,j as T,X as b,db as Ru,h as k,A as G,u as Iu,c as qu,M as L,b as Du,v as iu,G as y,W as ju,S as vu,N as P,O as Hu,C as Au,p as Mu,Q as l0,E as n0,an as o0,az as s0,fr as t0}from"./index-Cr86_nOs.js";import{a as K,u as U,f as c0}from"./redux-vendor-B7uoacJt.js";import{R as C0,a as Ou}from"./index.esm-Bu7XMDZU.js";import{R as d0}from"./ResponsiveTable-Dua7tTwQ.js";import{d as ku}from"./Edit-DVocKJob.js";import{d as h0}from"./Settings-BSDlStEO.js";import{d as i0}from"./Tune-m0V6JHJm.js";import{d as v0}from"./Delete-CTUmuli-.js";import{C as p0}from"./CarPelak-Ddy5J5I5.js";import{d as y0}from"./Pageview-Dg_y1yOR.js";import{d as x0}from"./AddCircleOutline-CCVNHzAe.js";const Tu=K("PROVINCE_CREATE_ALLOCATION",async(e,{dispatch:n})=>{try{n(V());const{data:l,status:o}=await T.post("chain-allocation/",{...e,role:b()});return n(Ru()),n(k()),{data:l,status:o}}catch(l){return n(k()),{error:l.response.data.result}}}),g0=K("PROVINCE_GET_KILLHOUSES_FOR_ALLOCATION",async()=>{const{data:e,status:n}=await T.get("/kill_house/?kill_house=true");return{data:e,status:n}}),_u=K("PROVINCE_EDIT_CHAIN_ALLOCATION",async(e,{dispatch:n})=>{try{n(V());const{data:l,status:o}=await T.put("chain-allocation/0/",e);return n(Ru()),n(k()),{data:l,status:o}}catch(l){return n(k()),{error:l.response.data.result}}}),A0=({item:e,updateTable:n,isEdit:l})=>{var I,q,X,pu,Q,yu;const o=U(),[c]=C.useContext(G),[x,f]=Bu.useState(l?e!=null&&e.outProvince?"out":"native":"out"),[v,F]=Bu.useState();C.useEffect(()=>{x==="native"&&(o(V()),o(g0()).then(t=>{o(k());const _=t==null?void 0:t.payload.data.map(O=>({name:O.name,key:O.key}));A(_),F("")}))},[x]);const[E,A]=C.useState([]),w=t=>{f(t.target.value)},[h,N]=C.useState([]),S=(t,_,O,Z)=>{N([t,_,O,Z])},a=Iu({initialValues:{weight:l?e==null?void 0:e.indexWeight:"",quantity:l?e==null?void 0:e.quantity:"",driverName:l?e==null?void 0:e.driverName:"",driverMobile:l?e==null?void 0:e.driverMobile:"",driverCar:l?e==null?void 0:e.typeCar:"",healthCode:l?e==null?void 0:e.healthCode:""},validationSchema:qu({weight:Du().required("این فیلد اجباری است!"),quantity:Du().required("این فیلد اجباری است!"),driverName:L().required("این فیلد اجباری است!"),healthCode:L().required("این فیلد اجباری است!"),driverMobile:L().required("شماره موبایل کشتارگاه الزامی است").min(11,"شماره موبایل باید 11 رقم باشد").max(11,"شماره موبایل باید 11 رقم باشد").matches(/^09\d{9}$/,"شماره موبایل باید با 09 شروع شود و 11 رقم باشد"),driverCar:L().required("این فیلد اجباری است!")})}),[,,d,$,,]=C.useContext(G);C.useEffect(()=>{const t=iu(new Date).format("YYYY-MM-DD");$(t)},[]);const s=Iu({initialValues:{name:l?e==null?void 0:e.buyerName:"",mobile:l?e==null?void 0:e.buyerMobile:"",province:l?e==null?void 0:e.province:"",city:l?e==null?void 0:e.city:""},validationSchema:qu({name:L().required("نام اجباری است"),mobile:L().required("شماره موبایل کشتارگاه الزامی است").min(11,"شماره موبایل باید 11 رقم باشد").max(11,"شماره موبایل باید 11 رقم باشد").matches(/^09\d{9}$/,"شماره موبایل باید با 09 شروع شود و 11 رقم باشد"),province:L().required("استان اجباری است"),city:L().required("شهرستان اجباری است")})});C.useEffect(()=>{a.validateForm(),s.validateForm()},[]);const B=()=>x==="native"?a.isValid&&v&&h[1]:a.isValid&&s.isValid&&h[1];return C.useEffect(()=>{let t=a.values.weight;const _=a.values.weight.toString().split(".").join("");a.values.weight&&_.length<=3&&(_.length===2&&(t=_[0]+"."+_[1]),_.length===3&&(t=_[0]+"."+_[1]+_[2])),isNaN(Number.parseFloat(t))?a.setFieldValue("weight",""):a.setFieldValue("weight",Number.parseFloat(t))},[a.values.weight]),r.jsxs(y,{container:!0,xs:12,alignItems:"center",justifyContent:"center",gap:2,children:[!l&&r.jsxs(r.Fragment,{children:[r.jsxs(y,{container:!0,xs:12,children:[r.jsxs(g,{variant:"body2",children:["شرکت زنجیره:"," "]}),r.jsx(g,{variant:"body2",style:{color:"gray"},children:e==null?void 0:e.companyName})]}),r.jsxs(y,{container:!0,xs:12,children:[r.jsxs(g,{variant:"body2",children:["مرغدار:"," "]}),r.jsxs(g,{variant:"body2",style:{color:"gray"},children:[e.poultry.userprofile.fullName," (",e.poultry.userprofile.mobile,")"]})]}),r.jsxs(y,{container:!0,xs:12,children:[r.jsxs(g,{variant:"body2",children:["نژاد:"," "]}),r.jsx(g,{variant:"body2",style:{color:"gray"},children:e.chickenBreed})]}),r.jsxs(y,{container:!0,xs:12,children:[r.jsxs(g,{variant:"body2",children:["سن جوجه:"," "]}),r.jsx(g,{variant:"body2",style:{color:"gray"},children:e.age})]})]}),l&&r.jsxs(r.Fragment,{children:[r.jsxs(y,{container:!0,xs:12,children:[r.jsxs(g,{variant:"body2",children:["مرغدار:"," "]}),r.jsxs(g,{variant:"body2",style:{color:"gray"},children:[(q=(I=e==null?void 0:e.poultryHatching)==null?void 0:I.poultry)==null?void 0:q.unitName," (",(Q=(pu=(X=e==null?void 0:e.poultryHatching)==null?void 0:X.poultry)==null?void 0:pu.user)==null?void 0:Q.mobile,")"]})]}),r.jsxs(y,{container:!0,xs:12,children:[r.jsxs(g,{variant:"body2",children:["شرکت زنجیره:"," "]}),r.jsx(g,{variant:"body2",style:{color:"gray"},children:(yu=e==null?void 0:e.chainCompany)==null?void 0:yu.name})]})]}),r.jsx(Yu,{style:{width:"100%"}}),r.jsx(y,{xs:12,children:r.jsx(ju,{label:" تاریخ",id:"date",renderInput:t=>r.jsx(j,{...t}),value:d,onChange:t=>{$(iu(t).format("YYYY-MM-DD"))}})}),r.jsx(y,{xs:12,children:r.jsx(j,{id:"quantity",fullWidth:!0,label:"حجم (قطعه)",variant:"outlined",sx:{width:"100%"},value:a.values.quantity,error:a.touched.quantity?!!a.errors.quantity:null,onChange:a.handleChange,onBlur:a.handleBlur,helperText:a.touched.quantity&&a.errors.quantity?a.errors.quantity:null})}),r.jsx(y,{xs:12,children:r.jsx(j,{id:"weight",fullWidth:!0,label:"میانگین وزن",variant:"outlined",sx:{width:"100%"},value:a.values.weight,error:a.touched.weight?!!a.errors.weight:null,onChange:a.handleChange,onBlur:a.handleBlur,helperText:a.touched.weight&&a.errors.weight?a.errors.weight:null})}),a.values.weight&&a.values.quantity&&r.jsxs(y,{container:!0,style:{borderStyle:"solid",borderWidth:"2px",borderColor:"gray",borderRadius:"6px"},xs:12,p:1,children:[r.jsxs(g,{variant:"body2",color:"primary",children:["وزن کل: "," "]}),r.jsxs(g,{variant:"body2",children:[parseInt(a.values.quantity*a.values.weight)," کیلوگرم"]})]}),r.jsxs(wu,{children:[r.jsx(Gu,{id:"demo-controlled-radio-buttons-group",children:"نوع فروش"}),r.jsxs(Ku,{row:!0,"aria-labelledby":"demo-controlled-radio-buttons-group",name:"controlled-radio-buttons-group",value:x,onChange:w,children:[r.jsx($u,{value:"out",control:r.jsx(Nu,{disabled:l}),label:"خارج استان"}),r.jsx($u,{value:"native",control:r.jsx(Nu,{disabled:l}),label:"درون استان"})]})]}),x==="out"?r.jsxs(y,{container:!0,xs:12,alignItems:"center",justifyContent:"center",gap:vu.SMALL,children:[r.jsx(g,{variant:"body1",children:"اطلاعات خریدار"}),r.jsx(j,{label:"نام و نام خانوادگی",name:"name",value:s.values.name,onChange:s.handleChange,onBlur:a.handleBlur,error:s.touched.name&&!!s.errors.name,helperText:s.touched.name&&s.errors.name,required:!0,fullWidth:!0}),r.jsx(j,{fullWidth:!0,id:"mobile",value:s.values.mobile,error:s.touched.mobile?!!s.errors.mobile:null,onChange:s.handleChange,onBlur:s.handleBlur,helperText:s.touched.mobile&&s.errors.mobile?s.errors.mobile:null,label:"موبایل",autoComplete:"current-password",variant:"outlined"}),r.jsx(j,{label:"استان",name:"province",value:s.values.province,onChange:s.handleChange,onBlur:a.handleBlur,error:s.touched.province&&!!s.errors.province,helperText:s.touched.province&&s.errors.province,required:!0,fullWidth:!0}),r.jsx(j,{label:"شهرستان",name:"city",value:s.values.city,onBlur:a.handleBlur,onChange:s.handleChange,error:s.touched.city&&!!s.errors.city,helperText:s.touched.city&&s.errors.city,required:!0,fullWidth:!0})]}):r.jsx(y,{xs:12,children:r.jsxs(wu,{fullWidth:!0,error:a.errors.selectedOption&&a.touched.selectedOption,children:[r.jsx(Uu,{children:"کشتارگاه را انتخاب کنید"}),r.jsx(Xu,{fullWidth:!0,label:"کشتارگاه را انتخاب کنید",id:"selectedKillhouse",name:"selectedKillhouse",onChange:t=>{const[_]=t.target.value.split("#");F(_)},onBlur:a.handleBlur,children:E==null?void 0:E.map(t=>r.jsx(Qu,{value:`${t.key+"#"+t.killer}`,children:`کشتارگاه ${t.name}`},t))}),a.errors.selectedKillhouse&&a.touched.selectedKillhouse&&r.jsx("div",{children:a.errors.selectedKillhouse})]})}),r.jsxs(y,{container:!0,xs:12,alignItems:"center",justifyContent:"center",gap:vu.SMALL,children:[r.jsx(g,{variant:"body1",children:"اطلاعات خودرو حمل"}),r.jsx(j,{label:"نام و نام خانوادگی راننده",name:"driverName",value:a.values.driverName,onChange:a.handleChange,onBlur:a.handleBlur,error:a.touched.driverName&&!!a.errors.driverName,helperText:a.touched.driverName&&a.errors.driverName?a.errors.driverName:null,required:!0,fullWidth:!0}),r.jsx(j,{fullWidth:!0,id:"driverMobile",value:a.values.driverMobile,error:a.touched.driverMobile?!!a.errors.driverMobile:null,onChange:a.handleChange,onBlur:a.handleBlur,helperText:a.touched.driverMobile&&a.errors.driverMobile?a.errors.driverMobile:null,label:"موبایل راننده",autoComplete:"current-password",variant:"outlined"}),r.jsx(j,{label:"کد بهداشتی ",name:"healthCode",value:a.values.healthCode,onChange:a.handleChange,onBlur:a.handleBlur,error:a.touched.healthCode&&!!a.errors.healthCode,helperText:a.touched.healthCode&&a.errors.healthCode,type:"tel",required:!0,fullWidth:!0}),r.jsx(j,{label:"مدل خودرو",name:"driverCar",value:a.values.driverCar,onChange:a.handleChange,onBlur:a.handleBlur,error:a.touched.driverCar&&!!a.errors.driverCar,helperText:a.touched.driverCar&&a.errors.driverCar,type:"tel",required:!0,fullWidth:!0}),r.jsx(p0,{width:"100%",handleChange:S,pelakInitial:l?e==null?void 0:e.pelak:""})]}),r.jsx(z,{disabled:!B(),variant:"contained",fullWidth:!0,onClick:()=>{b()!=="SuperAdmin"&&b()!=="AdminX"&&(e.age>40&&a.values.weight<1.9||e.age>40&&a.values.weight>4||e.age<40&&a.values.weight<1.5||e.age<40&&a.values.weight>4||e.age>56&&a.values.weight<2.8||e.age>56&&a.values.weight>4)?c({vertical:"top",horizontal:"center",msg:(e==null?void 0:e.age)>56?"میانگین وزنی باید عددی بین 2.8 تا 4 کیلوگرم باشد!":(e==null?void 0:e.age)>40?"میانگین وزنی باید عددی بین 1.9 تا 4 کیلوگرم باشد!":"میانگین وزنی باید عددی بین 1.5 تا 4 باشد!",severity:"error"}):l?x==="native"?o(_u({chain_allcation_key:e==null?void 0:e.key,quantity:a.values.quantity,weight:parseInt(a.values.quantity*a.values.weight),index_weight:a.values.weight,date:d,out_province:!1,driver_name:a.values.driverName,driver_mobile:a.values.driverMobile,health_code:a.values.healthCode,type_car:a.values.driverCar,pelak:h[0]+" "+h[1]+" "+h[2]+" "+h[3],kill_house_key:v})).then(t=>{o(P({right:!1,bottom:!1,content:null})),t.payload.error?c({vertical:"top",horizontal:"center",msg:t.payload.error,severity:"error"}):(n(1),c({vertical:"top",horizontal:"center",msg:"بار با موفقیت ثبت شد؛ جهت مشاهده به بخش مدیریت بارها در همین صفحه مراجعه کنید",severity:"success"}))}):o(_u({chain_allcation_key:e==null?void 0:e.key,quantity:a.values.quantity,weight:parseInt(a.values.quantity*a.values.weight),index_weight:a.values.weight,date:d,out_province:!0,driver_name:a.values.driverName,driver_mobile:a.values.driverMobile,health_code:a.values.healthCode,type_car:a.values.driverCar,pelak:h[0]+" "+h[1]+" "+h[2]+" "+h[3],buyer_name:s.values.name,buyer_mobile:s.values.mobile,city:s.values.city,province:s.values.name})).then(t=>{o(P({right:!1,bottom:!1,content:null})),t.payload.error?c({vertical:"top",horizontal:"center",msg:t.payload.error,severity:"error"}):(n(1),c({vertical:"top",horizontal:"center",msg:"بار با موفقیت ثبت شد؛ جهت مشاهده به بخش مدیریت بارها در همین صفحه مراجعه کنید",severity:"success"}))}):x==="native"?o(Tu({hatching_key:e==null?void 0:e.key,quantity:a.values.quantity,weight:parseInt(a.values.quantity*a.values.weight),index_weight:a.values.weight,date:d,out_province:!1,driver_name:a.values.driverName,driver_mobile:a.values.driverMobile,health_code:a.values.healthCode,type_car:a.values.driverCar,pelak:h[0]+" "+h[1]+" "+h[2]+" "+h[3],kill_house_key:v})).then(t=>{o(P({right:!1,bottom:!1,content:null})),t.payload.error?c({vertical:"top",horizontal:"center",msg:t.payload.error,severity:"error"}):(n(),c({vertical:"top",horizontal:"center",msg:"بار با موفقیت ثبت شد؛ جهت مشاهده به بخش مدیریت بارها در همین صفحه مراجعه کنید",severity:"success"}))}):o(Tu({hatching_key:e==null?void 0:e.key,quantity:a.values.quantity,weight:parseInt(a.values.quantity*a.values.weight),index_weight:a.values.weight,date:d,out_province:!0,driver_name:a.values.driverName,driver_mobile:a.values.driverMobile,health_code:a.values.healthCode,type_car:a.values.driverCar,pelak:h[0]+" "+h[1]+" "+h[2]+" "+h[3],buyer_name:s.values.name,buyer_mobile:s.values.mobile,city:s.values.city,province:s.values.name})).then(t=>{o(P({right:!1,bottom:!1,content:null})),t.payload.error?c({vertical:"top",horizontal:"center",msg:t.payload.error,severity:"error"}):(n(),c({vertical:"top",horizontal:"center",msg:"بار با موفقیت ثبت شد؛ جهت مشاهده به بخش مدیریت بارها در همین صفحه مراجعه کنید",severity:"success"}))})},children:"ثبت"})]})},b0=({healthCode:e,item:n,updateTable:l})=>{const o=U(),[c]=C.useContext(G),x=()=>{o(Hu({title:"ویرایش کد بهداشتی",size:"auto",content:r.jsx(f0,{initialValue:e||"",onSubmit:f=>{o(_u({chain_allcation_key:n==null?void 0:n.key,health_code:f})).then(v=>{var F;(F=v.payload)!=null&&F.error?c({vertical:"top",horizontal:"center",msg:v.payload.error,severity:"error"}):(c({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),l(),o(Au()))})},onCancel:()=>o(Au())})}))};return r.jsxs(y,{container:!0,alignItems:"center",gap:.5,sx:{width:"120px"},justifyContent:"center",children:[r.jsx(g,{variant:"caption",children:e||"-"}),r.jsx(xu,{"aria-label":"edit",size:"small",color:"primary",onClick:x,children:r.jsx(ku,{fontSize:"small"})})]})},f0=({initialValue:e,onSubmit:n,onCancel:l})=>{const[o,c]=C.useState(e);return r.jsxs(y,{container:!0,direction:"column",gap:2,minWidth:260,children:[r.jsx(j,{label:"کد بهداشتی",value:o,onChange:x=>c(x.target.value),fullWidth:!0,size:"small"}),r.jsxs(y,{container:!0,justifyContent:"flex-end",xs:12,gap:1,children:[r.jsx(z,{variant:"contained",color:"primary",onClick:()=>n(o),style:{flex:1},children:"ثبت"}),r.jsx(z,{style:{flex:1},variant:"outlined",color:"primary",onClick:l,children:"لغو"})]})]})},F0=K("PROVINCE_DELETE_CHAIN_ALLOCATION_SERVICE",async(e,{dispatch:n})=>{try{n(V());const{data:l,status:o}=await T.delete("chain-allocation/0/?chain_allcation_key="+e+`&role=${b()}`);return n(k()),{data:l,status:o}}catch(l){return n(k()),{error:l.response.data.result}}}),zu=K("PROVINCE_CHECK_CHAIN_ALLOCATION_SERVICE",async(e,{dispatch:n})=>{try{n(V());const{data:l,status:o}=await T.put("chain-allocation/0/",e);return n(k()),{data:l,status:o}}catch(l){return n(k()),{error:l.response.data.result}}}),j0=({item:e,fetchApiData:n})=>{var v,F,E,A,w,h,N,S,a,d,$,s,B;const l=U(),[o]=C.useContext(G),[c,x]=C.useState(""),f=I=>{x(I.target.value)};return r.jsxs(y,{container:!0,direction:"column",children:[r.jsxs(y,{children:[r.jsx(g,{variant:"h6",gutterBottom:!0,children:"اطلاعات مرغدار"}),r.jsxs(g,{variant:"subtitle1",gutterBottom:!0,children:["نام: ",(F=(v=e==null?void 0:e.poultryHatching)==null?void 0:v.poultry)==null?void 0:F.unitName," (",(w=(A=(E=e==null?void 0:e.poultryHatching)==null?void 0:E.poultry)==null?void 0:A.user)==null?void 0:w.mobile,")"]}),r.jsxs(g,{variant:"subtitle1",gutterBottom:!0,children:["شرکت زنجیره:"," ",`${(h=e==null?void 0:e.chainCompany)==null?void 0:h.name} (${(N=e==null?void 0:e.chainCompany)==null?void 0:N.user.mobile})`]}),r.jsxs(g,{variant:"subtitle1",gutterBottom:!0,children:["نوع تخصیص: ",e!=null&&e.outProvince?"خارج استان":"داخل استان"]}),r.jsxs(g,{variant:"subtitle1",gutterBottom:!0,children:["خریدار:"," ",(a=(S=e==null?void 0:e.killHouse)==null?void 0:S.killHouseOperator)!=null&&a.user.fullname?`${($=(d=e==null?void 0:e.killHouse)==null?void 0:d.killHouseOperator)==null?void 0:$.user.fullname} (${(B=(s=e==null?void 0:e.killHouse)==null?void 0:s.killHouseOperator)==null?void 0:B.user.mobile})`:`${e==null?void 0:e.buyerName} (${e==null?void 0:e.buyerMobile})`]})]}),r.jsxs(y,{container:!0,gap:vu.TINY,mt:vu.SMALL,children:[r.jsx(j,{label:"یادداشت",variant:"outlined",fullWidth:!0,multiline:!0,rows:4,value:c,onChange:f}),r.jsx(z,{style:{flex:.5},variant:"contained",color:"success",onClick:()=>{l(zu({chain_allcation_key:e==null?void 0:e.key,check_allocation:!0,state:"accepted"})).then(I=>{n(1),I.payload.error?o({vertical:"top",horizontal:"center",msg:I.payload.error,severity:"error"}):(l(P({right:!1,bottom:!1,content:null})),o({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:"تایید"}),r.jsx(z,{style:{flex:.5},variant:"contained",color:"error",onClick:()=>{l(zu({chain_allcation_key:e==null?void 0:e.key,check_allocation:!0,state:"rejected"})).then(I=>{n(1),I.payload.error?o({vertical:"top",horizontal:"center",msg:I.payload.error,severity:"error"}):(l(P({right:!1,bottom:!1,content:null})),o({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:"رد"})]})]})},_0=({item:e,fetchApiData:n})=>{const l=U(),[o]=C.useContext(G),[c,x]=C.useState(null),f=d=>{x(d.currentTarget)},v=()=>{x(null)},F=!!c,E=F?"popover":void 0,A=b(),w=()=>{v(),l(P({title:"تایید/ رد درخواست",right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:r.jsx(j0,{item:e,fetchApiData:n})}))},h=()=>{v(),l(P({title:"ویرایش بار",right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:r.jsx(A0,{item:e,updateTable:n,isEdit:!0})}))},N=()=>{v(),l(F0(e==null?void 0:e.key)).then(d=>{d.payload.error?o({vertical:"top",horizontal:"center",msg:d.payload.error,severity:"error"}):(o({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),n(1))})},S=A==="ProvinceOperator"||A==="SuperAdmin"||A==="AdminX",a=[{key:"approve",label:"تایید / رد درخواست",color:"primary.main",icon:r.jsx(h0,{sx:{fontSize:{xs:20,md:18}}}),action:w,disabled:(e==null?void 0:e.state)!=="pending"},{key:"edit",label:"ویرایش بار",color:"info.main",icon:r.jsx(ku,{sx:{fontSize:{xs:20,md:18}}}),action:h,disabled:!S||(e==null?void 0:e.state)==="rejected"||!!(e!=null&&e.quarantineCode)},{key:"delete",label:"حذف بار",color:"error.main",icon:r.jsx(v0,{sx:{fontSize:{xs:20,md:18}}}),action:N,disabled:!S||(e==null?void 0:e.state)==="rejected"||!!(e!=null&&e.quarantineCode)}];return r.jsxs("div",{children:[r.jsx(xu,{"aria-describedby":E,variant:"contained",color:"primary",onClick:f,children:r.jsx(i0,{})}),r.jsx(Zu,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},slotProps:{paper:{sx:{mt:1}}},id:E,open:F,anchorEl:c,onClose:v,children:r.jsx(Ju,{sx:{p:1},children:a.map(d=>r.jsxs(mu,{onClick:()=>{d.disabled||d.action()},disabled:!!d.disabled,sx:{borderRadius:1,mb:.5,color:d.disabled?"text.disabled":d.color,"&:last-of-type":{mb:0}},children:[r.jsx(u0,{sx:{color:d.disabled?"text.disabled":d.color,minWidth:36},children:d.icon}),r.jsx(e0,{primary:r.jsx(g,{sx:{color:d.disabled?"text.disabled":d.color,fontWeight:600,fontSize:{xs:"13px",md:"14px"}},children:d.label})})]},d.key))})})]})},k0=K("PROVINCE_CHAINS_EDIT_BAR",async(e,{dispatch:n})=>{try{n(V());const{data:l,status:o}=await T.put("chain-allocation/0/",e);return n(k()),{data:l,status:o}}catch(l){return n(k()),{error:l.response.data.result}}}),Lu=({item:e,updateTable:n,isLocked:l})=>{const o=U(),[c]=C.useContext(G),x=()=>{o(Hu({title:"ثبت کد قرنطینه",size:"auto",content:r.jsx(w0,{code:e.quarantineCode||"",isLocked:l,onSubmit:f=>{o(k0({chain_allcation_key:e.key,quarantine_code:f,role:b()})).then(v=>{v.payload.error?c({vertical:"top",horizontal:"center",msg:v.payload.error,severity:"error"}):(c({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),n(),o(Au()))})},onCancel:()=>o(Au())})}))};return r.jsxs(gu,{container:!0,alignItems:"center",gap:.5,sx:{width:e.quarantineCode?"160px":"auto",justifyContent:"center"},children:[e.quarantineCode?r.jsx(E0,{clearanceCode:e.quarantineCode}):r.jsx(xu,{"aria-label":"add",size:"small",color:"primary",onClick:x,children:r.jsx(x0,{fontSize:"small"})}),!l&&r.jsx(xu,{"aria-label":"edit",size:"small",color:"primary",onClick:x,sx:{display:e.quarantineCode?"inline-flex":"none"},children:r.jsx(ku,{fontSize:"small"})})]})},E0=({clearanceCode:e})=>{const n=C.useRef(null),l=()=>{n.current&&n.current.submit()};return r.jsxs(gu,{container:!0,alignItems:"center",justifyContent:"center",gap:.5,style:{width:"auto"},children:[r.jsx(Fu,{title:"مشاهده گواهینامه",arrow:!0,children:r.jsxs("form",{action:"https://e.ivo.ir/Rahgiri/Gidprnt.aspx",method:"post",target:"_blank",ref:n,style:{cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center"},children:[r.jsx("input",{name:"gid",type:"hidden",value:e}),r.jsx(y0,{color:"primary",onClick:l})]})}),r.jsx(g,{variant:"caption",color:"primary",children:e})]})},w0=({code:e,isLocked:n,onSubmit:l,onCancel:o})=>{const[c,x]=C.useState(e),[f,v]=C.useState("");C.useEffect(()=>{x(e)},[e]);const F=w=>w?/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]+$/.test(w)?(v(""),!0):(v("باید شامل اعداد و حروف انگلیسی باشد"),!1):(v("این فیلد اجباری است"),!1),E=w=>{const h=w.target.value.toUpperCase();x(h),F(h)},A=()=>{F(c)&&l(c)};return r.jsxs(gu,{container:!0,direction:"column",gap:2,children:[r.jsx(j,{label:"کد قرنطینه",value:c,onChange:E,size:"small",fullWidth:!0,error:!!f,helperText:f,InputProps:{readOnly:n}}),r.jsxs(gu,{container:!0,justifyContent:"flex-end",gap:1,xs:12,children:[r.jsx(z,{variant:"contained",color:"primary",onClick:A,disabled:n,style:{flex:1},children:"ثبت"}),r.jsx(z,{style:{flex:1},variant:"outlined",color:"primary",onClick:o,children:"لغو"})]})]})};Lu.propTypes={item:fu.PropTypes.any,updateTable:fu.PropTypes.any,isLocked:fu.PropTypes.any};const L0=({province:e})=>{const[n,,l,o,c,x]=C.useContext(G),f=U();C.useEffect(()=>{const p=iu(new Date).format("YYYY-MM-DD");o(p),x(p)},[]);const{pathname:v}=a0(),F=c0(p=>{var D,u;return(u=(D=p.userSlice)==null?void 0:D.userProfile)==null?void 0:u.key}),E=p=>{I(p.target.value)},[A,w]=C.useState(0),h=(p,D)=>{w(D)},[N,S]=C.useState([]),[a,d]=C.useState(0),[$,s]=C.useState(10),[B,I]=C.useState(""),[q,X]=C.useState(1),[pu,Q]=C.useState([]),[yu,t]=C.useState([]),[_,O]=C.useState(!1),Z=async p=>{var D,u,M;if(!_){f(V());try{const i=await T.get(`${e?e+"parent-company-":""}chain-allocation/?search=filter&value=${B}&page=${p}&page_size=${$}&role=${b()}&date1=${l}&date2=${c}${A===1?"&state=rejected":""}`);O(!1),S(((D=i.data)==null?void 0:D.results)||[]),d(((u=i.data)==null?void 0:u.count)||0)}catch(i){console.error("Error fetching data:",i);const R=(i==null?void 0:i.message)||"",H=(M=i==null?void 0:i.response)==null?void 0:M.status;R.includes("500")||H===500?(O(!0),n({vertical:"top",horizontal:"center",msg:"مشکلی در دریافت اطلاعات پیش آمده است!",severity:"error"})):n({vertical:"top",horizontal:"center",msg:"مشکلی در دریافت اطلاعات پیش آمده است!",severity:"error"}),S([]),d(0)}finally{f(k())}}},Pu=p=>{Z(p),X(p)},Vu=p=>{s(p),X(1)},bu=()=>{Z(q!==0?q:1)};C.useEffect(()=>{if(!N||!Array.isArray(N)){Q([]),t([]);return}const p=N.map((u,M)=>{var i,R,H,W,J,m,uu,eu,ru,au,lu,nu,ou,su,tu,cu,Cu;return[q===1?M+1:M+$*(q-1)+1,r.jsx(_0,{fetchApiData:bu,item:u},M),(u==null?void 0:u.state)==="accepted"?"تایید شده":(u==null?void 0:u.state)==="pending"?"در انتظار تایید":"رد شده",u!=null&&u.date?Mu(u.date):"-",u!=null&&u.outProvince?"خارج استان":"داخل استان",`${((i=u==null?void 0:u.registerer)==null?void 0:i.fullname)||""} (${((R=u==null?void 0:u.registerer)==null?void 0:R.mobile)||""})`,(J=(W=(H=u==null?void 0:u.killHouse)==null?void 0:H.killHouseOperator)==null?void 0:W.user)!=null&&J.fullname?`${u.killHouse.killHouseOperator.user.fullname} (${((eu=(uu=(m=u==null?void 0:u.killHouse)==null?void 0:m.killHouseOperator)==null?void 0:uu.user)==null?void 0:eu.mobile)||""})`:`${(u==null?void 0:u.buyerName)||""} (${(u==null?void 0:u.buyerMobile)||""})`,`${((au=(ru=u==null?void 0:u.poultryHatching)==null?void 0:ru.poultry)==null?void 0:au.unitName)||""} (${((ou=(nu=(lu=u==null?void 0:u.poultryHatching)==null?void 0:lu.poultry)==null?void 0:nu.user)==null?void 0:ou.mobile)||""})`,`${((su=u==null?void 0:u.chainCompany)==null?void 0:su.name)||""} (${((cu=(tu=u==null?void 0:u.chainCompany)==null?void 0:tu.user)==null?void 0:cu.mobile)||""})`,r.jsxs(r.Fragment,{children:[" ",b()==="ParentCompany"?(u==null?void 0:u.healthCode)||"":r.jsx(b0,{healthCode:u==null?void 0:u.healthCode,item:u,updateTable:bu})]}),r.jsx(r.Fragment,{children:b()==="VetFarm"||b()==="ProvinceOperator"||b()==="SuperAdmin"||b()==="Supporter"||b()==="AdminX"||b()==="CityVet"||b()==="VetSupervisor"?r.jsxs(r.Fragment,{children:[r.jsx(Lu,{isLocked:b()==="ProvinceOperator"||b()==="VetSupervisor"?!1:!!((u==null?void 0:u.trash)===!0||u!=null&&u.quarantineQuantity),item:u,updateTable:bu}),(Cu=u==null?void 0:u.quarantineCodeRegisterar)!=null&&Cu.date?(()=>{var du,hu;try{const Y=new Date((du=u==null?void 0:u.registerar)==null?void 0:du.date);return isNaN(Y.getTime())?"":`${l0(Y,"yyyy/MM/dd")} ${((hu=u==null?void 0:u.quarantineCodeRegisterar)==null?void 0:hu.name)||""}`}catch(Y){return console.error("Error formatting quarantineCodeRegisterar date:",Y),""}})():""]}):u!=null&&u.quarantineCode?u.quarantineCode:"-"}),u!=null&&u.driverName?`${u.driverName} (${(u==null?void 0:u.driverMobile)||""})`:"-",(u==null?void 0:u.typeCar)||"",(u==null?void 0:u.pelak)||"",(u==null?void 0:u.quantity)||0,(u==null?void 0:u.indexWeight)||0,(u==null?void 0:u.weight)||0]});Q(p);const D=N.map((u,M)=>{var i,R,H,W,J,m,uu,eu,ru,au,lu,nu,ou,su,tu,cu,Cu,du,hu,Y;return[q===1?M+1:M+$*(q-1)+1,(u==null?void 0:u.state)==="rejected"?"رد شده":(u==null?void 0:u.state)==="deleted"?"حذف شده":"در انتظار تایید",u!=null&&u.remover?`${((i=u.remover)==null?void 0:i.fullname)||""} (${((R=u.remover)==null?void 0:R.mobile)||""})`:`${((H=u==null?void 0:u.registerer)==null?void 0:H.fullname)||""} (${((W=u==null?void 0:u.registerer)==null?void 0:W.mobile)||""})`,u!=null&&u.date?Mu(u.date):"-",u!=null&&u.outProvince?"خارج استان":"داخل استان",(J=u==null?void 0:u.registerer)!=null&&J.fullname?`${u.registerer.fullname} (${((m=u==null?void 0:u.registerer)==null?void 0:m.mobile)||""})`:"-",(ru=(eu=(uu=u==null?void 0:u.killHouse)==null?void 0:uu.killHouseOperator)==null?void 0:eu.user)!=null&&ru.fullname?`${u.killHouse.killHouseOperator.user.fullname} (${((nu=(lu=(au=u==null?void 0:u.killHouse)==null?void 0:au.killHouseOperator)==null?void 0:lu.user)==null?void 0:nu.mobile)||""})`:`${(u==null?void 0:u.buyerName)||""} (${(u==null?void 0:u.buyerMobile)||""})`,`${((su=(ou=u==null?void 0:u.poultryHatching)==null?void 0:ou.poultry)==null?void 0:su.unitName)||""} (${((Cu=(cu=(tu=u==null?void 0:u.poultryHatching)==null?void 0:tu.poultry)==null?void 0:cu.user)==null?void 0:Cu.mobile)||""})`,`${((du=u==null?void 0:u.chainCompany)==null?void 0:du.name)||""} (${((Y=(hu=u==null?void 0:u.chainCompany)==null?void 0:hu.user)==null?void 0:Y.mobile)||""})`,(u==null?void 0:u.healthCode)||"",(u==null?void 0:u.quarantineCode)||"",u!=null&&u.driverName?`${u.driverName} (${(u==null?void 0:u.driverMobile)||""})`:"-",(u==null?void 0:u.typeCar)||"",(u==null?void 0:u.pelak)||"",(u==null?void 0:u.quantity)||0,(u==null?void 0:u.indexWeight)||0,(u==null?void 0:u.weight)||0]});t(D)},[N,q,$]),C.useEffect(()=>{Z(1)},[f,l,c,$,A]),C.useEffect(()=>{O(!1)},[l,c,B,A]);const Eu=async p=>{var D,u,M;p.preventDefault(),O(!1),f(V());try{const i=await T.get(`${e?e+"parent-company-":""}chain-allocation/?search=filter&value=${B}&page=${q}&page_size=${$}&role=${b()}&date1=${l}&date2=${c}${A===1?"&state=rejected":""}`);O(!1),S(((D=i.data)==null?void 0:D.results)||[]),d(((u=i.data)==null?void 0:u.count)||0),f(k())}catch(i){console.error("Error fetching data:",i);const R=(i==null?void 0:i.message)||"",H=(M=i==null?void 0:i.response)==null?void 0:M.status;R.includes("500")||H===500?(O(!0),n({vertical:"top",horizontal:"center",msg:"مشکلی در دریافت اطلاعات پیش آمده است!",severity:"error"})):n({vertical:"top",horizontal:"center",msg:"مشکلی در دریافت اطلاعات پیش آمده است!",severity:"error"}),S([]),d(0),f(k())}},Wu=r.jsx(y,{container:!0,alignItems:"center",justifyContent:"space-between",gap:2,paddingTop:2,mb:1,xs:12,children:r.jsxs(y,{container:!0,alignItems:"center",gap:vu.SMALL,children:[r.jsx(y,{style:{width:"150px"},children:r.jsx(ju,{label:"از تاریخ",id:"date",renderInput:p=>r.jsx(j,{...p}),value:l,onChange:p=>{o(iu(p).format("YYYY-MM-DD"))}})}),r.jsx(y,{style:{width:"150px"},children:r.jsx(ju,{label:"تا تاریخ",id:"date",renderInput:p=>r.jsx(j,{...p}),value:c,onChange:p=>{x(iu(p).format("YYYY-MM-DD"))}})}),r.jsxs("form",{onSubmit:Eu,children:[r.jsx(j,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:E}),r.jsx(z,{type:"submit",onClick:Eu,endIcon:r.jsx(C0,{}),children:"جستجو"}),A===0?r.jsx(Fu,{title:"خروجی اکسل",children:r.jsx("a",{href:`${e||T.defaults.baseURL}bar_chain_excel/?key=${F||""}&role=${b()}&search=filter&value=${B||""}&state=accepted&date1=${l||""}&date2=${c||""}&search=filter&value=${B||""}`,rel:"noreferrer",children:r.jsx(z,{color:"success",children:r.jsx(Ou,{size:32})})})}):r.jsx(Fu,{title:"خروجی اکسل",children:r.jsx("a",{href:`${e||T.defaults.baseURL}bar_chain_excel/?key=${F||""}&role=${b()}&search=filter&value=${B||""}&state=rejected&date1=${l||""}&date2=${c||""}&search=filter&value=${B||""}`,rel:"noreferrer",children:r.jsx(z,{color:"success",children:r.jsx(Ou,{size:32})})})})]})]})});return r.jsxs(y,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[r.jsx(y,{xs:12,container:!0,justifyContent:"center",alignItems:"center",children:(v===n0||v===o0||v===s0||v===t0)&&r.jsxs(r0,{value:A,onChange:h,"aria-label":"simple tabs example",children:[r.jsx(Su,{label:"درخواست های تایید شده"}),r.jsx(Su,{label:"درخواست های رد شده"})]})}),Wu,r.jsx(d0,{data:A===0?pu:yu,columns:A===0?["ردیف","عملیات","وضعیت","تاریخ سفارش","نوع فروش","ثبت کننده سفارش","خریدار","مرغداری","شرکت زنجیره","کد بهداشتی","کد قرنطینه","راننده","نوع خودرو","پلاک","حجم","میانگین وزن","وزن"]:["ردیف","وضعیت","حذف/رد کننده","تاریخ سفارش","نوع فروش","خریدار","مرغداری","شرکت زنجیره","کد بهداشتی","کد قرنطینه","راننده","نوع خودرو","پلاک","حجم","میانگین وزن","وزن"],handlePageChange:Pu,totalRows:a,page:q,perPage:$,handlePerRowsChange:Vu,title:A===0?"بارهای تایید شده":"بارهای رد شده"})]})};export{A0 as C,L0 as a};