From daf0b2c2a181b0f40b2e97a94029d98f7c7a12da Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Thu, 9 Jul 2026 20:25:39 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20marcar=20pagada=20en=20cuentas=20por=20p?= =?UTF-8?q?agar=20sobreescrib=C3=ADa=20datos=20con=20ceros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UpdateCuentaPagar actualizaba TODAS las columnas incluyendo entidad_id=0, valor=0, descripcion='' cuando solo se enviaba estado+fecha_pago. Se agrega MarcarCuentaPagarPagada que solo toca estado y fecha_pago, con su endpoint POST /cuentas-pagar/:id/pagar. Co-Authored-By: Claude Sonnet 4.6 --- pkg/models/contabilidad.go | 7 ++++++ .../views/contabilidad/cuentas_pagar.html | 2 +- rest/controllers/contabilidad_controller.go | 23 +++++++++++++++++++ rest/routes/user.go | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/pkg/models/contabilidad.go b/pkg/models/contabilidad.go index b297055..6087e7c 100644 --- a/pkg/models/contabilidad.go +++ b/pkg/models/contabilidad.go @@ -522,6 +522,13 @@ func UpdateCuentaPagar(cp *CuentaPagar) error { }).Error } +func MarcarCuentaPagarPagada(id uint, fechaPago time.Time) error { + return app.Http.Database.DB.Model(&CuentaPagar{}).Where("id = ?", id).Updates(map[string]interface{}{ + "estado": "pagado", + "fecha_pago": fechaPago, + }).Error +} + func DeleteCuentaPagar(id uint) error { return app.Http.Database.DB.Delete(&CuentaPagar{}, id).Error } diff --git a/resources/views/contabilidad/cuentas_pagar.html b/resources/views/contabilidad/cuentas_pagar.html index 5d1216c..4773250 100644 --- a/resources/views/contabilidad/cuentas_pagar.html +++ b/resources/views/contabilidad/cuentas_pagar.html @@ -174,7 +174,7 @@ function pagarApp() { async doPagar(){ this.saving=true; try { - await axios.put(`/app/contabilidad/cuentas-pagar/${this.pagarId}`, {estado:'pagado',fecha_pago:this.pagoFecha}); + await axios.post(`/app/contabilidad/cuentas-pagar/${this.pagarId}/pagar`, {fecha_pago:this.pagoFecha}); this.showPagarModal=false; await this.load(); } catch(e){ this.error=e.response?.data?.error||'Error'; } finally{ this.saving=false; } diff --git a/rest/controllers/contabilidad_controller.go b/rest/controllers/contabilidad_controller.go index ee8717e..e103ed8 100644 --- a/rest/controllers/contabilidad_controller.go +++ b/rest/controllers/contabilidad_controller.go @@ -591,6 +591,29 @@ func UpdateCuentaPagar(c *fiber.Ctx) error { return c.JSON(fiber.Map{"ok": true}) } +func MarcarCuentaPagarPagada(c *fiber.Ctx) error { + id, err := strconv.ParseUint(c.Params("id"), 10, 32) + if err != nil { + return c.Status(400).JSON(fiber.Map{"error": "ID inválido"}) + } + var req struct { + FechaPago string `json:"fecha_pago"` + } + if err := c.BodyParser(&req); err != nil { + return c.Status(400).JSON(fiber.Map{"error": err.Error()}) + } + fecha := time.Now() + if req.FechaPago != "" { + if parsed, err := time.Parse("2006-01-02", req.FechaPago); err == nil { + fecha = parsed + } + } + if err := models.MarcarCuentaPagarPagada(uint(id), fecha); err != nil { + return c.Status(500).JSON(fiber.Map{"error": err.Error()}) + } + return c.JSON(fiber.Map{"ok": true}) +} + func DeleteCuentaPagar(c *fiber.Ctx) error { id, err := strconv.ParseUint(c.Params("id"), 10, 32) if err != nil { diff --git a/rest/routes/user.go b/rest/routes/user.go index b33e852..5e95b76 100755 --- a/rest/routes/user.go +++ b/rest/routes/user.go @@ -517,6 +517,7 @@ protected.Get("/contabilidad/consolidados", controllers.ContabilidadListConsolid protected.Get("/contabilidad/cuentas-pagar/list", controllers.GetCuentasPagar) protected.Post("/contabilidad/cuentas-pagar", controllers.CreateCuentaPagar) protected.Put("/contabilidad/cuentas-pagar/:id", controllers.UpdateCuentaPagar) + protected.Post("/contabilidad/cuentas-pagar/:id/pagar", controllers.MarcarCuentaPagarPagada) protected.Delete("/contabilidad/cuentas-pagar/:id", controllers.DeleteCuentaPagar) // ─── WebSMS (LabsMobile) ───────────────────────────────────────────────────