Compare commits
2 Commits
4ab7be97bb
...
18f60ec336
| Author | SHA1 | Date | |
|---|---|---|---|
| 18f60ec336 | |||
|
|
3b11781132 |
@@ -14,6 +14,7 @@ class ProductCharacteristicsMasterExporter extends Exporter
|
|||||||
public static function getColumns(): array
|
public static function getColumns(): array
|
||||||
{
|
{
|
||||||
static $rowNumber = 0;
|
static $rowNumber = 0;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
ExportColumn::make('no')
|
ExportColumn::make('no')
|
||||||
->label('NO')
|
->label('NO')
|
||||||
@@ -21,8 +22,8 @@ class ProductCharacteristicsMasterExporter extends Exporter
|
|||||||
// Increment and return the row number
|
// Increment and return the row number
|
||||||
return ++$rowNumber;
|
return ++$rowNumber;
|
||||||
}),
|
}),
|
||||||
ExportColumn::make('plant.name')
|
ExportColumn::make('plant.code')
|
||||||
->label('PLANT'),
|
->label('PLANT CODE'),
|
||||||
ExportColumn::make('item.code')
|
ExportColumn::make('item.code')
|
||||||
->label('ITEM CODE'),
|
->label('ITEM CODE'),
|
||||||
ExportColumn::make('line.name')
|
ExportColumn::make('line.name')
|
||||||
@@ -34,15 +35,15 @@ class ProductCharacteristicsMasterExporter extends Exporter
|
|||||||
ExportColumn::make('characteristics_type')
|
ExportColumn::make('characteristics_type')
|
||||||
->label('CHARACTERISTICS TYPE'),
|
->label('CHARACTERISTICS TYPE'),
|
||||||
ExportColumn::make('name')
|
ExportColumn::make('name')
|
||||||
->label('NAME'),
|
->label('CHARACTERISTICS NAME'),
|
||||||
ExportColumn::make('inspection_type')
|
ExportColumn::make('inspection_type')
|
||||||
->label('INSPECTION TYPE'),
|
->label('INSPECTION TYPE'),
|
||||||
ExportColumn::make('upper')
|
|
||||||
->label('UPPER'),
|
|
||||||
ExportColumn::make('lower')
|
ExportColumn::make('lower')
|
||||||
->label('LOWER'),
|
->label('LOWER'),
|
||||||
ExportColumn::make('middle')
|
ExportColumn::make('middle')
|
||||||
->label('MIDDLE'),
|
->label('MIDDLE'),
|
||||||
|
ExportColumn::make('upper')
|
||||||
|
->label('UPPER'),
|
||||||
ExportColumn::make('created_at')
|
ExportColumn::make('created_at')
|
||||||
->label('CREATED AT'),
|
->label('CREATED AT'),
|
||||||
ExportColumn::make('updated_at')
|
ExportColumn::make('updated_at')
|
||||||
|
|||||||
@@ -9,12 +9,12 @@ use App\Models\Plant;
|
|||||||
use App\Models\ProductCharacteristicsMaster;
|
use App\Models\ProductCharacteristicsMaster;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\WorkGroupMaster;
|
use App\Models\WorkGroupMaster;
|
||||||
|
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||||
use Filament\Actions\Imports\ImportColumn;
|
use Filament\Actions\Imports\ImportColumn;
|
||||||
use Filament\Actions\Imports\Importer;
|
use Filament\Actions\Imports\Importer;
|
||||||
use Filament\Actions\Imports\Models\Import;
|
use Filament\Actions\Imports\Models\Import;
|
||||||
use Str;
|
|
||||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Str;
|
||||||
|
|
||||||
class ProductCharacteristicsMasterImporter extends Importer
|
class ProductCharacteristicsMasterImporter extends Importer
|
||||||
{
|
{
|
||||||
@@ -25,10 +25,10 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
return [
|
return [
|
||||||
ImportColumn::make('plant')
|
ImportColumn::make('plant')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Plant Name')
|
->exampleHeader('Plant Code')
|
||||||
->example('Ransar Industries-I')
|
->example('1000')
|
||||||
->label('Plant Name')
|
->label('Plant Code')
|
||||||
->relationship(resolveUsing:'name')
|
->relationship(resolveUsing: 'code')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('item')
|
ImportColumn::make('item')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
@@ -39,9 +39,9 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('line')
|
ImportColumn::make('line')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Line')
|
->exampleHeader('Line Name')
|
||||||
->example('4 inch pump line')
|
->example('4 inch pump line')
|
||||||
->label('Line')
|
->label('Line Name')
|
||||||
->relationship(resolveUsing: 'name')
|
->relationship(resolveUsing: 'name')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('work_group_master_id')
|
ImportColumn::make('work_group_master_id')
|
||||||
@@ -64,9 +64,9 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
->label('Characteristics Type')
|
->label('Characteristics Type')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('name')
|
ImportColumn::make('name')
|
||||||
->exampleHeader('Name')
|
->exampleHeader('Characteristics Name')
|
||||||
->example('Body')
|
->example('Body')
|
||||||
->label('Name')
|
->label('Characteristics Name')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('inspection_type')
|
ImportColumn::make('inspection_type')
|
||||||
->exampleHeader('Inspection Type')
|
->exampleHeader('Inspection Type')
|
||||||
@@ -102,29 +102,32 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
{
|
{
|
||||||
|
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
$plantCod = $this->data['plant'];
|
||||||
|
$plant = null;
|
||||||
|
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
|
$warnMsg[] = 'Invalid plant code found';
|
||||||
|
} else {
|
||||||
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
if (! $plant) {
|
if (! $plant) {
|
||||||
$warnMsg[] = "Plant not found";
|
$warnMsg[] = 'Plant not found';
|
||||||
}
|
} else {
|
||||||
|
|
||||||
$itemExists = Item::where('code', $this->data['item'])->first();
|
$itemExists = Item::where('code', $this->data['item'])->first();
|
||||||
if (! $itemExists) {
|
if (! $itemExists) {
|
||||||
$warnMsg[] = "Item not found";
|
$warnMsg[] = 'Item not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
$itemAgainstPlant = Item::where('code', $this->data['item'])
|
$itemAgainstPlant = Item::where('code', $this->data['item'])
|
||||||
->where('plant_id', $plant->id)
|
->where('plant_id', $plant->id)
|
||||||
->first();
|
->first();
|
||||||
if (! $itemAgainstPlant) {
|
if (! $itemAgainstPlant) {
|
||||||
$warnMsg[] = "Item code not found for the given plant";
|
$warnMsg[] = 'Item code not found for the given plant';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$itemId = $itemAgainstPlant->id;
|
$itemId = $itemAgainstPlant->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$lineExists = Line::where('name', $this->data['line'])->first();
|
$lineExists = Line::where('name', $this->data['line'])->first();
|
||||||
if (! $lineExists) {
|
if (! $lineExists) {
|
||||||
$warnMsg[] = "Line not found";
|
$warnMsg[] = 'Line not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
$lineAgainstPlant = Line::where('name', $this->data['line'])
|
$lineAgainstPlant = Line::where('name', $this->data['line'])
|
||||||
@@ -132,18 +135,15 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (! $lineAgainstPlant) {
|
if (! $lineAgainstPlant) {
|
||||||
$warnMsg[] = "Line not found for the given plant";
|
$warnMsg[] = 'Line not found for the given plant';
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$LineId = $lineAgainstPlant->id;
|
$LineId = $lineAgainstPlant->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$WorkgroupMaster = WorkGroupMaster::where('name', $this->data['work_group_master_id'])->where('plant_id', $plant->id)->first();
|
$WorkgroupMaster = WorkGroupMaster::where('name', $this->data['work_group_master_id'])->where('plant_id', $plant->id)->first();
|
||||||
if (! $WorkgroupMaster) {
|
if (! $WorkgroupMaster) {
|
||||||
$warnMsg[] = "Work Group Master value not found";
|
$warnMsg[] = 'Work Group Master value not found';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
|
|
||||||
$workGroupMasterId = $WorkgroupMaster->id;
|
$workGroupMasterId = $WorkgroupMaster->id;
|
||||||
|
|
||||||
@@ -158,18 +158,15 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
|
|
||||||
if (! $existsInLine) {
|
if (! $existsInLine) {
|
||||||
$warnMsg[] = "Work Group Master '{$WorkgroupMaster->name}' is not mapped to any line in this plant";
|
$warnMsg[] = "Work Group Master '{$WorkgroupMaster->name}' is not mapped to any line in this plant";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$workGroupMasterId = $WorkgroupMaster->id;
|
$workGroupMasterId = $WorkgroupMaster->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$machine = Machine::where('work_center', $this->data['machine'])->first();
|
$machine = Machine::where('work_center', $this->data['machine'])->first();
|
||||||
if (! $machine) {
|
if (! $machine) {
|
||||||
$warnMsg[] = "Work Center not found";
|
$warnMsg[] = 'Work Center not found';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$machineId = $machine->id;
|
$machineId = $machine->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,16 +175,14 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (! $machineAgainstPlant) {
|
if (! $machineAgainstPlant) {
|
||||||
$warnMsg[] = "Work Center not found for the given plant";
|
$warnMsg[] = 'Work Center not found for the given plant';
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$machineId = $machineAgainstPlant->id;
|
$machineId = $machineAgainstPlant->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = User::where('name', $this->data['created_by'])->first();
|
$user = User::where('name', $this->data['created_by'])->first();
|
||||||
if (! $user) {
|
if (! $user) {
|
||||||
$warnMsg[] = "Operator ID not found";
|
$warnMsg[] = 'Operator ID not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($this->data['inspection_type'] ?? null) == 'Value') {
|
if (($this->data['inspection_type'] ?? null) == 'Value') {
|
||||||
@@ -198,17 +193,17 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
if (is_null($upper) || is_null($lower) || is_null($middle)) {
|
if (is_null($upper) || is_null($lower) || is_null($middle)) {
|
||||||
$warnMsg[] = "For 'Value' inspection type, Upper, Lower, and Middle values are required.";
|
$warnMsg[] = "For 'Value' inspection type, Upper, Lower, and Middle values are required.";
|
||||||
} elseif (! is_numeric($upper) || ! is_numeric($lower) || ! is_numeric($middle)) {
|
} elseif (! is_numeric($upper) || ! is_numeric($lower) || ! is_numeric($middle)) {
|
||||||
$warnMsg[] = "Upper, Lower, and Middle values must be numeric.";
|
$warnMsg[] = 'Upper, Lower, and Middle values must be numeric.';
|
||||||
} elseif (! ($lower <= $middle && $middle <= $upper)) {
|
} elseif (! ($lower <= $middle && $middle <= $upper)) {
|
||||||
$warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower ≤ Middle ≤ Upper.";
|
$warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower ≤ Middle ≤ Upper.";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (! empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
$record = ProductCharacteristicsMaster::firstOrNew([
|
$record = ProductCharacteristicsMaster::firstOrNew([
|
||||||
'plant_id' => $plant->id,
|
'plant_id' => $plant->id,
|
||||||
'item_id' => $itemId,
|
'item_id' => $itemId,
|
||||||
|
|||||||
Reference in New Issue
Block a user