Prevent invoicing tasks/expenses with archived clients

This commit is contained in:
Hillel Coren 2018-03-14 12:58:07 +02:00
parent 0b7621bd7d
commit 8a874ba602
3 changed files with 19 additions and 18 deletions

View File

@ -18,6 +18,7 @@ use Auth;
use Cache; use Cache;
use Input; use Input;
use Redirect; use Redirect;
use Request;
use Session; use Session;
use URL; use URL;
use Utils; use Utils;
@ -223,6 +224,7 @@ class ExpenseController extends BaseController
{ {
$action = Input::get('action'); $action = Input::get('action');
$ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids'); $ids = Input::get('public_id') ? Input::get('public_id') : Input::get('ids');
$referer = Request::server('HTTP_REFERER');
switch ($action) { switch ($action) {
case 'invoice': 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 // 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) { foreach ($expenses as $expense) {
if ($expense->client) { if ($expense->client) {
if ($expense->client->trashed()) {
return redirect($referer)->withError(trans('texts.client_must_be_active'));
}
if (! $clientPublicId) { if (! $clientPublicId) {
$clientPublicId = $expense->client->public_id; $clientPublicId = $expense->client->public_id;
} elseif ($clientPublicId != $expense->client->public_id) { } elseif ($clientPublicId != $expense->client->public_id) {
Session::flash('error', trans('texts.expense_error_multiple_clients')); return redirect($referer)->withError(trans('texts.expense_error_multiple_clients'));
return Redirect::to('expenses');
} }
} }
if (! $currencyId) { if (! $currencyId) {
$currencyId = $expense->invoice_currency_id; $currencyId = $expense->invoice_currency_id;
} elseif ($currencyId != $expense->invoice_currency_id && $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($referer)->withError(trans('texts.expense_error_multiple_currencies'));
return Redirect::to('expenses');
} }
if ($expense->invoice_id) { if ($expense->invoice_id) {
Session::flash('error', trans('texts.expense_error_invoiced')); return redirect($referer)->withError(trans('texts.expense_error_invoiced'));
return Redirect::to('expenses');
} }
} }

View File

@ -16,6 +16,7 @@ use Auth;
use DropdownButton; use DropdownButton;
use Input; use Input;
use Redirect; use Redirect;
use Request;
use Session; use Session;
use URL; use URL;
use Utils; use Utils;
@ -260,6 +261,7 @@ class TaskController extends BaseController
{ {
$action = Input::get('action'); $action = Input::get('action');
$ids = Input::get('public_id') ?: (Input::get('id') ?: Input::get('ids')); $ids = Input::get('public_id') ?: (Input::get('id') ?: Input::get('ids'));
$referer = Request::server('HTTP_REFERER');
if (in_array($action, ['resume', 'stop'])) { if (in_array($action, ['resume', 'stop'])) {
$this->taskRepo->save($ids, ['action' => $action]); $this->taskRepo->save($ids, ['action' => $action]);
@ -273,23 +275,21 @@ class TaskController extends BaseController
$lastProjectId = false; $lastProjectId = false;
foreach ($tasks as $task) { foreach ($tasks as $task) {
if ($task->client) { if ($task->client) {
if ($task->client->trashed()) {
return redirect($referer)->withError(trans('texts.client_must_be_active'));
}
if (! $clientPublicId) { if (! $clientPublicId) {
$clientPublicId = $task->client->public_id; $clientPublicId = $task->client->public_id;
} elseif ($clientPublicId != $task->client->public_id) { } elseif ($clientPublicId != $task->client->public_id) {
Session::flash('error', trans('texts.task_error_multiple_clients')); return redirect($referer)->withError(trans('texts.task_error_multiple_clients'));
return Redirect::to('tasks');
} }
} }
if ($task->is_running) { if ($task->is_running) {
Session::flash('error', trans('texts.task_error_running')); return redirect($referer)->withError(trans('texts.task_error_running'));
return Redirect::to('tasks');
} elseif ($task->invoice_id) { } elseif ($task->invoice_id) {
Session::flash('error', trans('texts.task_error_invoiced')); return redirect($referer)->withError(trans('texts.task_error_invoiced'));
return Redirect::to('tasks');
} }
$account = Auth::user()->account; $account = Auth::user()->account;

View File

@ -2785,6 +2785,7 @@ $LANG = array(
'auto_archive_quote_help' => 'Automatically archive quotes when they are converted.', 'auto_archive_quote_help' => 'Automatically archive quotes when they are converted.',
'invoice_workflow' => 'Invoice Workflow', 'invoice_workflow' => 'Invoice Workflow',
'quote_workflow' => 'Quote Workflow', 'quote_workflow' => 'Quote Workflow',
'client_must_be_active' => 'Error: the client must be active',
); );