import{r as c,j as e}from"./login-aN2dRsX6.js";import{h as v,B as y,C as T}from"./query-c3dDncii.js";import{p as h,b as k,a as i}from"./alert-CsXKWu2a.js";import{B as _}from"./button_submit-wN0ayemz.js";import{D as C}from"./DataTable-D2rA17vR.js";import{P as K}from"./page_header-wdV8ucix.js";import{u as D,F as N}from"./modalJurnalCostum-CegFdN4Y.js";import{useModalTransaksiKas as S}from"./modalTransaksiKas-BE5YLH6S.js";import{f,b as w,c as E}from"./index-26bvdVY4.js";/* empty css               */import{C as B}from"./circle-plus-D9wc3WnO.js";import{E as F}from"./eye-By1xm0Dd.js";import"./app-gmlkJjeD.js";import"./ThemeProvider-Cx_yflmw.js";import"./search-4uBqei5W.js";import"./createLucideIcon-C44k9nIN.js";import"./delete-PVCdpT-9.js";import"./trash-CTcWUXGP.js";import"./index-B595qSOc.js";import"./react-number-format.es-iP3AzcWx.js";import"./Select-B6FG_hRH.js";import"./defineProperty-DRmM3rRU.js";import"./typeof-QjJsDpFa.js";import"./setPrototypeOf-B4fUID9J.js";import"./index-Ci65TyJp.js";import"./floating-ui.dom-C5vApqfE.js";import"./SelectTransaksiKas-DsODUtKN.js";import"./modalBrowseAkun-CPnbOv5J.js";import"./modalAkun-DKxSDKLU.js";import"./Modal-Dn58D0E5.js";import"./save-CB8xeERj.js";import"./x-CZwmhdFm.js";function ua(){const m=new URLSearchParams(window.location.search),b=m.get("tgl_awal")||f(new Date),j=m.get("tgl_akhir")||f(new Date),[o,x]=c.useState({tgl_awal:b,tgl_akhir:j}),[s,p]=c.useState(o),r=v(o),u=S({onSubmit:async()=>(r.refetch(),!0)}),d=[{label:e.jsx("center",{children:"Trans ID"}),width:150,align:"center",value:a=>a.trans_id},{label:e.jsx("center",{children:"Sumber"}),width:100,align:"center",value:a=>"akun"in a&&a.akun?"KAS":"BANK"},{label:e.jsx("center",{children:"Rekening"}),width:200,value:a=>"akun"in a&&a.akun?a.kas.nama:a.penempatan.nama},{label:e.jsx("center",{children:"Masuk"}),width:120,align:"right",value:a=>w(a.masuk|a.debet)},{label:e.jsx("center",{children:"Keluar"}),width:120,align:"right",value:a=>w(a.keluar|a.kredit)},{label:"Keterangan",value:a=>a.keterangan},{label:e.jsx("center",{children:"Trans Date"}),width:160,align:"center",value:a=>E(a.trans_date)},{label:e.jsx("center",{children:"User"}),width:120,align:"center",value:a=>{var n;return(n=a.user)==null?void 0:n.username}},{label:e.jsx("center",{}),width:80,align:"center",value:a=>e.jsx("span",{className:"c-pointer",onClick:()=>g.open(a),children:e.jsx(F,{size:18})})}],g=D({column:d,onDelete:async a=>{const{isConfirmed:n}=await h({message:"Apa kamu yakin akan membatalkan transaksi ini?",callback:async()=>{try{console.log("Deleting transaction with ID:",a);const t=await T(a);console.log(t);const l=await t.json();return t.status==200?(await k(l.message||"Transaksi berhasil dihapus"),!0):(await i(l.message||"Gagal menghapus transaksi"),!1)}catch(t){return console.error("Error deleting transaction:",t),t instanceof Error?i(t.message):i("Terjadi kesalahan saat menghapus transaksi"),!1}finally{r.refetch()}}});return n},onValidate:async a=>{const{isConfirmed:n}=await h({message:"Apa kamu yakin akan memvalidasi transaksi ini?",callback:async()=>{try{const t=await y(a);console.log(t);const l=await t.json();return t.status==200?(await k(l.message||"Transaksi berhasil divalidasi"),!0):(await i(l.message||"Gagal memvalidasi transaksi"),!1)}catch(t){return console.error("Error validating transaction:",t),t instanceof Error?i(t.message):i("Terjadi kesalahan saat memvalidasi transaksi"),!1}finally{r.refetch()}}});return n}});return c.useEffect(()=>{r.refetch()},[o]),e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"container",children:[e.jsx(K,{title:"Transaksi Kas",breadcrumb:[{title:"Transaksi",path:"/app/transaksi"},{title:"Kas",path:"/app/transaksi/kas"}]}),e.jsx(C,{data:r.data??[],column:d,search:!0,pagination:!0,item_per_page:15,loading:r.isLoading||r.isFetching,buttons:e.jsxs("div",{className:"d-flex gap-2",children:[e.jsxs("div",{className:"input-group",children:[e.jsx("input",{className:"form-control",type:"date",value:s.tgl_awal??"",onChange:a=>p({...s,tgl_awal:a.target.value})}),e.jsx("span",{className:"input-group-text",children:" sampai "}),e.jsx("input",{className:"form-control",type:"date",value:s.tgl_akhir??"",onChange:a=>p({...s,tgl_akhir:a.target.value})}),e.jsx(_,{className:"btn-secondary",icon:e.jsx(N,{size:18}),onClick:()=>{window.history.replaceState({},"",`?tgl_awal=${encodeURIComponent(s.tgl_awal)}&tgl_akhir=${encodeURIComponent(s.tgl_akhir)}`),x(s)},children:"Filter"})]}),e.jsxs("button",{className:"btn btn-primary d-flex gap-2 align-items-center justify-content-center",style:{width:230},onClick:()=>u.open(),children:[e.jsx(B,{size:18}),"Tambah Transaksi"]})]})})]}),g.modal,u.modal]})}export{ua as default};
