Files
bssapp/svc/queries/account_balance_fast.go
2026-02-27 11:48:12 +03:00

92 lines
1.9 KiB
Go
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package queries
import (
"bssapp-backend/models"
"context"
)
func GetCustomerBalanceList(
ctx context.Context,
params models.CustomerBalanceListParams,
) ([]models.CustomerBalanceListRow, error) {
//------------------------------------------------
// 1⃣ DATA ÇEK
//------------------------------------------------
balances, err := getFastBalances(ctx, params.SelectedDate)
if err != nil {
return nil, err
}
masterMap, err := getCariMasterMap(ctx)
if err != nil {
return nil, err
}
//------------------------------------------------
// 2⃣ MERGE
//------------------------------------------------
resultMap := make(map[string]*models.CustomerBalanceListRow)
for _, b := range balances {
key := b.CariKodu + "|" + b.CariDoviz
r, ok := resultMap[key]
if !ok {
r = &models.CustomerBalanceListRow{
CariKodu: b.CariKodu,
CariDoviz: b.CariDoviz,
}
// Master
if m, ok := masterMap[b.CariKodu]; ok {
r.CariDetay = m.CariDetay
r.Piyasa = m.Piyasa
r.Temsilci = m.Temsilci
r.Ozellik03 = m.Ozellik03
r.Ozellik05 = m.Ozellik05
r.Ozellik06 = m.Ozellik06
r.Ozellik07 = m.Ozellik07
r.CariIlkGrup = m.Ozellik08
}
resultMap[key] = r
}
//------------------------------------------------
// 3⃣ TOPLA
//------------------------------------------------
if b.PislemTipi == "1_2" {
r.Bakiye12 += b.Bakiye
r.TLBakiye12 += b.KurBakiye
r.USDBakiye12 += b.KurBakiye / b.UsdKur
} else if b.PislemTipi == "1_3" {
r.Bakiye13 += b.Bakiye
r.TLBakiye13 += b.KurBakiye
r.USDBakiye13 += b.KurBakiye / b.UsdKur
}
}
//------------------------------------------------
// 4⃣ SLICE DÖN
//------------------------------------------------
out := make([]models.CustomerBalanceListRow, 0, len(resultMap))
for _, v := range resultMap {
out = append(out, *v)
}
return out, nil
}