mirror of
https://github.com/FJurmanovic/wallet-go-api.git
synced 2026-02-06 14:18:12 +00:00
Use timezone from database
This commit is contained in:
@@ -24,9 +24,9 @@ func (as *SubscriptionService) New(body *models.NewSubscriptionBody) *models.Sub
|
|||||||
tm.SubscriptionTypeID = body.SubscriptionTypeID
|
tm.SubscriptionTypeID = body.SubscriptionTypeID
|
||||||
tm.CustomRange = int(customRange)
|
tm.CustomRange = int(customRange)
|
||||||
tm.Description = body.Description
|
tm.Description = body.Description
|
||||||
tm.StartDate = body.StartDate.Local()
|
tm.StartDate = body.StartDate
|
||||||
tm.HasEnd = body.HasEnd
|
tm.HasEnd = body.HasEnd
|
||||||
tm.EndDate = body.EndDate.Local()
|
tm.EndDate = body.EndDate
|
||||||
tm.Amount = float32(math.Round(amount*100) / 100)
|
tm.Amount = float32(math.Round(amount*100) / 100)
|
||||||
|
|
||||||
if body.StartDate.IsZero() {
|
if body.StartDate.IsZero() {
|
||||||
@@ -63,11 +63,12 @@ func (as *SubscriptionService) SubToTrans(subModel *models.Subscription) {
|
|||||||
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())
|
||||||
|
|
||||||
startDate := subModel.StartDate.Local()
|
startDate := subModel.StartDate
|
||||||
stopDate := firstOfNextMonth
|
stopDate := tzFirstOfNextMonth
|
||||||
if subModel.HasEnd && subModel.EndDate.Local().Before(firstOfNextMonth) {
|
if subModel.HasEnd && subModel.EndDate.Before(tzFirstOfNextMonth) {
|
||||||
stopDate = subModel.EndDate.Local()
|
stopDate = subModel.EndDate
|
||||||
}
|
}
|
||||||
|
|
||||||
transactions := new([]models.Transaction)
|
transactions := new([]models.Transaction)
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ func (as *TransactionService) New(body *models.NewTransactionBody) *models.Trans
|
|||||||
tm.WalletID = body.WalletID
|
tm.WalletID = body.WalletID
|
||||||
tm.TransactionTypeID = body.TransactionTypeID
|
tm.TransactionTypeID = body.TransactionTypeID
|
||||||
tm.Description = body.Description
|
tm.Description = body.Description
|
||||||
tm.TransactionDate = body.TransactionDate.Local()
|
tm.TransactionDate = body.TransactionDate
|
||||||
tm.Amount = float32(math.Round(amount*100) / 100)
|
tm.Amount = float32(math.Round(amount*100) / 100)
|
||||||
|
|
||||||
if body.TransactionDate.IsZero() {
|
if body.TransactionDate.IsZero() {
|
||||||
|
|||||||
@@ -80,19 +80,22 @@ func (as *WalletService) GetHeader(am *models.Auth, walletId string) *models.Wal
|
|||||||
|
|
||||||
for i, wallet := range *wallets {
|
for i, wallet := range *wallets {
|
||||||
for _, trans := range wallet.Transactions {
|
for _, trans := range wallet.Transactions {
|
||||||
if trans.TransactionDate.Local().Before(firstOfNextMonth) && trans.TransactionDate.Local().After(firstOfMonth) || trans.TransactionDate.Local().Equal(firstOfMonth) {
|
tzFirstOfMonthAfterNext := firstOfMonthAfterNext.In(trans.TransactionDate.Location())
|
||||||
|
tzFirstOfNextMonth := firstOfNextMonth.In(trans.TransactionDate.Location())
|
||||||
|
tzFirstOfMonth := firstOfMonth.In(trans.TransactionDate.Location())
|
||||||
|
if trans.TransactionDate.Before(tzFirstOfNextMonth) && trans.TransactionDate.After(tzFirstOfMonth) || trans.TransactionDate.Equal(tzFirstOfMonth) {
|
||||||
if trans.TransactionType.Type == "expense" {
|
if trans.TransactionType.Type == "expense" {
|
||||||
(*wallets)[i].CurrentBalance -= trans.Amount
|
(*wallets)[i].CurrentBalance -= trans.Amount
|
||||||
} else {
|
} else {
|
||||||
(*wallets)[i].CurrentBalance += trans.Amount
|
(*wallets)[i].CurrentBalance += trans.Amount
|
||||||
}
|
}
|
||||||
} else if trans.TransactionDate.Local().Before(firstOfMonthAfterNext) && trans.TransactionDate.Local().After(firstOfNextMonth) {
|
} else if trans.TransactionDate.Before(tzFirstOfMonthAfterNext) && trans.TransactionDate.After(tzFirstOfNextMonth) {
|
||||||
if trans.TransactionType.Type == "expense" {
|
if trans.TransactionType.Type == "expense" {
|
||||||
(*wallets)[i].NextMonth -= trans.Amount
|
(*wallets)[i].NextMonth -= trans.Amount
|
||||||
} else {
|
} else {
|
||||||
(*wallets)[i].NextMonth += trans.Amount
|
(*wallets)[i].NextMonth += trans.Amount
|
||||||
}
|
}
|
||||||
} else if trans.TransactionDate.Local().Before(firstOfMonth) {
|
} else if trans.TransactionDate.Before(tzFirstOfMonth) {
|
||||||
if trans.TransactionType.Type == "expense" {
|
if trans.TransactionType.Type == "expense" {
|
||||||
(*wallets)[i].LastMonth -= trans.Amount
|
(*wallets)[i].LastMonth -= trans.Amount
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user