mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some basic fixes for the transaction controller [skip ci]
This commit is contained in:
parent
af856a135f
commit
d756324432
@ -15,24 +15,21 @@ function inputRange(e) {
|
||||
var target = $(e.target);
|
||||
var piggyBankId = target.attr('name').substring(6);
|
||||
var accountId = target.data('account');
|
||||
var value = parseFloat(target.val());
|
||||
var amount = parseFloat(target.val());
|
||||
|
||||
|
||||
var leftInAccount = leftInAccounts(accountId);
|
||||
|
||||
if(leftInAccount <= 0) {
|
||||
value = parseFloat($('#piggy_'+piggyBankId+'_amount').val());
|
||||
target.val(parseFloat(value));
|
||||
}
|
||||
var valueId = 'piggy_' + piggyBankId + '_amount';
|
||||
$('#' + valueId).val(value.toFixed(2));
|
||||
//
|
||||
// // new percentage for amount in piggy bank, formatted.
|
||||
// new percentage for amount in piggy bank, formatted.
|
||||
var pctId = 'piggy_' + piggyBankId + '_pct';
|
||||
percentage = Math.round((value / parseFloat(target.attr('max'))) * 100) + '%'; //Math.round((value / parseFloat(target.attr('total'))) * 100) + '%';
|
||||
percentage = Math.round((amount / parseFloat(target.attr('max'))) * 100) + '%'; //Math.round((value / parseFloat(target.attr('total'))) * 100) + '%';
|
||||
$('#' + pctId).text(percentage);
|
||||
|
||||
// update the bar accordingly.
|
||||
// new value for number input:
|
||||
var valueId = 'piggy_' + piggyBankId + '_amount';
|
||||
$('#' + valueId).val(amount.toFixed(2));
|
||||
|
||||
leftInAccounts(accountId);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -42,27 +39,27 @@ function inputNumber(e) {
|
||||
var amount = parseFloat(target.val());
|
||||
var piggyBankId = target.data('piggy');
|
||||
var accountId = target.data('account');
|
||||
var leftInAccount = leftInAccounts(accountId);
|
||||
|
||||
if(leftInAccount <= 0) {
|
||||
amount = parseFloat($('#piggy_'+piggyBankId+'_amount').val());
|
||||
} else {
|
||||
// do something!
|
||||
}
|
||||
|
||||
// update amount in range input:
|
||||
target.val(amount);
|
||||
console.log('SERVER');
|
||||
$('input[name="piggy_'+piggyBankId+'"]').val(amount);
|
||||
console.log('SERVER: ' + amount);
|
||||
$.post('piggybanks/updateAmount/' + piggyBankId, {amount: amount});
|
||||
|
||||
leftInAccounts(accountId);
|
||||
}
|
||||
|
||||
|
||||
function updateAmount(e) {
|
||||
|
||||
// update amount on server:
|
||||
var target = $(e.target);
|
||||
var piggyBankId = target.attr('name').substring(6);
|
||||
var accountId = target.data('account');
|
||||
var value = target.val();
|
||||
console.log('SERVER');
|
||||
$.post('piggybanks/updateAmount/' + piggyBankId, {amount: value});
|
||||
var amount = target.val();
|
||||
console.log('SERVER: ' + amount);
|
||||
$.post('piggybanks/updateAmount/' + piggyBankId, {amount: amount});
|
||||
|
||||
|
||||
}
|
||||
@ -80,7 +77,11 @@ function leftInAccounts(accountId) {
|
||||
}
|
||||
});
|
||||
var left = total - inPiggies;
|
||||
console.log('LEFT: ' + left);
|
||||
|
||||
// set amount left:
|
||||
leftFormatted = '€ ' + left.toFixed(2);
|
||||
$('#account_'+accountId+'_left').text(leftFormatted);
|
||||
|
||||
// return amount left:
|
||||
return left;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Firefly\Storage\Category\CategoryRepositoryInterface as CRI;
|
||||
use Firefly\Helper\Controllers\CategoryInterface as CI;
|
||||
use Firefly\Storage\Category\CategoryRepositoryInterface as CRI;
|
||||
|
||||
/**
|
||||
* Class CategoryController
|
||||
@ -35,6 +35,7 @@ class CategoryController extends BaseController
|
||||
} else {
|
||||
Session::flash('error', 'Could not delete the category. Check the logs to be sure.');
|
||||
}
|
||||
|
||||
return Redirect::route('categories.index');
|
||||
}
|
||||
|
||||
@ -46,6 +47,7 @@ class CategoryController extends BaseController
|
||||
public function index()
|
||||
{
|
||||
$categories = $this->_repository->get();
|
||||
|
||||
return View::make('categories.index')->with('categories', $categories);
|
||||
}
|
||||
|
||||
@ -57,7 +59,7 @@ class CategoryController extends BaseController
|
||||
|
||||
$journals = $this->_category->journalsInRange($category, $start, $end);
|
||||
|
||||
return View::make('categories.show')->with('category', $category)->with('journals',$journals);
|
||||
return View::make('categories.show')->with('category', $category)->with('journals', $journals);
|
||||
}
|
||||
|
||||
public function store()
|
||||
@ -69,9 +71,11 @@ class CategoryController extends BaseController
|
||||
if (Input::get('create') == '1') {
|
||||
return Redirect::route('categories.create');
|
||||
}
|
||||
|
||||
return Redirect::route('categories.index');
|
||||
} else {
|
||||
Session::flash('error', 'Could not save the new category!');
|
||||
|
||||
return Redirect::route('categories.create')->withInput();
|
||||
}
|
||||
}
|
||||
|
@ -35,8 +35,8 @@ class ChartController extends BaseController
|
||||
$end = Session::get('end');
|
||||
|
||||
\Log::debug('Draw home account chart.');
|
||||
\Log::debug('From: '.$start.' ('.$start->timezone.')');
|
||||
\Log::debug('Until: '.$end);
|
||||
\Log::debug('From: ' . $start . ' (' . $start->timezone . ')');
|
||||
\Log::debug('Until: ' . $end);
|
||||
|
||||
if (is_null($account)) {
|
||||
// get, depending on preferences:
|
||||
@ -116,7 +116,9 @@ class ChartController extends BaseController
|
||||
|
||||
|
||||
}
|
||||
public function categoryShowChart(Category $category) {
|
||||
|
||||
public function categoryShowChart(Category $category)
|
||||
{
|
||||
$start = Session::get('start');
|
||||
$end = Session::get('end');
|
||||
$range = Session::get('range');
|
||||
@ -124,11 +126,11 @@ class ChartController extends BaseController
|
||||
$serie = $this->_chart->categoryShowChart($category, $range, $start, $end);
|
||||
$data = [
|
||||
'chart_title' => $category->name,
|
||||
'subtitle' => '<a href="' . route('categories.show', [$category->id]) . '">View more</a>',
|
||||
'series' => $serie
|
||||
'subtitle' => '<a href="' . route('categories.show', [$category->id]) . '">View more</a>',
|
||||
'series' => $serie
|
||||
];
|
||||
return Response::json($data);
|
||||
|
||||
return Response::json($data);
|
||||
|
||||
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ class LimitController extends BaseController
|
||||
{
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
$prefilled = [
|
||||
'startdate' => Input::get('startdate') ? : date('Y-m-d'),
|
||||
'startdate' => Input::get('startdate') ? : date('Y-m-d'),
|
||||
'repeat_freq' => Input::get('repeat_freq') ? : 'monthly',
|
||||
'budget_id' => $budget ? $budget->id : null
|
||||
'budget_id' => $budget ? $budget->id : null
|
||||
];
|
||||
|
||||
$budgets = $this->_budgets->getAsSelectList();
|
||||
|
@ -27,19 +27,24 @@ class PiggybankController extends BaseController
|
||||
return View::make('piggybanks.create')->with('accounts', $accounts);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
public function delete(Piggybank $piggyBank)
|
||||
{
|
||||
return View::make('piggybanks.delete')->with('piggybank', $piggyBank);
|
||||
}
|
||||
|
||||
public function destroy()
|
||||
public function destroy(Piggybank $piggyBank)
|
||||
{
|
||||
$piggyBank->delete();
|
||||
Session::flash('success', 'Piggy bank deleted.');
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
}
|
||||
|
||||
public function edit()
|
||||
public function edit(Piggybank $piggyBank)
|
||||
{
|
||||
}
|
||||
public function updateAmount(Piggybank $piggybank) {
|
||||
$this->_repository->updateAmount($piggybank,Input::get('amount'));
|
||||
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
|
||||
|
||||
return View::make('piggybanks.edit')->with('piggybank', $piggyBank)->with('accounts', $accounts);
|
||||
}
|
||||
|
||||
public function index()
|
||||
@ -55,8 +60,10 @@ class PiggybankController extends BaseController
|
||||
if (!isset($accounts[$id])) {
|
||||
$account->balance = $account->balance();
|
||||
$account->left = $account->balance - $piggyBank->amount;
|
||||
$account->total = $piggyBank->target;
|
||||
} else {
|
||||
$account->left -= $piggyBank->amount;
|
||||
$account->total += $piggyBank->target;
|
||||
|
||||
}
|
||||
$accounts[$id] = $account;
|
||||
@ -80,7 +87,12 @@ class PiggybankController extends BaseController
|
||||
|
||||
return Redirect::route('piggybanks.create')->withInput();
|
||||
} else {
|
||||
Session::flash('success', 'New piggy bank created!');
|
||||
Session::flash('success', 'New piggy bank "' . $piggyBank->name . '" created!');
|
||||
|
||||
|
||||
if (Input::get('create') == '1') {
|
||||
return Redirect::route('piggybanks.create')->withInput();
|
||||
}
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
}
|
||||
@ -89,5 +101,15 @@ class PiggybankController extends BaseController
|
||||
|
||||
public function update()
|
||||
{
|
||||
|
||||
$piggyBank = $this->_repository->update(Input::all());
|
||||
Session::flash('success', 'Piggy bank "' . $piggyBank->name . '" updated.');
|
||||
|
||||
return Redirect::route('piggybanks.index');
|
||||
}
|
||||
|
||||
public function updateAmount(Piggybank $piggybank)
|
||||
{
|
||||
$this->_repository->updateAmount($piggybank, Input::get('amount'));
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
class RecurringController extends BaseController {
|
||||
class RecurringController extends BaseController
|
||||
{
|
||||
public function create()
|
||||
{
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
class ReportController extends BaseController {
|
||||
|
||||
class ReportController extends BaseController
|
||||
{
|
||||
|
||||
|
||||
public function index()
|
||||
|
@ -1,9 +1,6 @@
|
||||
<?php
|
||||
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
@ -12,38 +9,33 @@ use Firefly\Storage\TransactionJournal\TransactionJournalRepositoryInterface as
|
||||
class TransactionController extends BaseController
|
||||
{
|
||||
|
||||
protected $_accounts;
|
||||
protected $_budgets;
|
||||
protected $_categories;
|
||||
protected $_journal;
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param ARI $accounts
|
||||
* @param Bud $budgets
|
||||
* @param Cat $categories
|
||||
* @param TJRI $journal
|
||||
* @param TJRI $repository
|
||||
*/
|
||||
public function __construct(ARI $accounts, Bud $budgets, Cat $categories, TJRI $journal)
|
||||
public function __construct(TJRI $repository)
|
||||
{
|
||||
$this->_accounts = $accounts;
|
||||
$this->_budgets = $budgets;
|
||||
$this->_categories = $categories;
|
||||
$this->_journal = $journal;
|
||||
|
||||
|
||||
$this->_repository = $repository;
|
||||
View::share('menu', 'home');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $what
|
||||
* @param string $what
|
||||
*
|
||||
* @return $this|\Illuminate\View\View
|
||||
* @return \Illuminate\View\View
|
||||
*/
|
||||
public function create($what)
|
||||
public function create($what = 'deposit')
|
||||
{
|
||||
// get accounts with names and id's.
|
||||
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
|
||||
$budgets = $this->_budgets->getAsSelectList();
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts = $accountRepository->getActiveDefaultAsSelectList();
|
||||
|
||||
// get budgets as a select list.
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */
|
||||
$budgetRepository = App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets = $budgetRepository->getAsSelectList();
|
||||
$budgets[0] = '(no budget)';
|
||||
|
||||
|
||||
@ -52,63 +44,78 @@ class TransactionController extends BaseController
|
||||
);
|
||||
}
|
||||
|
||||
public function delete(TransactionJournal $transactionJournal)
|
||||
{
|
||||
return View::make('transactions.delete')->with('journal', $transactionJournal);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function destroy(TransactionJournal $transactionJournal)
|
||||
{
|
||||
$transactionJournal->delete();
|
||||
|
||||
return Redirect::route('transactions.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $journalId
|
||||
*
|
||||
* @return $this|\Illuminate\View\View
|
||||
*/
|
||||
public function edit($journalId)
|
||||
public function edit(TransactionJournal $journal)
|
||||
{
|
||||
// get journal:
|
||||
$journal = $this->_journal->find($journalId);
|
||||
// type is useful for display:
|
||||
$what = strtolower($journal->transactiontype->type);
|
||||
|
||||
if ($journal) {
|
||||
// type is useful for display:
|
||||
$what = strtolower($journal->transactiontype->type);
|
||||
// some lists prefilled:
|
||||
// get accounts with names and id's.
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$accounts = $accountRepository->getActiveDefaultAsSelectList();
|
||||
|
||||
// some lists prefilled:
|
||||
$budgets = $this->_budgets->getAsSelectList();
|
||||
$budgets[0] = '(no budget)';
|
||||
$accounts = $this->_accounts->getActiveDefaultAsSelectList();
|
||||
// get budgets as a select list.
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */
|
||||
$budgetRepository = App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
$budgets = $budgetRepository->getAsSelectList();
|
||||
$budgets[0] = '(no budget)';
|
||||
|
||||
// data to properly display form:
|
||||
$data = [
|
||||
'date' => $journal->date->format('Y-m-d'),
|
||||
'category' => '',
|
||||
'budget_id' => 0
|
||||
];
|
||||
$category = $journal->categories()->first();
|
||||
if (!is_null($category)) {
|
||||
$data['category'] = $category->name;
|
||||
}
|
||||
switch ($journal->transactiontype->type) {
|
||||
case 'Withdrawal':
|
||||
$data['account_id'] = $journal->transactions[0]->account->id;
|
||||
$data['beneficiary'] = $journal->transactions[1]->account->name;
|
||||
$data['amount'] = floatval($journal->transactions[1]->amount);
|
||||
$budget = $journal->budgets()->first();
|
||||
if (!is_null($budget)) {
|
||||
$data['budget_id'] = $budget->id;
|
||||
}
|
||||
break;
|
||||
case 'Deposit':
|
||||
$data['account_id'] = $journal->transactions[1]->account->id;
|
||||
$data['beneficiary'] = $journal->transactions[0]->account->name;
|
||||
$data['amount'] = floatval($journal->transactions[1]->amount);
|
||||
break;
|
||||
case 'Transfer':
|
||||
$data['account_from_id'] = $journal->transactions[1]->account->id;
|
||||
$data['account_to_id'] = $journal->transactions[0]->account->id;
|
||||
$data['amount'] = floatval($journal->transactions[1]->amount);
|
||||
break;
|
||||
}
|
||||
|
||||
return View::make('transactions.edit')->with('journal', $journal)->with('accounts', $accounts)->with(
|
||||
'what', $what
|
||||
)->with('budgets', $budgets)->with('data', $data);
|
||||
// data to properly display form:
|
||||
$data = [
|
||||
'date' => $journal->date->format('Y-m-d'),
|
||||
'category' => '',
|
||||
'budget_id' => 0
|
||||
];
|
||||
$category = $journal->categories()->first();
|
||||
if (!is_null($category)) {
|
||||
$data['category'] = $category->name;
|
||||
}
|
||||
switch ($journal->transactiontype->type) {
|
||||
case 'Withdrawal':
|
||||
$data['account_id'] = $journal->transactions[0]->account->id;
|
||||
$data['beneficiary'] = $journal->transactions[1]->account->name;
|
||||
$data['amount'] = floatval($journal->transactions[1]->amount);
|
||||
$budget = $journal->budgets()->first();
|
||||
if (!is_null($budget)) {
|
||||
$data['budget_id'] = $budget->id;
|
||||
}
|
||||
break;
|
||||
case 'Deposit':
|
||||
$data['account_id'] = $journal->transactions[1]->account->id;
|
||||
$data['beneficiary'] = $journal->transactions[0]->account->name;
|
||||
$data['amount'] = floatval($journal->transactions[1]->amount);
|
||||
break;
|
||||
case 'Transfer':
|
||||
$data['account_from_id'] = $journal->transactions[1]->account->id;
|
||||
$data['account_to_id'] = $journal->transactions[0]->account->id;
|
||||
$data['amount'] = floatval($journal->transactions[1]->amount);
|
||||
break;
|
||||
}
|
||||
|
||||
return View::make('error')->with('message', 'Invalid journal');
|
||||
return View::make('transactions.edit')->with('journal', $journal)->with('accounts', $accounts)->with(
|
||||
'what', $what
|
||||
)->with('budgets', $budgets)->with('data', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,9 +123,9 @@ class TransactionController extends BaseController
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$transactions = $this->_journal->paginate(25);
|
||||
$journals = $this->_repository->paginate(25);
|
||||
|
||||
return View::make('transactions.index')->with('transactions', $transactions);
|
||||
return View::make('transactions.index')->with('journals', $journals);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,12 +135,12 @@ class TransactionController extends BaseController
|
||||
*/
|
||||
public function show($journalId)
|
||||
{
|
||||
$journal = $this->_journal->find($journalId);
|
||||
if ($journal) {
|
||||
return View::make('transactions.show')->with('journal', $journal);
|
||||
}
|
||||
|
||||
return View::make('error')->with('message', 'Invalid journal');
|
||||
// $journal = $this->_journal->find($journalId);
|
||||
// if ($journal) {
|
||||
// return View::make('transactions.show')->with('journal', $journal);
|
||||
// }
|
||||
//
|
||||
// return View::make('error')->with('message', 'Invalid journal');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,137 +150,37 @@ class TransactionController extends BaseController
|
||||
*/
|
||||
public function store($what)
|
||||
{
|
||||
// $fromAccount and $toAccount are found
|
||||
// depending on the $what
|
||||
|
||||
$fromAccount = null;
|
||||
$toAccount = null;
|
||||
|
||||
switch ($what) {
|
||||
case 'withdrawal':
|
||||
$fromAccount = $this->_accounts->find(intval(Input::get('account_id')));
|
||||
$toAccount = $this->_accounts->createOrFindBeneficiary(Input::get('beneficiary'));
|
||||
break;
|
||||
case 'deposit':
|
||||
$fromAccount = $this->_accounts->createOrFindBeneficiary(Input::get('beneficiary'));
|
||||
$toAccount = $this->_accounts->find(intval(Input::get('account_id')));
|
||||
break;
|
||||
case 'transfer':
|
||||
$fromAccount = $this->_accounts->find(intval(Input::get('account_from_id')));
|
||||
$toAccount = $this->_accounts->find(intval(Input::get('account_to_id')));
|
||||
break;
|
||||
}
|
||||
// fall back to cash if necessary:
|
||||
$fromAccount = is_null($fromAccount) ? $fromAccount = $this->_accounts->getCashAccount() : $fromAccount;
|
||||
$toAccount = is_null($toAccount) ? $toAccount = $this->_accounts->getCashAccount() : $toAccount;
|
||||
|
||||
// create or find category:
|
||||
$category = $this->_categories->createOrFind(Input::get('category'));
|
||||
|
||||
// find budget:
|
||||
$budget = $this->_budgets->find(intval(Input::get('budget_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 */
|
||||
try {
|
||||
$journal = $this->_journal->createSimpleJournal($fromAccount, $toAccount, $description, $amount, $date);
|
||||
} catch (\Firefly\Exception\FireflyException $e) {
|
||||
return Redirect::route('transactions.create', $what)->withInput();
|
||||
}
|
||||
|
||||
// attach bud/cat (?)
|
||||
if (!is_null($budget)) {
|
||||
$journal->budgets()->save($budget);
|
||||
}
|
||||
if (!is_null($category)) {
|
||||
$journal->categories()->save($category);
|
||||
}
|
||||
|
||||
Session::flash('success', 'Transaction "' . $description . '" saved');
|
||||
|
||||
if (Input::get('create') == '1') {
|
||||
return Redirect::route('transactions.create', $what)->withInput();
|
||||
$transactionJournal = $this->_repository->store($what, Input::all());
|
||||
if ($transactionJournal->id) {
|
||||
Session::flash('success', 'Transaction "' . $transactionJournal->description . '" saved!');
|
||||
if (Input::get('create') == '1') {
|
||||
return Redirect::route('transactions.create', [$what])->withInput();
|
||||
} else {
|
||||
return Redirect::route('transactions.index');
|
||||
}
|
||||
} else {
|
||||
return Redirect::route('index');
|
||||
Session::flash('error', 'Could not save transaction: ' . $transactionJournal->errors()->first());
|
||||
|
||||
return Redirect::route('transactions.create', [$what])->withInput()->withErrors(
|
||||
$transactionJournal->errors()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function update($journalId)
|
||||
public function update(TransactionJournal $journal)
|
||||
{
|
||||
$journal = $this->_repository->update($journal, Input::all());
|
||||
if ($journal->validate()) {
|
||||
// has been saved, return to index:
|
||||
Session::flash('success', 'Transaction updated!');
|
||||
|
||||
// get journal:
|
||||
$journal = $this->_journal->find($journalId);
|
||||
return Redirect::route('transactions.index');
|
||||
} else {
|
||||
Session::flash('error', 'Could not update transaction: ' . $journal->errors()->first());
|
||||
|
||||
if ($journal) {
|
||||
// update basics first:
|
||||
$journal->description = Input::get('description');
|
||||
$journal->date = Input::get('date');
|
||||
$amount = floatval(Input::get('amount'));
|
||||
|
||||
// remove previous category, if any:
|
||||
if (!is_null($journal->categories()->first())) {
|
||||
$journal->categories()->detach($journal->categories()->first()->id);
|
||||
}
|
||||
// remove previous budget, if any:
|
||||
if (!is_null($journal->budgets()->first())) {
|
||||
$journal->budgets()->detach($journal->budgets()->first()->id);
|
||||
}
|
||||
|
||||
// get the category:
|
||||
$category = $this->_categories->findByName(Input::get('category'));
|
||||
if (!is_null($category)) {
|
||||
$journal->categories()->attach($category);
|
||||
}
|
||||
// update the amounts:
|
||||
$journal->transactions[0]->amount = $amount * -1;
|
||||
$journal->transactions[1]->amount = $amount;
|
||||
|
||||
// switch on type to properly change things:
|
||||
switch ($journal->transactiontype->type) {
|
||||
case 'Withdrawal':
|
||||
// means transaction[0] is the users account.
|
||||
$account = $this->_accounts->find(Input::get('account_id'));
|
||||
$beneficiary = $this->_accounts->findByName(Input::get('beneficiary'));
|
||||
$journal->transactions[0]->account()->associate($account);
|
||||
$journal->transactions[1]->account()->associate($beneficiary);
|
||||
|
||||
|
||||
// do budget:
|
||||
$budget = $this->_budgets->find(Input::get('budget_id'));
|
||||
$journal->budgets()->attach($budget);
|
||||
|
||||
break;
|
||||
case 'Deposit':
|
||||
// means transaction[0] is the beneficiary.
|
||||
$account = $this->_accounts->find(Input::get('account_id'));
|
||||
$beneficiary = $this->_accounts->findByName(Input::get('beneficiary'));
|
||||
$journal->transactions[0]->account()->associate($beneficiary);
|
||||
$journal->transactions[1]->account()->associate($account);
|
||||
break;
|
||||
case 'Transfer':
|
||||
// means transaction[0] is account that sent the money (from).
|
||||
$fromAccount = $this->_accounts->find(Input::get('account_from_id'));
|
||||
$toAccount = $this->_accounts->find(Input::get('account_to_id'));
|
||||
$journal->transactions[0]->account()->associate($fromAccount);
|
||||
$journal->transactions[1]->account()->associate($toAccount);
|
||||
break;
|
||||
default:
|
||||
throw new \Firefly\Exception\FireflyException('Cannot edit this!');
|
||||
break;
|
||||
}
|
||||
|
||||
$journal->transactions[0]->save();
|
||||
$journal->transactions[1]->save();
|
||||
$journal->save();
|
||||
|
||||
return Redirect::route('transactions.edit', $journal->id);
|
||||
return Redirect::route('transactions.edit', $journal->id)->withInput()->withErrors($journal->errors());
|
||||
}
|
||||
|
||||
|
||||
|
@ -15,10 +15,9 @@ class Category implements CategoryInterface
|
||||
{
|
||||
public function journalsInRange(\Category $category, Carbon $start, Carbon $end)
|
||||
{
|
||||
return $category->transactionjournals()->
|
||||
with(['transactions','transactions.account','transactiontype','components'])->
|
||||
|
||||
orderBy('date','DESC')->orderBy('id','DESC')->before($end)->after($start)->get();
|
||||
return $category->transactionjournals()->with(
|
||||
['transactions', 'transactions.account', 'transactiontype', 'components']
|
||||
)->orderBy('date', 'DESC')->orderBy('id', 'DESC')->before($end)->after($start)->get();
|
||||
|
||||
}
|
||||
}
|
@ -11,7 +11,8 @@ namespace Firefly\Helper\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
interface CategoryInterface {
|
||||
interface CategoryInterface
|
||||
{
|
||||
|
||||
|
||||
public function journalsInRange(\Category $category, Carbon $start, Carbon $end);
|
||||
|
@ -21,7 +21,9 @@ class Chart implements ChartInterface
|
||||
$return = ['name' => $account->name, 'id' => $account->id, 'data' => []];
|
||||
|
||||
while ($current <= $end) {
|
||||
\Log::debug('Now at day: ' . $current . '('.$current->timestamp.'), ('.($current->timestamp * 1000).') ');
|
||||
\Log::debug(
|
||||
'Now at day: ' . $current . '(' . $current->timestamp . '), (' . ($current->timestamp * 1000) . ') '
|
||||
);
|
||||
if ($current > $today) {
|
||||
$return['data'][] = [$current->timestamp * 1000, $account->predict(clone $current)];
|
||||
} else {
|
||||
@ -38,7 +40,7 @@ class Chart implements ChartInterface
|
||||
{
|
||||
$result = [
|
||||
'rows' => [],
|
||||
'sum' => 0
|
||||
'sum' => 0
|
||||
];
|
||||
if ($account) {
|
||||
// get journals in range:
|
||||
@ -219,7 +221,6 @@ class Chart implements ChartInterface
|
||||
}
|
||||
|
||||
|
||||
|
||||
// now format the current range:
|
||||
$title = '';
|
||||
switch ($range) {
|
||||
@ -240,7 +241,7 @@ class Chart implements ChartInterface
|
||||
$title = $beginning->format('M Y') . ' - ' . $currentEnd->format('M Y');
|
||||
break;
|
||||
case 'custom':
|
||||
$title = $beginning->format('d-m-Y').' - '.$currentEnd->format('d-m-Y');
|
||||
$title = $beginning->format('d-m-Y') . ' - ' . $currentEnd->format('d-m-Y');
|
||||
break;
|
||||
case 'yearly':
|
||||
// return $this->startdate->format('Y');
|
||||
@ -257,7 +258,10 @@ class Chart implements ChartInterface
|
||||
)
|
||||
->leftJoin('transaction_types', 'transaction_types.id', '=', 'transaction_journals.transaction_type_id')
|
||||
->where('transaction_types.type', 'Withdrawal')
|
||||
->leftJoin('component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin(
|
||||
'component_transaction_journal', 'component_transaction_journal.transaction_journal_id', '=',
|
||||
'transaction_journals.id'
|
||||
)
|
||||
->leftJoin('components', 'components.id', '=', 'component_transaction_journal.component_id')
|
||||
->where('components.id', '=', $category->id)
|
||||
//->leftJoin()
|
||||
@ -306,6 +310,7 @@ class Chart implements ChartInterface
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
|
||||
|
@ -14,6 +14,7 @@ interface CategoryRepositoryInterface
|
||||
* @return mixed
|
||||
*/
|
||||
public function get();
|
||||
|
||||
public function find($categoryId);
|
||||
|
||||
/**
|
||||
|
@ -66,6 +66,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
|
||||
|
||||
$category->user()->associate(\Auth::user());
|
||||
$category->save();
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
{
|
||||
return \Piggybank::leftJoin('accounts', 'accounts.id', '=', 'piggybanks.account_id')->where(
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
)->where('piggybanks.id', $piggyBankId)->first('piggybanks.*');
|
||||
)->where('piggybanks.id', $piggyBankId)->first(['piggybanks.*']);
|
||||
}
|
||||
|
||||
public function get()
|
||||
@ -32,13 +32,6 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
'accounts.user_id', \Auth::user()->id
|
||||
)->get(['piggybanks.*']);
|
||||
}
|
||||
public function updateAmount(\Piggybank $piggyBank, $amount) {
|
||||
$piggyBank->amount = floatval($amount);
|
||||
if($piggyBank->validate()) {
|
||||
$piggyBank->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function store($data)
|
||||
{
|
||||
@ -62,4 +55,31 @@ class EloquentPiggybankRepository implements PiggybankRepositoryInterface
|
||||
|
||||
return $piggyBank;
|
||||
}
|
||||
|
||||
public function update($data)
|
||||
{
|
||||
$piggyBank = $this->find($data['id']);
|
||||
if ($piggyBank) {
|
||||
$accounts = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
$account = $accounts->find($data['account_id']);
|
||||
// update piggybank accordingly:
|
||||
$piggyBank->name = $data['name'];
|
||||
$piggyBank->target = floatval($data['target']);
|
||||
$piggyBank->account()->associate($account);
|
||||
if ($piggyBank->validate()) {
|
||||
$piggyBank->save();
|
||||
}
|
||||
}
|
||||
|
||||
return $piggyBank;
|
||||
}
|
||||
|
||||
public function updateAmount(\Piggybank $piggyBank, $amount)
|
||||
{
|
||||
$piggyBank->amount = floatval($amount);
|
||||
if ($piggyBank->validate()) {
|
||||
$piggyBank->save();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -12,9 +12,15 @@ interface PiggybankRepositoryInterface
|
||||
{
|
||||
|
||||
public function find($piggyBankId);
|
||||
|
||||
public function count();
|
||||
|
||||
public function store($data);
|
||||
|
||||
public function get();
|
||||
|
||||
public function updateAmount(\Piggybank $piggyBank, $amount);
|
||||
|
||||
public function update($data);
|
||||
|
||||
}
|
@ -32,8 +32,6 @@ class StorageServiceProvider extends ServiceProvider
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Storage\Account\AccountRepositoryInterface',
|
||||
'Firefly\Storage\Account\EloquentAccountRepository'
|
||||
|
@ -14,26 +14,6 @@ use Firefly\Exception\FireflyException;
|
||||
class EloquentTransactionJournalRepository implements TransactionJournalRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $journalId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($journalId)
|
||||
{
|
||||
return \Auth::user()->transactionjournals()->with(
|
||||
['transactions' => function ($q) {
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
}, 'transactioncurrency', 'transactiontype', 'components', 'transactions.account',
|
||||
'transactions.account.accounttype']
|
||||
)
|
||||
->where('id', $journalId)->first();
|
||||
}
|
||||
/*
|
||||
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* We're building this thinking the money goes from A to B.
|
||||
@ -66,20 +46,24 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
public function createSimpleJournal(\Account $from, \Account $toAccount, $description, $amount, Carbon $date)
|
||||
{
|
||||
\Log::debug('Creating tranaction "' . $description . '".');
|
||||
$journal = new \TransactionJournal;
|
||||
|
||||
$amountFrom = $amount * -1;
|
||||
$amountTo = $amount;
|
||||
|
||||
if (round(floatval($amount), 2) == 0.00) {
|
||||
\Log::error('Transaction will never save: amount = 0');
|
||||
\Session::flash('error', 'The amount should not be empty or zero.');
|
||||
throw new FireflyException('Could not figure out transaction type.');
|
||||
$journal->errors()->add('amount', 'Amount must not be zero.');
|
||||
|
||||
return $journal;
|
||||
}
|
||||
// same account:
|
||||
if ($from->id == $toAccount->id) {
|
||||
\Log::error('Accounts cannot be equal');
|
||||
\Session::flash('error', 'Select two different accounts.');
|
||||
throw new FireflyException('Select two different accounts.');
|
||||
$journal->errors()->add('account_id', 'Must be different accounts.');
|
||||
$journal->errors()->add('account_from_id', 'Must be different accounts.');
|
||||
|
||||
return $journal;
|
||||
}
|
||||
|
||||
// account types for both:
|
||||
@ -129,18 +113,15 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
}
|
||||
|
||||
// new journal:
|
||||
$journal = new \TransactionJournal();
|
||||
|
||||
$journal->transactionType()->associate($journalType);
|
||||
$journal->transactionCurrency()->associate($currency);
|
||||
$journal->user()->associate(\Auth::user());
|
||||
$journal->completed = false;
|
||||
$journal->description = $description;
|
||||
$journal->date = $date;
|
||||
if (!$journal->save()) {
|
||||
\Log::error('Cannot create valid journal.');
|
||||
\Log::error('Errors: ' . print_r($journal->errors()->all(), true));
|
||||
\Session::flash('error', 'Could not create journal: ' . $journal->errors()->first());
|
||||
throw new FireflyException('Cannot create valid journal.');
|
||||
if (!$journal->validate()) {
|
||||
return $journal;
|
||||
}
|
||||
$journal->save();
|
||||
|
||||
@ -150,7 +131,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$fromTransaction->transactionJournal()->associate($journal);
|
||||
$fromTransaction->description = null;
|
||||
$fromTransaction->amount = $amountFrom;
|
||||
if (!$fromTransaction->save()) {
|
||||
if (!$fromTransaction->validate()) {
|
||||
\Log::error('Cannot create valid transaction (from) for journal #' . $journal->id);
|
||||
\Log::error('Errors: ' . print_r($fromTransaction->errors()->all(), true));
|
||||
throw new FireflyException('Cannot create valid transaction (from).');
|
||||
@ -162,7 +143,7 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
$toTransaction->transactionJournal()->associate($journal);
|
||||
$toTransaction->description = null;
|
||||
$toTransaction->amount = $amountTo;
|
||||
if (!$toTransaction->save()) {
|
||||
if (!$toTransaction->validate()) {
|
||||
\Log::error('Cannot create valid transaction (to) for journal #' . $journal->id);
|
||||
\Log::error('Errors: ' . print_r($toTransaction->errors()->all(), true));
|
||||
throw new FireflyException('Cannot create valid transaction (to).');
|
||||
@ -174,6 +155,26 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
|
||||
return $journal;
|
||||
}
|
||||
/*
|
||||
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param $journalId
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($journalId)
|
||||
{
|
||||
return \Auth::user()->transactionjournals()->with(
|
||||
['transactions' => function ($q) {
|
||||
return $q->orderBy('amount', 'ASC');
|
||||
}, 'transactioncurrency', 'transactiontype', 'components', 'transactions.account',
|
||||
'transactions.account.accounttype']
|
||||
)
|
||||
->where('id', $journalId)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -183,6 +184,35 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByAccountAndDate(\Account $account, Carbon $date)
|
||||
{
|
||||
$accountID = $account->id;
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
[
|
||||
'transactions',
|
||||
'transactions.account',
|
||||
'transactioncurrency',
|
||||
'transactiontype'
|
||||
]
|
||||
)
|
||||
->distinct()
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->where('transactions.account_id', $accountID)
|
||||
->where('transaction_journals.date', $date->format('Y-m-d'))
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->get(['transaction_journals.*']);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param int $count
|
||||
@ -214,6 +244,17 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByDateRange(Carbon $start, Carbon $end)
|
||||
{
|
||||
die('no impl');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $count
|
||||
*
|
||||
@ -234,50 +275,154 @@ class EloquentTransactionJournalRepository implements TransactionJournalReposito
|
||||
)
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->take($count)
|
||||
->paginate($count);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Carbon $start
|
||||
* @param Carbon $end
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByDateRange(Carbon $start, Carbon $end)
|
||||
public function store($what, $data)
|
||||
{
|
||||
die('no impl');
|
||||
// $fromAccount and $toAccount are found
|
||||
// depending on the $what
|
||||
|
||||
$fromAccount = null;
|
||||
$toAccount = null;
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Category\CategoryRepositoryInterface $catRepository */
|
||||
$catRepository = \App::make('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budRepository */
|
||||
$budRepository = \App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
|
||||
|
||||
switch ($what) {
|
||||
case 'withdrawal':
|
||||
$fromAccount = $accountRepository->find(intval($data['account_id']));
|
||||
$toAccount = $accountRepository->createOrFindBeneficiary($data['beneficiary']);
|
||||
break;
|
||||
case 'deposit':
|
||||
$fromAccount = $accountRepository->createOrFindBeneficiary($data['beneficiary']);
|
||||
$toAccount = $accountRepository->find(intval($data['account_id']));
|
||||
break;
|
||||
case 'transfer':
|
||||
$fromAccount = $accountRepository->find(intval($data['account_from_id']));
|
||||
$toAccount = $accountRepository->find(intval($data['account_to_id']));
|
||||
break;
|
||||
}
|
||||
// fall back to cash if necessary:
|
||||
$fromAccount = is_null($fromAccount) ? $fromAccount = $accountRepository->getCashAccount() : $fromAccount;
|
||||
$toAccount = is_null($toAccount) ? $toAccount = $accountRepository->getCashAccount() : $toAccount;
|
||||
|
||||
// create or find category:
|
||||
$category = isset($data['category']) ? $catRepository->createOrFind($data['category']) : null;
|
||||
|
||||
// find budget:
|
||||
$budget = isset($data['budget_id']) ? $budRepository->find(intval($data['budget_id'])) : null;
|
||||
//
|
||||
// // find amount & description:
|
||||
$description = trim($data['description']);
|
||||
$amount = floatval($data['amount']);
|
||||
$date = new \Carbon\Carbon($data['date']);
|
||||
|
||||
// try to create a journal:
|
||||
$transactionJournal = $this->createSimpleJournal($fromAccount, $toAccount, $description, $amount, $date);
|
||||
if (!$transactionJournal->id || $transactionJournal->completed == 0) {
|
||||
return $transactionJournal;
|
||||
}
|
||||
|
||||
// attach:
|
||||
if (!is_null($budget)) {
|
||||
$transactionJournal->budgets()->save($budget);
|
||||
}
|
||||
if (!is_null($category)) {
|
||||
$transactionJournal->categories()->save($category);
|
||||
}
|
||||
|
||||
return $transactionJournal;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Account $account
|
||||
* @param Carbon $date
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getByAccountAndDate(\Account $account, Carbon $date)
|
||||
public function update(\TransactionJournal $journal, $data)
|
||||
{
|
||||
$accountID = $account->id;
|
||||
$query = \Auth::user()->transactionjournals()->with(
|
||||
[
|
||||
'transactions',
|
||||
'transactions.account',
|
||||
'transactioncurrency',
|
||||
'transactiontype'
|
||||
]
|
||||
)
|
||||
->distinct()
|
||||
->leftJoin('transactions', 'transactions.transaction_journal_id', '=', 'transaction_journals.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
|
||||
->where('transactions.account_id', $accountID)
|
||||
->where('transaction_journals.date', $date->format('Y-m-d'))
|
||||
->orderBy('transaction_journals.date', 'DESC')
|
||||
->orderBy('transaction_journals.id', 'DESC')
|
||||
->get(['transaction_journals.*']);
|
||||
/** @var \Firefly\Storage\Category\CategoryRepositoryInterface $catRepository */
|
||||
$catRepository = \App::make('Firefly\Storage\Category\CategoryRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Budget\BudgetRepositoryInterface $budgetRepository */
|
||||
$budRepository = \App::make('Firefly\Storage\Budget\BudgetRepositoryInterface');
|
||||
|
||||
/** @var \Firefly\Storage\Account\AccountRepositoryInterface $accountRepository */
|
||||
$accountRepository = \App::make('Firefly\Storage\Account\AccountRepositoryInterface');
|
||||
|
||||
|
||||
// update basics first:
|
||||
$journal->description = $data['description'];
|
||||
$journal->date = $data['date'];
|
||||
$amount = floatval($data['amount']);
|
||||
|
||||
// remove previous category, if any:
|
||||
if (!is_null($journal->categories()->first())) {
|
||||
$journal->categories()->detach($journal->categories()->first()->id);
|
||||
}
|
||||
// remove previous budget, if any:
|
||||
if (!is_null($journal->budgets()->first())) {
|
||||
$journal->budgets()->detach($journal->budgets()->first()->id);
|
||||
}
|
||||
|
||||
|
||||
$category = isset($data['category']) ? $catRepository->findByName($data['category']) : null;
|
||||
if (!is_null($category)) {
|
||||
$journal->categories()->attach($category);
|
||||
}
|
||||
// update the amounts:
|
||||
/** @var \Transaction $transaction */
|
||||
$transactions = $journal->transactions()->orderBy('amount', 'ASC')->get();
|
||||
$transactions[0]->amount = $amount;
|
||||
$transactions[1]->amount = $amount;
|
||||
|
||||
// switch on type to properly change things:
|
||||
switch ($journal->transactiontype->type) {
|
||||
case 'Withdrawal':
|
||||
// means transaction[0] is the users account.
|
||||
$account = $accountRepository->find($data['account_id']);
|
||||
$beneficiary = $accountRepository->findByName($data['beneficiary']);
|
||||
$transactions[0]->account()->associate($account);
|
||||
$transactions[1]->account()->associate($beneficiary);
|
||||
|
||||
// do budget:
|
||||
$budget = $budRepository->find($data['budget_id']);
|
||||
$journal->budgets()->attach($budget);
|
||||
|
||||
break;
|
||||
case 'Deposit':
|
||||
// means transaction[0] is the beneficiary.
|
||||
$account = $accountRepository->find($data['account_id']);
|
||||
$beneficiary = $accountRepository->findByName($data['beneficiary']);
|
||||
$journal->transactions[0]->account()->associate($beneficiary);
|
||||
$journal->transactions[1]->account()->associate($account);
|
||||
break;
|
||||
case 'Transfer':
|
||||
// means transaction[0] is account that sent the money (from).
|
||||
$fromAccount = $accountRepository->find($data['account_from_id']);
|
||||
$toAccount = $accountRepository->find($data['account_to_id']);
|
||||
$journal->transactions[0]->account()->associate($fromAccount);
|
||||
$journal->transactions[1]->account()->associate($toAccount);
|
||||
break;
|
||||
default:
|
||||
throw new \Firefly\Exception\FireflyException('Cannot edit this!');
|
||||
break;
|
||||
}
|
||||
|
||||
$transactions[0]->save();
|
||||
$transactions[1]->save();
|
||||
if ($journal->validate()) {
|
||||
$journal->save();
|
||||
}
|
||||
|
||||
return $journal;
|
||||
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
|
@ -27,6 +27,10 @@ interface TransactionJournalRepositoryInterface
|
||||
*/
|
||||
public function get();
|
||||
|
||||
public function store($what, $data);
|
||||
|
||||
public function update(\TransactionJournal $journal, $data);
|
||||
|
||||
/**
|
||||
* @param $journalId
|
||||
*
|
||||
|
@ -46,14 +46,14 @@ class EloquentLimitTrigger
|
||||
if ($limit->repeats == 0) {
|
||||
$limit->createRepetition($limit->startdate);
|
||||
}
|
||||
if($limit->repeats == 1) {
|
||||
if ($limit->repeats == 1) {
|
||||
$start = $limit->startdate;
|
||||
$end = new Carbon;
|
||||
|
||||
// repeat for period:
|
||||
$current = clone $start;
|
||||
\Log::debug('Create repeating limit for #'.$limit->id.' starting on ' . $current);
|
||||
while($current <= $end) {
|
||||
\Log::debug('Create repeating limit for #' . $limit->id . ' starting on ' . $current);
|
||||
while ($current <= $end) {
|
||||
\Log::debug('Current is now: ' . $current);
|
||||
$limit->createRepetition(clone $current);
|
||||
// switch period, add time:
|
||||
@ -128,10 +128,10 @@ class EloquentLimitTrigger
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
|
@ -1,6 +1,29 @@
|
||||
<?php
|
||||
use LaravelBook\Ardent\Ardent as Ardent;
|
||||
|
||||
/**
|
||||
* Piggybank
|
||||
*
|
||||
* @property integer $id
|
||||
* @property \Carbon\Carbon $created_at
|
||||
* @property \Carbon\Carbon $updated_at
|
||||
* @property integer $account_id
|
||||
* @property \Carbon\Carbon $targetdate
|
||||
* @property string $name
|
||||
* @property float $amount
|
||||
* @property float $target
|
||||
* @property integer $order
|
||||
* @property-read \Account $account
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereCreatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereUpdatedAt($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereAccountId($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereTargetdate($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereName($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereAmount($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereTarget($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\Piggybank whereOrder($value)
|
||||
*/
|
||||
class Piggybank extends Ardent
|
||||
{
|
||||
public static $rules
|
||||
@ -18,4 +41,9 @@ class Piggybank extends Ardent
|
||||
return $this->belongsTo('Account');
|
||||
}
|
||||
|
||||
public function getDates()
|
||||
{
|
||||
return array('created_at', 'updated_at', 'targetdate');
|
||||
}
|
||||
|
||||
}
|
@ -47,6 +47,14 @@ use LaravelBook\Ardent\Ardent;
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Budget[] $budgets
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\
|
||||
* 'Category[] $categories
|
||||
*/
|
||||
class TransactionJournal extends Ardent
|
||||
{
|
||||
|
@ -32,6 +32,7 @@ use LaravelBook\Ardent\Ardent;
|
||||
* @method static \Illuminate\Database\Query\Builder|\User whereRememberToken($value)
|
||||
* @method static \Illuminate\Database\Query\Builder|\User whereMigrated($value)
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\TransactionJournal[] $transactionjournals
|
||||
* @property-read \Illuminate\Database\Eloquent\Collection|\Piggybank[] $piggybanks
|
||||
*/
|
||||
class User extends Ardent implements UserInterface, RemindableInterface
|
||||
{
|
||||
@ -72,7 +73,8 @@ class User extends Ardent implements UserInterface, RemindableInterface
|
||||
return $this->hasMany('Account');
|
||||
}
|
||||
|
||||
public function piggybanks() {
|
||||
public function piggybanks()
|
||||
{
|
||||
return $this->hasMany('Piggybank');
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,16 @@ Route::bind('category', function($value, $route)
|
||||
return null;
|
||||
});
|
||||
|
||||
Route::bind('tj', function($value, $route)
|
||||
{
|
||||
if(Auth::check()) {
|
||||
return TransactionJournal::
|
||||
where('id', $value)->
|
||||
where('user_id',Auth::user()->id)->first();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
Route::bind('limit', function($value, $route)
|
||||
{
|
||||
if(Auth::check()) {
|
||||
@ -78,6 +88,8 @@ Route::group(['before' => 'auth'], function () {
|
||||
// piggy bank controller
|
||||
Route::get('/piggybanks',['uses' => 'PiggybankController@index','as' => 'piggybanks.index']);
|
||||
Route::get('/piggybanks/create', ['uses' => 'PiggybankController@create','as' => 'piggybanks.create']);
|
||||
Route::get('/piggybanks/edit/{piggybank}', ['uses' => 'PiggybankController@edit','as' => 'piggybanks.edit']);
|
||||
Route::get('/piggybanks/delete/{piggybank}', ['uses' => 'PiggybankController@delete','as' => 'piggybanks.delete']);
|
||||
Route::post('/piggybanks/updateAmount/{piggybank}',['uses' => 'PiggybankController@updateAmount','as' => 'piggybanks.updateAmount']);
|
||||
|
||||
|
||||
@ -119,10 +131,11 @@ Route::group(['before' => 'auth'], function () {
|
||||
|
||||
// transaction controller:
|
||||
Route::get('/transactions/create/{what}', ['uses' => 'TransactionController@create', 'as' => 'transactions.create'])->where(['what' => 'withdrawal|deposit|transfer']);
|
||||
Route::get('/transaction/show/{id}',['uses' => 'TransactionController@show','as' => 'transactions.show']);
|
||||
Route::get('/transaction/edit/{id}',['uses' => 'TransactionController@edit','as' => 'transactions.edit']);
|
||||
Route::get('/transaction/delete/{id}',['uses' => 'TransactionController@delete','as' => 'transactions.delete']);
|
||||
Route::get('/transaction/show/{tj}',['uses' => 'TransactionController@show','as' => 'transactions.show']);
|
||||
Route::get('/transaction/edit/{tj}',['uses' => 'TransactionController@edit','as' => 'transactions.edit']);
|
||||
Route::get('/transaction/delete/{tj}',['uses' => 'TransactionController@delete','as' => 'transactions.delete']);
|
||||
Route::get('/transactions/index',['uses' => 'TransactionController@index','as' => 'transactions.index']);
|
||||
|
||||
// migration controller
|
||||
Route::get('/migrate', ['uses' => 'MigrationController@index', 'as' => 'migrate']);
|
||||
|
||||
@ -149,7 +162,8 @@ Route::group(['before' => 'csrf|auth'], function () {
|
||||
|
||||
// piggy bank controller
|
||||
Route::post('/piggybanks/store',['uses' => 'PiggybankController@store','as' => 'piggybanks.store']);
|
||||
|
||||
Route::post('/piggybanks/update', ['uses' => 'PiggybankController@update','as' => 'piggybanks.update']);
|
||||
Route::post('/piggybanks/destroy/{piggybank}', ['uses' => 'PiggybankController@destroy','as' => 'piggybanks.destroy']);
|
||||
|
||||
|
||||
|
||||
@ -169,7 +183,8 @@ Route::group(['before' => 'csrf|auth'], function () {
|
||||
// transaction controller:
|
||||
Route::post('/transactions/store/{what}', ['uses' => 'TransactionController@store', 'as' => 'transactions.store'])
|
||||
->where(['what' => 'withdrawal|deposit|transfer']);
|
||||
Route::post('/transaction/update/{id}',['uses' => 'TransactionController@update','as' => 'transactions.update']);
|
||||
Route::post('/transaction/update/{tj}',['uses' => 'TransactionController@update','as' => 'transactions.update']);
|
||||
Route::post('/transaction/destroy/{tj}',['uses' => 'TransactionController@destroy','as' => 'transactions.destroy']);
|
||||
|
||||
}
|
||||
);
|
||||
|
@ -28,10 +28,10 @@
|
||||
<td>
|
||||
@foreach($journal->components as $component)
|
||||
@if($component->class == 'Budget')
|
||||
<a href="#budget-overview"><span class="glyphicon glyphicon-tasks" title="Budget: {{{$component->name}}}"></span></a>
|
||||
<a href="#budget-overview-in-month"><span class="glyphicon glyphicon-tasks" title="Budget: {{{$component->name}}}"></span></a>
|
||||
@endif
|
||||
@if($component->class == 'Category')
|
||||
<a href="#category-overview"><span class="glyphicon glyphicon-tag" title="Category: {{{$component->name}}}"></span></a>
|
||||
<a href="#category-overview-in-month"><span class="glyphicon glyphicon-tag" title="Category: {{{$component->name}}}"></span></a>
|
||||
@endif
|
||||
@endforeach
|
||||
</td>
|
||||
|
45
app/views/piggybanks/delete.blade.php
Normal file
45
app/views/piggybanks/delete.blade.php
Normal file
@ -0,0 +1,45 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h1>Firefly
|
||||
<small>Delete piggy bank</small>
|
||||
</h1>
|
||||
<p class="lead">Remember that deleting something is permanent.</p>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.destroy',$piggybank->id)])}}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<h4> </h4>
|
||||
<p class="text-info">
|
||||
This form allows you to delete the piggy bank "{{{$piggybank->name}}}".
|
||||
</p>
|
||||
<p class="text-info">
|
||||
Destroying an envelope does not remove any transactions or accounts.
|
||||
</p>
|
||||
<p class="text-danger">
|
||||
Are you sure?
|
||||
</p>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-8">
|
||||
<input type="submit" name="submit" value="Remove piggy bank" class="btn btn-danger" />
|
||||
@if(Input::get('from') == 'date')
|
||||
<a href="{{route('budgets.index')}}" class="btn-default btn">Cancel</a>
|
||||
@else
|
||||
<a href="{{route('budgets.index.budget')}}" class="btn-default btn">Cancel</a>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{{Form::close()}}
|
||||
|
||||
@stop
|
105
app/views/piggybanks/edit.blade.php
Normal file
105
app/views/piggybanks/edit.blade.php
Normal file
@ -0,0 +1,105 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h1>Firefly
|
||||
<small>Edit piggy bank "{{{$piggybank->name}}}"</small>
|
||||
</h1>
|
||||
<p class="lead">Use piggy banks to make saving money easier</p>
|
||||
<p class="text-info">
|
||||
Saving money is <em>hard</em>. Piggy banks allow you to group money
|
||||
from an account together. If you also set a target (and a target date) you
|
||||
can save towards your goals.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{Form::open(['class' => 'form-horizontal','url' => route('piggybanks.update')])}}
|
||||
{{Form::hidden('id',$piggybank->id)}}
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
<h4>Mandatory fields</h4>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="name" class="col-sm-4 control-label">Name</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="text" name="name" class="form-control" id="name" value="{{{Input::old('name') ?: $piggybank->name}}}" placeholder="Name">
|
||||
@if($errors->has('name'))
|
||||
<p class="text-danger">{{$errors->first('name')}}</p>
|
||||
@else
|
||||
<span class="help-block">For example: new bike, new camera</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('target', 'Target amount', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
<div class="input-group">
|
||||
<span class="input-group-addon">€</span>
|
||||
{{Form::input('number','target', Input::old('target') ?: $piggybank->target, ['step' => 'any', 'min' => '1', 'class' => 'form-control'])}}
|
||||
</div>
|
||||
|
||||
@if($errors->has('target'))
|
||||
<p class="text-danger">{{$errors->first('target')}}</p>
|
||||
@else
|
||||
<span class="help-block">How much money do you need to save?</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="account_id" class="col-sm-4 control-label">
|
||||
Saving account
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
{{Form::select('account_id',$accounts,Input::old('account_id') ?: $piggybank->account_id,['class' => 'form-control'])}}
|
||||
@if($errors->has('account_id'))
|
||||
<p class="text-danger">{{$errors->first('account_id')}}</p>
|
||||
@else
|
||||
<span class="help-block">Indicate on which account you've got your savings.</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
<h4>Optional fields</h4>
|
||||
|
||||
<div class="form-group">
|
||||
{{ Form::label('targetdate', 'Target date', ['class' => 'col-sm-4 control-label'])}}
|
||||
<div class="col-sm-8">
|
||||
{{ Form::input('date','targetdate', Input::old('targetdate') ?: $piggybank->targetdate, ['class'
|
||||
=> 'form-control']) }}
|
||||
@if($errors->has('targetdate'))
|
||||
<p class="text-danger">{{$errors->first('targetdate')}}</p>
|
||||
@else
|
||||
<span class="help-block">
|
||||
If you want to, set a target date. This will inform you how much money you should save to
|
||||
get to the target amount.
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-12 col-sm-6">
|
||||
|
||||
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-4 col-sm-8">
|
||||
<button type="submit" class="btn btn-default btn-success">Create the piggy bank</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{Form::close()}}
|
||||
|
||||
|
||||
@stop
|
@ -28,12 +28,14 @@
|
||||
<th>Account</th>
|
||||
<th>Current balance</th>
|
||||
<th>Left for (other) piggy banks</th>
|
||||
<th>Total target</th>
|
||||
</tr>
|
||||
@foreach($accounts as $account)
|
||||
<tr>
|
||||
<td>{{{$account->name}}}</td>
|
||||
<td id="account_{{$account->id}}_total" data-raw="{{$account->balance}}">{{mf($account->balance)}}</td>
|
||||
<td id="account_{{$account->id}}_left" data-raw="{{$account->left}}">{{mf($account->left)}}</td>
|
||||
<td>{{mf($account->total)}}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
@ -46,6 +48,11 @@
|
||||
|
||||
@foreach($piggybanks as $piggybank)
|
||||
<h4>{{{$piggybank->name}}} <small>{{mf($piggybank->target)}}</small></h4>
|
||||
@if(!is_null($piggybank->targetdate))
|
||||
<p>
|
||||
Target date: {{$piggybank->targetdate->format('jS F Y')}}
|
||||
</p>
|
||||
@endif
|
||||
<table class="table table-bordered">
|
||||
<tr>
|
||||
<td style="width:15%;">
|
||||
@ -56,6 +63,12 @@
|
||||
</td>
|
||||
<td><input type="range" data-account="{{$piggybank->account_id}}" name="piggy_{{$piggybank->id}}" min="0" max="{{$piggybank->target}}" step="any" value="{{$piggybank->amount}}" /></td>
|
||||
<td style="width: 10%;"><span id="piggy_{{$piggybank->id}}_pct">{{$piggybank->pct}}</span></td>
|
||||
<td style="width:8%;">
|
||||
<div class="btn-group btn-group-xs">
|
||||
<a href="{{route('piggybanks.edit',$piggybank->id)}}" class="btn btn-default btn-xs"><span class="glyphicon glyphicon-pencil"></span></a>
|
||||
<a href="{{route('piggybanks.delete',$piggybank->id)}}" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
@endforeach
|
||||
|
@ -82,6 +82,9 @@
|
||||
<label for="account_from_id" class="col-sm-4 control-label">Account from</label>
|
||||
<div class="col-sm-8">
|
||||
{{Form::select('account_from_id',$accounts,Input::old('account_from_id'),['class' => 'form-control'])}}
|
||||
@if($errors->has('account_from_id'))
|
||||
<p class="text-danger">{{$errors->first('account_from_id')}}</p>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -89,6 +92,9 @@
|
||||
<label for="account_to_id" class="col-sm-4 control-label">Account to</label>
|
||||
<div class="col-sm-8">
|
||||
{{Form::select('account_to_id',$accounts,Input::old('account_to_id'),['class' => 'form-control'])}}
|
||||
@if($errors->has('account_to_id'))
|
||||
<p class="text-danger">{{$errors->first('account_to_id')}}</p>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@ -108,6 +114,9 @@
|
||||
</label>
|
||||
<div class="col-sm-8">
|
||||
<input type="number" name="amount" min="0.01" value="{{Input::old('amount')}}" step="any" class="form-control" />
|
||||
@if($errors->has('amount'))
|
||||
<p class="text-danger">{{$errors->first('amount')}}</p>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
38
app/views/transactions/delete.blade.php
Normal file
38
app/views/transactions/delete.blade.php
Normal file
@ -0,0 +1,38 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-lg-12 col-md-12 col-sm-12">
|
||||
<h1>Firefly
|
||||
<small>Delete transaction</small>
|
||||
</h1>
|
||||
<p class="lead">Remember that deleting something is permanent.</p>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
{{Form::open(['class' => 'form-horizontal','url' => route('transactions.destroy',$journal->id)])}}
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-6">
|
||||
<p class="text-info">
|
||||
This form allows you to delete the transaction labelled "{{{$journal->description}}}".
|
||||
</p>
|
||||
<p class="text-danger">
|
||||
Are you sure?
|
||||
</p>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="col-sm-8">
|
||||
<input type="submit" name="submit" value="Delete transaction" class="btn btn-danger" />
|
||||
<a href="{{route('transactions.index')}}" class="btn-default btn">Cancel</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{{Form::close()}}
|
||||
|
||||
@stop
|
@ -1,6 +1,8 @@
|
||||
@extends('layouts.default')
|
||||
@section('content')
|
||||
Bla bla TODO
|
||||
|
||||
@include('paginated.transactions')
|
||||
|
||||
|
||||
@stop
|
||||
|
||||
|
@ -1,7 +1,8 @@
|
||||
#!/bin/bash
|
||||
composer self-update
|
||||
composer update
|
||||
php artisan clear-compiled --env=local
|
||||
php artisan ide-helper:generate --env=local
|
||||
php artisan ide-helper:models --env=local --write
|
||||
php artisan optimize --env=local
|
||||
php artisan dump-autoload --env=local
|
||||
php artisan dump-autoload --env=m n
|
Loading…
Reference in New Issue
Block a user