Skip to content

Firefly III: a personal finances manager

Various code changes.

James Cole5664695a9225
diff --git a/.ci/phpmd/composer.lock b/.ci/phpmd/composer.lock
index b14f856ab8..0c1647d097 100644
--- a/.ci/phpmd/composer.lock
+++ b/.ci/phpmd/composer.lock
@@ -470,16 +470,16 @@
},
{
"name": "symfony/dependency-injection",
- "version": "v7.0.1",
+ "version": "v7.0.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/dependency-injection.git",
- "reference": "f6667642954bce638733f254c39e5b5700b47ba4"
+ "reference": "bd25ef7c937b9da12510bdc4f1c66728f19620e3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/f6667642954bce638733f254c39e5b5700b47ba4",
- "reference": "f6667642954bce638733f254c39e5b5700b47ba4",
+ "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/bd25ef7c937b9da12510bdc4f1c66728f19620e3",
+ "reference": "bd25ef7c937b9da12510bdc4f1c66728f19620e3",
"shasum": ""
},
"require": {
@@ -530,7 +530,7 @@
"description": "Allows you to standardize and centralize the way objects are constructed in your application",
"homepage": "https://symfony.com",
"support": {
- "source": "https://github.com/symfony/dependency-injection/tree/v7.0.1"
+ "source": "https://github.com/symfony/dependency-injection/tree/v7.0.2"
},
"funding": [
{
@@ -546,7 +546,7 @@
"type": "tidelift"
}
],
- "time": "2023-12-01T15:10:06+00:00"
+ "time": "2023-12-28T19:18:20+00:00"
},
{
"name": "symfony/deprecation-contracts",
@@ -927,16 +927,16 @@
},
{
"name": "symfony/var-exporter",
- "version": "v7.0.1",
+ "version": "v7.0.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/var-exporter.git",
- "reference": "a3d7c877414fcd59ab7075ecdc3b8f9c00f7bcc3"
+ "reference": "345c62fefe92243c3a06fc0cc65f2ec1a47e0764"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/var-exporter/zipball/a3d7c877414fcd59ab7075ecdc3b8f9c00f7bcc3",
- "reference": "a3d7c877414fcd59ab7075ecdc3b8f9c00f7bcc3",
+ "url": "https://api.github.com/repos/symfony/var-exporter/zipball/345c62fefe92243c3a06fc0cc65f2ec1a47e0764",
+ "reference": "345c62fefe92243c3a06fc0cc65f2ec1a47e0764",
"shasum": ""
},
"require": {
@@ -981,7 +981,7 @@
"serialize"
],
"support": {
- "source": "https://github.com/symfony/var-exporter/tree/v7.0.1"
+ "source": "https://github.com/symfony/var-exporter/tree/v7.0.2"
},
"funding": [
{
@@ -997,7 +997,7 @@
"type": "tidelift"
}
],
- "time": "2023-11-30T11:38:21+00:00"
+ "time": "2023-12-27T08:42:13+00:00"
}
],
"aliases": [],
diff --git a/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php b/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php
index 87afccf4d9..f9125717a6 100644
--- a/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php
+++ b/app/Api/V1/Requests/Models/PiggyBank/StoreRequest.php
@@ -64,11 +64,11 @@ class StoreRequest extends FormRequest
{
return [
'name' => 'required|between:1,255|uniquePiggyBankForUser',
- 'current_amount' => ['numeric', 'gte:0', 'lte:target_amount','max:1000000000'],
+ 'current_amount' => ['numeric', 'gte:0', 'lte:target_amount', 'max:1000000000'],
'account_id' => 'required|numeric|belongsToUser:accounts,id',
'object_group_id' => 'numeric|belongsToUser:object_groups,id',
'object_group_title' => 'between:1,255',
- 'target_amount' => ['numeric', 'gte:0', 'lte:target_amount', 'required','max:1000000000'],
+ 'target_amount' => ['numeric', 'gte:0', 'lte:target_amount', 'required', 'max:1000000000'],
'start_date' => 'date|nullable',
'target_date' => 'date|nullable|after:start_date',
'notes' => 'max:65000',
diff --git a/app/Api/V1/Requests/Models/PiggyBank/UpdateRequest.php b/app/Api/V1/Requests/Models/PiggyBank/UpdateRequest.php
index 81cfa11576..8350906fc5 100644
--- a/app/Api/V1/Requests/Models/PiggyBank/UpdateRequest.php
+++ b/app/Api/V1/Requests/Models/PiggyBank/UpdateRequest.php
@@ -69,7 +69,7 @@ class UpdateRequest extends FormRequest
return [
'name' => 'between:1,255|uniquePiggyBankForUser:'.$piggyBank->id,
- 'current_amount' => ['numeric', 'gte:0', new LessThanPiggyTarget(),'max:1000000000'],
+ 'current_amount' => ['numeric', 'gte:0', new LessThanPiggyTarget(), 'max:1000000000'],
'target_amount' => 'numeric|gte:0|max:1000000000',
'start_date' => 'date|nullable',
'target_date' => 'date|nullable|after:start_date',
diff --git a/app/Http/Controllers/Account/EditController.php b/app/Http/Controllers/Account/EditController.php
index d4c6bee5cd..109097f394 100644
--- a/app/Http/Controllers/Account/EditController.php
+++ b/app/Http/Controllers/Account/EditController.php
@@ -171,7 +171,7 @@ class EditController extends Controller
$data = $request->getAccountData();
$this->repository->update($account, $data);
-
+ Log::channel('audit')->info(sprintf('Updated account #%d.', $account->id), $data);
$request->session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name]));
// store new attachment(s):
diff --git a/app/Http/Controllers/Bill/EditController.php b/app/Http/Controllers/Bill/EditController.php
index d18a703510..92fd5bf228 100644
--- a/app/Http/Controllers/Bill/EditController.php
+++ b/app/Http/Controllers/Bill/EditController.php
@@ -117,6 +117,8 @@ class EditController extends Controller
$billData = $request->getBillData();
$bill = $this->repository->update($bill, $billData);
+ Log::channel('audit')->info(sprintf('Updated bill #%d.', $bill->id), $billData);
+
$request->session()->flash('success', (string)trans('firefly.updated_bill', ['name' => $bill->name]));
app('preferences')->mark();
diff --git a/app/Repositories/Tag/TagRepository.php b/app/Repositories/Tag/TagRepository.php
index 1e4411559d..2ca33ce3f4 100644
--- a/app/Repositories/Tag/TagRepository.php
+++ b/app/Repositories/Tag/TagRepository.php
@@ -246,7 +246,18 @@ class TagRepository implements TagRepositoryInterface
/** @var array $journal */
foreach ($journals as $journal) {
- $currencyId = (int)$journal['currency_id'];
+ $found = false;
+
+ /** @var array $localTag */
+ foreach ($journal['tags'] as $localTag) {
+ if ($localTag['id'] === $tag->id) {
+ $found = true;
+ }
+ }
+ if (false === $found) {
+ continue;
+ }
+ $currencyId = (int) $journal['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currencyId,
'currency_name' => $journal['currency_name'],
@@ -260,7 +271,7 @@ class TagRepository implements TagRepositoryInterface
];
// add amount to correct type:
- $amount = app('steam')->positive((string)$journal['amount']);
+ $amount = app('steam')->positive((string) $journal['amount']);
$type = $journal['transaction_type_type'];
if (TransactionType::WITHDRAWAL === $type) {
$amount = bcmul($amount, '-1');
@@ -281,7 +292,7 @@ class TagRepository implements TagRepositoryInterface
TransactionType::OPENING_BALANCE => '0',
];
// add foreign amount to correct type:
- $amount = app('steam')->positive((string)$journal['foreign_amount']);
+ $amount = app('steam')->positive((string) $journal['foreign_amount']);
if (TransactionType::WITHDRAWAL === $type) {
$amount = bcmul($amount, '-1');
}
diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php
index 698140971c..7f2eb36ed7 100644
--- a/app/Support/Http/Controllers/PeriodOverview.php
+++ b/app/Support/Http/Controllers/PeriodOverview.php
@@ -347,7 +347,7 @@ trait PeriodOverview
$cache->addProperty('tag-period-entries');
$cache->addProperty($tag->id);
if ($cache->has()) {
- return $cache->get();
+ // return $cache->get();
}
/** @var array $dates */
@@ -378,6 +378,11 @@ trait PeriodOverview
$collector->setTypes([TransactionType::TRANSFER]);
$transferSet = $collector->getExtractedJournals();
+ // filer all of them:
+ $earnedSet = $this->filterJournalsByTag($earnedSet, $tag);
+ $spentSet = $this->filterJournalsByTag($spentSet, $tag);
+ $transferSet = $this->filterJournalsByTag($transferSet, $tag);
+
foreach ($dates as $currentDate) {
$spent = $this->filterJournalsByDate($spentSet, $currentDate['start'], $currentDate['end']);
$earned = $this->filterJournalsByDate($earnedSet, $currentDate['start'], $currentDate['end']);
@@ -485,7 +490,7 @@ trait PeriodOverview
/** @var array $journal */
foreach ($journals as $journal) {
- if ($account->id === (int)$journal['source_account_id']) {
+ if ($account->id === (int) $journal['source_account_id']) {
$return[] = $journal;
}
}
@@ -502,7 +507,7 @@ trait PeriodOverview
/** @var array $journal */
foreach ($journals as $journal) {
- if ($account->id === (int)$journal['destination_account_id']) {
+ if ($account->id === (int) $journal['destination_account_id']) {
$return[] = $journal;
}
}
@@ -516,7 +521,7 @@ trait PeriodOverview
/** @var array $journal */
foreach ($journals as $journal) {
- $currencyId = (int)$journal['currency_id'];
+ $currencyId = (int) $journal['currency_id'];
$foreignCurrencyId = $journal['foreign_currency_id'];
if (!array_key_exists($currencyId, $return)) {
$return[$currencyId] = [
@@ -537,7 +542,7 @@ trait PeriodOverview
$return[$foreignCurrencyId] = [
'amount' => '0',
'count' => 0,
- 'currency_id' => (int)$foreignCurrencyId,
+ 'currency_id' => (int) $foreignCurrencyId,
'currency_name' => $journal['foreign_currency_name'],
'currency_code' => $journal['foreign_currency_code'],
'currency_symbol' => $journal['foreign_currency_symbol'],
@@ -551,4 +556,25 @@ trait PeriodOverview
return $return;
}
+
+ private function filterJournalsByTag(array $set, Tag $tag): array
+ {
+ $return = [];
+ foreach ($set as $entry) {
+ $found = false;
+
+ /** @var array $localTag */
+ foreach ($entry['tags'] as $localTag) {
+ if ($localTag['id'] === $tag->id) {
+ $found = true;
+ }
+ }
+ if (false === $found) {
+ continue;
+ }
+ $return[] = $entry;
+ }
+
+ return $return;
+ }
}