2 lines
17 KiB
JavaScript
2 lines
17 KiB
JavaScript
import{j as u,d as X,I as q,ak as R,B as H,a3 as D,al as Z,T as tu,ai as m,aX as uu,b2 as du,b3 as ou,b0 as iu,b as Cu}from"./mui-vendor-CkIVaoQP.js";import{f as nu,u as ru,r as l,j as lu}from"./react-vendor-CmFgShSM.js";import{G as j,S as G,h1 as B,h2 as K,h3 as J,h4 as hu,X as E,A as cu,j as w,L as k,h as S,c as pu,c2 as eu,M as W,u as gu,N as M,c5 as xu,h5 as fu,h6 as ju,h7 as Fu}from"./index-BHF9XhlR.js";import{B as yu}from"./BackButton-C3p7AEJl.js";import{N as Au}from"./NavLink-D2GD_ItM.js";import{L as vu}from"./LinkItem-B0NRrkKX.js";import{R as Q}from"./ResponsiveTable-cmj--TTX.js";import{u as N,a as Y}from"./redux-vendor-B7uoacJt.js";import{R as au,a as Su}from"./index.esm-Bu7XMDZU.js";import{d as Eu}from"./Visibility-DUYp8piW.js";import{s as _u,a as bu}from"./slaughter-get-provinces-C6Pl8X0E.js";import{d as wu}from"./Edit-DE-0ja3Q.js";import{d as ku}from"./Tune-rHyTJYQA.js";import"./FilterAlt-C5yvLNoT.js";import"./styled-components.browser.esm-gS9mh05b.js";import"./iconBase-BEJYyZsk.js";const Lu=()=>{const{pathname:t}=nu();return u.jsx(j,{container:!0,gap:G.SMALL,p:G.SMALL,direction:{xs:"column",md:"row"},justifyContent:"center",style:{placeContent:"baseline"},children:u.jsx(j,{container:!0,direction:"column",style:{width:"100%"},children:u.jsx(j,{container:!0,gap:G.SMALL,justifyContent:"center",children:u.jsx(Au,{to:E()==="ProvinceOperator"?B:E()==="AdminX"?K:J,active:t===B?"true":null,children:u.jsx(vu,{icon:u.jsx(hu,{size:30,color:"#244CCC"}),title:"سردخانه ها",description:"سردخانه ها"})})})})})},Iu=()=>{const t=N(),d=ru(),a=c=>{A(c.target.value)},[r]=l.useContext(cu),[p,C]=l.useState([]),[y,g]=l.useState(0),[x,f]=l.useState(10),[_,A]=l.useState(""),[v,F]=l.useState(1),[o,s]=l.useState([]),i=async c=>{let e;t(k()),e=await w.get(`kill-house-cold-house/?search=filter&value=${_}&role=${E()}&page=${c}&page_size=${x}`),t(S()),C(e.data.results),g(e.data.count)},b=c=>{i(c),F(c)},$=c=>{f(c),F(1)};l.useEffect(()=>{const c=p==null?void 0:p.map((e,h)=>{var n,L,I,P,O,V,z,U;return[v===1?h+1:h+x*(v-1)+1,e==null?void 0:e.name,e==null?void 0:e.fullname,e==null?void 0:e.mobile,e==null?void 0:e.city,(L=(n=e==null?void 0:e.coldHousesInfo)==null?void 0:n.totalColdHouses)==null?void 0:L.toLocaleString(),(P=(I=e==null?void 0:e.coldHousesInfo)==null?void 0:I.totalInputWeight)==null?void 0:P.toLocaleString(),(V=(O=e==null?void 0:e.coldHousesInfo)==null?void 0:O.totalAllocatedWeight)==null?void 0:V.toLocaleString(),(U=(z=e==null?void 0:e.coldHousesInfo)==null?void 0:z.totalRemainWeight)==null?void 0:U.toLocaleString(),u.jsx(X,{placement:"left",title:"نمایش",children:u.jsx(q,{size:"small",color:"success",onClick:()=>{d((E()==="ProvinceOperator"?B:E()==="AdminX"?K:J)+"/"+(e==null?void 0:e.key)+"/"+(e==null?void 0:e.fullname)+"/killhouse")},children:u.jsx(Eu,{})})},h)]});s(c)},[p]),l.useEffect(()=>{i(1)},[t,x]);const T=async c=>{c.preventDefault(),t(k());try{const e=await w.get(`kill-house-cold-house/?role=${E()}&search=filter&value=${_}&page=1&page_size=${x}`);C(e.data.results),g(e.data.count),t(S())}catch(e){console.error("Error fetching data:",e)}};return u.jsxs(j,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsxs(j,{container:!0,xs:12,justifyContent:"start",alignItems:"center",gap:2,children:[u.jsx(j,{children:u.jsxs("form",{onSubmit:T,children:[u.jsx(R,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:a}),u.jsx(H,{type:"submit",onClick:T,endIcon:u.jsx(au,{}),children:"جستجو"})]})}),u.jsx(X,{title:"خروجی اکسل",children:u.jsx(H,{color:"success",onClick:()=>{r({vertical:"top",horizontal:"center",msg:"فایل اکسل در حال دانلود می باشد، این علمیات ممکن است زمان بر باشد لطفا صبر کنید.",severity:"success"});const c=`${w.defaults.baseURL}management_cold_house_excel`;window.location.href=c},children:u.jsx(Su,{size:32})})})]}),u.jsx(Q,{data:o,columns:["ردیف","نام کشتارگاه","نام مالک","موبایل","شهر","تعداد سردخانه ها","وزن وارد شده","وزن خارج شده","وزن باقیمانده","سردخانه ها"],handlePageChange:b,totalRows:y,page:v,perPage:x,handlePerRowsChange:$,title:"سردخانه های کشتارگاه ها"})]})},Pu=Y("GET_PROVINCE_COLD_HOUSES_DASHBOARD",async(t,{dispatch:d})=>{d(k());const{data:a,status:r}=await w.get("cold-house-total-dashboard");return d(S()),{data:a,status:r}}),Ou=Y("PROVINCE_GET_ALL_STEWARDS_SERVICE",async(t,{dispatch:d})=>{try{d(k());const{data:a,status:r}=await w.get("stewards-for-cold-house/",{});return d(S()),{data:a,status:r}}catch(a){return d(S()),{error:a.response.data.result}}}),Ru=Y("PROVINCE_CREATE_COLD_HOUSE_SERVICE",async(t,{dispatch:d})=>{try{d(k());const{data:a,status:r}=await w.post("cold-house/",t);return d(S()),{data:a,status:r}}catch(a){return d(S()),{error:a.response.data.result}}}),$u=Y("PROVINCE_EDIT_COLD_HOUSE_SERVICE",async(t,{dispatch:d})=>{try{d(k());const{data:a,status:r}=await w.put("cold-house/0/",t);return d(S()),{data:a,status:r}}catch(a){return d(S()),{error:a.response.data.result}}}),su=({isEdit:t,updateTable:d,item:a,stewardKey:r,killhouseKey:p})=>{const C=N(),[y,g]=l.useState([]),x=pu({name:W().required("این فیلد اجباریست!"),address:W().required("این فیلد اجباریست!"),steward_key:W(),province:W().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),city:W().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),active:eu(),broadcast:eu(),relocate:eu()}),[f,_]=l.useState([]),[A,v]=l.useState([]),[F]=l.useContext(cu);l.useEffect(()=>{!t&&!r&&C(Ou()).then(s=>{g(s.payload.data)})},[]);const o=gu({initialValues:{name:t?a==null?void 0:a.name:"",address:t?a==null?void 0:a.address:"",steward_key:"",province:t?a==null?void 0:a.province:"",city:t?a==null?void 0:a.city:"",active:t?a==null?void 0:a.active:!1,broadcast:t?a==null?void 0:a.broadcast:!1,relocate:t?a==null?void 0:a.relocate:!1},validationSchema:x,onSubmit:s=>{if(t)C($u({cold_house_key:a==null?void 0:a.key,name:s.name,province:s.province,city:s.city,address:s.address,active:s.active,broadcast:s.broadcast,relocate:s.relocate})).then(i=>{i.payload.error?F({vertical:"top",horizontal:"center",msg:i.payload.error,severity:"error"}):(C(M({right:!1,bottom:!1,content:null})),d(),F({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))});else{let i={steward_key:p?null:r||s.steward_key,kill_house_key:p,name:s.name,province:s.province,city:s.city,address:s.address,active:s.active,broadcast:s.broadcast,relocate:s.relocate};i=Object.fromEntries(Object.entries(i).filter(([b,$])=>$!==null)),C(Ru(i)).then(b=>{b.payload.error?F({vertical:"top",horizontal:"center",msg:b.payload.error,severity:"error"}):(C(M({right:!1,bottom:!1,content:null})),d(),F({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})}}});return l.useEffect(()=>{o.validateForm()},[]),l.useEffect(()=>{C(_u()).then(s=>{_(s.payload.data)})},[]),l.useEffect(()=>{o.values.province&&v([],C(bu(o.values.province)).then(s=>{v(s.payload.data)}))},[o.values.province]),u.jsxs(D,{xs:12,container:!0,justifyContent:"center",alignItems:"center",gap:2,children:[!t&&!r&&u.jsx(D,{item:!0,xs:12,children:u.jsx(Z,{style:{width:"100%"},options:y?y.map(s=>({id:s.key,label:`${s.fullname} / ${s.mobile} `,item:s})):[],value:o.values.guild,onChange:(s,i)=>{o.setFieldValue("steward_key",i==null?void 0:i.id),o.validateForm()},error:o.touched.guild&&!!o.errors.guild,helperText:o.touched.guild&&o.errors.guild,getOptionLabel:s=>s.label,renderInput:s=>u.jsx(R,{...s,label:"انتخاب مباشر",variant:"outlined"})})}),u.jsx(D,{item:!0,xs:12,children:u.jsx(R,{fullWidth:!0,id:"name",name:"name",label:"نام سردخانه",value:o.values.name,onChange:o.handleChange,onBlur:o.handleBlur,error:o.touched.name&&!!o.errors.name,helperText:o.touched.name&&o.errors.name})}),u.jsx(Z,{style:{width:"100%"},disablePortal:!0,id:"province",options:f?f.map(s=>({id:s.name,label:s.name})):[],onChange:(s,i)=>{o.setFieldValue("province",i?i.id:""),o.setFieldValue("city","")},renderInput:s=>u.jsx(R,{...s,label:"استان را انتخاب کنید"})}),t&&u.jsxs(tu,{variant:"caption",color:"error",children:["استان: ",o.values.province]}),u.jsx(Z,{minWidth:210,style:{width:"100%"},disabled:!o.values.province,disablePortal:!0,id:"city",options:A?A.map(s=>({id:s.name,label:s.name})):[],onChange:(s,i)=>{o.setFieldValue("city",i?i.id:"")},renderInput:s=>u.jsx(R,{...s,label:"شهر را انتخاب کنید"})}),t&&u.jsxs(tu,{variant:"caption",color:"error",children:["شهر: ",o.values.city]}),u.jsx(D,{item:!0,xs:12,children:u.jsx(R,{fullWidth:!0,id:"address",name:"address",label:"آدرس",value:o.values.address,onChange:o.handleChange,onBlur:o.handleBlur,error:o.touched.address&&!!o.errors.address,helperText:o.touched.address&&o.errors.address})}),u.jsxs(D,{item:!0,xs:12,container:!0,direction:"column",children:[u.jsx(m,{control:u.jsx(uu,{checked:o.values.active,onChange:o.handleChange,name:"active"}),label:"فعال"}),u.jsx(m,{control:u.jsx(uu,{checked:o.values.broadcast,onChange:o.handleChange,name:"broadcast"}),label:"اجازه پخش"}),u.jsx(m,{control:u.jsx(uu,{checked:o.values.relocate,onChange:o.handleChange,name:"relocate"}),label:"اجازه جابجایی"})]}),u.jsx(D,{item:!0,xs:12,children:u.jsx(H,{disabled:t||r?!o.isValid:!o.isValid&&!o.values.steward_key,fullWidth:!0,type:"submit",variant:"contained",color:"primary",onClick:o.handleSubmit,children:"ثبت"})})]})},Tu=()=>{const t=N(),d=ru(),a=c=>{_(c.target.value)},[r,p]=l.useState([]),[C,y]=l.useState(0),[g,x]=l.useState(10),[f,_]=l.useState(""),[A,v]=l.useState(1),[F,o]=l.useState([]),s=async c=>{let e;t(k()),e=await w.get(`stewards-for-cold-house/?search=filter&value=${f}&role=${E()}&page=${c}&page_size=${g}&total=true`),t(S()),p(e.data.results),y(e.data.count)},i=c=>{s(c),v(c)},b=c=>{x(c),v(1)},$=()=>{s(A!==0?A:1)};l.useEffect(()=>{const c=r==null?void 0:r.map((e,h)=>{var n,L,I,P,O,V,z,U;return[A===1?h+1:h+g*(A-1)+1,e==null?void 0:e.fullname,e==null?void 0:e.mobile,e==null?void 0:e.city,(L=(n=e==null?void 0:e.coldHousesInfo)==null?void 0:n.totalColdHouses)==null?void 0:L.toLocaleString(),(P=(I=e==null?void 0:e.coldHousesInfo)==null?void 0:I.totalInputWeight)==null?void 0:P.toLocaleString(),(V=(O=e==null?void 0:e.coldHousesInfo)==null?void 0:O.totalAllocatedWeight)==null?void 0:V.toLocaleString(),(U=(z=e==null?void 0:e.coldHousesInfo)==null?void 0:z.totalRemainWeight)==null?void 0:U.toLocaleString(),u.jsx(X,{placement:"left",title:"نمایش",children:u.jsx(q,{color:"primary",size:"small",onClick:()=>{d((E()==="ProvinceOperator"?B:E()==="AdminX"?K:J)+"/"+(e==null?void 0:e.key)+"/"+(e==null?void 0:e.fullname)+"/steward")},children:u.jsx(xu,{})})},h)]});o(c)},[r]),l.useEffect(()=>{s(1)},[t,g]);const T=async c=>{c.preventDefault(),t(k());try{const e=await w.get(`stewards-for-cold-house/?role=${E()}&search=filter&value=${f}&page=1&page_size=${g}&total=true`);p(e.data.results),y(e.data.count),t(S())}catch(e){console.error("Error fetching data:",e)}};return u.jsxs(j,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsxs(j,{container:!0,xs:12,justifyContent:"start",alignItems:"center",gap:2,children:[u.jsx(H,{variant:"contained",onClick:()=>{t(M({right:!0,title:"ایجاد سردخانه",content:u.jsx(su,{updateTable:$})}))},children:"ایجاد سردخانه"}),u.jsx(j,{children:u.jsxs("form",{onSubmit:T,children:[u.jsx(R,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:a}),u.jsx(H,{type:"submit",onClick:T,endIcon:u.jsx(au,{}),children:"جستجو"})]})})]}),u.jsx(Q,{data:F,columns:["ردیف","نام مالک","موبایل","شهر","تعداد سردخانه ها","وزن وارد شده","وزن خارج شده","وزن باقیمانده","سردخانه ها"],handlePageChange:i,totalRows:C,page:A,perPage:g,handlePerRowsChange:b,title:"مباشرین"})]})},Hu=()=>{var y,g,x,f,_,A;const[t,d]=l.useState(0),a=(v,F)=>{d(F)},[r,p]=l.useState([]),C=N();return l.useEffect(()=>{C(Pu()).then(v=>{p(v.payload.data)})},[C]),u.jsxs(j,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsx(Q,{isDashboard:!0,noPagination:!0,columns:["تعداد کل سردخانه ها","تعداد کل سردخانه های کشتارگاه ها","تعداد کل سردخانه های مباشرین","کل وزن وارد شده","کل وزن خارج شده","کل وزن باقیمانده"],data:[[(y=r==null?void 0:r.totalColdHouses)==null?void 0:y.toLocaleString(),(g=r==null?void 0:r.totalKillHouseColdHouse)==null?void 0:g.toLocaleString(),(x=r==null?void 0:r.totalStewardColdHouse)==null?void 0:x.toLocaleString(),(f=r==null?void 0:r.totalInputWeight)==null?void 0:f.toLocaleString(),(_=r==null?void 0:r.totalAllocatedWeight)==null?void 0:_.toLocaleString(),(A=r==null?void 0:r.totalRemainWeight)==null?void 0:A.toLocaleString()]],title:"خلاصه اطلاعات"}),u.jsx(j,{xs:12,container:!0,alignItems:"center",justifyContent:"center",mt:2,children:u.jsxs(du,{scrollButtons:"auto",variant:"scrollable",allowScrollButtonsMobile:!0,value:t,onChange:a,children:[u.jsx(ou,{label:"سردخانه های کشتارگاه ها",value:0}),u.jsx(ou,{label:"سردخانه های مباشرین",value:1})]})}),t===0&&u.jsx(Iu,{}),t===1&&u.jsx(Tu,{})]})},Du=({item:t,updateTable:d})=>{const[a,r]=l.useState(null),p=N(),C=f=>{r(f.currentTarget)},y=()=>{r(null)},g=!!a,x=g?"popover":void 0;return u.jsxs("div",{children:[u.jsx(q,{"aria-describedby":x,variant:"contained",color:"primary",onClick:C,children:u.jsx(ku,{})}),u.jsx(iu,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:x,open:g,anchorEl:a,onClose:y,children:u.jsx("div",{style:{padding:"20px"},children:u.jsx(j,{container:!0,direction:"column",children:u.jsx(X,{placement:"left",title:"ویرایش سردخانه",children:u.jsx(q,{color:"primary",onClick:()=>{y(),p(M({title:"ویرایش سردخانه",right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(su,{isEdit:!0,item:t,updateTable:d})}))},children:u.jsx(wu,{})})})})})})]})},Nu=()=>{const t=N(),d=h=>{v(h.target.value)},{key:a,name:r,type:p}=lu(),[C,y]=l.useState([]),[g,x]=l.useState(0),[f,_]=l.useState(10),[A,v]=l.useState(""),[F,o]=l.useState(1),[s,i]=l.useState([]),b=async h=>{let n;t(k()),n=await w.get(`cold-house-for-province/?search=filter&value=${A}&role=${E()}&page=${h}&page_size=${f}${p==="steward"?`&type=Steward&steward_key=${a}`:""}${p==="killhouse"?`&type=KillHouse&kill_house_key=${a}`:""}`),t(S()),y(n.data.results),x(n.data.count)},$=h=>{b(h),o(h)},T=h=>{_(h),o(1)},c=()=>{b(F!==0?F:1)};l.useEffect(()=>{const h=C==null?void 0:C.map((n,L)=>{var I,P,O;return[F===1?L+1:L+f*(F-1)+1,n==null?void 0:n.name,n==null?void 0:n.city,n==null?void 0:n.address,(I=n==null?void 0:n.totalInputWeight)==null?void 0:I.toLocaleString(),(P=n==null?void 0:n.totalAllocatedWeight)==null?void 0:P.toLocaleString(),(O=n==null?void 0:n.totalRemainWeight)==null?void 0:O.toLocaleString(),n!=null&&n.active?"فعال":"غیر فعال",n!=null&&n.broadcast?"دارد":"ندارد",n!=null&&n.relocate?"دارد":"ندارد",n==null?void 0:n.capacity,u.jsx(Du,{item:n,updateTable:c},L)]});i(h)},[C]),l.useEffect(()=>{b(1)},[t,f]);const e=async h=>{h.preventDefault(),t(k());try{const n=await w.get(`cold-house-for-province/?role=${E()}&search=filter&value=${A}&page=1&page_size=${f}${p==="steward"?`&type=Steward&steward_key=${a}`:""}${p==="killhouse"?`&type=KillHouse&kill_house_key=${a}`:""}`);y(n.data.results),x(n.data.count),t(S())}catch(n){console.error("Error fetching data:",n)}};return u.jsxs(j,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsxs(j,{container:!0,xs:12,justifyContent:"start",alignItems:"center",gap:2,children:[u.jsx(H,{variant:"contained",onClick:()=>{t(M({right:!0,title:"افزودن سردخانه",content:u.jsx(su,{updateTable:c,stewardKey:a,killhouseKey:a})}))},children:"افزودن سردخانه"}),u.jsx(j,{children:u.jsxs("form",{onSubmit:e,children:[u.jsx(R,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:d}),u.jsx(H,{type:"submit",onClick:e,endIcon:u.jsx(au,{}),children:"جستجو"})]})})]}),u.jsx(Q,{data:s,columns:["ردیف","نام سردخانه","شهر","آدرس","وزن کل","وزن خارج شده","وزن باقیمانده","وضعیت","اجازه پخش","اجازه جابجایی","ظرفیت","عملیات"],handlePageChange:$,totalRows:g,page:F,perPage:f,handlePerRowsChange:T,title:`مشاهده سردخانه های ${r}`})]})},e6=()=>{const{pathname:t}=nu(),{key:d}=lu();return u.jsx(u.Fragment,{children:u.jsx(Cu,{display:"flex",justifyContent:"center",children:u.jsxs(j,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[t===fu||t===ju||t===Fu?u.jsxs(j,{justifyContent:"center",my:G.MEDIUM,children:[u.jsx(j,{children:u.jsx(tu,{variant:"h6",children:"داشبورد مدیریت سردخانه ها "})}),u.jsx(Lu,{})]}):u.jsx(yu,{}),(t===B||t===K||t===J)&&u.jsx(Hu,{}),d&&u.jsx(Nu,{})]})})})};export{e6 as default};
|