Skip to content

Commit

Permalink
All code for issue #38.
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Dec 29, 2014
1 parent 5a4c5a3 commit a021c26
Show file tree
Hide file tree
Showing 32 changed files with 573 additions and 498 deletions.
30 changes: 15 additions & 15 deletions app/breadcrumbs.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,37 +195,37 @@ function (Generator $breadcrumbs) {
}
);

// recurring transactions
// bills
Breadcrumbs::register(
'recurring.index', function (Generator $breadcrumbs) {
'bills.index', function (Generator $breadcrumbs) {
$breadcrumbs->parent('home');
$breadcrumbs->push('Recurring transactions', route('recurring.index'));
$breadcrumbs->push('Bills', route('bills.index'));
}
);
Breadcrumbs::register(
'recurring.create', function (Generator $breadcrumbs) {
$breadcrumbs->parent('recurring.index');
$breadcrumbs->push('Create new recurring transaction', route('recurring.create'));
'bills.create', function (Generator $breadcrumbs) {
$breadcrumbs->parent('bills.index');
$breadcrumbs->push('Create new bill', route('bills.create'));
}
);

Breadcrumbs::register(
'recurring.edit', function (Generator $breadcrumbs, RecurringTransaction $recurring) {
$breadcrumbs->parent('recurring.show', $recurring);
$breadcrumbs->push('Edit ' . $recurring->name, route('recurring.edit', $recurring->id));
'bills.edit', function (Generator $breadcrumbs, Bill $bill) {
$breadcrumbs->parent('bills.show', $bill);
$breadcrumbs->push('Edit ' . $bill->name, route('bills.edit', $bill->id));
}
);
Breadcrumbs::register(
'recurring.delete', function (Generator $breadcrumbs, RecurringTransaction $recurring) {
$breadcrumbs->parent('recurring.show', $recurring);
$breadcrumbs->push('Delete ' . $recurring->name, route('recurring.delete', $recurring->id));
'bills.delete', function (Generator $breadcrumbs, Bill $bill) {
$breadcrumbs->parent('bills.show', $bill);
$breadcrumbs->push('Delete ' . $bill->name, route('bills.delete', $bill->id));
}
);

Breadcrumbs::register(
'recurring.show', function (Generator $breadcrumbs, RecurringTransaction $recurring) {
$breadcrumbs->parent('recurring.index');
$breadcrumbs->push($recurring->name, route('recurring.show', $recurring->id));
'bills.show', function (Generator $breadcrumbs, Bill $bill) {
$breadcrumbs->parent('bills.index');
$breadcrumbs->push($bill->name, route('bills.show', $bill->id));

}
);
Expand Down
205 changes: 205 additions & 0 deletions app/controllers/BillController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<?php
use FireflyIII\Database\Bill\Bill as Repository;
use FireflyIII\Exception\FireflyException;

/**
*
* @SuppressWarnings("CamelCase") // I'm fine with this.
* @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
* @SuppressWarnings("NPathComplexity")
* Class BillController
*
*/
class BillController extends BaseController
{

/** @var Repository */
protected $_repository;

/**
* @param Repository $repository
*/
public function __construct(Repository $repository)
{
$this->_repository = $repository;

View::share('title', 'Bills');
View::share('mainTitleIcon', 'fa-rotate-right');
}

/**
* @return $this
*/
public function create()
{
$periods = \Config::get('firefly.periods_to_text');

return View::make('bills.create')->with('periods', $periods)->with('subTitle', 'Create new');
}

/**
* @param Bill $bill
*
* @return $this
*/
public function delete(Bill $bill)
{
return View::make('bills.delete')->with('bill', $bill)->with(
'subTitle', 'Delete "' . $bill->name . '"'
);
}

/**
* @param Bill $bill
*
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Bill $bill)
{
$this->_repository->destroy($bill);
Session::flash('success', 'The bill was deleted.');

return Redirect::route('bills.index');

}

/**
* @param Bill $bill
*
* @return $this
*/
public function edit(Bill $bill)
{
$periods = \Config::get('firefly.periods_to_text');

return View::make('bills.edit')->with('periods', $periods)->with('bill', $bill)->with(
'subTitle', 'Edit "' . $bill->name . '"'
);
}

/**
* @return $this
*/
public function index()
{
$bills = $this->_repository->get();

return View::make('bills.index', compact('bills'));
}

/**
* @param Bill $bill
*
* @return mixed
*/
public function rescan(Bill $bill)
{
if (intval($bill->active) == 0) {
Session::flash('warning', 'Inactive bills cannot be scanned.');

return Redirect::intended('/');
}

$this->_repository->scanEverything($bill);

Session::flash('success', 'Rescanned everything.');

return Redirect::intended('/');
}

/**
* @param Bill $bill
*
* @return mixed
*/
public function show(Bill $bill)
{
$journals = $bill->transactionjournals()->withRelevantData()->orderBy('date', 'DESC')->get();
$hideBill = true;


return View::make('bills.show', compact('journals', 'hideBills'))->with('bill', $bill)->with(
'subTitle', $bill->name
);
}

/**
* @return $this
* @throws FireflyException
*/
public function store()
{
$data = Input::all();
$data['user_id'] = Auth::user()->id;


// always validate:
$messages = $this->_repository->validate($data);

// flash messages:
Session::flash('warnings', $messages['warnings']);
Session::flash('successes', $messages['successes']);
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not store bill: ' . $messages['errors']->first());
}

// return to create screen:
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
return Redirect::route('bills.create')->withInput();
}

// store:
$this->_repository->store($data);
Session::flash('success', 'Bill "' . e($data['name']) . '" stored.');
if ($data['post_submit_action'] == 'store') {
return Redirect::route('bills.index');
}

return Redirect::route('bills.create')->withInput();

}

/**
* @param Bill $bill
*
* @return $this
* @throws FireflyException
*/
public function update(Bill $bill)
{
$data = Input::except('_token');
$data['active'] = isset($data['active']) ? 1 : 0;
$data['automatch'] = isset($data['automatch']) ? 1 : 0;
$data['user_id'] = Auth::user()->id;

// always validate:
$messages = $this->_repository->validate($data);

// flash messages:
Session::flash('warnings', $messages['warnings']);
Session::flash('successes', $messages['successes']);
Session::flash('errors', $messages['errors']);
if ($messages['errors']->count() > 0) {
Session::flash('error', 'Could not update bill: ' . $messages['errors']->first());
}

// return to update screen:
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
return Redirect::route('bills.edit', $bill->id)->withInput();
}

// update
$this->_repository->update($bill, $data);
Session::flash('success', 'Bill "' . e($data['name']) . '" updated.');

// go back to list
if ($data['post_submit_action'] == 'update') {
return Redirect::route('bills.index');
}

// go back to update screen.
return Redirect::route('bills.edit', $bill->id)->withInput(['post_submit_action' => 'return_to_edit']);

}
}
16 changes: 8 additions & 8 deletions app/controllers/GoogleChartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ public function piggyBankHistory(\PiggyBank $piggyBank)
}

/**
* @param RecurringTransaction $recurring
* @param Bill $bill
*
* @return \Illuminate\Http\JsonResponse
*/
public function recurringOverview(RecurringTransaction $recurring)
public function billOverview(Bill $bill)
{

$this->_chart->addColumn('Date', 'date');
Expand All @@ -347,23 +347,23 @@ public function recurringOverview(RecurringTransaction $recurring)
$this->_chart->addColumn('Current entry', 'number');

// get first transaction or today for start:
$first = $recurring->transactionjournals()->orderBy('date', 'ASC')->first();
$first = $bill->transactionjournals()->orderBy('date', 'ASC')->first();
if ($first) {
$start = $first->date;
} else {
$start = new Carbon;
}
$end = new Carbon;
while ($start <= $end) {
$result = $recurring->transactionjournals()->before($end)->after($start)->first();
$result = $bill->transactionjournals()->before($end)->after($start)->first();
if ($result) {
$amount = $result->getAmount();
} else {
$amount = 0;
}
unset($result);
$this->_chart->addRow(clone $start, $recurring->amount_max, $recurring->amount_min, $amount);
$start = DateKit::addPeriod($start, $recurring->repeat_freq, 0);
$this->_chart->addRow(clone $start, $bill->amount_max, $bill->amount_min, $amount);
$start = DateKit::addPeriod($start, $bill->repeat_freq, 0);
}

$this->_chart->generate();
Expand All @@ -378,14 +378,14 @@ public function recurringOverview(RecurringTransaction $recurring)
* @return \Illuminate\Http\JsonResponse
* @throws \FireflyIII\Exception\FireflyException
*/
public function recurringTransactionsOverview()
public function billsOverview()
{
$paid = ['items' => [], 'amount' => 0];
$unpaid = ['items' => [], 'amount' => 0];
$this->_chart->addColumn('Name', 'string');
$this->_chart->addColumn('Amount', 'number');

$set = $this->_repository->getRecurringSummary($this->_start, $this->_end);
$set = $this->_repository->getBillsSummary($this->_start, $this->_end);

foreach ($set as $entry) {
if (intval($entry->journalId) == 0) {
Expand Down

0 comments on commit a021c26

Please sign in to comment.