diff --git a/app/breadcrumbs.php b/app/breadcrumbs.php
index 1753d137c5..68d1e10a5f 100644
--- a/app/breadcrumbs.php
+++ b/app/breadcrumbs.php
@@ -195,37 +195,37 @@ Breadcrumbs::register(
}
);
-// 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));
}
);
diff --git a/app/controllers/BillController.php b/app/controllers/BillController.php
new file mode 100644
index 0000000000..3ea9810eb9
--- /dev/null
+++ b/app/controllers/BillController.php
@@ -0,0 +1,205 @@
+_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']);
+
+ }
+}
\ No newline at end of file
diff --git a/app/controllers/GoogleChartController.php b/app/controllers/GoogleChartController.php
index fcb2c8884b..58c3a9dfb7 100644
--- a/app/controllers/GoogleChartController.php
+++ b/app/controllers/GoogleChartController.php
@@ -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) {
diff --git a/app/controllers/RecurringController.php b/app/controllers/RecurringController.php
deleted file mode 100644
index 4b7f094dd7..0000000000
--- a/app/controllers/RecurringController.php
+++ /dev/null
@@ -1,205 +0,0 @@
-_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']);
-
- }
-}
\ No newline at end of file
diff --git a/app/database/migrations/2014_12_24_191544_changes_for_v322.php b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
index 5c377f7ec3..54aa328839 100644
--- a/app/database/migrations/2014_12_24_191544_changes_for_v322.php
+++ b/app/database/migrations/2014_12_24_191544_changes_for_v322.php
@@ -1,7 +1,6 @@
dropSoftDeletes();
}
);
+
+ // drop keys from bills (foreign bills_uid_for and unique uid_name_unique)
+ Schema::table(
+ 'bills', function (Blueprint $table) {
+ $table->dropForeign('bills_uid_for');
+ $table->dropUnique('uid_name_unique');
+ }
+ );
+ // drop foreign key from transaction_journals (bill_id_foreign)
+ Schema::table(
+ 'transaction_journals', function (Blueprint $table) {
+ $table->dropForeign('bill_id_foreign');
+
+ }
+ );
+
+ // drop foreign key from budget_limits:
+ Schema::table(
+ 'budget_limits', function (Blueprint $table) {
+ $table->dropForeign('bid_foreign');
+ $table->dropUnique('unique_bl_combi');
+ }
+ );
+
+ // rename bills to recurring_transactions
+ Schema::rename('bills', 'recurring_transactions');
+ // recreate foreign key recurring_transactions_user_id_foreign in recurring_transactions
+ // recreate unique recurring_transactions_user_id_name_unique in recurring_transactions
+ Schema::table(
+ 'recurring_transactions', function (Blueprint $table) {
+ $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
+ $table->unique(['user_id', 'name']);
+ }
+ );
+
+ // rename bill_id to recurring_transaction_id
+ // recreate foreign transaction_journals_recurring_transaction_id_foreign in transaction_journals
+ Schema::table(
+ 'transaction_journals', function (Blueprint $table) {
+ $table->renameColumn('bill_id', 'recurring_transaction_id');
+ $table->foreign('recurring_transaction_id')->references('id')->on('recurring_transactions')->onDelete('set null');
+ }
+ );
+
+
}
@@ -55,13 +99,13 @@ class ChangesForV322 extends Migration
Schema::table(
'budget_limits', function (Blueprint $table) {
-// try {
- //$table->dropUnique('limits_component_id_startdate_repeat_freq_unique');
-// } catch (QueryException $e) {
- //$table->dropUnique('unique_ci_combi');
-// } catch (PDOException $e) {
-// $table->dropUnique('unique_ci_combi');
-// }
+ // try {
+ //$table->dropUnique('limits_component_id_startdate_repeat_freq_unique');
+ // } catch (QueryException $e) {
+ //$table->dropUnique('unique_ci_combi');
+ // } catch (PDOException $e) {
+ // $table->dropUnique('unique_ci_combi');
+ // }
}
);
@@ -91,6 +135,48 @@ class ChangesForV322 extends Migration
$table->softDeletes();
}
);
+
+ // rename everything related to recurring transactions, aka bills:
+ Schema::table(
+ 'transaction_journals', function (Blueprint $table) {
+
+
+ // drop relation
+ $table->dropForeign('transaction_journals_recurring_transaction_id_foreign');
+ // rename column
+ $table->renameColumn('recurring_transaction_id', 'bill_id');
+
+ }
+ );
+
+ Schema::table(
+ 'recurring_transactions', function (Blueprint $table) {
+ $table->dropForeign('recurring_transactions_user_id_foreign');
+ $table->dropUnique('recurring_transactions_user_id_name_unique');
+ }
+ );
+ // rename table:
+ Schema::rename('recurring_transactions', 'bills');
+
+ // recreate foreign relation:
+ Schema::table(
+ 'transaction_journals', function (Blueprint $table) {
+ $table->foreign('bill_id', 'bill_id_foreign')->references('id')->on('bills')->onDelete('set null');
+ }
+ );
+
+ // recreate more foreign relations.
+ Schema::table(
+ 'bills', function (Blueprint $table) {
+ // connect user id to users
+ $table->foreign('user_id', 'bills_uid_for')->references('id')->on('users')->onDelete('cascade');
+
+ // for a user, the name must be unique
+ $table->unique(['user_id', 'name'], 'uid_name_unique');
+ }
+ );
+
+
}
}
diff --git a/app/database/seeds/TestContentSeeder.php b/app/database/seeds/TestContentSeeder.php
index 93e5fee98e..1d43dc075d 100644
--- a/app/database/seeds/TestContentSeeder.php
+++ b/app/database/seeds/TestContentSeeder.php
@@ -36,19 +36,19 @@ class TestContentSeeder extends Seeder
$deleteBudget = Budget::create(['user_id' => $user->id, 'name' => 'Delete me']);
// some limits:
- $startDate = Carbon::now()->startOfMonth();
- $endDate = Carbon::now()->endOfMonth();
+ $startDate = Carbon::now()->startOfMonth();
+ $endDate = Carbon::now()->endOfMonth();
$secondStart = Carbon::now()->subMonth()->startOfMonth();
- $secondEnd = Carbon::now()->subMonth()->endOfMonth();
- $limitOne = BudgetLimit::create(
+ $secondEnd = Carbon::now()->subMonth()->endOfMonth();
+ $limitOne = BudgetLimit::create(
['startdate' => $startDate->format('Y-m-d'), 'amount' => 201, 'repeats' => 0, 'repeat_freq' => 'monthly',
'budget_id' => $groceriesBudget->id]
);
- $limitTwo = BudgetLimit::create(
+ $limitTwo = BudgetLimit::create(
['startdate' => $secondStart->format('Y-m-d'), 'amount' => 202, 'repeats' => 0, 'repeat_freq' => 'monthly',
'budget_id' => $billsBudget->id]
);
- $limitThree = BudgetLimit::create(
+ $limitThree = BudgetLimit::create(
['startdate' => '2014-01-01', 'amount' => 203, 'repeats' => 0, 'repeat_freq' => 'monthly',
'budget_id' => $deleteBudget->id]
);
@@ -58,7 +58,8 @@ class TestContentSeeder extends Seeder
['budget_limit_id' => $limitOne->id, 'startdate' => $startDate->format('Y-m-d'), 'enddate' => $endDate->format('Y-m-d'), 'amount' => 201]
);
$repTwo = LimitRepetition::create(
- ['budget_limit_id' => $limitTwo->id, 'startdate' => $secondStart->format('Y-m-d'), 'enddate' => $secondEnd->format('Y-m-d'), 'amount' => 202]
+ ['budget_limit_id' => $limitTwo->id, 'startdate' => $secondStart->format('Y-m-d'), 'enddate' => $secondEnd->format('Y-m-d'),
+ 'amount' => 202]
);
$repThree = LimitRepetition::create(
['budget_limit_id' => $limitThree->id, 'startdate' => '2014-01-01', 'enddate' => '2014-01-31', 'amount' => 203]
@@ -79,7 +80,7 @@ class TestContentSeeder extends Seeder
Component::create(['user_id' => $user->id, 'name' => 'Some Component 7', 'class' => 'Category']);
// piggy bank
- $piggy = PiggyBank::create(
+ $piggy = PiggyBank::create(
[
'account_id' => $savings->id,
'name' => 'New camera',
@@ -99,7 +100,7 @@ class TestContentSeeder extends Seeder
PiggyBankEvent::create(['piggy_bank_id' => 1, 'date' => $startDate->format('Y-m-d'), 'amount' => 100]);
PiggyBankRepetition::create(
[
- 'piggy_bank_id' => $piggy->id,
+ 'piggy_bank_id' => $piggy->id,
'startdate' => Carbon::now()->format('Y-m-d'),
'targetdate' => null,
'currentamount' => 0
@@ -107,7 +108,7 @@ class TestContentSeeder extends Seeder
);
// piggy bank
- $piggyTargeted = PiggyBank::create(
+ $piggyTargeted = PiggyBank::create(
[
'account_id' => $savings->id,
'name' => 'New clothes',
@@ -128,15 +129,15 @@ class TestContentSeeder extends Seeder
PiggyBankEvent::create(['piggy_bank_id' => $piggyTargeted->id, 'date' => $startDate->format('Y-m-d'), 'amount' => 100]);
PiggyBankRepetition::create(
[
- 'piggy_bank_id' => $piggyTargeted->id,
+ 'piggy_bank_id' => $piggyTargeted->id,
'startdate' => Carbon::now()->format('Y-m-d'),
'targetdate' => Carbon::now()->addMonths(4)->format('Y-m-d'),
'currentamount' => 0
]
);
- // recurring transaction
- $recurring = \RecurringTransaction::create(
+ // bill
+ $firstBill = \Bill::create(
[
'user_id' => $user->id,
'name' => 'Huur',
@@ -151,8 +152,8 @@ class TestContentSeeder extends Seeder
]
);
- // recurring transaction
- $secondRecurring = \RecurringTransaction::create(
+ // bill
+ $secondBill = \Bill::create(
[
'user_id' => $user->id,
'name' => 'Gas licht',
@@ -198,7 +199,7 @@ class TestContentSeeder extends Seeder
while ($start <= $end) {
$this->createTransaction(
$checking, $portaal, 500, $withdrawal, 'Huur Portaal for ' . $start->format('F Y'), $start->format('Y-m-') . '01', $billsBudget, $house,
- $recurring
+ $firstBill
);
$this->createTransaction(
$checking, $vitens, 12, $withdrawal, 'Water for ' . $start->format('F Y'), $start->format('Y-m-') . '02', $billsBudget, $house
@@ -261,28 +262,27 @@ class TestContentSeeder extends Seeder
*
* @param Budget $budget
* @param Category $category
- * @param RecurringTransaction $recurring
+ * @param Bill $bill
*
* @return TransactionJournal
*/
public function createTransaction(
- Account $from, Account $to, $amount, TransactionType $type, $description, $date, Budget $budget = null, Category $category = null,
- $recurring = null
+ Account $from, Account $to, $amount, TransactionType $type, $description, $date, Budget $budget = null, Category $category = null, Bill $bill = null
) {
- $user = User::whereEmail('thegrumpydictator@gmail.com')->first();
- $euro = TransactionCurrency::whereCode('EUR')->first();
- $recurringID = is_null($recurring) ? null : $recurring->id;
+ $user = User::whereEmail('thegrumpydictator@gmail.com')->first();
+ $euro = TransactionCurrency::whereCode('EUR')->first();
+ $billID = is_null($bill) ? null : $bill->id;
/** @var TransactionJournal $journal */
$journal = TransactionJournal::create(
[
- 'user_id' => $user->id,
- 'transaction_type_id' => $type->id,
- 'transaction_currency_id' => $euro->id,
- 'recurring_transaction_id' => $recurringID,
- 'description' => $description,
- 'completed' => 1,
- 'date' => $date
+ 'user_id' => $user->id,
+ 'transaction_type_id' => $type->id,
+ 'transaction_currency_id' => $euro->id,
+ 'bill_id' => $billID,
+ 'description' => $description,
+ 'completed' => 1,
+ 'date' => $date
]
);
diff --git a/app/lib/FireflyIII/Chart/Chart.php b/app/lib/FireflyIII/Chart/Chart.php
index 302a014c5b..c390105efb 100644
--- a/app/lib/FireflyIII/Chart/Chart.php
+++ b/app/lib/FireflyIII/Chart/Chart.php
@@ -48,12 +48,12 @@ class Chart implements ChartInterface
*
* @return Collection
*/
- public function getRecurringSummary(Carbon $start, Carbon $end)
+ public function getBillsSummary(Carbon $start, Carbon $end)
{
- return \RecurringTransaction::
+ return \Bill::
leftJoin(
'transaction_journals', function (JoinClause $join) use ($start, $end) {
- $join->on('recurring_transactions.id', '=', 'transaction_journals.recurring_transaction_id')
+ $join->on('bills.id', '=', 'transaction_journals.bill_id')
->where('transaction_journals.date', '>=', $start->format('Y-m-d'))
->where('transaction_journals.date', '<=', $end->format('Y-m-d'));
}
@@ -64,11 +64,11 @@ class Chart implements ChartInterface
}
)
->where('active', 1)
- ->groupBy('recurring_transactions.id')
+ ->groupBy('bills.id')
->get(
- ['recurring_transactions.id', 'recurring_transactions.name', 'transaction_journals.description',
+ ['bills.id', 'bills.name', 'transaction_journals.description',
'transaction_journals.id as journalId',
- \DB::Raw('SUM(`recurring_transactions`.`amount_min` + `recurring_transactions`.`amount_max`) / 2 as `averageAmount`'),
+ \DB::Raw('SUM(`bills`.`amount_min` + `bills`.`amount_max`) / 2 as `averageAmount`'),
'transactions.amount AS actualAmount']
);
}
diff --git a/app/lib/FireflyIII/Chart/ChartInterface.php b/app/lib/FireflyIII/Chart/ChartInterface.php
index 7b29e3c9e9..5617cf8337 100644
--- a/app/lib/FireflyIII/Chart/ChartInterface.php
+++ b/app/lib/FireflyIII/Chart/ChartInterface.php
@@ -26,6 +26,6 @@ interface ChartInterface
*
* @return Collection
*/
- public function getRecurringSummary(Carbon $start, Carbon $end);
+ public function getBillsSummary(Carbon $start, Carbon $end);
}
\ No newline at end of file
diff --git a/app/lib/FireflyIII/Database/RecurringTransaction/RecurringTransaction.php b/app/lib/FireflyIII/Database/Bill/Bill.php
similarity index 78%
rename from app/lib/FireflyIII/Database/RecurringTransaction/RecurringTransaction.php
rename to app/lib/FireflyIII/Database/Bill/Bill.php
index 1a4b424043..bee5256214 100644
--- a/app/lib/FireflyIII/Database/RecurringTransaction/RecurringTransaction.php
+++ b/app/lib/FireflyIII/Database/Bill/Bill.php
@@ -1,6 +1,6 @@
user()->associate($this->getUser());
- $recurring->name = $data['name'];
- $recurring->match = $data['match'];
- $recurring->amount_max = floatval($data['amount_max']);
- $recurring->amount_min = floatval($data['amount_min']);
+ $bill = new \Bill;
+ $bill->user()->associate($this->getUser());
+ $bill->name = $data['name'];
+ $bill->match = $data['match'];
+ $bill->amount_max = floatval($data['amount_max']);
+ $bill->amount_min = floatval($data['amount_min']);
$date = new Carbon($data['date']);
- $recurring->active = intval($data['active']);
- $recurring->automatch = intval($data['automatch']);
- $recurring->repeat_freq = $data['repeat_freq'];
+ $bill->active = intval($data['active']);
+ $bill->automatch = intval($data['automatch']);
+ $bill->repeat_freq = $data['repeat_freq'];
/*
* Jump to the start of the period.
*/
$date = \DateKit::startOfPeriod($date, $data['repeat_freq']);
- $recurring->date = $date;
- $recurring->skip = intval($data['skip']);
+ $bill->date = $date;
+ $bill->skip = intval($data['skip']);
- $recurring->save();
+ $bill->save();
- return $recurring;
+ return $bill;
}
/**
@@ -118,7 +118,7 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
$errors->add('amount_max', 'Maximum amount can not be less than minimum amount.');
$errors->add('amount_min', 'Minimum amount can not be more than maximum amount.');
}
- $object = new \RecurringTransaction($model);
+ $object = new \Bill($model);
$object->isValid();
$errors->merge($object->getErrors());
@@ -167,7 +167,7 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
*/
public function get()
{
- return $this->getUser()->recurringtransactions()->get();
+ return $this->getUser()->bills()->get();
}
/**
@@ -189,35 +189,35 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
*/
public function getActive()
{
- return $this->getUser()->recurringtransactions()->where('active', 1)->get();
+ return $this->getUser()->bills()->where('active', 1)->get();
}
/**
- * @param \RecurringTransaction $recurring
+ * @param \Bill $bill
* @param Carbon $start
* @param Carbon $end
*
* @return \TransactionJournal|null
*/
- public function getJournalForRecurringInRange(\RecurringTransaction $recurring, Carbon $start, Carbon $end)
+ public function getJournalForBillInRange(\Bill $bill, Carbon $start, Carbon $end)
{
- return $this->getUser()->transactionjournals()->where('recurring_transaction_id', $recurring->id)->after($start)->before($end)->first();
+ return $this->getUser()->transactionjournals()->where('bill_id', $bill->id)->after($start)->before($end)->first();
}
/**
- * @param \RecurringTransaction $recurring
+ * @param \Bill $bill
* @param \TransactionJournal $journal
*
* @return bool
*/
- public function scan(\RecurringTransaction $recurring, \TransactionJournal $journal)
+ public function scan(\Bill $bill, \TransactionJournal $journal)
{
/*
* Match words.
*/
$wordMatch = false;
- $matches = explode(',', $recurring->match);
+ $matches = explode(',', $bill->match);
$description = strtolower($journal->description);
/*
@@ -261,8 +261,8 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
if (count($transactions) > 1) {
$amount = max(floatval($transactions[0]->amount), floatval($transactions[1]->amount));
- $min = floatval($recurring->amount_min);
- $max = floatval($recurring->amount_max);
+ $min = floatval($bill->amount_min);
+ $max = floatval($bill->amount_max);
if ($amount >= $min && $amount <= $max) {
$amountMatch = true;
\Log::debug('Amount match is true!');
@@ -273,17 +273,17 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
* If both, update!
*/
if ($wordMatch && $amountMatch) {
- $journal->recurringTransaction()->associate($recurring);
+ $journal->bill()->associate($bill);
$journal->save();
}
}
/**
- * @param \RecurringTransaction $recurring
+ * @param \Bill $bill
*
* @return bool
*/
- public function scanEverything(\RecurringTransaction $recurring)
+ public function scanEverything(\Bill $bill)
{
// get all journals that (may) be relevant.
// this is usually almost all of them.
@@ -291,7 +291,7 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
/** @var \FireflyIII\Database\TransactionJournal\TransactionJournal $journalRepository */
$journalRepository = \App::make('FireflyIII\Database\TransactionJournal\TransactionJournal');
- $set = \DB::table('transactions')->where('amount', '>', 0)->where('amount', '>=', $recurring->amount_min)->where('amount', '<=', $recurring->amount_max)
+ $set = \DB::table('transactions')->where('amount', '>', 0)->where('amount', '>=', $bill->amount_min)->where('amount', '<=', $bill->amount_max)
->get(['transaction_journal_id']);
$ids = [];
@@ -303,7 +303,7 @@ class RecurringTransaction implements CUD, CommonDatabaseCalls, RecurringTransac
$journals = $journalRepository->getByIds($ids);
/** @var \TransactionJournal $journal */
foreach ($journals as $journal) {
- $this->scan($recurring, $journal);
+ $this->scan($bill, $journal);
}
}
diff --git a/app/lib/FireflyIII/Database/Bill/BillInterface.php b/app/lib/FireflyIII/Database/Bill/BillInterface.php
new file mode 100644
index 0000000000..7be8a55b73
--- /dev/null
+++ b/app/lib/FireflyIII/Database/Bill/BillInterface.php
@@ -0,0 +1,41 @@
+add('description', 'Internal error: need to know type of transaction!');
}
- if (isset($model['recurring_transaction_id']) && intval($model['recurring_transaction_id']) < 0) {
- $errors->add('recurring_transaction_id', 'Recurring transaction is invalid.');
+ if (isset($model['bill_id']) && intval($model['bill_id']) < 0) {
+ $errors->add('bill_id', 'Bill is invalid.');
}
if (!isset($model['description'])) {
$errors->add('description', 'This field is mandatory.');
diff --git a/app/lib/FireflyIII/Event/TransactionJournal.php b/app/lib/FireflyIII/Event/TransactionJournal.php
index ed62684c96..ebb5e344f0 100644
--- a/app/lib/FireflyIII/Event/TransactionJournal.php
+++ b/app/lib/FireflyIII/Event/TransactionJournal.php
@@ -17,12 +17,12 @@ class TransactionJournal
*/
public function store(\TransactionJournal $journal)
{
- /** @var \FireflyIII\Database\RecurringTransaction\RecurringTransaction $repository */
- $repository = \App::make('FireflyIII\Database\RecurringTransaction\RecurringTransaction');
+ /** @var \FireflyIII\Database\Bill\Bill $repository */
+ $repository = \App::make('FireflyIII\Database\Bill\Bill');
$set = $repository->get();
- /** @var \RecurringTransaction $entry */
+ /** @var \Bill $entry */
foreach ($set as $entry) {
$repository->scan($entry, $journal);
}
@@ -43,13 +43,13 @@ class TransactionJournal
*/
public function update(\TransactionJournal $journal)
{
- /** @var \FireflyIII\Database\RecurringTransaction\RecurringTransaction $repository */
- $repository = \App::make('FireflyIII\Database\RecurringTransaction\RecurringTransaction');
+ /** @var \FireflyIII\Database\Bill\Bill $repository */
+ $repository = \App::make('FireflyIII\Database\Bill\Bill');
$set = $repository->get();
- $journal->recurring_transaction_id = null;
+ $journal->bill_id = null;
$journal->save();
- /** @var \RecurringTransaction $entry */
+ /** @var \Bill $entry */
foreach ($set as $entry) {
$repository->scan($entry, $journal);
}
diff --git a/app/models/RecurringTransaction.php b/app/models/Bill.php
similarity index 88%
rename from app/models/RecurringTransaction.php
rename to app/models/Bill.php
index f939cff382..a7f0da04a2 100644
--- a/app/models/RecurringTransaction.php
+++ b/app/models/Bill.php
@@ -3,9 +3,9 @@ use Carbon\Carbon;
use Watson\Validating\ValidatingTrait;
use \Illuminate\Database\Eloquent\Model as Eloquent;
/**
- * Class RecurringTransaction
+ * Class Bill
*/
-class RecurringTransaction extends Eloquent
+class Bill extends Eloquent
{
use ValidatingTrait;
@@ -57,8 +57,7 @@ class RecurringTransaction extends Eloquent
/**
* TODO remove this method in favour of something in the FireflyIII libraries.
*
- * Find the next expected match based on the set journals and the date stuff from the recurring
- * transaction.
+ * Find the next expected match based on the set journals and the date stuff from the bill.
*/
public function nextExpectedMatch()
{
@@ -78,18 +77,15 @@ class RecurringTransaction extends Eloquent
$today = DateKit::addPeriod(new Carbon, $this->repeat_freq, 0);
/*
- * FF3 loops from the $start of the recurring transaction, and to make sure
+ * FF3 loops from the $start of the bill, and to make sure
* $skip works, it adds one (for modulo).
*/
$skip = $this->skip + 1;
$start = DateKit::startOfPeriod(new Carbon, $this->repeat_freq);
/*
* go back exactly one month/week/etc because FF3 does not care about 'next'
- * recurring transactions if they're too far into the past.
+ * bills if they're too far into the past.
*/
- // echo 'Repeat freq is: ' . $recurringTransaction->repeat_freq . '
';
-
- // echo 'Start: ' . $start . '
';
$counter = 0;
while ($start <= $today) {
diff --git a/app/models/TransactionJournal.php b/app/models/TransactionJournal.php
index ee9cd336c7..6bfde9564f 100644
--- a/app/models/TransactionJournal.php
+++ b/app/models/TransactionJournal.php
@@ -85,9 +85,9 @@ class TransactionJournal extends Eloquent
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
- public function recurringTransaction()
+ public function bill()
{
- return $this->belongsTo('RecurringTransaction');
+ return $this->belongsTo('Bill');
}
/**
@@ -202,7 +202,7 @@ class TransactionJournal extends Eloquent
$query->with(
['transactions' => function ($q) {
$q->orderBy('amount', 'ASC');
- }, 'transactiontype', 'budgets','categories', 'transactions.account.accounttype', 'recurringTransaction', 'budgets', 'categories']
+ }, 'transactiontype', 'budgets','categories', 'transactions.account.accounttype', 'bill', 'budgets', 'categories']
);
}
diff --git a/app/models/User.php b/app/models/User.php
index 938f353bde..f41750cda7 100644
--- a/app/models/User.php
+++ b/app/models/User.php
@@ -69,9 +69,9 @@ class User extends Eloquent implements UserInterface, RemindableInterface
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
- public function recurringtransactions()
+ public function bills()
{
- return $this->hasMany('RecurringTransaction');
+ return $this->hasMany('Bill');
}
/**
diff --git a/app/routes.php b/app/routes.php
index a519bfa7cb..d68c319738 100644
--- a/app/routes.php
+++ b/app/routes.php
@@ -34,9 +34,9 @@ Route::bind(
Route::bind(
- 'recurring', function ($value, $route) {
+ 'bill', function ($value, $route) {
if (Auth::check()) {
- return RecurringTransaction::
+ return Bill::
where('id', $value)->where('user_id', Auth::user()->id)->first();
}
@@ -192,11 +192,11 @@ Route::group(
Route::get('/chart/home/account', ['uses' => 'GoogleChartController@allAccountsBalanceChart']);
Route::get('/chart/home/budgets', ['uses' => 'GoogleChartController@allBudgetsHomeChart']);
Route::get('/chart/home/categories', ['uses' => 'GoogleChartController@allCategoriesHomeChart']);
- Route::get('/chart/home/recurring', ['uses' => 'GoogleChartController@recurringTransactionsOverview']);
+ Route::get('/chart/home/bills', ['uses' => 'GoogleChartController@billsOverview']);
Route::get('/chart/account/{account}/{view?}', ['uses' => 'GoogleChartController@accountBalanceChart']);
Route::get('/chart/reports/income-expenses/{year}', ['uses' => 'GoogleChartController@yearInExp']);
Route::get('/chart/reports/income-expenses-sum/{year}', ['uses' => 'GoogleChartController@yearInExpSum']);
- Route::get('/chart/recurring/{recurring}', ['uses' => 'GoogleChartController@recurringOverview']);
+ Route::get('/chart/bills/{bill}', ['uses' => 'GoogleChartController@billOverview']);
Route::get('/chart/budget/{budget}/{limitrepetition}', ['uses' => 'GoogleChartController@budgetLimitSpending']);
Route::get('/chart/piggy_history/{piggy_bank}', ['uses' => 'GoogleChartController@piggyBankHistory']);
@@ -234,13 +234,13 @@ Route::group(
Route::get('/profile', ['uses' => 'ProfileController@index', 'as' => 'profile']);
Route::get('/profile/change-password', ['uses' => 'ProfileController@changePassword', 'as' => 'change-password']);
- // recurring transactions controller
- Route::get('/recurring', ['uses' => 'RecurringController@index', 'as' => 'recurring.index']);
- Route::get('/recurring/rescan/{recurring}', ['uses' => 'RecurringController@rescan', 'as' => 'recurring.rescan']); # rescan for matching.
- Route::get('/recurring/create', ['uses' => 'RecurringController@create', 'as' => 'recurring.create']);
- Route::get('/recurring/edit/{recurring}', ['uses' => 'RecurringController@edit', 'as' => 'recurring.edit']);
- Route::get('/recurring/delete/{recurring}', ['uses' => 'RecurringController@delete', 'as' => 'recurring.delete']);
- Route::get('/recurring/show/{recurring}', ['uses' => 'RecurringController@show', 'as' => 'recurring.show']);
+ // bills controller
+ Route::get('/bills', ['uses' => 'BillController@index', 'as' => 'bills.index']);
+ Route::get('/bills/rescan/{bill}', ['uses' => 'BillController@rescan', 'as' => 'bills.rescan']); # rescan for matching.
+ Route::get('/bills/create', ['uses' => 'BillController@create', 'as' => 'bills.create']);
+ Route::get('/bills/edit/{bill}', ['uses' => 'BillController@edit', 'as' => 'bills.edit']);
+ Route::get('/bills/delete/{bill}', ['uses' => 'BillController@delete', 'as' => 'bills.delete']);
+ Route::get('/bills/show/{bill}', ['uses' => 'BillController@show', 'as' => 'bills.show']);
// repeated expenses controller:
Route::get('/repeatedexpenses', ['uses' => 'RepeatedExpenseController@index', 'as' => 'repeated.index']);
@@ -328,10 +328,10 @@ Route::group(
// profile controller
Route::post('/profile/change-password', ['uses' => 'ProfileController@postChangePassword']);
- // recurring controller
- Route::post('/recurring/store', ['uses' => 'RecurringController@store', 'as' => 'recurring.store']);
- Route::post('/recurring/update/{recurring}', ['uses' => 'RecurringController@update', 'as' => 'recurring.update']);
- Route::post('/recurring/destroy/{recurring}', ['uses' => 'RecurringController@destroy', 'as' => 'recurring.destroy']);
+ // bills controller
+ Route::post('/bills/store', ['uses' => 'BillController@store', 'as' => 'bills.store']);
+ Route::post('/bills/update/{bill}', ['uses' => 'BillController@update', 'as' => 'bills.update']);
+ Route::post('/bills/destroy/{bill}', ['uses' => 'BillController@destroy', 'as' => 'bills.destroy']);
// transaction controller:
Route::post('/transactions/store/{what}', ['uses' => 'TransactionController@store', 'as' => 'transactions.store'])->where(
diff --git a/app/views/recurring/create.blade.php b/app/views/bills/create.blade.php
similarity index 91%
rename from app/views/recurring/create.blade.php
rename to app/views/bills/create.blade.php
index a14eaf114d..823716451d 100644
--- a/app/views/recurring/create.blade.php
+++ b/app/views/bills/create.blade.php
@@ -1,7 +1,7 @@
@extends('layouts.default')
@section('content')
{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName()) }}
-{{Form::open(['class' => 'form-horizontal','id' => 'store','url' => route('recurring.store')])}}
+{{Form::open(['class' => 'form-horizontal','id' => 'store','url' => route('bills.store')])}}
diff --git a/app/views/recurring/edit.blade.php b/app/views/bills/edit.blade.php similarity index 80% rename from app/views/recurring/edit.blade.php rename to app/views/bills/edit.blade.php index 5824b10655..9e55131576 100644 --- a/app/views/recurring/edit.blade.php +++ b/app/views/bills/edit.blade.php @@ -1,7 +1,7 @@ @extends('layouts.default') @section('content') -{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $recurringTransaction) }} -{{Form::model($recurringTransaction, ['class' => 'form-horizontal','id' => 'update','url' => route('recurring.update', $recurringTransaction->id)])}} +{{ Breadcrumbs::renderIfExists(Route::getCurrentRoute()->getName(), $bill) }} +{{Form::model($bill, ['class' => 'form-horizontal','id' => 'update','url' => route('bills.update', $bill->id)])}}