mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-11-30 20:54:04 -06:00
Expand code for #384
This commit is contained in:
parent
06683c57dd
commit
b93a96db23
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user