Files
Rasadyar_FrontEnd/build/assets/GuildPspDevices-CysFwX7k.js

2 lines
18 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{j as u,a5 as d,T as w,aj as Au,ak as gu,al as P,am as cu,aD as Cu,ao as pu,an as su,az as yu,aA as tu,B as T,ay as Fu,a_ as q,I as ru,b3 as bu,aq as Su,b7 as hu,as as du,at as xu,b as au,au as mu,cy as _u}from"./mui-vendor-D_SVL-Dx.js";import{r as c}from"./react-vendor-CmFgShSM.js";import{u as Y,f as fu}from"./redux-vendor-CfkcHgWN.js";import{A as nu,S as O,a0 as J,j as N,_ as H,C as X,ad as ku,O as uu,L as ou,h as Q,G as V,p as Eu}from"./index-D80MdVQn.js";import{B as Du}from"./BackButton-Dr-K0JXJ.js";import{R as zu}from"./index.esm-C1-dCPnj.js";import{R as wu}from"./ResponsiveTable-bUYl0qDM.js";import{d as Iu}from"./Tune-BBzxV8DK.js";import{d as $u}from"./PersonAddAlt1Rounded--1IUMwiN.js";import{d as Bu}from"./Add-CiyqkOpq.js";import{d as Ou}from"./Delete-CIwpNviU.js";import{L as eu}from"./LabelField-BYhJrYEE.js";import{c as W}from"./checkPathStartsWith-DedybDvj.js";import"./FilterAlt-DZsHj-WQ.js";import"./styled-components.browser.esm-gS9mh05b.js";const Tu=({device:t,onSuccess:C})=>{const E=Y(),[g]=c.useContext(nu),[x,D]=c.useState([]),[e,h]=c.useState(null),[_,p]=c.useState(""),[y,f]=c.useState(!1),[F,m]=c.useState(!1),[j,A]=c.useState(""),[i,o]=c.useState("delegate"),b=fu(a=>a.userSlice.selectedSubUser);c.useEffect(()=>{let a=!0;return(async()=>{var I,s,n,S;f(!0),A(""),h(null),p("");try{let r;const $=J();if(i==="delegate"?r=await N.get(`/get_representatives/?role=${$}${W("slaughter")||W("steward")?`&role_key=${b==null?void 0:b.key}`:""}`):r=await N.get(`/get_dispensers/?role=${$}${W("slaughter")||W("steward")?`&role_key=${b==null?void 0:b.key}`:""}`),a){const Z=(Array.isArray((I=r==null?void 0:r.data)==null?void 0:I.results)?(s=r==null?void 0:r.data)==null?void 0:s.results:Array.isArray(r==null?void 0:r.data)?r==null?void 0:r.data:Array.isArray((n=r==null?void 0:r.data)==null?void 0:n.data)?(S=r==null?void 0:r.data)==null?void 0:S.data:Array.isArray(r)?r:[]).map(B=>{const L=(B==null?void 0:B.fullname)||"-",K=(B==null?void 0:B.mobile)||"",U=K?` (${K})`:"",v=`${L}${U}`;return{...B,label:v||"-"}});D(Z)}}catch(r){a&&(A("دریافت لیست کاربران با خطا مواجه شد."),console.error("Error fetching users:",r))}finally{a&&f(!1)}})(),()=>{a=!1}},[i,b==null?void 0:b.key]);const R=()=>{E(X())},M=a=>{if(!a)return[];const l=[],I=["active","trash","deleted","isActive","isDeleted"];return Object.keys(a).forEach(s=>{if(typeof a[s]=="boolean"&&a[s]===!0&&!I.includes(s.toLowerCase())){const n=H(s);l.push({key:s,label:n||s})}}),l},G=async()=>{var a,l,I,s;if(!e){g({vertical:"top",horizontal:"center",severity:"error",msg:"لطفاً یک کاربر را انتخاب کنید."});return}if(!(t!=null&&t.key)&&!(t!=null&&t.id)){g({vertical:"top",horizontal:"center",severity:"error",msg:"شناسه دستگاه یافت نشد. لطفاً دوباره تلاش کنید."});return}m(!0);try{const n={key:(t==null?void 0:t.key)||(t==null?void 0:t.id),recipient_type:i==="delegate"?"representative":"dispenser",recipient_key:(e==null?void 0:e.key)||(e==null?void 0:e.id)};await N.put("/user-pos-machine/0/",n),g({vertical:"top",horizontal:"center",severity:"success",msg:"دستگاه با موفقیت به کاربر فرعی اختصاص داده شد."}),C&&C(),R()}catch(n){g({vertical:"top",horizontal:"center",severity:"error",msg:((l=(a=n==null?void 0:n.response)==null?void 0:a.data)==null?void 0:l.result)||((s=(I=n==null?void 0:n.response)==null?void 0:I.data)==null?void 0:s.detail)||"اختصاص دستگاه با خطا مواجه شد."})}finally{m(!1)}},z=e?M(e):[];return u.jsxs(d,{container:!0,direction:"column",gap:O.SMALL,width:"100%",alignItems:"stretch",sx:{minWidth:400},children:[u.jsxs(w,{variant:"body2",children:["دستگاه انتخاب شده:"," ",(t==null?void 0:t.serial)||(t==null?void 0:t.pos_unique_id)||(t==null?void 0:t.pos_id)||(t==null?void 0:t.posId)||"-"]}),u.jsx(eu,{label:"نوع کاربر",children:u.jsx(Au,{fullWidth:!0,children:u.jsxs(gu,{row:!0,sx:{gap:2},value:i,onChange:a=>o(a.target.value),children:[u.jsx(P,{value:"delegate",control:u.jsx(cu,{}),label:"نماینده‌ها"}),u.jsx(P,{value:"dispenser",control:u.jsx(cu,{}),label:"پخش‌کنندگان"})]})})}),y?u.jsx(d,{container:!0,justifyContent:"center",children:u.jsx(Cu,{size:24})}):u.jsx(pu,{disablePortal:!0,fullWidth:!0,size:"small",options:x,value:e,loading:y,loadingText:"در حال دریافت...",noOptionsText:"موردی یافت نشد.",onChange:(a,l)=>{h(l),p("")},isOptionEqualToValue:(a,l)=>(a==null?void 0:a.key)===(l==null?void 0:l.key)||(a==null?void 0:a.id)===(l==null?void 0:l.id),getOptionLabel:a=>(a==null?void 0:a.label)||"",renderOption:(a,l)=>l?c.createElement("li",{...a,key:(l==null?void 0:l.key)||(l==null?void 0:l.id)},u.jsxs(d,{container:!0,direction:"column",children:[u.jsx(w,{variant:"body2",fontWeight:600,children:(l==null?void 0:l.label)||"-"}),(l==null?void 0:l.city)&&u.jsx(w,{variant:"caption",color:"text.secondary",children:l.city})]})):null,renderInput:a=>u.jsx(su,{...a,label:"انتخاب کاربر",placeholder:"نام یا شماره تماس",InputProps:{...a.InputProps,endAdornment:u.jsxs(u.Fragment,{children:[y?u.jsx(Cu,{color:"inherit",size:16}):null,a.InputProps.endAdornment]})}})}),j&&u.jsx(w,{variant:"caption",color:"error",children:j}),e&&z.length>0&&u.jsx(eu,{label:"سطح دسترسی فرعی",children:u.jsxs(yu,{fullWidth:!0,size:"small",value:_,onChange:a=>p(a.target.value),displayEmpty:!0,children:[u.jsx(tu,{value:"",children:u.jsx("em",{children:"انتخاب سطح دسترسی"})}),z.map(a=>u.jsx(tu,{value:a.key,children:a.label},a.key))]})}),u.jsxs(d,{container:!0,justifyContent:"flex-end",gap:O.SMALL,mt:2,children:[u.jsx(T,{variant:"outlined",color:"primary",onClick:R,disabled:F,children:"انصراف"}),u.jsx(T,{variant:"contained",onClick:G,disabled:!e||F||y,children:F?"در حال ثبت...":"ثبت"})]})]})},Mu=({device:t,onSuccess:C})=>{const E=Y(),[g]=c.useContext(nu),[x,D]=c.useState(""),[e,h]=c.useState(!1),_=["Steward","KillHouse","Guilds"],p=()=>{E(X())},y=async()=>{var f,F,m,j;if(!x){g({vertical:"top",horizontal:"center",severity:"error",msg:"لطفاً یک سطح دسترسی را انتخاب کنید."});return}if(!(t!=null&&t.key)&&!(t!=null&&t.id)){g({vertical:"top",horizontal:"center",severity:"error",msg:"شناسه دستگاه یافت نشد. لطفاً دوباره تلاش کنید."});return}h(!0);try{const A={pos_key:(t==null?void 0:t.key)||(t==null?void 0:t.id),name:x};await N.post("/pos-access-level/",A),g({vertical:"top",horizontal:"center",severity:"success",msg:"سطح دسترسی با موفقیت افزوده شد."}),C&&C(),p()}catch(A){g({vertical:"top",horizontal:"center",severity:"error",msg:((F=(f=A==null?void 0:A.response)==null?void 0:f.data)==null?void 0:F.result)||((j=(m=A==null?void 0:A.response)==null?void 0:m.data)==null?void 0:j.detail)||"افزودن سطح دسترسی با خطا مواجه شد."})}finally{h(!1)}};return u.jsxs(d,{container:!0,direction:"column",gap:O.SMALL,width:"100%",alignItems:"stretch",sx:{minWidth:300},children:[u.jsxs(w,{variant:"body2",children:["دستگاه انتخاب شده:"," ",(t==null?void 0:t.serial)||(t==null?void 0:t.pos_unique_id)||(t==null?void 0:t.pos_id)||(t==null?void 0:t.posId)||"-"]}),u.jsxs(Au,{fullWidth:!0,size:"small",children:[u.jsx(Fu,{id:"access-level-label",children:"سطح دسترسی"}),u.jsxs(yu,{labelId:"access-level-label",id:"access-level-select",value:x,label:"سطح دسترسی",onChange:f=>D(f.target.value),children:[u.jsx(tu,{value:"",children:u.jsx("em",{children:"انتخاب سطح دسترسی"})}),_.map(f=>u.jsx(tu,{value:f,children:H(f)},f))]})]}),u.jsxs(d,{container:!0,justifyContent:"flex-end",gap:O.SMALL,mt:2,children:[u.jsx(T,{variant:"outlined",color:"primary",onClick:p,disabled:e,children:"انصراف"}),u.jsx(T,{variant:"contained",onClick:y,disabled:!x||e,children:e?"در حال ثبت...":"ثبت"})]})]})},Pu=({accessLevel:t,device:C,onSuccess:E})=>{const g=Y(),[x]=c.useContext(nu),[D,e]=c.useState(!1),[h,_]=c.useState({in_province_sale:(t==null?void 0:t.in_province_sale)||!1,out_province_sale:(t==null?void 0:t.out_province_sale)||!1,cutting:(t==null?void 0:t.cutting)||!1,freezing:(t==null?void 0:t.freezing)||!1,warehouse:(t==null?void 0:t.warehouse)||!1,retail:(t==null?void 0:t.retail)||!1}),p=()=>{g(X())},y=F=>m=>{_(j=>({...j,[F]:m.target.checked}))},f=async()=>{var F,m,j,A;if(!(t!=null&&t.key)){x({vertical:"top",horizontal:"center",severity:"error",msg:"شناسه سطح دسترسی یافت نشد. لطفاً دوباره تلاش کنید."});return}e(!0);try{const i={key:t.key,in_province_sale:h.in_province_sale,out_province_sale:h.out_province_sale,cutting:h.cutting,freezing:h.freezing,warehouse:h.warehouse,retail:h.retail};await N.put("/pos-access-level/0/",i),x({vertical:"top",horizontal:"center",severity:"success",msg:"زیربخش‌های سطح دسترسی با موفقیت ویرایش شد."}),E&&E(),p()}catch(i){x({vertical:"top",horizontal:"center",severity:"error",msg:((m=(F=i==null?void 0:i.response)==null?void 0:F.data)==null?void 0:m.result)||((A=(j=i==null?void 0:i.response)==null?void 0:j.data)==null?void 0:A.detail)||"ویرایش زیربخش‌ها با خطا مواجه شد."})}finally{e(!1)}};return u.jsxs(d,{container:!0,direction:"column",gap:O.SMALL,width:"100%",alignItems:"stretch",sx:{minWidth:400},children:[u.jsxs(w,{variant:"body2",children:["سطح دسترسی:"," ",H(t==null?void 0:t.name)||(t==null?void 0:t.name)||"-"]}),u.jsxs(w,{variant:"body2",children:["دستگاه:"," ",(C==null?void 0:C.serial)||(C==null?void 0:C.pos_unique_id)||(C==null?void 0:C.pos_id)||(C==null?void 0:C.posId)||"-"]}),u.jsx(eu,{label:"تنظیمات زیربخش‌ها",children:u.jsxs(d,{container:!0,p:1,children:[u.jsx(d,{item:!0,xs:6,children:u.jsx(P,{control:u.jsx(q,{checked:h.in_province_sale,onChange:y("in_province_sale")}),label:"فروش داخل استان"})}),u.jsx(d,{item:!0,xs:6,children:u.jsx(P,{control:u.jsx(q,{checked:h.out_province_sale,onChange:y("out_province_sale")}),label:"فروش خارج استان"})}),u.jsx(d,{item:!0,xs:6,children:u.jsx(P,{control:u.jsx(q,{checked:h.cutting,onChange:y("cutting")}),label:"قطعه بندی"})}),u.jsx(d,{item:!0,xs:6,children:u.jsx(P,{control:u.jsx(q,{checked:h.freezing,onChange:y("freezing")}),label:"انجماد"})}),u.jsx(d,{item:!0,xs:6,children:u.jsx(P,{control:u.jsx(q,{checked:h.warehouse,onChange:y("warehouse")}),label:"انبار"})}),u.jsx(d,{item:!0,xs:6,children:u.jsx(P,{control:u.jsx(q,{checked:h.retail,onChange:y("retail")}),label:"خرده‌فروشی"})})]})}),u.jsxs(d,{container:!0,justifyContent:"flex-end",gap:O.SMALL,mt:2,children:[u.jsx(T,{variant:"outlined",color:"primary",onClick:p,disabled:D,children:"انصراف"}),u.jsx(T,{variant:"contained",onClick:f,disabled:D,children:D?"در حال ثبت...":"ثبت"})]})]})},Wu=({device:t,onSubUserAssigned:C,fetchApiData:E,page:g})=>{const[x,D]=c.useState(null),e=Y(),[h]=c.useContext(nu),_=o=>{D(o.currentTarget)},p=()=>{D(null)},y=()=>{p(),e(uu({title:"اختصاص دستگاه به کاربر فرعی",width:"auto",content:u.jsx(Tu,{device:t,onSuccess:C})}))},f=()=>{p(),e(uu({title:"افزودن سطح دسترسی",width:"auto",content:u.jsx(Mu,{device:t,onSuccess:C})}))},F=o=>{p(),e(uu({title:"ویرایش زیربخش‌های سطح دسترسی",width:"auto",content:u.jsx(Pu,{accessLevel:o,device:t,onSuccess:()=>E(g)})}))},m=o=>{p(),e(uu({title:"حذف سطح دسترسی",size:320,content:u.jsxs(d,{container:!0,spacing:2,children:[u.jsx(d,{item:!0,xs:12,container:!0,justifyContent:"center",alignItems:"center",mb:2,children:u.jsxs(w,{variant:"body2",color:"default",children:["آیا از حذف سطح دسترسی"," ",H(o==null?void 0:o.name)||(o==null?void 0:o.name)," مطمئن هستید؟"]})}),u.jsx(d,{item:!0,xs:6,children:u.jsx(T,{fullWidth:!0,variant:"contained",color:"error",onClick:async()=>{var b,R,M,G;try{e(ou()),await N.delete(`/pos-access-level/0/?key=${o==null?void 0:o.key}`),e(Q()),e(X()),h({vertical:"top",horizontal:"center",severity:"success",msg:"سطح دسترسی با موفقیت حذف شد."}),E&&E(g)}catch(z){e(Q()),h({vertical:"top",horizontal:"center",severity:"error",msg:((R=(b=z==null?void 0:z.response)==null?void 0:b.data)==null?void 0:R.result)||((G=(M=z==null?void 0:z.response)==null?void 0:M.data)==null?void 0:G.detail)||"حذف سطح دسترسی با خطا مواجه شد."})}},children:"تایید"})}),u.jsx(d,{item:!0,xs:6,children:u.jsx(T,{fullWidth:!0,variant:"outlined",onClick:()=>e(X()),children:"انصراف"})})]})}))},j=!!x,A=j?"device-operations-popover":void 0,i=Array.isArray(t==null?void 0:t.accessLevels)?t.accessLevels.filter(o=>!(o!=null&&o.trash)):[];return u.jsxs(u.Fragment,{children:[u.jsx(ru,{"aria-describedby":A,color:"primary",onClick:_,size:"small",children:u.jsx(Iu,{fontSize:"small"})}),u.jsx(bu,{id:A,open:j,anchorEl:x,onClose:p,anchorOrigin:{vertical:"bottom",horizontal:"right"},transformOrigin:{vertical:"top",horizontal:"left"},children:u.jsxs(Su,{sx:{minWidth:200,p:0},children:[u.jsxs(hu,{onClick:y,children:[u.jsx(du,{sx:{minWidth:36,color:"success.main"},children:u.jsx($u,{fontSize:"small"})}),u.jsx(xu,{primary:"اختصاص به کاربر",primaryTypographyProps:{sx:{color:"success.main",fontSize:"0.875rem"}}})]}),u.jsxs(hu,{onClick:f,children:[u.jsx(du,{sx:{minWidth:36,color:"info.main"},children:u.jsx(Bu,{fontSize:"small"})}),u.jsx(xu,{primary:"افزودن سطح دسترسی",primaryTypographyProps:{sx:{color:"info.main",fontSize:"0.875rem"}}})]}),i.length>0&&u.jsxs(u.Fragment,{children:[u.jsx(au,{sx:{pl:1.5,py:.5,bgcolor:"action.hover"},children:u.jsx(w,{variant:"caption",color:"text.secondary",children:"مدیریت سطح دسترسی:"})}),i.map((o,b)=>u.jsx(au,{sx:{pl:1,pr:.5},children:u.jsxs(d,{container:!0,alignItems:"center",justifyContent:"space-between",children:[u.jsx(w,{variant:"body2",sx:{py:.5,pl:.5},children:H(o==null?void 0:o.name)||(o==null?void 0:o.name)||"-"}),u.jsxs(d,{gap:.5,children:[u.jsx(ru,{size:"small",color:"primary",onClick:()=>F(o),children:u.jsx(ku,{fontSize:"small"})}),u.jsx(ru,{size:"small",color:"error",onClick:()=>m(o),children:u.jsx(Ou,{fontSize:"small"})})]})]})},(o==null?void 0:o.key)||b))]})]})})]})},u6=()=>{const[t,C]=c.useState([]),[E,g]=c.useState(0),[x,D]=c.useState(10),[e,h]=c.useState(""),[_,p]=c.useState(1),[y,f]=c.useState([]),[F,m]=c.useState([]),[j,A]=c.useState(""),i=fu(s=>s.userSlice.selectedSubUser),o=Y(),b=async()=>{try{o(ou());const s=await N.get(`/get_all_pos_company/?role=${J()}${W("slaughter")||W("steward")?`&role_key=${i==null?void 0:i.key}`:""}`);m(s.data),o(Q())}catch(s){console.error("Error fetching brands:",s),o(Q())}},R=s=>{var n,S,r;return(S=(n=s==null?void 0:s.owner)==null?void 0:n.role)!=null&&S.includes("KillHouse")?J()==="KillHouse":(r=s==null?void 0:s.owner)!=null&&r.includes("Steward")?J()==="Steward":!1},M=async s=>{var n,S;try{o(ou());let r=`/user-pos-machine/?search=filter&value=${e}&role=${J()}${W("slaughter")||W("steward")?`&role_key=${i==null?void 0:i.key}`:""}&page=${s}&page_size=${x}`;j&&(r+=`&company=${j}`);const $=await N.get(r);C(((n=$.data)==null?void 0:n.results)||[]),g(((S=$.data)==null?void 0:S.count)||0)}catch(r){console.error("Error fetching devices:",r)}finally{o(Q())}},G=s=>{M(s),p(s)},z=s=>{D(s),p(1)},a=s=>{h(s.target.value)};c.useEffect(()=>{const s=t==null?void 0:t.map((n,S)=>{var L,K,U,v,iu;const r=(n==null?void 0:n.owner)||{},$=(n==null?void 0:n.posCompany)||{},lu=n!=null&&n.recipient?`${((L=n==null?void 0:n.recipient)==null?void 0:L.firstName)||""} ${((K=n==null?void 0:n.recipient)==null?void 0:K.lastName)||""}`.trim()+((U=n==null?void 0:n.recipient)!=null&&U.mobile?` (${(v=n==null?void 0:n.recipient)==null?void 0:v.mobile} - ${((iu=n==null?void 0:n.recipient)==null?void 0:iu.agentType)==="dispenser"?"توزیع کننده":"نماینده"})`:""):"-",Z=Array.isArray(n==null?void 0:n.accessLevels)?n.accessLevels.filter(k=>!(k!=null&&k.trash)):[],B=Z.length>0?u.jsx(V,{container:!0,gap:.5,flexWrap:"wrap",children:Z.map((k,ju)=>u.jsx(mu,{label:H(k==null?void 0:k.name)||(k==null?void 0:k.name)||"-",size:"small"},(k==null?void 0:k.key)||ju))}):"-";return[_===1?S+1:S+x*(_-1)+1,($==null?void 0:$.name)||"-",(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.posUniqueId)||(n==null?void 0:n.posId)||"-",r!=null&&r.fullname?`${r==null?void 0:r.fullname} (${(r==null?void 0:r.mobile)??"-"})`:"-",(r==null?void 0:r.nationalId)||(r==null?void 0:r.nationalCode)||"-",n!=null&&n.createDate?Eu(n==null?void 0:n.createDate):"-",B,lu,n!=null&&n.active?"فعال":"غیرفعال",R(n)?u.jsx(Wu,{device:n},(n==null?void 0:n.id)||(n==null?void 0:n.key)||`device-${S}`):u.jsx(_u,{sx:{fontSize:20,mt:1,color:"gray"}})]});f(s)},[t,_,x]),c.useEffect(()=>{b()},[o,i==null?void 0:i.key]),c.useEffect(()=>{M(_)},[j,x,i==null?void 0:i.key]);const l=async s=>{s.preventDefault(),M(1)},I=u.jsx(V,{container:!0,alignItems:"center",justifyContent:"space-between",gap:2,mb:1,padding:2,width:"100%",children:u.jsx(V,{container:!0,width:"100%",alignItems:"center",justifyContent:"space-between",gap:O.SMALL,children:u.jsxs(V,{container:!0,alignItems:"center",gap:O.SMALL,xs:12,md:"auto",children:[u.jsx(pu,{size:"small",style:{minWidth:210},disablePortal:!0,id:"brand",options:Array.isArray(F)?F.map(s=>({data:s,label:`${(s==null?void 0:s.name)||""}`})):[],onChange:(s,n)=>{var S;A((S=n==null?void 0:n.data)==null?void 0:S.key)},renderInput:s=>u.jsx(su,{fullWidth:!0,...s,label:"انتخاب برند دستگاه"})}),u.jsxs(V,{container:!0,alignItems:"center",gap:O.SMALL,children:[u.jsx(su,{size:"small",autoComplete:"off",label:"جستجو",variant:"outlined",style:{width:250},value:e,onChange:a}),u.jsx(T,{type:"submit",onClick:l,endIcon:u.jsx(zu,{}),children:"جستجو"})]})]})})});return u.jsx(au,{display:"flex",justifyContent:"center",children:u.jsxs(V,{container:!0,xs:12,lg:10,children:[u.jsx(Du,{}),I,u.jsx(wu,{data:y,columns:["ردیف","برند دستگاه","شماره سریال","شماره پذیرنده","شماره ترمینال","کلمه عبور امنیتی","کلید پوز","مالک","کدملی","تاریخ ایجاد","سطوح دسترسی","تحویل گیرنده","فعال / غیرفعال","عملیات"],handlePageChange:G,totalRows:E,page:_,perPage:x,handlePerRowsChange:z,title:"مدیریت دستگاه ها"})]})})};export{u6 as default};