Merge branch 'develop' into main

This commit is contained in:
Fran Jurmanović
2021-07-05 22:28:07 +02:00
3 changed files with 28 additions and 8 deletions

View File

@@ -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
} }

View File

@@ -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

View File

@@ -1,7 +1,7 @@
package configs package configs
const ( const (
Version = "0.0.72" Version = "0.0.73"
Prefix = "v1" Prefix = "v1"
Secret = "Donde4sta" Secret = "Donde4sta"
SecretCode = "brasno" SecretCode = "brasno"