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