Files
Rasadyar_FrontEnd/build/assets/SlaughterManageInventoryAllocationOperations-CAkldXdj.js
2026-01-19 15:55:00 +03:30

2 lines
9.8 KiB
JavaScript

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