diff --git a/TODO b/TODO
index 6b5822e..30f7d1e 100644
--- a/TODO
+++ b/TODO
@@ -1,56 +1,34 @@
- Grupo6 string `json:"grupo6"`
- Po int `json:"po" gorm:"index"`
- Co int `json:"co"`
- Colada string `json:"colada"`
- Calidad string `json:"calidad"`
- Matnr string `json:"matnr"`
- Dibujo int `json:"dibujo"`
- Operador string `json:"operador"`
- Serie int `json:"serie"`
- Nromatricula string `gorm:"primaryKey" json:"nromatricula"`
- NroBulto string `json:"nro_bulto"`
- EtiquetaDoble string `json:"etiqueta_doble"`
- Fecha int `json:"fecha"`
- Turno string `json:"turno"`
- Observacion1 string `json:"observacion1"`
- Observacion2 string `json:"observacion2"`
- Observacion3 string `json:"observacion3"`
- PaqueteLongitud float64 `json:"paquete_longitud"`
- PaqueteAncho int `json:"paquete_ancho"`
- PaqueteAlto float64 `json:"paquete_alto"`
- PaquetePeso int `json:"paquete_peso"`
- PaqueteNroSecciones int `json:"paquete_nro_secciones"`
- PaqueteNroMantos int `json:"paquete_nro_mantos"`
- PaqueteNroSeccManto int `json:"paquete_nro_secc_manto"`
- SeccionTipo string `gorm:"index" json:"seccion_tipo"`
- SeccionLongitud int `json:"seccion_longitud"`
- SeccionAncho float64 `json:"seccion_ancho"`
- SeccionAlto float64 `json:"seccion_alto"`
- Idioma string `json:"idioma"`
- Destino int `json:"destino"`
- Hora int `json:"hora"`
- Horario int `json:"horario"`
- Inst string `json:"inst"`
- Tren int `json:"tren"`
- Normed string `json:"normed"`
- Norpro string `json:"norpro"`
- Nortol string `json:"nortol"`
- Spras string `json:"spras"`
- Statu int `json:"statu"`
- Crlf string `json:"crlf"`
- Maquina int `json:"maquina"`
- Padre string `json:"padre"`
- Paqpadre string `json:"paqpadre"`
- RelevantTime string `json:"relevant_time"`
- Desvio float64 `json:"desvio"`
- Pesoteorico float64 `json:"pesoteorico"`
- PesoteoricoReal float64 `json:"pesoteorico_real"`
- DesvioTeoricoReal float64 `json:"desvio_teorico_real"`
- FechaImpresion string `json:"fecha_impresion"`
- PesoNivel1 float64 `json:"peso_nivel1"`
- L3Sended bool `json:"l3_sended,omitempty"`
- Confirmed bool `json:"confirmed,omitempty"`
- SAP bool `json:"sap,omitempty"`
- CreatedAt time.Time `gorm:"->;<-:create" json:"createdat,omitempty"`
- UpdatedAt time.Time `json:"updatedat,omitempty"`
- DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedat,omitempty"`
\ No newline at end of file
+
\ No newline at end of file
diff --git a/handlers/bundle.go b/handlers/bundle.go
index c04a13c..8cd5ed0 100644
--- a/handlers/bundle.go
+++ b/handlers/bundle.go
@@ -37,6 +37,13 @@ func BundleHandler(storage storage.Storager) httprouter.Handle {
fechas := r.FormValue("fechas")
// loading bed
evacuadores := r.FormValue("evacuadores")
+ // checkbox value
+ onoff := r.FormValue("confirmed")
+ // confirmed
+ confirmed := false
+ if onoff == "on" {
+ confirmed = true
+ }
// check form values
if codigo != "" {
// call storager
@@ -62,7 +69,7 @@ func BundleHandler(storage storage.Storager) httprouter.Handle {
return
}
// call storager
- data, err := storage.ListBundle(r.Context(), lb, inicio, final)
+ data, err := storage.ListBundle(r.Context(), lb, inicio, final, confirmed)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
diff --git a/handlers/index.go b/handlers/index.go
index 594afd9..b19e1da 100644
--- a/handlers/index.go
+++ b/handlers/index.go
@@ -3,15 +3,42 @@ package handlers
import (
"net/http"
"text/template"
+ "time"
+ "git.espin.casa/albert/cml04-falcon-ui/helper"
"git.espin.casa/albert/cml04-falcon-ui/storage"
+ "git.espin.casa/albert/cml04-falcon-ui/types"
"github.com/julienschmidt/httprouter"
)
func IndexHandler(storage storage.Storager) httprouter.Handle {
+ type PageView struct {
+ Stats *types.Stats
+ Bundles []types.BundleData
+ Barcodes []types.Barcode
+ }
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
+ // get current shift dates
+ dates, err := helper.GetShiftDates(time.Now())
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ //
+ bundles, err := storage.ShiftListBundle(r.Context(), dates[0], dates[1])
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ // create view
+ view := &PageView{
+ Stats: &types.Stats{},
+ Bundles: bundles,
+ Barcodes: []types.Barcode{},
+ }
+
t, _ := template.ParseFiles("templates/base.html", "templates/index.html")
- err := t.Execute(w, nil)
+ err = t.Execute(w, view)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
diff --git a/helper/helper.go b/helper/helper.go
index 21a6429..e596a21 100644
--- a/helper/helper.go
+++ b/helper/helper.go
@@ -1,6 +1,7 @@
package helper
import (
+ "fmt"
"strings"
"time"
)
@@ -24,3 +25,27 @@ func Dates(dr string) (start, finish time.Time, err error) {
}
return
}
+
+func GetShiftDates(inputTime time.Time) ([]time.Time, error) {
+ if inputTime.Hour() >= 6 && inputTime.Hour() < 14 {
+ // First shift: 6 to 14 hours
+ startTime := time.Date(inputTime.Year(), inputTime.Month(), inputTime.Day(), 6, 0, 0, 0, inputTime.Location())
+ endTime := time.Date(inputTime.Year(), inputTime.Month(), inputTime.Day(), 14, 0, 0, 0, inputTime.Location())
+
+ return []time.Time{startTime, endTime}, nil
+ } else if inputTime.Hour() >= 14 && inputTime.Hour() < 22 {
+ // Second shift: 14 to 22 hours
+ startTime := time.Date(inputTime.Year(), inputTime.Month(), inputTime.Day(), 14, 0, 0, 0, inputTime.Location())
+ endTime := time.Date(inputTime.Year(), inputTime.Month(), inputTime.Day(), 22, 0, 0, 0, inputTime.Location())
+
+ return []time.Time{startTime, endTime}, nil
+ } else if inputTime.Hour() >= 22 || inputTime.AddDate(0, 0, 1).Hour() < 6 {
+ // Third shift: 22 hours to 6 next day
+ startTime := time.Date(inputTime.Year(), inputTime.Month(), inputTime.Day(), 22, 0, 0, 0, inputTime.Location())
+ endTime := time.Date(inputTime.AddDate(0, 0, 1).Year(), inputTime.AddDate(0, 0, 1).Month(), inputTime.AddDate(0, 0, 1).Day(), 6, 0, 0, 0, inputTime.Location())
+
+ return []time.Time{startTime, endTime}, nil
+ } else {
+ return nil, fmt.Errorf("el horario de entrada no es válido")
+ }
+}
diff --git a/helper/helper_test.go b/helper/helper_test.go
new file mode 100644
index 0000000..700b23e
--- /dev/null
+++ b/helper/helper_test.go
@@ -0,0 +1,42 @@
+package helper
+
+import (
+ "testing"
+ "time"
+)
+
+func TestGetShiftDates(t *testing.T) {
+ // First case 1: First shift
+ inputTime := time.Date(2023, 1, 15, 7, 0, 0, 0, time.UTC)
+ expectedStart := time.Date(2023, 1, 15, 6, 0, 0, 0, time.UTC)
+ expectedEnd := time.Date(2023, 1, 15, 14, 0, 0, 0, time.UTC)
+ shifts, err := GetShiftDates(inputTime)
+ if err != nil {
+ t.Errorf("unexpected error GetShiftDates: %v", err)
+ }
+ if shifts[0] != expectedStart || shifts[1] != expectedEnd {
+ t.Errorf("not expected results: got %v, %v; want %v, %v", shifts[0], shifts[1], expectedStart, expectedEnd)
+ }
+ // Second case 1: Second shift
+ inputTime = time.Date(2023, 1, 15, 14, 0, 0, 0, time.UTC)
+ expectedStart = time.Date(2023, 1, 15, 14, 0, 0, 0, time.UTC)
+ expectedEnd = time.Date(2023, 1, 15, 22, 0, 0, 0, time.UTC)
+ shifts, err = GetShiftDates(inputTime)
+ if err != nil {
+ t.Errorf("unexpected error GetShiftDates: %v", err)
+ }
+ if shifts[0] != expectedStart || shifts[1] != expectedEnd {
+ t.Errorf("not expected results: got %v, %v; want %v, %v", shifts[0], shifts[1], expectedStart, expectedEnd)
+ }
+ // Third case 3: Third shift
+ inputTime = time.Date(2023, 1, 15, 23, 0, 0, 0, time.UTC)
+ expectedStart = time.Date(2023, 1, 15, 22, 0, 0, 0, time.UTC)
+ expectedEnd = time.Date(2023, 1, 16, 6, 0, 0, 0, time.UTC)
+ shifts, err = GetShiftDates(inputTime)
+ if err != nil {
+ t.Errorf("unexpected error GetShiftDates: %v", err)
+ }
+ if shifts[0] != expectedStart || shifts[1] != expectedEnd {
+ t.Errorf("not expected results: got %v, %v; want %v, %v", shifts[0], shifts[1], expectedStart, expectedEnd)
+ }
+}
diff --git a/storage/storage.go b/storage/storage.go
index c885371..bb19048 100644
--- a/storage/storage.go
+++ b/storage/storage.go
@@ -24,6 +24,7 @@ type Storager interface {
ListBarcode(ctx context.Context, lb types.LoadingBed, inicio, final time.Time) (barcodes []types.Barcode, err error)
Bundle(ctx context.Context, ua string) (bundle *types.BundleData, err error)
ListBundle(ctx context.Context, lb types.LoadingBed, inicio, final time.Time, confirmed bool) (bundles []types.BundleData, err error)
+ ShiftListBundle(ctx context.Context, inicio, final time.Time) (bundles []types.BundleData, err error)
}
type storage struct {
@@ -31,6 +32,14 @@ type storage struct {
mux sync.RWMutex
}
+// ShiftListBundle implements Storager.
+func (s *storage) ShiftListBundle(ctx context.Context, inicio, final time.Time) (bundles []types.BundleData, err error) {
+ if err := s.db.Where("created_at >= ? and created_at < ?", inicio, final).Find(&bundles).WithContext(ctx).Error; err != nil {
+ return nil, err
+ }
+ return
+}
+
// ListBundle implements Storager.
func (s *storage) ListBundle(ctx context.Context, lb types.LoadingBed, inicio time.Time, final time.Time, confirmed bool) (bundles []types.BundleData, err error) {
if lb == types.ALL {
diff --git a/templates/barcodes.html b/templates/barcodes.html
index b6d0e24..636d20d 100644
--- a/templates/barcodes.html
+++ b/templates/barcodes.html
@@ -4,38 +4,6 @@
-
-
-
Busqueda de códigos
@@ -112,7 +80,7 @@
- {{ range . }}
+ {{ range . }}
{{ .Barcode }}
{{ .FormatLoadingBed }}
diff --git a/templates/base.html b/templates/base.html
index b8fc488..4d7aa13 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -17,13 +17,65 @@
-
+
+
+
+
{{ template "body" . }}
diff --git a/templates/bcp.html b/templates/bcp.html
index 8bcb56d..5b898b4 100644
--- a/templates/bcp.html
+++ b/templates/bcp.html
@@ -3,40 +3,9 @@
{{define "body"}}
+
+
Orden corte placa
-
-
-
-
Orden de corte placa
diff --git a/templates/co.html b/templates/co.html
index ec55151..9d9a1d0 100644
--- a/templates/co.html
+++ b/templates/co.html
@@ -3,40 +3,9 @@
{{define "body"}}
+
+
Orden cliente
-
-
-
-
Orden de cliente
diff --git a/templates/hbcp.html b/templates/hbcp.html
index 43f76ab..058df8b 100644
--- a/templates/hbcp.html
+++ b/templates/hbcp.html
@@ -3,39 +3,9 @@
{{define "body"}}
+
+
Hoja cortes
-
-
-
Hoja patrón corte
diff --git a/templates/index.html b/templates/index.html
index f5edc24..07716df 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -3,38 +3,36 @@
{{define "body"}}
-
-
-
+
+
Panel principal
+
+
+
+ Estadísticas turno
+
+
+
+
+ Paq.Etiquetados
+ Eti.Leídas
+ Paq.Confirmados
+
+
+
+
+
+
+
+
+
+
+
@@ -65,14 +63,8 @@
-
- Estadísticas turno
-
-
-
100 Etiquetas leídas
-
-
+ {{ if .Bundles }}
Paquetes
@@ -83,15 +75,15 @@
UA
PO
CO
- Colada
Calidad
Código SAP
Producto
Peso
Desvío
- Confirmado
- Nivel 3
+ Conf.
+ N3
SAP
+ Fecha
@@ -99,37 +91,40 @@
UA
PO
CO
- Colada
Calidad
Código SAP
Producto
Peso
Desvío
- Confirmado
- Nivel 3
+ Conf.
+ N3
SAP
+ Fecha
+ {{ range .Bundles }}
- 9402555315
- 131620
- 40160750
- CE253242
- S 275 JR +AR
- BB01-140X12.1
- HEB140
- 4776
- -2.40
- No
- No
- No
+ {{ .Nromatricula }}
+ {{ .Po }}
+ {{ .Co }}
+ {{ .Calidad }}
+ {{ .Matnr }}
+ {{ .SeccionTipo }}
+ {{ .PaquetePeso }}
+ {{ .FormatDesvio }}
+ {{if .L3Sended }} Sí {{ else }} No {{ end }}
+ {{if .Confirmed }} Sí {{ else }} No {{ end }}
+ {{if .SAP }} Sí {{ else }} No {{ end }}
+ {{ .FormatCreatedAt }}
+ {{ end }}
+ {{ end }}
{{ end }}
\ No newline at end of file
diff --git a/templates/lcp.html b/templates/lcp.html
index f09e794..7af868f 100644
--- a/templates/lcp.html
+++ b/templates/lcp.html
@@ -3,40 +3,9 @@
{{define "body"}}
+
+
Ordenes de corte layer
-
-
-
-
Orden de corte layer
diff --git a/templates/po.html b/templates/po.html
index 74ebef9..c5ae3b1 100644
--- a/templates/po.html
+++ b/templates/po.html
@@ -3,40 +3,9 @@
{{define "body"}}
+
+
Orden fabricación
-
-
-
-
Orden de producción
diff --git a/types/stats.go b/types/stats.go
new file mode 100644
index 0000000..a1f680e
--- /dev/null
+++ b/types/stats.go
@@ -0,0 +1,20 @@
+package types
+
+import "time"
+
+type Stats struct {
+ PaquetesEtiquetados int
+ EtiquetasLeidas int
+ PaquetesConfirmados int
+ PaquetesPrimeras int
+ ToneladasPrimeras float64
+ PaquetesSegundas int
+ ToneladasSegundas float64
+ PaquetesPendientes int
+ ToneladasPendientes float64
+ PaquetesCortas int
+ ToneladasCortas float64
+ DesvioPromedio float64
+ FechaInicio time.Time
+ FechaFinal time.Time
+}