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) ───────────────────────────────────────────────────