Improve account CRUD and tests.

This commit is contained in:
James Cole
2019-06-22 10:25:34 +02:00
parent 150818e673
commit 0f70cc5780
18 changed files with 480 additions and 255 deletions

View File

@@ -43,6 +43,7 @@ class IndexController extends Controller
/**
* IndexController constructor.
* @codeCoverageIgnore
*/
public function __construct()
{
@@ -65,16 +66,16 @@ class IndexController extends Controller
* Show list of accounts.
*
* @param Request $request
* @param string $what
* @param string $objectType
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index(Request $request, string $what)
public function index(Request $request, string $objectType)
{
$what = $what ?? 'asset';
$subTitle = (string)trans('firefly.' . $what . '_accounts');
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $what);
$types = config('firefly.accountTypesByIdentifier.' . $what);
$objectType = $objectType ?? 'asset';
$subTitle = (string)trans(sprintf('firefly.%s_accounts', $objectType));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));
$collection = $this->repository->getAccountsByType($types);
$total = $collection->count();
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
@@ -99,16 +100,16 @@ class IndexController extends Controller
$account->endBalance = $this->isInArray($endBalances, $account->id);
$account->difference = bcsub($account->endBalance, $account->startBalance);
$account->interest = round($this->repository->getMetaValue($account, 'interest'), 6);
$account->interestPeriod = (string)trans('firefly.interest_calc_' . $this->repository->getMetaValue($account, 'interest_period'));
$account->accountTypeString = (string)trans('firefly.account_type_' . $account->accountType->type);
$account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
$account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type));
}
);
// make paginator:
$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);
$accounts->setPath(route('accounts.index', [$what]));
$accounts->setPath(route('accounts.index', [$objectType]));
return view('accounts.index', compact('what', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
return view('accounts.index', compact('objectType', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
}