mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
All code for issue #38.
This commit is contained in:
205
app/controllers/BillController.php
Normal file
205
app/controllers/BillController.php
Normal file
@@ -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']);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -334,11 +334,11 @@ class GoogleChartController extends BaseController
|
||||
}
|
||||
|
||||
/**
|
||||
* @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');
|
||||
@@ -347,7 +347,7 @@ class GoogleChartController extends BaseController
|
||||
$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 {
|
||||
@@ -355,15 +355,15 @@ class GoogleChartController extends BaseController
|
||||
}
|
||||
$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();
|
||||
@@ -378,14 +378,14 @@ class GoogleChartController extends BaseController
|
||||
* @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) {
|
||||
|
||||
@@ -1,205 +0,0 @@
|
||||
<?php
|
||||
use FireflyIII\Database\RecurringTransaction\RecurringTransaction as Repository;
|
||||
use FireflyIII\Exception\FireflyException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @SuppressWarnings("CamelCase") // I'm fine with this.
|
||||
* @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
|
||||
* @SuppressWarnings("NPathComplexity")
|
||||
* Class RecurringController
|
||||
*
|
||||
*/
|
||||
class RecurringController extends BaseController
|
||||
{
|
||||
|
||||
/** @var Repository */
|
||||
protected $_repository;
|
||||
|
||||
/**
|
||||
* @param Repository $repository
|
||||
*/
|
||||
public function __construct(Repository $repository)
|
||||
{
|
||||
$this->_repository = $repository;
|
||||
|
||||
View::share('title', 'Recurring transactions');
|
||||
View::share('mainTitleIcon', 'fa-rotate-right');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
|
||||
return View::make('recurring.create')->with('periods', $periods)->with('subTitle', 'Create new');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurringTransaction $recurringTransaction
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function delete(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
return View::make('recurring.delete')->with('recurringTransaction', $recurringTransaction)->with(
|
||||
'subTitle', 'Delete "' . $recurringTransaction->name . '"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurringTransaction $recurringTransaction
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function destroy(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
$this->_repository->destroy($recurringTransaction);
|
||||
Session::flash('success', 'The recurring transaction was deleted.');
|
||||
|
||||
return Redirect::route('recurring.index');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurringTransaction $recurringTransaction
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function edit(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
$periods = \Config::get('firefly.periods_to_text');
|
||||
|
||||
return View::make('recurring.edit')->with('periods', $periods)->with('recurringTransaction', $recurringTransaction)->with(
|
||||
'subTitle', 'Edit "' . $recurringTransaction->name . '"'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$recurring = $this->_repository->get();
|
||||
|
||||
return View::make('recurring.index', compact('recurring'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurringTransaction $recurringTransaction
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function rescan(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
if (intval($recurringTransaction->active) == 0) {
|
||||
Session::flash('warning', 'Inactive recurring transactions cannot be scanned.');
|
||||
|
||||
return Redirect::intended('/');
|
||||
}
|
||||
|
||||
$this->_repository->scanEverything($recurringTransaction);
|
||||
|
||||
Session::flash('success', 'Rescanned everything.');
|
||||
|
||||
return Redirect::intended('/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurringTransaction $recurringTransaction
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function show(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
$journals = $recurringTransaction->transactionjournals()->withRelevantData()->orderBy('date', 'DESC')->get();
|
||||
$hideRecurring = true;
|
||||
|
||||
|
||||
return View::make('recurring.show', compact('journals', 'hideRecurring'))->with('recurring', $recurringTransaction)->with(
|
||||
'subTitle', $recurringTransaction->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 recurring transaction: ' . $messages['errors']->first());
|
||||
}
|
||||
|
||||
// return to create screen:
|
||||
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
|
||||
return Redirect::route('recurring.create')->withInput();
|
||||
}
|
||||
|
||||
// store:
|
||||
$this->_repository->store($data);
|
||||
Session::flash('success', 'Recurring transaction "' . e($data['name']) . '" stored.');
|
||||
if ($data['post_submit_action'] == 'store') {
|
||||
return Redirect::route('recurring.index');
|
||||
}
|
||||
|
||||
return Redirect::route('recurring.create')->withInput();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RecurringTransaction $recurringTransaction
|
||||
*
|
||||
* @return $this
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function update(RecurringTransaction $recurringTransaction)
|
||||
{
|
||||
$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 recurring transaction: ' . $messages['errors']->first());
|
||||
}
|
||||
|
||||
// return to update screen:
|
||||
if ($data['post_submit_action'] == 'validate_only' || $messages['errors']->count() > 0) {
|
||||
return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput();
|
||||
}
|
||||
|
||||
// update
|
||||
$this->_repository->update($recurringTransaction, $data);
|
||||
Session::flash('success', 'Recurring transaction "' . e($data['name']) . '" updated.');
|
||||
|
||||
// go back to list
|
||||
if ($data['post_submit_action'] == 'update') {
|
||||
return Redirect::route('recurring.index');
|
||||
}
|
||||
|
||||
// go back to update screen.
|
||||
return Redirect::route('recurring.edit', $recurringTransaction->id)->withInput(['post_submit_action' => 'return_to_edit']);
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user