wip
This commit is contained in:
parent
489fed7471
commit
529751ae38
@ -7,10 +7,5 @@ $(document).ready(function () {
|
||||
isRange:true,
|
||||
color:"link",
|
||||
minuteSteps:1});
|
||||
// To access to bulmaCalendar instance of an element
|
||||
$('#submit').click(function() {
|
||||
const dateInput = $('#inicio').val();
|
||||
//$('#selected-date').text(`Fecha seleccionada: ${dateInput}`);
|
||||
});
|
||||
});
|
||||
|
||||
|
10
assets/js/bundle.js
Normal file
10
assets/js/bundle.js
Normal file
@ -0,0 +1,10 @@
|
||||
$(document).ready(function () {
|
||||
// Initialize all input of date type.
|
||||
const calendar = bulmaCalendar.attach('[type="date"]',{
|
||||
weekStart: 1,
|
||||
dateFormat: 'dd/MM/yyyy',
|
||||
type:"datetime",
|
||||
isRange:true,
|
||||
color:"link",
|
||||
minuteSteps:1});
|
||||
});
|
@ -36,12 +36,6 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle {
|
||||
codigo := r.FormValue("codigo")
|
||||
// date range
|
||||
fechas := r.FormValue("fechas")
|
||||
// get range dates
|
||||
inicio, final, err := helper.Dates(fechas)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// loading bed
|
||||
evacuadores := r.FormValue("evacuadores")
|
||||
// check form values
|
||||
@ -55,6 +49,12 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle {
|
||||
// append barcode to holder
|
||||
Barcodes = append(Barcodes, *data)
|
||||
} else {
|
||||
// get range dates
|
||||
inicio, final, err := helper.Dates(fechas)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// get loading bed from string
|
||||
lb, ok := types.MapLoadingBed[evacuadores]
|
||||
// if loading bed not found
|
||||
|
@ -1,10 +1,13 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"text/template"
|
||||
|
||||
"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"
|
||||
)
|
||||
|
||||
@ -20,24 +23,60 @@ func BundleHandler(storage storage.Storager) httprouter.Handle {
|
||||
}
|
||||
}
|
||||
|
||||
// if r.Method == http.MethodPost {
|
||||
// // barcodes holder
|
||||
// Bundles := []types.BundleData{}
|
||||
// // parse form data from formulary
|
||||
// if err := r.ParseForm(); err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
// }
|
||||
// // barcode
|
||||
// codigo := r.FormValue("codigo")
|
||||
// // date range
|
||||
// fechas := r.FormValue("fechas")
|
||||
// // get range dates
|
||||
// inicio, final, err := helper.Dates(fechas)
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
|
||||
// post method
|
||||
if r.Method == http.MethodPost {
|
||||
// bundles holder
|
||||
Bundles := []types.BundleData{}
|
||||
// parse form data from formulary
|
||||
if err := r.ParseForm(); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
// ua
|
||||
codigo := r.FormValue("ua")
|
||||
// date range
|
||||
fechas := r.FormValue("fechas")
|
||||
// loading bed
|
||||
evacuadores := r.FormValue("evacuadores")
|
||||
// check form values
|
||||
if codigo != "" {
|
||||
// call storager
|
||||
data, err := storage.Bundle(r.Context(), codigo)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// append barcode to holder
|
||||
Bundles = append(Bundles, *data)
|
||||
} else {
|
||||
// get range dates
|
||||
inicio, final, err := helper.Dates(fechas)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// get loading bed from string
|
||||
lb, ok := types.MapLoadingBed[evacuadores]
|
||||
// if loading bed not found
|
||||
if !ok {
|
||||
http.Error(w, fmt.Errorf("loading bed value not found").Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// call storager
|
||||
data, err := storage.ListBundle(r.Context(), lb, inicio, final)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
//set barcodes
|
||||
Bundles = data
|
||||
}
|
||||
// parse template files
|
||||
t, _ := template.ParseFiles("templates/base.html", "templates/bundle.html")
|
||||
// execute templates
|
||||
if err := t.Execute(w, Bundles); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,11 +34,11 @@ type storage struct {
|
||||
// ListBundle implements Storager.
|
||||
func (s *storage) ListBundle(ctx context.Context, lb types.LoadingBed, inicio time.Time, final time.Time) (bundles []types.BundleData, err error) {
|
||||
if lb == types.ALL {
|
||||
if err := s.db.Where("created_at >= ? and created_at < ?", inicio, final).Find(bundles).WithContext(ctx).Error; err != nil {
|
||||
if err := s.db.Where("created_at >= ? and created_at < ?", inicio, final).Find(&bundles).WithContext(ctx).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err := s.db.Where("loading_bed = ? and created_at >= ? and created_at < ?", lb, inicio, final).Find(bundles).WithContext(ctx).Error; err != nil {
|
||||
if err := s.db.Where("loading_bed = ? and created_at >= ? and created_at < ?", lb, inicio, final).Find(&bundles).WithContext(ctx).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
@ -47,7 +47,7 @@ func (s *storage) ListBundle(ctx context.Context, lb types.LoadingBed, inicio ti
|
||||
|
||||
// Bundle implements Storager.
|
||||
func (s *storage) Bundle(ctx context.Context, ua string) (bundle *types.BundleData, err error) {
|
||||
if err := s.db.First(bundle, ua).WithContext(ctx).Error; err != nil {
|
||||
if err := s.db.First(&bundle, ua).WithContext(ctx).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return
|
||||
|
@ -115,8 +115,8 @@
|
||||
{{ range . }}
|
||||
<tr>
|
||||
<td>{{ .Barcode }}</td>
|
||||
<td>{{ .LoadingBed }}</td>
|
||||
<td>{{ .CreatedAt }}</td>
|
||||
<td>{{ .FormatLoadingBed }}</td>
|
||||
<td>{{ .FormatCreatedAt }}</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
</tbody>
|
||||
@ -127,7 +127,5 @@
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
<script src="/assets/js/barcode.js">
|
||||
|
||||
</script>
|
||||
<script src="/assets/js/barcode.js"></script>
|
||||
{{ end }}
|
@ -40,11 +40,59 @@
|
||||
<div class="column">
|
||||
<nav class="panel is-link">
|
||||
<p class="panel-heading"><i class="fas fa-box" aria-hidden="true"></i> Busqueda Paquetes</p>
|
||||
<div class="panel-block">
|
||||
|
||||
</div>
|
||||
<form action="/bundle" method="post">
|
||||
<div class="panel-block">
|
||||
<div class="field">
|
||||
<label class="label">Unidad almacén</label>
|
||||
<div class="control">
|
||||
<p class="control has-icons-left">
|
||||
<input class="input is-link has-dropdown is-hoverable has-icons-right" type="text"
|
||||
id="ua" name="ua" minlength="10" maxlength="10" />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-block">
|
||||
<div class="field">
|
||||
<label class="label">Fechas</label>
|
||||
<div class="control">
|
||||
<p class="control has-icons-left">
|
||||
<input class="input is-link has-dropdown is-hoverable has-icons-right" type="date"
|
||||
id="fechas" name="fechas" required />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-block">
|
||||
<div class="field">
|
||||
<label class="label">Evacuadores</label>
|
||||
<div class="control">
|
||||
<p class="control has-icons-left">
|
||||
<div class="select">
|
||||
<select name="evacuadores" id="evacuadores">
|
||||
<option value="3">TODOS</option>
|
||||
<option value="1">ATA12</option>
|
||||
<option value="2">ATA345</option>
|
||||
</select>
|
||||
</div>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-block">
|
||||
<div class="buttons">
|
||||
<button type="submit" class="button is-link is-outlined">
|
||||
Busqueda
|
||||
</button>
|
||||
<button type="reset" class="button is-danger is-outlined">
|
||||
Reset
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
{{ if .}}
|
||||
<div class="column">
|
||||
<nav class="panel is-link">
|
||||
@ -62,8 +110,8 @@
|
||||
<th>Producto</th>
|
||||
<th>Peso</th>
|
||||
<th>Desvío</th>
|
||||
<th>Confirmado</th>
|
||||
<th>Nivel 3</th>
|
||||
<th><abbr title="Paquete confirmado">Conf.</abbr></th>
|
||||
<th><abbr title="Nivel 3">N3</abbr></th>
|
||||
<th>SAP</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -78,8 +126,8 @@
|
||||
<th>Producto</th>
|
||||
<th>Peso</th>
|
||||
<th>Desvío</th>
|
||||
<th>Confirmado</th>
|
||||
<th>Nivel 3</th>
|
||||
<th><abbr title="Paquete confirmado">Conf.</abbr></th>
|
||||
<th><abbr title="Nivel 3">N3</abbr></th>
|
||||
<th>SAP</th>
|
||||
</tr>
|
||||
</tfoot>
|
||||
@ -94,7 +142,7 @@
|
||||
<td>{{ .Matnr }}</td>
|
||||
<td>{{ .SeccionTipo }}</td>
|
||||
<td>{{ .PaquetePeso }}</td>
|
||||
<td>{{ .Desvio }}</td>
|
||||
<td>{{ .FormatDesvio }}</td>
|
||||
<td>{{ .L3Sended }}</td>
|
||||
<td>{{ .Confirmed }}</td>
|
||||
<td>{{ .SAP }}</td>
|
||||
@ -105,7 +153,8 @@
|
||||
</div>
|
||||
</nav>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
<script src="/assets/js/bundle.js"></script>
|
||||
{{ end }}
|
@ -22,6 +22,12 @@ var MapLoadingBed = map[string]LoadingBed{
|
||||
"3": ALL,
|
||||
}
|
||||
|
||||
var MapFormatBed = map[LoadingBed]string{
|
||||
ATA12: "ATA12",
|
||||
ATA345: "ATA345",
|
||||
ALL: "TODOS",
|
||||
}
|
||||
|
||||
type Barcode struct {
|
||||
Barcode string `gorm:"primaryKey"`
|
||||
LoadingBed LoadingBed
|
||||
@ -30,10 +36,14 @@ type Barcode struct {
|
||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedat,omitempty"`
|
||||
}
|
||||
|
||||
// func (b *Barcode) FormatCreatedAt() string {
|
||||
// return b.CreatedAt.Format("02/01/2006 15:04:03")
|
||||
// }
|
||||
func (b *Barcode) FormatLoadingBed() string {
|
||||
return MapFormatBed[b.LoadingBed]
|
||||
}
|
||||
|
||||
// func (b *Barcode) FormatUpdateAt() string {
|
||||
// return b.UpdatedAt.Format("02/01/2006 15:04:03")
|
||||
// }
|
||||
func (b *Barcode) FormatCreatedAt() string {
|
||||
return b.CreatedAt.Format("02/01/2006 15:04:03")
|
||||
}
|
||||
|
||||
func (b *Barcode) FormatUpdateAt() string {
|
||||
return b.UpdatedAt.Format("02/01/2006 15:04:03")
|
||||
}
|
||||
|
@ -70,95 +70,6 @@ func (BundleData) TableName() string {
|
||||
return "bundles"
|
||||
}
|
||||
|
||||
func (b *BundleData) BeforeSave(tx *gorm.DB) error {
|
||||
// calculate and assign teorical weight
|
||||
PesoTeorico(b)
|
||||
// calculation of the deviation of the actual weight from the theoretical weight
|
||||
if err := Desvio(b); err != nil {
|
||||
return err
|
||||
}
|
||||
// calculation of the "real" theorical weight means lenght + the lenght of the disc saw (10mm)
|
||||
PesoTeoricoReal(b)
|
||||
if err := DesvioReal(b); err != nil {
|
||||
return err
|
||||
}
|
||||
// // calculation of the deviation between theorical and SAP
|
||||
// if err := PesoDesvioSAP(b); err != nil {
|
||||
// return err
|
||||
// }
|
||||
return nil
|
||||
}
|
||||
|
||||
func PesoTeorico(b *BundleData) {
|
||||
// get the lenght of the bundle
|
||||
bl := b.PaqueteLongitud
|
||||
// weight per meter
|
||||
bw := b.PaqueteAlto
|
||||
// number of pieces
|
||||
bp := b.PaqueteNroSecciones
|
||||
// calculate theoretical weight
|
||||
bt := bl * bw * float64(bp)
|
||||
// set value
|
||||
b.Pesoteorico = bt
|
||||
}
|
||||
|
||||
func Desvio(b *BundleData) error {
|
||||
// check if theorical is 0
|
||||
if b.Pesoteorico == 0 {
|
||||
return fmt.Errorf("theorical weight is zero")
|
||||
}
|
||||
// calculate deviation
|
||||
dv := float64(b.PaquetePeso) - (b.Pesoteorico)
|
||||
// % of deviation
|
||||
pdv := (dv / float64(b.Pesoteorico)) * 100
|
||||
// set value
|
||||
b.Desvio = pdv
|
||||
// done
|
||||
return nil
|
||||
}
|
||||
|
||||
func PesoTeoricoReal(b *BundleData) {
|
||||
// get the lenght of the bundle
|
||||
bl := b.PaqueteLongitud + 0.01 // added 10 mm
|
||||
// weight per meter
|
||||
bw := b.PaqueteAlto
|
||||
// number of pieces
|
||||
bp := b.PaqueteNroSecciones
|
||||
// calculate theoretical weight
|
||||
bt := bl * bw * float64(bp)
|
||||
// set value
|
||||
b.PesoteoricoReal = bt
|
||||
}
|
||||
|
||||
func DesvioReal(b *BundleData) error {
|
||||
// check if theorical is 0
|
||||
if b.PesoteoricoReal == 0 {
|
||||
return fmt.Errorf("theorical weight is zero")
|
||||
}
|
||||
// calculate deviation
|
||||
dv := float64(b.PaquetePeso) - (b.PesoteoricoReal)
|
||||
// % of deviation
|
||||
pdv := (dv / float64(b.PesoteoricoReal)) * 100
|
||||
// set value
|
||||
b.DesvioTeoricoReal = pdv
|
||||
// done
|
||||
return nil
|
||||
}
|
||||
|
||||
func PesoDesvioSAP(b *BundleData) error {
|
||||
// check if theorical is 0
|
||||
if b.Pesoteorico == 0 {
|
||||
return fmt.Errorf("theorical weight is zero")
|
||||
}
|
||||
// check if SAP deviation is 0
|
||||
if b.PesoNivel1 == 0 {
|
||||
return fmt.Errorf("SAP deviation not found")
|
||||
}
|
||||
// get deviation
|
||||
dvs := b.PesoNivel1
|
||||
// calculates weight
|
||||
res := b.Pesoteorico + (b.Pesoteorico * (dvs / 100))
|
||||
// set weight value
|
||||
b.PesoNivel1 = res
|
||||
return nil
|
||||
func (b *BundleData) FormatDesvio() string {
|
||||
return fmt.Sprintf("%.3f", b.Desvio)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user