Reformat various code.

This commit is contained in:
James Cole
2022-03-29 14:58:06 +02:00
parent 1209c4e76a
commit 29bed2547c
140 changed files with 1004 additions and 1010 deletions

View File

@@ -30,6 +30,6 @@ namespace FireflyIII\Enums;
class ClauseType class ClauseType
{ {
public const TRANSACTION = 'transaction'; public const TRANSACTION = 'transaction';
public const WHERE = 'where';
public const UPDATE = 'update'; public const UPDATE = 'update';
public const WHERE = 'where';
} }

View File

@@ -42,11 +42,11 @@ class AdminRequestedTestMessage extends Event
/** /**
* Create a new event instance. * Create a new event instance.
* *
* @param User $user * @param User $user
*/ */
public function __construct(User $user) public function __construct(User $user)
{ {
Log::debug(sprintf('Triggered AdminRequestedTestMessage for user #%d (%s)', $user->id, $user->email)); Log::debug(sprintf('Triggered AdminRequestedTestMessage for user #%d (%s)', $user->id, $user->email));
$this->user = $user; $this->user = $user;
} }
} }

View File

@@ -41,7 +41,7 @@ class RequestedReportOnJournals
use Dispatchable, InteractsWithSockets, SerializesModels; use Dispatchable, InteractsWithSockets, SerializesModels;
public Collection $groups; public Collection $groups;
public int $userId; public int $userId;
/** /**
* Create a new event instance. * Create a new event instance.

View File

@@ -38,7 +38,7 @@ class UserChangedEmail extends Event
public string $newEmail; public string $newEmail;
public string $oldEmail; public string $oldEmail;
public User $user; public User $user;
/** /**
* UserChangedEmail constructor. * UserChangedEmail constructor.
@@ -49,8 +49,8 @@ class UserChangedEmail extends Event
*/ */
public function __construct(User $user, string $newEmail, string $oldEmail) public function __construct(User $user, string $newEmail, string $oldEmail)
{ {
$this->user = $user; $this->user = $user;
$this->oldEmail = $oldEmail; $this->oldEmail = $oldEmail;
$this->newEmail = $newEmail; $this->newEmail = $newEmail;
} }
} }

View File

@@ -37,8 +37,8 @@ class WarnUserAboutBill extends Event
use SerializesModels; use SerializesModels;
public Bill $bill; public Bill $bill;
public string $field;
public int $diff; public int $diff;
public string $field;
/** /**
* @param Bill $bill * @param Bill $bill

View File

@@ -148,7 +148,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
$route = $request->route(); $route = $request->route();
$accountId = (int)$route->parameter('account'); $accountId = (int) $route->parameter('account');
/** @var Account $account */ /** @var Account $account */
$account = $user->accounts()->with(['accountType'])->withTrashed()->find($accountId); $account = $user->accounts()->with(['accountType'])->withTrashed()->find($accountId);
if (null === $account) { if (null === $account) {
@@ -176,7 +176,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
$route = $request->route(); $route = $request->route();
$groupId = (int)$route->parameter('transactionGroup'); $groupId = (int) $route->parameter('transactionGroup');
/** @var TransactionGroup $group */ /** @var TransactionGroup $group */
$group = $user->transactionGroups()->withTrashed()->find($groupId); $group = $user->transactionGroups()->withTrashed()->find($groupId);
@@ -216,7 +216,7 @@ class GracefulNotFoundHandler extends ExceptionHandler
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
$route = $request->route(); $route = $request->route();
$attachmentId = (int)$route->parameter('attachment'); $attachmentId = (int) $route->parameter('attachment');
/** @var Attachment $attachment */ /** @var Attachment $attachment */
$attachment = $user->attachments()->withTrashed()->find($attachmentId); $attachment = $user->attachments()->withTrashed()->find($attachmentId);
if (null === $attachment) { if (null === $attachment) {

View File

@@ -137,7 +137,7 @@ class AccountFactory
*/ */
protected function getAccountType(array $data): ?AccountType protected function getAccountType(array $data): ?AccountType
{ {
$accountTypeId = array_key_exists('account_type_id', $data) ? (int)$data['account_type_id'] : 0; $accountTypeId = array_key_exists('account_type_id', $data) ? (int) $data['account_type_id'] : 0;
$accountTypeName = array_key_exists('account_type_name', $data) ? $data['account_type_name'] : null; $accountTypeName = array_key_exists('account_type_name', $data) ? $data['account_type_name'] : null;
$result = null; $result = null;
// find by name or ID // find by name or ID
@@ -200,7 +200,7 @@ class AccountFactory
'iban' => $data['iban'], 'iban' => $data['iban'],
]; ];
// fix virtual balance when it's empty // fix virtual balance when it's empty
if ('' === (string)$databaseData['virtual_balance']) { if ('' === (string) $databaseData['virtual_balance']) {
$databaseData['virtual_balance'] = null; $databaseData['virtual_balance'] = null;
} }
// remove virtual balance when not an asset account or a liability // remove virtual balance when not an asset account or a liability
@@ -252,9 +252,9 @@ class AccountFactory
*/ */
private function cleanMetaDataArray(Account $account, array $data): array private function cleanMetaDataArray(Account $account, array $data): array
{ {
$currencyId = array_key_exists('currency_id', $data) ? (int)$data['currency_id'] : 0; $currencyId = array_key_exists('currency_id', $data) ? (int) $data['currency_id'] : 0;
$currencyCode = array_key_exists('currency_code', $data) ? (string)$data['currency_code'] : ''; $currencyCode = array_key_exists('currency_code', $data) ? (string) $data['currency_code'] : '';
$accountRole = array_key_exists('account_role', $data) ? (string)$data['account_role'] : null; $accountRole = array_key_exists('account_role', $data) ? (string) $data['account_role'] : null;
$currency = $this->getCurrency($currencyId, $currencyCode); $currency = $this->getCurrency($currencyId, $currencyCode);
// only asset account may have a role: // only asset account may have a role:
@@ -301,7 +301,7 @@ class AccountFactory
$data[$field] = 1; $data[$field] = 1;
} }
$factory->crud($account, $field, (string)$data[$field]); $factory->crud($account, $field, (string) $data[$field]);
} }
} }
} }
@@ -372,7 +372,7 @@ class AccountFactory
$order = $maxOrder + 1; $order = $maxOrder + 1;
} }
if (array_key_exists('order', $data)) { if (array_key_exists('order', $data)) {
$order = (int)($data['order'] > $maxOrder ? $maxOrder + 1 : $data['order']); $order = (int) ($data['order'] > $maxOrder ? $maxOrder + 1 : $data['order']);
$order = 0 === $order ? $maxOrder + 1 : $order; $order = 0 === $order ? $maxOrder + 1 : $order;
} }

View File

