Skip to content

Commit

Permalink
Merge pull request #223 from Viva-con-Agua/dk/develop_2
Browse files Browse the repository at this point in the history
solves #179
  • Loading branch information
TobiKaestle authored Dec 4, 2024
2 parents 1590afe + a8c41eb commit ca3a697
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 10 deletions.
20 changes: 20 additions & 0 deletions dao/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ func UpdateDatabase() {
PublishRoles()
Updates.Insert(ctx, "publish_roles_initial")
}
if !Updates.Check(ctx, "date_of_deposit") {
UpdateDateOfDeposit(ctx)
Updates.Insert(ctx, "date_of_deposit")
}
}

func UpdateCrewMaibox(ctx context.Context) {
Expand Down Expand Up @@ -285,3 +289,19 @@ func UpdateDepositUnitNorms(ctx context.Context) {
log.Print(err)
}
}

func UpdateDateOfDeposit(ctx context.Context) {
filter := vmdb.NewFilter()
filter.EqualStringList("status", []string{"wait", "confirmed"})
deposits := []models.Deposit{}
if err := DepositCollection.Find(ctx, bson.D{{}}, &deposits); err != nil {
log.Print(err)
}
for _, entry := range deposits {
updateFilter := bson.D{{Key: "_id", Value: entry.ID}}
update := bson.D{{Key: "date_of_deposit", Value: entry.Modified.Created}}
if err := DepositCollection.UpdateOne(ctx, updateFilter, vmdb.UpdateSet(update), nil); err != nil {
log.Print(err)
}
}
}
28 changes: 18 additions & 10 deletions models/deposit.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package models

import (
"time"

"github.com/Viva-con-Agua/vcago"
"github.com/Viva-con-Agua/vcago/vmdb"
"github.com/Viva-con-Agua/vcago/vmod"
Expand Down Expand Up @@ -47,14 +49,15 @@ type (
UpdateState string `json:"update_state" bson:"-"`
}
DepositUpdate struct {
ID string `json:"id" bson:"_id"`
CrewID string `json:"crew_id" bson:"crew_id"`
Status string `json:"status" bson:"status"`
DepositUnit []DepositUnitUpdate `json:"deposit_units" bson:"-"`
HasExternal bool `json:"has_external" bson:"has_external"`
External External `json:"external" bson:"external"`
UpdateState string `json:"update_state" bson:"-"`
Money vmod.Money `json:"money" bson:"money"`
ID string `json:"id" bson:"_id"`
CrewID string `json:"crew_id" bson:"crew_id"`
Status string `json:"status" bson:"status"`
DepositUnit []DepositUnitUpdate `json:"deposit_units" bson:"-"`
HasExternal bool `json:"has_external" bson:"has_external"`
External External `json:"external" bson:"external"`
UpdateState string `json:"update_state" bson:"-"`
DateOfDeposit int64 `json:"date_of_deposit" bson:"date_of_deposit"`
Money vmod.Money `json:"money" bson:"money"`
}
DepositDatabase struct {
ID string `json:"id" bson:"_id"`
Expand All @@ -65,6 +68,7 @@ type (
CreatorID string `json:"creator_id" bson:"creator_id"`
ConfirmerID string `json:"confirmer_id" bson:"confirmer_id"`
HasExternal bool `json:"has_external" bson:"has_external"`
DateOfDeposit int64 `json:"date_of_deposit" bson:"date_of_deposit"`
External External `json:"external" bson:"external"`
Modified vmod.Modified `json:"modified" bson:"modified"`
}
Expand All @@ -80,6 +84,7 @@ type (
Confirmer User `json:"confirmer" bson:"confirmer"`
HasExternal bool `json:"has_external" bson:"has_external"`
Receipts []ReceiptFile `json:"receipts" bson:"receipts"`
DateOfDeposit int64 `json:"date_of_deposit" bson:"date_of_deposit"`
External External `json:"external" bson:"external"`
Modified vmod.Modified `json:"modified" bson:"modified"`
}
Expand Down Expand Up @@ -202,7 +207,7 @@ func (i *DepositUpdate) DepositDatabase(current *Deposit) (r *DepositUpdate, cre
contains = true
}
}
if contains == false {
if !contains {
delete = append(delete, value_current)
}
}
Expand All @@ -223,12 +228,15 @@ func (i *DepositUpdate) DepositDatabase(current *Deposit) (r *DepositUpdate, cre
}
}
currency := "EUR"
if i.DepositUnit != nil && len(i.DepositUnit) != 0 {
if len(i.DepositUnit) != 0 {
currency = i.DepositUnit[0].Money.Currency
}
r = i
r.Money.Amount = amount
r.Money.Currency = currency
if current.Status != "wait" && i.Status == "wait" {
r.DateOfDeposit = time.Now().Unix()
}
return
}

Expand Down

0 comments on commit ca3a697

Please sign in to comment.