Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-03-05 10:45:12 +03:00
parent 5564dbfbd3
commit 4a6ca5a4d2
9 changed files with 334 additions and 99 deletions

View File

@@ -12,41 +12,29 @@ import (
func OrderListExcelRoute(db *sql.DB) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
// ======================
// PARAMS
// ======================
search := r.URL.Query().Get("search")
currAcc := r.URL.Query().Get("CurrAccCode")
orderDate := r.URL.Query().Get("OrderDate")
// ======================
// QUERY
// ======================
rows, err := queries.GetOrderListExcel(db, search, currAcc, orderDate)
if err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer rows.Close()
// ======================
// EXCEL INIT
// ======================
f := excelize.NewFile()
sheet := "Orders"
f.SetSheetName("Sheet1", sheet)
// ======================
// HEADERS
// ======================
headers := []string{
"Sipariş No",
"Siparis No",
"Tarih",
"Termin Tarihi",
"Cari Kod",
"Cari Adı",
"Cari Adi",
"Temsilci",
"Piyasa",
"PB",
@@ -55,8 +43,9 @@ func OrderListExcelRoute(db *sql.DB) http.Handler {
"Paketlenen Tutar",
"Paketlenen (USD)",
"Paketlenme (%)",
"Uretim",
"USD Kur",
"Açıklama",
"Aciklama",
}
for i, h := range headers {
@@ -64,58 +53,55 @@ func OrderListExcelRoute(db *sql.DB) http.Handler {
f.SetCellValue(sheet, cell, h)
}
// ======================
// ROWS
// ======================
row := 2
for rows.Next() {
// 🔴 15 KOLON = 15 DEĞİŞKEN
var (
id, no, date, code, name string
rep, piyasa, cur string
id, no, date, termin, code, name string
rep, piyasa, cur string
total float64
totalUSD float64
packedAmount float64
packedUSD float64
packedRatePct float64
hasUretim bool
desc string
usdRate float64
desc string
)
// 🔴 SELECT SIRASIYLA BİREBİR
err := rows.Scan(
&id, // 1
&no, // 2
&date, // 3
&code, // 4
&name, // 5
&rep, // 6
&piyasa, // 7
&cur, // 8
&total, // 9
&totalUSD, // 10
&packedAmount, // 11
&packedUSD, // 12
&packedRatePct, // 13
&desc, // 14
&usdRate, // 15
&termin, // 4
&code, // 5
&name, // 6
&rep, // 7
&piyasa, // 8
&cur, // 9
&total, // 10
&totalUSD, // 11
&packedAmount, // 12
&packedUSD, // 13
&packedRatePct, // 14
&hasUretim, // 15
&desc, // 16
&usdRate, // 17
)
if err != nil {
http.Error(w, "Scan error: "+err.Error(), 500)
http.Error(w, "Scan error: "+err.Error(), http.StatusInternalServerError)
return
}
// ======================
// WRITE ROW
// ======================
uretim := ""
if hasUretim {
uretim = "VAR"
}
f.SetSheetRow(sheet, fmt.Sprintf("A%d", row), &[]any{
no,
date,
termin,
code,
name,
rep,
@@ -126,6 +112,7 @@ func OrderListExcelRoute(db *sql.DB) http.Handler {
packedAmount,
packedUSD,
packedRatePct,
uretim,
usdRate,
desc,
})
@@ -133,38 +120,17 @@ func OrderListExcelRoute(db *sql.DB) http.Handler {
row++
}
// ======================
// BUFFER WRITE
// ======================
buf, err := f.WriteToBuffer()
if err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
filename := fmt.Sprintf(
"siparis_listesi_%s.xlsx",
time.Now().Format("20060102_150405"),
)
// ======================
// RESPONSE
// ======================
w.Header().Set(
"Content-Type",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
)
w.Header().Set(
"Content-Disposition",
"attachment; filename=\""+filename+"\"",
)
w.Header().Set(
"Content-Length",
fmt.Sprint(len(buf.Bytes())),
)
filename := fmt.Sprintf("siparis_listesi_%s.xlsx", time.Now().Format("20060102_150405"))
w.Header().Set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
w.Header().Set("Content-Disposition", "attachment; filename=\""+filename+"\"")
w.Header().Set("Content-Length", fmt.Sprint(len(buf.Bytes())))
w.WriteHeader(http.StatusOK)
_, _ = w.Write(buf.Bytes())
})