Merge pull request 'ranjith-dev' (#554) from ranjith-dev into master
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Reviewed-on: #554
This commit was merged in pull request #554.
This commit is contained in:
327
app/Filament/Resources/ProductionOrderResource.php
Normal file
327
app/Filament/Resources/ProductionOrderResource.php
Normal file
@@ -0,0 +1,327 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources;
|
||||||
|
|
||||||
|
use App\Filament\Exports\ProductionOrderExporter;
|
||||||
|
use App\Filament\Imports\ProductionOrderImporter;
|
||||||
|
use App\Filament\Resources\ProductionOrderResource\Pages;
|
||||||
|
use App\Models\Item;
|
||||||
|
use App\Models\Plant;
|
||||||
|
use App\Models\ProductionOrder;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Forms;
|
||||||
|
use Filament\Forms\Components\Section;
|
||||||
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Forms\Get;
|
||||||
|
use Filament\Resources\Resource;
|
||||||
|
use Filament\Tables;
|
||||||
|
use Filament\Tables\Actions\ExportAction;
|
||||||
|
use Filament\Tables\Actions\ImportAction;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||||
|
|
||||||
|
class ProductionOrderResource extends Resource
|
||||||
|
{
|
||||||
|
protected static ?string $model = ProductionOrder::class;
|
||||||
|
|
||||||
|
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||||
|
|
||||||
|
protected static ?string $navigationGroup = 'Production Order';
|
||||||
|
|
||||||
|
public static function form(Form $form): Form
|
||||||
|
{
|
||||||
|
return $form
|
||||||
|
->schema([
|
||||||
|
Section::make('')
|
||||||
|
->schema([
|
||||||
|
Forms\Components\Select::make('plant_id')
|
||||||
|
->label('Plant Name')
|
||||||
|
->relationship('plant', 'name')
|
||||||
|
->searchable()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
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')))
|
||||||
|
->default(function () {
|
||||||
|
$userHas = Filament::auth()->user()->plant_id;
|
||||||
|
|
||||||
|
return ($userHas && strlen($userHas) > 0) ? $userHas : optional(ProductionOrder::latest()->first())->plant_id;
|
||||||
|
})
|
||||||
|
->reactive()
|
||||||
|
->extraAttributes(fn ($get) => [
|
||||||
|
'class' => $get('poPlantError') ? 'border-red-500' : '',
|
||||||
|
])
|
||||||
|
->hint(fn ($get) => $get('poPlantError') ? $get('poPlantError') : null)
|
||||||
|
->hintColor('danger')
|
||||||
|
->required()
|
||||||
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
|
$set('item_id', null);
|
||||||
|
$set('quantity', null);
|
||||||
|
$set('show_extra_fields', false);
|
||||||
|
$set('start_date', null);
|
||||||
|
$set('end_date', null);
|
||||||
|
$set('production_order', null);
|
||||||
|
$set('from_serial_number', null);
|
||||||
|
$set('to_serial_number', null);
|
||||||
|
}),
|
||||||
|
Forms\Components\Select::make('item_id')
|
||||||
|
->label('Item Code')
|
||||||
|
->searchable()
|
||||||
|
->reactive()
|
||||||
|
->options(function (callable $get) {
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
if (empty($plantId)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||||
|
})
|
||||||
|
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||||
|
->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;
|
||||||
|
})
|
||||||
|
->required()
|
||||||
|
->afterStateUpdated(function ($state, callable $set) {
|
||||||
|
$set('quantity', null);
|
||||||
|
$set('show_extra_fields', false);
|
||||||
|
$set('start_date', null);
|
||||||
|
$set('end_date', null);
|
||||||
|
$set('production_order', null);
|
||||||
|
$set('from_serial_number', null);
|
||||||
|
$set('to_serial_number', null);
|
||||||
|
}),
|
||||||
|
Forms\Components\TextInput::make('quantity')
|
||||||
|
->label('Quantity')
|
||||||
|
->reactive()
|
||||||
|
->integer()
|
||||||
|
->required()
|
||||||
|
->readOnly(fn ($get) => ($get('plant_id') == null || $get('item_id') == null))
|
||||||
|
->afterStateUpdated(function ($state, callable $set, $get) {
|
||||||
|
if (! empty($state) && $state > 0) {
|
||||||
|
$set('show_extra_fields', true);
|
||||||
|
$now = Carbon::now();
|
||||||
|
$plantId = $get('plant_id');
|
||||||
|
$quantity = $get('quantity');
|
||||||
|
$set('start_date', null);
|
||||||
|
$set('end_date', null);
|
||||||
|
$plantCode = Plant::find($plantId)->code;
|
||||||
|
|
||||||
|
$year = $now->format('y'); // Year (last 2 digits)
|
||||||
|
$month = $now->format('m');
|
||||||
|
|
||||||
|
$monthText = strtoupper($now->format('M')); // APR
|
||||||
|
$monthNumber = '';
|
||||||
|
|
||||||
|
foreach (str_split($monthText) as $char) {
|
||||||
|
$curSeq = ord($char) - 64;
|
||||||
|
$monthNumber .= str_pad($curSeq, 2, '0', STR_PAD_LEFT);
|
||||||
|
}
|
||||||
|
|
||||||
|
$prefix = $year.$monthNumber;
|
||||||
|
|
||||||
|
$last = ProductionOrder::where('production_order', 'like', "{$prefix}%")->orderByDesc('production_order')->first(); // ProductionOrder::where('production_order', 'like', $prefix.'%')->orderBy('production_order', 'desc')->first();
|
||||||
|
|
||||||
|
if ($last) {
|
||||||
|
$lastSeq = substr($last->production_order, -4);
|
||||||
|
$nextSeq = str_pad(((int) $lastSeq + 1), 4, '0', STR_PAD_LEFT);
|
||||||
|
} else {
|
||||||
|
$nextSeq = '0001';
|
||||||
|
}
|
||||||
|
|
||||||
|
$productionOrder = $prefix.$nextSeq;
|
||||||
|
|
||||||
|
$set('production_order', $productionOrder);
|
||||||
|
|
||||||
|
$prefixSerial = $plantCode.$year.$month;
|
||||||
|
|
||||||
|
$last = ProductionOrder::where('to_serial_number', 'like', "{$prefixSerial}%")->orderByDesc('to_serial_number')->first();
|
||||||
|
|
||||||
|
if ($last) {
|
||||||
|
$lastSeq = (int) substr($last->to_serial_number, -6);
|
||||||
|
$startSeq = $lastSeq + 1;
|
||||||
|
} else {
|
||||||
|
$startSeq = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$endSeq = $startSeq + $quantity - 1;
|
||||||
|
|
||||||
|
$fromSerial = $prefixSerial.str_pad($startSeq, 6, '0', STR_PAD_LEFT);
|
||||||
|
$toSerial = $prefixSerial.str_pad($endSeq, 6, '0', STR_PAD_LEFT);
|
||||||
|
|
||||||
|
$set('from_serial_number', $fromSerial);
|
||||||
|
$set('to_serial_number', $toSerial);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
$set('show_extra_fields', false);
|
||||||
|
|
||||||
|
$set('production_order', null);
|
||||||
|
$set('start_date', null);
|
||||||
|
$set('end_date', null);
|
||||||
|
$set('from_serial_number', null);
|
||||||
|
$set('to_serial_number', null);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
Forms\Components\Hidden::make('show_extra_fields')
|
||||||
|
->default(false),
|
||||||
|
Forms\Components\DateTimePicker::make('start_date')
|
||||||
|
->label('Start Date'),
|
||||||
|
Forms\Components\DateTimePicker::make('end_date')
|
||||||
|
->label('End Date'),
|
||||||
|
Forms\Components\TextInput::make('production_order')
|
||||||
|
->label('Production Order')
|
||||||
|
->readOnly()
|
||||||
|
->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')),
|
||||||
|
Forms\Components\TextInput::make('to_serial_number')
|
||||||
|
->label('To Serial Number')
|
||||||
|
->readOnly()
|
||||||
|
->visible(fn ($get) => $get('show_extra_fields')),
|
||||||
|
Forms\Components\Hidden::make('created_by')
|
||||||
|
->label('Created By')
|
||||||
|
->default(Filament::auth()->user()?->name),
|
||||||
|
Forms\Components\Hidden::make('updated_by')
|
||||||
|
->label('Updated By')
|
||||||
|
->default(Filament::auth()->user()?->name),
|
||||||
|
Forms\Components\View::make('forms.components.save-production-order-button'),
|
||||||
|
])
|
||||||
|
->columns(5),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function table(Table $table): Table
|
||||||
|
{
|
||||||
|
return $table
|
||||||
|
->columns([
|
||||||
|
Tables\Columns\TextColumn::make('No.')
|
||||||
|
->label('No.')
|
||||||
|
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
|
||||||
|
$paginator = $livewire->getTableRecords();
|
||||||
|
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
|
||||||
|
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
|
||||||
|
|
||||||
|
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||||
|
}),
|
||||||
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
|
->label('Plant Name')
|
||||||
|
->alignCenter()
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('item.code')
|
||||||
|
->label('Item Code')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('quantity')
|
||||||
|
->label('Quantity')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('start_date')
|
||||||
|
->label('Start Date')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->dateTime()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('end_date')
|
||||||
|
->label('End Date')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->dateTime()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('production_order')
|
||||||
|
->label('Production Order')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('from_serial_number')
|
||||||
|
->label('From Serial Number')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('to_serial_number')
|
||||||
|
->label('To Serial Number')
|
||||||
|
->searchable()
|
||||||
|
->alignCenter()
|
||||||
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
|
->label('Created At')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
Tables\Columns\TextColumn::make('updated_at')
|
||||||
|
->label('Updated At')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
Tables\Columns\TextColumn::make('deleted_at')
|
||||||
|
->label('Deleted At')
|
||||||
|
->dateTime()
|
||||||
|
->sortable()
|
||||||
|
->toggleable(isToggledHiddenByDefault: true),
|
||||||
|
])
|
||||||
|
->filters([
|
||||||
|
Tables\Filters\TrashedFilter::make(),
|
||||||
|
])
|
||||||
|
->actions([
|
||||||
|
Tables\Actions\ViewAction::make(),
|
||||||
|
Tables\Actions\EditAction::make(),
|
||||||
|
])
|
||||||
|
->bulkActions([
|
||||||
|
Tables\Actions\BulkActionGroup::make([
|
||||||
|
Tables\Actions\DeleteBulkAction::make(),
|
||||||
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||||
|
Tables\Actions\RestoreBulkAction::make(),
|
||||||
|
]),
|
||||||
|
])
|
||||||
|
->headerActions([
|
||||||
|
ImportAction::make()
|
||||||
|
->label('Import Production Orders')
|
||||||
|
->color('warning')
|
||||||
|
->importer(ProductionOrderImporter::class)
|
||||||
|
->visible(function () {
|
||||||
|
return Filament::auth()->user()->can('view import production orders');
|
||||||
|
}),
|
||||||
|
ExportAction::make()
|
||||||
|
->label('Export Production Orders')
|
||||||
|
->color('warning')
|
||||||
|
->exporter(ProductionOrderExporter::class)
|
||||||
|
->visible(function () {
|
||||||
|
return Filament::auth()->user()->can('view export production orders');
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRelations(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getPages(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'index' => Pages\ListProductionOrders::route('/'),
|
||||||
|
'create' => Pages\CreateProductionOrder::route('/create'),
|
||||||
|
'view' => Pages\ViewProductionOrder::route('/{record}'),
|
||||||
|
'edit' => Pages\EditProductionOrder::route('/{record}/edit'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getEloquentQuery(): Builder
|
||||||
|
{
|
||||||
|
return parent::getEloquentQuery()
|
||||||
|
->withoutGlobalScopes([
|
||||||
|
SoftDeletingScope::class,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,186 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\ProductionOrderResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\ProductionOrderResource;
|
||||||
|
use App\Models\ProductionOrder;
|
||||||
|
use Filament\Facades\Filament;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Resources\Pages\CreateRecord;
|
||||||
|
|
||||||
|
class CreateProductionOrder extends CreateRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = ProductionOrderResource::class;
|
||||||
|
|
||||||
|
public function saveProductionOrder()
|
||||||
|
{
|
||||||
|
$plantId = trim($this->form->getState()['plant_id'] ?? '') ?? null;
|
||||||
|
|
||||||
|
$itemId = trim($this->form->getState()['item_id'] ?? '') ?? null;
|
||||||
|
|
||||||
|
$quantity = trim($this->form->getState()['quantity'] ?? '') ?? null;
|
||||||
|
|
||||||
|
$startDate = trim($this->form->getState()['start_date'] ?? '') ?? null;
|
||||||
|
|
||||||
|
$endDate = trim($this->form->getState()['end_date'] ?? '') ?? null;
|
||||||
|
|
||||||
|
$pOrder = trim($this->form->getState()['production_order'] ?? '') ?? null;
|
||||||
|
|
||||||
|
$fSerNo = trim($this->form->getState()['from_serial_number'] ?? '') ?? null;
|
||||||
|
|
||||||
|
$tSerNo = trim($this->form->getState()['to_serial_number'] ?? '') ?? null;
|
||||||
|
|
||||||
|
$operatorName = Filament::auth()->user()?->name;
|
||||||
|
|
||||||
|
if (empty($plantId)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Plant name cannot be empty!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($itemId)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Item code cannot be empty!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($quantity)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Quantity cannot be empty!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($startDate)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Please choose a Start Date!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($endDate)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Please choose a End Date!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($pOrder)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Production order cannot be empty!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($fSerNo)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('From serial number cannot be empty!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($tSerNo)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('To serial number cannot be empty!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
} elseif (empty($operatorName)) {
|
||||||
|
Notification::make()
|
||||||
|
->title('Operator Name cannot be empty!')
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$dupProd = ProductionOrder::where('plant_id', $plantId)->where('production_order', $pOrder)->first();
|
||||||
|
if ($dupProd) {
|
||||||
|
Notification::make()
|
||||||
|
->title("Production Order '{$pOrder}' already exists in database!")
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$insert = ProductionOrder::create([
|
||||||
|
'plant_id' => $plantId ?? null,
|
||||||
|
'item_id' => $itemId ?? null,
|
||||||
|
'quantity' => $quantity ?? null,
|
||||||
|
'start_date' => $startDate ?? null,
|
||||||
|
'end_date' => $endDate ?? null,
|
||||||
|
'production_order' => $pOrder ?? null,
|
||||||
|
'from_serial_number' => $fSerNo ?? null,
|
||||||
|
'to_serial_number' => $tSerNo ?? null,
|
||||||
|
'created_by' => $operatorName ?? null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
if ($insert) {
|
||||||
|
Notification::make()
|
||||||
|
->title("Production Order '{$pOrder}' saved successfully.")
|
||||||
|
->success()
|
||||||
|
->send();
|
||||||
|
|
||||||
|
$this->form->fill([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'item_id' => $itemId,
|
||||||
|
'quantity' => $quantity,
|
||||||
|
'start_date' => $startDate,
|
||||||
|
'end_date' => $endDate,
|
||||||
|
'production_order' => $pOrder,
|
||||||
|
'from_serial_number' => $fSerNo,
|
||||||
|
'to_serial_number' => $tSerNo,
|
||||||
|
'show_extra_fields' => true,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
Notification::make()
|
||||||
|
->title("Failed to save Production Order '{$pOrder}'!")
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
$this->form->fill([
|
||||||
|
'plant_id' => $plantId,
|
||||||
|
'item_id' => $itemId,
|
||||||
|
'quantity' => null,
|
||||||
|
'start_date' => null,
|
||||||
|
'end_date' => null,
|
||||||
|
'production_order' => null,
|
||||||
|
'from_serial_number' => null,
|
||||||
|
'to_serial_number' => null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function printProductionOrder()
|
||||||
|
{
|
||||||
|
$pOrder = $this->form->getState()['production_order'];
|
||||||
|
|
||||||
|
$pOrder = trim($pOrder) ?? null;
|
||||||
|
|
||||||
|
$pOrderExists = ProductionOrder::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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getFormActions(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\ProductionOrderResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\ProductionOrderResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\EditRecord;
|
||||||
|
|
||||||
|
class EditProductionOrder extends EditRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = ProductionOrderResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\ViewAction::make(),
|
||||||
|
Actions\DeleteAction::make(),
|
||||||
|
Actions\ForceDeleteAction::make(),
|
||||||
|
Actions\RestoreAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\ProductionOrderResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\ProductionOrderResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ListRecords;
|
||||||
|
|
||||||
|
class ListProductionOrders extends ListRecords
|
||||||
|
{
|
||||||
|
protected static string $resource = ProductionOrderResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\CreateAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Resources\ProductionOrderResource\Pages;
|
||||||
|
|
||||||
|
use App\Filament\Resources\ProductionOrderResource;
|
||||||
|
use Filament\Actions;
|
||||||
|
use Filament\Resources\Pages\ViewRecord;
|
||||||
|
|
||||||
|
class ViewProductionOrder extends ViewRecord
|
||||||
|
{
|
||||||
|
protected static string $resource = ProductionOrderResource::class;
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Actions\EditAction::make(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
92
app/Http/Controllers/ProductionOrderController.php
Normal file
92
app/Http/Controllers/ProductionOrderController.php
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Models\ProductionOrder;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||||||
|
use Barryvdh\DomPDF\Facade\Pdf;
|
||||||
|
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
|
||||||
|
$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');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
31
app/Models/ProductionOrder.php
Normal file
31
app/Models/ProductionOrder.php
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
class ProductionOrder extends Model
|
||||||
|
{
|
||||||
|
use SoftDeletes;
|
||||||
|
protected $fillable = [
|
||||||
|
'plant_id',
|
||||||
|
'item_id',
|
||||||
|
'quantity',
|
||||||
|
'start_date',
|
||||||
|
'end_date',
|
||||||
|
'production_order',
|
||||||
|
'from_serial_number',
|
||||||
|
'to_serial_number',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function plant()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Plant::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function item()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Item::class);
|
||||||
|
}
|
||||||
|
}
|
||||||
106
app/Policies/ProductionOrderPolicy.php
Normal file
106
app/Policies/ProductionOrderPolicy.php
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use Illuminate\Auth\Access\Response;
|
||||||
|
use App\Models\ProductionOrder;
|
||||||
|
use App\Models\User;
|
||||||
|
|
||||||
|
class ProductionOrderPolicy
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view any models.
|
||||||
|
*/
|
||||||
|
public function viewAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('view-any ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can view the model.
|
||||||
|
*/
|
||||||
|
public function view(User $user, ProductionOrder $productionorder): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('view ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can create models.
|
||||||
|
*/
|
||||||
|
public function create(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('create ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can update the model.
|
||||||
|
*/
|
||||||
|
public function update(User $user, ProductionOrder $productionorder): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('update ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete the model.
|
||||||
|
*/
|
||||||
|
public function delete(User $user, ProductionOrder $productionorder): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('delete ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can delete any models.
|
||||||
|
*/
|
||||||
|
public function deleteAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('delete-any ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore the model.
|
||||||
|
*/
|
||||||
|
public function restore(User $user, ProductionOrder $productionorder): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('restore ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can restore any models.
|
||||||
|
*/
|
||||||
|
public function restoreAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('restore-any ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can replicate the model.
|
||||||
|
*/
|
||||||
|
public function replicate(User $user, ProductionOrder $productionorder): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('replicate ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can reorder the models.
|
||||||
|
*/
|
||||||
|
public function reorder(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('reorder ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete the model.
|
||||||
|
*/
|
||||||
|
public function forceDelete(User $user, ProductionOrder $productionorder): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('force-delete ProductionOrder');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine whether the user can permanently delete any models.
|
||||||
|
*/
|
||||||
|
public function forceDeleteAny(User $user): bool
|
||||||
|
{
|
||||||
|
return $user->checkPermissionTo('force-delete-any ProductionOrder');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
$sql = <<<'SQL'
|
||||||
|
CREATE TABLE production_orders (
|
||||||
|
id BIGINT GENERATED always AS IDENTITY PRIMARY KEY,
|
||||||
|
|
||||||
|
plant_id BIGINT NOT NULL,
|
||||||
|
item_id BIGINT NOT NULL,
|
||||||
|
quantity INT DEFAULT NULL,
|
||||||
|
start_date TIMESTAMP DEFAULT NULL,
|
||||||
|
end_date TIMESTAMP DEFAULT NULL,
|
||||||
|
production_order TEXT UNIQUE,
|
||||||
|
from_serial_number TEXT DEFAULT NULL,
|
||||||
|
to_serial_number TEXT DEFAULT NULL,
|
||||||
|
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||||
|
updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
|
||||||
|
created_by TEXT DEFAULT NULL,
|
||||||
|
updated_by TEXT DEFAULT NULL,
|
||||||
|
deleted_at TIMESTAMP,
|
||||||
|
|
||||||
|
FOREIGN KEY (plant_id) REFERENCES plants (id),
|
||||||
|
FOREIGN KEY (item_id) REFERENCES items (id)
|
||||||
|
);
|
||||||
|
SQL;
|
||||||
|
DB::statement($sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('production_orders');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
wire:click="saveProductionOrder"
|
||||||
|
class="px-2 py-1 border border-primary-500 text-primary-600 rounded hover:bg-primary-50 hover:border-primary-700 transition text-sm"
|
||||||
|
>
|
||||||
|
Save
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
wire:click="printProductionOrder"
|
||||||
|
class="px-2 py-1 border border-primary-500 text-primary-600 rounded hover:bg-primary-50 hover:border-primary-700 transition text-sm"
|
||||||
|
>
|
||||||
|
Print
|
||||||
|
</button>
|
||||||
|
|
||||||
|
|
||||||
105
resources/views/production-orders/print.blade.php
Normal file
105
resources/views/production-orders/print.blade.php
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
@page {
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.sticker {
|
||||||
|
width: 170pt;
|
||||||
|
height: 40pt;
|
||||||
|
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: 26pt;
|
||||||
|
height: 26pt;
|
||||||
|
padding-top: 7pt;
|
||||||
|
padding-left: 6.5pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* .text {
|
||||||
|
padding-left: 5pt;
|
||||||
|
} */
|
||||||
|
|
||||||
|
.text {
|
||||||
|
position: relative;
|
||||||
|
padding-left: 5pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* .serial {
|
||||||
|
font-size: 10pt;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-top: 6pt;
|
||||||
|
} */
|
||||||
|
|
||||||
|
.serial {
|
||||||
|
font-size: 10pt;
|
||||||
|
font-weight: bold;
|
||||||
|
position: relative;
|
||||||
|
top: 5pt;
|
||||||
|
right: 6pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* .po {
|
||||||
|
font-size: 8pt;
|
||||||
|
margin-bottom: 6pt;
|
||||||
|
margin-left: 75pt;
|
||||||
|
} */
|
||||||
|
|
||||||
|
.po {
|
||||||
|
font-size: 8pt;
|
||||||
|
position: absolute;
|
||||||
|
right: 5pt;
|
||||||
|
top: 6pt;
|
||||||
|
}
|
||||||
|
|
||||||
|
.desc {
|
||||||
|
font-size: 7pt;
|
||||||
|
margin-left: -5pt;
|
||||||
|
padding-top: 10pt;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
@foreach($stickers as $sticker)
|
||||||
|
<div class="sticker">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td style="width:40pt;">
|
||||||
|
<img class="qr" src="{{ $sticker['qr'] }}">
|
||||||
|
</td>
|
||||||
|
<td class="text">
|
||||||
|
<div class="serial">{{ $sticker['serial'] }}</div>
|
||||||
|
<div class="po">{{ $sticker['production_order'] }}</div>
|
||||||
|
<div class="desc">{{ $sticker['description'] }}</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\CharacteristicApprovalController;
|
use App\Http\Controllers\CharacteristicApprovalController;
|
||||||
|
use App\Http\Controllers\ProductionOrderController;
|
||||||
// use App\Http\Controllers\FileUploadController;
|
// use App\Http\Controllers\FileUploadController;
|
||||||
use App\Models\EquipmentMaster;
|
use App\Models\EquipmentMaster;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
@@ -52,6 +53,10 @@ Route::get('/approval/approve-success', function () {
|
|||||||
return view('approval.approve-success');
|
return view('approval.approve-success');
|
||||||
})->name('approval.approve.success');
|
})->name('approval.approve.success');
|
||||||
|
|
||||||
|
Route::get('/production-orders/print/{production_order}',
|
||||||
|
[ProductionOrderController::class, 'print']
|
||||||
|
)->name('production-orders.print');
|
||||||
|
|
||||||
// Route::get('/characteristic/approve', [CharacteristicApprovalController::class, 'approve'])
|
// Route::get('/characteristic/approve', [CharacteristicApprovalController::class, 'approve'])
|
||||||
// ->name('characteristic.approve')
|
// ->name('characteristic.approve')
|
||||||
// ->middleware('signed');
|
// ->middleware('signed');
|
||||||
@@ -67,6 +72,7 @@ Route::get('/approval/approve-success', function () {
|
|||||||
// ->middleware('signed');
|
// ->middleware('signed');
|
||||||
|
|
||||||
// routes/web.php
|
// routes/web.php
|
||||||
|
|
||||||
Route::post('/save-serials-to-session', function (Request $request) {
|
Route::post('/save-serials-to-session', function (Request $request) {
|
||||||
session(['serial_numbers' => $request->serial_numbers]);
|
session(['serial_numbers' => $request->serial_numbers]);
|
||||||
|
|
||||||
@@ -86,6 +92,16 @@ Route::get('/part-validation-image/{filename}', function ($filename) {
|
|||||||
return response()->file($path);
|
return response()->file($path);
|
||||||
})->name('part.validation.image');
|
})->name('part.validation.image');
|
||||||
|
|
||||||
|
Route::get('/workflow-image/{filename}', function ($filename) {
|
||||||
|
$path = storage_path("app/private/uploads/LaserDocs/{$filename}");
|
||||||
|
|
||||||
|
if (! file_exists($path)) {
|
||||||
|
abort(404, 'Image not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->file($path);
|
||||||
|
})->name('workflow.image');
|
||||||
|
|
||||||
// web.php
|
// web.php
|
||||||
Route::post('/temp-upload', function (Request $request) {
|
Route::post('/temp-upload', function (Request $request) {
|
||||||
if (! $request->hasFile('photo')) {
|
if (! $request->hasFile('photo')) {
|
||||||
|
|||||||
Reference in New Issue
Block a user