2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import{j as u,I as X,b3 as hu,d as du,B as v,bj as pu,ao as Q,an as F,ab as gu,T as y,b as Eu}from"./mui-vendor-D_SVL-Dx.js";import{G as i,S as q,hR as ru,hS as au,hT as tu,hU as su,a0 as d,hV as nu,hW as ou,hX as cu,hY as lu,L as D,j as L,h as _,A as iu,O as Au,C as Z,fI as xu,c as yu,V as B,b as _u,u as ju,W as Cu,a3 as Ru,hZ as Su,h_ as Iu,h$ as Lu,i0 as fu}from"./index-D80MdVQn.js";import{N as J}from"./NavLink-Uri4Pz8C.js";import{L as uu}from"./LinkItem-Din4toX7.js";import{m as Tu}from"./index.esm-DYumyMPq.js";import{a as Fu}from"./index.esm-D7rRcI8K.js";import{P as vu}from"./ProvinceBarDifference-BXZCyzMP.js";import{B as eu}from"./BackButton-Dr-K0JXJ.js";import{r as h,f as Du}from"./react-vendor-CmFgShSM.js";import{a as U,u as $,f as bu}from"./redux-vendor-CfkcHgWN.js";import{R as Nu}from"./index.esm-C1-dCPnj.js";import{R as ku}from"./ResponsiveTable-bUYl0qDM.js";import{d as Ou}from"./Tune-BBzxV8DK.js";import{d as Hu}from"./Delete-CIwpNviU.js";import{b as qu}from"./aviculture-get-hatching-data-BHS_PijM.js";import"./toBase64-UDzdrM-n.js";import"./PublishedWithChanges-Dz7dEVRv.js";import"./resizeImage-Csf2MO3w.js";import"./checkPathStartsWith-DedybDvj.js";import"./ShowImage-DxnwAx1k.js";import"./Download-CJYPO5Fu.js";import"./Close-J1gH5PMD.js";import"./FilterAlt-DZsHj-WQ.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(J,{to:d()==="AdminX"?ru:d()==="SuperAdmin"?au:d()==="ProvinceOperator"?tu:d()==="CityOperator"?su:"",children:u.jsx(uu,{icon:u.jsx(Tu,{size:30,color:"#244CCC"}),title:"اختلاف کشتار در کشتارگاه"})}),u.jsx(J,{to:d()==="AdminX"?nu:d()==="SuperAdmin"?ou:d()==="ProvinceOperator"?cu:d()==="CityOperator"?lu:"",children:u.jsx(uu,{icon:u.jsx(Fu,{size:30,color:"#244CCC"}),title:"افزایش حجم جوجه ریزی"})})]}),Bu=U("CITY_INCREASE_HATCHING_SERVICE",async(n,{dispatch:o})=>{try{o(D());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}}}),$u=U("CITY_EDIT_INCREASE_HATCHING_SERVICE",async(n,{dispatch:o})=>{try{o(D());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}}}),wu=U("CITY_DELETE_INCREASE_HATCHING_SERVICE",async(n,{dispatch:o})=>{o(D());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 Gu=({item:n,updateTable:o})=>{const a=$(),[l,j]=h.useState(null),[s]=h.useContext(iu),S=A=>{j(A.currentTarget)},p=()=>{j(null)},g=!!l,E=g?"popover":void 0;return u.jsxs("div",{children:[u.jsx(X,{"aria-describedby":E,variant:"contained",color:"primary",onClick:S,children:u.jsx(Ou,{})}),u.jsx(hu,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:E,open:g,anchorEl:l,onClose:p,children:u.jsx("div",{style:{padding:"20px"},children:u.jsx(i,{container:!0,direction:"column",children:u.jsx(du,{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(wu(n==null?void 0:n.key)).then(A=>{A.payload.error?s({vertical:"top",horizontal:"center",msg:A.payload.error,severity:"error"}):(o(),a(Z()),s({vertical:"top",horizontal:"center",msg:A.payload.data.result,severity:"success"}))})},children:"تایید"})}),u.jsx(i,{item:!0,children:u.jsx(v,{onClick:()=>{a(Z())},children:"لغو"})})]})}))},children:u.jsx(Hu,{})})})})})})]})},Vu=({updateTable:n,isEdit:o,item:a})=>{var b,N,I,k,O,f,T,C,e;const[l,j]=h.useState([]),[s,S]=h.useState(null),[p]=h.useContext(iu),g=$(),{slaughterGetPoultries:E}=bu(t=>t.slaughterSlice);h.useEffect(()=>{g(xu())},[]);const A={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=yu().shape({poultry:B().required("انتخاب مرغدار الزامی است"),hatching_key:B().required("انتخاب محل پرورش الزامی است"),quantity:_u().typeError("عدد وارد کنید").required("حجم الزامی است"),message:B().typeError("پر کردن این فیلد الزامی است").required("پیام الزامی است")}),r=ju({initialValues:A,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(pu,{spacing:2,children:[u.jsx(Q,{id:"poultry",disableClearable:!0,options:E==null?void 0:E.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(F,{...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(F,{...t,label:"انتخاب محل پرورش",error:r.touched.hatching_key&&!!r.errors.hatching_key,helperText:r.touched.hatching_key&&r.errors.hatching_key})}),s&&u.jsxs(gu,{variant:"outlined",sx:{p:2,borderRadius:2},children:[u.jsxs(y,{children:["شماره مجوز جوجه ریزی:"," ",(b=s==null?void 0:s.licenceNumber)==null?void 0:b.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:["حجم کشتار شده:",(T=s==null?void 0:s.killedQuantity)==null?void 0:T.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(F,{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(F,{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?$u({...t,key:a==null?void 0:a.key}):Bu(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(Cu({right:!1,bottom:!1,content:null})))})},children:o?"ویرایش":"ثبت"})]})},Mu=({state:n})=>{const o=$(),a=C=>{A(C.target.value)},[l,j]=h.useState([]),[s,S]=h.useState(0),[p,g]=h.useState(10),[E,A]=h.useState(""),[R,r]=h.useState(1),[b,N]=h.useState([]),I=async C=>{o(D());const e=await L.get(`hatching-increase-request/?search=filter&value=${E}&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,w,G,V,M,K,z,m,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=(w=(H=e==null?void 0:e.hatching)==null?void 0:H.poultry)==null?void 0:w.user)==null?void 0:G.mobile})`,(V=e==null?void 0:e.hatching)==null?void 0:V.licenceNumber,(K=(M=e==null?void 0:e.hatching)==null?void 0:M.poultry)==null?void 0:K.breedingUniqueId,(z=e==null?void 0:e.hatchingQuantity)==null?void 0:z.toLocaleString(),(m=e==null?void 0:e.hatchingKillQuantity)==null?void 0:m.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})`,Ru(e==null?void 0:e.date),e==null?void 0:e.message,u.jsx(Gu,{updateTable:f,item:e},t)]});N(C)},[l,n]),h.useEffect(()=>{I(1)},[o,p,n]);const T=async C=>{C.preventDefault(),o(D());try{const e=await L.get(`hatching-increase-request/?role=${d()}&search=filter&value=${E}&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(Cu({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(Vu,{updateTable:f}),title:"افزایش جوجه ریزی"}))},children:"افزایش جوجه ریزی"})}),u.jsx(i,{children:u.jsxs("form",{onSubmit:T,children:[u.jsx(F,{id:"outlined-basic",size:"small",label:"جستجو",variant:"outlined",style:{width:250},onChange:a}),u.jsx(v,{type:"submit",onClick:T,endIcon:u.jsx(Nu,{}),children:"جستجو"})]})})]}),u.jsx(ku,{data:b,columns:["ردیف","مرغدار","شماره مجوز جوجه ریزی","شناسه یکتا فارم","حجم جوجه ریزی","حجم کشتار","حجم تلفات","مانده در سالن","حجم افزایشی","ثبت کننده","تاریخ ثبت","پیغام","عملیات"],handlePageChange:k,totalRows:s,page:R,perPage:p,handlePerRowsChange:O,title:"افزایش حجم جوجه ریزی"})]})},p6=()=>{const{pathname:n}=Du();return u.jsx(u.Fragment,{children:u.jsxs(Eu,{display:"flex",justifyContent:"center",xs:12,children:[u.jsxs(i,{container:!0,xs:12,md:10,children:[u.jsx(i,{container:!0,xs:12,gap:q.SMALL,children:u.jsx(i,{xs:12,justifyContent:"center",children:n===Su||n===Iu||n===Lu||n===fu?u.jsxs(u.Fragment,{children:[" ",u.jsx(i,{item:!0,xs:12,mb:2,justifyContent:"center",children:u.jsx(eu,{})}),u.jsx(Uu,{})]}):u.jsx(eu,{})})}),u.jsxs(i,{xs:12,sm:12,children:[(n.includes(ru)||n.includes(au)||n.includes(tu)||n.includes(su))&&u.jsx(vu,{}),(n.includes(cu)||n.includes(nu)||n.includes(lu)||n.includes(ou))&&u.jsx(Mu,{})]})]}),u.jsx(i,{container:!0,justifyContent:"space-between",gap:q.SMALL,children:u.jsx(i,{xs:12})})]})})};export{p6 as default};
|