New bulk task options
This commit is contained in:
parent
f7250f643a
commit
1f62b24e25
|
|
@ -514,11 +514,13 @@ class TaskController extends BaseController
|
||||||
|
|
||||||
$tasks = Task::withTrashed()->whereIn('id', $this->transformKeys($ids))->company();
|
$tasks = Task::withTrashed()->whereIn('id', $this->transformKeys($ids))->company();
|
||||||
|
|
||||||
if ($request->action == 'bulk_update' && $user->can('edit', $tasks->first())) {
|
$_tasks = (clone $tasks);
|
||||||
|
|
||||||
|
if ($request->action == 'bulk_update' && $user->can('edit', $_tasks->first())) {
|
||||||
|
|
||||||
$this->task_repo->bulkUpdate($tasks, $request->column, $request->new_value);
|
$this->task_repo->bulkUpdate($tasks, $request->column, $request->new_value);
|
||||||
|
|
||||||
return $this->listResponse(Task::withTrashed()->whereIn('id', $this->transformKeys($ids)));
|
return $this->listResponse(Task::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ use App\Models\Task;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Factory\TaskFactory;
|
use App\Factory\TaskFactory;
|
||||||
use App\Jobs\Task\TaskAssigned;
|
use App\Jobs\Task\TaskAssigned;
|
||||||
|
use App\Utils\Traits\MakesHash;
|
||||||
use App\Utils\Traits\GeneratesCounter;
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
use Illuminate\Database\QueryException;
|
use Illuminate\Database\QueryException;
|
||||||
|
|
||||||
|
|
@ -25,6 +26,7 @@ use Illuminate\Database\QueryException;
|
||||||
class TaskRepository extends BaseRepository
|
class TaskRepository extends BaseRepository
|
||||||
{
|
{
|
||||||
use GeneratesCounter;
|
use GeneratesCounter;
|
||||||
|
use MakesHash;
|
||||||
|
|
||||||
public $new_task = true;
|
public $new_task = true;
|
||||||
|
|
||||||
|
|
@ -432,9 +434,21 @@ class TaskRepository extends BaseRepository
|
||||||
|
|
||||||
public function bulkUpdate(\Illuminate\Database\Eloquent\Builder $models, string $column, mixed $new_value): void
|
public function bulkUpdate(\Illuminate\Database\Eloquent\Builder $models, string $column, mixed $new_value): void
|
||||||
{
|
{
|
||||||
|
nlog("xx");
|
||||||
|
nlog($models->pluck('id'));
|
||||||
|
nlog("yy");
|
||||||
|
|
||||||
// First, filter out tasks that have been invoiced
|
// First, filter out tasks that have been invoiced
|
||||||
$models->whereNull('invoice_id');
|
$models->whereNull('invoice_id');
|
||||||
|
|
||||||
|
nlog($models->pluck('id'));
|
||||||
|
|
||||||
|
if(stripos($column, '_id') !== false) {
|
||||||
|
$new_value = $this->decodePrimaryKey($new_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
nlog("setting column = " . $column . " to " . $new_value);
|
||||||
|
|
||||||
if ($column === 'project_id') {
|
if ($column === 'project_id') {
|
||||||
// Handle project_id updates with client_id synchronization
|
// Handle project_id updates with client_id synchronization
|
||||||
$project = Project::withTrashed()
|
$project = Project::withTrashed()
|
||||||
|
|
@ -449,7 +463,7 @@ class TaskRepository extends BaseRepository
|
||||||
'client_id' => $project->client_id,
|
'client_id' => $project->client_id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
} elseif ($column === 'client_id') {
|
} elseif ($column === 'client_id') {
|
||||||
// If you are updating the client - we will unset the project id!
|
// If you are updating the client - we will unset the project id!
|
||||||
$models->update([$column => $new_value, 'project_id' => null]);
|
$models->update([$column => $new_value, 'project_id' => null]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue