Merge remote-tracking branch 'origin/master'
This commit is contained in:
41
svc/routes/statement_aging.go
Normal file
41
svc/routes/statement_aging.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bssapp-backend/auth"
|
||||
"bssapp-backend/models"
|
||||
"bssapp-backend/queries"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// GET /api/finance/account-aging-statement
|
||||
func GetStatementAgingHandler(w http.ResponseWriter, r *http.Request) {
|
||||
claims, ok := auth.GetClaimsFromContext(r.Context())
|
||||
if !ok || claims == nil {
|
||||
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
params := models.StatementAgingParams{
|
||||
AccountCode: strings.TrimSpace(r.URL.Query().Get("accountcode")),
|
||||
EndDate: strings.TrimSpace(r.URL.Query().Get("enddate")),
|
||||
Parislemler: r.URL.Query()["parislemler"],
|
||||
}
|
||||
|
||||
if params.AccountCode == "" || params.EndDate == "" {
|
||||
http.Error(w, "accountcode and enddate are required", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
rows, err := queries.GetStatementAging(params)
|
||||
if err != nil {
|
||||
http.Error(w, "Error fetching aging statement: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
if err := json.NewEncoder(w).Encode(rows); err != nil {
|
||||
http.Error(w, "Error encoding response: "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user