1import{m as y,r as s,s as p,f as j,n as g,j as n,B as v}from"./index-DfOJmvz4.js";import{O as w}from"./OfficeCashFlowSection-Dl8rZZ_H.js";import{importBankStatementMovements as A}from"./importBankStatement-CRonA0Qi.js";import{A as N}from"./arrow-left-DHLt5dfU.js";import{W as C}from"./wallet-DjkT_BNu.js";import"./form-CGjVjtQi.js";import"./label-B-DNcIAs.js";import"./input-Vet5F-CU.js";import"./textarea-BWprJflG.js";import"./select-CJff1OXZ.js";import"./index-6ZOEkj60.js";import"./index-BtGj9Er1.js";import"./chevron-down-UE20mCyh.js";import"./check-XU_nGxmM.js";import"./TestDataFillButton-DxKkR1nf.js";import"./dropdown-menu-By9cTOSf.js";import"./index-ivjWPsw3.js";import"./chevron-right-pbEstDsr.js";import"./localStorageStore-Csk9HjkB.js";import"./flask-conical-CYR3TkvV.js";import"./rotate-ccw-CiOcocQM.js";import"./randomUtils-BxS1LCYa.js";import"./types-Cpd3zVNa.js";import"./badge-Dbl0Jwtm.js";import"./trending-up-DK3lRMJo.js";import"./trending-down-BqLvFXqs.js";import"./format-9oAvKElA.js";import"./es-DYyshBza.js";import"./differenceInCalendarDays-CyB0mb81.js";import"./getTimezoneOffsetInMilliseconds-vKak5z5M.js";import"./DeleteConfirmDialog-CGD4ovZb.js";import"./alert-dialog-Bu3Oi65g.js";import"./table-DfwkKR6X.js";import"./types-Ctgwi9gV.js";import"./file-spreadsheet-DTWg_2WK.js";import"./plus-BrPtK6Sd.js";import"./search-CuA8j5sK.js";import"./ellipsis-ChaP9twA.js";import"./pencil-BjX4drB7.js";import"./trash-2-Br_Yo4vG.js";import"./index-C-llSyQH.js";import"./index-vseAPPBi.js";import"./checkbox-D-CdFUfS.js";import"./scroll-area-DpAp9dfv.js";import"./xlsx-CwpDMyS9.js";import"./upload-C_kbLsjP.js";import"./tabs-Czrmf5jI.js";import"./progress-DzZVASWB.js";import"./subMonths-DmDqQDVe.js";import"./addMonths-Bjx4jNjV.js";import"./startOfMonth-DGaJEfit.js";import"./endOfMonth-DQMs1Pvv.js";function M(a){const{toast:m}=y(),[i,c]=s.useState([]),[u,x]=s.useState([]),[b,f]=s.useState(!0),d=s.useCallback(async()=>{if(!a)return;const{data:r,error:e}=await p.from("bank_accounts").select("*").eq("owner_id",a).order("nombre_cuenta");!e&&r&&c(r)},[a]),l=s.useCallback(async()=>{if(!a)return;const{data:r,error:e}=await p.from("apartment_treasury_movements").select("*").eq("owner_id",a).order("fecha",{ascending:!1});if(!e&&r){const h=(r||[]).map(o=>({id:o.id,owner_id:o.owner_id,bank_account_id:o.bank_account_id,tipo_movimiento:o.tipo||"ingreso",categoria:o.concepto,subcategoria:null,concepto:o.concepto,monto:o.monto,fecha:o.fecha,metodo_pago:o.metodo||null,referencia:o.referencia||null,comprobante_url:null,notas:o.notas||null,created_at:o.created_at}));x(h)}},[a]),t=s.useCallback(async()=>{f(!0),await Promise.all([d(),l()]),f(!1)},[d,l]);return s.useEffect(()=>{a&&t()},[a,t]),{accounts:i,movements:u,loading:b,fetchAccounts:d,fetchMovements:l,fetchAll:t,deleteMovement:async r=>{const{error:e}=await p.from("apartment_treasury_movements").delete().eq("id",r);e?m({title:"Error",description:e.message,variant:"destructive"}):(m({title:"Movimiento eliminado"}),t())}}}async function k(a,m,i){const c=a.find(u=>u.id===m);c&&await p.from("bank_accounts").update({saldo_actual:c.saldo_actual+i}).eq("id",m)}function Ct(){const a=j(),{currentUser:m}=g(),i=m==null?void 0:m.profileId,{accounts:c,movements:u,loading:x,fetchAll:b,deleteMovement:f}=M(i),d=s.useCallback(async(t,_,r,e)=>{const h={owner_id:_,tipo:t.tipo_movimiento,concepto:t.concepto,monto:t.monto,fecha:t.fecha,bank_account_id:t.bank_account_id||null,metodo:t.metodo_pago||null,referencia:t.referencia||null,notas:t.notas||null};if(e){const{error:o}=await p.from("apartment_treasury_movements").update(h).eq("id",e.id);if(o)throw o;return t.bank_account_id&&(e.bank_account_id&&await k(r,e.bank_account_id,e.tipo_movimiento==="ingreso"?-e.monto:e.monto),await k(r,t.bank_account_id,t.tipo_movimiento==="ingreso"?t.monto:-t.monto)),"Movimiento actualizado"}else{const{error:o}=await p.from("apartment_treasury_movements").insert(h);if(o)throw o;return t.bank_account_id&&await k(r,t.bank_account_id,t.tipo_movimiento==="ingreso"?t.monto:-t.monto),"Movimiento registrado"}},[]),l=s.useCallback(async(t,_)=>{i&&await A({movements:t,bankAccountId:_,profileId:i,table:"apartment_treasury_movements"})},[i]);return i?x?n.jsx("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:"Cargando..."}):n.jsxs("div",{className:"container mx-auto p-4 max-w-7xl space-y-4",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(v,{variant:"ghost",size:"icon",onClick:()=>a(-1),children:n.jsx(N,{className:"h-5 w-5"})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(C,{className:"h-6 w-6 text-primary"}),n.jsxs("div",{children:[n.jsx("h1",{className:"text-2xl font-bold",children:"TesorerÃa de Departamentos"}),n.jsx("p",{className:"text-sm text-muted-foreground",children:"Flujo de caja y movimientos"})]})]})]}),n.jsx(w,{movements:u,accounts:c,profileId:i,onRefresh:b,onDelete:f,customSubmit:d,onBankStatementImport:l,propertyType:"apartment"})]}):n.jsx("div",{className:"flex items-center justify-center h-screen text-muted-foreground",children:"Cargando perfil..."})}export{Ct as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.