Files
Rasadyar_FrontEnd/build/assets/StewardSegmentOperation-B4ydd22p.js
2026-01-19 15:40:45 +03:30

4 lines
12 KiB
JavaScript

import{a as g,u as G}from"./redux-vendor-B7uoacJt.js";import{L as y,j as C,h as i,X as v,A as Q,G as _,S as Z,N as b,u as le,c as ie,e8 as ce,M as P,b as de}from"./index-CeyyVc1v.js";import{j as t,al as K,ak as k,ar as Ce,B as D,ag as V,ah as z,ai as T,aj as L,aa as he,I as ge,b0 as ye,an as me,ao as Y,b4 as H,ap as q,T as X}from"./mui-vendor-CkIVaoQP.js";import{r as l}from"./react-vendor-CmFgShSM.js";import{M as pe}from"./SlaughterAllocateToGuild-Dfz5LRq5.js";import{L as J}from"./LabelField-B6eRSoQP.js";import{d as Se}from"./Tune-D4M2CAhp.js";import{d as fe}from"./EditOutlined-n5ie2Fmu.js";import{d as Ee}from"./DeleteOutlineOutlined-G071NcE9.js";const Ue=g("SLAUGHTER_GET_BUYER_SERVICE",async(a,{dispatch:u})=>{u(y());const{data:e,status:n}=await C.get("base-out-province-carcasses-buyer/?mobile="+a);return u(i()),{data:e,status:n}}),$e=g("SLAUGHTER_SUBMIT_BUYER_SERVICE",async(a,{dispatch:u})=>{try{u(y());const{data:e,status:n}=await C.post("out-province-carcasses-buyer/",a);return u(i()),{data:e,status:n}}catch(e){return u(i()),{error:e.response.data.result}}}),Ne=g("SLAUGHTER_EDIT_BUYER_SERVICE",async(a,{dispatch:u})=>{try{u(y());const{data:e,status:n}=await C.put("out-province-carcasses-buyer/0/",a);return u(i()),{data:e,status:n}}catch(e){return u(i()),{error:e.response.data.result}}}),Me=g("SLAUGHTER_SUBMIT_OUT_OF_PROVINCE_SELL",async(a,{dispatch:u})=>{try{u(y());const{data:e,status:n}=await C.post("kill_house_free_sale_bar/",a);return u(i()),{data:e,status:n}}catch(e){return u(i()),{error:e.response.data.result}}}),We=g("GUILD_SUBMIT_OUT_OF_PROVINCE_SELL",async(a,{dispatch:u})=>{try{u(y());const{data:e,status:n}=await C.post("steward_free_sale_bar/",a);return u(i()),{data:e,status:n}}catch(e){return u(i()),{error:e.response.data.result}}}),Pe=g("SLAUGHTER_GET_PRICE_SERVICE",async(a,{dispatch:u})=>{u(y());const{data:e,status:n}=await C.get("broadcast-price/",{params:{...a}});return u(i()),{data:e,status:n}}),_e=g("SLAUGHTER_GET_GUILDS_FOR_COMMONLY_USED",async(a,{dispatch:u})=>{u(y());const{data:e,status:n}=await C.get("guilds/",{params:{role:v(),commonly_used:!0,...a}});return u(i()),{data:e,status:n}}),we=g("SLAUGHTER_ADD_DAILY_LIST_SERVICE",async(a,{dispatch:u})=>{u(y());const{data:e,status:n}=await C.post("commonly-used/",{role:v(),guild_key_list:a.guild_key_list,...a});return u(i()),{data:e,status:n}}),Ve=g("SUBMIT_BATCH_ALLOCATIONS",async(a,{dispatch:u})=>{u(y());try{return(await C.post("batch-steward-allocation/",{allocations_list:a})).data}finally{u(i())}}),ze=g("SLAUGHTER_DELETE_DAILY_LIST_SERVICE",async(a,{dispatch:u})=>{u(y());const{data:e,status:n}=await C.delete(`commonly-used/0/?commonly_used_key=${a}`);return u(i()),{data:e,status:n}}),Ye=({updateTable:a})=>{const[u]=l.useContext(Q),e=G(),[n,d]=l.useState([]),[m,w]=l.useState([]);l.useEffect(()=>{(async()=>{e(_e()).then(S=>{d(S.payload.data)})})()},[e]);const x=()=>{e(we({guild_key_list:m.map(o=>o.key)})).then(o=>{o.payload.error?u({vertical:"top",horizontal:"center",msg:"خطا در ثبت لیست",severity:"error"}):(u({vertical:"top",horizontal:"center",msg:"لیست با موفقیت ثبت شد.",severity:"success"}),e(b({right:!1,bottom:!1,content:null})),a(1))})},E=o=>{w(S=>S.filter(p=>p.key!==o))};return t.jsxs(_,{container:!0,direction:"column",gap:Z.SMALL,children:[t.jsx(K,{multiple:!0,disablePortal:!0,id:"guilds-select",options:n,renderTags:()=>null,getOptionLabel:o=>{var S,p;return`${o.steward?"مباشر":"صنف"} ${o.name||o.guildsName}
${((S=o.user)==null?void 0:S.fullname)||""}
(${((p=o.user)==null?void 0:p.mobile)||""})`},onChange:(o,S)=>{w(S)},sx:{width:"250px"},renderInput:o=>t.jsx(k,{...o,fullWidth:!0,label:"انتخاب مباشر / صنف",placeholder:"انتخاب کنید"})}),t.jsx(_,{container:!0,direction:"column",gap:1,children:m.map(o=>t.jsx(Ce,{label:`${o.steward?"مباشر":"صنف"} ${o.name||o.guildsName}`,onDelete:()=>E(o.key),sx:{width:"fit-content"}},o.key))}),t.jsx(D,{variant:"contained",onClick:x,disabled:m.length===0,children:"ثبت"})]})},He=g("STEWRD_GET_OUT_SELL_SERVICE",async(a,{dispatch:u})=>{u(y());const{data:e,status:n}=await C.get("roles-products/?role="+v());return u(i()),{data:e,status:n}}),xe=g("STEWARD_DELETE_SEGMENT",async(a,{dispatch:u})=>{u(y());try{const{data:e,status:n}=await C.delete(`app-segmentation/0/?key=${a}`);return u(i()),{data:e,status:n}}catch(e){return u(i()),{error:e}}}),Ae=g("STEWARD_SUBMIT_SEGMANT",async(a,{dispatch:u})=>{try{u(y());const{data:e,status:n}=await C.post("app-segmentation/",a);return u(i()),{data:e,status:n}}catch(e){return u(i()),{error:e.response.data.result}}}),be=g("STEWARD_GET_SEGMANT_ROLE_SERVICE",async(a,{dispatch:u})=>{u(y());const{data:e,status:n}=await C.get("guilds/?&all=true",{params:{...a}});return u(i()),{data:e,status:n}}),ve=g("STEWARD_EDIT_SEGMENT_SERVICE",async(a,{dispatch:u})=>{var e,n;u(y());try{const{data:d,status:m}=await C.put("app-segmentation/0/",a);return u(i()),{data:d,status:m}}catch(d){return u(i()),{error:(n=(e=d.response)==null?void 0:e.data)==null?void 0:n.result}}}),je=a=>ie().shape({weight:de().required("وزن لاشه الزامی است").min(.01,"وزن باید بیشتر از 0 باشد").test("max-production-date-amount",`وزن نمی‌تواند بیشتر از موجودی تاریخ تولید (${(a==null?void 0:a.toLocaleString())||0} کیلوگرم) باشد!`,function(u){return!a||a===null?!0:u<=a}),product_key:P().when("segmentType",{is:"own",then:P().required("انتخاب کلید الزامی است")})}),Te=({updateTable:a,productKey:u,editData:e,item:n})=>{const d=G(),[m]=l.useContext(Q),[w,x]=l.useState([]),[E,o]=l.useState("own"),[S]=l.useState("free"),[p,ee]=l.useState("governmental"),[B,O]=l.useState(null),[ue,U]=l.useState(null),[$,te]=l.useState({}),[F,N]=l.useState(null),[h,R]=l.useState(null),[A,re]=l.useState({governmental:[],free:[]}),f=le({initialValues:{product_key:u||(e==null?void 0:e.productkey)||"",weight:(e==null?void 0:e.weight)||"",segmentType:e&&e!=null&&e.guildkey?"free":"own"},validationSchema:je(h),onSubmit:r=>{if(e){const s={weight:r.weight,key:n==null?void 0:n.key};d(ve(s)).then(c=>{var I;(I=c.payload)!=null&&I.error?m({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(d(b({right:!1,bottom:!1,content:null})),a(),m({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})}else{let s;if(E==="own")s={product_key:r==null?void 0:r.product_key,weight:r.weight,sale_type:S,quota:p,production_date:F,distribution_type:"web"};else{if(!B){m({vertical:"top",horizontal:"center",msg:"لطفا مباشر یا صنف را انتخاب کنید",severity:"error"});return}s={guild_key:B.key,weight:r.weight,product_key:u||"",sale_type:S,quota:p,production_date:F,distribution_type:"web"}}d(Ae(s)).then(c=>{c.payload.error?m({vertical:"top",horizontal:"center",msg:c.payload.error,severity:"error"}):(d(b({right:!1,bottom:!1,content:null})),a(),m({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})}}}),ae=r=>{const s=r.target.value;o(s),f.setFieldValue("segmentType",s)},ne=r=>{const s=r.target.value;ee(s)},se=r=>{if(r&&r.formattedDate){U(r.formattedDate);const s=$[r.formattedDate];s&&s.originalDay&&N(s.originalDay),s&&s.value1!==void 0?R(s.value1):R(null)}},M=l.useCallback(r=>{if(!Array.isArray(r))return{};const s={};return r.forEach(c=>{if(c.day&&c.amount!==void 0){const oe=new ce(new Date(c.day)).format("YYYY/MM/DD");s[oe]={value1:c.amount,originalDay:c.day,active:c.active===!0}}}),s},[]),j=l.useCallback(r=>{const s=M(r);te(s)},[M]),W=l.useCallback(async()=>{try{const r=await C.get(`/${v()==="Steward"?"steward":"kill-house"}-remain-weight/`);if(r.data){re({governmental:r.data.governmental||[],free:r.data.free||[]});const s=p==="governmental"?r.data.governmental:r.data.free;j(s)}}catch(r){console.error("Error fetching calendar data:",r)}},[p,j]);return l.useEffect(()=>{e||d(be({role:v()})).then(r=>{x(r.payload.data)}),W()},[d,e,W]),l.useEffect(()=>{if(A.governmental.length>0||A.free.length>0){const r=p==="governmental"?A.governmental:A.free;j(r),U(null),N(null),R(null)}},[p,A,j]),l.useEffect(()=>{f.validateForm()},[h]),t.jsx(_,{container:!0,direction:"column",justifyContent:"center",gap:2,children:t.jsx(_,{container:!0,direction:"column",justifyContent:"center",gap:2,pt:2,children:t.jsxs("form",{onSubmit:f.handleSubmit,style:{display:"flex",flexDirection:"column",gap:Z.LARGE+4},children:[!e&&t.jsx(J,{label:"قطعه بندی (کاربر)",children:t.jsx(V,{children:t.jsxs(z,{row:!0,"aria-labelledby":"segment-type-radio-group",name:"segmentType",value:E,onChange:ae,sx:{justifyContent:"space-between"},children:[t.jsx(T,{value:"own",control:t.jsx(L,{}),label:"قطعه بندی (کاربر)"}),t.jsx(T,{value:"free",control:t.jsx(L,{}),label:"تخصیص به قطعه بند"})]})})}),!e&&E==="free"&&t.jsx(_,{xs:12,container:!0,children:t.jsx(K,{fullWidth:!0,style:{minWidth:210},disablePortal:!0,id:"steward-select",options:w?w.map(r=>{var s,c;return{data:r,label:`${r!=null&&r.steward?"مباشر":"صنف"} ${r==null?void 0:r.guildsName} ${(s=r==null?void 0:r.user)==null?void 0:s.fullname} (${(c=r==null?void 0:r.user)==null?void 0:c.mobile})`}}):[],onChange:(r,s)=>{var c;O(s?{item:s==null?void 0:s.data,key:(c=s==null?void 0:s.data)==null?void 0:c.key}:null)},renderInput:r=>t.jsx(k,{fullWidth:!0,...r,label:"انتخاب مباشر / صنف",required:E==="free"})})}),!e&&t.jsx(J,{label:"نوع انبار",children:t.jsx(V,{children:t.jsxs(z,{row:!0,"aria-labelledby":"segment-type-radio-group",name:"segmentType",value:p,onChange:ne,sx:{justifyContent:"space-between"},children:[t.jsx(T,{value:"governmental",control:t.jsx(L,{}),label:"دولتی"}),t.jsx(T,{value:"free",control:t.jsx(L,{}),label:"آزاد"})]})})}),!e&&t.jsx(_,{style:{width:"100%"},container:!0,xs:12,lg:3,justifyContent:"center",alignItems:"center",gap:1,children:t.jsx(pe,{onDateSelect:se,dayData:$,selectedDate:ue,label:`تاریخ تولید گوشت ${h!==null?`(موجودی: ${h==null?void 0:h.toLocaleString()} کیلوگرم)`:""}`})}),t.jsx(k,{id:"weight",name:"weight",label:"وزن لاشه",type:"number",InputProps:{endAdornment:t.jsx(he,{position:"end",children:"کیلوگرم"})},value:f.values.weight,onChange:f.handleChange,onBlur:f.handleBlur,error:f.touched.weight&&!!f.errors.weight||h&&f.values.weight>h,helperText:h&&f.values.weight>h?`وزن نمی‌تواند بیشتر از موجودی تاریخ تولید (${h==null?void 0:h.toLocaleString()} کیلوگرم) باشد!`:f.touched.weight&&f.errors.weight,fullWidth:!0}),t.jsxs(_,{container:!0,spacing:2,children:[t.jsx(_,{xs:6,children:t.jsx(D,{type:"submit",fullWidth:!0,variant:"contained",color:"primary",disabled:!e&&(!F||h&&f.values.weight>h),children:e?"ویرایش":"ثبت"})}),t.jsx(_,{xs:6,children:t.jsx(D,{fullWidth:!0,variant:"outlined",color:"primary",onClick:()=>{d(b({right:!1,bottom:!1,content:null}))},children:"انصراف"})})]})]})})})},qe=({item:a,updateTable:u,productKey:e})=>{const n=G(),[d,m]=l.useState(null),w=p=>{m(p.currentTarget)},x=()=>{m(null)},E=!!d,o=E?"popover":void 0,S=()=>{x(),n(xe(a.key)).then(()=>{u()})};return t.jsxs("div",{children:[t.jsx(ge,{"aria-describedby":o,variant:"contained",color:"primary",onClick:w,children:t.jsx(Se,{})}),t.jsx(ye,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:o,open:E,anchorEl:d,onClose:x,children:t.jsxs(me,{sx:{p:1},children:[t.jsx(Y,{disablePadding:!0,children:t.jsxs(H,{sx:{color:"primary.main"},onClick:()=>{x(),n(b({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ویرایش قطعه بندی",content:t.jsx(Te,{item:a,updateTable:u,editData:a,productKey:e})}))},children:[t.jsx(q,{sx:{minWidth:36,color:"inherit"},children:t.jsx(fe,{fontSize:"small"})}),t.jsx(X,{variant:"body2",children:"ویرایش"})]})}),t.jsx(Y,{disablePadding:!0,children:t.jsxs(H,{sx:{color:"error.main"},onClick:S,children:[t.jsx(q,{sx:{minWidth:36,color:"inherit"},children:t.jsx(Ee,{fontSize:"small"})}),t.jsx(X,{variant:"body2",color:"inherit",children:"حذف"})]})})]})})]})};export{Ye as S,$e as a,Me as b,ze as c,Pe as d,Ve as e,He as f,We as g,qe as h,Te as i,Ue as j,Ne as s};