New bulk task options

This commit is contained in:
David Bomba 2025-09-06 13:20:55 +10:00
parent f7250f643a
commit 1f62b24e25
2 changed files with 20 additions and 4 deletions

View File

@ -514,11 +514,13 @@ class TaskController extends BaseController
$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);
return $this->listResponse(Task::withTrashed()->whereIn('id', $this->transformKeys($ids)));
return $this->listResponse(Task::withTrashed()->whereIn('id', $this->transformKeys($ids))->company());
}

View File

@ -16,6 +16,7 @@ use App\Models\Task;
use App\Models\Project;
use App\Factory\TaskFactory;
use App\Jobs\Task\TaskAssigned;
use App\Utils\Traits\MakesHash;
use App\Utils\Traits\GeneratesCounter;
use Illuminate\Database\QueryException;
@ -25,6 +26,7 @@ use Illuminate\Database\QueryException;
class TaskRepository extends BaseRepository
{
use GeneratesCounter;
use MakesHash;
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
{
nlog("xx");
nlog($models->pluck('id'));
nlog("yy");
// First, filter out tasks that have been invoiced
$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') {
// Handle project_id updates with client_id synchronization
$project = Project::withTrashed()
@ -449,7 +463,7 @@ class TaskRepository extends BaseRepository
'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!
$models->update([$column => $new_value, 'project_id' => null]);
}