wip
This commit is contained in:
parent
489fed7471
commit
529751ae38
@ -7,10 +7,5 @@ $(document).ready(function () {
|
|||||||
isRange:true,
|
isRange:true,
|
||||||
color:"link",
|
color:"link",
|
||||||
minuteSteps:1});
|
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")
|
codigo := r.FormValue("codigo")
|
||||||
// date range
|
// date range
|
||||||
fechas := r.FormValue("fechas")
|
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
|
// loading bed
|
||||||
evacuadores := r.FormValue("evacuadores")
|
evacuadores := r.FormValue("evacuadores")
|
||||||
// check form values
|
// check form values
|
||||||
@ -55,6 +49,12 @@ func BarcodesHandler(storage storage.Storager) httprouter.Handle {
|
|||||||
// append barcode to holder
|
// append barcode to holder
|
||||||
Barcodes = append(Barcodes, *data)
|
Barcodes = append(Barcodes, *data)
|
||||||
} else {
|
} 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
|
// get loading bed from string
|
||||||
lb, ok := types.MapLoadingBed[evacuadores]
|
lb, ok := types.MapLoadingBed[evacuadores]
|
||||||
// if loading bed not found
|
// if loading bed not found
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"text/template"
|
"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/storage"
|
||||||
|
"git.espin.casa/albert/cml04-falcon-ui/types"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,24 +23,60 @@ func BundleHandler(storage storage.Storager) httprouter.Handle {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if r.Method == http.MethodPost {
|
// post method
|
||||||
// // barcodes holder
|
if r.Method == http.MethodPost {
|
||||||
// Bundles := []types.BundleData{}
|
// bundles holder
|
||||||
// // parse form data from formulary
|
Bundles := []types.BundleData{}
|
||||||
// if err := r.ParseForm(); err != nil {
|
// parse form data from formulary
|
||||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
if err := r.ParseForm(); err != nil {
|
||||||
// }
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
// // barcode
|
}
|
||||||
// codigo := r.FormValue("codigo")
|
// ua
|
||||||
// // date range
|
codigo := r.FormValue("ua")
|
||||||
// fechas := r.FormValue("fechas")
|
// date range
|
||||||
// // get range dates
|
fechas := r.FormValue("fechas")
|
||||||
// inicio, final, err := helper.Dates(fechas)
|
// loading bed
|
||||||
// if err != nil {
|
evacuadores := r.FormValue("evacuadores")
|
||||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
// check form values
|
||||||
// return
|
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.
|
// ListBundle implements Storager.
|
||||||
func (s *storage) ListBundle(ctx context.Context, lb types.LoadingBed, inicio time.Time, final time.Time) (bundles []types.BundleData, err error) {
|
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 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
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} 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
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,7 +47,7 @@ func (s *storage) ListBundle(ctx context.Context, lb types.LoadingBed, inicio ti
|
|||||||
|
|
||||||
// Bundle implements Storager.
|
// Bundle implements Storager.
|
||||||
func (s *storage) Bundle(ctx context.Context, ua string) (bundle *types.BundleData, err error) {
|
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 nil, err
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -115,8 +115,8 @@
|
|||||||
{{ range . }}
|
{{ range . }}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{{ .Barcode }}</td>
|
<td>{{ .Barcode }}</td>
|
||||||
<td>{{ .LoadingBed }}</td>
|
<td>{{ .FormatLoadingBed }}</td>
|
||||||
<td>{{ .CreatedAt }}</td>
|
<td>{{ .FormatCreatedAt }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -127,7 +127,5 @@
|
|||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script src="/assets/js/barcode.js">
|
<script src="/assets/js/barcode.js"></script>
|
||||||
|
|
||||||
</script>
|
|
||||||
{{ end }}
|
{{ end }}
|
@ -40,11 +40,59 @@
|
|||||||
<div class="column">
|
<div class="column">
|
||||||
<nav class="panel is-link">
|
<nav class="panel is-link">
|
||||||
<p class="panel-heading"><i class="fas fa-box" aria-hidden="true"></i> Busqueda Paquetes</p>
|
<p class="panel-heading"><i class="fas fa-box" aria-hidden="true"></i> Busqueda Paquetes</p>
|
||||||
<div class="panel-block">
|
<form action="/bundle" method="post">
|
||||||
|
<div class="panel-block">
|
||||||
</div>
|
<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>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{ if .}}
|
{{ if .}}
|
||||||
<div class="column">
|
<div class="column">
|
||||||
<nav class="panel is-link">
|
<nav class="panel is-link">
|
||||||
@ -62,8 +110,8 @@
|
|||||||
<th>Producto</th>
|
<th>Producto</th>
|
||||||
<th>Peso</th>
|
<th>Peso</th>
|
||||||
<th>Desvío</th>
|
<th>Desvío</th>
|
||||||
<th>Confirmado</th>
|
<th><abbr title="Paquete confirmado">Conf.</abbr></th>
|
||||||
<th>Nivel 3</th>
|
<th><abbr title="Nivel 3">N3</abbr></th>
|
||||||
<th>SAP</th>
|
<th>SAP</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -78,8 +126,8 @@
|
|||||||
<th>Producto</th>
|
<th>Producto</th>
|
||||||
<th>Peso</th>
|
<th>Peso</th>
|
||||||
<th>Desvío</th>
|
<th>Desvío</th>
|
||||||
<th>Confirmado</th>
|
<th><abbr title="Paquete confirmado">Conf.</abbr></th>
|
||||||
<th>Nivel 3</th>
|
<th><abbr title="Nivel 3">N3</abbr></th>
|
||||||
<th>SAP</th>
|
<th>SAP</th>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
@ -94,7 +142,7 @@
|
|||||||
<td>{{ .Matnr }}</td>
|
<td>{{ .Matnr }}</td>
|
||||||
<td>{{ .SeccionTipo }}</td>
|
<td>{{ .SeccionTipo }}</td>
|
||||||
<td>{{ .PaquetePeso }}</td>
|
<td>{{ .PaquetePeso }}</td>
|
||||||
<td>{{ .Desvio }}</td>
|
<td>{{ .FormatDesvio }}</td>
|
||||||
<td>{{ .L3Sended }}</td>
|
<td>{{ .L3Sended }}</td>
|
||||||
<td>{{ .Confirmed }}</td>
|
<td>{{ .Confirmed }}</td>
|
||||||
<td>{{ .SAP }}</td>
|
<td>{{ .SAP }}</td>
|
||||||
@ -105,7 +153,8 @@
|
|||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
|
||||||
</div>
|
</div>
|
||||||
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
<script src="/assets/js/bundle.js"></script>
|
||||||
{{ end }}
|
{{ end }}
|
@ -22,6 +22,12 @@ var MapLoadingBed = map[string]LoadingBed{
|
|||||||
"3": ALL,
|
"3": ALL,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var MapFormatBed = map[LoadingBed]string{
|
||||||
|
ATA12: "ATA12",
|
||||||
|
ATA345: "ATA345",
|
||||||
|
ALL: "TODOS",
|
||||||
|
}
|
||||||
|
|
||||||
type Barcode struct {
|
type Barcode struct {
|
||||||
Barcode string `gorm:"primaryKey"`
|
Barcode string `gorm:"primaryKey"`
|
||||||
LoadingBed LoadingBed
|
LoadingBed LoadingBed
|
||||||
@ -30,10 +36,14 @@ type Barcode struct {
|
|||||||
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedat,omitempty"`
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"deletedat,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (b *Barcode) FormatCreatedAt() string {
|
func (b *Barcode) FormatLoadingBed() string {
|
||||||
// return b.CreatedAt.Format("02/01/2006 15:04:03")
|
return MapFormatBed[b.LoadingBed]
|
||||||
// }
|
}
|
||||||
|
|
||||||
// func (b *Barcode) FormatUpdateAt() string {
|
func (b *Barcode) FormatCreatedAt() string {
|
||||||
// return b.UpdatedAt.Format("02/01/2006 15:04:03")
|
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"
|
return "bundles"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BundleData) BeforeSave(tx *gorm.DB) error {
|
func (b *BundleData) FormatDesvio() string {
|
||||||
// calculate and assign teorical weight
|
return fmt.Sprintf("%.3f", b.Desvio)
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user