Files
Rasadyar_FrontEnd/build/assets/SlaughterAllocateToGuild-CeWc5BWf.js

2 lines
16 KiB
JavaScript

import{a as te,u as re,f as ae}from"./redux-vendor-CfkcHgWN.js";import{L as le,j as Vu,h as _u,A as se,v as g,et as oe,a0 as Eu,g2 as ne,c as ie,V as N,g5 as de,b as X,u as Ce,G as w,$ as ce,S as K,W as Tu,C as he,g4 as me}from"./index-D80MdVQn.js";import{j as t,an as V,ao as Bu,aj as R,ak as W,al as b,am as j,T as G,a_ as ge,ac as Pu,B as Nu}from"./mui-vendor-D_SVL-Dx.js";import{r as i}from"./react-vendor-CmFgShSM.js";import{N as D}from"./NumberFormatCustom-BXcOcGV4.js";import{s as ye,a as fe}from"./slaughter-allocate-steward-CCu9314u.js";import{a as pe,s as Ae}from"./slaughter-get-guilds-for-allocate-CQRKvxsV.js";import{I as xe,f as we}from"./toBase64-UDzdrM-n.js";import{a as Fe}from"./province-policy-upload-image-DZLwIF5K.js";import{M as be}from"./MonthlyDataCalendar-_xfuL-Zd.js";import{L}from"./LabelField-BYhJrYEE.js";import{c as h}from"./checkPathStartsWith-DedybDvj.js";const We=te("SLAUGHTER_INVENTORY_FINAL_SUBMIT_SERVICE",async(F,{dispatch:_})=>{_(le());try{const{data:E,status:$}=await Vu.put("steward-allocation/0/",F);return _(_u()),{data:E,status:$}}catch(E){return _(_u()),{error:E.response.data.result}}}),Ge=({item:F,key:_,sellerType:E,buyerType:$,allocationType:Ru,sellType:Wu,updateTable:I,fetchApiData:U,editData:s,priceInfo:d,coldHouseKey:T,coldHouseItemKey:uu,killHouseAllocation:eu,disableFreeOptions:M=!1})=>{var fu;const A=re(),[tu,Gu]=i.useState([]),[ru,Y]=i.useState([]),[au,q]=i.useState([]),[S,Lu]=i.useState("governmental"),[v,lu]=i.useState("true"),[su,$u]=i.useState(null),[z]=i.useContext(se),[ou,Mu]=i.useState(s!=null&&s.image?[{data_url:s.image}]:[]),[c,Yu]=i.useState(""),[k,nu]=i.useState(""),[qu,zu]=i.useState(1),[O,iu]=i.useState(!1),[Z,du]=i.useState(!1),[Ou,Cu]=i.useState(null),[cu,Zu]=i.useState({}),[y,hu]=i.useState(null),[C,H]=i.useState(null),[B,Hu]=i.useState({governmental:[],free:[]}),o=ae(u=>u.userSlice.selectedSubUser),[f,Ju]=i.useState(g(new Date).format("YYYY-MM-DD")),[mu,J]=i.useState(null),Qu=u=>{const a=u.target.value;Yu(a),P({key:"",item:"",buyerType:"",allocationType:""}),Y([]),q([])},Xu=u=>{nu(u.target.value),P({key:"",item:"",buyerType:"",allocationType:""}),Y([]),q([])},Ku=u=>{const a=u.target.value;Lu(a)},Du=u=>{const a=u.target.value;lu(a),a==="false"&&e.setFieldValue("price","")},Iu=u=>{if(u&&u.formattedDate){Cu(u.formattedDate);const a=cu[u.formattedDate];if(a&&a.originalDay&&hu(a.originalDay),a&&(a.amount!==void 0||a.value1!==void 0)){const r=a.amount!==void 0?a.amount:a.value1,l=Number(typeof r=="string"?r.replace(/,/g,""):r);H(Number.isFinite(l)?l:null)}else H(null)}},gu=i.useCallback(u=>{if(!Array.isArray(u))return{};const a={};return u.forEach(r=>{if(r.day&&r.amount!==void 0){const m=new oe(new Date(r.day)).format("YYYY/MM/DD"),x=r.amount,p=Number(typeof x=="string"?x.replace(/,/g,""):x);a[m]={value1:p,originalDay:r.day,active:r.active===!0}}}),a},[]),Q=i.useCallback(u=>{const a=gu(u);Zu(a)},[gu]),Uu=i.useCallback(async()=>{try{const u=await Vu.get("/kill-house-remain-weight/",{params:{date:f,role:Eu(),role_key:(h("slaughter")||h("steward"))&&(o==null?void 0:o.key)||""}});if(u.data){Hu({governmental:u.data.governmental||[],free:u.data.free||[]});const a=S==="governmental"?u.data.governmental:u.data.free;Q(a)}}catch(u){console.error("Error fetching calendar data:",u)}},[S,Q,f,o]),[n,P]=i.useState({key:_,item:F,buyerType:$,allocationType:Ru});i.useEffect(()=>{Eu()==="Steward"&&nu("free"),Uu()},[o==null?void 0:o.key]),i.useEffect(()=>{if(B.governmental.length>0||B.free.length>0){const u=S==="governmental"?B.governmental:B.free;Q(u),Cu(null),hu(null),H(null)}},[S,B]),i.useEffect(()=>{A(Fe({role_key:(h("slaughter")||h("steward"))&&(o==null?void 0:o.key)||""})).then(u=>{var a;(a=u.payload)!=null&&a.data&&zu(u.payload.data.killHouseAllocation)}),s||(A(ne({role_key:(h("slaughter")||h("steward"))&&(o==null?void 0:o.key)||""})).then(u=>{Gu(u.payload.data)}),!F&&c&&k&&(c==="guilds"?A(pe({free:k==="free",role_key:(h("slaughter")||h("steward"))&&(o==null?void 0:o.key)||""})).then(u=>{Y(u.payload.data)}):c==="stewards"&&A(Ae({free:k==="free",role_key:(h("slaughter")||h("steward"))&&(o==null?void 0:o.key)||""})).then(u=>{q(u.payload.data)})))},[c,k,o==null?void 0:o.key]);const ue=ie({mobile:N().when([],{is:()=>!s,then:u=>u.required("شماره موبایل الزامی است").min(11,"شماره موبایل باید 11 رقم باشد").max(11,"شماره موبایل باید 11 رقم باشد").matches(/^09\d{9}$/,"شماره موبایل باید با 09 شروع شود و 11 رقم باشد"),otherwise:u=>u.notRequired()}),weight:X().required("این فیلد اجباری است!").integer("عدد باید صحیح باشد!").min(1,"یک مقدار مثبت وارد کنید!").test("max-production-date-amount",`وزن نمی‌تواند بیشتر از موجودی تاریخ تولید (${(C==null?void 0:C.toLocaleString())||0} کیلوگرم) باشد!`,function(u){return!C||C===null?!0:u<=C}),price:X().required("این فیلد اجباری است!").min(1,"یک مقدار مثبت وارد کنید!"),wholePrice:X().required("این فیلد اجباری است!").min(1,"یک مقدار مثبت وارد کنید!"),date:de().test("date-not-before-production","تاریخ نمی‌تواند قبل از تاریخ تولید باشد",function(u){return!y||!u?!0:g(u).isSameOrAfter(g(y),"day")}),...eu&&{image:N().when([],{is:()=>(!s||O)&&qu>0,then:N().required("عکس الزامی است"),otherwise:N().notRequired()})}}),ee=u=>{var a;u[0]?(e.setFieldValue("image",we((a=u[0])==null?void 0:a.data_url)),iu(!0)):(e.setFieldValue("image",""),iu(!0)),Mu(u)},e=Ce({initialValues:{mobile:"",weight:(s==null?void 0:s.realWeightOfCarcasses)||"",wholePrice:(s==null?void 0:s.totalAmount)||"",price:(s==null?void 0:s.amount)||"",image:(s==null?void 0:s.image)||"",date:f},validationSchema:ue});i.useEffect(()=>{e.validateForm()},[C,y]),i.useEffect(()=>{e.setFieldValue("date",f)},[f]),i.useEffect(()=>{(d==null?void 0:d.active)===!1&&lu("false")},[d==null?void 0:d.active]),i.useEffect(()=>{v==="true"&&(d!=null&&d.active)&&e.setFieldValue("price",d==null?void 0:d.killHousePrice)},[v]),i.useEffect(()=>{v==="true"&&(d!=null&&d.active)?e.values.weight&&e.setFieldValue("wholePrice",(d==null?void 0:d.killHousePrice)*e.values.weight):e.values.weight&&e.values.price&&e.setFieldValue("wholePrice",e.values.price*e.values.weight)},[e.values.price,e.values.weight,v]);const yu=()=>{A(he()),z({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),A(me({role_key:(h("slaughter")||h("steward"))&&(o==null?void 0:o.key)||""})),A(Tu({right:!1,bottom:!1,left:!1,content:null})),I&&I(),U&&U()};return t.jsxs(w,{container:!0,xs:12,direction:"column",justifyContent:"center",alignItems:"flex-start",gap:1.8,children:[!s&&t.jsx(ce,{label:"تاریخ ثبت توزیع",id:"date",renderInput:u=>t.jsx(V,{fullWidth:!0,...u,error:!!mu||u.error,helperText:mu||u.helperText}),shouldDisableDate:u=>{const a=g(u),r=g();return!a.isSame(r,"day")},value:f,onChange:u=>{if(!u){J(null);return}const a=g(u),r=g(),l=g().subtract(1,"day");if(!(a.isSame(r,"day")||a.isSame(l,"day"))){J("تنها امکان انتخاب «امروز» یا «دیروز» وجود دارد.");return}J(null),Ju(g(u).format("YYYY-MM-DD"))}}),!s&&!T&&t.jsx(w,{xs:12,container:!0,children:t.jsx(Bu,{fullWidth:!0,disablePortal:!0,id:"hatching",options:tu?tu.map(u=>({data:u,label:`${u.name}`})):[],onChange:(u,a)=>{$u(a.data)},renderInput:u=>t.jsx(V,{fullWidth:!0,...u,label:"انتخاب محصول"})})}),!s&&t.jsx(L,{label:"خریداران",children:t.jsx(R,{fullWidth:!0,children:t.jsxs(W,{row:!0,"aria-labelledby":"buyer-category-radio-group",name:"buyerCategory",value:c,onChange:Qu,sx:{justifyContent:"space-between"},children:[t.jsx(b,{value:"stewards",control:t.jsx(j,{}),label:"مباشرین"}),t.jsx(b,{value:"guilds",control:t.jsx(j,{}),label:"اصناف"})]})})}),!s&&c&&t.jsx(L,{label:"",children:t.jsx(R,{fullWidth:!0,children:t.jsxs(W,{row:!0,"aria-labelledby":"buyer-type-radio-group",name:"buyerType",value:k,onChange:Xu,sx:{justifyContent:"space-between"},children:[t.jsx(b,{value:"own",control:t.jsx(j,{}),label:"اختصاصی"}),t.jsx(b,{value:"free",control:t.jsx(j,{}),label:"آزاد",disabled:M})]})})}),!F&&!s&&c&&k&&t.jsx(w,{xs:12,container:!0,children:(()=>{const u=c==="guilds"?ru:au;return!u||u.length===0?t.jsx(G,{variant:"body2",color:"text.secondary",sx:{width:"100%",textAlign:"center",padding:2,fontStyle:"italic"},children:c==="guilds"?"هیچ صنفی یافت نشد":"هیچ مباشری یافت نشد"}):t.jsx(Bu,{fullWidth:!0,disablePortal:!0,id:"buyer-selection",options:c==="guilds"?ru.map(r=>{var l,m;return{data:r,label:`${r!=null&&r.steward?"مباشر":"صنف"} ${r==null?void 0:r.guildsName} ${(l=r==null?void 0:r.user)==null?void 0:l.fullname} (${(m=r==null?void 0:r.user)==null?void 0:m.mobile})`}}):au.map(r=>{var l,m;return{data:r,label:`${(r==null?void 0:r.name)||""} - ${((l=r==null?void 0:r.user)==null?void 0:l.fullname)||""} (${((m=r==null?void 0:r.user)==null?void 0:m.mobile)||""})`}}),onChange:(r,l)=>{var x,p,pu,Au,xu,wu,Fu,bu,ju,vu,ku,Su;c==="guilds"?(P({item:l==null?void 0:l.data,key:(x=l==null?void 0:l.data)==null?void 0:x.key,allocationType:(p=l==null?void 0:l.data)!=null&&p.steward?"killhouse_steward":"killhouse_guild",buyerType:(pu=l==null?void 0:l.data)!=null&&pu.steward?"Steward":"Guild"}),e.setFieldValue("mobile",(xu=(Au=l==null?void 0:l.data)==null?void 0:Au.user)==null?void 0:xu.mobile)):c==="stewards"&&(P({item:l==null?void 0:l.data,key:(wu=l==null?void 0:l.data)==null?void 0:wu.key,allocationType:"killhouse_steward",buyerType:"Steward"}),e.setFieldValue("mobile",(bu=(Fu=l==null?void 0:l.data)==null?void 0:Fu.user)==null?void 0:bu.mobile)),e.setFieldTouched("mobile",!0,!1),e.validateField("mobile");const m=new RegExp(/^09\d{9}$/);(vu=(ju=l==null?void 0:l.data)==null?void 0:ju.user)!=null&&vu.mobile&&!m.test((Su=(ku=l==null?void 0:l.data)==null?void 0:ku.user)==null?void 0:Su.mobile)&&du(!0)},renderInput:r=>t.jsx(V,{fullWidth:!0,...r,label:c==="guilds"?"انتخاب صنف":"انتخاب مباشر"})})})()}),!F&&!s&&(n==null?void 0:n.key)&&t.jsxs(w,{container:!0,direction:"column",alignItems:"flex-start",p:1,gap:K.TINY,sx:{border:2,borderColor:"#e6e6e6",borderRadius:2,width:"100%",boxSizing:"border-box"},children:[t.jsxs(G,{variant:"caption",color:"error",children:[t.jsx(ge,{sx:{ml:-1.25},checked:Z,onChange:()=>du(!Z)}),c==="stewards"?"از این قسمت میتوانید تلفن مباشر را ویرایش کنید.":c==="guilds"?"از این قسمت میتوانید تلفن صنف را ویرایش کنید.":"از این قسمت میتوانید تلفن مباشر/صنف را ویرایش کنید."]}),Z&&t.jsx(V,{id:"mobile",value:e.values.mobile,error:e.touched.mobile?!!e.errors.mobile:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.mobile&&e.errors.mobile?e.errors.mobile:null,label:"موبایل",autoComplete:"current-password",variant:"outlined"})]}),!F&&!s&&(d==null?void 0:d.active)!==!1&&t.jsx(L,{label:"نوع فروش",children:t.jsx(R,{fullWidth:!0,children:t.jsxs(W,{row:!0,"aria-labelledby":"segment-type-radio-group",name:"segmentType",value:v,onChange:Du,sx:{justifyContent:"space-between"},children:[t.jsx(b,{value:!0,control:t.jsx(j,{}),label:"قیمت دولتی"}),t.jsx(b,{value:!1,control:t.jsx(j,{}),label:"قیمت آزاد",disabled:M})]})})}),!F&&!s&&t.jsx(L,{label:"نوع انبار",children:t.jsx(R,{fullWidth:!0,children:t.jsxs(W,{row:!0,"aria-labelledby":"segment-type-radio-group",name:"segmentType",value:S,onChange:Ku,sx:{justifyContent:"space-between"},children:[t.jsx(b,{value:"governmental",control:t.jsx(j,{}),label:"دولتی"}),t.jsx(b,{value:"free",control:t.jsx(j,{}),label:"آزاد",disabled:M})]})})}),t.jsxs(w,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:K.TINY,sx:{width:"100%"},direction:"column",children:[t.jsx(be,{onDateSelect:Iu,dayData:cu,selectedDate:Ou,maxGregorianDate:f,label:`تاریخ تولید گوشت ${C!==null?`(موجودی: ${C==null?void 0:C.toLocaleString()} کیلوگرم)`:""}`}),y&&f&&g(y).isAfter(g(f),"day")&&t.jsx(G,{sx:{color:"#d32f2f",fontSize:"0.75rem",marginTop:"4px",marginRight:"14px",textAlign:"right"},children:"تاریخ تولید نمی‌تواند بعد از تاریخ انتخابی باشد"})]}),t.jsx(D,{allowLeadingZeros:!0,thousandSeparator:",",decimalScale:0,allowNegative:!1,fullWidth:!0,id:"weight",label:"وزن لاشه",variant:"outlined",value:e.values.weight,error:!C&&!y?!0:e.touched.weight?!!e.errors.weight:C&&e.values.weight>C,onChange:u=>{const a=u.target.value;if(a===""||a===null||a===void 0){e.setFieldValue("weight","");return}const r=Math.floor(Number(a));r>0?e.setFieldValue("weight",r):r===0&&e.setFieldValue("weight","")},onBlur:e.handleBlur,helperText:!C&&!y?"لطفاً ابتدا تاریخ تولید را انتخاب کنید!":e.touched.weight&&e.errors.weight?e.errors.weight:null,disabled:!C&&!y,sx:{"& .MuiFormHelperText-root":{color:C&&e.values.weight>C?"error.main":void 0}}}),t.jsx(D,{allowLeadingZeros:!0,thousandSeparator:",",fullWidth:!0,id:"price",label:"قیمت هر کیلوگرم",variant:"outlined",InputProps:{endAdornment:t.jsx(Pu,{position:"start",children:"ریال"})},value:e.values.price,error:e.touched.price?!!e.errors.price:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.price&&e.errors.price?e.errors.price:null,disabled:v==="true"&&(d==null?void 0:d.active)}),t.jsx(D,{disabled:!0,allowLeadingZeros:!0,thousandSeparator:",",fullWidth:!0,id:"wholePrice",label:"هزینه کل",variant:"outlined",InputProps:{endAdornment:t.jsx(Pu,{position:"start",children:"ریال"})},value:e.values.wholePrice,error:e.touched.wholePrice?!!e.errors.wholePrice:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.wholePrice&&e.errors.wholePrice?e.errors.wholePrice:null}),(eu||s&&s.image)&&t.jsxs(w,{container:!0,xs:12,justifyContent:"center",alignItems:"center",children:[t.jsx(xe,{onChange:ee,images:ou,maxNumber:1,title:"بارگزاری سند"}),e.touched.image&&!!e.errors.image&&t.jsx(G,{color:"error",children:"ثبت تصویر الزامی است"})]}),t.jsxs(w,{container:!0,xs:12,spacing:K.SMALL,children:[t.jsx(w,{xs:6,children:t.jsx(Nu,{variant:"contained",fullWidth:!0,disabled:s?!e.isValid:!e.isValid||(T?!1:!su)||!c||!k||!((fu=n==null?void 0:n.item)!=null&&fu.key)||!y||y&&f&&g(y).isAfter(g(f),"day"),onClick:()=>{var a,r,l,m,x;let u={};uu?u={allocation_key:uu,number_of_carcasses:0,weight_of_carcasses:e.values.weight,amount:e.values.price,role_key:h("slaughter")&&(o==null?void 0:o.key)||"",total_amount:e.values.wholePrice,distribution_type:"web",...O&&{image:e.values.image}}:s?u={allocation_key:s==null?void 0:s.key,number_of_carcasses:0,role_key:h("slaughter")&&(o==null?void 0:o.key)||"",weight_of_carcasses:e.values.weight,amount:e.values.price,total_amount:e.values.wholePrice,distribution_type:"web",...O&&{image:e.values.image}}:(u={seller_type:E,buyer_type:n==null?void 0:n.buyerType,guild_key:(n==null?void 0:n.buyerType)==="Guild"?(a=n==null?void 0:n.item)==null?void 0:a.key:null,steward_key:(n==null?void 0:n.buyerType)==="Steward"?(r=n==null?void 0:n.item)==null?void 0:r.key:null,kill_house_key:(n==null?void 0:n.buyerType)==="KillHouse"?(l=n==null?void 0:n.item)==null?void 0:l.key:null,cold_house_key:T||null,product_key:T?null:su.key,type:"manual",allocation_type:T?"ColdHouse":n==null?void 0:n.allocationType,role_key:h("slaughter")&&(o==null?void 0:o.key)||"",number_of_carcasses:0,weight_of_carcasses:e.values.weight,sell_type:Wu,amount:e.values.price,total_amount:e.values.wholePrice,approved_price_status:v==="true",quota:S,date:f,production_date:y,distribution_type:"web",...((x=(m=n==null?void 0:n.item)==null?void 0:m.user)==null?void 0:x.mobile)!==e.values.mobile?{interface_number:e.values.mobile}:{},...ou.length>0&&{image:e.values.image}},u=Object.fromEntries(Object.entries(u).filter(([,p])=>p!==null))),s?A(fe(u)).then(p=>{p.payload.error?z({vertical:"top",horizontal:"center",msg:p.payload.error,severity:"error"}):yu()}):A(ye(u)).then(p=>{p.payload.error?z({vertical:"top",horizontal:"center",msg:p.payload.error,severity:"error"}):yu()})},children:s?"ویرایش":"ثبت"})}),t.jsx(w,{xs:6,children:t.jsx(Nu,{fullWidth:!0,variant:"outlined",color:"primary",onClick:()=>{A(Tu({right:!1,bottom:!1,content:null}))},children:"انصراف"})})]})]})};export{Ge as S,We as s};