ranjith-dev #187
@@ -24,17 +24,18 @@ class BlockExporter 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('name')
|
||||
->label('NAME'),
|
||||
->label('BLOCK NAME'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
->label('UPDATED AT')
|
||||
->enabledByDefault(true),
|
||||
ExportColumn::make('deleted_at')
|
||||
->enabledByDefault(false)
|
||||
->label('DELETED AT'),
|
||||
->label('DELETED AT')
|
||||
->enabledByDefault(false),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class CharacteristicValueExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
|
||||
@@ -24,8 +24,8 @@ class CheckPointNameExporter 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('name')
|
||||
->label('CHECK POINT NAME'),
|
||||
ExportColumn::make('created_at')
|
||||
|
||||
@@ -24,8 +24,8 @@ class CheckPointTimeExporter 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('checkPointNames1.name')
|
||||
->label('CHECK POINT 1'),
|
||||
ExportColumn::make('checkPointNames2.name')
|
||||
|
||||
@@ -14,6 +14,7 @@ class DeviceMasterExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
@@ -21,8 +22,8 @@ class DeviceMasterExporter 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('name')
|
||||
->label('DEVICE NAME'),
|
||||
ExportColumn::make('mac_address')
|
||||
|
||||
@@ -10,7 +10,9 @@ use Filament\Actions\Exports\Models\Export;
|
||||
class EbReadingExporter extends Exporter
|
||||
{
|
||||
protected static ?string $model = EbReading::class;
|
||||
static $rowNumber = 0;
|
||||
|
||||
public static $rowNumber = 0;
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
@@ -20,8 +22,8 @@ class EbReadingExporter 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('lcd_segment_check')
|
||||
->label('LCD SEGMENT CHECK'),
|
||||
ExportColumn::make('meter_serial_no')
|
||||
|
||||
@@ -14,6 +14,7 @@ class EquipmentMasterExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
@@ -21,8 +22,8 @@ class EquipmentMasterExporter 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('machine.name')
|
||||
->label('MACHINE NAME'),
|
||||
ExportColumn::make('name')
|
||||
|
||||
@@ -14,6 +14,7 @@ class GrMasterExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
@@ -21,10 +22,10 @@ class GrMasterExporter 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'),
|
||||
->label('ITEM CODE'),
|
||||
ExportColumn::make('serial_number')
|
||||
->label('SERIAL NUMBER'),
|
||||
ExportColumn::make('gr_number')
|
||||
|
||||
@@ -24,8 +24,8 @@ class GuardNameExporter 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('name')
|
||||
->label('GUARD NAME'),
|
||||
ExportColumn::make('identification1')
|
||||
|
||||
@@ -24,8 +24,8 @@ class GuardPatrolEntryExporter extends Exporter
|
||||
}),
|
||||
// ExportColumn::make('id')
|
||||
// ->label('ID'),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('guardNames.name')
|
||||
->label('GUARD NAME'),
|
||||
ExportColumn::make('checkPointNames.name')
|
||||
|
||||
@@ -24,12 +24,12 @@ class LineExporter 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('name')
|
||||
->label('NAME'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('type')
|
||||
->label('TYPE'),
|
||||
->label('LINE TYPE'),
|
||||
ExportColumn::make('no_of_operation')
|
||||
->label('NO OF OPERATION'),
|
||||
ExportColumn::make('workGroup1.name')
|
||||
|
||||
@@ -22,12 +22,12 @@ class MachineExporter 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('line.name')
|
||||
->label('LINE'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('name')
|
||||
->label('MACHINE'),
|
||||
->label('MACHINE NAME'),
|
||||
ExportColumn::make('work_center')
|
||||
->label('WORK CENTER'),
|
||||
ExportColumn::make('workGroupMaster.name')
|
||||
|
||||
@@ -14,6 +14,7 @@ class MfmMeterExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
@@ -21,14 +22,14 @@ class MfmMeterExporter 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('device.name')
|
||||
->label('DEVICE NAME'),
|
||||
ExportColumn::make('sequence')
|
||||
->label('SEQUENCE'),
|
||||
ExportColumn::make('name')
|
||||
->label('NAME'),
|
||||
->label('METER NAME'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('updated_at')
|
||||
|
||||
@@ -14,6 +14,7 @@ class MfmParameterExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
@@ -21,12 +22,12 @@ class MfmParameterExporter 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('deviceName.name')
|
||||
->label('Device Name'),
|
||||
ExportColumn::make('name')
|
||||
->label('NAME'),
|
||||
->label('PARAMETER NAME'),
|
||||
ExportColumn::make('mfmMeter.name')
|
||||
->label('MFM METER'),
|
||||
ExportColumn::make('register_id')
|
||||
|
||||
@@ -23,7 +23,7 @@ class MotorTestingMasterExporter extends Exporter
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT'),
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('item.category')
|
||||
->label('CATEGORY'),
|
||||
ExportColumn::make('item.code')
|
||||
|
||||
@@ -37,13 +37,13 @@ class ProductionLineStopExporter extends Exporter
|
||||
ExportColumn::make('stop_min')
|
||||
->label('STOP MINUTE'),
|
||||
ExportColumn::make('line.name')
|
||||
->label('LINE'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('shift.block.name')
|
||||
->label('BLOCK'),
|
||||
->label('BLOCK NAME'),
|
||||
ExportColumn::make('shift.name')
|
||||
->label('SHIFT'),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
->label('SHIFT NAME'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('operator_id')
|
||||
->label('OPERATOR ID'),
|
||||
ExportColumn::make('created_at')
|
||||
|
||||
@@ -29,13 +29,13 @@ class ProductionPlanExporter extends Exporter
|
||||
ExportColumn::make('production_quantity')
|
||||
->label('PRODUCTION QUANTITY'),
|
||||
ExportColumn::make('line.name')
|
||||
->label('LINE'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('shift.block.name')
|
||||
->label('BLOCK'),
|
||||
->label('BLOCK NAME'),
|
||||
ExportColumn::make('shift.name')
|
||||
->label('SHIFT'),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
->label('SHIFT NAME'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('operator_id')
|
||||
->label('OPERATOR ID'),
|
||||
ExportColumn::make('created_at')
|
||||
|
||||
@@ -33,13 +33,13 @@ class ProductionQuantityExporter extends Exporter
|
||||
ExportColumn::make('item.uom')
|
||||
->label('UNIT OF MEASURE'),
|
||||
ExportColumn::make('line.name')
|
||||
->label('LINE'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('shift.block.name')
|
||||
->label('BLOCK'),
|
||||
->label('BLOCK NAME'),
|
||||
ExportColumn::make('shift.name')
|
||||
->label('SHIFT'),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
->label('SHIFT NAME'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('sap_msg_status')
|
||||
->label('SAP MESSAGE STATUS'),
|
||||
ExportColumn::make('sap_msg_description')
|
||||
|
||||
@@ -24,10 +24,10 @@ class QualityValidationExporter 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('line.name')
|
||||
->label('LINE'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('production_order')
|
||||
->label('PRODUCTION ORDER'),
|
||||
ExportColumn::make('serial_number')
|
||||
@@ -54,14 +54,14 @@ class QualityValidationExporter extends Exporter
|
||||
->label('NAME PLATE PUMP'),
|
||||
ExportColumn::make('name_plate_pumpset')
|
||||
->label('NAME PLATE PUMPSET'),
|
||||
ExportColumn::make('warranty_card')
|
||||
->label('WARRANTY CARD'),
|
||||
ExportColumn::make('tube_sticker_motor')
|
||||
->label('TUBE STICKER MOTOR'),
|
||||
ExportColumn::make('tube_sticker_pump')
|
||||
->label('TUBE STICKER PUMP'),
|
||||
ExportColumn::make('tube_sticker_pumpset')
|
||||
->label('TUBE STICKER PUMPSET'),
|
||||
ExportColumn::make('warranty_card')
|
||||
->label('WARRANTY CARD'),
|
||||
ExportColumn::make('part_validation1')
|
||||
->label('PART VALIDATION 1'),
|
||||
ExportColumn::make('part_validation2')
|
||||
|
||||
@@ -14,6 +14,7 @@ class SerialValidationExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
@@ -21,8 +22,8 @@ class SerialValidationExporter 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('invoice_number')
|
||||
->label('INVOICE NUMBER'),
|
||||
ExportColumn::make('serial_number')
|
||||
|
||||
@@ -25,11 +25,11 @@ class ShiftExporter extends Exporter
|
||||
return ++$rowNumber;
|
||||
}),
|
||||
ExportColumn::make('block.name')
|
||||
->label('BLOCK'),
|
||||
ExportColumn::make('plant.name')
|
||||
->label('PLANT'),
|
||||
->label('BLOCK NAME'),
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('name')
|
||||
->label('NAME'),
|
||||
->label('SHIFT NAME'),
|
||||
ExportColumn::make('start_time')
|
||||
->label('START TIME'),
|
||||
ExportColumn::make('duration')
|
||||
|
||||
@@ -24,18 +24,18 @@ class TestingPanelReadingExporter 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('line.name')
|
||||
->label('LINE'),
|
||||
->label('LINE NAME'),
|
||||
ExportColumn::make('machine.name')
|
||||
->label('MACHINE'),
|
||||
->label('MACHINE NAME'),
|
||||
ExportColumn::make('motorTestingMaster.item.code')
|
||||
->label('ITEM CODE'),
|
||||
ExportColumn::make('motorTestingMaster.item.description')
|
||||
->label('MODEL'),
|
||||
->label('MODEL DESCRIPTION'),
|
||||
ExportColumn::make('output')
|
||||
->label('OUTPUT'),
|
||||
->label('OUTPUT NAME'),
|
||||
ExportColumn::make('serial_number')
|
||||
->label('SERIAL NUMBER'),
|
||||
ExportColumn::make('winded_serial_number')
|
||||
@@ -125,7 +125,7 @@ class TestingPanelReadingExporter extends Exporter
|
||||
ExportColumn::make('rework_count')
|
||||
->label('REWORK COUNT'),
|
||||
ExportColumn::make('update_count')
|
||||
->label('UPDATE COUNT'),
|
||||
->label('UPDATED COUNT'),
|
||||
ExportColumn::make('output_flag')
|
||||
->label('OUTPUT FLAG'),
|
||||
ExportColumn::make('tested_by')
|
||||
|
||||
@@ -24,8 +24,8 @@ class WeightValidationExporter 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('obd_number')
|
||||
|
||||
@@ -14,6 +14,7 @@ class WorkGroupMasterExporter extends Exporter
|
||||
public static function getColumns(): array
|
||||
{
|
||||
static $rowNumber = 0;
|
||||
|
||||
return [
|
||||
ExportColumn::make('no')
|
||||
->label('NO')
|
||||
@@ -21,12 +22,12 @@ class WorkGroupMasterExporter 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('name')
|
||||
->label('NAME'),
|
||||
->label('WORK GROUP NAME'),
|
||||
ExportColumn::make('description')
|
||||
->label('DESCRIPTION'),
|
||||
->label('WORK GROUP DESCRIPTION'),
|
||||
ExportColumn::make('operation_number')
|
||||
->label('OPERATION NUMBER'),
|
||||
ExportColumn::make('created_by')
|
||||
|
||||
@@ -8,7 +8,6 @@ use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Notification;
|
||||
use Str;
|
||||
|
||||
class BlockImporter extends Importer
|
||||
@@ -20,16 +19,16 @@ class BlockImporter extends Importer
|
||||
return [
|
||||
ImportColumn::make('name')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Block Name')
|
||||
->exampleHeader('BLOCK NAME')
|
||||
->example('Block A')
|
||||
->label('Block Name')
|
||||
->label('BLOCK NAME')
|
||||
->rules(['required']),
|
||||
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']),
|
||||
];
|
||||
}
|
||||
@@ -37,21 +36,28 @@ class BlockImporter extends Importer
|
||||
public function resolveRecord(): ?Block
|
||||
{
|
||||
$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 '" . $this->data['plant'] . "' not found";
|
||||
$warnMsg[] = 'Plant not found';
|
||||
// $warnMsg[] = "Plant '" . $plantCod . "' not found";
|
||||
}
|
||||
}
|
||||
if (Str::length($this->data['name']) < 0) {
|
||||
$warnMsg[] = "Block name not found";
|
||||
$warnMsg[] = 'Block name not found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
return Block::updateOrCreate([
|
||||
'name' => $this->data['name'],
|
||||
'plant_id' => $plant->id
|
||||
'plant_id' => $plant->id,
|
||||
]);
|
||||
// return Block::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
|
||||
@@ -20,10 +20,10 @@ class CheckPointNameImporter 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('name')
|
||||
->requiredMapping()
|
||||
@@ -43,16 +43,22 @@ class CheckPointNameImporter extends Importer
|
||||
public function resolveRecord(): ?CheckPointName
|
||||
{
|
||||
$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"; // '" . $this->data['plant'] . "'
|
||||
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
|
||||
}
|
||||
}
|
||||
if (Str::length($this->data['name']) < 3) { // || !ctype_alnum($this->data['name'])
|
||||
$warnMsg[] = "Invalid check point name found";
|
||||
$warnMsg[] = 'Invalid check point name found';
|
||||
}
|
||||
$createdBy = $this->data['created_by'];
|
||||
if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy)
|
||||
$warnMsg[] = "Invalid created by name found";
|
||||
$warnMsg[] = 'Invalid created by name found';
|
||||
}
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
@@ -60,10 +66,10 @@ class CheckPointNameImporter extends Importer
|
||||
|
||||
return CheckPointName::updateOrCreate([
|
||||
'name' => $this->data['name'],
|
||||
'plant_id' => $plant->id
|
||||
'plant_id' => $plant->id,
|
||||
],
|
||||
[
|
||||
'created_by' => $this->data['created_by']
|
||||
'created_by' => $this->data['created_by'],
|
||||
]
|
||||
);
|
||||
// // return CheckPointName::firstOrNew([
|
||||
|
||||
@@ -21,10 +21,10 @@ class CheckPointTimeImporter 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('checkPointNames1')
|
||||
->requiredMapping()
|
||||
@@ -73,49 +73,50 @@ class CheckPointTimeImporter extends Importer
|
||||
public function resolveRecord(): ?CheckPointTime
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$checkPointNames1 = null;
|
||||
$checkPointNames2 = 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"; // '" . $this->data['plant'] . "'
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
|
||||
} else {
|
||||
$checkPointNames1 = CheckPointName::where('name', $this->data['checkPointNames1'])->first();
|
||||
if (! $checkPointNames1) {
|
||||
$warnMsg[] = "Check point 1 not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = 'Check point 1 not found';
|
||||
} else {
|
||||
$checkPointNames2 = CheckPointName::where('name', $this->data['checkPointNames2'])->first();
|
||||
if (! $checkPointNames2) {
|
||||
$warnMsg[] = "Check point 2 not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = 'Check point 2 not found';
|
||||
} else {
|
||||
if ($checkPointNames1->id === $checkPointNames2->id) {
|
||||
$warnMsg[] = "Check point 1 and 2 can't be the same";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($this->data['sequence_number']) < 1 || ! is_numeric($this->data['sequence_number']) || $this->data['sequence_number'] <= 0) {
|
||||
$warnMsg[] = "Invalid sequence number found";
|
||||
$warnMsg[] = 'Invalid sequence number found';
|
||||
}
|
||||
|
||||
if (Str::length($this->data['time_lapse']) < 1 || ! is_numeric($this->data['time_lapse']) || $this->data['time_lapse'] <= 0) {
|
||||
$warnMsg[] = "Invalid time lapse found";
|
||||
$warnMsg[] = 'Invalid time lapse found';
|
||||
}
|
||||
|
||||
if (Str::length($this->data['time_lapse_cushioning']) < 1 || ! is_numeric($this->data['time_lapse_cushioning']) || $this->data['time_lapse_cushioning'] <= 0) {
|
||||
$warnMsg[] = "Invalid time lapse cushioning found";
|
||||
$warnMsg[] = 'Invalid time lapse cushioning found';
|
||||
}
|
||||
|
||||
$createdBy = $this->data['created_by'];
|
||||
if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy)
|
||||
$warnMsg[] = "Invalid created by name found";
|
||||
$warnMsg[] = 'Invalid created by name found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
@@ -124,12 +125,12 @@ class CheckPointTimeImporter extends Importer
|
||||
'plant_id' => $plant->id,
|
||||
'check_point1_id' => $checkPointNames1->id,
|
||||
'check_point2_id' => $checkPointNames2->id,
|
||||
'sequence_number' => $this->data['sequence_number']
|
||||
'sequence_number' => $this->data['sequence_number'],
|
||||
],
|
||||
[
|
||||
'time_lapse' => $this->data['time_lapse'],
|
||||
'time_lapse_cushioning' => $this->data['time_lapse_cushioning'],
|
||||
'created_by' => $this->data['created_by']
|
||||
'created_by' => $this->data['created_by'],
|
||||
]
|
||||
);
|
||||
// // return CheckPointTime::firstOrNew([
|
||||
|
||||
@@ -62,7 +62,7 @@ class ConfigurationImporter extends Importer
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new Configuration();
|
||||
return new Configuration;
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -16,10 +16,10 @@ class DeviceMasterImporter 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('name')
|
||||
->requiredMapping()
|
||||
@@ -53,7 +53,7 @@ class DeviceMasterImporter extends Importer
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new DeviceMaster();
|
||||
return new DeviceMaster;
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -16,10 +16,10 @@ class EbReadingImporter 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('lcd_segment_check')
|
||||
->label('LCD Segment Check')
|
||||
@@ -227,7 +227,7 @@ class EbReadingImporter extends Importer
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new EbReading();
|
||||
return new EbReading;
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -16,10 +16,10 @@ class EquipmentMasterImporter 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('machine')
|
||||
->requiredMapping()
|
||||
@@ -93,7 +93,7 @@ class EquipmentMasterImporter extends Importer
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new EquipmentMaster();
|
||||
return new EquipmentMaster;
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\GrMaster;
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use App\Models\User;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use App\Models\Plant;
|
||||
use App\Models\Item;
|
||||
use Str;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use App\Models\User;
|
||||
|
||||
class GrMasterImporter extends Importer
|
||||
{
|
||||
@@ -21,10 +21,10 @@ class GrMasterImporter 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()
|
||||
@@ -63,44 +63,47 @@ class GrMasterImporter extends Importer
|
||||
// ]);
|
||||
|
||||
$warnMsg = [];
|
||||
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$item = null;
|
||||
if ($plant) {
|
||||
|
||||
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';
|
||||
} else {
|
||||
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
||||
}
|
||||
if (! $item) {
|
||||
$warnMsg[] = "Item not found";
|
||||
$warnMsg[] = 'Item not found';
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($this->data['serial_number']) < 9 || ! ctype_alnum($this->data['serial_number'])) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
$warnMsg[] = 'Invalid serial number found';
|
||||
}
|
||||
|
||||
if (empty($this->data['gr_number'])) {
|
||||
$warnMsg[] = "GR Number cannot be empty.";
|
||||
$warnMsg[] = 'GR Number cannot be empty.';
|
||||
}
|
||||
|
||||
$user = User::where('name', $this->data['created_by'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = "User not found";
|
||||
$warnMsg[] = 'User not found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
else { //if (empty($warnMsg))
|
||||
} else { // if (empty($warnMsg))
|
||||
$grMaster = GrMaster::where('plant_id', $plant->id)
|
||||
->where('serial_number', $this->data['serial_number'])
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($grMaster) {
|
||||
throw new RowImportFailedException("Serial number already exist!");
|
||||
throw new RowImportFailedException('Serial number already exist!');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,10 +20,10 @@ class GuardNameImporter 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('name')
|
||||
->requiredMapping()
|
||||
@@ -54,19 +54,25 @@ class GuardNameImporter extends Importer
|
||||
public function resolveRecord(): ?GuardName
|
||||
{
|
||||
$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"; // '" . $this->data['plant'] . "'
|
||||
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
|
||||
}
|
||||
}
|
||||
if (Str::length($this->data['name']) < 3) { // || !ctype_alnum($this->data['name'])
|
||||
$warnMsg[] = "Invalid guard name found";
|
||||
$warnMsg[] = 'Invalid guard name found';
|
||||
}
|
||||
if (Str::length($this->data['identification1']) < 5) {
|
||||
$warnMsg[] = "Invalid identification-1 found";
|
||||
$warnMsg[] = 'Invalid identification-1 found';
|
||||
}
|
||||
$createdBy = $this->data['created_by'];
|
||||
if (Str::length($createdBy) < 3) { // || !ctype_alnum($createdBy)
|
||||
$warnMsg[] = "Invalid created by name found";
|
||||
$warnMsg[] = 'Invalid created by name found';
|
||||
}
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
@@ -74,12 +80,12 @@ class GuardNameImporter extends Importer
|
||||
|
||||
return GuardName::updateOrCreate([
|
||||
'name' => $this->data['name'],
|
||||
'plant_id' => $plant->id
|
||||
'plant_id' => $plant->id,
|
||||
],
|
||||
[
|
||||
'identification1' => $this->data['identification1'],
|
||||
'identification2' => $this->data['identification2'],
|
||||
'created_by' => $this->data['created_by']
|
||||
'created_by' => $this->data['created_by'],
|
||||
]
|
||||
);
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ class GuardPatrolEntryImporter 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('guardNames')
|
||||
->requiredMapping()
|
||||
@@ -68,27 +68,27 @@ class GuardPatrolEntryImporter extends Importer
|
||||
public function resolveRecord(): ?GuardPatrolEntry
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$guardNames = null;
|
||||
$checkPointNames = null;
|
||||
$patrolDateTime = null; // $fdateTime = 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"; // '" . $this->data['plant'] . "'
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = 'Plant not found'; // '" . $plantCod . "'
|
||||
} else {
|
||||
$guardNames = GuardName::where('plant_id', $plant->id)->where('name', $this->data['guardNames'])->first();
|
||||
if (! $guardNames) {
|
||||
$warnMsg[] = "Guard name not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = 'Guard name not found';
|
||||
} else {
|
||||
$checkPointNames = CheckPointName::where('plant_id', $plant->id)->where('name', $this->data['checkPointNames'])->first();
|
||||
if (! $checkPointNames) {
|
||||
$warnMsg[] = "Check point name not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = 'Check point name not found';
|
||||
} else {
|
||||
$patrolTime = $this->data['patrol_time']; // $fromDate = $this->data['from_datetime'];
|
||||
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||
|
||||
@@ -105,12 +105,11 @@ class GuardPatrolEntryImporter extends Importer
|
||||
if (! isset($patrolDateTime)) {
|
||||
// throw new \Exception('Invalid date time format');
|
||||
$warnMsg[] = "Invalid 'Patrol DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$guardEntryFound = GuardPatrolEntry::where('plant_id', $plant->id)->where('guard_name_id', $guardNames->id)->where('check_point_name_id', $checkPointNames->id)->where('patrol_time', $patrolDateTime->format('Y-m-d H:i:s'))->first();
|
||||
if ($guardEntryFound) {
|
||||
$warnMsg[] = "Duplicate guard patrol entry found";
|
||||
$warnMsg[] = 'Duplicate guard patrol entry found';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -119,7 +118,7 @@ class GuardPatrolEntryImporter extends Importer
|
||||
|
||||
$createdBy = Filament::auth()->user()->name; // ?? 'Admin'
|
||||
if (! $createdBy) {
|
||||
$warnMsg[] = "Invalid created by name found";
|
||||
$warnMsg[] = 'Invalid created by name found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
@@ -130,14 +129,15 @@ class GuardPatrolEntryImporter extends Importer
|
||||
'plant_id' => $plant->id,
|
||||
'guard_name_id' => $guardNames->id,
|
||||
'check_point_name_id' => $checkPointNames->id,
|
||||
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s')
|
||||
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s'),
|
||||
],
|
||||
[
|
||||
'reader_code' => null,
|
||||
'created_by' => $createdBy,
|
||||
'updated_by' => $createdBy
|
||||
'updated_by' => $createdBy,
|
||||
]
|
||||
);
|
||||
|
||||
return null;
|
||||
// // return GuardPatrolEntry::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
|
||||
@@ -87,10 +87,10 @@ class LineImporter extends Importer
|
||||
->label('Work Group Center 10'),
|
||||
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']),
|
||||
];
|
||||
}
|
||||
@@ -98,18 +98,24 @@ class LineImporter extends Importer
|
||||
public function resolveRecord(): ?Line
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
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) {
|
||||
throw new RowImportFailedException("Plant '{$this->data['plant']}' not found");
|
||||
throw new RowImportFailedException('Plant not found');
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($this->data['name'] ?? '') <= 0) {
|
||||
throw new RowImportFailedException("Line name not found");
|
||||
throw new RowImportFailedException('Line name not found');
|
||||
}
|
||||
|
||||
if (Str::length($this->data['type'] ?? '') <= 0) {
|
||||
throw new RowImportFailedException("Line type not found");
|
||||
throw new RowImportFailedException('Line type not found');
|
||||
}
|
||||
|
||||
$noOfOps = (int) ($this->data['no_of_operation'] ?? 0);
|
||||
@@ -118,8 +124,7 @@ class LineImporter extends Importer
|
||||
throw new RowImportFailedException("'No of Operation' is required and must be a number $noOfOps");
|
||||
}
|
||||
|
||||
if ($noOfOps > 10)
|
||||
{
|
||||
if ($noOfOps > 10) {
|
||||
throw new RowImportFailedException("Invalid 'No Of Operation' value: {$noOfOps}, maximum allowed is 10");
|
||||
}
|
||||
|
||||
@@ -132,7 +137,7 @@ class LineImporter extends Importer
|
||||
}
|
||||
if (! empty($missingGroups)) {
|
||||
throw new RowImportFailedException(
|
||||
"Invalid data: Required work groups missing values in: " . implode(', ', $missingGroups)
|
||||
'Invalid data: Required work groups missing values in: '.implode(', ', $missingGroups)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -160,7 +165,7 @@ class LineImporter extends Importer
|
||||
->first();
|
||||
|
||||
if (! $workGroupRecord) {
|
||||
throw new RowImportFailedException("Work group '{$workGroupName}' not found in plant '{$this->data['plant']}'");
|
||||
throw new RowImportFailedException("Work group '{$workGroupName}' not found in plant '{$plantCod}'");
|
||||
}
|
||||
|
||||
$existsInLines = Line::where('plant_id', $plant->id)
|
||||
@@ -169,21 +174,20 @@ class LineImporter extends Importer
|
||||
->first();
|
||||
|
||||
if ($existsInLines) {
|
||||
$warnMsg[] = "Work group '{$workGroupName}' is already assigned to another line in plant '{$this->data['plant']}'";
|
||||
$warnMsg[] = "Work group '{$workGroupName}' is already assigned to another line in plant '{$plantCod}'";
|
||||
}
|
||||
|
||||
$this->data["work_group{$i}_id"] = $workGroupRecord->id;
|
||||
}
|
||||
|
||||
if (!empty($warnMsg))
|
||||
{
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
|
||||
Line::updateOrCreate(
|
||||
[
|
||||
'name' => $this->data['name'],
|
||||
'plant_id' => $plant->id
|
||||
'plant_id' => $plant->id,
|
||||
],
|
||||
[
|
||||
'type' => $this->data['type'],
|
||||
|
||||
@@ -10,7 +10,6 @@ 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 LocatorInvoiceValidationImporter extends Importer
|
||||
@@ -116,48 +115,44 @@ class LocatorInvoiceValidationImporter extends Importer
|
||||
$updatedBy = $this->data['updated_by'];
|
||||
|
||||
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', $this->data['plant'])->first();
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
} else {
|
||||
$plant = Plant::where('code', $plantCod)->first();
|
||||
if (! $plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
if (Str::length($invoiceNo) < 5 || ! ctype_alnum($invoiceNo)) {
|
||||
$warnMsg[] = "Invalid invoice number found";
|
||||
$warnMsg[] = 'Invalid invoice number found';
|
||||
}
|
||||
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
$warnMsg[] = 'Invalid serial number found';
|
||||
}
|
||||
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
|
||||
$warnMsg[] = "Invalid pallet number found";
|
||||
$warnMsg[] = 'Invalid pallet number found';
|
||||
}
|
||||
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
|
||||
$warnMsg[] = "Invalid locator number found";
|
||||
$warnMsg[] = 'Invalid locator number found';
|
||||
}
|
||||
if (Str::length($scannedStat) > 0 && $scannedStat != 'Scanned') {
|
||||
$warnMsg[] = "Invalid scanned status found";
|
||||
$warnMsg[] = 'Invalid scanned status found';
|
||||
}
|
||||
if ($uploadStat != 'Y' && $uploadStat != 'N') {
|
||||
$warnMsg[] = "Invalid upload status found";
|
||||
$warnMsg[] = 'Invalid upload status found';
|
||||
}
|
||||
$created = User::where('name', $createdBy)->first();
|
||||
if (! $created) {
|
||||
$warnMsg[] = "Created by not found";
|
||||
$warnMsg[] = 'Created by not found';
|
||||
}
|
||||
if (Str::length($scannedBy) > 0) {
|
||||
$scanned = User::where('name', $scannedBy)->first();
|
||||
if (! $scanned) {
|
||||
$warnMsg[] = "Scanned by not found";
|
||||
$warnMsg[] = 'Scanned by not found';
|
||||
}
|
||||
}
|
||||
if (Str::length($updatedBy) > 0) {
|
||||
$updated = User::where('name', $updatedBy)->first();
|
||||
if (! $updated) {
|
||||
$warnMsg[] = "Updated by not found";
|
||||
$warnMsg[] = 'Updated by not found';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,8 +173,7 @@ class LocatorInvoiceValidationImporter extends Importer
|
||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
|
||||
if (Str::length($scannedAt) > 0)
|
||||
{
|
||||
if (Str::length($scannedAt) > 0) {
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$sDateTime = Carbon::createFromFormat($format, $scannedAt);
|
||||
@@ -195,8 +189,7 @@ class LocatorInvoiceValidationImporter extends Importer
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($updatedAt) > 0)
|
||||
{
|
||||
if (Str::length($updatedAt) > 0) {
|
||||
foreach ($formats as $format) {
|
||||
try {
|
||||
$uDateTime = Carbon::createFromFormat($format, $updatedAt);
|
||||
@@ -209,9 +202,7 @@ class LocatorInvoiceValidationImporter extends Importer
|
||||
|
||||
if (! isset($uDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (isset($cDateTime) && isset($uDateTime)) {
|
||||
if ($cDateTime->greaterThan($uDateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||
@@ -233,7 +224,7 @@ class LocatorInvoiceValidationImporter extends Importer
|
||||
LocatorInvoiceValidation::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'serial_number' => $serialNo
|
||||
'serial_number' => $serialNo,
|
||||
],
|
||||
[
|
||||
'invoice_number' => $invoiceNo,
|
||||
@@ -246,9 +237,10 @@ class LocatorInvoiceValidationImporter extends Importer
|
||||
'updated_at' => (Str::length($updatedAt) > 0) ? $uDateTime->format('Y-m-d H:i:s') : null,
|
||||
'created_by' => $createdBy,
|
||||
'scanned_by' => $scannedBy,
|
||||
'updated_by' => $updatedBy
|
||||
'updated_by' => $updatedBy,
|
||||
]
|
||||
);
|
||||
|
||||
return null;
|
||||
// // return LocatorInvoiceValidation::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
|
||||
@@ -21,9 +21,9 @@ class MachineImporter extends Importer
|
||||
return [
|
||||
ImportColumn::make('name')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Machine')
|
||||
->exampleHeader('Machine Name')
|
||||
->example(['1600251'])
|
||||
->label('Machine')
|
||||
->label('Machine Name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('work_center')
|
||||
->requiredMapping()
|
||||
@@ -41,16 +41,16 @@ class MachineImporter extends Importer
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Line')
|
||||
->exampleHeader('Line Name')
|
||||
->example(['4 inch pump line'])
|
||||
->label('Line')
|
||||
->label('Line Name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Plant')
|
||||
->example(['Ransar Industries-I'])
|
||||
->label('Plant')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000'])
|
||||
->label('Plant Code')
|
||||
->rules(['required']),
|
||||
];
|
||||
}
|
||||
@@ -58,37 +58,37 @@ class MachineImporter extends Importer
|
||||
public function resolveRecord(): ?Machine
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$line = null;
|
||||
$machine = $this->data['name'];
|
||||
$workCenter = $this->data['work_center'];
|
||||
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->first();
|
||||
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!";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Plant not found!';
|
||||
} else {
|
||||
$groupWorkCenter = WorkGroupMaster::where('name', $this->data['workGroupMaster'])->where('plant_id', $plant->id)->first();
|
||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||
if ($line) {
|
||||
$grpWrkCnr = $line->no_of_operation;
|
||||
if (!$grpWrkCnr || $grpWrkCnr < 1)//Str::length($grpWrkCnr) < 1)
|
||||
{
|
||||
$warnMsg[] = "Group work center line not found!";
|
||||
}
|
||||
else if (!$groupWorkCenter) {
|
||||
$warnMsg[] = "Group work center not found!";
|
||||
}
|
||||
else {
|
||||
if (! $grpWrkCnr || $grpWrkCnr < 1) {// Str::length($grpWrkCnr) < 1)
|
||||
$warnMsg[] = 'Group work center line not found!';
|
||||
} elseif (! $groupWorkCenter) {
|
||||
$warnMsg[] = 'Group work center not found!';
|
||||
} else {
|
||||
$dupMachine = Machine::where('plant_id', $plant->id)->where('work_center', '!=', $workCenter)->where('name', $machine)->first();
|
||||
if ($dupMachine) {
|
||||
$warnMsg[] = "Duplicate machine name found!";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Duplicate machine name found!';
|
||||
} else {
|
||||
$isValidGroupWork = false;
|
||||
for ($i = 1; $i <= $line->no_of_operation; $i++) {
|
||||
$column = "work_group{$i}_id";
|
||||
if (! empty($line->$column)) {
|
||||
if ($line->$column == $groupWorkCenter->id) {
|
||||
if ($groupWorkCenter->id == $line->$column) {
|
||||
$isValidGroupWork = true;
|
||||
break;
|
||||
}
|
||||
@@ -96,19 +96,18 @@ class MachineImporter extends Importer
|
||||
}
|
||||
|
||||
if (! $isValidGroupWork) {
|
||||
$warnMsg[] = "Group work center does not match with line!";
|
||||
$warnMsg[] = 'Group work center does not match with line!';
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$warnMsg[] = 'Line not found!';
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = "Line not found!";
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($machine) <= 0) {
|
||||
$warnMsg[] = "Machine name not found!";
|
||||
$warnMsg[] = 'Machine name not found!';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
@@ -118,14 +117,15 @@ class MachineImporter extends Importer
|
||||
Machine::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'work_center' => $workCenter
|
||||
'work_center' => $workCenter,
|
||||
],
|
||||
[
|
||||
'line_id' => $line->id,
|
||||
'name' => $machine,
|
||||
'work_group_master_id' => $groupWorkCenter->id
|
||||
'work_group_master_id' => $groupWorkCenter->id,
|
||||
]
|
||||
);
|
||||
|
||||
return null;
|
||||
// // return Machine::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
|
||||
@@ -16,10 +16,10 @@ class MfmMeterImporter 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('Device Name')
|
||||
->requiredMapping()
|
||||
@@ -56,7 +56,7 @@ class MfmMeterImporter extends Importer
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new MfmMeter();
|
||||
return new MfmMeter;
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -16,10 +16,10 @@ class MfmParameterImporter 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('deviceName')
|
||||
->requiredMapping()
|
||||
@@ -82,7 +82,7 @@ class MfmParameterImporter extends Importer
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new MfmParameter();
|
||||
return new MfmParameter;
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -237,7 +237,7 @@ class MotorTestingMasterImporter extends Importer
|
||||
$plantCod = trim($this->data['plant']);
|
||||
$iCode = trim($this->data['item']);
|
||||
$sCode = trim($this->data['subassembly_code']);
|
||||
$isiModel = (trim($this->data['isi_model']) == "1") ? true : false;
|
||||
$isiModel = (trim($this->data['isi_model']) == '1') ? true : false;
|
||||
$phase = trim($this->data['phase']);
|
||||
$kw = trim($this->data['kw']);
|
||||
$hp = trim($this->data['hp']);
|
||||
@@ -270,40 +270,25 @@ class MotorTestingMasterImporter extends Importer
|
||||
$updatedBy = trim($this->data['updated_by']);
|
||||
|
||||
$plant = null;
|
||||
if (Str::length($plantCod) < 4 || !is_numeric($plantCod) || !preg_match('/^[1-9]\d{3,}$/', $plantCod))
|
||||
{
|
||||
$warnMsg[] = "Invalid plant code found";
|
||||
}
|
||||
else if (Str::length($iCode) < 6 || !ctype_alnum($iCode))
|
||||
{
|
||||
$warnMsg[] = "Invalid item code found";
|
||||
}
|
||||
else if (Str::length($sCode) < 6 || !ctype_alnum($sCode))
|
||||
{
|
||||
$warnMsg[] = "Invalid sub-assembly code found";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
} elseif (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
|
||||
$warnMsg[] = 'Invalid item code found';
|
||||
} elseif (Str::length($sCode) < 6 || ! ctype_alnum($sCode)) {
|
||||
$warnMsg[] = 'Invalid sub-assembly code found';
|
||||
} else {
|
||||
$plant = Plant::where('code', $plantCod)->first();
|
||||
$codeExist = Item::where('code', $iCode)->first();
|
||||
if ($plant)
|
||||
{
|
||||
if ($plant) {
|
||||
$iCode = Item::where('code', $iCode)->where('plant_id', $plant->id)->first();
|
||||
}
|
||||
if (!$plant)
|
||||
{
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else if (!$codeExist)
|
||||
{
|
||||
$warnMsg[] = "Item code not found";
|
||||
}
|
||||
else if (!$iCode)
|
||||
{
|
||||
$warnMsg[] = "Item code not found for choosed plant";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (! $plant) {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} elseif (! $codeExist) {
|
||||
$warnMsg[] = 'Item code not found';
|
||||
} elseif (! $iCode) {
|
||||
$warnMsg[] = 'Item code not found for choosed plant';
|
||||
} else {
|
||||
// if (Str::length($isiModel) <= 0 || $isiModel == "0" || $isiModel == "1") {
|
||||
// $warnMsg[] = "Invalid ISI Model found";
|
||||
// }
|
||||
@@ -311,89 +296,89 @@ class MotorTestingMasterImporter extends Importer
|
||||
// {
|
||||
// $isiModel = ($isiModel == "1");
|
||||
// }
|
||||
if (Str::length($phase) <= 0 || ($phase != "Single" && $phase != "Three")) {//!is_string($phase) ||
|
||||
$warnMsg[] = "Invalid phase found";
|
||||
if (Str::length($phase) <= 0 || ($phase != 'Single' && $phase != 'Three')) {// !is_string($phase) ||
|
||||
$warnMsg[] = 'Invalid phase found';
|
||||
}
|
||||
if (Str::length($hp) <= 0 || ! is_numeric($hp)) {
|
||||
$warnMsg[] = "Invalid HP found";
|
||||
$warnMsg[] = 'Invalid HP found';
|
||||
}
|
||||
if (Str::length($kw) <= 0 || ! is_numeric($kw)) {
|
||||
$warnMsg[] = "Invalid KW found";
|
||||
$warnMsg[] = 'Invalid KW found';
|
||||
}
|
||||
if (Str::length($volt) <= 0 || ! is_numeric($volt)) {
|
||||
$warnMsg[] = "Invalid volt found";
|
||||
$warnMsg[] = 'Invalid volt found';
|
||||
}
|
||||
if (Str::length($current) <= 0 || ! is_numeric($current)) {
|
||||
$warnMsg[] = "Invalid current found";
|
||||
$warnMsg[] = 'Invalid current found';
|
||||
}
|
||||
if (Str::length($rpm) <= 0 || ! is_numeric($rpm)) {
|
||||
$warnMsg[] = "Invalid RPM found";
|
||||
$warnMsg[] = 'Invalid RPM found';
|
||||
}
|
||||
if (Str::length($torque) <= 0 || ! is_numeric($torque)) {
|
||||
$warnMsg[] = "Invalid torque found";
|
||||
$warnMsg[] = 'Invalid torque found';
|
||||
}
|
||||
if (Str::length($frequency) <= 0 || ! is_numeric($frequency)) {
|
||||
$warnMsg[] = "Invalid frequency found";
|
||||
$warnMsg[] = 'Invalid frequency found';
|
||||
}
|
||||
if (Str::length($connection) <= 0 || ($connection != "Star-Delta" && $connection != "Star" && $connection != "Delta")) {
|
||||
$warnMsg[] = "Invalid connection found";
|
||||
if (Str::length($connection) <= 0 || ($connection != 'Star-Delta' && $connection != 'Star' && $connection != 'Delta')) {
|
||||
$warnMsg[] = 'Invalid connection found';
|
||||
}
|
||||
if (Str::length($insResLimit) <= 0 || ! is_numeric($insResLimit)) {
|
||||
$warnMsg[] = "Invalid insulation resistance limit found";
|
||||
$warnMsg[] = 'Invalid insulation resistance limit found';
|
||||
}
|
||||
if (Str::length($insResType) <= 0 || ($insResType != "O" && $insResType != "M" && $insResType != "G")) {
|
||||
$warnMsg[] = "Invalid insulation resistance type found";
|
||||
if (Str::length($insResType) <= 0 || ($insResType != 'O' && $insResType != 'M' && $insResType != 'G')) {
|
||||
$warnMsg[] = 'Invalid insulation resistance type found';
|
||||
}
|
||||
if (Str::length($routineTestTime) <= 0 || ! isValidTimeFormat($routineTestTime)) {
|
||||
$warnMsg[] = "Invalid routine test time found";
|
||||
$warnMsg[] = 'Invalid routine test time found';
|
||||
}
|
||||
if (Str::length($resRyLl) <= 0 || ! is_numeric($resRyLl)) {
|
||||
$warnMsg[] = "Invalid resistance RY lower limit found";
|
||||
$warnMsg[] = 'Invalid resistance RY lower limit found';
|
||||
}
|
||||
if (Str::length($resRyUl) <= 0 || ! is_numeric($resRyUl)) {
|
||||
$warnMsg[] = "Invalid resistance RY upper limit found";
|
||||
$warnMsg[] = 'Invalid resistance RY upper limit found';
|
||||
}
|
||||
if (Str::length($resYbLl) <= 0 || ! is_numeric($resYbLl)) {
|
||||
$warnMsg[] = "Invalid resistance YB lower limit found";
|
||||
$warnMsg[] = 'Invalid resistance YB lower limit found';
|
||||
}
|
||||
if (Str::length($resYbUl) <= 0 || ! is_numeric($resYbUl)) {
|
||||
$warnMsg[] = "Invalid resistance YB upper limit found";
|
||||
$warnMsg[] = 'Invalid resistance YB upper limit found';
|
||||
}
|
||||
if (Str::length($resBrLl) <= 0 || ! is_numeric($resBrLl)) {
|
||||
$warnMsg[] = "Invalid resistance BR lower limit found";
|
||||
$warnMsg[] = 'Invalid resistance BR lower limit found';
|
||||
}
|
||||
if (Str::length($resBrUl) <= 0 || ! is_numeric($resBrUl)) {
|
||||
$warnMsg[] = "Invalid resistance BR upper limit found";
|
||||
$warnMsg[] = 'Invalid resistance BR upper limit found';
|
||||
}
|
||||
if (Str::length($lockVoltLimit) <= 0 || ! is_numeric($lockVoltLimit)) {
|
||||
$warnMsg[] = "Invalid locked volt limit found";
|
||||
$warnMsg[] = 'Invalid locked volt limit found';
|
||||
}
|
||||
if (Str::length($leakCurLimit) <= 0 || ! is_numeric($leakCurLimit)) {
|
||||
$warnMsg[] = "Invalid leakage current limit found";
|
||||
$warnMsg[] = 'Invalid leakage current limit found';
|
||||
}
|
||||
if (Str::length($lockCurLl) <= 0 || ! is_numeric($lockCurLl)) {
|
||||
$warnMsg[] = "Invalid locked current lower limit found";
|
||||
$warnMsg[] = 'Invalid locked current lower limit found';
|
||||
}
|
||||
if (Str::length($lockCurUl) <= 0 || ! is_numeric($lockCurUl)) {
|
||||
$warnMsg[] = "Invalid locked current upper limit found";
|
||||
$warnMsg[] = 'Invalid locked current upper limit found';
|
||||
}
|
||||
if (Str::length($noloadCurLl) <= 0 || ! is_numeric($noloadCurLl)) {
|
||||
$warnMsg[] = "Invalid no load current lower limit found";
|
||||
$warnMsg[] = 'Invalid no load current lower limit found';
|
||||
}
|
||||
if (Str::length($noloadCurUl) <= 0 || ! is_numeric($noloadCurUl)) {
|
||||
$warnMsg[] = "Invalid no load current upper limit found";
|
||||
$warnMsg[] = 'Invalid no load current upper limit found';
|
||||
}
|
||||
if (Str::length($noloadPowLl) <= 0 || ! is_numeric($noloadPowLl)) {
|
||||
$warnMsg[] = "Invalid no load power lower limit found";
|
||||
$warnMsg[] = 'Invalid no load power lower limit found';
|
||||
}
|
||||
if (Str::length($noloadPowUl) <= 0 || ! is_numeric($noloadPowUl)) {
|
||||
$warnMsg[] = "Invalid no load power upper limit found";
|
||||
$warnMsg[] = 'Invalid no load power upper limit found';
|
||||
}
|
||||
if (Str::length($noloadSpdLl) <= 0 || ! is_numeric($noloadSpdLl)) {
|
||||
$warnMsg[] = "Invalid no load speed lower limit found";
|
||||
$warnMsg[] = 'Invalid no load speed lower limit found';
|
||||
}
|
||||
if (Str::length($noloadSpdUl) <= 0 || ! is_numeric($noloadSpdUl)) {
|
||||
$warnMsg[] = "Invalid no load speed upper limit found";
|
||||
$warnMsg[] = 'Invalid no load speed upper limit found';
|
||||
}
|
||||
|
||||
$oldCode = MotorTestingMaster::where('item_id', $iCode->id)->where('plant_id', $plant->id)->first();
|
||||
@@ -401,22 +386,20 @@ class MotorTestingMasterImporter extends Importer
|
||||
if ($oldCode) {
|
||||
$created = $oldCode->created_by ? User::where('name', $oldCode->created_by)->first() : null;
|
||||
if (! $created) {
|
||||
$warnMsg[] = "Created by not found on update";
|
||||
$warnMsg[] = 'Created by not found on update';
|
||||
}
|
||||
$updated = User::where('name', $updatedBy)->first();
|
||||
if (! $updated) {
|
||||
$warnMsg[] = "Updated by not found on update";
|
||||
$warnMsg[] = 'Updated by not found on update';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$created = User::where('name', $createdBy)->first();
|
||||
if (! $created) {
|
||||
$warnMsg[] = "Created by not found";
|
||||
$warnMsg[] = 'Created by not found';
|
||||
}
|
||||
$updated = User::where('name', $updatedBy)->first();
|
||||
if (! $updated) {
|
||||
$warnMsg[] = "Updated by not found";
|
||||
$warnMsg[] = 'Updated by not found';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -428,7 +411,7 @@ class MotorTestingMasterImporter extends Importer
|
||||
|
||||
MotorTestingMaster::updateOrCreate([
|
||||
'plant_id' => $plant->id,
|
||||
'item_id' => $iCode->id
|
||||
'item_id' => $iCode->id,
|
||||
],
|
||||
[
|
||||
'subassembly_code' => $sCode,
|
||||
@@ -465,6 +448,7 @@ class MotorTestingMasterImporter extends Importer
|
||||
'updated_by' => $updated->name,
|
||||
]
|
||||
);
|
||||
|
||||
return null;
|
||||
// // return MotorTestingMaster::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
@@ -486,12 +470,14 @@ class MotorTestingMasterImporter extends Importer
|
||||
}
|
||||
}
|
||||
|
||||
function isValidTimeFormat($time) {
|
||||
function isValidTimeFormat($time)
|
||||
{
|
||||
// If time starts with a single digit hour without leading zero, pad it
|
||||
if (preg_match('/^\d(:\d{2}:\d{2})$/', $time, $matches)) {
|
||||
$time = '0'.$time;
|
||||
}
|
||||
|
||||
$dateTime = DateTime::createFromFormat('H:i:s', $time);
|
||||
|
||||
return $dateTime && $dateTime->format('H:i:s') === $time;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Str;
|
||||
|
||||
|
||||
class PalletValidationImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = PalletValidation::class;
|
||||
@@ -123,45 +122,41 @@ class PalletValidationImporter extends Importer
|
||||
$updatedBy = $this->data['updated_by'];
|
||||
|
||||
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', $this->data['plant'])->first();
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
} else {
|
||||
$plant = Plant::where('code', $plantCod)->first();
|
||||
if (! $plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
$warnMsg[] = 'Invalid serial number found';
|
||||
}
|
||||
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
|
||||
$warnMsg[] = "Invalid pallet number found";
|
||||
$warnMsg[] = 'Invalid pallet number found';
|
||||
}
|
||||
if (Str::length($palletStat) > 0 && $palletStat != 'Completed') {
|
||||
$warnMsg[] = "Invalid pallet status found";
|
||||
$warnMsg[] = 'Invalid pallet status found';
|
||||
}
|
||||
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
|
||||
$warnMsg[] = "Invalid locator number found";
|
||||
$warnMsg[] = 'Invalid locator number found';
|
||||
}
|
||||
if (Str::length($palletNo) <= 0 && Str::length($locatorNo) <= 0) {
|
||||
$warnMsg[] = "Pallet and locator number found";
|
||||
$warnMsg[] = 'Pallet and locator number found';
|
||||
}
|
||||
if (Str::length($locatorQty) < 0 || ! is_numeric($locatorQty) || $locatorQty < 0 || $locatorQty > 2) {
|
||||
$warnMsg[] = "Invalid locator quantity found";
|
||||
$warnMsg[] = 'Invalid locator quantity found';
|
||||
}
|
||||
$created = User::where('name', $createdBy)->first();
|
||||
if (! $created) {
|
||||
$warnMsg[] = "Created by not found";
|
||||
$warnMsg[] = 'Created by not found';
|
||||
}
|
||||
$scanned = User::where('name', $scannedBy)->first();
|
||||
if (! $scanned) {
|
||||
$warnMsg[] = "Scanned by not found";
|
||||
$warnMsg[] = 'Scanned by not found';
|
||||
}
|
||||
$updated = User::where('name', $updatedBy)->first();
|
||||
if (! $updated) {
|
||||
$warnMsg[] = "Updated by not found";
|
||||
$warnMsg[] = 'Updated by not found';
|
||||
}
|
||||
|
||||
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||
@@ -196,8 +191,7 @@ class PalletValidationImporter extends Importer
|
||||
}
|
||||
|
||||
foreach ($formats as $format) {
|
||||
try
|
||||
{
|
||||
try {
|
||||
$uDateTime = Carbon::createFromFormat($format, $updatedAt);
|
||||
break;
|
||||
} catch (\Exception $e) {
|
||||
@@ -208,9 +202,7 @@ class PalletValidationImporter extends Importer
|
||||
|
||||
if (! isset($uDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (isset($cDateTime) && isset($uDateTime)) {
|
||||
if ($cDateTime->greaterThan($uDateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||
@@ -231,7 +223,7 @@ class PalletValidationImporter extends Importer
|
||||
PalletValidation::updateOrCreate(
|
||||
[
|
||||
'plant_id' => $plant->id,
|
||||
'serial_number' => $serialNo
|
||||
'serial_number' => $serialNo,
|
||||
],
|
||||
[
|
||||
'pallet_number' => $palletNo,
|
||||
@@ -243,9 +235,10 @@ class PalletValidationImporter extends Importer
|
||||
'updated_at' => $uDateTime->format('Y-m-d H:i:s'),
|
||||
'created_by' => $createdBy,
|
||||
'scanned_by' => $scannedBy,
|
||||
'updated_by' => $updatedBy
|
||||
'updated_by' => $updatedBy,
|
||||
]
|
||||
);
|
||||
|
||||
return null;
|
||||
// // return PalletValidation::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
|
||||
@@ -51,16 +51,16 @@ class PlantImporter extends Importer
|
||||
$warnMsg = [];
|
||||
$company = Company::where('name', $this->data['company'])->first();
|
||||
if (! $company) {
|
||||
$warnMsg[] = "Company name not found";
|
||||
$warnMsg[] = 'Company name not found';
|
||||
}
|
||||
if (Str::length($this->data['name']) < 0) {
|
||||
$warnMsg[] = "Plant name not found";
|
||||
$warnMsg[] = 'Plant name not found';
|
||||
}
|
||||
if (Str::length($this->data['code']) < 4 || ! is_numeric($this->data['code']) || ! preg_match('/^[1-9]\d{3,}$/', $this->data['code'])) {
|
||||
$warnMsg[] = "Invalid plant code found";
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
}
|
||||
if (Str::length($this->data['address']) < 3) {
|
||||
$warnMsg[] = "Invalid address found";
|
||||
$warnMsg[] = 'Invalid address found';
|
||||
}
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
@@ -71,10 +71,9 @@ class PlantImporter extends Importer
|
||||
$plantCode = Plant::where('code', $this->data['code'])->first();
|
||||
$plantName = Plant::where('name', $this->data['name'])->first();
|
||||
if ($plantName) {
|
||||
throw new RowImportFailedException("Duplicate plant name found");
|
||||
}
|
||||
else if ($plantCode) {
|
||||
throw new RowImportFailedException("Duplicate plant code found");
|
||||
throw new RowImportFailedException('Duplicate plant name found');
|
||||
} elseif ($plantCode) {
|
||||
throw new RowImportFailedException('Duplicate plant code found');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +83,7 @@ class PlantImporter extends Importer
|
||||
],
|
||||
[
|
||||
'address' => $this->data['address'],
|
||||
'company_id' => $company->id
|
||||
'company_id' => $company->id,
|
||||
]
|
||||
);
|
||||
// return Plant::firstOrNew([
|
||||
|
||||
@@ -15,6 +15,7 @@ use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Facades\Filament;
|
||||
use Str;
|
||||
|
||||
class ProductionLineStopImporter extends Importer
|
||||
{
|
||||
@@ -78,10 +79,10 @@ class ProductionLineStopImporter extends Importer
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example(['Ransar Industries-I', 'Ransar Industries-I'])
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000', '1000'])
|
||||
->label('Plant Code')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('operator_id')
|
||||
->requiredMapping()
|
||||
@@ -95,56 +96,57 @@ class ProductionLineStopImporter extends Importer
|
||||
public function resolveRecord(): ?ProductionLineStop
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$line = null;
|
||||
$block = null;
|
||||
$shift = 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";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||
// block_reference
|
||||
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
|
||||
}
|
||||
}
|
||||
if (! $line) {
|
||||
$warnMsg[] = "Line not found";
|
||||
$warnMsg[] = 'Line not found';
|
||||
}
|
||||
$shift = null;
|
||||
if (! $block) {
|
||||
$warnMsg[] = "Block not found";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Block not found';
|
||||
} elseif ($plant) {
|
||||
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
|
||||
}
|
||||
// $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
|
||||
if (! $shift) {
|
||||
$warnMsg[] = "Shift not found";
|
||||
$warnMsg[] = 'Shift not found';
|
||||
}
|
||||
$linestop = LineStop::where('code', $this->data['linestop'])->first();
|
||||
if (! $linestop) {
|
||||
$warnMsg[] = "Line stop code not found";
|
||||
$warnMsg[] = 'Line stop code not found';
|
||||
}
|
||||
$stophour = is_numeric($this->data['stop_hour']) && $this->data['stop_hour'] >= 0;
|
||||
$stopmin = is_numeric($this->data['stop_min']) && $this->data['stop_min'] >= 0 && $this->data['stop_min'] <= 60;
|
||||
if (! $stophour && ! $stopmin) {
|
||||
$warnMsg[] = "Invalid stop hour/minute found";
|
||||
}
|
||||
else if (!$stophour) {
|
||||
$warnMsg[] = "Invalid stop hour found";
|
||||
}
|
||||
else if (!$stopmin) {
|
||||
$warnMsg[] = "Invalid stop min found";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Invalid stop hour/minute found';
|
||||
} elseif (! $stophour) {
|
||||
$warnMsg[] = 'Invalid stop hour found';
|
||||
} elseif (! $stopmin) {
|
||||
$warnMsg[] = 'Invalid stop min found';
|
||||
} else {
|
||||
$stophour = (int) $this->data['stop_hour'];
|
||||
$stopmin = (int) $this->data['stop_min'];
|
||||
if ($stophour == 0 && $stopmin == 0) {
|
||||
$warnMsg[] = "Invalid stop hour/minute found";
|
||||
$warnMsg[] = 'Invalid stop hour/minute found';
|
||||
}
|
||||
}
|
||||
$validHourMin = ($stophour == 0 && $stopmin == 0) ? false : true;
|
||||
if (! $validHourMin) {
|
||||
$warnMsg[] = "Invalid stop hour/minute found";
|
||||
$warnMsg[] = 'Invalid stop hour/minute found';
|
||||
}
|
||||
$fromDate = $this->data['from_datetime'];
|
||||
$toDate = $this->data['to_datetime'];
|
||||
@@ -201,7 +203,7 @@ class ProductionLineStopImporter extends Importer
|
||||
|
||||
$user = User::where('name', $this->data['operator_id'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = "Operator ID not found";
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
@@ -219,6 +221,7 @@ class ProductionLineStopImporter extends Importer
|
||||
'stop_min' => (int) $this->data['stop_min'],
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
]);
|
||||
|
||||
return null;
|
||||
// return ProductionLineStop::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
|
||||
@@ -65,10 +65,10 @@ class ProductionPlanImporter extends Importer
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example(['Ransar Industries-I', 'Ransar Industries-I'])
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000', '1000'])
|
||||
->label('Plant Code')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_at')
|
||||
->requiredMapping()
|
||||
@@ -88,36 +88,45 @@ class ProductionPlanImporter extends Importer
|
||||
public function resolveRecord(): ?ProductionPlan
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$line = null;
|
||||
$block = null;
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
|
||||
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();
|
||||
}
|
||||
else {
|
||||
|
||||
if (! $plant) {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||
// block_reference
|
||||
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
|
||||
}
|
||||
|
||||
if (! $line) {
|
||||
$warnMsg[] = "Line not found";
|
||||
$warnMsg[] = 'Line not found';
|
||||
}
|
||||
|
||||
$shift = null;
|
||||
if (! $block) {
|
||||
$warnMsg[] = "Block not found";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Block not found';
|
||||
} elseif ($plant) {
|
||||
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
|
||||
}
|
||||
|
||||
// $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
|
||||
if (! $shift) {
|
||||
$warnMsg[] = "Shift not found";
|
||||
$warnMsg[] = 'Shift not found';
|
||||
}
|
||||
if (Str::length($this->data['plan_quantity']) < 0 || ! is_numeric($this->data['plan_quantity']) || $this->data['plan_quantity'] <= 0) {
|
||||
$warnMsg[] = "Invalid plan quantity found";
|
||||
$warnMsg[] = 'Invalid plan quantity found';
|
||||
}
|
||||
if (Str::length($this->data['production_quantity']) < 0 || ! is_numeric($this->data['production_quantity']) || $this->data['production_quantity'] < 0) {
|
||||
$warnMsg[] = "Invalid production quantity found";
|
||||
$warnMsg[] = 'Invalid production quantity found';
|
||||
}
|
||||
|
||||
$fromDate = $this->data['created_at'];
|
||||
@@ -152,8 +161,7 @@ class ProductionPlanImporter extends Importer
|
||||
if (! isset($fdateTime)) {
|
||||
// throw new \Exception('Invalid date time format');
|
||||
$warnMsg[] = "Invalid 'Created DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$fDateOnly = $fdateTime->toDateString();
|
||||
}
|
||||
if (! isset($tdateTime)) {
|
||||
@@ -175,13 +183,12 @@ class ProductionPlanImporter extends Importer
|
||||
|
||||
$user = User::where('name', $this->data['operator_id'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = "Operator ID not found";
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
else { //if (empty($warnMsg))
|
||||
} else { // if (empty($warnMsg))
|
||||
$productionPlan = ProductionPlan::where('plant_id', $plant->id)
|
||||
->where('shift_id', $shift->id)
|
||||
->where('line_id', $line->id)
|
||||
@@ -205,6 +212,7 @@ class ProductionPlanImporter extends Importer
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
]);
|
||||
$productionPlan->save();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -219,6 +227,7 @@ class ProductionPlanImporter extends Importer
|
||||
'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
]);
|
||||
|
||||
return null;
|
||||
// return ProductionPlan::firstOrNew([
|
||||
// // Update existing records, matching them by `$this->data['column_name']`
|
||||
|
||||
@@ -59,9 +59,9 @@ class ProductionQuantityImporter extends Importer
|
||||
->rules(['required']),
|
||||
ImportColumn::make('block_reference')
|
||||
->requiredMapping() // Or optionalMapping() if not always present
|
||||
->exampleHeader('Block')
|
||||
->exampleHeader('Block Name')
|
||||
->example(['Block A', 'Block A'])
|
||||
->label('Block')
|
||||
->label('Block Name')
|
||||
->rules(['required']), // Or remove if not required
|
||||
ImportColumn::make('shift')
|
||||
->requiredMapping()
|
||||
@@ -72,10 +72,10 @@ class ProductionQuantityImporter extends Importer
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Plant Name')
|
||||
->example(['Ransar Industries-I', 'Ransar Industries-I'])
|
||||
->label('Plant Name')
|
||||
->relationship(resolveUsing:'name')
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000', '1000'])
|
||||
->label('Plant Code')
|
||||
->relationship(resolveUsing: 'code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('updated_at')
|
||||
->requiredMapping()
|
||||
@@ -95,43 +95,51 @@ class ProductionQuantityImporter extends Importer
|
||||
public function resolveRecord(): ?ProductionQuantity
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$line = null;
|
||||
$block = null;
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
$shift = 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();
|
||||
}
|
||||
else {
|
||||
|
||||
if (! $plant) {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||
// block_reference
|
||||
$block = Block::where('name', $this->data['block_reference'])->where('plant_id', $plant->id)->first();
|
||||
}
|
||||
|
||||
if (! $line) {
|
||||
$warnMsg[] = "Line not found";
|
||||
$warnMsg[] = 'Line not found';
|
||||
}
|
||||
$shift = null;
|
||||
if (! $block) {
|
||||
$warnMsg[] = "Block not found";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Block not found';
|
||||
} elseif ($plant) {
|
||||
$shift = Shift::where('name', $this->data['shift'])->where('plant_id', $plant->id)->where('block_id', $block->id)->first();
|
||||
}
|
||||
|
||||
// $shift = Shift::where('id', $this->data['shift'])->where('plant_id', $plant->id)->first();
|
||||
if (! $shift) {
|
||||
$warnMsg[] = "Shift not found";
|
||||
$warnMsg[] = 'Shift not found';
|
||||
}
|
||||
|
||||
$item = null;
|
||||
if ($plant) {
|
||||
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
||||
}
|
||||
if (! $item) {
|
||||
$warnMsg[] = "Item not found";
|
||||
$warnMsg[] = 'Item not found';
|
||||
}
|
||||
if (Str::length($this->data['serial_number']) < 9 || ! ctype_alnum($this->data['serial_number'])) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
$warnMsg[] = 'Invalid serial number found';
|
||||
}
|
||||
if (Str::length($this->data['production_order']) > 0 && (Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14 || ! is_numeric($this->data['production_order']))) {
|
||||
$warnMsg[] = "Invalid production order found";
|
||||
$warnMsg[] = 'Invalid production order found';
|
||||
}
|
||||
|
||||
$fromDate = $this->data['created_at'];
|
||||
@@ -188,20 +196,19 @@ class ProductionQuantityImporter extends Importer
|
||||
|
||||
$user = User::where('name', $this->data['operator_id'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = "Operator ID not found";
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
else { //if (empty($warnMsg))
|
||||
} else { // if (empty($warnMsg))
|
||||
$productionQuan = ProductionQuantity::where('plant_id', $plant->id)
|
||||
->where('serial_number', $this->data['serial_number'])
|
||||
->latest()
|
||||
->first();
|
||||
|
||||
if ($productionQuan) {
|
||||
throw new RowImportFailedException("Serial number already exist!");
|
||||
throw new RowImportFailedException('Serial number already exist!');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,6 +223,7 @@ class ProductionQuantityImporter extends Importer
|
||||
'updated_at' => $tdateTime->format('Y-m-d H:i:s'), // $this->data['updated_at'],
|
||||
'operator_id' => $this->data['operator_id'],
|
||||
]);
|
||||
|
||||
// ProductionQuantity::updateOrCreate([
|
||||
// 'serial_number' => $this->data['serial_number'],
|
||||
// 'plant_id' => $plant->id,
|
||||
@@ -259,7 +267,7 @@ class ProductionQuantityImporter extends Importer
|
||||
'line_id' => $this->resolveLineId($row['line']),
|
||||
'shift_id' => $this->resolveShiftId($row['shift']),
|
||||
'plant_id' => $this->resolvePlantId($row['plant']),
|
||||
'updated_at' => $row['updated_at']
|
||||
'updated_at' => $row['updated_at'],
|
||||
]);
|
||||
} finally {
|
||||
// Always disable flag even if errors occur
|
||||
|
||||
@@ -14,7 +14,6 @@ use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Facades\Filament;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Str;
|
||||
|
||||
class QualityValidationImporter extends Importer
|
||||
@@ -101,6 +100,11 @@ class QualityValidationImporter extends Importer
|
||||
->exampleHeader('Name Plate PumpSet')
|
||||
->example('1')
|
||||
->label('Name Plate PumpSet'),
|
||||
ImportColumn::make('warranty_card')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Warranty Card')
|
||||
->example('1')
|
||||
->label('Warranty Card'),
|
||||
ImportColumn::make('tube_sticker_motor')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Tube Sticker Motor')
|
||||
@@ -116,11 +120,6 @@ class QualityValidationImporter extends Importer
|
||||
->exampleHeader('Tube Sticker PumpSet')
|
||||
->example('1')
|
||||
->label('Tube Sticker PumpSet'),
|
||||
ImportColumn::make('warranty_card')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Warranty Card')
|
||||
->example('1')
|
||||
->label('Warranty Card'),
|
||||
ImportColumn::make('part_validation1')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Part Validation 1')
|
||||
@@ -160,10 +159,10 @@ class QualityValidationImporter extends Importer
|
||||
->rules(['required']),
|
||||
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('updated_at')
|
||||
->requiredMapping()
|
||||
@@ -183,13 +182,19 @@ class QualityValidationImporter extends Importer
|
||||
public function resolveRecord(): ?QualityValidation
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$line = null;
|
||||
$stickMaster = null;
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
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();
|
||||
}
|
||||
else {
|
||||
|
||||
if (! $plant) {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$line = Line::where('name', $this->data['line'])->where('plant_id', $plant->id)->first();
|
||||
$uniqueCode = trim($this->data['sticker_master_id_code']); // stickerMaster.item
|
||||
$stickMaster = StickerMaster::select('id')->with('item')
|
||||
@@ -199,19 +204,19 @@ class QualityValidationImporter extends Importer
|
||||
}
|
||||
|
||||
if (! $line) {
|
||||
$warnMsg[] = "Line not found";
|
||||
$warnMsg[] = 'Line not found';
|
||||
}
|
||||
|
||||
if (! $stickMaster) {
|
||||
$warnMsg[] = "Sticker item code not found";
|
||||
$warnMsg[] = 'Sticker item code not found';
|
||||
}
|
||||
|
||||
if (! is_numeric($this->data['production_order']) || Str::length($this->data['production_order']) < 7 || Str::length($this->data['production_order']) > 14) {
|
||||
$warnMsg[] = "Invalid production order found";
|
||||
$warnMsg[] = 'Invalid production order found';
|
||||
}
|
||||
|
||||
if (! ctype_alnum($this->data['serial_number']) || Str::length($this->data['serial_number']) < 9) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
$warnMsg[] = 'Invalid serial number found';
|
||||
}
|
||||
// dd($stickMaster);
|
||||
|
||||
@@ -221,7 +226,7 @@ class QualityValidationImporter extends Importer
|
||||
|
||||
$user = User::where('name', $this->data['operator_id'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = "Operator ID not found";
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
$fromDate = $this->data['created_at'];
|
||||
$toDate = $this->data['updated_at'];
|
||||
@@ -282,7 +287,7 @@ class QualityValidationImporter extends Importer
|
||||
QualityValidation::updateOrCreate([
|
||||
'plant_id' => $plant->id,
|
||||
'sticker_master_id' => $stickMaster, // ->id
|
||||
'serial_number' => $this->data['serial_number']
|
||||
'serial_number' => $this->data['serial_number'],
|
||||
],
|
||||
[
|
||||
'line_id' => $line->id,
|
||||
|
||||
@@ -135,51 +135,47 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
|
||||
$reworkedBy = $this->data['reworked_by'];
|
||||
|
||||
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', $this->data['plant'])->first();
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
} else {
|
||||
$plant = Plant::where('code', $plantCod)->first();
|
||||
if (! $plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
if (Str::length($invoiceNo) < 5 || ! ctype_alnum($invoiceNo)) {
|
||||
$warnMsg[] = "Invalid invoice number found";
|
||||
$warnMsg[] = 'Invalid invoice number found';
|
||||
}
|
||||
if (Str::length($serialNo) < 9 || Str::length($serialNo) > 20 || ! ctype_alnum($serialNo)) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
$warnMsg[] = 'Invalid serial number found';
|
||||
}
|
||||
if (Str::length($palletNo) > 0 && Str::length($palletNo) < 10) {
|
||||
$warnMsg[] = "Invalid pallet number found";
|
||||
$warnMsg[] = 'Invalid pallet number found';
|
||||
}
|
||||
if (Str::length($locatorNo) > 0 && Str::length($locatorNo) < 7) {
|
||||
$warnMsg[] = "Invalid locator number found";
|
||||
$warnMsg[] = 'Invalid locator number found';
|
||||
}
|
||||
if ($scannedStat != 'Scanned') {
|
||||
$warnMsg[] = "Invalid scanned status found";
|
||||
$warnMsg[] = 'Invalid scanned status found';
|
||||
}
|
||||
if ($uploadStat != 'Y' && $uploadStat != 'N') {
|
||||
$warnMsg[] = "Invalid upload status found";
|
||||
$warnMsg[] = 'Invalid upload status found';
|
||||
}
|
||||
$created = User::where('name', $createdBy)->first();
|
||||
if (! $created) {
|
||||
$warnMsg[] = "Created by not found";
|
||||
$warnMsg[] = 'Created by not found';
|
||||
}
|
||||
$scanned = User::where('name', $scannedBy)->first();
|
||||
if (! $scanned) {
|
||||
$warnMsg[] = "Scanned by not found";
|
||||
$warnMsg[] = 'Scanned by not found';
|
||||
}
|
||||
if (Str::length($updatedBy) > 0) {
|
||||
$updated = User::where('name', $updatedBy)->first();
|
||||
if (! $updated) {
|
||||
$warnMsg[] = "Updated by not found";
|
||||
$warnMsg[] = 'Updated by not found';
|
||||
}
|
||||
}
|
||||
$reworked = User::where('name', $reworkedBy)->first();
|
||||
if (! $reworked) {
|
||||
$warnMsg[] = "Reworked by not found";
|
||||
$warnMsg[] = 'Reworked by not found';
|
||||
}
|
||||
|
||||
$formats = ['d-m-Y H:i', 'd-m-Y H:i:s']; // '07-05-2025 08:00' or '07-05-2025 08:00:00'
|
||||
@@ -225,9 +221,7 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
|
||||
|
||||
if (! isset($uDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Updated DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (isset($cDateTime) && isset($uDateTime)) {
|
||||
if ($cDateTime->greaterThan($uDateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Updated DateTime'.";
|
||||
@@ -247,9 +241,7 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
|
||||
|
||||
if (! isset($rDateTime)) {
|
||||
$warnMsg[] = "Invalid 'Reworked DateTime' format. Expected DD-MM-YYYY HH:MM:SS";
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (isset($cDateTime) && isset($rDateTime)) {
|
||||
if ($cDateTime->greaterThan($rDateTime)) {
|
||||
$warnMsg[] = "'Created DataTime' is greater than 'Reworked DateTime'.";
|
||||
@@ -283,9 +275,10 @@ class ReworkLocatorInvoiceValidationImporter extends Importer
|
||||
'created_by' => $createdBy,
|
||||
'scanned_by' => $scannedBy,
|
||||
'updated_by' => $updatedBy,
|
||||
'reworked_by' => $reworkedBy
|
||||
'reworked_by' => $reworkedBy,
|
||||
]
|
||||
);
|
||||
|
||||
return null;
|
||||
// // return ReworkLocatorInvoiceValidation::firstOrNew([
|
||||
// // // Update existing records, matching them by `$this->data['column_name']`
|
||||
|
||||
@@ -52,10 +52,10 @@ class ShiftImporter extends Importer
|
||||
->rules(['required']),
|
||||
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('status')
|
||||
->requiredMapping()
|
||||
@@ -69,25 +69,35 @@ class ShiftImporter extends Importer
|
||||
public function resolveRecord(): ?Shift
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
if (!$plant) {
|
||||
$warnMsg[] = "Plant not found";
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$block = 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';
|
||||
} else {
|
||||
$block = Block::where('name', $this->data['block'])->where('plant_id', $plant->id)->first();
|
||||
}
|
||||
|
||||
if (! $block) {
|
||||
$warnMsg[] = "Block not found";
|
||||
$warnMsg[] = 'Block not found';
|
||||
}
|
||||
if (Str::length($this->data['duration']) < 0 || ! is_numeric($this->data['duration'])) {
|
||||
$warnMsg[] = "Invalid duration found";
|
||||
$warnMsg[] = 'Invalid duration found';
|
||||
}
|
||||
if (Str::length($this->data['start_time']) < 0) {
|
||||
$warnMsg[] = "Invalid start time found";
|
||||
$warnMsg[] = 'Invalid start time found';
|
||||
}
|
||||
if (Str::length($this->data['end_time']) < 0) {
|
||||
$warnMsg[] = "Invalid end time found";
|
||||
$warnMsg[] = 'Invalid end time found';
|
||||
}
|
||||
if (Str::length($this->data['status']) < 0 || $this->data['status'] != 'Active') {
|
||||
$warnMsg[] = "Invalid shift status found";
|
||||
$warnMsg[] = 'Invalid shift status found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
@@ -105,8 +115,9 @@ class ShiftImporter extends Importer
|
||||
'start_time' => $this->data['start_time'],
|
||||
'duration' => $this->data['duration'],
|
||||
'end_time' => $this->data['end_time'],
|
||||
'status' => $this->data['status']
|
||||
'status' => $this->data['status'],
|
||||
]);
|
||||
|
||||
return $shift;
|
||||
} else {
|
||||
// Safe to create new
|
||||
@@ -117,7 +128,7 @@ class ShiftImporter extends Importer
|
||||
'start_time' => $this->data['start_time'],
|
||||
'duration' => $this->data['duration'],
|
||||
'end_time' => $this->data['end_time'],
|
||||
'status' => $this->data['status']
|
||||
'status' => $this->data['status'],
|
||||
]);
|
||||
}
|
||||
// return Shift::firstOrNew([
|
||||
|
||||
@@ -2,15 +2,14 @@
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Plant;
|
||||
use App\Models\StickerPrinting;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Filament\Actions\Imports\Exceptions\RowImportFailedException;
|
||||
use App\Models\Plant;
|
||||
use App\Models\User;
|
||||
use Str;
|
||||
use Filament\Facades\Filament;
|
||||
use Str;
|
||||
|
||||
class StickerPrintingImporter extends Importer
|
||||
{
|
||||
@@ -49,30 +48,26 @@ class StickerPrintingImporter extends Importer
|
||||
// ]);
|
||||
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('code', $this->data['plant'])->first();
|
||||
|
||||
if (Str::length($this->data['serial_number']) < 9 || !ctype_alnum($this->data['serial_number'])) {
|
||||
$warnMsg[] = "Invalid serial number found";
|
||||
}
|
||||
|
||||
$existing = StickerPrinting::where('plant_id', $plant->id)
|
||||
->where('serial_number', $this->data['serial_number'])
|
||||
->first();
|
||||
|
||||
if ($existing) {
|
||||
$warnMsg[] = "Serial number already exists for this plant!";//throw new RowImportFailedException("Serial number already exists for this plant!");
|
||||
}
|
||||
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
$serial = $this->data['serial_number'];
|
||||
|
||||
// --- Check duplicate in DB ---
|
||||
$existsInDB = StickerPrinting::where('plant_id', $plant->id)
|
||||
->where('serial_number', $serial)
|
||||
->first();
|
||||
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!';
|
||||
}
|
||||
}
|
||||
|
||||
if ($existsInDB) {
|
||||
//throw new RowImportFailedException("Serial number '{$serial}' already exists in DB for this plant!");
|
||||
$warnMsg[] = "Serial number '{$serial}' already exists in DB for this plant!";
|
||||
if (Str::length($serial) < 9 || ! ctype_alnum($serial)) {
|
||||
$warnMsg[] = 'Invalid serial number found';
|
||||
} elseif ($plant) {
|
||||
$existing = StickerPrinting::where('plant_id', $plant->id)->where('serial_number', $serial)->first();
|
||||
if ($existing) {
|
||||
$warnMsg[] = "Serial number '{$serial}' already exists for plant '{$plantCod}'!"; // throw new RowImportFailedException("Serial number already exists for this plant!");
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
|
||||
@@ -80,11 +80,17 @@ class TestingPanelReadingImporter extends Importer
|
||||
->rules(['required']),
|
||||
ImportColumn::make('line')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
->relationship(resolveUsing: 'name')
|
||||
->exampleHeader('Line Name')
|
||||
->example(['4 inch pump line'])
|
||||
->label('Line Name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('plant')
|
||||
->requiredMapping()
|
||||
->relationship()
|
||||
->relationship(resolveUsing: 'code')
|
||||
->exampleHeader('Plant Code')
|
||||
->example(['1000'])
|
||||
->label('Plant Code')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('tested_by'),
|
||||
ImportColumn::make('updated_by'),
|
||||
@@ -101,7 +107,7 @@ class TestingPanelReadingImporter extends Importer
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
|
||||
return new TestingPanelReading();
|
||||
return new TestingPanelReading;
|
||||
}
|
||||
|
||||
public static function getCompletedNotificationBody(Import $import): string
|
||||
|
||||
@@ -54,31 +54,28 @@ class UserImporter extends Importer
|
||||
public function resolveRecord(): ?User
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plantCod = $this->data['plant'];
|
||||
$plant = null;
|
||||
if (Str::length($this->data['plant']) > 0) {
|
||||
if (Str::length($this->data['plant']) < 4 || !is_numeric($this->data['plant']) || !preg_match('/^[1-9]\d{3,}$/', $this->data['plant'])) {
|
||||
$warnMsg[] = "Invalid plant code found!";
|
||||
}
|
||||
else {
|
||||
$plant = Plant::where('code', $this->data['plant'])->first();
|
||||
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";
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = 'Plant not found';
|
||||
} else {
|
||||
$plant = $plant->id ?? null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($this->data['name']) < 1) {
|
||||
$warnMsg[] = "User name not found!";
|
||||
if (Str::length($this->data['name']) < 3) {
|
||||
$warnMsg[] = 'Invalid user name found!';
|
||||
}
|
||||
// || !is_numeric($this->data['code']) || !preg_match('/^[1-9]\d{3,}$/', $this->data['code'])
|
||||
if (Str::length($this->data['email']) < 5) {
|
||||
$warnMsg[] = "Invalid email found!";
|
||||
$warnMsg[] = 'Invalid email found!';
|
||||
}
|
||||
if (Str::length($this->data['password']) < 3) {
|
||||
$warnMsg[] = "Invalid password found!";
|
||||
$warnMsg[] = 'Invalid password found!';
|
||||
}
|
||||
// Validate roles if provided
|
||||
$roles = [];
|
||||
@@ -93,9 +90,8 @@ class UserImporter extends Importer
|
||||
$warnMsg[] = "Role : '{$roleName}' does not exist!";
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$warnMsg[] = "User roles not found!";
|
||||
} else {
|
||||
$warnMsg[] = 'User roles not found!';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
|
||||
@@ -75,10 +75,10 @@ class WeightValidationImporter extends Importer
|
||||
->rules(['required']),
|
||||
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('scanned_by')
|
||||
->requiredMapping()
|
||||
@@ -92,62 +92,75 @@ class WeightValidationImporter extends Importer
|
||||
public function resolveRecord(): ?WeightValidation
|
||||
{
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$iCode = $this->data['item'];
|
||||
$plantId = null;
|
||||
$itemId = 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 {
|
||||
$plantId = $plant->id;
|
||||
}
|
||||
$item = null;
|
||||
if ($plant) {
|
||||
if (Str::length($this->data['item']) < 6 || !ctype_alnum($this->data['item'])) {
|
||||
$warnMsg[] = "Invalid item code found";
|
||||
}
|
||||
else
|
||||
{
|
||||
$item = Item::where('code', $this->data['item'])->where('plant_id', $plant->id)->first();
|
||||
if (!$item) {
|
||||
$warnMsg[] = "Item code not found";
|
||||
|
||||
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
|
||||
$warnMsg[] = 'Invalid item code found';
|
||||
} else {
|
||||
$itemCode = Item::where('code', $iCode)->first();
|
||||
if (! $itemCode) {
|
||||
$warnMsg[] = 'Item code not found';
|
||||
} else {
|
||||
if ($plantId) {
|
||||
$itemAgainstPlant = Item::where('code', $iCode)->where('plant_id', $plantId)->first();
|
||||
if (! $itemAgainstPlant) {
|
||||
$warnMsg[] = 'Item code not found for the given plant';
|
||||
} else {
|
||||
$itemId = $itemAgainstPlant->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
else { //if (!$item)
|
||||
$warnMsg[] = "Item code not found";
|
||||
}
|
||||
|
||||
$obdNum = $this->data['obd_number'];
|
||||
if (Str::length($obdNum) < 8 || ! ctype_alnum($obdNum)) {
|
||||
$warnMsg[] = "Invalid OBD number found";
|
||||
$warnMsg[] = 'Invalid OBD number found';
|
||||
}
|
||||
$lineNum = $this->data['line_number'];
|
||||
if (Str::length($lineNum) < 1 || ! is_numeric($lineNum)) {
|
||||
$warnMsg[] = "Invalid line number found";
|
||||
$warnMsg[] = 'Invalid line number found';
|
||||
}
|
||||
$batchNum = $this->data['batch_number'];
|
||||
if (Str::length($batchNum) < 8 || ! is_numeric($batchNum)) {
|
||||
$warnMsg[] = "Invalid batch number found";
|
||||
$warnMsg[] = 'Invalid batch number found';
|
||||
}
|
||||
$heatNum = $this->data['heat_number'];
|
||||
if (Str::length($heatNum) < 4) {
|
||||
$warnMsg[] = "Invalid heat number found";
|
||||
$warnMsg[] = 'Invalid heat number found';
|
||||
}
|
||||
$actWeight = $this->data['obd_weight'];
|
||||
if (Str::length($actWeight) < 1 || ! is_numeric($actWeight)) {
|
||||
$warnMsg[] = "Invalid actual weight found";
|
||||
$warnMsg[] = 'Invalid actual weight found';
|
||||
}
|
||||
$vehicleNum = $this->data['vehicle_number'];
|
||||
if (Str::length($vehicleNum) < 10 || ! ctype_alnum($vehicleNum)) {
|
||||
$warnMsg[] = "Invalid vehicle number found";
|
||||
$warnMsg[] = 'Invalid vehicle number found';
|
||||
}
|
||||
$bundleNum = $this->data['bundle_number'];
|
||||
if (Str::length($bundleNum) < 1 || ! is_numeric($bundleNum)) {
|
||||
$warnMsg[] = "Invalid bundle number found";
|
||||
$warnMsg[] = 'Invalid bundle number found';
|
||||
}
|
||||
$pickWeight = $this->data['picked_weight'];
|
||||
if (Str::length($pickWeight) < 1 || ! is_numeric($pickWeight)) {
|
||||
$warnMsg[] = "Invalid picked weight found";
|
||||
$warnMsg[] = 'Invalid picked weight found';
|
||||
}
|
||||
$scanBy = $this->data['scanned_by'];
|
||||
if (Str::length($scanBy) < 3 || ! ctype_alnum($scanBy)) {
|
||||
$warnMsg[] = "Invalid scanned by name found";
|
||||
$warnMsg[] = 'Invalid scanned by name found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
@@ -155,19 +168,19 @@ class WeightValidationImporter extends Importer
|
||||
}
|
||||
|
||||
return WeightValidation::updateOrCreate([
|
||||
'plant_id' => $plant->id,
|
||||
'plant_id' => $plantId,
|
||||
'obd_number' => $obdNum,
|
||||
'line_number' => $lineNum
|
||||
'line_number' => $lineNum,
|
||||
],
|
||||
[
|
||||
'item_id' => $item->id,
|
||||
'item_id' => $itemId,
|
||||
'batch_number' => $batchNum,
|
||||
'heat_number' => $heatNum,
|
||||
'obd_weight' => $actWeight,
|
||||
'vehicle_number' => $vehicleNum,
|
||||
'bundle_number' => $bundleNum,
|
||||
'picked_weight' => $pickWeight,
|
||||
'scanned_by' => $scanBy
|
||||
'scanned_by' => $scanBy,
|
||||
]
|
||||
);
|
||||
// return WeightValidation::firstOrNew([
|
||||
|
||||
@@ -20,22 +20,22 @@ class WorkGroupMasterImporter 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('name')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Name')
|
||||
->exampleHeader('Work Group Name')
|
||||
->example('RMGCEABC')
|
||||
->label('Name')
|
||||
->label('Work Group Name')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('description')
|
||||
->requiredMapping()
|
||||
->exampleHeader('Description')
|
||||
->exampleHeader('Work Group Description')
|
||||
->example('Testing Model 1')
|
||||
->label('Description')
|
||||
->label('Work Group Description')
|
||||
->rules(['required']),
|
||||
ImportColumn::make('operation_number')
|
||||
->requiredMapping()
|
||||
@@ -52,8 +52,6 @@ class WorkGroupMasterImporter extends Importer
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function resolveRecord(): ?WorkGroupMaster
|
||||
{
|
||||
// return WorkGroupMaster::firstOrNew([
|
||||
@@ -61,75 +59,81 @@ class WorkGroupMasterImporter extends Importer
|
||||
// 'email' => $this->data['email'],
|
||||
// ]);
|
||||
$warnMsg = [];
|
||||
$plant = Plant::where('name', $this->data['plant'])->first();
|
||||
$plantCod = $this->data['plant'];
|
||||
$plantId = 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 {
|
||||
$plantId = $plant->id;
|
||||
}
|
||||
}
|
||||
|
||||
if (Str::length($this->data['name']) <= 0) { // || !ctype_alnum($this->data['description'])
|
||||
$warnMsg[] = "Invalid name found";
|
||||
$warnMsg[] = 'Invalid work group name found';
|
||||
}
|
||||
|
||||
if (Str::length(trim($this->data['description'])) <= 0) {
|
||||
$warnMsg[] = "Invalid description found";
|
||||
$warnMsg[] = 'Invalid work group description found';
|
||||
}
|
||||
|
||||
$desc = trim($this->data['description']);
|
||||
|
||||
if (Str::length($desc) > 44) {
|
||||
$warnMsg[] = "Description should be less than 44 digits.";
|
||||
$warnMsg[] = ' work group description should be less than 44 digits.';
|
||||
}
|
||||
|
||||
if (Str::length($this->data['operation_number']) <= 0) {
|
||||
$warnMsg[] = "Invalid operation number found";
|
||||
$warnMsg[] = 'Invalid operation number found';
|
||||
}
|
||||
|
||||
if(!is_numeric($this->data['operation_number']))
|
||||
{
|
||||
$warnMsg[] = "Invalid operation number found must be numeric";
|
||||
if (! is_numeric($this->data['operation_number'])) {
|
||||
$warnMsg[] = 'Invalid operation number found must be numeric';
|
||||
}
|
||||
|
||||
$user = User::where('name', $this->data['created_by'])->first();
|
||||
if (! $user) {
|
||||
$warnMsg[] = "Operator ID not found";
|
||||
$warnMsg[] = 'Operator ID not found';
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Check (plant_id, name)
|
||||
$existingByName = WorkGroupMaster::where('plant_id', $plant->id)
|
||||
$existingByName = WorkGroupMaster::where('plant_id', $plantId)
|
||||
->where('name', $this->data['name'])
|
||||
->first();
|
||||
|
||||
if ($existingByName) {
|
||||
throw new RowImportFailedException("Work group name already exists for this plant!");
|
||||
throw new RowImportFailedException('Work group name already exists for this plant!');
|
||||
}
|
||||
|
||||
// Check (plant_id, operation_number)
|
||||
$existingByOpNum = WorkGroupMaster::where('plant_id', $plant->id)
|
||||
$existingByOpNum = WorkGroupMaster::where('plant_id', $plantId)
|
||||
->where('operation_number', $this->data['operation_number'])
|
||||
->where('name', $this->data['name'])
|
||||
->first();
|
||||
|
||||
if ($existingByOpNum) {
|
||||
throw new RowImportFailedException("Operation number already exists for this plant!");
|
||||
throw new RowImportFailedException('Operation number already exists for this plant!');
|
||||
}
|
||||
|
||||
// Check (plant_id)
|
||||
$existingByOperator = WorkGroupMaster::where('plant_id', $plant->id)
|
||||
$existingByOperator = WorkGroupMaster::where('plant_id', $plantId)
|
||||
->where('name', $this->data['name'])
|
||||
->first();
|
||||
|
||||
if ($existingByOperator) {
|
||||
throw new RowImportFailedException("Already work group name assigned to another plant!");
|
||||
throw new RowImportFailedException('Already work group name assigned to another plant!');
|
||||
}
|
||||
}
|
||||
|
||||
WorkGroupMaster::updateOrCreate([
|
||||
'plant_id' => $plant->id,
|
||||
'plant_id' => $plantId,
|
||||
'name' => $this->data['name'],
|
||||
'description' => $this->data['description'],
|
||||
'operation_number' => $this->data['operation_number'],
|
||||
|
||||
@@ -5,26 +5,25 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\CharacteristicValueExporter;
|
||||
use App\Filament\Imports\CharacteristicValueImporter;
|
||||
use App\Filament\Resources\CharacteristicValueResource\Pages;
|
||||
use App\Filament\Resources\CharacteristicValueResource\RelationManagers;
|
||||
use App\Models\CharacteristicValue;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Machine;
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
|
||||
class CharacteristicValueResource extends Resource
|
||||
{
|
||||
@@ -192,7 +191,7 @@ class CharacteristicValueResource extends Resource
|
||||
->label('Status')
|
||||
->options([
|
||||
'Ok' => 'OK',
|
||||
'NotOk' => 'Not Ok'
|
||||
'NotOk' => 'Not Ok',
|
||||
])
|
||||
->reactive()
|
||||
->required(),
|
||||
@@ -296,6 +295,7 @@ class CharacteristicValueResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -368,7 +368,7 @@ class CharacteristicValueResource extends Resource
|
||||
->label('Status')
|
||||
->options([
|
||||
'Ok' => 'OK',
|
||||
'NotOk' => 'Not Ok'
|
||||
'NotOk' => 'Not Ok',
|
||||
]),
|
||||
DateTimePicker::make(name: 'created_from')
|
||||
->label('Created From')
|
||||
@@ -389,6 +389,12 @@ class CharacteristicValueResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Line'])) {
|
||||
@@ -423,7 +429,6 @@ class CharacteristicValueResource extends Resource
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
|
||||
|
||||
// $query->orderBy('created_at', 'asc');
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
@@ -431,6 +436,12 @@ class CharacteristicValueResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Line'])) {
|
||||
@@ -466,7 +477,7 @@ class CharacteristicValueResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
@@ -5,23 +5,22 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\EbReadingExporter;
|
||||
use App\Filament\Imports\EbReadingImporter;
|
||||
use App\Filament\Resources\EbReadingResource\Pages;
|
||||
use App\Filament\Resources\EbReadingResource\RelationManagers;
|
||||
use App\Models\EbReading;
|
||||
use App\Models\Plant;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
|
||||
class EbReadingResource extends Resource
|
||||
{
|
||||
@@ -39,6 +38,7 @@ class EbReadingResource extends Resource
|
||||
->relationship('plant', 'name')
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->required(),
|
||||
@@ -154,6 +154,7 @@ class EbReadingResource extends Resource
|
||||
$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')
|
||||
@@ -334,6 +335,7 @@ class EbReadingResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -361,6 +363,12 @@ class EbReadingResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['created_from'])) {
|
||||
@@ -381,6 +389,12 @@ class EbReadingResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['electrician_sign'])) {
|
||||
@@ -396,7 +410,7 @@ class EbReadingResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\GuardPatrolEntryExporter;
|
||||
use App\Filament\Imports\GuardPatrolEntryImporter;
|
||||
use App\Filament\Resources\GuardPatrolEntryResource\Pages;
|
||||
use App\Filament\Resources\GuardPatrolEntryResource\RelationManagers;
|
||||
use App\Models\CheckPointName;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\GuardName;
|
||||
@@ -17,7 +16,6 @@ use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Tabs\Tab;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
@@ -54,6 +52,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -65,10 +64,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
if (! $plantId) {
|
||||
// $set('gPePlantError', 'Please select a plant first.');
|
||||
$set('gPePlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
$set('gPePlantError', null);
|
||||
@@ -102,10 +100,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
$guardName = $get('guard_name_id');
|
||||
if (! $guardName) {
|
||||
$set('gPeGuardNameError', 'Please select a guard name first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
$set('gPeGuardNameError', null);
|
||||
@@ -150,10 +147,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
if (! $checkPointName) {
|
||||
$set('check_point_name_id', null);
|
||||
$set('gPeCheckPointNameError', 'Please select a check point name first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
$set('gPeCheckPointNameError', null);
|
||||
@@ -176,8 +172,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
->hidden(fn (Get $get) => ! $get('id'))
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if(!$get('id'))
|
||||
{
|
||||
if (! $get('id')) {
|
||||
$set('patrol_time', now()->format('Y-m-d H:i:s'));
|
||||
}
|
||||
$set('updated_by', Filament::auth()->user()?->name);
|
||||
@@ -225,6 +220,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
$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('id')
|
||||
@@ -288,6 +284,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
@@ -350,6 +347,12 @@ class GuardPatrolEntryResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Guard Name'])) {
|
||||
@@ -377,6 +380,12 @@ class GuardPatrolEntryResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Guard Name'])) {
|
||||
@@ -400,7 +409,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -422,6 +431,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->label('Select Plant')
|
||||
@@ -435,10 +445,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
$set('guard_patrol_entry', null);
|
||||
if (! $plantId) {
|
||||
$set('gPeSelectPlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('gPeSelectPlantError', null);
|
||||
}
|
||||
})
|
||||
@@ -482,21 +491,20 @@ class GuardPatrolEntryResource extends Resource
|
||||
|
||||
$folderPath = Configuration::where('c_name', 'GUARD_PATROL_ENTRY_FOLDER_PATH')->where('plant_id', $plantId)->value('c_value');
|
||||
|
||||
if(!$folderPath)
|
||||
{
|
||||
if (! $folderPath) {
|
||||
Notification::make()
|
||||
->title('Upload Folder Path Not Found!')
|
||||
->body('Please set the folder path in configuration for Guard Patrol Entry.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$fullFolderPath = "uploads/$folderPath";
|
||||
|
||||
// Check if the folder exists, if not, create it
|
||||
if (!Storage::disk('local')->exists($fullFolderPath))
|
||||
{
|
||||
if (! Storage::disk('local')->exists($fullFolderPath)) {
|
||||
Storage::disk('local')->makeDirectory($fullFolderPath);
|
||||
}
|
||||
|
||||
@@ -504,12 +512,10 @@ class GuardPatrolEntryResource extends Resource
|
||||
|
||||
$fullPath = Storage::disk('local')->path($path);
|
||||
|
||||
if ($fullPath && file_exists($fullPath))
|
||||
{
|
||||
if ($fullPath && file_exists($fullPath)) {
|
||||
$rows = Excel::toArray(null, $fullPath)[0];
|
||||
|
||||
if((count($rows) - 1) <= 0)
|
||||
{
|
||||
if ((count($rows) - 1) <= 0) {
|
||||
Notification::make()
|
||||
->title('Invalid Guard Patrol Entry Found')
|
||||
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
||||
@@ -519,6 +525,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -529,9 +536,10 @@ class GuardPatrolEntryResource extends Resource
|
||||
$invalidPatrolTimes = [];
|
||||
$validRowsFound = false;
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index === 0) continue; // Skip header
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index === 0) {
|
||||
continue;
|
||||
} // Skip header
|
||||
|
||||
$rowNumber = trim($row[0]);
|
||||
$guardName = trim($row[1]);
|
||||
@@ -539,21 +547,20 @@ class GuardPatrolEntryResource extends Resource
|
||||
$readerCode = trim($row[3]);
|
||||
$patrolTime = trim($row[4]);
|
||||
|
||||
if (empty($rowNumber)) { continue; }
|
||||
if (empty($rowNumber)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
|
||||
$invalidRows[] = $rowNumber;
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Str::length($guardName) < 3 || Str::length($checkPointName) < 3 || Str::length($readerCode) < 3 || Str::length($patrolTime) < 3)
|
||||
{
|
||||
} else {
|
||||
if (Str::length($guardName) < 3 || Str::length($checkPointName) < 3 || Str::length($readerCode) < 3 || Str::length($patrolTime) < 3) {
|
||||
$invalidGuardCheckPoints[] = $rowNumber;
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$isValidRow = true;
|
||||
$guardNames = GuardName::where('plant_id', $plantId)->where('name', $guardName)->first();
|
||||
if (! $guardNames) {
|
||||
@@ -602,6 +609,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -616,6 +624,7 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -672,15 +681,17 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$validCnt = 0;
|
||||
$dupCnt = 0;
|
||||
$validRowsFound = false;
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index === 0) continue; // Skip header
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index === 0) {
|
||||
continue;
|
||||
} // Skip header
|
||||
|
||||
$rowNumber = trim($row[0]);
|
||||
$guardName = trim($row[1]);
|
||||
@@ -688,7 +699,9 @@ class GuardPatrolEntryResource extends Resource
|
||||
$readerCode = trim($row[3]);
|
||||
$patrolTime = trim($row[4]);
|
||||
|
||||
if (empty($rowNumber)) { continue; }
|
||||
if (empty($rowNumber)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($guardName) || empty($checkPointName) || empty($readerCode) || empty($patrolTime)) {
|
||||
continue;
|
||||
@@ -720,21 +733,20 @@ class GuardPatrolEntryResource extends Resource
|
||||
if ($guardEntryFound) {
|
||||
// $warnMsg[] = "Duplicate guard patrol entry found";
|
||||
$dupCnt++;
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$validCnt++;
|
||||
GuardPatrolEntry::updateOrCreate([
|
||||
'plant_id' => $plantId,
|
||||
'guard_name_id' => $guardNames->id,
|
||||
'check_point_name_id' => $checkPointNames->id,
|
||||
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s')
|
||||
'patrol_time' => $patrolDateTime->format('Y-m-d H:i:s'),
|
||||
],
|
||||
[
|
||||
'reader_code' => $readerCode,
|
||||
'created_by' => $user,
|
||||
'updated_by' => $user
|
||||
'updated_by' => $user,
|
||||
]
|
||||
);
|
||||
$validRowsFound = true;
|
||||
@@ -748,25 +760,19 @@ class GuardPatrolEntryResource extends Resource
|
||||
->body("Uploaded excel sheet contains '{$dupCnt}' duplicate entries!<br>Please check the uploaded file and try again.")
|
||||
->danger()
|
||||
->send();
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
}
|
||||
else if ($validRowsFound && $validCnt > 0)
|
||||
{
|
||||
} elseif ($validRowsFound && $validCnt > 0) {
|
||||
// session(['guard_patrol_entry_path' => $fullPath]);
|
||||
Notification::make()
|
||||
->title("Success: '{$validCnt}' guard patrol entries imported successfully.")
|
||||
->success()
|
||||
->send();
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
Notification::make()
|
||||
->title('Failed: Something went wrong while uploading guard patrol entries!')
|
||||
->danger()
|
||||
|
||||
@@ -1181,6 +1181,12 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
@@ -1218,6 +1224,12 @@ class InvoiceValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
|
||||
@@ -5,35 +5,33 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\LocatorInvoiceValidationExporter;
|
||||
use App\Filament\Imports\LocatorInvoiceValidationImporter;
|
||||
use App\Filament\Resources\LocatorInvoiceValidationResource\Pages;
|
||||
use App\Filament\Resources\LocatorInvoiceValidationResource\RelationManagers;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\LocatorInvoiceValidation;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\StickerMaster;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Storage;
|
||||
use Str;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
class LocatorInvoiceValidationResource extends Resource
|
||||
{
|
||||
@@ -57,14 +55,14 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->relationship('plant', 'name')
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->disabled(fn (Get $get) => $get('invoice_number'))
|
||||
->required()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if ($plantId)
|
||||
{
|
||||
if ($plantId) {
|
||||
$set('plant', $plantId);
|
||||
$set('invoice_number', null);
|
||||
$set('pallet_number', null);
|
||||
@@ -72,9 +70,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$set('sno_quantity', 0);
|
||||
$set('scan_quantity', 0);
|
||||
$set('pend_quantity', 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('plant', null);
|
||||
$set('invoice_number', null);
|
||||
$set('pallet_number', null);
|
||||
@@ -107,9 +103,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
$set('invoice_number', null);
|
||||
$set('pallet_number', null);
|
||||
}
|
||||
else if ($invNo)
|
||||
{
|
||||
} elseif ($invNo) {
|
||||
$snoCount = LocatorInvoiceValidation::where('plant_id', $plantId)->where('invoice_number', $invNo)->count();
|
||||
|
||||
$pendingCount = LocatorInvoiceValidation::where('invoice_number', $invNo)->where('plant_id', $plantId)->whereNull('scanned_status')->orWhere('scanned_status', '=', '')->count();
|
||||
@@ -139,8 +133,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->get();
|
||||
|
||||
$allScanned = true;
|
||||
foreach ($records as $record)
|
||||
{
|
||||
foreach ($records as $record) {
|
||||
if (($record->scanned_status == null) || trim($record->scanned_status) == '') {
|
||||
$allScanned = false;
|
||||
break;
|
||||
@@ -181,8 +174,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->get();
|
||||
|
||||
$allScanned = true;
|
||||
foreach ($records as $record)
|
||||
{
|
||||
foreach ($records as $record) {
|
||||
if (($record->scanned_status == null) || trim($record->scanned_status) == '') {
|
||||
$allScanned = false;
|
||||
break;
|
||||
@@ -236,8 +228,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
$allScanned = true;
|
||||
|
||||
foreach ($records as $record)
|
||||
{
|
||||
foreach ($records as $record) {
|
||||
if (($record->scanned_status == null) || trim($record->scanned_status) == '') {
|
||||
$allScanned = false;
|
||||
break;
|
||||
@@ -289,6 +280,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($state !== '1') {
|
||||
$set('update_locator_invoice', '0');
|
||||
$set('pallet_number', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -296,13 +288,13 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
->where('pallet_number', $palletNumber)
|
||||
->first();
|
||||
|
||||
if (!$palletRecord)
|
||||
{
|
||||
if (! $palletRecord) {
|
||||
Notification::make()
|
||||
->title("Pallet number '{$palletNumber}' does not exist.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -318,13 +310,13 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
}
|
||||
}
|
||||
|
||||
if (!$allCompleted)
|
||||
{
|
||||
if (! $allCompleted) {
|
||||
Notification::make()
|
||||
->title("Pallet number '{$palletNumber}' is not completed in masters")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
->send();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -413,7 +405,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
})
|
||||
}),
|
||||
])
|
||||
->columns(5),
|
||||
|
||||
@@ -431,6 +423,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$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')
|
||||
@@ -504,6 +497,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->label('Select Plant')
|
||||
@@ -546,8 +540,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$fullFolderPath = "uploads/$folderPath";
|
||||
|
||||
// Check if the folder exists, if not, create it
|
||||
if (!Storage::disk('local')->exists($fullFolderPath))
|
||||
{
|
||||
if (! Storage::disk('local')->exists($fullFolderPath)) {
|
||||
Storage::disk('local')->makeDirectory($fullFolderPath);
|
||||
}
|
||||
|
||||
@@ -555,12 +548,10 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
$fullPath = Storage::disk('local')->path($path);
|
||||
|
||||
if ($fullPath && file_exists($fullPath))
|
||||
{
|
||||
if ($fullPath && file_exists($fullPath)) {
|
||||
$rows = Excel::toArray(null, $fullPath)[0];
|
||||
|
||||
if((count($rows) - 1) <= 0)
|
||||
{
|
||||
if ((count($rows) - 1) <= 0) {
|
||||
Notification::make()
|
||||
->title('Invalid Locator Invoice Found')
|
||||
->body('Uploaded excel sheet is empty or<br>contains no valid data.')
|
||||
@@ -571,6 +562,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -579,29 +571,22 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
$seenSerialNumbers = [];
|
||||
$validRowsFound = false;
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index === 0) continue; // Skip header
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index === 0) {
|
||||
continue;
|
||||
} // Skip header
|
||||
|
||||
$serialNumber = trim($row[0]);
|
||||
|
||||
if (empty($serialNumber))
|
||||
{
|
||||
if (empty($serialNumber)) {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(Str::length($serialNumber) < 9 || Str::length($serialNumber) > 20 || !ctype_alnum($serialNumber))
|
||||
{
|
||||
} else {
|
||||
if (Str::length($serialNumber) < 9 || Str::length($serialNumber) > 20 || ! ctype_alnum($serialNumber)) {
|
||||
$invalidSerialCodes[] = $serialNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (in_array($serialNumber, $seenSerialNumbers)) {
|
||||
$duplicateSerials[] = $serialNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$seenSerialNumbers[] = $serialNumber;
|
||||
$validRowsFound = true;
|
||||
}
|
||||
@@ -622,6 +607,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -638,6 +624,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -652,6 +639,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -674,10 +662,9 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Save full file path to session
|
||||
session(['uploaded_invoice_path' => $fullPath]);
|
||||
Notification::make()
|
||||
@@ -707,11 +694,6 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
return Filament::auth()->user()->can('view export locator invoice validation');
|
||||
}),
|
||||
])
|
||||
|
||||
// ->filters([
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
@@ -725,6 +707,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -748,6 +731,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('invoice_number')
|
||||
->where('invoice_number', '!=', '')
|
||||
@@ -770,6 +754,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('pallet_number')
|
||||
->where('pallet_number', '!=', '')
|
||||
@@ -788,6 +773,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return LocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('locator_number')
|
||||
->where('locator_number', '!=', '')
|
||||
@@ -839,6 +825,12 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
@@ -889,6 +881,12 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
@@ -933,7 +931,7 @@ class LocatorInvoiceValidationResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
@@ -5,21 +5,20 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\LocatorExporter;
|
||||
use App\Filament\Imports\LocatorImporter;
|
||||
use App\Filament\Resources\LocatorResource\Pages;
|
||||
use App\Filament\Resources\LocatorResource\RelationManagers;
|
||||
use App\Models\Locator;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
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\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
@@ -48,6 +47,7 @@ class LocatorResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -63,10 +63,9 @@ class LocatorResource extends Resource
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('locPlantError', null);
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
@@ -91,16 +90,15 @@ class LocatorResource extends Resource
|
||||
$set('locator_number', null);
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
|
||||
return;
|
||||
}
|
||||
else if (!$locator || Str::length($locator) < 7) {
|
||||
} elseif (! $locator || Str::length($locator) < 7) {
|
||||
$set('locNameError', 'Please scan the valid locator number.');
|
||||
$set('locator_quantity', 0);
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('locNameError', null);
|
||||
$set('locator_quantity', PalletValidation::where('locator_number', $locator)->where('plant_id', $plantId)->distinct('pallet_number')->count('pallet_number'));
|
||||
$set('operator_id', Filament::auth()->user()?->name);
|
||||
@@ -145,6 +143,7 @@ class LocatorResource extends Resource
|
||||
$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')
|
||||
@@ -194,6 +193,7 @@ class LocatorResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -213,6 +213,7 @@ class LocatorResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Locator::where('plant_id', $plantId)->orderBy('locator_number', 'asc')->get()->unique('locator_number')->pluck('locator_number', 'locator_number')->toArray();
|
||||
// ->whereNotNull('locator_number')
|
||||
// ->where('locator_number','!=', '')
|
||||
@@ -260,6 +261,12 @@ class LocatorResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['locator_number'])) {
|
||||
@@ -295,6 +302,12 @@ class LocatorResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['locator_number'])) {
|
||||
@@ -326,7 +339,7 @@ class LocatorResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\MachineExporter;
|
||||
use App\Filament\Imports\MachineImporter;
|
||||
use App\Filament\Resources\MachineResource\Pages;
|
||||
use App\Filament\Resources\MachineResource\RelationManagers;
|
||||
use App\Models\Line;
|
||||
use App\Models\Machine;
|
||||
use App\Models\Plant;
|
||||
@@ -16,11 +15,11 @@ 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;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Str;
|
||||
|
||||
@@ -45,6 +44,7 @@ class MachineResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -57,10 +57,9 @@ class MachineResource extends Resource
|
||||
$set('mPlantError', 'Please select a plant first.');
|
||||
$set('line_id', null);
|
||||
$set('work_group_master_id', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('mPlantError', null);
|
||||
}
|
||||
})
|
||||
@@ -90,10 +89,9 @@ class MachineResource extends Resource
|
||||
if (! $lineId) {
|
||||
$set('mLineError', 'Please select a line first.');
|
||||
$set('work_group_master_id', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// $grpWrkCnr = Line::find($lineId)->group_work_center;
|
||||
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
|
||||
// {
|
||||
@@ -138,10 +136,9 @@ class MachineResource extends Resource
|
||||
$lineId = $get('line_id');
|
||||
if (! $lineId) {
|
||||
$set('mGroupWorkError', 'Please select a line first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// $grpWrkCnr = Line::find($lineId)->group_work_center;
|
||||
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
|
||||
// {
|
||||
@@ -194,6 +191,7 @@ class MachineResource extends Resource
|
||||
$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')
|
||||
|
||||
@@ -36,30 +36,84 @@ class MfmParameterResource extends Resource
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->relationship('plant', 'name')
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('device_master_id', null);
|
||||
$set('mfm_meter_id', null);
|
||||
$set('name', null);
|
||||
$set('register_id', null);
|
||||
$set('identifier', null);
|
||||
$set('byte_to_convert', null);
|
||||
$set('type_to_convert', null);
|
||||
$set('decimal_to_display', null);
|
||||
})
|
||||
->required(),
|
||||
Forms\Components\Select::make('device_master_id')
|
||||
->label('Device Master')
|
||||
->relationship('deviceName', 'name')
|
||||
//->relationship('deviceName', 'name')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\DeviceMaster::where('plant_id', $plantId)
|
||||
->pluck('name', 'id');
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('mfm_meter_id', null);
|
||||
$set('name', null);
|
||||
$set('register_id', null);
|
||||
$set('identifier', null);
|
||||
$set('byte_to_convert', null);
|
||||
$set('type_to_convert', null);
|
||||
$set('decimal_to_display', null);
|
||||
})
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\Select::make('mfm_meter_id')
|
||||
->label('Mfm Meter')
|
||||
->relationship('mfmMeter', 'sequence')
|
||||
// ->relationship('mfmMeter', 'sequence')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
if (!$plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\MfmMeter::where('plant_id', $plantId)
|
||||
->pluck('sequence', 'id');
|
||||
})
|
||||
->afterStateUpdated(function (callable $set) {
|
||||
$set('name', null);
|
||||
$set('register_id', null);
|
||||
$set('identifier', null);
|
||||
$set('byte_to_convert', null);
|
||||
$set('type_to_convert', null);
|
||||
$set('decimal_to_display', null);
|
||||
})
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label('Parameter Name')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('register_id')
|
||||
->label('Register ID')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('identifier')
|
||||
->label('Identifier')
|
||||
->reactive()
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('byte_to_convert')
|
||||
->label('Byte To Convert')
|
||||
->reactive()
|
||||
->default(2)
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('type_to_convert')
|
||||
@@ -67,6 +121,7 @@ class MfmParameterResource extends Resource
|
||||
->required(),
|
||||
Forms\Components\TextInput::make('decimal_to_display')
|
||||
->label('Decimal To Display')
|
||||
->reactive()
|
||||
->default(1)
|
||||
->required(),
|
||||
])
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\MotorTestingMasterExporter;
|
||||
use App\Filament\Imports\MotorTestingMasterImporter;
|
||||
use App\Filament\Resources\MotorTestingMasterResource\Pages;
|
||||
use App\Filament\Resources\MotorTestingMasterResource\RelationManagers;
|
||||
use App\Models\Configuration;
|
||||
use App\Models\Item;
|
||||
use App\Models\MotorTestingMaster;
|
||||
@@ -20,12 +19,12 @@ 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\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class MotorTestingMasterResource extends Resource
|
||||
@@ -49,6 +48,7 @@ class MotorTestingMasterResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -59,10 +59,9 @@ class MotorTestingMasterResource extends Resource
|
||||
$plantId = $get('plant_id');
|
||||
if (! $plantId) {
|
||||
$set('mTmError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('mTmError', null);
|
||||
}
|
||||
})
|
||||
@@ -108,17 +107,17 @@ class MotorTestingMasterResource extends Resource
|
||||
$code = $get('subassembly_code');
|
||||
if (! $code) {
|
||||
$set('iCodeError', 'Scan the valid Subassembly Code.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (strlen($code) < 6) {
|
||||
$set('iCodeError', 'Subassembly code must be at least 6 digits.');
|
||||
|
||||
return;
|
||||
}
|
||||
else if (!preg_match('/^[a-zA-Z0-9]{6,}$/', $code)) {
|
||||
} elseif (! preg_match('/^[a-zA-Z0-9]{6,}$/', $code)) {
|
||||
$set('code', null);
|
||||
$set('iCodeError', 'Subassembly code must contain only alpha-numeric characters.');
|
||||
|
||||
return;
|
||||
}
|
||||
$set('iCodeError', null);
|
||||
@@ -145,16 +144,13 @@ class MotorTestingMasterResource extends Resource
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
if ($plantId)
|
||||
{
|
||||
if ($plantId) {
|
||||
return Configuration::where('plant_id', $plantId)
|
||||
->where('c_name', 'MOTOR_PHASE')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
->toArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return Configuration::where('c_name', 'MOTOR_PHASE')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
@@ -197,16 +193,13 @@ class MotorTestingMasterResource extends Resource
|
||||
->selectablePlaceholder(false)
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if ($plantId)
|
||||
{
|
||||
if ($plantId) {
|
||||
return Configuration::where('plant_id', $plantId)
|
||||
->where('c_name', 'MOTOR_CONNECTION')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
->toArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return Configuration::where('c_name', 'MOTOR_CONNECTION')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
@@ -230,16 +223,13 @@ class MotorTestingMasterResource extends Resource
|
||||
->selectablePlaceholder(false)
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if ($plantId)
|
||||
{
|
||||
if ($plantId) {
|
||||
return Configuration::where('plant_id', $plantId)
|
||||
->where('c_name', 'INSULATION_RESISTANCE_TYPE')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
->toArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return Configuration::where('c_name', 'INSULATION_RESISTANCE_TYPE')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
@@ -317,6 +307,7 @@ class MotorTestingMasterResource extends Resource
|
||||
$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')
|
||||
@@ -474,6 +465,7 @@ class MotorTestingMasterResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -488,6 +480,7 @@ class MotorTestingMasterResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$pId = $get('Plant');
|
||||
|
||||
return Item::whereHas('motorTestingMasters', function ($query) use ($pId) {
|
||||
if ($pId) {
|
||||
$query->where('plant_id', $pId);
|
||||
@@ -505,7 +498,7 @@ class MotorTestingMasterResource extends Resource
|
||||
->options([
|
||||
'All' => 'All',
|
||||
'Y' => 'Y',
|
||||
'N' => 'N'
|
||||
'N' => 'N',
|
||||
])
|
||||
->default(null)
|
||||
->inlineLabel(false)
|
||||
@@ -516,16 +509,13 @@ class MotorTestingMasterResource extends Resource
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
if ($plantId)
|
||||
{
|
||||
if ($plantId) {
|
||||
return Configuration::where('plant_id', $plantId)
|
||||
->where('c_name', 'MOTOR_PHASE')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
->toArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return Configuration::where('c_name', 'MOTOR_PHASE')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
@@ -544,16 +534,13 @@ class MotorTestingMasterResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if ($plantId)
|
||||
{
|
||||
if ($plantId) {
|
||||
return Configuration::where('plant_id', $plantId)
|
||||
->where('c_name', 'MOTOR_CONNECTION')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
->toArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return Configuration::where('c_name', 'MOTOR_CONNECTION')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
@@ -571,12 +558,9 @@ class MotorTestingMasterResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId)
|
||||
{
|
||||
if (! $plantId) {
|
||||
return MotorTestingMaster::whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return MotorTestingMaster::where('plant_id', $plantId)->whereNotNull('created_by')->select('created_by')->distinct()->pluck('created_by', 'created_by');
|
||||
}
|
||||
})
|
||||
@@ -597,12 +581,9 @@ class MotorTestingMasterResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId)
|
||||
{
|
||||
if (! $plantId) {
|
||||
return MotorTestingMaster::whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return MotorTestingMaster::where('plant_id', $plantId)->whereNotNull('updated_by')->select('updated_by')->distinct()->pluck('updated_by', 'updated_by');
|
||||
}
|
||||
})
|
||||
@@ -627,6 +608,12 @@ class MotorTestingMasterResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Item'])) {
|
||||
@@ -642,7 +629,9 @@ class MotorTestingMasterResource extends Resource
|
||||
if (! empty($data['description'])) {
|
||||
$pId = $data['Plant'] ?? null;
|
||||
$descIds = Item::where('description', 'like', '%'.$data['description'].'%')->whereHas('motorTestingMasters', function ($query) use ($pId) {
|
||||
if ($pId) { $query->where('plant_id', $pId); }
|
||||
if ($pId) {
|
||||
$query->where('plant_id', $pId);
|
||||
}
|
||||
})->pluck('id')->toArray();
|
||||
|
||||
if (! empty($descIds)) {
|
||||
@@ -652,8 +641,7 @@ class MotorTestingMasterResource extends Resource
|
||||
|
||||
if ($data['isi_type'] == 'Y') {
|
||||
$query->where('isi_model', true);
|
||||
}
|
||||
else if ($data['isi_type'] == 'N') {
|
||||
} elseif ($data['isi_type'] == 'N') {
|
||||
$query->where('isi_model', false);
|
||||
}
|
||||
|
||||
@@ -694,6 +682,12 @@ class MotorTestingMasterResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Item'])) {
|
||||
@@ -707,8 +701,7 @@ class MotorTestingMasterResource extends Resource
|
||||
|
||||
if ($data['isi_type'] == 'Y') {
|
||||
$indicators[] = 'ISI Model: Yes';
|
||||
}
|
||||
else if ($data['isi_type'] == 'N') {
|
||||
} elseif ($data['isi_type'] == 'N') {
|
||||
$indicators[] = 'ISI Model: No';
|
||||
}
|
||||
|
||||
@@ -745,7 +738,7 @@ class MotorTestingMasterResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
@@ -5,31 +5,24 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\PalletValidationExporter;
|
||||
use App\Filament\Imports\PalletValidationImporter;
|
||||
use App\Filament\Resources\PalletValidationResource\Pages;
|
||||
use App\Filament\Resources\PalletValidationResource\RelationManagers;
|
||||
use App\Models\Item;
|
||||
use App\Models\LocatorInvoiceValidation;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\StickerMaster;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Actions;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Log;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
|
||||
class PalletValidationResource extends Resource
|
||||
{
|
||||
@@ -55,6 +48,7 @@ class PalletValidationResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set) {
|
||||
@@ -74,8 +68,7 @@ class PalletValidationResource extends Resource
|
||||
'x-model' => 'value',
|
||||
'x-on:keydown.enter.prevent' => '$wire.processPalletNo()',
|
||||
])
|
||||
->suffixAction(fn ($get,$set) =>
|
||||
Forms\Components\Actions\Action::make('addPallet')
|
||||
->suffixAction(fn ($get, $set) => Forms\Components\Actions\Action::make('addPallet')
|
||||
->label('')
|
||||
->button()
|
||||
->icon('heroicon-o-plus')
|
||||
@@ -105,14 +98,12 @@ class PalletValidationResource extends Resource
|
||||
} else {
|
||||
$newNumber = str_pad(intval($serialPart2) + 1, strlen($serialPart2), '0', STR_PAD_LEFT);
|
||||
}
|
||||
}
|
||||
else if ($lastPallet1) {
|
||||
} elseif ($lastPallet1) {
|
||||
$serialPart1 = substr($lastPallet1->pallet_number, strlen($prefix));
|
||||
// OR
|
||||
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
|
||||
$newNumber = str_pad(intval($serialPart1) + 1, strlen($serialPart1), '0', STR_PAD_LEFT);
|
||||
}
|
||||
else if ($lastPallet2) {
|
||||
} elseif ($lastPallet2) {
|
||||
$serialPart2 = substr($lastPallet2->pallet_number, strlen($prefix));
|
||||
// OR
|
||||
// $serialPart = str_replace($prefix, '', $lastPallet->pallet_number);
|
||||
@@ -172,6 +163,7 @@ class PalletValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return PalletValidation::query()
|
||||
->where('plant_id', $plantId)
|
||||
->where(function ($query) {
|
||||
@@ -186,7 +178,7 @@ class PalletValidationResource extends Resource
|
||||
->toArray();
|
||||
}),
|
||||
|
||||
Forms\Components\View::make('forms.components.save-pallet-button')
|
||||
Forms\Components\View::make('forms.components.save-pallet-button'),
|
||||
])
|
||||
->columns(5),
|
||||
Forms\Components\TextInput::make('id')
|
||||
@@ -199,7 +191,6 @@ class PalletValidationResource extends Resource
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
|
||||
->columns([
|
||||
// Tables\Columns\TextColumn::make('id')
|
||||
// ->label('ID')
|
||||
@@ -212,6 +203,7 @@ class PalletValidationResource extends Resource
|
||||
$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')
|
||||
@@ -286,6 +278,7 @@ class PalletValidationResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -309,6 +302,7 @@ class PalletValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return PalletValidation::where('plant_id', $plantId)
|
||||
// ->whereNotNull('pallet_number')
|
||||
// ->where('pallet_number', '!=', '')
|
||||
@@ -339,6 +333,7 @@ class PalletValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return PalletValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('locator_number')
|
||||
->where('locator_number', '!=', '')
|
||||
@@ -393,6 +388,12 @@ class PalletValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['pallet_number'])) {
|
||||
@@ -448,6 +449,12 @@ class PalletValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['pallet_number'])) {
|
||||
@@ -495,7 +502,7 @@ class PalletValidationResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -521,6 +528,7 @@ class PalletValidationResource extends Resource
|
||||
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->required()
|
||||
@@ -555,6 +563,7 @@ class PalletValidationResource extends Resource
|
||||
])
|
||||
->action(function (array $data) {
|
||||
$selectedPalletNumber = $data['pallet_list'];
|
||||
|
||||
return redirect()->route('download-reprint-qr-pdf', ['palletNo' => $selectedPalletNumber]);
|
||||
|
||||
})
|
||||
|
||||
@@ -5,11 +5,15 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\ProcessOrderExporter;
|
||||
use App\Filament\Imports\ProcessOrderImporter;
|
||||
use App\Filament\Resources\ProcessOrderResource\Pages;
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProcessOrder;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Actions\Action;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Forms\Set;
|
||||
@@ -18,19 +22,13 @@ use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
|
||||
use Smalot\PdfParser\Parser;
|
||||
use Storage;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\Select;
|
||||
use App\Models\Line;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use App\Models\Item;
|
||||
use App\Models\User;
|
||||
|
||||
// use App\Models\PalletValidation;
|
||||
// use Dom\Text;
|
||||
@@ -482,6 +480,7 @@ class ProcessOrderResource extends Resource
|
||||
$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')
|
||||
@@ -561,9 +560,6 @@ class ProcessOrderResource extends Resource
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
// ->filters([
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
@@ -574,6 +570,7 @@ class ProcessOrderResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -581,21 +578,19 @@ class ProcessOrderResource extends Resource
|
||||
$set('Item', null);
|
||||
}),
|
||||
Select::make('Item')
|
||||
->label('Item Code')
|
||||
->label('Search by Item Code')
|
||||
->nullable()
|
||||
->searchable()
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
|
||||
if(empty($plantId)) {
|
||||
return [];
|
||||
return Item::whereHas('processOrders', function ($query) use ($plantId) {
|
||||
if ($plantId) {
|
||||
$query->where('plant_id', $plantId);
|
||||
}
|
||||
|
||||
return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||
|
||||
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
|
||||
})->pluck('code', 'id');
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('process_order', null);
|
||||
}),
|
||||
@@ -627,6 +622,12 @@ class ProcessOrderResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Item'])) {
|
||||
@@ -660,6 +661,12 @@ class ProcessOrderResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Item'])) {
|
||||
@@ -687,7 +694,7 @@ class ProcessOrderResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -787,6 +794,7 @@ class ProcessOrderResource extends Resource
|
||||
if (! $plantId || ! $itemId || ! $processOrder || ! $state) {
|
||||
$set('received_quantity', null);
|
||||
$set('machine_name', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -815,6 +823,7 @@ class ProcessOrderResource extends Resource
|
||||
// })
|
||||
->action(function (array $data) {
|
||||
$username = Filament::auth()->user()->name;
|
||||
|
||||
return redirect()->route('download-reprint-process-pdf', [
|
||||
'plant' => $data['plant'],
|
||||
'item' => $data['Item'],
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\ProductCharacteristicsMasterExporter;
|
||||
use App\Filament\Imports\ProductCharacteristicsMasterImporter;
|
||||
use App\Filament\Resources\ProductCharacteristicsMasterResource\Pages;
|
||||
use App\Filament\Resources\ProductCharacteristicsMasterResource\RelationManagers;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Machine;
|
||||
@@ -14,19 +13,19 @@ use App\Models\ProductCharacteristicsMaster;
|
||||
use App\Models\WorkGroupMaster;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
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\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
|
||||
class ProductCharacteristicsMasterResource extends Resource
|
||||
{
|
||||
@@ -45,6 +44,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
->relationship('plant', 'name')
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -59,6 +59,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
if (empty($plantId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return \App\Models\Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||
})
|
||||
->required(),
|
||||
@@ -70,6 +71,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
if (empty($plantId)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Line::where('plant_id', $plantId)->pluck('name', 'id');
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
@@ -107,10 +109,9 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
if (! $lineId) {
|
||||
$set('mGroupWorkError', 'Please select a line first.');
|
||||
$set('machine_id', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// $grpWrkCnr = Line::find($lineId)->group_work_center;
|
||||
// if (!$grpWrkCnr || Str::length($grpWrkCnr) < 1)
|
||||
// {
|
||||
@@ -210,7 +211,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
|
||||
if (! is_null($lower) && ! is_null($upper) && ! is_null($middle)) {
|
||||
if (! ($lower <= $middle && $middle <= $upper)) {
|
||||
$fail("Middle must be between Lower and Upper (Lower ≤ Middle ≤ Upper).");
|
||||
$fail('Middle must be between Lower and Upper (Lower ≤ Middle ≤ Upper).');
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -233,6 +234,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
$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')
|
||||
@@ -317,11 +319,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
// ->filters([
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
->filters([
|
||||
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
->label('Advanced Filters')
|
||||
@@ -331,6 +329,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -356,24 +355,22 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
$set('Item', null);
|
||||
}),
|
||||
Select::make('Item')
|
||||
->label('Item Code')
|
||||
->label('Search by Item Code')
|
||||
->nullable()
|
||||
->searchable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
|
||||
if(empty($plantId)) {
|
||||
return [];
|
||||
return Item::whereHas('productCharacteristicsMasters', function ($query) use ($plantId) {
|
||||
if ($plantId) {
|
||||
$query->where('plant_id', $plantId);
|
||||
}
|
||||
|
||||
return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||
|
||||
//return $plantId ? Item::where('plant_id', $plantId)->pluck('code', 'id') : [];
|
||||
})->pluck('code', 'id');
|
||||
})
|
||||
->reactive()
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('process_order', null);
|
||||
}),
|
||||
->reactive(),
|
||||
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
// $set('process_order', null);
|
||||
// }),
|
||||
Select::make('work_group_master')
|
||||
->label('Select Work Group Master')
|
||||
->nullable()
|
||||
@@ -421,7 +418,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
->label('Characteristics Type')
|
||||
->options([
|
||||
'Product' => 'Product',
|
||||
'Process' => 'Process'
|
||||
'Process' => 'Process',
|
||||
]),
|
||||
DateTimePicker::make(name: 'created_from')
|
||||
->label('Created From')
|
||||
@@ -442,6 +439,12 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Line'])) {
|
||||
@@ -472,7 +475,6 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
|
||||
|
||||
// $query->orderBy('created_at', 'asc');
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
@@ -480,6 +482,12 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Line'])) {
|
||||
@@ -511,7 +519,7 @@ class ProductCharacteristicsMasterResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
@@ -6,30 +6,28 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
|
||||
use App\Filament\Exports\ProductionLineStopExporter;
|
||||
use App\Filament\Imports\ProductionLineStopImporter;
|
||||
use App\Filament\Resources\ProductionLineStopResource\Pages;
|
||||
use App\Filament\Resources\ProductionLineStopResource\RelationManagers;
|
||||
use App\Models\Block;
|
||||
use App\Models\Line;
|
||||
use App\Models\LineStop;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ProductionLineStop;
|
||||
use App\Models\Shift;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
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\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
|
||||
class ProductionLineStopResource extends Resource
|
||||
{
|
||||
@@ -56,6 +54,7 @@ class ProductionLineStopResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -68,10 +67,9 @@ class ProductionLineStopResource extends Resource
|
||||
$set('block_name', null);
|
||||
if (! $plantId) {
|
||||
$set('plsPlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('plsPlantError', null);
|
||||
}
|
||||
})
|
||||
@@ -97,17 +95,16 @@ class ProductionLineStopResource extends Resource
|
||||
->reactive()
|
||||
->default(function () {
|
||||
$latestShiftId = optional(ProductionLineStop::latest()->first())->shift_id;
|
||||
|
||||
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
|
||||
})
|
||||
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
if ($get('id')) {
|
||||
$getShift = ProductionLineStop::where('id', $get('id'))->first();
|
||||
// $getBlock = \App\Models\Shift::where('id', $getShift->shift_id)->first();
|
||||
$getBlock = Shift::where('id', $getShift->shift_id)->first();
|
||||
if($getBlock->block_id)
|
||||
{
|
||||
if ($getBlock->block_id) {
|
||||
$set('block_name', $getBlock->block_id);
|
||||
$set('plsBlockError', null);
|
||||
}
|
||||
@@ -118,10 +115,9 @@ class ProductionLineStopResource extends Resource
|
||||
|
||||
if (! $blockId) {
|
||||
$set('plsBlockError', 'Please select a block first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('plsBlockError', null);
|
||||
}
|
||||
})
|
||||
@@ -150,11 +146,9 @@ class ProductionLineStopResource extends Resource
|
||||
})
|
||||
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
if ($get('id')) {
|
||||
$getShift = ProductionLineStop::where('id', $get('id'))->first();
|
||||
if($getShift->shift_id)
|
||||
{
|
||||
if ($getShift->shift_id) {
|
||||
$set('shift_id', $getShift->shift_id);
|
||||
$set('plsShiftError', null);
|
||||
}
|
||||
@@ -165,10 +159,9 @@ class ProductionLineStopResource extends Resource
|
||||
|
||||
if (! $shiftId) {
|
||||
$set('plsShiftError', 'Please select a shift first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('plsShiftError', null);
|
||||
}
|
||||
})
|
||||
@@ -196,11 +189,9 @@ class ProductionLineStopResource extends Resource
|
||||
return optional(ProductionLineStop::latest()->first())->line_id;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
if ($get('id')) {
|
||||
$getShift = ProductionLineStop::where('id', $get('id'))->first();
|
||||
if($getShift->line_id)
|
||||
{
|
||||
if ($getShift->line_id) {
|
||||
$set('line_id', $getShift->line_id);
|
||||
$set('plsLineError', null);
|
||||
}
|
||||
@@ -212,10 +203,9 @@ class ProductionLineStopResource extends Resource
|
||||
|
||||
if (! $lineId) {
|
||||
$set('plsLineError', 'Please select a line first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('plsLineError', null);
|
||||
}
|
||||
})
|
||||
@@ -253,6 +243,7 @@ class ProductionLineStopResource extends Resource
|
||||
// Ensure `linestop_id` is not cleared
|
||||
if (! $lineStopId) {
|
||||
$set('lineStop_reason', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -275,16 +266,14 @@ class ProductionLineStopResource extends Resource
|
||||
->before('to_datetime')
|
||||
->reactive()
|
||||
// ->closeOnDateSelection()
|
||||
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
|
||||
self::updateStopDuration($get, $set)
|
||||
->afterStateUpdated(fn ($state, callable $set, callable $get) => self::updateStopDuration($get, $set)
|
||||
),
|
||||
Forms\Components\DateTimePicker::make('to_datetime')
|
||||
->label('To DateTime')
|
||||
->required()
|
||||
->after('from_datetime')
|
||||
->reactive()
|
||||
->afterStateUpdated(fn ($state, callable $set, callable $get) =>
|
||||
self::updateStopDuration($get, $set) //self means it calling the function within the class
|
||||
->afterStateUpdated(fn ($state, callable $set, callable $get) => self::updateStopDuration($get, $set) // self means it calling the function within the class
|
||||
)
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('plsToDateError') ? 'border-red-500' : '',
|
||||
@@ -328,14 +317,11 @@ class ProductionLineStopResource extends Resource
|
||||
$diffInMinutes = $fromTime->diffInMinutes($toTime);
|
||||
// $set('stop_hour', floor($diffInMinutes / 60));
|
||||
// $set('stop_min', $diffInMinutes % 60);
|
||||
if((floor($diffInMinutes / 60) === 0.0) && ($diffInMinutes % 60 === 0))
|
||||
{
|
||||
if ((floor($diffInMinutes / 60) === 0.0) && ($diffInMinutes % 60 === 0)) {
|
||||
$set('stop_hour', null);
|
||||
$set('stop_min', null);
|
||||
$set('plsToDateError', 'Time difference must be atlease a minute.');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('stop_hour', floor($diffInMinutes / 60));
|
||||
$set('stop_min', $diffInMinutes % 60);
|
||||
$set('plsToDateError', null);
|
||||
@@ -363,6 +349,7 @@ class ProductionLineStopResource extends Resource
|
||||
$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('linestop.code')
|
||||
@@ -433,7 +420,6 @@ class ProductionLineStopResource extends Resource
|
||||
Filter::make('advanced_filters')
|
||||
->label('Advanced Filters')
|
||||
->form([
|
||||
|
||||
// plant
|
||||
Select::make('Plant')
|
||||
->label('Select Plant')
|
||||
@@ -443,6 +429,7 @@ class ProductionLineStopResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -463,6 +450,7 @@ class ProductionLineStopResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Line::where('plant_id', $plantId)
|
||||
->pluck('name', 'id');
|
||||
})
|
||||
@@ -478,6 +466,7 @@ class ProductionLineStopResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
|
||||
})
|
||||
->reactive()
|
||||
@@ -509,6 +498,7 @@ class ProductionLineStopResource extends Resource
|
||||
// ->options(fn () => LineStop::orderBy('code')->whereHas('productionLineStops')->pluck('code', 'id'))
|
||||
->options(function (callable $get) {
|
||||
$pId = $get('Plant');
|
||||
|
||||
return LineStop::orderBy('code')->whereHas('productionLineStops', function ($query) use ($pId) {
|
||||
if ($pId) {
|
||||
$query->where('plant_id', $pId);
|
||||
@@ -535,19 +525,25 @@ class ProductionLineStopResource extends Resource
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if ($plant = $data['Plant'] ?? null) {
|
||||
$query->where('plant_id', $plant);
|
||||
if (! empty($data['Plant'])) {// if ($plant = $data['Plant'] ?? null) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if ($shift = $data['Shift'] ?? null) {
|
||||
$query->where('shift_id', $shift);
|
||||
if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
|
||||
$query->where('shift_id', $data['Shift']);
|
||||
}
|
||||
|
||||
if ($line = $data['Line'] ?? null) {
|
||||
$query->where('line_id', $line);
|
||||
if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
|
||||
$query->where('line_id', $data['Line']);
|
||||
}
|
||||
|
||||
if ($code = $data['line_stop_id'] ?? null) {
|
||||
if (! empty($data['line_stop_id'])) { // if ($code = $data['line_stop_id'] ?? null) {
|
||||
// Find the linestop_id by code entered
|
||||
// $lineStop = \App\Models\LineStop::where('code', 'like', "%{$code}%")->first();
|
||||
|
||||
@@ -558,15 +554,15 @@ class ProductionLineStopResource extends Resource
|
||||
// // If no match found, you can either handle it as an error or return no results
|
||||
// $query->where('linestop_id', null); // This will return no results if no match
|
||||
// }
|
||||
$query->where('linestop_id', $code);
|
||||
$query->where('linestop_id', $data['line_stop_id']);
|
||||
}
|
||||
|
||||
if ($from = $data['created_from'] ?? null) {
|
||||
$query->where('created_at', '>=', $from);
|
||||
if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
|
||||
if ($to = $data['created_to'] ?? null) {
|
||||
$query->where('created_at', '<=', $to);
|
||||
if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
// return $query;
|
||||
})
|
||||
@@ -575,6 +571,12 @@ class ProductionLineStopResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Shift'])) {
|
||||
@@ -599,7 +601,7 @@ class ProductionLineStopResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -611,7 +613,7 @@ class ProductionLineStopResource extends Resource
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
FilamentExportBulkAction::make('export')
|
||||
FilamentExportBulkAction::make('export'),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
|
||||
@@ -6,7 +6,6 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
|
||||
use App\Filament\Exports\ProductionPlanExporter;
|
||||
use App\Filament\Imports\ProductionPlanImporter;
|
||||
use App\Filament\Resources\ProductionPlanResource\Pages;
|
||||
use App\Filament\Resources\ProductionPlanResource\RelationManagers;
|
||||
use App\Models\Block;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
@@ -16,19 +15,18 @@ use Carbon\Carbon;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
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\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
class ProductionPlanResource extends Resource
|
||||
{
|
||||
@@ -55,6 +53,7 @@ class ProductionPlanResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -67,10 +66,9 @@ class ProductionPlanResource extends Resource
|
||||
$set('block_name', null);
|
||||
if (! $plantId) {
|
||||
$set('ppPlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('ppPlantError', null);
|
||||
}
|
||||
})
|
||||
@@ -95,16 +93,15 @@ class ProductionPlanResource extends Resource
|
||||
->reactive()
|
||||
->default(function () {
|
||||
$latestShiftId = optional(ProductionPlan::latest()->first())->shift_id;
|
||||
|
||||
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
|
||||
})
|
||||
// ->afterStateUpdated(fn ($set) => $set('shift_id', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
if ($get('id')) {
|
||||
$getShift = ProductionPlan::where('id', $get('id'))->first();
|
||||
$getBlock = Shift::where('id', $getShift->shift_id)->first();
|
||||
if($getBlock->block_id)
|
||||
{
|
||||
if ($getBlock->block_id) {
|
||||
$set('block_name', $getBlock->block_id);
|
||||
$set('ppBlockError', null);
|
||||
}
|
||||
@@ -115,10 +112,9 @@ class ProductionPlanResource extends Resource
|
||||
|
||||
if (! $blockId) {
|
||||
$set('ppBlockError', 'Please select a block first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('ppBlockError', null);
|
||||
}
|
||||
})
|
||||
@@ -148,11 +144,9 @@ class ProductionPlanResource extends Resource
|
||||
})
|
||||
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
if ($get('id')) {
|
||||
$getShift = ProductionPlan::where('id', $get('id'))->first();
|
||||
if($getShift->shift_id)
|
||||
{
|
||||
if ($getShift->shift_id) {
|
||||
$set('shift_id', $getShift->shift_id);
|
||||
$set('ppShiftError', null);
|
||||
}
|
||||
@@ -163,10 +157,9 @@ class ProductionPlanResource extends Resource
|
||||
|
||||
if (! $curShiftId) {
|
||||
$set('ppShiftError', 'Please select a shift first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('ppShiftError', null);
|
||||
}
|
||||
})
|
||||
@@ -198,17 +191,13 @@ class ProductionPlanResource extends Resource
|
||||
// return optional(ProductionPlan::latest()->first())->line_id;
|
||||
// })
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
if ($get('id')) {
|
||||
$getShift = ProductionPlan::where('id', $get('id'))->first();
|
||||
if($getShift->line_id)
|
||||
{
|
||||
if ($getShift->line_id) {
|
||||
$set('line_id', $getShift->line_id);
|
||||
$set('ppLineError', null);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$currentDT = Carbon::now()->toDateTimeString();
|
||||
$set('created_at', $currentDT);
|
||||
$set('update_date', null);
|
||||
@@ -219,13 +208,11 @@ class ProductionPlanResource extends Resource
|
||||
|
||||
if (! $lineId) {
|
||||
$set('ppLineError', 'Please select a line first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$isUpdate = ! empty($get('id'));
|
||||
if (!$isUpdate)
|
||||
{
|
||||
if (! $isUpdate) {
|
||||
$exists = ProductionPlan::where('plant_id', $get('plant_id'))
|
||||
->where('shift_id', $get('shift_id'))
|
||||
->where('line_id', $get('line_id'))
|
||||
@@ -233,14 +220,12 @@ class ProductionPlanResource extends Resource
|
||||
->latest()
|
||||
->exists();
|
||||
|
||||
if ($exists)
|
||||
{
|
||||
if ($exists) {
|
||||
$set('line_id', null);
|
||||
$set('ppLineError', 'Production plan already updated.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$existShifts = ProductionPlan::where('plant_id', $get('plant_id'))
|
||||
->where('shift_id', $get('shift_id'))
|
||||
->where('line_id', $get('line_id'))
|
||||
@@ -248,8 +233,7 @@ class ProductionPlanResource extends Resource
|
||||
->latest()
|
||||
->exists();
|
||||
|
||||
if ($existShifts) //if ($existShifts->count() > 0)
|
||||
{
|
||||
if ($existShifts) { // if ($existShifts->count() > 0)
|
||||
// $currentDate = date('Y-m-d');
|
||||
$yesterday = date('Y-m-d', strtotime('-1 days'));
|
||||
|
||||
@@ -274,11 +258,10 @@ class ProductionPlanResource extends Resource
|
||||
|
||||
$set('line_id', null);
|
||||
$set('ppLineError', 'Production plan already updated.');
|
||||
|
||||
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$currentDate = date('Y-m-d');
|
||||
|
||||
$shiftId = Shift::where('id', $get('shift_id'))
|
||||
@@ -302,16 +285,16 @@ class ProductionPlanResource extends Resource
|
||||
|
||||
$set('line_id', null);
|
||||
$set('ppLineError', 'Choosed a invalid shift.');
|
||||
|
||||
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$set('ppLineError', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// $currentDate = date('Y-m-d');
|
||||
$yesterday = date('Y-m-d', strtotime('-1 days'));
|
||||
|
||||
@@ -339,11 +322,10 @@ class ProductionPlanResource extends Resource
|
||||
$set('update_date', '1');
|
||||
|
||||
$set('ppLineError', null);
|
||||
|
||||
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$currentDate = date('Y-m-d');
|
||||
|
||||
$shiftId = Shift::where('id', $get('shift_id'))
|
||||
@@ -367,12 +349,14 @@ class ProductionPlanResource extends Resource
|
||||
|
||||
$set('line_id', null);
|
||||
$set('ppLineError', 'Choosed a invalid shift.');
|
||||
|
||||
// $set('ppLineError', 'Valid (From: '.$from_dt.', To: '.$to_dt.')');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$set('ppLineError', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -449,10 +433,8 @@ class ProductionPlanResource extends Resource
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$planQuan = $get('plan_quantity');
|
||||
|
||||
if(!$get('update_date') )
|
||||
{
|
||||
if(!$get('id'))
|
||||
{
|
||||
if (! $get('update_date')) {
|
||||
if (! $get('id')) {
|
||||
$currentDT = Carbon::now()->toDateTimeString();
|
||||
$set('created_at', $currentDT);
|
||||
}
|
||||
@@ -460,10 +442,9 @@ class ProductionPlanResource extends Resource
|
||||
|
||||
if (! $planQuan) {
|
||||
$set('ppPlanQuanError', 'Scan the valid plan quantity.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('ppPlanQuanError', null);
|
||||
}
|
||||
})
|
||||
@@ -529,6 +510,7 @@ class ProductionPlanResource extends Resource
|
||||
$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('plan_quantity')
|
||||
@@ -593,6 +575,7 @@ class ProductionPlanResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -612,6 +595,7 @@ class ProductionPlanResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Line::where('plant_id', $plantId)
|
||||
->pluck('name', 'id');
|
||||
})
|
||||
@@ -627,6 +611,7 @@ class ProductionPlanResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
|
||||
})
|
||||
->reactive()
|
||||
@@ -669,25 +654,32 @@ class ProductionPlanResource extends Resource
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if ($plant = $data['Plant'] ?? null) {
|
||||
$query->where('plant_id', $plant);
|
||||
if (! empty($data['Plant'])) {// if ($plant = $data['Plant'] ?? null) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if ($shift = $data['Shift'] ?? null) {
|
||||
$query->where('shift_id', $shift);
|
||||
if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
|
||||
$query->where('shift_id', $data['Shift']);
|
||||
}
|
||||
|
||||
if ($line = $data['Line'] ?? null) {
|
||||
$query->where('line_id', $line);
|
||||
if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
|
||||
$query->where('line_id', $data['Line']);
|
||||
}
|
||||
|
||||
if ($from = $data['created_from'] ?? null) {
|
||||
$query->where('created_at', '>=', $from);
|
||||
if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
|
||||
if ($to = $data['created_to'] ?? null) {
|
||||
$query->where('created_at', '<=', $to);
|
||||
if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
})
|
||||
->indicateUsing(function (array $data) {
|
||||
@@ -695,6 +687,12 @@ class ProductionPlanResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Shift'])) {
|
||||
@@ -714,7 +712,7 @@ class ProductionPlanResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -726,7 +724,7 @@ class ProductionPlanResource extends Resource
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
FilamentExportBulkAction::make('export')
|
||||
FilamentExportBulkAction::make('export'),
|
||||
]),
|
||||
])
|
||||
->headerActions([
|
||||
|
||||
@@ -6,8 +6,6 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction as ActionsFilam
|
||||
use App\Filament\Exports\ProductionQuantityExporter;
|
||||
use App\Filament\Imports\ProductionQuantityImporter;
|
||||
use App\Filament\Resources\ProductionQuantityResource\Pages;
|
||||
use App\Filament\Resources\ProductionQuantityResource\RelationManagers;
|
||||
use App\Forms\Components\PlantSelect;
|
||||
use App\Models\Block;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
@@ -18,29 +16,25 @@ use Carbon\Carbon;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Hidden;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Concerns\InteractsWithForms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Livewire\Livewire;
|
||||
// use Filament\Forms\Components\View;
|
||||
use Filament\Tables\Actions\FilamentExportBulkAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
// use Filament\Forms\Components\View;
|
||||
use Livewire\Livewire;
|
||||
|
||||
class ProductionQuantityResource extends Resource
|
||||
{
|
||||
|
||||
protected static ?string $model = ProductionQuantity::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
@@ -52,7 +46,6 @@ class ProductionQuantityResource extends Resource
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
|
||||
// public $plant_id;
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
@@ -69,6 +62,7 @@ class ProductionQuantityResource extends Resource
|
||||
->columnSpan(2) // 1
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
// ->default(fn () => optional(ProductionQuantity::latest()->first())->plant_id)
|
||||
@@ -81,13 +75,11 @@ class ProductionQuantityResource extends Resource
|
||||
->afterStateUpdated(function ($state, $set, callable $get, $livewire) {
|
||||
$plantId = $get('plant_id');
|
||||
$set('block_name', null);
|
||||
if (!$plantId)
|
||||
{
|
||||
if (! $plantId) {
|
||||
$set('pqPlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('validationError', null);
|
||||
$set('pqPlantError', null);
|
||||
}
|
||||
@@ -138,15 +130,14 @@ class ProductionQuantityResource extends Resource
|
||||
->reactive()
|
||||
->default(function () {
|
||||
$latestShiftId = optional(ProductionQuantity::latest()->first())->shift_id;
|
||||
|
||||
return optional(Shift::where('id', $latestShiftId)->first())->block_id;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
if ($get('id')) {
|
||||
$getShift = ProductionQuantity::where('id', $get('id'))->first();
|
||||
$getBlock = Shift::where('id', $getShift->shift_id)->first();
|
||||
if($getBlock->block_id)
|
||||
{
|
||||
if ($getBlock->block_id) {
|
||||
$set('block_name', $getBlock->block_id);
|
||||
$set('pqBlockError', null);
|
||||
}
|
||||
@@ -160,10 +151,9 @@ class ProductionQuantityResource extends Resource
|
||||
|
||||
if (! $blockId) {
|
||||
$set('pqBlockError', 'Please select a block first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('validationError', null);
|
||||
$set('pqBlockError', null);
|
||||
}
|
||||
@@ -194,11 +184,9 @@ class ProductionQuantityResource extends Resource
|
||||
})
|
||||
// ->afterStateUpdated(fn ($set) => $set('line_id', null))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
if ($get('id')) {
|
||||
$getShift = ProductionQuantity::where('id', $get('id'))->first();
|
||||
if($getShift->shift_id)
|
||||
{
|
||||
if ($getShift->shift_id) {
|
||||
$set('shift_id', $getShift->shift_id);
|
||||
$set('pqShiftError', null);
|
||||
}
|
||||
@@ -209,10 +197,9 @@ class ProductionQuantityResource extends Resource
|
||||
|
||||
if (! $curShiftId) {
|
||||
$set('pqShiftError', 'Please select a shift first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('validationError', null);
|
||||
$set('pqShiftError', null);
|
||||
}
|
||||
@@ -246,11 +233,9 @@ class ProductionQuantityResource extends Resource
|
||||
return optional(ProductionQuantity::latest()->first())->line_id;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if($get('id'))
|
||||
{
|
||||
if ($get('id')) {
|
||||
$getShift = ProductionQuantity::where('id', $get('id'))->first();
|
||||
if($getShift->line_id)
|
||||
{
|
||||
if ($getShift->line_id) {
|
||||
$set('line_id', $getShift->line_id);
|
||||
$set('pqLineError', null);
|
||||
}
|
||||
@@ -265,10 +250,9 @@ class ProductionQuantityResource extends Resource
|
||||
|
||||
if (! $lineId) {
|
||||
$set('pqLineError', 'Please select a line first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('validationError', null);
|
||||
$set('pqLineError', null);
|
||||
$set('item_id', null);
|
||||
@@ -296,7 +280,7 @@ class ProductionQuantityResource extends Resource
|
||||
// 'x-on:change' => "\$wire.dispatch('filtersUpdated')", // Dispatch Livewire event from Alpine.js
|
||||
// ])
|
||||
->extraAttributes([
|
||||
'x-on:change' => "\$wire.dispatch('filtersUpdated', { lineId: \$event.target.value })"
|
||||
'x-on:change' => "\$wire.dispatch('filtersUpdated', { lineId: \$event.target.value })",
|
||||
])
|
||||
->extraAttributes(fn ($get) => [
|
||||
'class' => $get('pqLineError') ? 'border-red-500' : '',
|
||||
@@ -328,21 +312,20 @@ class ProductionQuantityResource extends Resource
|
||||
// $latestProductionOrder = ProductionQuantity::latest()->first()->production_order;
|
||||
// return $latestProductionOrder ?? null;
|
||||
$latestProduction = ProductionQuantity::latest()->first();
|
||||
|
||||
return $latestProduction ? $latestProduction->production_order : null;
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $get, callable $set): void {
|
||||
if(!is_numeric($get('production_order')) || !preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order')))
|
||||
{
|
||||
if (! is_numeric($get('production_order')) || ! preg_match('/^[1-9][0-9]{6,13}$/', $get('production_order'))) {
|
||||
$set('item_code', null);
|
||||
$set('item_id', null);
|
||||
$set('serial_number', null);
|
||||
$set('production_order', null);
|
||||
$set('prodOrdError', "Must be a numeric value with 7 to 14 digits.");
|
||||
$set('prodOrdError', 'Must be a numeric value with 7 to 14 digits.');
|
||||
$set('validationError', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('item_code', null);
|
||||
$set('item_id', null);
|
||||
// $set('item_description', null);
|
||||
@@ -350,6 +333,7 @@ class ProductionQuantityResource extends Resource
|
||||
$set('production_order', $state);
|
||||
$set('prodOrdError', null);
|
||||
$set('validationError', null);
|
||||
|
||||
return;
|
||||
// if (empty($state)) {
|
||||
// }
|
||||
@@ -971,6 +955,7 @@ class ProductionQuantityResource extends Resource
|
||||
$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('production_order')
|
||||
@@ -1049,6 +1034,7 @@ class ProductionQuantityResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -1071,6 +1057,7 @@ class ProductionQuantityResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Line::where('plant_id', $plantId)
|
||||
->pluck('name', 'id');
|
||||
})
|
||||
@@ -1089,6 +1076,7 @@ class ProductionQuantityResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Block::where('plant_id', $get('Plant'))->pluck('name', 'id');
|
||||
})
|
||||
->reactive()
|
||||
@@ -1133,10 +1121,9 @@ class ProductionQuantityResource extends Resource
|
||||
$plantId = $get('Plant');
|
||||
|
||||
if (! $plantId) {
|
||||
return Item::distinct()->whereHas('productionQuantities')->pluck('code', 'id');
|
||||
}
|
||||
else {
|
||||
return Item::where('plant_id', $plantId)->whereHas('productionQuantities')->distinct()->pluck('code', 'id');
|
||||
return Item::whereHas('productionQuantities')->distinct()->pluck('code', 'id');
|
||||
} else {
|
||||
return Item::whereHas('productionQuantities')->where('plant_id', $plantId)->distinct()->pluck('code', 'id');
|
||||
}
|
||||
// return Item::whereHas('stickerMasters', function ($query) use ($pId) {
|
||||
// if ($pId) {
|
||||
@@ -1156,8 +1143,7 @@ class ProductionQuantityResource extends Resource
|
||||
|
||||
if (! $plantId) {
|
||||
return ProductionQuantity::whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status');
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('sap_msg_status')->select('sap_msg_status')->distinct()->pluck('sap_msg_status', 'sap_msg_status');
|
||||
}
|
||||
})
|
||||
@@ -1171,24 +1157,15 @@ class ProductionQuantityResource extends Resource
|
||||
$plantId = $get('Plant');
|
||||
$lineId = $get('Line');
|
||||
$shiftId = $get('Shift');
|
||||
if (!$plantId && !$lineId && !$shiftId)
|
||||
{
|
||||
if (! $plantId && ! $lineId && ! $shiftId) {
|
||||
return ProductionQuantity::whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
|
||||
}
|
||||
else if ($plantId && !$lineId && !$shiftId)
|
||||
{
|
||||
} elseif ($plantId && ! $lineId && ! $shiftId) {
|
||||
return ProductionQuantity::where('plant_id', $plantId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
|
||||
}
|
||||
else if ($plantId && $lineId && !$shiftId)
|
||||
{
|
||||
} elseif ($plantId && $lineId && ! $shiftId) {
|
||||
return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
|
||||
}
|
||||
else if ($plantId && !$lineId && $shiftId)
|
||||
{
|
||||
} elseif ($plantId && ! $lineId && $shiftId) {
|
||||
return ProductionQuantity::where('plant_id', $plantId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
|
||||
}
|
||||
else// if ($plantId && $lineId && $shiftId)
|
||||
{
|
||||
} else { // if ($plantId && $lineId && $shiftId)
|
||||
return ProductionQuantity::where('plant_id', $plantId)->where('line_id', $lineId)->where('shift_id', $shiftId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
|
||||
}
|
||||
})
|
||||
@@ -1212,16 +1189,22 @@ class ProductionQuantityResource extends Resource
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
if ($plant = $data['Plant'] ?? null) {
|
||||
$query->where('plant_id', $plant);
|
||||
if (! empty($data['Plant'])) {// if ($plant = $data['Plant'] ?? null) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if ($shift = $data['Shift'] ?? null) {
|
||||
$query->where('shift_id', $shift);
|
||||
if (! empty($data['Shift'])) {// if ($shift = $data['Shift'] ?? null) {
|
||||
$query->where('shift_id', $data['Shift']);
|
||||
}
|
||||
|
||||
if ($line = $data['Line'] ?? null) {
|
||||
$query->where('line_id', $line);
|
||||
if (! empty($data['Line'])) {// if ($line = $data['Line'] ?? null) {
|
||||
$query->where('line_id', $data['Line']);
|
||||
}
|
||||
|
||||
if (! empty($data['production_order'])) {
|
||||
@@ -1244,12 +1227,12 @@ class ProductionQuantityResource extends Resource
|
||||
$query->where('operator_id', $data['operator_id']);
|
||||
}
|
||||
|
||||
if ($from = $data['created_from'] ?? null) {
|
||||
$query->where('created_at', '>=', $from);
|
||||
if (! empty($data['created_from'])) {// if ($from = $data['created_from'] ?? null) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
|
||||
if ($to = $data['created_to'] ?? null) {
|
||||
$query->where('created_at', '<=', $to);
|
||||
if (! empty($data['created_to'])) {// if ($to = $data['created_to'] ?? null) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
|
||||
// return $query;
|
||||
@@ -1259,6 +1242,12 @@ class ProductionQuantityResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Shift'])) {
|
||||
@@ -1298,7 +1287,7 @@ class ProductionQuantityResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -1370,7 +1359,6 @@ class ProductionQuantityResource extends Resource
|
||||
return 'Production Reports';
|
||||
}
|
||||
|
||||
|
||||
// public function triggerChartUpdate(): void
|
||||
// {
|
||||
// if (session()->has('select_plant') && session()->has('select_line')) {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,30 +5,28 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\ReworkLocatorInvoiceValidationExporter;
|
||||
use App\Filament\Imports\ReworkLocatorInvoiceValidationImporter;
|
||||
use App\Filament\Resources\ReworkLocatorInvoiceValidationResource\Pages;
|
||||
use App\Filament\Resources\ReworkLocatorInvoiceValidationResource\RelationManagers;
|
||||
use App\Models\InvoiceValidation;
|
||||
use App\Models\LocatorInvoiceValidation;
|
||||
use App\Models\PalletValidation;
|
||||
use App\Models\Plant;
|
||||
use App\Models\ReworkLocatorInvoiceValidation;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Select;
|
||||
|
||||
class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
{
|
||||
@@ -54,20 +52,18 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
->required()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
if ($plantId)
|
||||
{
|
||||
if ($plantId) {
|
||||
$set('plant', $plantId);
|
||||
$set('invoice_number', null);
|
||||
$set('scan_pallet_no', null);
|
||||
$set('scan_serial_no', null);
|
||||
$set('rework_type', null);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('plant', null);
|
||||
$set('invoice_number', null);
|
||||
$set('scan_pallet_no', null);
|
||||
@@ -128,8 +124,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$set('invoice_number', null);
|
||||
$set('scan_pallet_no', null);
|
||||
$set('scan_serial_no', null);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$set('reworkType', null);
|
||||
$set('invoice_number', null);
|
||||
$set('scan_pallet_no', null);
|
||||
@@ -163,16 +158,14 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
->count();
|
||||
|
||||
$isScanningComplete = true;
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
foreach ($rows as $row) {
|
||||
if ($row->scanned_status != 'Scanned') {
|
||||
$isScanningComplete = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$isScanningComplete)
|
||||
{
|
||||
if (! $isScanningComplete) {
|
||||
Notification::make()
|
||||
->title("Scanned invoice number: '$invoiceNumber' does not completed the scanning process!<br>Has '$notCompletedCount' pending serial number to scan!<br>Please, scan the valid completed invoice number to proceed...")
|
||||
->danger()
|
||||
@@ -181,6 +174,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
|
||||
$set('invoice_number', null);
|
||||
$set('update_invoice', null);
|
||||
|
||||
return;
|
||||
}
|
||||
}),
|
||||
@@ -198,15 +192,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$serialNo = trim($get('scan_serial_no'));
|
||||
$updatePalletStatus = $get('update_pallet') ?? null;
|
||||
|
||||
if ($updatePalletStatus == 0)
|
||||
{
|
||||
if ($updatePalletStatus == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (strlen($palletNumber) < 10)
|
||||
{
|
||||
if (strlen($palletNumber) < 10) {
|
||||
Notification::make()
|
||||
->title("Invalid: Pallet Number")
|
||||
->title('Invalid: Pallet Number')
|
||||
->body("Pallet number '$palletNumber' must be at least 10 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
@@ -216,13 +208,13 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$set('scan_serial_no', null);
|
||||
$set('scan_pallet_no', null);
|
||||
$set('update_pallet', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$PalletSerialNumbers = PalletValidation::where('plant_id', $plantId)->where('pallet_number', $palletNumber)->first();
|
||||
|
||||
if (!$PalletSerialNumbers)
|
||||
{
|
||||
if (! $PalletSerialNumbers) {
|
||||
Notification::make()
|
||||
->title('Pallet Not Found')
|
||||
->body("Pallet number '$palletNumber' doesn't exist in pallet table!<br><br>Scan the valid exist 'Pallet Number' to proceed..!")
|
||||
@@ -234,6 +226,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$set('scan_serial_no', null);
|
||||
$set('scan_pallet_no', null);
|
||||
$set('update_pallet', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -242,8 +235,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
->get();
|
||||
|
||||
$isScanningComplete = true;
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
foreach ($rows as $row) {
|
||||
if ($row->pallet_status != 'Completed') {
|
||||
$isScanningComplete = false;
|
||||
break;
|
||||
@@ -254,8 +246,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$isScanningComplete = false;
|
||||
}
|
||||
|
||||
if (!$isScanningComplete)
|
||||
{
|
||||
if (! $isScanningComplete) {
|
||||
Notification::make()
|
||||
->title('Pallet Not Completed')
|
||||
->body("Scanned pallet number '$palletNumber' doesn't completed the master packing!<br><br>Please, scan the valid completed pallet number to proceed..!")
|
||||
@@ -267,13 +258,11 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$set('scan_serial_no', null);
|
||||
$set('scan_pallet_no', null);
|
||||
$set('update_pallet', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$locatExist = ($PalletSerialNumbers->locator_number != null && $PalletSerialNumbers->locator_number != '') ? $PalletSerialNumbers->locator_number : '';
|
||||
if ($locatExist)
|
||||
{
|
||||
if ($locatExist) {
|
||||
Notification::make()
|
||||
->title('Locator Pallet Found')
|
||||
->body("Scanned pallet number '$palletNumber' exist in locator number '$locatExist'.<br><br>Remove scanned 'Pallet' from 'Locator' to proceed re-master packing..!")
|
||||
@@ -285,14 +274,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$set('scan_serial_no', null);
|
||||
$set('scan_pallet_no', null);
|
||||
$set('update_pallet', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20))
|
||||
{
|
||||
} else {
|
||||
if (strlen($serialNo) > 0 && (strlen($serialNo) < 9 || strlen($serialNo) > 20)) {
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Serial number '$serialNo' should contain minimum 9 digits and maximum 20 digits.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
@@ -301,12 +288,11 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet');
|
||||
$set('scan_serial_no', null);
|
||||
$set('update_pallet', null);
|
||||
|
||||
return;
|
||||
}
|
||||
else if (strlen($serialNo) > 0 && !ctype_alnum($serialNo))
|
||||
{
|
||||
} elseif (strlen($serialNo) > 0 && ! ctype_alnum($serialNo)) {
|
||||
Notification::make()
|
||||
->title("Invalid: Serial Number")
|
||||
->title('Invalid: Serial Number')
|
||||
->body("Serial number '$serialNo' must contain alpha-numeric values only.")
|
||||
->danger()
|
||||
->duration(5000)
|
||||
@@ -315,13 +301,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$livewire->dispatch('loadData', '', $palletNumber, $plantId, 'pallet');
|
||||
$set('scan_serial_no', null);
|
||||
$set('update_pallet', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($updatePalletStatus == 1)
|
||||
{
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
if ($updatePalletStatus == 1) {
|
||||
foreach ($rows as $row) {
|
||||
$row->forceDelete(); // Delete the row from the original table
|
||||
}
|
||||
|
||||
@@ -336,6 +321,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$set('scan_serial_no', null);
|
||||
$set('scan_pallet_no', null);
|
||||
$set('update_pallet', null);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -349,7 +335,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
->hidden()
|
||||
->readOnly(),
|
||||
])
|
||||
->columns(5)
|
||||
->columns(5),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -364,6 +350,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
$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')
|
||||
@@ -455,9 +442,6 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
return Filament::auth()->user()->can('view export rework invoice validation');
|
||||
}),
|
||||
])
|
||||
// ->filters([
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
@@ -471,6 +455,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -494,6 +479,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('invoice_number')
|
||||
->where('invoice_number', '!=', '')
|
||||
@@ -515,6 +501,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('pallet_number')
|
||||
->where('pallet_number', '!=', '')
|
||||
@@ -533,6 +520,7 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return ReworkLocatorInvoiceValidation::where('plant_id', $plantId)
|
||||
->whereNotNull('locator_number')
|
||||
->where('locator_number', '!=', '')
|
||||
@@ -571,6 +559,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
@@ -610,6 +604,12 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
@@ -643,8 +643,9 @@ class ReworkLocatorInvoiceValidationResource extends Resource
|
||||
if (! empty($data['rework_by'])) {
|
||||
$indicators[] = 'Reworked By: '.$data['rework_by'];
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
@@ -4,40 +4,41 @@ namespace App\Filament\Resources;
|
||||
|
||||
use App\Filament\Exports\SerialValidationExporter;
|
||||
use App\Filament\Resources\SerialValidationResource\Pages;
|
||||
use App\Filament\Resources\SerialValidationResource\RelationManagers;
|
||||
use App\Models\Item;
|
||||
use App\Models\Plant;
|
||||
use App\Models\SerialValidation;
|
||||
use App\Models\StickerMaster;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\FileUpload;
|
||||
use Filament\Forms\Components\Radio;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\ToggleButtons;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Str;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
|
||||
class SerialValidationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = SerialValidation::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-rectangle-stack';
|
||||
|
||||
protected static ?string $navigationGroup = 'Serial Validation';
|
||||
|
||||
public $invoiceNumber;
|
||||
|
||||
public static function form(Form $form): Form
|
||||
@@ -53,6 +54,7 @@ class SerialValidationResource extends Resource
|
||||
->columnSpan(1)
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -70,10 +72,9 @@ class SerialValidationResource extends Resource
|
||||
$set('total_quantity', null);
|
||||
$set('scanned_quantity', null);
|
||||
$set('ivPlantError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('ivPlantError', null);
|
||||
}
|
||||
})
|
||||
@@ -115,12 +116,58 @@ class SerialValidationResource extends Resource
|
||||
'id' => 'serial_number_input',
|
||||
'x-data' => '{ value: "" }',
|
||||
'x-model' => 'value',
|
||||
'wire:keydown.enter.prevent' => 'processSerialNumber(value)', // Using wire:keydown
|
||||
// 'x-data' => '{}',
|
||||
// 'x-on:keydown.enter.prevent' => "
|
||||
// let v = (\$event.target.value || '').replace(/[\\r\\n\\s]+$/g, '').trim().toLowerCase();
|
||||
|
||||
// if (!v.endsWith('/c')) {
|
||||
// \$wire.processSerialNumber(v);
|
||||
// }
|
||||
// ",
|
||||
// 'wire:keydown.enter.prevent' => 'processSerialNumber(value)', // Using wire:keydown
|
||||
'x-on:keydown.enter.prevent' => "
|
||||
let serial = \$event.target.value;
|
||||
if (serial.trim() != '') {
|
||||
\$wire.dispatch('process-scan', serial);
|
||||
}
|
||||
",
|
||||
])
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get, $livewire) {
|
||||
$set('update_invoice', 0);
|
||||
// if (str_ends_with(strtolower($state), '/c')) {
|
||||
// $livewire->dispatch('focus-capacitor');
|
||||
// }
|
||||
})
|
||||
->columnSpan(1),
|
||||
|
||||
Forms\Components\TextInput::make('capacitor')
|
||||
->label('Capacitor')
|
||||
->reactive()
|
||||
// ->hidden(fn (callable $get) => !str_ends_with(strtolower($get('serial_number')), '/c'))
|
||||
->visible(fn (callable $get) => str_ends_with(strtolower($get('serial_number')), '/c')
|
||||
)
|
||||
->extraAttributes([
|
||||
'id' => 'focus-capacitor-input',
|
||||
'x-data' => "{
|
||||
getItemCode() {
|
||||
return this.\$el.dataset.itemCode || '';
|
||||
}
|
||||
}",
|
||||
'x-init' => '
|
||||
// Nothing needed here now, listener runs globally
|
||||
',
|
||||
// Trigger processing with Enter key
|
||||
'x-on:keydown.enter.prevent' => "
|
||||
\$wire.processCapacitor(
|
||||
\$el.querySelector('input').value,
|
||||
getItemCode()
|
||||
)
|
||||
",
|
||||
// 'x-on:keydown.enter.prevent' => 'processCapacitor(value)',
|
||||
])
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
$set('update_invoice', 0);
|
||||
// $this->dispatch('focus-serial-number');
|
||||
// if (!$invNo) { return; } else { }
|
||||
$get('serial_number');
|
||||
|
||||
})
|
||||
->columnSpan(1),
|
||||
Forms\Components\TextInput::make('total_quantity')
|
||||
@@ -138,18 +185,17 @@ class SerialValidationResource extends Resource
|
||||
->reactive()
|
||||
->hidden(fn (callable $get) => ($get('invoice_number') == null || $get('update_invoice') == '0') || ! empty($get('serial_number')))
|
||||
->afterStateUpdated(function ($state, callable $set, callable $get) {
|
||||
if (!$get('plant_id'))
|
||||
{
|
||||
if (! $get('plant_id')) {
|
||||
$set('update_invoice', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($get('update_invoice') == "1")
|
||||
{
|
||||
if ($get('update_invoice') == '1') {
|
||||
$totQuan = SerialValidation::where('invoice_number', $get('invoice_number'))->where('plant_id', $get('plant_id'))->count();
|
||||
if ($totQuan <= 0)
|
||||
{
|
||||
if ($totQuan <= 0) {
|
||||
$set('update_invoice', null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -157,19 +203,16 @@ class SerialValidationResource extends Resource
|
||||
$scanMQuan = SerialValidation::where('invoice_number', $get('invoice_number'))->whereNotNull('serial_number')->where('serial_number', '!=', '')->where('plant_id', $get('plant_id'))->count();
|
||||
$scanSQuan = SerialValidation::where('invoice_number', $get('invoice_number'))->where('scanned_status', 'Scanned')->where('plant_id', $get('plant_id'))->count();
|
||||
|
||||
if ($totMQuan > 0)
|
||||
{
|
||||
if ($totQuan == $scanMQuan)
|
||||
{
|
||||
if ($totMQuan > 0) {
|
||||
if ($totQuan == $scanMQuan) {
|
||||
$set('update_invoice', null);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($totQuan == $scanSQuan)
|
||||
{
|
||||
} else {
|
||||
if ($totQuan == $scanSQuan) {
|
||||
$set('update_invoice', null);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -194,6 +237,7 @@ class SerialValidationResource extends Resource
|
||||
$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('invoice_number')
|
||||
@@ -287,6 +331,7 @@ class SerialValidationResource extends Resource
|
||||
// ->options(Plant::pluck('name', 'id')->toArray()) // Fetch plant names and IDs
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->label('Select Plant')
|
||||
@@ -330,42 +375,37 @@ class SerialValidationResource extends Resource
|
||||
// /home/iot-dev/projects/pds/storage/app/private/uploads/temp/3RA0018735.xlsx
|
||||
|
||||
$totQuan = SerialValidation::where('invoice_number', $originalNameOnly)->count();
|
||||
if ($totQuan > 0)
|
||||
{
|
||||
if ($totQuan > 0) {
|
||||
$scanSQuan = SerialValidation::where('invoice_number', $originalNameOnly)->where('scanned_status', 'Scanned')->count();
|
||||
if ($totQuan == $scanSQuan)
|
||||
{
|
||||
if ($totQuan == $scanSQuan) {
|
||||
$invoiceFirst = SerialValidation::with('plant')->where('invoice_number', $originalNameOnly)->first();
|
||||
$plantName = $invoiceFirst ? (String)$invoiceFirst->plant->name : null;
|
||||
$plantName = $invoiceFirst ? (string) $invoiceFirst->plant->name : null;
|
||||
|
||||
Notification::make()
|
||||
->title("Serial invoice number : '$originalNameOnly' already completed the scanning process for plant : '$plantName'.")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$invoiceFirst = SerialValidation::with('plant')->where('invoice_number', $originalNameOnly)->first();
|
||||
// $plantCode = $invoiceFirst ? (String)$invoiceFirst->plant->code : null;
|
||||
$plantName = $invoiceFirst ? (String)$invoiceFirst->plant->name : null;
|
||||
$plantName = $invoiceFirst ? (string) $invoiceFirst->plant->name : null;
|
||||
$invoicePlantId = $invoiceFirst->plant_id;
|
||||
if ($plantId != $invoicePlantId)
|
||||
{
|
||||
if ($plantId != $invoicePlantId) {
|
||||
Notification::make()
|
||||
->title("Serial invoice number : '$originalNameOnly' already exists for plant : '$plantName'.<br>Choose the valid 'Plant' to proceed!")
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -374,26 +414,23 @@ class SerialValidationResource extends Resource
|
||||
$totQuan = SerialValidation::where('invoice_number', $originalNameOnly)->where('plant_id', $plantId)->count();
|
||||
$scanSQuan = SerialValidation::where('invoice_number', $originalNameOnly)->where('scanned_status', 'Scanned')->where('plant_id', $plantId)->count();
|
||||
|
||||
if ($totQuan > 0 && $totQuan == $scanSQuan)
|
||||
{
|
||||
if ($totQuan > 0 && $totQuan == $scanSQuan) {
|
||||
Notification::make()
|
||||
->title('Serial invoice already completed the scanning process for selected plant.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($fullPath && file_exists($fullPath))
|
||||
{
|
||||
if ($fullPath && file_exists($fullPath)) {
|
||||
$rows = Excel::toArray(null, $fullPath)[0];
|
||||
|
||||
if ((count($rows) - 1) <= 0)
|
||||
{
|
||||
if ((count($rows) - 1) <= 0) {
|
||||
Notification::make()
|
||||
->title('Records Not Found')
|
||||
->body("Import the valid 'Serial Invoice' file to proceed..!")
|
||||
@@ -403,6 +440,7 @@ class SerialValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -414,9 +452,10 @@ class SerialValidationResource extends Resource
|
||||
$seenSerialNumbers = [];
|
||||
$validRowsFound = false;
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index == 0) continue; // Skip header
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index == 0) {
|
||||
continue;
|
||||
} // Skip header
|
||||
|
||||
$materialCode = trim($row[0]);
|
||||
$serialNumber = trim($row[1]);
|
||||
@@ -425,24 +464,16 @@ class SerialValidationResource extends Resource
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!empty($materialCode))
|
||||
{
|
||||
if (Str::length($materialCode) < 6 || !ctype_alnum($materialCode))
|
||||
{
|
||||
if (! empty($materialCode)) {
|
||||
if (Str::length($materialCode) < 6 || ! ctype_alnum($materialCode)) {
|
||||
$invalidMatCodes[] = $materialCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (empty($serialNumber)) {
|
||||
$missingSerials[] = $materialCode;
|
||||
|
||||
}
|
||||
else if (Str::length($serialNumber) < 9 || !ctype_alnum($serialNumber))
|
||||
{
|
||||
} elseif (Str::length($serialNumber) < 9 || ! ctype_alnum($serialNumber)) {
|
||||
$invalidSerialCodes[] = $serialNumber;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if (in_array($serialNumber, $seenSerialNumbers)) {
|
||||
$duplicateSerials[] = $serialNumber;
|
||||
} else {
|
||||
@@ -452,9 +483,7 @@ class SerialValidationResource extends Resource
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -476,9 +505,9 @@ class SerialValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (!empty($uniqueMissingSerials)) {
|
||||
} elseif (! empty($uniqueMissingSerials)) {
|
||||
Notification::make()
|
||||
->title('Missing Serial Numbers')
|
||||
->body("The following item codes doesn't have valid serial number:<br>".implode(', ', $uniqueMissingSerials))
|
||||
@@ -487,9 +516,9 @@ class SerialValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (!empty($uniqueSerialCodes)) {
|
||||
} elseif (! empty($uniqueSerialCodes)) {
|
||||
Notification::make()
|
||||
->title('Invalid Serial Number')
|
||||
->body('The following serial numbers should contain minimum 9 digit alpha numeric values:<br>'.implode(', ', $uniqueSerialCodes))
|
||||
@@ -498,9 +527,9 @@ class SerialValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (!empty($duplicateSerialCodes)) {
|
||||
} elseif (! empty($duplicateSerialCodes)) {
|
||||
Notification::make()
|
||||
->title('Duplicate Serial Numbers')
|
||||
->body('The following serial numbers are already exist in imported excel:<br>'.implode(', ', $duplicateSerialCodes))
|
||||
@@ -509,6 +538,7 @@ class SerialValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -521,6 +551,7 @@ class SerialValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -536,8 +567,7 @@ class SerialValidationResource extends Resource
|
||||
|
||||
$missingCodes = array_diff($uniqueCodes, $matchedCodes);
|
||||
|
||||
if (!empty($missingCodes))
|
||||
{
|
||||
if (! empty($missingCodes)) {
|
||||
$missingCount = count($missingCodes);
|
||||
|
||||
$message = $missingCount > 10 ? "'$missingCount' item codes are not found in database." : 'The following item codes are not found in database:<br>'.implode(', ', $missingCodes);
|
||||
@@ -551,6 +581,7 @@ class SerialValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -560,8 +591,7 @@ class SerialValidationResource extends Resource
|
||||
->pluck('item.code')
|
||||
->toArray();
|
||||
|
||||
if (count($invalidCodes) > 10)
|
||||
{
|
||||
if (count($invalidCodes) > 10) {
|
||||
Notification::make()
|
||||
->title('Invalid item codes found')
|
||||
->body(''.count($invalidCodes).'item codes found have material type.')
|
||||
@@ -571,10 +601,9 @@ class SerialValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else if (count($invalidCodes) > 0)
|
||||
{
|
||||
} elseif (count($invalidCodes) > 0) {
|
||||
Notification::make()
|
||||
->title('Invalid item codes found')
|
||||
->body('Material invoice Item Codes found : '.implode(', ', $invalidCodes))
|
||||
@@ -584,10 +613,9 @@ class SerialValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Save full file path to session
|
||||
session(['uploaded_invoice_path' => $fullPath]);
|
||||
Notification::make()
|
||||
@@ -921,7 +949,6 @@ class SerialValidationResource extends Resource
|
||||
// $excelCode = trim($row[0]);
|
||||
// $excelMatQty = trim($row[1]);
|
||||
|
||||
|
||||
// if ($excelCode == $code && is_numeric($excelMatQty)) {
|
||||
// $totalExcelQty += $excelMatQty; // Sum up the quantities
|
||||
// }
|
||||
@@ -988,9 +1015,6 @@ class SerialValidationResource extends Resource
|
||||
return Filament::auth()->user()->can('view export serial validation invoice');
|
||||
}),
|
||||
])
|
||||
// ->filters([
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
@@ -1000,7 +1024,7 @@ class SerialValidationResource extends Resource
|
||||
->label('Type ?')
|
||||
->boolean()
|
||||
->options([
|
||||
'Serial' => 'Serial'
|
||||
'Serial' => 'Serial',
|
||||
])
|
||||
->default('Serial')
|
||||
->inlineLabel(false)
|
||||
@@ -1013,6 +1037,7 @@ class SerialValidationResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive()
|
||||
@@ -1032,6 +1057,7 @@ class SerialValidationResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$pId = $get('Plant');
|
||||
|
||||
// if (empty($pId)) {
|
||||
// return [];
|
||||
// }
|
||||
@@ -1058,12 +1084,9 @@ class SerialValidationResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId)
|
||||
{
|
||||
if (! $plantId) {
|
||||
return SerialValidation::whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return SerialValidation::where('plant_id', $plantId)->whereNotNull('operator_id')->select('operator_id')->distinct()->pluck('operator_id', 'operator_id');
|
||||
}
|
||||
})
|
||||
@@ -1083,13 +1106,13 @@ class SerialValidationResource extends Resource
|
||||
->query(function ($query, array $data) {
|
||||
// Hide all records initially if no filters are applied
|
||||
if (empty($data['invoice_type']) || (empty($data['Plant']) && empty($data['invoice_number']) && empty($data['serial_number']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['operator_id']) && empty($data['scanned_status']) && empty($data['sticker_master_id']))) {
|
||||
if (empty($data['invoice_type']))
|
||||
{
|
||||
if (empty($data['invoice_type'])) {
|
||||
Notification::make()
|
||||
->title('Please, choose invoice type to filter.')
|
||||
->danger()
|
||||
->send();
|
||||
}
|
||||
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
|
||||
@@ -1101,7 +1124,7 @@ class SerialValidationResource extends Resource
|
||||
$query->whereNotNull('scanned_status')->where('scanned_status', '!=', '');
|
||||
} elseif ($data['scanned_status'] == 'Pending') {
|
||||
// $query->whereNull('scanned_status')->orWhere('scanned_status', '');
|
||||
$query->where(function ($query) use ($data) {
|
||||
$query->where(function ($query) {
|
||||
// if (empty($data['scanned_status']) || $data['scanned_status'] == 'Pending') {
|
||||
$query->whereNull('scanned_status')->orWhere('scanned_status', '!=', 'Scanned');
|
||||
// }
|
||||
@@ -1115,7 +1138,7 @@ class SerialValidationResource extends Resource
|
||||
if ($data['scanned_status'] == 'Scanned') {
|
||||
$query->whereNotNull('serial_number')->where('serial_number', '!=', '');
|
||||
} elseif ($data['scanned_status'] == 'Pending') {
|
||||
$query->where(function ($query) use ($data) {
|
||||
$query->where(function ($query) {
|
||||
$query->whereNull('serial_number')->orWhere('serial_number', '=', '');
|
||||
});
|
||||
}
|
||||
@@ -1124,6 +1147,12 @@ class SerialValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) { // $plant = $data['Plant'] ?? null
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
@@ -1161,6 +1190,12 @@ class SerialValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['invoice_number'])) {
|
||||
@@ -1193,7 +1228,7 @@ class SerialValidationResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources;
|
||||
|
||||
use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
|
||||
use App\Exports\TestingPanelReadingExport;
|
||||
use App\Exports\MotorFreeRunExport;
|
||||
use App\Filament\Exports\TestingPanelReadingExporter;
|
||||
use App\Filament\Imports\TestingPanelReadingImporter;
|
||||
use App\Filament\Resources\TestingPanelReadingResource\Pages;
|
||||
@@ -23,19 +22,24 @@ use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Notifications\Collection as NotificationsCollection;
|
||||
use Filament\Notifications\Notification;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Actions\BulkAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Response;
|
||||
// use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
// use App\Exports\TestingPanelReadingExport;
|
||||
use PhpOffice\PhpSpreadsheet\IOFactory; // For loading Excel file
|
||||
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
||||
|
||||
class TestingPanelReadingResource extends Resource
|
||||
{
|
||||
@@ -58,6 +62,7 @@ class TestingPanelReadingResource extends Resource
|
||||
->reactive()
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
@@ -71,10 +76,9 @@ class TestingPanelReadingResource extends Resource
|
||||
$set('item_id', null);
|
||||
$set('machine_id', null);
|
||||
$set('tPrError', 'Please select a plant first.');
|
||||
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$set('line_id', null);
|
||||
$set('item_id', null);
|
||||
$set('machine_id', null);
|
||||
@@ -94,6 +98,7 @@ class TestingPanelReadingResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Line::where('plant_id', $plantId)
|
||||
->pluck('name', 'id')
|
||||
->toArray();
|
||||
@@ -113,6 +118,7 @@ class TestingPanelReadingResource extends Resource
|
||||
if (! $lineId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Only show machines for the selected line
|
||||
return Machine::where('line_id', $lineId)
|
||||
->pluck('name', 'id')
|
||||
@@ -144,6 +150,7 @@ class TestingPanelReadingResource extends Resource
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return MotorTestingMaster::query()
|
||||
->join('items', 'motor_testing_masters.item_id', '=', 'items.id')
|
||||
->where('motor_testing_masters.plant_id', $plantId)
|
||||
@@ -259,6 +266,7 @@ class TestingPanelReadingResource extends Resource
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
|
||||
return $table
|
||||
->columns([
|
||||
// Tables\Columns\TextColumn::make('id')
|
||||
@@ -271,6 +279,7 @@ class TestingPanelReadingResource extends Resource
|
||||
$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')
|
||||
@@ -463,7 +472,6 @@ class TestingPanelReadingResource extends Resource
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
->filters([
|
||||
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
->label('Advanced Filters')
|
||||
@@ -485,8 +493,7 @@ class TestingPanelReadingResource extends Resource
|
||||
->nullable()
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (!$plantId)
|
||||
{
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -509,9 +516,7 @@ class TestingPanelReadingResource extends Resource
|
||||
->whereHas('motorTestingMasters')
|
||||
->pluck('code', 'id')
|
||||
->toArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return Item::whereHas('motorTestingMasters')
|
||||
->pluck('code', 'id')
|
||||
->toArray();
|
||||
@@ -528,6 +533,7 @@ class TestingPanelReadingResource extends Resource
|
||||
if (! $plantId || ! $lineId) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return Machine::where('plant_id', $plantId)
|
||||
->where('line_id', $lineId)
|
||||
->pluck('name', 'id')
|
||||
@@ -548,6 +554,7 @@ class TestingPanelReadingResource extends Resource
|
||||
if ($plantId) {
|
||||
$query->where('plant_id', $plantId);
|
||||
}
|
||||
|
||||
return $query->pluck('description', 'description')->toArray();
|
||||
|
||||
})
|
||||
@@ -602,16 +609,13 @@ class TestingPanelReadingResource extends Resource
|
||||
->default('Star')
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if ($plantId)
|
||||
{
|
||||
if ($plantId) {
|
||||
return Configuration::where('plant_id', $plantId)
|
||||
->where('c_name', 'MOTOR_CONNECTION')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
->toArray();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return Configuration::where('c_name', 'MOTOR_CONNECTION')
|
||||
->orderBy('created_at')
|
||||
->pluck('c_value', 'c_value')
|
||||
@@ -667,6 +671,12 @@ class TestingPanelReadingResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Line'])) {
|
||||
@@ -700,8 +710,7 @@ class TestingPanelReadingResource extends Resource
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($data['output']))
|
||||
{
|
||||
if (! empty($data['output'])) {
|
||||
$query->where('output', $data['output']);
|
||||
}
|
||||
|
||||
@@ -713,37 +722,30 @@ class TestingPanelReadingResource extends Resource
|
||||
// });
|
||||
// }
|
||||
|
||||
if (!empty($data['connection']))
|
||||
{
|
||||
if (! empty($data['connection'])) {
|
||||
// $query->where('connection',$data['connection']);
|
||||
$query->whereHas('motorTestingMaster', function ($subQuery) use ($data) {
|
||||
$subQuery->where('connection', $data['connection']);
|
||||
});
|
||||
}
|
||||
|
||||
if (!empty($data['remark']))
|
||||
{
|
||||
if (! empty($data['remark'])) {
|
||||
$query->where('remark', $data['remark']);
|
||||
}
|
||||
|
||||
if (!empty($data['batch_number']))
|
||||
{
|
||||
if (! empty($data['batch_number'])) {
|
||||
$query->where('batch_number', $data['batch_number']);
|
||||
}
|
||||
|
||||
if (!empty($data['result']))
|
||||
{
|
||||
if (! empty($data['result'])) {
|
||||
$query->where('result', $data['result']);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($data['created_from']))
|
||||
{
|
||||
if (! empty($data['created_from'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
|
||||
if (!empty($data['created_to']))
|
||||
{
|
||||
if (! empty($data['created_to'])) {
|
||||
$query->where('created_at', '<=', $data['created_to']);
|
||||
}
|
||||
})
|
||||
@@ -752,6 +754,12 @@ class TestingPanelReadingResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
if (! empty($data['Line'])) {
|
||||
$indicators[] = 'Line: '.Line::where('id', $data['Line'])->value('name');
|
||||
@@ -780,8 +788,7 @@ class TestingPanelReadingResource extends Resource
|
||||
if (! empty($data['batch_number'])) {
|
||||
$indicators[] = 'Batch Number: '.$data['batch_number'];
|
||||
}
|
||||
if (!empty($data['result']))
|
||||
{
|
||||
if (! empty($data['result'])) {
|
||||
$indicators[] = 'Result: '.$data['result'];
|
||||
}
|
||||
|
||||
@@ -798,7 +805,7 @@ class TestingPanelReadingResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -810,168 +817,355 @@ class TestingPanelReadingResource extends Resource
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||
Tables\Actions\RestoreBulkAction::make(),
|
||||
|
||||
// BulkAction::make('exportExcel')
|
||||
// ->label('Export Selected to Excel')
|
||||
// ->icon('heroicon-o-document-arrow-down')
|
||||
// ->action(function (Collection $records) {
|
||||
// return Excel::download(
|
||||
// new MotorFreeRunExport($records),
|
||||
// 'Motor_Free_Run_Register.xlsx'
|
||||
// );
|
||||
// }),
|
||||
|
||||
BulkAction::make('export_pdf')
|
||||
->label('Export Readings PDF')
|
||||
->action(function ($records)
|
||||
{
|
||||
//$records->load('item');
|
||||
$records->load('motorTestingMaster.item');
|
||||
$plantId = $records->first()?->plant_id;
|
||||
|
||||
$plant = $plantId ? Plant::find($plantId) : null;
|
||||
|
||||
// Check if all records are Star-Delta type
|
||||
$isAllStarDelta = $records->every(function ($record) {
|
||||
return $record->motorTestingMaster?->connection === 'Star-Delta';
|
||||
});
|
||||
// $hasStarDelta = $records->contains(function ($record) {
|
||||
// return $record->motorTestingMaster?->connection === 'Star-Delta';
|
||||
// });
|
||||
|
||||
|
||||
//dd($isAllStarDelta);
|
||||
if(!$isAllStarDelta)
|
||||
{
|
||||
$mappedData = collect($records)->map(function ($record) {
|
||||
return [
|
||||
// 'Date' => $record['created_at'] ?? '',
|
||||
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||
'Output' => $record['output'] ?? '',
|
||||
'Motor SNo' => $record['serial_number'] ?? '',
|
||||
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||
'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||
|
||||
'kw' => $record->motorTestingMaster->kw ?? '',
|
||||
'hp' => $record->motorTestingMaster->hp ?? '',
|
||||
'phase' => $record->motorTestingMaster->phase ?? '',
|
||||
'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||
|
||||
// BEFORE FREE RUN
|
||||
'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||
'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||
'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||
'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||
'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||
'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||
'Insulation_Resistance' => $record['before_fr_ir'] ?? '',
|
||||
'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||
'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||
|
||||
// AFTER FREE RUN
|
||||
'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||
'Current_After' => $record['after_fr_cur'] ?? '',
|
||||
'Power_After' => $record['after_fr_pow'] ?? '',
|
||||
'IR_Hot' => $record['after_fr_ir_hot'] ?? '',
|
||||
'IR_Cool' => $record['after_fr_ir_cool'] ?? '',
|
||||
'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||
'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||
'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||
|
||||
// LOCKED ROTOR TEST
|
||||
'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||
'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||
'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||
|
||||
// Last 8 columns
|
||||
'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||
'Room_Temp' => $record['room_temperature'] ?? '',
|
||||
'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||
'Batch_Number' => $record['batch_number'] ?? '',
|
||||
'Batch_Count' => $record['batch_count'] ?? '',
|
||||
'Result' => $record['result'] ?? '',
|
||||
'Remark' => $record['remark'] ?? '',
|
||||
'Tested_By' => $record['tested_by'] ?? '',
|
||||
];
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
$mappedData = collect($records)->map(function ($record) {
|
||||
return [
|
||||
//'Date' => $record['created_at'] ?? '',
|
||||
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||
'Output' => $record['output'] ?? '',
|
||||
'Motor SNo' => $record['serial_number'] ?? '',
|
||||
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||
'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||
|
||||
'kw' => $record->motorTestingMaster->kw ?? '',
|
||||
'hp' => $record->motorTestingMaster->hp ?? '',
|
||||
'phase' => $record->motorTestingMaster->phase ?? '',
|
||||
'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||
|
||||
// BEFORE FREE RUN
|
||||
'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||
'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||
'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||
'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||
'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||
'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||
'Insulation_Resistance_R' => $record['before_fr_ir_r'] ?? '',
|
||||
'Insulation_Resistance_Y' => $record['before_fr_ir_y'] ?? '',
|
||||
'Insulation_Resistance_B' => $record['before_fr_ir_b'] ?? '',
|
||||
'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||
'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||
|
||||
// AFTER FREE RUN
|
||||
'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||
'Current_After' => $record['after_fr_cur'] ?? '',
|
||||
'Power_After' => $record['after_fr_pow'] ?? '',
|
||||
'IR_Hot_R' => $record['after_fr_ir_hot_r'] ?? '',
|
||||
'IR_Hot_Y' => $record['after_fr_ir_hot_y'] ?? '',
|
||||
'IR_Hot_B' => $record['after_fr_ir_hot_b'] ?? '',
|
||||
'IR_Cool_R' => $record['after_fr_ir_cool_r'] ?? '',
|
||||
'IR_Cool_Y' => $record['after_fr_ir_cool_y'] ?? '',
|
||||
'IR_Cool_B' => $record['after_fr_ir_cool_b'] ?? '',
|
||||
'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||
'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||
'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||
|
||||
// LOCKED ROTOR TEST
|
||||
'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||
'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||
'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||
|
||||
// Last 8 columns
|
||||
'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||
'Room_Temp' => $record['room_temperature'] ?? '',
|
||||
'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||
'Batch_Number' => $record['batch_number'] ?? '',
|
||||
'Batch_Count' => $record['batch_count'] ?? '',
|
||||
'Result' => $record['result'] ?? '',
|
||||
'Remark' => $record['remark'] ?? '',
|
||||
'Tested_By' => $record['tested_by'] ?? '',
|
||||
];
|
||||
});
|
||||
}
|
||||
|
||||
$view = $isAllStarDelta ? 'exports.export-three-phase-pdf' : 'exports.testingpanel-pdf';
|
||||
|
||||
|
||||
$pdf = Pdf::loadView($view, [
|
||||
'records' => $mappedData,
|
||||
'plant' => $plant,
|
||||
]);
|
||||
|
||||
// $pdf = Pdf::loadView('exports.testingpanel-pdf',[
|
||||
// // ['records' => $mappedData]
|
||||
// 'records' => $mappedData,
|
||||
// 'plant' => $plant,
|
||||
|
||||
// ]);
|
||||
|
||||
return response()->streamDownload(
|
||||
fn () => print($pdf->stream()),
|
||||
'TestingPanelReading.pdf'
|
||||
);
|
||||
->label('Export Selected to Excel')
|
||||
->action(function ($records) {
|
||||
// $ids = $records->pluck('id')->toArray();
|
||||
// $query = TestingPanelReading::whereIn('id', $ids);
|
||||
$templatePath = storage_path('app/private/uploads/temp/MotorTestingPanelReportTemplate.xlsx');
|
||||
|
||||
return Excel::download(new MotorFreeRunExport($records, $templatePath), 'MotorFreeRunData.xlsx');
|
||||
})
|
||||
->icon('heroicon-o-document-arrow-down'),
|
||||
|
||||
// BulkAction::make('export_pdf')
|
||||
// ->label('Export Readings PDF'),
|
||||
// ->action(function ($records)
|
||||
// {
|
||||
// //$records->load('item');
|
||||
// $records->load('motorTestingMaster.item');
|
||||
// $plantId = $records->first()?->plant_id;
|
||||
|
||||
// $plant = $plantId ? Plant::find($plantId) : null;
|
||||
|
||||
// // Check if all records are Star-Delta type
|
||||
// $isAllStarDelta = $records->every(function ($record) {
|
||||
// return $record->motorTestingMaster?->connection === 'Star-Delta';
|
||||
// });
|
||||
// // $hasStarDelta = $records->contains(function ($record) {
|
||||
// // return $record->motorTestingMaster?->connection === 'Star-Delta';
|
||||
// // });
|
||||
|
||||
// //dd($isAllStarDelta);
|
||||
// if(!$isAllStarDelta)
|
||||
// {
|
||||
// $mappedData = collect($records)->map(function ($record) {
|
||||
// return [
|
||||
// // 'Date' => $record['created_at'] ?? '',
|
||||
// 'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||
// 'Output' => $record['output'] ?? '',
|
||||
// 'Motor SNo' => $record['serial_number'] ?? '',
|
||||
// 'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||
// 'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||
|
||||
// 'kw' => $record->motorTestingMaster->kw ?? '',
|
||||
// 'hp' => $record->motorTestingMaster->hp ?? '',
|
||||
// 'phase' => $record->motorTestingMaster->phase ?? '',
|
||||
// 'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||
|
||||
// // BEFORE FREE RUN
|
||||
// 'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||
// 'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||
// 'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||
// 'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||
// 'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||
// 'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||
// 'Insulation_Resistance' => $record['before_fr_ir'] ?? '',
|
||||
// 'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||
// 'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||
|
||||
// // AFTER FREE RUN
|
||||
// 'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||
// 'Current_After' => $record['after_fr_cur'] ?? '',
|
||||
// 'Power_After' => $record['after_fr_pow'] ?? '',
|
||||
// 'IR_Hot' => $record['after_fr_ir_hot'] ?? '',
|
||||
// 'IR_Cool' => $record['after_fr_ir_cool'] ?? '',
|
||||
// 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||
// 'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||
// 'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||
|
||||
// // LOCKED ROTOR TEST
|
||||
// 'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||
// 'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||
// 'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||
|
||||
// // Last 8 columns
|
||||
// 'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||
// 'Room_Temp' => $record['room_temperature'] ?? '',
|
||||
// 'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||
// 'Batch_Number' => $record['batch_number'] ?? '',
|
||||
// 'Batch_Count' => $record['batch_count'] ?? '',
|
||||
// 'Result' => $record['result'] ?? '',
|
||||
// 'Remark' => $record['remark'] ?? '',
|
||||
// 'Tested_By' => $record['tested_by'] ?? '',
|
||||
// ];
|
||||
// });
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
|
||||
// $mappedData = collect($records)->map(function ($record) {
|
||||
// return [
|
||||
// //'Date' => $record['created_at'] ?? '',
|
||||
// 'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||
// 'Output' => $record['output'] ?? '',
|
||||
// 'Motor SNo' => $record['serial_number'] ?? '',
|
||||
// 'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||
// 'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||
|
||||
// 'kw' => $record->motorTestingMaster->kw ?? '',
|
||||
// 'hp' => $record->motorTestingMaster->hp ?? '',
|
||||
// 'phase' => $record->motorTestingMaster->phase ?? '',
|
||||
// 'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||
|
||||
// // BEFORE FREE RUN
|
||||
// 'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||
// 'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||
// 'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||
// 'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||
// 'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||
// 'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||
// 'Insulation_Resistance_R' => $record['before_fr_ir_r'] ?? '',
|
||||
// 'Insulation_Resistance_Y' => $record['before_fr_ir_y'] ?? '',
|
||||
// 'Insulation_Resistance_B' => $record['before_fr_ir_b'] ?? '',
|
||||
// 'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||
// 'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||
|
||||
// // AFTER FREE RUN
|
||||
// 'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||
// 'Current_After' => $record['after_fr_cur'] ?? '',
|
||||
// 'Power_After' => $record['after_fr_pow'] ?? '',
|
||||
// 'IR_Hot_R' => $record['after_fr_ir_hot_r'] ?? '',
|
||||
// 'IR_Hot_Y' => $record['after_fr_ir_hot_y'] ?? '',
|
||||
// 'IR_Hot_B' => $record['after_fr_ir_hot_b'] ?? '',
|
||||
// 'IR_Cool_R' => $record['after_fr_ir_cool_r'] ?? '',
|
||||
// 'IR_Cool_Y' => $record['after_fr_ir_cool_y'] ?? '',
|
||||
// 'IR_Cool_B' => $record['after_fr_ir_cool_b'] ?? '',
|
||||
// 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||
// 'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||
// 'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||
|
||||
// // LOCKED ROTOR TEST
|
||||
// 'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||
// 'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||
// 'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||
|
||||
// // Last 8 columns
|
||||
// 'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||
// 'Room_Temp' => $record['room_temperature'] ?? '',
|
||||
// 'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||
// 'Batch_Number' => $record['batch_number'] ?? '',
|
||||
// 'Batch_Count' => $record['batch_count'] ?? '',
|
||||
// 'Result' => $record['result'] ?? '',
|
||||
// 'Remark' => $record['remark'] ?? '',
|
||||
// 'Tested_By' => $record['tested_by'] ?? '',
|
||||
// ];
|
||||
// });
|
||||
// }
|
||||
|
||||
// $view = $isAllStarDelta ? 'exports.export-three-phase-pdf' : 'exports.testingpanel-pdf';
|
||||
|
||||
// $pdf = Pdf::loadView($view, [
|
||||
// 'records' => $mappedData,
|
||||
// 'plant' => $plant,
|
||||
// ]);
|
||||
|
||||
// // $pdf = Pdf::loadView('exports.testingpanel-pdf',[
|
||||
// // // ['records' => $mappedData]
|
||||
// // 'records' => $mappedData,
|
||||
// // 'plant' => $plant,
|
||||
|
||||
// // ]);
|
||||
|
||||
// return response()->streamDownload(
|
||||
// fn () => print($pdf->stream()),
|
||||
// 'TestingPanelReading.pdf'
|
||||
// );
|
||||
// // return $pdf->download('TestingPanelReading.pdf');
|
||||
// })
|
||||
|
||||
// ->action(function ($records) {
|
||||
|
||||
// // Load related item data
|
||||
// $records->load('motorTestingMaster.item');
|
||||
|
||||
// $plantId = $records->first()?->plant_id;
|
||||
// $plant = $plantId ? Plant::find($plantId) : null;
|
||||
|
||||
// // Check if all records are Star-Delta type
|
||||
// $isAllStarDelta = $records->every(fn($record) => $record->motorTestingMaster?->connection === 'Star-Delta');
|
||||
|
||||
// // Map records for export
|
||||
// $mappedData = $records->map(function ($record) use ($isAllStarDelta) {
|
||||
|
||||
// if (!$isAllStarDelta) {
|
||||
// return [
|
||||
// 'Date' => date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||
// 'Output' => $record['output'] ?? '',
|
||||
// 'Motor SNo' => $record['serial_number'] ?? '',
|
||||
// 'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||
// 'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||
// 'kw' => $record->motorTestingMaster->kw ?? '',
|
||||
// 'hp' => $record->motorTestingMaster->hp ?? '',
|
||||
// 'phase' => $record->motorTestingMaster->phase ?? '',
|
||||
// 'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||
// 'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||
// 'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||
// 'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||
// 'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||
// 'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||
// 'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||
// 'Insulation_Resistance' => $record['before_fr_ir'] ?? '',
|
||||
// 'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||
// 'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||
// 'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||
// 'Current_After' => $record['after_fr_cur'] ?? '',
|
||||
// 'Power_After' => $record['after_fr_pow'] ?? '',
|
||||
// 'IR_Hot' => $record['after_fr_ir_hot'] ?? '',
|
||||
// 'IR_Cool' => $record['after_fr_ir_cool'] ?? '',
|
||||
// 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||
// 'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||
// 'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||
// 'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||
// 'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||
// 'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||
// 'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||
// 'Room_Temp' => $record['room_temperature'] ?? '',
|
||||
// 'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||
// 'Batch_Number' => $record['batch_number'] ?? '',
|
||||
// 'Batch_Count' => $record['batch_count'] ?? '',
|
||||
// 'Result' => $record['result'] ?? '',
|
||||
// 'Remark' => $record['remark'] ?? '',
|
||||
// 'Tested_By' => $record['tested_by'] ?? '',
|
||||
// ];
|
||||
// } else {
|
||||
// // Star-Delta records
|
||||
// return [
|
||||
// 'Date' => date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||
// 'Output' => $record['output'] ?? '',
|
||||
// 'Motor SNo' => $record['serial_number'] ?? '',
|
||||
// 'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||
// 'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||
// 'kw' => $record->motorTestingMaster->kw ?? '',
|
||||
// 'hp' => $record->motorTestingMaster->hp ?? '',
|
||||
// 'phase' => $record->motorTestingMaster->phase ?? '',
|
||||
// 'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||
// 'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||
// 'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||
// 'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||
// 'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||
// 'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||
// 'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||
// 'Insulation_Resistance_R' => $record['before_fr_ir_r'] ?? '',
|
||||
// 'Insulation_Resistance_Y' => $record['before_fr_ir_y'] ?? '',
|
||||
// 'Insulation_Resistance_B' => $record['before_fr_ir_b'] ?? '',
|
||||
// 'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||
// 'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||
// 'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||
// 'Current_After' => $record['after_fr_cur'] ?? '',
|
||||
// 'Power_After' => $record['after_fr_pow'] ?? '',
|
||||
// 'IR_Hot_R' => $record['after_fr_ir_hot_r'] ?? '',
|
||||
// 'IR_Hot_Y' => $record['after_fr_ir_hot_y'] ?? '',
|
||||
// 'IR_Hot_B' => $record['after_fr_ir_hot_b'] ?? '',
|
||||
// 'IR_Cool_R' => $record['after_fr_ir_cool_r'] ?? '',
|
||||
// 'IR_Cool_Y' => $record['after_fr_ir_cool_y'] ?? '',
|
||||
// 'IR_Cool_B' => $record['after_fr_ir_cool_b'] ?? '',
|
||||
// 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
||||
// 'Frequency_After' => $record['after_fr_freq'] ?? '',
|
||||
// 'Speed_After' => $record['after_fr_speed'] ?? '',
|
||||
// 'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||
// 'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||
// 'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||
// 'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
||||
// 'Room_Temp' => $record['room_temperature'] ?? '',
|
||||
// 'High_Voltage_Test' => $record['hv_test'] ?? '',
|
||||
// 'Batch_Number' => $record['batch_number'] ?? '',
|
||||
// 'Batch_Count' => $record['batch_count'] ?? '',
|
||||
// 'Result' => $record['result'] ?? '',
|
||||
// 'Remark' => $record['remark'] ?? '',
|
||||
// 'Tested_By' => $record['tested_by'] ?? '',
|
||||
// ];
|
||||
// }
|
||||
// });
|
||||
|
||||
// // Excel template path
|
||||
// $templatePath = storage_path('app/private/uploads/temp/MotorTestingPanelReportTemplate.xlsx');
|
||||
|
||||
// // Check if template exists
|
||||
// if (!file_exists($templatePath)) {
|
||||
// Notification::make()
|
||||
// ->title('Template Not Found')
|
||||
// ->danger()
|
||||
// ->body('The Excel template file does not exist. Please upload it first.')
|
||||
// ->send();
|
||||
|
||||
// return; // Stop further execution
|
||||
// }
|
||||
// // Export Excel
|
||||
// // return Excel::download(
|
||||
// // new MotorFreeRunExport(collect($mappedData)),
|
||||
// // 'TestingPanelReading.xlsx',
|
||||
// // \Maatwebsite\Excel\Excel::XLSX,
|
||||
// // [
|
||||
// // 'template' => $templatePath,
|
||||
// // ]
|
||||
// // );
|
||||
// // Load the template
|
||||
// $spreadsheet = IOFactory::load($templatePath);
|
||||
// $sheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
// // Insert mapped data starting from row 3
|
||||
// $row = 7;
|
||||
// foreach ($mappedData as $dataRow) {
|
||||
// $col = 'A';
|
||||
// foreach ($dataRow as $cell) {
|
||||
// $sheet->setCellValue($col . $row, $cell);
|
||||
// $col++;
|
||||
// }
|
||||
// $row++;
|
||||
// }
|
||||
|
||||
// // Download the modified template as Excel
|
||||
// $writer = new Xlsx($spreadsheet);
|
||||
// return response()->streamDownload(function() use ($writer) {
|
||||
// $writer->save('php://output');
|
||||
// }, 'TestingPanelReading.xlsx');
|
||||
// })
|
||||
// ->action(function ($records) {
|
||||
|
||||
// // If no template, notify
|
||||
// $templatePath = storage_path('app/private/uploads/temp/MotorTestingPanelReportTemplate.xlsx');
|
||||
// if (!file_exists($templatePath)) {
|
||||
// Notification::make()
|
||||
// ->title('Template Not Found')
|
||||
// ->danger()
|
||||
// ->body('The Excel template file does not exist. Please upload it first.')
|
||||
// ->send();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // Just export the raw data (fast, chunked)
|
||||
// return Excel::download(new MotorFreeRunExport($records->pluck('id')), 'MotorFreeRunData.xlsx');
|
||||
// })
|
||||
// ->icon('heroicon-o-document-arrow-down'), c
|
||||
|
||||
BulkAction::make('export_isi_pdf')
|
||||
->label('Export ISI Readings PDF')
|
||||
->action(function ($records)
|
||||
{
|
||||
->action(function ($records) {
|
||||
// Increase memory and execution time
|
||||
// ini_set('memory_limit', '1024M');
|
||||
// set_time_limit(300);
|
||||
$records->load('motorTestingMaster.item');
|
||||
$plantId = $records->first()?->plant_id;
|
||||
|
||||
@@ -985,8 +1179,7 @@ class TestingPanelReadingResource extends Resource
|
||||
// });
|
||||
|
||||
// dd($isAllStarDelta);
|
||||
if(!$isAllStarDelta)
|
||||
{
|
||||
if (! $isAllStarDelta) {
|
||||
$mappedData = collect($records)->map(function ($record) {
|
||||
return [
|
||||
// 'Date' => $record['created_at'] ?? '',
|
||||
@@ -1024,9 +1217,7 @@ class TestingPanelReadingResource extends Resource
|
||||
'Remark' => $record['remark'] ?? '',
|
||||
];
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$mappedData = collect($records)->map(function ($record) {
|
||||
return [
|
||||
// 'Date' => $record['created_at'] ?? '',
|
||||
@@ -1070,7 +1261,6 @@ class TestingPanelReadingResource extends Resource
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$view = $isAllStarDelta ? 'exports.export-isi-three-phase-pdf' : 'exports.export-isi-pdf';
|
||||
|
||||
$pdf = Pdf::loadView($view, [
|
||||
@@ -1093,15 +1283,18 @@ class TestingPanelReadingResource extends Resource
|
||||
})
|
||||
->icon('heroicon-o-document-arrow-down'),
|
||||
]),
|
||||
|
||||
])
|
||||
->headerActions([
|
||||
ImportAction::make()
|
||||
->label('Import Testing Panel Readings')
|
||||
->color('warning')
|
||||
->importer(TestingPanelReadingImporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view import testing panel reading');
|
||||
}),
|
||||
ExportAction::make()
|
||||
->label('Export Testing Panel Readings')
|
||||
->color('warning')
|
||||
->exporter(TestingPanelReadingExporter::class)
|
||||
->visible(function () {
|
||||
return Filament::auth()->user()->can('view export testing panel reading');
|
||||
|
||||
@@ -5,14 +5,10 @@ namespace App\Filament\Resources;
|
||||
use App\Filament\Exports\WeightValidationExporter;
|
||||
use App\Filament\Imports\WeightValidationImporter;
|
||||
use App\Filament\Resources\WeightValidationResource\Pages;
|
||||
use App\Filament\Resources\WeightValidationResource\RelationManagers;
|
||||
use App\Models\Item;
|
||||
use App\Models\Line;
|
||||
use App\Models\Plant;
|
||||
use App\Models\QualityValidation;
|
||||
use App\Models\StickerMaster;
|
||||
use App\Models\WeightValidation;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
@@ -26,14 +22,13 @@ use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
use Filament\Tables\Actions\ImportAction;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use Str;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
|
||||
class WeightValidationResource extends Resource
|
||||
{
|
||||
@@ -51,6 +46,7 @@ class WeightValidationResource extends Resource
|
||||
->relationship('plant', 'name')
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->required(),
|
||||
@@ -80,7 +76,7 @@ class WeightValidationResource extends Resource
|
||||
Forms\Components\TextInput::make('picked_weight')
|
||||
->label('Picked Weight'),
|
||||
Forms\Components\TextInput::make('scanned_by')
|
||||
->label('Scanned By')
|
||||
->label('Scanned By'),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -98,6 +94,7 @@ class WeightValidationResource extends Resource
|
||||
$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')
|
||||
@@ -157,9 +154,6 @@ class WeightValidationResource extends Resource
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
])
|
||||
// ->filters([
|
||||
// Tables\Filters\TrashedFilter::make(),
|
||||
// ])
|
||||
->filters([
|
||||
Tables\Filters\TrashedFilter::make(),
|
||||
Filter::make('advanced_filters')
|
||||
@@ -173,6 +167,7 @@ class WeightValidationResource extends Resource
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->reactive(),
|
||||
@@ -180,18 +175,33 @@ class WeightValidationResource extends Resource
|
||||
// $set('sticker_master_id', null);
|
||||
// $set('sap_msg_status', null);
|
||||
// }),
|
||||
|
||||
Select::make('Item Code')
|
||||
->label('Search by Item Code')
|
||||
->nullable()
|
||||
// ->options(function (callable $get) {
|
||||
// $plantId = $get('Plant');
|
||||
// if (! $plantId) {
|
||||
// return [];
|
||||
// }
|
||||
|
||||
// return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||
// })
|
||||
->options(function (callable $get) {
|
||||
$plantId = $get('Plant');
|
||||
if (! $plantId) {
|
||||
return [];
|
||||
}
|
||||
return Item::where('plant_id', $plantId)->pluck('code', 'id');
|
||||
|
||||
return Item::whereHas('weightValidations', function ($query) use ($plantId) {
|
||||
if ($plantId) {
|
||||
$query->where('plant_id', $plantId);
|
||||
}
|
||||
})->pluck('code', 'id');
|
||||
})
|
||||
->searchable()
|
||||
->reactive(),
|
||||
|
||||
TextInput::make('Obd Number')
|
||||
->label('OBD Number')
|
||||
->placeholder('Enter OBD Number'),
|
||||
@@ -243,6 +253,7 @@ class WeightValidationResource extends Resource
|
||||
->placeholder(placeholder: 'Select From DateTime')
|
||||
->reactive()
|
||||
->native(false),
|
||||
|
||||
DateTimePicker::make('created_to')
|
||||
->label('Created To')
|
||||
->placeholder(placeholder: 'Select To DateTime')
|
||||
@@ -257,6 +268,12 @@ class WeightValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$query->where('plant_id', $data['Plant']);
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return $query->whereRaw('1 = 0');
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Item Code'])) {
|
||||
@@ -295,7 +312,6 @@ class WeightValidationResource extends Resource
|
||||
$query->where('scanned_by', $data['Scanned By']);
|
||||
}
|
||||
|
||||
|
||||
if (! empty($data['created_from'])) {
|
||||
$query->where('created_at', '>=', $data['created_from']);
|
||||
}
|
||||
@@ -309,6 +325,12 @@ class WeightValidationResource extends Resource
|
||||
|
||||
if (! empty($data['Plant'])) {
|
||||
$indicators[] = 'Plant: '.Plant::where('id', $data['Plant'])->value('name');
|
||||
} else {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
if ($userHas && strlen($userHas) > 0) {
|
||||
return 'Plant: Choose plant to filter records.';
|
||||
}
|
||||
}
|
||||
|
||||
if (! empty($data['Item Code'])) {
|
||||
@@ -361,7 +383,7 @@ class WeightValidationResource extends Resource
|
||||
}
|
||||
|
||||
return $indicators;
|
||||
})
|
||||
}),
|
||||
])
|
||||
->filtersFormMaxHeight('280px')
|
||||
->actions([
|
||||
@@ -383,6 +405,7 @@ class WeightValidationResource extends Resource
|
||||
// ->options(Plant::pluck('name', 'id')->toArray())
|
||||
->options(function (callable $get) {
|
||||
$userHas = Filament::auth()->user()->plant_id;
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::pluck('name', 'id')->toArray();
|
||||
})
|
||||
->label('Select Plant')
|
||||
@@ -435,10 +458,10 @@ class WeightValidationResource extends Resource
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
if ($disk->exists($path))
|
||||
{
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -469,6 +492,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -482,9 +506,10 @@ class WeightValidationResource extends Resource
|
||||
$lineNumbers = [];
|
||||
$validRowsFound = false;
|
||||
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
if ($index === 0) continue; // Skip header
|
||||
foreach ($rows as $index => $row) {
|
||||
if ($index === 0) {
|
||||
continue;
|
||||
} // Skip header
|
||||
|
||||
$materialCode = trim($row[0]);
|
||||
$lineNumber = trim($row[1]);
|
||||
@@ -497,31 +522,23 @@ class WeightValidationResource extends Resource
|
||||
}
|
||||
|
||||
if (! empty($materialCode)) {
|
||||
if(Str::length($materialCode) < 6 || !ctype_alnum($materialCode))
|
||||
{
|
||||
if (Str::length($materialCode) < 6 || ! ctype_alnum($materialCode)) {
|
||||
$invalidMatCodes[] = $materialCode;
|
||||
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$materialCodes[] = $materialCode;
|
||||
|
||||
$validData = true;
|
||||
if(Str::length($lineNumber) < 1 || !is_numeric($lineNumber))
|
||||
{
|
||||
if (Str::length($lineNumber) < 1 || ! is_numeric($lineNumber)) {
|
||||
$validData = false;
|
||||
$invalidLines[] = $materialCode;
|
||||
}
|
||||
else if (in_array($lineNumber, $lineNumbers))
|
||||
{
|
||||
} elseif (in_array($lineNumber, $lineNumbers)) {
|
||||
$duplicateLines[] = $materialCode;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$lineNumbers[] = $lineNumber;
|
||||
}
|
||||
if(Str::length($batchNumber) < 8 || !is_numeric($batchNumber))//ctype_alnum
|
||||
{
|
||||
if (Str::length($batchNumber) < 8 || ! is_numeric($batchNumber)) {// ctype_alnum
|
||||
$validData = false;
|
||||
$invalidBatch[] = $materialCode;
|
||||
}
|
||||
@@ -530,20 +547,16 @@ class WeightValidationResource extends Resource
|
||||
// $validData = false;
|
||||
// $invalidHeat[] = $materialCode;
|
||||
// }
|
||||
if(Str::length($actualWeight) < 1 || !is_numeric($actualWeight))//ctype_alnum
|
||||
{
|
||||
if (Str::length($actualWeight) < 1 || ! is_numeric($actualWeight)) {// ctype_alnum
|
||||
$validData = false;
|
||||
$invalidWeight[] = $materialCode;
|
||||
}
|
||||
|
||||
if ($validData)
|
||||
{
|
||||
if ($validData) {
|
||||
$validRowsFound = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@@ -560,6 +573,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -575,6 +589,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -590,6 +605,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -605,6 +621,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -635,6 +652,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -671,6 +689,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -695,6 +714,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -709,6 +729,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -729,10 +750,11 @@ class WeightValidationResource extends Resource
|
||||
|
||||
$inserted = 0;
|
||||
// $updated = 0;
|
||||
foreach ($rows as $index => $row)
|
||||
{
|
||||
foreach ($rows as $index => $row) {
|
||||
// Skip header
|
||||
if ($index === 0) { continue; }
|
||||
if ($index === 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$materialCode = trim($row[0]);
|
||||
$lineNumber = trim($row[1]);
|
||||
@@ -750,12 +772,9 @@ class WeightValidationResource extends Resource
|
||||
$masItem = Item::where('plant_id', $plantId)->where('code', $materialCode)->first();
|
||||
if ($recordExist) {
|
||||
$skipUpd = $recordExist->vehicle_number ?? null;
|
||||
if($skipUpd)
|
||||
{
|
||||
if ($skipUpd) {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($masItem) {
|
||||
$recordExist->update([
|
||||
'item_id' => $masItem->id,
|
||||
@@ -767,8 +786,7 @@ class WeightValidationResource extends Resource
|
||||
$updated++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ($masItem) {
|
||||
WeightValidation::create([
|
||||
'item_id' => $masItem->id,
|
||||
@@ -779,12 +797,9 @@ class WeightValidationResource extends Resource
|
||||
// 'heat_number' => $heatNumber,
|
||||
'obd_weight' => $actualWeight,
|
||||
]);
|
||||
if (in_array($lineNumber, $availLines))
|
||||
{
|
||||
if (in_array($lineNumber, $availLines)) {
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$inserted++;
|
||||
}
|
||||
}
|
||||
@@ -795,7 +810,7 @@ class WeightValidationResource extends Resource
|
||||
if ($updateInv) {
|
||||
if ($updated > 0) {
|
||||
Notification::make()
|
||||
->title("Start the scanning process!")
|
||||
->title('Start the scanning process!')
|
||||
->body("'$updated' OBD lines were updated and<br>'$inserted' OBD lines were inserted for<br>imported OBD Invoice : '$originalNameOnly'.")
|
||||
->info()
|
||||
// ->success()
|
||||
@@ -806,24 +821,20 @@ class WeightValidationResource extends Resource
|
||||
$totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
|
||||
$scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
|
||||
|
||||
if ($totalQuantity === $scannedQuantity)
|
||||
{
|
||||
if ($totalQuantity === $scannedQuantity) {
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
|
||||
}
|
||||
}
|
||||
else if ($inserted > 0) {
|
||||
} elseif ($inserted > 0) {
|
||||
Notification::make()
|
||||
->title("Start the scanning process!")
|
||||
->title('Start the scanning process!')
|
||||
->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.")
|
||||
->info()
|
||||
// ->success()
|
||||
@@ -834,24 +845,20 @@ class WeightValidationResource extends Resource
|
||||
$totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
|
||||
$scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
|
||||
|
||||
if ($totalQuantity === $scannedQuantity)
|
||||
{
|
||||
if ($totalQuantity === $scannedQuantity) {
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Notification::make()
|
||||
->title("Import Failed: OBD Invoice")
|
||||
->title('Import Failed: OBD Invoice')
|
||||
->body("No exist records were updated for imported OBD Invoice : '$originalNameOnly'.")
|
||||
->danger()
|
||||
->seconds(2)
|
||||
@@ -863,14 +870,14 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
// $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if ($inserted > 0) {
|
||||
Notification::make()
|
||||
->title("Start the scanning process!")
|
||||
->title('Start the scanning process!')
|
||||
->body("'$inserted' OBD lines were inserted for imported OBD Invoice : '$originalNameOnly'.")
|
||||
->info()
|
||||
// ->success()
|
||||
@@ -881,24 +888,20 @@ class WeightValidationResource extends Resource
|
||||
$totalQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->count();
|
||||
$scannedQuantity = WeightValidation::where('obd_number', $originalNameOnly)->where('plant_id', $plantId)->whereNotNull('vehicle_number')->where('vehicle_number', '!=', '')->count();
|
||||
|
||||
if ($totalQuantity === $scannedQuantity)
|
||||
{
|
||||
if ($totalQuantity === $scannedQuantity) {
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
// $this->dispatch('refreshCompletedInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
// $this->dispatch('refreshInvoiceData', invoiceNumber: $originalNameOnly, plantId: $plantId);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
Notification::make()
|
||||
->title("Import Failed: OBD Invoice")
|
||||
->title('Import Failed: OBD Invoice')
|
||||
->body("No new records were inserted for imported OBD Invoice : '$originalNameOnly'.")
|
||||
->danger()
|
||||
->seconds(2)
|
||||
@@ -910,6 +913,7 @@ class WeightValidationResource extends Resource
|
||||
if ($disk->exists($path)) {
|
||||
$disk->delete($path);
|
||||
}
|
||||
|
||||
// $this->dispatch('refreshEmptyInvoice', invoiceNumber: $originalNameOnly, plantId: $plantId);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Item extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
|
||||
protected $fillable = [
|
||||
"plant_id",
|
||||
'plant_id',
|
||||
'category',
|
||||
'code',
|
||||
'description',
|
||||
@@ -43,4 +43,19 @@ class Item extends Model
|
||||
{
|
||||
return $this->hasMany(TestingPanelReading::class);
|
||||
}
|
||||
|
||||
public function processOrders()
|
||||
{
|
||||
return $this->hasMany(ProcessOrder::class);
|
||||
}
|
||||
|
||||
public function productCharacteristicsMasters()
|
||||
{
|
||||
return $this->hasMany(ProductCharacteristicsMaster::class);
|
||||
}
|
||||
|
||||
public function weightValidations()
|
||||
{
|
||||
return $this->hasMany(WeightValidation::class);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user