2 lines
18 KiB
JavaScript
2 lines
18 KiB
JavaScript
import{a as Zu,u as Uu}from"./redux-vendor-B7uoacJt.js";import{L as Hu,j as Vu,h as Tu,e8 as E,v as g,A as Xu,X as Ju,fF as Qu,c as Ku,M as ou,fI as Iu,b as gu,u as ue,G as T,W as ee,S as fu,N as Mu,C as te,fH as re}from"./index-N50kY0pn.js";import{j as t,b as nu,ak as J,I as xu,c6 as se,b0 as ae,aJ as Pu,c7 as le,T as z,C as oe,a3 as X,al as Yu,ag as pu,ah as Au,ai as L,aj as $,aX as ne,aa as Ru,B as Nu}from"./mui-vendor-CkIVaoQP.js";import{r as l}from"./react-vendor-CmFgShSM.js";import{N as yu}from"./NumberFormatCustom-DwWPj40N.js";import{c as ie,s as ce,a as de}from"./slaughter-get-guilds-for-allocate-vpZQhgy1.js";import{I as he,f as Ce}from"./toBase64-7xJ86bMI.js";import{a as me}from"./province-policy-upload-image-D2EGPJ2q.js";import{L as bu}from"./LabelField-Mkfcpni4.js";const je=Zu("SLAUGHTER_INVENTORY_FINAL_SUBMIT_SERVICE",async(y,{dispatch:x})=>{x(Hu());try{const{data:b,status:G}=await Vu.put("steward-allocation/0/",y);return x(Tu()),{data:b,status:G}}catch(b){return x(Tu()),{error:b.response.data.result}}}),ge=({onDateSelect:y,dayData:x={},selectedDate:b=null,label:G="انتخاب تاریخ",className:iu="",disableToday:cu=!1,maxGregorianDate:O=null,customDateFilter:D=null})=>{const[a,n]=l.useState(new E),[M,Q]=l.useState([]),[q,N]=l.useState(null),f=l.useRef(null),K=!!q,I=()=>{N(f.current)},Z=()=>{N(null)},uu=["فروردین","اردیبهشت","خرداد","تیر","مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند"],P=["ش","ی","د","س","چ","پ","ج"],eu=s=>x[s]||null,k=s=>{const c=s.format("YYYY/MM/DD");if(D)return D(s,c,x);const j=new E,Y=new E().subtract("day",2),w=new E().subtract("day",1),v=j.format("YYYY/MM/DD"),C=Y.format("YYYY/MM/DD"),m=w.format("YYYY/MM/DD"),S=cu?!1:c===v;let _=!1;if(O){const h=s.toDate?s.toDate():new Date;_=g(h).isAfter(g(O),"day")}const W=x[c]!==void 0&&(x[c].active===void 0||x[c].active===!0);return!_&&(S||c===C||c===m||W)};l.useEffect(()=>{(()=>{const c=[],j=a.year(),Y=a.month(),w=a.daysInMonth();let C=new E([j,Y,1]).day();C>=1&&C<=7&&(C=C-1),C=C%7;for(let m=0;m<C;m++)c.push(null);for(let m=1;m<=w;m++){const S=new E([j,Y,m]),_=new E,V=k(S),W=S.format("YYYY/MM/DD"),h=eu(W),au=V&&h&&h.value1===0;c.push({date:S,day:m,formattedDate:W,isToday:S.year()===_.year()&&S.month()===_.month()&&S.date()===_.date(),isEnabled:V,hasZeroValue:au})}Q(c)})()},[a,x]);const tu=s=>{s&&s.isEnabled&&!s.hasZeroValue&&y&&(y(s),Z())},ru=()=>{const s=new E([a.year(),a.month()+1,1]);n(s)},du=()=>{const s=new E([a.year(),a.month()-1,1]);n(s)},U=s=>b&&b===s,su=s=>s==null?"":s.toLocaleString("fa-IR"),hu=()=>{if(!b)return"";const s=M.find(c=>c&&c.formattedDate===b);return s?`${s.day.toLocaleString("fa-IR")} ${uu[s.date.month()-1]}`:b};return t.jsxs(nu,{className:iu,sx:{width:"100%"},children:[t.jsx(J,{ref:f,fullWidth:!0,value:hu(),onClick:I,label:G,placeholder:"انتخاب تاریخ...",size:"medium",InputProps:{readOnly:!0,startAdornment:t.jsx(xu,{size:"small",onClick:I,children:t.jsx(se,{fontSize:"small"})})},sx:{cursor:"pointer",width:"100%",fontSize:{xs:"13px",sm:"16px"}}}),t.jsx(ae,{open:K,anchorEl:q,onClose:Z,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},children:t.jsxs(Pu,{elevation:3,sx:{p:{xs:1,sm:2},borderRadius:3,backgroundColor:"#fff",maxWidth:500,width:"99%"},children:[t.jsxs(nu,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:{xs:1,sm:2},pb:{xs:1,sm:2},borderBottom:"2px solid #f0f0f0"},children:[t.jsx(xu,{onClick:du,size:"small",children:t.jsx(le,{})}),t.jsxs(z,{variant:"h6",sx:{fontWeight:"bold",color:"#333",fontSize:{xs:"16px",sm:"20px"}},children:[uu[a.month()-1]," ",a.year()]}),t.jsx(xu,{onClick:ru,size:"small",children:t.jsx(oe,{})})]}),t.jsx(X,{container:!0,spacing:{xs:.5,sm:1},sx:{mb:{xs:.5,sm:1}},children:P.map((s,c)=>t.jsx(X,{item:!0,xs:12/7.3,children:t.jsx(nu,{sx:{textAlign:"center",fontWeight:"bold",color:"#666",fontSize:{xs:"12px",sm:"14px"},py:{xs:.5,sm:1}},children:s})},c))}),t.jsx(X,{container:!0,spacing:{xs:.5,sm:1},children:M.map((s,c)=>{if(!s)return t.jsx(X,{item:!0,xs:12/7.3,children:t.jsx(nu,{sx:{aspectRatio:"1/1"}})},`empty-${c}`);const j=eu(s.formattedDate),Y=U(s.formattedDate);let w="#fff",v="#e0e0e0",C=1,m="pointer";return!s.isEnabled||s.hasZeroValue?(w="#f5f5f5",v="#d0d0d0",C=s.hasZeroValue?.4:.25,m="not-allowed"):Y&&(w="#e3f2fd",v="#1976d2"),s.isToday&&s.isEnabled&&!s.hasZeroValue&&(v="#ff9800"),t.jsx(X,{item:!0,xs:12/7.3,children:t.jsxs(Pu,{onClick:()=>tu(s),sx:{aspectRatio:"1/1",cursor:m,transition:"all 0.2s ease",backgroundColor:w,border:{xs:`1.5px solid ${v}`,sm:`2px solid ${v}`},display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",p:{xs:.5,sm:1},gap:{xs:.25,sm:.5},opacity:C,"&:hover":s.isEnabled&&!s.hasZeroValue?{transform:"scale(1.05)",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",backgroundColor:"#f5f5f5"}:{}},children:[t.jsx(z,{variant:"body1",sx:{fontWeight:"bold",fontSize:{xs:"16px",sm:"20px"},color:s.isToday?"#ff9800":"#333",lineHeight:1.2},children:s.day.toLocaleString("fa-IR")}),j&&j.value1!==void 0&&t.jsx(z,{variant:"caption",sx:{fontSize:{xs:"10px",sm:"13px"},color:"#1976d2",fontWeight:"600",lineHeight:1.2},children:su(j.value1)})]})},c)})})]})})]})},Se=({item:y,key:x,sellerType:b,buyerType:G,allocationType:iu,sellType:cu,updateTable:O,fetchApiData:D,editData:a,priceInfo:n,coldHouseKey:M,coldHouseItemKey:Q,killHouseAllocation:q,disableFreeOptions:N=!1})=>{var Eu;const f=Uu(),[K,I]=l.useState([]),[Z,uu]=l.useState([]),[P,eu]=l.useState("governmental"),[k,tu]=l.useState("true"),[ru,du]=l.useState(null),[U]=l.useContext(Xu),[su,hu]=l.useState(a!=null&&a.image?[{data_url:a.image}]:[]),[s,c]=l.useState("own"),[j,Y]=l.useState(1),[w,v]=l.useState(!1),[C,m]=l.useState(!1),[S,_]=l.useState(null),[V,W]=l.useState({}),[h,au]=l.useState(null),[d,Cu]=l.useState(null),[H,Wu]=l.useState({governmental:[],free:[]}),[p,Lu]=l.useState(g(new Date).format("YYYY-MM-DD")),[wu,mu]=l.useState(null),$u=u=>{c(u.target.value),ju({key:"",item:"",buyerType:"",allocationType:""})},zu=u=>{const r=u.target.value;eu(r)},Gu=u=>{const r=u.target.value;tu(r),r==="false"&&e.setFieldValue("price","")},Ou=u=>{if(u&&u.formattedDate){_(u.formattedDate);const r=V[u.formattedDate];if(r&&r.originalDay&&au(r.originalDay),r&&(r.amount!==void 0||r.value1!==void 0)){const i=r.amount!==void 0?r.amount:r.value1,F=Number(typeof i=="string"?i.replace(/,/g,""):i);Cu(Number.isFinite(F)?F:null)}else Cu(null)}},vu=l.useCallback(u=>{if(!Array.isArray(u))return{};const r={};return u.forEach(i=>{if(i.day&&i.amount!==void 0){const R=new E(new Date(i.day)).format("YYYY/MM/DD"),B=i.amount,A=Number(typeof B=="string"?B.replace(/,/g,""):B);r[R]={value1:A,originalDay:i.day,active:i.active===!0}}}),r},[]),lu=l.useCallback(u=>{const r=vu(u);W(r)},[vu]),Fu=l.useCallback(async()=>{try{const u=await Vu.get("/kill-house-remain-weight/",{params:{date:p}});if(u.data){Wu({governmental:u.data.governmental||[],free:u.data.free||[]});const r=P==="governmental"?u.data.governmental:u.data.free;lu(r)}}catch(u){console.error("Error fetching calendar data:",u)}},[P,lu,p]),[o,ju]=l.useState({key:x,item:y,buyerType:G,allocationType:iu});l.useEffect(()=>{Ju()==="Steward"&&c("free"),Fu()},[Fu]),l.useEffect(()=>{if(H.governmental.length>0||H.free.length>0){const u=P==="governmental"?H.governmental:H.free;lu(u),_(null),au(null),Cu(null)}},[P,H,lu]),l.useEffect(()=>{f(me()).then(u=>{var r;(r=u.payload)!=null&&r.data&&Y(u.payload.data.killHouseAllocation)}),a||(f(Qu()).then(u=>{I(u.payload.data)}),y||f(ie({free:s==="free"})).then(u=>{uu(u.payload.data)}))},[f,s]);const Du=Ku({mobile:ou().when([],{is:()=>!a,then:u=>u.required("شماره موبایل الزامی است").min(11,"شماره موبایل باید 11 رقم باشد").max(11,"شماره موبایل باید 11 رقم باشد").matches(/^09\d{9}$/,"شماره موبایل باید با 09 شروع شود و 11 رقم باشد"),otherwise:u=>u.notRequired()}),weight:gu().required("این فیلد اجباری است!").integer("عدد باید صحیح باشد!").min(1,"یک مقدار مثبت وارد کنید!").test("max-production-date-amount",`وزن نمیتواند بیشتر از موجودی تاریخ تولید (${(d==null?void 0:d.toLocaleString())||0} کیلوگرم) باشد!`,function(u){return!d||d===null?!0:u<=d}),price:gu().required("این فیلد اجباری است!").min(1,"یک مقدار مثبت وارد کنید!"),wholePrice:gu().required("این فیلد اجباری است!").min(1,"یک مقدار مثبت وارد کنید!"),date:Iu().test("date-not-before-production","تاریخ نمیتواند قبل از تاریخ تولید باشد",function(u){return!h||!u?!0:g(u).isSameOrAfter(g(h),"day")}),...q&&{image:ou().when([],{is:()=>(!a||w)&&j>0,then:ou().required("عکس الزامی است"),otherwise:ou().notRequired()})}}),qu=u=>{var r;u[0]?(e.setFieldValue("image",Ce((r=u[0])==null?void 0:r.data_url)),v(!0)):(e.setFieldValue("image",""),v(!0)),hu(u)},e=ue({initialValues:{mobile:"",weight:(a==null?void 0:a.realWeightOfCarcasses)||"",wholePrice:(a==null?void 0:a.totalAmount)||"",price:(a==null?void 0:a.amount)||"",image:(a==null?void 0:a.image)||"",date:p},validationSchema:Du});l.useEffect(()=>{e.validateForm()},[d,h]),l.useEffect(()=>{e.setFieldValue("date",p)},[p]),l.useEffect(()=>{(n==null?void 0:n.active)===!1&&tu("false")},[n==null?void 0:n.active]),l.useEffect(()=>{k==="true"&&(n!=null&&n.active)&&e.setFieldValue("price",n==null?void 0:n.killHousePrice)},[k]),l.useEffect(()=>{k==="true"&&(n!=null&&n.active)?e.values.weight&&e.setFieldValue("wholePrice",(n==null?void 0:n.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,k]);const Su=()=>{f(te()),U({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),f(re()),f(Mu({right:!1,bottom:!1,left:!1,content:null})),O&&O(),D&&D()};return t.jsxs(T,{container:!0,xs:12,direction:"column",justifyContent:"center",alignItems:"flex-start",gap:1.8,children:[!a&&t.jsx(ee,{label:"تاریخ ثبت توزیع",id:"date",renderInput:u=>t.jsx(J,{fullWidth:!0,...u,error:!!wu||u.error,helperText:wu||u.helperText}),shouldDisableDate:u=>{const r=g(u),i=g();return!r.isSame(i,"day")},value:p,onChange:u=>{if(!u){mu(null);return}const r=g(u),i=g(),F=g().subtract(1,"day");if(!(r.isSame(i,"day")||r.isSame(F,"day"))){mu("تنها امکان انتخاب «امروز» یا «دیروز» وجود دارد.");return}mu(null),Lu(g(u).format("YYYY-MM-DD"))}}),!a&&!M&&t.jsx(T,{xs:12,container:!0,children:t.jsx(Yu,{fullWidth:!0,disablePortal:!0,id:"hatching",options:K?K.map(u=>({data:u,label:`${u.name}`})):[],onChange:(u,r)=>{du(r.data)},renderInput:u=>t.jsx(J,{fullWidth:!0,...u,label:"انتخاب محصول"})})}),!a&&t.jsx(bu,{label:"خریداران",children:t.jsx(pu,{fullWidth:!0,children:t.jsxs(Au,{row:!0,"aria-labelledby":"demo-controlled-radio-buttons-group",name:"controlled-radio-buttons-group",value:s,onChange:$u,sx:{justifyContent:"space-between"},children:[t.jsx(L,{value:"own",control:t.jsx($,{}),label:"صنوف اختصاصی"}),t.jsx(L,{value:"free",control:t.jsx($,{}),label:"صنوف آزاد",disabled:N})]})})}),!y&&!a&&t.jsx(T,{xs:12,container:!0,children:t.jsx(Yu,{fullWidth:!0,disablePortal:!0,id:"hatching",options:Z?Z.map(u=>{var r,i;return{data:u,label:`${u!=null&&u.steward?"مباشر":"صنف"} ${u==null?void 0:u.guildsName} ${(r=u==null?void 0:u.user)==null?void 0:r.fullname} (${(i=u==null?void 0:u.user)==null?void 0:i.mobile})`}}):[],onChange:(u,r)=>{var F,R,B,A,ku,_u,Bu;ju({item:r==null?void 0:r.data,key:(F=r==null?void 0:r.data)==null?void 0:F.key,allocationType:(R=r==null?void 0:r.data)!=null&&R.steward?"killhouse_steward":"killhouse_guild",buyerType:(B=r==null?void 0:r.data)!=null&&B.steward?"Steward":"Guild"}),e.setFieldValue("mobile",(ku=(A=r==null?void 0:r.data)==null?void 0:A.user)==null?void 0:ku.mobile),e.setFieldTouched("mobile",!0,!1),e.validateField("mobile"),new RegExp(/^09\d{9}$/).test((Bu=(_u=r==null?void 0:r.data)==null?void 0:_u.user)==null?void 0:Bu.mobile)||m(!0)},renderInput:u=>t.jsx(J,{fullWidth:!0,...u,label:"انتخاب مباشر / صنف"})})}),!y&&!a&&t.jsxs(T,{container:!0,xs:12,alignItems:"center",justifyContent:"center",p:1,gap:fu.TINY,sx:{border:2,borderColor:"#e6e6e6",borderRadius:2},children:[t.jsxs(z,{variant:"caption",color:"error",children:[t.jsx(ne,{sx:{ml:-1.25},checked:C,onChange:()=>m(!C)}),"از این قسمت میتوانید تلفن مباشر/صنف را ویرایش کنید."]}),(o==null?void 0:o.key)&&C&&t.jsx(J,{fullWidth:!0,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"})]}),!y&&!a&&(n==null?void 0:n.active)!==!1&&t.jsx(bu,{label:"نوع فروش",children:t.jsx(pu,{fullWidth:!0,children:t.jsxs(Au,{row:!0,"aria-labelledby":"segment-type-radio-group",name:"segmentType",value:k,onChange:Gu,sx:{justifyContent:"space-between"},children:[t.jsx(L,{value:!0,control:t.jsx($,{}),label:"قیمت دولتی"}),t.jsx(L,{value:!1,control:t.jsx($,{}),label:"قیمت آزاد",disabled:N})]})})}),!y&&!a&&t.jsx(bu,{label:"نوع انبار",children:t.jsx(pu,{fullWidth:!0,children:t.jsxs(Au,{row:!0,"aria-labelledby":"segment-type-radio-group",name:"segmentType",value:P,onChange:zu,sx:{justifyContent:"space-between"},children:[t.jsx(L,{value:"governmental",control:t.jsx($,{}),label:"دولتی"}),t.jsx(L,{value:"free",control:t.jsx($,{}),label:"آزاد",disabled:N})]})})}),t.jsxs(T,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:fu.TINY,sx:{width:"100%"},direction:"column",children:[t.jsx(ge,{onDateSelect:Ou,dayData:V,selectedDate:S,maxGregorianDate:p,label:`تاریخ تولید گوشت ${d!==null?`(موجودی: ${d==null?void 0:d.toLocaleString()} کیلوگرم)`:""}`}),h&&p&&g(h).isAfter(g(p),"day")&&t.jsx(z,{sx:{color:"#d32f2f",fontSize:"0.75rem",marginTop:"4px",marginRight:"14px",textAlign:"right"},children:"تاریخ تولید نمیتواند بعد از تاریخ انتخابی باشد"})]}),t.jsx(yu,{allowLeadingZeros:!0,thousandSeparator:",",decimalScale:0,allowNegative:!1,fullWidth:!0,id:"weight",label:"وزن لاشه",variant:"outlined",value:e.values.weight,error:!d&&!h?!0:e.touched.weight?!!e.errors.weight:d&&e.values.weight>d,onChange:u=>{const r=u.target.value;if(r===""||r===null||r===void 0){e.setFieldValue("weight","");return}const i=Math.floor(Number(r));i>0?e.setFieldValue("weight",i):i===0&&e.setFieldValue("weight","")},onBlur:e.handleBlur,helperText:!d&&!h?"لطفاً ابتدا تاریخ تولید را انتخاب کنید!":e.touched.weight&&e.errors.weight?e.errors.weight:null,disabled:!d&&!h,sx:{"& .MuiFormHelperText-root":{color:d&&e.values.weight>d?"error.main":void 0}}}),t.jsx(yu,{allowLeadingZeros:!0,thousandSeparator:",",fullWidth:!0,id:"price",label:"قیمت هر کیلوگرم",variant:"outlined",InputProps:{endAdornment:t.jsx(Ru,{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:k==="true"&&(n==null?void 0:n.active)}),t.jsx(yu,{disabled:!0,allowLeadingZeros:!0,thousandSeparator:",",fullWidth:!0,id:"wholePrice",label:"هزینه کل",variant:"outlined",InputProps:{endAdornment:t.jsx(Ru,{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}),(q||a&&a.image)&&t.jsxs(T,{container:!0,xs:12,justifyContent:"center",alignItems:"center",children:[t.jsx(he,{onChange:qu,images:su,maxNumber:1,title:"بارگزاری سند"}),e.touched.image&&!!e.errors.image&&t.jsx(z,{color:"error",children:"ثبت تصویر الزامی است"})]}),t.jsxs(T,{container:!0,xs:12,spacing:fu.SMALL,children:[t.jsx(T,{xs:6,children:t.jsx(Nu,{variant:"contained",fullWidth:!0,disabled:a?!e.isValid:!e.isValid||(M?!1:!ru)||!((Eu=o==null?void 0:o.item)!=null&&Eu.key)||!h||h&&p&&g(h).isAfter(g(p),"day"),onClick:()=>{var r,i,F,R,B;let u={};Q?u={allocation_key:Q,number_of_carcasses:0,weight_of_carcasses:e.values.weight,amount:e.values.price,total_amount:e.values.wholePrice,distribution_type:"web",...w&&{image:e.values.image}}:a?u={allocation_key:a==null?void 0:a.key,number_of_carcasses:0,weight_of_carcasses:e.values.weight,amount:e.values.price,total_amount:e.values.wholePrice,distribution_type:"web",...w&&{image:e.values.image}}:(u={seller_type:b,buyer_type:o==null?void 0:o.buyerType,guild_key:(o==null?void 0:o.buyerType)==="Guild"?(r=o==null?void 0:o.item)==null?void 0:r.key:null,steward_key:(o==null?void 0:o.buyerType)==="Steward"?(i=o==null?void 0:o.item)==null?void 0:i.key:null,kill_house_key:(o==null?void 0:o.buyerType)==="KillHouse"?(F=o==null?void 0:o.item)==null?void 0:F.key:null,cold_house_key:M||null,product_key:M?null:ru.key,type:"manual",allocation_type:M?"ColdHouse":o==null?void 0:o.allocationType,number_of_carcasses:0,weight_of_carcasses:e.values.weight,sell_type:cu,amount:e.values.price,total_amount:e.values.wholePrice,approved_price_status:k==="true",quota:P,date:p,production_date:h,distribution_type:"web",...((B=(R=o==null?void 0:o.item)==null?void 0:R.user)==null?void 0:B.mobile)!==e.values.mobile?{interface_number:e.values.mobile}:{},...su.length>0&&{image:e.values.image}},u=Object.fromEntries(Object.entries(u).filter(([,A])=>A!==null))),a?f(de(u)).then(A=>{A.payload.error?U({vertical:"top",horizontal:"center",msg:A.payload.error,severity:"error"}):Su()}):f(ce(u)).then(A=>{A.payload.error?U({vertical:"top",horizontal:"center",msg:A.payload.error,severity:"error"}):Su()})},children:a?"ویرایش":"ثبت"})}),t.jsx(T,{xs:6,children:t.jsx(Nu,{fullWidth:!0,variant:"outlined",color:"primary",onClick:()=>{f(Mu({right:!1,bottom:!1,content:null}))},children:"انصراف"})})]})]})};export{ge as M,Se as S,je as s};
|