diff --git a/cmd/clitest/main.go b/cmd/clitest/main.go index ddc67d5..ca799d1 100644 --- a/cmd/clitest/main.go +++ b/cmd/clitest/main.go @@ -82,6 +82,27 @@ func main() { // MODIFIERS if predictionMonths, err := strconv.ParseInt(r.URL.Query().Get("predictionMonths"), 10, 16); err == nil && predictionMonths > 0 { + for _, whatIf := range r.URL.Query()["predictWhatIf"] { // ?whatIf=2023-01=AssetAccount:Cash=$=-1.00 + date := strings.Split(whatIf, "=")[0] + name := strings.Split(whatIf, "=")[1] + currency := ledger.Currency(strings.Split(whatIf, "=")[2]) + delta, err := strconv.ParseFloat(strings.Split(whatIf, "=")[3], 64) + if err != nil { + panic(err) + } + mostRecentDateBefore := "" + for _, d := range register.Dates() { + if _, ok := register[d][name]; !ok { + continue + } else if d > date { + continue + } + mostRecentDateBefore = d + } + balanceWouldBe := maps.Clone(register[mostRecentDateBefore][name]) + balanceWouldBe[currency] += delta + register[date][name] = balanceWouldBe + } predictionDuration := time.Hour * 24 * 365 / 12 * time.Duration(predictionMonths) if r.URL.Query().Get("predictContributions") != "" { register, err = ledger.RegisterWithContributionPrediction(register, predictionDuration)