ranjith-dev #912
87
app/Filament/Exports/PanelBoxValidationExporter.php
Normal file
87
app/Filament/Exports/PanelBoxValidationExporter.php
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Exports;
|
||||||
|
|
||||||
|
use App\Models\PanelBoxValidation;
|
||||||
|
use Filament\Actions\Exports\ExportColumn;
|
||||||
|
use Filament\Actions\Exports\Exporter;
|
||||||
|
use Filament\Actions\Exports\Models\Export;
|
||||||
|
|
||||||
|
class PanelBoxValidationExporter extends Exporter
|
||||||
|
{
|
||||||
|
protected static ?string $model = PanelBoxValidation::class;
|
||||||
|
|
||||||
|
public static function getColumns(): array
|
||||||
|
{
|
||||||
|
static $rowNumber = 0;
|
||||||
|
return [
|
||||||
|
ExportColumn::make('no')
|
||||||
|
->label('NO')
|
||||||
|
->state(function ($record) use (&$rowNumber) {
|
||||||
|
// Increment and return the row number
|
||||||
|
return ++$rowNumber;
|
||||||
|
}),
|
||||||
|
ExportColumn::make('plant.name')
|
||||||
|
->label('PLANT NAME'),
|
||||||
|
ExportColumn::make('line.name')
|
||||||
|
->label('LINE NAME'),
|
||||||
|
ExportColumn::make('stickerMaster.item.code')
|
||||||
|
->label('ITEM CODE'),
|
||||||
|
ExportColumn::make('production_order')
|
||||||
|
->label('PRODUCTION ORDER'),
|
||||||
|
ExportColumn::make('inspection_lot_number')
|
||||||
|
->label('INSPECTION LOT NUMBER'),
|
||||||
|
ExportColumn::make('serial_number')
|
||||||
|
->label('SERIAL NUMBER'),
|
||||||
|
ExportColumn::make('panel_box_supplier')
|
||||||
|
->label('PANEL BOX SUPPLIER'),
|
||||||
|
ExportColumn::make('panel_box_serial_number')
|
||||||
|
->label('PANEL BOX SERIAL NUMBER'),
|
||||||
|
ExportColumn::make('panel_box_code')
|
||||||
|
->label('PANEL BOX CODE'),
|
||||||
|
ExportColumn::make('serial_number_panel')
|
||||||
|
->label('SERIAL NUMBER PANEL'),
|
||||||
|
ExportColumn::make('pack_slip_panel')
|
||||||
|
->label('PACK SLIP PANEL'),
|
||||||
|
ExportColumn::make('name_plate_panel')
|
||||||
|
->label('NAME PLATE PANEL'),
|
||||||
|
ExportColumn::make('tube_sticker_panel')
|
||||||
|
->label('TUBE STICKER PANEL'),
|
||||||
|
ExportColumn::make('warranty_card_panel')
|
||||||
|
->label('WARRANTY CARD PANEL'),
|
||||||
|
ExportColumn::make('part_validation1')
|
||||||
|
->label('PART VALIDATION 1'),
|
||||||
|
ExportColumn::make('part_validation2')
|
||||||
|
->label('PART VALIDATION 2'),
|
||||||
|
ExportColumn::make('part_validation3')
|
||||||
|
->label('PART VALIDATION 3'),
|
||||||
|
ExportColumn::make('part_validation4')
|
||||||
|
->label('PART VALIDATION 4'),
|
||||||
|
ExportColumn::make('part_validation5')
|
||||||
|
->label('PART VALIDATION 5'),
|
||||||
|
ExportColumn::make('created_at')
|
||||||
|
->label('CREATED AT'),
|
||||||
|
ExportColumn::make('updated_at')
|
||||||
|
->label('UPDATED AT'),
|
||||||
|
ExportColumn::make('created_by')
|
||||||
|
->label('CREATED BY'),
|
||||||
|
ExportColumn::make('updated_by')
|
||||||
|
->label('UPDATED BY'),
|
||||||
|
ExportColumn::make('deleted_at')
|
||||||
|
->label('DELETED AT')
|
||||||
|
->enabledByDefault(false),
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCompletedNotificationBody(Export $export): string
|
||||||
|
{
|
||||||
|
$body = 'Your panel box validation export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';
|
||||||
|
|
||||||
|
if ($failedRowsCount = $export->getFailedRowsCount()) {
|
||||||
|
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
}
|
||||||
70
app/Filament/Imports/PanelBoxValidationImporter.php
Normal file
70
app/Filament/Imports/PanelBoxValidationImporter.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Filament\Imports;
|
||||||
|
|
||||||
|
use App\Models\PanelBoxValidation;
|
||||||
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
|
use Filament\Actions\Imports\Importer;
|
||||||
|
use Filament\Actions\Imports\Models\Import;
|
||||||
|
|
||||||
|
class PanelBoxValidationImporter extends Importer
|
||||||
|
{
|
||||||
|
protected static ?string $model = PanelBoxValidation::class;
|
||||||
|
|
||||||
|
public static function getColumns(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
ImportColumn::make('plant')
|
||||||
|
->requiredMapping()
|
||||||
|
->relationship()
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('line')
|
||||||
|
->requiredMapping()
|
||||||
|
->relationship()
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('stickerMaster')
|
||||||
|
->requiredMapping()
|
||||||
|
->relationship()
|
||||||
|
->rules(['required']),
|
||||||
|
ImportColumn::make('production_order'),
|
||||||
|
ImportColumn::make('serial_number'),
|
||||||
|
ImportColumn::make('serial_number_panel'),
|
||||||
|
ImportColumn::make('pack_slip_panel'),
|
||||||
|
ImportColumn::make('name_plate_panel'),
|
||||||
|
ImportColumn::make('tube_sticker_panel'),
|
||||||
|
ImportColumn::make('warranty_card_panel'),
|
||||||
|
ImportColumn::make('part_validation1'),
|
||||||
|
ImportColumn::make('part_validation2'),
|
||||||
|
ImportColumn::make('part_validation3'),
|
||||||
|
ImportColumn::make('part_validation4'),
|
||||||
|
ImportColumn::make('part_validation5'),
|
||||||
|
ImportColumn::make('created_by'),
|
||||||
|
ImportColumn::make('updated_by'),
|
||||||
|
ImportColumn::make('panel_box_supplier'),
|
||||||
|
ImportColumn::make('panel_box_serial_number'),
|
||||||
|
ImportColumn::make('panel_box_code'),
|
||||||
|
ImportColumn::make('inspection_lot_number'),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function resolveRecord(): ?PanelBoxValidation
|
||||||
|
{
|
||||||
|
// return PanelBoxValidation::firstOrNew([
|
||||||
|
// // Update existing records, matching them by `$this->data['column_name']`
|
||||||
|
// 'email' => $this->data['email'],
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
return new PanelBoxValidation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getCompletedNotificationBody(Import $import): string
|
||||||
|
{
|
||||||
|
$body = 'Your panel box validation import has completed and ' . number_format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.';
|
||||||
|
|
||||||
|
if ($failedRowsCount = $import->getFailedRowsCount()) {
|
||||||
|
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,10 @@ use Filament\Forms\Components\Select;
|
|||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Tables\Filters\Filter;
|
use Filament\Tables\Filters\Filter;
|
||||||
use Str;
|
use Str;
|
||||||
|
use Filament\Tables\Actions\ExportAction;
|
||||||
|
use Filament\Tables\Actions\ImportAction;
|
||||||
|
use App\Filament\Exports\PanelBoxValidationExporter;
|
||||||
|
use App\Filament\Imports\PanelBoxValidationImporter;
|
||||||
|
|
||||||
class PanelBoxValidationResource extends Resource
|
class PanelBoxValidationResource extends Resource
|
||||||
{
|
{
|
||||||
@@ -172,6 +176,40 @@ class PanelBoxValidationResource extends Resource
|
|||||||
$set('production_order', request()->get('production_order'));
|
$set('production_order', request()->get('production_order'));
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
Forms\Components\TextInput::make('inspection_lot_number')
|
||||||
|
->label('Inspec Lot No')
|
||||||
|
->placeholder('Scan the valid Inspec Lot No')
|
||||||
|
->minLength(7)
|
||||||
|
->maxLength(14)
|
||||||
|
->reactive()
|
||||||
|
->readOnly(fn (callable $get) => $get('item_id'))
|
||||||
|
->afterStateUpdated(function (callable $set, callable $get, ?string $state) {
|
||||||
|
if (! is_numeric($get('inspection_lot_number'))) {
|
||||||
|
$set('inspecOrdError', 'Must be a numeric value.');
|
||||||
|
$set('item_id', null);
|
||||||
|
$set('sticker_master_id', null);
|
||||||
|
$set('uom', null);
|
||||||
|
$set('serial_number', null);
|
||||||
|
} else {
|
||||||
|
$set('inspecOrdError', null);
|
||||||
|
$set('inspection_lot_number', $state);
|
||||||
|
$set('inspection', $state);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
->default(fn ($get) => $get('inspection') ?? session('last_selected_inspection'))
|
||||||
|
->extraAttributes(fn ($get) => [
|
||||||
|
'class' => $get('inspecOrdError') ? 'border-red-500' : '',
|
||||||
|
])
|
||||||
|
->hint(fn ($get) => $get('inspecOrdError') ? $get('inspecOrdError') : null)
|
||||||
|
->hintColor('danger')
|
||||||
|
->required(),
|
||||||
|
Forms\Components\Hidden::make('inspection')
|
||||||
|
->default(fn () => session('last_selected_inspection'))
|
||||||
|
->afterStateHydrated(function ($state, $set) {
|
||||||
|
if (! $state && request()->has('inspection_lot_number')) {
|
||||||
|
$set('inspection_lot_number', request()->get('inspection_lot_number'));
|
||||||
|
}
|
||||||
|
}),
|
||||||
Forms\Components\TextInput::make('item_id')
|
Forms\Components\TextInput::make('item_id')
|
||||||
->label('Item Code')
|
->label('Item Code')
|
||||||
// ->id('item_id')
|
// ->id('item_id')
|
||||||
@@ -186,6 +224,7 @@ class PanelBoxValidationResource extends Resource
|
|||||||
$pId = $get('line_id');
|
$pId = $get('line_id');
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
$plaCode = Plant::find($plantId)?->code;
|
$plaCode = Plant::find($plantId)?->code;
|
||||||
|
$inspecLotNo = $get('inspection_lot_number');
|
||||||
$set('part_validation_type', null);
|
$set('part_validation_type', null);
|
||||||
$set('show_validation_image', false);
|
$set('show_validation_image', false);
|
||||||
$set('validation1_image_url', null);
|
$set('validation1_image_url', null);
|
||||||
@@ -584,6 +623,15 @@ class PanelBoxValidationResource extends Resource
|
|||||||
$set('item_id', null);
|
$set('item_id', null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
else if($existInMaster->inspection_lot_number != $inspecLotNo){
|
||||||
|
Notification::make()
|
||||||
|
->title('Panel GR Found')
|
||||||
|
->body("Inspection Lot Number code not match for Production Order (Or) Doc No'{$pOrder}' and Item '{$itemCode}'.")
|
||||||
|
->danger()
|
||||||
|
->send();
|
||||||
|
$set('item_id', null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
else if($existInMaster->quantity == '' || $existInMaster->quantity == null){
|
else if($existInMaster->quantity == '' || $existInMaster->quantity == null){
|
||||||
Notification::make()
|
Notification::make()
|
||||||
->title('Panel GR Found')
|
->title('Panel GR Found')
|
||||||
@@ -1619,6 +1667,11 @@ class PanelBoxValidationResource extends Resource
|
|||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('inspection_lot_number')
|
||||||
|
->label('Inspection Lot No')
|
||||||
|
->alignCenter()
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('serial_number')
|
Tables\Columns\TextColumn::make('serial_number')
|
||||||
->label('Serial Number')
|
->label('Serial Number')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
@@ -1628,52 +1681,62 @@ class PanelBoxValidationResource extends Resource
|
|||||||
->label('Serial Number Panel')
|
->label('Serial Number Panel')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->serial_number_panel == 1),
|
||||||
Tables\Columns\TextColumn::make('pack_slip_panel')
|
Tables\Columns\TextColumn::make('pack_slip_panel')
|
||||||
->label('Pack Slip Panel')
|
->label('Pack Slip Panel')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->pack_slip_panel == 1),
|
||||||
Tables\Columns\TextColumn::make('name_plate_panel')
|
Tables\Columns\TextColumn::make('name_plate_panel')
|
||||||
->label('Name Plate Panel')
|
->label('Name Plate Panel')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->name_plate_panel == 1),
|
||||||
Tables\Columns\TextColumn::make('tube_sticker_panel')
|
Tables\Columns\TextColumn::make('tube_sticker_panel')
|
||||||
->label('Tube Sticker Panel')
|
->label('Tube Sticker Panel')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->tube_sticker_panel == 1),
|
||||||
Tables\Columns\TextColumn::make('warranty_card_panel')
|
Tables\Columns\TextColumn::make('warranty_card_panel')
|
||||||
->label('Warranty Card Panel')
|
->label('Warranty Card Panel')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->warranty_card_panel == 1),
|
||||||
Tables\Columns\TextColumn::make('part_validation1')
|
Tables\Columns\TextColumn::make('part_validation1')
|
||||||
->label('Part Validation 1')
|
->label('Part Validation 1')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->part_validation1 != null),
|
||||||
Tables\Columns\TextColumn::make('part_validation2')
|
Tables\Columns\TextColumn::make('part_validation2')
|
||||||
->label('Part Validation 2')
|
->label('Part Validation 2')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->part_validation2 != null),
|
||||||
Tables\Columns\TextColumn::make('part_validation3')
|
Tables\Columns\TextColumn::make('part_validation3')
|
||||||
->label('Part Validation 3')
|
->label('Part Validation 3')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->part_validation3 != null),
|
||||||
Tables\Columns\TextColumn::make('part_validation4')
|
Tables\Columns\TextColumn::make('part_validation4')
|
||||||
->label('Part Validation 4')
|
->label('Part Validation 4')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->part_validation4 != null),
|
||||||
Tables\Columns\TextColumn::make('part_validation5')
|
Tables\Columns\TextColumn::make('part_validation5')
|
||||||
->label('Part Validation 5')
|
->label('Part Validation 5')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable()
|
||||||
|
->visible(fn ($record) => $record?->stickerMaster?->part_validation5 != null),
|
||||||
Tables\Columns\TextColumn::make('panel_box_supplier')
|
Tables\Columns\TextColumn::make('panel_box_supplier')
|
||||||
->label('Panel Box Supplier')
|
->label('Panel Box Supplier')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
@@ -1909,6 +1972,22 @@ class PanelBoxValidationResource extends Resource
|
|||||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||||
Tables\Actions\RestoreBulkAction::make(),
|
Tables\Actions\RestoreBulkAction::make(),
|
||||||
]),
|
]),
|
||||||
|
])
|
||||||
|
->headerActions([
|
||||||
|
ImportAction::make()
|
||||||
|
->label('Import Panel Box Validation')
|
||||||
|
->color('warning')
|
||||||
|
->importer(PanelBoxValidationImporter::class)
|
||||||
|
->visible(function () {
|
||||||
|
return Filament::auth()->user()->can('view import panel box validation');
|
||||||
|
}),
|
||||||
|
ExportAction::make()
|
||||||
|
->label('Export Panel Box Validation')
|
||||||
|
->color('warning')
|
||||||
|
->exporter(PanelBoxValidationExporter::class)
|
||||||
|
->visible(function () {
|
||||||
|
return Filament::auth()->user()->can('view export panel box validation');
|
||||||
|
}),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class CreatePanelBoxValidation extends CreateRecord {
|
|||||||
'last_selected_plant_id',
|
'last_selected_plant_id',
|
||||||
'last_selected_line',
|
'last_selected_line',
|
||||||
'last_selected_production',
|
'last_selected_production',
|
||||||
|
'last_selected_inspection',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +118,7 @@ class CreatePanelBoxValidation extends CreateRecord {
|
|||||||
'plant_id' => $this->data['plant_id'] ?? null,
|
'plant_id' => $this->data['plant_id'] ?? null,
|
||||||
'line_id' => $this->data['line_id'] ?? null,
|
'line_id' => $this->data['line_id'] ?? null,
|
||||||
'production_order' => $this->data['production_order'] ?? null,
|
'production_order' => $this->data['production_order'] ?? null,
|
||||||
|
'inspection_lot_number' => $this->data['inspection_lot_number'] ?? null,
|
||||||
])
|
])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -220,6 +222,7 @@ class CreatePanelBoxValidation extends CreateRecord {
|
|||||||
$plant = $this->form->getState()['plant'] ?? null;
|
$plant = $this->form->getState()['plant'] ?? null;
|
||||||
$line = $this->form->getState()['line'] ?? null;
|
$line = $this->form->getState()['line'] ?? null;
|
||||||
$production = $this->form->getState()['production'] ?? null;
|
$production = $this->form->getState()['production'] ?? null;
|
||||||
|
$inspection = $this->form->getState()['inspection'] ?? null;
|
||||||
|
|
||||||
// $this->skipChecklistValidation = false;
|
// $this->skipChecklistValidation = false;
|
||||||
// $this->showChecklist = false;
|
// $this->showChecklist = false;
|
||||||
@@ -244,6 +247,7 @@ class CreatePanelBoxValidation extends CreateRecord {
|
|||||||
'plant_id' => null,
|
'plant_id' => null,
|
||||||
'line_id' => null,
|
'line_id' => null,
|
||||||
'production_order' => null,
|
'production_order' => null,
|
||||||
|
'inspection_lot_number' => null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
||||||
@@ -260,6 +264,9 @@ class CreatePanelBoxValidation extends CreateRecord {
|
|||||||
if ($production) {
|
if ($production) {
|
||||||
session(['last_selected_production' => $production]);
|
session(['last_selected_production' => $production]);
|
||||||
}
|
}
|
||||||
|
if ($inspection) {
|
||||||
|
session(['last_selected_inspection' => $inspection]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRedirectUrl(): string
|
protected function getRedirectUrl(): string
|
||||||
@@ -270,6 +277,7 @@ class CreatePanelBoxValidation extends CreateRecord {
|
|||||||
'plant_id' => $this->data['plant_id'] ?? null,
|
'plant_id' => $this->data['plant_id'] ?? null,
|
||||||
'line_id' => $this->data['line_id'] ?? null,
|
'line_id' => $this->data['line_id'] ?? null,
|
||||||
'production_order' => $this->data['production_order'] ?? null,
|
'production_order' => $this->data['production_order'] ?? null,
|
||||||
|
'inspection_lot_number' => $this->data['inspection_lot_number'] ?? null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user