import{j as u,T as c,ao as t0,ap as s0,aq as n0,B as O,aA as a6,al as J,ak as v,I as uu,aU as xu,aa as i6,ag as yu,ah as eu,am as c6,av as o0,aw as a0,ax as B,aX as $,ai as Y,aj as R,d as C6,bi as i0}from"./mui-vendor-CkIVaoQP.js";import{d as d6}from"./Search-Dek2fED1.js";import{r as a}from"./react-vendor-CmFgShSM.js";import{a as su,f as ru,u as c0}from"./redux-vendor-B7uoacJt.js";import{L as tu,j as nu,h as H,X as L,A as h6,$ as C0,di as d0,u as lu,du as h0,a0 as p6,fS as p0,c as z,v as A6,cs as g6,b as _,c2 as A0,M as I,fe as g0,N as U,p as v0,O as F0,G as s,S as A,C as v6,W as x0,fg as fu,cm as F6,a1 as x6,fA as y6}from"./index-CeyyVc1v.js";import{d as y0}from"./Delete-C5MyLelE.js";import{d as f0}from"./Add--yVWBJhC.js";import{d as j0}from"./Done-Dp5awdte.js";import{a as m0}from"./aviculture-get-unions-C1NoVg85.js";import{a as S0}from"./aviculture-get-hatching-data-DsjDNd82.js";import{N as f6}from"./NumberFormatCustom-DwWPj40N.js";import{D as b0}from"./DialogAlert-BfXcr-Kr.js";import{S as E0}from"./SimpleTable-DBAoNnCU.js";import{b as k0,a as B0}from"./province-get-sell-for-freezing-status-ieuVFEgW.js";import{p as T0,a as P0}from"./province-policy-market-daily-limitation-DueqDboR.js";import{i as w0}from"./isValidIndexWeight-C_ik-uYa.js";import{L as _0}from"./LabelField-B6eRSoQP.js";const j6=su("CITY_GET_POULTRY_DATA",async(b,{dispatch:S})=>{S(tu());const{data:P,status:N}=await nu.get("Poultry/?type=filter&value="+b);return S(H()),{data:P,status:N}}),I0=su("CITY_GET_BUYER",async b=>{const{data:S,status:P}=await nu.get("https://artasystemback.rasadyaar.ir/api/find/?data="+b);return{data:S,status:P}}),W0=su("AVICULTURE_GET_POULTRY",async()=>{const{data:b,status:S}=await nu.get("Poultry/",{params:{role:L()}});return{data:b,status:S}}),L0=su("AVICULTURE_GET_DIRECT_BUYS",async(b,{dispatch:S})=>{S(tu());const{data:P,status:N}=await nu.get("kill_request/?poultry_key="+b);return S(H()),{data:P,status:N}}),J0=({userCheck:b,selectedAge1:S,selectedAge2:P,isAviculture:N,updateTable:Q})=>{var Lu,Nu,qu,Du,Vu,Mu,Gu,Ou,$u,Yu,Ru,zu,Uu,Hu,Qu,Ku,Xu,Zu,Ju;const[j]=a.useContext(h6),[K,m6]=a.useState(""),[ju,S6]=a.useState(""),[F,b6]=a.useState(""),[f,ou]=a.useState(""),[q,E6]=a.useState(""),[au,k6]=a.useState(""),[mu,B6]=a.useState(""),[D,T6]=a.useState(""),[P6]=a.useState(!1),[V,w6]=a.useState(!1),[_6,I6]=a.useState(),[iu,W6]=a.useState(""),[X,L6]=a.useState(""),[W,N6]=a.useState(!1),[m,Su]=a.useState(!1),[cu,q6]=a.useState(!1),[i,D6]=a.useState(null),[n,bu]=a.useState(),[,,Cu,,du]=a.useContext(h6),[Eu,ku]=a.useState(!1),[,hu]=C0(),[Bu,Tu]=a.useState(!1),{weightRange:V6}=ru(e=>e.provinceSlice),[M6,G6]=a.useState([]),{avicultureSlaughters:Z}=ru(e=>e.avicultureSlice),{cityGetPoultries:O6}=ru(e=>e.citySlice),[Pu,$6]=a.useState(!1),Y6=()=>{C(B0()).then(e=>{$6(e.payload.data.poultryStatus)})};a.useEffect(()=>{G6(Z==null?void 0:Z.map(e=>{var p;let t="";return e.killer?t=`کشتارکن ${e==null?void 0:e.name}`:t=`کشتارگاه ${e==null?void 0:e.name}`,{label:`${t} / ${(p=e==null?void 0:e.quantitySum)==null?void 0:p.toLocaleString()} قطعه`,value:`${e==null?void 0:e.name} (${e==null?void 0:e.fullname})`,quantity:e==null?void 0:e.quantitySum,killhouseKey:e==null?void 0:e.killReqKey,item:e}}))},[Z]);const[r,R6]=a.useState(),[pu,Au]=a.useState();a.useEffect(()=>{C(d0()).then(e=>{var t,p,g,h,w,G;R6(e.payload.data),((t=e.payload.data)==null?void 0:t.approved)===!1&&l.setFieldValue("avicultureSellType","freePrice"),((p=e.payload.data)==null?void 0:p.approved)===!0&&((g=e.payload.data)==null?void 0:g.lowestPrice)===0&&((h=e.payload.data)==null?void 0:h.highestPrice)===0&&((w=e.payload.data)==null?void 0:w.lowestWeight)===0&&((G=e.payload.data)==null?void 0:G.highestWeight)===0&&l.setFieldValue("avicultureSellType","goverment")}),C(h0())},[]),a.useEffect(()=>{b&&(Tu(!0),C(j6(b)).then(e=>{ou(e.payload.data),Tu(!1)}))},[b]),a.useEffect(()=>{N&&(C(tu()),C(W0()).then(e=>{ou(e.payload.data),C(H())})),Y6()},[]);const z6=[{type:"text",id:1,value:""}],U6=[{type:"text",id:1,value:""}],[T,gu]=a.useState(z6),[M,vu]=a.useState(U6),C=c0(),{avicultureChickenPrice:d}=ru(e=>e.avicultureSlice),[wu]=a.useState("insideProvince");a.useEffect(()=>{C(p6())},[]);const[y,H6]=a.useState(),[Fu,_u]=a.useState(),[Iu,Wu]=a.useState(null);a.useEffect(()=>{var e;f&&C(m0({breeding_uniq_id:(e=f[0])==null?void 0:e.breedingUniqueId})).then(t=>{var p;_u((p=t.payload.data[0])==null?void 0:p.key),H6(t.payload.data)})},[f]),a.useEffect(()=>{ku(!0),C(p0()).then(()=>{ku(!1)})},[]);const Q6=()=>{T.length<3&&(gu(e=>[...e,{type:"text",value:""}]),vu(e=>[...e,{type:"text",value:""}]))},K6=()=>{const e=T.length-1;if(e!==0){const t=T==null?void 0:T.filter((g,h)=>h!==e),p=M==null?void 0:M.filter((g,h)=>h!==e);gu(t),vu(p)}},X6=e=>{e.preventDefault();const t=e.target.id;gu(p=>{const g=p.slice();return g[t].value=e.target.value,g})},k=e=>{e.preventDefault();const t=e.target.id;vu(p=>{const g=p.slice();return g[t].value=e.target.dataset.value,g})};a.useEffect(()=>{d&&I6(d==null?void 0:d.key)},[d]);const l=lu({initialValues:{noChicken:"",sellType:{cash:!0,haveTime:!1},price1:"",price2:"",price3:"",slaughterDate:A6(Date()).format("YYYY-MM-DD"),period1:"4",period2:"4",period3:"4",weight:"",losses:"0",isUnion:P6,isStockMarket:V,isAccepted:L()!=="Poultry",selectedSlaughters:[],financialOperation:"outside-system",avicultureSellType:"goverment",poultryPrice:""},validationSchema:z({noChicken:I().required("این فیلد اجباری است!").typeError("لطفا عدد وارد کنید!").min(0,"تعداد وارد شده از حداقل ممکن کمتر است").max(Number(X),"تعداد وارد شده قابل تخصیص نیست"),isAccepted:A0().test("req","باید تعهد نامه را بپذیرید!",(e,t)=>t.originalValue&&t.originalValue===!0).required("این فیلد اجباری است!"),price1:_().typeError("لطفا عدد وارد کنید!").min(d==null?void 0:d.floorPrice,"قیمت وارد شده از کف قیمت امروز کمتر است").max(d==null?void 0:d.ceilingPrice,"قیمت وارد شده از سقف قیمت امروز بیشتر است"),price2:_().typeError("لطفا عدد وارد کنید!").min(d==null?void 0:d.floorPrice,"قیمت وارد شده از کف قیمت امروز کمتر است").max(d==null?void 0:d.ceilingPrice,"قیمت وارد شده از سقف قیمت امروز بیشتر است"),price3:_().typeError("لطفا عدد وارد کنید!").min(d==null?void 0:d.floorPrice,"قیمت وارد شده از کف قیمت امروز کمتر است").max(d==null?void 0:d.ceilingPrice,"قیمت وارد شده از سقف قیمت امروز بیشتر است"),weight:_().test("weight","وزن را تا دو رقم اعشار وارد کنید",(e,t)=>t.originalValue&&t.originalValue.toString().length<=4).required("این فیلد اجباری است!").typeError("لطفا وزن را وارد کنید!"),losses:_().required("این فیلد اجباری است!").max(au,"تلفات وارد شده از باقیمانده بیشتر است!").typeError("لطفا تعداد تلفات را وارد کنید!"),poultryPrice:_().typeError("لطفا فیلد را به درستی وارد کنید!"),sellType:z().test("sellType","نحوه فروش را انتخاب کنید!",(e,t)=>t.originalValue&&Object.values(t.originalValue).some(p=>p===!0)).required("این فیلد اجباری است!"),selectedSlaughters:(Nu=(Lu=f[0])==null?void 0:Lu.provinceAllowChooseKillHouse)!=null&&Nu.mandatory?g6().of(I().required("At least one item is required.")).min(1,"At least one item is required."):g6()})});a.useEffect(()=>{if(r!=null&&r.approved&&!((r==null?void 0:r.lowestPrice)===0&&(r==null?void 0:r.highestPrice)===0&&(r==null?void 0:r.lowestWeight)===0&&(r==null?void 0:r.highestWeight)===0))if(l.values.weight*1e3<=(r==null?void 0:r.lowestWeight))Au(r==null?void 0:r.lowestPrice);else if(l.values.weight*1e3>=(r==null?void 0:r.highestWeight))Au(r==null?void 0:r.highestPrice);else{const e=(r==null?void 0:r.highestWeight)-(r==null?void 0:r.lowestWeight),p=((r==null?void 0:r.highestPrice)-(r==null?void 0:r.lowestPrice))/e,g=l.values.weight*1e3-(r==null?void 0:r.lowestWeight);Au(g*p+(r==null?void 0:r.lowestPrice)),l.setFieldValue("poultryPrice",g*p+(r==null?void 0:r.lowestPrice))}},[l.values.weight]);const x=lu({initialValues:{userInfoCheck:""},validationSchema:z({userInfoCheck:I().min(11,"شماره موبایل باید 11 رقم باشد").max(11,"شماره موبایل باید 11 رقم باشد").matches(/^09\d{9}$/,"شماره موبایل باید با 09 شروع شود و 11 رقم باشد")})}),E=lu({initialValues:{userInfoCheck:""},validationSchema:z({userInfoCheck:_().typeError("لطفا فیلد را به درستی وارد کنید!")})}),o=lu({initialValues:{mobile:"",fname:"",lname:"",nationalCode:"",province:"",city:""},validationSchema:z({mobile:I().test("len","شماره تلفن باید با 0 شروع شود",(e,t)=>t.originalValue&&t.originalValue.startsWith("0")).test("len","شماره تماس 11 رقم باید باشد",(e,t)=>{if(t.originalValue)return t.originalValue.length===11}).required("این فیلد اجباری است!").typeError("لطفا عدد وارد کنید!"),fname:I().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),lname:I().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),nationalCode:_().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),province:I().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!"),city:I().required("این فیلد اجباری است!").typeError("لطفا فیلد را به درستی وارد کنید!")})});a.useEffect(()=>{l.validateForm(),x.validateForm(),E.validateForm(),o.validateForm()},[]),a.useEffect(()=>{C(g0({date:l.values.slaughterDate}))},[l.values.slaughterDate]);const Z6=l.values.noChicken*1e3,J6=u.jsxs(u.Fragment,{children:[u.jsxs(c,{variant:"body1",children:["اینجانب ",hu==null?void 0:hu.fullname," به وکالت از"," ",(Du=(qu=f[0])==null?void 0:qu.userprofile)==null?void 0:Du.fullName," موافقت خود را نسبت به موارد ذکر شده اعلام می نمایم."]}),u.jsxs(t0,{children:[u.jsx(s0,{children:u.jsx(j0,{})}),u.jsx(n0,{primary:` بر اساس این توافق نامه در صورت لغو فروش ${l.values.noChicken} قطعه مرغ ${Z6} ریال جریمه خواهم شد.`})]}),u.jsx(c,{})]});a.useEffect(()=>{let e=l.values.weight;const t=l.values.weight.toString().split(".").join("");l.values.weight&&t.length<=3&&(t.length===2&&(e=t[0]+"."+t[1]),t.length===3&&(e=t[0]+"."+t[1]+t[2])),isNaN(Number.parseFloat(e))?l.setFieldValue("weight",""):l.setFieldValue("weight",Number.parseFloat(e))},[l.values.weight]),a.useEffect(()=>{V&&C(p6()).then(e=>{Array.isArray(e.payload.data)&&(j({vertical:"top",horizontal:"center",msg:"قیمت روز مرغ در سامانه ثبت نشده است.",severity:"error"}),C(U({right:!1,bottom:!1,content:null})))})},[V]),a.useEffect(()=>{l.validateForm(),x.validateForm()},[]),a.useEffect(()=>{l.setFieldValue("selectedSlaughters",[]),Wu(null)},[l.values.noChicken]),a.useEffect(()=>{q&&(C(L0(q)).then(e=>{var p;const t=(p=e==null?void 0:e.payload)==null?void 0:p.data;if(t!=null&&t.length){const g=t==null?void 0:t.map(h=>{var G,u6,e6,r6,l6,t6,s6,n6,o6;let w="";return h.directBuyingState==="pending"?w="در انتظار تایید استان":h.directBuyingState==="rejected"?w="رد شده":h.directBuyingState==="accepted"?w="تایید شده":h.directBuyingState==="deleted"&&(w="حذف شده"),[(G=h==null?void 0:h.killHouse)!=null&&G.killer?"کشتارکن":"کشتارگاه",`${(u6=h==null?void 0:h.killHouse)==null?void 0:u6.name} (${(l6=(r6=(e6=h==null?void 0:h.killHouse)==null?void 0:e6.killHouseOperator)==null?void 0:r6.user)==null?void 0:l6.fullname}) ${(n6=(s6=(t6=h==null?void 0:h.killHouse)==null?void 0:t6.killHouseOperator)==null?void 0:s6.user)==null?void 0:n6.mobile}`,(o6=h==null?void 0:h.killCapacity)==null?void 0:o6.toLocaleString(),v0(h==null?void 0:h.reciveDate),h.inputDirectBuyingCode?"دارد":"ندارد",w]});C(F0({title:"هشدار!",content:u.jsxs(u.Fragment,{children:[u.jsx(c,{children:"مرغدار انتخاب شده برای تاریخ امروز درخواست فعال خرید مستقیم دارد."}),u.jsx(E0,{columns:["ماهیت خریدار","خریدار","تعداد (قطعه)","تاریخ کشتار","تاییدیه مرغدار","وضعیت"],data:g}),u.jsxs(s,{container:!0,gap:A.SMALL,children:[u.jsx(O,{variant:"contained",color:"error",onClick:()=>{C(v6()),C(U({right:!1,bottom:!1,content:null}))},children:"انصراف از عملیات"}),u.jsx(O,{variant:"contained",onClick:()=>{C(v6())},children:"ادامه عملیات"})]})]})}))}}),C(S0(q)).then(e=>{e.payload.data?S6(e.payload.data):j({vertical:"top",horizontal:"center",msg:"اطلاعات جوجه ریزی یافت نشد!",severity:"error"})}))},[q]),a.useEffect(()=>{var t,p,g;let e=l.values.noChicken<=Number(D)&&Number(l.values.losses)<=Number(D)?l.values.avicultureSellType==="freePrice"?parseInt((t=F==null?void 0:F.freeGovernmentalInfo)==null?void 0:t.leftTotalFreeCommitmentQuantity):Number(D)-Number(l.values.losses):0;if(m&&(i!=null&&i.active)&&((p=i==null?void 0:i.market)==null?void 0:p.remainQuantity)!==void 0&&((g=i==null?void 0:i.market)==null?void 0:g.maxLimitationQuantity)!==void 0){const h=i.market.remainQuantity;e=Math.min(e,h)}L6(e),l.validateForm()},[l.values.losses,D,l.values.noChicken,l.values.avicultureSellType,m,i]);const[u0,e0]=a.useState(!1),[r0,l0]=a.useState(!1);return a.useEffect(()=>{k6(F.quantity),B6(F.losses),T6(F.leftOver),C(k0()).then(e=>{e0(e.payload.data.permission)}),C(T0()).then(e=>{l0(e.payload.data.allow)})},[F]),a.useEffect(()=>{m&&C(P0()).then(e=>{var t;(t=e.payload)!=null&&t.data&&D6(e.payload.data)})},[m]),u.jsx(u.Fragment,{children:!f&&!N?u.jsxs(u.Fragment,{children:[u.jsx(s,{container:!0,alignItems:"center",justifyContent:"center",children:Bu&&u.jsx(a6,{})}),!Bu&&u.jsxs(s,{children:[u.jsx(c,{children:"جستجو کاربر"}),u.jsxs(s,{mt:A.SMALL,display:"flex",width:1,children:[u.jsx(J,{fullWidth:!0,id:"userInfoCheck",getOptionDisabled:e=>e.disabled<=0,loading:Eu,options:O6||[],getOptionLabel:e=>e.label,onChange:(e,t)=>{x.setFieldValue("userInfoCheck",t.value)},onBlur:x.handleBlur,renderInput:e=>u.jsx(v,{...e,label:"مرغداری/مانده جوجه ریزی",variant:"outlined",slotProps:{input:{...e.InputProps,endAdornment:u.jsxs(u.Fragment,{children:[Eu?u.jsx(a6,{color:"inherit",size:20}):null,e.InputProps.endAdornment]})}}})}),u.jsx(uu,{disabled:!x.isValid,"aria-label":"delete",color:"primary",onClick:()=>{C(j6(x.values.userInfoCheck)).then(e=>{e.error&&j({vertical:"top",horizontal:"center",msg:"کاربر یافت نشد",severity:"error"}),ou(e.payload.data)})},children:u.jsx(d6,{})})]}),u.jsx(xu,{children:"شماره موبایل با صفر شروع می‌شود!"}),u.jsx(c,{mt:A.SMALL,variant:"body2",color:"secondary",children:"پس از ثبت درخواست، میتوانید آن را در بخش درخواست ها مدیریت کنید."})]})]}):u.jsxs(s,{container:!0,gap:A.SMALL,direction:"column",display:"flex",children:[u.jsxs(s,{container:!0,gap:A.SMALL,direction:"column",children:[u.jsx(s,{minWidth:210,children:u.jsx(J,{disablePortal:!0,id:"combo-box-demo",options:Array.isArray(f)?f.map(e=>({id:e.key,label:e.unitName})):[],onChange:(e,t)=>{E6(t.id)},renderInput:e=>u.jsx(v,{...e,label:"محل پرورش"})})}),q&&u.jsx(s,{minWidth:210,children:u.jsx(J,{disablePortal:!0,id:"hatching",options:ju?ju.map(e=>({id:e.key,race:e.chickenBreed,selected:e,label:`دوره ${e.period} سالن ${e.hall} نژاد ${e.chickenBreed} باقیمانده ${e.leftOver} قطعه`})):[],onChange:(e,t)=>{m6(t.id),b6(t.selected),W6(t.race)},renderInput:e=>u.jsx(v,{...e,label:"دوره جوجه ریزی"})})}),K&&u.jsxs(u.Fragment,{children:[u.jsx(s,{children:u.jsx(v,{disabled:!0,fullWidth:!0,id:"outlined-read-only-input",label:"تعداد جوجه ریزی",value:au||"نامشخص",InputProps:{readOnly:!0}})}),u.jsx(s,{children:u.jsx(v,{disabled:!0,fullWidth:!0,id:"outlined-read-only-input",label:"جمع تلفات ثبت شده دامپزشک و مرغدار",value:mu||"نامشخص",InputProps:{readOnly:!0}})}),u.jsx(s,{children:u.jsx(v,{disabled:!0,fullWidth:!0,id:"outlined-read-only-input",label:"باقیمانده",value:D||"نامشخص",InputProps:{readOnly:!0}})})]})]}),F&&u.jsxs(s,{container:!0,gap:A.SMALL,direction:"column",children:[u.jsx(s,{children:u.jsx(c,{children:"اطلاعات کشتار"})}),u.jsx(s,{children:u.jsx(f6,{allowLeadingZeros:!0,thousandSeparator:",",fullWidth:!0,id:"noChicken",label:"تعداد مرغ برای کشتار",variant:"outlined",value:l.values.noChicken,error:l.values.noChicken>X?(()=>{var e,t,p;return m&&(i!=null&&i.active)&&l.values.noChicken>((e=i==null?void 0:i.market)==null?void 0:e.remainQuantity)?`حداکثر ظرفیت پنل معاملات ${(p=(t=i==null?void 0:i.market)==null?void 0:t.remainQuantity)==null?void 0:p.toLocaleString()} قطعه است!`:"این حجم قابل تخصیص نیست!"})():l.touched.noChicken?!!l.errors.noChicken:null,onChange:l.handleChange,onBlur:l.handleBlur,helperText:l.values.noChicken>X?(()=>{var e,t,p;return m&&(i!=null&&i.active)&&l.values.noChicken>((e=i==null?void 0:i.market)==null?void 0:e.remainQuantity)?`حداکثر ظرفیت پنل معاملات ${(p=(t=i==null?void 0:i.market)==null?void 0:t.remainQuantity)==null?void 0:p.toLocaleString()} قطعه است!`:"این حجم قابل تخصیص نیست!"})():l.touched.noChicken&&l.errors.noChicken?l.errors.noChicken:null})}),(r==null?void 0:r.approved)&&u.jsxs(s,{container:!0,gap:A.TINY,justifyContent:"start",alignItems:"start",children:[u.jsxs(s,{container:!0,gap:A.TINY,children:[u.jsx(c,{color:e=>e.palette.grey.A700,variant:"caption",children:"مجوز فروش آزاد:"}),u.jsx(c,{variant:"button",children:(Mu=parseInt((Vu=F==null?void 0:F.freeGovernmentalInfo)==null?void 0:Vu.totalFreeCommitmentQuantity))==null?void 0:Mu.toLocaleString()}),u.jsx(c,{variant:"button",children:"قطعه"})]}),u.jsxs(s,{container:!0,gap:A.TINY,children:[u.jsx(c,{color:"error",variant:"caption",children:"مانده فروش آزاد:"}),u.jsxs(c,{variant:"button",color:"error",children:[parseInt((Gu=F==null?void 0:F.freeGovernmentalInfo)==null?void 0:Gu.leftTotalFreeCommitmentQuantity).toLocaleString(),"‌‌","قطعه"]})]})]}),u.jsx(s,{children:u.jsx(x0,{label:"تاریخ کشتار",id:"slaughterDate",renderInput:e=>u.jsx(v,{...e}),value:l.values.slaughterDate,error:l.touched.slaughterDate?!!l.errors.slaughterDate:null,onChange:e=>{l.setFieldValue("slaughterDate",A6(e).format("YYYY-MM-DD"))},onBlur:l.handleBlur,helperText:l.touched.slaughterDate&&l.errors.slaughterDate?l.errors.slaughterDate:null})}),u.jsx(s,{children:u.jsx(v,{id:"weight",label:"وزن تقریبی مرغ",variant:"outlined",InputProps:{endAdornment:u.jsx(i6,{position:"end",children:"کیلوگرم"})},value:l.values.weight,error:l.touched.weight?!!l.errors.weight:null,onChange:l.handleChange,onBlur:l.handleBlur,helperText:l.touched.weight&&l.errors.weight?l.errors.weight:null})}),wu==="insideProvince"?u.jsxs(u.Fragment,{children:[u.jsx(s,{display:"none",children:u.jsx(yu,{children:u.jsx(eu,{"aria-labelledby":"demo-radio-buttons-group-label",defaultValue:"فروش اتحادیه",name:"radio-buttons-group",onChange:e=>{w6(e.currentTarget.value)},children:V==="فروش مزایده ای"&&u.jsxs(s,{container:!0,gap:A.SMALL,children:[u.jsxs(s,{container:!0,gap:A.SMALL,alignItems:"center",children:[u.jsx(c,{color:e=>e.palette.grey.A700,variant:"caption",children:"کف قیمت امروز:"}),u.jsxs(c,{color:"secondary",variant:"button",children:[d!=null&&d.floorPrice?d==null?void 0:d.floorPrice.toLocaleString():"نامشخص"," "," ","ریال"]})]}),u.jsxs(s,{container:!0,gap:A.SMALL,alignItems:"center",children:[u.jsx(c,{color:e=>e.palette.grey.A700,variant:"caption",children:"سقف قیمت امروز:"}),u.jsxs(c,{color:"secondary",variant:"button",children:[d!=null&&d.ceilingPrice?d==null?void 0:d.ceilingPrice.toLocaleString():"نامشخص","ریال"]})]}),u.jsx(c6,{style:{width:"100%"}}),T.map((e,t)=>u.jsxs(s,{gap:A.SMALL,container:!0,sx:{minWidth:210},children:[u.jsxs(c,{mb:A.SMALL,display:"flex",children:["پیشنهاد ",t+1]}),u.jsx(f6,{allowLeadingZeros:!0,thousandSeparator:",",error:!1,fullWidth:!0,label:"قیمت پیشنهادی",variant:"outlined",onChange:X6,id:t}),u.jsxs(yu,{fullWidth:!0,children:[u.jsx(o0,{id:"demo-simple-select-label",children:"بازه زمانی (ساعت)"}),u.jsxs(a0,{id:t,labelId:"demo-simple-select-label",label:"بازه زمانی (ساعت)",children:[u.jsx(B,{onClick:k,id:t,value:"1",children:"1"}),u.jsx(B,{onClick:k,id:t,value:"2",children:"2"}),u.jsx(B,{onClick:k,id:t,value:"3",children:"3"}),u.jsx(B,{onClick:k,id:t,value:"4",children:"4"}),u.jsx(B,{onClick:k,id:t,value:"5",children:"5"}),u.jsx(B,{onClick:k,id:t,value:"6",children:"6"}),u.jsx(B,{onClick:k,id:t,value:"7",children:"7"}),u.jsx(B,{onClick:k,id:t,value:"8",children:"8"}),u.jsx(B,{onClick:k,id:t,value:"9",children:"9"}),u.jsx(B,{onClick:k,id:t,value:"10",children:"10"})]}),u.jsx(xu,{children:l.touched.period1&&l.errors.period1?l.errors.period1:null})]})]},t)),u.jsxs(s,{container:!0,children:[T.length>1&&u.jsx(uu,{onClick:K6,"aria-label":"delete",color:"secondary",children:u.jsx(y0,{})}),T.length<3&&u.jsxs(uu,{xs:12,onClick:Q6,"aria-label":"add",color:"primary",children:[u.jsx(f0,{}),u.jsx(c,{children:"افزودن پیشنهاد جدید"})]})]}),u.jsx(s,{container:!0,sx:{width:"100%"},children:u.jsxs(c,{variant:"body2",children:["در صورت عدم فروش در بورس، از طریق اتحادیه فروش برود",u.jsx($,{id:"isUnion",onChange:l.handleChange})]})})]})})})}),(r==null?void 0:r.approved)&&!((r==null?void 0:r.lowestPrice)===0&&(r==null?void 0:r.highestPrice)===0&&(r==null?void 0:r.lowestWeight)===0&&(r==null?void 0:r.highestWeight)===0)&&u.jsxs(s,{children:[u.jsx(c,{children:"نوع فروش"}),u.jsxs(eu,{"aria-label":"avicultureSellType",name:"avicultureSellType",value:l.values.avicultureSellType,onChange:l.handleChange,children:[u.jsx(Y,{value:"goverment",control:u.jsx(R,{}),label:"دولتی"}),u.jsx(Y,{value:"freePrice",control:u.jsx(R,{}),label:"آزاد"})]})]}),(r==null?void 0:r.approved)&&l.values.avicultureSellType==="goverment"&&!((r==null?void 0:r.lowestPrice)===0&&(r==null?void 0:r.highestPrice)===0&&(r==null?void 0:r.lowestWeight)===0&&(r==null?void 0:r.highestWeight)===0)&&u.jsxs(s,{gap:1,container:!0,p:1,style:{borderStyle:"solid",borderWidth:"1px",borderColor:"red",borderRadius:"5px"},children:[u.jsx(C6,{title:`قیمت مصوب بر اساس قیمت مصوب کف ${r==null?void 0:r.lowestPrice.toLocaleString()} هزار ریال و سقف ${(Ou=r==null?void 0:r.highestPrice)==null?void 0:Ou.toLocaleString()} هزار ریال محاسبه شده است.`,children:u.jsx(c,{variant:"body1",color:"secondary",children:"قیمت مصوب:"})}),u.jsxs(c,{variant:"body1",color:"primary",children:[pu?($u=Math.round(pu))==null?void 0:$u.toLocaleString():0,"ریال"]})]}),u.jsx(c6,{}),u.jsxs(s,{style:{display:"none"},children:[u.jsx(c,{children:"نحوه تسویه حساب"}),u.jsxs(eu,{name:"financialOperation",value:l.values.financialOperation,onChange:l.handleChange,children:[u.jsx(C6,{title:"تسویه با مرغدار توسط خریدار بصورت مستقیم صورت میگیرد",arrow:!0,children:u.jsx(Y,{value:"outside-system",control:u.jsx(R,{}),label:"خارج از سامانه"})}),u.jsx(Y,{value:"inside-system",control:u.jsx(R,{}),label:"درون سامانه",disabled:!0})]})]}),(f==null?void 0:f.length)&&((Ru=(Yu=f[0])==null?void 0:Yu.provinceAllowChooseKillHouse)==null?void 0:Ru.allowState)&&u.jsxs(s,{container:!0,direction:"column",gap:A.SMALL,children:[u.jsx(J,{disablePortal:!0,value:(zu=l.values.selectedSlaughters)!=null&&zu.length?l.values.selectedSlaughters[0]:null,onChange:(e,t)=>{l.setFieldValue("selectedSlaughters",[t.value]),Wu(t.killhouseKey)},id:"combo-box-demo",options:M6,sx:{width:"100%"},getOptionDisabled:e=>{const t=Number(l.values.noChicken);return e.item.quantitySumu.jsx(v,{...e,label:"خریدار/ظرفیت باقیمانده"})}),u.jsxs(s,{container:!0,gap:A.SMALL,children:[l.values.selectedSlaughters&&u.jsx(c,{variant:"body1",children:"کشتارگاهای انتخابی"}),u.jsx(s,{container:!0,direction:"column",children:l.values.selectedSlaughters.map((e,t)=>u.jsxs(c,{variant:"body2",children:[t+1,"- ",e]},t))})]})]}),u.jsx(s,{style:{display:"none"},children:u.jsxs(yu,{children:[u.jsx(i0,{id:"demo-radio-buttons-group-label",children:"اطلاعات تعاونی"}),u.jsx(eu,{defaultValue:y!=null&&y.length?(Uu=y[0])==null?void 0:Uu.key:"",name:"radio-buttons-group",onChange:e=>{_u(e.currentTarget.value)},children:y==null?void 0:y.map(e=>u.jsx(u.Fragment,{children:u.jsx(Y,{disabled:!0,value:e.key,control:u.jsx(R,{}),label:e.unitName})}))})]})})]}):u.jsxs(u.Fragment,{children:[u.jsxs(s,{children:[u.jsx(c,{variant:"body2",children:"اطلاعات کاربر را وارد یا جستجو کنید."}),u.jsxs(s,{mt:A.SMALL,display:"flex",width:1,children:[u.jsx(v,{fullWidth:!0,id:"userInfoCheck",label:"شماره موبایل یا کد ملی ",variant:"outlined",value:E.values.userInfoCheck,error:E.touched.userInfoCheck?!!E.errors.userInfoCheck:null,onChange:E.handleChange,onBlur:E.handleBlur,helperText:E.touched.userInfoCheck&&E.errors.userInfoCheck?E.errors.userInfoCheck:null}),u.jsx(uu,{disabled:!E.isValid,"aria-label":"delete",color:"primary",onClick:()=>{C(I0(E.values.userInfoCheck)).then(e=>{e.error?(j({vertical:"top",horizontal:"center",msg:"کاربر یافت نشد",severity:"error"}),bu("")):bu(e.payload.data)})},children:u.jsx(d6,{})})]}),u.jsx(xu,{children:"شماره موبایل با صفر شروع می‌شود!"})]}),n?u.jsxs(s,{children:[u.jsxs(s,{display:"flex",children:[u.jsx(c,{variant:"body1",mr:A.TINY,color:e=>e.palette.grey.A700,children:"نام کامل:"}),u.jsx(c,{mr:A.TINY,fontWeight:"bold",children:(n!=null&&n.firstname?n==null?void 0:n.firstname:"")+" "+(n!=null&&n.lastname?n==null?void 0:n.lastname:"")})]}),u.jsxs(s,{display:"flex",children:[u.jsx(c,{variant:"body1",mr:A.TINY,color:e=>e.palette.grey.A700,children:"نقش:"}),u.jsx(c,{mr:A.TINY,fontWeight:"bold",children:"اپراتور استان"})]}),u.jsxs(s,{display:"flex",children:[u.jsx(c,{variant:"body1",mr:A.TINY,color:e=>e.palette.grey.A700,children:"استان:"}),u.jsx(c,{mr:A.TINY,fontWeight:"bold",children:n==null?void 0:n.province})]}),u.jsxs(s,{display:"flex",children:[u.jsx(c,{variant:"body1",mr:A.TINY,color:e=>e.palette.grey.A700,children:"شهر:"}),u.jsx(c,{mr:A.TINY,fontWeight:"bold",children:n==null?void 0:n.city})]})]}):u.jsxs(s,{container:!0,gap:A.SMALL,children:[u.jsx(c,{variant:"body2",children:"اطلاعات کاربر را وارد کنید"}),u.jsx(v,{fullWidth:!0,id:"mobile",label:"شماره موبایل ",variant:"outlined",value:o.values.mobile,error:o.touched.mobile?!!o.errors.mobile:null,onChange:o.handleChange,onBlur:o.handleBlur,helperText:o.touched.mobile&&o.errors.mobile?o.errors.mobile:null}),u.jsx(v,{fullWidth:!0,id:"fname",label:"نام",variant:"outlined",value:o.values.fname,error:o.touched.fname?!!o.errors.fname:null,onChange:o.handleChange,onBlur:o.handleBlur,helperText:o.touched.fname&&o.errors.fname?o.errors.fname:null}),u.jsx(v,{fullWidth:!0,id:"lname",label:"نام خانوادگی",variant:"outlined",value:o.values.lname,error:o.touched.lname?!!o.errors.lname:null,onChange:o.handleChange,onBlur:o.handleBlur,helperText:o.touched.lname&&o.errors.lname?o.errors.lname:null}),u.jsx(v,{fullWidth:!0,id:"nationalCode",label:"کد ملی",variant:"outlined",value:o.values.nationalCode,error:o.touched.nationalCode?!!o.errors.nationalCode:null,onChange:o.handleChange,onBlur:o.handleBlur,helperText:o.touched.nationalCode&&o.errors.nationalCode?o.errors.nationalCode:null}),u.jsx(v,{fullWidth:!0,id:"province",label:"استان",variant:"outlined",value:o.values.province,error:o.touched.province?!!o.errors.province:null,onChange:o.handleChange,onBlur:o.handleBlur,helperText:o.touched.province&&o.errors.province?o.errors.province:null}),u.jsx(v,{fullWidth:!0,id:"city",label:"شهر",variant:"outlined",value:o.values.city,error:o.touched.city?!!o.errors.city:null,onChange:o.handleChange,onBlur:o.handleBlur,helperText:o.touched.city&&o.errors.city?o.errors.city:null})]})]}),u.jsxs(s,{container:!0,xs:12,gap:1,justifyContent:"start",children:[u0&&u.jsx(s,{xs:12,children:u.jsxs(s,{container:!0,alignItems:"center",children:[u.jsx($,{checked:W,onChange:()=>{N6(!W)},inputProps:{"aria-label":"controlled"}}),u.jsx(c,{variant:"body1",children:"کشتار برای انجماد"})]})}),i!=null&&i.active?u.jsx(_0,{label:"جزییات پنل",children:u.jsxs(s,{container:!0,direction:"column",gap:1,children:[u.jsxs(s,{container:!0,alignItems:"center",children:[u.jsx($,{checked:m,onChange:()=>{Su(!m)},inputProps:{"aria-label":"controlled"}}),u.jsx(c,{variant:"body1",children:"نمایش در پنل معاملات"})]}),m&&u.jsxs(s,{container:!0,direction:"column",gap:1,pr:2,children:[u.jsx(s,{container:!0,gap:A.TINY,justifyContent:"space-between",alignItems:"start"}),u.jsxs(s,{container:!0,gap:1,alignItems:"center",children:[u.jsx(c,{variant:"caption",color:e=>e.palette.grey.A700,children:"باقیمانده مجاز:"}),u.jsxs(c,{variant:"button",color:"primary",children:[(Qu=(Hu=i==null?void 0:i.market)==null?void 0:Hu.remainQuantity)==null?void 0:Qu.toLocaleString()," ","قطعه"]})]}),u.jsxs(s,{container:!0,gap:1,alignItems:"center",children:[u.jsx(c,{variant:"caption",color:e=>e.palette.grey.A700,children:"حداکثر قطعه مجاز:"}),u.jsxs(c,{variant:"button",children:[(Xu=(Ku=i==null?void 0:i.market)==null?void 0:Ku.maxLimitationQuantity)==null?void 0:Xu.toLocaleString()," ","قطعه"]})]})]})]})}):u.jsxs(s,{container:!0,alignItems:"center",children:[u.jsx($,{checked:m,onChange:()=>{Su(!m)},inputProps:{"aria-label":"controlled"}}),u.jsx(c,{variant:"body1",children:"نمایش در پنل معاملات"})]})]}),(l.values.avicultureSellType!=="goverment"||(r==null?void 0:r.approved)&&(r==null?void 0:r.lowestPrice)===0&&(r==null?void 0:r.highestPrice)===0&&(r==null?void 0:r.lowestWeight)===0&&(r==null?void 0:r.highestWeight)===0)&&u.jsxs(s,{children:[u.jsx(v,{id:"poultryPrice",label:"قیمت پیشنهادی مرغدار",variant:"outlined",InputProps:{endAdornment:u.jsx(i6,{position:"end",children:"ریال"})},value:l.values.poultryPrice,error:l.touched.poultryPrice?!!l.errors.poultryPrice:null,onChange:l.handleChange,onBlur:l.handleBlur,helperText:l.touched.poultryPrice&&l.errors.poultryPrice?l.errors.poultryPrice:null,sx:{"& .Mui-disabled":{backgroundColor:"#f0f0f0",color:"#666","& .MuiOutlinedInput-notchedOutline":{borderColor:"#ccc"}}},disabled:W}),!(r!=null&&r.approved)&&l.values.avicultureSellType!=="goverment"&&u.jsx(c,{variant:"caption",color:"error",children:"نوع فروش: آزاد"})]}),r0&&u.jsxs(s,{container:!0,alignItems:"center",children:[u.jsx($,{checked:cu,onChange:()=>{q6(!cu)},inputProps:{"aria-label":"controlled"}}),u.jsx(c,{variant:"body1",children:"کشتار برای صادرات"})]}),L()==="Poultry"&&u.jsx(s,{children:u.jsx(b0,{title:"تعهد نامه",content:J6,actions:u.jsxs(s,{container:!0,gap:A.TINY,children:[u.jsx(O,{variant:"outlined",color:"error",onClick:()=>{l.setFieldValue("isAccepted",!1)},children:"رد"}),u.jsx(O,{variant:"contained",color:"success",onClick:()=>{l.setFieldValue("isAccepted",!0)},children:"موافقم"})]}),btnTitle:"متن تعهد نامه تایید شد!",isAccepted:l.values.isAccepted})}),Pu&&u.jsx(v,{fullWidth:!0,id:"userInfoCheck",label:"ویرایش تلفن مرغدار",variant:"outlined",value:x.values.userInfoCheck,error:x.touched.city?!!x.errors.userInfoCheck:null,onChange:x.handleChange,onBlur:x.handleBlur,helperText:x.touched.userInfoCheck&&x.errors.userInfoCheck?x.errors.userInfoCheck:null}),Pu&&u.jsx(c,{variant:"caption",color:"error",children:"احراز پیامکی قیمت مرغدار در استان فعال است. در صورت ویرایش، تلفن مرغدار در سراسر سامانه با تلفن جدید جایگزین میگردد!"}),u.jsx(s,{mb:A.SMALL,children:u.jsx(O,{fullWidth:!0,disabled:!l.isValid||!x.isValid||l.values.avicultureSellType==="freePrice"&&(W?!1:!l.values.poultryPrice)||m&&(i==null?void 0:i.active)&&(l.values.noChicken>((Zu=i==null?void 0:i.market)==null?void 0:Zu.remainQuantity)||l.values.noChicken>((Ju=i==null?void 0:i.market)==null?void 0:Ju.maxLimitationQuantity)),onClick:()=>{L()!=="SuperAdmin"&&L()!=="AdminX"&&!w0(V6,F==null?void 0:F.age,l.values.weight)?j({vertical:"top",horizontal:"center",msg:"میانگین وزنی با احراز سنی مطابقت ندارد. لطفا با اتحادیه تماس بگیرید.",severity:"error"}):l.values.noChicken>X?j({vertical:"top",horizontal:"center",msg:"تعداد وارد شده از حجم قابل تخصیص بزرگتر است!",severity:"error"}):(C(tu()),wu==="insideProvince"?V==="فروش مزایده ای"?C(fu({role:L(),poultry_key:f==null?void 0:f.key,operator_key:(y==null?void 0:y.length)>1?Fu:"",poultry_hatching_key:K,quantity:l.values.noChicken,send_date:l.values.slaughterDate,chicken_breed:iu,Index_weight:l.values.weight,freezing:W,union:l.values.isUnion,losses:l.values.losses!==""?l.values.losses:0,auction:!0,auction_list:T.map((e,t)=>({pricing_key:_6,fee:e.value?e.value:d==null?void 0:d.floorPrice,hour:M[t].value?M[t].value:"4"}))})).then(e=>{e.error?e.error.message.includes("403")?j({vertical:"top",horizontal:"center",msg:"قیمت پیشنهادی نباید از حداکثر قیمت روز بیشتر باشد.",severity:"error"}):j({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است!",severity:"error"}):(j({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),C(U({right:!1,bottom:!1,content:null})))}):C(fu({approved_price:r==null?void 0:r.approved,market:m,kill_req_key:Iu,operator_key:(y==null?void 0:y.length)>1?Fu:"",poultry_hatching_key:K,quantity:l.values.noChicken,send_date:l.values.slaughterDate,chicken_breed:iu,Index_weight:l.values.weight,losses:l.values.losses!==""?l.values.losses:0,auction_list:[],freezing:W,export:cu,cash:l.values.sellType.cash,credit:l.values.sellType.haveTime,kill_house_list:l.values.selectedSlaughters,role:L(),poultry_key:q,amount:r!=null&&r.approved&&!((r==null?void 0:r.lowestPrice)===0&&(r==null?void 0:r.highestPrice)===0&&(r==null?void 0:r.lowestWeight)===0&&(r==null?void 0:r.highestWeight)===0)?Math.round(pu):Number(l.values.poultryPrice),financial_operation:l.values.financialOperation,free_sale_in_province:l.values.avicultureSellType!=="goverment",confirm_poultry_mobile:x.values.userInfoCheck})).then(e=>{C(H()),e.payload.error?j({vertical:"top",horizontal:"center",msg:e.payload.error,severity:"error"}):(Q&&Q(),C(F6({selectedDate1:Cu,selectedDate2:du})),C(x6({selectedDate1:Cu,selectedDate2:du})),C(y6({selectedAge1:S,selectedAge2:P})),j({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),C(U({right:!1,bottom:!1,content:null})))}):C(fu({approved_price:r==null?void 0:r.approved,kill_req_key:Iu,buyer:{firstname:n!=null&&n.firstname?n==null?void 0:n.firstname:o.values.fname,lastname:n!=null&&n.lastname?n==null?void 0:n.lastname:o.values.lname,mobile:n!=null&&n.mobile?n==null?void 0:n.mobile:o.values.mobile,national_id:n!=null&&n.national_id?n==null?void 0:n.national_id:o.values.nationalCode,province:n!=null&&n.province?n==null?void 0:n.province:o.values.province,city:n!=null&&n.city?n==null?void 0:n.city:o.values.city},freezing:W,operator_key:(y==null?void 0:y.length)>1?Fu:"",poultry_hatching_key:K,quantity:l.values.noChicken,send_date:l.values.slaughterDate,chicken_breed:iu,Index_weight:l.values.weight,losses:l.values.losses!==""?l.values.losses:0,auction_list:[],cash:l.values.sellType.cash,credit:l.values.sellType.haveTime,kill_house_list:l.values.selectedSlaughters,confirm_poultry_mobile:x.values.userInfoCheck})).then(e=>{C(H()),e.error?e.error.message.includes("403")?j({vertical:"top",horizontal:"center",msg:"تعداد مرغ برای کشتار از باقیمانده بیشتر است!",severity:"error"}):j({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است!",severity:"error"}):(Q&&Q(),C(F6({selectedDate1:Cu,selectedDate2:du})),C(x6()),C(y6({selectedAge1:S,selectedAge2:P})),j({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),C(U({right:!1,bottom:!1,content:null})))}))},size:"large",variant:"contained",children:"ثبت درخواست"})})]})]})})};export{J0 as C,W0 as a};