Skip to content

Firefly III: a personal finances manager

Fix https://github.com/orgs/firefly-iii/discussions/12210

James Colefd8722e40144
diff --git a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php
index 92695f652e..43852665f2 100644
--- a/app/Repositories/PiggyBank/ModifiesPiggyBanks.php
+++ b/app/Repositories/PiggyBank/ModifiesPiggyBanks.php
@@ -385,9 +385,9 @@ trait ModifiesPiggyBanks
$piggyBank->target_date = $data['target_date'];
$piggyBank->target_date_tz = $data['target_date']?->format('e');
}
- if (array_key_exists('start_date', $data)) {
+ if (array_key_exists('start_date', $data) && '' !== $data['start_date']) {
$piggyBank->start_date = $data['start_date'];
- $piggyBank->start_date_tz = $data['target_date']?->format('e');
+ $piggyBank->start_date_tz = $data['start_date']?->format('e');
}
$piggyBank->save();
diff --git a/app/Support/JsonApi/Enrichments/PiggyBankEnrichment.php b/app/Support/JsonApi/Enrichments/PiggyBankEnrichment.php
index 48b51a33ef..24f4663e7f 100644
--- a/app/Support/JsonApi/Enrichments/PiggyBankEnrichment.php
+++ b/app/Support/JsonApi/Enrichments/PiggyBankEnrichment.php
@@ -163,6 +163,7 @@ class PiggyBankEnrichment implements EnrichmentInterface
}
// get suggested per month.
+
$meta['save_per_month'] = Steam::bcround(
$this->getSuggestedMonthlyAmount($this->date, $item->target_date, $meta['target_amount'], $meta['current_amount']),
$currency->decimal_places
@@ -295,6 +296,7 @@ class PiggyBankEnrichment implements EnrichmentInterface
/**
* Returns the suggested amount the user should save per month, or "".
+ * TODO same as in repository.
*/
private function getSuggestedMonthlyAmount(?Carbon $startDate, ?Carbon $targetDate, ?string $targetAmount, string $currentAmount): string
{
@@ -303,8 +305,7 @@ class PiggyBankEnrichment implements EnrichmentInterface
}
$savePerMonth = '0';
if (1 === bccomp($targetAmount, $currentAmount)) {
- $now = today(config('app.timezone'));
- $diffInMonths = (int) $startDate->diffInMonths($targetDate);
+ $diffInMonths = ceil($startDate->diffInMonths($targetDate));
$remainingAmount = bcsub($targetAmount, $currentAmount);
// more than 1 month to go and still need money to save: