Merge pull request 'Adde panel box qr code logic fro production order screen' (#566) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

Reviewed-on: #566
This commit was merged in pull request #566.
This commit is contained in:
2026-05-06 12:31:39 +00:00
7 changed files with 368 additions and 41 deletions

View File

@@ -45,7 +45,8 @@ class ProductionOrderResource extends Resource
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
})
->disabled(fn (Get $get) => ! empty($get('id')))
->disabled(fn (string $context): bool => $context == 'edit')
->dehydrated(true)
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
@@ -84,7 +85,7 @@ class ProductionOrderResource extends Resource
->default(function () {
$userHas = Filament::auth()->user()->plant_id;
return ($userHas && strlen($userHas) > 0) ? optional(ProductionOrder::where('plant_id', $userHas)->latest()->first())->plant_id : optional(ProductionOrder::latest()->first())->plant_id;
return ($userHas && strlen($userHas) > 0) ? optional(ProductionOrder::where('plant_id', $userHas)->latest()->first())->item_id : optional(ProductionOrder::latest()->first())->item_id;
})
->required()
->afterStateUpdated(function ($state, callable $set) {
@@ -102,6 +103,7 @@ class ProductionOrderResource extends Resource
->integer()
->required()
->readOnly(fn ($get) => ($get('plant_id') == null || $get('item_id') == null))
->disabled(fn (string $context): bool => $context === 'edit')
->afterStateUpdated(function ($state, callable $set, $get) {
if (! empty($state) && $state > 0) {
$set('show_extra_fields', true);
@@ -170,21 +172,39 @@ class ProductionOrderResource extends Resource
Forms\Components\Hidden::make('show_extra_fields')
->default(false),
Forms\Components\DateTimePicker::make('start_date')
->label('Start Date'),
->label('Start Date')
->reactive()
// ->minDate(function () {
// return Carbon::now()->addMinute();
// })
->afterStateUpdated(function ($state, callable $set) {
$set('end_date', null);
}),
Forms\Components\DateTimePicker::make('end_date')
->label('End Date'),
->label('End Date')
->reactive(),
// ->rule('after:start_date')
// ->minDate(function (callable $get) {
// $startDate = $get('start_date');
// if ($startDate) {
// return Carbon::parse($startDate)->addMinute();
// }
// return Carbon::now()->addMinute();
// }),
Forms\Components\TextInput::make('production_order')
->label('Production Order')
->readOnly()
->visible(fn ($get) => $get('show_extra_fields')),
->visible(fn ($get) => $get('quantity') > 0),
// ->visible(fn ($get) => $get('show_extra_fields')),
Forms\Components\TextInput::make('from_serial_number')
->label('From Serial Number')
->readOnly()
->visible(fn ($get) => $get('show_extra_fields')),
->visible(fn ($get) => $get('quantity') > 0),
Forms\Components\TextInput::make('to_serial_number')
->label('To Serial Number')
->readOnly()
->visible(fn ($get) => $get('show_extra_fields')),
->visible(fn ($get) => $get('quantity') > 0),
Forms\Components\Hidden::make('created_by')
->label('Created By')
->default(Filament::auth()->user()?->name),

View File

@@ -3,6 +3,7 @@
namespace App\Filament\Resources\ProductionOrderResource\Pages;
use App\Filament\Resources\ProductionOrderResource;
use App\Models\Plant;
use App\Models\ProductionOrder;
use Filament\Facades\Filament;
use Filament\Notifications\Notification;
@@ -209,6 +210,44 @@ class CreateProductionOrder extends CreateRecord
}
}
public function printPanel()
{
$pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null;
$plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null;
$plantCode = Plant::where('id', $plantId)->value('code');
if (empty($plantId)) {
Notification::make()
->title('Plant name cannot be empty!')
->danger()
->send();
return;
} elseif (empty($pOrder)) {
Notification::make()
->title('Production order cannot be empty!')
->danger()
->send();
return;
}
$pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first();
if (! $pOrderExists) {
Notification::make()
->title("Production Order '{$pOrder}' does not exist to get print!")
->danger()
->send();
return;
} else {
return redirect()->route('production-orders.printpanel', ['production_order' => $pOrder, 'plant_code' => $plantCode]);
}
}
protected function getFormActions(): array
{
return [];

View File

@@ -3,13 +3,92 @@
namespace App\Filament\Resources\ProductionOrderResource\Pages;
use App\Filament\Resources\ProductionOrderResource;
use App\Models\Plant;
use App\Models\ProductionOrder;
use Filament\Actions;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
class EditProductionOrder extends EditRecord
{
protected static string $resource = ProductionOrderResource::class;
public function printProductionOrder()
{
$pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null;
$plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null;
if (empty($plantId)) {
Notification::make()
->title('Plant name cannot be empty!')
->danger()
->send();
return;
} elseif (empty($pOrder)) {
Notification::make()
->title('Production order cannot be empty!')
->danger()
->send();
return;
}
$pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first();
if (! $pOrderExists) {
Notification::make()
->title("Production Order '{$pOrder}' does not exist to get print!")
->danger()
->send();
return;
} else {
return redirect()->route('production-orders.print', ['production_order' => $pOrder]);
}
}
public function printPanel()
{
$plantId = $this->form->getState()['plant_id'] ?? null;
$plantId = filled($plantId) ? (int) $plantId : null;
$pOrder = $this->form->getState()['production_order'] ?? null;
$pOrder = filled($pOrder) ? trim($pOrder) : null;
$plantCode = Plant::where('id', $plantId)->value('code');
if (empty($plantId)) {
Notification::make()
->title('Plant name cannot be empty!')
->danger()
->send();
return;
} elseif (empty($pOrder)) {
Notification::make()
->title('Production order cannot be empty!')
->danger()
->send();
return;
}
$pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first();
if (! $pOrderExists) {
Notification::make()
->title("Production Order '{$pOrder}' does not exist to get print!")
->danger()
->send();
return;
} else {
return redirect()->route('production-orders.printpanel', ['production_order' => $pOrder, 'plant_code' => $plantCode]);
}
}
protected function getHeaderActions(): array
{
return [

View File

@@ -3,13 +3,92 @@
namespace App\Filament\Resources\ProductionOrderResource\Pages;
use App\Filament\Resources\ProductionOrderResource;
use App\Models\Plant;
use App\Models\ProductionOrder;
use Filament\Actions;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ViewRecord;
class ViewProductionOrder extends ViewRecord
{
protected static string $resource = ProductionOrderResource::class;
public function printProductionOrder()
{
$pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null;
$plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null;
if (empty($plantId)) {
Notification::make()
->title('Plant name cannot be empty!')
->danger()
->send();
return;
} elseif (empty($pOrder)) {
Notification::make()
->title('Production order cannot be empty!')
->danger()
->send();
return;
}
$pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first();
if (! $pOrderExists) {
Notification::make()
->title("Production Order '{$pOrder}' does not exist to get print!")
->danger()
->send();
return;
} else {
return redirect()->route('production-orders.print', ['production_order' => $pOrder]);
}
}
public function printPanel()
{
$plantId = $this->form->getState()['plant_id'] ?? null;
$plantId = filled($plantId) ? (int) $plantId : null;
$pOrder = $this->form->getState()['production_order'] ?? null;
$pOrder = filled($pOrder) ? trim($pOrder) : null;
$plantCode = Plant::where('id', $plantId)->value('code');
if (empty($plantId)) {
Notification::make()
->title('Plant name cannot be empty!')
->danger()
->send();
return;
} elseif (empty($pOrder)) {
Notification::make()
->title('Production order cannot be empty!')
->danger()
->send();
return;
}
$pOrderExists = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first();
if (! $pOrderExists) {
Notification::make()
->title("Production Order '{$pOrder}' does not exist to get print!")
->danger()
->send();
return;
} else {
return redirect()->route('production-orders.printpanel', ['production_order' => $pOrder, 'plant_code' => $plantCode]);
}
}
protected function getHeaderActions(): array
{
return [

View File

@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Models\ProductionOrder;
use Carbon\Carbon;
use Illuminate\Http\Request;
// use SimpleSoftwareIO\QrCode\Facades\QrCode;
use Illuminate\Support\Facades\Log;
@@ -42,8 +43,6 @@ class ProductionOrderController extends Controller
$qrData = $itemCode . '|' . $serial;
Log::info($qrData);
// $qrBase64 = base64_encode(
// QrCode::format('png')->size(100)->generate($qrData)
// );
@@ -68,47 +67,53 @@ class ProductionOrderController extends Controller
}
}
// public function printpanel($production_order){
// $order = ProductionOrder::where('production_order', $production_order)->first();
public function printpanel($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 ?? '';
// $year =
// $month =
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');
// $stickers = [];
$stickers = [];
// for ($i = $fromSerial; $i <= $toSerial; $i++)
// {
for ($i = $fromSerial; $i <= $toSerial; $i++)
{
// $serial = str_pad($i, 6, '0', STR_PAD_LEFT);
$serial = str_pad($i, 6, '0', STR_PAD_LEFT);
$serialCount = substr(str_pad($i, 6, '0', STR_PAD_LEFT), -5);
// $qrData = $serial . '/' . $itemCode . '/' . $serial . '/' . $itemCode;
$qrData = $plantCode . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount;
// $qrBase64 = base64_encode(
// QrCode::format('png')->size(100)->generate($qrData)
// );
$panel = $plantCode . '/' . $itemCode . '/' . $year.$month . '/' . $serialCount;
// $stickers[] = [
// 'serial' => $serial,
// 'qr' => 'data:image/png;base64,' . $qrBase64,
// 'production_order' => $production_order,
// 'description' => $itemDes ?? ''
// ];
// }
// $pdf = Pdf::loadView('production-orders.printpallet', compact('stickers'))
// ->setPaper([0, 0, 170, 40]);
$qrCode = new QrCode($qrData);
$output = new Output\Png;
$qrBinary = $output->output($qrCode, 100);
$qrBase64 = base64_encode($qrBinary);
// return $pdf->stream('stickers.pdf');
// }
// }
$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');
}
}
/**
* Store a newly created resource in storage.

View File

@@ -0,0 +1,101 @@
<!DOCTYPE html>
<html>
<head>
<style>
@page {
margin: 0;
}
body {
margin: 0;
padding: 0;
/* font-family: "Arial Narrow", "DejaVu Sans", sans-serif; */
}
.sticker {
width: 113.39pt;
height: 113.39pt;
overflow: hidden;
}
.sticker:last-child {
page-break-after: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
td {
padding: 0;
margin: 0;
vertical-align: top;
}
.qr {
width: 90pt;
height: 90pt;
padding-top: 2pt;
/* padding-left: 12pt; */
}
.text {
position: relative;
/* padding-left: 5pt; */
}
.serial {
font-size: 7pt;
font-weight: bold;
position: relative;
/* top: 30pt; */
top: -5pt;
/* padding-left: 1pt; */
}
/* .po {
font-size: 8pt;
font-weight: bold;
text-align: left !important;
position: absolute;
right: 5pt;
top: 8pt;
} */
.desc {
font-family: "Arial Narrow";
font-size: 6pt;
font-weight: bold;
white-space: nowrap;
/* padding-top: 42pt; */
left: -38pt;
}
</style>
</head>
<body>
@foreach($stickers as $sticker)
<div class="sticker">
<table>
<tr>
<td align="center">
<img class="qr" src="{{ $sticker['qr'] }}">
</td>
</tr>
<tr>
<td class="text" align="center">
<div class="serial">{{ $sticker['serial'] }}</div>
</td>
</tr>
<tr>
<td class="text" align="center">
<div class="desc">{{ $sticker['description'] }}</div>
</td>
</tr>
</table>
</div>
@endforeach
</body>
</html>

View File

@@ -57,6 +57,10 @@ Route::get('/production-orders/print/{production_order}',
[ProductionOrderController::class, 'print']
)->name('production-orders.print');
Route::get('production-orders/{production_order}/{plant_code}/printpanel',
[ProductionOrderController::class, 'printpanel']
)->name('production-orders.printpanel');
// Route::get('/characteristic/approve', [CharacteristicApprovalController::class, 'approve'])
// ->name('characteristic.approve')
// ->middleware('signed');