| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- "use client"
- import { useState } from "react"
- import { FacturaHeader } from "@/components/factura/FacturaHeader"
- import { InfoTributariaForm } from "@/components/factura/InfoTributariaForm"
- import { InfoFacturaForm } from "@/components/factura/InfoFacturaForm"
- import { DetallesList } from "@/components/factura/DetallesList"
- import { ResumenTotales } from "@/components/factura/ResumenTotales"
- import { FacturaActions } from "@/components/factura/FacturaActions"
- import { XmlGenerationDialog } from "@/components/factura/XmlGenerationDialog"
- import { useFacturaState } from "@/hooks/factura/useFacturaState"
- import { useFacturaCalculations } from "@/hooks/factura/useFacturaCalculations"
- import { useXmlGeneration } from "@/hooks/factura/useXmlGeneration"
- export default function FacturaPage() {
- const [dialogOpen, setDialogOpen] = useState(false)
- const {
- infoTributaria,
- infoFactura,
- detalles,
- xmlGenerado,
- setXmlGenerado,
- handleInfoTributariaChange,
- handleInfoFacturaChange,
- agregarDetalle,
- actualizarDetalle,
- eliminarDetalle,
- updateInfoFactura
- } = useFacturaState()
- const { calcularTotalesImpuestos } = useFacturaCalculations(detalles, updateInfoFactura)
- const { generarXml, descargarXml } = useXmlGeneration()
- const handleGenerarXml = () => {
- const totalesImpuestos = calcularTotalesImpuestos()
- generarXml(
- infoTributaria,
- infoFactura,
- detalles,
- totalesImpuestos,
- setXmlGenerado
- )
- setDialogOpen(true)
- }
- const handleDescargarXml = () => {
- descargarXml(xmlGenerado, infoTributaria.ruc)
- }
- return (
- <div className="space-y-6">
- {/* Header */}
- <FacturaHeader />
- {/* Info Tributaria */}
- <InfoTributariaForm
- infoTributaria={infoTributaria}
- onChange={handleInfoTributariaChange}
- />
- {/* Info Factura */}
- <InfoFacturaForm
- infoFactura={infoFactura}
- onChange={handleInfoFacturaChange}
- />
- {/* Detalles */}
- <DetallesList
- detalles={detalles}
- onAgregarDetalle={agregarDetalle}
- onActualizarDetalle={actualizarDetalle}
- onEliminarDetalle={eliminarDetalle}
- />
- {/* Totales */}
- <ResumenTotales
- detalles={detalles}
- importeTotal={infoFactura.importeTotal}
- />
- {/* Acciones */}
- <FacturaActions onGenerarXml={handleGenerarXml} />
- {/* Modal de XML Generado */}
- <XmlGenerationDialog
- open={dialogOpen}
- onOpenChange={setDialogOpen}
- xmlGenerado={xmlGenerado}
- onDescargarXml={handleDescargarXml}
- />
- </div>
- )
- }
|