whatif shows something is wrong
parent
e9117a12a5
commit
a2634974f2
|
|
@ -82,6 +82,27 @@ func main() {
|
||||||
|
|
||||||
// MODIFIERS
|
// MODIFIERS
|
||||||
if predictionMonths, err := strconv.ParseInt(r.URL.Query().Get("predictionMonths"), 10, 16); err == nil && predictionMonths > 0 {
|
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)
|
predictionDuration := time.Hour * 24 * 365 / 12 * time.Duration(predictionMonths)
|
||||||
if r.URL.Query().Get("predictContributions") != "" {
|
if r.URL.Query().Get("predictContributions") != "" {
|
||||||
register, err = ledger.RegisterWithContributionPrediction(register, predictionDuration)
|
register, err = ledger.RegisterWithContributionPrediction(register, predictionDuration)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue