1 | <?php |
||||
2 | |||||
3 | /** |
||||
4 | * AvailableBudgetController.php |
||||
5 | * Copyright (c) 2019 [email protected] |
||||
6 | * |
||||
7 | * This file is part of Firefly III. |
||||
8 | * |
||||
9 | * Firefly III is free software: you can redistribute it and/or modify |
||||
10 | * it under the terms of the GNU General Public License as published by |
||||
11 | * the Free Software Foundation, either version 3 of the License, or |
||||
12 | * (at your option) any later version. |
||||
13 | * |
||||
14 | * Firefly III is distributed in the hope that it will be useful, |
||||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
17 | * GNU General Public License for more details. |
||||
18 | * |
||||
19 | * You should have received a copy of the GNU General Public License |
||||
20 | * along with Firefly III. If not, see <http://www.gnu.org/licenses/>. |
||||
21 | */ |
||||
22 | |||||
23 | declare(strict_types=1); |
||||
24 | |||||
25 | namespace FireflyIII\Api\V1\Controllers\Chart; |
||||
26 | |||||
27 | |||||
28 | use FireflyIII\Api\V1\Controllers\Controller; |
||||
29 | use FireflyIII\Models\AvailableBudget; |
||||
30 | use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; |
||||
31 | use FireflyIII\User; |
||||
32 | use Illuminate\Http\JsonResponse; |
||||
33 | use Illuminate\Http\Request; |
||||
34 | use Illuminate\Support\Collection; |
||||
35 | |||||
36 | /** |
||||
37 | * Class AvailableBudgetController |
||||
38 | */ |
||||
39 | class AvailableBudgetController extends Controller |
||||
40 | { |
||||
41 | /** @var BudgetRepositoryInterface */ |
||||
42 | private $repository; |
||||
43 | |||||
44 | /** |
||||
45 | * AvailableBudgetController constructor. |
||||
46 | */ |
||||
47 | public function __construct() |
||||
48 | { |
||||
49 | parent::__construct(); |
||||
50 | $this->middleware( |
||||
51 | function ($request, $next) { |
||||
52 | /** @var User $user */ |
||||
53 | $user = auth()->user(); |
||||
54 | $this->repository = app(BudgetRepositoryInterface::class); |
||||
55 | $this->repository->setUser($user); |
||||
56 | |||||
57 | return $next($request); |
||||
58 | } |
||||
59 | ); |
||||
60 | } |
||||
61 | |||||
62 | /** |
||||
63 | * @param Request $request |
||||
64 | * |
||||
65 | * @param AvailableBudget $availableBudget |
||||
66 | * |
||||
67 | * @return JsonResponse |
||||
68 | */ |
||||
69 | public function overview(Request $request, AvailableBudget $availableBudget): JsonResponse |
||||
0 ignored issues
–
show
|
|||||
70 | { |
||||
71 | $currency = $availableBudget->transactionCurrency; |
||||
72 | $budgets = $this->repository->getActiveBudgets(); |
||||
73 | $budgetInformation = $this->repository->spentInPeriodMc($budgets, new Collection, $availableBudget->start_date, $availableBudget->end_date); |
||||
74 | $spent = 0.0; |
||||
75 | |||||
76 | // get for current currency |
||||
77 | foreach ($budgetInformation as $spentInfo) { |
||||
78 | if ($spentInfo['currency_id'] === $availableBudget->transaction_currency_id) { |
||||
79 | $spent = $spentInfo['amount']; |
||||
80 | } |
||||
81 | } |
||||
82 | $left = bcadd($availableBudget->amount, (string)$spent); |
||||
83 | // left less than zero? Set to zero. |
||||
84 | if (bccomp($left, '0') === -1) { |
||||
85 | $left = '0'; |
||||
86 | } |
||||
87 | |||||
88 | $chartData = [ |
||||
89 | [ |
||||
90 | 'label' => trans('firefly.spent'), |
||||
91 | 'currency_id' => $currency->id, |
||||
92 | 'currency_code' => $currency->code, |
||||
93 | 'currency_symbol' => $currency->symbol, |
||||
94 | 'currency_decimal_places' => $currency->decimal_places, |
||||
95 | 'type' => 'pie', |
||||
96 | 'yAxisID' => 0, // 0, 1, 2 |
||||
97 | 'entries' => [$spent * -1], |
||||
98 | ], |
||||
99 | [ |
||||
100 | 'label' => trans('firefly.left'), |
||||
101 | 'currency_id' => $currency->id, |
||||
102 | 'currency_code' => $currency->code, |
||||
103 | 'currency_symbol' => $currency->symbol, |
||||
104 | 'currency_decimal_places' => $currency->decimal_places, |
||||
105 | 'type' => 'line', // line, area or bar |
||||
106 | 'yAxisID' => 0, // 0, 1, 2 |
||||
107 | 'entries' => [round($left, $currency->decimal_places)], |
||||
0 ignored issues
–
show
$left of type string is incompatible with the type double expected by parameter $val of round() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
108 | ], |
||||
109 | ]; |
||||
110 | |||||
111 | return response()->json($chartData); |
||||
112 | } |
||||
113 | |||||
114 | } |
||||
115 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.