mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add usergroup, clean up some code.
This commit is contained in:
parent
41fa2a6208
commit
b407d8d315
@ -30,7 +30,6 @@ use FireflyIII\Api\V1\Requests\Data\DateRequest;
|
|||||||
use FireflyIII\Enums\AccountTypeEnum;
|
use FireflyIII\Enums\AccountTypeEnum;
|
||||||
use FireflyIII\Exceptions\FireflyException;
|
use FireflyIII\Exceptions\FireflyException;
|
||||||
use FireflyIII\Models\Account;
|
use FireflyIII\Models\Account;
|
||||||
use FireflyIII\Models\AccountType;
|
|
||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||||
use FireflyIII\Support\Http\Api\ApiSupport;
|
use FireflyIII\Support\Http\Api\ApiSupport;
|
||||||
@ -73,19 +72,19 @@ class AccountController extends Controller
|
|||||||
public function overview(DateRequest $request): JsonResponse
|
public function overview(DateRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
// parameters for chart:
|
// parameters for chart:
|
||||||
$dates = $request->getAll();
|
$dates = $request->getAll();
|
||||||
|
|
||||||
/** @var Carbon $start */
|
/** @var Carbon $start */
|
||||||
$start = $dates['start'];
|
$start = $dates['start'];
|
||||||
|
|
||||||
/** @var Carbon $end */
|
/** @var Carbon $end */
|
||||||
$end = $dates['end'];
|
$end = $dates['end'];
|
||||||
|
|
||||||
// user's preferences
|
// user's preferences
|
||||||
$defaultSet = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value])->pluck('id')->toArray();
|
$defaultSet = $this->repository->getAccountsByType([AccountTypeEnum::ASSET->value])->pluck('id')->toArray();
|
||||||
|
|
||||||
/** @var Preference $frontpage */
|
/** @var Preference $frontpage */
|
||||||
$frontpage = app('preferences')->get('frontpageAccounts', $defaultSet);
|
$frontpage = app('preferences')->get('frontpageAccounts', $defaultSet);
|
||||||
|
|
||||||
if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) {
|
if (!(is_array($frontpage->data) && count($frontpage->data) > 0)) {
|
||||||
$frontpage->data = $defaultSet;
|
$frontpage->data = $defaultSet;
|
||||||
@ -93,14 +92,14 @@ class AccountController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get accounts:
|
// get accounts:
|
||||||
$accounts = $this->repository->getAccountsById($frontpage->data);
|
$accounts = $this->repository->getAccountsById($frontpage->data);
|
||||||
$chartData = [];
|
$chartData = [];
|
||||||
|
|
||||||
/** @var Account $account */
|
/** @var Account $account */
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency;
|
$currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency;
|
||||||
$field = $this->convertToNative ? 'native_balance' : 'balance';
|
$field = $this->convertToNative && $currency->id !== $this->defaultCurrency->id ? 'native_balance' : 'balance';
|
||||||
$currentSet = [
|
$currentSet = [
|
||||||
'label' => $account->name,
|
'label' => $account->name,
|
||||||
'currency_id' => (string) $currency->id,
|
'currency_id' => (string) $currency->id,
|
||||||
'currency_code' => $currency->code,
|
'currency_code' => $currency->code,
|
||||||
@ -117,14 +116,14 @@ class AccountController extends Controller
|
|||||||
$range = app('steam')->finalAccountBalanceInRange($account, $start, clone $end, $this->convertToNative);
|
$range = app('steam')->finalAccountBalanceInRange($account, $start, clone $end, $this->convertToNative);
|
||||||
$previous = array_values($range)[0][$field];
|
$previous = array_values($range)[0][$field];
|
||||||
while ($currentStart <= $end) {
|
while ($currentStart <= $end) {
|
||||||
$format = $currentStart->format('Y-m-d');
|
$format = $currentStart->format('Y-m-d');
|
||||||
$label = $currentStart->toAtomString();
|
$label = $currentStart->toAtomString();
|
||||||
$balance = array_key_exists($format, $range) ? $range[$format][$field] : $previous;
|
$balance = array_key_exists($format, $range) ? $range[$format][$field] : $previous;
|
||||||
$previous = $balance;
|
$previous = $balance;
|
||||||
$currentStart->addDay();
|
$currentStart->addDay();
|
||||||
$currentSet['entries'][$label] = $balance;
|
$currentSet['entries'][$label] = $balance;
|
||||||
}
|
}
|
||||||
$chartData[] = $currentSet;
|
$chartData[] = $currentSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
return response()->json($chartData);
|
return response()->json($chartData);
|
||||||
|
@ -10,4 +10,5 @@
|
|||||||
- {{ trans('email.date_time') }}: {{ $time }}
|
- {{ trans('email.date_time') }}: {{ $time }}
|
||||||
- {{ trans('email.user_agent') }}: {{ $userAgent }}
|
- {{ trans('email.user_agent') }}: {{ $userAgent }}
|
||||||
|
|
||||||
|
|
||||||
@endcomponent
|
@endcomponent
|
||||||
|
@ -23,6 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Tests\integration;
|
namespace Tests\integration;
|
||||||
|
|
||||||
|
use FireflyIII\Models\UserGroup;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||||
use Tests\integration\Traits\CollectsValues;
|
use Tests\integration\Traits\CollectsValues;
|
||||||
|
Loading…
Reference in New Issue
Block a user