Private
Public Access
bueno es parte del plan de implementacion para el caso de uso de gestion
de stock
This commit is contained in:
1 parent
24e746b1b7
commit
6ed8805e21
40 files changed
+2748
-31
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package factura
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
r "repuestera_back/repositorios"
|
||||
)
|
||||
|
||||
func ObtenerFacturas(c *gin.Context) {
|
||||
filtros := r.FiltrosFactura{
|
||||
Numero: c.Query("numero"),
|
||||
Cliente: c.Query("cliente"),
|
||||
}
|
||||
|
||||
if raw := c.Query("clienteId"); raw != "" {
|
||||
id, err := strconv.ParseUint(raw, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "clienteId inválido"})
|
||||
return
|
||||
}
|
||||
filtros.ClienteID = uint(id)
|
||||
}
|
||||
|
||||
desde, err := fechaQuery(c.Query("desde"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "desde inválido, se espera YYYY-MM-DD"})
|
||||
return
|
||||
}
|
||||
hasta, err := fechaQuery(c.Query("hasta"))
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "hasta inválido, se espera YYYY-MM-DD"})
|
||||
return
|
||||
}
|
||||
filtros.Desde = desde
|
||||
filtros.Hasta = hasta
|
||||
|
||||
facturas, err := r.ObtenerRepositorios(c).Factura.Listar(filtros)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, facturas)
|
||||
}
|
||||
|
||||
func fechaQuery(valor string) (*time.Time, error) {
|
||||
if valor == "" {
|
||||
return nil, nil
|
||||
}
|
||||
fecha, err := time.Parse("2006-01-02", valor)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &fecha, nil
|
||||
}
|
||||
Reference in new issue
Block a user