Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Update bill transformers with enrichments
Sander Dorigo2d95b7f8ef1e
diff --git a/app/Api/V1/Controllers/Models/Bill/ShowController.php b/app/Api/V1/Controllers/Models/Bill/ShowController.phpindex 0204fcaf99..07b60bb735 100644--- a/app/Api/V1/Controllers/Models/Bill/ShowController.php+++ b/app/Api/V1/Controllers/Models/Bill/ShowController.php@@ -109,6 +109,17 @@ class ShowController extends Controller{$manager = $this->getManager();+ // enrich+ /** @var User $admin */+ $admin = auth()->user();+ $enrichment = new SubscriptionEnrichment();+ $enrichment->setUser($admin);+ $enrichment->setConvertToNative($this->convertToNative);+ $enrichment->setNative($this->nativeCurrency);+ $enrichment->setStart($this->parameters->get('start'));+ $enrichment->setEnd($this->parameters->get('end'));+ $bill = $enrichment->enrichSingle($bill);+/** @var BillTransformer $transformer */$transformer = app(BillTransformer::class);$transformer->setParameters($this->parameters);diff --git a/app/Api/V1/Controllers/Models/Bill/StoreController.php b/app/Api/V1/Controllers/Models/Bill/StoreController.phpindex db256a4e49..a3adea7416 100644--- a/app/Api/V1/Controllers/Models/Bill/StoreController.php+++ b/app/Api/V1/Controllers/Models/Bill/StoreController.php@@ -29,7 +29,9 @@ use FireflyIII\Api\V1\Requests\Models\Bill\StoreRequest;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Repositories\Bill\BillRepositoryInterface;use FireflyIII\Support\Http\Api\TransactionFilter;+use FireflyIII\Support\JsonApi\Enrichments\SubscriptionEnrichment;use FireflyIII\Transformers\BillTransformer;+use FireflyIII\User;use Illuminate\Http\JsonResponse;use League\Fractal\Resource\Item;@@ -72,6 +74,17 @@ class StoreController extends Controller$bill = $this->repository->store($data);$manager = $this->getManager();+ // enrich+ /** @var User $admin */+ $admin = auth()->user();+ $enrichment = new SubscriptionEnrichment();+ $enrichment->setUser($admin);+ $enrichment->setConvertToNative($this->convertToNative);+ $enrichment->setNative($this->nativeCurrency);+ $enrichment->setStart($this->parameters->get('start'));+ $enrichment->setEnd($this->parameters->get('end'));+ $bill = $enrichment->enrichSingle($bill);+/** @var BillTransformer $transformer */$transformer = app(BillTransformer::class);$transformer->setParameters($this->parameters);diff --git a/app/Api/V1/Controllers/Models/Bill/UpdateController.php b/app/Api/V1/Controllers/Models/Bill/UpdateController.phpindex 50803d22e9..1081e1fe5b 100644--- a/app/Api/V1/Controllers/Models/Bill/UpdateController.php+++ b/app/Api/V1/Controllers/Models/Bill/UpdateController.php@@ -28,7 +28,9 @@ use FireflyIII\Api\V1\Controllers\Controller;use FireflyIII\Api\V1\Requests\Models\Bill\UpdateRequest;use FireflyIII\Models\Bill;use FireflyIII\Repositories\Bill\BillRepositoryInterface;+use FireflyIII\Support\JsonApi\Enrichments\SubscriptionEnrichment;use FireflyIII\Transformers\BillTransformer;+use FireflyIII\User;use Illuminate\Http\JsonResponse;use League\Fractal\Resource\Item;@@ -67,6 +69,17 @@ class UpdateController extends Controller$bill = $this->repository->update($bill, $data);$manager = $this->getManager();+ // enrich+ /** @var User $admin */+ $admin = auth()->user();+ $enrichment = new SubscriptionEnrichment();+ $enrichment->setUser($admin);+ $enrichment->setConvertToNative($this->convertToNative);+ $enrichment->setNative($this->nativeCurrency);+ $enrichment->setStart($this->parameters->get('start'));+ $enrichment->setEnd($this->parameters->get('end'));+ $bill = $enrichment->enrichSingle($bill);+/** @var BillTransformer $transformer */$transformer = app(BillTransformer::class);$transformer->setParameters($this->parameters);diff --git a/app/Api/V1/Controllers/Models/ObjectGroup/ListController.php b/app/Api/V1/Controllers/Models/ObjectGroup/ListController.phpindex bc97296aac..e24ed1013b 100644--- a/app/Api/V1/Controllers/Models/ObjectGroup/ListController.php+++ b/app/Api/V1/Controllers/Models/ObjectGroup/ListController.php@@ -28,6 +28,7 @@ use FireflyIII\Api\V1\Controllers\Controller;use FireflyIII\Exceptions\FireflyException;use FireflyIII\Models\ObjectGroup;use FireflyIII\Repositories\ObjectGroup\ObjectGroupRepositoryInterface;+use FireflyIII\Support\JsonApi\Enrichments\SubscriptionEnrichment;use FireflyIII\Transformers\BillTransformer;use FireflyIII\Transformers\PiggyBankTransformer;use FireflyIII\User;@@ -79,6 +80,17 @@ class ListController extends Controller$count = $collection->count();$bills = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);+ // enrich+ /** @var User $admin */+ $admin = auth()->user();+ $enrichment = new SubscriptionEnrichment();+ $enrichment->setUser($admin);+ $enrichment->setConvertToNative($this->convertToNative);+ $enrichment->setNative($this->nativeCurrency);+ $enrichment->setStart($this->parameters->get('start'));+ $enrichment->setEnd($this->parameters->get('end'));+ $bills = $enrichment->enrich($bills);+// make paginator:$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));$paginator->setPath(route('api.v1.currencies.bills', [$objectGroup->id]).$this->buildParams());diff --git a/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php b/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.phpindex b7052ccfb9..6e5331a67c 100644--- a/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php+++ b/app/Api/V1/Controllers/Models/TransactionCurrency/ListController.php@@ -43,6 +43,7 @@ use FireflyIII\Repositories\Rule\RuleRepositoryInterface;use FireflyIII\Support\Http\Api\AccountFilter;use FireflyIII\Support\Http\Api\TransactionFilter;use FireflyIII\Support\JsonApi\Enrichments\AccountEnrichment;+use FireflyIII\Support\JsonApi\Enrichments\SubscriptionEnrichment;use FireflyIII\Support\JsonApi\Enrichments\TransactionGroupEnrichment;use FireflyIII\Transformers\AccountTransformer;use FireflyIII\Transformers\AvailableBudgetTransformer;@@ -182,6 +183,17 @@ class ListController extends Controller$count = $collection->count();$bills = $collection->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);+ // enrich+ /** @var User $admin */+ $admin = auth()->user();+ $enrichment = new SubscriptionEnrichment();+ $enrichment->setUser($admin);+ $enrichment->setConvertToNative($this->convertToNative);+ $enrichment->setNative($this->nativeCurrency);+ $enrichment->setStart($this->parameters->get('start'));+ $enrichment->setEnd($this->parameters->get('end'));+ $bills = $enrichment->enrichSingle($bills);+// make paginator:$paginator = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page'));$paginator->setPath(route('api.v1.currencies.bills', [$currency->code]).$this->buildParams());diff --git a/app/Http/Controllers/Bill/IndexController.php b/app/Http/Controllers/Bill/IndexController.phpindex c42607eabb..159a9c5c80 100644--- a/app/Http/Controllers/Bill/IndexController.php+++ b/app/Http/Controllers/Bill/IndexController.php@@ -29,7 +29,9 @@ use FireflyIII\Http\Controllers\Controller;use FireflyIII\Models\Bill;use FireflyIII\Repositories\Bill\BillRepositoryInterface;use FireflyIII\Repositories\ObjectGroup\OrganisesObjectGroups;+use FireflyIII\Support\JsonApi\Enrichments\SubscriptionEnrichment;use FireflyIII\Transformers\BillTransformer;+use FireflyIII\User;use Illuminate\Contracts\View\Factory;use Illuminate\Contracts\View\View;use Illuminate\Foundation\Application;@@ -76,11 +78,26 @@ class IndexController extends Controller$collection = $this->repository->getBills();$total = $collection->count();++$parameters = new ParameterBag();// sub one day from temp start so the last paid date is one day before it should be.$tempStart = clone $start;// 2023-06-23 do not sub one day from temp start, fix is in BillTransformer::payDates instead// $tempStart->subDay();++ // enrich+ /** @var User $admin */+ $admin = auth()->user();+ $enrichment = new SubscriptionEnrichment();+ $enrichment->setUser($admin);+ $enrichment->setConvertToNative($this->convertToNative);+ $enrichment->setNative($this->defaultCurrency);+ $enrichment->setStart($tempStart);+ $enrichment->setEnd($end);+ $collection = $enrichment->enrich($collection);++$parameters->set('start', $tempStart);$parameters->set('end', $end);$parameters->set('convertToNative', $this->convertToNative);diff --git a/app/Http/Controllers/Bill/ShowController.php b/app/Http/Controllers/Bill/ShowController.phpindex 812ea5149e..bd6cb150c8 100644--- a/app/Http/Controllers/Bill/ShowController.php+++ b/app/Http/Controllers/Bill/ShowController.php@@ -30,9 +30,11 @@ use FireflyIII\Http\Controllers\Controller;use FireflyIII\Models\Attachment;use FireflyIII\Models\Bill;use FireflyIII\Repositories\Bill\BillRepositoryInterface;+use FireflyIII\Support\JsonApi\Enrichments\SubscriptionEnrichment;use FireflyIII\TransactionRules\Engine\RuleEngineInterface;use FireflyIII\Transformers\AttachmentTransformer;use FireflyIII\Transformers\BillTransformer;+use FireflyIII\User;use Illuminate\Contracts\View\Factory;use Illuminate\Http\RedirectResponse;use Illuminate\Http\Request;@@ -142,6 +144,17 @@ class ShowController extends Controller$parameters->set('start', $start);$parameters->set('end', $end);+ // enrich+ /** @var User $admin */+ $admin = auth()->user();+ $enrichment = new SubscriptionEnrichment();+ $enrichment->setUser($admin);+ $enrichment->setConvertToNative($this->convertToNative);+ $enrichment->setNative($this->defaultCurrency);+ $enrichment->setStart($start);+ $enrichment->setEnd($end);+ $bill = $enrichment->enrichSingle($bill);+/** @var BillTransformer $transformer */$transformer = app(BillTransformer::class);$transformer->setParameters($parameters);diff --git a/app/Transformers/AttachmentTransformer.php b/app/Transformers/AttachmentTransformer.phpindex dba5661a7d..66f924314d 100644--- a/app/Transformers/AttachmentTransformer.php+++ b/app/Transformers/AttachmentTransformer.php@@ -35,7 +35,7 @@ class AttachmentTransformer extends AbstractTransformerprivate readonly AttachmentRepositoryInterface $repository;/**- * BillTransformer constructor.+ * AttachmentTransformer constructor.*/public function __construct(){