Files
pds/app/Http/Controllers/ProductionStickerReprintController.php
dhanabalan 7d5e02f491
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 10s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 11s
Gemini PR Review / review (pull_request) Failing after 23s
Laravel Pint / pint (pull_request) Successful in 2m23s
Laravel Larastan / larastan (pull_request) Failing after 3m49s
chnaged logic in sticker reprint logic
2025-12-18 16:21:10 +05:30

123 lines
2.9 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Item;
use App\Models\ProductionQuantity;
use App\Models\StickerMaster;
use Illuminate\Http\Request;
use Mpdf\Mpdf;
use Mpdf\QrCode\Output;
use Mpdf\QrCode\QrCode;
class ProductionStickerReprintController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
public function downloadQrPdf($palletNo)
{
$palletNo = urldecode($palletNo);
$parts = explode('|', $palletNo);
$itemCode = trim($parts[0]);
$serialNumberRaw = isset($parts[1]) ? trim($parts[1]) : null;
if ($serialNumberRaw != null) {
$serial = preg_replace('/\/.*/', '', $serialNumberRaw);
$serial = trim($serial);
} else {
$serial = null;
}
$item = Item::where('code', $itemCode)->first();
$itemId= $item->id;
if (!$item) {
abort(404, "Item with code {$itemCode} not found.");
}
$production = ProductionQuantity::where('item_id', $item->id)
->where('serial_number', $serial)
->first();
if (!$production) {
abort(404, "Production data for item code '{$itemCode}' with serial '{$serial}' not found.");
}
$productionOrder = $production->production_order ?? '';
if(!preg_match('/\//', $palletNo)){
if ($item->category == 'Submersible Motor')
{
$copies = 1;
}
elseif ($item->category == 'Submersible Pump')
{
$copies = 2;
}
}
else
{
if ($item->category == 'Submersible Motor')
{
$copies = 1;
}
elseif ($item->category == 'Submersible Pump')
{
$copies = 1;
}
}
$palletNo = preg_replace('/\/.*/', '', $palletNo);
// 5. Generate QR Code (base64)
$qrCode = new QrCode($palletNo);
$output = new Output\Png();
$qrBinary = $output->output($qrCode, 100); // 100 = size
$qrBase64 = base64_encode($qrBinary);
// 6. Return view
return view('print-qr', [
'qrBase64' => $qrBase64,
'serial' => $serial,
'productionOrder' => $productionOrder,
'item' => $item,
'copies'=> $copies,
]);
}
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(string $id)
{
//
}
}