mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 02:36:28 +00:00 
			
		
		
		
	Merge branch 'develop' into adminlte4
This commit is contained in:
		| @@ -65,12 +65,16 @@ class AccountController extends Controller | ||||
| 
 | ||||
|     /** | ||||
|      * Documentation for this endpoint: | ||||
|      * TODO endpoint is not documented. | ||||
|      * TODO list of checks | ||||
|      * 1. use dates from ParameterBag | ||||
|      * 2. Request validates dates | ||||
|      * 3. Request includes user_group_id as administration_id | ||||
|      * 4. Endpoint is documented. | ||||
|      * 5. Collector uses administration_id | ||||
|      * | ||||
|      * @param AutocompleteRequest $request | ||||
|      * | ||||
|      * @return JsonResponse | ||||
|      * @throws JsonException | ||||
|      * @throws FireflyException | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
| @@ -79,7 +83,7 @@ class AccountController extends Controller | ||||
|         $data  = $request->getData(); | ||||
|         $types = $data['types']; | ||||
|         $query = $data['query']; | ||||
|         $date  = $data['date'] ?? today(config('app.timezone')); | ||||
|         $date  = $this->parameters->get('date') ?? today(config('app.timezone')); | ||||
|         $this->adminRepository->setAdministrationId($data['administration_id']); | ||||
| 
 | ||||
|         $return          = []; | ||||
|   | ||||
| @@ -71,6 +71,8 @@ class AccountController extends Controller | ||||
|      * If a transaction has foreign currency = native currency, the foreign amount will be used, no conversion | ||||
|      * will take place. | ||||
|      * | ||||
|      * TODO validate and set administration_id from request | ||||
|      * | ||||
|      * @param DateRequest $request | ||||
|      * | ||||
|      * @return JsonResponse | ||||
| @@ -80,15 +82,11 @@ class AccountController extends Controller | ||||
|      */ | ||||
|     public function dashboard(DateRequest $request): JsonResponse | ||||
|     { | ||||
|         // parameters for chart:
 | ||||
|         $dates = $request->getAll(); | ||||
|         /** @var Carbon $start */ | ||||
|         $start = $dates['start']; | ||||
|         $start = $this->parameters->get('start'); | ||||
|         /** @var Carbon $end */ | ||||
|         $end = $dates['end']; | ||||
|         $end = $this->parameters->get('end'); | ||||
|         $end->endOfDay(); | ||||
|         /** @var User $user */ | ||||
|         $user = auth()->user(); | ||||
| 
 | ||||
|         // user's preferences
 | ||||
|         $defaultSet = $this->repository->getAccountsByType([AccountType::ASSET, AccountType::DEFAULT])->pluck('id')->toArray(); | ||||
|   | ||||
| @@ -69,6 +69,9 @@ class BalanceController extends Controller | ||||
|      * If the transaction being processed is already in native currency OR if the | ||||
|      * foreign amount is in the native currency, the amount will not be converted. | ||||
|      * | ||||
|      * TODO validate and set administration_id | ||||
|      * TODO collector set group, not user | ||||
|      * | ||||
|      * @param BalanceChartRequest $request | ||||
|      * | ||||
|      * @return JsonResponse | ||||
| @@ -78,9 +81,9 @@ class BalanceController extends Controller | ||||
|     { | ||||
|         $params = $request->getAll(); | ||||
|         /** @var Carbon $start */ | ||||
|         $start = $params['start']; | ||||
|         $start = $this->parameters->get('start'); | ||||
|         /** @var Carbon $end */ | ||||
|         $end = $params['end']; | ||||
|         $end = $this->parameters->get('end'); | ||||
|         $end->endOfDay(); | ||||
|         /** @var Collection $accounts */ | ||||
|         $accounts       = $params['accounts']; | ||||
|   | ||||
| @@ -69,6 +69,8 @@ class BudgetController extends Controller | ||||
|     /** | ||||
|      * @param DateRequest $request | ||||
|      * | ||||
|      * TODO see autocomplete/accountcontroller | ||||
|      * | ||||
|      * @return JsonResponse | ||||
|      * @throws FireflyException | ||||
|      */ | ||||
|   | ||||
| @@ -61,6 +61,7 @@ class CategoryController extends Controller | ||||
| 
 | ||||
|     /** | ||||
|      * TODO may be worth to move to a handler but the data is simple enough. | ||||
|      * TODO see autoComplete/account controller | ||||
|      * | ||||
|      * @param DateRequest $request | ||||
|      * | ||||
| @@ -69,11 +70,10 @@ class CategoryController extends Controller | ||||
|      */ | ||||
|     public function dashboard(DateRequest $request): JsonResponse | ||||
|     { | ||||
|         $params = $request->getAll(); | ||||
|         /** @var Carbon $start */ | ||||
|         $start = $params['start']; | ||||
|         $start = $this->parameters->get('start'); | ||||
|         /** @var Carbon $end */ | ||||
|         $end        = $params['end']; | ||||
|         $end        = $this->parameters->get('end'); | ||||
|         $accounts   = $this->accountRepos->getAccountsByType([AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::ASSET, AccountType::DEFAULT]); | ||||
|         $default    = app('amount')->getDefaultCurrency(); | ||||
|         $converter  = new ExchangeRateConverter(); | ||||
|   | ||||
| @@ -93,21 +93,25 @@ class Controller extends BaseController | ||||
|         // some date fields:
 | ||||
|         foreach ($dates as $field) { | ||||
|             $date = null; | ||||
|             $obj  = null; | ||||
|             try { | ||||
|                 $date = request()->query->get($field); | ||||
|             } catch (BadRequestException $e) { | ||||
|                 Log::error(sprintf('Request field "%s" contains a non-scalar value. Value set to NULL.', $field)); | ||||
|                 Log::error($e->getMessage()); | ||||
|                 $value = null; | ||||
|             } | ||||
|             $obj = null; | ||||
|             if (null !== $date) { | ||||
|                 try { | ||||
|                     $obj = Carbon::parse($date); | ||||
|                     $obj = Carbon::parse($date, config('app.timezone')); | ||||
|                 } catch (InvalidDateException | InvalidFormatException $e) { | ||||
|                     // don't care
 | ||||
|                     app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', substr($date, 0, 20), $e->getMessage())); | ||||
|                 } | ||||
|                 // out of range? set to null.
 | ||||
|                 if (null !== $obj && ($obj->year <= 1900 || $obj->year > 2099)) { | ||||
|                     app('log')->warning(sprintf('Refuse to use date "%s" in API v2 controller parameter check: %s', $field, $obj->toAtomString())); | ||||
|                     $obj = null; | ||||
|                 } | ||||
|             } | ||||
|             $bag->set($field, $obj); | ||||
|         } | ||||
|   | ||||
							
								
								
									
										72
									
								
								app/Api/V2/Controllers/Model/Bill/ShowController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								app/Api/V2/Controllers/Model/Bill/ShowController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| <?php | ||||
| /* | ||||
|  * ShowController.php | ||||
|  * Copyright (c) 2023 james@firefly-iii.org | ||||
|  * | ||||
|  * 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\Bill; | ||||
| 
 | ||||
| use FireflyIII\Api\V2\Controllers\Controller; | ||||
| use FireflyIII\Repositories\Administration\Bill\BillRepositoryInterface; | ||||
| use FireflyIII\Transformers\V2\BillTransformer; | ||||
| use Illuminate\Http\JsonResponse; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Pagination\LengthAwarePaginator; | ||||
| 
 | ||||
| /** | ||||
|  * Class ShowController | ||||
|  */ | ||||
| class ShowController extends Controller | ||||
| { | ||||
|     private BillRepositoryInterface $repository; | ||||
| 
 | ||||
|     public function __construct() | ||||
|     { | ||||
|         parent::__construct(); | ||||
|         $this->middleware( | ||||
|             function ($request, $next) { | ||||
|                 $this->repository = app(BillRepositoryInterface::class); | ||||
|                 $this->repository->setAdministrationId(auth()->user()->user_group_id); | ||||
|                 return $next($request); | ||||
|             } | ||||
|         ); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * @param Request $request | ||||
|      * | ||||
|      * TODO see autocomplete/accountcontroller for list. | ||||
|      * | ||||
|      * @return JsonResponse | ||||
|      */ | ||||
|     public function index(Request $request): JsonResponse | ||||
|     { | ||||
|         $this->repository->correctOrder(); | ||||
|         $bills       = $this->repository->getBills(); | ||||
|         $pageSize    = (int)app('preferences')->getForUser(auth()->user(), 'listPageSize', 50)->data; | ||||
|         $count       = $bills->count(); | ||||
|         $bills       = $bills->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize); | ||||
|         $paginator   = new LengthAwarePaginator($bills, $count, $pageSize, $this->parameters->get('page')); | ||||
|         $transformer = new BillTransformer(); | ||||
|         $transformer->setParameters($this->parameters); // give params to transformer
 | ||||
| 
 | ||||
|         return response() | ||||
|             ->json($this->jsonApiList('subscriptions', $paginator, $transformer)) | ||||
|             ->header('Content-Type', self::CONTENT_TYPE); | ||||
|     } | ||||
| } | ||||
| @@ -26,7 +26,7 @@ namespace FireflyIII\Api\V2\Controllers\Model\Bill; | ||||
| 
 | ||||
| use FireflyIII\Api\V2\Controllers\Controller; | ||||
| use FireflyIII\Api\V2\Request\Generic\DateRequest; | ||||
| use FireflyIII\Repositories\Bill\BillRepositoryInterface; | ||||
| use FireflyIII\Repositories\Administration\Bill\BillRepositoryInterface; | ||||
| use FireflyIII\Support\Http\Api\ConvertsExchangeRates; | ||||
| use Illuminate\Http\JsonResponse; | ||||
| 
 | ||||
| @@ -35,8 +35,6 @@ use Illuminate\Http\JsonResponse; | ||||
|  */ | ||||
| class SumController extends Controller | ||||
| { | ||||
|     use ConvertsExchangeRates; | ||||
| 
 | ||||
|     private BillRepositoryInterface $repository; | ||||
| 
 | ||||
|     /** | ||||
| @@ -58,35 +56,37 @@ class SumController extends Controller | ||||
|      * This endpoint is documented at: | ||||
|      * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/transactions-sum/getBillsPaidTrSum
 | ||||
|      * | ||||
|      * TODO see autocomplete/accountcontroller for list. | ||||
|      * | ||||
|      * @param DateRequest $request | ||||
|      * | ||||
|      * @return JsonResponse | ||||
|      */ | ||||
|     public function paid(DateRequest $request): JsonResponse | ||||
|     { | ||||
|         $dates     = $request->getAll(); | ||||
|         $result    = $this->repository->sumPaidInRange($dates['start'], $dates['end']); | ||||
|         $converted = $this->cerSum($result); | ||||
|         $this->repository->setAdministrationId(auth()->user()->user_group_id); | ||||
|         $result = $this->repository->sumPaidInRange($this->parameters->get('start'), $this->parameters->get('end')); | ||||
| 
 | ||||
|         // convert to JSON response:
 | ||||
|         return response()->api($converted); | ||||
|         return response()->api(array_values($result)); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * This endpoint is documented at: | ||||
|      * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v2)#/transactions-sum/getBillsUnpaidTrSum
 | ||||
|      * | ||||
|      * TODO see autocomplete/accountcontroller for list. | ||||
|      * | ||||
|      * @param DateRequest $request | ||||
|      * | ||||
|      * @return JsonResponse | ||||
|      */ | ||||
|     public function unpaid(DateRequest $request): JsonResponse | ||||
|     { | ||||
|         $dates     = $request->getAll(); | ||||
|         $result    = $this->repository->sumUnpaidInRange($dates['start'], $dates['end']); | ||||
|         $converted = $this->cerSum($result); | ||||
|         $this->repository->setAdministrationId(auth()->user()->user_group_id); | ||||
|         $result = $this->repository->sumUnpaidInRange($this->parameters->get('start'), $this->parameters->get('end')); | ||||
| 
 | ||||
|         // convert to JSON response:
 | ||||
|         return response()->api($converted); | ||||
|         return response()->api(array_values($result)); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -60,6 +60,8 @@ class ListController extends Controller | ||||
|      */ | ||||
|     public function index(Request $request): JsonResponse | ||||
|     { | ||||
|         echo 'this needs move to Administration'; | ||||
|         exit; | ||||
|         $collection = $this->repository->getActiveBudgets(); | ||||
|         $total      = $collection->count(); | ||||
|         $collection->slice($this->pageSize * $this->parameters->get('page'), $this->pageSize); | ||||
|   | ||||
| @@ -41,8 +41,6 @@ class BalanceChartRequest extends FormRequest | ||||
|     public function getAll(): array | ||||
|     { | ||||
|         return [ | ||||
|             'start'    => $this->getCarbonDate('start'), | ||||
|             'end'      => $this->getCarbonDate('end'), | ||||
|             'accounts' => $this->getAccountList(), | ||||
|             'period'   => $this->string('period'), | ||||
|         ]; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user