Various code cleanup and fixed alignments.

This commit is contained in:
James Cole
2024-01-01 14:43:56 +01:00
parent 1368aafe5f
commit f963ac63f1
443 changed files with 3668 additions and 3672 deletions

View File

@@ -95,7 +95,7 @@ class CreateController extends Controller
];
// interest calculation periods:
$interestPeriods = [
$interestPeriods = [
'daily' => (string)trans('firefly.interest_calc_daily'),
'monthly' => (string)trans('firefly.interest_calc_monthly'),
'yearly' => (string)trans('firefly.interest_calc_yearly'),
@@ -132,8 +132,8 @@ class CreateController extends Controller
*/
public function store(AccountFormRequest $request)
{
$data = $request->getAccountData();
$account = $this->repository->store($data);
$data = $request->getAccountData();
$account = $this->repository->store($data);
$request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name]));
app('preferences')->mark();
@@ -151,7 +151,7 @@ class CreateController extends Controller
// store attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($account, $files);
}
@@ -165,7 +165,7 @@ class CreateController extends Controller
}
// redirect to previous URL.
$redirect = redirect($this->getPreviousUrl('accounts.create.url'));
$redirect = redirect($this->getPreviousUrl('accounts.create.url'));
if (1 === (int)$request->get('create_another')) {
// set value so create routine will not overwrite URL:
$request->session()->put('accounts.create.fromStore', true);

View File

@@ -80,17 +80,17 @@ class EditController extends Controller
return $this->redirectAccountToAccount($account);
}
$objectType = config('firefly.shortNamesByFullName')[$account->accountType->type];
$subTitle = (string) trans(sprintf('firefly.edit_%s_account', $objectType), ['name' => $account->name]);
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$roles = $this->getRoles();
$liabilityTypes = $this->getLiabilityTypes();
$location = $repository->getLocation($account);
$latitude = null !== $location ? $location->latitude : config('firefly.default_location.latitude');
$longitude = null !== $location ? $location->longitude : config('firefly.default_location.longitude');
$zoomLevel = null !== $location ? $location->zoom_level : config('firefly.default_location.zoom_level');
$hasLocation = null !== $location;
$locations = [
$objectType = config('firefly.shortNamesByFullName')[$account->accountType->type];
$subTitle = (string) trans(sprintf('firefly.edit_%s_account', $objectType), ['name' => $account->name]);
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$roles = $this->getRoles();
$liabilityTypes = $this->getLiabilityTypes();
$location = $repository->getLocation($account);
$latitude = null !== $location ? $location->latitude : config('firefly.default_location.latitude');
$longitude = null !== $location ? $location->longitude : config('firefly.default_location.longitude');
$zoomLevel = null !== $location ? $location->zoom_level : config('firefly.default_location.zoom_level');
$hasLocation = null !== $location;
$locations = [
'location' => [
'latitude' => null !== old('location_latitude') ? old('location_latitude') : $latitude,
'longitude' => null !== old('location_longitude') ? old('location_longitude') : $longitude,
@@ -99,13 +99,13 @@ class EditController extends Controller
],
];
$liabilityDirections = [
$liabilityDirections = [
'debit' => trans('firefly.liability_direction_debit'),
'credit' => trans('firefly.liability_direction_credit'),
];
// interest calculation periods:
$interestPeriods = [
$interestPeriods = [
'daily' => (string) trans('firefly.interest_calc_daily'),
'monthly' => (string) trans('firefly.interest_calc_monthly'),
'yearly' => (string) trans('firefly.interest_calc_yearly'),
@@ -121,17 +121,17 @@ class EditController extends Controller
if ('0' === $openingBalanceAmount) {
$openingBalanceAmount = '';
}
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$openingBalanceDate = $repository->getOpeningBalanceDate($account);
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
// include this account in net-worth charts?
$includeNetWorth = $repository->getMetaValue($account, 'include_net_worth');
$includeNetWorth = null === $includeNetWorth ? true : '1' === $includeNetWorth;
$includeNetWorth = $repository->getMetaValue($account, 'include_net_worth');
$includeNetWorth = null === $includeNetWorth ? true : '1' === $includeNetWorth;
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');
$virtualBalance = null === $account->virtual_balance ? '0' : $account->virtual_balance;
$preFilled = [
$hasOldInput = null !== $request->old('_token');
$virtualBalance = null === $account->virtual_balance ? '0' : $account->virtual_balance;
$preFilled = [
'account_number' => $repository->getMetaValue($account, 'account_number'),
'account_role' => $repository->getMetaValue($account, 'account_role'),
'cc_type' => $repository->getMetaValue($account, 'cc_type'),
@@ -169,14 +169,14 @@ class EditController extends Controller
return $this->redirectAccountToAccount($account);
}
$data = $request->getAccountData();
$data = $request->getAccountData();
$this->repository->update($account, $data);
Log::channel('audit')->info(sprintf('Updated account #%d.', $account->id), $data);
$request->session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name]));
// store new attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($account, $files);
}

View File

@@ -70,22 +70,22 @@ class IndexController extends Controller
* */
public function inactive(Request $request, string $objectType)
{
$inactivePage = true;
$subTitle = (string)trans(sprintf('firefly.%s_accounts_inactive', $objectType));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));
$collection = $this->repository->getInactiveAccountsByType($types);
$total = $collection->count();
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);
$inactivePage = true;
$subTitle = (string)trans(sprintf('firefly.%s_accounts_inactive', $objectType));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));
$collection = $this->repository->getInactiveAccountsByType($types);
$total = $collection->count();
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);
unset($collection);
/** @var Carbon $start */
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$start->subDay();
$ids = $accounts->pluck('id')->toArray();
@@ -108,7 +108,7 @@ class IndexController extends Controller
);
// make paginator:
$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);
$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);
$accounts->setPath(route('accounts.inactive.index', [$objectType]));
return view('accounts.index', compact('objectType', 'inactivePage', 'subTitleIcon', 'subTitle', 'page', 'accounts'));
@@ -124,9 +124,9 @@ class IndexController extends Controller
public function index(Request $request, string $objectType)
{
app('log')->debug(sprintf('Now at %s', __METHOD__));
$subTitle = (string)trans(sprintf('firefly.%s_accounts', $objectType));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));
$subTitle = (string)trans(sprintf('firefly.%s_accounts', $objectType));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));
$this->repository->resetAccountOrder();
@@ -142,10 +142,10 @@ class IndexController extends Controller
unset($collection);
/** @var Carbon $start */
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$start->subDay();
$ids = $accounts->pluck('id')->toArray();
@@ -155,8 +155,8 @@ class IndexController extends Controller
$accounts->each(
function (Account $account) use ($activities, $startBalances, $endBalances): void {
$interest = (string)$this->repository->getMetaValue($account, 'interest');
$interest = '' === $interest ? '0' : $interest;
$interest = (string)$this->repository->getMetaValue($account, 'interest');
$interest = '' === $interest ? '0' : $interest;
// See reference nr. 68
$account->lastActivityDate = $this->isInArrayDate($activities, $account->id);
@@ -178,7 +178,7 @@ class IndexController extends Controller
app('log')->debug(sprintf('Count of accounts before LAP: %d', $accounts->count()));
/** @var LengthAwarePaginator $accounts */
$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);
$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);
$accounts->setPath(route('accounts.index', [$objectType]));
app('log')->debug(sprintf('Count of accounts after LAP (1): %d', $accounts->count()));

View File

