All kinds of fixes and things. I should really start organizing.

This commit is contained in:
Sander Dorigo
2014-11-07 11:18:06 +01:00
parent 44705f0e18
commit 139d985904
16 changed files with 142 additions and 311 deletions

View File

@@ -15,8 +15,8 @@ class HomeController extends BaseController
protected $_journal;
/**
* @param ARI $accounts
* @param PHI $preferences
* @param ARI $accounts
* @param PHI $preferences
* @param TJRI $journal
*/
public function __construct(ARI $accounts, PHI $preferences, TJRI $journal)
@@ -115,4 +115,59 @@ class HomeController extends BaseController
return View::make('index')->with('count', $count)->with('transactions', $transactions)->with('title', 'Firefly')
->with('subTitle', 'What\'s playing?')->with('mainTitleIcon', 'fa-fire');
}
public function cleanup()
{
/** @var \FireflyIII\Database\TransactionJournal $jrnls */
$jrnls = App::make('FireflyIII\Database\TransactionJournal');
/** @var \FireflyIII\Database\Account $acct */
$acct = \App::make('FireflyIII\Database\Account');
/** @var \FireflyIII\Database\AccountType $acctType */
$acctType = \App::make('FireflyIII\Database\AccountType');
$rightAcctType = $acctType->findByWhat('revenue');
$all = $jrnls->get();
/** @var \TransactionJournal $entry */
foreach ($all as $entry) {
$wrongFromType = false;
$wrongToType = false;
$transactions = $entry->transactions;
if (count($transactions) == 2) {
switch ($entry->transactionType->type) {
case 'Deposit':
/** @var \Transaction $transaction */
foreach ($transactions as $transaction) {
if (floatval($transaction->amount) < 0) {
$accountType = $transaction->account->accountType;
if ($accountType->type == 'Beneficiary account') {
// should be a Revenue account!
$name = $transaction->account->name;
/** @var \Account $account */
$account = \Auth::user()->accounts()->where('name', $name)->where('account_type_id', $rightAcctType->id)->first();
if (!$account) {
$new = [
'name' => $name,
'what' => 'revenue'
];
$account = $acct->store($new);
}
$transaction->account()->associate($account);
$transaction->save();
}
echo 'Paid by: ' . $transaction->account->name . ' (' . $transaction->account->accountType->type . ')<br />';
}
}
break;
}
}
}
}
}