Added esign record fetching
This commit is contained in:
parent
38acaf262a
commit
0b1d6baf7f
1 changed files with 79 additions and 16 deletions
|
|
@ -12,16 +12,16 @@ import (
|
|||
// "errors"
|
||||
// "os"
|
||||
|
||||
// "github.com/gin-contrib/cors"
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
// DEV
|
||||
// var connection string = "root:superuser@tcp(localhost:3306)/iips"
|
||||
var connection string = "root:superuser@tcp(localhost:3306)/iips"
|
||||
|
||||
// SERVER
|
||||
var connection string = "iips:iipsuser@tcp(192.168.7.100:3306)/iips"
|
||||
// var connection string = "iips:iipsuser@tcp(192.168.7.100:3306)/iips"
|
||||
|
||||
func main() {
|
||||
connect()
|
||||
|
|
@ -37,24 +37,23 @@ func connect() {
|
|||
defer db.Close()
|
||||
|
||||
router := gin.Default()
|
||||
// router.Use(cors.Default())
|
||||
router.Use(cors.Default())
|
||||
|
||||
//DEV
|
||||
// router.Use(cors.New(cors.Config{
|
||||
// AllowOrigins: []string{"http://localhost:5173"},
|
||||
// // AllowAllOrigins: true,
|
||||
// AllowMethods: []string{"GET", "POST"},
|
||||
// AllowHeaders: []string{"Origin", "OCBO-ShieldConnection"},
|
||||
// ExposeHeaders: []string{"Content-Length"},
|
||||
// AllowCredentials: true,
|
||||
// }))
|
||||
router.Use(cors.New(cors.Config{
|
||||
AllowOrigins: []string{"http://localhost:5173"},
|
||||
AllowMethods: []string{"GET", "POST"},
|
||||
AllowHeaders: []string{"Origin", "OCBO-ShieldConnection"},
|
||||
ExposeHeaders: []string{"Content-Length"},
|
||||
AllowCredentials: true,
|
||||
}))
|
||||
|
||||
//SERVER
|
||||
// router.Use(cors.New(cors.Config{
|
||||
// // AllowOrigins: []string{"http://192.168.7.160:8080/esign"},
|
||||
// AllowAllOrigins: true,
|
||||
// AllowMethods: []string{"GET", "POST"},
|
||||
// AllowHeaders: []string{"Origin", "OCBO-ShieldConnection"},
|
||||
// AllowAllOrigins: true,
|
||||
// AllowMethods: []string{"GET", "POST", "OPTIONS"},
|
||||
// AllowHeaders: []string{"Origin"},
|
||||
// ExposeHeaders: []string{"Content-Length"},
|
||||
// AllowCredentials: true,
|
||||
// }))
|
||||
|
|
@ -101,7 +100,7 @@ func connect() {
|
|||
array2 := []string{}
|
||||
|
||||
results, err := db.Query(`SELECT IFNULL(e.electricalno, '') AS result, IF(c.firstName IS NULL OR c.firstName = '', c.lastName, CONCAT(c.firstName, ' ', IF(c.middleInitial IS NULL OR c.middleInitial = '', '', CONCAT(c.middleInitial, '. ')), c.lastName) ) AS result2
|
||||
FROM iips.electrical e JOIN iips.customer c ON e.customerid = c.customerid JOIN iips.ref_elec_occupancy ec ON e.ref_elec_occupancyid = ec.ref_elec_occupancyid JOIN iips.electricaldocflowtxn ed ON e.electricalid = ed.electricalid JOIN (SELECT electricalid, MAX(electricaldocflowtxnid) AS latest_electricaldocflowtxnid FROM electricaldocflowtxn GROUP BY electricalid) latest_doc ON ed.electricalid = latest_doc.electricalid AND ed.electricaldocflowtxnid = latest_doc.latest_electricaldocflowtxnid WHERE remarks = ? AND is_approve = 0 ORDER BY e.electricalno ASC`, "FOR ELECTRICAL ORDER OF PAYMENT APPROVAL")
|
||||
FROM iips.electrical e JOIN iips.customer c ON e.customerid = c.customerid JOIN iips.ref_elec_occupancy ec ON e.ref_elec_occupancyid = ec.ref_elec_occupancyid JOIN iips.electricaldocflowtxn ed ON e.electricalid = ed.electricalid JOIN (SELECT electricalid, MAX(electricaldocflowtxnid) AS latest_electricaldocflowtxnid FROM electricaldocflowtxn GROUP BY electricalid) latest_doc ON ed.electricalid = latest_doc.electricalid AND ed.electricaldocflowtxnid = latest_doc.latest_electricaldocflowtxnid WHERE remarks = ? AND is_approve = 0 ORDER BY ed.txndate DESC`, "FOR ELECTRICAL ORDER OF PAYMENT APPROVAL")
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
|
|
@ -726,6 +725,17 @@ func connect() {
|
|||
"result": result,
|
||||
})
|
||||
|
||||
case "get-esignid":
|
||||
err := db.QueryRow("SELECT IFNULL(esignid, 0) AS result FROM esign WHERE employeeid = ?", data).Scan(&result)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"result": result,
|
||||
})
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -753,6 +763,17 @@ func connect() {
|
|||
c.JSON(http.StatusOK, gin.H{
|
||||
"result": result,
|
||||
})
|
||||
|
||||
case "get-signeddate":
|
||||
err := db.QueryRow("SELECT IFNULL(date_signed, '') AS result FROM esign_transactions WHERE esignid = ? AND referenceNo = ?", data, data2).Scan(&result)
|
||||
if err != nil {
|
||||
c.AbortWithError(http.StatusBadRequest, err)
|
||||
c.String(http.StatusBadRequest, err.Error())
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"result": result,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
|
@ -927,5 +948,47 @@ func connect() {
|
|||
}
|
||||
})
|
||||
|
||||
router.POST("/api/post-esigntransaction", func(c *gin.Context) {
|
||||
type UpdateOpData struct {
|
||||
Data int `json:"data"`
|
||||
Data2 string `json:"data2"`
|
||||
Data3 string `json:"data3"`
|
||||
}
|
||||
var updateOpData UpdateOpData
|
||||
if err := c.ShouldBindJSON(&updateOpData); err != nil {
|
||||
c.String(http.StatusBadRequest, "Invalid request body")
|
||||
return
|
||||
}
|
||||
|
||||
c.Writer.Header().Set("X-XSS-Protection", "1; mode=block")
|
||||
c.Writer.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
c.Writer.Header().Set("X-DNS-Prefetch-Control", "off")
|
||||
c.Writer.Header().Set("X-Frame-Options", "DENY")
|
||||
c.Writer.Header().Set("X-Download-Options", "noopen")
|
||||
c.Writer.Header().Set("Referrer-Policy", "no-referrer")
|
||||
|
||||
dbpost, err := db.Prepare("INSERT INTO esign_transactions (esign_transactionsid, esignid, referenceNo, date_signed) VALUES (NULL, ?, ?, ?)")
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
defer dbpost.Close()
|
||||
|
||||
exec, err := dbpost.Exec(updateOpData.Data, updateOpData.Data2, updateOpData.Data3)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
affect, err := exec.RowsAffected()
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
|
||||
if affect > 0 {
|
||||
c.String(http.StatusOK, "Success on Saving eSign transaction")
|
||||
} else {
|
||||
c.String(http.StatusInternalServerError, "Failed on Saving eSign transaction")
|
||||
}
|
||||
})
|
||||
|
||||
router.Run(":4320")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue