mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 06:08:16 +00:00
fixed wallet not displaying next month correctly
This commit is contained in:
@@ -77,11 +77,11 @@ func (as *SubscriptionService) SubToTrans(subModel *models.Subscription, tx *pg.
|
|||||||
currentLocation := now.Location()
|
currentLocation := now.Location()
|
||||||
|
|
||||||
firstOfNextMonth := time.Date(currentYear, currentMonth+1, 1, 0, 0, 0, 0, currentLocation)
|
firstOfNextMonth := time.Date(currentYear, currentMonth+1, 1, 0, 0, 0, 0, currentLocation)
|
||||||
tzFirstOfNextMonth := firstOfNextMonth.In(subModel.StartDate.Location())
|
//tzFirstOfNextMonth := firstOfNextMonth.In(subModel.StartDate.Location())
|
||||||
|
|
||||||
startDate := subModel.StartDate
|
startDate := subModel.StartDate
|
||||||
stopDate := tzFirstOfNextMonth
|
stopDate := firstOfNextMonth
|
||||||
if subModel.HasEnd && subModel.EndDate.Before(tzFirstOfNextMonth) {
|
if subModel.HasEnd && subModel.EndDate.Before(firstOfNextMonth) {
|
||||||
stopDate = subModel.EndDate
|
stopDate = subModel.EndDate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"sync"
|
|
||||||
"time"
|
"time"
|
||||||
"wallet-api/pkg/models"
|
"wallet-api/pkg/models"
|
||||||
"wallet-api/pkg/utl/common"
|
"wallet-api/pkg/utl/common"
|
||||||
@@ -50,7 +49,6 @@ func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletI
|
|||||||
|
|
||||||
wm := new(models.WalletHeader)
|
wm := new(models.WalletHeader)
|
||||||
wallets := new([]models.WalletTransactions)
|
wallets := new([]models.WalletTransactions)
|
||||||
var wg sync.WaitGroup
|
|
||||||
transactions := new([]models.Transaction)
|
transactions := new([]models.Transaction)
|
||||||
subscriptions := new([]models.Subscription)
|
subscriptions := new([]models.Subscription)
|
||||||
|
|
||||||
@@ -85,6 +83,30 @@ func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletI
|
|||||||
query.Select()
|
query.Select()
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
|
|
||||||
|
for _, sub := range *subscriptions {
|
||||||
|
stopDate := firstOfMonthAfterNext
|
||||||
|
if sub.HasEnd && sub.EndDate.Before(firstOfMonthAfterNext) {
|
||||||
|
stopDate = sub.EndDate
|
||||||
|
}
|
||||||
|
startDate := sub.StartDate
|
||||||
|
for startDate.Before(stopDate) {
|
||||||
|
trans := sub.ToTrans()
|
||||||
|
trans.TransactionDate = startDate
|
||||||
|
if startDate.After(firstOfNextMonth) || startDate.Equal(firstOfNextMonth) {
|
||||||
|
*transactions = append(*transactions, *trans)
|
||||||
|
}
|
||||||
|
if sub.SubscriptionType.Type == "monthly" {
|
||||||
|
startDate = startDate.AddDate(0, sub.CustomRange, 0)
|
||||||
|
} else if sub.SubscriptionType.Type == "weekly" {
|
||||||
|
startDate = startDate.AddDate(0, 0, 7*sub.CustomRange)
|
||||||
|
} else if sub.SubscriptionType.Type == "daily" {
|
||||||
|
startDate = startDate.AddDate(0, 0, sub.CustomRange)
|
||||||
|
} else {
|
||||||
|
startDate = startDate.AddDate(sub.CustomRange, 0, 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, trans := range *transactions {
|
for _, trans := range *transactions {
|
||||||
addWhere(wallets, trans.WalletID, trans)
|
addWhere(wallets, trans.WalletID, trans)
|
||||||
}
|
}
|
||||||
@@ -117,8 +139,6 @@ func (as *WalletService) GetHeader(ctx context.Context, am *models.Auth, walletI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
for _, wallet := range *wallets {
|
for _, wallet := range *wallets {
|
||||||
wm.LastMonth += wallet.LastMonth
|
wm.LastMonth += wallet.LastMonth
|
||||||
wm.CurrentBalance += wallet.CurrentBalance + wallet.LastMonth
|
wm.CurrentBalance += wallet.CurrentBalance + wallet.LastMonth
|
||||||
|
|||||||
Reference in New Issue
Block a user