Diversen
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\ServiceRequest;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Communication;
|
||||
use App\Mail\ServiceRequestNotification;
|
||||
use App\Mail\PickupConfirmation;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
@@ -115,11 +116,11 @@ class ServiceRequestController extends Controller
|
||||
$validated = $request->validate([
|
||||
'actual_repair_date' => 'nullable|date|after:today',
|
||||
'actual_repair_time' => 'nullable|date_format:H:i',
|
||||
'status' => 'nullable|in:pending,confirmed,completed,cancelled',
|
||||
'status' => 'nullable|in:pending,confirmed,mail_sent,completed,cancelled',
|
||||
], [
|
||||
'actual_repair_date.after' => 'Werkelijke reparatie datum moet in de toekomst liggen',
|
||||
'actual_repair_time.date_format' => 'Werkelijke reparatie tijd moet een geldig tijdformaat hebben (HH:MM)',
|
||||
'status.in' => 'Status moet een van de volgende waarden hebben: in afwachting, bevestigd, voltooid, geannuleerd',
|
||||
'status.in' => 'Status moet een van de volgende waarden hebben: in afwachting, bevestigd, bevestigd mail verstuurd, voltooid, geannuleerd',
|
||||
]);
|
||||
|
||||
$serviceRequest->update($validated);
|
||||
@@ -252,6 +253,74 @@ class ServiceRequestController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send pickup confirmation email to customer
|
||||
*/
|
||||
public function sendPickupConfirmation(ServiceRequest $serviceRequest): JsonResponse
|
||||
{
|
||||
try {
|
||||
if (empty($serviceRequest->email)) {
|
||||
return response()->json([
|
||||
'message' => 'Geen e-mailadres beschikbaar voor deze service aanvraag'
|
||||
], 400);
|
||||
}
|
||||
|
||||
if (empty($serviceRequest->actual_repair_date) || empty($serviceRequest->actual_repair_time)) {
|
||||
return response()->json([
|
||||
'message' => 'Werkelijke reparatie datum en tijd zijn vereist'
|
||||
], 400);
|
||||
}
|
||||
|
||||
// Get the custom message from settings
|
||||
$customMessage = Setting::getValue('pickup_confirmation_email_text', 'Uw fiets is klaar en kan worden opgehaald.');
|
||||
|
||||
// Format the pickup date and time
|
||||
$pickupDate = \Carbon\Carbon::parse($serviceRequest->actual_repair_date)->format('d-m-Y');
|
||||
$pickupTime = $serviceRequest->actual_repair_time;
|
||||
|
||||
// Send email
|
||||
Mail::to($serviceRequest->email)->send(
|
||||
new PickupConfirmation(
|
||||
$serviceRequest,
|
||||
$customMessage,
|
||||
$pickupDate,
|
||||
$pickupTime
|
||||
)
|
||||
);
|
||||
|
||||
// Update status to 'mail_sent'
|
||||
$serviceRequest->update(['status' => 'mail_sent']);
|
||||
|
||||
// Store communication record
|
||||
$communication = Communication::create([
|
||||
'service_request_id' => $serviceRequest->id,
|
||||
'type' => 'email',
|
||||
'message' => 'Ophaalbevestiging verzonden - Datum: ' . $pickupDate . ', Tijd: ' . $pickupTime,
|
||||
'direction' => 'admin_to_customer',
|
||||
'recipient' => $serviceRequest->email,
|
||||
'sent_at' => now(),
|
||||
]);
|
||||
|
||||
Log::info('Ophaalbevestiging e-mail verzonden naar klant', [
|
||||
'service_request_id' => $serviceRequest->id,
|
||||
'email' => $serviceRequest->email,
|
||||
'pickup_date' => $pickupDate,
|
||||
'pickup_time' => $pickupTime
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'message' => 'Ophaalbevestiging succesvol verzonden',
|
||||
'communication' => $communication,
|
||||
'service_request' => $serviceRequest->fresh()
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
'message' => 'Ophaalbevestiging verzenden mislukt',
|
||||
'error' => $e->getMessage()
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get communication history
|
||||
*/
|
||||
@@ -261,7 +330,7 @@ class ServiceRequestController extends Controller
|
||||
$communications = $serviceRequest->communications()
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
|
||||
return response()->json($communications);
|
||||
} catch (\Exception $e) {
|
||||
return response()->json([
|
||||
|
||||
Reference in New Issue
Block a user