2 lines
16 KiB
JavaScript
2 lines
16 KiB
JavaScript
import{j as u,b as J,B as X,T as L,ai as fe,b5 as xe,ak as oe,I as pe,b2 as Fe,b3 as he}from"./mui-vendor-CkIVaoQP.js";import{L as re,j as Q,h as V,A as le,p as ae,N as Ae,G as l,S as H,X as De,v as ne,W as Ce,_ as _e,O as Ee,C as ge}from"./index-Cr86_nOs.js";import{B as Pe}from"./BackButton-7Uc4b2uz.js";import{r,f as ce}from"./react-vendor-CmFgShSM.js";import{a as m,u as ie}from"./redux-vendor-B7uoacJt.js";import{R as se}from"./ResponsiveTable-Dua7tTwQ.js";import{I as Ie,f as Te}from"./toBase64-CmPKyXM7.js";import{r as Re}from"./resizeImage-Csf2MO3w.js";import{d as ze}from"./Delete-CTUmuli-.js";import{d as ke}from"./Search-DLgMQCPC.js";import"./FilterAlt-RwhTl5ac.js";import"./styled-components.browser.esm-gS9mh05b.js";import"./PublishedWithChanges-wX45M9wC.js";const Le=m("PROVINCE_WAREHOUSE_ARCHIVE",async e=>{const{data:a,status:c}=await Q.post("ware-house-archive/",e);return{data:a,status:c}}),We=m("PROVINCE_GET_WAREHOUSE_ARCHIVE",async(e,{dispatch:a})=>{var c,x;try{a(re());const n={date1:e==null?void 0:e.date1,date2:e==null?void 0:e.date2,search:(e==null?void 0:e.search)??"filter",value:(e==null?void 0:e.value)??"",page:(e==null?void 0:e.page)??1,page_size:(e==null?void 0:e.page_size)??10};e!=null&&e.archive_type&&(n.archive_type=e.archive_type),e!=null&&e.owner_type&&(n.owner_type=e.owner_type);const{data:s,status:b}=await Q.get("ware-house-archive/",{params:n});return a(V()),{data:s,status:b}}catch(n){return a(V()),{error:((x=(c=n.response)==null?void 0:c.data)==null?void 0:x.result)||"خطا در دریافت اطلاعات"}}}),Ne=m("PROVINCE_DELETE_WAREHOUSE_ARCHIVE",async({key:e},{dispatch:a})=>{var c,x;try{a(re());const n="ware-house-archive/0/",{data:s,status:b}=await Q.delete(`${n}?key=${e}`);return a(V()),{data:s,status:b}}catch(n){return a(V()),{error:((x=(c=n.response)==null?void 0:c.data)==null?void 0:x.result)||"خطا در حذف بایگانی"}}}),Be=m("PROVINCE_GET_TOTAL_KILLHOUSE_REMAIN_WEIGHT",async(e,{dispatch:a})=>{var c,x;try{a(re());const n=typeof window<"u"?window.location.pathname:"",s=(n==null?void 0:n.split("/").filter(Boolean).pop())==="steward",b=s?"total-steward-remain-weight/":"total-kill-house-remain-weight/",S={search:(e==null?void 0:e.search)??"filter",value:(e==null?void 0:e.value)??"",page:(e==null?void 0:e.page)??1,page_size:(e==null?void 0:e.page_size)??(s?40:10),quota:(e==null?void 0:e.quota)??!1};e!=null&&e.date1&&(S.date1=e.date1),e!=null&&e.date2&&(S.date2=e.date2),s?S.owner_type=(e==null?void 0:e.owner_type)??"steward":S.role=(e==null?void 0:e.role)??"SuperAdmin";const{data:F,status:_}=await Q.get(b,{params:S});return a(V()),{data:F,status:_}}catch(n){return a(V()),{error:((x=(c=n.response)==null?void 0:c.data)==null?void 0:x.result)||"خطا در دریافت اطلاعات"}}}),Me=m("PROVINCE_GET_TOTAL_KILLHOUSE_ARCHIVE_DASHBOARD",async(e,{dispatch:a})=>{var c,x;try{a(re());const n=(e==null?void 0:e.owner_type)==="steward",s=n?"total-guild-steward-archive-dashboard/":"total-kill-house-archive-dashboard/",b={search:(e==null?void 0:e.search)??"filter",value:(e==null?void 0:e.value)??"",date1:e==null?void 0:e.date1,date2:e==null?void 0:e.date2,page:(e==null?void 0:e.page)??1,page_size:(e==null?void 0:e.page_size)??10};n?b.owner_type=e.owner_type??"steward":b.role=(e==null?void 0:e.role)??"SuperAdmin";const{data:S,status:F}=await Q.get(s,{params:b});return a(V()),{data:S,status:F}}catch(n){return a(V()),{error:((x=(c=n.response)==null?void 0:c.data)==null?void 0:x.result)||"خطا در دریافت اطلاعات"}}}),Oe=({killhouseName:e,killhouseKey:a,dayData:c,governmentalData:x,freeData:n,selectedType:s,onSuccess:b})=>{const S=ie(),F=ce(),[_]=r.useContext(le),[R,d]=r.useState(""),[U,$]=r.useState([]),[E,P]=r.useState(""),D=s==="free"?n:x,Y=()=>{const j=F.pathname.split("/").filter(Boolean);return j.includes("steward")?"steward":j.includes("killhouse")?"kill_house":j[j.length-1]||"kill_house"},z=j=>{var k;if($(j),j[0]){const A=(k=j[0])==null?void 0:k.file;Re(A,p=>{const i=Te(p);P(i)})}else P("")},Z=()=>{const j=Y(),A={role:De(),owner_key:a,archive_type:j,date:c,weight:D.amount,quota:s,image:E||"",description:R||""};S(Le(A)).then(p=>{var i;(i=p.payload)!=null&&i.error?_({vertical:"top",horizontal:"center",msg:p.payload.error,severity:"error"}):(_({vertical:"top",horizontal:"center",msg:"بایگانی با موفقیت ثبت شد",severity:"success"}),S(Ae({top:!1,left:!1,bottom:!1,right:!1,title:null,content:null,size:null})),d(""),P(""),$([]),b&&b())})};return u.jsxs(l,{container:!0,gap:2,children:[u.jsxs(l,{item:!0,xs:12,children:[u.jsx(L,{variant:"h6",color:"primary",gutterBottom:!0,children:e}),u.jsxs(L,{variant:"body2",color:"text.secondary",children:["تاریخ: ",ae(c)]})]}),u.jsx(l,{item:!0,xs:12,children:u.jsxs(J,{sx:{padding:2,backgroundColor:s==="free"?"#e8f5e9":"#e3f2fd",borderRadius:2,mt:1,border:`2px solid ${s==="free"?"#2e7d32":"#1565c0"}`,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[u.jsxs(L,{variant:"subtitle2",gutterBottom:!0,fontWeight:"bold",sx:{color:s==="free"?"#2e7d32":"#1565c0"},children:["موجودی ",s==="free"?"آزاد":"دولتی",":"]}),u.jsxs(L,{variant:"h6",fontWeight:"600",children:[D.amount.toLocaleString()," کیلوگرم"]})]})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(Ie,{onChange:z,images:U,maxNumber:1,title:"بارگذاری سند"})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(oe,{fullWidth:!0,multiline:!0,rows:5,label:"توضیحات",variant:"outlined",value:R,onChange:j=>{d(j.target.value)},placeholder:"توضیحات خود را وارد کنید..."})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(X,{variant:"contained",color:"primary",fullWidth:!0,onClick:Z,disabled:!R.trim(),children:"ثبت بایگانی"})})]})},Ve=()=>{const e=ie(),[a]=r.useContext(le),x=ce().pathname.split("/").filter(Boolean),s=(x[x.length-1]||"")==="steward",b=s?"مباشر":"کشتارگاه",[S,F]=r.useState([]),[_,R]=r.useState([]),[d,U]=r.useState("governmental"),$=s?40:10,[E,P]=r.useState(1),[D,Y]=r.useState($),[z,Z]=r.useState(0),j=()=>{U(A=>A==="free"?"governmental":"free")},k=r.useCallback(()=>{const A={search:"filter",value:"",page:E,page_size:D,quota:d==="free"?"free":"governmental",...s?{owner_type:"steward"}:{}};e(Be(A)).then(p=>{var i,W;if((i=p.payload)!=null&&i.error)a({vertical:"top",horizontal:"center",msg:p.payload.error,severity:"error"});else if((W=p.payload)!=null&&W.data){const h=p.payload.data.results||[],M=p.payload.data.count||0;if(Z(M),h.length===0&&M>0&&E>1){P(C=>Math.max(C-1,1));return}const w=h.filter(C=>C.info!==null).map(C=>{var q,y;return{id:C.key,key:C.key,name:s&&C.guildsName||C.name,governmental:((q=C.info)==null?void 0:q.governmental)||[],free:((y=C.info)==null?void 0:y.free)||[]}});R(w)}})},[e,a,s,E,D,d]);return r.useEffect(()=>{P(1),Y(s?40:10)},[s]),r.useEffect(()=>{k()},[k]),r.useEffect(()=>{const A=_.map(i=>{const W=d==="free"?i.free:i.governmental,h=Array.isArray(W)?W.filter(w=>w==null?void 0:w.amount):[];if(!h.length)return null;const M=h.reduce((w,C)=>w+((C==null?void 0:C.amount)||0),0);return{killhouse:i,nonZeroDays:h,totalWeight:M}}).filter(Boolean);if(!A.length&&z>0&&E>1){P(i=>Math.max(i-1,1));return}const p=A.map((i,W)=>{const{killhouse:h,nonZeroDays:M,totalWeight:w}=i,C=[...new Set(M.map(y=>y.day))].sort(),q=u.jsx(J,{sx:{display:"flex",gap:1,flexWrap:"wrap",alignItems:"center",width:"100%",justifyContent:"flex-start"},children:C.map((y,ee)=>{const o=h.governmental.find(N=>N.day===y),g=h.free.find(N=>N.day===y),I=d==="free"?(g==null?void 0:g.amount)||0:(o==null?void 0:o.amount)||0;return I?u.jsxs(X,{variant:"outlined",size:"small",onClick:()=>{e(Ae({right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,size:360,title:`جزئیات موجودی - ${ae(y)}`,content:u.jsx(Oe,{killhouseName:h.name,killhouseKey:h.key,dayData:y,governmentalData:o||{day:y,amount:0},freeData:g||{day:y,amount:0},selectedType:d,onSuccess:k})}))},sx:{minWidth:90,minHeight:42,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",padding:"2px 8px",backgroundColor:"#e3f2fd",borderColor:"primary.main","&:hover":{backgroundColor:"#bbdefb"}},children:[u.jsx(L,{variant:"caption",sx:{fontSize:{xs:"11px",md:"14px"},color:"text.secondary",marginBottom:"0px"},children:ae(y)}),u.jsxs(L,{variant:"caption",sx:{fontSize:{xs:"11px",md:"13px"},color:d==="free"?"#2e7d32":"#1565c0",fontWeight:600},children:[d==="free"?"آزاد":"دولتی",":"," ",I.toLocaleString()]})]},`day-${ee}-${y}`):null}).filter(Boolean)},`days-${h.id}`);return[(E-1)*D+W+1,h.name||"نامشخص",w.toLocaleString(),q]});F(p)},[d,_,k,e,E,D,z]),u.jsxs(l,{container:!0,spacing:2,px:2,mt:H.SMALL,children:[u.jsx(l,{item:!0,xs:12,children:u.jsx(J,{sx:{display:"flex",alignItems:"flex-start",flexDirection:"column",justifyContent:"space-between",mb:2},children:u.jsx(l,{children:u.jsx(fe,{control:u.jsx(xe,{checked:d==="free",onChange:j,color:"primary"}),label:u.jsxs(J,{sx:{display:"flex",alignItems:"center",gap:1},children:[u.jsx(L,{variant:"body2",sx:{color:d==="governmental"?"#1565c0":"#666",fontWeight:d==="governmental"?600:400},children:"دولتی"}),u.jsx(L,{variant:"body2",color:"text.secondary",children:"/"}),u.jsx(L,{variant:"body2",sx:{color:d==="free"?"#2e7d32":"#666",fontWeight:d==="free"?600:400},children:"آزاد"})]}),labelPlacement:"start"})})})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(se,{title:"مانده فعال "+(d==="free"?"آزاد":"دولتی"),columns:["ردیف",b,`کل مانده ${d==="free"?"آزاد":"دولتی"} (کیلوگرم)`,"روزها"],data:S,totalRows:z,page:E,perPage:D,handlePageChange:A=>P(A),handlePerRowsChange:A=>{Y(A),P(1)}})})]})},G=e=>{let a=Number(e).toFixed(2).replace(/\d(?=(\d{3})+\.)/g,"$&,"),c=a.split(".");return c.length>1&&(a=c[0]),a},Ye=()=>{const e=ie(),[a]=r.useContext(le),n=ce().pathname.split("/").filter(Boolean).includes("steward"),s=n?"نام مباشر":"نام کشتارگاه",[b,S]=r.useState([]),[F,_]=r.useState(1),[R,d]=r.useState(10),[U,$]=r.useState(0),[E,P]=r.useState([]),[D,Y]=r.useState(1),[z,Z]=r.useState(10),[j,k]=r.useState(0),[A,p]=r.useState(""),[i,W]=r.useState(!1),[h,M]=r.useState(ne(new Date).format("YYYY-MM-DD")),[w,C]=r.useState(ne(new Date).format("YYYY-MM-DD")),q=o=>{e(Ee({title:"تأیید حذف",size:"auto",content:u.jsxs(l,{container:!0,spacing:2,children:[u.jsx(l,{item:!0,xs:12,container:!0,justifyContent:"center",alignItems:"center",children:u.jsx(L,{variant:"body1",children:"آیا از حذف این بایگانی اطمینان دارید؟"})}),u.jsx(l,{item:!0,xs:6,mt:4,children:u.jsx(X,{fullWidth:!0,variant:"contained",color:"error",onClick:()=>{e(ge()),e(Ne({key:o,ownerType:n?"steward":"kill_house"})).then(g=>{var I;(I=g.payload)!=null&&I.error?a({vertical:"top",horizontal:"center",msg:g.payload.error,severity:"error"}):(a({vertical:"top",horizontal:"center",msg:"حذف با موفقیت انجام شد",severity:"success"}),ee())})},children:"بله"})}),u.jsx(l,{item:!0,xs:6,mt:4,children:u.jsx(X,{fullWidth:!0,variant:"outlined",onClick:()=>e(ge()),children:"خیر"})})]})}))},y=()=>{const o={search:"filter",value:A,page:D,page_size:z,...n?{owner_type:"steward"}:{role:"SuperAdmin"}};i&&(o.date1=h,o.date2=w),e(Me(o)).then(g=>{var I,N;if((I=g.payload)!=null&&I.error)a({vertical:"top",horizontal:"center",msg:g.payload.error,severity:"error"});else if((N=g.payload)!=null&&N.data){const ue=g.payload.data.results||[];k(g.payload.data.count||0);const te=ue.map((v,t)=>{const B=(v==null?void 0:v.info)||{},f=(...O)=>{for(const K of O)if((B==null?void 0:B[K])!==void 0&&(B==null?void 0:B[K])!==null)return B[K];return 0},T=n?(v==null?void 0:v.guilds_name)||(v==null?void 0:v.guildsName)||(v==null?void 0:v.name)||"نامشخص":(v==null?void 0:v.name)||"نامشخص";return[(D-1)*z+t+1,T,G(f("total_count","totalCount"))||0,G(f("total_governmental_count","totalGovernmentalCount"))||0,G(f("total_free_count","totalFreeCount"))||0,G(f("total_weight","totalWeight"))||0,G(f("total_governmental_weight","totalGovernmentalWeight"))||0,G(f("total_free_weight","totalFreeWeight"))||0]});P(te)}})},ee=()=>{const o={search:"filter",value:"",page:F,page_size:R,...n?{archive_type:"steward",owner_type:"steward"}:{}};i&&(o.date1=h,o.date2=w),e(We(o)).then(g=>{var I,N;if((I=g.payload)!=null&&I.error)a({vertical:"top",horizontal:"center",msg:g.payload.error,severity:"error"});else if((N=g.payload)!=null&&N.data){const ue=g.payload.data.results||[],te=g.payload.data.count||0;if($(te),ue.length===0&&te>0&&F>1){_(t=>Math.max(t-1,1));return}const v=ue.map((t,B)=>{const f=(t==null?void 0:t.killHouse)||{},T=(t==null?void 0:t.steward)||{},O=(t==null?void 0:t.guild)||{},K=t==null?void 0:t.createDate,ye=(t==null?void 0:t.registererMobile)||"-",ve=(t==null?void 0:t.registerer)||"-",be=(t==null?void 0:t.quota)==="free"?"آزاد":"دولتی",je=(t==null?void 0:t.description)||"-",de=t==null?void 0:t.key,we=n?(t==null?void 0:t.guildsName)||(T==null?void 0:T.guildsName)||(T==null?void 0:T.fullname)||(O==null?void 0:O.name)||(t==null?void 0:t.ownerName)||(f==null?void 0:f.name)||"نامشخص":(f==null?void 0:f.name)||(t==null?void 0:t.ownerName)||"نامشخص",Se=n?(t==null?void 0:t.guildsCity)||(T==null?void 0:T.city)||(O==null?void 0:O.city)||(t==null?void 0:t.ownerCity)||(f==null?void 0:f.city)||"-":(f==null?void 0:f.city)||(t==null?void 0:t.ownerCity)||"-";return[(F-1)*R+B+1,K?_e(K):"-",t!=null&&t.date?ae(t.date):"-",we,Se,G((t==null?void 0:t.weight)||0)||0,be,ve,ye,je,u.jsx(pe,{color:"error",onClick:()=>q(de),size:"small",children:u.jsx(ze,{})},`delete-${de}`)]});S(v)}})};return r.useEffect(()=>{_(1)},[h,w,i]),r.useEffect(()=>{ee()},[h,w,i,F,R]),r.useEffect(()=>{y()},[h,w,i,D,z]),u.jsxs(l,{container:!0,direction:"column",alignItems:"center",spacing:2,px:2,mt:H.SMALL,children:[u.jsx(l,{children:u.jsxs(l,{container:!0,alignItems:"center",gap:H.SMALL,pt:1,children:[u.jsx(fe,{control:u.jsx(xe,{checked:i,onChange:o=>W(o.target.checked),color:"primary"})}),u.jsx(l,{children:u.jsx(Ce,{label:"از تاریخ",id:"date1",renderInput:o=>u.jsx(oe,{style:{width:"160px"},...o}),value:h,onChange:o=>{M(ne(o).format("YYYY-MM-DD"))}})}),u.jsx(l,{children:u.jsx(Ce,{label:"تا تاریخ",id:"date2",renderInput:o=>u.jsx(oe,{style:{width:"160px"},...o}),value:w,onChange:o=>{C(ne(o).format("YYYY-MM-DD"))}})}),u.jsxs(l,{container:!0,alignItems:"center",gap:H.TINY,children:[u.jsx(oe,{label:`جستجو در ${n?"مباشرها":"کشتارگاهها"}`,variant:"outlined",size:"small",sx:{width:"240px"},value:A,onChange:o=>p(o.target.value),onKeyPress:o=>{o.key==="Enter"&&y()}}),u.jsx(X,{variant:"contained",color:"primary",size:"small",startIcon:u.jsx(ke,{}),onClick:y,children:"جستجو"})]})]})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(se,{columns:["ردیف",s,"تعداد کل","تعداد دولتی","تعداد آزاد","وزن کل (کیلوگرم)","وزن دولتی (کیلوگرم)","وزن آزاد (کیلوگرم)"],title:"داشبورد جمع مانده "+(n?"مباشرها":"کشتارگاهها"),data:E,paginated:!0,totalRows:j,page:D,perPage:z,handlePageChange:o=>Y(o),handlePerRowsChange:o=>{Z(o),Y(1)}})}),u.jsx(l,{item:!0,xs:12,children:u.jsx(se,{columns:["ردیف","تاریخ بایگانی","تاریخ انبار",s,n?"شهر مباشر":"شهر","وزن (کیلوگرم)","نوع سهمیه","ثبت کننده","شماره تماس","توضیحات","عملیات"],title:"مانده بایگانی شده",data:b,totalRows:U,page:F,perPage:R,handlePageChange:o=>_(o),handlePerRowsChange:o=>{d(o),_(1)}})})]})},tu=()=>{const[e,a]=r.useState("active"),c=(x,n)=>{a(n)};return u.jsx(J,{display:"flex",justifyContent:"center",children:u.jsxs(l,{container:!0,justifyContent:"center",gap:H.SMALL,p:H.SMALL,direction:"column",xs:12,sm:12,md:10,lg:10,children:[u.jsx(l,{container:!0,children:u.jsx(Pe,{})}),u.jsxs(l,{container:!0,justifyContent:"center",direction:"column",alignItems:"center",children:[u.jsxs(Fe,{value:e,onChange:c,"aria-label":"dispensers stock slug tabs",scrollButtons:"auto",variant:"scrollable",allowScrollButtonsMobile:!0,children:[u.jsx(he,{label:"فعال",value:"active"}),u.jsx(he,{label:"بایگانی",value:"archive"})]}),u.jsxs(l,{container:!0,justifyContent:"center",px:2,py:3,children:[e==="active"&&u.jsx(Ve,{}),e==="archive"&&u.jsx(Ye,{})]})]})]})})};export{tu as default};
|