diff --git a/app/Http/Controllers/ExpenseController.php b/app/Http/Controllers/ExpenseController.php index e226a111e4e8..b02d6d978638 100644 --- a/app/Http/Controllers/ExpenseController.php +++ b/app/Http/Controllers/ExpenseController.php @@ -18,6 +18,7 @@ use Auth; use Cache; use Input; use Redirect; +use Request; use Session; use URL; use Utils; @@ -223,6 +224,7 @@ class ExpenseController extends BaseController { $action = Input::get('action'); $ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids'); + $referer = Request::server('HTTP_REFERER'); switch ($action) { case 'invoice': @@ -234,27 +236,25 @@ class ExpenseController extends BaseController // Validate that either all expenses do not have a client or if there is a client, it is the same client foreach ($expenses as $expense) { if ($expense->client) { + if ($expense->client->trashed()) { + return redirect($referer)->withError(trans('texts.client_must_be_active')); + } + if (! $clientPublicId) { $clientPublicId = $expense->client->public_id; } elseif ($clientPublicId != $expense->client->public_id) { - Session::flash('error', trans('texts.expense_error_multiple_clients')); - - return Redirect::to('expenses'); + return redirect($referer)->withError(trans('texts.expense_error_multiple_clients')); } } if (! $currencyId) { $currencyId = $expense->invoice_currency_id; } elseif ($currencyId != $expense->invoice_currency_id && $expense->invoice_currency_id) { - Session::flash('error', trans('texts.expense_error_multiple_currencies')); - - return Redirect::to('expenses'); + return redirect($referer)->withError(trans('texts.expense_error_multiple_currencies')); } if ($expense->invoice_id) { - Session::flash('error', trans('texts.expense_error_invoiced')); - - return Redirect::to('expenses'); + return redirect($referer)->withError(trans('texts.expense_error_invoiced')); } } diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index 5ae727a59019..9495406cd387 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -16,6 +16,7 @@ use Auth; use DropdownButton; use Input; use Redirect; +use Request; use Session; use URL; use Utils; @@ -260,6 +261,7 @@ class TaskController extends BaseController { $action = Input::get('action'); $ids = Input::get('public_id') ?: (Input::get('id') ?: Input::get('ids')); + $referer = Request::server('HTTP_REFERER'); if (in_array($action, ['resume', 'stop'])) { $this->taskRepo->save($ids, ['action' => $action]); @@ -273,23 +275,21 @@ class TaskController extends BaseController $lastProjectId = false; foreach ($tasks as $task) { if ($task->client) { + if ($task->client->trashed()) { + return redirect($referer)->withError(trans('texts.client_must_be_active')); + } + if (! $clientPublicId) { $clientPublicId = $task->client->public_id; } elseif ($clientPublicId != $task->client->public_id) { - Session::flash('error', trans('texts.task_error_multiple_clients')); - - return Redirect::to('tasks'); + return redirect($referer)->withError(trans('texts.task_error_multiple_clients')); } } if ($task->is_running) { - Session::flash('error', trans('texts.task_error_running')); - - return Redirect::to('tasks'); + return redirect($referer)->withError(trans('texts.task_error_running')); } elseif ($task->invoice_id) { - Session::flash('error', trans('texts.task_error_invoiced')); - - return Redirect::to('tasks'); + return redirect($referer)->withError(trans('texts.task_error_invoiced')); } $account = Auth::user()->account; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 7ea494af83fd..df95e495c2af 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2785,6 +2785,7 @@ $LANG = array( 'auto_archive_quote_help' => 'Automatically archive quotes when they are converted.', 'invoice_workflow' => 'Invoice Workflow', 'quote_workflow' => 'Quote Workflow', + 'client_must_be_active' => 'Error: the client must be active', );