mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 03:43:07 +00:00
Build some extra features for the recurring transaction controller.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -66,4 +66,35 @@ class EloquentRecurringTransactionRepository implements RecurringTransactionRepo
|
||||
return $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;
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -30,5 +30,12 @@ interface RecurringTransactionRepositoryInterface
|
||||
*/
|
||||
public function destroy(\RecurringTransaction $recurringTransaction);
|
||||
|
||||
/**
|
||||
* @param \RecurringTransaction $recurringTransaction
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(\RecurringTransaction $recurringTransaction, $data);
|
||||
|
||||
|
||||
}
|
@@ -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);
|
||||
|
@@ -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();
|
||||
|
@@ -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>
|
||||
|
@@ -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 transaction
|
||||
and help you organize these expenses into manageable groups. The front page of Firefly will show you which recurring
|
||||
|
Reference in New Issue
Block a user