Files
pds/app/Http/Controllers/ProductionOrderController.php
dhanabalan 2d19661364
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 16s
Gemini PR Review / Gemini PR Review (pull_request) Failing after 20s
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Successful in 18s
Laravel Pint / pint (pull_request) Successful in 2m1s
Laravel Larastan / larastan (pull_request) Failing after 6m42s
changed print panel box 2 button logic in produciton order
2026-11-25 16:54:08 +05:30

404 lines
12 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Models\Plant;
use App\Models\ProductionOrder;
use Carbon\Carbon;
use Illuminate\Http\Request;
// use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Illuminate\Support\Facades\Log;
use Mpdf\QrCode\QrCode;
use Mpdf\QrCode\Output;
use Barryvdh\DomPDF\Facade\Pdf;
use App\Exports\SerialExport;
use Maatwebsite\Excel\Facades\Excel;
class ProductionOrderController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
public function print($production_order)
{
$order = ProductionOrder::where('production_order', $production_order)->first();
if (!$order) {
abort(404, 'Production Order not found');
}
else{
$fromSerial = (int) $order->from_serial_number;
$toSerial = (int) $order->to_serial_number;
$itemCode = $order->item->code ?? '';
$itemDes = $order->item->description ?? '';
$stickers = [];
for ($i = $fromSerial; $i <= $toSerial; $i++)
{
$serial = str_pad($i, 6, '0', STR_PAD_LEFT);
$qrData = $itemCode . '|' . $serial;
// $qrBase64 = base64_encode(
// QrCode::format('png')->size(100)->generate($qrData)
// );
$qrCode = new QrCode($qrData);
$output = new Output\Png;
// $qrBinary = $output->output($qrCode, 100);
$qrBinary = $output->output($qrCode, 100);
$qrBase64 = base64_encode($qrBinary);
$stickers[] = [
'serial' => $serial,
'qr' => 'data:image/png;base64,' . $qrBase64,
'production_order' => $production_order,
'description' => $itemDes ?? ''
];
}
$pdf = Pdf::loadView('production-orders.print', compact('stickers'))
->setPaper([0, 0, 170, 40]);
return $pdf->stream('stickers.pdf');
}
}
public function printpanel($production_order, $plantCode){
\Log::info('Print Panel Started', [
'production_order' => $production_order,
'plantCode' => $plantCode,
]);
$order = ProductionOrder::where('production_order', $production_order)->first();
$wareHouseNo = Plant::where('code', $plantCode)->first();
$wareNo = $wareHouseNo->warehouse_number ?? null;
\Log::info('Plant Data', [
'plant' => $wareHouseNo ? $wareHouseNo->toArray() : null,
]);
\Log::info('Warehouse Number', [
'warehouse_number' => $wareNo,
'final_code' => $plantCode . $wareNo,
]);
if (!$order) {
abort(404, 'Production Order not found');
}
else{
$fromSerial = (int) $order->from_serial_number;
$toSerial = (int) $order->to_serial_number;
$itemCode = $order->item->code ?? '';
$itemDes = $order->item->description ?? '';
$now = Carbon::now();
$year = $now->format('y');
// $month = $now->format('m');
// $month = $now->format('m');
$stickers = [];
for ($i = $fromSerial; $i <= $toSerial; $i++)
{
$currentSerial = (string) $i;
$year = substr($currentSerial, -10, 2);
$month = substr($currentSerial, -8, 2);
$serial = str_pad($i, 6, '0', STR_PAD_LEFT);
$serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6);
$qrData = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount;
$panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount;
$qrCode = new QrCode($qrData);
$output = new Output\Png;
$qrBinary = $output->output($qrCode, 100);
$qrBase64 = base64_encode($qrBinary);
$stickers[] = [
'serial' => $panel,
'qr' => 'data:image/png;base64,' . $qrBase64,
'production_order' => $production_order,
'description' => $itemDes ?? ''
];
}
$pdf = Pdf::loadView('production-orders.printpanel', compact('stickers'))
->setPaper([0, 0, 113.39, 113.39]);
return $pdf->stream('stickers.pdf');
}
}
// public function printpanel2($production_order, $plantCode){
// $order = ProductionOrder::where('production_order', $production_order)->first();
// $wareHouseNo = Plant::where('code', $plantCode)->first();
// $wareNo = $wareHouseNo->warehouse_number ?? null;
// if (!$order) {
// abort(404, 'Production Order not found');
// }
// else{
// $fromSerial = (int) $order->from_serial_number;
// $toSerial = (int) $order->to_serial_number;
// $itemCode = $order->item->code ?? '';
// $itemDes = $order->item->description ?? '';
// $now = Carbon::now();
// $year = $now->format('y');
// // $month = $now->format('m');
// // $month = $now->format('m');
// // $stickers = [];
// // for ($i = $fromSerial; $i <= $toSerial; $i++)
// // {
// // $currentSerial = (string) $i;
// // $year = substr($currentSerial, -10, 2);
// // $month = substr($currentSerial, -8, 2);
// // $serial = str_pad($i, 6, '0', STR_PAD_LEFT);
// // $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6);
// // $qrData = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount;
// // $panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount;
// // $qrCode = new QrCode($qrData);
// // $output = new Output\Png;
// // $qrBinary = $output->output($qrCode, 100);
// // $qrBase64 = base64_encode($qrBinary);
// // $stickers[] = [
// // 'serial' => $panel,
// // 'qr' => 'data:image/png;base64,' . $qrBase64,
// // 'production_order' => $production_order,
// // 'description' => $itemDes ?? ''
// // ];
// // }
// $pdf = Pdf::loadView('production-orders.printpanel2', compact('stickers'))
// ->setPaper([0, 0, 113.39, 113.39]);
// return $pdf->stream('stickers.pdf');
// }
// }
public function printpanel2($production_order, $plantCode)
{
$order = ProductionOrder::where('production_order', $production_order)->first();
if (!$order) {
abort(404, 'Production Order not found');
}
$fromSerial = (int) $order->from_serial_number;
$toSerial = (int) $order->to_serial_number;
$itemCode = $order->item->code ?? '';
$itemDes = $order->item->description ?? '';
$stickers = [];
for ($i = $fromSerial; $i <= $toSerial; $i += 2) {
$row = [];
for ($j = 0; $j < 2; $j++) {
$current = $i + $j;
if ($current > $toSerial) {
break;
}
// Original encoded serial number
$currentSerial = (string) $current;
// Extract year and month
$year = substr($currentSerial, -10, 2);
$month = substr($currentSerial, -8, 2);
// Extract only the last 6 digits
$serialCount = substr($currentSerial, -6);
// QR format: PlantCode/ItemCode/YearMonth/Serial
$qrData = $plantCode . '/' .
$itemCode . '/' .
$year . $month . '/' .
$serialCount;
// Generate QR code
$qrCode = new QrCode($qrData);
$output = new Output\Png;
$qrBinary = $output->output($qrCode, 100);
$qrBase64 = base64_encode($qrBinary);
$row[] = [
'serial' => $qrData,
'qr' => 'data:image/png;base64,' . $qrBase64,
'production_order' => $production_order,
'description' => $itemDes,
];
}
$stickers[] = $row;
}
$pdf = Pdf::loadView(
'production-orders.printpanel2',
compact('stickers')
)->setPaper([0, 0, 113.39, 113.39]);
return $pdf->stream('stickers.pdf');
}
public function printitemserial($production_order, $plantCode)
{
$order = ProductionOrder::where('production_order', $production_order)->first();
if (!$order) {
abort(404, 'Production Order not found');
}
else{
$fromSerial = (int) $order->from_serial_number;
$toSerial = (int) $order->to_serial_number;
$itemCode = $order->item->code ?? '';
$itemDes = $order->item->description ?? '';
$wareHouseNo = Plant::where('code', $plantCode)->first();
$wareNo = $wareHouseNo->warehouse_number ?? null;
$now = Carbon::now();
$year = $now->format('y');
$month = $now->format('m');
$stickers = [];
for ($i = $fromSerial; $i <= $toSerial; $i++)
{
$serial = str_pad($i, 6, '0', STR_PAD_LEFT);
if(!empty($wareNo)){
$serial = substr($serial, 0, 4) . $wareNo . substr($serial, 4);
$qrData = $itemCode . '|' . $serial;
} else {
$qrData = $itemCode . '|' . $serial;
$serial = str_pad($i, 6, '0', STR_PAD_LEFT);
}
// $qrData = $itemCode . '|' . $serial;
// $serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -6);
// $serialWithWarehouse = substr($serial, 0, 4) . $wareNo . substr($serial, 4);
// $qrData = $itemCode . '|' . $serialWithWarehouse;
// $panel = $plantCode . $wareNo . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount;
// $qrBase64 = base64_encode(
// QrCode::format('png')->size(100)->generate($qrData)
// );
$qrCode = new QrCode($qrData);
$output = new Output\Png;
// $qrBinary = $output->output($qrCode, 100);
$qrBinary = $output->output($qrCode, 100);
$qrBase64 = base64_encode($qrBinary);
$stickers[] = [
'serial' => $serial,
'qr' => 'data:image/png;base64,' . $qrBase64,
'production_order' => $itemCode,
'description' => $itemDes ?? ''
];
}
$pdf = Pdf::loadView('production-orders.printItemSerial', compact('stickers'))
->setPaper([0, 0, 170, 40]);
return $pdf->stream('stickers.pdf');
}
}
public function exportSerial($production_order, $plantCode, $fromSerialNo, $toSerialNo){
$order = ProductionOrder::where('production_order', $production_order)->first();
if (!$order) {
abort(404, 'Production Order not found');
}
else{
return Excel::download(
new SerialExport(
$order->item->code,
$fromSerialNo,
$toSerialNo
),
'serial_numbers.xlsx'
);
}
}
/**
* Store a newly created resource in storage.
*/
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)
{
//
}
}