Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Add first budget view
James Coleea808b441b56
diff --git a/app/Api/V2/Controllers/Model/Budget/ListController.php b/app/Api/V2/Controllers/Model/Budget/ListController.phpnew file mode 100644index 0000000000..8218695ebc--- /dev/null+++ b/app/Api/V2/Controllers/Model/Budget/ListController.php@@ -0,0 +1,45 @@+<?php+/*+ * ListController.php+ * Copyright (c) 2022 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++namespace FireflyIII\Api\V2\Controllers\Model\Budget;++use FireflyIII\Api\V2\Controllers\Controller;+use FireflyIII\Transformers\V2\BudgetTransformer;+use Illuminate\Http\JsonResponse;+use Illuminate\Pagination\LengthAwarePaginator;+use Illuminate\Support\Collection;++class ListController extends Controller+{+ /**+ * @return JsonResponse+ */+ public function index(): JsonResponse+ {+ $collection = new Collection;+ $paginator = new LengthAwarePaginator($collection, 0, 50, 1);+ $transformer = new BudgetTransformer();+ return response()+ ->api($this->jsonApiList('budgets', $paginator, $transformer))+ ->header('Content-Type', self::CONTENT_TYPE);+ }++}diff --git a/app/Transformers/V2/BudgetTransformer.php b/app/Transformers/V2/BudgetTransformer.phpnew file mode 100644index 0000000000..9f38d43a30--- /dev/null+++ b/app/Transformers/V2/BudgetTransformer.php@@ -0,0 +1,133 @@+<?php+/**+ * BudgetTransformer.php+ * Copyright (c) 2019 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++declare(strict_types=1);++namespace FireflyIII\Transformers\V2;++use FireflyIII\Models\Budget;+use Illuminate\Support\Collection;++/**+ * Class BudgetTransformer+ */+class BudgetTransformer extends AbstractTransformer+{+ //private OperationsRepositoryInterface $opsRepository;+ //private BudgetRepositoryInterface $repository;++ /**+ * BudgetTransformer constructor.+ *+ * @codeCoverageIgnore+ */+ public function __construct()+ {+ //$this->opsRepository = app(OperationsRepositoryInterface::class);+ //$this->repository = app(BudgetRepositoryInterface::class);+ //$this->parameters = new ParameterBag();+ }++ /**+ * Transform a budget.+ *+ * @param Budget $budget+ *+ * @return array+ */+ public function transform(Budget $budget): array+ {+ //$this->opsRepository->setUser($budget->user);+ $start = $this->parameters->get('start');+ $end = $this->parameters->get('end');+ //$autoBudget = $this->repository->getAutoBudget($budget);+// $spent = [];+// if (null !== $start && null !== $end) {+// $spent = $this->beautify($this->opsRepository->sumExpenses($start, $end, null, new Collection([$budget])));+// }++// $abCurrencyId = null;+// $abCurrencyCode = null;+// $abType = null;+// $abAmount = null;+// $abPeriod = null;+// $notes = $this->repository->getNoteText($budget);+//+// $types = [+// AutoBudget::AUTO_BUDGET_RESET => 'reset',+// AutoBudget::AUTO_BUDGET_ROLLOVER => 'rollover',+// ];+//+// if (null !== $autoBudget) {+// $abCurrencyId = (string) $autoBudget->transactionCurrency->id;+// $abCurrencyCode = $autoBudget->transactionCurrency->code;+// $abType = $types[$autoBudget->auto_budget_type];+// $abAmount = number_format((float) $autoBudget->amount, $autoBudget->transactionCurrency->decimal_places, '.', '');+// $abPeriod = $autoBudget->period;+// }++ return [+ 'id' => (string) $budget->id,+ 'created_at' => $budget->created_at->toAtomString(),+ 'updated_at' => $budget->updated_at->toAtomString(),+ 'active' => $budget->active,+ 'name' => $budget->name,+ 'order' => $budget->order,+ // 'notes' => $notes,+ // 'auto_budget_type' => $abType,+ // 'auto_budget_period' => $abPeriod,+ // 'auto_budget_currency_id' => $abCurrencyId,+ // 'auto_budget_currency_code' => $abCurrencyCode,+ // 'auto_budget_amount' => $abAmount,+ // 'spent' => $spent,+ 'links' => [+ [+ 'rel' => 'self',+ 'uri' => sprintf('/budgets/%d', $budget->id),+ ],+ ],+ ];+ }++ /**+ * @param array $array+ *+ * @return array+ */+ private function beautify(array $array): array+ {+ $return = [];+ foreach ($array as $data) {+ $data['sum'] = number_format((float) $data['sum'], (int) $data['currency_decimal_places'], '.', '');+ $return[] = $data;+ }++ return $return;+ }++ /**+ * @inheritDoc+ */+ public function collectMetaData(Collection $objects): void+ {+ // TODO: Implement collectMetaData() method.+ }+}diff --git a/frontend/src/api/v2/budgets/list.js b/frontend/src/api/v2/budgets/list.jsnew file mode 100644index 0000000000..122c817e98--- /dev/null+++ b/frontend/src/api/v2/budgets/list.js@@ -0,0 +1,28 @@+/*+ * list.js+ * Copyright (c) 2022 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++import {api} from "boot/axios";++export default class List {+ list(page) {+ let url = '/api/v2/budgets';+ return api.get(url, {params: {page: page}});+ }+}diff --git a/frontend/src/components/dashboard/BudgetBox.vue b/frontend/src/components/dashboard/BudgetBox.vuenew file mode 100644index 0000000000..8c743a4438--- /dev/null+++ b/frontend/src/components/dashboard/BudgetBox.vue@@ -0,0 +1,110 @@+<!--+ - BudgetBox.vue+ - Copyright (c) 2022 [email protected]+ -+ - This file is part of Firefly III (https://github.com/firefly-iii).+ -+ - This program is free software: you can redistribute it and/or modify+ - it under the terms of the GNU Affero General Public License as+ - published by the Free Software Foundation, either version 3 of the+ - License, or (at your option) any later version.+ -+ - This program is distributed in the hope that it will be useful,+ - but WITHOUT ANY WARRANTY; without even the implied warranty of+ - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ - GNU Affero General Public License for more details.+ -+ - You should have received a copy of the GNU Affero General Public License+ - along with this program. If not, see <https://www.gnu.org/licenses/>.+ -->++<template>+ <div class="q-mt-sm q-mr-sm">+ <q-card bordered>+ <q-item>+ <q-item-section>+ <q-item-label><strong>+ Budgets+ </strong></q-item-label>+ </q-item-section>+ </q-item>+ <q-separator/>+ <q-card-section>+ <div class="row">+ <div class="col">+ I am budget<br/>+ </div>+ </div>+ <div class="row">+ <div class="col">+ <small>I am range</small>+ </div>+ <div class="col">+ I am bar+ </div>+ </div>+ <div class="row">+ <div class="col">+ <small>I am range</small>+ </div>+ <div class="col">+ I am bar+ </div>+ </div>+ <div class="row">+ <div class="col">+ I am budget<br/>+ </div>+ </div>+ </q-card-section>++ </q-card>+ </div>+</template>++<script>+import {useFireflyIIIStore} from "../../stores/fireflyiii";+import List from '../../api/v2/budgets/list';++export default {+ name: "BudgetBox",+ data() {+ return {+ budgets: [],+ locale: 'en-US',+ page: 1+ }+ },+ mounted() {+ this.store = useFireflyIIIStore();+ this.store.$onAction(+ ({name, store, args, after, onError,}) => {+ after((result) => {+ if (name === 'setRange') {+ this.locale = this.store.getLocale;+ this.loadBox();+ }+ })+ }+ )+ if (null !== this.store.getRange.start && null !== this.store.getRange.end) {+ this.loadBox();+ }+ },+ methods: {+ loadBox: function() {++ (new List).list(1).then((data) => {+ console.log(data.data);+ });+ // todo go to next page as well.++ console.log('loadbox');+ }+ }+}+</script>++<style scoped>++</style>diff --git a/frontend/src/pages/dashboard/Dashboard.vue b/frontend/src/pages/dashboard/Dashboard.vueindex 943d4db1b4..f04c67a104 100644--- a/frontend/src/pages/dashboard/Dashboard.vue+++ b/frontend/src/pages/dashboard/Dashboard.vue@@ -24,28 +24,28 @@<div class="q-ma-md"><div class="row q-mb-sm"><div class="col">- <BillInsightBox />+ <BillInsightBox/></div><div class="col">- <SpendInsightBox />+ <SpendInsightBox/></div><div class="col">- <NetWorthInsightBox />+ <NetWorthInsightBox/></div></div><div class="row q-mb-sm"><div class="col">- <AccountChart />+ <AccountChart/></div></div><div class="row q-mb-sm"><div class="col">- <TransactionLists />+ <TransactionLists/></div></div><div class="row q-mb-sm"><div class="col">- Budget box+ <BudgetBox/></div><div class="col">Category box@@ -77,11 +77,16 @@icon="fas fa-chevron-up"direction="up">- <q-fab-action color="primary" square icon="fas fa-chart-pie" :label="$t('firefly.new_budget')" :to="{ name: 'budgets.create' }"/>- <q-fab-action color="primary" square icon="far fa-money-bill-alt" :label="$t('firefly.new_asset_account')" :to="{ name: 'accounts.create', params: {type: 'asset'} }"/>- <q-fab-action color="primary" square icon="fas fa-exchange-alt" :label="$t('firefly.newTransfer')" :to="{ name: 'transactions.create', params: {type: 'transfer'} }"/>- <q-fab-action color="primary" square icon="fas fa-long-arrow-alt-right" :label="$t('firefly.newDeposit')" :to="{ name: 'transactions.create', params: {type: 'deposit'} }"/>- <q-fab-action color="primary" square icon="fas fa-long-arrow-alt-left" :label="$t('firefly.newWithdrawal')" :to="{ name: 'transactions.create', params: {type: 'withdrawal'} }"/>+ <q-fab-action color="primary" square icon="fas fa-chart-pie" :label="$t('firefly.new_budget')"+ :to="{ name: 'budgets.create' }"/>+ <q-fab-action color="primary" square icon="far fa-money-bill-alt" :label="$t('firefly.new_asset_account')"+ :to="{ name: 'accounts.create', params: {type: 'asset'} }"/>+ <q-fab-action color="primary" square icon="fas fa-exchange-alt" :label="$t('firefly.newTransfer')"+ :to="{ name: 'transactions.create', params: {type: 'transfer'} }"/>+ <q-fab-action color="primary" square icon="fas fa-long-arrow-alt-right" :label="$t('firefly.newDeposit')"+ :to="{ name: 'transactions.create', params: {type: 'deposit'} }"/>+ <q-fab-action color="primary" square icon="fas fa-long-arrow-alt-left" :label="$t('firefly.newWithdrawal')"+ :to="{ name: 'transactions.create', params: {type: 'withdrawal'} }"/></q-fab></q-page-sticky></div>@@ -98,6 +103,7 @@ export default {NetWorthInsightBox: defineAsyncComponent(() => import('../../components/dashboard/NetWorthInsightBox.vue')),BillInsightBox: defineAsyncComponent(() => import('../../components/dashboard/BillInsightBox.vue')),SpendInsightBox: defineAsyncComponent(() => import('../../components/dashboard/SpendInsightBox.vue')),+ BudgetBox: defineAsyncComponent(() => import('../../components/dashboard/BudgetBox.vue')),}}</script>diff --git a/routes/api.php b/routes/api.phpindex e5a17250d4..781c229c52 100644--- a/routes/api.php+++ b/routes/api.php@@ -96,6 +96,7 @@ Route::group(['namespace' => 'FireflyIII\Api\V2\Controllers\Model\Budget', 'prefix' => 'v2/budgets','as' => 'api.v2.budgets',],static function () {+ Route::get('', ['uses' => 'ListController@index', 'as' => 'index']);Route::get('sum/budgeted', ['uses' => 'SumController@budgeted', 'as' => 'sum.budgeted']);Route::get('sum/spent', ['uses' => 'SumController@spent', 'as' => 'sum.spent']);}