mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-09 20:11:22 +00:00
Finally updated the transaction controller to have some more sensible code.
This commit is contained in:
83
app/lib/FireflyIII/Helper/TransactionJournal/Helper.php
Normal file
83
app/lib/FireflyIII/Helper/TransactionJournal/Helper.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Helper\TransactionJournal;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Class Helper
|
||||
*
|
||||
* @package FireflyIII\Helper\TransactionJournal
|
||||
*/
|
||||
class Helper implements HelperInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* Get the account_id, which is the asset account that paid for the transaction.
|
||||
*
|
||||
* @param string $what
|
||||
* @param Collection $transactions
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getAssetAccount($what, Collection $transactions)
|
||||
{
|
||||
if ($what == 'withdrawal') {
|
||||
// transaction #1 is the one that paid for it.
|
||||
return intval($transactions[1]->account->id);
|
||||
}
|
||||
|
||||
// otherwise (its a deposit), it's been paid into account #0.
|
||||
return intval($transactions[0]->account->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getAssetAccounts()
|
||||
{
|
||||
/** @var \FireflyIII\Database\Account\Account $accountRepository */
|
||||
$accountRepository = \App::make('FireflyIII\Database\Account\Account');
|
||||
|
||||
return $accountRepository->getAssetAccounts();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getBudgets()
|
||||
{
|
||||
/** @var \FireflyIII\Database\Budget\Budget $budgetRepository */
|
||||
$budgetRepository = \App::make('FireflyIII\Database\Budget\Budget');
|
||||
|
||||
return $budgetRepository->get();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getPiggyBanks()
|
||||
{
|
||||
/** @var \FireflyIII\Database\PiggyBank\PiggyBank $piggyRepository */
|
||||
$piggyRepository = \App::make('FireflyIII\Database\PiggyBank\PiggyBank');
|
||||
|
||||
return $piggyRepository->get();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
public function getRepeatedExpenses()
|
||||
{
|
||||
/** @var \FireflyIII\Database\PiggyBank\RepeatedExpense $repRepository */
|
||||
$repRepository = \App::make('FireflyIII\Database\PiggyBank\RepeatedExpense');
|
||||
|
||||
return $repRepository->get();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user