diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index 1cc28e55ee..f62913fc6b 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -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()); } diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index 93c31d0131..ebd8f16b3f 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -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]); }