Updated backend

This commit is contained in:
Patrick Alvin Alcala 2025-10-24 18:10:58 +08:00
parent dc912bdef2
commit 050f98f296

View file

@ -754,7 +754,7 @@ func connect() {
})
case "get-popsdetails-electrical":
var result2, result3, result4, result5, result6, result7, result8, result9, result10 string
var result2, result3, result4, result5, result6, result7, result8, result9 string
array := []string{}
array2 := []string{}
array3 := []string{}
@ -764,10 +764,9 @@ func connect() {
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
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.accountcode, '') AS result9
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 {
@ -776,7 +775,7 @@ func connect() {
return
}
for results.Next() {
err = results.Scan(&result, &result2, &result3, &result4, &result5, &result6, &result7, &result8, &result9, &result10)
err = results.Scan(&result, &result2, &result3, &result4, &result5, &result6, &result7, &result8, &result9)
if err != nil {
c.AbortWithError(http.StatusBadRequest, err)
c.String(http.StatusBadRequest, err.Error())
@ -791,7 +790,6 @@ func connect() {
array7 = append(array7, result7)
array8 = append(array8, result8)
array9 = append(array9, result9)
array10 = append(array10, result10)
}
c.JSON(http.StatusOK, gin.H{
"result": array,
@ -803,7 +801,6 @@ func connect() {
"result7": array7,
"result8": array8,
"result9": array9,
"result10": array10,
})
}
})
@ -959,18 +956,24 @@ func connect() {
dbpost, err := db.Prepare("UPDATE electricaldocflowtxn SET is_approve = 1 WHERE electricalid = ? AND remarks = ?")
if err != nil {
panic(err.Error())
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, "Internal Server Error")
return
}
defer dbpost.Close()
exec, err := dbpost.Exec(updateDocflowData.Data, updateDocflowData.Data2)
if err != nil {
panic(err.Error())
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, "Internal Server Error")
return
}
affect, err := exec.RowsAffected()
if err != nil {
panic(err.Error())
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, "Internal Server Error")
return
}
if affect > 0 {
@ -1115,5 +1118,52 @@ func connect() {
}
})
router.POST("/api/update-opapproved-electrical", func(c *gin.Context) {
type UpdateOpData struct {
Data int `json:"data"`
}
var updateOpData UpdateOpData
if err := c.ShouldBindJSON(&updateOpData); err != nil {
c.AbortWithError(http.StatusBadRequest, err)
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("UPDATE electrical_orderofpayment_new SET is_approve = 1 WHERE electricalid = ? AND for_approval = 1 AND is_paid = 0")
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, "Internal Server Error")
return
}
defer dbpost.Close()
exec, err := dbpost.Exec(updateOpData.Data)
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, "Internal Server Error")
return
}
affect, err := exec.RowsAffected()
if err != nil {
c.AbortWithError(http.StatusInternalServerError, err)
c.String(http.StatusInternalServerError, "Internal Server Error")
return
}
if affect > 0 {
c.String(http.StatusOK, "Success on Updating Order of Payment on Approval")
} else {
c.String(http.StatusInternalServerError, "Failed on Updating Order of Payment on Approval")
}
})
router.Run(":4320")
}