Files
Rasadyar_FrontEnd/build/assets/SlaughterManageInventoryAllocationOperations-P9wf5kfn.js

2 lines
10 KiB
JavaScript

import{j as e,an as V,ao as eu,aj as tu,ak as au,al as Y,am as z,T as ou,B as w,I as xu,b3 as vu,aq as Au,b7 as Fu,as as ju,at as Su}from"./mui-vendor-D_SVL-Dx.js";import{r}from"./react-vendor-CmFgShSM.js";import{d as ku}from"./Tune-BBzxV8DK.js";import{A as lu,et as wu,j as bu,c as _u,b as Eu,v as d,u as Du,g2 as Bu,g3 as Tu,G as y,$ as Lu,C as b,g4 as nu,ad as Pu,O as G,S as ru}from"./index-D80MdVQn.js";import{d as Mu}from"./CheckCircleOutline-fmBK9poN.js";import{d as Yu}from"./Delete-CIwpNviU.js";import{u as su,f as iu}from"./redux-vendor-CfkcHgWN.js";import{S as zu,s as Wu}from"./SlaughterAllocateToGuild-CeWc5BWf.js";import{s as Ou,a as $u,b as Nu}from"./slaughter-allocate-steward-CCu9314u.js";import{N as Ru}from"./NumberFormatCustom-BXcOcGV4.js";import{M as Vu}from"./MonthlyDataCalendar-_xfuL-Zd.js";import{c as F}from"./checkPathStartsWith-DedybDvj.js";import{L as Gu}from"./LabelField-BYhJrYEE.js";const Hu=({sellerType:A,sellType:s,updateTable:_,fetchApiData:E,editData:o,remainWeight:m,priceInfo:g})=>{const f=su(),[x,D]=r.useState([]),[j,B]=r.useState(null),[C,W]=r.useState([]),[T,O]=r.useState(null),[p,c]=r.useState("governmental"),[v,cu]=r.useState((g==null?void 0:g.active)!==!1),a=iu(u=>u.userSlice.selectedSubUser),[$]=r.useContext(lu),[Cu,H]=r.useState(null),[I,du]=r.useState({}),[L,q]=r.useState(null),[n,N]=r.useState(null),[S,hu]=r.useState({governmental:[],free:[]}),K=r.useCallback(u=>{if(!Array.isArray(u))return{};const t={};return u.forEach(l=>{if(l.day&&l.amount!==void 0){const U=new wu(new Date(l.day)).format("YYYY/MM/DD");t[U]={value1:l.amount,originalDay:l.day,active:l.active===!0}}}),t},[]),P=r.useCallback(u=>{const t=K(u);du(t)},[K]),k=r.useCallback(async u=>{try{const t=await bu.get("/kill-house-remain-weight/",{params:{date:u,role_key:F("slaughter")&&(a==null?void 0:a.key)||""}});if(t.data){hu({governmental:t.data.governmental||[],free:t.data.free||[]});const l=p==="governmental"?t.data.governmental:t.data.free;P(l)}}catch(t){console.error("Error fetching calendar data:",t)}},[p,P,a]),yu=u=>{if(u&&u.formattedDate){H(u.formattedDate);const t=I[u.formattedDate];if(t&&t.originalDay){const l=t.originalDay;if(h&&d(l).isAfter(d(h),"day")){Q("تاریخ تولید نمی‌تواند بعد از تاریخ انتخابی باشد");return}Q(null),q(l)}t&&t.value1!==void 0?N(t.value1):N(null)}},gu=r.useCallback(()=>_u({weight:Eu().required("این فیلد اجباری است!").integer("عدد باید صحیح باشد!").min(1,"یک مقدار مثبت وارد کنید!").max(m+((o==null?void 0:o.realWeightOfCarcasses)||0),"وزن وارد شده بیش از موجودی انبار است!").test("max-production-date-amount",`وزن نمی‌تواند بیشتر از موجودی تاریخ تولید (${(n==null?void 0:n.toLocaleString())||0} کیلوگرم) باشد!`,function(u){return!n||n===null?!0:u<=n})}),[m,o,n])(),[h,pu]=r.useState(d(new Date).format("YYYY-MM-DD")),[Z,R]=r.useState(null),[J,Q]=r.useState(null),i=Du({initialValues:{weight:(o==null?void 0:o.realWeightOfCarcasses)||""},validationSchema:gu}),X=()=>{f(b()),$({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),f(nu({role_key:F("slaughter")&&(a==null?void 0:a.key)||""})),E(),_()},fu=u=>{const t=u.target.value;c(t)},mu=u=>{const t=u.target.value;cu(t)};return r.useEffect(()=>{o||(f(Bu({role_key:F("slaughter")&&(a==null?void 0:a.key)||""})).then(u=>{D(u.payload.data)}),f(Tu({role_key:F("slaughter")&&(a==null?void 0:a.key)||""})).then(u=>{W(u.payload.data)})),k(h)},[f,o,k,h,a==null?void 0:a.key]),r.useEffect(()=>{k(h)},[h,k,a==null?void 0:a.key]),r.useEffect(()=>{if(S.governmental.length>0||S.free.length>0){const u=p==="governmental"?S.governmental:S.free;P(u),H(null),q(null),N(null)}},[p,S,P]),r.useEffect(()=>{i.validateForm()},[n]),e.jsxs(y,{container:!0,xs:12,direction:"column",justifyContent:"center",alignItems:"center",gap:1,children:[!o&&e.jsx(Lu,{label:"تاریخ",id:"date",renderInput:u=>e.jsx(V,{fullWidth:!0,...u,error:!!Z||u.error,helperText:Z||u.helperText}),shouldDisableDate:u=>{const t=d(u),l=d(),M=d().subtract(1,"day");return!(t.isSame(l,"day")||t.isSame(M,"day"))},value:h,onChange:u=>{if(!u){R(null);return}const t=d(u),l=d(),M=d().subtract(1,"day");if(!(t.isSame(l,"day")||t.isSame(M,"day"))){R("تنها امکان انتخاب «امروز» یا «دیروز» وجود دارد.");return}R(null);const uu=d(u).format("YYYY-MM-DD");pu(uu),k(uu)}}),!o&&e.jsx(y,{xs:12,container:!0,children:e.jsx(eu,{fullWidth:!0,style:{minWidth:210},disablePortal:!0,id:"hatching",options:x?x.map(u=>({data:u,label:`${u.name}`})):[],onChange:(u,t)=>{B(t.data)},renderInput:u=>e.jsx(V,{fullWidth:!0,...u,label:"انتخاب محصول"})})}),!o&&e.jsx(y,{xs:12,container:!0,children:e.jsx(eu,{fullWidth:!0,style:{minWidth:210},disablePortal:!0,id:"hatching",options:C?C.map(u=>({data:u,label:`${u.name}`})):[],onChange:(u,t)=>{var l;O((l=t.data)==null?void 0:l.key)},renderInput:u=>e.jsx(V,{fullWidth:!0,...u,label:"انتخاب سردخانه"})})}),!o&&(g==null?void 0:g.active)&&e.jsx(tu,{children:e.jsxs(au,{row:!0,"aria-labelledby":"segment-type-radio-group",name:"segmentType",value:v,onChange:mu,children:[e.jsx(Y,{value:!0,control:e.jsx(z,{}),label:"قیمت دولتی"}),e.jsx(Y,{value:!1,control:e.jsx(z,{}),label:"قیمت آزاد"})]})}),!o&&e.jsx(y,{my:1,xs:12,children:e.jsx(Gu,{label:"نوع انبار",children:e.jsx(tu,{children:e.jsxs(au,{row:!0,"aria-labelledby":"segment-type-radio-group",name:"segmentType",value:p,onChange:fu,children:[e.jsx(Y,{value:"governmental",control:e.jsx(z,{}),label:"دولتی"}),e.jsx(Y,{value:"free",control:e.jsx(z,{}),label:"آزاد"})]})})})}),!o&&e.jsxs(y,{style:{width:"100%"},container:!0,xs:12,lg:3,justifyContent:"center",alignItems:"center",mb:3,mt:2,gap:1,children:[e.jsx(Vu,{onDateSelect:yu,dayData:I,selectedDate:Cu,maxGregorianDate:h,label:`تاریخ تولید گوشت ${n!==null?`(موجودی: ${n==null?void 0:n.toLocaleString()} کیلوگرم)`:""}`}),J&&e.jsx(ou,{sx:{color:"#d32f2f",fontSize:"0.75rem",marginTop:"4px",marginRight:"14px",textAlign:"right"},children:J})]}),e.jsx(Ru,{allowLeadingZeros:!0,thousandSeparator:",",decimalScale:0,allowNegative:!1,fullWidth:!0,id:"weight",disabled:m<1,label:"وزن لاشه",variant:"outlined",value:i.values.weight,error:m<1?!0:i.touched.weight?!!i.errors.weight:n&&i.values.weight>n,onChange:u=>{const t=u.target.value;if(t===""||t===null||t===void 0){i.setFieldValue("weight","");return}const l=Math.floor(Number(t));l>0?i.setFieldValue("weight",l):l===0&&i.setFieldValue("weight","")},onBlur:i.handleBlur,helperText:m<1?"موجودی انبار خالی است!":n&&i.values.weight>n?`وزن نمی‌تواند بیشتر از موجودی تاریخ تولید (${n==null?void 0:n.toLocaleString()} کیلوگرم) باشد!`:i.touched.weight&&i.errors.weight?i.errors.weight:null}),e.jsx(w,{variant:"contained",fullWidth:!0,disabled:o?!i.isValid:!i.isValid||!j||!T||!L||n&&i.values.weight>n||L&&h&&d(L).isAfter(d(h),"day"),onClick:()=>{let u={};o?u={weight_of_carcasses:i.values.weight,allocation_key:o==null?void 0:o.key,distribution_type:"web",role_key:F("slaughter")&&(a==null?void 0:a.key)||""}:u={seller_type:A,product_key:j.key,type:"manual",number_of_carcasses:0,weight_of_carcasses:i.values.weight,approved_price_status:v==="true",quota:p,sell_type:s,buyer_type:"ColdHouse",cold_house_key:T,role_key:F("slaughter")&&(a==null?void 0:a.key)||"",allocation_type:"ColdHouse",date:h,production_date:L,distribution_type:"web"},o?f($u(u)).then(t=>{t.payload.error?$({vertical:"top",horizontal:"center",msg:t.payload.error,severity:"error"}):X()}):f(Ou(u)).then(t=>{t.payload.error?$({vertical:"top",horizontal:"center",msg:t.payload.error,severity:"error"}):X()})},children:"ثبت"})]})},le=({fetchApiData:A,item:s,priceInfo:_,remainWeight:E})=>{const[o,m]=r.useState(null),g=iu(c=>{var v;return(v=c==null?void 0:c.userSlice)==null?void 0:v.selectedSubUser}),f=c=>{m(c.currentTarget)},x=()=>{m(null)},D=!!o,j=D?"popover":void 0,[B]=r.useContext(lu),C=su(),W=()=>{x(),C(G({title:"ویرایش تخصیص",content:(s==null?void 0:s.allocationType)==="ColdHouse"?e.jsx(Hu,{fetchApiData:A,editData:s,priceInfo:_,remainWeight:E}):e.jsx(zu,{fetchApiData:A,editData:s,priceInfo:_,remainWeight:E})}))},T=()=>{x(),C(G({title:"ثبت نهایی",content:e.jsxs(y,{container:!0,gap:ru.SMALL,children:[e.jsx(ou,{children:"در صورت ثبت نهایی انجام هیچگونه عملیاتی مانند حذف و ویرایش امکان پذیر نمی باشد."}),e.jsxs(y,{container:!0,direction:"column",gap:ru.TINY,width:"100%",children:[e.jsx(w,{fullWidth:!0,variant:"contained",onClick:()=>{C(Wu({steward_allocation_list:[s==null?void 0:s.key]})).then(c=>{C(b()),c.payload.error?B({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(A(1),B({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:"تایید"}),e.jsx(w,{fullWidth:!0,color:"error",variant:"contained",onClick:()=>{C(b())},children:"لغو"})]})]})}))},O=()=>{x(),C(G({title:"آیا مطمئن هستید؟",content:e.jsxs(y,{container:!0,spacing:2,children:[e.jsx(y,{item:!0,children:e.jsx(w,{variant:"contained",color:"error",onClick:()=>{C(Nu({steward_allocation_key:s.key})).then(()=>{C(b()),C(nu({role_key:(g==null?void 0:g.key)||""})),A(1)})},children:"تایید"})}),e.jsx(y,{item:!0,children:e.jsx(w,{onClick:()=>{C(b())},children:"لغو"})})]})}))},p=[{key:"edit",label:"ویرایش",icon:Pu,color:"primary.main",action:W}];return s!=null&&s.registrationCode||p.push({key:"finalSubmit",label:"تایید نهایی",icon:Mu,color:"info.main",action:T}),s!=null&&s.registrationCode||p.push({key:"delete",label:"حذف",icon:Yu,color:"error.main",action:O}),e.jsxs(y,{container:!0,children:[e.jsx(xu,{size:"small",disabled:s==null?void 0:s.registrationCode,"aria-describedby":j,variant:"contained",color:"primary",onClick:f,children:e.jsx(ku,{})}),e.jsx(vu,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:j,open:D,anchorEl:o,onClose:x,children:e.jsx(Au,{sx:{minWidth:160,p:.5},children:p.map(c=>{const v=c.icon;return e.jsxs(Fu,{onClick:c.action,sx:{borderRadius:1,mb:.25,py:.5,"&:last-of-type":{mb:0}},children:[e.jsx(ju,{sx:{minWidth:32,color:c.color},children:e.jsx(v,{fontSize:"small"})}),e.jsx(Su,{primary:c.label,primaryTypographyProps:{sx:{color:c.color,fontSize:"0.82rem",fontWeight:600}}})]},c.key)})})})]})};export{le as S,Hu as a};