Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Optimise code.
James Cole3979e1204392
diff --git a/app/Console/Commands/Correction/FixPiggies.php b/app/Console/Commands/Correction/FixPiggies.phpindex 8cca164de8..eb7875c3ed 100644--- a/app/Console/Commands/Correction/FixPiggies.php+++ b/app/Console/Commands/Correction/FixPiggies.php@@ -86,7 +86,6 @@ class FixPiggies extends Command$event->save();$this->line(sprintf('Piggy bank #%d was referenced by an invalid event. This has been fixed.', $event->piggy_bank_id));$this->count++;- continue;}}if (0 === $this->count) {diff --git a/app/Http/Controllers/System/CronController.php b/app/Http/Controllers/System/CronController.phpindex 3baa9a8415..9c8a632f06 100644--- a/app/Http/Controllers/System/CronController.php+++ b/app/Http/Controllers/System/CronController.php@@ -33,11 +33,9 @@ class CronControlleruse CronRunner;/**- * @param string $token- ** @return string*/- public function cron(string $token): string+ public function cron(): string{$results = [];$results[] = $this->runRecurring();diff --git a/app/Http/Controllers/Transaction/ConvertController.php b/app/Http/Controllers/Transaction/ConvertController.phpindex 1a6278e5fa..a551b1fa51 100644--- a/app/Http/Controllers/Transaction/ConvertController.php+++ b/app/Http/Controllers/Transaction/ConvertController.php@@ -69,7 +69,7 @@ class ConvertController extends Controllerfunction ($request, $next) {$this->repository = app(JournalRepositoryInterface::class);$this->accountRepository = app(AccountRepositoryInterface::class);- app('view')->share('title', (string) trans('firefly.transactions'));+ app('view')->share('title', (string)trans('firefly.transactions'));app('view')->share('mainTitleIcon', 'fa-exchange');return $next($request);@@ -103,7 +103,7 @@ class ConvertController extends Controller$groupTitle = $group->title ?? $first->description;$groupArray = $transformer->transformObject($group);- $subTitle = (string) trans('firefly.convert_to_' . $destinationType->type, ['description' => $groupTitle]);+ $subTitle = (string)trans('firefly.convert_to_' . $destinationType->type, ['description' => $groupTitle]);$subTitleIcon = 'fa-exchange';// get a list of asset accounts and liabilities and stuff, in various combinations:@@ -119,7 +119,7 @@ class ConvertController extends Controllerif ($sourceType->type === $destinationType->type) { // cannot convert to its own type.Log::debug('This is already a transaction of the expected type..');- session()->flash('info', (string) trans('firefly.convert_is_already_type_' . $destinationType->type));+ session()->flash('info', (string)trans('firefly.convert_is_already_type_' . $destinationType->type));return redirect(route('transactions.show', [$group->id]));}@@ -174,9 +174,8 @@ class ConvertController extends Controller// correct transfers:$group->refresh();- $this->correctTransfer($group);- session()->flash('success', (string) trans('firefly.converted_to_' . $destinationType->type));+ session()->flash('success', (string)trans('firefly.converted_to_' . $destinationType->type));event(new UpdatedTransactionGroup($group));return redirect(route('transactions.show', [$group->id]));@@ -203,10 +202,10 @@ class ConvertController extends Controller$destinationName = $data['destination_name'][$journal->id] ?? null;// double check its not an empty string.- $sourceId = '' === $sourceId || null === $sourceId ? null : (int) $sourceId;- $sourceName = '' === $sourceName ? null : (string) $sourceName;- $destinationId = '' === $destinationId || null === $destinationId ? null : (int) $destinationId;- $destinationName = '' === $destinationName ? null : (string) $destinationName;+ $sourceId = '' === $sourceId || null === $sourceId ? null : (int)$sourceId;+ $sourceName = '' === $sourceName ? null : (string)$sourceName;+ $destinationId = '' === $destinationId || null === $destinationId ? null : (int)$destinationId;+ $destinationName = '' === $destinationName ? null : (string)$destinationName;$validSource = $validator->validateSource($sourceId, $sourceName, null);$validDestination = $validator->validateDestination($destinationId, $destinationName, null);@@ -236,13 +235,6 @@ class ConvertController extends Controllerreturn $journal;}- /**- * @param TransactionGroup $group- */- private function correctTransfer(TransactionGroup $group): void- {- }-/*** @return array* @throws Exception@@ -260,12 +252,12 @@ class ConvertController extends Controllerforeach ($accountList as $account) {$balance = app('steam')->balance($account, today());$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;- $role = (string) $accountRepository->getMetaValue($account, 'account_role');+ $role = (string)$accountRepository->getMetaValue($account, 'account_role');if ('' === $role) {$role = 'no_account_type'; // @codeCoverageIgnore}- $key = (string) trans('firefly.opt_group_' . $role);+ $key = (string)trans('firefly.opt_group_' . $role);$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';}@@ -290,7 +282,7 @@ class ConvertController extends Controller$balance = app('steam')->balance($account, today());$currency = $accountRepository->getAccountCurrency($account) ?? $defaultCurrency;$role = 'l_' . $account->accountType->type;- $key = (string) trans('firefly.opt_group_' . $role);+ $key = (string)trans('firefly.opt_group_' . $role);$grouped[$key][$account->id] = $account->name . ' (' . app('amount')->formatAnything($currency, $balance, false) . ')';}@@ -312,7 +304,7 @@ class ConvertController extends Controller// group accounts:/** @var Account $account */foreach ($accountList as $account) {- $role = (string) $accountRepository->getMetaValue($account, 'account_role');+ $role = (string)$accountRepository->getMetaValue($account, 'account_role');$name = $account->name;if ('' === $role) {$role = 'no_account_type'; // @codeCoverageIgnore@@ -332,7 +324,7 @@ class ConvertController extends Controller$role = 'revenue_account'; // @codeCoverageIgnore}- $key = (string) trans('firefly.opt_group_' . $role);+ $key = (string)trans('firefly.opt_group_' . $role);$grouped[$key][$account->id] = $name;}@@ -345,16 +337,17 @@ class ConvertController extends Controllerprivate function getValidWithdrawalDests(): array{// make repositories- /** @var AccountRepositoryInterface $repository */- $repository = app(AccountRepositoryInterface::class);- $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];- $accountList = $repository- ->getActiveAccountsByType([AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]);- $grouped = [];+ /** @var AccountRepositoryInterface $accountRepository */+ $accountRepository = app(AccountRepositoryInterface::class);+ $liabilityTypes = [AccountType::MORTGAGE, AccountType::DEBT, AccountType::CREDITCARD, AccountType::LOAN];+ $accountList = $accountRepository->getActiveAccountsByType(+ [AccountType::EXPENSE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE]+ );+ $grouped = [];// group accounts:/** @var Account $account */foreach ($accountList as $account) {- $role = (string) $repository->getMetaValue($account, 'account_role');+ $role = (string)$accountRepository->getMetaValue($account, 'account_role');$name = $account->name;if ('' === $role) {$role = 'no_account_type'; // @codeCoverageIgnore@@ -374,7 +367,7 @@ class ConvertController extends Controller$role = 'expense_account'; // @codeCoverageIgnore}- $key = (string) trans('firefly.opt_group_' . $role);+ $key = (string)trans('firefly.opt_group_' . $role);$grouped[$key][$account->id] = $name;}diff --git a/app/Http/Controllers/Transaction/IndexController.php b/app/Http/Controllers/Transaction/IndexController.phpindex 4f7c1db0a9..95f3b7767f 100644--- a/app/Http/Controllers/Transaction/IndexController.php+++ b/app/Http/Controllers/Transaction/IndexController.php@@ -41,8 +41,7 @@ class IndexController extends Controller{use PeriodOverview;- /** @var JournalRepositoryInterface */- private $repository;+ private JournalRepositoryInterface $repository;/*** IndexController constructor.@@ -132,16 +131,12 @@ class IndexController extends Controller*/public function indexAll(Request $request, string $objectType){- /** @var JournalRepositoryInterface $repository */- $repository = app(JournalRepositoryInterface::class);--$subTitleIcon = config('firefly.transactionIconsByType.' . $objectType);$types = config('firefly.transactionTypesByType.' . $objectType);$page = (int) $request->get('page');$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;$path = route('transactions.index.all', [$objectType]);- $first = $repository->firstNull();+ $first = $this->repository->firstNull();$start = null === $first ? new Carbon : $first->date;$last = $this->repository->getLast();$end = $last ? $last->date : today(config('app.timezone'));diff --git a/app/Http/Controllers/Transaction/MassController.php b/app/Http/Controllers/Transaction/MassController.phpindex 0adfed6c3c..9260f72c22 100644--- a/app/Http/Controllers/Transaction/MassController.php+++ b/app/Http/Controllers/Transaction/MassController.php@@ -47,8 +47,7 @@ use Log;*/class MassController extends Controller{- /** @var JournalRepositoryInterface Journals and transactions overview */- private $repository;+ private JournalRepositoryInterface $repository;/*** MassController constructor.@@ -131,16 +130,16 @@ class MassController extends Controller{$subTitle = (string) trans('firefly.mass_edit_journals');- /** @var AccountRepositoryInterface $repository */- $repository = app(AccountRepositoryInterface::class);+ /** @var AccountRepositoryInterface $accountRepository */+ $accountRepository = app(AccountRepositoryInterface::class);// valid withdrawal sources:$array = array_keys(config(sprintf('firefly.source_dests.%s', TransactionType::WITHDRAWAL)));- $withdrawalSources = $repository->getAccountsByType($array);+ $withdrawalSources = $accountRepository->getAccountsByType($array);// valid deposit destinations:$array = config(sprintf('firefly.source_dests.%s.%s', TransactionType::DEPOSIT, AccountType::REVENUE));- $depositDestinations = $repository->getAccountsByType($array);+ $depositDestinations = $accountRepository->getAccountsByType($array);/** @var BudgetRepositoryInterface $budgetRepository */$budgetRepository = app(BudgetRepositoryInterface::class);diff --git a/app/Http/Requests/RecurrenceFormRequest.php b/app/Http/Requests/RecurrenceFormRequest.phpindex 8653735036..7217cc527f 100644--- a/app/Http/Requests/RecurrenceFormRequest.php+++ b/app/Http/Requests/RecurrenceFormRequest.php@@ -331,8 +331,6 @@ class RecurrenceFormRequest extends FormRequest$message = (string)trans('validation.generic_invalid_destination');$validator->errors()->add('destination_id', $message);$validator->errors()->add('withdrawal_destination_id', $message);-- return;}}}diff --git a/app/Http/Requests/ReportFormRequest.php b/app/Http/Requests/ReportFormRequest.phpindex a63d964253..b2e24bfc37 100644--- a/app/Http/Requests/ReportFormRequest.php+++ b/app/Http/Requests/ReportFormRequest.php@@ -212,7 +212,6 @@ class ReportFormRequest extends FormRequest$tag = $repository->findNull((int)$tagTag);if (null !== $tag) {$collection->push($tag);- continue;}}}diff --git a/app/Jobs/CreateRecurringTransactions.php b/app/Jobs/CreateRecurringTransactions.phpindex 252ee95b7f..f32b998992 100644--- a/app/Jobs/CreateRecurringTransactions.php+++ b/app/Jobs/CreateRecurringTransactions.php@@ -27,12 +27,10 @@ namespace FireflyIII\Jobs;use Carbon\Carbon;use FireflyIII\Events\RequestedReportOnJournals;use FireflyIII\Events\StoredTransactionGroup;-use FireflyIII\Factory\PiggyBankEventFactory;use FireflyIII\Models\Recurrence;use FireflyIII\Models\RecurrenceRepetition;use FireflyIII\Models\RecurrenceTransaction;use FireflyIII\Models\TransactionGroup;-use FireflyIII\Models\TransactionJournal;use FireflyIII\Repositories\Journal\JournalRepositoryInterface;use FireflyIII\Repositories\Recurring\RecurringRepositoryInterface;use FireflyIII\Repositories\TransactionGroup\TransactionGroupRepositoryInterface;@@ -52,22 +50,14 @@ class CreateRecurringTransactions implements ShouldQueue{use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;- /** @var int Transaction groups created */- public int $created;- /** @var int Number of recurrences actually fired */- public int $executed;- /** @var int Number of recurrences submitted */- public int $submitted;- /** @var Carbon The current date */- private Carbon $date;- /** @var bool Force the transaction to be created no matter what. */- private bool $force;- /** @var TransactionGroupRepositoryInterface */- private $groupRepository;- /** @var JournalRepositoryInterface Journal repository */- private $journalRepository;- /** @var RecurringRepositoryInterface Recurring transactions repository. */- private $repository;+ public int $created;+ public int $executed;+ public int $submitted;+ private Carbon $date;+ private bool $force;+ private TransactionGroupRepositoryInterface $groupRepository;+ private JournalRepositoryInterface $journalRepository;+ private RecurringRepositoryInterface $repository;/*** Create a new job instance.@@ -121,9 +111,9 @@ class CreateRecurringTransactions implements ShouldQueueapp('preferences')->setForUser($recurrence->user, 'lastActivity', microtime());Log::debug(sprintf('Now at recurrence #%d', $recurrence->id));- $created = $this->handleRepetitions($recurrence);+ $createdReps = $this->handleRepetitions($recurrence);Log::debug(sprintf('Done with recurrence #%d', $recurrence->id));- $result[$recurrence->user_id] = $result[$recurrence->user_id]->merge($created);+ $result[$recurrence->user_id] = $result[$recurrence->user_id]->merge($createdReps);$this->executed++;}@@ -218,11 +208,11 @@ class CreateRecurringTransactions implements ShouldQueue$return = [];/** @var RecurrenceTransaction $transaction */foreach ($transactions as $index => $transaction) {- $single = [+ $single = ['type' => strtolower($recurrence->transactionType->type),'date' => $date,'user' => $recurrence->user_id,- 'currency_id' => (int) $transaction->transaction_currency_id,+ 'currency_id' => (int)$transaction->transaction_currency_id,'currency_code' => null,'description' => $recurrence->recurrenceTransactions()->first()->description,'amount' => $transaction->amount,@@ -239,16 +229,16 @@ class CreateRecurringTransactions implements ShouldQueue'foreign_amount' => $transaction->foreign_amount,'reconciled' => false,'identifier' => $index,- 'recurrence_id' => (int) $recurrence->id,+ 'recurrence_id' => (int)$recurrence->id,'order' => $index,- 'notes' => (string) trans('firefly.created_from_recurrence', ['id' => $recurrence->id, 'title' => $recurrence->title]),+ 'notes' => (string)trans('firefly.created_from_recurrence', ['id' => $recurrence->id, 'title' => $recurrence->title]),'tags' => $this->repository->getTags($transaction),'piggy_bank_id' => $this->repository->getPiggyBank($transaction),'piggy_bank_name' => null,'bill_id' => null,'bill_name' => null,- 'recurrence_total' => $total,- 'recurrence_count' => $count,+ 'recurrence_total' => $total,+ 'recurrence_count' => $count,];$return[] = $single;}diff --git a/app/Mail/NewIPAddressWarningMail.php b/app/Mail/NewIPAddressWarningMail.phpindex 37afabb119..19b82c7db8 100644--- a/app/Mail/NewIPAddressWarningMail.php+++ b/app/Mail/NewIPAddressWarningMail.php@@ -57,9 +57,9 @@ class NewIPAddressWarningMail extends Mailable// time$this->time = now()->formatLocalized((string)trans('config.date_time'));$this->host = '';- $host = gethostbyaddr($this->ipAddress);- if($host !== $this->ipAddress) {- $this->host = $host;+ $hostName = gethostbyaddr($this->ipAddress);+ if($hostName !== $this->ipAddress) {+ $this->host = $hostName;}return $this->view('emails.new-ip-html')->text('emails.new-ip-text')diff --git a/app/Services/Internal/Update/BillUpdateService.php b/app/Services/Internal/Update/BillUpdateService.phpindex a3e7d7fd7b..11ac14cc2b 100644--- a/app/Services/Internal/Update/BillUpdateService.php+++ b/app/Services/Internal/Update/BillUpdateService.php@@ -44,17 +44,7 @@ class BillUpdateService{use BillServiceTrait, CreatesObjectGroups;- protected $user;-- /**- * Constructor.- */- public function __construct()- {- if ('testing' === config('app.env')) {- Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));- }- }+ protected User $user;/*** @param Bill $bill@@ -223,7 +213,6 @@ class BillUpdateServiceLog::debug(sprintf('Updated rule trigger #%d from value "%s" to value "%s"', $trigger->id, $oldValue, $newValue));$trigger->trigger_value = $newValue;$trigger->save();- continue;}}}@@ -248,18 +237,14 @@ class BillUpdateServiceprivate function updateOrder(Bill $bill, int $oldOrder, int $newOrder): void{if ($newOrder > $oldOrder) {- /** @var User $user */- $user = $this->user;- $user->bills()->where('order', '<=', $newOrder)->where('order', '>', $oldOrder)+ $this->user->bills()->where('order', '<=', $newOrder)->where('order', '>', $oldOrder)->where('bills.id', '!=', $bill->id)->update(['order' => DB::raw('bills.order-1')]);$bill->order = $newOrder;$bill->save();}if ($newOrder < $oldOrder) {- /** @var User $user */- $user = $this->user;- $user->bills()->where('order', '>=', $newOrder)->where('order', '<', $oldOrder)+ $this->user->bills()->where('order', '>=', $newOrder)->where('order', '<', $oldOrder)->where('bills.id', '!=', $bill->id)->update(['order' => DB::raw('bills.order+1')]);$bill->order = $newOrder;diff --git a/app/Services/Internal/Update/JournalUpdateService.php b/app/Services/Internal/Update/JournalUpdateService.phpindex be8084d3ae..7593a145af 100644--- a/app/Services/Internal/Update/JournalUpdateService.php+++ b/app/Services/Internal/Update/JournalUpdateService.php@@ -54,32 +54,17 @@ class JournalUpdateService{use JournalServiceTrait;- /** @var BillRepositoryInterface */- private $billRepository;- /** @var CurrencyRepositoryInterface */- private $currencyRepository;- /** @var array The data to update the journal with. */- private $data;- /** @var Account The destination account. */- private $destinationAccount;- /** @var Transaction */- private $destinationTransaction;- /** @var array All meta values that are dates. */- private $metaDate;- /** @var array All meta values that are strings. */- private $metaString;- /** @var Account Source account of the journal */- private $sourceAccount;- /** @var Transaction Source transaction of the journal. */- private $sourceTransaction;- /** @var TransactionGroup The parent group. */- private $transactionGroup;- /** @var TransactionJournal The journal to update. */- private $transactionJournal;- /** @var Account If new account info is submitted, this array will hold the valid destination. */- private $validDestination;- /** @var Account If new account info is submitted, this array will hold the valid source. */- private $validSource;+ private BillRepositoryInterface $billRepository;+ private CurrencyRepositoryInterface $currencyRepository;+ private array $data;+ private Account $destinationAccount;+ private Transaction $destinationTransaction;+ private array $metaDate;+ private array $metaString;+ private Account $sourceAccount;+ private Transaction $sourceTransaction;+ private TransactionGroup $transactionGroup;+ private TransactionJournal $transactionJournal;/*** JournalUpdateService constructor.@@ -253,7 +238,7 @@ class JournalUpdateService}$destInfo = [- 'id' => (int) ($this->data['destination_id'] ?? null),+ 'id' => (int)($this->data['destination_id'] ?? null),'name' => $this->data['destination_name'] ?? null,'iban' => $this->data['destination_iban'] ?? null,'number' => $this->data['destination_number'] ?? null,@@ -287,7 +272,7 @@ class JournalUpdateService}$sourceInfo = [- 'id' => (int) ($this->data['source_id'] ?? null),+ 'id' => (int)($this->data['source_id'] ?? null),'name' => $this->data['source_name'] ?? null,'iban' => $this->data['source_iban'] ?? null,'number' => $this->data['source_number'] ?? null,@@ -479,8 +464,8 @@ class JournalUpdateService)&& TransactionType::WITHDRAWAL === $type) {- $billId = (int) ($this->data['bill_id'] ?? 0);- $billName = (string) ($this->data['bill_name'] ?? '');+ $billId = (int)($this->data['bill_id'] ?? 0);+ $billName = (string)($this->data['bill_name'] ?? '');$bill = $this->billRepository->findBill($billId, $billName);$this->transactionJournal->bill_id = null === $bill ? null : $bill->id;Log::debug('Updated bill ID');@@ -551,15 +536,15 @@ class JournalUpdateService*/private function updateField(string $fieldName): void{- if (array_key_exists($fieldName, $this->data) && '' !== (string) $this->data[$fieldName]) {+ if (array_key_exists($fieldName, $this->data) && '' !== (string)$this->data[$fieldName]) {$value = $this->data[$fieldName];if ('date' === $fieldName) {- if($value instanceof Carbon) {+ if ($value instanceof Carbon) {// update timezone.$value->setTimezone(config('app.timezone'));}- if(!($value instanceof Carbon)) {+ if (!($value instanceof Carbon)) {$value = new Carbon($value);}// do some parsing.@@ -667,7 +652,7 @@ class JournalUpdateServiceforeach ($this->metaDate as $field) {if ($this->hasFields([$field])) {try {- $value = '' === (string) $this->data[$field] ? null : new Carbon($this->data[$field]);+ $value = '' === (string)$this->data[$field] ? null : new Carbon($this->data[$field]);} catch (Exception $e) {Log::debug(sprintf('%s is not a valid date value: %s', $this->data[$field], $e->getMessage()));@@ -713,7 +698,7 @@ class JournalUpdateService{// update notes.if ($this->hasFields(['notes'])) {- $notes = '' === (string) $this->data['notes'] ? null : $this->data['notes'];+ $notes = '' === (string)$this->data['notes'] ? null : $this->data['notes'];$this->storeNotes($this->transactionJournal, $notes);}}diff --git a/app/Support/System/OAuthKeys.php b/app/Support/System/OAuthKeys.phpindex 156566e83a..e6cb83dfa0 100644--- a/app/Support/System/OAuthKeys.php+++ b/app/Support/System/OAuthKeys.php@@ -106,8 +106,6 @@ class OAuthKeys}if (!self::keysInDatabase() && self::hasKeyFiles()) {self::storeKeysInDB();-- return;}}diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.phpindex 3a431f60d0..a207f20b4e 100644--- a/app/Transformers/AccountTransformer.php+++ b/app/Transformers/AccountTransformer.php@@ -75,7 +75,7 @@ class AccountTransformer extends AbstractTransformer[$currencyId, $currencyCode, $currencySymbol, $decimalPlaces] = $this->getCurrency($account);[$creditCardType, $monthlyPaymentDate] = $this->getCCInfo($account, $accountRole, $accountType);- [$openingBalance, $openingBalanceDate] = $this->getOpeningBalance($account, $accountType, $decimalPlaces);+ [$openingBalance, $openingBalanceDate] = $this->getOpeningBalance($account, $accountType);[$interest, $interestPeriod] = $this->getInterest($account, $accountType);$openingBalance = number_format((float) $openingBalance, $decimalPlaces, '.', '');@@ -235,7 +235,7 @@ class AccountTransformer extends AbstractTransformer** TODO refactor call to getOpeningBalanceAmount / Date because its extra queries.*/- private function getOpeningBalance(Account $account, string $accountType, int $decimalPlaces): array+ private function getOpeningBalance(Account $account, string $accountType): array{$openingBalance = null;$openingBalanceDate = null;diff --git a/app/Validation/Account/AccountValidatorProperties.php b/app/Validation/Account/AccountValidatorProperties.phpindex 416e95b5f5..1a1001746f 100644--- a/app/Validation/Account/AccountValidatorProperties.php+++ b/app/Validation/Account/AccountValidatorProperties.php@@ -29,26 +29,19 @@ use FireflyIII\Repositories\Account\AccountRepositoryInterface;use FireflyIII\User;/**+ * I have no idea what made me do this. I'll reverse it some day.+ ** Trait AccountValidatorProperties*/trait AccountValidatorProperties{- /** @var bool */- public $createMode;- /** @var string */- public $destError;- /** @var Account */- public $destination;- /** @var Account */- public $source;- /** @var string */- public $sourceError;- /** @var AccountRepositoryInterface */- private $accountRepository;- /** @var array */- private $combinations;- /** @var string */- private $transactionType;- /** @var User */- private $user;+ public bool $createMode;+ public string $destError;+ public Account $destination;+ public Account $source;+ public string $sourceError;+ private AccountRepositoryInterface $accountRepository;+ private array $combinations;+ private string $transactionType;+ private User $user;}diff --git a/app/Validation/TransactionValidation.php b/app/Validation/TransactionValidation.phpindex 691482df2d..6b7d3e2394 100644--- a/app/Validation/TransactionValidation.php+++ b/app/Validation/TransactionValidation.php@@ -96,8 +96,6 @@ trait TransactionValidationif (false === $validDestination) {$validator->errors()->add(sprintf('transactions.%d.destination_id', $index), $accountValidator->destError);$validator->errors()->add(sprintf('transactions.%d.destination_name', $index), $accountValidator->destError);-- return;}}@@ -257,8 +255,6 @@ trait TransactionValidation$unique = array_unique($types);if (count($unique) > 1) {$validator->errors()->add('transactions.0.type', (string) trans('validation.transaction_types_equal'));-- return;}}diff --git a/public/v1/js/ff/charts.js b/public/v1/js/ff/charts.jsindex 996294241f..7decfc2ae5 100644--- a/public/v1/js/ff/charts.js+++ b/public/v1/js/ff/charts.js@@ -64,11 +64,11 @@ function colorizeData(data) {var newData = {};newData.datasets = [];- for (var i = 0; i < data.count; i++) {+ for (var loop = 0; loop < data.count; loop++) {newData.labels = data.labels;- var dataset = data.datasets[i];+ var dataset = data.datasets[loop];dataset.fill = false;- dataset.backgroundColor = dataset.borderColor = fillColors[i];+ dataset.backgroundColor = dataset.borderColor = fillColors[loop];newData.datasets.push(dataset);}return newData;diff --git a/public/v1/js/ff/list/groups.js b/public/v1/js/ff/list/groups.jsindex dc512ab66f..98bc371cf5 100644--- a/public/v1/js/ff/list/groups.js+++ b/public/v1/js/ff/list/groups.js@@ -22,7 +22,97 @@ var count = 0;$(document).ready(function () {updateListButtons();+ addSort();});++var fixHelper = function (e, tr) {+ "use strict";+ var $originals = tr.children();+ var $helper = tr.clone();+ $helper.children().each(function (index) {+ // Set helper cell sizes to match the original sizes+ $(this).width($originals.eq(index).width());+ });+ return $helper;+};++/**+ *+ */+function addSort() {+ if (typeof $(".table-sortable>tbody").sortable !== "undefined") {+ $('.table-sortable>tbody').sortable(+ {+ items: "tr:not(.unsortable)",+ handle: '.object-handle',+ stop: sortStop,+ start: function (event, ui) {+ // Build a placeholder cell that spans all the cells in the row+ var cellCount = 0;+ $('td, th', ui.helper).each(function () {+ // For each TD or TH try and get it's colspan attribute, and add that or 1 to the total+ var colspan = 1;+ var colspanAttr = $(this).attr('colspan');+ if (colspanAttr > 1) {+ colspan = colspanAttr;+ }+ cellCount += colspan;+ });++ // Add the placeholder UI - note that this is the item's content, so TD rather than TR+ ui.placeholder.html('<td colspan="' + cellCount + '"> </td>');+ }+ }+ );+ }+}++/**+ *+ * @param event+ * @param ui+ * @returns {boolean|undefined}+ */+function sortStop(event, ui) {+ "use strict";+ var current = $(ui.item);+ var thisDate = current.data('date');+ var originalBG = current.css('backgroundColor');+++ if (current.prev().data('date') !== thisDate && current.next().data('date') !== thisDate) {+ // animate something with color:+ current.animate({backgroundColor: "#d9534f"}, 200, function () {+ $(this).animate({backgroundColor: originalBG}, 200);+ return undefined;+ });++ return false;+ }+ //return false;+ // do update+ var list = $('tr[data-date="' + thisDate + '"]');+ var submit = [];+ $.each(list, function (i, v) {+ var row = $(v);+ var id = row.data('id');+ submit.push(id);+ });++ // do extra animation when done?+ $.post('transactions/reorder', {items: submit, date: thisDate, _token: token});++ current.animate({backgroundColor: "#5cb85c"}, 200, function () {+ $(this).animate({backgroundColor: originalBG}, 200);+ return undefined;+ });+ return undefined;+}+++/**+ *+ */function updateListButtons() {// top button to select all / deselect all:$('input[name="select-all"]').change(function () {@@ -91,8 +181,6 @@ function getCheckboxes() {}--function countChecked() {count = $('.mass-select:checked').length;}diff --git a/public/v1/js/ff/rules/index.js b/public/v1/js/ff/rules/index.jsindex 2b49866b1f..c15c09dc29 100644--- a/public/v1/js/ff/rules/index.js+++ b/public/v1/js/ff/rules/index.js@@ -59,7 +59,7 @@ function testRuleTriggers(e) {var modal = $("#testTriggerModal");// respond to modal:- modal.on('hide.bs.modal', function (e) {+ modal.on('hide.bs.modal', function () {disableRuleSpinners();});@@ -98,28 +98,28 @@ function sortStop(event, ui) {// resort / move rule$.each($('.group-rules'), function(i,v) {- $.each($('tr.single-rule', $(v)), function (i, v) {- var holder = $(v);+ $.each($('tr.single-rule', $(v)), function (counter, value) {+ var holder = $(value);var position = parseInt(holder.data('position'));var ruleGroupId = holder.data('group-id');var ruleId = holder.data('id');var originalOrder = parseInt(holder.data('order'));var newOrder;- if (position === i) {+ if (position === counter) {// not changed, position is what it should be.return;}- if (position < i) {+ if (position < counter) {// position is less.- console.log('Rule #' + ruleId + ' moved down from position ' + originalOrder + ' to ' + (i + 1));+ console.log('Rule #' + ruleId + ' moved down from position ' + originalOrder + ' to ' + (counter + 1));}- if (position > i) {- console.log('Rule #' + ruleId + ' moved up from position ' + originalOrder + ' to ' + (i + 1));+ if (position > counter) {+ console.log('Rule #' + ruleId + ' moved up from position ' + originalOrder + ' to ' + (counter + 1));}// update position:- holder.data('position', i);- newOrder = i+1;+ holder.data('position', counter);+ newOrder = counter + 1;$.post('rules/move-rule/' + ruleId + '/' + ruleGroupId, {order: newOrder, _token: token});});diff --git a/resources/assets/js/components/transactions/EditTransaction.vue b/resources/assets/js/components/transactions/EditTransaction.vueindex 8a4a28d03e..1f0e1c4d5e 100644--- a/resources/assets/js/components/transactions/EditTransaction.vue+++ b/resources/assets/js/components/transactions/EditTransaction.vue@@ -806,7 +806,7 @@ export default {// console.log('Uploading attachment #' + key);const uploadUri = './api/v1/attachments/' + response.data.data.id + '/upload';axios.post(uploadUri, fileData[key].content)- .then(response => {+ .then(secondResponse => {// console.log('Uploaded attachment #' + key);uploads++;if (uploads === count) {diff --git a/resources/views/v1/accounts/show.twig b/resources/views/v1/accounts/show.twigindex de3a8519f3..116ce38b24 100644--- a/resources/views/v1/accounts/show.twig+++ b/resources/views/v1/accounts/show.twig@@ -171,13 +171,13 @@{% block scripts %}<script type="text/javascript" nonce="{{ JS_NONCE }}">-+ var doPlaceMarker = false;// location stuff{% if location %}var latitude = {{ location.latitude|default("52.3167") }};var longitude = {{ location.longitude|default("5.5500") }};var zoomLevel = {{ location.zoom_level|default("6") }};- var doPlaceMarker = true;+ doPlaceMarker = true;// token for Mapbox:var mapboxToken = "{{ config('firefly.mapbox_api_key') }}";{% endif %}diff --git a/resources/views/v1/list/groups.twig b/resources/views/v1/list/groups.twigindex e3848caaf2..2663cb406d 100644--- a/resources/views/v1/list/groups.twig+++ b/resources/views/v1/list/groups.twig@@ -1,8 +1,4 @@-<!---TODO: reconcile-TODO: hide and show columns--->-<table class="table table-condensed table-hover table-responsive">+<table class="table table-condensed table-hover table-responsive table-sortable"><thead><tr>{% if showCategory or showBudget %}@@ -53,7 +49,7 @@ TODO: hide and show columns<tbody>{% for group in groups %}{% if group.count > 1 %}- <tr style="border-top:1px #aaa solid;">+ <tr style="border-top:1px #aaa solid;" class="unsortable"><td colspan="2" style="border-top:1px #aaa solid;"><small><strong><a href="{{ route('transactions.show', [group.id]) }}"@@ -102,25 +98,25 @@ TODO: hide and show columns{% if group.transactions|length == loop.index and group.count > 1 %}{% set style="border-bottom:1px #aaa solid;" %}{% endif %}- <tr data-date="{{ transaction.date.format('Y-m-d') }}">+ <tr data-date="{{ transaction.date.format('Y-m-d') }}" data-count="{{ group.count }}" data-id="{{ group.id }}"><td style=" {{ style|raw }}" class="hidden-xs">{% if transaction.transaction_type_type == 'Withdrawal' %}- <i class="fa fa-long-arrow-left fa-fw" title="{{ trans('firefly.Withdrawal') }}"></i>+ <i class="object-handle fa fa-long-arrow-left fa-fw" title="{{ trans('firefly.Withdrawal') }}"></i>{% endif %}{% if transaction.transaction_type_type == 'Deposit' %}- <i class="fa fa-long-arrow-right fa-fw" title="{{ trans('firefly.Deposit') }}"></i>+ <i class="object-handle fa fa-long-arrow-right fa-fw" title="{{ trans('firefly.Deposit') }}"></i>{% endif %}{% if transaction.transaction_type_type == 'Transfer' %}- <i class="fa fa-exchange fa-fw" title="{{ trans('firefly.Transfer') }}"></i>+ <i class="object-handle fa fa-exchange fa-fw" title="{{ trans('firefly.Transfer') }}"></i>{% endif %}{% if transaction.transaction_type_type == 'Reconciliation' %}- <i class="fa-fw fa fa-calculator" title="{{ trans('firefly.reconciliation_transaction') }}"></i>+ <i class="object-handle fa-fw fa fa-calculator" title="{{ trans('firefly.reconciliation_transaction') }}"></i>{% endif %}{% if transaction.transaction_type_type == 'Opening balance' %}- <i class="fa-fw fa fa-star-o" title="{{ trans('firefly.Opening balance') }}"></i>+ <i class="object-handle fa-fw fa fa-star-o" title="{{ trans('firefly.Opening balance') }}"></i>{% endif %}</td>