Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -67,6 +67,8 @@ func ExportCustomerBalanceExcelHandler(_ *sql.DB) http.HandlerFunc {
|
||||
"1_2 TRY Bakiye",
|
||||
"1_3 USD Bakiye",
|
||||
"1_3 TRY Bakiye",
|
||||
"Vade Gun",
|
||||
"Belge Tarihi Gun",
|
||||
}
|
||||
|
||||
for i, h := range headers {
|
||||
@@ -75,6 +77,7 @@ func ExportCustomerBalanceExcelHandler(_ *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
|
||||
var totalUSD12, totalTRY12, totalUSD13, totalTRY13 float64
|
||||
var totalVadeBase, totalVadeSum, totalVadeBelgeSum float64
|
||||
totalPrBr12 := map[string]float64{}
|
||||
totalPrBr13 := map[string]float64{}
|
||||
|
||||
@@ -83,6 +86,12 @@ func ExportCustomerBalanceExcelHandler(_ *sql.DB) http.HandlerFunc {
|
||||
totalTRY12 += s.TLBakiye12
|
||||
totalUSD13 += s.USDBakiye13
|
||||
totalTRY13 += s.TLBakiye13
|
||||
w := absFloatExcel(s.USDBakiye12) + absFloatExcel(s.TLBakiye12) + absFloatExcel(s.USDBakiye13) + absFloatExcel(s.TLBakiye13)
|
||||
if w > 0 {
|
||||
totalVadeBase += w
|
||||
totalVadeSum += s.VadeGun * w
|
||||
totalVadeBelgeSum += s.VadeBelge * w
|
||||
}
|
||||
for k, v := range s.Bakiye12Map {
|
||||
totalPrBr12[k] += v
|
||||
}
|
||||
@@ -91,6 +100,13 @@ func ExportCustomerBalanceExcelHandler(_ *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
totalVade := 0.0
|
||||
totalVadeBelge := 0.0
|
||||
if totalVadeBase > 0 {
|
||||
totalVade = totalVadeSum / totalVadeBase
|
||||
totalVadeBelge = totalVadeBelgeSum / totalVadeBase
|
||||
}
|
||||
|
||||
f.SetSheetRow(sheet, "A2", &[]any{
|
||||
"TOPLAM",
|
||||
"",
|
||||
@@ -103,6 +119,8 @@ func ExportCustomerBalanceExcelHandler(_ *sql.DB) http.HandlerFunc {
|
||||
totalTRY12,
|
||||
totalUSD13,
|
||||
totalTRY13,
|
||||
totalVade,
|
||||
totalVadeBelge,
|
||||
})
|
||||
|
||||
rowNo := 3
|
||||
@@ -119,6 +137,8 @@ func ExportCustomerBalanceExcelHandler(_ *sql.DB) http.HandlerFunc {
|
||||
s.TLBakiye12,
|
||||
s.USDBakiye13,
|
||||
s.TLBakiye13,
|
||||
s.VadeGun,
|
||||
s.VadeBelge,
|
||||
})
|
||||
rowNo++
|
||||
}
|
||||
@@ -127,7 +147,7 @@ func ExportCustomerBalanceExcelHandler(_ *sql.DB) http.HandlerFunc {
|
||||
_ = f.SetColWidth(sheet, "B", "B", 34)
|
||||
_ = f.SetColWidth(sheet, "C", "E", 18)
|
||||
_ = f.SetColWidth(sheet, "F", "G", 34)
|
||||
_ = f.SetColWidth(sheet, "H", "K", 18)
|
||||
_ = f.SetColWidth(sheet, "H", "M", 18)
|
||||
|
||||
buf, err := f.WriteToBuffer()
|
||||
if err != nil {
|
||||
@@ -143,3 +163,10 @@ func ExportCustomerBalanceExcelHandler(_ *sql.DB) http.HandlerFunc {
|
||||
_, _ = w.Write(buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func absFloatExcel(v float64) float64 {
|
||||
if v < 0 {
|
||||
return -v
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -29,6 +29,9 @@ type balanceSummaryPDF struct {
|
||||
TLBakiye12 float64
|
||||
USDBakiye13 float64
|
||||
TLBakiye13 float64
|
||||
VadeGun float64
|
||||
VadeBelge float64
|
||||
VadeBase float64
|
||||
}
|
||||
|
||||
func ExportCustomerBalancePDFHandler(_ *sql.DB) http.HandlerFunc {
|
||||
@@ -182,6 +185,12 @@ func buildCustomerBalancePDFData(rows []models.CustomerBalanceListRow) ([]balanc
|
||||
s.TLBakiye12 += row.TLBakiye12
|
||||
s.USDBakiye13 += row.USDBakiye13
|
||||
s.TLBakiye13 += row.TLBakiye13
|
||||
w := absFloat(row.Bakiye12) + absFloat(row.Bakiye13)
|
||||
if w > 0 {
|
||||
s.VadeBase += w
|
||||
s.VadeGun += row.VadeGun * w
|
||||
s.VadeBelge += row.VadeBelgeGun * w
|
||||
}
|
||||
|
||||
detailsByMaster[master] = append(detailsByMaster[master], row)
|
||||
}
|
||||
@@ -194,6 +203,11 @@ func buildCustomerBalancePDFData(rows []models.CustomerBalanceListRow) ([]balanc
|
||||
|
||||
summaries := make([]balanceSummaryPDF, 0, len(masters))
|
||||
for _, m := range masters {
|
||||
s := summaryMap[m]
|
||||
if s != nil && s.VadeBase > 0 {
|
||||
s.VadeGun = s.VadeGun / s.VadeBase
|
||||
s.VadeBelge = s.VadeBelge / s.VadeBase
|
||||
}
|
||||
summaries = append(summaries, *summaryMap[m])
|
||||
d := detailsByMaster[m]
|
||||
sort.SliceStable(d, func(i, j int) bool {
|
||||
@@ -225,11 +239,11 @@ func drawCustomerBalancePDF(
|
||||
marginL, marginT, marginR, marginB := 8.0, 8.0, 8.0, 12.0
|
||||
tableW := pageW - marginL - marginR
|
||||
|
||||
summaryCols := []string{"Ana Cari Kod", "Ana Cari Detay", "Piyasa", "Temsilci", "Risk", "1_2 Pr.Br", "1_3 Pr.Br", "1_2 USD", "1_2 TRY", "1_3 USD", "1_3 TRY"}
|
||||
summaryW := normalizeWidths([]float64{20, 52, 16, 20, 14, 24, 24, 14, 14, 14, 14}, tableW)
|
||||
summaryCols := []string{"Ana Cari Kod", "Ana Cari Detay", "Piyasa", "Temsilci", "Risk", "1_2 Pr.Br", "1_3 Pr.Br", "1_2 USD", "1_2 TRY", "1_3 USD", "1_3 TRY", "Vade Gun", "Belge Gun"}
|
||||
summaryW := normalizeWidths([]float64{18, 46, 14, 18, 12, 20, 20, 12, 12, 12, 12, 10, 10}, tableW)
|
||||
|
||||
detailCols := []string{"Cari Kod", "Cari Detay", "Sirket", "Muhasebe", "Doviz", "1_2 Pr.Br", "1_3 Pr.Br", "1_2 USD", "1_2 TRY", "1_3 USD", "1_3 TRY"}
|
||||
detailW := normalizeWidths([]float64{26, 46, 10, 20, 10, 24, 24, 15, 15, 15, 15}, tableW)
|
||||
detailCols := []string{"Cari Kod", "Cari Detay", "Sirket", "Muhasebe", "Doviz", "1_2 Pr.Br", "1_3 Pr.Br", "1_2 USD", "1_2 TRY", "1_3 USD", "1_3 TRY", "Vade Gun", "Belge Gun"}
|
||||
detailW := normalizeWidths([]float64{22, 40, 9, 16, 8, 20, 20, 12, 12, 12, 12, 9, 9}, tableW)
|
||||
|
||||
header := func() {
|
||||
pdf.AddPage()
|
||||
@@ -352,18 +366,27 @@ func drawCustomerBalancePDF(
|
||||
formatMoneyPDF(s.TLBakiye12),
|
||||
formatMoneyPDF(s.USDBakiye13),
|
||||
formatMoneyPDF(s.TLBakiye13),
|
||||
formatMoneyPDF(s.VadeGun),
|
||||
formatMoneyPDF(s.VadeBelge),
|
||||
}
|
||||
wrapCols := map[int]bool{1: true, 3: true}
|
||||
rowH := calcWrappedRowHeight(row, summaryW, wrapCols, 3.2, 6.2)
|
||||
if needPage(rowH) {
|
||||
header()
|
||||
drawSummaryHeader()
|
||||
pdf.SetFont("dejavu", "", 7.2)
|
||||
pdf.SetTextColor(20, 20, 20)
|
||||
}
|
||||
|
||||
y := pdf.GetY()
|
||||
x := marginL
|
||||
for i, v := range row {
|
||||
pdf.Rect(x, y, summaryW[i], rowH, "")
|
||||
if detailed {
|
||||
pdf.SetFillColor(246, 241, 231)
|
||||
pdf.Rect(x, y, summaryW[i], rowH, "FD")
|
||||
} else {
|
||||
pdf.Rect(x, y, summaryW[i], rowH, "")
|
||||
}
|
||||
align := "L"
|
||||
if i >= 7 {
|
||||
align = "R"
|
||||
@@ -414,7 +437,25 @@ func drawCustomerBalancePDF(
|
||||
pdf.SetTextColor(40, 40, 40)
|
||||
|
||||
for _, r := range rows {
|
||||
if needPage(5.8) {
|
||||
line := []string{
|
||||
r.CariKodu,
|
||||
r.CariDetay,
|
||||
r.Sirket,
|
||||
r.MuhasebeKodu,
|
||||
r.CariDoviz,
|
||||
formatMoneyPDF(r.Bakiye12),
|
||||
formatMoneyPDF(r.Bakiye13),
|
||||
formatMoneyPDF(r.USDBakiye12),
|
||||
formatMoneyPDF(r.TLBakiye12),
|
||||
formatMoneyPDF(r.USDBakiye13),
|
||||
formatMoneyPDF(r.TLBakiye13),
|
||||
formatMoneyPDF(r.VadeGun),
|
||||
formatMoneyPDF(r.VadeBelgeGun),
|
||||
}
|
||||
detailWrapCols := map[int]bool{1: true}
|
||||
rowH := calcWrappedRowHeight(line, detailW, detailWrapCols, 3.0, 5.8)
|
||||
|
||||
if needPage(rowH) {
|
||||
header()
|
||||
pdf.SetFont("dejavu", "B", 8)
|
||||
pdf.SetFillColor(218, 193, 151)
|
||||
@@ -429,33 +470,23 @@ func drawCustomerBalancePDF(
|
||||
pdf.SetTextColor(40, 40, 40)
|
||||
}
|
||||
|
||||
line := []string{
|
||||
r.CariKodu,
|
||||
r.CariDetay,
|
||||
r.Sirket,
|
||||
r.MuhasebeKodu,
|
||||
r.CariDoviz,
|
||||
formatMoneyPDF(r.Bakiye12),
|
||||
formatMoneyPDF(r.Bakiye13),
|
||||
formatMoneyPDF(r.USDBakiye12),
|
||||
formatMoneyPDF(r.TLBakiye12),
|
||||
formatMoneyPDF(r.USDBakiye13),
|
||||
formatMoneyPDF(r.TLBakiye13),
|
||||
}
|
||||
|
||||
rowY := pdf.GetY()
|
||||
rowX := marginL
|
||||
for i, v := range line {
|
||||
pdf.Rect(rowX, rowY, detailW[i], 5.8, "")
|
||||
pdf.Rect(rowX, rowY, detailW[i], rowH, "")
|
||||
align := "L"
|
||||
if i >= 5 {
|
||||
align = "R"
|
||||
}
|
||||
pdf.SetXY(rowX+1, rowY+0.8)
|
||||
pdf.CellFormat(detailW[i]-2, 4.0, v, "", 0, align, false, 0, "")
|
||||
if detailWrapCols[i] {
|
||||
drawWrapped(v, rowX, rowY, detailW[i], rowH, 3.0, "L")
|
||||
} else {
|
||||
pdf.SetXY(rowX+1, rowY+(rowH-4.0)/2)
|
||||
pdf.CellFormat(detailW[i]-2, 4.0, v, "", 0, align, false, 0, "")
|
||||
}
|
||||
rowX += detailW[i]
|
||||
}
|
||||
pdf.SetY(rowY + 5.8)
|
||||
pdf.SetY(rowY + rowH)
|
||||
}
|
||||
pdf.Ln(1.2)
|
||||
}
|
||||
@@ -508,3 +539,10 @@ func formatMoneyPDF(v float64) string {
|
||||
|
||||
return sign + strings.Join(out, ".") + "," + decPart
|
||||
}
|
||||
|
||||
func absFloat(v float64) float64 {
|
||||
if v < 0 {
|
||||
return -v
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ func buildMissingVariants(mssql *sql.DB, orderHeaderID string, lines []models.Or
|
||||
newColor := strings.TrimSpace(line.NewColor)
|
||||
newDim2 := strings.TrimSpace(line.NewDim2)
|
||||
|
||||
if lineID == "" || newItem == "" || newColor == "" {
|
||||
if lineID == "" || newItem == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -286,9 +286,6 @@ func validateUpdateLines(lines []models.OrderProductionUpdateLine) error {
|
||||
if strings.TrimSpace(line.NewItemCode) == "" {
|
||||
return errors.New("Yeni urun kodu zorunlu")
|
||||
}
|
||||
if strings.TrimSpace(line.NewColor) == "" {
|
||||
return errors.New("Yeni renk kodu zorunlu")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// GET /api/finance/account-aging-statement
|
||||
@@ -17,18 +18,35 @@ func GetStatementAgingHandler(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
selectedDate := time.Now().Format("2006-01-02")
|
||||
params := models.StatementAgingParams{
|
||||
AccountCode: strings.TrimSpace(r.URL.Query().Get("accountcode")),
|
||||
EndDate: strings.TrimSpace(r.URL.Query().Get("enddate")),
|
||||
EndDate: selectedDate,
|
||||
Parislemler: r.URL.Query()["parislemler"],
|
||||
}
|
||||
|
||||
if params.AccountCode == "" || params.EndDate == "" {
|
||||
http.Error(w, "accountcode and enddate are required", http.StatusBadRequest)
|
||||
listParams := models.CustomerBalanceListParams{
|
||||
SelectedDate: selectedDate,
|
||||
CariSearch: strings.TrimSpace(r.URL.Query().Get("cari_search")),
|
||||
CariIlkGrup: strings.TrimSpace(r.URL.Query().Get("cari_ilk_grup")),
|
||||
Piyasa: strings.TrimSpace(r.URL.Query().Get("piyasa")),
|
||||
Temsilci: strings.TrimSpace(r.URL.Query().Get("temsilci")),
|
||||
RiskDurumu: strings.TrimSpace(r.URL.Query().Get("risk_durumu")),
|
||||
IslemTipi: strings.TrimSpace(r.URL.Query().Get("islem_tipi")),
|
||||
Ulke: strings.TrimSpace(r.URL.Query().Get("ulke")),
|
||||
Il: strings.TrimSpace(r.URL.Query().Get("il")),
|
||||
Ilce: strings.TrimSpace(r.URL.Query().Get("ilce")),
|
||||
}
|
||||
if params.AccountCode != "" {
|
||||
listParams.CariSearch = params.AccountCode
|
||||
}
|
||||
|
||||
if err := queries.RebuildStatementAgingCache(r.Context()); err != nil {
|
||||
http.Error(w, "Error rebuilding aging cache: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
rows, err := queries.GetStatementAging(params)
|
||||
rows, err := queries.GetStatementAgingBalanceList(r.Context(), listParams)
|
||||
if err != nil {
|
||||
http.Error(w, "Error fetching aging statement: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
||||
34
svc/routes/statement_aging_cache.go
Normal file
34
svc/routes/statement_aging_cache.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bssapp-backend/auth"
|
||||
"bssapp-backend/queries"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type agingCacheRefreshResponse struct {
|
||||
OK bool `json:"ok"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// POST /api/finance/account-aging-statement/rebuild-cache
|
||||
// Runs only step2 + step3.
|
||||
func RebuildStatementAgingCacheHandler(w http.ResponseWriter, r *http.Request) {
|
||||
claims, ok := auth.GetClaimsFromContext(r.Context())
|
||||
if !ok || claims == nil {
|
||||
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
if err := queries.RebuildStatementAgingCache(r.Context()); err != nil {
|
||||
http.Error(w, "cache rebuild error: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
_ = json.NewEncoder(w).Encode(agingCacheRefreshResponse{
|
||||
OK: true,
|
||||
Message: "SP_BUILD_CARI_VADE_GUN_STAGING -> SP_BUILD_CARI_BAKIYE_CACHE çalıştırıldı.",
|
||||
})
|
||||
}
|
||||
90
svc/routes/statement_aging_excel.go
Normal file
90
svc/routes/statement_aging_excel.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"bssapp-backend/auth"
|
||||
"bssapp-backend/models"
|
||||
"bssapp-backend/queries"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/xuri/excelize/v2"
|
||||
)
|
||||
|
||||
func ExportStatementAgingExcelHandler(_ *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
claims, ok := auth.GetClaimsFromContext(r.Context())
|
||||
if !ok || claims == nil {
|
||||
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
selectedDate := time.Now().Format("2006-01-02")
|
||||
params := models.CustomerBalanceListParams{
|
||||
SelectedDate: selectedDate,
|
||||
CariSearch: strings.TrimSpace(r.URL.Query().Get("cari_search")),
|
||||
CariIlkGrup: strings.TrimSpace(r.URL.Query().Get("cari_ilk_grup")),
|
||||
Piyasa: strings.TrimSpace(r.URL.Query().Get("piyasa")),
|
||||
Temsilci: strings.TrimSpace(r.URL.Query().Get("temsilci")),
|
||||
RiskDurumu: strings.TrimSpace(r.URL.Query().Get("risk_durumu")),
|
||||
IslemTipi: strings.TrimSpace(r.URL.Query().Get("islem_tipi")),
|
||||
Ulke: strings.TrimSpace(r.URL.Query().Get("ulke")),
|
||||
Il: strings.TrimSpace(r.URL.Query().Get("il")),
|
||||
Ilce: strings.TrimSpace(r.URL.Query().Get("ilce")),
|
||||
}
|
||||
excludeZero12 := parseBoolQuery(r.URL.Query().Get("exclude_zero_12"))
|
||||
excludeZero13 := parseBoolQuery(r.URL.Query().Get("exclude_zero_13"))
|
||||
|
||||
rows, err := queries.GetStatementAgingBalanceList(r.Context(), params)
|
||||
if err != nil {
|
||||
http.Error(w, "db error: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
rows = filterCustomerBalanceRowsForPDF(rows, excludeZero12, excludeZero13)
|
||||
summaries, _ := buildCustomerBalancePDFData(rows)
|
||||
|
||||
f := excelize.NewFile()
|
||||
sheet := "CariYaslandirma"
|
||||
f.SetSheetName("Sheet1", sheet)
|
||||
|
||||
headers := []string{
|
||||
"Ana Cari Kodu", "Ana Cari Detay", "Piyasa", "Temsilci", "Risk Durumu",
|
||||
"1_2 Bakiye Pr.Br", "1_3 Bakiye Pr.Br", "1_2 USD Bakiye", "1_2 TRY Bakiye",
|
||||
"1_3 USD Bakiye", "1_3 TRY Bakiye", "Vade Gun", "Belge Tarihi Gun",
|
||||
}
|
||||
for i, h := range headers {
|
||||
cell, _ := excelize.CoordinatesToCellName(i+1, 1)
|
||||
f.SetCellValue(sheet, cell, h)
|
||||
}
|
||||
|
||||
rowNo := 2
|
||||
for _, s := range summaries {
|
||||
f.SetSheetRow(sheet, fmt.Sprintf("A%d", rowNo), &[]any{
|
||||
s.AnaCariKodu, s.AnaCariAdi, s.Piyasa, s.Temsilci, s.RiskDurumu,
|
||||
formatCurrencyMapPDF(s.Bakiye12Map), formatCurrencyMapPDF(s.Bakiye13Map),
|
||||
s.USDBakiye12, s.TLBakiye12, s.USDBakiye13, s.TLBakiye13, s.VadeGun, s.VadeBelge,
|
||||
})
|
||||
rowNo++
|
||||
}
|
||||
|
||||
_ = f.SetColWidth(sheet, "A", "A", 16)
|
||||
_ = f.SetColWidth(sheet, "B", "B", 34)
|
||||
_ = f.SetColWidth(sheet, "C", "F", 18)
|
||||
_ = f.SetColWidth(sheet, "G", "M", 18)
|
||||
|
||||
buf, err := f.WriteToBuffer()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
filename := fmt.Sprintf("cari_yaslandirmali_bakiye_%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())
|
||||
}
|
||||
}
|
||||
@@ -82,23 +82,30 @@ func ExportStatementAgingPDFHandler(_ *sql.DB) http.HandlerFunc {
|
||||
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
|
||||
selectedDate := time.Now().Format("2006-01-02")
|
||||
listParams := models.CustomerBalanceListParams{
|
||||
SelectedDate: selectedDate,
|
||||
CariSearch: strings.TrimSpace(r.URL.Query().Get("cari_search")),
|
||||
CariIlkGrup: strings.TrimSpace(r.URL.Query().Get("cari_ilk_grup")),
|
||||
Piyasa: strings.TrimSpace(r.URL.Query().Get("piyasa")),
|
||||
Temsilci: strings.TrimSpace(r.URL.Query().Get("temsilci")),
|
||||
RiskDurumu: strings.TrimSpace(r.URL.Query().Get("risk_durumu")),
|
||||
IslemTipi: strings.TrimSpace(r.URL.Query().Get("islem_tipi")),
|
||||
Ulke: strings.TrimSpace(r.URL.Query().Get("ulke")),
|
||||
Il: strings.TrimSpace(r.URL.Query().Get("il")),
|
||||
Ilce: strings.TrimSpace(r.URL.Query().Get("ilce")),
|
||||
}
|
||||
detailed := parseBoolQuery(r.URL.Query().Get("detailed"))
|
||||
excludeZero12 := parseBoolQuery(r.URL.Query().Get("exclude_zero_12"))
|
||||
excludeZero13 := parseBoolQuery(r.URL.Query().Get("exclude_zero_13"))
|
||||
|
||||
rows, err := queries.GetStatementAging(params)
|
||||
rows, err := queries.GetStatementAgingBalanceList(r.Context(), listParams)
|
||||
if err != nil {
|
||||
http.Error(w, "db error: "+err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
masters := buildAgingPDFData(rows)
|
||||
rows = filterCustomerBalanceRowsForPDF(rows, excludeZero12, excludeZero13)
|
||||
summaries, detailsByMaster := buildCustomerBalancePDFData(rows)
|
||||
|
||||
pdf := gofpdf.New("L", "mm", "A4", "")
|
||||
pdf.SetMargins(8, 8, 8)
|
||||
@@ -108,7 +115,14 @@ func ExportStatementAgingPDFHandler(_ *sql.DB) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
drawStatementAgingPDF(pdf, params, masters)
|
||||
drawCustomerBalancePDF(
|
||||
pdf,
|
||||
selectedDate,
|
||||
listParams.CariSearch,
|
||||
detailed,
|
||||
summaries,
|
||||
detailsByMaster,
|
||||
)
|
||||
|
||||
if err := pdf.Error(); err != nil {
|
||||
http.Error(w, "pdf render error: "+err.Error(), http.StatusInternalServerError)
|
||||
@@ -122,7 +136,11 @@ func ExportStatementAgingPDFHandler(_ *sql.DB) http.HandlerFunc {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/pdf")
|
||||
w.Header().Set("Content-Disposition", `inline; filename="account-aging-detailed.pdf"`)
|
||||
filename := "account-aging-summary.pdf"
|
||||
if detailed {
|
||||
filename = "account-aging-detailed.pdf"
|
||||
}
|
||||
w.Header().Set("Content-Disposition", fmt.Sprintf("inline; filename=%q", filename))
|
||||
_, _ = w.Write(buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user