@@ -85,10 +85,10 @@ class ReconcileController extends Controller
return redirect(route('accounts.index', [config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type))]));
}
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
// no start or end:
$range = app('navigation')->getViewRange(false);
$range = app('navigation')->getViewRange(false);
// get start and end
@@ -97,7 +97,7 @@ class ReconcileController extends Controller
$start = clone session('start', app('navigation')->startOfPeriod(new Carbon(), $range));
/** @var Carbon $end */
$end = clone session('end', app('navigation')->endOfPeriod(new Carbon(), $range));
$end = clone session('end', app('navigation')->endOfPeriod(new Carbon(), $range));
}
if (null === $end) {
/** @var Carbon $end */
@@ -108,12 +108,12 @@ class ReconcileController extends Controller
[$start, $end] = [$end, $start];
}
$startDate = clone $start;
$startDate = clone $start;
$startDate->subDay();
$startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = app('steam')->bcround(app('steam')->balance($account, $end), $currency->decimal_places);
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
$subTitle = (string)trans('firefly.reconcile_account', ['account' => $account->name]);
$startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = app('steam')->bcround(app('steam')->balance($account, $end), $currency->decimal_places);
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
$subTitle = (string)trans('firefly.reconcile_account', ['account' => $account->name]);
// various links
$transactionsUrl = route('accounts.reconcile.transactions', [$account->id, '%start%', '%end%']);
@@ -154,7 +154,7 @@ class ReconcileController extends Controller
}
app('log')->debug('In ReconcileController::submit()');
$data = $request->getAll();
$data = $request->getAll();
/** @var string $journalId */
foreach ($data['journals'] as $journalId) {
@@ -209,14 +209,14 @@ class ReconcileController extends Controller
}
// title:
$description = trans(
$description = trans(
'firefly.reconciliation_transaction_title',
[
'from' => $start->isoFormat($this->monthAndDayFormat),
'to' => $end->isoFormat($this->monthAndDayFormat),
]
);
$submission = [
$submission = [
'user' => auth()->user()->id,
'group_title' => null,
'transactions' => [
@@ -238,10 +238,10 @@ class ReconcileController extends Controller
];
/** @var TransactionGroupFactory $factory */
$factory = app(TransactionGroupFactory::class);
$factory = app(TransactionGroupFactory::class);
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
$factory->setUser($user);
try {

View File

@@ -77,7 +77,7 @@ class ShowController extends Controller
* */
public function show(Request $request, Account $account, Carbon $start = null, Carbon $end = null)
{
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
if (!$this->isEditableAccount($account)) {
return $this->redirectAccountToAccount($account);
@@ -86,7 +86,7 @@ class ShowController extends Controller
// @var Carbon $start
$start ??= session('start');
// @var Carbon $end
$end ??= session('end');
$end ??= session('end');
if ($end < $start) {
[$start, $end] = [$end, $start];
@@ -111,7 +111,7 @@ class ShowController extends Controller
}
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector
->setAccounts(new Collection([$account]))
->setLimit($pageSize)
@@ -123,11 +123,11 @@ class ShowController extends Controller
// is just part of ONE of the journals. To force this:
$collector->setExpandGroupSearch(true);
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]));
$showAll = false;
$balance = app('steam')->balance($account, $end);
$showAll = false;
$balance = app('steam')->balance($account, $end);
return view(
'accounts.show',
@@ -178,18 +178,18 @@ class ShowController extends Controller
$periods = new Collection();
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page)->withAccountInformation()->withCategoryInformation();
// this search will not include transaction groups where this asset account (or liability)
// is just part of ONE of the journals. To force this:
$collector->setExpandGroupSearch(true);
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('accounts.show.all', [$account->id]));
$chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$showAll = true;
$balance = app('steam')->balance($account, $end);
$chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$showAll = true;
$balance = app('steam')->balance($account, $end);
return view(
'accounts.show',

View File

@@ -61,8 +61,8 @@ class ConfigurationController extends Controller
*/
public function index()
{
$subTitle = (string)trans('firefly.instance_configuration');
$subTitleIcon = 'fa-wrench';
$subTitle = (string)trans('firefly.instance_configuration');
$subTitleIcon = 'fa-wrench';
Log::channel('audit')->info('User visits admin config index.');

View File

@@ -70,7 +70,7 @@ class HomeController extends Controller
foreach (config('firefly.admin_notifications') as $item) {
$notifications[$item] = app('fireflyconfig')->get(sprintf('notification_%s', $item), true)->data;
}
$slackUrl = app('fireflyconfig')->get('slack_webhook_url', '')->data;
$slackUrl = app('fireflyconfig')->get('slack_webhook_url', '')->data;
return view('admin.index', compact('title', 'mainTitleIcon', 'email', 'notifications', 'slackUrl'));
}

View File

@@ -237,7 +237,7 @@ class LinkController extends Controller
return redirect(route('admin.links.index'));
}
$data = [
$data = [
'name' => $request->convertString('name'),
'inward' => $request->convertString('inward'),
'outward' => $request->convertString('outward'),

View File

@@ -75,7 +75,7 @@ class UpdateController extends Controller
1 => (string)trans('firefly.updates_enable_check'),
];
$channelOptions = [
$channelOptions = [
'stable' => (string)trans('firefly.update_channel_stable'),
'beta' => (string)trans('firefly.update_channel_beta'),
'alpha' => (string)trans('firefly.update_channel_alpha'),

View File

@@ -133,11 +133,11 @@ class UserController extends Controller
}
session()->forget('users.edit.fromUpdate');
$subTitle = (string)trans('firefly.edit_user', ['email' => $user->email]);
$subTitleIcon = 'fa-user-o';
$currentUser = auth()->user();
$isAdmin = $this->repository->hasRole($user, 'owner');
$codes = [
$subTitle = (string)trans('firefly.edit_user', ['email' => $user->email]);
$subTitleIcon = 'fa-user-o';
$currentUser = auth()->user();
$isAdmin = $this->repository->hasRole($user, 'owner');
$codes = [
'' => (string)trans('firefly.no_block_code'),
'bounced' => (string)trans('firefly.block_code_bounced'),
'expired' => (string)trans('firefly.block_code_expired'),
@@ -164,7 +164,7 @@ class UserController extends Controller
$allowInvites = true;
}
$invitedUsers = $this->repository->getInvitedUsers();
$invitedUsers = $this->repository->getInvitedUsers();
// add meta stuff.
$users->each(
@@ -223,7 +223,7 @@ class UserController extends Controller
public function update(UserFormRequest $request, User $user)
{
app('log')->debug('Actually here');
$data = $request->getUserData();
$data = $request->getUserData();
// var_dump($data);

View File

@@ -103,8 +103,8 @@ class AttachmentController extends Controller
public function download(Attachment $attachment)
{
if ($this->repository->exists($attachment)) {
$content = $this->repository->getContent($attachment);
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
$content = $this->repository->getContent($attachment);
$quoted = sprintf('"%s"', addcslashes(basename($attachment->filename), '"\\'));
/** @var LaravelResponse $response */
$response = response($content);
@@ -141,7 +141,7 @@ class AttachmentController extends Controller
$this->rememberPreviousUrl('attachments.edit.url');
}
$request->session()->forget('attachments.edit.fromUpdate');
$preFilled = [
$preFilled = [
'notes' => $this->repository->getNoteText($attachment),
];
$request->session()->flash('preFilled', $preFilled);
@@ -173,7 +173,7 @@ class AttachmentController extends Controller
*/
public function update(AttachmentFormRequest $request, Attachment $attachment): RedirectResponse
{
$data = $request->getAttachmentData();
$data = $request->getAttachmentData();
$this->repository->update($attachment, $data);
$request->session()->flash('success', (string)trans('firefly.attachment_updated', ['name' => $attachment->filename]));
@@ -202,7 +202,7 @@ class AttachmentController extends Controller
$content = $this->repository->getContent($attachment);
// prevent XSS by adding a new secure header.
$csp = [
$csp = [
"default-src 'none'",
"object-src 'none'",
"script-src 'none'",

View File

@@ -72,7 +72,7 @@ class ForgotPasswordController extends Controller
// verify if the user is not a demo user. If so, we give him back an error.
/** @var null|User $user */
$user = User::where('email', $request->get('email'))->first();
$user = User::where('email', $request->get('email'))->first();
if (null !== $user && $repository->hasRole($user, 'demo')) {
return back()->withErrors(['email' => (string)trans('firefly.cannot_reset_demo_user')]);
@@ -81,7 +81,7 @@ class ForgotPasswordController extends Controller
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$result = $this->broker()->sendResetLink($request->only('email'));
$result = $this->broker()->sendResetLink($request->only('email'));
if ('passwords.throttled' === $result) {
app('log')->error(sprintf('Cowardly refuse to send a password reset message to user #%d because the reset button has been throttled.', $user->id));
}

View File

@@ -139,8 +139,8 @@ class LoginController extends Controller
*/
public function logout(Request $request)
{
$authGuard = config('firefly.authentication_guard');
$logoutUrl = config('firefly.custom_logout_url');
$authGuard = config('firefly.authentication_guard');
$logoutUrl = config('firefly.custom_logout_url');
if ('remote_user_guard' === $authGuard && '' !== $logoutUrl) {
return redirect($logoutUrl);
}
@@ -176,9 +176,9 @@ class LoginController extends Controller
{
Log::channel('audit')->info('Show login form (1.1).');
$count = \DB::table('users')->count();
$guard = config('auth.defaults.guard');
$title = (string)trans('firefly.login_page_title');
$count = \DB::table('users')->count();
$guard = config('auth.defaults.guard');
$title = (string)trans('firefly.login_page_title');
if (0 === $count && 'web' === $guard) {
return redirect(route('register'));
@@ -198,15 +198,15 @@ class LoginController extends Controller
$allowReset = false;
}
$email = $request->old('email');
$remember = $request->old('remember');
$email = $request->old('email');
$remember = $request->old('remember');
$storeInCookie = config('google2fa.store_in_cookie', false);
$storeInCookie = config('google2fa.store_in_cookie', false);
if (false !== $storeInCookie) {
$cookieName = config('google2fa.cookie_name', 'google2fa_token');
request()->cookies->set($cookieName, 'invalid');
}
$usernameField = $this->username();
$usernameField = $this->username();
return view('auth.login', compact('allowRegistration', 'email', 'remember', 'allowReset', 'title', 'usernameField'));
}

View File

@@ -92,7 +92,7 @@ class RegisterController extends Controller
}
$this->validator($request->all())->validate();
$user = $this->createUser($request->all());
$user = $this->createUser($request->all());
app('log')->info(sprintf('Registered new user %s', $user->email));
event(new RegisteredUser($user));
@@ -136,7 +136,7 @@ class RegisterController extends Controller
return view('error', compact('message'));
}
$email = $request->old('email');
$email = $request->old('email');
return view('auth.register', compact('isDemoSite', 'email', 'pageTitle', 'inviteCode'));
}
@@ -160,7 +160,7 @@ class RegisterController extends Controller
return view('error', compact('message'));
}
$email = $request->old('email');
$email = $request->old('email');
return view('auth.register', compact('isDemoSite', 'email', 'pageTitle'));
}
@@ -178,8 +178,8 @@ class RegisterController extends Controller
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
$singleUserMode = true;
}
$userCount = User::count();
$guard = config('auth.defaults.guard');
$userCount = User::count();
$guard = config('auth.defaults.guard');
if (true === $singleUserMode && $userCount > 0 && 'web' === $guard) {
$allowRegistration = false;
}

View File

@@ -80,7 +80,7 @@ class ResetPasswordController extends Controller
return view('error', compact('message'));
}
$rules = [
$rules = [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed|min:16|secure_password',

View File

@@ -59,8 +59,8 @@ class TwoFactorController extends Controller
public function submitMFA(Request $request)
{
/** @var array $mfaHistory */
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
$mfaCode = (string)$request->get('one_time_password');
$mfaHistory = app('preferences')->get('mfa_history', [])->data;
$mfaCode = (string)$request->get('one_time_password');
// is in history? then refuse to use it.
if ($this->inMFAHistory($mfaCode, $mfaHistory)) {
@@ -171,7 +171,7 @@ class TwoFactorController extends Controller
*/
private function removeFromBackupCodes(string $mfaCode): void
{
$list = app('preferences')->get('mfa_recovery', [])->data;
$list = app('preferences')->get('mfa_recovery', [])->data;
if (!is_array($list)) {
$list = [];
}

View File

@@ -69,10 +69,10 @@ class CreateController extends Controller
*/
public function create(Request $request)
{
$periods = [];
$periods = [];
/** @var array $billPeriods */
$billPeriods = config('firefly.bill_periods');
$billPeriods = config('firefly.bill_periods');
foreach ($billPeriods as $current) {
$periods[$current] = (string)trans('firefly.repeat_freq_'.$current);
}
@@ -93,7 +93,7 @@ class CreateController extends Controller
*/
public function store(BillStoreRequest $request): RedirectResponse
{
$billData = $request->getBillData();
$billData = $request->getBillData();
$billData['active'] = true;
@@ -111,7 +111,7 @@ class CreateController extends Controller
app('preferences')->mark();
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($bill, $files);
}

View File

@@ -69,16 +69,16 @@ class EditController extends Controller
*/
public function edit(Request $request, Bill $bill)
{
$periods = [];
$periods = [];
/** @var array $billPeriods */
$billPeriods = config('firefly.bill_periods');
$billPeriods = config('firefly.bill_periods');
foreach ($billPeriods as $current) {
$periods[$current] = (string)trans('firefly.'.$current);
}
$subTitle = (string)trans('firefly.edit_bill', ['name' => $bill->name]);
$subTitle = (string)trans('firefly.edit_bill', ['name' => $bill->name]);
// put previous url in session if not redirect from store (not "return_to_edit").
if (true !== session('bills.edit.fromUpdate')) {
@@ -92,9 +92,9 @@ class EditController extends Controller
$defaultCurrency = app('amount')->getDefaultCurrency();
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');
$hasOldInput = null !== $request->old('_token');
$preFilled = [
$preFilled = [
'bill_end_date' => $bill->end_date,
'extension_date' => $bill->extension_date,
'notes' => $this->repository->getNoteText($bill),
@@ -123,7 +123,7 @@ class EditController extends Controller
app('preferences')->mark();
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($bill, $files);
}

View File

@@ -71,29 +71,29 @@ class IndexController extends Controller
{
$this->cleanupObjectGroups();
$this->repository->correctOrder();
$start = session('start');
$end = session('end');
$collection = $this->repository->getBills();
$total = $collection->count();
$start = session('start');
$end = session('end');
$collection = $this->repository->getBills();
$total = $collection->count();
$defaultCurrency = app('amount')->getDefaultCurrency();
$parameters = new ParameterBag();
// sub one day from temp start so the last paid date is one day before it should be.
$tempStart = clone $start;
$tempStart = clone $start;
// 2023-06-23 do not sub one day from temp start, fix is in BillTransformer::payDates instead
// $tempStart->subDay();
$parameters->set('start', $tempStart);
$parameters->set('end', $end);
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer = app(BillTransformer::class);
$transformer->setParameters($parameters);
// loop all bills, convert to array and add rules and stuff.
$rules = $this->repository->getRulesForBills($collection);
$rules = $this->repository->getRulesForBills($collection);
// make bill groups:
$bills = [
$bills = [
0 => [ // the index is the order, not the ID.
'object_group_id' => 0,
'object_group_title' => (string)trans('firefly.default_group_title_name'),
@@ -103,8 +103,8 @@ class IndexController extends Controller
/** @var Bill $bill */
foreach ($collection as $bill) {
$array = $transformer->transform($bill);
$groupOrder = (int)$array['object_group_order'];
$array = $transformer->transform($bill);
$groupOrder = (int)$array['object_group_order'];
// make group array if necessary:
$bills[$groupOrder] ??= [
'object_group_id' => $array['object_group_id'],
@@ -127,9 +127,9 @@ class IndexController extends Controller
ksort($bills);
// summarise per currency / per group.
$sums = $this->getSums($bills);
$totals = $this->getTotals($sums);
$today = now()->startOfDay();
$sums = $this->getSums($bills);
$totals = $this->getTotals($sums);
$today = now()->startOfDay();
return view('bills.index', compact('bills', 'sums', 'total', 'totals', 'today'));
}
@@ -168,7 +168,7 @@ class IndexController extends Controller
continue;
}
$currencyId = $bill['currency_id'];
$currencyId = $bill['currency_id'];
$sums[$groupOrder][$currencyId] ??= [
'currency_id' => $currencyId,
'currency_code' => $bill['currency_code'],
@@ -196,7 +196,7 @@ class IndexController extends Controller
private function amountPerPeriod(array $bill, string $range): string
{
$avg = bcdiv(bcadd((string)$bill['amount_min'], (string)$bill['amount_max']), '2');
$avg = bcdiv(bcadd((string)$bill['amount_min'], (string)$bill['amount_max']), '2');
app('log')->debug(sprintf('Amount per period for bill #%d "%s"', $bill['id'], $bill['name']));
app('log')->debug(sprintf('Average is %s', $avg));
@@ -213,7 +213,7 @@ class IndexController extends Controller
app('log')->debug(sprintf('Amount per year is %s (%s * %s / %s)', $yearAmount, $avg, $multiplies[$bill['repeat_freq']], (string)($bill['skip'] + 1)));
// per period:
$division = [
$division = [
'1Y' => '1',
'6M' => '2',
'3M' => '4',
@@ -228,7 +228,7 @@ class IndexController extends Controller
'last90' => '4',
'last365' => '1',
];
$perPeriod = bcdiv($yearAmount, $division[$range]);
$perPeriod = bcdiv($yearAmount, $division[$range]);
app('log')->debug(sprintf('Amount per %s is %s (%s / %s)', $range, $perPeriod, $yearAmount, $division[$range]));
@@ -251,7 +251,7 @@ class IndexController extends Controller
* @var array $entry
*/
foreach ($array as $currencyId => $entry) {
$totals[$currencyId] ??= [
$totals[$currencyId] ??= [
'currency_id' => $currencyId,
'currency_code' => $entry['currency_code'],
'currency_name' => $entry['currency_name'],

View File

@@ -77,13 +77,13 @@ class ShowController extends Controller
*/
public function rescan(Request $request, Bill $bill)
{
$total = 0;
$total = 0;
if (false === $bill->active) {
$request->session()->flash('warning', (string)trans('firefly.cannot_scan_inactive_bill'));
return redirect(route('bills.show', [$bill->id]));
}
$set = $this->repository->getRulesForBill($bill);
$set = $this->repository->getRulesForBill($bill);
if (0 === $set->count()) {
$request->session()->flash('error', (string)trans('firefly.no_rules_for_bill'));
@@ -115,34 +115,34 @@ class ShowController extends Controller
public function show(Request $request, Bill $bill)
{
// add info about rules:
$rules = $this->repository->getRulesForBill($bill);
$subTitle = $bill->name;
$rules = $this->repository->getRulesForBill($bill);
$subTitle = $bill->name;
/** @var Carbon $start */
$start = session('start');
$start = session('start');
/** @var Carbon $end */
$end = session('end');
$year = $start->year;
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$yearAverage = $this->repository->getYearAverage($bill, $start);
$overallAverage = $this->repository->getOverallAverage($bill);
$manager = new Manager();
$end = session('end');
$year = $start->year;
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$yearAverage = $this->repository->getYearAverage($bill, $start);
$overallAverage = $this->repository->getOverallAverage($bill);
$manager = new Manager();
$manager->setSerializer(new DataArraySerializer());
$manager->parseIncludes(['attachments', 'notes']);
// add another period to end, could fix 8163
$range = app('navigation')->getViewRange(true);
$end = app('navigation')->addPeriod($end, $range);
$range = app('navigation')->getViewRange(true);
$end = app('navigation')->addPeriod($end, $range);
// Make a resource out of the data and
$parameters = new ParameterBag();
$parameters = new ParameterBag();
$parameters->set('start', $start);
$parameters->set('end', $end);
/** @var BillTransformer $transformer */
$transformer = app(BillTransformer::class);
$transformer = app(BillTransformer::class);
$transformer->setParameters($parameters);
$resource = new Item($bill, $transformer, 'bill');
@@ -150,16 +150,16 @@ class ShowController extends Controller
$object['data']['currency'] = $bill->transactionCurrency;
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setBill($bill)->setLimit($pageSize)->setPage($page)->withBudgetInformation()
->withCategoryInformation()->withAccountInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('bills.show', [$bill->id]));
// transform any attachments as well.
$collection = $this->repository->getAttachments($bill);
$attachments = new Collection();
$collection = $this->repository->getAttachments($bill);
$attachments = new Collection();
if ($collection->count() > 0) {
/** @var AttachmentTransformer $transformer */

View File

@@ -83,7 +83,7 @@ class BudgetLimitController extends Controller
$budgetLimits = $this->blRepository->getBudgetLimits($budget, $start, $end);
// remove already budgeted currencies with the same date range
$currencies = $collection->filter(
$currencies = $collection->filter(
static function (TransactionCurrency $currency) use ($budgetLimits, $start, $end) {
/** @var BudgetLimit $limit */
foreach ($budgetLimits as $limit) {
@@ -125,14 +125,14 @@ class BudgetLimitController extends Controller
if (null === $currency || null === $budget) {
throw new FireflyException('No valid currency or budget.');
}
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
if (false === $start || false === $end) {
return response()->json([]);
}
$amount = (string)$request->get('amount');
$amount = (string)$request->get('amount');
$start->startOfDay();
$end->startOfDay();
@@ -142,7 +142,7 @@ class BudgetLimitController extends Controller
app('log')->debug(sprintf('Start: %s, end: %s', $start->format('Y-m-d'), $end->format('Y-m-d')));
$limit = $this->blRepository->find($budget, $currency, $start, $end);
$limit = $this->blRepository->find($budget, $currency, $start, $end);
// sanity check on amount:
if (0 === bccomp($amount, '0')) {
@@ -177,15 +177,15 @@ class BudgetLimitController extends Controller
}
if ($request->expectsJson()) {
$array = $limit->toArray();
$array = $limit->toArray();
// add some extra metadata:
$spentArr = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection([$budget]), $currency);
$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string)$this->activeDaysLeft($start, $end);
$spentArr = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection([$budget]), $currency);
$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string)$this->activeDaysLeft($start, $end);
// left per day:
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
// left per day formatted.
$array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']);
@@ -198,7 +198,7 @@ class BudgetLimitController extends Controller
public function update(Request $request, BudgetLimit $budgetLimit): JsonResponse
{
$amount = (string)$request->get('amount');
$amount = (string)$request->get('amount');
if ('' === $amount) {
$amount = '0';
}
@@ -208,7 +208,7 @@ class BudgetLimitController extends Controller
$budgetId = $budgetLimit->budget_id;
$currency = $budgetLimit->transactionCurrency;
$this->blRepository->destroyBudgetLimit($budgetLimit);
$array = [
$array = [
'budget_id' => $budgetId,
'left_formatted' => app('amount')->formatAnything($currency, '0'),
'left_per_day_formatted' => app('amount')->formatAnything($currency, '0'),
@@ -224,23 +224,23 @@ class BudgetLimitController extends Controller
$amount = bcmul($amount, '-1');
}
$limit = $this->blRepository->update($budgetLimit, ['amount' => $amount]);
$limit = $this->blRepository->update($budgetLimit, ['amount' => $amount]);
app('preferences')->mark();
$array = $limit->toArray();
$array = $limit->toArray();
$spentArr = $this->opsRepository->sumExpenses(
$spentArr = $this->opsRepository->sumExpenses(
$limit->start_date,
$limit->end_date,
null,
new Collection([$budgetLimit->budget]),
$budgetLimit->transactionCurrency
);
$array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string)$this->activeDaysLeft($limit->start_date, $limit->end_date);
$array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string)$this->activeDaysLeft($limit->start_date, $limit->end_date);
// left per day:
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
$array['left_per_day'] = bcdiv(bcadd($array['spent'], $array['amount']), $array['days_left']);
// left per day formatted.
$array['amount'] = app('steam')->bcround($limit['amount'], $limit->transactionCurrency->decimal_places);

View File

@@ -68,7 +68,7 @@ class CreateController extends Controller
*/
public function create(Request $request)
{
$hasOldInput = null !== $request->old('_token');
$hasOldInput = null !== $request->old('_token');
// auto budget types
$autoBudgetTypes = [
@@ -87,7 +87,7 @@ class CreateController extends Controller
];
$currency = app('amount')->getDefaultCurrency();
$preFilled = [
$preFilled = [
'auto_budget_period' => $hasOldInput ? (bool)$request->old('auto_budget_period') : 'monthly',
'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id,
];
@@ -99,7 +99,7 @@ class CreateController extends Controller
$this->rememberPreviousUrl('budgets.create.url');
}
$request->session()->forget('budgets.create.fromStore');
$subTitle = (string)trans('firefly.create_new_budget');
$subTitle = (string)trans('firefly.create_new_budget');
return view('budgets.create', compact('subTitle', 'autoBudgetTypes', 'autoBudgetPeriods'));
}
@@ -111,9 +111,9 @@ class CreateController extends Controller
*/
public function store(BudgetFormStoreRequest $request): RedirectResponse
{
$data = $request->getBudgetData();
$data = $request->getBudgetData();
$budget = $this->repository->store($data);
$budget = $this->repository->store($data);
$this->repository->cleanupBudgets();
$request->session()->flash('success', (string)trans('firefly.stored_new_budget', ['name' => $budget->name]));
app('preferences')->mark();
@@ -122,7 +122,7 @@ class CreateController extends Controller
// store attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($budget, $files);
}

View File

@@ -69,8 +69,8 @@ class EditController extends Controller
*/
public function edit(Request $request, Budget $budget)
{
$subTitle = (string)trans('firefly.edit_budget', ['name' => $budget->name]);
$autoBudget = $this->repository->getAutoBudget($budget);
$subTitle = (string)trans('firefly.edit_budget', ['name' => $budget->name]);
$autoBudget = $this->repository->getAutoBudget($budget);
// auto budget types
$autoBudgetTypes = [
@@ -89,14 +89,14 @@ class EditController extends Controller
];
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');
$currency = app('amount')->getDefaultCurrency();
$preFilled = [
$hasOldInput = null !== $request->old('_token');
$currency = app('amount')->getDefaultCurrency();
$preFilled = [
'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active,
'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id,
];
if (null !== $autoBudget) {
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
if (is_array($amount)) {
$amount = '0';
}
@@ -119,7 +119,7 @@ class EditController extends Controller
*/
public function update(BudgetFormUpdateRequest $request, Budget $budget): RedirectResponse
{
$data = $request->getBudgetData();
$data = $request->getBudgetData();
$this->repository->update($budget, $data);
$request->session()->flash('success', (string)trans('firefly.updated_budget', ['name' => $budget->name]));
@@ -132,7 +132,7 @@ class EditController extends Controller
// store new attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($budget, $files);
}

View File

@@ -91,8 +91,8 @@ class IndexController extends Controller
app('log')->debug(sprintf('Start of IndexController::index("%s", "%s")', $start?->format('Y-m-d'), $end?->format('Y-m-d')));
// collect some basic vars:
$range = app('navigation')->getViewRange(true);
$isCustomRange = session('is_custom_range', false);
$range = app('navigation')->getViewRange(true);
$isCustomRange = session('is_custom_range', false);
if (false === $isCustomRange) {
$start ??= session('start', today(config('app.timezone'))->startOfMonth());
$end ??= app('navigation')->endOfPeriod($start, $range);
@@ -104,22 +104,22 @@ class IndexController extends Controller
$end ??= session('end', today(config('app.timezone'))->endOfMonth());
}
$defaultCurrency = app('amount')->getDefaultCurrency();
$currencies = $this->currencyRepository->get();
$budgeted = '0';
$spent = '0';
$defaultCurrency = app('amount')->getDefaultCurrency();
$currencies = $this->currencyRepository->get();
$budgeted = '0';
$spent = '0';
// new period stuff:
$periodTitle = app('navigation')->periodShow($start, $range);
$prevLoop = $this->getPreviousPeriods($start, $range);
$nextLoop = $this->getNextPeriods($start, $range);
$periodTitle = app('navigation')->periodShow($start, $range);
$prevLoop = $this->getPreviousPeriods($start, $range);
$nextLoop = $this->getNextPeriods($start, $range);
// get all available budgets:
$availableBudgets = $this->getAllAvailableBudgets($start, $end);
// get all active budgets:
$budgets = $this->getAllBudgets($start, $end, $currencies, $defaultCurrency);
$sums = $this->getSums($budgets);
$budgets = $this->getAllBudgets($start, $end, $currencies, $defaultCurrency);
$sums = $this->getSums($budgets);
// get budgeted for default currency:
if (0 === count($availableBudgets)) {
@@ -134,7 +134,7 @@ class IndexController extends Controller
$activeDaysLeft = $this->activeDaysLeft($start, $end); // see method description.
// get all inactive budgets, and simply list them:
$inactive = $this->repository->getInactiveBudgets();
$inactive = $this->repository->getInactiveBudgets();
return view(
'budgets.index',
@@ -191,13 +191,13 @@ class IndexController extends Controller
$array['end_date'] = $entry->end_date;
// spent in period:
$spentArr = $this->opsRepository->sumExpenses($entry->start_date, $entry->end_date, null, null, $entry->transactionCurrency);
$array['spent'] = $spentArr[$entry->transaction_currency_id]['sum'] ?? '0';
$spentArr = $this->opsRepository->sumExpenses($entry->start_date, $entry->end_date, null, null, $entry->transactionCurrency);
$array['spent'] = $spentArr[$entry->transaction_currency_id]['sum'] ?? '0';
// budgeted in period:
$budgeted = $this->blRepository->budgeted($entry->start_date, $entry->end_date, $entry->transactionCurrency);
$array['budgeted'] = $budgeted;
$availableBudgets[] = $array;
$budgeted = $this->blRepository->budgeted($entry->start_date, $entry->end_date, $entry->transactionCurrency);
$array['budgeted'] = $budgeted;
$availableBudgets[] = $array;
unset($spentArr);
}
@@ -252,7 +252,7 @@ class IndexController extends Controller
$array['spent'][$currency->id]['currency_decimal_places'] = $currency->decimal_places;
}
}
$budgets[] = $array;
$budgets[] = $array;
}
return $budgets;
@@ -295,7 +295,7 @@ class IndexController extends Controller
// also calculate how much left from budgeted:
$sums['left'][$currencyId]
??= [
??= [
'amount' => '0',
'currency_id' => $budgeted['currency_id'],
'currency_symbol' => $budgeted['currency_symbol'],

View File

@@ -80,8 +80,8 @@ class ShowController extends Controller
// @var Carbon $start
$start ??= session('start');
// @var Carbon $end
$end ??= session('end');
$subTitle = trans(
$end ??= session('end');
$subTitle = trans(
'firefly.without_budget_between',
['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat)]
);
@@ -98,7 +98,7 @@ class ShowController extends Controller
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
->withoutBudget()->withAccountInformation()->withCategoryInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('budgets.no-budget'));
return view('budgets.no-budget', compact('groups', 'subTitle', 'periods', 'start', 'end'));
@@ -111,19 +111,19 @@ class ShowController extends Controller
*/
public function noBudgetAll(Request $request)
{
$subTitle = (string)trans('firefly.all_journals_without_budget');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$end = today(config('app.timezone'));
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$subTitle = (string)trans('firefly.all_journals_without_budget');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$end = today(config('app.timezone'));
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->setTypes([TransactionType::WITHDRAWAL])->setLimit($pageSize)->setPage($page)
->withoutBudget()->withAccountInformation()->withCategoryInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('budgets.no-budget-all'));
return view('budgets.no-budget', compact('groups', 'subTitle', 'start', 'end'));
@@ -147,15 +147,15 @@ class ShowController extends Controller
// collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($allStart, $allEnd)->setBudget($budget)
->withAccountInformation()
->setLimit($pageSize)->setPage($page)->withBudgetInformation()->withCategoryInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('budgets.show', [$budget->id]));
$subTitle = (string)trans('firefly.all_journals_for_budget', ['name' => $budget->name]);
$subTitle = (string)trans('firefly.all_journals_for_budget', ['name' => $budget->name]);
return view('budgets.show', compact('limits', 'attachments', 'budget', 'repetition', 'groups', 'subTitle'));
}
@@ -173,9 +173,9 @@ class ShowController extends Controller
throw new FireflyException('This budget limit is not part of this budget.');
}
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$subTitle = trans(
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$subTitle = trans(
'firefly.budget_in_period',
[
'name' => $budget->name,
@@ -187,12 +187,12 @@ class ShowController extends Controller
// collector:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($budgetLimit->start_date, $budgetLimit->end_date)->withAccountInformation()
->setBudget($budget)->setLimit($pageSize)->setPage($page)->withBudgetInformation()->withCategoryInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('budgets.show.limit', [$budget->id, $budgetLimit->id]));
/** @var Carbon $start */

View File

@@ -95,7 +95,7 @@ class CreateController extends Controller
// store attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($category, $files);
}

View File

@@ -69,7 +69,7 @@ class EditController extends Controller
*/
public function edit(Request $request, Category $category)
{
$subTitle = (string)trans('firefly.edit_category', ['name' => $category->name]);
$subTitle = (string)trans('firefly.edit_category', ['name' => $category->name]);
// put previous url in session if not redirect from store (not "return_to_edit").
if (true !== session('categories.edit.fromUpdate')) {
@@ -91,7 +91,7 @@ class EditController extends Controller
*/
public function update(CategoryFormRequest $request, Category $category)
{
$data = $request->getCategoryData();
$data = $request->getCategoryData();
$this->repository->update($category, $data);
$request->session()->flash('success', (string)trans('firefly.updated_category', ['name' => $category->name]));
@@ -99,7 +99,7 @@ class EditController extends Controller
// store new attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($category, $files);
}

View File

@@ -76,14 +76,14 @@ class NoCategoryController extends Controller
// @var Carbon $start
$start ??= session('start');
// @var Carbon $end
$end ??= session('end');
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$subTitle = trans(
$end ??= session('end');
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$subTitle = trans(
'firefly.without_category_between',
['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat)]
);
$periods = $this->getNoCategoryPeriodOverview($start);
$periods = $this->getNoCategoryPeriodOverview($start);
app('log')->debug(sprintf('Start for noCategory() is %s', $start->format('Y-m-d')));
app('log')->debug(sprintf('End for noCategory() is %s', $end->format('Y-m-d')));
@@ -95,7 +95,7 @@ class NoCategoryController extends Controller
->withAccountInformation()->withBudgetInformation()
->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER])
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('categories.no-category', [$start->format('Y-m-d'), $end->format('Y-m-d')]));
return view('categories.no-category', compact('groups', 'subTitle', 'periods', 'start', 'end'));
@@ -109,16 +109,16 @@ class NoCategoryController extends Controller
public function showAll(Request $request)
{
// default values:
$start = null;
$end = null;
$periods = new Collection();
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$start = null;
$end = null;
$periods = new Collection();
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
app('log')->debug('Start of noCategory()');
$subTitle = (string)trans('firefly.all_journals_without_category');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$end = today(config('app.timezone'));
$subTitle = (string)trans('firefly.all_journals_without_category');
$first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon() : $first->date;
$end = today(config('app.timezone'));
app('log')->debug(sprintf('Start for noCategory() is %s', $start->format('Y-m-d')));
app('log')->debug(sprintf('End for noCategory() is %s', $end->format('Y-m-d')));
@@ -128,7 +128,7 @@ class NoCategoryController extends Controller
->withAccountInformation()->withBudgetInformation()
->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::TRANSFER])
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath(route('categories.no-category.all'));
return view('categories.no-category', compact('groups', 'subTitle', 'periods', 'start', 'end'));

View File

@@ -76,7 +76,7 @@ class ShowController extends Controller
// @var Carbon $start
$start ??= session('start', today(config('app.timezone'))->startOfMonth());
// @var Carbon $end
$end ??= session('end', today(config('app.timezone'))->endOfMonth());
$end ??= session('end', today(config('app.timezone'))->endOfMonth());
$subTitleIcon = 'fa-bookmark';
$page = (int)$request->get('page');
$attachments = $this->repository->getAttachments($category);
@@ -94,13 +94,13 @@ class ShowController extends Controller
);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)
->withAccountInformation()
->setCategory($category)->withBudgetInformation()->withCategoryInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath($path);
return view('categories.show', compact('category', 'attachments', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));
@@ -121,23 +121,23 @@ class ShowController extends Controller
$end = null;
$periods = new Collection();
$subTitle = (string)trans('firefly.all_journals_for_category', ['name' => $category->name]);
$first = $this->repository->firstUseDate($category);
$subTitle = (string)trans('firefly.all_journals_for_category', ['name' => $category->name]);
$first = $this->repository->firstUseDate($category);
/** @var Carbon $start */
$start = $first ?? today(config('app.timezone'));
$end = today(config('app.timezone'));
$path = route('categories.show.all', [$category->id]);
$attachments = $this->repository->getAttachments($category);
$start = $first ?? today(config('app.timezone'));
$end = today(config('app.timezone'));
$path = route('categories.show.all', [$category->id]);
$attachments = $this->repository->getAttachments($category);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)
->withAccountInformation()
->setCategory($category)->withBudgetInformation()->withCategoryInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath($path);
return view('categories.show', compact('category', 'attachments', 'groups', 'periods', 'subTitle', 'subTitleIcon', 'start', 'end'));

View File

@@ -80,11 +80,11 @@ class AccountController extends Controller
public function expenseAccounts(): JsonResponse
{
/** @var Carbon $start */
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$cache = new CacheProperties();
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.account.expense-accounts');
@@ -94,13 +94,13 @@ class AccountController extends Controller
$start->subDay();
// prep some vars:
$currencies = [];
$chartData = [];
$tempData = [];
$currencies = [];
$chartData = [];
$tempData = [];
// grab all accounts and names
$accounts = $this->accountRepository->getAccountsByType([AccountType::EXPENSE]);
$accountNames = $this->extractNames($accounts);
$accounts = $this->accountRepository->getAccountsByType([AccountType::EXPENSE]);
$accountNames = $this->extractNames($accounts);
// grab all balances
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
@@ -111,12 +111,12 @@ class AccountController extends Controller
$accountId = (int)$accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int)$currencyId;
$currencyId = (int)$currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
$diff = bcsub((string)$endAmount, $startAmount);
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
$diff = bcsub((string)$endAmount, $startAmount);
$currencies[$currencyId] ??= $this->currencyRepository->find($currencyId);
if (0 !== bccomp($diff, '0')) {
// store the values in a temporary array.
@@ -131,7 +131,7 @@ class AccountController extends Controller
}
// sort temp array by amount.
$amounts = array_column($tempData, 'diff_float');
$amounts = array_column($tempData, 'diff_float');
array_multisort($amounts, SORT_DESC, $tempData);
// loop all found currencies and build the data array for the chart.
@@ -158,7 +158,7 @@ class AccountController extends Controller
$chartData[$currencyId]['entries'][$name] = $entry['difference'];
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@@ -180,7 +180,7 @@ class AccountController extends Controller
*/
public function expenseBudget(Account $account, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($account->id);
$cache->addProperty($start);
$cache->addProperty($end);
@@ -199,9 +199,9 @@ class AccountController extends Controller
/** @var array $journal */
foreach ($journals as $journal) {
$budgetId = (int)$journal['budget_id'];
$key = sprintf('%d-%d', $budgetId, $journal['currency_id']);
$budgetIds[] = $budgetId;
$budgetId = (int)$journal['budget_id'];
$key = sprintf('%d-%d', $budgetId, $journal['currency_id']);
$budgetIds[] = $budgetId;
if (!array_key_exists($key, $result)) {
$result[$key] = [
'total' => '0',
@@ -214,7 +214,7 @@ class AccountController extends Controller
$result[$key]['total'] = bcadd($journal['amount'], $result[$key]['total']);
}
$names = $this->getBudgetNames($budgetIds);
$names = $this->getBudgetNames($budgetIds);
foreach ($result as $row) {
$budgetId = $row['budget_id'];
@@ -223,7 +223,7 @@ class AccountController extends Controller
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -245,7 +245,7 @@ class AccountController extends Controller
*/
public function expenseCategory(Account $account, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($account->id);
$cache->addProperty($start);
$cache->addProperty($end);
@@ -263,7 +263,7 @@ class AccountController extends Controller
/** @var array $journal */
foreach ($journals as $journal) {
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
if (!array_key_exists($key, $result)) {
$result[$key] = [
'total' => '0',
@@ -275,7 +275,7 @@ class AccountController extends Controller
}
$result[$key]['total'] = bcadd($journal['amount'], $result[$key]['total']);
}
$names = $this->getCategoryNames(array_keys($result));
$names = $this->getCategoryNames(array_keys($result));
foreach ($result as $row) {
$categoryId = $row['category_id'];
@@ -284,7 +284,7 @@ class AccountController extends Controller
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -297,9 +297,9 @@ class AccountController extends Controller
* */
public function frontpage(AccountRepositoryInterface $repository): JsonResponse
{
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$defaultSet = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET])->pluck('id')->toArray();
app('log')->debug('Default set is ', $defaultSet);
$frontPage = app('preferences')->get('frontPageAccounts', $defaultSet);
$frontPageArray = !is_array($frontPage->data) ? [] : $frontPage->data;
@@ -308,7 +308,7 @@ class AccountController extends Controller
app('preferences')->set('frontPageAccounts', $defaultSet);
app('log')->debug('frontpage set is empty!');
}
$accounts = $repository->getAccountsById($frontPageArray);
$accounts = $repository->getAccountsById($frontPageArray);
return response()->json($this->accountBalanceChart($accounts, $start, $end));
}
@@ -329,7 +329,7 @@ class AccountController extends Controller
*/
public function incomeCategory(Account $account, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($account->id);
$cache->addProperty($start);
$cache->addProperty($end);
@@ -349,7 +349,7 @@ class AccountController extends Controller
/** @var array $journal */
foreach ($journals as $journal) {
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
if (!array_key_exists($key, $result)) {
$result[$key] = [
'total' => '0',
@@ -362,14 +362,14 @@ class AccountController extends Controller
$result[$key]['total'] = bcadd($journal['amount'], $result[$key]['total']);
}
$names = $this->getCategoryNames(array_keys($result));
$names = $this->getCategoryNames(array_keys($result));
foreach ($result as $row) {
$categoryId = $row['category_id'];
$name = $names[$categoryId] ?? '(unknown)';
$label = (string)trans('firefly.name_in_currency', ['name' => $name, 'currency' => $row['currency_name']]);
$chartData[$label] = ['amount' => $row['total'], 'currency_symbol' => $row['currency_symbol'], 'currency_code' => $row['currency_code']];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -382,8 +382,8 @@ class AccountController extends Controller
*/
public function period(Account $account, Carbon $start, Carbon $end): JsonResponse
{
$chartData = [];
$cache = new CacheProperties();
$chartData = [];
$cache = new CacheProperties();
$cache->addProperty('chart.account.period');
$cache->addProperty($start);
$cache->addProperty($end);
@@ -403,7 +403,7 @@ class AccountController extends Controller
$chartData[] = $this->periodByCurrency($start, $end, $account, $currency);
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@@ -429,11 +429,11 @@ class AccountController extends Controller
public function revenueAccounts(): JsonResponse
{
/** @var Carbon $start */
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$cache = new CacheProperties();
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.account.revenue-accounts');
@@ -443,13 +443,13 @@ class AccountController extends Controller
$start->subDay();
// prep some vars:
$currencies = [];
$chartData = [];
$tempData = [];
$currencies = [];
$chartData = [];
$tempData = [];
// grab all accounts and names
$accounts = $this->accountRepository->getAccountsByType([AccountType::REVENUE]);
$accountNames = $this->extractNames($accounts);
$accounts = $this->accountRepository->getAccountsByType([AccountType::REVENUE]);
$accountNames = $this->extractNames($accounts);
// grab all balances
$startBalances = app('steam')->balancesPerCurrencyByAccounts($accounts, $start);
@@ -460,12 +460,12 @@ class AccountController extends Controller
$accountId = (int)$accountId;
// loop each expense entry (each entry can be a different currency).
foreach ($expenses as $currencyId => $endAmount) {
$currencyId = (int)$currencyId;
$currencyId = (int)$currencyId;
// see if there is an accompanying start amount.
// grab the difference and find the currency.
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
$diff = bcsub((string)$endAmount, $startAmount);
$startAmount = (string)($startBalances[$accountId][$currencyId] ?? '0');
$diff = bcsub((string)$endAmount, $startAmount);
$currencies[$currencyId] ??= $this->currencyRepository->find($currencyId);
if (0 !== bccomp($diff, '0')) {
// store the values in a temporary array.
@@ -480,7 +480,7 @@ class AccountController extends Controller
}
// sort temp array by amount.
$amounts = array_column($tempData, 'diff_float');
$amounts = array_column($tempData, 'diff_float');
array_multisort($amounts, SORT_ASC, $tempData);
// loop all found currencies and build the data array for the chart.
@@ -507,7 +507,7 @@ class AccountController extends Controller
$chartData[$currencyId]['entries'][$name] = bcmul($entry['difference'], '-1');
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@@ -519,21 +519,21 @@ class AccountController extends Controller
private function periodByCurrency(Carbon $start, Carbon $end, Account $account, TransactionCurrency $currency): array
{
app('log')->debug(sprintf('Now in periodByCurrency("%s", "%s", %s, "%s")', $start->format('Y-m-d'), $end->format('Y-m-d'), $account->id, $currency->code));
$locale = app('steam')->getLocale();
$step = $this->calculateStep($start, $end);
$result = [
$locale = app('steam')->getLocale();
$step = $this->calculateStep($start, $end);
$result = [
'label' => sprintf('%s (%s)', $account->name, $currency->symbol),
'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code,
];
$entries = [];
$current = clone $start;
$entries = [];
$current = clone $start;
app('log')->debug(sprintf('Step is %s', $step));
// fix for issue https://github.com/firefly-iii/firefly-iii/issues/8041
// have to make sure this chart is always based on the balance at the END of the period.
// This period depends on the size of the chart
$current = app('navigation')->endOfX($current, $step, null);
$current = app('navigation')->endOfX($current, $step, null);
app('log')->debug(sprintf('$current date is %s', $current->format('Y-m-d')));
if ('1D' === $step) {
// per day the entire period, balance for every day.
@@ -557,7 +557,7 @@ class AccountController extends Controller
$entries[$label] = $balance;
$current = app('navigation')->addPeriod($current, $step, 0);
// here too, to fix #8041, the data is corrected to the end of the period.
$current = app('navigation')->endOfX($current, $step, null);
$current = app('navigation')->endOfX($current, $step, null);
}
}
$result['entries'] = $entries;

View File

@@ -53,9 +53,9 @@ class BillController extends Controller
*/
public function frontpage(BillRepositoryInterface $repository): JsonResponse
{
$start = session('start', today(config('app.timezone'))->startOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
$cache = new CacheProperties();
$start = session('start', today(config('app.timezone'))->startOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.bill.frontpage');
@@ -93,7 +93,7 @@ class BillController extends Controller
];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -106,17 +106,17 @@ class BillController extends Controller
*/
public function single(Bill $bill): JsonResponse
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty('chart.bill.single');
$cache->addProperty($bill->id);
if ($cache->has()) {
return response()->json($cache->get());
}
$locale = app('steam')->getLocale();
$locale = app('steam')->getLocale();
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$journals = $collector->setBill($bill)->getExtractedJournals();
$collector = app(GroupCollectorInterface::class);
$journals = $collector->setBill($bill)->getExtractedJournals();
// sort the other way around:
usort(
@@ -166,7 +166,7 @@ class BillController extends Controller
if (!array_key_exists($date, $chartData[2]['entries'])) {
$chartData[2]['entries'][$date] = '0';
}
$amount = bcmul($journal['amount'], '-1');
$amount = bcmul($journal['amount'], '-1');
if ($currencyId === $journal['foreign_currency_id']) {
$amount = bcmul($journal['foreign_amount'], '-1');
}
@@ -174,7 +174,7 @@ class BillController extends Controller
$chartData[2]['entries'][$date] = bcadd($chartData[2]['entries'][$date], $amount); // amount of journal
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);

View File

@@ -83,11 +83,11 @@ class BudgetController extends Controller
public function budget(Budget $budget): JsonResponse
{
/** @var Carbon $start */
$start = $this->repository->firstUseDate($budget) ?? session('start', today(config('app.timezone')));
$start = $this->repository->firstUseDate($budget) ?? session('start', today(config('app.timezone')));
/** @var Carbon $end */
$end = session('end', today(config('app.timezone')));
$cache = new CacheProperties();
$end = session('end', today(config('app.timezone')));
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.budget.budget');
@@ -105,19 +105,19 @@ class BudgetController extends Controller
$defaultEntries = [];
while ($end >= $loopStart) {
/** @var Carbon $loopEnd */
$loopEnd = app('navigation')->endOfPeriod($loopStart, $step);
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection);
$label = trim(app('navigation')->periodShow($loopStart, $step));
$loopEnd = app('navigation')->endOfPeriod($loopStart, $step);
$spent = $this->opsRepository->sumExpenses($loopStart, $loopEnd, null, $collection);
$label = trim(app('navigation')->periodShow($loopStart, $step));
foreach ($spent as $row) {
$currencyId = $row['currency_id'];
$currencyId = $row['currency_id'];
$currencies[$currencyId] ??= $row; // don't mind the field 'sum'
// also store this day's sum:
$currencies[$currencyId]['spent'][$label] = $row['sum'];
}
$defaultEntries[$label] = 0;
// set loop start to the next period:
$loopStart = clone $loopEnd;
$loopStart = clone $loopEnd;
$loopStart->addSecond();
}
// loop all currencies:
@@ -133,7 +133,7 @@ class BudgetController extends Controller
$chartData[$currencyId]['entries'][$label] = bcmul($spent, '-1');
}
}
$data = $this->generator->multiSet(array_values($chartData));
$data = $this->generator->multiSet(array_values($chartData));
$cache->store($data);
return response()->json($data);
@@ -150,9 +150,9 @@ class BudgetController extends Controller
throw new FireflyException('This budget limit is not part of this budget.');
}
$start = clone $budgetLimit->start_date;
$end = clone $budgetLimit->end_date;
$cache = new CacheProperties();
$start = clone $budgetLimit->start_date;
$end = clone $budgetLimit->end_date;
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.budget.budget.limit');
@@ -162,11 +162,11 @@ class BudgetController extends Controller
if ($cache->has()) {
return response()->json($cache->get());
}
$locale = app('steam')->getLocale();
$entries = [];
$amount = $budgetLimit->amount;
$budgetCollection = new Collection([$budget]);
$currency = $budgetLimit->transactionCurrency;
$locale = app('steam')->getLocale();
$entries = [];
$amount = $budgetLimit->amount;
$budgetCollection = new Collection([$budget]);
$currency = $budgetLimit->transactionCurrency;
while ($start <= $end) {
$current = clone $start;
$expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $currency);
@@ -177,7 +177,7 @@ class BudgetController extends Controller
$start->addDay();
}
$data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
$data = $this->generator->singleSet((string)trans('firefly.left'), $entries);
// add currency symbol from budget limit:
$data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol;
$data['datasets'][0]['currency_code'] = $budgetLimit->transactionCurrency->code;
@@ -198,8 +198,8 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-asset');
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
@@ -214,14 +214,14 @@ class BudgetController extends Controller
}
$collector->setRange($start, $end);
$collector->setBudget($budget);
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
// group by asset account ID:
foreach ($journals as $journal) {
$key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']);
$result[$key] ??= [
$result[$key] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
@@ -230,7 +230,7 @@ class BudgetController extends Controller
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
}
$names = $this->getAccountNames(array_keys($result));
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$assetId = (int)$parts[0];
@@ -243,7 +243,7 @@ class BudgetController extends Controller
];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -261,8 +261,8 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-category');
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
@@ -276,12 +276,12 @@ class BudgetController extends Controller
}
$collector->setRange($start, $end);
$collector->setBudget($budget)->withCategoryInformation();
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
foreach ($journals as $journal) {
$key = sprintf('%d-%d', $journal['category_id'], $journal['currency_id']);
$result[$key] ??= [
$result[$key] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
@@ -290,7 +290,7 @@ class BudgetController extends Controller
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
}
$names = $this->getCategoryNames(array_keys($result));
$names = $this->getCategoryNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$categoryId = (int)$parts[0];
@@ -301,7 +301,7 @@ class BudgetController extends Controller
'currency_code' => $info['currency_code'],
];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -319,8 +319,8 @@ class BudgetController extends Controller
$cache->addProperty($budget->id);
$cache->addProperty($budgetLimitId);
$cache->addProperty('chart.budget.expense-expense');
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
$start = session('first', today(config('app.timezone'))->startOfYear());
$end = today();
if (null !== $budgetLimit) {
$start = $budgetLimit->start_date;
$end = $budgetLimit->end_date;
@@ -334,14 +334,14 @@ class BudgetController extends Controller
}
$collector->setRange($start, $end);
$collector->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)->withAccountInformation();
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
$journals = $collector->getExtractedJournals();
$result = [];
$chartData = [];
/** @var array $journal */
foreach ($journals as $journal) {
$key = sprintf('%d-%d', $journal['destination_account_id'], $journal['currency_id']);
$result[$key] ??= [
$result[$key] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
@@ -350,7 +350,7 @@ class BudgetController extends Controller
$result[$key]['amount'] = bcadd($journal['amount'], $result[$key]['amount']);
}
$names = $this->getAccountNames(array_keys($result));
$names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId);
$opposingId = (int)$parts[0];
@@ -363,7 +363,7 @@ class BudgetController extends Controller
];
}
$data = $this->generator->multiCurrencyPieChart($chartData);
$data = $this->generator->multiCurrencyPieChart($chartData);
$cache->store($data);
return response()->json($data);
@@ -374,11 +374,11 @@ class BudgetController extends Controller
*/
public function frontpage(): JsonResponse
{
$start = session('start', today(config('app.timezone'))->startOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
$start = session('start', today(config('app.timezone'))->startOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.budget.frontpage');
@@ -391,8 +391,8 @@ class BudgetController extends Controller
$chartGenerator->setStart($start);
$chartGenerator->setEnd($end);
$chartData = $chartGenerator->generate();
$data = $this->generator->multiSet($chartData);
$chartData = $chartGenerator->generate();
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@@ -408,7 +408,7 @@ class BudgetController extends Controller
public function period(Budget $budget, TransactionCurrency $currency, Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($accounts);
@@ -437,11 +437,11 @@ class BudgetController extends Controller
],
];
$currentStart = clone $start;
$currentStart = clone $start;
while ($currentStart <= $end) {
$currentStart = app('navigation')->startOfPeriod($currentStart, $preferredRange);
$title = $currentStart->isoFormat($titleFormat);
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
$currentStart = app('navigation')->startOfPeriod($currentStart, $preferredRange);
$title = $currentStart->isoFormat($titleFormat);
$currentEnd = app('navigation')->endOfPeriod($currentStart, $preferredRange);
// default limit is no limit:
$chartData[0]['entries'][$title] = 0;
@@ -450,7 +450,7 @@ class BudgetController extends Controller
$chartData[1]['entries'][$title] = 0;
// get budget limit in this period for this currency.
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
$limit = $this->blRepository->find($budget, $currency, $currentStart, $currentEnd);
if (null !== $limit) {
$chartData[1]['entries'][$title] = app('steam')->bcround($limit->amount, $currency->decimal_places);
}
@@ -460,11 +460,11 @@ class BudgetController extends Controller
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
$chartData[0]['entries'][$title] = app('steam')->bcround($amount, $currency->decimal_places);
$currentStart = clone $currentEnd;
$currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay();
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@@ -476,7 +476,7 @@ class BudgetController extends Controller
public function periodNoBudget(TransactionCurrency $currency, Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($accounts);
@@ -500,7 +500,7 @@ class BudgetController extends Controller
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
}
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
$data = $this->generator->singleSet((string)trans('firefly.spent'), $chartData);
$cache->store($data);
return response()->json($data);

View File

@@ -76,7 +76,7 @@ class BudgetReportController extends Controller
// loop expenses.
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
$title = sprintf('%s (%s)', $budget['name'], $currency['currency_name']);
$title = sprintf('%s (%s)', $budget['name'], $currency['currency_name']);
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
@@ -89,7 +89,7 @@ class BudgetReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -105,8 +105,8 @@ class BudgetReportController extends Controller
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
@@ -119,7 +119,7 @@ class BudgetReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -136,7 +136,7 @@ class BudgetReportController extends Controller
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$title = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
$title = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
@@ -149,7 +149,7 @@ class BudgetReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -166,7 +166,7 @@ class BudgetReportController extends Controller
// loop expenses.
foreach ($spent as $currency) {
// add things to chart Data for each currency:
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$chartData[$spentKey] ??= [
'label' => sprintf(
'%s (%s)',
@@ -190,7 +190,7 @@ class BudgetReportController extends Controller
}
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
return response()->json($data);
}
@@ -207,7 +207,7 @@ class BudgetReportController extends Controller
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$title = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
$title = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
@@ -220,7 +220,7 @@ class BudgetReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}

View File

@@ -71,7 +71,7 @@ class CategoryController extends Controller
public function all(Category $category): JsonResponse
{
// cache results:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty('chart.category.all');
$cache->addProperty($category->id);
if ($cache->has()) {
@@ -79,11 +79,11 @@ class CategoryController extends Controller
}
/** @var CategoryRepositoryInterface $repository */
$repository = app(CategoryRepositoryInterface::class);
$start = $repository->firstUseDate($category) ?? $this->getDate();
$range = app('navigation')->getViewRange(false);
$start = app('navigation')->startOfPeriod($start, $range);
$end = $this->getDate();
$repository = app(CategoryRepositoryInterface::class);
$start = $repository->firstUseDate($category) ?? $this->getDate();
$range = app('navigation')->getViewRange(false);
$start = app('navigation')->startOfPeriod($start, $range);
$end = $this->getDate();
/** @var WholePeriodChartGenerator $chartGenerator */
$chartGenerator = app(WholePeriodChartGenerator::class);
@@ -100,10 +100,10 @@ class CategoryController extends Controller
*/
public function frontPage(): JsonResponse
{
$start = session('start', today(config('app.timezone'))->startOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
$start = session('start', today(config('app.timezone'))->startOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.category.frontpage');
@@ -134,7 +134,7 @@ class CategoryController extends Controller
if ($cache->has()) {
return response()->json($cache->get());
}
$data = $this->reportPeriodChart($accounts, $start, $end, $category);
$data = $this->reportPeriodChart($accounts, $start, $end, $category);
$cache->store($data);
@@ -155,7 +155,7 @@ class CategoryController extends Controller
if ($cache->has()) {
return response()->json($cache->get());
}
$data = $this->reportPeriodChart($accounts, $start, $end, null);
$data = $this->reportPeriodChart($accounts, $start, $end, null);
$cache->store($data);
@@ -170,14 +170,14 @@ class CategoryController extends Controller
*/
public function specificPeriod(Category $category, Carbon $date): JsonResponse
{
$range = app('navigation')->getViewRange(false);
$start = app('navigation')->startOfPeriod($date, $range);
$end = session()->get('end');
$range = app('navigation')->getViewRange(false);
$start = app('navigation')->startOfPeriod($date, $range);
$end = session()->get('end');
if ($end < $start) {
[$end, $start] = [$start, $end];
}
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($category->id);
@@ -214,8 +214,8 @@ class CategoryController extends Controller
$noCatRepository = app(NoCategoryRepositoryInterface::class);
// this gives us all currencies
$expenses = $noCatRepository->listExpenses($start, $end, $accounts);
$income = $noCatRepository->listIncome($start, $end, $accounts);
$expenses = $noCatRepository->listExpenses($start, $end, $accounts);
$income = $noCatRepository->listIncome($start, $end, $accounts);
}
if (null !== $category) {
@@ -223,9 +223,9 @@ class CategoryController extends Controller
$opsRepository = app(OperationsRepositoryInterface::class);
$categoryId = $category->id;
// this gives us all currencies
$collection = new Collection([$category]);
$expenses = $opsRepository->listExpenses($start, $end, null, $collection);
$income = $opsRepository->listIncome($start, $end, null, $collection);
$collection = new Collection([$category]);
$expenses = $opsRepository->listExpenses($start, $end, null, $collection);
$income = $opsRepository->listIncome($start, $end, null, $collection);
}
$currencies = array_unique(array_merge(array_keys($income), array_keys($expenses)));
$periods = app('navigation')->listOfPeriods($start, $end);
@@ -246,7 +246,7 @@ class CategoryController extends Controller
];
$chartData[$inKey]
= [
= [
'label' => sprintf('%s (%s)', (string)trans('firefly.earned'), $currencyInfo['currency_name']),
'entries' => [],
'type' => 'bar',
@@ -259,7 +259,7 @@ class CategoryController extends Controller
$chartData[$inKey]['entries'][$label] = '0';
}
// loop income and expenses for this category.:
$outSet = $expenses[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
$outSet = $expenses[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
foreach ($outSet['transaction_journals'] as $journal) {
$amount = app('steam')->positive($journal['amount']);
$date = $journal['date']->isoFormat($format);
@@ -268,7 +268,7 @@ class CategoryController extends Controller
$chartData[$outKey]['entries'][$date] = bcadd($amount, $chartData[$outKey]['entries'][$date]);
}
$inSet = $income[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
$inSet = $income[$currencyId]['categories'][$categoryId] ?? ['transaction_journals' => []];
foreach ($inSet['transaction_journals'] as $journal) {
$amount = app('steam')->positive($journal['amount']);
$date = $journal['date']->isoFormat($format);

View File

@@ -77,7 +77,7 @@ class CategoryReportController extends Controller
foreach ($category['transaction_journals'] as $journal) {
$objectName = $journal['budget_name'] ?? trans('firefly.no_budget');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -88,7 +88,7 @@ class CategoryReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -102,7 +102,7 @@ class CategoryReportController extends Controller
foreach ($spent as $currency) {
/** @var array $category */
foreach ($currency['categories'] as $category) {
$title = sprintf('%s (%s)', $category['name'], $currency['currency_name']);
$title = sprintf('%s (%s)', $category['name'], $currency['currency_name']);
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
@@ -115,7 +115,7 @@ class CategoryReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -129,7 +129,7 @@ class CategoryReportController extends Controller
foreach ($earned as $currency) {
/** @var array $category */
foreach ($currency['categories'] as $category) {
$title = sprintf('%s (%s)', $category['name'], $currency['currency_name']);
$title = sprintf('%s (%s)', $category['name'], $currency['currency_name']);
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
@@ -142,7 +142,7 @@ class CategoryReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -159,7 +159,7 @@ class CategoryReportController extends Controller
foreach ($category['transaction_journals'] as $journal) {
$objectName = $journal['destination_account_name'] ?? trans('firefly.empty');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -170,7 +170,7 @@ class CategoryReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -187,7 +187,7 @@ class CategoryReportController extends Controller
foreach ($category['transaction_journals'] as $journal) {
$objectName = $journal['destination_account_name'] ?? trans('firefly.empty');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -198,7 +198,7 @@ class CategoryReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -213,7 +213,7 @@ class CategoryReportController extends Controller
// loop expenses.
foreach ($spent as $currency) {
// add things to chart Data for each currency:
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$chartData[$spentKey] ??= [
'label' => sprintf(
'%s (%s)',
@@ -240,7 +240,7 @@ class CategoryReportController extends Controller
// loop income.
foreach ($earned as $currency) {
// add things to chart Data for each currency:
$spentKey = sprintf('%d-earned', $currency['currency_id']);
$spentKey = sprintf('%d-earned', $currency['currency_id']);
$chartData[$spentKey] ??= [
'label' => sprintf(
'%s (%s)',
@@ -264,7 +264,7 @@ class CategoryReportController extends Controller
}
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
return response()->json($data);
}
@@ -281,7 +281,7 @@ class CategoryReportController extends Controller
foreach ($category['transaction_journals'] as $journal) {
$objectName = $journal['source_account_name'] ?? trans('firefly.empty');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -292,7 +292,7 @@ class CategoryReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -309,7 +309,7 @@ class CategoryReportController extends Controller
foreach ($category['transaction_journals'] as $journal) {
$objectName = $journal['source_account_name'] ?? trans('firefly.empty');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -320,7 +320,7 @@ class CategoryReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}

View File

@@ -75,7 +75,7 @@ class DoubleReportController extends Controller
foreach ($currency['transaction_journals'] as $journal) {
$categoryName = $journal['budget_name'] ?? trans('firefly.no_budget');
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -85,7 +85,7 @@ class DoubleReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -102,7 +102,7 @@ class DoubleReportController extends Controller
foreach ($currency['transaction_journals'] as $journal) {
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -112,7 +112,7 @@ class DoubleReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -129,7 +129,7 @@ class DoubleReportController extends Controller
foreach ($currency['transaction_journals'] as $journal) {
$categoryName = $journal['category_name'] ?? trans('firefly.no_category');
$title = sprintf('%s (%s)', $categoryName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -139,7 +139,7 @@ class DoubleReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -148,11 +148,11 @@ class DoubleReportController extends Controller
{
$chartData = [];
$opposing = $this->repository->expandWithDoubles(new Collection([$account]));
$accounts = $accounts->merge($opposing);
$spent = $this->opsRepository->listExpenses($start, $end, $accounts);
$earned = $this->opsRepository->listIncome($start, $end, $accounts);
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
$opposing = $this->repository->expandWithDoubles(new Collection([$account]));
$accounts = $accounts->merge($opposing);
$spent = $this->opsRepository->listExpenses($start, $end, $accounts);
$earned = $this->opsRepository->listIncome($start, $end, $accounts);
$format = app('navigation')->preferredCarbonLocalizedFormat($start, $end);
// loop expenses.
foreach ($spent as $currency) {
@@ -207,7 +207,7 @@ class DoubleReportController extends Controller
}
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
return response()->json($data);
}
@@ -226,11 +226,11 @@ class DoubleReportController extends Controller
// no tags? also deserves a sport
if (0 === count($journal['tags'])) {
$includedJournals[] = $journalId;
$includedJournals[] = $journalId;
// do something
$tagName = trans('firefly.no_tags');
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -245,11 +245,11 @@ class DoubleReportController extends Controller
if (in_array($journalId, $includedJournals, true)) {
continue;
}
$includedJournals[] = $journalId;
$includedJournals[] = $journalId;
// do something
$tagName = $tag['name'];
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -260,7 +260,7 @@ class DoubleReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -279,11 +279,11 @@ class DoubleReportController extends Controller
// no tags? also deserves a sport
if (0 === count($journal['tags'])) {
$includedJournals[] = $journalId;
$includedJournals[] = $journalId;
// do something
$tagName = trans('firefly.no_tags');
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -298,11 +298,11 @@ class DoubleReportController extends Controller
if (in_array($journalId, $includedJournals, true)) {
continue;
}
$includedJournals[] = $journalId;
$includedJournals[] = $journalId;
// do something
$tagName = $tag['name'];
$title = sprintf('%s (%s)', $tagName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -313,7 +313,7 @@ class DoubleReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}

View File

@@ -72,7 +72,7 @@ class ExpenseReportController extends Controller
*/
public function mainChart(Collection $accounts, Collection $expense, Carbon $start, Carbon $end): JsonResponse
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty('chart.expense.report.main');
$cache->addProperty($accounts);
$cache->addProperty($expense);
@@ -100,14 +100,14 @@ class ExpenseReportController extends Controller
foreach ($combined as $name => $combination) {
// first is always expense account:
/** @var Account $exp */
$exp = $combination->first();
$chartData[$exp->id.'-in'] = [
$exp = $combination->first();
$chartData[$exp->id.'-in'] = [
'label' => sprintf('%s (%s)', $name, (string) trans('firefly.income')),
'type' => 'bar',
'yAxisID' => 'y-axis-0',
'entries' => [],
];
$chartData[$exp->id.'-out'] = [
$chartData[$exp->id.'-out'] = [
'label' => sprintf('%s (%s)', $name, (string) trans('firefly.expenses')),
'type' => 'bar',
'yAxisID' => 'y-axis-0',
@@ -134,30 +134,30 @@ class ExpenseReportController extends Controller
$sumOfExpense = [];
while ($currentStart < $end) {
$currentEnd = clone $currentStart;
$currentEnd = $currentEnd->{$function}(); // @phpstan-ignore-line
$currentEnd = clone $currentStart;
$currentEnd = $currentEnd->{$function}(); // @phpstan-ignore-line
// get expenses grouped by opposing name:
$expenses = $this->groupByName($this->getExpensesForOpposing($accounts, $all, $currentStart, $currentEnd));
$income = $this->groupByName($this->getIncomeForOpposing($accounts, $all, $currentStart, $currentEnd));
$label = $currentStart->isoFormat($format);
$expenses = $this->groupByName($this->getExpensesForOpposing($accounts, $all, $currentStart, $currentEnd));
$income = $this->groupByName($this->getIncomeForOpposing($accounts, $all, $currentStart, $currentEnd));
$label = $currentStart->isoFormat($format);
foreach ($combined as $name => $combination) {
// first is always expense account:
/** @var Account $exp */
$exp = $combination->first();
$labelIn = $exp->id.'-in';
$labelOut = $exp->id.'-out';
$labelSumIn = $exp->id.'-total-in';
$labelSumOut = $exp->id.'-total-out';
$currentIncome = bcmul($income[$name] ?? '0', '-1');
$currentExpense = $expenses[$name] ?? '0';
$exp = $combination->first();
$labelIn = $exp->id.'-in';
$labelOut = $exp->id.'-out';
$labelSumIn = $exp->id.'-total-in';
$labelSumOut = $exp->id.'-total-out';
$currentIncome = bcmul($income[$name] ?? '0', '-1');
$currentExpense = $expenses[$name] ?? '0';
// add to sum:
$sumOfIncome[$exp->id] ??= '0';
$sumOfExpense[$exp->id] ??= '0';
$sumOfIncome[$exp->id] = bcadd($sumOfIncome[$exp->id], $currentIncome);
$sumOfExpense[$exp->id] = bcadd($sumOfExpense[$exp->id], $currentExpense);
$sumOfIncome[$exp->id] = bcadd($sumOfIncome[$exp->id], $currentIncome);
$sumOfExpense[$exp->id] = bcadd($sumOfExpense[$exp->id], $currentExpense);
// add to chart:
$chartData[$labelIn]['entries'][$label] = $currentIncome;
@@ -172,7 +172,7 @@ class ExpenseReportController extends Controller
$currentStart->startOfDay();
}
// remove all empty entries to prevent cluttering:
$newSet = [];
$newSet = [];
foreach ($chartData as $key => $entry) {
// TODO not sure, this is a bad comparison.
if (array_sum($entry['entries']) > 0) {
@@ -182,7 +182,7 @@ class ExpenseReportController extends Controller
if (0 === count($newSet)) {
$newSet = $chartData;
}
$data = $this->generator->multiSet($newSet);
$data = $this->generator->multiSet($newSet);
$cache->store($data);
return response()->json($data);

View File

@@ -64,30 +64,30 @@ class PiggyBankController extends Controller
public function history(PiggyBankRepositoryInterface $repository, PiggyBank $piggyBank): JsonResponse
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty('chart.piggy-bank.history');
$cache->addProperty($piggyBank->id);
if ($cache->has()) {
return response()->json($cache->get());
}
$set = $repository->getEvents($piggyBank);
$set = $set->reverse();
$locale = app('steam')->getLocale();
$set = $repository->getEvents($piggyBank);
$set = $set->reverse();
$locale = app('steam')->getLocale();
// get first event or start date of piggy bank or today
$startDate = $piggyBank->startdate ?? today(config('app.timezone'));
$startDate = $piggyBank->startdate ?? today(config('app.timezone'));
/** @var null|PiggyBankEvent $firstEvent */
$firstEvent = $set->first();
$firstDate = null === $firstEvent ? new Carbon() : $firstEvent->date;
$firstEvent = $set->first();
$firstDate = null === $firstEvent ? new Carbon() : $firstEvent->date;
// which ever is older:
$oldest = $startDate->lt($firstDate) ? $startDate : $firstDate;
$today = today(config('app.timezone'));
$oldest = $startDate->lt($firstDate) ? $startDate : $firstDate;
$today = today(config('app.timezone'));
// depending on diff, do something with range of chart.
$step = $this->calculateStep($oldest, $today);
$step = $this->calculateStep($oldest, $today);
$chartData = [];
$chartData = [];
while ($oldest <= $today) {
$filtered = $set->filter(
static function (PiggyBankEvent $event) use ($oldest) {
@@ -108,7 +108,7 @@ class PiggyBankController extends Controller
$finalLabel = $today->isoFormat((string)trans('config.month_and_day_js', [], $locale));
$chartData[$finalLabel] = $finalSum;
$data = $this->generator->singleSet($piggyBank->name, $chartData);
$data = $this->generator->singleSet($piggyBank->name, $chartData);
$cache->store($data);
return response()->json($data);

View File

@@ -64,7 +64,7 @@ class ReportController extends Controller
public function netWorth(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty('chart.report.net-worth');
$cache->addProperty($start);
$cache->addProperty(implode(',', $accounts->pluck('id')->toArray()));
@@ -72,12 +72,12 @@ class ReportController extends Controller
if ($cache->has()) {
return response()->json($cache->get());
}
$locale = app('steam')->getLocale();
$current = clone $start;
$chartData = [];
$locale = app('steam')->getLocale();
$current = clone $start;
$chartData = [];
/** @var NetWorthInterface $helper */
$helper = app(NetWorthInterface::class);
$helper = app(NetWorthInterface::class);
$helper->setUser(auth()->user());
// filter accounts on having the preference for being included.
@@ -107,8 +107,8 @@ class ReportController extends Controller
if ('native' === $key) {
continue;
}
$currencyId = $netWorthItem['currency_id'];
$label = $current->isoFormat((string) trans('config.month_and_day_js', [], $locale));
$currencyId = $netWorthItem['currency_id'];
$label = $current->isoFormat((string) trans('config.month_and_day_js', [], $locale));
if (!array_key_exists($currencyId, $chartData)) {
$chartData[$currencyId] = [
'label' => 'Net worth in '.$netWorthItem['currency_name'],
@@ -123,7 +123,7 @@ class ReportController extends Controller
$current->addDays(7);
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);
@@ -137,7 +137,7 @@ class ReportController extends Controller
public function operations(Collection $accounts, Carbon $start, Carbon $end): JsonResponse
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty('chart.report.operations');
$cache->addProperty($start);
$cache->addProperty($accounts);
@@ -154,17 +154,17 @@ class ReportController extends Controller
$chartData = [];
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->withAccountInformation();
$collector->setXorAccounts($accounts);
$collector->setTypes([TransactionType::WITHDRAWAL, TransactionType::DEPOSIT, TransactionType::RECONCILIATION, TransactionType::TRANSFER]);
$journals = $collector->getExtractedJournals();
$journals = $collector->getExtractedJournals();
// loop. group by currency and by period.
/** @var array $journal */
foreach ($journals as $journal) {
$period = $journal['date']->format($format);
$currencyId = (int) $journal['currency_id'];
$period = $journal['date']->format($format);
$currencyId = (int) $journal['currency_id'];
$data[$currencyId] ??= [
'currency_id' => $currencyId,
'currency_symbol' => $journal['currency_symbol'],
@@ -178,8 +178,8 @@ class ReportController extends Controller
'earned' => '0',
];
// in our outgoing?
$key = 'spent';
$amount = app('steam')->positive($journal['amount']);
$key = 'spent';
$amount = app('steam')->positive($journal['amount']);
// deposit = incoming
// transfer or reconcile or opening balance, and these accounts are the destination.
@@ -192,7 +192,7 @@ class ReportController extends Controller
// loop this data, make chart bars for each currency:
/** @var array $currency */
foreach ($data as $currency) {
$income = [
$income = [
'label' => (string) trans('firefly.box_earned_in_currency', ['currency' => $currency['currency_name']]),
'type' => 'bar',
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
@@ -201,7 +201,7 @@ class ReportController extends Controller
'currency_code' => $currency['currency_code'],
'entries' => [],
];
$expense = [
$expense = [
'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]),
'type' => 'bar',
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
@@ -220,11 +220,11 @@ class ReportController extends Controller
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
}
$chartData[] = $income;
$chartData[] = $expense;
$chartData[] = $income;
$chartData[] = $expense;
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
$cache->store($data);
return response()->json($data);

View File

@@ -77,7 +77,7 @@ class TagReportController extends Controller
foreach ($tag['transaction_journals'] as $journal) {
$objectName = $journal['budget_name'] ?? trans('firefly.no_budget');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -88,7 +88,7 @@ class TagReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -105,7 +105,7 @@ class TagReportController extends Controller
foreach ($tag['transaction_journals'] as $journal) {
$objectName = $journal['category_name'] ?? trans('firefly.no_category');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -116,7 +116,7 @@ class TagReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -133,7 +133,7 @@ class TagReportController extends Controller
foreach ($tag['transaction_journals'] as $journal) {
$objectName = $journal['category_name'] ?? trans('firefly.no_category');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -144,7 +144,7 @@ class TagReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -161,7 +161,7 @@ class TagReportController extends Controller
foreach ($tag['transaction_journals'] as $journal) {
$objectName = $journal['destination_account_name'] ?? trans('firefly.empty');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -172,7 +172,7 @@ class TagReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -189,7 +189,7 @@ class TagReportController extends Controller
foreach ($tag['transaction_journals'] as $journal) {
$objectName = $journal['destination_account_name'] ?? trans('firefly.empty');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -200,7 +200,7 @@ class TagReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -218,7 +218,7 @@ class TagReportController extends Controller
// loop expenses.
foreach ($spent as $currency) {
// add things to chart Data for each currency:
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$spentKey = sprintf('%d-spent', $currency['currency_id']);
$chartData[$spentKey] ??= [
'label' => sprintf(
'%s (%s)',
@@ -245,7 +245,7 @@ class TagReportController extends Controller
// loop income.
foreach ($earned as $currency) {
// add things to chart Data for each currency:
$spentKey = sprintf('%d-earned', $currency['currency_id']);
$spentKey = sprintf('%d-earned', $currency['currency_id']);
$chartData[$spentKey] ??= [
'label' => sprintf(
'%s (%s)',
@@ -269,7 +269,7 @@ class TagReportController extends Controller
}
}
$data = $this->generator->multiSet($chartData);
$data = $this->generator->multiSet($chartData);
return response()->json($data);
}
@@ -286,7 +286,7 @@ class TagReportController extends Controller
foreach ($tag['transaction_journals'] as $journal) {
$objectName = $journal['source_account_name'] ?? trans('firefly.empty');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -297,7 +297,7 @@ class TagReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -314,7 +314,7 @@ class TagReportController extends Controller
foreach ($tag['transaction_journals'] as $journal) {
$objectName = $journal['source_account_name'] ?? trans('firefly.empty');
$title = sprintf('%s (%s)', $objectName, $currency['currency_name']);
$result[$title] ??= [
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
'currency_code' => $currency['currency_code'],
@@ -325,7 +325,7 @@ class TagReportController extends Controller
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -339,7 +339,7 @@ class TagReportController extends Controller
foreach ($spent as $currency) {
/** @var array $tag */
foreach ($currency['tags'] as $tag) {
$title = sprintf('%s (%s)', $tag['name'], $currency['currency_name']);
$title = sprintf('%s (%s)', $tag['name'], $currency['currency_name']);
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
@@ -351,7 +351,7 @@ class TagReportController extends Controller
}
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}
@@ -365,7 +365,7 @@ class TagReportController extends Controller
foreach ($earned as $currency) {
/** @var array $tag */
foreach ($currency['tags'] as $tag) {
$title = sprintf('%s (%s)', $tag['name'], $currency['currency_name']);
$title = sprintf('%s (%s)', $tag['name'], $currency['currency_name']);
$result[$title] ??= [
'amount' => '0',
'currency_symbol' => $currency['currency_symbol'],
@@ -377,7 +377,7 @@ class TagReportController extends Controller
}
}
}
$data = $this->generator->multiCurrencyPieChart($result);
$data = $this->generator->multiCurrencyPieChart($result);
return response()->json($data);
}

View File

@@ -54,7 +54,7 @@ class TransactionController extends Controller
*/
public function budgets(Carbon $start, Carbon $end)
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('chart.transactions.budgets');
@@ -68,22 +68,22 @@ class TransactionController extends Controller
$collector->withBudgetInformation();
$collector->setTypes([TransactionType::WITHDRAWAL]);
$result = $collector->getExtractedJournals();
$data = [];
$result = $collector->getExtractedJournals();
$data = [];
// group by category.
/** @var array $journal */
foreach ($result as $journal) {
$budget = $journal['budget_name'] ?? (string)trans('firefly.no_budget');
$title = sprintf('%s (%s)', $budget, $journal['currency_symbol']);
$data[$title] ??= [
$data[$title] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
];
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['amount']);
}
$chart = $this->generator->multiCurrencyPieChart($data);
$chart = $this->generator->multiCurrencyPieChart($data);
$cache->store($chart);
return response()->json($chart);
@@ -94,7 +94,7 @@ class TransactionController extends Controller
*/
public function categories(string $objectType, Carbon $start, Carbon $end)
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($objectType);
@@ -118,22 +118,22 @@ class TransactionController extends Controller
$collector->setTypes([TransactionType::TRANSFER]);
}
$result = $collector->getExtractedJournals();
$data = [];
$result = $collector->getExtractedJournals();
$data = [];
// group by category.
/** @var array $journal */
foreach ($result as $journal) {
$category = $journal['category_name'] ?? (string)trans('firefly.no_category');
$title = sprintf('%s (%s)', $category, $journal['currency_symbol']);
$data[$title] ??= [
$data[$title] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
];
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['amount']);
}
$chart = $this->generator->multiCurrencyPieChart($data);
$chart = $this->generator->multiCurrencyPieChart($data);
$cache->store($chart);
return response()->json($chart);
@@ -144,7 +144,7 @@ class TransactionController extends Controller
*/
public function destinationAccounts(string $objectType, Carbon $start, Carbon $end)
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($objectType);
@@ -168,22 +168,22 @@ class TransactionController extends Controller
$collector->setTypes([TransactionType::TRANSFER]);
}
$result = $collector->getExtractedJournals();
$data = [];
$result = $collector->getExtractedJournals();
$data = [];
// group by category.
/** @var array $journal */
foreach ($result as $journal) {
$name = $journal['destination_account_name'];
$title = sprintf('%s (%s)', $name, $journal['currency_symbol']);
$data[$title] ??= [
$data[$title] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
];
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['amount']);
}
$chart = $this->generator->multiCurrencyPieChart($data);
$chart = $this->generator->multiCurrencyPieChart($data);
$cache->store($chart);
return response()->json($chart);
@@ -194,7 +194,7 @@ class TransactionController extends Controller
*/
public function sourceAccounts(string $objectType, Carbon $start, Carbon $end)
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($objectType);
@@ -218,22 +218,22 @@ class TransactionController extends Controller
$collector->setTypes([TransactionType::TRANSFER]);
}
$result = $collector->getExtractedJournals();
$data = [];
$result = $collector->getExtractedJournals();
$data = [];
// group by category.
/** @var array $journal */
foreach ($result as $journal) {
$name = $journal['source_account_name'];
$title = sprintf('%s (%s)', $name, $journal['currency_symbol']);
$data[$title] ??= [
$data[$title] ??= [
'amount' => '0',
'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'],
];
$data[$title]['amount'] = bcadd($data[$title]['amount'], $journal['amount']);
}
$chart = $this->generator->multiCurrencyPieChart($data);
$chart = $this->generator->multiCurrencyPieChart($data);
$cache->store($chart);
return response()->json($chart);

View File

@@ -66,25 +66,25 @@ abstract class Controller extends BaseController
app('view')->share('featuringWebhooks', true === config('firefly.feature_flags.webhooks') && true === config('firefly.allow_webhooks'));
// share custom auth guard info.
$authGuard = config('firefly.authentication_guard');
$logoutUrl = config('firefly.custom_logout_url');
$authGuard = config('firefly.authentication_guard');
$logoutUrl = config('firefly.custom_logout_url');
app('view')->share('authGuard', $authGuard);
app('view')->share('logoutUrl', $logoutUrl);
// upload size
$maxFileSize = app('steam')->phpBytes((string)ini_get('upload_max_filesize'));
$maxPostSize = app('steam')->phpBytes((string)ini_get('post_max_size'));
$uploadSize = min($maxFileSize, $maxPostSize);
$maxFileSize = app('steam')->phpBytes((string)ini_get('upload_max_filesize'));
$maxPostSize = app('steam')->phpBytes((string)ini_get('post_max_size'));
$uploadSize = min($maxFileSize, $maxPostSize);
app('view')->share('uploadSize', $uploadSize);
// share is alpha, is beta
$isAlpha = false;
$isAlpha = false;
if (str_contains(config('firefly.version'), 'alpha')) {
$isAlpha = true;
}
$isBeta = false;
$isBeta = false;
if (str_contains(config('firefly.version'), 'beta')) {
$isBeta = true;
}
@@ -94,7 +94,7 @@ abstract class Controller extends BaseController
$this->middleware(
function ($request, $next): mixed {
$locale = app('steam')->getLocale();
$locale = app('steam')->getLocale();
// translations for specific strings:
$this->monthFormat = (string)trans('config.month_js', [], $locale);
$this->monthAndDayFormat = (string)trans('config.month_and_day_js', [], $locale);

View File

@@ -116,14 +116,14 @@ class DebugController extends Controller
*/
public function index()
{
$table = $this->generateTable();
$table = str_replace(["\n", "\t", ' '], '', $table);
$now = now(config('app.timezone'))->format('Y-m-d H:i:s');
$table = $this->generateTable();
$table = str_replace(["\n", "\t", ' '], '', $table);
$now = now(config('app.timezone'))->format('Y-m-d H:i:s');
// get latest log file:
$logger = Log::driver();
$logger = Log::driver();
// PHPstan doesn't recognize the method because of its polymorphic nature.
$handlers = $logger->getHandlers(); // @phpstan-ignore-line
$handlers = $logger->getHandlers(); // @phpstan-ignore-line
$logContent = '';
foreach ($handlers as $handler) {
if ($handler instanceof RotatingFileHandler) {
@@ -227,7 +227,7 @@ class DebugController extends Controller
private function getAppInfo(): array
{
$userGuard = config('auth.defaults.guard');
$userGuard = config('auth.defaults.guard');
$config = app('fireflyconfig')->get('last_rt_job', 0);
$lastTime = (int)$config->data;
@@ -252,24 +252,24 @@ class DebugController extends Controller
// any of the cron jobs will do, they always run at the same time.
// but this job is the oldest, so the biggest chance it ran once
'last_cronjob' => $lastCronjob,
'last_cronjob_ago' => $lastCronjobAgo,
'last_cronjob' => $lastCronjob,
'last_cronjob_ago' => $lastCronjobAgo,
];
}
private function getuserInfo(): array
{
$userFlags = $this->getUserFlags();
$userFlags = $this->getUserFlags();
// user info
$userAgent = request()->header('user-agent');
$userAgent = request()->header('user-agent');
// set languages, see what happens:
$original = setlocale(LC_ALL, '0');
$localeAttempts = [];
$parts = app('steam')->getLocaleArray(app('steam')->getLocale());
foreach ($parts as $code) {
$code = trim($code);
$code = trim($code);
app('log')->debug(sprintf('Trying to set %s', $code));
$result = setlocale(LC_ALL, $code);
$localeAttempts[$code] = $result === $code;
@@ -293,7 +293,7 @@ class DebugController extends Controller
$flags = [];
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
// has liabilities
if ($user->accounts()->accountTypeIn([AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE])->count() > 0) {
@@ -306,7 +306,7 @@ class DebugController extends Controller
}
// has stored reconciliations
$type = TransactionType::whereType(TransactionType::RECONCILIATION)->first();
$type = TransactionType::whereType(TransactionType::RECONCILIATION)->first();
if ($user->transactionJournals()->where('transaction_type_id', $type->id)->count() > 0) {
$flags[] = '<span title="Has reconciled">:ledger:</span>';
}

View File

@@ -74,19 +74,19 @@ class IndexController extends Controller
// get first transaction in DB:
$firstDate = today(config('app.timezone'));
$firstDate->subYear();
$journal = $this->journalRepository->firstNull();
$journal = $this->journalRepository->firstNull();
if (null !== $journal) {
$firstDate = clone $journal->date;
}
$generator->setStart($firstDate);
$result = $generator->export();
$result = $generator->export();
$name = sprintf('%s_transaction_export.csv', date('Y_m_d'));
$quoted = sprintf('"%s"', addcslashes($name, '"\\'));
$name = sprintf('%s_transaction_export.csv', date('Y_m_d'));
$quoted = sprintf('"%s"', addcslashes($name, '"\\'));
// headers for CSV file.
/** @var LaravelResponse $response */
$response = response($result['transactions']);
$response = response($result['transactions']);
$response
->header('Content-Description', 'File Transfer')
->header('Content-Type', 'text/x-csv')

View File

@@ -61,8 +61,8 @@ class HomeController extends Controller
*/
public function dateRange(Request $request): JsonResponse
{
$stringStart = '';
$stringEnd = '';
$stringStart = '';
$stringEnd = '';
try {
$stringStart = e((string)$request->get('start'));
@@ -97,7 +97,7 @@ class HomeController extends Controller
app('log')->debug('Range is now marked as "custom".');
}
$diff = $start->diffInDays($end) + 1;
$diff = $start->diffInDays($end) + 1;
if ($diff > 50) {
$request->session()->flash('warning', (string)trans('firefly.warning_much_data', ['days' => $diff]));
@@ -120,8 +120,8 @@ class HomeController extends Controller
*/
public function index(AccountRepositoryInterface $repository): mixed
{
$types = config('firefly.accountTypesByIdentifier.asset');
$count = $repository->count($types);
$types = config('firefly.accountTypesByIdentifier.asset');
$count = $repository->count($types);
Log::channel('audit')->info('User visits homepage.');
if (0 === $count) {
@@ -136,15 +136,15 @@ class HomeController extends Controller
}
/** @var Carbon $start */
$start = session('start', today(config('app.timezone'))->startOfMonth());
$start = session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = session('end', today(config('app.timezone'))->endOfMonth());
$accounts = $repository->getAccountsById($frontPageArray);
$today = today(config('app.timezone'));
$end = session('end', today(config('app.timezone'))->endOfMonth());
$accounts = $repository->getAccountsById($frontPageArray);
$today = today(config('app.timezone'));
// sort frontpage accounts by order
$accounts = $accounts->sortBy('order');
$accounts = $accounts->sortBy('order');
app('log')->debug('Frontpage accounts are ', $frontPageArray);
@@ -154,14 +154,14 @@ class HomeController extends Controller
// collect groups for each transaction.
foreach ($accounts as $account) {
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->withAccountInformation()->setRange($start, $end)->setLimit(10)->setPage(1);
$set = $collector->getExtractedJournals();
$transactions[] = ['transactions' => $set, 'account' => $account];
}
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
event(new RequestedVersionCheckStatus($user));
return view('index', compact('count', 'subTitle', 'transactions', 'billCount', 'start', 'end', 'today'));

View File

@@ -95,8 +95,8 @@ class JavascriptController extends Controller
* */
public function variables(Request $request, AccountRepositoryInterface $repository): Response
{
$account = $repository->find((int)$request->get('account'));
$currency = app('amount')->getDefaultCurrency();
$account = $repository->find((int)$request->get('account'));
$currency = app('amount')->getDefaultCurrency();
if (null !== $account) {
$currency = $repository->getAccountCurrency($account) ?? $currency;
}
@@ -108,7 +108,7 @@ class JavascriptController extends Controller
$dateRange = $this->getDateRangeConfig();
$uid = substr(hash('sha256', sprintf('%s-%s-%s', (string)config('app.key'), auth()->user()->id, auth()->user()->email)), 0, 12);
$data = [
$data = [
'currencyCode' => $currency->code,
'currencySymbol' => $currency->symbol,
'accountingLocaleInfo' => $accounting,
@@ -135,9 +135,9 @@ class JavascriptController extends Controller
$start = clone session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$end = clone session('end', today(config('app.timezone'))->endOfMonth());
$data = [
$data = [
'start' => $start->format('Y-m-d'),
'end' => $end->format('Y-m-d'),
];

View File

@@ -56,22 +56,22 @@ class BoxController extends Controller
app('log')->debug('Now in available()');
/** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class);
$opsRepository = app(OperationsRepositoryInterface::class);
/** @var AvailableBudgetRepositoryInterface $abRepository */
$abRepository = app(AvailableBudgetRepositoryInterface::class);
$abRepository = app(AvailableBudgetRepositoryInterface::class);
$abRepository->cleanup();
/** @var Carbon $start */
$start = session('start', today(config('app.timezone'))->startOfMonth());
$start = session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = session('end', today(config('app.timezone'))->endOfMonth());
$today = today(config('app.timezone'));
$display = 2; // see method docs.
$boxTitle = (string)trans('firefly.spent');
$end = session('end', today(config('app.timezone'))->endOfMonth());
$today = today(config('app.timezone'));
$display = 2; // see method docs.
$boxTitle = (string)trans('firefly.spent');
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty($today);
@@ -82,11 +82,11 @@ class BoxController extends Controller
$leftPerDayAmount = '0';
$leftToSpendAmount = '0';
$currency = app('amount')->getDefaultCurrency();
$currency = app('amount')->getDefaultCurrency();
app('log')->debug(sprintf('Default currency is %s', $currency->code));
$availableBudgets = $abRepository->getAvailableBudgetsByExactDate($start, $end);
$availableBudgets = $abRepository->getAvailableBudgetsByExactDate($start, $end);
app('log')->debug(sprintf('Found %d available budget(s)', $availableBudgets->count()));
$availableBudgets = $availableBudgets->filter(
$availableBudgets = $availableBudgets->filter(
static function (AvailableBudget $availableBudget) use ($currency) { // @phpstan-ignore-line
if ($availableBudget->transaction_currency_id === $currency->id) {
app('log')->debug(sprintf(
@@ -106,13 +106,13 @@ class BoxController extends Controller
app('log')->debug(sprintf('Filtered back to %d available budgets', $availableBudgets->count()));
// spent in this period, in budgets, for default currency.
// also calculate spent per day.
$spent = $opsRepository->sumExpenses($start, $end, null, null, $currency);
$spentAmount = $spent[$currency->id]['sum'] ?? '0';
$spent = $opsRepository->sumExpenses($start, $end, null, null, $currency);
$spentAmount = $spent[$currency->id]['sum'] ?? '0';
app('log')->debug(sprintf('Spent for default currency for all budgets in this period: %s', $spentAmount));
$days = $today->between($start, $end) ? $today->diffInDays($start) + 1 : $end->diffInDays($start) + 1;
$days = $today->between($start, $end) ? $today->diffInDays($start) + 1 : $end->diffInDays($start) + 1;
app('log')->debug(sprintf('Number of days left: %d', $days));
$spentPerDay = bcdiv($spentAmount, (string)$days);
$spentPerDay = bcdiv($spentAmount, (string)$days);
app('log')->debug(sprintf('Available to spend per day: %s', $spentPerDay));
if ($availableBudgets->count() > 0) {
$display = 0; // assume user overspent
@@ -132,7 +132,7 @@ class BoxController extends Controller
}
}
$return = [
$return = [
'display' => $display,
'spent_total' => app('amount')->formatAnything($currency, $spentAmount, false),
'spent_per_day' => app('amount')->formatAnything($currency, $spentPerDay, false),
@@ -155,11 +155,11 @@ class BoxController extends Controller
{
// Cache result, return cache if present.
/** @var Carbon $start */
$start = session('start', today(config('app.timezone'))->startOfMonth());
$start = session('start', today(config('app.timezone'))->startOfMonth());
/** @var Carbon $end */
$end = session('end', today(config('app.timezone'))->endOfMonth());
$cache = new CacheProperties();
$end = session('end', today(config('app.timezone'))->endOfMonth());
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('box-balance');
@@ -167,10 +167,10 @@ class BoxController extends Controller
return response()->json($cache->get());
}
// prep some arrays:
$incomes = [];
$expenses = [];
$sums = [];
$currency = app('amount')->getDefaultCurrency();
$incomes = [];
$expenses = [];
$sums = [];
$currency = app('amount')->getDefaultCurrency();
// collect income of user:
/** @var GroupCollectorInterface $collector */
@@ -178,7 +178,7 @@ class BoxController extends Controller
$collector->setRange($start, $end)
->setTypes([TransactionType::DEPOSIT])
;
$set = $collector->getExtractedJournals();
$set = $collector->getExtractedJournals();
/** @var array $journal */
foreach ($set as $journal) {
@@ -196,7 +196,7 @@ class BoxController extends Controller
$collector->setRange($start, $end)
->setTypes([TransactionType::WITHDRAWAL])
;
$set = $collector->getExtractedJournals();
$set = $collector->getExtractedJournals();
/** @var array $journal */
foreach ($set as $journal) {
@@ -208,7 +208,7 @@ class BoxController extends Controller
}
// format amounts:
$keys = array_keys($sums);
$keys = array_keys($sums);
foreach ($keys as $currencyId) {
$currency = $repository->find($currencyId);
$sums[$currencyId] = app('amount')->formatAnything($currency, $sums[$currencyId], false);
@@ -222,7 +222,7 @@ class BoxController extends Controller
$expenses[$currency->id] = app('amount')->formatAnything($currency, '0', false);
}
$response = [
$response = [
'incomes' => $incomes,
'expenses' => $expenses,
'sums' => $sums,
@@ -239,7 +239,7 @@ class BoxController extends Controller
*/
public function netWorth(): JsonResponse
{
$date = today(config('app.timezone'))->endOfDay();
$date = today(config('app.timezone'))->endOfDay();
// start and end in the future? use $end
if ($this->notInSessionRange($date)) {
@@ -248,7 +248,7 @@ class BoxController extends Controller
}
/** @var NetWorthInterface $netWorthHelper */
$netWorthHelper = app(NetWorthInterface::class);
$netWorthHelper = app(NetWorthInterface::class);
$netWorthHelper->setUser(auth()->user());
/** @var AccountRepositoryInterface $accountRepository */
@@ -259,7 +259,7 @@ class BoxController extends Controller
app('log')->debug(sprintf('Found %d accounts.', $allAccounts->count()));
// filter list on preference of being included.
$filtered = $allAccounts->filter(
$filtered = $allAccounts->filter(
static function (Account $account) use ($accountRepository) {
$includeNetWorth = $accountRepository->getMetaValue($account, 'include_net_worth');
$result = null === $includeNetWorth ? true : '1' === $includeNetWorth;
@@ -271,15 +271,15 @@ class BoxController extends Controller
}
);
$netWorthSet = $netWorthHelper->byAccounts($filtered, $date);
$return = [];
$netWorthSet = $netWorthHelper->byAccounts($filtered, $date);
$return = [];
foreach ($netWorthSet as $key => $data) {
if ('native' === $key) {
continue;
}
$return[$data['currency_id']] = app('amount')->formatFlat($data['currency_symbol'], $data['currency_decimal_places'], $data['balance'], false);
}
$return = [
$return = [
'net_worths' => array_values($return),
];

View File

@@ -49,12 +49,12 @@ class FrontpageController extends Controller
$amount = $repository->getCurrentAmount($piggyBank);
if (1 === bccomp($amount, '0')) {
// percentage!
$pct = 0;
$pct = 0;
if (0 !== bccomp($piggyBank->targetamount, '0')) {
$pct = (int)bcmul(bcdiv($amount, $piggyBank->targetamount), '100');
}
$entry = [
$entry = [
'id' => $piggyBank->id,
'name' => $piggyBank->name,
'amount' => $amount,

View File

@@ -41,7 +41,7 @@ class IntroController extends Controller
public function getIntroSteps(string $route, string $specificPage = null): JsonResponse
{
app('log')->debug(sprintf('getIntroSteps for route "%s" and page "%s"', $route, $specificPage));
$specificPage ??= '';
$specificPage ??= '';
$steps = $this->getBasicSteps($route);
$specificSteps = $this->getSpecificSteps($route, $specificPage);
if (0 === count($specificSteps)) {
@@ -55,8 +55,8 @@ class IntroController extends Controller
// remove last step:
array_pop($steps);
// merge arrays and add last step again
$steps = array_merge($steps, $specificSteps);
$steps[] = $lastStep;
$steps = array_merge($steps, $specificSteps);
$steps[] = $lastStep;
}
if (!$this->hasOutroStep($route)) {
$steps = array_merge($steps, $specificSteps);
@@ -77,7 +77,7 @@ class IntroController extends Controller
return false;
}
$hasStep = array_key_exists('outro', $elements);
$hasStep = array_key_exists('outro', $elements);
app('log')->debug('Elements is array', $elements);
app('log')->debug('Keys is', array_keys($elements));
@@ -94,8 +94,8 @@ class IntroController extends Controller
public function postEnable(string $route, string $specialPage = null): JsonResponse
{
$specialPage ??= '';
$route = str_replace('.', '_', $route);
$key = 'shown_demo_'.$route;
$route = str_replace('.', '_', $route);
$key = 'shown_demo_'.$route;
if ('' !== $specialPage) {
$key .= '_'.$specialPage;
}
@@ -114,7 +114,7 @@ class IntroController extends Controller
public function postFinished(string $route, string $specialPage = null): JsonResponse
{
$specialPage ??= '';
$key = 'shown_demo_'.$route;
$key = 'shown_demo_'.$route;
if ('' !== $specialPage) {
$key .= '_'.$specialPage;
}

View File

@@ -92,13 +92,13 @@ class ReconcileController extends Controller
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setJournalIds($selectedIds);
$journals = $collector->getExtractedJournals();
$journals = $collector->getExtractedJournals();
}
// Collect all journals already reconciled
if (count($clearedIds) > 0) {
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setJournalIds($clearedIds);
$clearedJournals = $collector->getExtractedJournals();
}
@@ -118,11 +118,11 @@ class ReconcileController extends Controller
$clearedAmount = $this->processJournal($account, $accountCurrency, $journal, $clearedAmount);
}
}
$difference = bcadd(bcadd(bcsub($startBalance, $endBalance), $clearedAmount), $amount);
$diffCompare = bccomp($difference, '0');
$countCleared = count($clearedJournals);
$difference = bcadd(bcadd(bcsub($startBalance, $endBalance), $clearedAmount), $amount);
$diffCompare = bccomp($difference, '0');
$countCleared = count($clearedJournals);
$reconSum = bcadd(bcadd($startBalance, $amount), $clearedAmount);
$reconSum = bcadd(bcadd($startBalance, $amount), $clearedAmount);
try {
$view = view(
@@ -151,7 +151,7 @@ class ReconcileController extends Controller
throw new FireflyException($view, 0, $e);
}
$return = [
$return = [
'post_url' => $route,
'html' => $view,
];
@@ -174,29 +174,29 @@ class ReconcileController extends Controller
if ($end->lt($start)) {
[$end, $start] = [$start, $end];
}
$startDate = clone $start;
$startDate = clone $start;
$startDate->subDay();
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = app('steam')->bcround(app('steam')->balance($account, $end), $currency->decimal_places);
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$startBalance = app('steam')->bcround(app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = app('steam')->bcround(app('steam')->balance($account, $end), $currency->decimal_places);
// get the transactions
$selectionStart = clone $start;
$selectionStart->subDays(3);
$selectionEnd = clone $end;
$selectionEnd = clone $end;
$selectionEnd->addDays(3);
// grab transactions:
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))
->setRange($selectionStart, $selectionEnd)
->withBudgetInformation()->withCategoryInformation()->withAccountInformation()
;
$array = $collector->getExtractedJournals();
$journals = $this->processTransactions($account, $array);
$array = $collector->getExtractedJournals();
$journals = $this->processTransactions($account, $array);
try {
$html = view(
@@ -216,7 +216,7 @@ class ReconcileController extends Controller
private function processJournal(Account $account, TransactionCurrency $currency, array $journal, string $amount): string
{
$toAdd = '0';
$toAdd = '0';
app('log')->debug(sprintf('User submitted %s #%d: "%s"', $journal['transaction_type_type'], $journal['transaction_journal_id'], $journal['description']));
// not much magic below we need to cover using tests.
@@ -254,7 +254,7 @@ class ReconcileController extends Controller
/** @var array $journal */
foreach ($array as $journal) {
$inverse = false;
$inverse = false;
if (TransactionType::DEPOSIT === $journal['transaction_type_type']) {
$inverse = true;

View File

@@ -66,20 +66,20 @@ class RecurrenceController extends Controller
*/
public function events(Request $request): JsonResponse
{
$occurrences = [];
$return = [];
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
$firstDate = Carbon::createFromFormat('Y-m-d', $request->get('first_date'));
$endDate = '' !== (string) $request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null;
$endsAt = (string) $request->get('ends');
$repetitionType = explode(',', $request->get('type'))[0];
$repetitions = (int) $request->get('reps');
$weekend = (int) $request->get('weekend');
$repetitionMoment = '';
$skip = (int) $request->get('skip');
$skip = $skip < 1 || $skip > 31 ? 1 : $skip;
$weekend = $weekend < 1 || $weekend > 4 ? 1 : $weekend;
$occurrences = [];
$return = [];
$start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
$firstDate = Carbon::createFromFormat('Y-m-d', $request->get('first_date'));
$endDate = '' !== (string) $request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null;
$endsAt = (string) $request->get('ends');
$repetitionType = explode(',', $request->get('type'))[0];
$repetitions = (int) $request->get('reps');
$weekend = (int) $request->get('weekend');
$repetitionMoment = '';
$skip = (int) $request->get('skip');
$skip = $skip < 1 || $skip > 31 ? 1 : $skip;
$weekend = $weekend < 1 || $weekend > 4 ? 1 : $weekend;
if (false === $start || false === $end || false === $firstDate || false === $endDate) {
return response()->json();
@@ -92,7 +92,7 @@ class RecurrenceController extends Controller
return response()->json();
}
// if $firstDate is beyond start, use that one:
$actualStart = clone $firstDate;
$actualStart = clone $firstDate;
if ('weekly' === $repetitionType || 'monthly' === $repetitionType) {
$repetitionMoment = explode(',', $request->get('type'))[1] ?? '1';
@@ -147,8 +147,8 @@ class RecurrenceController extends Controller
*/
public function suggest(Request $request): JsonResponse
{
$string = '' === (string) $request->get('date') ? date('Y-m-d') : (string) $request->get('date');
$today = today(config('app.timezone'))->startOfDay();
$string = '' === (string) $request->get('date') ? date('Y-m-d') : (string) $request->get('date');
$today = today(config('app.timezone'))->startOfDay();
try {
$date = Carbon::createFromFormat('Y-m-d', $string, config('app.timezone'));
@@ -165,7 +165,7 @@ class RecurrenceController extends Controller
app('log')->debug(sprintf('date = %s, today = %s. date > today? %s', $date->toAtomString(), $today->toAtomString(), var_export($date > $today, true)));
app('log')->debug(sprintf('past = true? %s', var_export('true' === (string) $request->get('past'), true)));
$result = [];
$result = [];
if ($date > $today || 'true' === (string) $request->get('past')) {
app('log')->debug('Will fill dropdown.');
$weekly = sprintf('weekly,%s', $date->dayOfWeekIso);

View File

@@ -69,8 +69,8 @@ class NewUserController extends Controller
app('view')->share('title', (string)trans('firefly.welcome'));
app('view')->share('mainTitleIcon', 'fa-fire');
$types = config('firefly.accountTypesByIdentifier.asset');
$count = $this->repository->count($types);
$types = config('firefly.accountTypesByIdentifier.asset');
$count = $this->repository->count($types);
$languages = [];
@@ -90,7 +90,7 @@ class NewUserController extends Controller
*/
public function submit(NewUserFormRequest $request, CurrencyRepositoryInterface $currencyRepository)
{
$language = $request->convertString('language');
$language = $request->convertString('language');
if (!array_key_exists($language, config('firefly.languages'))) {
$language = 'en_US';
}
@@ -98,7 +98,7 @@ class NewUserController extends Controller
// set language preference:
app('preferences')->set('language', $language);
// Store currency preference from input:
$currency = $currencyRepository->find((int)$request->input('amount_currency_id_bank_balance'));
$currency = $currencyRepository->find((int)$request->input('amount_currency_id_bank_balance'));
// if is null, set to EUR:
if (null === $currency) {
@@ -114,7 +114,7 @@ class NewUserController extends Controller
$currencyRepository->makeDefault($currency);
// store frontpage preferences:
$accounts = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray();
$accounts = $this->repository->getAccountsByType([AccountType::ASSET])->pluck('id')->toArray();
app('preferences')->set('frontPageAccounts', $accounts);
// mark.

View File

@@ -91,7 +91,7 @@ class EditController extends Controller
session()->flash('success', (string)trans('firefly.updated_object_group', ['title' => $objectGroup->title]));
app('preferences')->mark();
$redirect = redirect($this->getPreviousUrl('object-groups.edit.url'));
$redirect = redirect($this->getPreviousUrl('object-groups.edit.url'));
if (1 === (int)$request->get('return_to_edit')) {
session()->put('object-groups.edit.fromUpdate', true);

View File

@@ -76,7 +76,7 @@ class AmountController extends Controller
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
$maxAmount = min($leftOnAccount, $leftToSave);
}
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
return view('piggy-banks.add', compact('piggyBank', 'maxAmount', 'currency'));
}
@@ -98,7 +98,7 @@ class AmountController extends Controller
$leftToSave = bcsub($piggyBank->targetamount, $savedSoFar);
$maxAmount = min($leftOnAccount, $leftToSave);
}
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
$currency = $this->accountRepos->getAccountCurrency($piggyBank->account) ?? app('amount')->getDefaultCurrency();
return view('piggy-banks.add-mobile', compact('piggyBank', 'maxAmount', 'currency'));
}
@@ -164,7 +164,7 @@ class AmountController extends Controller
return redirect(route('piggy-banks.index'));
}
$amount = (string)$request->get('amount');
$amount = (string)$request->get('amount');
session()->flash(
'error',

View File

@@ -91,7 +91,7 @@ class CreateController extends Controller
*/
public function store(PiggyBankStoreRequest $request)
{
$data = $request->getPiggyBankData();
$data = $request->getPiggyBankData();
if (null === $data['startdate']) {
$data['startdate'] = today(config('app.timezone'));
}
@@ -102,7 +102,7 @@ class CreateController extends Controller
// store attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($piggyBank, $files);
}
@@ -114,7 +114,7 @@ class CreateController extends Controller
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
}
$redirect = redirect($this->getPreviousUrl('piggy-banks.create.url'));
$redirect = redirect($this->getPreviousUrl('piggy-banks.create.url'));
if (1 === (int)$request->get('create_another')) {
session()->put('piggy-banks.create.fromStore', true);

View File

@@ -77,14 +77,14 @@ class EditController extends Controller
$subTitleIcon = 'fa-pencil';
$note = $piggyBank->notes()->first();
// Flash some data to fill the form.
$targetDate = $piggyBank->targetdate?->format('Y-m-d');
$startDate = $piggyBank->startdate?->format('Y-m-d');
$currency = $this->accountRepository->getAccountCurrency($piggyBank->account);
$targetDate = $piggyBank->targetdate?->format('Y-m-d');
$startDate = $piggyBank->startdate?->format('Y-m-d');
$currency = $this->accountRepository->getAccountCurrency($piggyBank->account);
if (null === $currency) {
$currency = app('amount')->getDefaultCurrency();
}
$preFilled = [
$preFilled = [
'name' => $piggyBank->name,
'account_id' => $piggyBank->account_id,
'targetamount' => app('steam')->bcround($piggyBank->targetamount, $currency->decimal_places),
@@ -122,7 +122,7 @@ class EditController extends Controller
// store new attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($piggyBank, $files);
}
@@ -134,7 +134,7 @@ class EditController extends Controller
if (count($this->attachments->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
}
$redirect = redirect($this->getPreviousUrl('piggy-banks.edit.url'));
$redirect = redirect($this->getPreviousUrl('piggy-banks.edit.url'));
if (1 === (int)$request->get('return_to_edit')) {
session()->put('piggy-banks.edit.fromUpdate', true);

View File

@@ -79,21 +79,21 @@ class IndexController extends Controller
{
$this->cleanupObjectGroups();
$this->piggyRepos->resetOrder();
$collection = $this->piggyRepos->getPiggyBanks();
$accounts = [];
$collection = $this->piggyRepos->getPiggyBanks();
$accounts = [];
/** @var Carbon $end */
$end = session('end', today(config('app.timezone'))->endOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
// transform piggies using the transformer:
$parameters = new ParameterBag();
$parameters = new ParameterBag();
$parameters->set('end', $end);
// make piggy bank groups:
$piggyBanks = [];
$piggyBanks = [];
/** @var PiggyBankTransformer $transformer */
$transformer = app(PiggyBankTransformer::class);
$transformer = app(PiggyBankTransformer::class);
$transformer->setParameters(new ParameterBag());
/** @var AccountTransformer $accountTransformer */
@@ -102,8 +102,8 @@ class IndexController extends Controller
/** @var PiggyBank $piggy */
foreach ($collection as $piggy) {
$array = $transformer->transform($piggy);
$groupOrder = (int)$array['object_group_order'];
$array = $transformer->transform($piggy);
$groupOrder = (int)$array['object_group_order'];
// make group array if necessary:
$piggyBanks[$groupOrder] ??= [
'object_group_id' => $array['object_group_id'] ?? 0,
@@ -111,12 +111,12 @@ class IndexController extends Controller
'piggy_banks' => [],
];
$account = $accountTransformer->transform($piggy->account);
$accountId = (int)$account['id'];
$array['attachments'] = $this->piggyRepos->getAttachments($piggy);
$account = $accountTransformer->transform($piggy->account);
$accountId = (int)$account['id'];
$array['attachments'] = $this->piggyRepos->getAttachments($piggy);
if (!array_key_exists($accountId, $accounts)) {
// create new:
$accounts[$accountId] = $account;
$accounts[$accountId] = $account;
// add some interesting details:
$accounts[$accountId]['left'] = $accounts[$accountId]['current_balance'];
@@ -134,7 +134,7 @@ class IndexController extends Controller
$piggyBanks[$groupOrder]['piggy_banks'][] = $array;
}
// do a bunch of summaries.
$piggyBanks = $this->makeSums($piggyBanks);
$piggyBanks = $this->makeSums($piggyBanks);
ksort($piggyBanks);
@@ -165,7 +165,7 @@ class IndexController extends Controller
foreach ($piggyBanks as $groupOrder => $group) {
$groupId = $group['object_group_id'];
foreach ($group['piggy_banks'] as $piggy) {
$currencyId = $piggy['currency_id'];
$currencyId = $piggy['currency_id'];
$sums[$groupId][$currencyId] ??= [
'target' => '0',
'saved' => '0',

View File

@@ -70,9 +70,9 @@ class ShowController extends Controller
public function show(PiggyBank $piggyBank)
{
/** @var Carbon $end */
$end = session('end', today(config('app.timezone'))->endOfMonth());
$end = session('end', today(config('app.timezone'))->endOfMonth());
// transform piggies using the transformer:
$parameters = new ParameterBag();
$parameters = new ParameterBag();
$parameters->set('end', $end);
/** @var PiggyBankTransformer $transformer */

View File

@@ -49,7 +49,7 @@ class ReportController extends Controller
app('view')->share('start', $attributes['startDate']);
app('view')->share('end', $attributes['endDate']);
$html = match ($attributes['location']) {
$html = match ($attributes['location']) {
default => sprintf('Firefly III cannot handle "%s"-popups.', $attributes['location']),
'budget-spent-amount' => $this->budgetSpentAmount($attributes),
'expense-entry' => $this->expenseEntry($attributes),

View File

@@ -66,14 +66,14 @@ class PreferencesController extends Controller
*/
public function index(AccountRepositoryInterface $repository)
{
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$isDocker = env('IS_DOCKER', false);
$groupedAccounts = [];
$accounts = $repository->getAccountsByType([AccountType::DEFAULT, AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);
$isDocker = env('IS_DOCKER', false);
$groupedAccounts = [];
/** @var Account $account */
foreach ($accounts as $account) {
$type = $account->accountType->type;
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
$type = $account->accountType->type;
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
if (in_array($type, [AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN], true)) {
$role = sprintf('opt_group_l_%s', $type);
@@ -94,23 +94,23 @@ class PreferencesController extends Controller
if (!is_array($frontPageAccounts)) {
$frontPageAccounts = $accountIds;
}
$language = app('steam')->getLanguage();
$languages = config('firefly.languages');
$locale = app('preferences')->get('locale', config('firefly.default_locale', 'equal'))->data;
$listPageSize = app('preferences')->get('listPageSize', 50)->data;
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
$slackUrl = app('preferences')->get('slack_webhook_url', '')->data;
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
$fiscalYearStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
$language = app('steam')->getLanguage();
$languages = config('firefly.languages');
$locale = app('preferences')->get('locale', config('firefly.default_locale', 'equal'))->data;
$listPageSize = app('preferences')->get('listPageSize', 50)->data;
$darkMode = app('preferences')->get('darkMode', 'browser')->data;
$slackUrl = app('preferences')->get('slack_webhook_url', '')->data;
$customFiscalYear = app('preferences')->get('customFiscalYear', 0)->data;
$fiscalYearStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
if (is_array($fiscalYearStartStr)) {
$fiscalYearStartStr = '01-01';
}
$fiscalYearStart = sprintf('%s-%s', date('Y'), (string) $fiscalYearStartStr);
$tjOptionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
$availableDarkModes = config('firefly.available_dark_modes');
$fiscalYearStart = sprintf('%s-%s', date('Y'), (string) $fiscalYearStartStr);
$tjOptionalFields = app('preferences')->get('transaction_journal_optional_fields', [])->data;
$availableDarkModes = config('firefly.available_dark_modes');
// notification preferences (single value for each):
$notifications = [];
$notifications = [];
foreach (config('firefly.available_notifications') as $notification) {
$notifications[$notification] = app('preferences')->get(sprintf('notification_%s', $notification), true)->data;
}
@@ -125,7 +125,7 @@ class PreferencesController extends Controller
app('log')->error($e->getMessage());
$locales = [];
}
$locales = ['equal' => (string) trans('firefly.equal_to_language')] + $locales;
$locales = ['equal' => (string) trans('firefly.equal_to_language')] + $locales;
// an important fallback is that the frontPageAccount array gets refilled automatically
// when it turns up empty.
if (0 === count($frontPageAccounts)) {
@@ -164,7 +164,7 @@ class PreferencesController extends Controller
}
// extract notifications:
$all = $request->all();
$all = $request->all();
foreach (config('firefly.available_notifications') as $option) {
$key = sprintf('notification_%s', $option);
if (array_key_exists($key, $all)) {
@@ -194,8 +194,8 @@ class PreferencesController extends Controller
}
// custom fiscal year
$customFiscalYear = 1 === (int) $request->get('customFiscalYear');
$string = strtotime((string) $request->get('fiscalYearStart'));
$customFiscalYear = 1 === (int) $request->get('customFiscalYear');
$string = strtotime((string) $request->get('fiscalYearStart'));
if (false !== $string) {
$fiscalYearStart = date('m-d', $string);
app('preferences')->set('customFiscalYear', $customFiscalYear);
@@ -204,15 +204,15 @@ class PreferencesController extends Controller
// save page size:
app('preferences')->set('listPageSize', 50);
$listPageSize = (int) $request->get('listPageSize');
$listPageSize = (int) $request->get('listPageSize');
if ($listPageSize > 0 && $listPageSize < 1337) {
app('preferences')->set('listPageSize', $listPageSize);
}
// language:
/** @var Preference $currentLang */
$currentLang = app('preferences')->get('language', 'en_US');
$lang = $request->get('language');
$currentLang = app('preferences')->get('language', 'en_US');
$lang = $request->get('language');
if (array_key_exists($lang, config('firefly.languages'))) {
app('preferences')->set('language', $lang);
}
@@ -229,8 +229,8 @@ class PreferencesController extends Controller
}
// optional fields for transactions:
$setOptions = $request->get('tj') ?? [];
$optionalTj = [
$setOptions = $request->get('tj') ?? [];
$optionalTj = [
'interest_date' => array_key_exists('interest_date', $setOptions),
'book_date' => array_key_exists('book_date', $setOptions),
'process_date' => array_key_exists('process_date', $setOptions),
@@ -247,7 +247,7 @@ class PreferencesController extends Controller
app('preferences')->set('transaction_journal_optional_fields', $optionalTj);
// dark mode
$darkMode = $request->get('darkMode') ?? 'browser';
$darkMode = $request->get('darkMode') ?? 'browser';
if (in_array($darkMode, config('firefly.available_dark_modes'), true)) {
app('preferences')->set('darkMode', $darkMode);
}

View File

@@ -119,7 +119,7 @@ class ProfileController extends Controller
}
// generate recovery codes if not in session:
$recoveryCodes = '';
$recoveryCodes = '';
if (null === $codesPreference) {
// generate codes + store + flash:
@@ -136,9 +136,9 @@ class ProfileController extends Controller
$recoveryCodes = [];
}
$codes = implode("\r\n", $recoveryCodes);
$codes = implode("\r\n", $recoveryCodes);
$image = \Google2FA::getQRCodeInline($domain, auth()->user()->email, (string)$secret);
$image = \Google2FA::getQRCodeInline($domain, auth()->user()->email, (string)$secret);
return view('profile.code', compact('image', 'secret', 'codes'));
}
@@ -209,7 +209,7 @@ class ProfileController extends Controller
$repository = app(UserRepositoryInterface::class);
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
app('preferences')->delete('temp-mfa-secret');
app('preferences')->delete('temp-mfa-codes');
@@ -276,7 +276,7 @@ class ProfileController extends Controller
$repository->createPersonalAccessClient(null, config('app.name').' Personal Access Client', 'http://localhost');
}
$accessToken = app('preferences')->get('access_token');
$accessToken = app('preferences')->get('access_token');
if (null === $accessToken) {
$token = $user->generateAccessToken();
$accessToken = app('preferences')->set('access_token', $token);
@@ -407,7 +407,7 @@ class ProfileController extends Controller
$new = $request->get('new_password');
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
try {
$this->validatePassword($user, $current, $new);
@@ -459,7 +459,7 @@ class ProfileController extends Controller
}
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
@@ -480,7 +480,7 @@ class ProfileController extends Controller
app('preferences')->mark();
// also save the code so replay attack is prevented.
$mfaCode = $request->get('code');
$mfaCode = $request->get('code');
$this->addToMFAHistory($mfaCode);
// save backup codes in preferences:
@@ -592,8 +592,8 @@ class ProfileController extends Controller
}
// find preference with this token value.
$set = app('preferences')->findByName('email_change_undo_token');
$user = null;
$set = app('preferences')->findByName('email_change_undo_token');
$user = null;
/** @var Preference $preference */
foreach ($set as $preference) {
@@ -606,7 +606,7 @@ class ProfileController extends Controller
}
// found user.which email address to return to?
$set = app('preferences')->beginsWith($user, 'previous_email_');
$set = app('preferences')->beginsWith($user, 'previous_email_');
/** @var string $match */
$match = null;

View File

@@ -93,19 +93,19 @@ class CreateController extends Controller
$this->rememberPreviousUrl('recurring.create.url');
}
$request->session()->forget('recurring.create.fromStore');
$repetitionEnds = [
$repetitionEnds = [
'forever' => (string)trans('firefly.repeat_forever'),
'until_date' => (string)trans('firefly.repeat_until_date'),
'times' => (string)trans('firefly.repeat_times'),
];
$weekendResponses = [
$weekendResponses = [
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'),
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'),
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'),
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'),
];
$hasOldInput = null !== $request->old('_token'); // flash some data
$preFilled = [
$hasOldInput = null !== $request->old('_token'); // flash some data
$preFilled = [
'first_date' => $tomorrow->format('Y-m-d'),
'transaction_type' => $hasOldInput ? $request->old('transaction_type') : 'withdrawal',
'active' => $hasOldInput ? (bool)$request->old('active') : true,
@@ -138,12 +138,12 @@ class CreateController extends Controller
$this->rememberPreviousUrl('recurring.create.url');
}
$request->session()->forget('recurring.create.fromStore');
$repetitionEnds = [
$repetitionEnds = [
'forever' => (string)trans('firefly.repeat_forever'),
'until_date' => (string)trans('firefly.repeat_until_date'),
'times' => (string)trans('firefly.repeat_times'),
];
$weekendResponses = [
$weekendResponses = [
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'),
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'),
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'),
@@ -151,18 +151,18 @@ class CreateController extends Controller
];
// fill prefilled with journal info
$type = strtolower($journal->transactionType->type);
$type = strtolower($journal->transactionType->type);
/** @var Transaction $source */
$source = $journal->transactions()->where('amount', '<', 0)->first();
$source = $journal->transactions()->where('amount', '<', 0)->first();
/** @var Transaction $dest */
$dest = $journal->transactions()->where('amount', '>', 0)->first();
$category = null !== $journal->categories()->first() ? $journal->categories()->first()->name : '';
$budget = null !== $journal->budgets()->first() ? $journal->budgets()->first()->id : 0;
$bill = null !== $journal->bill ? $journal->bill->id : 0;
$hasOldInput = null !== $request->old('_token'); // flash some data
$preFilled = [];
$dest = $journal->transactions()->where('amount', '>', 0)->first();
$category = null !== $journal->categories()->first() ? $journal->categories()->first()->name : '';
$budget = null !== $journal->budgets()->first() ? $journal->budgets()->first()->id : 0;
$bill = null !== $journal->bill ? $journal->bill->id : 0;
$hasOldInput = null !== $request->old('_token'); // flash some data
$preFilled = [];
if (true === $hasOldInput) {
$preFilled = [
'title' => $request->old('title'),
@@ -222,7 +222,7 @@ class CreateController extends Controller
*/
public function store(RecurrenceFormRequest $request)
{
$data = $request->getAll();
$data = $request->getAll();
try {
$recurrence = $this->recurring->store($data);
@@ -237,7 +237,7 @@ class CreateController extends Controller
// store attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($recurrence, $files);
}

View File

@@ -67,7 +67,7 @@ class DeleteController extends Controller
*/
public function delete(Recurrence $recurrence)
{
$subTitle = (string)trans('firefly.delete_recurring', ['title' => $recurrence->title]);
$subTitle = (string)trans('firefly.delete_recurring', ['title' => $recurrence->title]);
// put previous url in session
$this->rememberPreviousUrl('recurrences.delete.url');

View File

@@ -85,22 +85,22 @@ class EditController extends Controller
public function edit(Request $request, Recurrence $recurrence)
{
// TODO this should be in the repository.
$count = $recurrence->recurrenceTransactions()->count();
$count = $recurrence->recurrenceTransactions()->count();
if (0 === $count) {
throw new FireflyException('This recurring transaction has no meta-data. You will have to delete it and recreate it. Sorry!');
}
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag());
$array = $transformer->transform($recurrence);
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills());
$array = $transformer->transform($recurrence);
$budgets = app('expandedform')->makeSelectListWithEmpty($this->budgetRepos->getActiveBudgets());
$bills = app('expandedform')->makeSelectListWithEmpty($this->billRepository->getActiveBills());
/** @var RecurrenceRepetition $repetition */
$repetition = $recurrence->recurrenceRepetitions()->first();
$currentRepType = $repetition->repetition_type;
$repetition = $recurrence->recurrenceRepetitions()->first();
$currentRepType = $repetition->repetition_type;
if ('' !== $repetition->repetition_moment) {
$currentRepType .= ','.$repetition->repetition_moment;
}
@@ -111,8 +111,8 @@ class EditController extends Controller
}
$request->session()->forget('recurrences.edit.fromUpdate');
$repetitionEnd = 'forever';
$repetitionEnds = [
$repetitionEnd = 'forever';
$repetitionEnds = [
'forever' => (string)trans('firefly.repeat_forever'),
'until_date' => (string)trans('firefly.repeat_until_date'),
'times' => (string)trans('firefly.repeat_times'),
@@ -124,7 +124,7 @@ class EditController extends Controller
$repetitionEnd = 'times';
}
$weekendResponses = [
$weekendResponses = [
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'),
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'),
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'),
@@ -168,14 +168,14 @@ class EditController extends Controller
*/
public function update(RecurrenceFormRequest $request, Recurrence $recurrence)
{
$data = $request->getAll();
$data = $request->getAll();
$this->recurring->update($recurrence, $data);
$request->session()->flash('success', (string)trans('firefly.updated_recurrence', ['title' => $recurrence->title]));
// store new attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachments->saveAttachmentsForModel($recurrence, $files);
}

View File

@@ -75,11 +75,11 @@ class IndexController extends Controller
*/
public function index(Request $request)
{
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$collection = $this->recurringRepos->get();
$today = today(config('app.timezone'));
$year = today(config('app.timezone'));
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$collection = $this->recurringRepos->get();
$today = today(config('app.timezone'));
$year = today(config('app.timezone'));
// split collection
$total = $collection->count();
@@ -89,7 +89,7 @@ class IndexController extends Controller
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag());
$recurring = [];
$recurring = [];
/** @var Recurrence $recurrence */
foreach ($recurrences as $recurrence) {
@@ -104,7 +104,7 @@ class IndexController extends Controller
$array['repeat_until'] = null === $array['repeat_until'] ? null : new Carbon($array['repeat_until']);
$array['latest_date'] = null === $array['latest_date'] ? null : new Carbon($array['latest_date']);
// lazy but OK
$array['attachments'] = $recurrence->attachments()->count();
$array['attachments'] = $recurrence->attachments()->count();
// make carbon objects out of occurrences
foreach ($array['repetitions'] as $repIndex => $repetition) {
@@ -113,11 +113,11 @@ class IndexController extends Controller
}
}
$recurring[] = $array;
$recurring[] = $array;
}
$paginator = new LengthAwarePaginator($recurring, $total, $pageSize, $page);
$paginator = new LengthAwarePaginator($recurring, $total, $pageSize, $page);
$paginator->setPath(route('recurring.index'));
$today = today(config('app.timezone'));
$today = today(config('app.timezone'));
$this->verifyRecurringCronJob();

View File

@@ -77,10 +77,10 @@ class ShowController extends Controller
*/
public function show(Recurrence $recurrence)
{
$repos = app(AttachmentRepositoryInterface::class);
$repos = app(AttachmentRepositoryInterface::class);
/** @var RecurrenceTransformer $transformer */
$transformer = app(RecurrenceTransformer::class);
$transformer = app(RecurrenceTransformer::class);
$transformer->setParameters(new ParameterBag());
$array = $transformer->transform($recurrence);
@@ -113,7 +113,7 @@ class ShowController extends Controller
$array['attachments'][] = $item;
}
$subTitle = (string)trans('firefly.overview_for_recurrence', ['title' => $recurrence->title]);
$subTitle = (string)trans('firefly.overview_for_recurrence', ['title' => $recurrence->title]);
return view('recurring.show', compact('recurrence', 'subTitle', 'array', 'groups', 'today'));
}

View File

@@ -40,24 +40,24 @@ class TriggerController extends Controller
{
public function trigger(Recurrence $recurrence, TriggerRecurrenceRequest $request): RedirectResponse
{
$all = $request->getAll();
$date = $all['date'];
$all = $request->getAll();
$date = $all['date'];
// grab the date from the last time the recurrence fired:
$backupDate = $recurrence->latest_date;
$backupDate = $recurrence->latest_date;
// fire the recurring cron job on the given date, then post-date the created transaction.
app('log')->info(sprintf('Trigger: will now fire recurring cron job task for date "%s".', $date->format('Y-m-d H:i:s')));
/** @var CreateRecurringTransactions $job */
$job = app(CreateRecurringTransactions::class);
$job = app(CreateRecurringTransactions::class);
$job->setRecurrences(new Collection([$recurrence]));
$job->setDate($date);
$job->setForce(false);
$job->handle();
app('log')->debug('Done with recurrence.');
$groups = $job->getGroups();
$groups = $job->getGroups();
/** @var TransactionGroup $group */
foreach ($groups as $group) {

View File

@@ -43,7 +43,7 @@ class AccountController extends Controller
public function general(Collection $accounts, Carbon $start, Carbon $end): string
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('account-report');

View File

@@ -66,7 +66,7 @@ class BalanceController extends Controller
*/
public function general(Collection $accounts, Carbon $start, Carbon $end)
{
$report = [
$report = [
'budgets' => [],
'accounts' => [],
];
@@ -85,26 +85,26 @@ class BalanceController extends Controller
/** @var Budget $budget */
foreach ($budgets as $budget) {
$budgetId = $budget->id;
$report['budgets'][$budgetId] = [
$budgetId = $budget->id;
$report['budgets'][$budgetId] = [
'budget_id' => $budgetId,
'budget_name' => $budget->name,
'spent' => [], // per account
'sums' => [], // per currency
];
$spent = [];
$spent = [];
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$journals = $collector->setRange($start, $end)->setSourceAccounts($accounts)->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)
$collector = app(GroupCollectorInterface::class);
$journals = $collector->setRange($start, $end)->setSourceAccounts($accounts)->setTypes([TransactionType::WITHDRAWAL])->setBudget($budget)
->getExtractedJournals()
;
/** @var array $journal */
foreach ($journals as $journal) {
$sourceAccount = $journal['source_account_id'];
$currencyId = $journal['currency_id'];
$spent[$sourceAccount] ??= [
$sourceAccount = $journal['source_account_id'];
$currencyId = $journal['currency_id'];
$spent[$sourceAccount] ??= [
'source_account_id' => $sourceAccount,
'currency_id' => $journal['currency_id'],
'currency_code' => $journal['currency_code'],
@@ -113,10 +113,10 @@ class BalanceController extends Controller
'currency_decimal_places' => $journal['currency_decimal_places'],
'spent' => '0',
];
$spent[$sourceAccount]['spent'] = bcadd($spent[$sourceAccount]['spent'], $journal['amount']);
$spent[$sourceAccount]['spent'] = bcadd($spent[$sourceAccount]['spent'], $journal['amount']);
// also fix sum:
$report['sums'][$budgetId][$currencyId] ??= [
$report['sums'][$budgetId][$currencyId] ??= [
'sum' => '0',
'currency_id' => $journal['currency_id'],
'currency_code' => $journal['currency_code'],
@@ -124,8 +124,8 @@ class BalanceController extends Controller
'currency_symbol' => $journal['currency_symbol'],
'currency_decimal_places' => $journal['currency_decimal_places'],
];
$report['sums'][$budgetId][$currencyId]['sum'] = bcadd($report['sums'][$budgetId][$currencyId]['sum'], $journal['amount']);
$report['accounts'][$sourceAccount]['sum'] = bcadd($report['accounts'][$sourceAccount]['sum'], $journal['amount']);
$report['sums'][$budgetId][$currencyId]['sum'] = bcadd($report['sums'][$budgetId][$currencyId]['sum'], $journal['amount']);
$report['accounts'][$sourceAccount]['sum'] = bcadd($report['accounts'][$sourceAccount]['sum'], $journal['amount']);
// add currency info for account sum
$report['accounts'][$sourceAccount]['currency_id'] = $journal['currency_id'];

View File

@@ -42,7 +42,7 @@ class BillController extends Controller
*/
public function overview(Collection $accounts, Carbon $start, Carbon $end) // chart properties for cache:
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('bill-report');

View File

@@ -79,7 +79,7 @@ class BudgetController extends Controller
$generator->setEnd($end);
$generator->accountPerBudget();
$report = $generator->getReport();
$report = $generator->getReport();
return view('reports.budget.partials.account-per-budget', compact('report', 'budgets'));
}
@@ -95,7 +95,7 @@ class BudgetController extends Controller
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
$accountId = $account->id;
$report[$accountId] ??= [
'name' => $account->name,
'id' => $account->id,
@@ -106,7 +106,7 @@ class BudgetController extends Controller
// loop expenses.
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -117,7 +117,7 @@ class BudgetController extends Controller
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$sourceAccountId = $journal['source_account_id'];
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
@@ -143,14 +143,14 @@ class BudgetController extends Controller
*/
public function avgExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$result[$key] ??= [
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$result[$key] ??= [
'transactions' => 0,
'sum' => '0',
'avg' => '0',
@@ -198,7 +198,7 @@ class BudgetController extends Controller
/** @var Budget $budget */
foreach ($budgets as $budget) {
$budgetId = $budget->id;
$budgetId = $budget->id;
$report[$budgetId] ??= [
'name' => $budget->name,
'id' => $budget->id,
@@ -206,7 +206,7 @@ class BudgetController extends Controller
];
}
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -221,7 +221,7 @@ class BudgetController extends Controller
foreach ($budget['transaction_journals'] as $journal) {
// add currency info to report array:
$report[$budgetId]['currencies'][$currencyId] ??= [
$report[$budgetId]['currencies'][$currencyId] ??= [
'sum' => '0',
'sum_pct' => '0',
'currency_id' => $currency['currency_id'],
@@ -238,9 +238,9 @@ class BudgetController extends Controller
// loop again to get percentages.
foreach ($report as $budgetId => $data) {
foreach ($data['currencies'] as $currencyId => $dataX) {
$sum = $dataX['sum'];
$total = $sums[$currencyId]['sum'] ?? '0';
$pct = '0';
$sum = $dataX['sum'];
$total = $sums[$currencyId]['sum'] ?? '0';
$pct = '0';
if (0 !== bccomp($sum, '0') && 0 !== bccomp($total, '9')) {
$pct = round((float)bcmul(bcdiv($sum, $total), '100')); // intentional float
}
@@ -269,7 +269,7 @@ class BudgetController extends Controller
$generator->setEnd($end);
$generator->general();
$report = $generator->getReport();
$report = $generator->getReport();
return view('reports.partials.budgets', compact('report'))->render();
}
@@ -283,7 +283,7 @@ class BudgetController extends Controller
*/
public function period(Collection $accounts, Carbon $start, Carbon $end)
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('budget-period-report');
@@ -295,9 +295,9 @@ class BudgetController extends Controller
$periods = app('navigation')->listOfPeriods($start, $end);
$keyFormat = app('navigation')->preferredCarbonFormat($start, $end);
// list expenses for budgets in account(s)
$expenses = $this->opsRepository->listExpenses($start, $end, $accounts);
$expenses = $this->opsRepository->listExpenses($start, $end, $accounts);
$report = [];
$report = [];
foreach ($expenses as $currency) {
foreach ($currency['budgets'] as $budget) {
$count = 0;
@@ -346,8 +346,8 @@ class BudgetController extends Controller
*/
public function topExpenses(Collection $accounts, Collection $budgets, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $budgets);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['budgets'] as $budget) {
foreach ($budget['transaction_journals'] as $journal) {

View File

@@ -74,7 +74,7 @@ class CategoryController extends Controller
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
$accountId = $account->id;
$report[$accountId] ??= [
'name' => $account->name,
'id' => $account->id,
@@ -90,8 +90,8 @@ class CategoryController extends Controller
/** @var array $category */
foreach ($currency['categories'] as $category) {
foreach ($category['transaction_journals'] as $journal) {
$sourceAccountId = $journal['source_account_id'];
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
$sourceAccountId = $journal['source_account_id'];
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
@@ -167,7 +167,7 @@ class CategoryController extends Controller
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
$accountId = $account->id;
$report[$accountId] ??= [
'name' => $account->name,
'id' => $account->id,
@@ -178,7 +178,7 @@ class CategoryController extends Controller
// loop expenses.
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -191,7 +191,7 @@ class CategoryController extends Controller
foreach ($currency['categories'] as $category) {
foreach ($category['transaction_journals'] as $journal) {
$sourceAccountId = $journal['source_account_id'];
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
@@ -216,7 +216,7 @@ class CategoryController extends Controller
// loop income.
foreach ($earned as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -229,7 +229,7 @@ class CategoryController extends Controller
foreach ($currency['categories'] as $category) {
foreach ($category['transaction_journals'] as $journal) {
$destinationAccountId = $journal['destination_account_id'];
$report[$destinationAccountId]['currencies'][$currencyId] ??= [
$report[$destinationAccountId]['currencies'][$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
@@ -262,14 +262,14 @@ class CategoryController extends Controller
*/
public function avgExpenses(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $categories);
$result = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $categories);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['categories'] as $category) {
foreach ($category['transaction_journals'] as $journal) {
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$result[$key] ??= [
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$result[$key] ??= [
'transactions' => 0,
'sum' => '0',
'avg' => '0',
@@ -312,13 +312,13 @@ class CategoryController extends Controller
*/
public function avgIncome(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
$result = [];
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['categories'] as $category) {
foreach ($category['transaction_journals'] as $journal) {
$sourceId = $journal['source_account_id'];
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
$sourceId = $journal['source_account_id'];
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
$result[$key] ??= [
'transactions' => 0,
'sum' => '0',
@@ -369,7 +369,7 @@ class CategoryController extends Controller
/** @var Category $category */
foreach ($categories as $category) {
$categoryId = $category->id;
$categoryId = $category->id;
$report[$categoryId] ??= [
'name' => $category->name,
'id' => $category->id,
@@ -377,7 +377,7 @@ class CategoryController extends Controller
];
}
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -394,7 +394,7 @@ class CategoryController extends Controller
foreach ($category['transaction_journals'] as $journal) {
// add currency info to report array:
$report[$categoryId]['currencies'][$currencyId] ??= [
$report[$categoryId]['currencies'][$currencyId] ??= [
'spent' => '0',
'earned' => '0',
'sum' => '0',
@@ -412,14 +412,14 @@ class CategoryController extends Controller
$journal['amount']
);
$sums[$currencyId]['spent_sum'] = bcadd($sums[$currencyId]['spent_sum'], $journal['amount']);
$sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']);
$sums[$currencyId]['spent_sum'] = bcadd($sums[$currencyId]['spent_sum'], $journal['amount']);
$sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']);
}
}
}
foreach ($earned as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -436,7 +436,7 @@ class CategoryController extends Controller
foreach ($category['transaction_journals'] as $journal) {
// add currency info to report array:
$report[$categoryId]['currencies'][$currencyId] ??= [
$report[$categoryId]['currencies'][$currencyId] ??= [
'spent' => '0',
'earned' => '0',
'sum' => '0',
@@ -454,8 +454,8 @@ class CategoryController extends Controller
$journal['amount']
);
$sums[$currencyId]['earned_sum'] = bcadd($sums[$currencyId]['earned_sum'], $journal['amount']);
$sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']);
$sums[$currencyId]['earned_sum'] = bcadd($sums[$currencyId]['earned_sum'], $journal['amount']);
$sums[$currencyId]['total_sum'] = bcadd($sums[$currencyId]['total_sum'], $journal['amount']);
}
}
}
@@ -472,7 +472,7 @@ class CategoryController extends Controller
*/
public function expenses(Collection $accounts, Carbon $start, Carbon $end)
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('category-period-expenses-report');
@@ -483,7 +483,7 @@ class CategoryController extends Controller
// depending on the carbon format (a reliable way to determine the general date difference)
// change the "listOfPeriods" call so the entire period gets included correctly.
$format = app('navigation')->preferredCarbonFormat($start, $end);
$format = app('navigation')->preferredCarbonFormat($start, $end);
if ('Y' === $format) {
$start->startOfYear();
@@ -499,7 +499,7 @@ class CategoryController extends Controller
foreach ([$with, $without] as $set) {
foreach ($set as $currencyId => $currencyRow) {
foreach ($currencyRow['categories'] as $categoryId => $categoryRow) {
$key = sprintf('%d-%d', $currencyId, $categoryId);
$key = sprintf('%d-%d', $currencyId, $categoryId);
$data[$key] ??= [
'id' => $categoryRow['id'],
'title' => sprintf('%s (%s)', $categoryRow['name'], $currencyRow['currency_name']),
@@ -523,7 +523,7 @@ class CategoryController extends Controller
$cache->store($data);
$report = $data;
$report = $data;
try {
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
@@ -546,7 +546,7 @@ class CategoryController extends Controller
*/
public function income(Collection $accounts, Carbon $start, Carbon $end): string
{
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('category-period-income-report');
@@ -557,7 +557,7 @@ class CategoryController extends Controller
// depending on the carbon format (a reliable way to determine the general date difference)
// change the "listOfPeriods" call so the entire period gets included correctly.
$format = app('navigation')->preferredCarbonFormat($start, $end);
$format = app('navigation')->preferredCarbonFormat($start, $end);
if ('Y' === $format) {
$start->startOfYear();
@@ -573,7 +573,7 @@ class CategoryController extends Controller
foreach ([$with, $without] as $set) {
foreach ($set as $currencyId => $currencyRow) {
foreach ($currencyRow['categories'] as $categoryId => $categoryRow) {
$key = sprintf('%d-%d', $currencyId, $categoryId);
$key = sprintf('%d-%d', $currencyId, $categoryId);
$data[$key] ??= [
'id' => $categoryRow['id'],
'title' => sprintf('%s (%s)', $categoryRow['name'], $currencyRow['currency_name']),
@@ -595,7 +595,7 @@ class CategoryController extends Controller
}
}
$report = $data;
$report = $data;
try {
$result = view('reports.partials.category-period', compact('report', 'periods'))->render();
@@ -619,7 +619,7 @@ class CategoryController extends Controller
public function operations(Collection $accounts, Carbon $start, Carbon $end): string
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('category-report');
@@ -634,7 +634,7 @@ class CategoryController extends Controller
$generator->setStart($start);
$generator->setEnd($end);
$generator->operations();
$report = $generator->getReport();
$report = $generator->getReport();
try {
$result = view('reports.partials.categories', compact('report'))->render();
@@ -656,8 +656,8 @@ class CategoryController extends Controller
*/
public function topExpenses(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $categories);
$result = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $categories);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['categories'] as $category) {
foreach ($category['transaction_journals'] as $journal) {
@@ -704,8 +704,8 @@ class CategoryController extends Controller
*/
public function topIncome(Collection $accounts, Collection $categories, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
$result = [];
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $categories);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['categories'] as $category) {
foreach ($category['transaction_journals'] as $journal) {

View File

@@ -75,8 +75,8 @@ class DoubleController extends Controller
$result = [];
foreach ($spent as $currency) {
foreach ($currency['transaction_journals'] as $journal) {
$sourceId = $journal['source_account_id'];
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
$sourceId = $journal['source_account_id'];
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
$result[$key] ??= [
'transactions' => 0,
'sum' => '0',
@@ -97,7 +97,7 @@ class DoubleController extends Controller
}
// sort by amount_float
// sort temp array by amount.
$amounts = array_column($result, 'avg_float');
$amounts = array_column($result, 'avg_float');
array_multisort($amounts, SORT_ASC, $result);
try {
@@ -125,9 +125,9 @@ class DoubleController extends Controller
$result = [];
foreach ($spent as $currency) {
foreach ($currency['transaction_journals'] as $journal) {
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$result[$key] ??= [
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$result[$key] ??= [
'transactions' => 0,
'sum' => '0',
'avg' => '0',
@@ -147,7 +147,7 @@ class DoubleController extends Controller
}
// sort by amount_float
// sort temp array by amount.
$amounts = array_column($result, 'avg_float');
$amounts = array_column($result, 'avg_float');
array_multisort($amounts, SORT_DESC, $result);
try {
@@ -174,8 +174,8 @@ class DoubleController extends Controller
$report = [];
$sums = [];
// see what happens when we collect transactions.
$spent = $this->opsRepository->listExpenses($start, $end, $together);
$earned = $this->opsRepository->listIncome($start, $end, $together);
$spent = $this->opsRepository->listExpenses($start, $end, $together);
$earned = $this->opsRepository->listIncome($start, $end, $together);
// group and list per account name (as long as its not in accounts, only in double)
/** @var array $currency */
@@ -195,11 +195,11 @@ class DoubleController extends Controller
/** @var array $journal */
foreach ($currency['transaction_journals'] as $journal) {
$destId = $journal['destination_account_id'];
$destName = $journal['destination_account_name'];
$destIban = $journal['destination_account_iban'];
$genericName = $this->getCounterpartName($withCounterpart, $destId, $destName, $destIban);
$objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']);
$destId = $journal['destination_account_id'];
$destName = $journal['destination_account_name'];
$destIban = $journal['destination_account_iban'];
$genericName = $this->getCounterpartName($withCounterpart, $destId, $destName, $destIban);
$objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']);
$report[$objectName] ??= [
'dest_name' => '',
'dest_iban' => '',
@@ -219,10 +219,10 @@ class DoubleController extends Controller
$report[$objectName]['dest_iban'] = $destIban;
// add amounts:
$report[$objectName]['spent'] = bcadd($report[$objectName]['spent'], $journal['amount']);
$report[$objectName]['sum'] = bcadd($report[$objectName]['sum'], $journal['amount']);
$sums[$currencyId]['spent'] = bcadd($sums[$currencyId]['spent'], $journal['amount']);
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']);
$report[$objectName]['spent'] = bcadd($report[$objectName]['spent'], $journal['amount']);
$report[$objectName]['sum'] = bcadd($report[$objectName]['sum'], $journal['amount']);
$sums[$currencyId]['spent'] = bcadd($sums[$currencyId]['spent'], $journal['amount']);
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']);
}
}
@@ -243,11 +243,11 @@ class DoubleController extends Controller
/** @var array $journal */
foreach ($currency['transaction_journals'] as $journal) {
$sourceId = $journal['source_account_id'];
$sourceName = $journal['source_account_name'];
$sourceIban = $journal['source_account_iban'];
$genericName = $this->getCounterpartName($withCounterpart, $sourceId, $sourceName, $sourceIban);
$objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']);
$sourceId = $journal['source_account_id'];
$sourceName = $journal['source_account_name'];
$sourceIban = $journal['source_account_iban'];
$genericName = $this->getCounterpartName($withCounterpart, $sourceId, $sourceName, $sourceIban);
$objectName = sprintf('%s (%s)', $genericName, $currency['currency_name']);
$report[$objectName] ??= [
'dest_name' => '',
'dest_iban' => '',
@@ -268,10 +268,10 @@ class DoubleController extends Controller
$report[$objectName]['source_iban'] = $sourceIban;
// add amounts:
$report[$objectName]['earned'] = bcadd($report[$objectName]['earned'], $journal['amount']);
$report[$objectName]['sum'] = bcadd($report[$objectName]['sum'], $journal['amount']);
$sums[$currencyId]['earned'] = bcadd($sums[$currencyId]['earned'], $journal['amount']);
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']);
$report[$objectName]['earned'] = bcadd($report[$objectName]['earned'], $journal['amount']);
$report[$objectName]['sum'] = bcadd($report[$objectName]['sum'], $journal['amount']);
$sums[$currencyId]['earned'] = bcadd($sums[$currencyId]['earned'], $journal['amount']);
$sums[$currencyId]['sum'] = bcadd($sums[$currencyId]['sum'], $journal['amount']);
}
}
@@ -288,8 +288,8 @@ class DoubleController extends Controller
$report = [];
$sums = [];
// see what happens when we collect transactions.
$spent = $this->opsRepository->listExpenses($start, $end, $together);
$earned = $this->opsRepository->listIncome($start, $end, $together);
$spent = $this->opsRepository->listExpenses($start, $end, $together);
$earned = $this->opsRepository->listIncome($start, $end, $together);
// group and list per account name (as long as its not in accounts, only in double)
/** @var array $currency */
@@ -309,7 +309,7 @@ class DoubleController extends Controller
/** @var array $journal */
foreach ($currency['transaction_journals'] as $journal) {
$objectName = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
$objectName = sprintf('%s (%s)', $journal['source_account_name'], $currency['currency_name']);
$report[$objectName] ??= [
'account_id' => $journal['source_account_id'],
'account_name' => $objectName,
@@ -348,7 +348,7 @@ class DoubleController extends Controller
/** @var array $journal */
foreach ($currency['transaction_journals'] as $journal) {
$objectName = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
$objectName = sprintf('%s (%s)', $journal['destination_account_name'], $currency['currency_name']);
$report[$objectName] ??= [
'account_id' => $journal['destination_account_id'],
'account_name' => $objectName,
@@ -406,7 +406,7 @@ class DoubleController extends Controller
}
// sort by amount_float
// sort temp array by amount.
$amounts = array_column($result, 'amount_float');
$amounts = array_column($result, 'amount_float');
array_multisort($amounts, SORT_ASC, $result);
try {
@@ -454,7 +454,7 @@ class DoubleController extends Controller
}
// sort by amount_float
// sort temp array by amount.
$amounts = array_column($result, 'amount_float');
$amounts = array_column($result, 'amount_float');
array_multisort($amounts, SORT_DESC, $result);
try {

View File

@@ -65,7 +65,7 @@ class OperationsController extends Controller
public function expenses(Collection $accounts, Carbon $start, Carbon $end)
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('expense-report');
@@ -99,7 +99,7 @@ class OperationsController extends Controller
public function income(Collection $accounts, Carbon $start, Carbon $end): string
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('income-report');
@@ -135,7 +135,7 @@ class OperationsController extends Controller
public function operations(Collection $accounts, Carbon $start, Carbon $end)
{
// chart properties for cache:
$cache = new CacheProperties();
$cache = new CacheProperties();
$cache->addProperty($start);
$cache->addProperty($end);
$cache->addProperty('inc-exp-report');
@@ -152,7 +152,7 @@ class OperationsController extends Controller
/** @var int $currencyId */
foreach ($keys as $currencyId) {
$currencyInfo = $incomes['sums'][$currencyId] ?? $expenses['sums'][$currencyId];
$sums[$currencyId] ??= [
$sums[$currencyId] ??= [
'currency_id' => $currencyId,
'currency_name' => $currencyInfo['currency_name'],
'currency_code' => $currencyInfo['currency_code'],

View File

@@ -68,7 +68,7 @@ class TagController extends Controller
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
$accountId = $account->id;
$report[$accountId] ??= [
'name' => $account->name,
'id' => $account->id,
@@ -85,8 +85,8 @@ class TagController extends Controller
foreach ($currency['tags'] as $tag) {
$tagId = $tag['id'];
foreach ($tag['transaction_journals'] as $journal) {
$sourceAccountId = $journal['source_account_id'];
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
$sourceAccountId = $journal['source_account_id'];
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
@@ -163,7 +163,7 @@ class TagController extends Controller
/** @var Account $account */
foreach ($accounts as $account) {
$accountId = $account->id;
$accountId = $account->id;
$report[$accountId] ??= [
'name' => $account->name,
'id' => $account->id,
@@ -174,7 +174,7 @@ class TagController extends Controller
// loop expenses.
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -187,7 +187,7 @@ class TagController extends Controller
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
$sourceAccountId = $journal['source_account_id'];
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
$report[$sourceAccountId]['currencies'][$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
@@ -212,7 +212,7 @@ class TagController extends Controller
// loop income.
foreach ($earned as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -225,7 +225,7 @@ class TagController extends Controller
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
$destinationAccountId = $journal['destination_account_id'];
$report[$destinationAccountId]['currencies'][$currencyId] ??= [
$report[$destinationAccountId]['currencies'][$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
'currency_name' => $currency['currency_name'],
@@ -258,14 +258,14 @@ class TagController extends Controller
*/
public function avgExpenses(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
$result = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$result[$key] ??= [
$destinationId = $journal['destination_account_id'];
$key = sprintf('%d-%d', $destinationId, $currency['currency_id']);
$result[$key] ??= [
'transactions' => 0,
'sum' => '0',
'avg' => '0',
@@ -308,13 +308,13 @@ class TagController extends Controller
*/
public function avgIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$result = [];
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
$sourceId = $journal['source_account_id'];
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
$sourceId = $journal['source_account_id'];
$key = sprintf('%d-%d', $sourceId, $currency['currency_id']);
$result[$key] ??= [
'transactions' => 0,
'sum' => '0',
@@ -365,7 +365,7 @@ class TagController extends Controller
/** @var Tag $tag */
foreach ($tags as $tag) {
$tagId = $tag->id;
$tagId = $tag->id;
$report[$tagId] ??= [
'name' => $tag->tag,
'id' => $tag->id,
@@ -373,7 +373,7 @@ class TagController extends Controller
];
}
foreach ($spent as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -392,7 +392,7 @@ class TagController extends Controller
}
foreach ($tag['transaction_journals'] as $journal) {
// add currency info to report array:
$report[$tagId]['currencies'][$currencyId] ??= [
$report[$tagId]['currencies'][$currencyId] ??= [
'spent' => '0',
'earned' => '0',
$tagId => $tagId,
@@ -411,7 +411,7 @@ class TagController extends Controller
}
foreach ($earned as $currency) {
$currencyId = $currency['currency_id'];
$currencyId = $currency['currency_id'];
$sums[$currencyId] ??= [
'currency_id' => $currency['currency_id'],
'currency_symbol' => $currency['currency_symbol'],
@@ -430,7 +430,7 @@ class TagController extends Controller
}
foreach ($tag['transaction_journals'] as $journal) {
// add currency info to report array:
$report[$tagId]['currencies'][$currencyId] ??= [
$report[$tagId]['currencies'][$currencyId] ??= [
'spent' => '0',
'earned' => '0',
'sum' => '0',
@@ -458,8 +458,8 @@ class TagController extends Controller
*/
public function topExpenses(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
$result = [];
$spent = $this->opsRepository->listExpenses($start, $end, $accounts, $tags);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {
@@ -506,8 +506,8 @@ class TagController extends Controller
*/
public function topIncome(Collection $accounts, Collection $tags, Carbon $start, Carbon $end)
{
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$result = [];
$spent = $this->opsRepository->listIncome($start, $end, $accounts, $tags);
$result = [];
foreach ($spent as $currency) {
foreach ($currency['tags'] as $tag) {
foreach ($tag['transaction_journals'] as $journal) {

View File

@@ -246,12 +246,12 @@ class ReportController extends Controller
);
// group accounts by role:
$groupedAccounts = [];
$groupedAccounts = [];
/** @var Account $account */
foreach ($accounts as $account) {
$type = $account->accountType->type;
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
$type = $account->accountType->type;
$role = sprintf('opt_group_%s', $repository->getMetaValue($account, 'account_role'));
if (in_array($type, [AccountType::MORTGAGE, AccountType::DEBT, AccountType::LOAN], true)) {
$role = sprintf('opt_group_l_%s', $type);
@@ -264,7 +264,7 @@ class ReportController extends Controller
}
ksort($groupedAccounts);
$accountList = implode(',', $accounts->pluck('id')->toArray());
$accountList = implode(',', $accounts->pluck('id')->toArray());
$this->repository->cleanupBudgets();
return view('reports.index', compact('months', 'accounts', 'start', 'accountList', 'groupedAccounts', 'customFiscalYear'));
@@ -342,7 +342,7 @@ class ReportController extends Controller
return view('error')->with('message', (string)trans('firefly.end_after_start_date'));
}
$url = match ($reportType) {
$url = match ($reportType) {
default => route('reports.report.default', [$accounts, $start, $end]),
'category' => route('reports.report.category', [$accounts, $categories, $start, $end]),
'audit' => route('reports.report.audit', [$accounts, $start, $end]),

View File

@@ -79,19 +79,19 @@ class CreateController extends Controller
public function create(Request $request, RuleGroup $ruleGroup = null)
{
$this->createDefaultRuleGroup();
$preFilled = [
$preFilled = [
'strict' => true,
];
$oldTriggers = [];
$oldActions = [];
$oldTriggers = [];
$oldActions = [];
// build triggers from query, if present.
$query = (string)$request->get('from_query');
$query = (string)$request->get('from_query');
if ('' !== $query) {
$search = app(SearchInterface::class);
$search = app(SearchInterface::class);
$search->parseQuery($query);
$words = $search->getWordsAsString();
$operators = $search->getOperators()->toArray();
$words = $search->getWordsAsString();
$operators = $search->getOperators()->toArray();
if ('' !== $words) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => $words]));
$operators[] = [
@@ -114,7 +114,7 @@ class CreateController extends Controller
$subTitleIcon = 'fa-clone';
// title depends on whether or not there is a rule group:
$subTitle = (string)trans('firefly.make_new_rule_no_group');
$subTitle = (string)trans('firefly.make_new_rule_no_group');
if (null !== $ruleGroup) {
$subTitle = (string)trans('firefly.make_new_rule', ['title' => $ruleGroup->title]);
}
@@ -146,7 +146,7 @@ class CreateController extends Controller
$request->session()->flash('info', (string)trans('firefly.instructions_rule_from_bill', ['name' => e($bill->name)]));
$this->createDefaultRuleGroup();
$preFilled = [
$preFilled = [
'strict' => true,
'title' => (string)trans('firefly.new_rule_for_bill_title', ['name' => $bill->name]),
'description' => (string)trans('firefly.new_rule_for_bill_description', ['name' => $bill->name]),
@@ -155,8 +155,8 @@ class CreateController extends Controller
// make triggers and actions from the bill itself.
// get triggers and actions for bill:
$oldTriggers = $this->getTriggersForBill($bill);
$oldActions = $this->getActionsForBill($bill);
$oldTriggers = $this->getTriggersForBill($bill);
$oldActions = $this->getActionsForBill($bill);
// restore actions and triggers from old input:
if (null !== $request->old()) {
@@ -169,7 +169,7 @@ class CreateController extends Controller
$subTitleIcon = 'fa-clone';
// title depends on whether there is a rule group:
$subTitle = (string)trans('firefly.make_new_rule_no_group');
$subTitle = (string)trans('firefly.make_new_rule_no_group');
// flash old data
$request->session()->flash('preFilled', $preFilled);
@@ -199,13 +199,13 @@ class CreateController extends Controller
$subTitle = (string)trans('firefly.make_new_rule_no_group');
// get triggers and actions for journal.
$oldTriggers = $this->getTriggersForJournal($journal);
$oldActions = [];
$oldTriggers = $this->getTriggersForJournal($journal);
$oldActions = [];
$this->createDefaultRuleGroup();
// collect pre-filled information:
$preFilled = [
$preFilled = [
'strict' => true,
'title' => (string)trans('firefly.new_rule_for_journal_title', ['description' => $journal->description]),
'description' => (string)trans('firefly.new_rule_for_journal_description', ['description' => $journal->description]),
@@ -253,9 +253,9 @@ class CreateController extends Controller
*/
public function store(RuleFormRequest $request)
{
$data = $request->getRuleData();
$data = $request->getRuleData();
$rule = $this->ruleRepos->store($data);
$rule = $this->ruleRepos->store($data);
session()->flash('success', (string)trans('firefly.stored_new_rule', ['title' => $rule->title]));
app('preferences')->mark();

View File

@@ -76,18 +76,18 @@ class EditController extends Controller
*/
public function edit(Request $request, Rule $rule)
{
$triggerCount = 0;
$actionCount = 0;
$oldActions = [];
$oldTriggers = [];
$triggerCount = 0;
$actionCount = 0;
$oldActions = [];
$oldTriggers = [];
// build triggers from query, if present.
$query = (string)$request->get('from_query');
$query = (string)$request->get('from_query');
if ('' !== $query) {
$search = app(SearchInterface::class);
$search = app(SearchInterface::class);
$search->parseQuery($query);
$words = $search->getWordsAsString();
$operators = $search->getOperators()->toArray();
$words = $search->getWordsAsString();
$operators = $search->getOperators()->toArray();
if ('' !== $words) {
session()->flash('warning', trans('firefly.rule_from_search_words', ['string' => $words]));
$operators[] = ['type' => 'description_contains', 'value' => $words];
@@ -99,8 +99,8 @@ class EditController extends Controller
$oldTriggers = $this->getPreviousTriggers($request);
$oldActions = $this->getPreviousActions($request);
}
$triggerCount = count($oldTriggers);
$actionCount = count($oldActions);
$triggerCount = count($oldTriggers);
$actionCount = count($oldActions);
// overrule old input and query data when it has no rule data:
if (0 === $triggerCount && 0 === $actionCount) {
@@ -110,8 +110,8 @@ class EditController extends Controller
$actionCount = count($oldActions);
}
$hasOldInput = null !== $request->old('_token');
$preFilled = [
$hasOldInput = null !== $request->old('_token');
$preFilled = [
'active' => $hasOldInput ? (bool)$request->old('active') : $rule->active,
'stop_processing' => $hasOldInput ? (bool)$request->old('stop_processing') : $rule->stop_processing,
'strict' => $hasOldInput ? (bool)$request->old('strict') : $rule->strict,
@@ -139,7 +139,7 @@ class EditController extends Controller
*/
public function update(RuleFormRequest $request, Rule $rule)
{
$data = $request->getRuleData();
$data = $request->getRuleData();
$this->ruleRepos->update($rule, $data);
@@ -171,7 +171,7 @@ class EditController extends Controller
}
asort($triggers);
$index = 0;
$index = 0;
foreach ($submittedOperators as $operator) {
try {
$renderedEntries[] = view(

View File

@@ -70,10 +70,10 @@ class SelectController extends Controller
{
// Get parameters specified by the user
/** @var User $user */
$user = auth()->user();
$accounts = implode(',', $request->get('accounts'));
$startDate = new Carbon($request->get('start'));
$endDate = new Carbon($request->get('end'));
$user = auth()->user();
$accounts = implode(',', $request->get('accounts'));
$startDate = new Carbon($request->get('start'));
$endDate = new Carbon($request->get('end'));
// create new rule engine:
$newRuleEngine = app(RuleEngineInterface::class);
@@ -87,7 +87,7 @@ class SelectController extends Controller
// set rules:
$newRuleEngine->setRules(new Collection([$rule]));
$newRuleEngine->fire();
$resultCount = $newRuleEngine->getResults();
$resultCount = $newRuleEngine->getResults();
session()->flash('success', trans_choice('firefly.applied_rule_selection', $resultCount, ['title' => $rule->title]));
@@ -121,14 +121,14 @@ class SelectController extends Controller
public function testTriggers(TestRuleFormRequest $request): JsonResponse
{
// build fake rule
$rule = new Rule();
$rule = new Rule();
/** @var \Illuminate\Database\Eloquent\Collection<int, RuleTrigger> $triggers */
$triggers = new Collection();
$rule->strict = '1' === $request->get('strict');
$triggers = new Collection();
$rule->strict = '1' === $request->get('strict');
// build trigger array from response
$textTriggers = $this->getValidTriggerList($request);
$textTriggers = $this->getValidTriggerList($request);
// warn if nothing.
if (0 === count($textTriggers)) {
@@ -150,22 +150,22 @@ class SelectController extends Controller
// create new rule engine:
/** @var RuleEngineInterface $newRuleEngine */
$newRuleEngine = app(RuleEngineInterface::class);
$newRuleEngine = app(RuleEngineInterface::class);
// set rules:
$newRuleEngine->setRules(new Collection([$rule]));
$newRuleEngine->setRefreshTriggers(false);
$collection = $newRuleEngine->find();
$collection = $collection->slice(0, 20);
$collection = $newRuleEngine->find();
$collection = $collection->slice(0, 20);
// Warn the user if only a subset of transactions is returned
$warning = '';
$warning = '';
if (0 === count($collection)) {
$warning = (string)trans('firefly.warning_no_matching_transactions');
}
// Return json response
$view = 'ERROR, see logs.';
$view = 'ERROR, see logs.';
try {
$view = view('list.journals-array-tiny', ['groups' => $collection])->render();
@@ -188,7 +188,7 @@ class SelectController extends Controller
*/
public function testTriggersByRule(Rule $rule): JsonResponse
{
$triggers = $rule->ruleTriggers;
$triggers = $rule->ruleTriggers;
if (0 === count($triggers)) {
return response()->json(['html' => '', 'warning' => (string)trans('firefly.warning_no_valid_triggers')]);
@@ -198,16 +198,16 @@ class SelectController extends Controller
// set rules:
$newRuleEngine->setRules(new Collection([$rule]));
$collection = $newRuleEngine->find();
$collection = $collection->slice(0, 20);
$collection = $newRuleEngine->find();
$collection = $collection->slice(0, 20);
$warning = '';
$warning = '';
if (0 === count($collection)) {
$warning = (string)trans('firefly.warning_no_matching_transactions');
}
// Return json response
$view = 'ERROR, see logs.';
$view = 'ERROR, see logs.';
try {
$view = view('list.journals-array-tiny', ['groups' => $collection])->render();

View File

@@ -90,7 +90,7 @@ class CreateController extends Controller
session()->flash('success', (string)trans('firefly.created_new_rule_group', ['title' => $ruleGroup->title]));
app('preferences')->mark();
$redirect = redirect($this->getPreviousUrl('rule-groups.create.url'));
$redirect = redirect($this->getPreviousUrl('rule-groups.create.url'));
if (1 === (int)$request->get('create_another')) {
session()->put('rule-groups.create.fromStore', true);

View File

@@ -81,7 +81,7 @@ class DeleteController extends Controller
*/
public function destroy(Request $request, RuleGroup $ruleGroup)
{
$title = $ruleGroup->title;
$title = $ruleGroup->title;
/** @var RuleGroup $moveTo */
$moveTo = $this->repository->find((int)$request->get('move_rules_before_delete'));

View File

@@ -67,7 +67,7 @@ class EditController extends Controller
*/
public function edit(Request $request, RuleGroup $ruleGroup)
{
$subTitle = (string)trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]);
$subTitle = (string)trans('firefly.edit_rule_group', ['title' => $ruleGroup->title]);
$hasOldInput = null !== $request->old('_token');
$preFilled = [
@@ -119,7 +119,7 @@ class EditController extends Controller
*/
public function update(RuleGroupFormRequest $request, RuleGroup $ruleGroup)
{
$data = [
$data = [
'title' => $request->convertString('title'),
'description' => $request->stringWithNewlines('description'),
'active' => 1 === (int)$request->input('active'),

View File

@@ -69,11 +69,11 @@ class ExecutionController extends Controller
{
// Get parameters specified by the user
/** @var User $user */
$user = auth()->user();
$accounts = implode(',', $request->get('accounts'));
$startDate = new Carbon($request->get('start'));
$endDate = new Carbon($request->get('end'));
$rules = $this->ruleGroupRepository->getActiveRules($ruleGroup);
$user = auth()->user();
$accounts = implode(',', $request->get('accounts'));
$startDate = new Carbon($request->get('start'));
$endDate = new Carbon($request->get('end'));
$rules = $this->ruleGroupRepository->getActiveRules($ruleGroup);
// create new rule engine:
$newRuleEngine = app(RuleEngineInterface::class);
$newRuleEngine->setUser($user);

View File

@@ -61,18 +61,18 @@ class SearchController extends Controller
public function index(Request $request, SearchInterface $searcher)
{
// search params:
$fullQuery = $request->get('search');
$fullQuery = $request->get('search');
if (is_array($request->get('search'))) {
$fullQuery = '';
}
$fullQuery = (string)$fullQuery;
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$ruleId = (int)$request->get('rule');
$ruleChanged = false;
$fullQuery = (string)$fullQuery;
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$ruleId = (int)$request->get('rule');
$ruleChanged = false;
// find rule, check if query is different, offer to update.
$ruleRepository = app(RuleRepositoryInterface::class);
$rule = $ruleRepository->find($ruleId);
$ruleRepository = app(RuleRepositoryInterface::class);
$rule = $ruleRepository->find($ruleId);
if (null !== $rule) {
$originalQuery = $ruleRepository->getSearchQuery($rule);
if ($originalQuery !== $fullQuery) {
@@ -98,12 +98,12 @@ class SearchController extends Controller
*/
public function search(Request $request, SearchInterface $searcher): JsonResponse
{
$entry = $request->get('query');
$entry = $request->get('query');
if (!is_scalar($entry)) {
$entry = '';
}
$fullQuery = (string)$entry;
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$fullQuery = (string)$entry;
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page');
$searcher->parseQuery($fullQuery);

View File

@@ -67,7 +67,7 @@ class InstallController extends Controller
'firefly-iii:verify-security-alerts' => [],
];
$this->lastError = '';
$this->lastError = '';
}
/**
@@ -99,10 +99,10 @@ class InstallController extends Controller
];
app('log')->debug(sprintf('Will now run commands. Request index is %d', $requestIndex));
$indexes = array_values(array_keys($this->upgradeCommands));
$indexes = array_values(array_keys($this->upgradeCommands));
if (array_key_exists($requestIndex, $indexes)) {
$command = $indexes[$requestIndex];
$parameters = $this->upgradeCommands[$command];
$command = $indexes[$requestIndex];
$parameters = $this->upgradeCommands[$command];
app('log')->debug(sprintf('Will now execute command "%s" with parameters', $command), $parameters);
try {
@@ -134,7 +134,7 @@ class InstallController extends Controller
*/
public function keys(): void
{
$key = RSA::createKey(4096);
$key = RSA::createKey(4096);
[$publicKey, $privateKey] = [
Passport::keyPath('oauth-public.key'),

View File

@@ -79,8 +79,8 @@ class TagController extends Controller
$subTitleIcon = 'fa-tag';
// location info:
$hasOldInput = null !== $request->old('_token');
$locations = [
$hasOldInput = null !== $request->old('_token');
$locations = [
'location' => [
'latitude' => $hasOldInput ? old('location_latitude') : config('firefly.default_location.latitude'),
'longitude' => $hasOldInput ? old('location_longitude') : config('firefly.default_location.longitude'),
@@ -123,12 +123,12 @@ class TagController extends Controller
$subTitle = (string)trans('firefly.edit_tag', ['tag' => $tag->tag]);
$subTitleIcon = 'fa-tag';
$location = $this->repository->getLocation($tag);
$latitude = null !== $location ? $location->latitude : config('firefly.default_location.latitude');
$longitude = null !== $location ? $location->longitude : config('firefly.default_location.longitude');
$zoomLevel = null !== $location ? $location->zoom_level : config('firefly.default_location.zoom_level');
$hasLocation = null !== $location;
$locations = [
$location = $this->repository->getLocation($tag);
$latitude = null !== $location ? $location->latitude : config('firefly.default_location.latitude');
$longitude = null !== $location ? $location->longitude : config('firefly.default_location.longitude');
$zoomLevel = null !== $location ? $location->zoom_level : config('firefly.default_location.zoom_level');
$hasLocation = null !== $location;
$locations = [
'location' => [
'latitude' => old('location_latitude') ?? $latitude,
'longitude' => old('location_longitude') ?? $longitude,
@@ -154,9 +154,9 @@ class TagController extends Controller
public function index(TagRepositoryInterface $repository)
{
// start with oldest tag
$first = session('first', today()) ?? today();
$oldestTagDate = null === $repository->oldestTag() ? clone $first : $repository->oldestTag()->date;
$newestTagDate = null === $repository->newestTag() ? today() : $repository->newestTag()->date;
$first = session('first', today()) ?? today();
$oldestTagDate = null === $repository->oldestTag() ? clone $first : $repository->oldestTag()->date;
$newestTagDate = null === $repository->newestTag() ? today() : $repository->newestTag()->date;
$oldestTagDate->startOfYear();
$newestTagDate->endOfYear();
$tags = [];
@@ -167,14 +167,14 @@ class TagController extends Controller
$tags[$year] = $repository->getTagsInYear($year);
$newestTagDate->subYear();
}
$count = $repository->count();
$count = $repository->count();
return view('tags.index', compact('tags', 'count'));
}
public function massDestroy(Request $request): RedirectResponse
{
$tags = $request->get('tags');
$tags = $request->get('tags');
if (null === $tags || !is_array($tags)) {
session()->flash('info', (string)trans('firefly.select_tags_to_delete'));
@@ -221,8 +221,8 @@ class TagController extends Controller
$subTitleIcon = 'fa-tag';
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$start ??= session('start');
$end ??= session('end');
$start ??= session('start');
$end ??= session('end');
$location = $this->repository->getLocation($tag);
$attachments = $this->repository->getAttachments($tag);
$subTitle = trans(
@@ -234,21 +234,21 @@ class TagController extends Controller
]
);
$startPeriod = $this->repository->firstUseDate($tag);
$startPeriod = $this->repository->firstUseDate($tag);
$startPeriod ??= today(config('app.timezone'));
$endPeriod = clone $end;
$periods = $this->getTagPeriodOverview($tag, $startPeriod, $endPeriod);
$path = route('tags.show', [$tag->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$endPeriod = clone $end;
$periods = $this->getTagPeriodOverview($tag, $startPeriod, $endPeriod);
$path = route('tags.show', [$tag->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withAccountInformation()
->setTag($tag)->withBudgetInformation()->withCategoryInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath($path);
$sums = $this->repository->sumsOfTag($tag, $start, $end);
$sums = $this->repository->sumsOfTag($tag, $start, $end);
return view('tags.show', compact('tag', 'attachments', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'groups', 'start', 'end', 'location'));
}
@@ -273,13 +273,13 @@ class TagController extends Controller
$location = $this->repository->getLocation($tag);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)->setLimit($pageSize)->setPage($page)->withAccountInformation()
->setTag($tag)->withBudgetInformation()->withCategoryInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath($path);
$sums = $this->repository->sumsOfTag($tag, $start, $end);
$sums = $this->repository->sumsOfTag($tag, $start, $end);
return view('tags.show', compact('tag', 'attachments', 'sums', 'periods', 'subTitle', 'subTitleIcon', 'groups', 'start', 'end', 'location'));
}
@@ -289,10 +289,10 @@ class TagController extends Controller
*/
public function store(TagFormRequest $request): RedirectResponse
{
$data = $request->collectTagData();
$data = $request->collectTagData();
app('log')->debug('Data from request', $data);
$result = $this->repository->store($data);
$result = $this->repository->store($data);
app('log')->debug('Data after storage', $result->toArray());
session()->flash('success', (string)trans('firefly.created_tag', ['tag' => $data['tag']]));
@@ -300,7 +300,7 @@ class TagController extends Controller
// store attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachmentsHelper->saveAttachmentsForModel($result, $files);
}
@@ -327,15 +327,15 @@ class TagController extends Controller
*/
public function update(TagFormRequest $request, Tag $tag): RedirectResponse
{
$data = $request->collectTagData();
$tag = $this->repository->update($tag, $data);
$data = $request->collectTagData();
$tag = $this->repository->update($tag, $data);
session()->flash('success', (string)trans('firefly.updated_tag', ['tag' => $data['tag']]));
app('preferences')->mark();
// store new attachment(s):
/** @var null|array $files */
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
$files = $request->hasFile('attachments') ? $request->file('attachments') : null;
if (null !== $files && !auth()->user()->hasRole('demo')) {
$this->attachmentsHelper->saveAttachmentsForModel($tag, $files);
}

View File

@@ -71,7 +71,7 @@ class BulkController extends Controller
*/
public function edit(array $journals)
{
$subTitle = (string)trans('firefly.mass_bulk_journals');
$subTitle = (string)trans('firefly.mass_bulk_journals');
$this->rememberPreviousUrl('transactions.bulk-edit.url');

View File

@@ -87,16 +87,16 @@ class ConvertController extends Controller
}
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer = app(TransactionGroupTransformer::class);
/** @var TransactionJournal $first */
$first = $group->transactionJournals()->first();
$sourceType = $first->transactionType;
$first = $group->transactionJournals()->first();
$sourceType = $first->transactionType;
$groupTitle = $group->title ?? $first->description;
$groupArray = $transformer->transformObject($group);
$subTitle = (string)trans('firefly.convert_to_'.$destinationType->type, ['description' => $groupTitle]);
$subTitleIcon = 'fa-exchange';
$groupTitle = $group->title ?? $first->description;
$groupArray = $transformer->transformObject($group);
$subTitle = (string)trans('firefly.convert_to_'.$destinationType->type, ['description' => $groupTitle]);
$subTitleIcon = 'fa-exchange';
// get a list of asset accounts and liabilities and stuff, in various combinations:
$validDepositSources = $this->getValidDepositSources();
@@ -105,7 +105,7 @@ class ConvertController extends Controller
$assets = $this->getAssetAccounts();
// old input variables:
$preFilled = [
$preFilled = [
'source_name' => old('source_name'),
];
@@ -179,8 +179,8 @@ class ConvertController extends Controller
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
if ('' === $role) {
$role = 'no_account_type';
}
@@ -216,8 +216,8 @@ class ConvertController extends Controller
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$name = $account->name;
if ('' === $role) {
$role = 'no_account_type';
}
@@ -277,9 +277,9 @@ class ConvertController extends Controller
// group accounts:
/** @var Account $account */
foreach ($accountList as $account) {
$balance = app('steam')->balance($account, today());
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
$balance = app('steam')->balance($account, today());
$currency = $this->accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
$role = (string)$this->accountRepository->getMetaValue($account, 'account_role');
if ('' === $role) {
$role = 'no_account_type';
}
@@ -297,14 +297,14 @@ class ConvertController extends Controller
private function convertJournal(TransactionJournal $journal, TransactionType $transactionType, array $data): TransactionJournal
{
/** @var AccountValidator $validator */
$validator = app(AccountValidator::class);
$validator = app(AccountValidator::class);
$validator->setUser(auth()->user());
$validator->setTransactionType($transactionType->type);
$sourceId = $data['source_id'][$journal->id] ?? null;
$sourceName = $data['source_name'][$journal->id] ?? null;
$destinationId = $data['destination_id'][$journal->id] ?? null;
$destinationName = $data['destination_name'][$journal->id] ?? null;
$sourceId = $data['source_id'][$journal->id] ?? null;
$sourceName = $data['source_name'][$journal->id] ?? null;
$destinationId = $data['destination_id'][$journal->id] ?? null;
$destinationName = $data['destination_name'][$journal->id] ?? null;
// double check its not an empty string.
$sourceId = '' === $sourceId || null === $sourceId ? null : (int)$sourceId;
@@ -323,7 +323,7 @@ class ConvertController extends Controller
// TODO typeOverrule: the account validator may have another opinion on the transaction type.
$update = [
$update = [
'source_id' => $sourceId,
'source_name' => $sourceName,
'destination_id' => $destinationId,
@@ -332,7 +332,7 @@ class ConvertController extends Controller
];
/** @var JournalUpdateService $service */
$service = app(JournalUpdateService::class);
$service = app(JournalUpdateService::class);
$service->setTransactionJournal($journal);
$service->setData($update);
$service->update();

View File

@@ -74,8 +74,8 @@ class CreateController extends Controller
app('preferences')->mark();
$title = $newGroup->title ?? $newGroup->transactionJournals->first()->description;
$link = route('transactions.show', [$newGroup->id]);
$title = $newGroup->title ?? $newGroup->transactionJournals->first()->description;
$link = route('transactions.show', [$newGroup->id]);
session()->flash('success', trans('firefly.stored_journal', ['description' => $title]));
session()->flash('success_url', $link);
@@ -101,8 +101,8 @@ class CreateController extends Controller
{
app('preferences')->mark();
$sourceId = (int)request()->get('source');
$destinationId = (int)request()->get('destination');
$sourceId = (int)request()->get('source');
$destinationId = (int)request()->get('destination');
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);

View File

@@ -76,7 +76,7 @@ class DeleteController extends Controller
app('log')->debug(sprintf('Start of delete view for group #%d', $group->id));
$journal = $group->transactionJournals->first();
$journal = $group->transactionJournals->first();
if (null === $journal) {
throw new NotFoundHttpException();
}
@@ -100,7 +100,7 @@ class DeleteController extends Controller
return $this->redirectGroupToAccount($group);
}
$journal = $group->transactionJournals->first();
$journal = $group->transactionJournals->first();
if (null === $journal) {
throw new NotFoundHttpException();
}
@@ -108,7 +108,7 @@ class DeleteController extends Controller
session()->flash('success', (string)trans('firefly.deleted_'.strtolower($objectType), ['description' => $group->title ?? $journal->description]));
// grab asset account(s) from group:
$accounts = [];
$accounts = [];
/** @var TransactionJournal $currentJournal */
foreach ($group->transactionJournals as $currentJournal) {

View File

@@ -79,12 +79,12 @@ class EditController extends Controller
$expectedSourceTypes = config('firefly.expected_source_types');
$allowedSourceDests = config('firefly.source_dests');
$defaultCurrency = app('amount')->getDefaultCurrency();
$cash = $repository->getCashAccount();
$previousUrl = $this->rememberPreviousUrl('transactions.edit.url');
$parts = parse_url($previousUrl);
$search = sprintf('?%s', $parts['query'] ?? '');
$previousUrl = str_replace($search, '', $previousUrl);
$defaultCurrency = app('amount')->getDefaultCurrency();
$cash = $repository->getCashAccount();
$previousUrl = $this->rememberPreviousUrl('transactions.edit.url');
$parts = parse_url($previousUrl);
$search = sprintf('?%s', $parts['query'] ?? '');
$previousUrl = str_replace($search, '', $previousUrl);
return view(
'transactions.edit',

View File

@@ -75,10 +75,10 @@ class IndexController extends Controller
$objectType = 'transfer';
}
$subTitleIcon = config('firefly.transactionIconsByType.'.$objectType);
$types = config('firefly.transactionTypesByType.'.$objectType);
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
$subTitleIcon = config('firefly.transactionIconsByType.'.$objectType);
$types = config('firefly.transactionTypesByType.'.$objectType);
$page = (int)$request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data;
if (null === $start) {
$start = session('start');
$end = session('end');
@@ -90,18 +90,18 @@ class IndexController extends Controller
}
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
$path = route('transactions.index', [$objectType, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$startStr = $start->isoFormat($this->monthAndDayFormat);
$endStr = $end->isoFormat($this->monthAndDayFormat);
$subTitle = (string)trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]);
$path = route('transactions.index', [$objectType, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$startStr = $start->isoFormat($this->monthAndDayFormat);
$endStr = $end->isoFormat($this->monthAndDayFormat);
$subTitle = (string)trans(sprintf('firefly.title_%s_between', $objectType), ['start' => $startStr, 'end' => $endStr]);
$firstJournal = $this->repository->firstNull();
$startPeriod = null === $firstJournal ? new Carbon() : $firstJournal->date;
$endPeriod = clone $end;
$periods = $this->getTransactionPeriodOverview($objectType, $startPeriod, $endPeriod);
$firstJournal = $this->repository->firstNull();
$startPeriod = null === $firstJournal ? new Carbon() : $firstJournal->date;
$endPeriod = clone $end;
$periods = $this->getTransactionPeriodOverview($objectType, $startPeriod, $endPeriod);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)
->setTypes($types)
@@ -112,7 +112,7 @@ class IndexController extends Controller
->withAccountInformation()
->withAttachmentInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath($path);
return view('transactions.index', compact('subTitle', 'objectType', 'subTitleIcon', 'groups', 'periods', 'start', 'end'));
@@ -137,7 +137,7 @@ class IndexController extends Controller
$subTitle = (string)trans('firefly.all_'.$objectType);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector = app(GroupCollectorInterface::class);
$collector->setRange($start, $end)
->setTypes($types)
@@ -148,7 +148,7 @@ class IndexController extends Controller
->withCategoryInformation()
->withAttachmentInformation()
;
$groups = $collector->getPaginatedGroups();
$groups = $collector->getPaginatedGroups();
$groups->setPath($path);
return view('transactions.index', compact('subTitle', 'objectType', 'subTitleIcon', 'groups', 'start', 'end'));

View File

@@ -109,10 +109,10 @@ class LinkController extends Controller
*/
public function store(JournalLinkRequest $request, TransactionJournal $journal)
{
$linkInfo = $request->getLinkInfo();
$linkInfo = $request->getLinkInfo();
app('log')->debug('We are here (store)');
$other = $this->journalRepository->find($linkInfo['transaction_journal_id']);
$other = $this->journalRepository->find($linkInfo['transaction_journal_id']);
if (null === $other) {
session()->flash('error', (string)trans('firefly.invalid_link_selection'));

View File

@@ -121,22 +121,22 @@ class MassController extends Controller
*/
public function edit(array $journals): IlluminateView
{
$subTitle = (string)trans('firefly.mass_edit_journals');
$subTitle = (string)trans('firefly.mass_edit_journals');
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountRepository = app(AccountRepositoryInterface::class);
// valid withdrawal sources:
$array = array_keys(config(sprintf('firefly.source_dests.%s', TransactionType::WITHDRAWAL)));
$withdrawalSources = $accountRepository->getAccountsByType($array);
$array = array_keys(config(sprintf('firefly.source_dests.%s', TransactionType::WITHDRAWAL)));
$withdrawalSources = $accountRepository->getAccountsByType($array);
// valid deposit destinations:
$array = config(sprintf('firefly.source_dests.%s.%s', TransactionType::DEPOSIT, AccountType::REVENUE));
$depositDestinations = $accountRepository->getAccountsByType($array);
/** @var BudgetRepositoryInterface $budgetRepository */
$budgetRepository = app(BudgetRepositoryInterface::class);
$budgets = $budgetRepository->getBudgets();
$budgetRepository = app(BudgetRepositoryInterface::class);
$budgets = $budgetRepository->getBudgets();
// reverse amounts
foreach ($journals as $index => $journal) {
@@ -164,7 +164,7 @@ class MassController extends Controller
// TODO this is a weird error, should be caught.
throw new FireflyException('This is not an array.');
}
$count = 0;
$count = 0;
/** @var string $journalId */
foreach ($journalIds as $journalId) {
@@ -198,7 +198,7 @@ class MassController extends Controller
// for each field, call the update service.
$service->setTransactionJournal($journal);
$data = [
$data = [
'date' => $this->getDateFromRequest($request, $journal->id, 'date'),
'description' => $this->getStringFromRequest($request, $journal->id, 'description'),
'source_id' => $this->getIntFromRequest($request, $journal->id, 'source_id'),

View File

@@ -80,25 +80,25 @@ class ShowController extends Controller
public function show(TransactionGroup $transactionGroup)
{
/** @var null|TransactionJournal $first */
$first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']);
$splits = $transactionGroup->transactionJournals()->count();
$first = $transactionGroup->transactionJournals()->first(['transaction_journals.*']);
$splits = $transactionGroup->transactionJournals()->count();
if (null === $first) {
throw new FireflyException('This transaction is broken :(.');
}
$type = (string)trans(sprintf('firefly.%s', $first->transactionType->type));
$title = 1 === $splits ? $first->description : $transactionGroup->title;
$subTitle = sprintf('%s: "%s"', $type, $title);
$type = (string)trans(sprintf('firefly.%s', $first->transactionType->type));
$title = 1 === $splits ? $first->description : $transactionGroup->title;
$subTitle = sprintf('%s: "%s"', $type, $title);
/** @var TransactionGroupTransformer $transformer */
$transformer = app(TransactionGroupTransformer::class);
$transformer = app(TransactionGroupTransformer::class);
$transformer->setParameters(new ParameterBag());
$groupArray = $transformer->transformObject($transactionGroup);
$groupArray = $transformer->transformObject($transactionGroup);
// do some calculations:
$amounts = $this->getAmounts($groupArray);
$accounts = $this->getAccounts($groupArray);
$amounts = $this->getAmounts($groupArray);
$accounts = $this->getAccounts($groupArray);
foreach (array_keys($groupArray['transactions']) as $index) {
$groupArray['transactions'][$index]['tags'] = $this->repository->getTagObjects(
@@ -113,9 +113,9 @@ class ShowController extends Controller
$logEntries[$journal->id] = $this->aleRepository->getForObject($journal);
}
$events = $this->repository->getPiggyEvents($transactionGroup);
$attachments = $this->repository->getAttachments($transactionGroup);
$links = $this->repository->getLinks($transactionGroup);
$events = $this->repository->getPiggyEvents($transactionGroup);
$attachments = $this->repository->getAttachments($transactionGroup);
$links = $this->repository->getLinks($transactionGroup);
return view(
'transactions.show',
@@ -141,7 +141,7 @@ class ShowController extends Controller
{
$amounts = [];
foreach ($group['transactions'] as $transaction) {
$symbol = $transaction['currency_symbol'];
$symbol = $transaction['currency_symbol'];
if (!array_key_exists($symbol, $amounts)) {
$amounts[$symbol] = [
'amount' => '0',
@@ -156,7 +156,7 @@ class ShowController extends Controller
$transaction['foreign_amount']
)) {
// same for foreign currency:
$foreignSymbol = $transaction['foreign_currency_symbol'];
$foreignSymbol = $transaction['foreign_currency_symbol'];
if (!array_key_exists($foreignSymbol, $amounts)) {
$amounts[$foreignSymbol] = [
'amount' => '0',
@@ -176,7 +176,7 @@ class ShowController extends Controller
private function getAccounts(array $group): array
{
$accounts = [
$accounts = [
'source' => [],
'destination' => [],
];

View File

@@ -72,7 +72,7 @@ class CreateController extends Controller
public function create(Request $request)
{
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))]));
@@ -101,8 +101,8 @@ class CreateController extends Controller
public function store(CurrencyFormRequest $request)
{
/** @var User $user */
$user = auth()->user();
$data = $request->getCurrencyData();
$user = auth()->user();
$data = $request->getCurrencyData();
if (!$this->userRepository->hasRole($user, 'owner')) {
app('log')->error('User '.auth()->user()->id.' is not admin, but tried to store a currency.');
Log::channel('audit')->info('Tried to create (POST) currency without admin rights.', $data);
@@ -120,7 +120,7 @@ class CreateController extends Controller
$request->session()->flash('error', (string)trans('firefly.could_not_store_currency'));
$currency = null;
}
$redirect = redirect($this->getPreviousUrl('currencies.create.url'));
$redirect = redirect($this->getPreviousUrl('currencies.create.url'));
if (null !== $currency) {
$request->session()->flash('success', (string)trans('firefly.created_currency', ['name' => $currency->name]));

View File

@@ -71,7 +71,7 @@ class DeleteController extends Controller
public function delete(Request $request, TransactionCurrency $currency)
{
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))]));
Log::channel('audit')->info(sprintf('Tried to visit page to delete currency %s but is not site owner.', $currency->code));

View File

@@ -69,7 +69,7 @@ class EditController extends Controller
public function edit(Request $request, TransactionCurrency $currency)
{
/** @var User $user */
$user = auth()->user();
$user = auth()->user();
if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))]));
Log::channel('audit')->info(sprintf('Tried to edit currency %s but is not owner.', $currency->code));
@@ -82,12 +82,12 @@ class EditController extends Controller
$currency->symbol = htmlentities($currency->symbol);
// is currently enabled (for this user?)
$userCurrencies = $this->repository->get()->pluck('id')->toArray();
$enabled = in_array($currency->id, $userCurrencies, true);
$userCurrencies = $this->repository->get()->pluck('id')->toArray();
$enabled = in_array($currency->id, $userCurrencies, true);
// code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token');
$preFilled = [
$hasOldInput = null !== $request->old('_token');
$preFilled = [
'enabled' => $hasOldInput ? (bool)$request->old('enabled') : $enabled,
];
@@ -111,8 +111,8 @@ class EditController extends Controller
public function update(CurrencyFormRequest $request, TransactionCurrency $currency)
{
/** @var User $user */
$user = auth()->user();
$data = $request->getCurrencyData();
$user = auth()->user();
$data = $request->getCurrencyData();
if (false === $data['enabled'] && $this->repository->currencyInUse($currency)) {
$data['enabled'] = true;

View File

@@ -85,7 +85,7 @@ class IndexController extends Controller
$currencies = new LengthAwarePaginator($collection, $total, $pageSize, $page);
$currencies->setPath(route('currencies.index'));
$isOwner = true;
$isOwner = true;
if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('info', (string)trans('firefly.ask_site_owner', ['owner' => config('firefly.site_owner')]));
$isOwner = false;