page.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. "use client"
  2. import { useState } from "react"
  3. import { FacturaHeader } from "@/components/factura/FacturaHeader"
  4. import { InfoTributariaForm } from "@/components/factura/InfoTributariaForm"
  5. import { InfoFacturaForm } from "@/components/factura/InfoFacturaForm"
  6. import { DetallesList } from "@/components/factura/DetallesList"
  7. import { ResumenTotales } from "@/components/factura/ResumenTotales"
  8. import { FacturaActions } from "@/components/factura/FacturaActions"
  9. import { XmlGenerationDialog } from "@/components/factura/XmlGenerationDialog"
  10. import { useFacturaState } from "@/hooks/factura/useFacturaState"
  11. import { useFacturaCalculations } from "@/hooks/factura/useFacturaCalculations"
  12. import { useXmlGeneration } from "@/hooks/factura/useXmlGeneration"
  13. export default function FacturaPage() {
  14. const [dialogOpen, setDialogOpen] = useState(false)
  15. const {
  16. infoTributaria,
  17. infoFactura,
  18. detalles,
  19. xmlGenerado,
  20. setXmlGenerado,
  21. handleInfoTributariaChange,
  22. handleInfoFacturaChange,
  23. agregarDetalle,
  24. actualizarDetalle,
  25. eliminarDetalle,
  26. updateInfoFactura
  27. } = useFacturaState()
  28. const { calcularTotalesImpuestos } = useFacturaCalculations(detalles, updateInfoFactura)
  29. const { generarXml, descargarXml } = useXmlGeneration()
  30. const handleGenerarXml = () => {
  31. const totalesImpuestos = calcularTotalesImpuestos()
  32. generarXml(
  33. infoTributaria,
  34. infoFactura,
  35. detalles,
  36. totalesImpuestos,
  37. setXmlGenerado
  38. )
  39. setDialogOpen(true)
  40. }
  41. const handleDescargarXml = () => {
  42. descargarXml(xmlGenerado, infoTributaria.ruc)
  43. }
  44. return (
  45. <div className="space-y-6">
  46. {/* Header */}
  47. <FacturaHeader />
  48. {/* Info Tributaria */}
  49. <InfoTributariaForm
  50. infoTributaria={infoTributaria}
  51. onChange={handleInfoTributariaChange}
  52. />
  53. {/* Info Factura */}
  54. <InfoFacturaForm
  55. infoFactura={infoFactura}
  56. onChange={handleInfoFacturaChange}
  57. />
  58. {/* Detalles */}
  59. <DetallesList
  60. detalles={detalles}
  61. onAgregarDetalle={agregarDetalle}
  62. onActualizarDetalle={actualizarDetalle}
  63. onEliminarDetalle={eliminarDetalle}
  64. />
  65. {/* Totales */}
  66. <ResumenTotales
  67. detalles={detalles}
  68. importeTotal={infoFactura.importeTotal}
  69. />
  70. {/* Acciones */}
  71. <FacturaActions onGenerarXml={handleGenerarXml} />
  72. {/* Modal de XML Generado */}
  73. <XmlGenerationDialog
  74. open={dialogOpen}
  75. onOpenChange={setDialogOpen}
  76. xmlGenerado={xmlGenerado}
  77. onDescargarXml={handleDescargarXml}
  78. />
  79. </div>
  80. )
  81. }