From 0b90b911b6a81ef20c77f3e6f79d83f405a24fb5 Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Fri, 6 Feb 2026 18:46:29 +0800 Subject: [PATCH] Added new api for mobile --- backend/main.go | 83 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 4 deletions(-) diff --git a/backend/main.go b/backend/main.go index cb26b7e..832919d 100644 --- a/backend/main.go +++ b/backend/main.go @@ -1361,18 +1361,19 @@ func connect() { } case "get-transactions": - var result2 string + var result2, result3 string array := []string{} array2 := []string{} + array3 := []string{} - results, err := db.Query(`SELECT IFNULL(referenceNo, '') AS result, IFNULL(DATE_FORMAT(date_signed, '%M %e, %Y'), '') AS result2 FROM esign_transactions WHERE esignid = (SELECT esignid FROM esign WHERE employeeid = (SELECT employeeid FROM employee WHERE employeename = ?))`, data) + results, err := db.Query(`SELECT IFNULL(referenceNo, '') AS result, IFNULL(DATE_FORMAT(date_signed, '%M %e, %Y'), '') AS result2, IFNULL(DATE_FORMAT(date_signed, '%h:%i %p'), '') AS result3 FROM esign_transactions WHERE esignid = (SELECT esignid FROM esign WHERE employeeid = (SELECT employeeid FROM employee WHERE employeename = ?)) ORDER BY date_signed DESC LIMIT 300`, data) if err != nil { c.AbortWithError(http.StatusBadRequest, err) c.String(http.StatusBadRequest, err.Error()) return } for results.Next() { - err = results.Scan(&result, &result2) + err = results.Scan(&result, &result2, &result3) if err != nil { c.AbortWithError(http.StatusBadRequest, err) c.String(http.StatusBadRequest, err.Error()) @@ -1380,10 +1381,12 @@ func connect() { } array = append(array, result) array2 = append(array2, result2) + array3 = append(array3, result3) } c.JSON(http.StatusOK, gin.H{ "result": array, "result2": array2, + "result3": array3, }) case "get-transactions-count": @@ -1396,8 +1399,18 @@ func connect() { c.JSON(http.StatusOK, gin.H{ "result": result, }) - } + case "get-esignid-byname": + err := db.QueryRow(`SELECT IFNULL(esignid, 0) AS result FROM esign WHERE employeeid = (SELECT employeeid FROM employee WHERE employeename = ?)`, 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, + }) + } }) router.GET("/api/:method/:data/:data2/fetch-data", func(c *gin.Context) { @@ -1448,6 +1461,68 @@ func connect() { c.JSON(http.StatusOK, gin.H{ "result": result, }) + + case "get-transactions-filter": + var result2, result3 string + array := []string{} + array2 := []string{} + array3 := []string{} + + results, err := db.Query("SELECT IFNULL(referenceNo, '') AS result, IFNULL(DATE_FORMAT(date_signed, '%M %e, %Y'), '') AS result2, IFNULL(DATE_FORMAT(date_signed, '%h:%i %p'), '') AS result3 FROM esign_transactions WHERE esignid = (SELECT esignid FROM esign WHERE employeeid = (SELECT employeeid FROM employee WHERE employeename = ?)) AND referenceNo LIKE ? ORDER BY date_signed DESC", data, "%"+data2+"%") + if err != nil { + c.AbortWithError(http.StatusBadRequest, err) + c.String(http.StatusBadRequest, err.Error()) + return + } + for results.Next() { + err = results.Scan(&result, &result2, &result3) + 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) + } + c.JSON(http.StatusOK, gin.H{ + "result": array, + "result2": array2, + "result3": array3, + }) + + case "get-infoapproval-electrical": + var result2, result3, result4 string + array := []string{} + array2 := []string{} + array3 := []string{} + array4 := []string{} + + results, err := db.Query(`SELECT 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 result, DATE_FORMAT(et.date_signed, '%M') AS result2, DATE_FORMAT(et.date_signed, '%e') AS result3, DATE_FORMAT(et.date_signed, '%Y') AS result4 + FROM electrical e JOIN customer c ON e.customerid = c.customerid JOIN esign_transactions et ON e.electricalNo = et.referenceNo WHERE e.electricalNo = ? AND et.esignid = ?`, data, data2) + 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) + 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) + } + c.JSON(http.StatusOK, gin.H{ + "result": array, + "result2": array2, + "result3": array3, + "result4": array4, + }) } })