2 lines
32 KiB
JavaScript
2 lines
32 KiB
JavaScript
import{j as u,ag as bu,av as ku,aw as Mu,ax as W,aU as Nu,ak as L,B as I,i as K,$ as Bu,T as k,d as V,b5 as vu,I as G,b as X,a9 as eu,b0 as Su,al as _u,an as zu,ao as Uu,aq as Au,b4 as Wu,ap as Vu,ah as Gu,ai as pu,aj as xu,aA as ju}from"./mui-vendor-CkIVaoQP.js";import{G as p,S as T,ia as ru,ib as su,ic as tu,X as P,id as au,ie as nu,ig as lu,L as B,j as R,h as M,A as q,u as Eu,c as wu,M as ou,C as J,r as Q,p as Y,N as H,m as gu,ih as Hu,O as Z,b as fu,c5 as qu,ii as Yu,ij as Xu,ik as Ju,il as Ku,im as Qu,io as Zu}from"./index-CeyyVc1v.js";import{B as u0}from"./BackButton-Crzr7NMa.js";import{N as yu}from"./NavLink-D2GD_ItM.js";import{L as Fu}from"./LinkItem-DT6qswcs.js";import{p as e0,q as r0}from"./index.esm-BY9chGNa.js";import{f as Pu,r as c}from"./react-vendor-CmFgShSM.js";import{a as uu,u as z,f as s0}from"./redux-vendor-B7uoacJt.js";import{R as Du,a as t0}from"./index.esm-Bu7XMDZU.js";import{R as Tu}from"./ResponsiveTable-w7hk7Uq8.js";import{C as a0}from"./CreateGuilds-CCT3R9v5.js";import{d as Ou}from"./Tune-D4M2CAhp.js";import{d as n0}from"./Edit-CqBj1Y2L.js";import{A as l0}from"./AdvancedTable-BYmmBtmq.js";import{S as o0}from"./SimpleTable-DBAoNnCU.js";import{d as c0}from"./Info-CZK82--l.js";import{d as i0}from"./Delete-C5MyLelE.js";import{A as d0}from"./index-9Ymn_7Kv.js";import{d as C0}from"./Add--yVWBJhC.js";import{P as h0}from"./PspActiveSession-DQjcq8bm.js";import{L as A0}from"./LabelField-B6eRSoQP.js";import"./iconBase-BEJYyZsk.js";import"./FilterAlt-scT0HEUg.js";import"./styled-components.browser.esm-gS9mh05b.js";import"./Person-Q1IHBezR.js";import"./Phone-Dv2y8iMM.js";import"./Badge-u1S44abW.js";import"./Cake-CkaTUHNX.js";import"./Business-J-mGuLnc.js";import"./CheckCircle-zgBvZQ-b.js";import"./Done-Dp5awdte.js";import"./DialogAlert-BfXcr-Kr.js";import"./index-CIfb_iLp.js";import"./Close-_jAEIgMD.js";import"./Search-Dek2fED1.js";const p0=()=>{const{pathname:e}=Pu();return u.jsxs(p,{container:!0,gap:T.SMALL,p:T.SMALL,direction:{xs:"column",md:"row"},justifyContent:"center",children:[u.jsx(yu,{to:P()==="PosCompany"?ru:P()==="SuperAdmin"?su:P()==="AdminX"?tu:"",active:P()==="PosCompany"?e===ru:P()==="SuperAdmin"?e===su:P()==="AdminX"?e===tu:null,children:u.jsx(Fu,{icon:u.jsx(e0,{size:30,color:"#244CCC"}),title:"دستگاه ها"})}),u.jsx(yu,{to:P()==="PosCompany"?au:P()==="SuperAdmin"?nu:P()==="AdminX"?lu:null,active:P()==="PosCompany"?e===au:P()==="SuperAdmin"?e===nu:P()==="AdminX"?e===lu:null,children:u.jsx(Fu,{icon:u.jsx(r0,{size:30,color:"#244CCC"}),title:"نشست های فعال"})})]})},x0=uu("PSP_SUBMIT_GUILD_CONDITION",async(e,{dispatch:d})=>{try{d(B());const{data:x,status:o}=await R.put("total_guilds_for_companies/0/",e);return d(M()),{data:x,status:o}}catch(x){return d(M()),{error:x.response.data.result}}}),j0=({item:e,updateTable:d})=>{const[x]=c.useContext(q),o=z(),r=Eu({initialValues:{condition:e.condition?e.condition:"مرجوع شده",description:e.descriptionCondition?e.descriptionCondition:""},validationSchema:wu({description:ou().required("این فیلد اجباری است!").typeError("لطفا توضیحات را وارد کنید.")})});return c.useEffect(()=>{r.validateForm()},[]),u.jsxs(p,{container:!0,justifyContent:"center",alignItems:"center",children:[u.jsx(p,{xs:12,children:u.jsxs(bu,{sx:{minWidth:310},children:[u.jsx(ku,{id:"demo-simple-select-label",children:"وضعیت"}),u.jsxs(Mu,{className:"fullWidthSelect",sx:{minWidth:"100%"},fullWidth:!0,labelId:"demo-simple-select-label",id:"condition",label:"وضعیت",value:r.values.condition,error:r.touched.condition?!!r.errors.condition:null,onChange:g=>{r.setFieldValue("condition",g.target.value)},onBlur:r.handleBlur,children:[u.jsx(W,{value:"مرجوع شده",children:"مرجوع شده"}),u.jsx(W,{value:"در انتظار تعریف ترمینال",children:"در انتظار تعریف ترمینال"}),u.jsx(W,{value:"در انتظار تایید شاپرک",children:"در انتظار تایید شاپرک"}),u.jsx(W,{value:"در انتظار نصب",children:"در انتظار نصب"}),u.jsx(W,{value:"نصب شده",children:"نصب شده"}),u.jsx(W,{value:"غیر قابل نصب",children:"غیر قابل نصب"}),u.jsx(W,{value:"جمع آوری شده",children:"جمع آوری شده"})]}),u.jsx(Nu,{children:r.touched.condition&&r.errors.condition?r.errors.condition:null})]})}),u.jsx(p,{xs:12,children:u.jsx(L,{id:"description",name:"description",label:"توضیحات",variant:"outlined",multiline:!0,rows:4,fullWidth:!0,margin:"normal",value:r.values.description,onChange:r.handleChange,onBlur:r.handleBlur,helperText:r.touched.description&&r.errors.description?r.errors.description:null,error:r.touched.description&&!!r.errors.description})}),u.jsx(p,{children:u.jsx(I,{disabled:!r.isValid,variant:"contained",onClick:()=>{o(x0({guild_key:e.key,condition:r.values.condition,description_condition:r.values.description})).then(g=>{o(J()),d(),g.error?x({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است!",severity:"error"}):x({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})})},children:e.descriptionCondition?"ویرایش وضعیت":"ثبت وضعیت"})})]})},g0=uu("PSP_CHANGE_POS_ACTIVE_STATE",async(e,{dispatch:d})=>{try{d(B());const{data:x,status:o}=await R.put("/pos-machine/0/",e);return d(M()),{data:x,status:o}}catch(x){return d(M()),{error:x.response.data.result}}});var cu={},f0=K;Object.defineProperty(cu,"__esModule",{value:!0});var Iu=cu.default=void 0,y0=f0(Q()),F0=u;Iu=cu.default=(0,y0.default)((0,F0.jsx)("path",{d:"M20 2H4c-1.11 0-2 .89-2 2v11c0 1.11.89 2 2 2h4v5l4-2 4 2v-5h4c1.11 0 2-.89 2-2V4c0-1.11-.89-2-2-2m0 13H4v-2h16zm0-5H4V4h16z"}),"CardMembership");const m0=uu("PSP_REMOVE_SESSION",async(e,{dispatch:d})=>{d(B());const{data:x,status:o}=await R.delete("pos_register_session_inspection/0/?session_key="+e);return d(M()),{data:x,status:o}}),b0=({item:e,updateTable:d})=>{var _,m,f;const x=z(),[o]=c.useContext(q),[r,g]=c.useState(!1),[C,w]=c.useState(null),y=a=>{x(Z({title:"آیا مطمئن هستید؟",content:u.jsxs(p,{container:!0,spacing:2,justifyContent:"center",children:[u.jsx(p,{item:!0,children:u.jsx(I,{variant:"contained",color:"error",onClick:()=>{x(m0(a)).then(A=>{var F,l;if((F=A.payload)!=null&&F.error)o({vertical:"top",horizontal:"center",msg:A.payload.error,severity:"error"});else{d(),x(J());let s=(l=C==null?void 0:C.posSessions)==null?void 0:l.findIndex(v=>v.key===a);C==null||C.posSessions.splice(s,1),o({vertical:"top",horizontal:"center",msg:"نشست با موفقیت حذف شد",severity:"success"})}})},sx:{mx:1},children:"تایید حذف"})}),u.jsx(p,{item:!0,children:u.jsx(I,{variant:"outlined",onClick:()=>x(J()),sx:{mx:1},children:"انصراف"})})]})}))},S=Bu(),D=e==null?void 0:e.guildPos.map((a,A)=>{var F,l,s,v;return[A+1,a.receiverNumber||"-",a.terminalNumber||"-",a.serial||"-",a.posId||"-",a.password||"-",a.posCompany||"-",((F=a==null?void 0:a.posSessions)==null?void 0:F.length)>0?Y((l=a.posSessions[0])==null?void 0:l.sessionCreateDate):"-",((s=a==null?void 0:a.posSessions)==null?void 0:s.length)>0?Y((v=a.posSessions[0])==null?void 0:v.sessionLastSeenDate):"-",u.jsxs(k,{justifyContent:"center",variant:"body2",color:a.posStatus?"success.main":"error.main",sx:{display:"flex",alignItems:"center",gap:.5},children:[a!=null&&a.posStatus?"در حال استفاده":"خاموش",u.jsx(c0,{fontSize:"small"})]},A),u.jsx(I,{disabled:!(a!=null&&a.posSessions.length),size:"small",variant:"outlined",color:"info",startIcon:u.jsx(Iu,{}),onClick:()=>{w(a),g(!0)},sx:{borderRadius:2,px:2,py:.5,textTransform:"none"},children:"نمایش نشستها"},A),u.jsx(V,{title:a!=null&&a.active?"غیرفعال کردن":"فعال کردن",placement:"bottom-start",children:u.jsx(vu,{size:"small",checked:a.active,color:a.active?"success":"default",onChange:()=>{x(g0({pos_key:a.key,active:!a.active})).then(O=>{d(),x(H({top:!1,bottom:!1,content:null})),O.error?o({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است!",severity:"error"}):o({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"})})}})},A)]}),$=(m=(_=C==null?void 0:C.posSessions)==null?void 0:_.sort((a,A)=>{const F=new Date(a.sessionLastSeenDate||a.sessionCreateDate).getTime();return new Date(A.sessionLastSeenDate||A.sessionCreateDate).getTime()-F}))==null?void 0:m.map((a,A)=>{const F=new Date;F.setDate(F.getDate()-7);const s=new Date(a.sessionLastSeenDate||a.sessionCreateDate)>F;return[A+1,a.name||"-",a.serial||"-",u.jsx(k,{color:s?"success.main":"text.primary",children:Y(a.sessionCreateDate||"-")},`create-${A}`),u.jsx(k,{color:s?"success.main":"text.primary",children:Y(a.sessionLastSeenDate||"-")},`lastseen-${A}`),u.jsx(p,{container:!0,justifyContent:"center",children:u.jsx(V,{title:"حذف نشست",children:u.jsx(G,{color:"error",onClick:()=>{y(a.key)},children:u.jsx(i0,{})})})},A)]});return u.jsx(X,{children:u.jsx(d0,{mode:"wait",children:r?u.jsx(gu.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.3},children:u.jsx(eu,{elevation:0,sx:{p:3,borderRadius:4},children:u.jsxs(p,{xs:12,container:!0,justifyContent:"center",children:[u.jsxs(p,{xs:12,container:!0,alignItems:"center",justifyContent:"space-between",sx:{mb:3},children:[u.jsx(I,{variant:"outlined",color:"primary",onClick:()=>{g(!1)},startIcon:u.jsx(Hu,{}),sx:{borderRadius:2,px:3,textTransform:"none"},children:"بازگشت به لیست"}),u.jsxs(k,{variant:"body1",sx:{color:"text.primary"},children:[u.jsx(X,{component:"span",color:"primary.main",children:"نشستهای فعال دستگاه"})," ",C==null?void 0:C.receiverNumber]})]}),u.jsx(p,{xs:12,container:!0,justifyContent:"center",children:u.jsx(eu,{elevation:0,sx:{width:"100%",p:2,borderRadius:4,backgroundColor:S.palette.grey[50]},children:u.jsx(o0,{name:"نشست های فعال",columns:["ردیف","نشست های فعال ","سریال","تاریخ ایجاد","آخرین بازدید","عملیات"],data:$})})})]})})},"detail"):u.jsx(gu.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.3},children:u.jsx(eu,{children:u.jsx(l0,{name:u.jsx(p,{container:!0,alignItems:"center",gap:2,sx:{mb:3},children:u.jsxs(p,{container:!0,gap:1,alignItems:"center",children:[u.jsx(k,{variant:"body1",fontWeight:"bold",color:"primary",children:"اطلاعات دستگاههای POS"}),u.jsxs(k,{variant:"caption",color:"text.secondary",children:["(",((f=e==null?void 0:e.guildPos)==null?void 0:f.length)||0," دستگاه ثبت شده)"]})]})}),columns:["ردیف","شماره پذیرنده","شماره ترمینال","سریال دستگاه","کلید اتصال","کلمه عبور امنیتی","نام دستگاه","اولین ورود","آخرین بازدید","وضعیت","نشستها","فعال/غیرفعال"],data:D||[],sx:{"& .MuiTableCell-root":{py:1.5},"& .MuiTableHead-root":{backgroundColor:S.palette.grey[100]}}})})},"table")})})},v0=uu("PSP_SUBMIT_POS",async(e,{dispatch:d})=>{d(B());const{data:x,status:o}=await R.post("pos-machine/",e);return d(M()),{data:x,status:o}}),S0=({item:e,updateTable:d})=>{const[x]=c.useContext(q),o=z(),r=Eu({initialValues:{reciver:"",terminal:"",serial:"",password:""},validationSchema:wu({reciver:fu().required("این فیلد اجباری است!").typeError("لطفا عدد وارد کنید!"),terminal:fu().required("این فیلد اجباری است!").typeError("لطفا وزن را وارد کنید!"),password:ou().matches(/^\d{4}$/,"پسورد باید یک عدد 4 رقمی باشد").typeError("لطفا یک عدد 4 رقمی وارد کنید."),serial:ou()})});return c.useEffect(()=>{r.validateForm()},[]),u.jsxs(p,{gap:T.SMALL,container:!0,xs:12,children:[u.jsx(L,{id:"reciver",label:"شماره پذیرنده",variant:"outlined",sx:{width:"100%"},value:r.values.reciver,error:r.touched.reciver?!!r.errors.reciver:null,onChange:r.handleChange,onBlur:r.handleBlur,helperText:r.touched.reciver&&r.errors.reciver?r.errors.reciver:null}),u.jsx(L,{id:"terminal",label:"شماره ترمینال",variant:"outlined",sx:{width:"100%"},value:r.values.terminal,error:r.touched.terminal?!!r.errors.terminal:null,onChange:r.handleChange,onBlur:r.handleBlur,helperText:r.touched.terminal&&r.errors.terminal?r.errors.terminal:null}),u.jsx(L,{id:"serial",name:"serial",label:"شماره سریال دستگاه",variant:"outlined",value:r.values.serial,onChange:r.handleChange,onBlur:r.handleBlur,helperText:r.touched.serial&&r.errors.serial?r.errors.serial:null,error:r.touched.serial&&!!r.errors.serial}),u.jsx(L,{id:"password",name:"password",label:"کلمه عبور مدیریتی",variant:"outlined",value:r.values.password,onChange:g=>{const C=g.target.value.replace(/\D/g,"").slice(0,4);r.setFieldValue("password",C)},onBlur:r.handleBlur,helperText:r.touched.password&&r.errors.password?r.errors.password:null,error:r.touched.password&&!!r.errors.password,inputProps:{maxLength:4}}),u.jsx(I,{disabled:!r.isValid,fullWidth:!0,variant:"contained",onClick:()=>{o(B()),o(v0({guild_key:e.key,receiver_number:r.values.reciver,terminal_number:r.values.terminal,password:r.values.password,serial:r.values.serial})).then(g=>{g.error?x({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است!",severity:"error"}):(x({vertical:"top",horizontal:"center",msg:"عملیات با موفقیت انجام شد.",severity:"success"}),d(),o(H({right:!1,bottom:!1,content:null})))})},children:"ثبت"})]})},_0=({item:e,updateTable:d})=>{const[x,o]=c.useState(null),r=z(),g=S=>{o(S.currentTarget)},C=()=>{o(null)},w=!!x,y=w?"popover":void 0;return u.jsxs("div",{children:[u.jsx(G,{"aria-describedby":y,color:"primary",onClick:g,sx:{padding:"8px"},children:u.jsx(Ou,{fontSize:"medium"})}),u.jsx(Su,{anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},id:y,open:w,anchorEl:x,onClose:C,children:u.jsx(X,{sx:{padding:"16px",minWidth:"50px"},children:u.jsxs(p,{container:!0,direction:"column",spacing:2,alignItems:"center",children:[(e==null?void 0:e.numberOfPos)>0&&u.jsx(p,{item:!0,children:u.jsx(V,{title:"مشاهده جزییات دستگاههای POS",placement:"right",children:u.jsx(G,{disabled:(e==null?void 0:e.provinceAcceptState)!=="accepted",color:"primary",onClick:()=>{C(),r(H({title:"جزئیات کارتخوان",top:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(b0,{item:e,updateTable:d})}))},children:u.jsx(qu,{size:24})})})}),u.jsx(p,{item:!0,children:u.jsx(V,{title:"ثبت دستگاه POS جدید",placement:"right",children:u.jsx(G,{disabled:(e==null?void 0:e.provinceAcceptState)!=="accepted",color:"secondary",sx:{fontSize:"1.5rem",width:"48px",height:"48px","&:hover":{backgroundColor:"rgba(156, 39, 176, 0.08)"}},onClick:()=>{C(),r(H({title:"ایجاد دستگاه",right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(S0,{item:e,updateTable:d})}))},children:u.jsx(C0,{size:24})})})}),u.jsx(p,{item:!0,children:u.jsx(V,{title:e!=null&&e.condition?"ویرایش وضعیت صنف":"ثبت وضعیت صنف",placement:"right",children:u.jsx(G,{disabled:(e==null?void 0:e.provinceAcceptState)!=="accepted",color:"success",sx:{fontSize:"1.5rem",width:"48px",height:"48px","&:hover":{backgroundColor:"rgba(46, 125, 50, 0.08)"}},onClick:()=>{C(),r(Z({title:"ثبت توضیحات",content:u.jsx(j0,{item:e,updateTable:d})}))},children:u.jsx(n0,{size:24})})})})]})})})]})},E0=()=>{var O;const[e,d]=c.useState([]),[x,o]=c.useState(0),[r,g]=c.useState(10),[C,w]=c.useState(""),[y,S]=c.useState(1),[D,$]=c.useState([]),_=z(),m=s0(i=>i.userSlice),f=async i=>{let t;_(B()),t=await R.get(`total_guilds_for_companies/?search=filter&value=${C}&role=${P()}&page=${i}&page_size=${r}`),_(M()),d(t.data.results),o(t.data.count)},a=i=>{f(i),S(i)},A=i=>{g(i),S(1)},F=()=>{f(y!==0?y:1)},l=i=>{w(i.target.value)};c.useEffect(()=>{const i=e==null?void 0:e.map((t,N)=>{var h,j,n,E,b,U,hu;return[y===1?N+1:N+r*(y-1)+1,t.guildsId,t==null?void 0:t.guildsName,`${(h=t==null?void 0:t.user)==null?void 0:h.fullname} (${(j=t==null?void 0:t.user)==null?void 0:j.mobile})`,(n=t==null?void 0:t.user)==null?void 0:n.nationalId,t==null?void 0:t.typeActivity,t==null?void 0:t.areaActivity,`${(E=t==null?void 0:t.user)==null?void 0:E.province}/${(b=t==null?void 0:t.user)==null?void 0:b.city}/${(U=t==null?void 0:t.user)!=null&&U.address?(hu=t==null?void 0:t.user)==null?void 0:hu.address:""}`,t!=null&&t.steward?"می باشد":"نمی باشد",(t==null?void 0:t.provinceAcceptState)==="accepted"?"تایید شده":(t==null?void 0:t.provinceAcceptState)==="rejected"?"رد شده":"در انتظار تایید",`${(t==null?void 0:t.condition)||"توضیحاتی وجود ندارد"} (${t==null?void 0:t.descriptionCondition})`,u.jsx(_0,{selectedAge1:null,selectedAge2:null,updateTable:F,item:t},"4")]});$(i)},[e]),c.useEffect(()=>{f(1)},[_,r]);const s=async i=>{i.preventDefault(),_(B());try{const t=await R.get(`total_guilds_for_companies/?role=${P()}&search=filter&value=${C}`);d(t.data.results),o(t.data.count),_(M())}catch(t){console.error("Error fetching data:",t)}},v=u.jsx(p,{container:!0,alignItems:"center",justifyContent:"space-between",gap:2,mb:1,padding:2,width:"100%",children:u.jsxs(p,{container:!0,width:"100%",alignItems:"center",justifyContent:"space-between",gap:T.SMALL,children:[u.jsx("form",{onSubmit:s,children:u.jsxs(p,{container:!0,alignItems:"center",gap:T.SMALL,children:[u.jsx(L,{size:"small",autoComplete:"off",label:"جستجو",variant:"outlined",style:{width:250},onChange:l}),u.jsx(I,{type:"submit",onClick:s,endIcon:u.jsx(Du,{}),children:"جستجو"}),u.jsx(V,{title:"خروجی اکسل",children:u.jsx("a",{href:`${R.defaults.baseURL}pos_excel/?&key=${(O=m==null?void 0:m.userProfile)==null?void 0:O.key}`,rel:"noreferrer",children:u.jsx(I,{color:"success",children:u.jsx(t0,{size:32})})})})]})}),u.jsx(p,{container:!0,alignItems:"center",gap:T.SMALL,children:u.jsx(V,{title:"ثبت صنف جدید",placement:"top",children:u.jsx(I,{variant:"contained",onClick:()=>{_(Z({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,title:"ثبت واحد جدید",size:window.innerWidth<=600?"small":"auto",content:u.jsx(a0,{updateTable:F})}))},children:"ثبت صنف جدید"})})})]})});return u.jsxs(p,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[v,u.jsx(Tu,{data:D,columns:["ردیف","شناسه صنف","نام واحد صنفی","نام شخص/شرکت","کدملی","نوع فعالیت","حوزه فعالیت","آدرس","مباشر","وضعیت احراز","توضیحات شرکت psp","عملیات"],handlePageChange:a,totalRows:x,page:y,perPage:r,handlePerRowsChange:A,title:"مدیریت اصناف"})]})};var iu={},w0=K;Object.defineProperty(iu,"__esModule",{value:!0});var $u=iu.default=void 0,P0=w0(Q()),mu=u;$u=iu.default=(0,P0.default)([(0,mu.jsx)("circle",{cx:"9",cy:"8",r:"4"},"0"),(0,mu.jsx)("path",{d:"M9 14c-2.67 0-8 1.34-8 4v1c0 .55.45 1 1 1h14c.55 0 1-.45 1-1v-1c0-2.66-5.33-4-8-4m11-4V7h-2v3h-3v2h3v3h2v-3h3v-2z"},"1")],"PersonAddAlt1Rounded");var du={},D0=K;Object.defineProperty(du,"__esModule",{value:!0});var Lu=du.default=void 0,T0=D0(Q()),O0=u;Lu=du.default=(0,T0.default)((0,O0.jsx)("path",{d:"m6.14 11.86-2.78 2.79c-.19.2-.19.51 0 .71l2.78 2.79c.31.32.85.09.85-.35V16H13c.55 0 1-.45 1-1s-.45-1-1-1H6.99v-1.79c0-.45-.54-.67-.85-.35m14.51-3.21-2.78-2.79c-.31-.32-.85-.09-.85.35V8H11c-.55 0-1 .45-1 1s.45 1 1 1h6.01v1.79c0 .45.54.67.85.35l2.78-2.79c.2-.19.2-.51.01-.7"}),"SwapHorizRounded");var Cu={},I0=K;Object.defineProperty(Cu,"__esModule",{value:!0});var Ru=Cu.default=void 0,$0=I0(Q()),L0=u;Ru=Cu.default=(0,$0.default)((0,L0.jsx)("path",{d:"M18 13h-5v5c0 .55-.45 1-1 1s-1-.45-1-1v-5H6c-.55 0-1-.45-1-1s.45-1 1-1h5V6c0-.55.45-1 1-1s1 .45 1 1v5h5c.55 0 1 .45 1 1s-.45 1-1 1"}),"AddRounded");const R0=async e=>await R.get(`/guilds/?role=${e}&page_size=1000&psp_pos=true`),k0=async()=>await R.get("/kill_house/?psp=true"),M0=async e=>await R.put("/new-pos-machine/0/",e),N0=()=>{const[e,d]=c.useState([]),[x,o]=c.useState(0),[r,g]=c.useState(10),[C,w]=c.useState(""),[y,S]=c.useState(1),[D,$]=c.useState([]),[_,m]=c.useState([]),[f,a]=c.useState(""),A=z(),F=async()=>{try{A(B());const j=await R.get(`/get_all_pos_company/?role=${P()}`);m(j.data),A(M())}catch(j){console.error("Error fetching companies:",j),A(M())}},l=async j=>{try{A(B());let n=`/new-pos-machine/?search=filter&value=${C}&role=${P()}&page=${j}&page_size=${r}`;f&&(n+=`&company=${f}`);const E=await R.get(n);d(E.data.results),o(E.data.count)}catch(n){console.error("Error fetching devices:",n)}finally{A(M())}},s=j=>{l(j),S(j)},v=j=>{g(j),S(1)},O=j=>{w(j.target.value)};c.useEffect(()=>{const j=e==null?void 0:e.map((n,E)=>{const b=(n==null?void 0:n.owner)||{},U=!!(n!=null&&n.owner);return[y===1?E+1:E+r*(y-1)+1,(n==null?void 0:n.companyName)||"-",(n==null?void 0:n.serial)??"-",(n==null?void 0:n.receiverNumber)??"-",(n==null?void 0:n.terminalNumber)??"-",(n==null?void 0:n.password)??"-",(n==null?void 0:n.posId)??"-",b!=null&&b.unitName?`${b==null?void 0:b.unitName}`:"-",b!=null&&b.fullname?`${b==null?void 0:b.fullname} (${(b==null?void 0:b.mobile)??"-"})`:"-",(b==null?void 0:b.licenseNumber)??"-",n!=null&&n.createDate?Y(n==null?void 0:n.createDate):"-",n!=null&&n.active?"فعال":"غیرفعال",u.jsx(B0,{device:n,hasOwner:U,onOwnerAssigned:()=>{l(y)}},(n==null?void 0:n.id)||`device-${E}`)]});$(j)},[e,y,r]),c.useEffect(()=>{F(),l(1)},[A]),c.useEffect(()=>{l(y)},[f,r]);const i=async j=>{j.preventDefault(),l(1)},t=()=>{S(1),l(1)},N=()=>{const j=window.innerWidth<=600;A(H({title:"ایجاد دستگاه",right:!j,bottom:j,content:u.jsx(U0,{onSuccess:t})}))},h=u.jsx(p,{container:!0,alignItems:"center",justifyContent:"space-between",gap:2,mb:1,padding:2,width:"100%",children:u.jsxs(p,{container:!0,width:"100%",alignItems:"center",justifyContent:"space-between",gap:T.SMALL,children:[u.jsxs(p,{container:!0,alignItems:"center",gap:T.SMALL,xs:12,md:"auto",children:[P()!=="PosCompany"&&u.jsx(_u,{size:"small",style:{minWidth:210},disablePortal:!0,id:"session",options:_?_.map(j=>({data:j,label:`${j==null?void 0:j.name}`})):[],onChange:(j,n)=>{var E;a((E=n==null?void 0:n.data)==null?void 0:E.key)},renderInput:j=>u.jsx(L,{fullWidth:!0,...j,label:"انتخاب شرکت psp"})}),u.jsxs(p,{container:!0,alignItems:"center",gap:T.SMALL,children:[u.jsx(L,{size:"small",autoComplete:"off",label:"جستجو",variant:"outlined",style:{width:250},value:C,onChange:O}),u.jsx(I,{type:"submit",onClick:i,endIcon:u.jsx(Du,{}),children:"جستجو"})]})]}),u.jsx(p,{container:!0,justifyContent:"flex-end",xs:12,md:"auto",children:u.jsx(I,{variant:"contained",startIcon:u.jsx(Ru,{}),onClick:N,children:"ایجاد دستگاه"})})]})});return u.jsxs(p,{container:!0,xs:12,justifyContent:"center",alignItems:"center",gap:2,children:[h,u.jsx(Tu,{data:D,columns:["ردیف","شرکت پرداختی","شماره سریال","شماره پذیرنده","شماره ترمینال","کلمه عبور امنیتی","کلید پوز","نام واحد","مالک","کدملی","تاریخ ایجاد","فعال / غیرفعال","عملیات"],handlePageChange:s,totalRows:x,page:y,perPage:r,handlePerRowsChange:v,title:"مدیریت دستگاه ها"})]})},B0=({device:e,hasOwner:d,onOwnerAssigned:x})=>{const[o,r]=c.useState(null),[g]=c.useState(!1),[C,w]=c.useState(!!(e!=null&&e.active)),y=z(),[S]=c.useContext(q);c.useEffect(()=>{w(!!(e!=null&&e.active))},[e==null?void 0:e.active]);const D=v=>{r(v.currentTarget)},$=()=>{r(null)},_=()=>{$(),y(Z({title:d?"تغییر مالک":"افزودن مالک",width:"auto",content:u.jsx(z0,{device:e,onSuccess:x})}))},m=!!o,f=m?"device-operations-popover":void 0,a=d?"تغییر مالک":"افزودن مالک",A=d?Lu:$u,F=d?"warning.main":"success.main",l=(e==null?void 0:e.key)||(e==null?void 0:e.id),s=async v=>{if(v.stopPropagation(),v.preventDefault(),!l){S({vertical:"top",horizontal:"center",severity:"error",msg:"شناسه دستگاه یافت نشد."});return}};return u.jsxs(u.Fragment,{children:[u.jsx(G,{"aria-describedby":f,color:"primary",onClick:D,size:"small",children:u.jsx(Ou,{fontSize:"small"})}),u.jsx(Su,{id:f,open:m,anchorEl:o,onClose:$,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},children:u.jsxs(zu,{sx:{minWidth:160,p:0},children:[u.jsxs(Uu,{sx:{px:2,py:1,display:"flex",alignItems:"center",gap:1},children:[u.jsx(Au,{primary:"وضعیت دستگاه",secondary:C?"فعال":"غیرفعال"}),u.jsx(vu,{edge:"end",color:"success",checked:C,onChange:s,disabled:g||!l})]}),u.jsxs(Wu,{onClick:_,children:[u.jsx(Vu,{sx:{minWidth:36,color:F},children:u.jsx(A,{fontSize:"small"})}),u.jsx(Au,{primary:a,primaryTypographyProps:{sx:{color:F}}})]})]})})]})},z0=({device:e,onSuccess:d})=>{const x=z(),[o]=c.useContext(q),[r,g]=c.useState([]),[C,w]=c.useState(null),[y,S]=c.useState(!1),[D,$]=c.useState(!1),[_,m]=c.useState(""),[f,a]=c.useState("guild");c.useEffect(()=>{let l=!0;return(async()=>{var v,O;S(!0),m(""),w(null);try{let i;if(f==="kill_house"?i=await k0():i=await R0(P()),l){const t=Array.isArray((v=i==null?void 0:i.data)==null?void 0:v.results)?(O=i==null?void 0:i.data)==null?void 0:O.results:Array.isArray(i==null?void 0:i.data)?i==null?void 0:i.data:[];let N;f==="kill_house"?N=t.map(h=>{const j=h!=null&&h.killer?"کشتارکن":"کشتارگاه",n=(h==null?void 0:h.unitName)||(h==null?void 0:h.fullname)||"-",E=h!=null&&h.mobile?` (${h.mobile})`:"";return{...h,label:`${n}${E}`,meta:j,group:""}}):N=t.map(h=>{var b,U;const j=h!=null&&h.steward?"مباشر":"صنف",n=(h==null?void 0:h.guildsName)||((b=h==null?void 0:h.user)==null?void 0:b.fullname)||"-",E=(U=h==null?void 0:h.user)!=null&&U.mobile?` (${h.user.mobile})`:"";return{...h,label:`${n}${E}`,meta:j,group:""}}),g(N),w(N.find(h=>{var j,n,E;return((j=h==null?void 0:h.user)==null?void 0:j.mobile)===((n=e==null?void 0:e.owner)==null?void 0:n.mobile)||(h==null?void 0:h.mobile)===((E=e==null?void 0:e.owner)==null?void 0:E.mobile)}))}}catch{l&&m("دریافت لیست مالکها با خطا مواجه شد.")}finally{l&&S(!1)}})(),()=>{l=!1}},[f]);const A=()=>{x(J())},F=async()=>{var l,s,v,O;if(C){if(!(e!=null&&e.key)&&!(e!=null&&e.id)){o({vertical:"top",horizontal:"center",severity:"error",msg:"شناسه دستگاه یافت نشد. لطفاً دوباره تلاش کنید."});return}$(!0);try{let i;f==="kill_house"?i="kill_house":i=C!=null&&C.steward?"Steward":"Guilds";const t={key:(e==null?void 0:e.key)||(e==null?void 0:e.id),owner_type:i,owner_key:C==null?void 0:C.key};await M0(t),o({vertical:"top",horizontal:"center",severity:"success",msg:"مالک با موفقیت ثبت شد."}),d&&d(),A()}catch(i){o({vertical:"top",horizontal:"center",severity:"error",msg:((s=(l=i==null?void 0:i.response)==null?void 0:l.data)==null?void 0:s.result)||((O=(v=i==null?void 0:i.response)==null?void 0:v.data)==null?void 0:O.detail)||"ثبت مالک با خطا مواجه شد."})}finally{$(!1)}}};return u.jsxs(p,{container:!0,direction:"column",gap:T.SMALL,width:"100%",alignItems:"stretch",children:[u.jsxs(k,{variant:"body2",children:["دستگاه انتخاب شده: ",(e==null?void 0:e.serial)||(e==null?void 0:e.posId)||"-"]}),u.jsx(A0,{label:"ماهیت مالک",children:u.jsx(bu,{children:u.jsxs(Gu,{row:!0,sx:{gap:2},value:f,onChange:l=>a(l.target.value),children:[u.jsx(pu,{value:"guild",control:u.jsx(xu,{}),label:"صنف / مباشر"}),u.jsx(pu,{value:"kill_house",control:u.jsx(xu,{}),label:"کشتارگاه / کشتارکن"})]})})}),y?u.jsx(p,{container:!0,justifyContent:"center",children:u.jsx(ju,{size:24})}):u.jsx(_u,{disablePortal:!0,fullWidth:!0,size:"small",options:r,value:C,groupBy:l=>(l==null?void 0:l.group)||"",loading:y,loadingText:"در حال دریافت...",noOptionsText:"موردی یافت نشد.",onChange:(l,s)=>w(s),isOptionEqualToValue:(l,s)=>(l==null?void 0:l.key)===(s==null?void 0:s.key),getOptionLabel:l=>(l==null?void 0:l.label)||"",renderOption:(l,s)=>{var v,O;return c.createElement("li",{...l,key:s==null?void 0:s.key},u.jsx(p,{container:!0,direction:"column",children:f==="kill_house"?u.jsxs(u.Fragment,{children:[u.jsx(k,{variant:"body2",fontWeight:600,children:`${(s==null?void 0:s.unitName)||(s==null?void 0:s.fullname)||""}${s!=null&&s.mobile?` (${s.mobile})`:""}`}),u.jsx(k,{variant:"caption",color:"text.secondary",children:`${(s==null?void 0:s.meta)||""}${s!=null&&s.city?` | ${s.city}`:""}`.replace(/^ \| /,"")})]}):u.jsxs(u.Fragment,{children:[u.jsx(k,{variant:"body2",fontWeight:600,children:`${(s==null?void 0:s.guildsName)||""}${(v=s==null?void 0:s.user)!=null&&v.mobile?` (${s.user.mobile})`:""}`}),u.jsx(k,{variant:"caption",color:"text.secondary",children:`${(s==null?void 0:s.typeActivity)||""}${s!=null&&s.areaActivity?` | ${s.areaActivity}`:""}${(O=s==null?void 0:s.user)!=null&&O.city?` | ${s.user.city}`:""}${s!=null&&s.licenseNumber?` | شناسه : ${s.licenseNumber}`:""}`.replace(/^ \| /,"")})]})}))},renderInput:l=>u.jsx(L,{...l,label:"انتخاب مالک",placeholder:"نام یا شماره تماس",InputProps:{...l.InputProps,endAdornment:u.jsxs(u.Fragment,{children:[y?u.jsx(ju,{color:"inherit",size:16}):null,l.InputProps.endAdornment]})}})}),_&&u.jsx(k,{variant:"caption",color:"error",children:_}),u.jsxs(p,{container:!0,justifyContent:"flex-end",gap:T.SMALL,children:[u.jsx(I,{variant:"outlined",color:"primary",onClick:A,disabled:D,children:"انصراف"}),u.jsx(I,{variant:"contained",onClick:F,disabled:!C||D||y,children:D?"در حال ثبت...":"ثبت"})]})]})},U0=({onSuccess:e})=>{const d=z(),[x]=c.useContext(q),[o,r]=c.useState({receiver_number:"",terminal_number:"",password:"",serial:""}),[g,C]=c.useState({}),[w,y]=c.useState(!1),S=()=>{d(H({right:!1,bottom:!1,content:null}))},D=m=>{const{name:f,value:a}=m.target;r(A=>({...A,[f]:a})),g[f]&&C(A=>({...A,[f]:""}))},$=()=>{var f,a,A,F;const m={};return(f=o.receiver_number)!=null&&f.trim()||(m.receiver_number="وارد کردن شماره پذیرنده الزامی است."),(a=o.terminal_number)!=null&&a.trim()||(m.terminal_number="وارد کردن شماره ترمینال الزامی است."),(A=o.password)!=null&&A.trim()||(m.password="وارد کردن رمز عبور الزامی است."),(F=o.serial)!=null&&F.trim()||(m.serial="وارد کردن سریال دستگاه الزامی است."),C(m),Object.keys(m).length===0},_=async m=>{var f,a,A,F;if(m.preventDefault(),!!$()){y(!0);try{await R.post("/new-pos-machine/",{receiver_number:o.receiver_number.trim(),terminal_number:o.terminal_number.trim(),password:o.password.trim(),serial:o.serial.trim()}),x({vertical:"top",horizontal:"center",severity:"success",msg:"دستگاه با موفقیت ایجاد شد."}),e&&e(),S()}catch(l){x({vertical:"top",horizontal:"center",severity:"error",msg:((a=(f=l==null?void 0:l.response)==null?void 0:f.data)==null?void 0:a.result)||((F=(A=l==null?void 0:l.response)==null?void 0:A.data)==null?void 0:F.detail)||"ایجاد دستگاه با خطا مواجه شد."})}finally{y(!1)}}};return u.jsxs(p,{component:"form",onSubmit:_,container:!0,direction:"column",gap:T.SMALL,width:"100%",autoComplete:"off",xs:12,children:[u.jsx(L,{label:"سریال دستگاه",name:"serial",value:o.serial,onChange:D,fullWidth:!0,error:!!g.serial,helperText:g.serial}),u.jsx(L,{label:"شماره پذیرنده",name:"receiver_number",value:o.receiver_number,onChange:D,fullWidth:!0,error:!!g.receiver_number,helperText:g.receiver_number}),u.jsx(L,{label:"شماره ترمینال",name:"terminal_number",value:o.terminal_number,onChange:D,fullWidth:!0,error:!!g.terminal_number,helperText:g.terminal_number}),u.jsx(L,{label:"رمز عبور",name:"password",value:o.password,onChange:D,fullWidth:!0,error:!!g.password,helperText:g.password}),u.jsxs(p,{container:!0,justifyContent:"justify-between",gap:T.SMALL,mt:T.SMALL,xs:12,children:[u.jsx(I,{variant:"outlined",color:"primary",style:{width:"46%"},onClick:S,disabled:w,children:"انصراف"}),u.jsx(I,{style:{width:"46%"},variant:"contained",type:"submit",disabled:w,children:w?"در حال ثبت...":"ثبت"})]})]})},v6=()=>{const{pathname:e}=Pu();return u.jsx(u.Fragment,{children:u.jsx(X,{display:"flex",justifyContent:"center",children:u.jsxs(p,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,children:[[Yu,Xu,Ju].includes(e)?u.jsx(p,{justifyContent:"center",my:T.MEDIUM,children:u.jsx(p0,{})}):u.jsx(u0,{}),u.jsx(p,{container:!0,justifyContent:"space-between",gap:T.SMALL,children:u.jsxs(p,{xs:12,children:[[Ku,Qu,Zu].includes(e)&&u.jsx(E0,{}),[au,nu,lu].includes(e)&&u.jsx(h0,{}),[ru,su,tu].includes(e)&&u.jsx(N0,{})]})})]})})})};export{v6 as default};
|