53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
|
|
|
use App\Models\Order;
|
|
use App\Services\InvoiceService;
|
|
use Illuminate\Support\Facades\Route;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
// Test route to generate and view an invoice
|
|
// Usage: http://localhost:8000/test-invoice/{order_number}
|
|
Route::get('/test-invoice/{orderNumber}', function ($orderNumber) {
|
|
$order = Order::where('order_number', $orderNumber)->first();
|
|
|
|
if (!$order) {
|
|
return response()->json(['error' => 'Order not found'], 404);
|
|
}
|
|
|
|
try {
|
|
// Generate invoice
|
|
$invoicePath = InvoiceService::generateInvoice($order);
|
|
|
|
// Get the full path from public disk
|
|
$fullPath = storage_path('app/public/' . $invoicePath);
|
|
|
|
Log::info('Invoice test:', [
|
|
'order_number' => $orderNumber,
|
|
'stored_path' => $invoicePath,
|
|
'full_path' => $fullPath,
|
|
'file_exists' => file_exists($fullPath),
|
|
]);
|
|
|
|
if (file_exists($fullPath)) {
|
|
return response()->file($fullPath);
|
|
} else {
|
|
return response()->json([
|
|
'error' => 'Invoice file not found',
|
|
'path' => $invoicePath,
|
|
'full_path' => $fullPath,
|
|
], 500);
|
|
}
|
|
} catch (\Exception $e) {
|
|
Log::error('Invoice test error:', [
|
|
'order_number' => $orderNumber,
|
|
'error' => $e->getMessage(),
|
|
'trace' => $e->getTraceAsString(),
|
|
]);
|
|
|
|
return response()->json([
|
|
'error' => 'Failed to generate invoice',
|
|
'message' => $e->getMessage()
|
|
], 500);
|
|
}
|
|
})->name('test-invoice');
|