@@ -52,7 +52,7 @@ class AttachmentFactory
// get journal instead of transaction. // get journal instead of transaction.
if (Transaction::class === $model) { if (Transaction::class === $model) {
/** @var Transaction $transaction */ /** @var Transaction $transaction */
$transaction = $this->user->transactions()->find((int)$data['attachable_id']); $transaction = $this->user->transactions()->find((int) $data['attachable_id']);
if (null === $transaction) { if (null === $transaction) {
throw new FireflyException('Unexpectedly could not find transaction'); throw new FireflyException('Unexpectedly could not find transaction');
} }
@@ -75,7 +75,7 @@ class AttachmentFactory
'uploaded' => 0, 'uploaded' => 0,
] ]
); );
$notes = (string)($data['notes'] ?? ''); $notes = (string) ($data['notes'] ?? '');
if ('' !== $notes) { if ('' !== $notes) {
$note = new Note; $note = new Note;
$note->noteable()->associate($attachment); $note->noteable()->associate($attachment);

View File

@@ -41,8 +41,8 @@ class BudgetFactory
*/ */
public function find(?int $budgetId, ?string $budgetName): ?Budget public function find(?int $budgetId, ?string $budgetName): ?Budget
{ {
$budgetId = (int)$budgetId; $budgetId = (int) $budgetId;
$budgetName = (string)$budgetName; $budgetName = (string) $budgetName;
if (0 === $budgetId && '' === $budgetName) { if (0 === $budgetId && '' === $budgetName) {
return null; return null;

View File

@@ -45,8 +45,8 @@ class CategoryFactory
*/ */
public function findOrCreate(?int $categoryId, ?string $categoryName): ?Category public function findOrCreate(?int $categoryId, ?string $categoryName): ?Category
{ {
$categoryId = (int)$categoryId; $categoryId = (int) $categoryId;
$categoryName = (string)$categoryName; $categoryName = (string) $categoryName;
Log::debug(sprintf('Going to find category with ID %d and name "%s"', $categoryId, $categoryName)); Log::debug(sprintf('Going to find category with ID %d and name "%s"', $categoryId, $categoryName));

View File

@@ -41,8 +41,8 @@ class PiggyBankFactory
*/ */
public function find(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank public function find(?int $piggyBankId, ?string $piggyBankName): ?PiggyBank
{ {
$piggyBankId = (int)$piggyBankId; $piggyBankId = (int) $piggyBankId;
$piggyBankName = (string)$piggyBankName; $piggyBankName = (string) $piggyBankName;
if ('' === $piggyBankName && 0 === $piggyBankId) { if ('' === $piggyBankName && 0 === $piggyBankId) {
return null; return null;
} }

View File

@@ -84,7 +84,7 @@ class RecurrenceFactory
$firstDate = $data['recurrence']['first_date']; $firstDate = $data['recurrence']['first_date'];
} }
if (array_key_exists('nr_of_repetitions', $data['recurrence'])) { if (array_key_exists('nr_of_repetitions', $data['recurrence'])) {
$repetitions = (int)$data['recurrence']['nr_of_repetitions']; $repetitions = (int) $data['recurrence']['nr_of_repetitions'];
} }
if (array_key_exists('repeat_until', $data['recurrence'])) { if (array_key_exists('repeat_until', $data['recurrence'])) {
$repeatUntil = $data['recurrence']['repeat_until']; $repeatUntil = $data['recurrence']['repeat_until'];
@@ -120,7 +120,7 @@ class RecurrenceFactory
$recurrence->save(); $recurrence->save();
if (array_key_exists('notes', $data['recurrence'])) { if (array_key_exists('notes', $data['recurrence'])) {
$this->updateNote($recurrence, (string)$data['recurrence']['notes']); $this->updateNote($recurrence, (string) $data['recurrence']['notes']);
} }

View File

@@ -80,9 +80,9 @@ class TagFactory
*/ */
public function create(array $data): ?Tag public function create(array $data): ?Tag
{ {
$zoomLevel = 0 === (int)$data['zoom_level'] ? null : (int)$data['zoom_level']; $zoomLevel = 0 === (int) $data['zoom_level'] ? null : (int) $data['zoom_level'];
$latitude = 0.0 === (float)$data['latitude'] ? null : (float)$data['latitude']; $latitude = 0.0 === (float) $data['latitude'] ? null : (float) $data['latitude'];
$longitude = 0.0 === (float)$data['longitude'] ? null : (float)$data['longitude']; $longitude = 0.0 === (float) $data['longitude'] ? null : (float) $data['longitude'];
$array = [ $array = [
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'tag' => trim($data['tag']), 'tag' => trim($data['tag']),

View File

@@ -46,7 +46,7 @@ class TransactionCurrencyFactory
// if the code already exists (deleted) // if the code already exists (deleted)
// force delete it and then create the transaction: // force delete it and then create the transaction:
$count = TransactionCurrency::withTrashed()->whereCode($data['code'])->count(); $count = TransactionCurrency::withTrashed()->whereCode($data['code'])->count();
if(1 === $count) { if (1 === $count) {
$old = TransactionCurrency::withTrashed()->whereCode($data['code'])->first(); $old = TransactionCurrency::withTrashed()->whereCode($data['code'])->first();
$old->forceDelete(); $old->forceDelete();
Log::warning(sprintf('Force deleted old currency with ID #%d and code "%s".', $old->id, $data['code'])); Log::warning(sprintf('Force deleted old currency with ID #%d and code "%s".', $old->id, $data['code']));
@@ -80,8 +80,8 @@ class TransactionCurrencyFactory
*/ */
public function find(?int $currencyId, ?string $currencyCode): ?TransactionCurrency public function find(?int $currencyId, ?string $currencyCode): ?TransactionCurrency
{ {
$currencyCode = (string)$currencyCode; $currencyCode = (string) $currencyCode;
$currencyId = (int)$currencyId; $currencyId = (int) $currencyId;
if ('' === $currencyCode && 0 === $currencyId) { if ('' === $currencyCode && 0 === $currencyId) {
Log::debug('Cannot find anything on empty currency code and empty currency ID!'); Log::debug('Cannot find anything on empty currency code and empty currency ID!');

View File

@@ -160,11 +160,11 @@ class TransactionJournalFactory
$type = $this->typeRepository->findTransactionType(null, $row['type']); $type = $this->typeRepository->findTransactionType(null, $row['type']);
$carbon = $row['date'] ?? today(config('app.timezone')); $carbon = $row['date'] ?? today(config('app.timezone'));
$order = $row['order'] ?? 0; $order = $row['order'] ?? 0;
$currency = $this->currencyRepository->findCurrency((int)$row['currency_id'], $row['currency_code']); $currency = $this->currencyRepository->findCurrency((int) $row['currency_id'], $row['currency_code']);
$foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']); $foreignCurrency = $this->currencyRepository->findCurrencyNull($row['foreign_currency_id'], $row['foreign_currency_code']);
$bill = $this->billRepository->findBill((int)$row['bill_id'], $row['bill_name']); $bill = $this->billRepository->findBill((int) $row['bill_id'], $row['bill_name']);
$billId = TransactionType::WITHDRAWAL === $type->type && null !== $bill ? $bill->id : null; $billId = TransactionType::WITHDRAWAL === $type->type && null !== $bill ? $bill->id : null;
$description = (string)$row['description']; $description = (string) $row['description'];
/** Manipulate basic fields */ /** Manipulate basic fields */
$carbon->setTimezone(config('app.timezone')); $carbon->setTimezone(config('app.timezone'));
@@ -237,7 +237,7 @@ class TransactionJournalFactory
$transactionFactory->setForeignCurrency($foreignCurrency); $transactionFactory->setForeignCurrency($foreignCurrency);
$transactionFactory->setReconciled($row['reconciled'] ?? false); $transactionFactory->setReconciled($row['reconciled'] ?? false);
try { try {
$negative = $transactionFactory->createNegative((string)$row['amount'], (string)$row['foreign_amount']); $negative = $transactionFactory->createNegative((string) $row['amount'], (string) $row['foreign_amount']);
} catch (FireflyException $e) { } catch (FireflyException $e) {
Log::error('Exception creating negative transaction.'); Log::error('Exception creating negative transaction.');
Log::error($e->getMessage()); Log::error($e->getMessage());
@@ -256,7 +256,7 @@ class TransactionJournalFactory
$transactionFactory->setForeignCurrency($foreignCurrency); $transactionFactory->setForeignCurrency($foreignCurrency);
$transactionFactory->setReconciled($row['reconciled'] ?? false); $transactionFactory->setReconciled($row['reconciled'] ?? false);
try { try {
$transactionFactory->createPositive((string)$row['amount'], (string)$row['foreign_amount']); $transactionFactory->createPositive((string) $row['amount'], (string) $row['foreign_amount']);
} catch (FireflyException $e) { } catch (FireflyException $e) {
Log::error('Exception creating positive transaction.'); Log::error('Exception creating positive transaction.');
Log::error($e->getMessage()); Log::error($e->getMessage());
@@ -307,7 +307,7 @@ class TransactionJournalFactory
$json = json_encode($dataRow, JSON_THROW_ON_ERROR); $json = json_encode($dataRow, JSON_THROW_ON_ERROR);
if (false === $json) { if (false === $json) {
$json = json_encode((string)microtime(), JSON_THROW_ON_ERROR); $json = json_encode((string) microtime(), JSON_THROW_ON_ERROR);
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow); Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow);
} }
@@ -366,10 +366,10 @@ class TransactionJournalFactory
// validate source account. // validate source account.
$array = [ $array = [
'id' => $data['source_id'] ? (int)$data['source_id'] : null, 'id' => $data['source_id'] ? (int) $data['source_id'] : null,
'name' => $data['source_name'] ? (string)$data['source_name'] : null, 'name' => $data['source_name'] ? (string) $data['source_name'] : null,
'iban' => $data['source_iban'] ? (string)$data['source_iban'] : null, 'iban' => $data['source_iban'] ? (string) $data['source_iban'] : null,
'number' => $data['source_number'] ? (string)$data['source_number'] : null, 'number' => $data['source_number'] ? (string) $data['source_number'] : null,
]; ];
$validSource = $this->accountValidator->validateSource($array); $validSource = $this->accountValidator->validateSource($array);
@@ -381,10 +381,10 @@ class TransactionJournalFactory
// validate destination account // validate destination account
$array = [ $array = [
'id' => $data['destination_id'] ? (int)$data['destination_id'] : null, 'id' => $data['destination_id'] ? (int) $data['destination_id'] : null,
'name' => $data['destination_name'] ? (string)$data['destination_name'] : null, 'name' => $data['destination_name'] ? (string) $data['destination_name'] : null,
'iban' => $data['destination_iban'] ? (string)$data['destination_iban'] : null, 'iban' => $data['destination_iban'] ? (string) $data['destination_iban'] : null,
'number' => $data['destination_number'] ? (string)$data['destination_number'] : null, 'number' => $data['destination_number'] ? (string) $data['destination_number'] : null,
]; ];
$validDestination = $this->accountValidator->validateDestination($array); $validDestination = $this->accountValidator->validateDestination($array);
@@ -526,7 +526,7 @@ class TransactionJournalFactory
return; return;
} }
$piggyBank = $this->piggyRepository->findPiggyBank((int)$data['piggy_bank_id'], $data['piggy_bank_name']); $piggyBank = $this->piggyRepository->findPiggyBank((int) $data['piggy_bank_id'], $data['piggy_bank_name']);
if (null !== $piggyBank) { if (null !== $piggyBank) {
$this->piggyEventFactory->create($journal, $piggyBank); $this->piggyEventFactory->create($journal, $piggyBank);
@@ -558,7 +558,7 @@ class TransactionJournalFactory
$set = [ $set = [
'journal' => $journal, 'journal' => $journal,
'name' => $field, 'name' => $field,
'data' => (string)($data[$field] ?? ''), 'data' => (string) ($data[$field] ?? ''),
]; ];
//Log::debug(sprintf('Going to store meta-field "%s", with value "%s".', $set['name'], $set['data'])); //Log::debug(sprintf('Going to store meta-field "%s", with value "%s".', $set['name'], $set['data']));

View File

@@ -60,7 +60,7 @@ class TransactionJournalMetaFactory
//Log::debug('Is a carbon object.'); //Log::debug('Is a carbon object.');
$value = $data['data']->toW3cString(); $value = $data['data']->toW3cString();
} }
if ('' === (string)$value) { if ('' === (string) $value) {
// Log::debug('Is an empty string.'); // Log::debug('Is an empty string.');
// don't store blank strings. // don't store blank strings.
if (null !== $entry) { if (null !== $entry) {

View File

@@ -50,7 +50,7 @@ class ChartJsGenerator implements GeneratorInterface
$amounts = array_column($data, 'amount'); $amounts = array_column($data, 'amount');
$next = next($amounts); $next = next($amounts);
$sortFlag = SORT_ASC; $sortFlag = SORT_ASC;
if (!is_bool($next) && 1 === bccomp((string)$next, '0')) { if (!is_bool($next) && 1 === bccomp((string) $next, '0')) {
$sortFlag = SORT_DESC; $sortFlag = SORT_DESC;
} }
array_multisort($amounts, $sortFlag, $data); array_multisort($amounts, $sortFlag, $data);
@@ -59,7 +59,7 @@ class ChartJsGenerator implements GeneratorInterface
$index = 0; $index = 0;
foreach ($data as $key => $valueArray) { foreach ($data as $key => $valueArray) {
// make larger than 0 // make larger than 0
$chartData['datasets'][0]['data'][] = (float)app('steam')->positive((string)$valueArray['amount']); $chartData['datasets'][0]['data'][] = (float) app('steam')->positive((string) $valueArray['amount']);
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index); $chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
$chartData['datasets'][0]['currency_symbol'][] = $valueArray['currency_symbol']; $chartData['datasets'][0]['currency_symbol'][] = $valueArray['currency_symbol'];
$chartData['labels'][] = $key; $chartData['labels'][] = $key;
@@ -165,7 +165,7 @@ class ChartJsGenerator implements GeneratorInterface
// different sort when values are positive and when they're negative. // different sort when values are positive and when they're negative.
asort($data); asort($data);
$next = next($data); $next = next($data);
if (!is_bool($next) && 1 === bccomp((string)$next, '0')) { if (!is_bool($next) && 1 === bccomp((string) $next, '0')) {
// next is positive, sort other way around. // next is positive, sort other way around.
arsort($data); arsort($data);
} }
@@ -174,7 +174,7 @@ class ChartJsGenerator implements GeneratorInterface
$index = 0; $index = 0;
foreach ($data as $key => $value) { foreach ($data as $key => $value) {
// make larger than 0 // make larger than 0
$chartData['datasets'][0]['data'][] = (float)app('steam')->positive((string)$value); $chartData['datasets'][0]['data'][] = (float) app('steam')->positive((string) $value);
$chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index); $chartData['datasets'][0]['backgroundColor'][] = ChartColour::getColour($index);
$chartData['labels'][] = $key; $chartData['labels'][] = $key;

View File

@@ -64,6 +64,16 @@ class MonthReportGenerator implements ReportGeneratorInterface
return $result; return $result;
} }
/**
* Return the preferred period.
*
* @return string
*/
protected function preferredPeriod(): string
{
return 'day';
}
/** /**
* Set accounts. * Set accounts.
* *
@@ -155,14 +165,4 @@ class MonthReportGenerator implements ReportGeneratorInterface
{ {
return $this; return $this;
} }
/**
* Return the preferred period.
*
* @return string
*/
protected function preferredPeriod(): string
{
return 'day';
}
} }

View File

@@ -90,6 +90,80 @@ class MonthReportGenerator implements ReportGeneratorInterface
return $result; return $result;
} }
/**
* Get the audit report.
*
* @param Account $account
* @param Carbon $date
*
* @return array
* @throws FireflyException
* @throws JsonException
*/
#[ArrayShape(['journals' => "array", 'currency' => "mixed", 'exists' => "bool", 'end' => "string", 'endBalance' => "mixed", 'dayBefore' => "string",
'dayBeforeBalance' => "mixed"])] public function getAuditReport(Account $account, Carbon $date): array
{
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountRepository->setUser($account->user);
/** @var JournalRepositoryInterface $journalRepository */
$journalRepository = app(JournalRepositoryInterface::class);
$journalRepository->setUser($account->user);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end)->withAccountInformation()
->withBudgetInformation()->withCategoryInformation()->withBillInformation();
$journals = $collector->getExtractedJournals();
$journals = array_reverse($journals, true);
$dayBeforeBalance = app('steam')->balance($account, $date);
$startBalance = $dayBeforeBalance;
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($account->user);
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
foreach ($journals as $index => $journal) {
$journals[$index]['balance_before'] = $startBalance;
$transactionAmount = $journal['amount'];
// make sure amount is in the right "direction".
if ($account->id === $journal['destination_account_id']) {
$transactionAmount = app('steam')->positive($journal['amount']);
}
if ($currency->id === $journal['foreign_currency_id']) {
$transactionAmount = $journal['foreign_amount'];
if ($account->id === $journal['destination_account_id']) {
$transactionAmount = app('steam')->positive($journal['foreign_amount']);
}
}
$newBalance = bcadd($startBalance, $transactionAmount);
$journals[$index]['balance_after'] = $newBalance;
$startBalance = $newBalance;
// add meta dates for each journal.
$journals[$index]['interest_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'interest_date');
$journals[$index]['book_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'book_date');
$journals[$index]['process_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'process_date');
$journals[$index]['due_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'due_date');
$journals[$index]['payment_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'payment_date');
$journals[$index]['invoice_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'invoice_date');
}
$locale = app('steam')->getLocale();
return [
'journals' => $journals,
'currency' => $currency,
'exists' => !empty($journals),
'end' => $this->end->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)),
'endBalance' => app('steam')->balance($account, $this->end),
'dayBefore' => $date->isoFormat((string) trans('config.month_and_day_moment_js', [], $locale)),
'dayBeforeBalance' => $dayBeforeBalance,
];
}
/** /**
* Account collection setter. * Account collection setter.
* *
@@ -187,78 +261,4 @@ class MonthReportGenerator implements ReportGeneratorInterface
{ {
return $this; return $this;
} }
/**
* Get the audit report.
*
* @param Account $account
* @param Carbon $date
*
* @return array
* @throws FireflyException
* @throws JsonException
*/
#[ArrayShape(['journals' => "array", 'currency' => "mixed", 'exists' => "bool", 'end' => "string", 'endBalance' => "mixed", 'dayBefore' => "string",
'dayBeforeBalance' => "mixed"])] public function getAuditReport(Account $account, Carbon $date): array
{
/** @var AccountRepositoryInterface $accountRepository */
$accountRepository = app(AccountRepositoryInterface::class);
$accountRepository->setUser($account->user);
/** @var JournalRepositoryInterface $journalRepository */
$journalRepository = app(JournalRepositoryInterface::class);
$journalRepository->setUser($account->user);
/** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class);
$collector->setAccounts(new Collection([$account]))->setRange($this->start, $this->end)->withAccountInformation()
->withBudgetInformation()->withCategoryInformation()->withBillInformation();
$journals = $collector->getExtractedJournals();
$journals = array_reverse($journals, true);
$dayBeforeBalance = app('steam')->balance($account, $date);
$startBalance = $dayBeforeBalance;
$defaultCurrency = app('amount')->getDefaultCurrencyByUser($account->user);
$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;
foreach ($journals as $index => $journal) {
$journals[$index]['balance_before'] = $startBalance;
$transactionAmount = $journal['amount'];
// make sure amount is in the right "direction".
if ($account->id === $journal['destination_account_id']) {
$transactionAmount = app('steam')->positive($journal['amount']);
}
if ($currency->id === $journal['foreign_currency_id']) {
$transactionAmount = $journal['foreign_amount'];
if ($account->id === $journal['destination_account_id']) {
$transactionAmount = app('steam')->positive($journal['foreign_amount']);
}
}
$newBalance = bcadd($startBalance, $transactionAmount);
$journals[$index]['balance_after'] = $newBalance;
$startBalance = $newBalance;
// add meta dates for each journal.
$journals[$index]['interest_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'interest_date');
$journals[$index]['book_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'book_date');
$journals[$index]['process_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'process_date');
$journals[$index]['due_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'due_date');
$journals[$index]['payment_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'payment_date');
$journals[$index]['invoice_date'] = $journalRepository->getMetaDateById($journal['transaction_journal_id'], 'invoice_date');
}
$locale = app('steam')->getLocale();
return [
'journals' => $journals,
'currency' => $currency,
'exists' => !empty($journals),
'end' => $this->end->isoFormat((string)trans('config.month_and_day_moment_js', [], $locale)),
'endBalance' => app('steam')->balance($account, $this->end),
'dayBefore' => $date->isoFormat((string)trans('config.month_and_day_moment_js', [], $locale)),
'dayBeforeBalance' => $dayBeforeBalance,
];
}
} }

View File

@@ -66,38 +66,6 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$this->run(); $this->run();
} }
/**
* @inheritDoc
*/
public function getVersion(): int
{
return $this->version;
}
/**
* @param Collection $objects
*/
public function setObjects(Collection $objects): void
{
$this->objects = $objects;
}
/**
* @param int $trigger
*/
public function setTrigger(int $trigger): void
{
$this->trigger = $trigger;
}
/**
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
}
/** /**
* @return Collection * @return Collection
*/ */
@@ -197,6 +165,14 @@ class StandardMessageGenerator implements MessageGeneratorInterface
$this->storeMessage($webhook, $basicMessage); $this->storeMessage($webhook, $basicMessage);
} }
/**
* @inheritDoc
*/
public function getVersion(): int
{
return $this->version;
}
/** /**
* @param TransactionGroup $transactionGroup * @param TransactionGroup $transactionGroup
* *
@@ -235,4 +211,28 @@ class StandardMessageGenerator implements MessageGeneratorInterface
return $webhookMessage; return $webhookMessage;
} }
/**
* @param Collection $objects
*/
public function setObjects(Collection $objects): void
{
$this->objects = $objects;
}
/**
* @param int $trigger
*/
public function setTrigger(int $trigger): void
{
$this->trigger = $trigger;
}
/**
* @param User $user
*/
public function setUser(User $user): void
{
$this->user = $user;
}
} }

View File

@@ -30,7 +30,6 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
use Laravel\Passport\Events\AccessTokenCreated; use Laravel\Passport\Events\AccessTokenCreated;
use Log; use Log;
use Mail; use Mail;
use Request;
use Session; use Session;
/** /**
@@ -50,7 +49,7 @@ class APIEventHandler
{ {
/** @var UserRepositoryInterface $repository */ /** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class); $repository = app(UserRepositoryInterface::class);
$user = $repository->find((int)$event->userId); $user = $repository->find((int) $event->userId);
if (null !== $user) { if (null !== $user) {
$email = $user->email; $email = $user->email;
@@ -62,7 +61,7 @@ class APIEventHandler
// see if user has alternative email address: // see if user has alternative email address:
$pref = app('preferences')->getForUser($user, 'remote_guard_alt_email'); $pref = app('preferences')->getForUser($user, 'remote_guard_alt_email');
if (null !== $pref) { if (null !== $pref) {
$email = (string)(is_array($pref->data) ? $email : $pref->data); $email = (string) (is_array($pref->data) ? $email : $pref->data);
} }
Log::debug(sprintf('Now in APIEventHandler::accessTokenCreated. Email is %s', $email)); Log::debug(sprintf('Now in APIEventHandler::accessTokenCreated. Email is %s', $email));

View File

@@ -51,7 +51,7 @@ class AdminEventHandler
// is user even admin? // is user even admin?
if ($repository->hasRole($event->user, 'owner')) { if ($repository->hasRole($event->user, 'owner')) {
$email = $event->user->email; $email = $event->user->email;
// if user is demo user, send to owner: // if user is demo user, send to owner:
if ($event->user->hasRole('demo')) { if ($event->user->hasRole('demo')) {

View File

@@ -132,12 +132,12 @@ class UpdatedGroupEventHandler
->orderBy('transaction_journals.description', 'DESC') ->orderBy('transaction_journals.description', 'DESC')
->first(); ->first();
if(null === $first) { if (null === $first) {
Log::warning(sprintf('Group #%d has no transaction journals.', $group->id)); Log::warning(sprintf('Group #%d has no transaction journals.', $group->id));
return; return;
} }
$all = $group->transactionJournals()->get()->pluck('id')->toArray(); $all = $group->transactionJournals()->get()->pluck('id')->toArray();
/** @var Account $sourceAccount */ /** @var Account $sourceAccount */
$sourceAccount = $first->transactions()->where('amount', '<', '0')->first()->account; $sourceAccount = $first->transactions()->where('amount', '<', '0')->first()->account;
/** @var Account $destAccount */ /** @var Account $destAccount */

View File

@@ -125,17 +125,17 @@ class UserEventHandler
// create a new group. // create a new group.
while (true === $groupExists) { while (true === $groupExists) {
$groupExists = UserGroup::where('title', $groupTitle)->count() > 0; $groupExists = UserGroup::where('title', $groupTitle)->count() > 0;
if(false === $groupExists) { if (false === $groupExists) {
$group = UserGroup::create(['title' => $groupTitle]); $group = UserGroup::create(['title' => $groupTitle]);
break; break;
} }
$groupTitle = sprintf('%s-%d', $user->email, $index); $groupTitle = sprintf('%s-%d', $user->email, $index);
$index++; $index++;
if($index > 99) { if ($index > 99) {
throw new FireflyException('Email address can no longer be used for registrations.'); throw new FireflyException('Email address can no longer be used for registrations.');
} }
} }
$role = UserRole::where('title', UserRole::OWNER)->first(); $role = UserRole::where('title', UserRole::OWNER)->first();
if (null === $role) { if (null === $role) {
throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?'); throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?');
} }
@@ -226,11 +226,11 @@ class UserEventHandler
*/ */
public function sendEmailChangeConfirmMail(UserChangedEmail $event): bool public function sendEmailChangeConfirmMail(UserChangedEmail $event): bool
{ {
$newEmail = $event->newEmail; $newEmail = $event->newEmail;
$oldEmail = $event->oldEmail; $oldEmail = $event->oldEmail;
$user = $event->user; $user = $event->user;
$token = app('preferences')->getForUser($user, 'email_change_confirm_token', 'invalid'); $token = app('preferences')->getForUser($user, 'email_change_confirm_token', 'invalid');
$uri = route('profile.confirm-email-change', [$token->data]); $uri = route('profile.confirm-email-change', [$token->data]);
try { try {
Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $uri)); Mail::to($newEmail)->send(new ConfirmEmailChangeMail($newEmail, $oldEmail, $uri));
@@ -251,12 +251,12 @@ class UserEventHandler
*/ */
public function sendEmailChangeUndoMail(UserChangedEmail $event): bool public function sendEmailChangeUndoMail(UserChangedEmail $event): bool
{ {
$newEmail = $event->newEmail; $newEmail = $event->newEmail;
$oldEmail = $event->oldEmail; $oldEmail = $event->oldEmail;
$user = $event->user; $user = $event->user;
$token = app('preferences')->getForUser($user, 'email_change_undo_token', 'invalid'); $token = app('preferences')->getForUser($user, 'email_change_undo_token', 'invalid');
$hashed = hash('sha256', sprintf('%s%s', (string)config('app.key'), $oldEmail)); $hashed = hash('sha256', sprintf('%s%s', (string) config('app.key'), $oldEmail));
$uri = route('profile.undo-email-change', [$token->data, $hashed]); $uri = route('profile.undo-email-change', [$token->data, $hashed]);
try { try {
Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $uri)); Mail::to($oldEmail)->send(new UndoEmailChangeMail($newEmail, $oldEmail, $uri));

View File

@@ -51,7 +51,7 @@ class VersionCheckEventHandler
// should not check for updates: // should not check for updates:
$permission = app('fireflyconfig')->get('permission_update_check', -1); $permission = app('fireflyconfig')->get('permission_update_check', -1);
$value = (int)$permission->data; $value = (int) $permission->data;
if (1 !== $value) { if (1 !== $value) {
Log::info('Update check is not enabled.'); Log::info('Update check is not enabled.');
$this->warnToCheckForUpdates($event); $this->warnToCheckForUpdates($event);
@@ -115,7 +115,7 @@ class VersionCheckEventHandler
// last check time was more than a week ago. // last check time was more than a week ago.
Log::debug('Have warned about a new version in four weeks!'); Log::debug('Have warned about a new version in four weeks!');
session()->flash('info', (string)trans('firefly.disabled_but_check')); session()->flash('info', (string) trans('firefly.disabled_but_check'));
app('fireflyconfig')->set('last_update_warning', time()); app('fireflyconfig')->set('last_update_warning', time());
} }
} }

View File

@@ -77,7 +77,7 @@ class FiscalHelper implements FiscalHelperInterface
if (true === $this->useCustomFiscalYear) { if (true === $this->useCustomFiscalYear) {
$prefStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data; $prefStartStr = app('preferences')->get('fiscalYearStart', '01-01')->data;
[$mth, $day] = explode('-', $prefStartStr); [$mth, $day] = explode('-', $prefStartStr);
$startDate->day((int)$day)->month((int)$mth); $startDate->day((int) $day)->month((int) $mth);
// if start date is after passed date, sub 1 year. // if start date is after passed date, sub 1 year.
if ($startDate > $date) { if ($startDate > $date) {

View File

@@ -31,7 +31,6 @@ use FireflyIII\Support\CacheProperties;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use JsonException; use JsonException;
use Log;
/** /**
* *
@@ -91,7 +90,7 @@ class NetWorth implements NetWorthInterface
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {
//Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name)); //Log::debug(sprintf('Now at account #%d: "%s"', $account->id, $account->name));
$currencyId = (int)$this->accountRepository->getMetaValue($account, 'currency_id'); $currencyId = (int) $this->accountRepository->getMetaValue($account, 'currency_id');
$currencyId = 0 === $currencyId ? $default->id : $currencyId; $currencyId = 0 === $currencyId ? $default->id : $currencyId;
//Log::debug(sprintf('Currency ID is #%d', $currencyId)); //Log::debug(sprintf('Currency ID is #%d', $currencyId));
@@ -102,7 +101,7 @@ class NetWorth implements NetWorthInterface
//Log::debug(sprintf('Balance is %s', $balance)); //Log::debug(sprintf('Balance is %s', $balance));
// always subtract virtual balance. // always subtract virtual balance.
$virtualBalance = (string)$account->virtual_balance; $virtualBalance = (string) $account->virtual_balance;
if ('' !== $virtualBalance) { if ('' !== $virtualBalance) {
$balance = bcsub($balance, $virtualBalance); $balance = bcsub($balance, $virtualBalance);
} }

View File

@@ -77,7 +77,7 @@ class PopupReport implements PopupReportInterface
if (null !== $currencyId) { if (null !== $currencyId) {
/** @var CurrencyRepositoryInterface $repos */ /** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class); $repos = app(CurrencyRepositoryInterface::class);
$currency = $repos->find((int)$currencyId); $currency = $repos->find((int) $currencyId);
} }
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
@@ -112,7 +112,7 @@ class PopupReport implements PopupReportInterface
if (null !== $currencyId) { if (null !== $currencyId) {
/** @var CurrencyRepositoryInterface $repos */ /** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class); $repos = app(CurrencyRepositoryInterface::class);
$currency = $repos->find((int)$currencyId); $currency = $repos->find((int) $currencyId);
} }
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
@@ -152,7 +152,7 @@ class PopupReport implements PopupReportInterface
if (null !== $currencyId) { if (null !== $currencyId) {
/** @var CurrencyRepositoryInterface $repos */ /** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class); $repos = app(CurrencyRepositoryInterface::class);
$currency = $repos->find((int)$currencyId); $currency = $repos->find((int) $currencyId);
} }
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
@@ -195,7 +195,7 @@ class PopupReport implements PopupReportInterface
if (null !== $currencyId) { if (null !== $currencyId) {
/** @var CurrencyRepositoryInterface $repos */ /** @var CurrencyRepositoryInterface $repos */
$repos = app(CurrencyRepositoryInterface::class); $repos = app(CurrencyRepositoryInterface::class);
$currency = $repos->find((int)$currencyId); $currency = $repos->find((int) $currencyId);
} }
/** @var JournalRepositoryInterface $repository */ /** @var JournalRepositoryInterface $repository */

View File

@@ -141,7 +141,7 @@ class ReportHelper implements ReportHelperInterface
$currentEnd = clone $start; $currentEnd = clone $start;
$currentEnd->endOfMonth(); $currentEnd->endOfMonth();
$months[$year]['months'][] = [ $months[$year]['months'][] = [
'formatted' => $start->isoFormat((string)trans('config.month_js')), 'formatted' => $start->isoFormat((string) trans('config.month_js')),
'start' => $start->format('Y-m-d'), 'start' => $start->format('Y-m-d'),
'end' => $currentEnd->format('Y-m-d'), 'end' => $currentEnd->format('Y-m-d'),
'month' => $start->month, 'month' => $start->month,

View File

@@ -61,7 +61,7 @@ class CreateController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string) trans('firefly.accounts'));
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class); $this->attachments = app(AttachmentHelperInterface::class);
@@ -84,7 +84,7 @@ class CreateController extends Controller
$objectType = $objectType ?? 'asset'; $objectType = $objectType ?? 'asset';
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$subTitle = (string)trans(sprintf('firefly.make_new_%s_account', $objectType)); $subTitle = (string) trans(sprintf('firefly.make_new_%s_account', $objectType));
$roles = $this->getRoles(); $roles = $this->getRoles();
$liabilityTypes = $this->getLiabilityTypes(); $liabilityTypes = $this->getLiabilityTypes();
$hasOldInput = null !== $request->old('_token'); $hasOldInput = null !== $request->old('_token');
@@ -103,9 +103,9 @@ class CreateController extends Controller
// interest calculation periods: // interest calculation periods:
$interestPeriods = [ $interestPeriods = [
'daily' => (string)trans('firefly.interest_calc_daily'), 'daily' => (string) trans('firefly.interest_calc_daily'),
'monthly' => (string)trans('firefly.interest_calc_monthly'), 'monthly' => (string) trans('firefly.interest_calc_monthly'),
'yearly' => (string)trans('firefly.interest_calc_yearly'), 'yearly' => (string) trans('firefly.interest_calc_yearly'),
]; ];
// pre fill some data // pre fill some data
@@ -113,7 +113,7 @@ class CreateController extends Controller
'preFilled', 'preFilled',
[ [
'currency_id' => $defaultCurrency->id, 'currency_id' => $defaultCurrency->id,
'include_net_worth' => $hasOldInput ? (bool)$request->old('include_net_worth') : true, 'include_net_worth' => $hasOldInput ? (bool) $request->old('include_net_worth') : true,
] ]
); );
@@ -142,7 +142,7 @@ class CreateController extends Controller
{ {
$data = $request->getAccountData(); $data = $request->getAccountData();
$account = $this->repository->store($data); $account = $this->repository->store($data);
$request->session()->flash('success', (string)trans('firefly.stored_new_account', ['name' => $account->name])); $request->session()->flash('success', (string) trans('firefly.stored_new_account', ['name' => $account->name]));
app('preferences')->mark(); app('preferences')->mark();
Log::channel('audit')->info('Stored new account.', $data); Log::channel('audit')->info('Stored new account.', $data);
@@ -161,7 +161,7 @@ class CreateController extends Controller
$this->attachments->saveAttachmentsForModel($account, $files); $this->attachments->saveAttachmentsForModel($account, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -170,7 +170,7 @@ class CreateController extends Controller
// redirect to previous URL. // redirect to previous URL.
$redirect = redirect($this->getPreviousUri('accounts.create.uri')); $redirect = redirect($this->getPreviousUri('accounts.create.uri'));
if (1 === (int)$request->get('create_another')) { if (1 === (int) $request->get('create_another')) {
// set value so create routine will not overwrite URL: // set value so create routine will not overwrite URL:
$request->session()->put('accounts.create.fromStore', true); $request->session()->put('accounts.create.fromStore', true);

View File

@@ -53,7 +53,7 @@ class DeleteController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string) trans('firefly.accounts'));
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
@@ -76,7 +76,7 @@ class DeleteController extends Controller
} }
$typeName = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); $typeName = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
$subTitle = (string)trans(sprintf('firefly.delete_%s_account', $typeName), ['name' => $account->name]); $subTitle = (string) trans(sprintf('firefly.delete_%s_account', $typeName), ['name' => $account->name]);
$accountList = app('expandedform')->makeSelectListWithEmpty($this->repository->getAccountsByType([$account->accountType->type])); $accountList = app('expandedform')->makeSelectListWithEmpty($this->repository->getAccountsByType([$account->accountType->type]));
$objectType = $typeName; $objectType = $typeName;
unset($accountList[$account->id]); unset($accountList[$account->id]);
@@ -104,11 +104,11 @@ class DeleteController extends Controller
$type = $account->accountType->type; $type = $account->accountType->type;
$typeName = config(sprintf('firefly.shortNamesByFullName.%s', $type)); $typeName = config(sprintf('firefly.shortNamesByFullName.%s', $type));
$name = $account->name; $name = $account->name;
$moveTo = $this->repository->find((int)$request->get('move_account_before_delete')); $moveTo = $this->repository->find((int) $request->get('move_account_before_delete'));
$this->repository->destroy($account, $moveTo); $this->repository->destroy($account, $moveTo);
$request->session()->flash('success', (string)trans(sprintf('firefly.%s_deleted', $typeName), ['name' => $name])); $request->session()->flash('success', (string) trans(sprintf('firefly.%s_deleted', $typeName), ['name' => $name]));
app('preferences')->mark(); app('preferences')->mark();
return redirect($this->getPreviousUri('accounts.delete.uri')); return redirect($this->getPreviousUri('accounts.delete.uri'));

View File

@@ -59,7 +59,7 @@ class EditController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string) trans('firefly.accounts'));
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class);
@@ -86,7 +86,7 @@ class EditController extends Controller
} }
$objectType = config('firefly.shortNamesByFullName')[$account->accountType->type]; $objectType = config('firefly.shortNamesByFullName')[$account->accountType->type];
$subTitle = (string)trans(sprintf('firefly.edit_%s_account', $objectType), ['name' => $account->name]); $subTitle = (string) trans(sprintf('firefly.edit_%s_account', $objectType), ['name' => $account->name]);
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$roles = $this->getRoles(); $roles = $this->getRoles();
$liabilityTypes = $this->getLiabilityTypes(); $liabilityTypes = $this->getLiabilityTypes();
@@ -111,9 +111,9 @@ class EditController extends Controller
// interest calculation periods: // interest calculation periods:
$interestPeriods = [ $interestPeriods = [
'daily' => (string)trans('firefly.interest_calc_daily'), 'daily' => (string) trans('firefly.interest_calc_daily'),
'monthly' => (string)trans('firefly.interest_calc_monthly'), 'monthly' => (string) trans('firefly.interest_calc_monthly'),
'yearly' => (string)trans('firefly.interest_calc_yearly'), 'yearly' => (string) trans('firefly.interest_calc_yearly'),
]; ];
// put previous url in session if not redirect from store (not "return_to_edit"). // put previous url in session if not redirect from store (not "return_to_edit").
@@ -122,7 +122,7 @@ class EditController extends Controller
} }
$request->session()->forget('accounts.edit.fromUpdate'); $request->session()->forget('accounts.edit.fromUpdate');
$openingBalanceAmount = (string)$repository->getOpeningBalanceAmount($account); $openingBalanceAmount = (string) $repository->getOpeningBalanceAmount($account);
if ('0' === $openingBalanceAmount) { if ('0' === $openingBalanceAmount) {
$openingBalanceAmount = ''; $openingBalanceAmount = '';
} }
@@ -143,17 +143,17 @@ class EditController extends Controller
'BIC' => $repository->getMetaValue($account, 'BIC'), 'BIC' => $repository->getMetaValue($account, 'BIC'),
'opening_balance_date' => $openingBalanceDate, 'opening_balance_date' => $openingBalanceDate,
'liability_type_id' => $account->account_type_id, 'liability_type_id' => $account->account_type_id,
'opening_balance' => number_format((float)$openingBalanceAmount, $currency->decimal_places,'.',''), 'opening_balance' => number_format((float) $openingBalanceAmount, $currency->decimal_places, '.', ''),
'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'), 'liability_direction' => $this->repository->getMetaValue($account, 'liability_direction'),
'virtual_balance' => number_format((float)$account->virtual_balance, $currency->decimal_places,'.',''), 'virtual_balance' => number_format((float) $account->virtual_balance, $currency->decimal_places, '.', ''),
'currency_id' => $currency->id, 'currency_id' => $currency->id,
'include_net_worth' => $includeNetWorth, 'include_net_worth' => $includeNetWorth,
'interest' => $repository->getMetaValue($account, 'interest'), 'interest' => $repository->getMetaValue($account, 'interest'),
'interest_period' => $repository->getMetaValue($account, 'interest_period'), 'interest_period' => $repository->getMetaValue($account, 'interest_period'),
'notes' => $this->repository->getNoteText($account), 'notes' => $this->repository->getNoteText($account),
'active' => $hasOldInput ? (bool)$request->old('active') : $account->active, 'active' => $hasOldInput ? (bool) $request->old('active') : $account->active,
]; ];
if('' === $openingBalanceAmount) { if ('' === $openingBalanceAmount) {
$preFilled['opening_balance'] = ''; $preFilled['opening_balance'] = '';
} }
@@ -194,7 +194,7 @@ class EditController extends Controller
$data = $request->getAccountData(); $data = $request->getAccountData();
$this->repository->update($account, $data); $this->repository->update($account, $data);
$request->session()->flash('success', (string)trans('firefly.updated_account', ['name' => $account->name])); $request->session()->flash('success', (string) trans('firefly.updated_account', ['name' => $account->name]));
// store new attachment(s): // store new attachment(s):
@@ -203,7 +203,7 @@ class EditController extends Controller
$this->attachments->saveAttachmentsForModel($account, $files); $this->attachments->saveAttachmentsForModel($account, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -212,7 +212,7 @@ class EditController extends Controller
// redirect // redirect
$redirect = redirect($this->getPreviousUri('accounts.edit.uri')); $redirect = redirect($this->getPreviousUri('accounts.edit.uri'));
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int) $request->get('return_to_edit')) {
// set value so edit routine will not overwrite URL: // set value so edit routine will not overwrite URL:
$request->session()->put('accounts.edit.fromUpdate', true); $request->session()->put('accounts.edit.fromUpdate', true);

View File

@@ -59,7 +59,7 @@ class IndexController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string) trans('firefly.accounts'));
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
@@ -79,13 +79,13 @@ class IndexController extends Controller
{ {
$objectType = $objectType ?? 'asset'; $objectType = $objectType ?? 'asset';
$inactivePage = true; $inactivePage = true;
$subTitle = (string)trans(sprintf('firefly.%s_accounts_inactive', $objectType)); $subTitle = (string) trans(sprintf('firefly.%s_accounts_inactive', $objectType));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); $types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));
$collection = $this->repository->getInactiveAccountsByType($types); $collection = $this->repository->getInactiveAccountsByType($types);
$total = $collection->count(); $total = $collection->count();
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize); $accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);
unset($collection); unset($collection);
/** @var Carbon $start */ /** @var Carbon $start */
@@ -105,11 +105,11 @@ class IndexController extends Controller
$account->startBalance = $this->isInArray($startBalances, $account->id); $account->startBalance = $this->isInArray($startBalances, $account->id);
$account->endBalance = $this->isInArray($endBalances, $account->id); $account->endBalance = $this->isInArray($endBalances, $account->id);
$account->difference = bcsub($account->endBalance, $account->startBalance); $account->difference = bcsub($account->endBalance, $account->startBalance);
$account->interest = number_format((float)$this->repository->getMetaValue($account, 'interest'), 4, '.', ''); $account->interest = number_format((float) $this->repository->getMetaValue($account, 'interest'), 4, '.', '');
$account->interestPeriod = (string)trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))); $account->interestPeriod = (string) trans(sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')));
$account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type)); $account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type));
$account->current_debt = '0'; $account->current_debt = '0';
$account->iban = implode(' ', str_split((string)$account->iban, 4)); $account->iban = implode(' ', str_split((string) $account->iban, 4));
} }
); );
@@ -134,7 +134,7 @@ class IndexController extends Controller
{ {
Log::debug(sprintf('Now at %s', __METHOD__)); Log::debug(sprintf('Now at %s', __METHOD__));
$objectType = $objectType ?? 'asset'; $objectType = $objectType ?? 'asset';
$subTitle = (string)trans(sprintf('firefly.%s_accounts', $objectType)); $subTitle = (string) trans(sprintf('firefly.%s_accounts', $objectType));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $objectType));
$types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType)); $types = config(sprintf('firefly.accountTypesByIdentifier.%s', $objectType));
@@ -142,8 +142,8 @@ class IndexController extends Controller
$collection = $this->repository->getActiveAccountsByType($types); $collection = $this->repository->getActiveAccountsByType($types);
$total = $collection->count(); $total = $collection->count();
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize); $accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);
$inactiveCount = $this->repository->getInactiveAccountsByType($types)->count(); $inactiveCount = $this->repository->getInactiveAccountsByType($types)->count();
@@ -168,15 +168,15 @@ class IndexController extends Controller
$account->startBalance = $this->isInArray($startBalances, $account->id); $account->startBalance = $this->isInArray($startBalances, $account->id);
$account->endBalance = $this->isInArray($endBalances, $account->id); $account->endBalance = $this->isInArray($endBalances, $account->id);
$account->difference = bcsub($account->endBalance, $account->startBalance); $account->difference = bcsub($account->endBalance, $account->startBalance);
$account->interest = number_format((float)$this->repository->getMetaValue($account, 'interest'), 4, '.', ''); $account->interest = number_format((float) $this->repository->getMetaValue($account, 'interest'), 4, '.', '');
$account->interestPeriod = (string)trans( $account->interestPeriod = (string) trans(
sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period')) sprintf('firefly.interest_calc_%s', $this->repository->getMetaValue($account, 'interest_period'))
); );
$account->accountTypeString = (string)trans(sprintf('firefly.account_type_%s', $account->accountType->type)); $account->accountTypeString = (string) trans(sprintf('firefly.account_type_%s', $account->accountType->type));
$account->location = $this->repository->getLocation($account); $account->location = $this->repository->getLocation($account);
$account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction'); $account->liability_direction = $this->repository->getMetaValue($account, 'liability_direction');
$account->current_debt = $this->repository->getMetaValue($account, 'current_debt') ?? '-'; $account->current_debt = $this->repository->getMetaValue($account, 'current_debt') ?? '-';
$account->iban = implode(' ', str_split((string)$account->iban, 4)); $account->iban = implode(' ', str_split((string) $account->iban, 4));
} }
); );
// make paginator: // make paginator:

View File

