mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-10-30 20:12:58 -04:00 
			
		
		
		
	Prevent invoicing tasks/expenses with archived clients
This commit is contained in:
		
							parent
							
								
									0b7621bd7d
								
							
						
					
					
						commit
						8a874ba602
					
				| @ -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')); | ||||
|                     } | ||||
|                 } | ||||
| 
 | ||||
|  | ||||
| @ -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; | ||||
|  | ||||
| @ -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', | ||||
| 
 | ||||
| ); | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user