Phase 4 work order profile depth
This commit is contained in:
@@ -71,14 +71,25 @@ class BuyerProfileController extends Controller
|
||||
'description' => ['nullable', 'string'],
|
||||
'service_categories' => ['nullable', 'string'],
|
||||
'hiring_regions' => ['nullable', 'string'],
|
||||
'hiring_policies_text' => ['nullable', 'string'],
|
||||
'locations_text' => ['nullable', 'string'],
|
||||
'vendor_onboarding' => ['nullable', 'string'],
|
||||
'payment_terms' => ['nullable', 'string'],
|
||||
'website_url' => ['nullable', 'url', 'max:255'],
|
||||
'contact_email' => ['nullable', 'email', 'max:255'],
|
||||
'public_contact' => ['nullable', 'boolean'],
|
||||
'profile_visibility' => ['nullable', 'array'],
|
||||
'profile_visibility.*' => ['nullable', 'boolean'],
|
||||
'private_notes' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
$data['public_contact'] = $request->boolean('public_contact');
|
||||
$data['hiring_policies'] = $this->linesToRecords($data['hiring_policies_text'] ?? '', ['name', 'summary']);
|
||||
$data['locations'] = $this->linesToRecords($data['locations_text'] ?? '', ['name', 'region']);
|
||||
$data['profile_visibility'] = $this->normalizeVisibility($request, [
|
||||
'description', 'categories', 'locations', 'policies', 'payment_terms', 'onboarding',
|
||||
]);
|
||||
unset($data['hiring_policies_text'], $data['locations_text']);
|
||||
|
||||
$request->user()->buyerProfile()->updateOrCreate(
|
||||
['user_id' => $request->user()->id],
|
||||
@@ -94,4 +105,21 @@ class BuyerProfileController extends Controller
|
||||
'profile' => $buyer->load('user', 'attachments', 'ratings.user'),
|
||||
]);
|
||||
}
|
||||
|
||||
private function linesToRecords(string $text, array $keys): array
|
||||
{
|
||||
return collect(preg_split('/\r\n|\r|\n/', $text))
|
||||
->map(fn (string $line): array => array_pad(array_map('trim', explode('|', $line, count($keys))), count($keys), null))
|
||||
->filter(fn (array $parts): bool => (bool) ($parts[0] ?? null))
|
||||
->map(fn (array $parts): array => collect($keys)->mapWithKeys(fn (string $key, int $index): array => [$key => $parts[$index] ?? null])->all())
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
private function normalizeVisibility(Request $request, array $fields): array
|
||||
{
|
||||
return collect($fields)
|
||||
->mapWithKeys(fn (string $field): array => [$field => $request->boolean("profile_visibility.$field")])
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +71,11 @@ class ProviderProfileController extends Controller
|
||||
'bio' => ['nullable', 'string'],
|
||||
'service_area' => ['nullable', 'string', 'max:255'],
|
||||
'skills' => ['nullable', 'string'],
|
||||
'services_text' => ['nullable', 'string'],
|
||||
'tools' => ['nullable', 'string'],
|
||||
'tool_inventory_text' => ['nullable', 'string'],
|
||||
'certifications' => ['nullable', 'string'],
|
||||
'certification_records_text' => ['nullable', 'string'],
|
||||
'insurance_status' => ['nullable', 'string', 'max:255'],
|
||||
'rate_card' => ['nullable', 'string'],
|
||||
'travel_policy' => ['nullable', 'string'],
|
||||
@@ -80,9 +83,19 @@ class ProviderProfileController extends Controller
|
||||
'website_url' => ['nullable', 'url', 'max:255'],
|
||||
'phone' => ['nullable', 'string', 'max:255'],
|
||||
'public_contact' => ['nullable', 'boolean'],
|
||||
'profile_visibility' => ['nullable', 'array'],
|
||||
'profile_visibility.*' => ['nullable', 'boolean'],
|
||||
'private_notes' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
$data['public_contact'] = $request->boolean('public_contact');
|
||||
$data['services'] = $this->linesToRecords($data['services_text'] ?? '', ['name', 'level']);
|
||||
$data['tool_inventory'] = $this->linesToRecords($data['tool_inventory_text'] ?? '', ['name', 'category']);
|
||||
$data['certification_records'] = $this->linesToRecords($data['certification_records_text'] ?? '', ['name', 'issuer']);
|
||||
$data['profile_visibility'] = $this->normalizeVisibility($request, [
|
||||
'bio', 'services', 'tools', 'certifications', 'rate_card', 'availability', 'imports',
|
||||
]);
|
||||
unset($data['services_text'], $data['tool_inventory_text'], $data['certification_records_text']);
|
||||
|
||||
$request->user()->providerProfile()->updateOrCreate(
|
||||
['user_id' => $request->user()->id],
|
||||
@@ -98,4 +111,21 @@ class ProviderProfileController extends Controller
|
||||
'profile' => $provider->load('user', 'externalImports.attachments', 'attachments', 'ratings.user'),
|
||||
]);
|
||||
}
|
||||
|
||||
private function linesToRecords(string $text, array $keys): array
|
||||
{
|
||||
return collect(preg_split('/\r\n|\r|\n/', $text))
|
||||
->map(fn (string $line): array => array_pad(array_map('trim', explode('|', $line, count($keys))), count($keys), null))
|
||||
->filter(fn (array $parts): bool => (bool) ($parts[0] ?? null))
|
||||
->map(fn (array $parts): array => collect($keys)->mapWithKeys(fn (string $key, int $index): array => [$key => $parts[$index] ?? null])->all())
|
||||
->values()
|
||||
->all();
|
||||
}
|
||||
|
||||
private function normalizeVisibility(Request $request, array $fields): array
|
||||
{
|
||||
return collect($fields)
|
||||
->mapWithKeys(fn (string $field): array => [$field => $request->boolean("profile_visibility.$field")])
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,6 +121,14 @@ class QuoteController extends Controller
|
||||
'status' => 'assigned',
|
||||
'agreed_terms' => trim(($quote->rate_summary ?? '')."\n\n".($quote->terms ?? '')),
|
||||
'deliverables_checklist' => $quote->jobPost->deliverables,
|
||||
'scheduled_at' => $quote->jobPost->starts_at,
|
||||
'appointment_window' => $quote->jobPost->time_window,
|
||||
'checklist_items' => collect(preg_split('/\r\n|\r|\n/', (string) $quote->jobPost->deliverables))
|
||||
->map(fn (string $item): string => trim($item, " \t\n\r\0\x0B-[]"))
|
||||
->filter()
|
||||
->values()
|
||||
->all(),
|
||||
'required_evidence' => $quote->jobPost->deliverables,
|
||||
'status_history' => [[
|
||||
'status' => 'assigned',
|
||||
'user_id' => $request->user()->id,
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Models\WorkOrder;
|
||||
use App\Notifications\ExchangeEventNotification;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Arr;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class WorkOrderController extends Controller
|
||||
@@ -43,6 +44,21 @@ class WorkOrderController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function print(Request $request, WorkOrder $workOrder): View
|
||||
{
|
||||
$this->authorizeParticipant($request, $workOrder);
|
||||
|
||||
return view('work-orders.print', [
|
||||
'workOrder' => $workOrder->load(
|
||||
'jobPost',
|
||||
'buyer.buyerProfile',
|
||||
'provider.providerProfile',
|
||||
'acceptedQuote',
|
||||
'attachments',
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
public function transition(Request $request, WorkOrder $workOrder): RedirectResponse
|
||||
{
|
||||
$this->authorizeParticipant($request, $workOrder);
|
||||
@@ -50,6 +66,8 @@ class WorkOrderController extends Controller
|
||||
$data = $request->validate([
|
||||
'status' => ['required', 'string', 'in:'.implode(',', WorkOrder::STATUSES)],
|
||||
'completion_notes' => ['nullable', 'string'],
|
||||
'checklist_completed' => ['nullable', 'array'],
|
||||
'checklist_completed.*' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$status = $data['status'];
|
||||
@@ -76,6 +94,10 @@ class WorkOrderController extends Controller
|
||||
'status' => $status,
|
||||
'status_history' => $history,
|
||||
'completion_notes' => $data['completion_notes'] ?? $workOrder->completion_notes,
|
||||
'checklist_completed' => $this->normalizeChecklistCompletion(
|
||||
$workOrder,
|
||||
$data['checklist_completed'] ?? $workOrder->checklistCompleted()
|
||||
),
|
||||
];
|
||||
|
||||
if (isset($timestamps[$status]) && ! $workOrder->{$timestamps[$status]}) {
|
||||
@@ -98,6 +120,76 @@ class WorkOrderController extends Controller
|
||||
return redirect()->route('work-orders.show', $workOrder)->with('status', 'Work order updated.');
|
||||
}
|
||||
|
||||
public function updateDetails(Request $request, WorkOrder $workOrder): RedirectResponse
|
||||
{
|
||||
$this->authorizeParticipant($request, $workOrder);
|
||||
abort_unless($request->user()->id === $workOrder->buyer_id || $request->user()->hasRole('admin'), 403);
|
||||
|
||||
$data = $request->validate([
|
||||
'scheduled_at' => ['nullable', 'date'],
|
||||
'appointment_window' => ['nullable', 'string', 'max:255'],
|
||||
'agreed_terms' => ['nullable', 'string'],
|
||||
'deliverables_checklist' => ['nullable', 'string'],
|
||||
'required_evidence' => ['nullable', 'string'],
|
||||
'evidence_rules' => ['nullable', 'array'],
|
||||
'evidence_rules.*' => ['nullable', 'string', 'max:255'],
|
||||
]);
|
||||
|
||||
$checklistItems = collect(preg_split('/\r\n|\r|\n/', (string) ($data['deliverables_checklist'] ?? '')))
|
||||
->map(fn (string $item): string => trim($item, " \t\n\r\0\x0B-[]"))
|
||||
->filter()
|
||||
->values()
|
||||
->all();
|
||||
|
||||
$workOrder->update([
|
||||
'scheduled_at' => $data['scheduled_at'] ?? null,
|
||||
'appointment_window' => $data['appointment_window'] ?? null,
|
||||
'agreed_terms' => $data['agreed_terms'] ?? null,
|
||||
'deliverables_checklist' => $data['deliverables_checklist'] ?? null,
|
||||
'checklist_items' => $checklistItems,
|
||||
'checklist_completed' => $this->normalizeChecklistCompletion($workOrder, $workOrder->checklistCompleted(), $checklistItems),
|
||||
'required_evidence' => $data['required_evidence'] ?? null,
|
||||
'evidence_rules' => array_values(array_filter($data['evidence_rules'] ?? [])),
|
||||
]);
|
||||
|
||||
return redirect()->route('work-orders.show', $workOrder)->with('status', 'Work order details updated.');
|
||||
}
|
||||
|
||||
public function requestChange(Request $request, WorkOrder $workOrder): RedirectResponse
|
||||
{
|
||||
$this->authorizeParticipant($request, $workOrder);
|
||||
|
||||
$data = $request->validate([
|
||||
'summary' => ['required', 'string', 'max:255'],
|
||||
'details' => ['nullable', 'string'],
|
||||
]);
|
||||
|
||||
$requests = $workOrder->changeRequests();
|
||||
$requests[] = [
|
||||
'summary' => $data['summary'],
|
||||
'details' => $data['details'] ?? null,
|
||||
'requested_by_id' => $request->user()->id,
|
||||
'requested_by_name' => $request->user()->name,
|
||||
'status' => 'open',
|
||||
'requested_at' => now()->toIso8601String(),
|
||||
];
|
||||
|
||||
$workOrder->update(['change_requests' => $requests]);
|
||||
|
||||
$recipient = $request->user()->id === $workOrder->buyer_id
|
||||
? $workOrder->provider
|
||||
: $workOrder->buyer;
|
||||
|
||||
$recipient->notify(new ExchangeEventNotification(
|
||||
'Work order change requested',
|
||||
$request->user()->name.' requested a change on '.$workOrder->jobPost->title.'.',
|
||||
route('work-orders.show', $workOrder),
|
||||
'work_order_change_request'
|
||||
));
|
||||
|
||||
return redirect()->route('work-orders.show', $workOrder)->with('status', 'Change request recorded.');
|
||||
}
|
||||
|
||||
private function authorizeParticipant(Request $request, WorkOrder $workOrder): void
|
||||
{
|
||||
abort_unless(
|
||||
@@ -123,4 +215,13 @@ class WorkOrderController extends Controller
|
||||
abort_unless(in_array($userId, [$workOrder->buyer_id, $workOrder->provider_id], true) || $request->user()->hasRole('admin'), 403);
|
||||
}
|
||||
}
|
||||
|
||||
private function normalizeChecklistCompletion(WorkOrder $workOrder, array $completed, ?array $items = null): array
|
||||
{
|
||||
$items ??= $workOrder->checklistItems();
|
||||
|
||||
return collect($items)
|
||||
->mapWithKeys(fn (string $item): array => [$item => (bool) Arr::get($completed, $item, false)])
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user