Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Fixed some reports.
James Coledbb1c4d5341b
diff --git a/app/Helpers/Report/ReportQuery.php b/app/Helpers/Report/ReportQuery.phpindex fdaed62f68..5a31f9f502 100644--- a/app/Helpers/Report/ReportQuery.php+++ b/app/Helpers/Report/ReportQuery.php@@ -202,60 +202,6 @@ class ReportQuery implements ReportQueryInterface}- /**- * Gets a list of expense accounts and the expenses therein, grouped by that expense account.- * This result excludes transfers to shared accounts which are expenses, technically.- *- * So now it will include them!- *- * @param Carbon $start- * @param Carbon $end- * @param bool $includeShared- *- * @return Collection- */- public function journalsByExpenseAccount(Carbon $start, Carbon $end, $includeShared = false)- {- $query = $this->queryJournalsWithTransactions($start, $end);- if ($includeShared === false) {- // get all withdrawals not from a shared accounts- // and all transfers to a shared account- $query->where(- function (Builder $query) {- $query->where(- function (Builder $q) {- $q->where('transaction_types.type', 'Withdrawal');- $q->where('acm_from.data', '!=', '"sharedAsset"');- }- );- $query->orWhere(- function (Builder $q) {- $q->where('transaction_types.type', 'Transfer');- $q->where('acm_to.data', '=', '"sharedAsset"');- }- );- }- );- } else {- // any withdrawal goes:- $query->where('transaction_types.type', 'Withdrawal');- }- $query->before($end)->after($start)- ->where('transaction_journals.user_id', Auth::user()->id)- ->groupBy('t_to.account_id')- ->orderBy('queryAmount', 'DESC');-- $data = $query->get(['t_to.account_id as id', 'ac_to.name as name', 'ac_to.encrypted', DB::Raw('SUM(t_to.amount) as `queryAmount`')]);-- // decrypt- $data->each(- function (Model $object) {- $object->name = intval($object->encrypted) == 1 ? Crypt::decrypt($object->name) : $object->name;- }- );-- return $data;- }/*** @param Account $accountdiff --git a/app/Helpers/Report/ReportQueryInterface.php b/app/Helpers/Report/ReportQueryInterface.phpindex b732337ff4..09478d885b 100644--- a/app/Helpers/Report/ReportQueryInterface.php+++ b/app/Helpers/Report/ReportQueryInterface.php@@ -78,19 +78,4 @@ interface ReportQueryInterfacepublic function spentNoBudget(Account $account, Carbon $start, Carbon $end, $shared = false);- /**- * Gets a list of expense accounts and the expenses therein, grouped by that expense account.- * This result excludes transfers to shared accounts which are expenses, technically.- *- * So now it will include them!- *- * @param Carbon $start- * @param Carbon $end- * @param bool $includeShared- *- * @return Collection- *- */- public function journalsByExpenseAccount(Carbon $start, Carbon $end, $includeShared = false);-}diff --git a/app/Http/Controllers/Chart/BillController.php b/app/Http/Controllers/Chart/BillController.phpindex f4570c3d5a..f32611d055 100644--- a/app/Http/Controllers/Chart/BillController.php+++ b/app/Http/Controllers/Chart/BillController.php@@ -96,7 +96,7 @@ class BillController extends Controller$creditCards = $accounts->getCreditCards();foreach ($creditCards as $creditCard) {- $balance = Steam::balance($creditCard, null, true);+ $balance = Steam::balance($creditCard, $end, true);$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));if ($balance < 0) {// unpaid! create a fake bill that matches the amount.diff --git a/app/Http/Controllers/JsonController.php b/app/Http/Controllers/JsonController.phpindex 4fb1c49ba2..c3d198abff 100644--- a/app/Http/Controllers/JsonController.php+++ b/app/Http/Controllers/JsonController.php@@ -59,7 +59,7 @@ class JsonController extends Controller// if the balance is not zero, the monthly payment is still underway./** @var Account $creditCard */foreach ($creditCards as $creditCard) {- $balance = Steam::balance($creditCard, null, true);+ $balance = Steam::balance($creditCard, $end, true);if ($balance == 0) {// find a transfer TO the credit card which should account for// anything paid. If not, the CC is not yet used.@@ -99,7 +99,7 @@ class JsonController extends Controller$creditCards = $accountRepository->getCreditCards();foreach ($creditCards as $creditCard) {- $balance = Steam::balance($creditCard, null, true);+ $balance = Steam::balance($creditCard, $end, true);$date = new Carbon($creditCard->getMeta('ccMonthlyPaymentDate'));if ($balance < 0) {// unpaid! create a fake bill that matches the amount.diff --git a/app/Http/Controllers/PiggyBankController.php b/app/Http/Controllers/PiggyBankController.phpindex aa128c8223..de177cfb76 100644--- a/app/Http/Controllers/PiggyBankController.php+++ b/app/Http/Controllers/PiggyBankController.php@@ -45,7 +45,8 @@ class PiggyBankController extends Controller*/public function add(AccountRepositoryInterface $repository, PiggyBank $piggyBank){- $leftOnAccount = $repository->leftOnAccount($piggyBank->account);+ $date = Session::get('end', Carbon::now()->endOfMonth());+ $leftOnAccount = $repository->leftOnAccount($piggyBank->account, $date);$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;$leftToSave = $piggyBank->targetamount - $savedSoFar;$maxAmount = min($leftOnAccount, $leftToSave);@@ -157,6 +158,7 @@ class PiggyBankController extends Controller{/** @var Collection $piggyBanks */$piggyBanks = $piggyRepository->getPiggyBanks();+ $end = Session::get('end', Carbon::now()->endOfMonth());$accounts = [];/** @var PiggyBank $piggyBank */@@ -172,8 +174,8 @@ class PiggyBankController extends Controllerif (!isset($accounts[$account->id])) {$accounts[$account->id] = ['name' => $account->name,- 'balance' => Steam::balance($account, null, true),- 'leftForPiggyBanks' => $repository->leftOnAccount($account),+ 'balance' => Steam::balance($account, $end, true),+ 'leftForPiggyBanks' => $repository->leftOnAccount($account, $end),'sumOfSaved' => $piggyBank->savedSoFar,'sumOfTargets' => floatval($piggyBank->targetamount),'leftToSave' => $piggyBank->leftToSave@@ -215,7 +217,8 @@ class PiggyBankController extends Controllerpublic function postAdd(PiggyBankRepositoryInterface $repository, AccountRepositoryInterface $accounts, PiggyBank $piggyBank){$amount = round(floatval(Input::get('amount')), 2);- $leftOnAccount = $accounts->leftOnAccount($piggyBank->account);+ $date = Session::get('end', Carbon::now()->endOfMonth());+ $leftOnAccount = $accounts->leftOnAccount($piggyBank->account, $date);$savedSoFar = $piggyBank->currentRelevantRep()->currentamount;$leftToSave = $piggyBank->targetamount - $savedSoFar;$maxAmount = round(min($leftOnAccount, $leftToSave), 2);diff --git a/app/Providers/ConfigServiceProvider.php b/app/Providers/ConfigServiceProvider.phpindex 4e54eb7f11..f5b1b6f7ab 100644--- a/app/Providers/ConfigServiceProvider.php+++ b/app/Providers/ConfigServiceProvider.php@@ -17,6 +17,8 @@ class ConfigServiceProvider extends ServiceProvider* to overwrite any "vendor" or package configuration that you may want to* modify before the application handles the incoming request / command.*+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)+ ** @return void*/public function register()diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex 7c3f3e94ff..6697651359 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -308,12 +308,14 @@ class AccountRepository implements AccountRepositoryInterface/*** @param Account $account+ * @param Carbon $date** @return float*/- public function leftOnAccount(Account $account)+ public function leftOnAccount(Account $account, Carbon $date){- $balance = Steam::balance($account, null, true);++ $balance = Steam::balance($account, $date, true);/** @var PiggyBank $p */foreach ($account->piggybanks()->get() as $p) {$balance -= $p->currentRelevantRep()->currentamount;diff --git a/app/Repositories/Account/AccountRepositoryInterface.php b/app/Repositories/Account/AccountRepositoryInterface.phpindex cc80a6c403..1a25f120d5 100644--- a/app/Repositories/Account/AccountRepositoryInterface.php+++ b/app/Repositories/Account/AccountRepositoryInterface.php@@ -115,10 +115,11 @@ interface AccountRepositoryInterface/*** @param Account $account+ * @param Carbon $date** @return float*/- public function leftOnAccount(Account $account);+ public function leftOnAccount(Account $account, Carbon $date);/*** @param Account $accountdiff --git a/app/Repositories/Budget/BudgetRepository.php b/app/Repositories/Budget/BudgetRepository.phpindex f2fbc0c0ad..96a5899e13 100644--- a/app/Repositories/Budget/BudgetRepository.php+++ b/app/Repositories/Budget/BudgetRepository.php@@ -261,7 +261,6 @@ class BudgetRepository implements BudgetRepositoryInterface* @param bool $shared** @return float- * @internal param Carbon $date*/public function spentInPeriod(Budget $budget, Carbon $start, Carbon $end, $shared = true){diff --git a/app/Support/Navigation.php b/app/Support/Navigation.phpindex 470089f369..a885931c92 100644--- a/app/Support/Navigation.php+++ b/app/Support/Navigation.php@@ -28,21 +28,11 @@ class Navigation$add = ($skip + 1);$functionMap = [- '1D' => 'addDays',- 'daily' => 'addDays',- '1W' => 'addWeeks',- 'weekly' => 'addWeeks',- 'week' => 'addWeeks',- '1M' => 'addMonths',- 'month' => 'addMonths',- 'monthly' => 'addMonths',- '3M' => 'addMonths',- 'quarter' => 'addMonths',- 'quarterly' => 'addMonths',- '6M' => 'addMonths',- 'half-year' => 'addMonths',- 'year' => 'addYears',- 'yearly' => 'addYears',+ '1D' => 'addDays', 'daily' => 'addDays',+ '1W' => 'addWeeks', 'weekly' => 'addWeeks', 'week' => 'addWeeks',+ '1M' => 'addMonths', 'month' => 'addMonths', 'monthly' => 'addMonths', '3M' => 'addMonths',+ 'quarter' => 'addMonths', 'quarterly' => 'addMonths', '6M' => 'addMonths', 'half-year' => 'addMonths',+ 'year' => 'addYears', 'yearly' => 'addYears',];$modifierMap = ['quarter' => 3,diff --git a/app/Support/Steam.php b/app/Support/Steam.phpindex 22fa07e211..512e7bbe93 100644--- a/app/Support/Steam.php+++ b/app/Support/Steam.php@@ -23,12 +23,9 @@ class Steam** @return float*/- public function balance(Account $account, Carbon $date = null, $ignoreVirtualBalance = false)+ public function balance(Account $account, Carbon $date, $ignoreVirtualBalance = false){- $date = is_null($date) ? Carbon::now() : $date;-// find the first known transaction on this account:- //$firstDateObject = $account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')@@ -37,12 +34,6 @@ class Steam$firstDate = is_null($firstDateObject) ? clone $date : new Carbon($firstDateObject->date);$date = $date < $firstDate ? $firstDate : $date;- /**- *select * from transactions- * left join transaction_journals ON transaction_journals.id = transactions.transaction_journal_id- * order by date ASC- */-$balance = floatval($account->transactions()->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id'diff --git a/app/Support/Twig/General.php b/app/Support/Twig/General.phpindex 1d36857366..d3f3a51cb6 100644--- a/app/Support/Twig/General.php+++ b/app/Support/Twig/General.php@@ -21,6 +21,7 @@ class General extends Twig_Extension/**+ * @SuppressWarnings(PHPMD.ExcessiveMethodLength)* @return array*/public function getFilters()diff --git a/app/Support/Twig/Journal.php b/app/Support/Twig/Journal.phpindex bb63d656c4..02a2832f7e 100644--- a/app/Support/Twig/Journal.php+++ b/app/Support/Twig/Journal.php@@ -18,6 +18,7 @@ class Journal extends Twig_Extension{/**+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)* @return array*/public function getFilters()@@ -27,20 +28,25 @@ class Journal extends Twig_Extension$filters[] = new Twig_SimpleFilter('typeIcon', function (TransactionJournal $journal) {$type = $journal->transactionType->type;- if ($type == 'Withdrawal') {- return '<span class="glyphicon glyphicon-arrow-left" title="Withdrawal"></span>';- }- if ($type == 'Deposit') {- return '<span class="glyphicon glyphicon-arrow-right" title="Deposit"></span>';- }- if ($type == 'Transfer') {- return '<i class="fa fa-fw fa-exchange" title="Transfer"></i>';- }- if ($type == 'Opening balance') {- return '<span class="glyphicon glyphicon-ban-circle" title="Opening balance"></span>';++ switch ($type) {+ case 'Withdrawal':+ return '<span class="glyphicon glyphicon-arrow-left" title="' . trans('firefly.withdrawal') . '"></span>';+ break;+ case 'Deposit':+ return '<span class="glyphicon glyphicon-arrow-right" title="' . trans('firefly.deposit') . '"></span>';+ break;+ case 'Transfer':+ return '<i class="fa fa-fw fa-exchange" title="' . trans('firefly.transfer') . '"></i>';+ break;+ case 'Opening balance':+ return '<span class="glyphicon glyphicon-ban-circle" title="' . trans('firefly.openingBalance') . '"></span>';+ break;+ default:+ return '';+ break;}- return '';}, ['is_safe' => ['html']]);@@ -49,6 +55,8 @@ class Journal extends Twig_Extension}/**+ * @SuppressWarnings(PHPMD.CyclomaticComplexity)+ ** @return array*/public function getFunctions()