ui: add B2B olmayan stok (orphans) page
This commit is contained in:
@@ -26,6 +26,8 @@ func GetProductPerformanceHandler(pg *sql.DB) http.HandlerFunc {
|
||||
Kategori: strings.TrimSpace(r.URL.Query().Get("kategori")),
|
||||
Seri: strings.TrimSpace(r.URL.Query().Get("seri")),
|
||||
Bucket: strings.TrimSpace(r.URL.Query().Get("bucket")),
|
||||
SortBy: strings.TrimSpace(r.URL.Query().Get("sort_by")),
|
||||
Descending: boolQuery(r, "descending", true),
|
||||
Limit: intQuery(r, "limit", 100),
|
||||
Page: intQuery(r, "page", 1),
|
||||
}
|
||||
@@ -44,6 +46,46 @@ func GetProductPerformanceHandler(pg *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
func GetProductPerformanceSalesDetailsHandler(pg *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 30*time.Second)
|
||||
defer cancel()
|
||||
rows, err := queries.ListProductPerformanceSalesDetails(
|
||||
ctx,
|
||||
pg,
|
||||
strings.TrimSpace(r.URL.Query().Get("product_code")),
|
||||
strings.TrimSpace(r.URL.Query().Get("color_code")),
|
||||
strings.TrimSpace(r.URL.Query().Get("yaka_kodu")),
|
||||
intQuery(r, "limit", 100),
|
||||
)
|
||||
if err != nil {
|
||||
http.Error(w, "urun satis detayi alinamadi: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(rows)
|
||||
}
|
||||
}
|
||||
|
||||
func GetProductPerformanceStockSizesHandler() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 60*time.Second)
|
||||
defer cancel()
|
||||
rows, err := queries.ListProductPerformanceStockSizes(
|
||||
ctx,
|
||||
strings.TrimSpace(r.URL.Query().Get("product_code")),
|
||||
strings.TrimSpace(r.URL.Query().Get("color_code")),
|
||||
strings.TrimSpace(r.URL.Query().Get("yaka_kodu")),
|
||||
)
|
||||
if err != nil {
|
||||
http.Error(w, "urun beden stok detayi alinamadi: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(rows)
|
||||
}
|
||||
}
|
||||
|
||||
func GetProductPerformanceSummaryHandler(pg *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
@@ -166,6 +208,14 @@ func intQuery(r *http.Request, key string, fallback int) int {
|
||||
return n
|
||||
}
|
||||
|
||||
func boolQuery(r *http.Request, key string, fallback bool) bool {
|
||||
raw := strings.TrimSpace(strings.ToLower(r.URL.Query().Get(key)))
|
||||
if raw == "" {
|
||||
return fallback
|
||||
}
|
||||
return raw == "1" || raw == "true" || raw == "yes" || raw == "on"
|
||||
}
|
||||
|
||||
func parseDateOrZero(raw string) time.Time {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
|
||||
Reference in New Issue
Block a user