generatePdf: serve uploaded conclusion file instead of system-generated PDF
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -287,53 +287,23 @@ class AutoController extends Controller
|
||||
|
||||
public function generatePdf($id)
|
||||
{
|
||||
$order = DB::table('auto_orders as o')
|
||||
->selectRaw('o.*, p.uz as purpose, c.uz as category, CONCAT_WS(\' \', o.owner_last_name, o.owner_first_name, o.owner_patronymic) as "ownerName"')
|
||||
->leftJoin('purposes as p', 'p.id', '=', 'o.purpose_id')
|
||||
->leftJoin('concerns as c', 'c.id', '=', 'o.car_category')
|
||||
->where('o.id', $id)
|
||||
// If uploaded conclusion exists — serve it directly
|
||||
$conclusionFile = DB::table('files')
|
||||
->where('order_id', $id)
|
||||
->where('order_type', 'conclusion_')
|
||||
->orderByDesc('created_at')
|
||||
->first();
|
||||
|
||||
if (!$order) {
|
||||
abort(404);
|
||||
if ($conclusionFile) {
|
||||
$path = storage_path('app/public' . str_replace('/storage', '', $conclusionFile->path));
|
||||
if (file_exists($path)) {
|
||||
return response()->file($path, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'attachment; filename="' . $conclusionFile->name . '.pdf"',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf = new Fpdi();
|
||||
$pdf->AddPage();
|
||||
|
||||
// Add Title
|
||||
$pdf->SetFont('Arial', 'B', 16);
|
||||
$pdf->Cell(0, 10, 'BAXOLASH XULOSASI (AVTO)', 0, 1, 'C');
|
||||
$pdf->Ln(10);
|
||||
|
||||
// Add Details
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
|
||||
$fields = [
|
||||
'Tartib raqami' => $order->number,
|
||||
'Sana' => date('d.m.Y', strtotime($order->created_at)),
|
||||
'Maqsadi' => $order->purpose,
|
||||
'Kategoriya' => $order->category,
|
||||
'Markasi' => $order->car_mark,
|
||||
'Davlat raqami' => $order->car_number,
|
||||
'Egasi' => $order->ownerName,
|
||||
'Ishlab chiqarilgan yili' => $order->made_date,
|
||||
'Baholangan summa' => number_format($order->object_price ?: 0, 0, '.', ' ') . ' UZS',
|
||||
];
|
||||
|
||||
foreach ($fields as $label => $value) {
|
||||
$pdf->SetFont('Arial', 'B', 12);
|
||||
$pdf->Cell(60, 10, $label . ':', 0, 0);
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->Cell(0, 10, $value ?: '-', 0, 1);
|
||||
}
|
||||
|
||||
$pdf->Ln(20);
|
||||
$pdf->SetFont('Arial', 'I', 10);
|
||||
$pdf->Cell(0, 10, 'Ushbu hujjat tizim tomonidan avtomatik generatsiya qilindi.', 0, 1, 'C');
|
||||
|
||||
return response($pdf->Output('S'), 200)
|
||||
->header('Content-Type', 'application/pdf')
|
||||
->header('Content-Disposition', 'attachment; filename="Conclusion_'.$order->number.'.pdf"');
|
||||
abort(404, 'Xulosa fayli topilmadi');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,49 +238,24 @@ class EstateController extends Controller
|
||||
|
||||
public function generatePdf($id)
|
||||
{
|
||||
$order = DB::table('estate_orders as o')
|
||||
->selectRaw('o.*, p.uz as purpose, r.uz as region_name, d.uz as district_name, CONCAT_WS(\' \', o.owner_last_name, o.owner_first_name, o.owner_patronymic) as "ownerName"')
|
||||
->leftJoin('purposes as p', 'p.id', '=', 'o.purpose_id')
|
||||
->leftJoin('regions as r', 'r.id', '=', 'o.region')
|
||||
->leftJoin('districts as d', 'd.id', '=', 'o.district')
|
||||
->where('o.id', $id)
|
||||
// If uploaded conclusion exists — serve it directly
|
||||
$conclusionFile = DB::table('files')
|
||||
->where('order_id', $id)
|
||||
->where('order_type', 'conclusion_')
|
||||
->orderByDesc('created_at')
|
||||
->first();
|
||||
|
||||
if (!$order) abort(404);
|
||||
|
||||
$pdf = new \setasign\Fpdi\Fpdi();
|
||||
$pdf->AddPage();
|
||||
$pdf->SetFont('Arial', 'B', 16);
|
||||
$pdf->Cell(0, 10, 'BAXOLASH XULOSASI (KO\'CHMAS MULK)', 0, 1, 'C');
|
||||
$pdf->Ln(10);
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
|
||||
$fields = [
|
||||
'Tartib raqami' => $order->number,
|
||||
'Sana' => date('d.m.Y', strtotime($order->created_at)),
|
||||
'Maqsadi' => $order->purpose,
|
||||
'Ob\'yekt nomi' => $order->name_of_object,
|
||||
'Viloyat' => $order->region_name,
|
||||
'Tuman' => $order->district_name,
|
||||
'Manzil' => $order->address,
|
||||
'Egasi' => $order->ownerName,
|
||||
'Baholangan summa'=> number_format($order->object_price ?: 0, 0, '.', ' ') . ' UZS',
|
||||
];
|
||||
|
||||
foreach ($fields as $label => $value) {
|
||||
$pdf->SetFont('Arial', 'B', 12);
|
||||
$pdf->Cell(60, 10, $label . ':', 0, 0);
|
||||
$pdf->SetFont('Arial', '', 12);
|
||||
$pdf->Cell(0, 10, $value ?: '-', 0, 1);
|
||||
if ($conclusionFile) {
|
||||
$path = storage_path('app/public' . str_replace('/storage', '', $conclusionFile->path));
|
||||
if (file_exists($path)) {
|
||||
return response()->file($path, [
|
||||
'Content-Type' => 'application/pdf',
|
||||
'Content-Disposition' => 'attachment; filename="' . $conclusionFile->name . '.pdf"',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf->Ln(20);
|
||||
$pdf->SetFont('Arial', 'I', 10);
|
||||
$pdf->Cell(0, 10, 'Ushbu hujjat tizim tomonidan avtomatik generatsiya qilindi.', 0, 1, 'C');
|
||||
|
||||
return response($pdf->Output('S'), 200)
|
||||
->header('Content-Type', 'application/pdf')
|
||||
->header('Content-Disposition', 'attachment; filename="Conclusion_'.$order->number.'.pdf"');
|
||||
abort(404, 'Xulosa fayli topilmadi');
|
||||
}
|
||||
|
||||
public function showDocuments($order, Request $request)
|
||||
|
||||
Reference in New Issue
Block a user