@@ -68,7 +68,7 @@ class ReconcileController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string) trans('firefly.accounts'));
$this->repository = app(JournalRepositoryInterface::class); $this->repository = app(JournalRepositoryInterface::class);
$this->accountRepos = app(AccountRepositoryInterface::class); $this->accountRepos = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class);
@@ -95,7 +95,7 @@ class ReconcileController extends Controller
} }
if (AccountType::ASSET !== $account->accountType->type) { if (AccountType::ASSET !== $account->accountType->type) {
session()->flash('error', (string)trans('firefly.must_be_asset_account')); session()->flash('error', (string) trans('firefly.must_be_asset_account'));
return redirect(route('accounts.index', [config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type))])); return redirect(route('accounts.index', [config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type))]));
@@ -125,10 +125,10 @@ class ReconcileController extends Controller
$startDate = clone $start; $startDate = clone $start;
$startDate->subDay(); $startDate->subDay();
$startBalance = number_format((float)app('steam')->balance($account, $startDate), $currency->decimal_places, '.', ''); $startBalance = number_format((float) app('steam')->balance($account, $startDate), $currency->decimal_places, '.', '');
$endBalance = number_format((float)app('steam')->balance($account, $end), $currency->decimal_places, '.', ''); $endBalance = number_format((float) app('steam')->balance($account, $end), $currency->decimal_places, '.', '');
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
$subTitle = (string)trans('firefly.reconcile_account', ['account' => $account->name]); $subTitle = (string) trans('firefly.reconcile_account', ['account' => $account->name]);
// various links // various links
$transactionsUri = route('accounts.reconcile.transactions', [$account->id, '%start%', '%end%']); $transactionsUri = route('accounts.reconcile.transactions', [$account->id, '%start%', '%end%']);
@@ -177,7 +177,7 @@ class ReconcileController extends Controller
/** @var string $journalId */ /** @var string $journalId */
foreach ($data['journals'] as $journalId) { foreach ($data['journals'] as $journalId) {
$this->repository->reconcileById((int)$journalId); $this->repository->reconcileById((int) $journalId);
} }
Log::debug('Reconciled all transactions.'); Log::debug('Reconciled all transactions.');
@@ -194,10 +194,10 @@ class ReconcileController extends Controller
Log::debug('End of routine.'); Log::debug('End of routine.');
app('preferences')->mark(); app('preferences')->mark();
if ('' === $result) { if ('' === $result) {
session()->flash('success', (string)trans('firefly.reconciliation_stored')); session()->flash('success', (string) trans('firefly.reconciliation_stored'));
} }
if ('' !== $result) { if ('' !== $result) {
session()->flash('error', (string)trans('firefly.reconciliation_error', ['error' => $result])); session()->flash('error', (string) trans('firefly.reconciliation_error', ['error' => $result]));
} }
return redirect(route('accounts.show', [$account->id])); return redirect(route('accounts.show', [$account->id]));
@@ -238,7 +238,7 @@ class ReconcileController extends Controller
$description = trans( $description = trans(
'firefly.reconciliation_transaction_title', 'firefly.reconciliation_transaction_title',
['from' => $start->isoFormat($this->monthAndDayFormat), ['from' => $start->isoFormat($this->monthAndDayFormat),
'to' => $end->isoFormat($this->monthAndDayFormat)] 'to' => $end->isoFormat($this->monthAndDayFormat)]
); );
$submission = [ $submission = [
'user' => auth()->user()->id, 'user' => auth()->user()->id,

View File

@@ -64,7 +64,7 @@ class ShowController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string) trans('firefly.accounts'));
$this->repository = app(AccountRepositoryInterface::class); $this->repository = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class);
@@ -106,19 +106,19 @@ class ShowController extends Controller
$attachments = $this->repository->getAttachments($account); $attachments = $this->repository->getAttachments($account);
$today = today(config('app.timezone')); $today = today(config('app.timezone'));
$subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type)); $subTitleIcon = config(sprintf('firefly.subIconsByIdentifier.%s', $account->accountType->type));
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); $currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$fStart = $start->isoFormat($this->monthAndDayFormat); $fStart = $start->isoFormat($this->monthAndDayFormat);
$fEnd = $end->isoFormat($this->monthAndDayFormat); $fEnd = $end->isoFormat($this->monthAndDayFormat);
$subTitle = (string)trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]); $subTitle = (string) trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]);
$chartUri = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); $chartUri = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
$firstTransaction = $this->repository->oldestJournalDate($account) ?? $start; $firstTransaction = $this->repository->oldestJournalDate($account) ?? $start;
$periods = $this->getAccountPeriodOverview($account, $firstTransaction, $end); $periods = $this->getAccountPeriodOverview($account, $firstTransaction, $end);
// if layout = v2, overrule the page title. // if layout = v2, overrule the page title.
if('v1'!==config('firefly.layout')) { if ('v1' !== config('firefly.layout')) {
$subTitle = (string)trans('firefly.all_journals_for_account', ['name' => $account->name]); $subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
} }
@@ -180,10 +180,10 @@ class ShowController extends Controller
$today = today(config('app.timezone')); $today = today(config('app.timezone'));
$start = $this->repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth(); $start = $this->repository->oldestJournalDate($account) ?? Carbon::now()->startOfMonth();
$subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type); $subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type);
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); $currency = $this->repository->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$subTitle = (string)trans('firefly.all_journals_for_account', ['name' => $account->name]); $subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
$periods = new Collection; $periods = new Collection;
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);

View File

@@ -47,7 +47,7 @@ class ConfigurationController extends Controller
$this->middleware( $this->middleware(
static function ($request, $next) { static function ($request, $next) {
app('view')->share('title', (string)trans('firefly.administration')); app('view')->share('title', (string) trans('firefly.administration'));
app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
return $next($request); return $next($request);
@@ -64,7 +64,7 @@ class ConfigurationController extends Controller
*/ */
public function index() public function index()
{ {
$subTitle = (string)trans('firefly.instance_configuration'); $subTitle = (string) trans('firefly.instance_configuration');
$subTitleIcon = 'fa-wrench'; $subTitleIcon = 'fa-wrench';
Log::channel('audit')->info('User visits admin config index.'); Log::channel('audit')->info('User visits admin config index.');
@@ -100,7 +100,7 @@ class ConfigurationController extends Controller
app('fireflyconfig')->set('is_demo_site', $data['is_demo_site']); app('fireflyconfig')->set('is_demo_site', $data['is_demo_site']);
// flash message // flash message
session()->flash('success', (string)trans('firefly.configuration_updated')); session()->flash('success', (string) trans('firefly.configuration_updated'));
app('preferences')->mark(); app('preferences')->mark();
return redirect()->route('admin.configuration.index'); return redirect()->route('admin.configuration.index');

View File

@@ -59,7 +59,7 @@ class HomeController extends Controller
public function index() public function index()
{ {
Log::channel('audit')->info('User visits admin index.'); Log::channel('audit')->info('User visits admin index.');
$title = (string)trans('firefly.administration'); $title = (string) trans('firefly.administration');
$mainTitleIcon = 'fa-hand-spock-o'; $mainTitleIcon = 'fa-hand-spock-o';
$email = auth()->user()->email; $email = auth()->user()->email;
$pref = app('preferences')->get('remote_guard_alt_email'); $pref = app('preferences')->get('remote_guard_alt_email');
@@ -82,10 +82,10 @@ class HomeController extends Controller
{ {
Log::channel('audit')->info('User sends test message.'); Log::channel('audit')->info('User sends test message.');
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
Log::debug('Now in testMessage() controller.'); Log::debug('Now in testMessage() controller.');
event(new AdminRequestedTestMessage($user)); event(new AdminRequestedTestMessage($user));
session()->flash('info', (string)trans('firefly.send_test_triggered')); session()->flash('info', (string) trans('firefly.send_test_triggered'));
return redirect(route('admin.index')); return redirect(route('admin.index'));
} }

View File

@@ -52,7 +52,7 @@ class LinkController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.administration')); app('view')->share('title', (string) trans('firefly.administration'));
app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
$this->repository = app(LinkTypeRepositoryInterface::class); $this->repository = app(LinkTypeRepositoryInterface::class);
@@ -71,7 +71,7 @@ class LinkController extends Controller
{ {
Log::channel('audit')->info('User visits link index.'); Log::channel('audit')->info('User visits link index.');
$subTitle = (string)trans('firefly.create_new_link_type'); $subTitle = (string) trans('firefly.create_new_link_type');
$subTitleIcon = 'fa-link'; $subTitleIcon = 'fa-link';
// put previous url in session if not redirect from store (not "create another"). // put previous url in session if not redirect from store (not "create another").
@@ -93,17 +93,17 @@ class LinkController extends Controller
public function delete(Request $request, LinkType $linkType) public function delete(Request $request, LinkType $linkType)
{ {
if (!$linkType->editable) { if (!$linkType->editable) {
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)])); $request->session()->flash('error', (string) trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)]));
return redirect(route('admin.links.index')); return redirect(route('admin.links.index'));
} }
Log::channel('audit')->info(sprintf('User wants to delete link type #%d', $linkType->id)); Log::channel('audit')->info(sprintf('User wants to delete link type #%d', $linkType->id));
$subTitle = (string)trans('firefly.delete_link_type', ['name' => $linkType->name]); $subTitle = (string) trans('firefly.delete_link_type', ['name' => $linkType->name]);
$otherTypes = $this->repository->get(); $otherTypes = $this->repository->get();
$count = $this->repository->countJournals($linkType); $count = $this->repository->countJournals($linkType);
$moveTo = []; $moveTo = [];
$moveTo[0] = (string)trans('firefly.do_not_save_connection'); $moveTo[0] = (string) trans('firefly.do_not_save_connection');
/** @var LinkType $otherType */ /** @var LinkType $otherType */
foreach ($otherTypes as $otherType) { foreach ($otherTypes as $otherType) {
@@ -130,10 +130,10 @@ class LinkController extends Controller
{ {
Log::channel('audit')->info(sprintf('User destroyed link type #%d', $linkType->id)); Log::channel('audit')->info(sprintf('User destroyed link type #%d', $linkType->id));
$name = $linkType->name; $name = $linkType->name;
$moveTo = $this->repository->find((int)$request->get('move_link_type_before_delete')); $moveTo = $this->repository->find((int) $request->get('move_link_type_before_delete'));
$this->repository->destroy($linkType, $moveTo); $this->repository->destroy($linkType, $moveTo);
$request->session()->flash('success', (string)trans('firefly.deleted_link_type', ['name' => $name])); $request->session()->flash('success', (string) trans('firefly.deleted_link_type', ['name' => $name]));
app('preferences')->mark(); app('preferences')->mark();
return redirect($this->getPreviousUri('link-types.delete.uri')); return redirect($this->getPreviousUri('link-types.delete.uri'));
@@ -150,11 +150,11 @@ class LinkController extends Controller
public function edit(Request $request, LinkType $linkType) public function edit(Request $request, LinkType $linkType)
{ {
if (!$linkType->editable) { if (!$linkType->editable) {
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)])); $request->session()->flash('error', (string) trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)]));
return redirect(route('admin.links.index')); return redirect(route('admin.links.index'));
} }
$subTitle = (string)trans('firefly.edit_link_type', ['name' => $linkType->name]); $subTitle = (string) trans('firefly.edit_link_type', ['name' => $linkType->name]);
$subTitleIcon = 'fa-link'; $subTitleIcon = 'fa-link';
Log::channel('audit')->info(sprintf('User wants to edit link type #%d', $linkType->id)); Log::channel('audit')->info(sprintf('User wants to edit link type #%d', $linkType->id));
@@ -175,7 +175,7 @@ class LinkController extends Controller
*/ */
public function index() public function index()
{ {
$subTitle = (string)trans('firefly.journal_link_configuration'); $subTitle = (string) trans('firefly.journal_link_configuration');
$subTitleIcon = 'fa-link'; $subTitleIcon = 'fa-link';
$linkTypes = $this->repository->get(); $linkTypes = $this->repository->get();
@@ -198,7 +198,7 @@ class LinkController extends Controller
*/ */
public function show(LinkType $linkType) public function show(LinkType $linkType)
{ {
$subTitle = (string)trans('firefly.overview_for_link', ['name' => $linkType->name]); $subTitle = (string) trans('firefly.overview_for_link', ['name' => $linkType->name]);
$subTitleIcon = 'fa-link'; $subTitleIcon = 'fa-link';
$links = $this->repository->getJournalLinks($linkType); $links = $this->repository->getJournalLinks($linkType);
@@ -225,9 +225,9 @@ class LinkController extends Controller
Log::channel('audit')->info('User stored new link type.', $linkType->toArray()); Log::channel('audit')->info('User stored new link type.', $linkType->toArray());
$request->session()->flash('success', (string)trans('firefly.stored_new_link_type', ['name' => $linkType->name])); $request->session()->flash('success', (string) trans('firefly.stored_new_link_type', ['name' => $linkType->name]));
$redirect = redirect($this->getPreviousUri('link-types.create.uri')); $redirect = redirect($this->getPreviousUri('link-types.create.uri'));
if (1 === (int)$request->get('create_another')) { if (1 === (int) $request->get('create_another')) {
// set value so create routine will not overwrite URL: // set value so create routine will not overwrite URL:
$request->session()->put('link-types.create.fromStore', true); $request->session()->put('link-types.create.fromStore', true);
@@ -249,7 +249,7 @@ class LinkController extends Controller
public function update(LinkTypeFormRequest $request, LinkType $linkType) public function update(LinkTypeFormRequest $request, LinkType $linkType)
{ {
if (!$linkType->editable) { if (!$linkType->editable) {
$request->session()->flash('error', (string)trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)])); $request->session()->flash('error', (string) trans('firefly.cannot_edit_link_type', ['name' => e($linkType->name)]));
return redirect(route('admin.links.index')); return redirect(route('admin.links.index'));
} }
@@ -263,10 +263,10 @@ class LinkController extends Controller
Log::channel('audit')->info(sprintf('User update link type #%d.', $linkType->id), $data); Log::channel('audit')->info(sprintf('User update link type #%d.', $linkType->id), $data);
$request->session()->flash('success', (string)trans('firefly.updated_link_type', ['name' => $linkType->name])); $request->session()->flash('success', (string) trans('firefly.updated_link_type', ['name' => $linkType->name]));
app('preferences')->mark(); app('preferences')->mark();
$redirect = redirect($this->getPreviousUri('link-types.edit.uri')); $redirect = redirect($this->getPreviousUri('link-types.edit.uri'));
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int) $request->get('return_to_edit')) {
// set value so edit routine will not overwrite URL: // set value so edit routine will not overwrite URL:
$request->session()->put('link-types.edit.fromUpdate', true); $request->session()->put('link-types.edit.fromUpdate', true);

View File

@@ -47,7 +47,7 @@ class UpdateController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
static function ($request, $next) { static function ($request, $next) {
app('view')->share('title', (string)trans('firefly.administration')); app('view')->share('title', (string) trans('firefly.administration'));
app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
return $next($request); return $next($request);
@@ -64,22 +64,22 @@ class UpdateController extends Controller
*/ */
public function index() public function index()
{ {
$subTitle = (string)trans('firefly.update_check_title'); $subTitle = (string) trans('firefly.update_check_title');
$subTitleIcon = 'fa-star'; $subTitleIcon = 'fa-star';
$permission = app('fireflyconfig')->get('permission_update_check', -1); $permission = app('fireflyconfig')->get('permission_update_check', -1);
$channel = app('fireflyconfig')->get('update_channel', 'stable'); $channel = app('fireflyconfig')->get('update_channel', 'stable');
$selected = $permission->data; $selected = $permission->data;
$channelSelected = $channel->data; $channelSelected = $channel->data;
$options = [ $options = [
-1 => (string)trans('firefly.updates_ask_me_later'), -1 => (string) trans('firefly.updates_ask_me_later'),
0 => (string)trans('firefly.updates_do_not_check'), 0 => (string) trans('firefly.updates_do_not_check'),
1 => (string)trans('firefly.updates_enable_check'), 1 => (string) trans('firefly.updates_enable_check'),
]; ];
$channelOptions = [ $channelOptions = [
'stable' => (string)trans('firefly.update_channel_stable'), 'stable' => (string) trans('firefly.update_channel_stable'),
'beta' => (string)trans('firefly.update_channel_beta'), 'beta' => (string) trans('firefly.update_channel_beta'),
'alpha' => (string)trans('firefly.update_channel_alpha'), 'alpha' => (string) trans('firefly.update_channel_alpha'),
]; ];
return view('admin.update.index', compact('subTitle', 'subTitleIcon', 'selected', 'options', 'channelSelected', 'channelOptions')); return view('admin.update.index', compact('subTitle', 'subTitleIcon', 'selected', 'options', 'channelSelected', 'channelOptions'));
@@ -94,14 +94,14 @@ class UpdateController extends Controller
*/ */
public function post(Request $request) public function post(Request $request)
{ {
$checkForUpdates = (int)$request->get('check_for_updates'); $checkForUpdates = (int) $request->get('check_for_updates');
$channel = $request->get('update_channel'); $channel = $request->get('update_channel');
$channel = in_array($channel, ['stable', 'beta', 'alpha'], true) ? $channel : 'stable'; $channel = in_array($channel, ['stable', 'beta', 'alpha'], true) ? $channel : 'stable';
app('fireflyconfig')->set('permission_update_check', $checkForUpdates); app('fireflyconfig')->set('permission_update_check', $checkForUpdates);
app('fireflyconfig')->set('last_update_check', time()); app('fireflyconfig')->set('last_update_check', time());
app('fireflyconfig')->set('update_channel', $channel); app('fireflyconfig')->set('update_channel', $channel);
session()->flash('success', (string)trans('firefly.configuration_updated')); session()->flash('success', (string) trans('firefly.configuration_updated'));
return redirect(route('admin.update-check')); return redirect(route('admin.update-check'));
} }

View File

@@ -51,7 +51,7 @@ class UserController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.administration')); app('view')->share('title', (string) trans('firefly.administration'));
app('view')->share('mainTitleIcon', 'fa-hand-spock-o'); app('view')->share('mainTitleIcon', 'fa-hand-spock-o');
$this->repository = app(UserRepositoryInterface::class); $this->repository = app(UserRepositoryInterface::class);
@@ -77,7 +77,7 @@ class UserController extends Controller
return redirect(route('admin.users')); return redirect(route('admin.users'));
} }
$subTitle = (string)trans('firefly.delete_user', ['email' => $user->email]); $subTitle = (string) trans('firefly.delete_user', ['email' => $user->email]);
return view('admin.users.delete', compact('user', 'subTitle')); return view('admin.users.delete', compact('user', 'subTitle'));
} }
@@ -97,7 +97,7 @@ class UserController extends Controller
return redirect(route('admin.users')); return redirect(route('admin.users'));
} }
$this->repository->destroy($user); $this->repository->destroy($user);
session()->flash('success', (string)trans('firefly.user_deleted')); session()->flash('success', (string) trans('firefly.user_deleted'));
return redirect(route('admin.users')); return redirect(route('admin.users'));
} }
@@ -121,15 +121,15 @@ class UserController extends Controller
} }
session()->forget('users.edit.fromUpdate'); session()->forget('users.edit.fromUpdate');
$subTitle = (string)trans('firefly.edit_user', ['email' => $user->email]); $subTitle = (string) trans('firefly.edit_user', ['email' => $user->email]);
$subTitleIcon = 'fa-user-o'; $subTitleIcon = 'fa-user-o';
$currentUser = auth()->user(); $currentUser = auth()->user();
$isAdmin = $this->repository->hasRole($user, 'owner'); $isAdmin = $this->repository->hasRole($user, 'owner');
$codes = [ $codes = [
'' => (string)trans('firefly.no_block_code'), '' => (string) trans('firefly.no_block_code'),
'bounced' => (string)trans('firefly.block_code_bounced'), 'bounced' => (string) trans('firefly.block_code_bounced'),
'expired' => (string)trans('firefly.block_code_expired'), 'expired' => (string) trans('firefly.block_code_expired'),
'email_changed' => (string)trans('firefly.block_code_email_changed'), 'email_changed' => (string) trans('firefly.block_code_email_changed'),
]; ];
return view('admin.users.edit', compact('user', 'canEditDetails', 'subTitle', 'subTitleIcon', 'codes', 'currentUser', 'isAdmin')); return view('admin.users.edit', compact('user', 'canEditDetails', 'subTitle', 'subTitleIcon', 'codes', 'currentUser', 'isAdmin'));
@@ -142,7 +142,7 @@ class UserController extends Controller
*/ */
public function index() public function index()
{ {
$subTitle = (string)trans('firefly.user_administration'); $subTitle = (string) trans('firefly.user_administration');
$subTitleIcon = 'fa-users'; $subTitleIcon = 'fa-users';
$users = $this->repository->all(); $users = $this->repository->all();
@@ -166,9 +166,9 @@ class UserController extends Controller
*/ */
public function show(User $user) public function show(User $user)
{ {
$title = (string)trans('firefly.administration'); $title = (string) trans('firefly.administration');
$mainTitleIcon = 'fa-hand-spock-o'; $mainTitleIcon = 'fa-hand-spock-o';
$subTitle = (string)trans('firefly.single_user_administration', ['email' => $user->email]); $subTitle = (string) trans('firefly.single_user_administration', ['email' => $user->email]);
$subTitleIcon = 'fa-user'; $subTitleIcon = 'fa-user';
$information = $this->repository->getUserData($user); $information = $this->repository->getUserData($user);
@@ -215,10 +215,10 @@ class UserController extends Controller
$this->repository->changeStatus($user, $data['blocked'], $data['blocked_code']); $this->repository->changeStatus($user, $data['blocked'], $data['blocked_code']);
$this->repository->updateEmail($user, $data['email']); $this->repository->updateEmail($user, $data['email']);
session()->flash('success', (string)trans('firefly.updated_user', ['email' => $user->email])); session()->flash('success', (string) trans('firefly.updated_user', ['email' => $user->email]));
app('preferences')->mark(); app('preferences')->mark();
$redirect = redirect($this->getPreviousUri('users.edit.uri')); $redirect = redirect($this->getPreviousUri('users.edit.uri'));
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int) $request->get('return_to_edit')) {
session()->put('users.edit.fromUpdate', true); session()->put('users.edit.fromUpdate', true);

View File

@@ -57,7 +57,7 @@ class AttachmentController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-paperclip'); app('view')->share('mainTitleIcon', 'fa-paperclip');
app('view')->share('title', (string)trans('firefly.attachments')); app('view')->share('title', (string) trans('firefly.attachments'));
$this->repository = app(AttachmentRepositoryInterface::class); $this->repository = app(AttachmentRepositoryInterface::class);
return $next($request); return $next($request);
@@ -74,7 +74,7 @@ class AttachmentController extends Controller
*/ */
public function delete(Attachment $attachment) public function delete(Attachment $attachment)
{ {
$subTitle = (string)trans('firefly.delete_attachment', ['name' => $attachment->filename]); $subTitle = (string) trans('firefly.delete_attachment', ['name' => $attachment->filename]);
// put previous url in session // put previous url in session
$this->rememberPreviousUri('attachments.delete.uri'); $this->rememberPreviousUri('attachments.delete.uri');
@@ -96,7 +96,7 @@ class AttachmentController extends Controller
$this->repository->destroy($attachment); $this->repository->destroy($attachment);
$request->session()->flash('success', (string)trans('firefly.attachment_deleted', ['name' => $name])); $request->session()->flash('success', (string) trans('firefly.attachment_deleted', ['name' => $name]));
app('preferences')->mark(); app('preferences')->mark();
return redirect($this->getPreviousUri('attachments.delete.uri')); return redirect($this->getPreviousUri('attachments.delete.uri'));
@@ -146,7 +146,7 @@ class AttachmentController extends Controller
public function edit(Request $request, Attachment $attachment) public function edit(Request $request, Attachment $attachment)
{ {
$subTitleIcon = 'fa-pencil'; $subTitleIcon = 'fa-pencil';
$subTitle = (string)trans('firefly.edit_attachment', ['name' => $attachment->filename]); $subTitle = (string) trans('firefly.edit_attachment', ['name' => $attachment->filename]);
// put previous url in session if not redirect from store (not "return_to_edit"). // put previous url in session if not redirect from store (not "return_to_edit").
if (true !== session('attachments.edit.fromUpdate')) { if (true !== session('attachments.edit.fromUpdate')) {
@@ -193,11 +193,11 @@ class AttachmentController extends Controller
$data = $request->getAttachmentData(); $data = $request->getAttachmentData();
$this->repository->update($attachment, $data); $this->repository->update($attachment, $data);
$request->session()->flash('success', (string)trans('firefly.attachment_updated', ['name' => $attachment->filename])); $request->session()->flash('success', (string) trans('firefly.attachment_updated', ['name' => $attachment->filename]));
app('preferences')->mark(); app('preferences')->mark();
$redirect = redirect($this->getPreviousUri('attachments.edit.uri')); $redirect = redirect($this->getPreviousUri('attachments.edit.uri'));
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int) $request->get('return_to_edit')) {
$request->session()->put('attachments.edit.fromUpdate', true); $request->session()->put('attachments.edit.fromUpdate', true);

View File

@@ -86,14 +86,14 @@ class ForgotPasswordController extends Controller
$user = User::where('email', $request->get('email'))->first(); $user = User::where('email', $request->get('email'))->first();
if (null !== $user && $repository->hasRole($user, 'demo')) { if (null !== $user && $repository->hasRole($user, 'demo')) {
return back()->withErrors(['email' => (string)trans('firefly.cannot_reset_demo_user')]); return back()->withErrors(['email' => (string) trans('firefly.cannot_reset_demo_user')]);
} }
// We will send the password reset link to this user. Once we have attempted // 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 // 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. // 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) { if ('passwords.throttled' === $result) {
Log::error(sprintf('Cowardly refuse to send a password reset message to user #%d because the reset button has been throttled.', $user->id)); Log::error(sprintf('Cowardly refuse to send a password reset message to user #%d because the reset button has been throttled.', $user->id));
} }
@@ -124,7 +124,7 @@ class ForgotPasswordController extends Controller
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data; $singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
$userCount = User::count(); $userCount = User::count();
$allowRegistration = true; $allowRegistration = true;
$pageTitle = (string)trans('firefly.forgot_pw_page_title'); $pageTitle = (string) trans('firefly.forgot_pw_page_title');
if (true === $singleUserMode && $userCount > 0) { if (true === $singleUserMode && $userCount > 0) {
$allowRegistration = false; $allowRegistration = false;
} }

View File

@@ -128,6 +128,37 @@ class LoginController extends Controller
$this->sendFailedLoginResponse($request); $this->sendFailedLoginResponse($request);
} }
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return $this->username;
}
/**
* Get the failed login response instance.
*
* @param Request $request
*
* @return void
*
* @throws ValidationException
*/
protected function sendFailedLoginResponse(Request $request)
{
$exception = ValidationException::withMessages(
[
$this->username() => [trans('auth.failed')],
]
);
$exception->redirectTo = route('login');
throw $exception;
}
/** /**
* Log the user out of the application. * Log the user out of the application.
* *
@@ -165,27 +196,6 @@ class LoginController extends Controller
: redirect('/'); : redirect('/');
} }
/**
* Get the failed login response instance.
*
* @param Request $request
*
* @return void
*
* @throws ValidationException
*/
protected function sendFailedLoginResponse(Request $request)
{
$exception = ValidationException::withMessages(
[
$this->username() => [trans('auth.failed')],
]
);
$exception->redirectTo = route('login');
throw $exception;
}
/** /**
* Show the application's login form. * Show the application's login form.
* *
@@ -200,7 +210,7 @@ class LoginController extends Controller
$count = DB::table('users')->count(); $count = DB::table('users')->count();
$guard = config('auth.defaults.guard'); $guard = config('auth.defaults.guard');
$title = (string)trans('firefly.login_page_title'); $title = (string) trans('firefly.login_page_title');
if (0 === $count && 'web' === $guard) { if (0 === $count && 'web' === $guard) {
return redirect(route('register')); return redirect(route('register'));
@@ -232,14 +242,4 @@ class LoginController extends Controller
return view('auth.login', compact('allowRegistration', 'email', 'remember', 'allowReset', 'title', 'usernameField')); return view('auth.login', compact('allowRegistration', 'email', 'remember', 'allowReset', 'title', 'usernameField'));
} }
/**
* Get the login username to be used by the controller.
*
* @return string
*/
public function username()
{
return $this->username;
}
} }

View File

@@ -100,13 +100,36 @@ class RegisterController extends Controller
$this->guard()->login($user); $this->guard()->login($user);
session()->flash('success', (string)trans('firefly.registered')); session()->flash('success', (string) trans('firefly.registered'));
$this->registered($request, $user); $this->registered($request, $user);
return redirect($this->redirectPath()); return redirect($this->redirectPath());
} }
/**
* @return bool
*/
protected function allowedToRegister(): bool
{
// is allowed to register?
$allowRegistration = true;
try {
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
$singleUserMode = true;
}
$userCount = User::count();
$guard = config('auth.defaults.guard');
if (true === $singleUserMode && $userCount > 0 && 'web' === $guard) {
$allowRegistration = false;
}
if ('web' !== $guard) {
$allowRegistration = false;
}
return $allowRegistration;
}
/** /**
* Show the application registration form. * Show the application registration form.
* *
@@ -118,7 +141,7 @@ class RegisterController extends Controller
public function showRegistrationForm(Request $request) public function showRegistrationForm(Request $request)
{ {
$isDemoSite = app('fireflyconfig')->get('is_demo_site', config('firefly.configuration.is_demo_site'))->data; $isDemoSite = app('fireflyconfig')->get('is_demo_site', config('firefly.configuration.is_demo_site'))->data;
$pageTitle = (string)trans('firefly.register_page_title'); $pageTitle = (string) trans('firefly.register_page_title');
$allowRegistration = $this->allowedToRegister(); $allowRegistration = $this->allowedToRegister();
if (false === $allowRegistration) { if (false === $allowRegistration) {
@@ -131,26 +154,4 @@ class RegisterController extends Controller
return view('auth.register', compact('isDemoSite', 'email', 'pageTitle')); return view('auth.register', compact('isDemoSite', 'email', 'pageTitle'));
} }
/**
* @return bool
*/
protected function allowedToRegister(): bool {
// is allowed to register?
$allowRegistration = true;
try {
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
} catch (ContainerExceptionInterface|NotFoundExceptionInterface $e) {
$singleUserMode = true;
}
$userCount = User::count();
$guard = config('auth.defaults.guard');
if (true === $singleUserMode && $userCount > 0 && 'web' === $guard) {
$allowRegistration = false;
}
if('web' !== $guard) {
$allowRegistration = false;
}
return $allowRegistration;
}
} }

