Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Expand code for #384
James Coleb93a96db23b2
diff --git a/app/Http/Controllers/Report/ExpenseController.php b/app/Http/Controllers/Report/ExpenseController.phpindex a738e8f529..fdf896db97 100644--- a/app/Http/Controllers/Report/ExpenseController.php+++ b/app/Http/Controllers/Report/ExpenseController.php@@ -23,7 +23,12 @@ declare(strict_types=1);namespace FireflyIII\Http\Controllers\Report;+use Carbon\Carbon;use FireflyIII\Http\Controllers\Controller;+use FireflyIII\Models\Account;+use FireflyIII\Models\AccountType;+use FireflyIII\Repositories\Account\AccountRepositoryInterface;+use Illuminate\Support\Collection;/**@@ -31,5 +36,58 @@ use FireflyIII\Http\Controllers\Controller;*/class ExpenseController extends Controller{+ /** @var AccountRepositoryInterface */+ protected $accountRepository;++ /**+ *+ */+ public function __construct()+ {+ parent::__construct();++ // translations:+ $this->middleware(+ function ($request, $next) {+ $this->accountRepository = app(AccountRepositoryInterface::class);++ return $next($request);+ }+ );+ }++ /**+ * @param Collection $accounts+ * @param Collection $expense+ * @param Carbon $start+ * @param Carbon $end+ */+ public function spentGrouped(Collection $accounts, Collection $expense, Carbon $start, Carbon $end)+ {+ $combined = $this->combineAccounts($expense);+ // for period, get spent and earned for each account (by name)+ /**+ * @var string $name+ * @var Collection $combi+ */+ foreach($combined as $name => $combi) {++ }+ }++ protected function combineAccounts(Collection $accounts): array+ {+ $combined = [];+ /** @var Account $expenseAccount */+ foreach ($accounts as $expenseAccount) {+ $combined[$expenseAccount->name] = [$expenseAccount];+ $revenue = $this->accountRepository->findByName($expenseAccount->name, [AccountType::REVENUE]);+ if (!is_null($revenue->id)) {+ $combined[$expenseAccount->name][] = $revenue;+ }+ }++ return $combined;+ }}\ No newline at end of filediff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex cb4b8f87fc..83f97f97aa 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -160,6 +160,7 @@ class AccountRepository implements AccountRepositoryInterface* @param array $data** @return Account+ * @throws FireflyException*/public function store(array $data): Account{@@ -364,13 +365,13 @@ class AccountRepository implements AccountRepositoryInterface'date' => $data['openingBalanceDate'],]);- Log::debug(sprintf('Created new opening balance journal: #%d', $journal->id));+ Log::notice(sprintf('Created new opening balance journal: #%d', $journal->id));$firstAccount = $account;$secondAccount = $opposing;$firstAmount = $amount;$secondAmount = bcmul($amount, '-1');- Log::debug(sprintf('First amount is %s, second amount is %s', $firstAmount, $secondAmount));+ Log::notice(sprintf('First amount is %s, second amount is %s', $firstAmount, $secondAmount));if (bccomp($amount, '0') === -1) {Log::debug(sprintf('%s is a negative number.', $amount));@@ -378,7 +379,7 @@ class AccountRepository implements AccountRepositoryInterface$secondAccount = $account;$firstAmount = bcmul($amount, '-1');$secondAmount = $amount;- Log::debug(sprintf('First amount is %s, second amount is %s', $firstAmount, $secondAmount));+ Log::notice(sprintf('First amount is %s, second amount is %s', $firstAmount, $secondAmount));}$one = new Transaction(@@ -400,7 +401,7 @@ class AccountRepository implements AccountRepositoryInterface);$two->save(); // second transaction: to- Log::debug(sprintf('Stored two transactions, #%d and #%d', $one->id, $two->id));+ Log::notice(sprintf('Stored two transactions for new account, #%d and #%d', $one->id, $two->id));return $journal;}