/**
* @return \Illuminate\Http\RedirectResponse
*/
public function bulk()
{
$action = Input::get('action');
$ids = Input::get('public_id') ?: (Input::get('id') ?: Input::get('ids'));
if ($action == 'stop') {
$this->taskRepo->save($ids, ['action' => $action]);
Session::flash('message', trans('texts.stopped_task'));
return Redirect::to('tasks');
} else {
if ($action == 'invoice' || $action == 'add_to_invoice') {
$tasks = Task::scope($ids)->with('client')->get();
$clientPublicId = false;
$data = [];
foreach ($tasks as $task) {
if ($task->client) {
if (!$clientPublicId) {
$clientPublicId = $task->client->public_id;
} else {
if ($clientPublicId != $task->client->public_id) {
Session::flash('error', trans('texts.task_error_multiple_clients'));
return Redirect::to('tasks');
}
}
}
if ($task->is_running) {
Session::flash('error', trans('texts.task_error_running'));
return Redirect::to('tasks');
} else {
if ($task->invoice_id) {
Session::flash('error', trans('texts.task_error_invoiced'));
return Redirect::to('tasks');
}
}
$account = Auth::user()->account;
$data[] = ['publicId' => $task->public_id, 'description' => $task->description . "\n\n" . $task->present()->times($account), 'duration' => $task->getHours()];
}
if ($action == 'invoice') {
return Redirect::to("invoices/create/{$clientPublicId}")->with('tasks', $data);
} else {
$invoiceId = Input::get('invoice_id');
return Redirect::to("invoices/{$invoiceId}/edit")->with('tasks', $data);
}
} else {
$count = $this->taskRepo->bulk($ids, $action);
$message = Utils::pluralize($action . 'd_task', $count);
Session::flash('message', $message);
if ($action == 'restore' && $count == 1) {
return Redirect::to('tasks/' . $ids[0] . '/edit');
} else {
return Redirect::to('tasks');
}
}
}
}