feat: automatización de cotizaciones, contratos, actas y cuentas de cobro con IA
Implementa las 4 fases de la especificación de automatización: módulo de plantillas/tarifas editable por el equipo, generación de PDF (HTML+JS vía Chrome headless) para cotizaciones/contratos/arquitecturas/cuentas de cobro, chat propio en el dashboard reutilizando el mismo motor y tools del bot de Telegram, y nuevas tools del agente para crear estos documentos end-to-end. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
772a4a5656
commit
516220a8a1
@@ -0,0 +1,75 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"github.com/sujit-baniya/fiber-boilerplate/app"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// Tarifa es la tabla de precios/reglas de negocio que la IA usa para calcular
|
||||
// cotizaciones y contratos: valor por hora según tipo de servicio, licencias M365,
|
||||
// tipos de VM Azure recurrentes, márgenes estándar, etc.
|
||||
type Tarifa struct {
|
||||
gorm.Model
|
||||
Categoria string `json:"categoria" gorm:"column:categoria;size:50;not null;index"` // hora_servicio | licencia | vm_azure | margen | otro
|
||||
Nombre string `json:"nombre" gorm:"column:nombre;size:150;not null"`
|
||||
Valor float64 `json:"valor" gorm:"column:valor;not null"`
|
||||
Moneda string `json:"moneda" gorm:"column:moneda;size:10;default:'COP'"`
|
||||
Unidad string `json:"unidad" gorm:"column:unidad;size:20"` // hora | mes | unico | porcentaje
|
||||
Notas string `json:"notas" gorm:"column:notas;type:text"`
|
||||
Activo bool `json:"activo" gorm:"column:activo;default:true"`
|
||||
}
|
||||
|
||||
func (Tarifa) TableName() string { return "tarifas" }
|
||||
|
||||
func GetAllTarifas(limit, offset int, search, categoria string) ([]Tarifa, int64, error) {
|
||||
var items []Tarifa
|
||||
var total int64
|
||||
db := app.Http.Database.DB.Model(&Tarifa{})
|
||||
if search != "" {
|
||||
db = db.Where("nombre ILIKE ?", "%"+search+"%")
|
||||
}
|
||||
if categoria != "" {
|
||||
db = db.Where("categoria = ?", categoria)
|
||||
}
|
||||
if err := db.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := db.Order("categoria ASC, nombre ASC").Limit(limit).Offset(offset).Find(&items).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
return items, total, nil
|
||||
}
|
||||
|
||||
// GetTarifasActivas retorna todas las tarifas activas, opcionalmente filtradas por categoría.
|
||||
// Es lo que usan los endpoints de generación para calcular precios.
|
||||
func GetTarifasActivas(categoria string) ([]Tarifa, error) {
|
||||
var items []Tarifa
|
||||
db := app.Http.Database.DB.Where("activo = ?", true)
|
||||
if categoria != "" {
|
||||
db = db.Where("categoria = ?", categoria)
|
||||
}
|
||||
if err := db.Order("nombre ASC").Find(&items).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
func GetTarifaByID(id uint) (*Tarifa, error) {
|
||||
var item Tarifa
|
||||
if err := app.Http.Database.DB.First(&item, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &item, nil
|
||||
}
|
||||
|
||||
func CreateTarifa(t Tarifa) error {
|
||||
return app.Http.Database.DB.Create(&t).Error
|
||||
}
|
||||
|
||||
func UpdateTarifa(id uint, updates map[string]interface{}) error {
|
||||
return app.Http.Database.DB.Model(&Tarifa{}).Where("id = ?", id).Updates(updates).Error
|
||||
}
|
||||
|
||||
func DeleteTarifa(id uint) error {
|
||||
return app.Http.Database.DB.Delete(&Tarifa{}, id).Error
|
||||
}
|
||||
Reference in New Issue
Block a user