Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Build some extra features for the recurring transaction controller.
James Colefdba0addb64e
diff --git a/app/controllers/RecurringController.php b/app/controllers/RecurringController.phpindex 46be9a5b6a..bf85aaf2bb 100644--- a/app/controllers/RecurringController.php+++ b/app/controllers/RecurringController.php@@ -82,8 +82,10 @@ class RecurringController extends BaseController/****/- public function show()+ public function show(RecurringTransaction $recurringTransaction){+ return View::make('recurring.show')->with('recurring',$recurringTransaction);+}/**@@ -113,5 +115,14 @@ class RecurringController extends BaseController*/public function update(RecurringTransaction $recurringTransaction){+ /** @var \RecurringTransaction $recurringTransaction */+ $recurringTransaction = $this->_repository->update($recurringTransaction, Input::all());+ if($recurringTransaction->errors()->count() == 0) {+ Session::flash('success', 'The recurring transaction has been updated.');+ return Redirect::route('recurring.index');+ } else {+ Session::flash('error', 'Could not update the recurring transaction: ' . $recurringTransaction->errors()->first());+ return Redirect::route('recurring.edit',$recurringTransaction->id)->withInput()->withErrors($recurringTransaction->errors());+ }}-}\ No newline at end of file+}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php b/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.phpindex 123ff2bc75..b8d840c501 100644--- a/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php+++ b/app/lib/Firefly/Storage/RecurringTransaction/EloquentRecurringTransactionRepository.php@@ -66,4 +66,35 @@ class EloquentRecurringTransactionRepository implements RecurringTransactionReporeturn $recurringTransaction;}+ /**+ * @param \RecurringTransaction $recurringTransaction+ * @param $data+ * @return mixed|void+ */+ public function update(\RecurringTransaction $recurringTransaction, $data) {+ $recurringTransaction->name = $data['name'];+ $recurringTransaction->match = join(' ', explode(',', $data['match']));+ $recurringTransaction->amount_max = floatval($data['amount_max']);+ $recurringTransaction->amount_min = floatval($data['amount_min']);++ // both amounts zero:+ if ($recurringTransaction->amount_max == 0 && $recurringTransaction->amount_min == 0) {+ $recurringTransaction->errors()->add('amount_max', 'Amount max and min cannot both be zero.');++ return $recurringTransaction;+ }+ $recurringTransaction->date = new Carbon($data['date']);+ $recurringTransaction->active = isset($data['active']) ? intval($data['active']) : 0;+ $recurringTransaction->automatch = isset($data['automatch']) ? intval($data['automatch']) : 0;+ $recurringTransaction->skip = isset($data['skip']) ? intval($data['skip']) : 0;+ $recurringTransaction->repeat_freq = $data['repeat_freq'];++ if ($recurringTransaction->validate()) {+ $recurringTransaction->save();+ }++ return $recurringTransaction;++ }+}\ No newline at end of filediff --git a/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php b/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.phpindex a4f33014b6..dc296f28c4 100644--- a/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php+++ b/app/lib/Firefly/Storage/RecurringTransaction/RecurringTransactionRepositoryInterface.php@@ -30,5 +30,12 @@ interface RecurringTransactionRepositoryInterface*/public function destroy(\RecurringTransaction $recurringTransaction);+ /**+ * @param \RecurringTransaction $recurringTransaction+ * @param $data+ * @return mixed+ */+ public function update(\RecurringTransaction $recurringTransaction, $data);+}\ No newline at end of filediff --git a/app/models/RecurringTransaction.php b/app/models/RecurringTransaction.phpindex 7b0ccde6ed..365cc797b7 100644--- a/app/models/RecurringTransaction.php+++ b/app/models/RecurringTransaction.php@@ -50,26 +50,6 @@ class RecurringTransaction extends Ardent'skip' => 'required|between:0,31',];- /**- * @return array- */- public static function factory()- {- $date = new Carbon;-- return [- 'user_id' => 'factory|User',- 'name' => 'string',- 'match' => 'string',- 'amount_max' => 100,- 'amount_min' => 50,- 'date' => $date,- 'active' => 1,- 'automatch' => 1,- 'repeat_freq' => 'monthly',- 'skip' => 0,- ];- }/*** @return array@@ -99,7 +79,7 @@ class RecurringTransaction extends Ardent$start->addMonths($skip);break;case 'quarterly':- $start->addMonths($skip);+ $start->addMonths($skip * 3);break;case 'half-year':$start->addMonths($skip * 6);diff --git a/app/tests/controllers/RecurringControllerTest.php b/app/tests/controllers/RecurringControllerTest.phpindex f35d918c7b..2c210e6672 100644--- a/app/tests/controllers/RecurringControllerTest.php+++ b/app/tests/controllers/RecurringControllerTest.php@@ -158,6 +158,8 @@ class RecurringControllerTest extends TestCase$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($recurringTransaction->user_id);$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');+ $this->_repository->shouldReceive('update')->andReturn($recurringTransaction);+$this->action('POST', 'RecurringController@update', $recurringTransaction->id);$this->assertResponseOk();diff --git a/app/views/recurring/create.blade.php b/app/views/recurring/create.blade.phpindex 4b143f4ec8..4cfd860cda 100644--- a/app/views/recurring/create.blade.php+++ b/app/views/recurring/create.blade.php@@ -38,7 +38,7 @@<p class="text-danger">{{$errors->first('match')}}</p>@else<span class="help-block">For example: rent, [company name]. All matches need to- be present for the recurring transaction to be recognized. This field is not case-sensitive.</span>+ be present for the recurring transaction to be recognized. This field is not case-sensitive. <em>Press enter after every match</em></span>@endif</div></div>diff --git a/app/views/recurring/index.blade.php b/app/views/recurring/index.blade.phpindex 179d44f1e8..2cf5be03b5 100644--- a/app/views/recurring/index.blade.php+++ b/app/views/recurring/index.blade.php@@ -5,7 +5,7 @@<h1>Firefly<small>Recurring transactions</small></h1>- <p class="lead">Use recurring transactions to track repeated expenses</p>+ <p class="lead">Use recurring transactions to track repeated withdrawals</p><p class="text-info">We all have bills to pay. Firefly can help you organize those bills into recurring transactions,which are exactly what the name suggests. Firefly can match new (and existing) transactions to such a recurring transactionand help you organize these expenses into manageable groups. The front page of Firefly will show you which recurring