diff --git a/assets/js/index.js b/assets/js/index.js
index 401f1b6..b65c2e8 100644
--- a/assets/js/index.js
+++ b/assets/js/index.js
@@ -1,6 +1,3 @@
$(document).ready(function () {
- setTimeout(function () {
- console.log("refresh");
- location.reload();
- }, 10 * 1000);
+
});
diff --git a/handlers/co.go b/handlers/co.go
new file mode 100644
index 0000000..8b291b0
--- /dev/null
+++ b/handlers/co.go
@@ -0,0 +1,33 @@
+package handlers
+
+import (
+ "html/template"
+ "net/http"
+ "strconv"
+
+ "git.espin.casa/albert/cml04-falcon-printer/storage"
+ "github.com/julienschmidt/httprouter"
+)
+
+func ListCustomerOrderHandler(storage storage.Storager) httprouter.Handle {
+ return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
+ // get po
+ po := ps.ByName("po")
+ iPo, _ := strconv.Atoi(po)
+ // get production orders
+ cos, err := storage.ListCostumerOrders(r.Context(), iPo)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ // create view
+ view := &PageView{
+ CustomerOrders: cos,
+ }
+ t, _ := template.ParseFiles("templates/base.html", "templates/index.html")
+ if err := t.Execute(w, view); err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
+ }
+}
diff --git a/handlers/index.go b/handlers/index.go
index 0f10691..603a8b0 100644
--- a/handlers/index.go
+++ b/handlers/index.go
@@ -5,16 +5,28 @@ import (
"net/http"
"git.espin.casa/albert/cml04-falcon-printer/storage"
+ "git.espin.casa/albert/cml04-falcon-printer/types"
"github.com/julienschmidt/httprouter"
)
type PageView struct {
+ ProductionOrders []*types.ProductionOrder
+ CustomerOrders []*types.CustomerOrder
}
func IndexHandler(storage storage.Storager) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
+ // get production orders
+ pos, err := storage.ListProductionOrders(r.Context(), 40)
+ if err != nil {
+ http.Error(w, err.Error(), http.StatusInternalServerError)
+ return
+ }
// create view
- view := &PageView{}
+ view := &PageView{
+ ProductionOrders: pos,
+ CustomerOrders: nil,
+ }
t, _ := template.ParseFiles("templates/base.html", "templates/index.html")
if err := t.Execute(w, view); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
diff --git a/routes/routes.go b/routes/routes.go
index f29fe7c..feff055 100644
--- a/routes/routes.go
+++ b/routes/routes.go
@@ -8,4 +8,5 @@ import (
func CreateRoutes(r *httprouter.Router, storage storage.Storager) {
r.GET("/", handlers.IndexHandler(storage))
+ r.GET("/cos/:po", handlers.ListCustomerOrderHandler(storage))
}
diff --git a/storage/storage.go b/storage/storage.go
index f680e11..4a4dbec 100644
--- a/storage/storage.go
+++ b/storage/storage.go
@@ -1,20 +1,43 @@
package storage
import (
+ "context"
"fmt"
"sync"
+ "git.espin.casa/albert/cml04-falcon-printer/types"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
-type Storager interface{}
+type Storager interface {
+ ListProductionOrders(ctx context.Context, limit int) ([]*types.ProductionOrder, error)
+ ListCostumerOrders(ctx context.Context, po int) ([]*types.CustomerOrder, error)
+}
type storage struct {
db *gorm.DB
mux sync.RWMutex
}
+// ListCostumerOrders implements Storager.
+func (s *storage) ListCostumerOrders(ctx context.Context, po int) ([]*types.CustomerOrder, error) {
+ cos := []*types.CustomerOrder{}
+ if err := s.db.WithContext(ctx).Order("c_order_no desc").Where("p_order_no = ?,po").Error; err != nil {
+ return nil, err
+ }
+ return cos, nil
+}
+
+// ListProductionOrders implements Storager.
+func (s *storage) ListProductionOrders(ctx context.Context, limit int) ([]*types.ProductionOrder, error) {
+ pos := []*types.ProductionOrder{}
+ if err := s.db.WithContext(ctx).Order("created_at,p_order_no desc").Limit(limit).Find(&pos).Error; err != nil {
+ return nil, err
+ }
+ return pos, nil
+}
+
type DBConfig struct {
Username string
Password string
diff --git a/templates/index.html b/templates/index.html
index 1d41b9f..8ec3cb0 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -14,8 +14,9 @@
@@ -23,10 +24,13 @@
diff --git a/types/co.go b/types/co.go
new file mode 100644
index 0000000..e742d79
--- /dev/null
+++ b/types/co.go
@@ -0,0 +1,87 @@
+package types
+
+import (
+ "time"
+
+ "gorm.io/gorm"
+)
+
+type CustomerOrder struct {
+ Inst string `json:"INST"`
+ DateTime string `json:"DATE_TIME"`
+ COrderNo int `json:"C_ORDER_NO" gorm:"primarykey;autoIncrement:false"`
+ POrderNo int `json:"P_ORDER_NO" gorm:"index"`
+ SchedulNo int `json:"SCHEDUL_NO"`
+ OrdWeight string `json:"ORD_WEIGHT"`
+ OrdLen string `json:"ORD_LEN"`
+ OrLenTU string `json:"OR_LEN_T_U"`
+ OrLenTL string `json:"OR_LEN_T_L"`
+ PackType int `json:"PACK_TYPE"`
+ SectLayer int `json:"SECT_LAYER"`
+ LayerPack int `json:"LAYER_PACK"`
+ SecLastL int `json:"SEC_LAST_L"`
+ TotalSect int `json:"TOTAL_SECT"`
+ PackWidth int `json:"PACK_WIDTH"`
+ PackHigh int `json:"PACK_HIGH"`
+ OutpTolU int `json:"OUTP_TOL_U"`
+ OutpTolD int `json:"OUTP_TOL_D"`
+ LogoCode int `json:"LOGO_CODE"`
+ SecondLab string `json:"SECOND_LAB"`
+ PaintText string `json:"PAINT_TEXT"`
+ AddLabel1 string `json:"ADD_LABEL1"`
+ AddLabel2 string `json:"ADD_LABEL2"`
+ AddLabel3 string `json:"ADD_LABEL3"`
+ MaterCode string `json:"MATER_CODE"`
+ ProduDate int `json:"PRODU_DATE"`
+ LangLabel string `json:"LANG_LABEL"`
+ Warehouse string `json:"WAREHOUSE"`
+ Location string `json:"LOCATION"`
+ Marking string `json:"MARKING"`
+ DisForwar string `json:"DIS_FORWAR"`
+ NumTies int `json:"NUM_TIES"`
+ DisTies string `json:"DIS_TIES"`
+ DisMachin string `json:"DIS_MACHIN"`
+ Vbeln string `json:"VBELN"`
+ Posnr string `json:"POSNR"`
+ CoType string `json:"CO_TYPE"`
+ LoadBed int `json:"LOAD_BED"`
+ SecNum int `json:"SEC_NUM"`
+ Numpal int `json:"NUMPAL"`
+ Numbul string `json:"NUMBUL"`
+ Marfab int `json:"MARFAB"`
+ Sortb string `json:"SORTB"`
+ Strol1 int `json:"STROL1"`
+ Strol2 string `json:"STROL2"`
+ Strol3 int `json:"STROL3"`
+ Strol4 int `json:"STROL4"`
+ Strol5 int `json:"STROL5"`
+ Strol6 int `json:"STROL6"`
+ Strol7 int `json:"STROL7"`
+ Strol8 int `json:"STROL8"`
+ Strol9 int `json:"STROL9"`
+ Strol10 int `json:"STROL10"`
+ Strol11 int `json:"STROL11"`
+ Strol12 int `json:"STROL12"`
+ Strol13 int `json:"STROL13"`
+ Strol14 int `json:"STROL14"`
+ Strol15 int `json:"STROL15"`
+ Strol16 string `json:"STROL16"`
+ Strol17 string `json:"STROL17"`
+ Strol18 string `json:"STROL18"`
+ Strol19 string `json:"STROL19"`
+ Strol20 string `json:"STROL20"`
+ Strol21 string `json:"STROL21"`
+ Strol22 string `json:"STROL22"`
+ Strol23 string `json:"STROL23"`
+ Strol24 string `json:"STROL24"`
+ Strol25 string `json:"STROL25"`
+ Strol26 string `json:"STROL26"`
+ Strol27 string `json:"STROL27"`
+ CreatedAt time.Time `gorm:"->;<-:create" json:"createdat,omitempty"`
+ UpdatedAt time.Time `json:"updated_at,omitempty"`
+ DeletedAt gorm.DeletedAt `gorm:"index"`
+}
+
+func (CustomerOrder) TableName() string {
+ return "sap_co"
+}
diff --git a/types/po.go b/types/po.go
new file mode 100644
index 0000000..ba401c5
--- /dev/null
+++ b/types/po.go
@@ -0,0 +1,78 @@
+package types
+
+import (
+ "time"
+
+ "gorm.io/gorm"
+)
+
+type ProductionOrder struct {
+ Inst string `json:"INST"`
+ DateTime string `json:"DATE_TIME"`
+ POrderNo int `json:"P_ORDER_NO" gorm:"primarykey;autoIncrement:false"`
+ SchedulNo int `json:"SCHEDUL_NO"`
+ SeqNumber int `json:"SEQ_NUMBER"`
+ PptimeWfc string `json:"PPTIME_WFC"`
+ PptimeMsc string `json:"PPTIME_MSC"`
+ SteelGrad string `json:"STEEL_GRAD"`
+ ITemp string `json:"I_TEMP"`
+ IHeight string `json:"I_HEIGHT"`
+ IWidth string `json:"I_WIDTH"`
+ ISection string `json:"I_SECTION"`
+ HeatingSt int `json:"HEATING_ST"`
+ FTarTemp string `json:"F_TAR_TEMP"`
+ FSection string `json:"F_SECTION"`
+ FSectType string `json:"F_SECT_TYPE"`
+ TotWeight string `json:"TOT_WEIGHT"`
+ TBeamBla int `json:"T_BEAM_BLA"`
+ TCustOrd int `json:"T_CUST_ORD"`
+ TestLen int `json:"TEST_LEN"`
+ PostFlag string `json:"POST_FLAG"`
+ ModuloX string `json:"MODULO_X"`
+ OvWTolU string `json:"OV_W_TOL_U"`
+ OvWTolL string `json:"OV_W_TOL_L"`
+ OvHTolU string `json:"OV_H_TOL_U"`
+ OvHTolL string `json:"OV_H_TOL_L"`
+ WeTTolU string `json:"WE_T_TOL_U"`
+ WeTTolL string `json:"WE_T_TOL_L"`
+ WeHTolU string `json:"WE_H_TOL_U"`
+ WeHTolL string `json:"WE_H_TOL_L"`
+ FlWDsU string `json:"FL_W_DS_U"`
+ FlWDsL string `json:"FL_W_DS_L"`
+ FlWOsU string `json:"FL_W_OS_U"`
+ FlWOsL string `json:"FL_W_OS_L"`
+ WeMetTU string `json:"WE_MET_T_U"`
+ WeMetTL string `json:"WE_MET_T_L"`
+ WeCenTol string `json:"WE_CEN_TOL"`
+ WeSquTol string `json:"WE_SQU_TOL"`
+ FlParTol string `json:"FL_PAR_TOL"`
+ BdRollID string `json:"BD_ROLL_ID"`
+ UrRollID string `json:"UR_ROLL_ID"`
+ EdRollID string `json:"ED_ROLL_ID"`
+ UfRollID string `json:"UF_ROLL_ID"`
+ SmRollID string `json:"SM_ROLL_ID"`
+ Grupo6 string `json:"GRUPO6"`
+ StName string `json:"ST_NAME"`
+ StWeighM string `json:"ST_WEIGH_M"`
+ StLen1 string `json:"ST_LEN_1"`
+ StLen2 string `json:"ST_LEN_2"`
+ StLen3 string `json:"ST_LEN_3"`
+ StLen4 string `json:"ST_LEN_4"`
+ StLen5 string `json:"ST_LEN_5"`
+ StLen6 string `json:"ST_LEN_6"`
+ StLen7 string `json:"ST_LEN_7"`
+ StLen8 string `json:"ST_LEN_8"`
+ StLen9 string `json:"ST_LEN_9"`
+ StLen10 string `json:"ST_LEN_10"`
+ StLen11 string `json:"ST_LEN_11"`
+ StLen12 string `json:"ST_LEN_12"`
+ Marfab int `json:"MARFAB"`
+ Sortb string `json:"SORTB"`
+ CreatedAt time.Time `gorm:"->;<-:create" json:"createdat,omitempty"`
+ UpdatedAt time.Time `json:"updated_at,omitempty"`
+ DeletedAt gorm.DeletedAt `gorm:"index"`
+}
+
+func (ProductionOrder) TableName() string {
+ return "sap_po"
+}