feat: cuentas por cobrar usa listado de clientes en vez de entidades contables

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Lizandro GD
2026-07-13 02:44:19 +00:00
co-authored by Claude Sonnet 5
parent daf0b2c2a1
commit 6e281dfbda
4 changed files with 35 additions and 36 deletions
+9 -10
View File
@@ -61,8 +61,10 @@ func (Transaccion) TableName() string { return "contab_transacciones" }
type CuentaCobro struct {
gorm.Model
EntidadID uint `json:"entidad_id" gorm:"column:entidad_id;index;not null"`
Entidad Entidad `json:"entidad" gorm:"foreignKey:EntidadID"`
ClienteID uint `json:"cliente_id" gorm:"column:cliente_id;index;not null"`
Cliente Cliente `json:"cliente" gorm:"foreignKey:ClienteID"`
EntidadID *uint `json:"entidad_id" gorm:"column:entidad_id;index"`
Entidad *Entidad `json:"entidad" gorm:"foreignKey:EntidadID"`
Fecha time.Time `json:"fecha" gorm:"column:fecha;not null"`
Descripcion string `json:"descripcion" gorm:"column:descripcion;type:text"`
Valor float64 `json:"valor" gorm:"column:valor;not null"`
@@ -260,11 +262,11 @@ func DeleteTransaccion(id uint) error {
func GetAllCuentasCobro(limit, offset int, search string, estado string) ([]CuentaCobro, int64, error) {
var items []CuentaCobro
var total int64
db := app.Http.Database.DB.Model(&CuentaCobro{}).Preload("Entidad").Preload("Transaccion")
db := app.Http.Database.DB.Model(&CuentaCobro{}).Preload("Cliente").Preload("Entidad").Preload("Transaccion")
if search != "" {
db = db.Joins("JOIN contab_entidades ON contab_entidades.id = contab_cuentas_cobro.entidad_id").
Where("contab_entidades.nombre ILIKE ? OR contab_cuentas_cobro.descripcion ILIKE ?",
"%"+search+"%", "%"+search+"%")
db = db.Joins("JOIN clientes ON clientes.id = contab_cuentas_cobro.cliente_id").
Where("clientes.nombre ILIKE ? OR clientes.empresa ILIKE ? OR contab_cuentas_cobro.descripcion ILIKE ?",
"%"+search+"%", "%"+search+"%", "%"+search+"%")
}
if estado != "" {
db = db.Where("contab_cuentas_cobro.estado = ?", estado)
@@ -463,10 +465,7 @@ func CreateCuentaCobro(cc *CuentaCobro) error {
func UpdateCuentaCobro(cc *CuentaCobro) error {
return app.Http.Database.DB.Model(&CuentaCobro{}).Where("id = ?", cc.ID).Updates(map[string]interface{}{
"entidad_id": cc.EntidadID,
"fecha": cc.Fecha,
"descripcion": cc.Descripcion,
"valor": cc.Valor,
"cliente_id": cc.ClienteID,
"estado": cc.Estado,
"fecha_vencimiento": cc.FechaVencimiento,
"fecha_pago": cc.FechaPago,