mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix parameters, re-order.
This commit is contained in:
parent
9b3131b95e
commit
594f9822c7
@ -10,8 +10,8 @@ use FireflyIII\Http\Requests\RuleGroupFormRequest;
|
||||
use FireflyIII\Http\Requests\SelectTransactionsRequest;
|
||||
use FireflyIII\Jobs\ExecuteRuleGroupOnExistingTransactions;
|
||||
use FireflyIII\Models\RuleGroup;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\RuleGroup\RuleGroupRepositoryInterface;
|
||||
use Input;
|
||||
use Preferences;
|
||||
use Session;
|
||||
@ -133,6 +133,60 @@ class RuleGroupController extends Controller
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the given rulegroup on a set of existing transactions
|
||||
*
|
||||
* @param SelectTransactionsRequest $request
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function execute(SelectTransactionsRequest $request, AccountRepositoryInterface $repository, RuleGroup $ruleGroup)
|
||||
{
|
||||
// Get parameters specified by the user
|
||||
$accounts = $repository->get($request->get('accounts'));
|
||||
$startDate = new Carbon($request->get('start_date'));
|
||||
$endDate = new Carbon($request->get('end_date'));
|
||||
|
||||
// Create a job to do the work asynchronously
|
||||
$job = new ExecuteRuleGroupOnExistingTransactions($ruleGroup);
|
||||
|
||||
// Apply parameters to the job
|
||||
$job->setUser(Auth::user());
|
||||
$job->setAccounts($accounts);
|
||||
$job->setStartDate($startDate);
|
||||
$job->setEndDate($endDate);
|
||||
|
||||
// Dispatch a new job to execute it in a queue
|
||||
$this->dispatch($job);
|
||||
|
||||
// Tell the user that the job is queued
|
||||
Session::flash('success', trans('firefly.executed_group_on_existing_transactions', ['title' => $ruleGroup->title]));
|
||||
|
||||
return redirect()->route('rules.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a form for the user to select a range of transactions to execute this rulegroup for
|
||||
*
|
||||
* @param AccountRepositoryInterface $repository
|
||||
* @param RuleGroup $ruleGroup
|
||||
*
|
||||
* @return View
|
||||
*/
|
||||
public function selectTransactions(AccountRepositoryInterface $repository, RuleGroup $ruleGroup)
|
||||
{
|
||||
// does the user have shared accounts?
|
||||
$accounts = $repository->getAccounts(['Default account', 'Asset account']);
|
||||
$accountList = ExpandedForm::makeSelectList($accounts);
|
||||
$checkedAccounts = array_keys($accountList);
|
||||
$first = session('first')->format('Y-m-d');
|
||||
$today = Carbon::create()->format('Y-m-d');
|
||||
|
||||
return view('rules.rule-group.select-transactions', compact('checkedAccounts', 'accountList', 'first', 'today', 'ruleGroup'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param RuleGroupFormRequest $request
|
||||
* @param RuleGroupRepositoryInterface $repository
|
||||
@ -144,7 +198,7 @@ class RuleGroupController extends Controller
|
||||
$data = [
|
||||
'title' => $request->input('title'),
|
||||
'description' => $request->input('description'),
|
||||
'user_id' => Auth::user()->id,
|
||||
'user_id' => Auth::user()->id,
|
||||
];
|
||||
|
||||
$ruleGroup = $repository->store($data);
|
||||
@ -208,48 +262,4 @@ class RuleGroupController extends Controller
|
||||
return redirect(session('rules.rule-group.edit.url'));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a form for the user to select a range of transactions to execute this rulegroup for
|
||||
* @param RuleGroup $ruleGroup
|
||||
*/
|
||||
public function selectTransactions(AccountRepositoryInterface $repository, RuleGroup $ruleGroup)
|
||||
{
|
||||
// does the user have shared accounts?
|
||||
$accounts = $repository->getAccounts(['Default account', 'Asset account']);
|
||||
$accountList = ExpandedForm::makeSelectList($accounts);
|
||||
$checkedAccounts = array_keys($accountList);
|
||||
$first = session('first')->format('Y-m-d');
|
||||
$today = Carbon::create()->format('Y-m-d');
|
||||
|
||||
return view('rules.rule-group.select-transactions', compact('checkedAccounts', 'accountList', 'first', 'today', 'ruleGroup'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the given rulegroup on a set of existing transactions
|
||||
* @param RuleGroup $ruleGroup
|
||||
*/
|
||||
public function execute(SelectTransactionsRequest $request, AccountRepositoryInterface $repository, RuleGroup $ruleGroup)
|
||||
{
|
||||
// Get parameters specified by the user
|
||||
$accounts = $repository->get($request->get('accounts'));
|
||||
$startDate = new Carbon($request->get('start_date'));
|
||||
$endDate = new Carbon($request->get('end_date'));
|
||||
|
||||
// Create a job to do the work asynchronously
|
||||
$job = new ExecuteRuleGroupOnExistingTransactions($ruleGroup);
|
||||
|
||||
// Apply parameters to the job
|
||||
$job->setUser(Auth::user());
|
||||
$job->setAccounts($accounts);
|
||||
$job->setStartDate($startDate);
|
||||
$job->setEndDate($endDate);
|
||||
|
||||
// Dispatch a new job to execute it in a queue
|
||||
$this->dispatch($job);
|
||||
|
||||
// Tell the user that the job is queued
|
||||
Session::flash('success', trans('firefly.executed_group_on_existing_transactions', ['title' => $ruleGroup->title]));
|
||||
return redirect()->route('rules.index');
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ interface AccountRepositoryInterface
|
||||
*
|
||||
* @param array $ids
|
||||
*
|
||||
* @return Collection
|
||||
* @return \Illuminate\Support\Collection
|
||||
*/
|
||||
public function get(array $ids): Collection;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user