fix: marcar pagada en cuentas por pagar sobreescribía datos con ceros
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 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
2ee5e2ea83
commit
daf0b2c2a1
@@ -522,6 +522,13 @@ func UpdateCuentaPagar(cp *CuentaPagar) error {
|
|||||||
}).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 {
|
func DeleteCuentaPagar(id uint) error {
|
||||||
return app.Http.Database.DB.Delete(&CuentaPagar{}, id).Error
|
return app.Http.Database.DB.Delete(&CuentaPagar{}, id).Error
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ function pagarApp() {
|
|||||||
async doPagar(){
|
async doPagar(){
|
||||||
this.saving=true;
|
this.saving=true;
|
||||||
try {
|
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();
|
this.showPagarModal=false; await this.load();
|
||||||
} catch(e){ this.error=e.response?.data?.error||'Error'; }
|
} catch(e){ this.error=e.response?.data?.error||'Error'; }
|
||||||
finally{ this.saving=false; }
|
finally{ this.saving=false; }
|
||||||
|
|||||||
@@ -591,6 +591,29 @@ func UpdateCuentaPagar(c *fiber.Ctx) error {
|
|||||||
return c.JSON(fiber.Map{"ok": true})
|
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 {
|
func DeleteCuentaPagar(c *fiber.Ctx) error {
|
||||||
id, err := strconv.ParseUint(c.Params("id"), 10, 32)
|
id, err := strconv.ParseUint(c.Params("id"), 10, 32)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -517,6 +517,7 @@ protected.Get("/contabilidad/consolidados", controllers.ContabilidadListConsolid
|
|||||||
protected.Get("/contabilidad/cuentas-pagar/list", controllers.GetCuentasPagar)
|
protected.Get("/contabilidad/cuentas-pagar/list", controllers.GetCuentasPagar)
|
||||||
protected.Post("/contabilidad/cuentas-pagar", controllers.CreateCuentaPagar)
|
protected.Post("/contabilidad/cuentas-pagar", controllers.CreateCuentaPagar)
|
||||||
protected.Put("/contabilidad/cuentas-pagar/:id", controllers.UpdateCuentaPagar)
|
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)
|
protected.Delete("/contabilidad/cuentas-pagar/:id", controllers.DeleteCuentaPagar)
|
||||||
|
|
||||||
// ─── WebSMS (LabsMobile) ───────────────────────────────────────────────────
|
// ─── WebSMS (LabsMobile) ───────────────────────────────────────────────────
|
||||||
|
|||||||
Reference in New Issue
Block a user