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>
52 lines
1.7 KiB
Go
52 lines
1.7 KiB
Go
package controllers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/sujit-baniya/fiber-boilerplate/pkg/services"
|
|
)
|
|
|
|
type crearCotizacionRequest struct {
|
|
ClienteID uint `json:"cliente_id"`
|
|
Alcance string `json:"alcance"`
|
|
TipoProyecto string `json:"tipo_proyecto"`
|
|
Items []services.ItemCotizacion `json:"items"`
|
|
}
|
|
|
|
// CreateCotizacion genera el PDF de una cotización a partir de la plantilla activa
|
|
// tipo 'cotizacion' + los items ya calculados por quien llama (Claude decide los
|
|
// valores consultando /api/v2/tarifas, el backend solo arma y suma el documento).
|
|
// La lógica real vive en services.CrearCotizacion, compartida con la tool del agente.
|
|
// POST /api/v2/cotizaciones
|
|
func CreateCotizacion(c *fiber.Ctx) error {
|
|
var req crearCotizacionRequest
|
|
if err := c.BodyParser(&req); err != nil {
|
|
return c.Status(400).JSON(fiber.Map{"error": err.Error()})
|
|
}
|
|
|
|
doc, total, err := services.CrearCotizacion(req.ClienteID, req.Alcance, req.TipoProyecto, req.Items, generadoPorFromContext(c))
|
|
if err != nil {
|
|
return c.Status(400).JSON(fiber.Map{"error": err.Error()})
|
|
}
|
|
|
|
return c.Status(201).JSON(fiber.Map{
|
|
"ok": true,
|
|
"message": fmt.Sprintf("Cotización #%d generada", doc.ID),
|
|
"total": total,
|
|
"documento": doc,
|
|
})
|
|
}
|
|
|
|
// generadoPorFromContext distingue si la petición vino del dashboard (sesión web,
|
|
// AuthApi) o de la API admin/agente (AdminApiAuth con ADMIN_API_KEY / bot).
|
|
func generadoPorFromContext(c *fiber.Ctx) string {
|
|
if c.Get("X-Agent-Channel") == "telegram" {
|
|
return "telegram"
|
|
}
|
|
if c.Get("Authorization") != "" || c.Get("X-API-Key") != "" {
|
|
return "claude_api"
|
|
}
|
|
return "web"
|
|
}
|