mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
Fix charts and balances.
This commit is contained in:
@@ -116,7 +116,7 @@ class AccountController extends Controller
|
||||
];
|
||||
// TODO this code is also present in the V2 chart account controller so this method is due to be deprecated.
|
||||
$currentStart = clone $start;
|
||||
$range = app('steam')->finalAccountBalanceInRange($account, $start, clone $end);
|
||||
$range = app('steam')->finalAccountBalanceInRange($account, $start, clone $end, $this->convertToNative);
|
||||
// 2022-10-11 this method no longer converts to float.
|
||||
$previous = array_values($range)[0];
|
||||
while ($currentStart <= $end) {
|
||||
|
@@ -55,6 +55,7 @@ abstract class Controller extends BaseController
|
||||
/** @var array<int, string> */
|
||||
protected array $allowedSort;
|
||||
protected ParameterBag $parameters;
|
||||
protected bool $convertToNative = false;
|
||||
|
||||
/**
|
||||
* Controller constructor.
|
||||
@@ -68,7 +69,9 @@ abstract class Controller extends BaseController
|
||||
$this->parameters = $this->getParameters();
|
||||
if (auth()->check()) {
|
||||
$language = app('steam')->getLanguage();
|
||||
$this->convertToNative = app('preferences')->get('convert_to_native', false)->data;
|
||||
app()->setLocale($language);
|
||||
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
|
@@ -118,7 +118,7 @@ class AccountController extends Controller
|
||||
'native_entries' => [],
|
||||
];
|
||||
$currentStart = clone $params['start'];
|
||||
$range = app('steam')->finalAccountBalanceInRange($account, $params['start'], clone $params['end'], $currency);
|
||||
$range = app('steam')->finalAccountBalanceInRange($account, $params['start'], clone $params['end'], $this->convertToNative);
|
||||
|
||||
$previous = array_values($range)[0]['balance'];
|
||||
$previousNative = array_values($range)[0]['native_balance'];
|
||||
|
@@ -54,9 +54,10 @@ class Controller extends BaseController
|
||||
{
|
||||
use ValidatesUserGroupTrait;
|
||||
|
||||
protected const string CONTENT_TYPE = 'application/vnd.api+json';
|
||||
protected const string CONTENT_TYPE = 'application/vnd.api+json';
|
||||
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
|
||||
protected ParameterBag $parameters;
|
||||
protected bool $convertToNative = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
@@ -77,12 +78,12 @@ class Controller extends BaseController
|
||||
*/
|
||||
private function getParameters(): ParameterBag
|
||||
{
|
||||
$bag = new ParameterBag();
|
||||
$bag = new ParameterBag();
|
||||
$bag->set('limit', 50);
|
||||
|
||||
try {
|
||||
$page = (int) request()->get('page');
|
||||
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
|
||||
} catch (ContainerExceptionInterface | NotFoundExceptionInterface $e) {
|
||||
$page = 1;
|
||||
}
|
||||
|
||||
@@ -112,7 +113,7 @@ class Controller extends BaseController
|
||||
if (null !== $date) {
|
||||
try {
|
||||
$obj = Carbon::parse((string) $date, config('app.timezone'));
|
||||
} catch (InvalidDateException|InvalidFormatException $e) {
|
||||
} catch (InvalidDateException | InvalidFormatException $e) {
|
||||
// don't care
|
||||
app('log')->warning(sprintf('Ignored invalid date "%s" in API v2 controller parameter check: %s', substr((string) $date, 0, 20), $e->getMessage()));
|
||||
}
|
||||
@@ -155,18 +156,18 @@ class Controller extends BaseController
|
||||
|
||||
final protected function jsonApiList(string $key, LengthAwarePaginator $paginator, AbstractTransformer $transformer): array
|
||||
{
|
||||
$manager = new Manager();
|
||||
$baseUrl = request()->getSchemeAndHttpHost().'/api/v2';
|
||||
$manager = new Manager();
|
||||
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v2';
|
||||
|
||||
// TODO add stuff to path?
|
||||
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
$objects = $paginator->getCollection();
|
||||
$objects = $paginator->getCollection();
|
||||
|
||||
// the transformer, at this point, needs to collect information that ALL items in the collection
|
||||
// require, like meta-data and stuff like that, and save it for later.
|
||||
$objects = $transformer->collectMetaData($objects);
|
||||
$objects = $transformer->collectMetaData($objects);
|
||||
$paginator->setCollection($objects);
|
||||
|
||||
$resource = new FractalCollection($objects, $transformer, $key);
|
||||
@@ -180,11 +181,11 @@ class Controller extends BaseController
|
||||
*
|
||||
* @param array<int, mixed>|Model $object
|
||||
*/
|
||||
final protected function jsonApiObject(string $key, array|Model $object, AbstractTransformer $transformer): array
|
||||
final protected function jsonApiObject(string $key, array | Model $object, AbstractTransformer $transformer): array
|
||||
{
|
||||
// create some objects:
|
||||
$manager = new Manager();
|
||||
$baseUrl = request()->getSchemeAndHttpHost().'/api/v2';
|
||||
$manager = new Manager();
|
||||
$baseUrl = request()->getSchemeAndHttpHost() . '/api/v2';
|
||||
$manager->setSerializer(new JsonApiSerializer($baseUrl));
|
||||
|
||||
$transformer->collectMetaData(new Collection([$object]));
|
||||
|
Reference in New Issue
Block a user