Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solves #179 #223

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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