Added 'created_by', 'updated_by' columns StickerMaster screens
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled

This commit is contained in:
dhanabalan
2026-02-06 11:36:24 +05:30
parent de11ae3b1f
commit 6163211672
5 changed files with 235 additions and 77 deletions

View File

@@ -9,6 +9,7 @@ use Filament\Actions\Imports\Exceptions\RowImportFailedException;
use Filament\Actions\Imports\ImportColumn;
use Filament\Actions\Imports\Importer;
use Filament\Actions\Imports\Models\Import;
use Filament\Facades\Filament;
use Str;
class StickerMasterImporter extends Importer
@@ -163,8 +164,13 @@ class StickerMasterImporter extends Importer
{
$warnMsg = [];
$plantCod = $this->data['plant'];
$itemCod = $this->data['item'];
$plant = null;
$item = null;
$plantId = null;
$itemId = null;
$createdBy = Filament::auth()->user()->name;
$updatedBy = Filament::auth()->user()->name;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
} else {
@@ -174,60 +180,80 @@ class StickerMasterImporter extends Importer
if (! $plant) {
$warnMsg[] = 'Plant not found';
} else {
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
if (! $item) {
$warnMsg[] = 'Item code not found';
$plantId = $plant->id;
if (Str::length($itemCod) < 6 || ! ctype_alnum($itemCod)) {
$warnMsg[] = 'Invalid item code found';
} else {
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
$warnMsg[] = 'Serial number motor must be 1 or empty';
}
if (Str::length($this->data['serial_number_pump']) > 0 && $this->data['serial_number_pump'] != '1') {
$warnMsg[] = 'Serial number pump must be 1 or empty';
}
if (Str::length($this->data['serial_number_pumpset']) > 0 && $this->data['serial_number_pumpset'] != '1') {
$warnMsg[] = 'Serial number pumpset must be 1 or empty';
}
if (Str::length($this->data['pack_slip_motor']) > 0 && $this->data['pack_slip_motor'] != '1') {
$warnMsg[] = 'Pack slip motor must be 1 or empty';
}
if (Str::length($this->data['pack_slip_pump']) > 0 && $this->data['pack_slip_pump'] != '1') {
$warnMsg[] = 'Pack slip pump must be 1 or empty';
}
if (Str::length($this->data['pack_slip_pumpset']) > 0 && $this->data['pack_slip_pumpset'] != '1') {
$warnMsg[] = 'Pack slip pumpset must be 1 or empty';
}
if (Str::length($this->data['name_plate_motor']) > 0 && $this->data['name_plate_motor'] != '1') {
$warnMsg[] = 'Name plate motor must be 1 or empty';
}
if (Str::length($this->data['name_plate_pump']) > 0 && $this->data['name_plate_pump'] != '1') {
$warnMsg[] = 'Name plate pump must be 1 or empty';
}
if (Str::length($this->data['name_plate_pumpset']) > 0 && $this->data['name_plate_pumpset'] != '1') {
$warnMsg[] = 'Name plate pumpset must be 1 or empty';
}
if (Str::length($this->data['tube_sticker_motor']) > 0 && $this->data['tube_sticker_motor'] != '1') {
$warnMsg[] = 'Tube sticker motor must be 1 or empty';
}
if (Str::length($this->data['tube_sticker_pump']) > 0 && $this->data['tube_sticker_pump'] != '1') {
$warnMsg[] = 'Tube sticker pump must be 1 or empty';
}
if (Str::length($this->data['tube_sticker_pumpset']) > 0 && $this->data['tube_sticker_pumpset'] != '1') {
$warnMsg[] = 'Tube sticker pumpset must be 1 or empty';
}
if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') {
$warnMsg[] = 'Warranty card must be 1 or empty';
}
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || ! ctype_alnum($this->data['panel_box_code']))) {
$warnMsg[] = 'Invalid panel box code found';
}
if (Str::length($this->data['load_rate']) < 0 || ! is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
$warnMsg[] = 'Load rate must be greater than or equal to 0';
}
if (Str::length($this->data['bundle_quantity']) > 0 && (! is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
$warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty";
}
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { // ($this->data['material_type'] != null) &&
$warnMsg[] = 'Material type must be 1 or 2 or 3 or empty';
$item = Item::where('code', $itemCod)->first();
if (! $item) {
$warnMsg[] = 'Item code not found';
} else {
$item = Item::where('code', $itemCod)->where('plant_id', $plantId)->first();
if (! $item) {
$warnMsg[] = 'Item code not found for the plant';
} else {
$itemId = $item->id;
if (Str::length($this->data['serial_number_motor']) > 0 && $this->data['serial_number_motor'] != '1') {
$warnMsg[] = 'Serial number motor must be 1 or empty';
}
if (Str::length($this->data['serial_number_pump']) > 0 && $this->data['serial_number_pump'] != '1') {
$warnMsg[] = 'Serial number pump must be 1 or empty';
}
if (Str::length($this->data['serial_number_pumpset']) > 0 && $this->data['serial_number_pumpset'] != '1') {
$warnMsg[] = 'Serial number pumpset must be 1 or empty';
}
if (Str::length($this->data['pack_slip_motor']) > 0 && $this->data['pack_slip_motor'] != '1') {
$warnMsg[] = 'Pack slip motor must be 1 or empty';
}
if (Str::length($this->data['pack_slip_pump']) > 0 && $this->data['pack_slip_pump'] != '1') {
$warnMsg[] = 'Pack slip pump must be 1 or empty';
}
if (Str::length($this->data['pack_slip_pumpset']) > 0 && $this->data['pack_slip_pumpset'] != '1') {
$warnMsg[] = 'Pack slip pumpset must be 1 or empty';
}
if (Str::length($this->data['name_plate_motor']) > 0 && $this->data['name_plate_motor'] != '1') {
$warnMsg[] = 'Name plate motor must be 1 or empty';
}
if (Str::length($this->data['name_plate_pump']) > 0 && $this->data['name_plate_pump'] != '1') {
$warnMsg[] = 'Name plate pump must be 1 or empty';
}
if (Str::length($this->data['name_plate_pumpset']) > 0 && $this->data['name_plate_pumpset'] != '1') {
$warnMsg[] = 'Name plate pumpset must be 1 or empty';
}
if (Str::length($this->data['tube_sticker_motor']) > 0 && $this->data['tube_sticker_motor'] != '1') {
$warnMsg[] = 'Tube sticker motor must be 1 or empty';
}
if (Str::length($this->data['tube_sticker_pump']) > 0 && $this->data['tube_sticker_pump'] != '1') {
$warnMsg[] = 'Tube sticker pump must be 1 or empty';
}
if (Str::length($this->data['tube_sticker_pumpset']) > 0 && $this->data['tube_sticker_pumpset'] != '1') {
$warnMsg[] = 'Tube sticker pumpset must be 1 or empty';
}
if (Str::length($this->data['warranty_card']) > 0 && $this->data['warranty_card'] != '1') {
$warnMsg[] = 'Warranty card must be 1 or empty';
}
if (Str::length($this->data['panel_box_code']) > 0 && (Str::length($this->data['panel_box_code']) < 6 || ! ctype_alnum($this->data['panel_box_code']))) {
$warnMsg[] = 'Invalid panel box code found';
}
if (Str::length($this->data['load_rate']) < 0 || ! is_numeric($this->data['load_rate']) || $this->data['load_rate'] < 0) {
$warnMsg[] = 'Load rate must be greater than or equal to 0';
}
if (Str::length($this->data['bundle_quantity']) > 0 && (! is_numeric($this->data['bundle_quantity']) || $this->data['bundle_quantity'] <= 1)) {
$warnMsg[] = "Bundle quantity must be greater than or equal to '2' or empty";
}
if (Str::length($this->data['material_type']) > 0 && $this->data['material_type'] != '1' && $this->data['material_type'] != '2' && $this->data['material_type'] != '3') { // ($this->data['material_type'] != null) &&
$warnMsg[] = 'Material type must be 1 or 2 or 3 or empty';
}
if (empty($warnMsg)) {
$recExist = StickerMaster::where('item_id', $itemId)->where('plant_id', $plantId)->first()?->created_by;
if ($recExist) {
$createdBy = $recExist;
}
}
}
}
}
}
@@ -237,8 +263,8 @@ class StickerMasterImporter extends Importer
}
StickerMaster::updateOrCreate([
'item_id' => $item->id,
'plant_id' => $plant->id,
'item_id' => $itemId,
'plant_id' => $plantId,
],
[
'serial_number_motor' => $this->data['serial_number_motor'],
@@ -265,6 +291,8 @@ class StickerMasterImporter extends Importer
'load_rate' => $this->data['load_rate'],
'bundle_quantity' => $this->data['bundle_quantity'],
'material_type' => $this->data['material_type'],
'created_by' => $createdBy,
'updated_by' => $updatedBy,
]);
return null;