mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Firefly is now capable of adding a transaction. Untested [skip-ci]
This commit is contained in:
@@ -2,25 +2,75 @@
|
||||
|
||||
|
||||
use Firefly\Storage\Account\AccountRepositoryInterface as ARI;
|
||||
use Firefly\Storage\Budget\BudgetRepositoryInterface as Bud;
|
||||
use Firefly\Storage\Category\CategoryRepositoryInterface as Cat;
|
||||
use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as TJRI;
|
||||
|
||||
class TransactionController extends BaseController {
|
||||
class TransactionController extends BaseController
|
||||
{
|
||||
|
||||
protected $accounts;
|
||||
protected $budgets;
|
||||
protected $categories;
|
||||
protected $tj;
|
||||
|
||||
public function __construct(ARI $accounts) {
|
||||
public function __construct(ARI $accounts, Bud $budgets, Cat $categories, TJRI $tj)
|
||||
{
|
||||
$this->accounts = $accounts;
|
||||
$this->budgets = $budgets;
|
||||
$this->categories = $categories;
|
||||
$this->tj = $tj;
|
||||
|
||||
|
||||
View::share('menu','home');
|
||||
View::share('menu', 'home');
|
||||
}
|
||||
|
||||
public function createWithdrawal() {
|
||||
public function createWithdrawal()
|
||||
{
|
||||
|
||||
// get accounts with names and id's.
|
||||
$accounts =$this->accounts->getActiveDefaultAsSelectList();
|
||||
$accounts = $this->accounts->getActiveDefaultAsSelectList();
|
||||
|
||||
$budgets = $this->budgets->getAsSelectList();
|
||||
|
||||
$budgets[0] = '(no budget)';
|
||||
|
||||
|
||||
return View::make('transactions.withdrawal')->with('accounts',$accounts);
|
||||
return View::make('transactions.withdrawal')->with('accounts', $accounts)->with('budgets', $budgets);
|
||||
}
|
||||
|
||||
public function postCreateWithdrawal()
|
||||
{
|
||||
|
||||
// create or find beneficiary:
|
||||
$beneficiary = $this->accounts->createOrFindBeneficiary(Input::get('beneficiary'));
|
||||
|
||||
// create or find category:
|
||||
$category = $this->categories->createOrFind(Input::get('category'));
|
||||
|
||||
// find budget:
|
||||
$budget = $this->budgets->find(intval(Input::get('budget_id')));
|
||||
|
||||
// find account:
|
||||
$account = $this->accounts->find(intval(Input::get('account_id')));
|
||||
|
||||
// find amount & description:
|
||||
$description = trim(Input::get('description'));
|
||||
$amount = floatval(Input::get('amount'));
|
||||
$date = new \Carbon\Carbon(Input::get('date'));
|
||||
|
||||
// create journal
|
||||
/** @var \TransactionJournal $journal */
|
||||
$journal = $this->tj->createSimpleJournal($account,$beneficiary,$description,$amount,$date);
|
||||
|
||||
var_dump($journal);
|
||||
|
||||
// attach bud/cat (?)
|
||||
$journal->budgets()->save($budget);
|
||||
$journal->categories()->save($category);
|
||||
|
||||
Session::flash('success','Transaction saved');
|
||||
return Redirect::route('index');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user