2 lines
8.5 KiB
JavaScript
2 lines
8.5 KiB
JavaScript
import{j as e,ak as v,B as M,I as G,aX as U,aa as X,b2 as $,b3 as R,aL as q,aM as J,aN as Q,b as Z}from"./mui-vendor-CkIVaoQP.js";import{B as ee}from"./BackButton-CX1bfrW9.js";import{L as f,j as E,h as A,A as T,u as ue,c as ae,M as te,G as g,C as z,O as B,X as ne,k as se,S as W}from"./index-Vwb3Bce5.js";import{r as p}from"./react-vendor-CmFgShSM.js";import{a as b,u as D}from"./redux-vendor-B7uoacJt.js";import{d as re}from"./Edit-CwJaslma.js";import{R as S}from"./ResponsiveTable-DugzNG82.js";import{p as oe}from"./province-policy-wages-edit-killhouse-B0xEaQ0F.js";import{d as Y}from"./Save-SBgvd7Mw.js";import"./FilterAlt-CTDmPS36.js";import"./styled-components.browser.esm-gS9mh05b.js";const le=b("PROVINCE_POLICY_GET_WAGE_FRACTIONS",async(r,{dispatch:u})=>{u(f());const{data:a,status:o}=await E.get("wage-type/");return u(A()),{data:a,status:o}}),ce=b("PROVINCE_POLICY_CREATE_WAGE",async(r,{dispatch:u})=>{try{u(f());const{data:a,status:o}=await E.post("share-type/",r);return u(A()),{data:a,status:o}}catch(a){return u(A()),{error:a.response.data.result}}}),ie=b("PROVINCE_POLICY_EDIT_SHARE_TYPE",async(r,{dispatch:u})=>{try{u(f());const{data:a,status:o}=await E.put("share-type/"+r.id+"/",{name:r.name});return u(A()),{data:a,status:o}}catch(a){return u(A()),{error:a.response.data.result}}}),V=({fetchData:r,item:u,itsEdit:a,fetchDataShareTypes:o})=>{const[w]=p.useContext(T),y=D(),i=ue({initialValues:{wageName:u!=null&&u.name?u==null?void 0:u.name:""},validationSchema:ae({wageName:te().typeError("لطفا فیلد را به درستی وارد کنید.!")})});return p.useEffect(()=>{i.validateForm()},[]),e.jsxs(g,{container:!0,xs:12,gap:2,children:[e.jsx(g,{xs:12,children:e.jsx(v,{id:"wageName",label:"عنوان نقش",variant:"outlined",sx:{width:"100%"},value:i.values.wageName,error:i.touched.wageName?!!i.errors.wageName:null,onChange:i.handleChange,onBlur:i.handleBlur,helperText:i.touched.wageName&&i.errors.wageName?i.errors.wageName:null})}),e.jsx(g,{xs:12,children:e.jsx(M,{variant:"contained",disabled:!i.isValid,onClick:()=>{a?y(ie({name:i.values.wageName,id:u==null?void 0:u.id})).then(x=>{r(),o(),y(z()),x.payload.error?w({vertical:"top",horizontal:"center",msg:x.payload.error,severity:"error"}):w({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})}):y(ce({name:i.values.wageName})).then(x=>{r(),o(),y(z()),x.payload.error?w({vertical:"top",horizontal:"center",msg:x.payload.error,severity:"error"}):w({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})})},children:"ثبت"})})]})},de=b("PROVINCE_POLICY_EDIT_WAGE",async(r,{dispatch:u})=>{try{u(f());const{data:a,status:o}=await E.put("wage-type/0/",r);return u(A()),{data:a,status:o}}catch(a){return u(A()),{error:a.response.data.result}}}),Ce=b("PROVINCE_POLICY_GET_SHARE_TYPE",async(r,{dispatch:u})=>{u(f());const{data:a,status:o}=await E.get("share-type/");return u(A()),{data:a,status:o}}),pe=b("PROVINCE_POLICY_WAGES_SETUP_GET_KILLHOUSES",async(r,{dispatch:u})=>{u(f());const{data:a,status:o}=await E.get("kill_house/?gate-way-kill-houses=true/");return u(A()),{data:a,status:o}}),he=()=>{const[r]=p.useContext(T),u=D(),[a,o]=p.useState(),[w,y]=p.useState(),i=()=>{u(pe()).then(l=>{o(l.payload.data)})};p.useEffect(()=>{i()},[]);const x=l=>parseInt(l==null?void 0:l.companyGatewayPercent)+parseInt(l.unionGatewayPercent)+parseInt(l.guildsGatewayPercent)+parseInt(l.otherGatewayPercent)>100;p.useEffect(()=>{const l=a==null?void 0:a.map((t,n)=>{var m,F;return[n+1,t==null?void 0:t.name,(F=(m=t==null?void 0:t.killHouseOperator)==null?void 0:m.user)==null?void 0:F.mobile,e.jsx(v,{style:{width:"160px"},label:"سهم شرکت",value:t.companyGatewayPercent,onChange:h=>I(h,n),size:"small"},n),e.jsx(v,{style:{width:"160px"},label:"سهم اتحادیه",value:t.unionGatewayPercent,onChange:h=>_(h,n),size:"small"},n),e.jsx(v,{style:{width:"160px"},label:"سهم صنف",value:t.guildsGatewayPercent,onChange:h=>j(h,n),size:"small"},n),e.jsx(v,{style:{width:"160px"},label:"سهم دیگر",value:t.otherGatewayPercent,onChange:h=>N(h,n),size:"small"},n),e.jsx(G,{disabled:x(t),color:"primary",onClick:()=>{u(oe({kill_house_key:t==null?void 0:t.key,company_gateway_percent:parseInt(t==null?void 0:t.companyGatewayPercent),union_gateway_percent:parseInt(t.unionGatewayPercent),guilds_gateway_percent:parseInt(t.guildsGatewayPercent),other_gateway_percent:parseInt(t.otherGatewayPercent)})).then(h=>{h.payload.error?r({vertical:"top",horizontal:"center",msg:h.payload.error,severity:"error"}):(i(),r({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}))})},children:e.jsx(Y,{})},n)]});y(l)},[a]);const I=(l,t)=>{const n=[...a];n[t].companyGatewayPercent=Number(l.target.value),o(n)},_=(l,t)=>{const n=[...a];n[t].unionGatewayPercent=Number(l.target.value),o(n)},j=(l,t)=>{const n=[...a];n[t].guildsGatewayPercent=Number(l.target.value),o(n)},N=(l,t)=>{const n=[...a];n[t].otherGatewayPercent=Number(l.target.value),o(n)};return e.jsx(g,{container:!0,alignItems:"center",justifyContent:"center",children:e.jsx(S,{paginated:!0,title:"بر اساس کشتارگاه",columns:["ردیف","نام کشتارگاه","موبایل","سهم شرکت","سهم اتحادیه","سهم صنف","سهم دیگر","ذخیره تغییرات"],data:w})})},ye=()=>{const r=D(),[u,a]=p.useState(),[o,w]=p.useState(),[y,i]=p.useState(),[x,I]=p.useState(),[_]=p.useContext(T),[j,N]=p.useState(0),l=(d,C)=>{N(C)},t=()=>{r(le()).then(d=>{a(d.payload.data)})},n=()=>{r(Ce()).then(d=>{i(d.payload.data)})};p.useEffect(()=>{j===0&&(t(),n())},[r,j]),p.useEffect(()=>{const d=u==null?void 0:u.map((s,c)=>{var k;return[c+1,s.name,e.jsx(U,{checked:s.status,onChange:P=>h(P,c,s),inputProps:{"aria-label":"controlled"}},c),e.jsx(v,{style:{width:{xs:"80px",lg:"120px"}},label:"مبلغ تعرفه",value:s.amount,disabled:!s.status,onChange:P=>F(P,c),size:"small",InputProps:{endAdornment:e.jsx(X,{position:"end",children:"ریال"})}},c),e.jsx(g,{container:!0,alignItems:"center",justifyContent:"center",gap:1,children:(k=s==null?void 0:s.percentages)==null?void 0:k.map((P,L)=>e.jsx(v,{disabled:!s.status,style:{width:{xs:"80px",lg:"100px"}},label:P.name,value:P.percent,onChange:K=>m(K,c,L),size:"small"},L))},c),e.jsx(G,{disabled:H(c)||!s.status,color:"primary",onClick:()=>O(s),children:e.jsx(Y,{})},c)]});I(d);const C=y==null?void 0:y.map((s,c)=>[c+1,s==null?void 0:s.name,e.jsx(G,{"aria-label":"delete",color:"primary",onClick:()=>{r(B({title:"ویرایش نقش",content:e.jsx(V,{itsEdit:!0,fetchData:t,fetchDataShareTypes:n,item:s})}))},children:e.jsx(re,{})},c)]);w(C)},[u,y]);const m=(d,C,s)=>{const c=[...u];c[C].percentages[s].percent=Number(d.target.value),a(c)},F=(d,C)=>{const s=[...u];s[C].amount=Number(d.target.value),a(s)},h=(d,C,s)=>{const c=[...u];c[C].status=!c[C].status,a(c,O(s))},H=d=>{if(u[d].percentages.length){let C=0;return u[d].percentages.forEach(s=>{C+=s.percent}),C!==100}},O=d=>{r(de(d)).then(C=>{t(),C.payload.error?_({vertical:"top",horizontal:"center",msg:C.payload.error,severity:"error"}):_({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})})};return e.jsxs(g,{container:!0,alignItems:"center",justifyContent:"center",children:[ne()==="AdminX"&&e.jsxs($,{scrollButtons:"auto",variant:"scrollable",allowScrollButtonsMobile:!0,value:j,onChange:l,children:[e.jsx(R,{label:"سهامداران"}),e.jsx(R,{label:"نوع تسویه"})]}),j===0&&e.jsx(e.Fragment,{children:e.jsxs(g,{container:!0,mb:2,children:[e.jsx(M,{variant:"contained",onClick:()=>{r(B({title:"افزودن نقش",content:e.jsx(V,{fetchData:t,fetchDataShareTypes:n})}))},children:"افزودن نقش"}),e.jsx(g,{xs:12,mt:2,children:e.jsxs(q,{children:[e.jsx(J,{expandIcon:e.jsx(se,{}),"aria-controls":"panel1-content",id:"panel1-header",children:"سهامداران"}),e.jsx(Q,{children:e.jsx(S,{paginated:!0,columns:["ردیف","نام","ویرایش"],data:o,title:"سهامداران"})})]})}),e.jsx(S,{paginated:!0,title:"تعرفه ها",columns:["ردیف","عنوان","وضعیت","مبلغ تعرفه","سهم بندی","ذخیره تغییرات"],data:x})]})}),j===1&&e.jsx(he,{})]})},me=()=>e.jsx(e.Fragment,{children:e.jsx(Z,{display:"flex",justifyContent:"center",children:e.jsxs(g,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[e.jsx(ee,{}),e.jsx(g,{container:!0,justifyContent:"space-between",gap:W.SMALL,children:e.jsx(g,{mt:W.SMALL,xs:12,children:e.jsx(ye,{})})})]})})});export{me as default};
|