View File

@@ -137,7 +137,7 @@ class ResetPasswordController extends Controller
$singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data; $singleUserMode = app('fireflyconfig')->get('single_user_mode', config('firefly.configuration.single_user_mode'))->data;
$userCount = User::count(); $userCount = User::count();
$allowRegistration = true; $allowRegistration = true;
$pageTitle = (string)trans('firefly.reset_pw_page_title'); $pageTitle = (string) trans('firefly.reset_pw_page_title');
if (true === $singleUserMode && $userCount > 0) { if (true === $singleUserMode && $userCount > 0) {
$allowRegistration = false; $allowRegistration = false;
} }

View File

@@ -47,7 +47,7 @@ class TwoFactorController extends Controller
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
$siteOwner = config('firefly.site_owner'); $siteOwner = config('firefly.site_owner');
$title = (string)trans('firefly.two_factor_forgot_title'); $title = (string) trans('firefly.two_factor_forgot_title');
return view('auth.lost-two-factor', compact('user', 'siteOwner', 'title')); return view('auth.lost-two-factor', compact('user', 'siteOwner', 'title'));
} }
@@ -61,7 +61,7 @@ class TwoFactorController extends Controller
{ {
/** @var array $mfaHistory */ /** @var array $mfaHistory */
$mfaHistory = Preferences::get('mfa_history', [])->data; $mfaHistory = Preferences::get('mfa_history', [])->data;
$mfaCode = (string)$request->get('one_time_password'); $mfaCode = (string) $request->get('one_time_password');
// is in history? then refuse to use it. // is in history? then refuse to use it.
if ($this->inMFAHistory($mfaCode, $mfaHistory)) { if ($this->inMFAHistory($mfaCode, $mfaHistory)) {

View File

@@ -54,7 +54,7 @@ class CreateController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.bills')); app('view')->share('title', (string) trans('firefly.bills'));
app('view')->share('mainTitleIcon', 'fa-calendar-o'); app('view')->share('mainTitleIcon', 'fa-calendar-o');
$this->attachments = app(AttachmentHelperInterface::class); $this->attachments = app(AttachmentHelperInterface::class);
$this->repository = app(BillRepositoryInterface::class); $this->repository = app(BillRepositoryInterface::class);
@@ -77,9 +77,9 @@ class CreateController extends Controller
/** @var array $billPeriods */ /** @var array $billPeriods */
$billPeriods = config('firefly.bill_periods'); $billPeriods = config('firefly.bill_periods');
foreach ($billPeriods as $current) { foreach ($billPeriods as $current) {
$periods[$current] = (string)trans('firefly.repeat_freq_' . $current); $periods[$current] = (string) trans('firefly.repeat_freq_' . $current);
} }
$subTitle = (string)trans('firefly.create_new_bill'); $subTitle = (string) trans('firefly.create_new_bill');
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
// put previous url in session if not redirect from store (not "create another"). // put previous url in session if not redirect from store (not "create another").
@@ -101,18 +101,18 @@ class CreateController extends Controller
*/ */
public function store(BillStoreRequest $request): RedirectResponse public function store(BillStoreRequest $request): RedirectResponse
{ {
$billData = $request->getBillData(); $billData = $request->getBillData();
$billData['active'] = true; $billData['active'] = true;
try { try {
$bill = $this->repository->store($billData); $bill = $this->repository->store($billData);
} catch (FireflyException $e) { } catch (FireflyException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
$request->session()->flash('error', (string)trans('firefly.bill_store_error')); $request->session()->flash('error', (string) trans('firefly.bill_store_error'));
return redirect(route('bills.create'))->withInput(); return redirect(route('bills.create'))->withInput();
} }
$request->session()->flash('success', (string)trans('firefly.stored_new_bill', ['name' => $bill->name])); $request->session()->flash('success', (string) trans('firefly.stored_new_bill', ['name' => $bill->name]));
app('preferences')->mark(); app('preferences')->mark();
/** @var array $files */ /** @var array $files */
@@ -121,7 +121,7 @@ class CreateController extends Controller
$this->attachments->saveAttachmentsForModel($bill, $files); $this->attachments->saveAttachmentsForModel($bill, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {

View File

@@ -53,7 +53,7 @@ class DeleteController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.bills')); app('view')->share('title', (string) trans('firefly.bills'));
app('view')->share('mainTitleIcon', 'fa-calendar-o'); app('view')->share('mainTitleIcon', 'fa-calendar-o');
$this->repository = app(BillRepositoryInterface::class); $this->repository = app(BillRepositoryInterface::class);
@@ -73,7 +73,7 @@ class DeleteController extends Controller
{ {
// put previous url in session // put previous url in session
$this->rememberPreviousUri('bills.delete.uri'); $this->rememberPreviousUri('bills.delete.uri');
$subTitle = (string)trans('firefly.delete_bill', ['name' => $bill->name]); $subTitle = (string) trans('firefly.delete_bill', ['name' => $bill->name]);
return view('bills.delete', compact('bill', 'subTitle')); return view('bills.delete', compact('bill', 'subTitle'));
} }
@@ -91,7 +91,7 @@ class DeleteController extends Controller
$name = $bill->name; $name = $bill->name;
$this->repository->destroy($bill); $this->repository->destroy($bill);
$request->session()->flash('success', (string)trans('firefly.deleted_bill', ['name' => $name])); $request->session()->flash('success', (string) trans('firefly.deleted_bill', ['name' => $name]));
app('preferences')->mark(); app('preferences')->mark();
return redirect($this->getPreviousUri('bills.delete.uri')); return redirect($this->getPreviousUri('bills.delete.uri'));

View File

@@ -55,7 +55,7 @@ class IndexController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.bills')); app('view')->share('title', (string) trans('firefly.bills'));
app('view')->share('mainTitleIcon', 'fa-calendar-o'); app('view')->share('mainTitleIcon', 'fa-calendar-o');
$this->repository = app(BillRepositoryInterface::class); $this->repository = app(BillRepositoryInterface::class);
@@ -92,14 +92,14 @@ class IndexController extends Controller
$bills = [ $bills = [
0 => [ // the index is the order, not the ID. 0 => [ // the index is the order, not the ID.
'object_group_id' => 0, 'object_group_id' => 0,
'object_group_title' => (string)trans('firefly.default_group_title_name'), 'object_group_title' => (string) trans('firefly.default_group_title_name'),
'bills' => [], 'bills' => [],
], ],
]; ];
/** @var Bill $bill */ /** @var Bill $bill */
foreach ($collection as $bill) { foreach ($collection as $bill) {
$array = $transformer->transform($bill); $array = $transformer->transform($bill);
$groupOrder = (int)$array['object_group_order']; $groupOrder = (int) $array['object_group_order'];
// make group array if necessary: // make group array if necessary:
$bills[$groupOrder] = $bills[$groupOrder] ?? [ $bills[$groupOrder] = $bills[$groupOrder] ?? [
'object_group_id' => $array['object_group_id'], 'object_group_id' => $array['object_group_id'],
@@ -136,9 +136,9 @@ class IndexController extends Controller
// summarise per currency / per group. // summarise per currency / per group.
$sums = $this->getSums($bills); $sums = $this->getSums($bills);
$totals = $this->getTotals($sums); $totals = $this->getTotals($sums);
$today = now()->startOfDay(); $today = now()->startOfDay();
return view('bills.index', compact('bills', 'sums', 'total', 'totals','today')); return view('bills.index', compact('bills', 'sums', 'total', 'totals', 'today'));
} }
/** /**
@@ -173,8 +173,8 @@ class IndexController extends Controller
]; ];
// only fill in avg when bill is active. // only fill in avg when bill is active.
if (count($bill['pay_dates']) > 0) { if (count($bill['pay_dates']) > 0) {
$avg = bcdiv(bcadd((string)$bill['amount_min'], (string)$bill['amount_max']), '2'); $avg = bcdiv(bcadd((string) $bill['amount_min'], (string) $bill['amount_max']), '2');
$avg = bcmul($avg, (string)count($bill['pay_dates'])); $avg = bcmul($avg, (string) count($bill['pay_dates']));
$sums[$groupOrder][$currencyId]['avg'] = bcadd($sums[$groupOrder][$currencyId]['avg'], $avg); $sums[$groupOrder][$currencyId]['avg'] = bcadd($sums[$groupOrder][$currencyId]['avg'], $avg);
} }
// fill in per period regardless: // fill in per period regardless:
@@ -193,7 +193,7 @@ class IndexController extends Controller
*/ */
private function amountPerPeriod(array $bill, string $range): string 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');
Log::debug(sprintf('Amount per period for bill #%d "%s"', $bill['id'], $bill['name'])); Log::debug(sprintf('Amount per period for bill #%d "%s"', $bill['id'], $bill['name']));
Log::debug(sprintf('Average is %s', $avg)); Log::debug(sprintf('Average is %s', $avg));
@@ -204,10 +204,10 @@ class IndexController extends Controller
'quarterly' => '4', 'quarterly' => '4',
'monthly' => '12', 'monthly' => '12',
'weekly' => '52.17', 'weekly' => '52.17',
'daily' => '365.24', 'daily' => '365.24',
]; ];
$yearAmount = bcmul($avg, bcdiv($multiplies[$bill['repeat_freq']], (string)($bill['skip'] + 1))); $yearAmount = bcmul($avg, bcdiv($multiplies[$bill['repeat_freq']], (string) ($bill['skip'] + 1)));
Log::debug(sprintf('Amount per year is %s (%s * %s / %s)', $yearAmount, $avg, $multiplies[$bill['repeat_freq']], (string)($bill['skip'] + 1))); Log::debug(sprintf('Amount per year is %s (%s * %s / %s)', $yearAmount, $avg, $multiplies[$bill['repeat_freq']], (string) ($bill['skip'] + 1)));
// per period: // per period:
$division = [ $division = [
@@ -273,8 +273,8 @@ class IndexController extends Controller
*/ */
public function setOrder(Request $request, Bill $bill): JsonResponse public function setOrder(Request $request, Bill $bill): JsonResponse
{ {
$objectGroupTitle = (string)$request->get('objectGroupTitle'); $objectGroupTitle = (string) $request->get('objectGroupTitle');
$newOrder = (int)$request->get('order'); $newOrder = (int) $request->get('order');
$this->repository->setOrder($bill, $newOrder); $this->repository->setOrder($bill, $newOrder);
if ('' !== $objectGroupTitle) { if ('' !== $objectGroupTitle) {
$this->repository->setObjectGroup($bill, $objectGroupTitle); $this->repository->setObjectGroup($bill, $objectGroupTitle);

View File

@@ -63,7 +63,7 @@ class ShowController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.bills')); app('view')->share('title', (string) trans('firefly.bills'));
app('view')->share('mainTitleIcon', 'fa-calendar-o'); app('view')->share('mainTitleIcon', 'fa-calendar-o');
$this->repository = app(BillRepositoryInterface::class); $this->repository = app(BillRepositoryInterface::class);
@@ -84,7 +84,7 @@ class ShowController extends Controller
{ {
$total = 0; $total = 0;
if (false === $bill->active) { if (false === $bill->active) {
$request->session()->flash('warning', (string)trans('firefly.cannot_scan_inactive_bill')); $request->session()->flash('warning', (string) trans('firefly.cannot_scan_inactive_bill'));
return redirect(route('bills.show', [$bill->id])); return redirect(route('bills.show', [$bill->id]));
} }
@@ -94,7 +94,7 @@ class ShowController extends Controller
$total = 0; $total = 0;
} }
if (0 === $set->count()) { if (0 === $set->count()) {
$request->session()->flash('error', (string)trans('firefly.no_rules_for_bill')); $request->session()->flash('error', (string) trans('firefly.no_rules_for_bill'));
return redirect(route('bills.show', [$bill->id])); return redirect(route('bills.show', [$bill->id]));
} }
@@ -110,7 +110,7 @@ class ShowController extends Controller
// file the rule(s) // file the rule(s)
$ruleEngine->fire(); $ruleEngine->fire();
$request->session()->flash('success', (string)trans_choice('firefly.rescanned_bill', $total)); $request->session()->flash('success', (string) trans_choice('firefly.rescanned_bill', $total));
app('preferences')->mark(); app('preferences')->mark();
return redirect(route('bills.show', [$bill->id])); return redirect(route('bills.show', [$bill->id]));
@@ -135,8 +135,8 @@ class ShowController extends Controller
/** @var Carbon $end */ /** @var Carbon $end */
$end = session('end'); $end = session('end');
$year = $start->year; $year = $start->year;
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$yearAverage = $this->repository->getYearAverage($bill, $start); $yearAverage = $this->repository->getYearAverage($bill, $start);
$overallAverage = $this->repository->getOverallAverage($bill); $overallAverage = $this->repository->getOverallAverage($bill);
$manager = new Manager(); $manager = new Manager();

View File

@@ -59,7 +59,7 @@ class AvailableBudgetController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('title', (string) trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->abRepository = app(AvailableBudgetRepositoryInterface::class); $this->abRepository = app(AvailableBudgetRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class);
@@ -96,7 +96,7 @@ class AvailableBudgetController extends Controller
return redirect(route('available-budgets.edit', [$first->id])); return redirect(route('available-budgets.edit', [$first->id]));
} }
$page = (int)($request->get('page') ?? 1); $page = (int) ($request->get('page') ?? 1);
return view('budgets.available-budgets.create', compact('start', 'end', 'page', 'currency')); return view('budgets.available-budgets.create', compact('start', 'end', 'page', 'currency'));
} }
@@ -128,7 +128,7 @@ class AvailableBudgetController extends Controller
return true; return true;
} }
); );
$page = (int)($request->get('page') ?? 1); $page = (int) ($request->get('page') ?? 1);
return view('budgets.available-budgets.create-alternative', compact('start', 'end', 'page', 'currencies')); return view('budgets.available-budgets.create-alternative', compact('start', 'end', 'page', 'currencies'));
} }
@@ -140,7 +140,7 @@ class AvailableBudgetController extends Controller
*/ */
public function delete(Request $request) public function delete(Request $request)
{ {
$id = (int)$request->get('id'); $id = (int) $request->get('id');
if (0 !== $id) { if (0 !== $id) {
$availableBudget = $this->abRepository->findById($id); $availableBudget = $this->abRepository->findById($id);
if (null !== $availableBudget) { if (null !== $availableBudget) {
@@ -162,7 +162,7 @@ class AvailableBudgetController extends Controller
*/ */
public function edit(AvailableBudget $availableBudget, Carbon $start, Carbon $end) public function edit(AvailableBudget $availableBudget, Carbon $start, Carbon $end)
{ {
$availableBudget->amount = number_format((float)$availableBudget->amount, $availableBudget->transactionCurrency->decimal_places, '.', ''); $availableBudget->amount = number_format((float) $availableBudget->amount, $availableBudget->transactionCurrency->decimal_places, '.', '');
return view('budgets.available-budgets.edit', compact('availableBudget', 'start', 'end')); return view('budgets.available-budgets.edit', compact('availableBudget', 'start', 'end'));
} }
@@ -185,7 +185,7 @@ class AvailableBudgetController extends Controller
} }
// validate amount // validate amount
$amount = (string)$request->get('amount'); $amount = (string) $request->get('amount');
if ('' === $amount) { if ('' === $amount) {
session()->flash('error', trans('firefly.invalid_amount')); session()->flash('error', trans('firefly.invalid_amount'));
@@ -198,7 +198,7 @@ class AvailableBudgetController extends Controller
} }
// find currency // find currency
$currency = $this->currencyRepos->find((int)$request->get('currency_id')); $currency = $this->currencyRepos->find((int) $request->get('currency_id'));
if (null === $currency) { if (null === $currency) {
session()->flash('error', trans('firefly.invalid_currency')); session()->flash('error', trans('firefly.invalid_currency'));
@@ -239,7 +239,7 @@ class AvailableBudgetController extends Controller
public function update(Request $request, AvailableBudget $availableBudget, Carbon $start, Carbon $end) public function update(Request $request, AvailableBudget $availableBudget, Carbon $start, Carbon $end)
{ {
// validate amount // validate amount
$amount = (string)$request->get('amount'); $amount = (string) $request->get('amount');
if ('' === $amount) { if ('' === $amount) {
session()->flash('error', trans('firefly.invalid_amount')); session()->flash('error', trans('firefly.invalid_amount'));

View File

@@ -65,7 +65,7 @@ class BudgetLimitController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('title', (string) trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->repository = app(BudgetRepositoryInterface::class); $this->repository = app(BudgetRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class);
@@ -130,14 +130,14 @@ class BudgetLimitController extends Controller
{ {
Log::debug('Going to store new budget-limit.', $request->all()); Log::debug('Going to store new budget-limit.', $request->all());
// first search for existing one and update it if necessary. // first search for existing one and update it if necessary.
$currency = $this->currencyRepos->find((int)$request->get('transaction_currency_id')); $currency = $this->currencyRepos->find((int) $request->get('transaction_currency_id'));
$budget = $this->repository->find((int)$request->get('budget_id')); $budget = $this->repository->find((int) $request->get('budget_id'));
if (null === $currency || null === $budget) { if (null === $currency || null === $budget) {
throw new FireflyException('No valid currency or budget.'); throw new FireflyException('No valid currency or budget.');
} }
$start = Carbon::createFromFormat('Y-m-d', $request->get('start')); $start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end')); $end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
$amount = (string)$request->get('amount'); $amount = (string) $request->get('amount');
$start->startOfDay(); $start->startOfDay();
$end->startOfDay(); $end->startOfDay();
@@ -156,7 +156,7 @@ class BudgetLimitController extends Controller
$limit = $this->blRepository->store( $limit = $this->blRepository->store(
[ [
'budget_id' => $request->get('budget_id'), 'budget_id' => $request->get('budget_id'),
'currency_id' => (int)$request->get('transaction_currency_id'), 'currency_id' => (int) $request->get('transaction_currency_id'),
'start_date' => $start, 'start_date' => $start,
'end_date' => $end, 'end_date' => $end,
'amount' => $amount, 'amount' => $amount,
@@ -171,7 +171,7 @@ class BudgetLimitController extends Controller
$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0'; $array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount'])); $array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); $array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string)$this->activeDaysLeft($start, $end); $array['days_left'] = (string) $this->activeDaysLeft($start, $end);
// left per day: // 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']);
@@ -192,7 +192,7 @@ class BudgetLimitController extends Controller
*/ */
public function update(Request $request, BudgetLimit $budgetLimit): JsonResponse public function update(Request $request, BudgetLimit $budgetLimit): JsonResponse
{ {
$amount = (string)$request->get('amount'); $amount = (string) $request->get('amount');
if ('' === $amount) { if ('' === $amount) {
$amount = '0'; $amount = '0';
} }
@@ -210,12 +210,12 @@ class BudgetLimitController extends Controller
$array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0'; $array['spent'] = $spentArr[$budgetLimit->transactionCurrency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount'])); $array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
$array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']); $array['amount_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $limit['amount']);
$array['days_left'] = (string)$this->activeDaysLeft($limit->start_date, $limit->end_date); $array['days_left'] = (string) $this->activeDaysLeft($limit->start_date, $limit->end_date);
// left per day: // 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. // left per day formatted.
$array['amount'] = number_format((float)$limit['amount'], $limit->transactionCurrency->decimal_places, '.', ''); $array['amount'] = number_format((float) $limit['amount'], $limit->transactionCurrency->decimal_places, '.', '');
$array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']); $array['left_per_day_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, $array['left_per_day']);
return response()->json($array); return response()->json($array);

View File

@@ -52,7 +52,7 @@ class CreateController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('title', (string) trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->repository = app(BudgetRepositoryInterface::class); $this->repository = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class); $this->attachments = app(AttachmentHelperInterface::class);
@@ -75,23 +75,23 @@ class CreateController extends Controller
// auto budget types // auto budget types
$autoBudgetTypes = [ $autoBudgetTypes = [
0 => (string)trans('firefly.auto_budget_none'), 0 => (string) trans('firefly.auto_budget_none'),
AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'), AutoBudget::AUTO_BUDGET_RESET => (string) trans('firefly.auto_budget_reset'),
AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'), AutoBudget::AUTO_BUDGET_ROLLOVER => (string) trans('firefly.auto_budget_rollover'),
]; ];
$autoBudgetPeriods = [ $autoBudgetPeriods = [
'daily' => (string)trans('firefly.auto_budget_period_daily'), 'daily' => (string) trans('firefly.auto_budget_period_daily'),
'weekly' => (string)trans('firefly.auto_budget_period_weekly'), 'weekly' => (string) trans('firefly.auto_budget_period_weekly'),
'monthly' => (string)trans('firefly.auto_budget_period_monthly'), 'monthly' => (string) trans('firefly.auto_budget_period_monthly'),
'quarterly' => (string)trans('firefly.auto_budget_period_quarterly'), 'quarterly' => (string) trans('firefly.auto_budget_period_quarterly'),
'half_year' => (string)trans('firefly.auto_budget_period_half_year'), 'half_year' => (string) trans('firefly.auto_budget_period_half_year'),
'yearly' => (string)trans('firefly.auto_budget_period_yearly'), 'yearly' => (string) trans('firefly.auto_budget_period_yearly'),
]; ];
$currency = app('amount')->getDefaultCurrency(); $currency = app('amount')->getDefaultCurrency();
$preFilled = [ $preFilled = [
'auto_budget_period' => $hasOldInput ? (bool)$request->old('auto_budget_period') : 'monthly', '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, 'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id,
]; ];
$request->session()->flash('preFilled', $preFilled); $request->session()->flash('preFilled', $preFilled);
@@ -101,7 +101,7 @@ class CreateController extends Controller
$this->rememberPreviousUri('budgets.create.uri'); $this->rememberPreviousUri('budgets.create.uri');
} }
$request->session()->forget('budgets.create.fromStore'); $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')); return view('budgets.create', compact('subTitle', 'autoBudgetTypes', 'autoBudgetPeriods'));
} }
@@ -120,7 +120,7 @@ class CreateController extends Controller
$budget = $this->repository->store($data); $budget = $this->repository->store($data);
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
$request->session()->flash('success', (string)trans('firefly.stored_new_budget', ['name' => $budget->name])); $request->session()->flash('success', (string) trans('firefly.stored_new_budget', ['name' => $budget->name]));
app('preferences')->mark(); app('preferences')->mark();
// store attachment(s): // store attachment(s):
@@ -129,7 +129,7 @@ class CreateController extends Controller
$this->attachments->saveAttachmentsForModel($budget, $files); $this->attachments->saveAttachmentsForModel($budget, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -138,7 +138,7 @@ class CreateController extends Controller
$redirect = redirect($this->getPreviousUri('budgets.create.uri')); $redirect = redirect($this->getPreviousUri('budgets.create.uri'));
if (1 === (int)$request->get('create_another')) { if (1 === (int) $request->get('create_another')) {
$request->session()->put('budgets.create.fromStore', true); $request->session()->put('budgets.create.fromStore', true);

View File

@@ -52,7 +52,7 @@ class DeleteController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('title', (string) trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->repository = app(BudgetRepositoryInterface::class); $this->repository = app(BudgetRepositoryInterface::class);
@@ -70,7 +70,7 @@ class DeleteController extends Controller
*/ */
public function delete(Budget $budget) public function delete(Budget $budget)
{ {
$subTitle = (string)trans('firefly.delete_budget', ['name' => $budget->name]); $subTitle = (string) trans('firefly.delete_budget', ['name' => $budget->name]);
// put previous url in session // put previous url in session
$this->rememberPreviousUri('budgets.delete.uri'); $this->rememberPreviousUri('budgets.delete.uri');
@@ -90,7 +90,7 @@ class DeleteController extends Controller
{ {
$name = $budget->name; $name = $budget->name;
$this->repository->destroy($budget); $this->repository->destroy($budget);
$request->session()->flash('success', (string)trans('firefly.deleted_budget', ['name' => $name])); $request->session()->flash('success', (string) trans('firefly.deleted_budget', ['name' => $name]));
app('preferences')->mark(); app('preferences')->mark();
return redirect($this->getPreviousUri('budgets.delete.uri')); return redirect($this->getPreviousUri('budgets.delete.uri'));

View File

@@ -56,7 +56,7 @@ class EditController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('title', (string) trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->repository = app(BudgetRepositoryInterface::class); $this->repository = app(BudgetRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class); $this->attachments = app(AttachmentHelperInterface::class);
@@ -76,34 +76,34 @@ class EditController extends Controller
*/ */
public function edit(Request $request, Budget $budget) public function edit(Request $request, Budget $budget)
{ {
$subTitle = (string)trans('firefly.edit_budget', ['name' => $budget->name]); $subTitle = (string) trans('firefly.edit_budget', ['name' => $budget->name]);
$autoBudget = $this->repository->getAutoBudget($budget); $autoBudget = $this->repository->getAutoBudget($budget);
// auto budget types // auto budget types
$autoBudgetTypes = [ $autoBudgetTypes = [
0 => (string)trans('firefly.auto_budget_none'), 0 => (string) trans('firefly.auto_budget_none'),
AutoBudget::AUTO_BUDGET_RESET => (string)trans('firefly.auto_budget_reset'), AutoBudget::AUTO_BUDGET_RESET => (string) trans('firefly.auto_budget_reset'),
AutoBudget::AUTO_BUDGET_ROLLOVER => (string)trans('firefly.auto_budget_rollover'), AutoBudget::AUTO_BUDGET_ROLLOVER => (string) trans('firefly.auto_budget_rollover'),
]; ];
$autoBudgetPeriods = [ $autoBudgetPeriods = [
'daily' => (string)trans('firefly.auto_budget_period_daily'), 'daily' => (string) trans('firefly.auto_budget_period_daily'),
'weekly' => (string)trans('firefly.auto_budget_period_weekly'), 'weekly' => (string) trans('firefly.auto_budget_period_weekly'),
'monthly' => (string)trans('firefly.auto_budget_period_monthly'), 'monthly' => (string) trans('firefly.auto_budget_period_monthly'),
'quarterly' => (string)trans('firefly.auto_budget_period_quarterly'), 'quarterly' => (string) trans('firefly.auto_budget_period_quarterly'),
'half_year' => (string)trans('firefly.auto_budget_period_half_year'), 'half_year' => (string) trans('firefly.auto_budget_period_half_year'),
'yearly' => (string)trans('firefly.auto_budget_period_yearly'), 'yearly' => (string) trans('firefly.auto_budget_period_yearly'),
]; ];
// code to handle active-checkboxes // code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token'); $hasOldInput = null !== $request->old('_token');
$currency = app('amount')->getDefaultCurrency(); $currency = app('amount')->getDefaultCurrency();
$preFilled = [ $preFilled = [
'active' => $hasOldInput ? (bool)$request->old('active') : $budget->active, 'active' => $hasOldInput ? (bool) $request->old('active') : $budget->active,
'auto_budget_currency_id' => $hasOldInput ? (int)$request->old('auto_budget_currency_id') : $currency->id, 'auto_budget_currency_id' => $hasOldInput ? (int) $request->old('auto_budget_currency_id') : $currency->id,
]; ];
if ($autoBudget) { if ($autoBudget) {
$amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount; $amount = $hasOldInput ? $request->old('auto_budget_amount') : $autoBudget->amount;
$preFilled['auto_budget_amount'] = number_format((float)$amount, $autoBudget->transactionCurrency->decimal_places, '.', ''); $preFilled['auto_budget_amount'] = number_format((float) $amount, $autoBudget->transactionCurrency->decimal_places, '.', '');
} }
// put previous url in session if not redirect from store (not "return_to_edit"). // put previous url in session if not redirect from store (not "return_to_edit").
@@ -129,7 +129,7 @@ class EditController extends Controller
$data = $request->getBudgetData(); $data = $request->getBudgetData();
$this->repository->update($budget, $data); $this->repository->update($budget, $data);
$request->session()->flash('success', (string)trans('firefly.updated_budget', ['name' => $budget->name])); $request->session()->flash('success', (string) trans('firefly.updated_budget', ['name' => $budget->name]));
$this->repository->cleanupBudgets(); $this->repository->cleanupBudgets();
app('preferences')->mark(); app('preferences')->mark();
@@ -141,14 +141,14 @@ class EditController extends Controller
$this->attachments->saveAttachmentsForModel($budget, $files); $this->attachments->saveAttachmentsForModel($budget, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
$request->session()->flash('info', $this->attachments->getMessages()->get('attachments')); $request->session()->flash('info', $this->attachments->getMessages()->get('attachments'));
} }
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int) $request->get('return_to_edit')) {
$request->session()->put('budgets.edit.fromUpdate', true); $request->session()->put('budgets.edit.fromUpdate', true);

View File

@@ -68,7 +68,7 @@ class IndexController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('title', (string) trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->repository = app(BudgetRepositoryInterface::class); $this->repository = app(BudgetRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class);
@@ -98,7 +98,7 @@ class IndexController extends Controller
Log::debug('Start of IndexController::index()'); Log::debug('Start of IndexController::index()');
// collect some basic vars: // collect some basic vars:
$range = (string)app('preferences')->get('viewRange', '1M')->data; $range = (string) app('preferences')->get('viewRange', '1M')->data;
$start = $start ?? session('start', Carbon::now()->startOfMonth()); $start = $start ?? session('start', Carbon::now()->startOfMonth());
$end = $end ?? app('navigation')->endOfPeriod($start, $range); $end = $end ?? app('navigation')->endOfPeriod($start, $range);
$defaultCurrency = app('amount')->getDefaultCurrency(); $defaultCurrency = app('amount')->getDefaultCurrency();
@@ -131,7 +131,7 @@ class IndexController extends Controller
// number of days for consistent budgeting. // number of days for consistent budgeting.
$activeDaysPassed = $this->activeDaysPassed($start, $end); // see method description. $activeDaysPassed = $this->activeDaysPassed($start, $end); // see method description.
$activeDaysLeft = $this->activeDaysLeft($start, $end); // see method description. $activeDaysLeft = $this->activeDaysLeft($start, $end); // see method description.
// get all inactive budgets, and simply list them: // get all inactive budgets, and simply list them:
$inactive = $this->repository->getInactiveBudgets(); $inactive = $this->repository->getInactiveBudgets();
@@ -207,7 +207,7 @@ class IndexController extends Controller
$currency = $limit->transactionCurrency ?? $defaultCurrency; $currency = $limit->transactionCurrency ?? $defaultCurrency;
$array['budgeted'][] = [ $array['budgeted'][] = [
'id' => $limit->id, 'id' => $limit->id,
'amount' => number_format((float)$limit->amount, $currency->decimal_places, '.', ''), 'amount' => number_format((float) $limit->amount, $currency->decimal_places, '.', ''),
'start_date' => $limit->start_date->isoFormat($this->monthAndDayFormat), 'start_date' => $limit->start_date->isoFormat($this->monthAndDayFormat),
'end_date' => $limit->end_date->isoFormat($this->monthAndDayFormat), 'end_date' => $limit->end_date->isoFormat($this->monthAndDayFormat),
'in_range' => $limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end), 'in_range' => $limit->start_date->isSameDay($start) && $limit->end_date->isSameDay($end),
@@ -307,7 +307,7 @@ class IndexController extends Controller
$budgetIds = $request->get('budgetIds'); $budgetIds = $request->get('budgetIds');
foreach ($budgetIds as $index => $budgetId) { foreach ($budgetIds as $index => $budgetId) {
$budgetId = (int)$budgetId; $budgetId = (int) $budgetId;
$budget = $repository->find($budgetId); $budget = $repository->find($budgetId);
if (null !== $budget) { if (null !== $budget) {
Log::debug(sprintf('Set budget #%d ("%s") to position %d', $budget->id, $budget->name, $index + 1)); Log::debug(sprintf('Set budget #%d ("%s") to position %d', $budget->id, $budget->name, $index + 1));

View File

@@ -60,7 +60,7 @@ class ShowController extends Controller
parent::__construct(); parent::__construct();
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('title', (string) trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->journalRepos = app(JournalRepositoryInterface::class); $this->journalRepos = app(JournalRepositoryInterface::class);
$this->repository = app(BudgetRepositoryInterface::class); $this->repository = app(BudgetRepositoryInterface::class);
@@ -95,8 +95,8 @@ class ShowController extends Controller
$first = $this->journalRepos->firstNull(); $first = $this->journalRepos->firstNull();
$firstDate = null !== $first ? $first->date : $start; $firstDate = null !== $first ? $first->date : $start;
$periods = $this->getNoBudgetPeriodOverview($firstDate, $end); $periods = $this->getNoBudgetPeriodOverview($firstDate, $end);
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
@@ -119,12 +119,12 @@ class ShowController extends Controller
public function noBudgetAll(Request $request) public function noBudgetAll(Request $request)
{ {
$subTitle = (string)trans('firefly.all_journals_without_budget'); $subTitle = (string) trans('firefly.all_journals_without_budget');
$first = $this->journalRepos->firstNull(); $first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon : $first->date; $start = null === $first ? new Carbon : $first->date;
$end = today(config('app.timezone')); $end = today(config('app.timezone'));
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
/** @var GroupCollectorInterface $collector */ /** @var GroupCollectorInterface $collector */
$collector = app(GroupCollectorInterface::class); $collector = app(GroupCollectorInterface::class);
@@ -150,8 +150,8 @@ class ShowController extends Controller
/** @var Carbon $allStart */ /** @var Carbon $allStart */
$allStart = session('first', Carbon::now()->startOfYear()); $allStart = session('first', Carbon::now()->startOfYear());
$allEnd = today(); $allEnd = today();
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$limits = $this->getLimits($budget, $allStart, $allEnd); $limits = $this->getLimits($budget, $allStart, $allEnd);
$repetition = null; $repetition = null;
$attachments = $this->repository->getAttachments($budget); $attachments = $this->repository->getAttachments($budget);
@@ -165,7 +165,7 @@ class ShowController extends Controller
$groups = $collector->getPaginatedGroups(); $groups = $collector->getPaginatedGroups();
$groups->setPath(route('budgets.show', [$budget->id])); $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')); return view('budgets.show', compact('limits', 'attachments', 'budget', 'repetition', 'groups', 'subTitle'));
} }
@@ -186,8 +186,8 @@ class ShowController extends Controller
throw new FireflyException('This budget limit is not part of this budget.'); throw new FireflyException('This budget limit is not part of this budget.');
} }
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$subTitle = trans( $subTitle = trans(
'firefly.budget_in_period', 'firefly.budget_in_period',
[ [

View File

@@ -53,7 +53,7 @@ class CreateController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.categories')); app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark'); app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class); $this->repository = app(CategoryRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class); $this->attachments = app(AttachmentHelperInterface::class);
@@ -76,7 +76,7 @@ class CreateController extends Controller
$this->rememberPreviousUri('categories.create.uri'); $this->rememberPreviousUri('categories.create.uri');
} }
$request->session()->forget('categories.create.fromStore'); $request->session()->forget('categories.create.fromStore');
$subTitle = (string)trans('firefly.create_new_category'); $subTitle = (string) trans('firefly.create_new_category');
return view('categories.create', compact('subTitle')); return view('categories.create', compact('subTitle'));
} }
@@ -94,7 +94,7 @@ class CreateController extends Controller
$data = $request->getCategoryData(); $data = $request->getCategoryData();
$category = $this->repository->store($data); $category = $this->repository->store($data);
$request->session()->flash('success', (string)trans('firefly.stored_category', ['name' => $category->name])); $request->session()->flash('success', (string) trans('firefly.stored_category', ['name' => $category->name]));
app('preferences')->mark(); app('preferences')->mark();
// store attachment(s): // store attachment(s):
@@ -103,7 +103,7 @@ class CreateController extends Controller
$this->attachments->saveAttachmentsForModel($category, $files); $this->attachments->saveAttachmentsForModel($category, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -111,7 +111,7 @@ class CreateController extends Controller
} }
$redirect = redirect(route('categories.index')); $redirect = redirect(route('categories.index'));
if (1 === (int)$request->get('create_another')) { if (1 === (int) $request->get('create_another')) {
$request->session()->put('categories.create.fromStore', true); $request->session()->put('categories.create.fromStore', true);

View File

@@ -51,7 +51,7 @@ class DeleteController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.categories')); app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark'); app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class); $this->repository = app(CategoryRepositoryInterface::class);
@@ -69,7 +69,7 @@ class DeleteController extends Controller
*/ */
public function delete(Category $category) public function delete(Category $category)
{ {
$subTitle = (string)trans('firefly.delete_category', ['name' => $category->name]); $subTitle = (string) trans('firefly.delete_category', ['name' => $category->name]);
// put previous url in session // put previous url in session
$this->rememberPreviousUri('categories.delete.uri'); $this->rememberPreviousUri('categories.delete.uri');
@@ -80,7 +80,7 @@ class DeleteController extends Controller
/** /**
* Destroy a category. * Destroy a category.
* *
* @param Request $request * @param Request $request
* @param Category $category * @param Category $category
* *
* @return RedirectResponse|Redirector * @return RedirectResponse|Redirector
@@ -90,7 +90,7 @@ class DeleteController extends Controller
$name = $category->name; $name = $category->name;
$this->repository->destroy($category); $this->repository->destroy($category);
$request->session()->flash('success', (string)trans('firefly.deleted_category', ['name' => $name])); $request->session()->flash('success', (string) trans('firefly.deleted_category', ['name' => $name]));
app('preferences')->mark(); app('preferences')->mark();
return redirect($this->getPreviousUri('categories.delete.uri')); return redirect($this->getPreviousUri('categories.delete.uri'));

View File

@@ -54,7 +54,7 @@ class EditController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.categories')); app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark'); app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class); $this->repository = app(CategoryRepositoryInterface::class);
$this->attachments = app(AttachmentHelperInterface::class); $this->attachments = app(AttachmentHelperInterface::class);
@@ -74,7 +74,7 @@ class EditController extends Controller
*/ */
public function edit(Request $request, Category $category) 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"). // put previous url in session if not redirect from store (not "return_to_edit").
if (true !== session('categories.edit.fromUpdate')) { if (true !== session('categories.edit.fromUpdate')) {
@@ -102,7 +102,7 @@ class EditController extends Controller
$data = $request->getCategoryData(); $data = $request->getCategoryData();
$this->repository->update($category, $data); $this->repository->update($category, $data);
$request->session()->flash('success', (string)trans('firefly.updated_category', ['name' => $category->name])); $request->session()->flash('success', (string) trans('firefly.updated_category', ['name' => $category->name]));
app('preferences')->mark(); app('preferences')->mark();
// store new attachment(s): // store new attachment(s):
@@ -111,7 +111,7 @@ class EditController extends Controller
$this->attachments->saveAttachmentsForModel($category, $files); $this->attachments->saveAttachmentsForModel($category, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -119,7 +119,7 @@ class EditController extends Controller
} }
$redirect = redirect($this->getPreviousUri('categories.edit.uri')); $redirect = redirect($this->getPreviousUri('categories.edit.uri'));
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int) $request->get('return_to_edit')) {
$request->session()->put('categories.edit.fromUpdate', true); $request->session()->put('categories.edit.fromUpdate', true);

View File

@@ -52,7 +52,7 @@ class IndexController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.categories')); app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark'); app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class); $this->repository = app(CategoryRepositoryInterface::class);
@@ -71,8 +71,8 @@ class IndexController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$collection = $this->repository->getCategories(); $collection = $this->repository->getCategories();
$total = $collection->count(); $total = $collection->count();
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize); $collection = $collection->slice(($page - 1) * $pageSize, $pageSize);

View File

@@ -58,7 +58,7 @@ class NoCategoryController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.categories')); app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark'); app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->journalRepos = app(JournalRepositoryInterface::class); $this->journalRepos = app(JournalRepositoryInterface::class);
@@ -84,8 +84,8 @@ class NoCategoryController extends Controller
$start = $start ?? session('start'); $start = $start ?? session('start');
/** @var Carbon $end */ /** @var Carbon $end */
$end = $end ?? session('end'); $end = $end ?? session('end');
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$subTitle = trans( $subTitle = trans(
'firefly.without_category_between', 'firefly.without_category_between',
['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat)] ['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat)]
@@ -121,10 +121,10 @@ class NoCategoryController extends Controller
$start = null; $start = null;
$end = null; $end = null;
$periods = new Collection; $periods = new Collection;
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
Log::debug('Start of noCategory()'); Log::debug('Start of noCategory()');
$subTitle = (string)trans('firefly.all_journals_without_category'); $subTitle = (string) trans('firefly.all_journals_without_category');
$first = $this->journalRepos->firstNull(); $first = $this->journalRepos->firstNull();
$start = null === $first ? new Carbon : $first->date; $start = null === $first ? new Carbon : $first->date;
$end = today(config('app.timezone')); $end = today(config('app.timezone'));

View File

@@ -59,7 +59,7 @@ class ShowController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.categories')); app('view')->share('title', (string) trans('firefly.categories'));
app('view')->share('mainTitleIcon', 'fa-bookmark'); app('view')->share('mainTitleIcon', 'fa-bookmark');
$this->repository = app(CategoryRepositoryInterface::class); $this->repository = app(CategoryRepositoryInterface::class);
@@ -86,9 +86,9 @@ class ShowController extends Controller
/** @var Carbon $end */ /** @var Carbon $end */
$end = $end ?? session('end', Carbon::now()->endOfMonth()); $end = $end ?? session('end', Carbon::now()->endOfMonth());
$subTitleIcon = 'fa-bookmark'; $subTitleIcon = 'fa-bookmark';
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$attachments = $this->repository->getAttachments($category); $attachments = $this->repository->getAttachments($category);
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$oldest = $this->repository->firstUseDate($category) ?? Carbon::now()->startOfYear(); $oldest = $this->repository->firstUseDate($category) ?? Carbon::now()->startOfYear();
$periods = $this->getCategoryPeriodOverview($category, $oldest, $end); $periods = $this->getCategoryPeriodOverview($category, $oldest, $end);
$path = route('categories.show', [$category->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); $path = route('categories.show', [$category->id, $start->format('Y-m-d'), $end->format('Y-m-d')]);
@@ -123,13 +123,13 @@ class ShowController extends Controller
{ {
// default values: // default values:
$subTitleIcon = 'fa-bookmark'; $subTitleIcon = 'fa-bookmark';
$page = (int)$request->get('page'); $page = (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$start = null; $start = null;
$end = null; $end = null;
$periods = new Collection; $periods = new Collection;
$subTitle = (string)trans('firefly.all_journals_for_category', ['name' => $category->name]); $subTitle = (string) trans('firefly.all_journals_for_category', ['name' => $category->name]);
$first = $this->repository->firstUseDate($category); $first = $this->repository->firstUseDate($category);
/** @var Carbon $start */ /** @var Carbon $start */
$start = $first ?? today(config('app.timezone')); $start = $first ?? today(config('app.timezone'));

View File

@@ -76,18 +76,18 @@ class BillController extends Controller
$chartData = []; $chartData = [];
$currencies = []; $currencies = [];
$paid = $repository->getBillsPaidInRangePerCurrency($start, $end); // will be a negative amount. $paid = $repository->getBillsPaidInRangePerCurrency($start, $end); // will be a negative amount.
$unpaid = $repository->getBillsUnpaidInRangePerCurrency($start, $end); // will be a positive amount. $unpaid = $repository->getBillsUnpaidInRangePerCurrency($start, $end); // will be a positive amount.
foreach ($paid as $currencyId => $amount) { foreach ($paid as $currencyId => $amount) {
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->find($currencyId); $currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->find($currencyId);
$label = (string)trans('firefly.paid_in_currency', ['currency' => $currencies[$currencyId]->name]); $label = (string) trans('firefly.paid_in_currency', ['currency' => $currencies[$currencyId]->name]);
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol, $chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol,
'currency_code' => $currencies[$currencyId]->code]; 'currency_code' => $currencies[$currencyId]->code];
} }
foreach ($unpaid as $currencyId => $amount) { foreach ($unpaid as $currencyId => $amount) {
$currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->find($currencyId); $currencies[$currencyId] = $currencies[$currencyId] ?? $currencyRepository->find($currencyId);
$label = (string)trans('firefly.unpaid_in_currency', ['currency' => $currencies[$currencyId]->name]); $label = (string) trans('firefly.unpaid_in_currency', ['currency' => $currencies[$currencyId]->name]);
$chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol, $chartData[$label] = ['amount' => $amount, 'currency_symbol' => $currencies[$currencyId]->symbol,
'currency_code' => $currencies[$currencyId]->code]; 'currency_code' => $currencies[$currencyId]->code];
} }
@@ -136,16 +136,16 @@ class BillController extends Controller
); );
$chartData = [ $chartData = [
['type' => 'line', 'label' => (string)trans('firefly.min-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, ['type' => 'line', 'label' => (string) trans('firefly.min-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol,
'currency_code' => $bill->transactionCurrency->code, 'entries' => []], 'currency_code' => $bill->transactionCurrency->code, 'entries' => []],
['type' => 'line', 'label' => (string)trans('firefly.max-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, ['type' => 'line', 'label' => (string) trans('firefly.max-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol,
'currency_code' => $bill->transactionCurrency->code, 'entries' => []], 'currency_code' => $bill->transactionCurrency->code, 'entries' => []],
['type' => 'bar', 'label' => (string)trans('firefly.journal-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol, ['type' => 'bar', 'label' => (string) trans('firefly.journal-amount'), 'currency_symbol' => $bill->transactionCurrency->symbol,
'currency_code' => $bill->transactionCurrency->code, 'entries' => []], 'currency_code' => $bill->transactionCurrency->code, 'entries' => []],
]; ];
foreach ($journals as $journal) { foreach ($journals as $journal) {
$date = $journal['date']->isoFormat((string)trans('config.month_and_day_js', [], $locale)); $date = $journal['date']->isoFormat((string) trans('config.month_and_day_js', [], $locale));
$chartData[0]['entries'][$date] = $bill->amount_min; // minimum amount of bill $chartData[0]['entries'][$date] = $bill->amount_min; // minimum amount of bill
$chartData[1]['entries'][$date] = $bill->amount_max; // maximum amount of bill $chartData[1]['entries'][$date] = $bill->amount_max; // maximum amount of bill

View File

@@ -182,14 +182,14 @@ class BudgetController extends Controller
while ($start <= $end) { while ($start <= $end) {
$current = clone $start; $current = clone $start;
$expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $currency); $expenses = $this->opsRepository->sumExpenses($current, $current, null, $budgetCollection, $currency);
$spent = $expenses[(int)$currency->id]['sum'] ?? '0'; $spent = $expenses[(int) $currency->id]['sum'] ?? '0';
$amount = bcadd($amount, $spent); $amount = bcadd($amount, $spent);
$format = $start->isoFormat((string)trans('config.month_and_day_js', [], $locale)); $format = $start->isoFormat((string) trans('config.month_and_day_js', [], $locale));
$entries[$format] = $amount; $entries[$format] = $amount;
$start->addDay(); $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: // add currency symbol from budget limit:
$data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol; $data['datasets'][0]['currency_symbol'] = $budgetLimit->transactionCurrency->symbol;
$data['datasets'][0]['currency_code'] = $budgetLimit->transactionCurrency->code; $data['datasets'][0]['currency_code'] = $budgetLimit->transactionCurrency->code;
@@ -238,7 +238,7 @@ class BudgetController extends Controller
// group by asset account ID: // group by asset account ID:
foreach ($journals as $journal) { foreach ($journals as $journal) {
$key = sprintf('%d-%d', (int)$journal['source_account_id'], $journal['currency_id']); $key = sprintf('%d-%d', (int) $journal['source_account_id'], $journal['currency_id']);
$result[$key] = $result[$key] ?? [ $result[$key] = $result[$key] ?? [
'amount' => '0', 'amount' => '0',
'currency_symbol' => $journal['currency_symbol'], 'currency_symbol' => $journal['currency_symbol'],
@@ -251,7 +251,7 @@ class BudgetController extends Controller
$names = $this->getAccountNames(array_keys($result)); $names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) { foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId); $parts = explode('-', $combinedId);
$assetId = (int)$parts[0]; $assetId = (int) $parts[0];
$title = sprintf('%s (%s)', $names[$assetId] ?? '(empty)', $info['currency_name']); $title = sprintf('%s (%s)', $names[$assetId] ?? '(empty)', $info['currency_name']);
$chartData[$title] $chartData[$title]
= [ = [
@@ -317,7 +317,7 @@ class BudgetController extends Controller
$names = $this->getCategoryNames(array_keys($result)); $names = $this->getCategoryNames(array_keys($result));
foreach ($result as $combinedId => $info) { foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId); $parts = explode('-', $combinedId);
$categoryId = (int)$parts[0]; $categoryId = (int) $parts[0];
$title = sprintf('%s (%s)', $names[$categoryId] ?? '(empty)', $info['currency_name']); $title = sprintf('%s (%s)', $names[$categoryId] ?? '(empty)', $info['currency_name']);
$chartData[$title] = [ $chartData[$title] = [
'amount' => $info['amount'], 'amount' => $info['amount'],
@@ -383,7 +383,7 @@ class BudgetController extends Controller
$names = $this->getAccountNames(array_keys($result)); $names = $this->getAccountNames(array_keys($result));
foreach ($result as $combinedId => $info) { foreach ($result as $combinedId => $info) {
$parts = explode('-', $combinedId); $parts = explode('-', $combinedId);
$opposingId = (int)$parts[0]; $opposingId = (int) $parts[0];
$name = $names[$opposingId] ?? 'no name'; $name = $names[$opposingId] ?? 'no name';
$title = sprintf('%s (%s)', $name, $info['currency_name']); $title = sprintf('%s (%s)', $name, $info['currency_name']);
$chartData[$title] = [ $chartData[$title] = [
@@ -460,14 +460,14 @@ class BudgetController extends Controller
$preferredRange = app('navigation')->preferredRangeFormat($start, $end); $preferredRange = app('navigation')->preferredRangeFormat($start, $end);
$chartData = [ $chartData = [
[ [
'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency->name]), 'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency->name]),
'type' => 'bar', 'type' => 'bar',
'entries' => [], 'entries' => [],
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code, 'currency_code' => $currency->code,
], ],
[ [
'label' => (string)trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]), 'label' => (string) trans('firefly.box_budgeted_in_currency', ['currency' => $currency->name]),
'type' => 'bar', 'type' => 'bar',
'currency_symbol' => $currency->symbol, 'currency_symbol' => $currency->symbol,
'currency_code' => $currency->code, 'currency_code' => $currency->code,
@@ -490,13 +490,13 @@ class BudgetController extends Controller
// get budget limit in this period for this currency. // 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) { if (null !== $limit) {
$chartData[1]['entries'][$title] = round((float)$limit->amount, $currency->decimal_places); $chartData[1]['entries'][$title] = round((float) $limit->amount, $currency->decimal_places);
} }
// get spent amount in this period for this currency. // get spent amount in this period for this currency.
$sum = $this->opsRepository->sumExpenses($currentStart, $currentEnd, $accounts, new Collection([$budget]), $currency); $sum = $this->opsRepository->sumExpenses($currentStart, $currentEnd, $accounts, new Collection([$budget]), $currency);
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0'); $amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
$chartData[0]['entries'][$title] = round((float)$amount, $currency->decimal_places); $chartData[0]['entries'][$title] = round((float) $amount, $currency->decimal_places);
$currentStart = clone $currentEnd; $currentStart = clone $currentEnd;
$currentStart->addDay()->startOfDay(); $currentStart->addDay()->startOfDay();
@@ -542,11 +542,11 @@ class BudgetController extends Controller
$title = $currentStart->isoFormat($titleFormat); $title = $currentStart->isoFormat($titleFormat);
$sum = $this->nbRepository->sumExpenses($currentStart, $currentEnd, $accounts, $currency); $sum = $this->nbRepository->sumExpenses($currentStart, $currentEnd, $accounts, $currency);
$amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0'); $amount = app('steam')->positive($sum[$currency->id]['sum'] ?? '0');
$chartData[$title] = round((float)$amount, $currency->decimal_places); $chartData[$title] = round((float) $amount, $currency->decimal_places);
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0); $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); $cache->store($data);
return response()->json($data); return response()->json($data);

View File

@@ -1,4 +1,5 @@
<?php /** <?php
/**
* BudgetReportController.php * BudgetReportController.php
* Copyright (c) 2020 james@firefly-iii.org * Copyright (c) 2020 james@firefly-iii.org
* *
@@ -200,7 +201,7 @@ class BudgetReportController extends Controller
$chartData[$spentKey] = $chartData[$spentKey] ?? [ $chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf( 'label' => sprintf(
'%s (%s)', '%s (%s)',
(string)trans('firefly.spent_in_specific_budget', ['budget' => $budget->name]), (string) trans('firefly.spent_in_specific_budget', ['budget' => $budget->name]),
$currency['currency_name'] $currency['currency_name']
), ),
'type' => 'bar', 'type' => 'bar',

View File

@@ -198,7 +198,7 @@ class CategoryController extends Controller
if (null !== $category) { if (null !== $category) {
/** @var OperationsRepositoryInterface $opsRepository */ /** @var OperationsRepositoryInterface $opsRepository */
$opsRepository = app(OperationsRepositoryInterface::class); $opsRepository = app(OperationsRepositoryInterface::class);
$categoryId = (int)$category->id; $categoryId = (int) $category->id;
// this gives us all currencies // this gives us all currencies
$collection = new Collection([$category]); $collection = new Collection([$category]);
$expenses = $opsRepository->listExpenses($start, $end, null, $collection); $expenses = $opsRepository->listExpenses($start, $end, null, $collection);
@@ -217,7 +217,7 @@ class CategoryController extends Controller
$inKey = sprintf('%d-in', $currencyId); $inKey = sprintf('%d-in', $currencyId);
$chartData[$outKey] $chartData[$outKey]
= [ = [
'label' => sprintf('%s (%s)', (string)trans('firefly.spent'), $currencyInfo['currency_name']), 'label' => sprintf('%s (%s)', (string) trans('firefly.spent'), $currencyInfo['currency_name']),
'entries' => [], 'entries' => [],
'type' => 'bar', 'type' => 'bar',
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red 'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
@@ -225,7 +225,7 @@ class CategoryController extends Controller
$chartData[$inKey] $chartData[$inKey]
= [ = [
'label' => sprintf('%s (%s)', (string)trans('firefly.earned'), $currencyInfo['currency_name']), 'label' => sprintf('%s (%s)', (string) trans('firefly.earned'), $currencyInfo['currency_name']),
'entries' => [], 'entries' => [],
'type' => 'bar', 'type' => 'bar',
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green 'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green

View File

@@ -265,7 +265,7 @@ class CategoryReportController extends Controller
$chartData[$spentKey] = $chartData[$spentKey] ?? [ $chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf( 'label' => sprintf(
'%s (%s)', '%s (%s)',
(string)trans('firefly.spent_in_specific_category', ['category' => $category->name]), (string) trans('firefly.spent_in_specific_category', ['category' => $category->name]),
$currency['currency_name'] $currency['currency_name']
), ),
'type' => 'bar', 'type' => 'bar',
@@ -292,7 +292,7 @@ class CategoryReportController extends Controller
$chartData[$spentKey] = $chartData[$spentKey] ?? [ $chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf( 'label' => sprintf(
'%s (%s)', '%s (%s)',
(string)trans('firefly.earned_in_specific_category', ['category' => $category->name]), (string) trans('firefly.earned_in_specific_category', ['category' => $category->name]),
$currency['currency_name'] $currency['currency_name']
), ),
'type' => 'bar', 'type' => 'bar',

View File

@@ -199,7 +199,7 @@ class DoubleReportController extends Controller
$chartData[$spentKey] = $chartData[$spentKey] ?? [ $chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf( 'label' => sprintf(
'%s (%s)', '%s (%s)',
(string)trans('firefly.spent_in_specific_double', ['account' => $name]), (string) trans('firefly.spent_in_specific_double', ['account' => $name]),
$currency['currency_name'] $currency['currency_name']
), ),
'type' => 'bar', 'type' => 'bar',
@@ -225,7 +225,7 @@ class DoubleReportController extends Controller
$chartData[$earnedKey] = $chartData[$earnedKey] ?? [ $chartData[$earnedKey] = $chartData[$earnedKey] ?? [
'label' => sprintf( 'label' => sprintf(
'%s (%s)', '%s (%s)',
(string)trans('firefly.earned_in_specific_double', ['account' => $name]), (string) trans('firefly.earned_in_specific_double', ['account' => $name]),
$currency['currency_name'] $currency['currency_name']
), ),
'type' => 'bar', 'type' => 'bar',

View File

@@ -113,27 +113,27 @@ class ExpenseReportController extends Controller
/** @var Account $exp */ /** @var Account $exp */
$exp = $combination->first(); $exp = $combination->first();
$chartData[$exp->id . '-in'] = [ $chartData[$exp->id . '-in'] = [
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.income')), 'label' => sprintf('%s (%s)', $name, (string) trans('firefly.income')),
'type' => 'bar', 'type' => 'bar',
'yAxisID' => 'y-axis-0', 'yAxisID' => 'y-axis-0',
'entries' => [], 'entries' => [],
]; ];
$chartData[$exp->id . '-out'] = [ $chartData[$exp->id . '-out'] = [
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.expenses')), 'label' => sprintf('%s (%s)', $name, (string) trans('firefly.expenses')),
'type' => 'bar', 'type' => 'bar',
'yAxisID' => 'y-axis-0', 'yAxisID' => 'y-axis-0',
'entries' => [], 'entries' => [],
]; ];
// total in, total out: // total in, total out:
$chartData[$exp->id . '-total-in'] = [ $chartData[$exp->id . '-total-in'] = [
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.sum_of_income')), 'label' => sprintf('%s (%s)', $name, (string) trans('firefly.sum_of_income')),
'type' => 'line', 'type' => 'line',
'fill' => false, 'fill' => false,
'yAxisID' => 'y-axis-1', 'yAxisID' => 'y-axis-1',
'entries' => [], 'entries' => [],
]; ];
$chartData[$exp->id . '-total-out'] = [ $chartData[$exp->id . '-total-out'] = [
'label' => sprintf('%s (%s)', $name, (string)trans('firefly.sum_of_expenses')), 'label' => sprintf('%s (%s)', $name, (string) trans('firefly.sum_of_expenses')),
'type' => 'line', 'type' => 'line',
'fill' => false, 'fill' => false,
'yAxisID' => 'y-axis-1', 'yAxisID' => 'y-axis-1',

View File

@@ -100,7 +100,7 @@ class PiggyBankController extends Controller
} }
); );
$currentSum = $filtered->sum('amount'); $currentSum = $filtered->sum('amount');
$label = $oldest->isoFormat((string)trans('config.month_and_day_js', [], $locale)); $label = $oldest->isoFormat((string) trans('config.month_and_day_js', [], $locale));
$chartData[$label] = $currentSum; $chartData[$label] = $currentSum;
$oldest = app('navigation')->addPeriod($oldest, $step, 0); $oldest = app('navigation')->addPeriod($oldest, $step, 0);
} }
@@ -110,7 +110,7 @@ class PiggyBankController extends Controller
} }
); );
$finalSum = $finalFiltered->sum('amount'); $finalSum = $finalFiltered->sum('amount');
$finalLabel = $today->isoFormat((string)trans('config.month_and_day_js', [], $locale)); $finalLabel = $today->isoFormat((string) trans('config.month_and_day_js', [], $locale));
$chartData[$finalLabel] = $finalSum; $chartData[$finalLabel] = $finalSum;
$data = $this->generator->singleSet($piggyBank->name, $chartData); $data = $this->generator->singleSet($piggyBank->name, $chartData);

View File

@@ -114,7 +114,7 @@ class ReportController extends Controller
/** @var array $netWorthItem */ /** @var array $netWorthItem */
foreach ($result as $netWorthItem) { foreach ($result as $netWorthItem) {
$currencyId = $netWorthItem['currency']->id; $currencyId = $netWorthItem['currency']->id;
$label = $current->isoFormat((string)trans('config.month_and_day_js', [], $locale)); $label = $current->isoFormat((string) trans('config.month_and_day_js', [], $locale));
if (!array_key_exists($currencyId, $chartData)) { if (!array_key_exists($currencyId, $chartData)) {
$chartData[$currencyId] = [ $chartData[$currencyId] = [
'label' => 'Net worth in ' . $netWorthItem['currency']->name, 'label' => 'Net worth in ' . $netWorthItem['currency']->name,
@@ -179,13 +179,13 @@ class ReportController extends Controller
/** @var array $journal */ /** @var array $journal */
foreach ($journals as $journal) { foreach ($journals as $journal) {
$period = $journal['date']->format($format); $period = $journal['date']->format($format);
$currencyId = (int)$journal['currency_id']; $currencyId = (int) $journal['currency_id'];
$data[$currencyId] = $data[$currencyId] ?? [ $data[$currencyId] = $data[$currencyId] ?? [
'currency_id' => $currencyId, 'currency_id' => $currencyId,
'currency_symbol' => $journal['currency_symbol'], 'currency_symbol' => $journal['currency_symbol'],
'currency_code' => $journal['currency_code'], 'currency_code' => $journal['currency_code'],
'currency_name' => $journal['currency_name'], 'currency_name' => $journal['currency_name'],
'currency_decimal_places' => (int)$journal['currency_decimal_places'], 'currency_decimal_places' => (int) $journal['currency_decimal_places'],
]; ];
$data[$currencyId][$period] = $data[$currencyId][$period] ?? [ $data[$currencyId][$period] = $data[$currencyId][$period] ?? [
'period' => $period, 'period' => $period,
@@ -217,7 +217,7 @@ class ReportController extends Controller
/** @var array $currency */ /** @var array $currency */
foreach ($data as $currency) { foreach ($data as $currency) {
$income = [ $income = [
'label' => (string)trans('firefly.box_earned_in_currency', ['currency' => $currency['currency_name']]), 'label' => (string) trans('firefly.box_earned_in_currency', ['currency' => $currency['currency_name']]),
'type' => 'bar', 'type' => 'bar',
'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green 'backgroundColor' => 'rgba(0, 141, 76, 0.5)', // green
'currency_id' => $currency['currency_id'], 'currency_id' => $currency['currency_id'],
@@ -226,7 +226,7 @@ class ReportController extends Controller
'entries' => [], 'entries' => [],
]; ];
$expense = [ $expense = [
'label' => (string)trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]), 'label' => (string) trans('firefly.box_spent_in_currency', ['currency' => $currency['currency_name']]),
'type' => 'bar', 'type' => 'bar',
'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red 'backgroundColor' => 'rgba(219, 68, 55, 0.5)', // red
'currency_id' => $currency['currency_id'], 'currency_id' => $currency['currency_id'],
@@ -240,8 +240,8 @@ class ReportController extends Controller
while ($currentStart <= $end) { while ($currentStart <= $end) {
$key = $currentStart->format($format); $key = $currentStart->format($format);
$title = $currentStart->isoFormat($titleFormat); $title = $currentStart->isoFormat($titleFormat);
$income['entries'][$title] = round((float)($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']); $income['entries'][$title] = round((float) ($currency[$key]['earned'] ?? '0'), $currency['currency_decimal_places']);
$expense['entries'][$title] = round((float)($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']); $expense['entries'][$title] = round((float) ($currency[$key]['spent'] ?? '0'), $currency['currency_decimal_places']);
$currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0); $currentStart = app('navigation')->addPeriod($currentStart, $preferredRange, 0);
} }

View File

@@ -270,7 +270,7 @@ class TagReportController extends Controller
$chartData[$spentKey] = $chartData[$spentKey] ?? [ $chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf( 'label' => sprintf(
'%s (%s)', '%s (%s)',
(string)trans('firefly.spent_in_specific_tag', ['tag' => $tag->tag]), (string) trans('firefly.spent_in_specific_tag', ['tag' => $tag->tag]),
$currency['currency_name'] $currency['currency_name']
), ),
'type' => 'bar', 'type' => 'bar',
@@ -297,7 +297,7 @@ class TagReportController extends Controller
$chartData[$spentKey] = $chartData[$spentKey] ?? [ $chartData[$spentKey] = $chartData[$spentKey] ?? [
'label' => sprintf( 'label' => sprintf(
'%s (%s)', '%s (%s)',
(string)trans('firefly.earned_in_specific_tag', ['tag' => $tag->tag]), (string) trans('firefly.earned_in_specific_tag', ['tag' => $tag->tag]),
$currency['currency_name'] $currency['currency_name']
), ),
'type' => 'bar', 'type' => 'bar',

View File

@@ -80,7 +80,7 @@ class TransactionController extends Controller
// group by category. // group by category.
/** @var array $journal */ /** @var array $journal */
foreach ($result as $journal) { foreach ($result as $journal) {
$budget = $journal['budget_name'] ?? (string)trans('firefly.no_budget'); $budget = $journal['budget_name'] ?? (string) trans('firefly.no_budget');
$title = sprintf('%s (%s)', $budget, $journal['currency_symbol']); $title = sprintf('%s (%s)', $budget, $journal['currency_symbol']);
$data[$title] = $data[$title] ?? [ $data[$title] = $data[$title] ?? [
'amount' => '0', 'amount' => '0',
@@ -138,7 +138,7 @@ class TransactionController extends Controller
// group by category. // group by category.
/** @var array $journal */ /** @var array $journal */
foreach ($result as $journal) { foreach ($result as $journal) {
$category = $journal['category_name'] ?? (string)trans('firefly.no_category'); $category = $journal['category_name'] ?? (string) trans('firefly.no_category');
$title = sprintf('%s (%s)', $category, $journal['currency_symbol']); $title = sprintf('%s (%s)', $category, $journal['currency_symbol']);
$data[$title] = $data[$title] ?? [ $data[$title] = $data[$title] ?? [
'amount' => '0', 'amount' => '0',

View File

@@ -92,9 +92,9 @@ abstract class Controller extends BaseController
function ($request, $next): mixed { function ($request, $next): mixed {
$locale = app('steam')->getLocale(); $locale = app('steam')->getLocale();
// translations for specific strings: // translations for specific strings:
$this->monthFormat = (string)trans('config.month_js', [], $locale); $this->monthFormat = (string) trans('config.month_js', [], $locale);
$this->monthAndDayFormat = (string)trans('config.month_and_day_js', [], $locale); $this->monthAndDayFormat = (string) trans('config.month_and_day_js', [], $locale);
$this->dateTimeFormat = (string)trans('config.date_time_js', [], $locale); $this->dateTimeFormat = (string) trans('config.date_time_js', [], $locale);
// get shown-intro-preference: // get shown-intro-preference:
if (auth()->check()) { if (auth()->check()) {

View File

@@ -56,7 +56,7 @@ class CurrencyController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.currencies')); app('view')->share('title', (string) trans('firefly.currencies'));
app('view')->share('mainTitleIcon', 'fa-usd'); app('view')->share('mainTitleIcon', 'fa-usd');
$this->repository = app(CurrencyRepositoryInterface::class); $this->repository = app(CurrencyRepositoryInterface::class);
$this->userRepository = app(UserRepositoryInterface::class); $this->userRepository = app(UserRepositoryInterface::class);
@@ -78,13 +78,13 @@ class CurrencyController extends Controller
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
if (!$this->userRepository->hasRole($user, 'owner')) { if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))]));
return redirect(route('currencies.index')); return redirect(route('currencies.index'));
} }
$subTitleIcon = 'fa-plus'; $subTitleIcon = 'fa-plus';
$subTitle = (string)trans('firefly.create_currency'); $subTitle = (string) trans('firefly.create_currency');
// put previous url in session if not redirect from store (not "create another"). // put previous url in session if not redirect from store (not "create another").
if (true !== session('currencies.create.fromStore')) { if (true !== session('currencies.create.fromStore')) {
@@ -107,7 +107,7 @@ class CurrencyController extends Controller
*/ */
public function defaultCurrency(Request $request) public function defaultCurrency(Request $request)
{ {
$currencyId = (int)$request->get('id'); $currencyId = (int) $request->get('id');
if ($currencyId > 0) { if ($currencyId > 0) {
// valid currency? // valid currency?
$currency = $this->repository->find($currencyId); $currency = $this->repository->find($currencyId);
@@ -117,7 +117,7 @@ class CurrencyController extends Controller
Log::channel('audit')->info(sprintf('Make %s the default currency.', $currency->code)); Log::channel('audit')->info(sprintf('Make %s the default currency.', $currency->code));
$this->repository->enable($currency); $this->repository->enable($currency);
$request->session()->flash('success', (string)trans('firefly.new_default_currency', ['name' => $currency->name])); $request->session()->flash('success', (string) trans('firefly.new_default_currency', ['name' => $currency->name]));
return redirect(route('currencies.index')); return redirect(route('currencies.index'));
} }
@@ -140,7 +140,7 @@ class CurrencyController extends Controller
$user = auth()->user(); $user = auth()->user();
if (!$this->userRepository->hasRole($user, 'owner')) { if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_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)); Log::channel('audit')->info(sprintf('Tried to visit page to delete currency %s but is not site owner.', $currency->code));
return redirect(route('currencies.index')); return redirect(route('currencies.index'));
@@ -149,7 +149,7 @@ class CurrencyController extends Controller
if ($this->repository->currencyInUse($currency)) { if ($this->repository->currencyInUse($currency)) {
$location = $this->repository->currencyInUseAt($currency); $location = $this->repository->currencyInUseAt($currency);
$message = (string)trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]); $message = (string) trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]);
$request->session()->flash('error', $message); $request->session()->flash('error', $message);
Log::channel('audit')->info(sprintf('Tried to visit page to delete currency %s but currency is in use.', $currency->code)); Log::channel('audit')->info(sprintf('Tried to visit page to delete currency %s but currency is in use.', $currency->code));
@@ -158,7 +158,7 @@ class CurrencyController extends Controller
// put previous url in session // put previous url in session
$this->rememberPreviousUri('currencies.delete.uri'); $this->rememberPreviousUri('currencies.delete.uri');
$subTitle = (string)trans('form.delete_currency', ['name' => $currency->name]); $subTitle = (string) trans('form.delete_currency', ['name' => $currency->name]);
Log::channel('audit')->info(sprintf('Visit page to delete currency %s.', $currency->code)); Log::channel('audit')->info(sprintf('Visit page to delete currency %s.', $currency->code));
return view('currencies.delete', compact('currency', 'subTitle')); return view('currencies.delete', compact('currency', 'subTitle'));
@@ -178,7 +178,7 @@ class CurrencyController extends Controller
$user = auth()->user(); $user = auth()->user();
if (!$this->userRepository->hasRole($user, 'owner')) { if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))]));
Log::channel('audit')->info(sprintf('Tried to delete currency %s but is not site owner.', $currency->code)); Log::channel('audit')->info(sprintf('Tried to delete currency %s but is not site owner.', $currency->code));
return redirect(route('currencies.index')); return redirect(route('currencies.index'));
@@ -186,14 +186,14 @@ class CurrencyController extends Controller
} }
if ($this->repository->currencyInUse($currency)) { if ($this->repository->currencyInUse($currency)) {
$request->session()->flash('error', (string)trans('firefly.cannot_delete_currency', ['name' => e($currency->name)])); $request->session()->flash('error', (string) trans('firefly.cannot_delete_currency', ['name' => e($currency->name)]));
Log::channel('audit')->info(sprintf('Tried to delete currency %s but is in use.', $currency->code)); Log::channel('audit')->info(sprintf('Tried to delete currency %s but is in use.', $currency->code));
return redirect(route('currencies.index')); return redirect(route('currencies.index'));
} }
if ($this->repository->isFallbackCurrency($currency)) { if ($this->repository->isFallbackCurrency($currency)) {
$request->session()->flash('error', (string)trans('firefly.cannot_delete_fallback_currency', ['name' => e($currency->name)])); $request->session()->flash('error', (string) trans('firefly.cannot_delete_fallback_currency', ['name' => e($currency->name)]));
Log::channel('audit')->info(sprintf('Tried to delete currency %s but is FALLBACK.', $currency->code)); Log::channel('audit')->info(sprintf('Tried to delete currency %s but is FALLBACK.', $currency->code));
return redirect(route('currencies.index')); return redirect(route('currencies.index'));
@@ -202,7 +202,7 @@ class CurrencyController extends Controller
Log::channel('audit')->info(sprintf('Deleted currency %s.', $currency->code)); Log::channel('audit')->info(sprintf('Deleted currency %s.', $currency->code));
$this->repository->destroy($currency); $this->repository->destroy($currency);
$request->session()->flash('success', (string)trans('firefly.deleted_currency', ['name' => $currency->name])); $request->session()->flash('success', (string) trans('firefly.deleted_currency', ['name' => $currency->name]));
return redirect($this->getPreviousUri('currencies.delete.uri')); return redirect($this->getPreviousUri('currencies.delete.uri'));
} }
@@ -215,7 +215,7 @@ class CurrencyController extends Controller
*/ */
public function disableCurrency(Request $request): JsonResponse public function disableCurrency(Request $request): JsonResponse
{ {
$currencyId = (int)$request->get('id'); $currencyId = (int) $request->get('id');
if ($currencyId > 0) { if ($currencyId > 0) {
// valid currency? // valid currency?
$currency = $this->repository->find($currencyId); $currency = $this->repository->find($currencyId);
@@ -226,7 +226,7 @@ class CurrencyController extends Controller
$user = auth()->user(); $user = auth()->user();
if (!$this->userRepository->hasRole($user, 'owner')) { if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))]));
Log::channel('audit')->info(sprintf('Tried to disable currency %s but is not site owner.', $currency->code)); Log::channel('audit')->info(sprintf('Tried to disable currency %s but is not site owner.', $currency->code));
return response()->json([]); return response()->json([]);
@@ -235,7 +235,7 @@ class CurrencyController extends Controller
if ($this->repository->currencyInUse($currency)) { if ($this->repository->currencyInUse($currency)) {
$location = $this->repository->currencyInUseAt($currency); $location = $this->repository->currencyInUseAt($currency);
$message = (string)trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]); $message = (string) trans(sprintf('firefly.cannot_disable_currency_%s', $location), ['name' => e($currency->name)]);
$request->session()->flash('error', $message); $request->session()->flash('error', $message);
Log::channel('audit')->info(sprintf('Tried to disable currency %s but is in use.', $currency->code)); Log::channel('audit')->info(sprintf('Tried to disable currency %s but is in use.', $currency->code));
@@ -258,10 +258,10 @@ class CurrencyController extends Controller
} }
if ('EUR' === $currency->code) { if ('EUR' === $currency->code) {
session()->flash('warning', (string)trans('firefly.disable_EUR_side_effects')); session()->flash('warning', (string) trans('firefly.disable_EUR_side_effects'));
} }
session()->flash('success', (string)trans('firefly.currency_is_now_disabled', ['name' => $currency->name])); session()->flash('success', (string) trans('firefly.currency_is_now_disabled', ['name' => $currency->name]));
} }
} }
@@ -282,7 +282,7 @@ class CurrencyController extends Controller
$user = auth()->user(); $user = auth()->user();
if (!$this->userRepository->hasRole($user, 'owner')) { if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_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)); Log::channel('audit')->info(sprintf('Tried to edit currency %s but is not owner.', $currency->code));
return redirect(route('currencies.index')); return redirect(route('currencies.index'));
@@ -290,13 +290,13 @@ class CurrencyController extends Controller
} }
$subTitleIcon = 'fa-pencil'; $subTitleIcon = 'fa-pencil';
$subTitle = (string)trans('breadcrumbs.edit_currency', ['name' => $currency->name]); $subTitle = (string) trans('breadcrumbs.edit_currency', ['name' => $currency->name]);
$currency->symbol = htmlentities($currency->symbol); $currency->symbol = htmlentities($currency->symbol);
// code to handle active-checkboxes // code to handle active-checkboxes
$hasOldInput = null !== $request->old('_token'); $hasOldInput = null !== $request->old('_token');
$preFilled = [ $preFilled = [
'enabled' => $hasOldInput ? (bool)$request->old('enabled') : $currency->enabled, 'enabled' => $hasOldInput ? (bool) $request->old('enabled') : $currency->enabled,
]; ];
$request->session()->flash('preFilled', $preFilled); $request->session()->flash('preFilled', $preFilled);
@@ -318,7 +318,7 @@ class CurrencyController extends Controller
*/ */
public function enableCurrency(Request $request) public function enableCurrency(Request $request)
{ {
$currencyId = (int)$request->get('id'); $currencyId = (int) $request->get('id');
if ($currencyId > 0) { if ($currencyId > 0) {
// valid currency? // valid currency?
$currency = $this->repository->find($currencyId); $currency = $this->repository->find($currencyId);
@@ -326,7 +326,7 @@ class CurrencyController extends Controller
app('preferences')->mark(); app('preferences')->mark();
$this->repository->enable($currency); $this->repository->enable($currency);
session()->flash('success', (string)trans('firefly.currency_is_now_enabled', ['name' => $currency->name])); session()->flash('success', (string) trans('firefly.currency_is_now_enabled', ['name' => $currency->name]));
Log::channel('audit')->info(sprintf('Enabled currency %s.', $currency->code)); Log::channel('audit')->info(sprintf('Enabled currency %s.', $currency->code));
} }
} }
@@ -346,8 +346,8 @@ class CurrencyController extends Controller
{ {
/** @var User $user */ /** @var User $user */
$user = auth()->user(); $user = auth()->user();
$page = 0 === (int)$request->get('page') ? 1 : (int)$request->get('page'); $page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
$pageSize = (int)app('preferences')->get('listPageSize', 50)->data; $pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$collection = $this->repository->getAll(); $collection = $this->repository->getAll();
$total = $collection->count(); $total = $collection->count();
$collection = $collection->slice(($page - 1) * $pageSize, $pageSize); $collection = $collection->slice(($page - 1) * $pageSize, $pageSize);
@@ -357,7 +357,7 @@ class CurrencyController extends Controller
$defaultCurrency = $this->repository->getCurrencyByPreference(app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR'))); $defaultCurrency = $this->repository->getCurrencyByPreference(app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR')));
$isOwner = true; $isOwner = true;
if (!$this->userRepository->hasRole($user, 'owner')) { if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('info', (string)trans('firefly.ask_site_owner', ['owner' => config('firefly.site_owner')])); $request->session()->flash('info', (string) trans('firefly.ask_site_owner', ['owner' => config('firefly.site_owner')]));
$isOwner = false; $isOwner = false;
} }
@@ -391,15 +391,15 @@ class CurrencyController extends Controller
} catch (FireflyException $e) { } catch (FireflyException $e) {
Log::error($e->getMessage()); Log::error($e->getMessage());
Log::channel('audit')->info('Could not store (POST) currency without admin rights.', $data); Log::channel('audit')->info('Could not store (POST) currency without admin rights.', $data);
$request->session()->flash('error', (string)trans('firefly.could_not_store_currency')); $request->session()->flash('error', (string) trans('firefly.could_not_store_currency'));
$currency = null; $currency = null;
} }
$redirect = redirect($this->getPreviousUri('currencies.create.uri')); $redirect = redirect($this->getPreviousUri('currencies.create.uri'));
if (null !== $currency) { if (null !== $currency) {
$request->session()->flash('success', (string)trans('firefly.created_currency', ['name' => $currency->name])); $request->session()->flash('success', (string) trans('firefly.created_currency', ['name' => $currency->name]));
Log::channel('audit')->info('Created (POST) currency.', $data); Log::channel('audit')->info('Created (POST) currency.', $data);
if (1 === (int)$request->get('create_another')) { if (1 === (int) $request->get('create_another')) {
$request->session()->put('currencies.create.fromStore', true); $request->session()->put('currencies.create.fromStore', true);
@@ -430,7 +430,7 @@ class CurrencyController extends Controller
} }
if (!$this->userRepository->hasRole($user, 'owner')) { if (!$this->userRepository->hasRole($user, 'owner')) {
$request->session()->flash('error', (string)trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))])); $request->session()->flash('error', (string) trans('firefly.ask_site_owner', ['owner' => e(config('firefly.site_owner'))]));
Log::channel('audit')->info('Tried to update (POST) currency without admin rights.', $data); Log::channel('audit')->info('Tried to update (POST) currency without admin rights.', $data);
return redirect(route('currencies.index')); return redirect(route('currencies.index'));
@@ -438,10 +438,10 @@ class CurrencyController extends Controller
} }
$currency = $this->repository->update($currency, $data); $currency = $this->repository->update($currency, $data);
Log::channel('audit')->info('Updated (POST) currency.', $data); Log::channel('audit')->info('Updated (POST) currency.', $data);
$request->session()->flash('success', (string)trans('firefly.updated_currency', ['name' => $currency->name])); $request->session()->flash('success', (string) trans('firefly.updated_currency', ['name' => $currency->name]));
app('preferences')->mark(); app('preferences')->mark();
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int) $request->get('return_to_edit')) {
$request->session()->put('currencies.edit.fromUpdate', true); $request->session()->put('currencies.edit.fromUpdate', true);

View File

@@ -54,7 +54,7 @@ class IndexController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-life-bouy'); app('view')->share('mainTitleIcon', 'fa-life-bouy');
app('view')->share('title', (string)trans('firefly.export_data_title')); app('view')->share('title', (string) trans('firefly.export_data_title'));
$this->journalRepository = app(JournalRepositoryInterface::class); $this->journalRepository = app(JournalRepositoryInterface::class);
$this->middleware(IsDemoUser::class)->except(['index']); $this->middleware(IsDemoUser::class)->except(['index']);
@@ -85,7 +85,7 @@ class IndexController extends Controller
$generator->setStart($firstDate); $generator->setStart($firstDate);
$result = $generator->export(); $result = $generator->export();
$name = sprintf('%s_transaction_export.csv', date('Y_m_d')); $name = sprintf('%s_transaction_export.csv', date('Y_m_d'));
$quoted = sprintf('"%s"', addcslashes($name, '"\\')); $quoted = sprintf('"%s"', addcslashes($name, '"\\'));
// headers for CSV file. // headers for CSV file.
/** @var LaravelResponse $response */ /** @var LaravelResponse $response */

View File

@@ -27,7 +27,6 @@ use Exception;
use FireflyIII\Events\RequestedVersionCheckStatus; use FireflyIII\Events\RequestedVersionCheckStatus;
use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Helpers\Collector\GroupCollectorInterface;
use FireflyIII\Http\Middleware\Installer; use FireflyIII\Http\Middleware\Installer;
use FireflyIII\Mail\UndoEmailChangeMail;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\Bill\BillRepositoryInterface; use FireflyIII\Repositories\Bill\BillRepositoryInterface;
@@ -36,7 +35,6 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Log; use Log;
use Mail;
/** /**
* Class HomeController. * Class HomeController.

View File

@@ -56,14 +56,14 @@ class JavascriptController extends Controller
); );
$preference = app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR')); $preference = app('preferences')->get('currencyPreference', config('firefly.default_currency', 'EUR'));
/** @noinspection NullPointerExceptionInspection */ /** @noinspection NullPointerExceptionInspection */
$default = $currencyRepository->findByCodeNull((string)$preference->data); $default = $currencyRepository->findByCodeNull((string) $preference->data);
$data = ['accounts' => []]; $data = ['accounts' => []];
/** @var Account $account */ /** @var Account $account */
foreach ($accounts as $account) { foreach ($accounts as $account) {
$accountId = $account->id; $accountId = $account->id;
$currency = (int)$repository->getMetaValue($account, 'currency_id'); $currency = (int) $repository->getMetaValue($account, 'currency_id');
/** @noinspection NullPointerExceptionInspection */ /** @noinspection NullPointerExceptionInspection */
$currency = 0 === $currency ? $default->id : $currency; $currency = 0 === $currency ? $default->id : $currency;
$entry = ['preferredCurrency' => $currency, 'name' => $account->name]; $entry = ['preferredCurrency' => $currency, 'name' => $account->name];
@@ -110,7 +110,7 @@ class JavascriptController extends Controller
*/ */
public function variables(Request $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response public function variables(Request $request, AccountRepositoryInterface $repository, CurrencyRepositoryInterface $currencyRepository): Response
{ {
$account = $repository->find((int)$request->get('account')); $account = $repository->find((int) $request->get('account'));
$currency = app('amount')->getDefaultCurrency(); $currency = app('amount')->getDefaultCurrency();
if (null !== $account) { if (null !== $account) {
$currency = $repository->getAccountCurrency($account) ?? $currency; $currency = $repository->getAccountCurrency($account) ?? $currency;
@@ -122,7 +122,7 @@ class JavascriptController extends Controller
/** @noinspection NullPointerExceptionInspection */ /** @noinspection NullPointerExceptionInspection */
$lang = $pref->data; $lang = $pref->data;
$dateRange = $this->getDateRangeConfig(); $dateRange = $this->getDateRangeConfig();
$uid = substr(hash('sha256', sprintf('%s-%s-%s', (string)config('app.key'), auth()->user()->id, auth()->user()->email)), 0, 12); $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, 'currencyCode' => $currency->code,

View File

@@ -66,7 +66,7 @@ class BoxController extends Controller
$end = session('end', Carbon::now()->endOfMonth()); $end = session('end', Carbon::now()->endOfMonth());
$today = today(config('app.timezone')); $today = today(config('app.timezone'));
$display = 2; // see method docs. $display = 2; // see method docs.
$boxTitle = (string)trans('firefly.spent'); $boxTitle = (string) trans('firefly.spent');
$cache = new CacheProperties; $cache = new CacheProperties;
$cache->addProperty($start); $cache->addProperty($start);
@@ -93,21 +93,21 @@ class BoxController extends Controller
// spent in this period, in budgets, for default currency. // spent in this period, in budgets, for default currency.
// also calculate spent per day. // also calculate spent per day.
$spent = $opsRepository->sumExpenses($start, $end, null, null, $currency); $spent = $opsRepository->sumExpenses($start, $end, null, null, $currency);
$spentAmount = $spent[(int)$currency->id]['sum'] ?? '0'; $spentAmount = $spent[(int) $currency->id]['sum'] ?? '0';
$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;
$spentPerDay = bcdiv($spentAmount, (string)$days); $spentPerDay = bcdiv($spentAmount, (string) $days);
if ($availableBudgets->count() > 0) { if ($availableBudgets->count() > 0) {
$display = 0; // assume user overspent $display = 0; // assume user overspent
$boxTitle = (string)trans('firefly.overspent'); $boxTitle = (string) trans('firefly.overspent');
$totalAvailableSum = (string)$availableBudgets->sum('amount'); $totalAvailableSum = (string) $availableBudgets->sum('amount');
// calculate with available budget. // calculate with available budget.
$leftToSpendAmount = bcadd($totalAvailableSum, $spentAmount); $leftToSpendAmount = bcadd($totalAvailableSum, $spentAmount);
if (1 === bccomp($leftToSpendAmount, '0')) { if (1 === bccomp($leftToSpendAmount, '0')) {
$boxTitle = (string)trans('firefly.left_to_spend'); $boxTitle = (string) trans('firefly.left_to_spend');
$days = $today->diffInDays($end) + 1; $days = $today->diffInDays($end) + 1;
$display = 1; // not overspent $display = 1; // not overspent
$leftPerDayAmount = bcdiv($leftToSpendAmount, (string)$days); $leftPerDayAmount = bcdiv($leftToSpendAmount, (string) $days);
} }
} }
@@ -161,7 +161,7 @@ class BoxController extends Controller
$set = $collector->getExtractedJournals(); $set = $collector->getExtractedJournals();
/** @var array $journal */ /** @var array $journal */
foreach ($set as $journal) { foreach ($set as $journal) {
$currencyId = (int)$journal['currency_id']; $currencyId = (int) $journal['currency_id'];
$amount = $journal['amount'] ?? '0'; $amount = $journal['amount'] ?? '0';
$incomes[$currencyId] = $incomes[$currencyId] ?? '0'; $incomes[$currencyId] = $incomes[$currencyId] ?? '0';
$incomes[$currencyId] = bcadd($incomes[$currencyId], app('steam')->positive($amount)); $incomes[$currencyId] = bcadd($incomes[$currencyId], app('steam')->positive($amount));
@@ -177,7 +177,7 @@ class BoxController extends Controller
$set = $collector->getExtractedJournals(); $set = $collector->getExtractedJournals();
/** @var array $journal */ /** @var array $journal */
foreach ($set as $journal) { foreach ($set as $journal) {
$currencyId = (int)$journal['currency_id']; $currencyId = (int) $journal['currency_id'];
$expenses[$currencyId] = $expenses[$currencyId] ?? '0'; $expenses[$currencyId] = $expenses[$currencyId] ?? '0';
$expenses[$currencyId] = bcadd($expenses[$currencyId], $journal['amount'] ?? '0'); $expenses[$currencyId] = bcadd($expenses[$currencyId], $journal['amount'] ?? '0');
$sums[$currencyId] = $sums[$currencyId] ?? '0'; $sums[$currencyId] = $sums[$currencyId] ?? '0';

View File

@@ -64,7 +64,7 @@ class BudgetController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.budgets')); app('view')->share('title', (string) trans('firefly.budgets'));
app('view')->share('mainTitleIcon', 'fa-pie-chart'); app('view')->share('mainTitleIcon', 'fa-pie-chart');
$this->repository = app(BudgetRepositoryInterface::class); $this->repository = app(BudgetRepositoryInterface::class);
$this->opsRepository = app(OperationsRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class);

View File

@@ -51,7 +51,7 @@ class FrontpageController extends Controller
if (1 === bccomp($amount, '0')) { if (1 === bccomp($amount, '0')) {
// percentage! // percentage!
$pct = 0; $pct = 0;
if(0.0 !== (float)$piggyBank->targetamount) { if (0.0 !== (float) $piggyBank->targetamount) {
$pct = round(($amount / $piggyBank->targetamount) * 100); $pct = round(($amount / $piggyBank->targetamount) * 100);
} }

View File

@@ -118,7 +118,7 @@ class IntroController extends Controller
app('preferences')->set($key, false); app('preferences')->set($key, false);
app('preferences')->mark(); app('preferences')->mark();
return response()->json(['message' => (string)trans('firefly.intro_boxes_after_refresh')]); return response()->json(['message' => (string) trans('firefly.intro_boxes_after_refresh')]);
} }
/** /**

View File

@@ -63,7 +63,7 @@ class ReconcileController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-credit-card'); app('view')->share('mainTitleIcon', 'fa-credit-card');
app('view')->share('title', (string)trans('firefly.accounts')); app('view')->share('title', (string) trans('firefly.accounts'));
$this->repository = app(JournalRepositoryInterface::class); $this->repository = app(JournalRepositoryInterface::class);
$this->accountRepos = app(AccountRepositoryInterface::class); $this->accountRepos = app(AccountRepositoryInterface::class);
$this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class);
@@ -236,8 +236,8 @@ class ReconcileController extends Controller
$startDate->subDay(); $startDate->subDay();
$currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency(); $currency = $this->accountRepos->getAccountCurrency($account) ?? app('amount')->getDefaultCurrency();
$startBalance = round((float)app('steam')->balance($account, $startDate), $currency->decimal_places); $startBalance = round((float) app('steam')->balance($account, $startDate), $currency->decimal_places);
$endBalance = round((float)app('steam')->balance($account, $end), $currency->decimal_places); $endBalance = round((float) app('steam')->balance($account, $end), $currency->decimal_places);
// get the transactions // get the transactions
$selectionStart = clone $start; $selectionStart = clone $start;

View File

@@ -73,10 +73,10 @@ class RecurrenceController extends Controller
$start = Carbon::createFromFormat('Y-m-d', $request->get('start')); $start = Carbon::createFromFormat('Y-m-d', $request->get('start'));
$end = Carbon::createFromFormat('Y-m-d', $request->get('end')); $end = Carbon::createFromFormat('Y-m-d', $request->get('end'));
$firstDate = Carbon::createFromFormat('Y-m-d', $request->get('first_date')); $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; $endDate = '' !== (string) $request->get('end_date') ? Carbon::createFromFormat('Y-m-d', $request->get('end_date')) : null;
$endsAt = (string)$request->get('ends'); $endsAt = (string) $request->get('ends');
$repetitionType = explode(',', $request->get('type'))[0]; $repetitionType = explode(',', $request->get('type'))[0];
$repetitions = (int)$request->get('reps'); $repetitions = (int) $request->get('reps');
$repetitionMoment = ''; $repetitionMoment = '';
$start->startOfDay(); $start->startOfDay();
@@ -100,8 +100,8 @@ class RecurrenceController extends Controller
$repetition = new RecurrenceRepetition; $repetition = new RecurrenceRepetition;
$repetition->repetition_type = $repetitionType; $repetition->repetition_type = $repetitionType;
$repetition->repetition_moment = $repetitionMoment; $repetition->repetition_moment = $repetitionMoment;
$repetition->repetition_skip = (int)$request->get('skip'); $repetition->repetition_skip = (int) $request->get('skip');
$repetition->weekend = (int)$request->get('weekend'); $repetition->weekend = (int) $request->get('weekend');
$actualEnd = clone $end; $actualEnd = clone $end;
switch ($endsAt) { switch ($endsAt) {
@@ -149,30 +149,30 @@ class RecurrenceController extends Controller
$string = $request->get('date') ?? date('Y-m-d'); $string = $request->get('date') ?? date('Y-m-d');
$today = Carbon::now()->startOfDay(); $today = Carbon::now()->startOfDay();
$date = Carbon::createFromFormat('Y-m-d', $string)->startOfDay(); $date = Carbon::createFromFormat('Y-m-d', $string)->startOfDay();
$preSelected = (string)$request->get('pre_select'); $preSelected = (string) $request->get('pre_select');
$locale = app('steam')->getLocale(); $locale = app('steam')->getLocale();
Log::debug(sprintf('date = %s, today = %s. date > today? %s', $date->toAtomString(), $today->toAtomString(), var_export($date > $today, true))); Log::debug(sprintf('date = %s, today = %s. date > today? %s', $date->toAtomString(), $today->toAtomString(), var_export($date > $today, true)));
Log::debug(sprintf('past = true? %s', var_export('true' === (string)$request->get('past'), true))); Log::debug(sprintf('past = true? %s', var_export('true' === (string) $request->get('past'), true)));
$result = []; $result = [];
if ($date > $today || 'true' === (string)$request->get('past')) { if ($date > $today || 'true' === (string) $request->get('past')) {
Log::debug('Will fill dropdown.'); Log::debug('Will fill dropdown.');
$weekly = sprintf('weekly,%s', $date->dayOfWeekIso); $weekly = sprintf('weekly,%s', $date->dayOfWeekIso);
$monthly = sprintf('monthly,%s', $date->day); $monthly = sprintf('monthly,%s', $date->day);
$dayOfWeek = (string)trans(sprintf('config.dow_%s', $date->dayOfWeekIso)); $dayOfWeek = (string) trans(sprintf('config.dow_%s', $date->dayOfWeekIso));
$ndom = sprintf('ndom,%s,%s', $date->weekOfMonth, $date->dayOfWeekIso); $ndom = sprintf('ndom,%s,%s', $date->weekOfMonth, $date->dayOfWeekIso);
$yearly = sprintf('yearly,%s', $date->format('Y-m-d')); $yearly = sprintf('yearly,%s', $date->format('Y-m-d'));
$yearlyDate = $date->isoFormat((string)trans('config.month_and_day_no_year_js', [], $locale)); $yearlyDate = $date->isoFormat((string) trans('config.month_and_day_no_year_js', [], $locale));
$result = [ $result = [
'daily' => ['label' => (string)trans('firefly.recurring_daily'), 'selected' => str_starts_with($preSelected, 'daily')], 'daily' => ['label' => (string) trans('firefly.recurring_daily'), 'selected' => str_starts_with($preSelected, 'daily')],
$weekly => ['label' => (string)trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]), $weekly => ['label' => (string) trans('firefly.recurring_weekly', ['weekday' => $dayOfWeek]),
'selected' => str_starts_with($preSelected, 'weekly')], 'selected' => str_starts_with($preSelected, 'weekly')],
$monthly => ['label' => (string)trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]), $monthly => ['label' => (string) trans('firefly.recurring_monthly', ['dayOfMonth' => $date->day]),
'selected' => str_starts_with($preSelected, 'monthly')], 'selected' => str_starts_with($preSelected, 'monthly')],
$ndom => ['label' => (string)trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]), $ndom => ['label' => (string) trans('firefly.recurring_ndom', ['weekday' => $dayOfWeek, 'dayOfMonth' => $date->weekOfMonth]),
'selected' => str_starts_with($preSelected, 'ndom')], 'selected' => str_starts_with($preSelected, 'ndom')],
$yearly => ['label' => (string)trans('firefly.recurring_yearly', ['date' => $yearlyDate]), $yearly => ['label' => (string) trans('firefly.recurring_yearly', ['date' => $yearlyDate]),
'selected' => str_starts_with($preSelected, 'yearly')], 'selected' => str_starts_with($preSelected, 'yearly')],
]; ];
} }

View File

@@ -43,11 +43,11 @@ class RuleController extends Controller
*/ */
public function action(Request $request): JsonResponse public function action(Request $request): JsonResponse
{ {
$count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1; $count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1;
$keys = array_keys(config('firefly.rule-actions')); $keys = array_keys(config('firefly.rule-actions'));
$actions = []; $actions = [];
foreach ($keys as $key) { foreach ($keys as $key) {
$actions[$key] = (string)trans('firefly.rule_action_' . $key . '_choice'); $actions[$key] = (string) trans('firefly.rule_action_' . $key . '_choice');
} }
try { try {
$view = view('rules.partials.action', compact('actions', 'count'))->render(); $view = view('rules.partials.action', compact('actions', 'count'))->render();
@@ -69,13 +69,13 @@ class RuleController extends Controller
*/ */
public function trigger(Request $request): JsonResponse public function trigger(Request $request): JsonResponse
{ {
$count = (int)$request->get('count') > 0 ? (int)$request->get('count') : 1; $count = (int) $request->get('count') > 0 ? (int) $request->get('count') : 1;
$operators = config('search.operators'); $operators = config('search.operators');
$triggers = []; $triggers = [];
foreach ($operators as $key => $operator) { foreach ($operators as $key => $operator) {
if ('user_action' !== $key && false === $operator['alias']) { if ('user_action' !== $key && false === $operator['alias']) {
$triggers[$key] = (string)trans(sprintf('firefly.rule_trigger_%s_choice', $key)); $triggers[$key] = (string) trans(sprintf('firefly.rule_trigger_%s_choice', $key));
} }
} }
asort($triggers); asort($triggers);

View File

@@ -66,7 +66,7 @@ class NewUserController extends Controller
*/ */
public function index() public function index()
{ {
app('view')->share('title', (string)trans('firefly.welcome')); app('view')->share('title', (string) trans('firefly.welcome'));
app('view')->share('mainTitleIcon', 'fa-fire'); app('view')->share('mainTitleIcon', 'fa-fire');
$types = config('firefly.accountTypesByIdentifier.asset'); $types = config('firefly.accountTypesByIdentifier.asset');
@@ -84,7 +84,7 @@ class NewUserController extends Controller
/** /**
* Store his new settings. * Store his new settings.
* *
* @param NewUserFormRequest $request * @param NewUserFormRequest $request
* @param CurrencyRepositoryInterface $currencyRepository * @param CurrencyRepositoryInterface $currencyRepository
* *
* @return RedirectResponse|Redirector * @return RedirectResponse|Redirector
@@ -101,7 +101,7 @@ class NewUserController extends Controller
// set language preference: // set language preference:
app('preferences')->set('language', $language); app('preferences')->set('language', $language);
// Store currency preference from input: // 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 is null, set to EUR:
if (null === $currency) { if (null === $currency) {
@@ -109,9 +109,9 @@ class NewUserController extends Controller
} }
$currencyRepository->enable($currency); $currencyRepository->enable($currency);
$this->createAssetAccount($request, $currency); // create normal asset account $this->createAssetAccount($request, $currency); // create normal asset account
$this->createSavingsAccount($request, $currency, $language); // create savings account $this->createSavingsAccount($request, $currency, $language); // create savings account
$this->createCashWalletAccount($currency, $language); // create cash wallet account $this->createCashWalletAccount($currency, $language); // create cash wallet account
// store currency preference: // store currency preference:
app('preferences')->set('currencyPreference', $currency->code); app('preferences')->set('currencyPreference', $currency->code);
@@ -128,7 +128,7 @@ class NewUserController extends Controller
'invoice_date' => false, 'internal_reference' => false, 'notes' => true, 'attachments' => true,]; 'invoice_date' => false, 'internal_reference' => false, 'notes' => true, 'attachments' => true,];
app('preferences')->set('transaction_journal_optional_fields', $visibleFields); app('preferences')->set('transaction_journal_optional_fields', $visibleFields);
session()->flash('success', (string)trans('firefly.stored_new_accounts_new_user')); session()->flash('success', (string) trans('firefly.stored_new_accounts_new_user'));
app('preferences')->mark(); app('preferences')->mark();
return redirect(route('index')); return redirect(route('index'));

View File

@@ -50,7 +50,7 @@ class DeleteController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-envelope-o'); app('view')->share('mainTitleIcon', 'fa-envelope-o');
app('view')->share('title', (string)trans('firefly.object_groups_page_title')); app('view')->share('title', (string) trans('firefly.object_groups_page_title'));
$this->repository = app(ObjectGroupRepositoryInterface::class); $this->repository = app(ObjectGroupRepositoryInterface::class);
@@ -68,7 +68,7 @@ class DeleteController extends Controller
*/ */
public function delete(ObjectGroup $objectGroup) public function delete(ObjectGroup $objectGroup)
{ {
$subTitle = (string)trans('firefly.delete_object_group', ['title' => $objectGroup->title]); $subTitle = (string) trans('firefly.delete_object_group', ['title' => $objectGroup->title]);
$piggyBanks = $objectGroup->piggyBanks()->count(); $piggyBanks = $objectGroup->piggyBanks()->count();
// put previous url in session // put previous url in session
@@ -86,7 +86,7 @@ class DeleteController extends Controller
*/ */
public function destroy(ObjectGroup $objectGroup): RedirectResponse public function destroy(ObjectGroup $objectGroup): RedirectResponse
{ {
session()->flash('success', (string)trans('firefly.deleted_object_group', ['title' => $objectGroup->title])); session()->flash('success', (string) trans('firefly.deleted_object_group', ['title' => $objectGroup->title]));
app('preferences')->mark(); app('preferences')->mark();
$this->repository->destroy($objectGroup); $this->repository->destroy($objectGroup);

View File

@@ -53,7 +53,7 @@ class EditController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-envelope-o'); app('view')->share('mainTitleIcon', 'fa-envelope-o');
app('view')->share('title', (string)trans('firefly.object_groups_page_title')); app('view')->share('title', (string) trans('firefly.object_groups_page_title'));
$this->repository = app(ObjectGroupRepositoryInterface::class); $this->repository = app(ObjectGroupRepositoryInterface::class);
@@ -71,7 +71,7 @@ class EditController extends Controller
*/ */
public function edit(ObjectGroup $objectGroup) public function edit(ObjectGroup $objectGroup)
{ {
$subTitle = (string)trans('firefly.edit_object_group', ['title' => $objectGroup->title]); $subTitle = (string) trans('firefly.edit_object_group', ['title' => $objectGroup->title]);
$subTitleIcon = 'fa-pencil'; $subTitleIcon = 'fa-pencil';
if (true !== session('object-groups.edit.fromUpdate')) { if (true !== session('object-groups.edit.fromUpdate')) {
@@ -95,12 +95,12 @@ class EditController extends Controller
$data = $request->getObjectGroupData(); $data = $request->getObjectGroupData();
$piggyBank = $this->repository->update($objectGroup, $data); $piggyBank = $this->repository->update($objectGroup, $data);
session()->flash('success', (string)trans('firefly.updated_object_group', ['title' => $objectGroup->title])); session()->flash('success', (string) trans('firefly.updated_object_group', ['title' => $objectGroup->title]));
app('preferences')->mark(); app('preferences')->mark();
$redirect = redirect($this->getPreviousUri('object-groups.edit.uri')); $redirect = redirect($this->getPreviousUri('object-groups.edit.uri'));
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int) $request->get('return_to_edit')) {
session()->put('object-groups.edit.fromUpdate', true); session()->put('object-groups.edit.fromUpdate', true);

View File

@@ -53,7 +53,7 @@ class IndexController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-envelope-o'); app('view')->share('mainTitleIcon', 'fa-envelope-o');
app('view')->share('title', (string)trans('firefly.object_groups_page_title')); app('view')->share('title', (string) trans('firefly.object_groups_page_title'));
$this->repository = app(ObjectGroupRepositoryInterface::class); $this->repository = app(ObjectGroupRepositoryInterface::class);
return $next($request); return $next($request);
@@ -68,7 +68,7 @@ class IndexController extends Controller
{ {
$this->repository->deleteEmpty(); $this->repository->deleteEmpty();
$this->repository->resetOrder(); $this->repository->resetOrder();
$subTitle = (string)trans('firefly.object_groups_index'); $subTitle = (string) trans('firefly.object_groups_index');
$objectGroups = $this->repository->get(); $objectGroups = $this->repository->get();
return view('object-groups.index', compact('subTitle', 'objectGroups')); return view('object-groups.index', compact('subTitle', 'objectGroups'));
@@ -83,7 +83,7 @@ class IndexController extends Controller
public function setOrder(Request $request, ObjectGroup $objectGroup) public function setOrder(Request $request, ObjectGroup $objectGroup)
{ {
Log::debug(sprintf('Found object group #%d "%s"', $objectGroup->id, $objectGroup->title)); Log::debug(sprintf('Found object group #%d "%s"', $objectGroup->id, $objectGroup->title));
$newOrder = (int)$request->get('order'); $newOrder = (int) $request->get('order');
$this->repository->setOrder($objectGroup, $newOrder); $this->repository->setOrder($objectGroup, $newOrder);
return response()->json([]); return response()->json([]);

View File

@@ -53,7 +53,7 @@ class CreateController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('title', (string) trans('firefly.piggyBanks'));
app('view')->share('mainTitleIcon', 'fa-bullseye'); app('view')->share('mainTitleIcon', 'fa-bullseye');
$this->attachments = app(AttachmentHelperInterface::class); $this->attachments = app(AttachmentHelperInterface::class);
@@ -71,7 +71,7 @@ class CreateController extends Controller
*/ */
public function create() public function create()
{ {
$subTitle = (string)trans('firefly.new_piggy_bank'); $subTitle = (string) trans('firefly.new_piggy_bank');
$subTitleIcon = 'fa-plus'; $subTitleIcon = 'fa-plus';
// put previous url in session if not redirect from store (not "create another"). // put previous url in session if not redirect from store (not "create another").
@@ -99,7 +99,7 @@ class CreateController extends Controller
} }
$piggyBank = $this->piggyRepos->store($data); $piggyBank = $this->piggyRepos->store($data);
session()->flash('success', (string)trans('firefly.stored_piggy_bank', ['name' => $piggyBank->name])); session()->flash('success', (string) trans('firefly.stored_piggy_bank', ['name' => $piggyBank->name]));
app('preferences')->mark(); app('preferences')->mark();
// store attachment(s): // store attachment(s):
@@ -109,7 +109,7 @@ class CreateController extends Controller
$this->attachments->saveAttachmentsForModel($piggyBank, $files); $this->attachments->saveAttachmentsForModel($piggyBank, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -117,7 +117,7 @@ class CreateController extends Controller
} }
$redirect = redirect($this->getPreviousUri('piggy-banks.create.uri')); $redirect = redirect($this->getPreviousUri('piggy-banks.create.uri'));
if (1 === (int)$request->get('create_another')) { if (1 === (int) $request->get('create_another')) {
session()->put('piggy-banks.create.fromStore', true); session()->put('piggy-banks.create.fromStore', true);

View File

@@ -50,7 +50,7 @@ class DeleteController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('title', (string) trans('firefly.piggyBanks'));
app('view')->share('mainTitleIcon', 'fa-bullseye'); app('view')->share('mainTitleIcon', 'fa-bullseye');
$this->piggyRepos = app(PiggyBankRepositoryInterface::class); $this->piggyRepos = app(PiggyBankRepositoryInterface::class);
@@ -69,7 +69,7 @@ class DeleteController extends Controller
*/ */
public function delete(PiggyBank $piggyBank) public function delete(PiggyBank $piggyBank)
{ {
$subTitle = (string)trans('firefly.delete_piggy_bank', ['name' => $piggyBank->name]); $subTitle = (string) trans('firefly.delete_piggy_bank', ['name' => $piggyBank->name]);
// put previous url in session // put previous url in session
$this->rememberPreviousUri('piggy-banks.delete.uri'); $this->rememberPreviousUri('piggy-banks.delete.uri');
@@ -86,7 +86,7 @@ class DeleteController extends Controller
*/ */
public function destroy(PiggyBank $piggyBank): RedirectResponse public function destroy(PiggyBank $piggyBank): RedirectResponse
{ {
session()->flash('success', (string)trans('firefly.deleted_piggy_bank', ['name' => $piggyBank->name])); session()->flash('success', (string) trans('firefly.deleted_piggy_bank', ['name' => $piggyBank->name]));
app('preferences')->mark(); app('preferences')->mark();
$this->piggyRepos->destroy($piggyBank); $this->piggyRepos->destroy($piggyBank);

View File

@@ -24,13 +24,13 @@ declare(strict_types=1);
namespace FireflyIII\Http\Controllers\PiggyBank; namespace FireflyIII\Http\Controllers\PiggyBank;
use Amount;
use FireflyIII\Helpers\Attachments\AttachmentHelperInterface; use FireflyIII\Helpers\Attachments\AttachmentHelperInterface;
use FireflyIII\Http\Controllers\Controller; use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Http\Requests\PiggyBankUpdateRequest; use FireflyIII\Http\Requests\PiggyBankUpdateRequest;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
use FireflyIII\Repositories\Account\AccountRepositoryInterface; use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
use Amount;
use Illuminate\Contracts\View\Factory; use Illuminate\Contracts\View\Factory;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Routing\Redirector; use Illuminate\Routing\Redirector;
@@ -41,9 +41,9 @@ use Illuminate\View\View;
*/ */
class EditController extends Controller class EditController extends Controller
{ {
private AccountRepositoryInterface $accountRepository;
private AttachmentHelperInterface $attachments; private AttachmentHelperInterface $attachments;
private PiggyBankRepositoryInterface $piggyRepos; private PiggyBankRepositoryInterface $piggyRepos;
private AccountRepositoryInterface $accountRepository;
/** /**
* PiggyBankController constructor. * PiggyBankController constructor.
@@ -95,7 +95,7 @@ class EditController extends Controller
'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '', 'object_group' => $piggyBank->objectGroups->first() ? $piggyBank->objectGroups->first()->title : '',
'notes' => null === $note ? '' : $note->text, 'notes' => null === $note ? '' : $note->text,
]; ];
if(0.0 === (float) $piggyBank->targetamount) { if (0.0 === (float) $piggyBank->targetamount) {
$preFilled['targetamount'] = ''; $preFilled['targetamount'] = '';
} }
session()->flash('preFilled', $preFilled); session()->flash('preFilled', $preFilled);

View File

@@ -57,7 +57,7 @@ class IndexController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('title', (string) trans('firefly.piggyBanks'));
app('view')->share('mainTitleIcon', 'fa-bullseye'); app('view')->share('mainTitleIcon', 'fa-bullseye');
$this->piggyRepos = app(PiggyBankRepositoryInterface::class); $this->piggyRepos = app(PiggyBankRepositoryInterface::class);
@@ -101,7 +101,7 @@ class IndexController extends Controller
/** @var PiggyBank $piggy */ /** @var PiggyBank $piggy */
foreach ($collection as $piggy) { foreach ($collection as $piggy) {
$array = $transformer->transform($piggy); $array = $transformer->transform($piggy);
$groupOrder = (int)$array['object_group_order']; $groupOrder = (int) $array['object_group_order'];
// make group array if necessary: // make group array if necessary:
$piggyBanks[$groupOrder] = $piggyBanks[$groupOrder] ?? [ $piggyBanks[$groupOrder] = $piggyBanks[$groupOrder] ?? [
'object_group_id' => $array['object_group_id'] ?? 0, 'object_group_id' => $array['object_group_id'] ?? 0,
@@ -110,7 +110,7 @@ class IndexController extends Controller
]; ];
$account = $accountTransformer->transform($piggy->account); $account = $accountTransformer->transform($piggy->account);
$accountId = (int)$account['id']; $accountId = (int) $account['id'];
$array['attachments'] = $this->piggyRepos->getAttachments($piggy); $array['attachments'] = $this->piggyRepos->getAttachments($piggy);
if (!array_key_exists($accountId, $accounts)) { if (!array_key_exists($accountId, $accounts)) {
// create new: // create new:
@@ -165,10 +165,10 @@ class IndexController extends Controller
// current_amount // current_amount
// left_to_save // left_to_save
// save_per_month // save_per_month
$sums[$groupId][$currencyId]['target'] = bcadd($sums[$groupId][$currencyId]['target'], (string)$piggy['target_amount']); $sums[$groupId][$currencyId]['target'] = bcadd($sums[$groupId][$currencyId]['target'], (string) $piggy['target_amount']);
$sums[$groupId][$currencyId]['saved'] = bcadd($sums[$groupId][$currencyId]['saved'], (string)$piggy['current_amount']); $sums[$groupId][$currencyId]['saved'] = bcadd($sums[$groupId][$currencyId]['saved'], (string) $piggy['current_amount']);
$sums[$groupId][$currencyId]['left_to_save'] = bcadd($sums[$groupId][$currencyId]['left_to_save'], (string)$piggy['left_to_save']); $sums[$groupId][$currencyId]['left_to_save'] = bcadd($sums[$groupId][$currencyId]['left_to_save'], (string) $piggy['left_to_save']);
$sums[$groupId][$currencyId]['save_per_month'] = bcadd($sums[$groupId][$currencyId]['save_per_month'], (string)$piggy['save_per_month']); $sums[$groupId][$currencyId]['save_per_month'] = bcadd($sums[$groupId][$currencyId]['save_per_month'], (string) $piggy['save_per_month']);
} }
} }
foreach ($piggyBanks as $groupOrder => $group) { foreach ($piggyBanks as $groupOrder => $group) {
@@ -189,8 +189,8 @@ class IndexController extends Controller
*/ */
public function setOrder(Request $request, PiggyBank $piggyBank): JsonResponse public function setOrder(Request $request, PiggyBank $piggyBank): JsonResponse
{ {
$objectGroupTitle = (string)$request->get('objectGroupTitle'); $objectGroupTitle = (string) $request->get('objectGroupTitle');
$newOrder = (int)$request->get('order'); $newOrder = (int) $request->get('order');
$this->piggyRepos->setOrder($piggyBank, $newOrder); $this->piggyRepos->setOrder($piggyBank, $newOrder);
if ('' !== $objectGroupTitle) { if ('' !== $objectGroupTitle) {
$this->piggyRepos->setObjectGroup($piggyBank, $objectGroupTitle); $this->piggyRepos->setObjectGroup($piggyBank, $objectGroupTitle);

View File

@@ -51,7 +51,7 @@ class ShowController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.piggyBanks')); app('view')->share('title', (string) trans('firefly.piggyBanks'));
app('view')->share('mainTitleIcon', 'fa-bullseye'); app('view')->share('mainTitleIcon', 'fa-bullseye');
$this->piggyRepos = app(PiggyBankRepositoryInterface::class); $this->piggyRepos = app(PiggyBankRepositoryInterface::class);

View File

@@ -51,7 +51,7 @@ class PreferencesController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('title', (string)trans('firefly.preferences')); app('view')->share('title', (string) trans('firefly.preferences'));
app('view')->share('mainTitleIcon', 'fa-gear'); app('view')->share('mainTitleIcon', 'fa-gear');
return $next($request); return $next($request);
@@ -114,7 +114,7 @@ class PreferencesController extends Controller
Log::error($e->getMessage()); Log::error($e->getMessage());
$locales = []; $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 // an important fallback is that the frontPageAccount array gets refilled automatically
// when it turns up empty. // when it turns up empty.
if (empty($frontPageAccounts->data)) { if (empty($frontPageAccounts->data)) {
@@ -154,7 +154,7 @@ class PreferencesController extends Controller
$frontPageAccounts = []; $frontPageAccounts = [];
if (is_array($request->get('frontPageAccounts')) && count($request->get('frontPageAccounts')) > 0) { if (is_array($request->get('frontPageAccounts')) && count($request->get('frontPageAccounts')) > 0) {
foreach ($request->get('frontPageAccounts') as $id) { foreach ($request->get('frontPageAccounts') as $id) {
$frontPageAccounts[] = (int)$id; $frontPageAccounts[] = (int) $id;
} }
app('preferences')->set('frontPageAccounts', $frontPageAccounts); app('preferences')->set('frontPageAccounts', $frontPageAccounts);
} }
@@ -167,8 +167,8 @@ class PreferencesController extends Controller
session()->forget('range'); session()->forget('range');
// custom fiscal year // custom fiscal year
$customFiscalYear = 1 === (int)$request->get('customFiscalYear'); $customFiscalYear = 1 === (int) $request->get('customFiscalYear');
$string = strtotime((string)$request->get('fiscalYearStart')); $string = strtotime((string) $request->get('fiscalYearStart'));
if (false !== $string) { if (false !== $string) {
$fiscalYearStart = date('m-d', $string); $fiscalYearStart = date('m-d', $string);
app('preferences')->set('customFiscalYear', $customFiscalYear); app('preferences')->set('customFiscalYear', $customFiscalYear);
@@ -178,7 +178,7 @@ class PreferencesController extends Controller
// save page size: // save page size:
app('preferences')->set('listPageSize', 50); app('preferences')->set('listPageSize', 50);
$listPageSize = (int)$request->get('listPageSize'); $listPageSize = (int) $request->get('listPageSize');
if ($listPageSize > 0 && $listPageSize < 1337) { if ($listPageSize > 0 && $listPageSize < 1337) {
app('preferences')->set('listPageSize', $listPageSize); app('preferences')->set('listPageSize', $listPageSize);
} }
@@ -220,7 +220,7 @@ class PreferencesController extends Controller
]; ];
app('preferences')->set('transaction_journal_optional_fields', $optionalTj); app('preferences')->set('transaction_journal_optional_fields', $optionalTj);
session()->flash('success', (string)trans('firefly.saved_preferences')); session()->flash('success', (string) trans('firefly.saved_preferences'));
app('preferences')->mark(); app('preferences')->mark();
return redirect(route('preferences.index')); return redirect(route('preferences.index'));

View File

@@ -78,7 +78,7 @@ class ProfileController extends Controller
$this->middleware( $this->middleware(
static function ($request, $next) { static function ($request, $next) {
app('view')->share('title', (string)trans('firefly.profile')); app('view')->share('title', (string) trans('firefly.profile'));
app('view')->share('mainTitleIcon', 'fa-user'); app('view')->share('mainTitleIcon', 'fa-user');
return $next($request); return $next($request);
@@ -110,7 +110,7 @@ class ProfileController extends Controller
$title = auth()->user()->email; $title = auth()->user()->email;
$email = auth()->user()->email; $email = auth()->user()->email;
$subTitle = (string)trans('firefly.change_your_email'); $subTitle = (string) trans('firefly.change_your_email');
$subTitleIcon = 'fa-envelope'; $subTitleIcon = 'fa-envelope';
return view('profile.change-email', compact('title', 'subTitle', 'subTitleIcon', 'email')); return view('profile.change-email', compact('title', 'subTitle', 'subTitleIcon', 'email'));
@@ -132,7 +132,7 @@ class ProfileController extends Controller
} }
$title = auth()->user()->email; $title = auth()->user()->email;
$subTitle = (string)trans('firefly.change_your_password'); $subTitle = (string) trans('firefly.change_your_password');
$subTitleIcon = 'fa-key'; $subTitleIcon = 'fa-key';
return view('profile.change-password', compact('title', 'subTitle', 'subTitleIcon')); return view('profile.change-password', compact('title', 'subTitle', 'subTitleIcon'));
@@ -229,7 +229,7 @@ class ProfileController extends Controller
$repository->unblockUser($user); $repository->unblockUser($user);
// return to login. // return to login.
session()->flash('success', (string)trans('firefly.login_with_new_email')); session()->flash('success', (string) trans('firefly.login_with_new_email'));
return redirect(route('login')); return redirect(route('login'));
} }
@@ -249,7 +249,7 @@ class ProfileController extends Controller
return redirect(route('profile.index')); return redirect(route('profile.index'));
} }
$title = auth()->user()->email; $title = auth()->user()->email;
$subTitle = (string)trans('firefly.delete_account'); $subTitle = (string) trans('firefly.delete_account');
$subTitleIcon = 'fa-trash'; $subTitleIcon = 'fa-trash';
return view('profile.delete-account', compact('title', 'subTitle', 'subTitleIcon')); return view('profile.delete-account', compact('title', 'subTitle', 'subTitleIcon'));
@@ -274,8 +274,8 @@ class ProfileController extends Controller
$user = auth()->user(); $user = auth()->user();
$repository->setMFACode($user, null); $repository->setMFACode($user, null);
session()->flash('success', (string)trans('firefly.pref_two_factor_auth_disabled')); session()->flash('success', (string) trans('firefly.pref_two_factor_auth_disabled'));
session()->flash('info', (string)trans('firefly.pref_two_factor_auth_remove_it')); session()->flash('info', (string) trans('firefly.pref_two_factor_auth_remove_it'));
return redirect(route('profile.index')); return redirect(route('profile.index'));
} }
@@ -304,7 +304,7 @@ class ProfileController extends Controller
// If FF3 already has a secret, just set the two factor auth enabled to 1, // If FF3 already has a secret, just set the two factor auth enabled to 1,
// and let the user continue with the existing secret. // and let the user continue with the existing secret.
session()->flash('info', (string)trans('firefly.2fa_already_enabled')); session()->flash('info', (string) trans('firefly.2fa_already_enabled'));
return redirect(route('profile.index')); return redirect(route('profile.index'));
} }
@@ -351,7 +351,7 @@ class ProfileController extends Controller
public function logoutOtherSessions() public function logoutOtherSessions()
{ {
if (!$this->internalAuth) { if (!$this->internalAuth) {
session()->flash('info', (string)trans('firefly.external_auth_disabled')); session()->flash('info', (string) trans('firefly.external_auth_disabled'));
return redirect(route('profile.index')); return redirect(route('profile.index'));
} }
@@ -409,7 +409,7 @@ class ProfileController extends Controller
$newEmail = $request->string('email'); $newEmail = $request->string('email');
$oldEmail = $user->email; $oldEmail = $user->email;
if ($newEmail === $user->email) { if ($newEmail === $user->email) {
session()->flash('error', (string)trans('firefly.email_not_changed')); session()->flash('error', (string) trans('firefly.email_not_changed'));
return redirect(route('profile.change-email'))->withInput(); return redirect(route('profile.change-email'))->withInput();
} }
@@ -419,7 +419,7 @@ class ProfileController extends Controller
Auth::guard()->logout(); Auth::guard()->logout();
$request->session()->invalidate(); $request->session()->invalidate();
session()->flash('success', (string)trans('firefly.email_changed')); session()->flash('success', (string) trans('firefly.email_changed'));
return redirect(route('index')); return redirect(route('index'));
} }
@@ -432,7 +432,7 @@ class ProfileController extends Controller
// force user logout. // force user logout.
Auth::guard()->logout(); Auth::guard()->logout();
$request->session()->invalidate(); $request->session()->invalidate();
session()->flash('success', (string)trans('firefly.email_changed')); session()->flash('success', (string) trans('firefly.email_changed'));
return redirect(route('index')); return redirect(route('index'));
} }
@@ -467,7 +467,7 @@ class ProfileController extends Controller
} }
$repository->changePassword($user, $request->get('new_password')); $repository->changePassword($user, $request->get('new_password'));
session()->flash('success', (string)trans('firefly.password_changed')); session()->flash('success', (string) trans('firefly.password_changed'));
return redirect(route('profile.index')); return redirect(route('profile.index'));
} }
@@ -496,7 +496,7 @@ class ProfileController extends Controller
$secret = session()->get('two-factor-secret'); $secret = session()->get('two-factor-secret');
$repository->setMFACode($user, $secret); $repository->setMFACode($user, $secret);
session()->flash('success', (string)trans('firefly.saved_preferences')); session()->flash('success', (string) trans('firefly.saved_preferences'));
app('preferences')->mark(); app('preferences')->mark();
// also save the code so replay attack is prevented. // also save the code so replay attack is prevented.
@@ -577,7 +577,7 @@ class ProfileController extends Controller
} }
if (!Hash::check($request->get('password'), auth()->user()->password)) { if (!Hash::check($request->get('password'), auth()->user()->password)) {
session()->flash('error', (string)trans('firefly.invalid_password')); session()->flash('error', (string) trans('firefly.invalid_password'));
return redirect(route('profile.delete-account')); return redirect(route('profile.delete-account'));
} }
@@ -601,7 +601,7 @@ class ProfileController extends Controller
public function postLogoutOtherSessions(Request $request) public function postLogoutOtherSessions(Request $request)
{ {
if (!$this->internalAuth) { if (!$this->internalAuth) {
session()->flash('info', (string)trans('firefly.external_auth_disabled')); session()->flash('info', (string) trans('firefly.external_auth_disabled'));
return redirect(route('profile.index')); return redirect(route('profile.index'));
} }
@@ -611,11 +611,11 @@ class ProfileController extends Controller
]; ];
if (Auth::once($creds)) { if (Auth::once($creds)) {
Auth::logoutOtherDevices($request->get('password')); Auth::logoutOtherDevices($request->get('password'));
session()->flash('info', (string)trans('firefly.other_sessions_logged_out')); session()->flash('info', (string) trans('firefly.other_sessions_logged_out'));
return redirect(route('profile.index')); return redirect(route('profile.index'));
} }
session()->flash('error', (string)trans('auth.failed')); session()->flash('error', (string) trans('auth.failed'));
return redirect(route('profile.index')); return redirect(route('profile.index'));
@@ -641,7 +641,7 @@ class ProfileController extends Controller
$user = auth()->user(); $user = auth()->user();
$token = $user->generateAccessToken(); $token = $user->generateAccessToken();
app('preferences')->set('access_token', $token); app('preferences')->set('access_token', $token);
session()->flash('success', (string)trans('firefly.token_regenerated')); session()->flash('success', (string) trans('firefly.token_regenerated'));
return redirect(route('profile.index')); return redirect(route('profile.index'));
} }
@@ -681,7 +681,7 @@ class ProfileController extends Controller
/** @var string $match */ /** @var string $match */
$match = null; $match = null;
foreach ($set as $entry) { foreach ($set as $entry) {
$hashed = hash('sha256', sprintf('%s%s', (string)config('app.key'), $entry->data)); $hashed = hash('sha256', sprintf('%s%s', (string) config('app.key'), $entry->data));
if ($hashed === $hash) { if ($hashed === $hash) {
$match = $entry->data; $match = $entry->data;
break; break;
@@ -696,7 +696,7 @@ class ProfileController extends Controller
$repository->unblockUser($user); $repository->unblockUser($user);
// return to login. // return to login.
session()->flash('success', (string)trans('firefly.login_with_old_email')); session()->flash('success', (string) trans('firefly.login_with_old_email'));
return redirect(route('login')); return redirect(route('login'));
} }

View File

@@ -63,8 +63,8 @@ class CreateController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-paint-brush'); app('view')->share('mainTitleIcon', 'fa-paint-brush');
app('view')->share('title', (string)trans('firefly.recurrences')); app('view')->share('title', (string) trans('firefly.recurrences'));
app('view')->share('subTitle', (string)trans('firefly.create_new_recurrence')); app('view')->share('subTitle', (string) trans('firefly.create_new_recurrence'));
$this->recurring = app(RecurringRepositoryInterface::class); $this->recurring = app(RecurringRepositoryInterface::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class); $this->budgetRepos = app(BudgetRepositoryInterface::class);
@@ -98,22 +98,22 @@ class CreateController extends Controller
} }
$request->session()->forget('recurring.create.fromStore'); $request->session()->forget('recurring.create.fromStore');
$repetitionEnds = [ $repetitionEnds = [
'forever' => (string)trans('firefly.repeat_forever'), 'forever' => (string) trans('firefly.repeat_forever'),
'until_date' => (string)trans('firefly.repeat_until_date'), 'until_date' => (string) trans('firefly.repeat_until_date'),
'times' => (string)trans('firefly.repeat_times'), 'times' => (string) trans('firefly.repeat_times'),
]; ];
$weekendResponses = [ $weekendResponses = [
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'), RecurrenceRepetition::WEEKEND_DO_NOTHING => (string) trans('firefly.do_nothing'),
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'), RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string) trans('firefly.skip_transaction'),
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'), RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string) trans('firefly.jump_to_friday'),
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'), RecurrenceRepetition::WEEKEND_TO_MONDAY => (string) trans('firefly.jump_to_monday'),
]; ];
$hasOldInput = null !== $request->old('_token'); // flash some data $hasOldInput = null !== $request->old('_token'); // flash some data
$preFilled = [ $preFilled = [
'first_date' => $tomorrow->format('Y-m-d'), 'first_date' => $tomorrow->format('Y-m-d'),
'transaction_type' => $hasOldInput ? $request->old('transaction_type') : 'withdrawal', 'transaction_type' => $hasOldInput ? $request->old('transaction_type') : 'withdrawal',
'active' => $hasOldInput ? (bool)$request->old('active') : true, 'active' => $hasOldInput ? (bool) $request->old('active') : true,
'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : true, 'apply_rules' => $hasOldInput ? (bool) $request->old('apply_rules') : true,
]; ];
$request->session()->flash('preFilled', $preFilled); $request->session()->flash('preFilled', $preFilled);
@@ -143,15 +143,15 @@ class CreateController extends Controller
} }
$request->session()->forget('recurring.create.fromStore'); $request->session()->forget('recurring.create.fromStore');
$repetitionEnds = [ $repetitionEnds = [
'forever' => (string)trans('firefly.repeat_forever'), 'forever' => (string) trans('firefly.repeat_forever'),
'until_date' => (string)trans('firefly.repeat_until_date'), 'until_date' => (string) trans('firefly.repeat_until_date'),
'times' => (string)trans('firefly.repeat_times'), 'times' => (string) trans('firefly.repeat_times'),
]; ];
$weekendResponses = [ $weekendResponses = [
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'), RecurrenceRepetition::WEEKEND_DO_NOTHING => (string) trans('firefly.do_nothing'),
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'), RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string) trans('firefly.skip_transaction'),
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'), RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string) trans('firefly.jump_to_friday'),
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'), RecurrenceRepetition::WEEKEND_TO_MONDAY => (string) trans('firefly.jump_to_monday'),
]; ];
@@ -184,8 +184,8 @@ class CreateController extends Controller
'category' => $request->old('category'), 'category' => $request->old('category'),
'budget_id' => $request->old('budget_id'), 'budget_id' => $request->old('budget_id'),
'bill_id' => $request->old('bill_id'), 'bill_id' => $request->old('bill_id'),
'active' => (bool)$request->old('active'), 'active' => (bool) $request->old('active'),
'apply_rules' => (bool)$request->old('apply_rules'), 'apply_rules' => (bool) $request->old('apply_rules'),
]; ];
} }
if (false === $hasOldInput) { if (false === $hasOldInput) {
@@ -236,7 +236,7 @@ class CreateController extends Controller
return redirect(route('recurring.create'))->withInput(); return redirect(route('recurring.create'))->withInput();
} }
$request->session()->flash('success', (string)trans('firefly.stored_new_recurrence', ['title' => $recurrence->title])); $request->session()->flash('success', (string) trans('firefly.stored_new_recurrence', ['title' => $recurrence->title]));
app('preferences')->mark(); app('preferences')->mark();
// store attachment(s): // store attachment(s):
@@ -246,7 +246,7 @@ class CreateController extends Controller
$this->attachments->saveAttachmentsForModel($recurrence, $files); $this->attachments->saveAttachmentsForModel($recurrence, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -254,7 +254,7 @@ class CreateController extends Controller
} }
$redirect = redirect($this->getPreviousUri('recurring.create.uri')); $redirect = redirect($this->getPreviousUri('recurring.create.uri'));
if (1 === (int)$request->get('create_another')) { if (1 === (int) $request->get('create_another')) {
// set value so create routine will not overwrite URL: // set value so create routine will not overwrite URL:
$request->session()->put('recurring.create.fromStore', true); $request->session()->put('recurring.create.fromStore', true);

View File

@@ -53,7 +53,7 @@ class DeleteController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-paint-brush'); app('view')->share('mainTitleIcon', 'fa-paint-brush');
app('view')->share('title', (string)trans('firefly.recurrences')); app('view')->share('title', (string) trans('firefly.recurrences'));
$this->recurring = app(RecurringRepositoryInterface::class); $this->recurring = app(RecurringRepositoryInterface::class);
@@ -71,7 +71,7 @@ class DeleteController extends Controller
*/ */
public function delete(Recurrence $recurrence) 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 // put previous url in session
$this->rememberPreviousUri('recurrences.delete.uri'); $this->rememberPreviousUri('recurrences.delete.uri');
@@ -92,7 +92,7 @@ class DeleteController extends Controller
public function destroy(RecurringRepositoryInterface $repository, Request $request, Recurrence $recurrence) public function destroy(RecurringRepositoryInterface $repository, Request $request, Recurrence $recurrence)
{ {
$repository->destroy($recurrence); $repository->destroy($recurrence);
$request->session()->flash('success', (string)trans('firefly.' . 'recurrence_deleted', ['title' => $recurrence->title])); $request->session()->flash('success', (string) trans('firefly.' . 'recurrence_deleted', ['title' => $recurrence->title]));
app('preferences')->mark(); app('preferences')->mark();
return redirect($this->getPreviousUri('recurrences.delete.uri')); return redirect($this->getPreviousUri('recurrences.delete.uri'));

View File

@@ -64,8 +64,8 @@ class EditController extends Controller
$this->middleware( $this->middleware(
function ($request, $next) { function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-paint-brush'); app('view')->share('mainTitleIcon', 'fa-paint-brush');
app('view')->share('title', (string)trans('firefly.recurrences')); app('view')->share('title', (string) trans('firefly.recurrences'));
app('view')->share('subTitle', (string)trans('firefly.recurrences')); app('view')->share('subTitle', (string) trans('firefly.recurrences'));
$this->recurring = app(RecurringRepositoryInterface::class); $this->recurring = app(RecurringRepositoryInterface::class);
$this->budgetRepos = app(BudgetRepositoryInterface::class); $this->budgetRepos = app(BudgetRepositoryInterface::class);
@@ -118,9 +118,9 @@ class EditController extends Controller
$repetitionEnd = 'forever'; $repetitionEnd = 'forever';
$repetitionEnds = [ $repetitionEnds = [
'forever' => (string)trans('firefly.repeat_forever'), 'forever' => (string) trans('firefly.repeat_forever'),
'until_date' => (string)trans('firefly.repeat_until_date'), 'until_date' => (string) trans('firefly.repeat_until_date'),
'times' => (string)trans('firefly.repeat_times'), 'times' => (string) trans('firefly.repeat_times'),
]; ];
if (null !== $recurrence->repeat_until) { if (null !== $recurrence->repeat_until) {
$repetitionEnd = 'until_date'; $repetitionEnd = 'until_date';
@@ -130,22 +130,22 @@ class EditController extends Controller
} }
$weekendResponses = [ $weekendResponses = [
RecurrenceRepetition::WEEKEND_DO_NOTHING => (string)trans('firefly.do_nothing'), RecurrenceRepetition::WEEKEND_DO_NOTHING => (string) trans('firefly.do_nothing'),
RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string)trans('firefly.skip_transaction'), RecurrenceRepetition::WEEKEND_SKIP_CREATION => (string) trans('firefly.skip_transaction'),
RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string)trans('firefly.jump_to_friday'), RecurrenceRepetition::WEEKEND_TO_FRIDAY => (string) trans('firefly.jump_to_friday'),
RecurrenceRepetition::WEEKEND_TO_MONDAY => (string)trans('firefly.jump_to_monday'), RecurrenceRepetition::WEEKEND_TO_MONDAY => (string) trans('firefly.jump_to_monday'),
]; ];
$hasOldInput = null !== $request->old('_token'); $hasOldInput = null !== $request->old('_token');
$preFilled = [ $preFilled = [
'transaction_type' => strtolower($recurrence->transactionType->type), 'transaction_type' => strtolower($recurrence->transactionType->type),
'active' => $hasOldInput ? (bool)$request->old('active') : $recurrence->active, 'active' => $hasOldInput ? (bool) $request->old('active') : $recurrence->active,
'apply_rules' => $hasOldInput ? (bool)$request->old('apply_rules') : $recurrence->apply_rules, 'apply_rules' => $hasOldInput ? (bool) $request->old('apply_rules') : $recurrence->apply_rules,
'deposit_source_id' => $array['transactions'][0]['source_id'], 'deposit_source_id' => $array['transactions'][0]['source_id'],
'withdrawal_destination_id' => $array['transactions'][0]['destination_id'], 'withdrawal_destination_id' => $array['transactions'][0]['destination_id'],
]; ];
$array['first_date'] = substr((string)$array['first_date'], 0, 10); $array['first_date'] = substr((string) $array['first_date'], 0, 10);
$array['repeat_until'] = substr((string)$array['repeat_until'], 0, 10); $array['repeat_until'] = substr((string) $array['repeat_until'], 0, 10);
$array['transactions'][0]['tags'] = implode(',', $array['transactions'][0]['tags'] ?? []); $array['transactions'][0]['tags'] = implode(',', $array['transactions'][0]['tags'] ?? []);
return view( return view(
@@ -171,7 +171,7 @@ class EditController extends Controller
$data = $request->getAll(); $data = $request->getAll();
$this->recurring->update($recurrence, $data); $this->recurring->update($recurrence, $data);
$request->session()->flash('success', (string)trans('firefly.updated_recurrence', ['title' => $recurrence->title])); $request->session()->flash('success', (string) trans('firefly.updated_recurrence', ['title' => $recurrence->title]));
// store new attachment(s): // store new attachment(s):
$files = $request->hasFile('attachments') ? $request->file('attachments') : null; $files = $request->hasFile('attachments') ? $request->file('attachments') : null;
@@ -179,7 +179,7 @@ class EditController extends Controller
$this->attachments->saveAttachmentsForModel($recurrence, $files); $this->attachments->saveAttachmentsForModel($recurrence, $files);
} }
if (null !== $files && auth()->user()->hasRole('demo')) { if (null !== $files && auth()->user()->hasRole('demo')) {
session()->flash('info', (string)trans('firefly.no_att_demo_user')); session()->flash('info', (string) trans('firefly.no_att_demo_user'));
} }
if (count($this->attachments->getMessages()->get('attachments')) > 0) { if (count($this->attachments->getMessages()->get('attachments')) > 0) {
@@ -187,7 +187,7 @@ class EditController extends Controller
} }
app('preferences')->mark(); app('preferences')->mark();
$redirect = redirect($this->getPreviousUri('recurrences.edit.uri')); $redirect = redirect($this->getPreviousUri('recurrences.edit.uri'));
if (1 === (int)$request->get('return_to_edit')) { if (1 === (int) $request->get('return_to_edit')) {
// set value so edit routine will not overwrite URL: // set value so edit routine will not overwrite URL:
$request->session()->put('recurrences.edit.fromUpdate', true); $request->session()->put('recurrences.edit.fromUpdate', true);

Some files were not shown because too many files have changed in this diff Show More