Kanban / timesheet update
This commit is contained in:
@@ -23,6 +23,16 @@ interface TaskQueries
|
||||
*/
|
||||
public function pinnedTaskIds(int $jobId): array;
|
||||
|
||||
/**
|
||||
* Tasks scheduled for the user between the dates (Y-m-d): booked on
|
||||
* their task calendar row, or open tasks they are the assignee or a
|
||||
* member of whose planned period overlaps the dates or that have no
|
||||
* planned period at all (so unscheduled own work is never hidden).
|
||||
*
|
||||
* @return list<int>
|
||||
*/
|
||||
public function scheduledTaskIdsFor(int $userId, string $from, string $to): array;
|
||||
|
||||
/**
|
||||
* Null when the task does not exist or belongs to another job.
|
||||
*/
|
||||
|
||||
@@ -8,8 +8,9 @@ use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
|
||||
/**
|
||||
* A task as time is recorded on it: which job and work type it belongs to,
|
||||
* and whether the job is locked for time entries.
|
||||
* A task as time is recorded on it: which job, customer and work type it
|
||||
* belongs to, the job's payment basis (a PaymentBasis value) and whether
|
||||
* the job is locked for time entries.
|
||||
*/
|
||||
final readonly class BookableTask
|
||||
{
|
||||
@@ -23,6 +24,10 @@ final readonly class BookableTask
|
||||
public string $workTypeName,
|
||||
public JobStatus $jobStatus,
|
||||
public TaskStatus $taskStatus,
|
||||
public int $customerId = 0,
|
||||
public string $customerName = '',
|
||||
public ?string $customerHeaderColor = null,
|
||||
public ?string $paymentBasis = null,
|
||||
) {}
|
||||
|
||||
public function isLocked(): bool
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Modules\Jobs\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Jobs\Application\Contracts\TaskQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\BookableTask;
|
||||
use App\Modules\Jobs\Application\DTOs\NamedId;
|
||||
@@ -21,8 +22,31 @@ class EloquentTaskQueries implements TaskQueries
|
||||
public function __construct(
|
||||
private CatalogQueries $catalog,
|
||||
private UserAccountQueries $users,
|
||||
private CustomerQueries $customers,
|
||||
) {}
|
||||
|
||||
public function scheduledTaskIdsFor(int $userId, string $from, string $to): array
|
||||
{
|
||||
$booked = DB::table('task_bookings')
|
||||
->where('user_id', $userId)
|
||||
->whereBetween('day', [$from, $to])
|
||||
->pluck('task_id');
|
||||
|
||||
$planned = DB::table('tasks')
|
||||
->where('status', '!=', TaskStatus::Done->value)
|
||||
->where(fn ($query) => $query
|
||||
->whereNull('planned_from')
|
||||
->orWhere(fn ($query) => $query
|
||||
->where('planned_from', '<=', $to)
|
||||
->where(fn ($query) => $query->whereNull('planned_to')->orWhere('planned_to', '>=', $from))))
|
||||
->where(fn ($query) => $query
|
||||
->where('assignee_user_id', $userId)
|
||||
->orWhereIn('id', DB::table('task_members')->select('task_id')->where('user_id', $userId)))
|
||||
->pluck('id');
|
||||
|
||||
return $booked->merge($planned)->map(fn ($id): int => (int) $id)->unique()->values()->all();
|
||||
}
|
||||
|
||||
public function tasksOf(int $jobId): array
|
||||
{
|
||||
$models = TaskModel::query()
|
||||
@@ -116,7 +140,11 @@ class EloquentTaskQueries implements TaskQueries
|
||||
->join('customer_jobs', 'customer_jobs.id', '=', 'tasks.customer_job_id')
|
||||
->orderBy('customer_jobs.number')
|
||||
->orderBy('tasks.id')
|
||||
->get(['tasks.id', 'tasks.customer_job_id', 'tasks.title', 'tasks.work_type_id', 'tasks.status', 'customer_jobs.number', 'customer_jobs.name', 'customer_jobs.status as job_status']);
|
||||
->get(['tasks.id', 'tasks.customer_job_id', 'tasks.title', 'tasks.work_type_id', 'tasks.status', 'customer_jobs.number', 'customer_jobs.name', 'customer_jobs.status as job_status', 'customer_jobs.customer_id', 'customer_jobs.payment_basis']);
|
||||
|
||||
$customerIds = $rows->pluck('customer_id')->map(fn ($id): int => (int) $id)->unique()->values()->all();
|
||||
$customerNames = $this->customers->namesByIds($customerIds);
|
||||
$customerColors = $this->customers->headerColorsByIds($customerIds);
|
||||
|
||||
$workTypeNames = [];
|
||||
foreach ($rows->pluck('work_type_id')->unique() as $workTypeId) {
|
||||
@@ -133,6 +161,10 @@ class EloquentTaskQueries implements TaskQueries
|
||||
$workTypeNames[(int) $row->work_type_id] ?? '',
|
||||
JobStatus::from((string) $row->job_status),
|
||||
TaskStatus::from((string) $row->status),
|
||||
(int) $row->customer_id,
|
||||
$customerNames[(int) $row->customer_id] ?? '',
|
||||
$customerColors[(int) $row->customer_id] ?? null,
|
||||
$row->payment_basis === null ? null : (string) $row->payment_basis,
|
||||
))->values()->all();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user