import{j as e,S as h,W as se,c as ne,a4 as ie,aH as le,ab as re,a6 as W,a9 as _,B as H,M as z}from"./vendor-mui-CBBEb17G.js";import{A as oe,S as ce}from"./index-Dot-Q_SK.js";import{B as de}from"./index-BkhbTDKf.js";import{a as n,c as $}from"./vendor-react-BBazpZul.js";import{y as ue,e as R,t as G,at as xe,aO as fe,c4 as he,et as pe,bx as me,bn as je,I as ge,v as Q,aP as Z,be as J,x as Se,J as I,cn as be,b4 as De,aX as X,f2 as Ce,f3 as we,a_ as q,ao as U,w as ye,b0 as Fe,jP as K,K as Ye,c$ as ve,aT as Ie}from"./index-IP_FWtso.js";import"./vendor-utils-BveVE6Uf.js";import{T as Ae}from"./index-Dz6vPtCj.js";import"./vendor-charts-tGnAgELZ.js";const ee=n.createContext(void 0),Te=({children:c})=>{const[i,d]=n.useState(),[o,p]=n.useState([]),[f,m]=n.useState([]),[r,u]=n.useState(!1),[g,l]=n.useState(!1),[a,x]=n.useState(!1),[C,A]=n.useState(!1),[w,T]=n.useState(new Date),[S,N]=n.useState(ue().endOf("jYear").toDate()),[y,F]=n.useState(1),{clinicId:Y,officeId:v}=R(j=>j.doctorData),{getAllFinancialYearAsync:k}=G();n.useEffect(()=>{t()},[]),n.useEffect(()=>{m(o)},[o]);const t=async()=>{u(!0);try{const{data:j}=await k({ClinicId:Y,OfficeId:v});j&&p(j)}finally{u(!1)}},b={loading:r,setLoading:u,print:g,setPrint:l,editMode:C,setEditMode:A,fromDateValue:w,setFromDateValue:T,toDateValue:S,setToDateValue:N,value:y,setValue:F,allData:o,financialYearDataList:f,getData:t,rowSelected:i,setRowSelected:d,search:j=>{m(o.filter(E=>E.title.includes(j)))},openCloseFinanceYear:a,setOpenCloseFinanceYear:x};return e.jsx(ee.Provider,{value:b,children:c})},B=()=>n.useContext(ee);function Ne(){const[c,i]=n.useState(!1),[d,o]=n.useState(1),p=xe(),{editMode:f,setEditMode:m,fromDateValue:r,setFromDateValue:u,setToDateValue:g,toDateValue:l,rowSelected:a,setRowSelected:x,getData:C,setPrint:A,setOpenCloseFinanceYear:w}=B(),{register:T,handleSubmit:S,formState:{errors:N},reset:y,setValue:F}=fe(),{clinicId:Y,officeId:v}=R(s=>s.doctorData),{addNewFinancialYearAsync:k,updateFinancialYearById:t,deleteFinnancialYearById:D}=G(),b=async s=>{const{title:O}=s,P=new Date,V=P>l||P<r,L={title:O,startDate:r,endDate:l,isActive:d===1,isClosed:V,clinicId:Y,officeId:v},{message:M}=await k(L);I.success(M),i(!1),y(),x(void 0),C()},j=async s=>{const{title:O}=s,P=new Date,V=P>l||P<r,L={id:a.id,title:O,startDate:r,endDate:l,isActive:d===1,isClosed:V,clinicId:Y,officeId:v},{message:M}=await t(L);I.success(M),i(!1),y(),x(void 0),C()},E=async()=>{p({content:"آیا از حذف این آیتم مطمئن هستید؟"}).then(async()=>{const{statusCode:s}=await D(a.id);s===200&&(I.success("با موفقیت حذف شد"),x(void 0),C())})},te=[{toolTipTitle:"افزودن",icon:e.jsx(he,{fontSize:"large",color:"success"}),handler:()=>{i(!0),m(!1)},disabled:!1,show:!0},{toolTipTitle:"ویرایش",icon:e.jsx(pe,{fontSize:"large",color:a?"primary":"disabled"}),handler:()=>{F("title",a==null?void 0:a.title),u(a.startDate),g(a.endDate),o(a.isActive?1:0),i(!0),m(!0)},disabled:!a,show:!0},{toolTipTitle:"حذف",icon:e.jsx(me,{fontSize:"large",color:a?"error":"disabled"}),handler:()=>{E()},disabled:!a,show:!0},{toolTipTitle:"چاپ",icon:e.jsx(je,{fontSize:"large",color:"primary"}),handler:()=>{A(!0)},disabled:!1,show:!0},{toolTipTitle:"بستن سال مالی",icon:e.jsx(ge.FinanceIcon,{fontSize:"large",color:a&&!(a!=null&&a.isClosed)?"primary":"disabled"}),handler:()=>{w(!0)},disabled:!(a&&!(a!=null&&a.isClosed)),show:!0}],ae=s=>{console.log(s),f?j(s):b(s)};return e.jsxs(e.Fragment,{children:[e.jsx(h,{direction:"row",paddingY:1,spacing:1,children:te.filter(s=>s.show===!0).map(s=>e.jsx(se,{title:s.toolTipTitle,children:e.jsx(oe,{disabled:s.disabled,onClick:s.handler,children:s.icon})}))}),c&&e.jsxs(Q,{title:f?"ویرایش سال مالی":"افزودن سال مالی",maxWidth:"xs",onClose:()=>i(!1),children:[e.jsx(ne,{className:"m-2 !p-2 border rounded-lg",children:e.jsxs(h,{component:"form",marginBottom:0,spacing:2,children:[e.jsx(h,{width:"100%",children:e.jsx(Z,{autoFocus:!0,label:"عنوان سال مالی",name:"title",register:T,validation:{required:!0},error:!!N.title})}),e.jsx(h,{width:"100%",children:e.jsx(J,{disablePast:!1,onChange:s=>u(s),value:r,label:"از تاریخ"})}),e.jsx(h,{width:"100%",children:e.jsx(J,{disablePast:!1,onChange:s=>g(s),value:l,label:"تا تاریخ"})}),e.jsx(h,{width:"100%",children:e.jsxs(ie,{children:[e.jsx(le,{children:"وضعیت"}),e.jsxs(re,{row:!0,value:d.toString(),onChange:s=>o(+s.target.value),children:[e.jsx(W,{classes:{label:"!text-sm"},value:"1",control:e.jsx(_,{}),label:"فعال"}),e.jsx(W,{classes:{label:"!text-sm"},value:"0",control:e.jsx(_,{}),label:"غیرفعال"})]})]})})]})}),e.jsx(Se,{onClose:()=>i(!1),onSubmit:S(ae),submitlabel:f?"ویرایش":"افزودن"})]})]})}function ke(){const{loading:c,allData:i,setRowSelected:d,financialYearDataList:o,print:p,setPrint:f}=B(),m=$.useRef();$.useEffect(()=>{p&&(r(),f(!1))},[p]);const r=be.useReactToPrint({contentRef:m,pageStyle:`@media print {
      @page {  size: 'landscape'} !important;
    }`}),u=[{title:"عنوان",dataIndex:"title",key:"title",width:100},{title:"تاریخ شروع",dataIndex:"startDate",key:"startDate",render:(l,a)=>`${q(l)}`,width:100},{title:"تاریخ پایان",dataIndex:"endDate",key:"endDate",render:(l,a)=>`${q(l)}`,width:100},{title:"وضعیت",dataIndex:"isActive",key:"isActive",render:(l,a)=>l?e.jsx("span",{className:"text-green-500",children:"فعال"}):e.jsx("span",{className:"text-red-500",children:"غیرفعال"}),width:60},{title:"بسته",dataIndex:"isClosed",key:"isClosed",render:l=>l?e.jsx("span",{className:"text-red-500",children:"بسته شده"}):e.jsx("span",{className:"text-green-500",children:"باز"}),width:60}],g=De();return e.jsxs(e.Fragment,{children:[e.jsx(h,{className:"h-[75vh]",children:e.jsx(X,{rowKey:"id",loading:c,columns:u||[],data:o||[],onClick:l=>{d(l)}})}),e.jsx(Ce,{ref:m,children:e.jsx(we,{centerData:g,title:"سال مالی",children:e.jsx(X,{tableProps:{className:"!w-full"},rowKey:"id",loading:c,columns:u||[],data:o||[],onClick:l=>{d(l)}})})})]})}const Pe=({onClose:c})=>{const{rowSelected:i}=B(),{reorderAccountDocumentNumbers:d,closeFinancialYear:o}=Ye(),{clinicId:p,officeId:f}=R(t=>t.doctorData),{getAllFinancialYearAsync:m}=G(),[r,u]=n.useState(0),[g,l]=n.useState(new Set),[a,x]=n.useState(!1),[C,A]=n.useState([]),[w,T]=n.useState(null),S=[{id:1,label:"مرتب سازی شماره اسناد",content:e.jsxs(h,{className:"w-full p-2",children:[`مرتب سازی شماره اسناد  ${i==null?void 0:i.title}`,e.jsx(U,{color:"primary",onClick:()=>v(),children:"تایید"})]})},{id:2,label:"بستن سال مالی",content:e.jsxs(h,{className:"w-full p-2 gap-2",children:[e.jsx(ye,{loading:a,label:"سال مالی آینده",selectOption:C,value:w,onChange:t=>T(t)}),e.jsx(U,{color:"primary",onClick:()=>k(),children:"تایید"})]})}],N=async()=>{try{x(!0);const{data:t}=await m({ClinicId:p,OfficeId:f});if(!t)return;const D=t.map(b=>({label:b.title,value:b.id.toString()}));A(D)}finally{x(!1)}},y=t=>g.has(t),F=()=>{let t=g;y(r)&&(t=new Set(t.values()),t.delete(r)),u(D=>D+1),l(t)},Y=()=>{u(t=>t-1)},v=async()=>{try{if(x(!0),!i)return;const{message:t}=await d(i.id);I.success(t),F()}finally{x(!1)}},k=async()=>{try{if(!i)return;if(!w){I.warning("سال مالی آینده را انتخاب نمایید");return}x(!0);const{message:t}=await o({financialYearId:i.id,nextFinancialYear:+w.value});I.success(t),F()}finally{x(!1)}};return n.useEffect(()=>{if(r===S.length){c();return}},[r,S]),n.useEffect(()=>{N()},[]),e.jsx(Q,{title:"بستن سال مالی",onClose:c,children:e.jsx(Fe,{className:"m-1 !p-2",children:e.jsxs(K,{sx:{width:"100%"},children:[e.jsx(Stepper,{activeStep:r,children:S.map((t,D)=>{const b={},j={};return y(D)&&(b.completed=!1),e.jsx(e.Fragment,{children:e.jsx(Step,{...b,children:e.jsx(StepLabel,{...j,children:t.label})},t.id)})})}),e.jsxs($.Fragment,{children:[[0,1].some(t=>t===r)&&S[r].content,e.jsxs(K,{sx:{display:"flex",flexDirection:"row",pt:2},children:[e.jsx(H,{color:"inherit",disabled:r===0,onClick:Y,sx:{mr:1},children:"قبلی"}),e.jsx(K,{sx:{flex:"1 1 auto"}}),e.jsx(H,{onClick:F,children:r===S.length-1?"پایان":"بعدی"})]})]})]})})})},Be=()=>{const{userType:c}=R(f=>f.user),{search:i}=B(),[d,o]=n.useState(""),p=()=>{i(d)};return e.jsxs(h,{className:"h-full overflow-y-auto p-2 pb-10 border-l",spacing:1,children:[e.jsx(Ae,{className:+c===ve.accountant?"!bg-[#b0d8e7]":"",children:"نام "}),e.jsx(Z,{label:"1404 ...",onChange:o}),e.jsx(h,{component:"form",gap:1,children:e.jsx(U,{fullWidth:!0,startIcon:e.jsx(Ie,{}),onClick:p,children:"جستجو"})})]})};function Re(){const{openCloseFinanceYear:c,setOpenCloseFinanceYear:i}=B();return e.jsxs(ce,{children:[e.jsx(de,{prevRoutes:[{path:"/",title:"داشبورد"},{path:"",title:"مالی"}],currentRoute:"سال مالی"}),e.jsxs(z,{container:!0,xs:12,spacing:1,className:"!h-full",children:[e.jsx(z,{item:!0,xs:12,sm:2,children:e.jsx(Be,{})}),e.jsxs(z,{item:!0,xs:12,sm:10,spacing:1,children:[e.jsx(Ne,{}),e.jsx(ke,{})]})]}),c&&e.jsx(Pe,{onClose:()=>i(!1)})]})}function Ue(){return e.jsx(Te,{children:e.jsx(Re,{})})}export{Ue as default};
