Updated backedn
This commit is contained in:
parent
2da2fbdd6e
commit
11aaecdf0f
1 changed files with 138 additions and 24 deletions
162
backend/main.go
162
backend/main.go
|
|
@ -19,9 +19,11 @@ import (
|
||||||
|
|
||||||
// DEV
|
// DEV
|
||||||
var connection string = "root:superuser@tcp(localhost:3306)/iips"
|
var connection string = "root:superuser@tcp(localhost:3306)/iips"
|
||||||
|
var connectionPops string = "root:superuser@tcp(localhost:3306)/pops"
|
||||||
|
|
||||||
// SERVER
|
// 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"
|
||||||
|
// var connectionPops string = "pops:Pops2023!@tcp(192.168.76.10:3306)/pops"
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
connect()
|
connect()
|
||||||
|
|
@ -29,12 +31,14 @@ func main() {
|
||||||
|
|
||||||
func connect() {
|
func connect() {
|
||||||
db, err := sql.Open("mysql", connection)
|
db, err := sql.Open("mysql", connection)
|
||||||
|
dbpop, err := sql.Open("mysql", connectionPops)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
defer dbpop.Close()
|
||||||
|
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
router.Use(cors.Default())
|
router.Use(cors.Default())
|
||||||
|
|
@ -50,9 +54,8 @@ func connect() {
|
||||||
|
|
||||||
//SERVER
|
//SERVER
|
||||||
// router.Use(cors.New(cors.Config{
|
// router.Use(cors.New(cors.Config{
|
||||||
// // AllowOrigins: []string{"http://192.168.7.160:8080/esign"},
|
|
||||||
// AllowAllOrigins: true,
|
// AllowAllOrigins: true,
|
||||||
// AllowMethods: []string{"GET", "POST", "OPTIONS"},
|
// AllowMethods: []string{"GET", "POST"},
|
||||||
// AllowHeaders: []string{"Origin"},
|
// AllowHeaders: []string{"Origin"},
|
||||||
// ExposeHeaders: []string{"Content-Length"},
|
// ExposeHeaders: []string{"Content-Length"},
|
||||||
// AllowCredentials: true,
|
// AllowCredentials: true,
|
||||||
|
|
@ -525,6 +528,17 @@ func connect() {
|
||||||
"result": result,
|
"result": result,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
case "get-idbyapplication-electrical":
|
||||||
|
err := db.QueryRow(`SELECT IFNULL(electricalid, '') AS result FROM electrical WHERE electricalNo = ?`, 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,
|
||||||
|
})
|
||||||
|
|
||||||
case "get-employeeid":
|
case "get-employeeid":
|
||||||
err := db.QueryRow("SELECT IFNULL(employeeid, 0) AS result FROM employee WHERE employeename = ?", data).Scan(&result)
|
err := db.QueryRow("SELECT IFNULL(employeeid, 0) AS result FROM employee WHERE employeename = ?", data).Scan(&result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -654,14 +668,6 @@ func connect() {
|
||||||
|
|
||||||
case "get-printdetails-electrical":
|
case "get-printdetails-electrical":
|
||||||
var result2, result3, result4, result5, result6, result7, result8 string
|
var result2, result3, result4, result5, result6, result7, result8 string
|
||||||
// array := []string{}
|
|
||||||
// array2 := []string{}
|
|
||||||
// array3 := []string{}
|
|
||||||
// array4 := []string{}
|
|
||||||
// array5 := []string{}
|
|
||||||
// array6 := []string{}
|
|
||||||
// array7 := []string{}
|
|
||||||
// array8 := []string{}
|
|
||||||
|
|
||||||
err := db.QueryRow(`SELECT DISTINCT IFNULL(el.electricalNo, '') AS result, IFNULL(op.opDate, '') AS result2, IFNULL(el.locationofinstallation, '') AS result3, IFNULL(occ.occupancy, '') AS result4, IFNULL(u.occupancyoruse, '') AS result5, IFNULL(el.noofUnits, '') AS result6, IFNULL(e.employeename, '') AS result7, IF(cu.firstName IS NULL OR cu.firstName = '', cu.lastName, CONCAT(cu.firstName, ' ', IF(cu.middleInitial IS NULL OR cu.middleInitial = '', '', CONCAT(cu.middleInitial, '. ')), cu.lastName) ) AS result8
|
err := db.QueryRow(`SELECT DISTINCT IFNULL(el.electricalNo, '') AS result, IFNULL(op.opDate, '') AS result2, IFNULL(el.locationofinstallation, '') AS result3, IFNULL(occ.occupancy, '') AS result4, IFNULL(u.occupancyoruse, '') AS result5, IFNULL(el.noofUnits, '') AS result6, IFNULL(e.employeename, '') AS result7, IF(cu.firstName IS NULL OR cu.firstName = '', cu.lastName, CONCAT(cu.firstName, ' ', IF(cu.middleInitial IS NULL OR cu.middleInitial = '', '', CONCAT(cu.middleInitial, '. ')), cu.lastName) ) AS result8
|
||||||
FROM electrical el, electrical_orderofpayment_new op, ref_occupancy occ, ref_elec_occupancy u, customer cu, employee e
|
FROM electrical el, electrical_orderofpayment_new op, ref_occupancy occ, ref_elec_occupancy u, customer cu, employee e
|
||||||
|
|
@ -746,6 +752,59 @@ func connect() {
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"result": result,
|
"result": result,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
case "get-popsdetails-electrical":
|
||||||
|
var result2, result3, result4, result5, result6, result7, result8, result9, result10 string
|
||||||
|
array := []string{}
|
||||||
|
array2 := []string{}
|
||||||
|
array3 := []string{}
|
||||||
|
array4 := []string{}
|
||||||
|
array5 := []string{}
|
||||||
|
array6 := []string{}
|
||||||
|
array7 := []string{}
|
||||||
|
array8 := []string{}
|
||||||
|
array9 := []string{}
|
||||||
|
array10 := []string{}
|
||||||
|
|
||||||
|
results, err := db.Query(`SELECT IFNULL(e.electricalNo, '') AS result, IFNULL(c.customerid, 0) AS result2, IFNULL(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 result3,
|
||||||
|
IFNULL(e.locationofinstallation, '') AS result4, IFNULL(op.amount, '') AS result5, IFNULL(op.amt_Gflgu, '') AS result6, IFNULL(op.amt_Gfdpwh, '') AS result7, IFNULL(op.amt_Tfbo, '') AS result8, IFNULL(ref.accountdescription, '') AS result9, IFNULL(ref.accountcode, '') AS result10
|
||||||
|
FROM electrical e JOIN customer c ON e.customerid = c.customerid JOIN electrical_orderofpayment_new op ON e.electricalid = op.electricalid JOIN ref_bldgcomputationsheet ref ON op.ref_bldgcomputationsheetid = ref.ref_bldgcomputationsheetid
|
||||||
|
WHERE e.electricalid = ?`, data)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
c.String(http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for results.Next() {
|
||||||
|
err = results.Scan(&result, &result2, &result3, &result4, &result5, &result6, &result7, &result8, &result9, &result10)
|
||||||
|
if err != nil {
|
||||||
|
c.AbortWithError(http.StatusBadRequest, err)
|
||||||
|
c.String(http.StatusBadRequest, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
array = append(array, result)
|
||||||
|
array2 = append(array2, result2)
|
||||||
|
array3 = append(array3, result3)
|
||||||
|
array4 = append(array4, result4)
|
||||||
|
array5 = append(array5, result5)
|
||||||
|
array6 = append(array6, result6)
|
||||||
|
array7 = append(array7, result7)
|
||||||
|
array8 = append(array8, result8)
|
||||||
|
array9 = append(array9, result9)
|
||||||
|
array10 = append(array10, result10)
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, gin.H{
|
||||||
|
"result": array,
|
||||||
|
"result2": array2,
|
||||||
|
"result3": array3,
|
||||||
|
"result4": array4,
|
||||||
|
"result5": array5,
|
||||||
|
"result6": array6,
|
||||||
|
"result7": array7,
|
||||||
|
"result8": array8,
|
||||||
|
"result9": array9,
|
||||||
|
"result10": array10,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -833,16 +892,17 @@ func connect() {
|
||||||
})
|
})
|
||||||
|
|
||||||
router.POST("/api/post-newstatus-electrical", func(c *gin.Context) {
|
router.POST("/api/post-newstatus-electrical", func(c *gin.Context) {
|
||||||
type RegistrationData struct {
|
type NewstatusData struct {
|
||||||
Data int `json:"data"`
|
Data int `json:"data"`
|
||||||
Data2 string `json:"data2"`
|
Data2 string `json:"data2"`
|
||||||
Data3 string `json:"data3"`
|
Data3 string `json:"data3"`
|
||||||
Data4 string `json:"data4"`
|
Data4 string `json:"data4"`
|
||||||
Data5 string `json:"data5"`
|
Data5 string `json:"data5"`
|
||||||
Data6 int `json:"data6"`
|
Data6 int `json:"data6"`
|
||||||
|
Data7 int `json:"data7"`
|
||||||
}
|
}
|
||||||
var registrationData RegistrationData
|
var newstatusData NewstatusData
|
||||||
if err := c.ShouldBindJSON(®istrationData); err != nil {
|
if err := c.ShouldBindJSON(&newstatusData); err != nil {
|
||||||
c.String(http.StatusBadRequest, "Invalid request body")
|
c.String(http.StatusBadRequest, "Invalid request body")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -855,13 +915,13 @@ func connect() {
|
||||||
c.Writer.Header().Set("Referrer-Policy", "no-referrer")
|
c.Writer.Header().Set("Referrer-Policy", "no-referrer")
|
||||||
|
|
||||||
dbpost, err := db.Prepare(`INSERT INTO electricaldocflowtxn (electricaldocflowtxnid, electricalid, txndate, remarks, comments, is_tag, tagword, is_approve, employeeid, is_delete)
|
dbpost, err := db.Prepare(`INSERT INTO electricaldocflowtxn (electricaldocflowtxnid, electricalid, txndate, remarks, comments, is_tag, tagword, is_approve, employeeid, is_delete)
|
||||||
VALUES (NULL, ?, ?, ?, NULL, ?, ?, 0, ?, 0)`)
|
VALUES (NULL, ?, ?, ?, NULL, ?, ?, ?, ?, 0)`)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
defer dbpost.Close()
|
defer dbpost.Close()
|
||||||
|
|
||||||
exec, err := dbpost.Exec(registrationData.Data, registrationData.Data2, registrationData.Data3, registrationData.Data4, registrationData.Data5, registrationData.Data6)
|
exec, err := dbpost.Exec(newstatusData.Data, newstatusData.Data2, newstatusData.Data3, newstatusData.Data4, newstatusData.Data5, newstatusData.Data6, newstatusData.Data7)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -879,12 +939,13 @@ func connect() {
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
router.POST("/api/update-opapproved-electrical", func(c *gin.Context) {
|
router.POST("/api/update-docflow-electrical", func(c *gin.Context) {
|
||||||
type UpdateOpData struct {
|
type UpdateDocflowData struct {
|
||||||
Data int `json:"data"`
|
Data int `json:"data"`
|
||||||
|
Data2 string `json:"data2"`
|
||||||
}
|
}
|
||||||
var updateOpData UpdateOpData
|
var updateDocflowData UpdateDocflowData
|
||||||
if err := c.ShouldBindJSON(&updateOpData); err != nil {
|
if err := c.ShouldBindJSON(&updateDocflowData); err != nil {
|
||||||
c.String(http.StatusBadRequest, "Invalid request body")
|
c.String(http.StatusBadRequest, "Invalid request body")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -896,13 +957,13 @@ func connect() {
|
||||||
c.Writer.Header().Set("X-Download-Options", "noopen")
|
c.Writer.Header().Set("X-Download-Options", "noopen")
|
||||||
c.Writer.Header().Set("Referrer-Policy", "no-referrer")
|
c.Writer.Header().Set("Referrer-Policy", "no-referrer")
|
||||||
|
|
||||||
dbpost, err := db.Prepare("UPDATE electrical_orderofpayment_new SET is_approve = 1 WHERE electricalid = ? AND for_approval = 1 AND is_release = 0 AND is_paid = 0 AND popstransmitted = 0")
|
dbpost, err := db.Prepare("UPDATE electricaldocflowtxn SET is_approve = 1 WHERE electricalid = ? AND remarks = ?")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
defer dbpost.Close()
|
defer dbpost.Close()
|
||||||
|
|
||||||
exec, err := dbpost.Exec(updateOpData.Data)
|
exec, err := dbpost.Exec(updateDocflowData.Data, updateDocflowData.Data2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
panic(err.Error())
|
||||||
}
|
}
|
||||||
|
|
@ -913,9 +974,9 @@ func connect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if affect > 0 {
|
if affect > 0 {
|
||||||
c.String(http.StatusOK, "Success on Updating Order of Payment for Approval")
|
c.String(http.StatusOK, "Success on Updating Docflow on Electrical")
|
||||||
} else {
|
} else {
|
||||||
c.String(http.StatusInternalServerError, "Failed on Updating Order of Payment for Approval")
|
c.String(http.StatusInternalServerError, "Failed on Updating Docflow on Electrical")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -1001,5 +1062,58 @@ func connect() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.POST("/api/post-pops", func(c *gin.Context) {
|
||||||
|
type PostPopData struct {
|
||||||
|
Data string `json:"data"` //applicationNo
|
||||||
|
Data2 string `json:"data2"` //date
|
||||||
|
Data3 string `json:"data3"` //customerId
|
||||||
|
Data4 string `json:"data4"` //customerName
|
||||||
|
Data5 string `json:"data5"` //customerAddress
|
||||||
|
Data6 string `json:"data6"` //accountCode
|
||||||
|
Data7 string `json:"data7"` //amount
|
||||||
|
Data8 string `json:"data8"` //approverName
|
||||||
|
Data9 string `json:"data9"` //dateAndTime
|
||||||
|
Data10 string `json:"data10"` //gflgu
|
||||||
|
Data11 string `json:"data11"` //gfdpwh
|
||||||
|
Data12 string `json:"data12"` //tfobo
|
||||||
|
Data13 string `json:"data13"` //publicIp
|
||||||
|
}
|
||||||
|
var postPopDate PostPopData
|
||||||
|
if err := c.ShouldBindJSON(&postPopDate); 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 := dbpop.Prepare(`INSERT INTO orderpaydetail (OrderPayId, OPRefId, OPSysId, OPDate, AcctRefId, AcctFullName, AcctAddress, AccountCode, AmountBasic, OPPostedBy, OPPostDate, OfficeCode, Amt_GFLGU, Amt_GFDPWH, Amt_TFBO, TranRefId)
|
||||||
|
VALUES (NULL, ?, 'IIPS', ?, ?, ?, ?, ?, ?, ?, ?, 8751, ?, ?, ?, ?)`)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
defer dbpost.Close()
|
||||||
|
|
||||||
|
exec, err := dbpost.Exec(postPopDate.Data, postPopDate.Data2, postPopDate.Data3, postPopDate.Data4, postPopDate.Data5, postPopDate.Data6, postPopDate.Data7, postPopDate.Data8, postPopDate.Data9, postPopDate.Data10, postPopDate.Data11, postPopDate.Data12, postPopDate.Data13)
|
||||||
|
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 Posting on POPS eSign transaction")
|
||||||
|
} else {
|
||||||
|
c.String(http.StatusInternalServerError, "Failed on Posting on POPS")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
router.Run(":4320")
|
router.Run(":4320")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue