2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import{j as u,I as X,b0 as Cu,d as hu,B as v,bh as du,al as Q,ak as T,a9 as pu,T as y,b as gu}from"./mui-vendor-CkIVaoQP.js";import{G as i,S as q,ho as eu,hp as ru,hq as au,hr as tu,X as d,hs as su,ht as nu,hu as ou,hv as cu,L as b,j as L,h as _,A as lu,O as Au,C as J,fn as Eu,c as xu,M as w,b as yu,u as _u,N as iu,_ as ju,hw as Ru,hx as Su,hy as Iu,hz as Lu}from"./index-CeyyVc1v.js";import{N as Z}from"./NavLink-D2GD_ItM.js";import{L as uu}from"./LinkItem-DT6qswcs.js";import{m as fu}from"./index.esm-CjWvmHks.js";import{a as Fu}from"./index.esm-fCjAhNPc.js";import{P as Tu}from"./ProvinceBarDifference-CBv5I_nz.js";import{B as vu}from"./BackButton-Crzr7NMa.js";import{r as h,f as bu}from"./react-vendor-CmFgShSM.js";import{a as U,u as B,f as Du}from"./redux-vendor-B7uoacJt.js";import{R as Nu}from"./index.esm-Bu7XMDZU.js";import{R as ku}from"./ResponsiveTable-w7hk7Uq8.js";import{d as Ou}from"./Tune-D4M2CAhp.js";import{d as Hu}from"./Delete-C5MyLelE.js";import{b as qu}from"./aviculture-get-hatching-data-DsjDNd82.js";import"./iconBase-BEJYyZsk.js";import"./toBase64-BzgTOHsW.js";import"./PublishedWithChanges-C8kvr_m4.js";import"./resizeImage-Csf2MO3w.js";import"./Edit-CqBj1Y2L.js";import"./ShowImage-CqhU2hmk.js";import"./Download-DQ-VVIaV.js";import"./Close-_jAEIgMD.js";import"./FilterAlt-scT0HEUg.js";import"./styled-components.browser.esm-gS9mh05b.js";const Uu=()=>u.jsxs(i,{container:!0,gap:q.SMALL,p:q.SMALL,direction:{xs:"row",md:"row"},justifyContent:"center",children:[u.jsx(Z,{to:d()==="AdminX"?eu:d()==="SuperAdmin"?ru:d()==="ProvinceOperator"?au:d()==="CityOperator"?tu:"",children:u.jsx(uu,{icon:u.jsx(fu,{size:30,color:"#244CCC"}),title:"اختلاف کشتار در کشتارگاه"})}),u.jsx(Z,{to:d()==="AdminX"?su:d()==="SuperAdmin"?nu:d()==="ProvinceOperator"?ou:d()==="CityOperator"?cu:"",children:u.jsx(uu,{icon:u.jsx(Fu,{size:30,color:"#244CCC"}),title:"افزایش حجم جوجه ریزی"})})]}),wu=U("CITY_INCREASE_HATCHING_SERVICE",async(n,{dispatch:o})=>{try{o(b());const{data:a,status:l}=await L.post("hatching-increase-request/",n);return o(_()),{data:a,status:l}}catch(a){return o(_()),{error:a.response.data.result}}}),Bu=U("CITY_EDIT_INCREASE_HATCHING_SERVICE",async(n,{dispatch:o})=>{try{o(b());const{data:a,status:l}=await L.put("hatching-increase-request/0/",n);return o(_()),{data:a,status:l}}catch(a){return o(_()),{error:a.response.data.result}}}),Gu=U("CITY_DELETE_INCREASE_HATCHING_SERVICE",async(n,{dispatch:o})=>{o(b());try{const{data:a,status:l}=await L.delete(`/hatching-increase-request/0/?key=${n}`);return o(_()),{data:a,status:l}}catch(a){return o(_()),{error:a.response.data.result}}});U("CITY_INCREASE_GET_HATCHING_SERVICE",async n=>{const{data:o,status:a}=await L.get("hatching-increase-request/",{params:n});return{data:o,status:a}});const $u=({item:n,updateTable:o})=>{const a=B(),[l,j]=h.useState(null),[s]=h.useContext(lu),S=E=>{j(E.currentTarget)},p=()=>{j(null)},g=!!l,A=g?"popover":void 0;return u.jsxs("div",{children:[u.jsx(X,{"aria-describedby":A,variant:"contained",color:"primary",onClick:S,children:u.jsx(Ou,{})}),u.jsx(Cu,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:A,open:g,anchorEl:l,onClose:p,children:u.jsx("div",{style:{padding:"20px"},children:u.jsx(i,{container:!0,direction:"column",children:u.jsx(hu,{title:"حذف",placement:"left-start",children:u.jsx(X,{"aria-label":"delete",color:"error",onClick:()=>{p(),a(Au({title:"آیا مطمئن هستید؟",content:u.jsxs(i,{container:!0,spacing:2,children:[u.jsx(i,{item:!0,children:u.jsx(v,{variant:"contained",color:"error",onClick:()=>{a(Gu(n==null?void 0:n.key)).then(E=>{E.payload.error?s({vertical:"top",horizontal:"center",msg:E.payload.error,severity:"error"}):(o(),a(J()),s({vertical:"top",horizontal:"center",msg:E.payload.data.result,severity:"success"}))})},children:"تایید"})}),u.jsx(i,{item:!0,children:u.jsx(v,{onClick:()=>{a(J())},children:"لغو"})})]})}))},children:u.jsx(Hu,{})})})})})})]})},Mu=({updateTable:n,isEdit:o,item:a})=>{var D,N,I,k,O,f,F,C,e;const[l,j]=h.useState([]),[s,S]=h.useState(null),[p]=h.useContext(lu),g=B(),{slaughterGetPoultries:A}=Du(t=>t.slaughterSlice);h.useEffect(()=>{g(Eu())},[]);const E={poultry:(a==null?void 0:a.poultrykey)||null,hatching_key:(a==null?void 0:a.hatchingkey)||null,quantity:(a==null?void 0:a.quantity)||null,message:(a==null?void 0:a.message)||null},R=xu().shape({poultry:w().required("انتخاب مرغدار الزامی است"),hatching_key:w().required("انتخاب محل پرورش الزامی است"),quantity:yu().typeError("عدد وارد کنید").required("حجم الزامی است"),message:w().typeError("پر کردن این فیلد الزامی است").required("پیام الزامی است")}),r=_u({initialValues:E,validationSchema:R});return h.useEffect(()=>{r.values.poultry&&g(qu(r.values.poultry,{increase:!0})).then(t=>{j(t.payload.data||[])})},[r.values.poultry]),u.jsxs(du,{spacing:2,children:[u.jsx(Q,{id:"poultry",disableClearable:!0,options:A==null?void 0:A.map(t=>{var c,x;return{label:`${t.unitName} (${(c=t.user)==null?void 0:c.fullname})(${(x=t.user)==null?void 0:x.mobile})`,value:t.key}}),getOptionLabel:t=>t.label,onChange:(t,c)=>{r.setFieldValue("poultry",c.value),r.setFieldValue("hatching_key",null)},renderInput:t=>u.jsx(T,{...t,label:"انتخاب مرغدار",error:r.touched.poultry&&!!r.errors.poultry,helperText:r.touched.poultry&&r.errors.poultry})}),u.jsx(Q,{id:"hatching_key",disableClearable:!0,disabled:!r.values.poultry,options:l==null?void 0:l.map(t=>{var c;return{label:((c=t==null?void 0:t.poultry)==null?void 0:c.unitName)||"-",value:t==null?void 0:t.key}}),getOptionLabel:t=>t.label,onChange:(t,c)=>{r.setFieldValue("hatching_key",c==null?void 0:c.value);const x=l.find(H=>H.key===(c==null?void 0:c.value));S(x)},renderInput:t=>u.jsx(T,{...t,label:"انتخاب محل پرورش",error:r.touched.hatching_key&&!!r.errors.hatching_key,helperText:r.touched.hatching_key&&r.errors.hatching_key})}),s&&u.jsxs(pu,{variant:"outlined",sx:{p:2,borderRadius:2},children:[u.jsxs(y,{children:["شماره مجوز جوجه ریزی:"," ",(D=s==null?void 0:s.licenceNumber)==null?void 0:D.toLocaleString()]}),u.jsxs(y,{children:["شناسه یکتا مرغدار :"," ",(I=(N=s==null?void 0:s.poultry)==null?void 0:N.breedingUniqueId)==null?void 0:I.toLocaleString()]}),u.jsxs(y,{children:["حجم جوجه ریزی:",(k=s==null?void 0:s.quantity)==null?void 0:k.toLocaleString(),"قطعه"]}),u.jsxs(y,{children:["سن جوجه: ",(O=s==null?void 0:s.chickenAge)==null?void 0:O.toLocaleString()," روز"]}),u.jsxs(y,{children:["مانده در سالن: ",(f=s==null?void 0:s.leftOver)==null?void 0:f.toLocaleString(),"قطعه"]}),u.jsxs(y,{children:["حجم کشتار شده:",(F=s==null?void 0:s.killedQuantity)==null?void 0:F.toLocaleString()," قطعه"]}),u.jsxs(y,{children:["نژاد: ",(C=s==null?void 0:s.chickenBreed)==null?void 0:C.toLocaleString()]}),u.jsxs(y,{children:["تلفات: ",(e=s==null?void 0:s.totalLosses)==null?void 0:e.toLocaleString("fa-IR"),"قطعه"]})]}),u.jsx(T,{label:"تعداد (قطعه)",name:"quantity",value:r.values.quantity,onChange:r.handleChange,onBlur:r.handleBlur,error:r.touched.quantity&&!!r.errors.quantity,helperText:r.touched.quantity&&r.errors.quantity,fullWidth:!0}),u.jsx(T,{label:"دلیل افزایش حجم",name:"message",multiline:!0,rows:3,value:r.values.message,onChange:r.handleChange,onBlur:r.handleBlur,error:r.touched.message&&!!r.errors.message,helperText:r.touched.message&&r.errors.message,fullWidth:!0}),u.jsx(v,{variant:"contained",fullWidth:!0,disabled:!(r.isValid&&r.values.poultry&&r.values.hatching_key&&r.values.quantity&&r.values.message),onClick:()=>{const t={hatching_key:r.values.hatching_key,quantity:parseInt(r.values.quantity),message:r.values.message,registerer_role:d()},c=o?Bu({...t,key:a==null?void 0:a.key}):wu(t);g(c).then(x=>{x.payload.error?p({msg:"مشکلی پیش آمده است!",severity:"error",vertical:"top",horizontal:"center"}):(p({msg:"عملیات با موفقیت انجام شد.",severity:"success",vertical:"top",horizontal:"center"}),n(),g(iu({right:!1,bottom:!1,content:null})))})},children:o?"ویرایش":"ثبت"})]})},Vu=({state:n})=>{const o=B(),a=C=>{E(C.target.value)},[l,j]=h.useState([]),[s,S]=h.useState(0),[p,g]=h.useState(10),[A,E]=h.useState(""),[R,r]=h.useState(1),[D,N]=h.useState([]),I=async C=>{let e;o(b()),e=await L.get(`hatching-increase-request/?search=filter&value=${A}&role=${d()}&page=${C}&page_size=${p}`),o(_()),j(e.data.results),S(e.data.count)},k=C=>{I(C),r(C)},O=C=>{g(C),r(1)},f=()=>{I(R!==0?R:1)};h.useEffect(()=>{const C=l==null?void 0:l.map((e,t)=>{var c,x,H,G,$,M,V,m,z,K,P,W,Y;return[R===1?t+1:t+p*(R-1)+1,`${(x=(c=e==null?void 0:e.hatching)==null?void 0:c.poultry)==null?void 0:x.unitName} (${($=(G=(H=e==null?void 0:e.hatching)==null?void 0:H.poultry)==null?void 0:G.user)==null?void 0:$.mobile})`,(M=e==null?void 0:e.hatching)==null?void 0:M.licenceNumber,(m=(V=e==null?void 0:e.hatching)==null?void 0:V.poultry)==null?void 0:m.breedingUniqueId,(z=e==null?void 0:e.hatchingQuantity)==null?void 0:z.toLocaleString(),(K=e==null?void 0:e.hatchingKillQuantity)==null?void 0:K.toLocaleString(),(P=e==null?void 0:e.hatchingLosses)==null?void 0:P.toLocaleString(),(W=e==null?void 0:e.hatchingLeftOver)==null?void 0:W.toLocaleString(),(Y=e==null?void 0:e.quantity)==null?void 0:Y.toLocaleString(),`${e==null?void 0:e.registererName} (${e==null?void 0:e.registererMobile})`,ju(e==null?void 0:e.date),e==null?void 0:e.message,u.jsx($u,{updateTable:f,item:e},t)]});N(C)},[l,n]),h.useEffect(()=>{I(1)},[o,p,n]);const F=async C=>{C.preventDefault(),o(b());try{const e=await L.get(`hatching-increase-request/?role=${d()}&search=filter&value=${A}&page=1&page_size=${p}`);j(e.data.results),S(e.data.count),o(_())}catch(e){console.error("Error fetching data:",e)}};return u.jsxs(i,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[u.jsxs(i,{container:!0,xs:12,justifyContent:"start",alignItems:"center",gap:2,children:[d()!=="KillHouse"&&u.jsx(i,{children:u.jsx(v,{variant:"contained",onClick:()=>{o(iu({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(Mu,{updateTable:f}),title:"افزایش جوجه ریزی"}))},children:"افزایش جوجه ریزی"})}),u.jsx(i,{children:u.jsxs("form",{onSubmit:F,children:[u.jsx(T,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:a}),u.jsx(v,{type:"submit",onClick:F,endIcon:u.jsx(Nu,{}),children:"جستجو"})]})})]}),u.jsx(ku,{data:D,columns:["ردیف","مرغدار","شماره مجوز جوجه ریزی","شناسه یکتا فارم","حجم جوجه ریزی","حجم کشتار","حجم تلفات","مانده در سالن","حجم افزایشی","ثبت کننده","تاریخ ثبت","پیغام","عملیات"],handlePageChange:k,totalRows:s,page:R,perPage:p,handlePerRowsChange:O,title:"افزایش حجم جوجه ریزی"})]})},g6=()=>{const{pathname:n}=bu();return u.jsx(u.Fragment,{children:u.jsxs(gu,{display:"flex",justifyContent:"center",mt:4,xs:12,children:[u.jsxs(i,{container:!0,direction:"column",xs:12,sm:12,md:10,lg:10,children:[u.jsx(i,{container:!0,justifyContent:"space-between",gap:q.SMALL,children:u.jsx(i,{xs:12,children:n===Ru||n===Su||n===Iu||n===Lu?u.jsxs(u.Fragment,{children:[" ",u.jsx(i,{item:!0,xs:12,mb:2,children:u.jsx(y,{variant:"h5",fontWeight:"bold",textAlign:"center",children:"اختلاف کشتار"})}),u.jsx(Uu,{})]}):u.jsx(vu,{})})}),u.jsxs(i,{xs:12,sm:12,px:2,children:[(n.includes(eu)||n.includes(ru)||n.includes(au)||n.includes(tu))&&u.jsx(Tu,{}),(n.includes(ou)||n.includes(su)||n.includes(cu)||n.includes(nu))&&u.jsx(Vu,{})]})]}),u.jsx(i,{container:!0,justifyContent:"space-between",gap:q.SMALL,children:u.jsx(i,{xs:12})})]})})};export{g6 as default};
|