SNYT ORDER PDF SOURCE REVIEW Generated: 2026-07-16 02:07:05 +04 ==================================================================================================== METHOD: App\Http\Controllers\CatalogController::orderPdf ==================================================================================================== File: /home/snyt/public_html/SubDomain/Catalog/app/Http/Controllers/CatalogController.php Lines: 289-348 ---------------------------------------------------------------------------------------------------- public function orderPdf(Request $request, Catalog $catalog) { $payload = json_decode($request->input('payload', '{}'), true); $cart = collect($payload['items'] ?? []) ->map(function ($row) { return [ 'id' => $row['id'] ?? $row['catalog_item_id'] ?? null, 'sku' => $row['sku'] ?? null, 'barcode' => $row['barcode'] ?? null, 'qty' => max(1, (int) ($row['qty'] ?? 1)), ]; }) ->filter(fn ($row) => $row['id'] || $row['sku'] || $row['barcode']) ->values(); abort_if($cart->isEmpty(), 422, 'Order cart is empty.'); $items = collect(); foreach ($cart as $cartRow) { $query = CatalogItem::query() ->where('catalog_id', $catalog->id) ->with('product'); if ($cartRow['id']) { $query->where('id', $cartRow['id']); } elseif ($cartRow['sku']) { $query->where('sku', $cartRow['sku']); } elseif ($cartRow['barcode']) { $query->where('barcode', $cartRow['barcode']); } $item = $query->first(); if ($item) { $item->order_qty = $cartRow['qty']; $item->line_total = ((float) $item->price) * $cartRow['qty']; $items->push($item); } } abort_if($items->isEmpty(), 422, 'No matching catalog items found.'); $customer = [ 'name' => $payload['customer_name'] ?? '-', 'phone' => $payload['customer_phone'] ?? '-', 'company' => $payload['company_name'] ?? '-', 'notes' => $payload['notes'] ?? '-', ]; $pdf = Pdf::loadView('catalogs.order-pdf', [ 'catalog' => $catalog, 'items' => $items, 'customer' => $customer, 'company' => \App\Models\CompanySetting::current(), ])->setPaper('a4', 'portrait'); return $pdf->stream('order_' . $catalog->id . '_' . now()->format('Ymd_His') . '.pdf'); } ==================================================================================================== METHOD: App\Http\Controllers\CatalogController::customerView ==================================================================================================== File: /home/snyt/public_html/SubDomain/Catalog/app/Http/Controllers/CatalogController.php Lines: 498-514 ---------------------------------------------------------------------------------------------------- public function customerView($catalog) { $catalogRow = Catalog::query() ->whereKey($catalog) ->orWhere('public_token', $catalog) ->firstOrFail(); abort_unless($catalogRow->isPubliclyShareable(), 404); if (empty($catalogRow->public_token)) { $catalogRow->update([ 'public_token' => Str::random(32), ]); } return $this->renderCustomerCatalog($catalogRow); } ==================================================================================================== METHOD: App\Http\Controllers\CatalogController::customerViewByToken ==================================================================================================== File: /home/snyt/public_html/SubDomain/Catalog/app/Http/Controllers/CatalogController.php Lines: 517-526 ---------------------------------------------------------------------------------------------------- public function customerViewByToken($token) { $catalogRow = Catalog::query() ->where('public_token', $token) ->firstOrFail(); abort_unless($catalogRow->isPubliclyShareable(), 404); return $this->renderCustomerCatalog($catalogRow); } ==================================================================================================== ROUTE DEFINITION IN routes/web.php ==================================================================================================== 31- ->name('portal.area'); 32- 33-/* 34-|-------------------------------------------------------------------------- 35-| Public Customer Catalog Routes 36-|-------------------------------------------------------------------------- 37-*/ 38- 39:Route::post('/catalogs/{catalog}/order-pdf', [CatalogController::class, 'orderPdf']) 40: ->name('catalogs.order-pdf'); 41- 42-Route::get('/catalogs/{catalog}/customer', [CatalogController::class, 'customerView']) 43- ->name('catalogs.customer'); 44- 45-Route::get('/catalog/{token}/customer', [CatalogController::class, 'customerViewByToken']) 46- ->name('catalogs.customer-token'); 47- 48-Route::middleware(['auth'])->group(function () { ==================================================================================================== VIEWS / JAVASCRIPT USING THE ORDER PDF ROUTE ==================================================================================================== resources/views/catalogs/customer.blade.php-21- company_name: document.getElementById('companyName')?.value || '', resources/views/catalogs/customer.blade.php-22- notes: document.getElementById('notes')?.value || '', resources/views/catalogs/customer.blade.php-23- items: cart.map(item => ({ resources/views/catalogs/customer.blade.php-24- id: item.id || item.catalog_item_id || null, resources/views/catalogs/customer.blade.php-25- sku: item.sku || null, resources/views/catalogs/customer.blade.php-26- barcode: item.barcode || null, resources/views/catalogs/customer.blade.php-27- qty: item.qty || 1 resources/views/catalogs/customer.blade.php-28- })) resources/views/catalogs/customer.blade.php-29- }; resources/views/catalogs/customer.blade.php-30- resources/views/catalogs/customer.blade.php-31- const form = document.createElement('form'); resources/views/catalogs/customer.blade.php-32- form.method = 'POST'; resources/views/catalogs/customer.blade.php:33: form.action = @json(route('catalogs.order-pdf', ['catalog' => $catalog->id])); resources/views/catalogs/customer.blade.php-34- form.target = '_blank'; resources/views/catalogs/customer.blade.php-35- resources/views/catalogs/customer.blade.php-36- form.innerHTML = ` resources/views/catalogs/customer.blade.php-37- resources/views/catalogs/customer.blade.php-38- resources/views/catalogs/customer.blade.php-39- `; resources/views/catalogs/customer.blade.php-40- resources/views/catalogs/customer.blade.php-41- document.body.appendChild(form); resources/views/catalogs/customer.blade.php-42- form.submit(); resources/views/catalogs/customer.blade.php-43- form.remove(); resources/views/catalogs/customer.blade.php-44- }); resources/views/catalogs/customer.blade.php-45-})(); -- app/Http/Controllers/CatalogController.php-277- 'pdf_file' => $filename, app/Http/Controllers/CatalogController.php-278- 'status' => 'pdf_generated', app/Http/Controllers/CatalogController.php-279- ]); app/Http/Controllers/CatalogController.php-280- app/Http/Controllers/CatalogController.php-281- return back()->with( app/Http/Controllers/CatalogController.php-282- 'success', app/Http/Controllers/CatalogController.php-283- 'PDF generated successfully.' app/Http/Controllers/CatalogController.php-284- ); app/Http/Controllers/CatalogController.php-285- } app/Http/Controllers/CatalogController.php-286- app/Http/Controllers/CatalogController.php-287- app/Http/Controllers/CatalogController.php-288- app/Http/Controllers/CatalogController.php:289: public function orderPdf(Request $request, Catalog $catalog) app/Http/Controllers/CatalogController.php-290- { app/Http/Controllers/CatalogController.php-291- $payload = json_decode($request->input('payload', '{}'), true); app/Http/Controllers/CatalogController.php-292- app/Http/Controllers/CatalogController.php-293- $cart = collect($payload['items'] ?? []) app/Http/Controllers/CatalogController.php-294- ->map(function ($row) { app/Http/Controllers/CatalogController.php-295- return [ app/Http/Controllers/CatalogController.php-296- 'id' => $row['id'] ?? $row['catalog_item_id'] ?? null, app/Http/Controllers/CatalogController.php-297- 'sku' => $row['sku'] ?? null, app/Http/Controllers/CatalogController.php-298- 'barcode' => $row['barcode'] ?? null, app/Http/Controllers/CatalogController.php-299- 'qty' => max(1, (int) ($row['qty'] ?? 1)), app/Http/Controllers/CatalogController.php-300- ]; app/Http/Controllers/CatalogController.php-301- }) -- app/Http/Controllers/CatalogController.php-328- } app/Http/Controllers/CatalogController.php-329- } app/Http/Controllers/CatalogController.php-330- app/Http/Controllers/CatalogController.php-331- abort_if($items->isEmpty(), 422, 'No matching catalog items found.'); app/Http/Controllers/CatalogController.php-332- app/Http/Controllers/CatalogController.php-333- $customer = [ app/Http/Controllers/CatalogController.php-334- 'name' => $payload['customer_name'] ?? '-', app/Http/Controllers/CatalogController.php-335- 'phone' => $payload['customer_phone'] ?? '-', app/Http/Controllers/CatalogController.php-336- 'company' => $payload['company_name'] ?? '-', app/Http/Controllers/CatalogController.php-337- 'notes' => $payload['notes'] ?? '-', app/Http/Controllers/CatalogController.php-338- ]; app/Http/Controllers/CatalogController.php-339- app/Http/Controllers/CatalogController.php:340: $pdf = Pdf::loadView('catalogs.order-pdf', [ app/Http/Controllers/CatalogController.php-341- 'catalog' => $catalog, app/Http/Controllers/CatalogController.php-342- 'items' => $items, app/Http/Controllers/CatalogController.php-343- 'customer' => $customer, app/Http/Controllers/CatalogController.php-344- 'company' => \App\Models\CompanySetting::current(), app/Http/Controllers/CatalogController.php-345- ])->setPaper('a4', 'portrait'); app/Http/Controllers/CatalogController.php-346- app/Http/Controllers/CatalogController.php-347- return $pdf->stream('order_' . $catalog->id . '_' . now()->format('Ymd_His') . '.pdf'); app/Http/Controllers/CatalogController.php-348- } app/Http/Controllers/CatalogController.php-349- app/Http/Controllers/CatalogController.php-350- app/Http/Controllers/CatalogController.php-351- public function bulkDestroy(Request $request) app/Http/Controllers/CatalogController.php-352- { -- app/Http/Controllers/SalesmanCatalogController.php-36- DB::raw('products.category as category'), app/Http/Controllers/SalesmanCatalogController.php-37- DB::raw('products.specification as specification'), app/Http/Controllers/SalesmanCatalogController.php-38- DB::raw('products.main_image as image'), app/Http/Controllers/SalesmanCatalogController.php-39- DB::raw('COALESCE(NULLIF(products.van_sales_price, 0), NULLIF(products.default_van_sales_price, 0), 0) as price') app/Http/Controllers/SalesmanCatalogController.php-40- ) app/Http/Controllers/SalesmanCatalogController.php-41- ->orderBy('products.category') app/Http/Controllers/SalesmanCatalogController.php-42- ->orderBy('products.name') app/Http/Controllers/SalesmanCatalogController.php-43- ->get(); app/Http/Controllers/SalesmanCatalogController.php-44- } app/Http/Controllers/SalesmanCatalogController.php-45- app/Http/Controllers/SalesmanCatalogController.php-46- /* app/Http/Controllers/SalesmanCatalogController.php-47- * The customer view needs a real numeric catalog ID for: app/Http/Controllers/SalesmanCatalogController.php:48: * POST /catalogs/{catalog}/order-pdf app/Http/Controllers/SalesmanCatalogController.php-49- * app/Http/Controllers/SalesmanCatalogController.php-50- * Do not use a virtual ID such as "salesman-2", because Laravel app/Http/Controllers/SalesmanCatalogController.php-51- * route model binding expects an existing row from catalogs. app/Http/Controllers/SalesmanCatalogController.php-52- */ app/Http/Controllers/SalesmanCatalogController.php-53- $permanentCatalog = DB::table('catalogs') app/Http/Controllers/SalesmanCatalogController.php-54- ->where(function ($query) use ($user) { app/Http/Controllers/SalesmanCatalogController.php-55- $query->where('permanent_key', 'salesman_' . $user->id) app/Http/Controllers/SalesmanCatalogController.php-56- ->orWhere(function ($query) use ($user) { app/Http/Controllers/SalesmanCatalogController.php-57- $query->where('source_type', 'van_stock') app/Http/Controllers/SalesmanCatalogController.php-58- ->where(function ($query) use ($user) { app/Http/Controllers/SalesmanCatalogController.php-59- $query->where('catalog_owner_user_id', $user->id) app/Http/Controllers/SalesmanCatalogController.php-60- ->orWhere('user_id', $user->id); -- routes/web.php-27-Route::get('/', [PublicPortalController::class, 'index']) routes/web.php-28- ->name('portal.index'); routes/web.php-29- routes/web.php-30-Route::get('/area/{slug}', [PublicPortalController::class, 'area']) routes/web.php-31- ->name('portal.area'); routes/web.php-32- routes/web.php-33-/* routes/web.php-34-|-------------------------------------------------------------------------- routes/web.php-35-| Public Customer Catalog Routes routes/web.php-36-|-------------------------------------------------------------------------- routes/web.php-37-*/ routes/web.php-38- routes/web.php:39:Route::post('/catalogs/{catalog}/order-pdf', [CatalogController::class, 'orderPdf']) routes/web.php:40: ->name('catalogs.order-pdf'); routes/web.php-41- routes/web.php-42-Route::get('/catalogs/{catalog}/customer', [CatalogController::class, 'customerView']) routes/web.php-43- ->name('catalogs.customer'); routes/web.php-44- routes/web.php-45-Route::get('/catalog/{token}/customer', [CatalogController::class, 'customerViewByToken']) routes/web.php-46- ->name('catalogs.customer-token'); routes/web.php-47- routes/web.php-48-Route::middleware(['auth'])->group(function () { routes/web.php-49- routes/web.php-50- Route::get('/dashboard', [DashboardController::class, 'index']) routes/web.php-51- ->name('dashboard'); routes/web.php-52- ==================================================================================================== CART PAYLOAD / CUSTOMER DATA REFERENCES ==================================================================================================== resources/views/catalogs/customer-redesign.blade.php-30-
resources/views/catalogs/customer-redesign.blade.php-31- {{ $items->where('qty', '>', 0)->count() }} products resources/views/catalogs/customer-redesign.blade.php-32- @if(!empty($latestImport?->updated_at)) resources/views/catalogs/customer-redesign.blade.php-33- • Updated {{ \Carbon\Carbon::parse($latestImport->updated_at)->format('Y-m-d H:i') }} resources/views/catalogs/customer-redesign.blade.php-34- @endif resources/views/catalogs/customer-redesign.blade.php-35-
resources/views/catalogs/customer-redesign.blade.php-36- resources/views/catalogs/customer-redesign.blade.php-37- resources/views/catalogs/customer-redesign.blade.php:38: resources/views/catalogs/customer-redesign.blade.php-42- resources/views/catalogs/customer-redesign.blade.php-43- resources/views/catalogs/customer-redesign.blade.php-44-