diff --git a/app/Filament/Exports/LeakTestReadingExporter.php b/app/Filament/Exports/LeakTestReadingExporter.php new file mode 100644 index 0000000..2711c5f --- /dev/null +++ b/app/Filament/Exports/LeakTestReadingExporter.php @@ -0,0 +1,64 @@ +label('NO') + ->state(function ($record) use (&$rowNumber) { + // Increment and return the row number + return ++$rowNumber; + }), + ExportColumn::make('plant.code') + ->label('PLANT CODE'), + ExportColumn::make('item_code') + ->label('ITEM CODE'), + ExportColumn::make('serial_number') + ->label('SERIAL NUMBER'), + ExportColumn::make('test_status') + ->label('TEST STATUS') + ->formatStateUsing(function ($state) { + if (! $state || $state == '' || $state == null) { + return '-'; + } + + return match ($state) { + 'P' => 'PASS', + 'F' => 'FAIL', + default => '-', + }; + }), + ExportColumn::make('created_at') + ->label('CREATED AT'), + ExportColumn::make('updated_at') + ->label('UPDATED AT'), + ExportColumn::make('deleted_at') + ->enabledByDefault(false) + ->label('DELETED AT'), + ]; + } + + public static function getCompletedNotificationBody(Export $export): string + { + $body = 'Your leak test reading export has completed and '.number_format($export->successful_rows).' '.str('row')->plural($export->successful_rows).' exported.'; + + if ($failedRowsCount = $export->getFailedRowsCount()) { + $body .= ' '.number_format($failedRowsCount).' '.str('row')->plural($failedRowsCount).' failed to export.'; + } + + return $body; + } +} diff --git a/app/Filament/Resources/LeakTestReadingResource.php b/app/Filament/Resources/LeakTestReadingResource.php new file mode 100644 index 0000000..2432f21 --- /dev/null +++ b/app/Filament/Resources/LeakTestReadingResource.php @@ -0,0 +1,452 @@ +schema([ + Section::make('') + ->schema([ + Forms\Components\Select::make('plant_id') + ->required() + ->label('Plant Name') + ->relationship('plant', 'name') + ->searchable() + ->reactive() + // ->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::orderBy('code')->pluck('name', 'id')->toArray(); + }) + ->default(function () { + return optional(LeakTestReading::latest()->first())->plant_id; + }) + ->disabled(fn (Get $get) => ! empty($get('id'))) + ->afterStateUpdated(function ($state, $set, callable $get) { + $plantId = $get('plant_id'); + + $set('lsrPlantError', null); + $set('item_code', null); + $set('serial_number', null); + $set('test_status', null); + if (! $plantId) { + $set('lsrPlantError', 'Please select a plant first.'); + + return; + } + }) + ->extraAttributes(fn ($get) => [ + 'class' => $get('lsrPlantError') ? 'border-red-500' : '', + ]) + ->hint(fn ($get) => $get('lsrPlantError') ? $get('lsrPlantError') : null) + ->hintColor('danger'), + Forms\Components\TextInput::make('item_code') + ->required() + ->label('Item Code') + ->placeholder('Scan the valid item code') + ->autofocus(true) + ->alphaNum() + ->minLength(6) + ->reactive() + ->disabled(fn (Get $get) => ! empty($get('id'))) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $code = $get('item_code'); + // Ensure `linestop_id` is not cleared + if (! $code) { + $set('lsrCodeError', 'Scan the valid item code.'); + + return; + } else { + if (strlen($code) < 6) { + $set('lsrCodeError', 'Item code must be at least 6 digits.'); + + return; + } elseif (! ctype_alnum($code)) { + $set('item_code', null); + $set('lsrSerialError', 'Item code must contain only alpha-numeric characters!'); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $code)) { + $set('item_code', null); + $set('lsrCodeError', "Item code should not begin with '0' or letter!"); + + return; + } + $set('lsrCodeError', null); + } + }) + ->extraAttributes(fn ($get) => [ + 'class' => $get('lsrCodeError') ? 'border-red-500' : '', + ]) + ->hint(fn ($get) => $get('lsrCodeError') ? $get('lsrCodeError') : null) + ->hintColor('danger'), + Forms\Components\TextInput::make('serial_number') + ->required() + ->label('Serial Number') + ->placeholder('Scan the valid serial number') + ->alphaNum() + ->minLength(9) + ->reactive() + ->disabled(fn (Get $get) => ! empty($get('id'))) + ->afterStateUpdated(function ($state, callable $set, callable $get) { + $serial = $get('serial_number'); + // Ensure `linestop_id` is not cleared + if (! $serial) { + $set('lsrSerialError', 'Scan the valid serial number!'); + + return; + } else { + if (strlen($serial) < 9) { + $set('lsrSerialError', 'Serial number must be at least 9 digits!'); + + return; + } elseif (! ctype_alnum($serial)) { + $set('serial_number', null); + $set('lsrSerialError', 'Serial number must contain only alpha-numeric characters!'); + } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $serial)) { + $set('serial_number', null); + $set('lsrSerialError', "Serial number should not begin with '0' or letter!"); + + return; + } + $set('lsrSerialError', null); + } + }) + ->extraAttributes(fn ($get) => [ + 'class' => $get('lsrSerialError') ? 'border-red-500' : '', + ]) + ->hint(fn ($get) => $get('lsrSerialError') ? $get('lsrSerialError') : null) + ->hintColor('danger'), + Forms\Components\Select::make('test_status') + ->required() + ->label('Test Status') + ->searchable() + ->reactive() + ->options(function (callable $set, callable $get) { + $plantId = $get('plant_id'); + $itemCode = $get('item_code'); + $serialNumber = $get('serial_number'); + + if (! $plantId || ! $itemCode || ! $serialNumber) { + $set('test_status', null); + + return []; + } + + return [ + 'P' => 'PASS', + 'F' => 'FAIL', + ]; + }) + ->default(function () { + $userHas = Filament::auth()->user()->plant_id; + + return ($userHas && strlen($userHas) > 0) ? 'F' : 'P'; + // return optional(CharacteristicApproverMaster::latest()->first())->approver_type ?? null; + }), + Forms\Components\TextInput::make('id') + ->hidden() + ->readOnly(), + ]) + ->columns(['default' => 1, 'sm' => 2]), + ]); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('No.') + ->label('No.') + ->getStateUsing(function ($record, $livewire, $column, $rowLoop) { + $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') + ->label('Plant Name') + ->alignCenter() + ->searchable() + ->sortable(), + Tables\Columns\TextColumn::make('item_code') + ->label('Item Code') + ->alignCenter() + ->searchable() + ->sortable(), + Tables\Columns\TextColumn::make('serial_number') + ->label('Serial Number') + ->alignCenter() + ->searchable() + ->sortable(), + Tables\Columns\TextColumn::make('test_status') + ->label('Test Status') + ->alignCenter() + ->searchable() + ->sortable() + ->formatStateUsing(function ($state) { + return match ($state) { + 'P' => 'PASS', + 'F' => 'FAIL', + default => '-', + }; + }), + Tables\Columns\TextColumn::make('created_at') + ->label('Created At') + ->alignCenter() + ->dateTime() + ->sortable(), + Tables\Columns\TextColumn::make('updated_at') + ->label('Updated At') + ->alignCenter() + ->dateTime() + ->sortable(), + Tables\Columns\TextColumn::make('deleted_at') + ->label('Deleted At') + ->alignCenter() + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->searchPlaceholder('Search Serial Number') + ->filters([ + Tables\Filters\TrashedFilter::make(), + Filter::make('advanced_filters') + ->label('Advanced Filters') + ->form([ + Select::make('Plant') + ->label('Search by Plant Name') + ->nullable() + ->options(function (callable $get) { + $userHas = Filament::auth()->user()->plant_id; + + if ($userHas && strlen($userHas) > 0) { + return Plant::where('id', $userHas)->pluck('name', 'id')->toArray(); + } else { + return Plant::whereHas('leakTestReadings', function ($query) { + $query->whereNotNull('id'); + })->orderBy('code')->pluck('name', 'id')->toArray(); + } + }) + ->searchable() + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get): void { + $set('item_code', null); + $set('serial_number', null); + $set('test_status', null); + }), + Select::make('item_code') + ->label('Search by Item Code') + ->nullable() + ->options(function (callable $get) { + $plantId = $get('Plant'); + + return $plantId ? LeakTestReading::where('plant_id', $plantId)->pluck('item_code', 'item_code')->toArray() : []; + }) + ->searchable() + ->reactive() + ->afterStateUpdated(function ($state, callable $set, callable $get): void { + $set('serial_number', null); + $set('test_status', null); + }), + TextInput::make('serial_number') + ->label('Search by Serial Number') + ->placeholder(placeholder: 'Enter Serial Number') + ->afterStateUpdated(function ($state, callable $set, callable $get): void { + $set('test_status', null); + }), + Select::make('test_status') + ->label('Search by Test Status') + ->nullable() + ->options(function () { + return [ + 'P' => 'PASS', + 'F' => 'FAIL', + ]; + }) + ->searchable() + ->reactive(), + DateTimePicker::make(name: 'created_from') + ->label('Created From') + ->placeholder(placeholder: 'Select From DateTime') + ->reactive() + ->native(false), + DateTimePicker::make('created_to') + ->label('Created To') + ->placeholder(placeholder: 'Select To DateTime') + ->reactive() + ->native(false), + DateTimePicker::make(name: 'updated_from') + ->label('Updated From') + ->placeholder(placeholder: 'Select From DateTime') + ->reactive() + ->native(false), + DateTimePicker::make('updated_to') + ->label('Updated To') + ->placeholder(placeholder: 'Select To DateTime') + ->reactive() + ->native(false), + ]) + ->query(function ($query, array $data) { + // Hide all records initially if no filters are applied + if (empty($data['Plant']) && empty($data['item_code']) && empty($data['serial_number']) && empty($data['test_status']) && empty($data['created_from']) && empty($data['created_to']) && empty($data['updated_from']) && empty($data['updated_to'])) { + return $query->whereRaw('1 = 0'); + } + + 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['item_code'])) { + $query->where('item_code', $data['item_code']); + } + + if (! empty($data['serial_number'])) { + $query->where('serial_number', 'like', '%'.$data['serial_number'].'%'); + } + + if (! empty($data['test_status'])) { + $query->where('test_status', $data['test_status']); + } + + if (! empty($data['created_from'])) { + $query->where('created_at', '>=', $data['created_from']); + } + + if (! empty($data['created_to'])) { + $query->where('created_at', '<=', $data['created_to']); + } + + if (! empty($data['updated_from'])) { + $query->where('updated_at', '>=', $data['updated_from']); + } + + if (! empty($data['updated_to'])) { + $query->where('updated_at', '<=', $data['updated_to']); + } + }) + ->indicateUsing(function (array $data) { + $indicators = []; + + 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'])) { + $indicators[] = 'Item Code: '.$data['item_code']; + } + + if (! empty($data['serial_number'])) { + $indicators[] = 'Serial Number: '.$data['serial_number']; + } + + if (! empty($data['test_status'])) { + $indicators[] = 'Test Status: '.$data['test_status']; + } + + if (! empty($data['created_from'])) { + $indicators[] = 'From: '.$data['created_from']; + } + + if (! empty($data['created_to'])) { + $indicators[] = 'To: '.$data['created_to']; + } + + if (! empty($data['updated_from'])) { + $indicators[] = 'From: '.$data['updated_from']; + } + + if (! empty($data['updated_to'])) { + $indicators[] = 'To: '.$data['updated_to']; + } + + return $indicators; + }), + ]) + ->filtersFormMaxHeight('280px') + ->actions([ + Tables\Actions\ViewAction::make(), + Tables\Actions\EditAction::make(), + ]) + ->bulkActions([ + Tables\Actions\BulkActionGroup::make([ + Tables\Actions\DeleteBulkAction::make(), + Tables\Actions\ForceDeleteBulkAction::make(), + Tables\Actions\RestoreBulkAction::make(), + ]), + ]) + ->headerActions([ + ExportAction::make() + ->label('Export Leak Test Readings') + ->color('warning') + ->exporter(LeakTestReadingExporter::class) + ->visible(function () { + return Filament::auth()->user()->can('view export leak test reading'); + }), + ]); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListLeakTestReadings::route('/'), + 'create' => Pages\CreateLeakTestReading::route('/create'), + 'view' => Pages\ViewLeakTestReading::route('/{record}'), + 'edit' => Pages\EditLeakTestReading::route('/{record}/edit'), + ]; + } + + public static function getEloquentQuery(): Builder + { + return parent::getEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/LeakTestReadingResource/Pages/CreateLeakTestReading.php b/app/Filament/Resources/LeakTestReadingResource/Pages/CreateLeakTestReading.php new file mode 100644 index 0000000..5089038 --- /dev/null +++ b/app/Filament/Resources/LeakTestReadingResource/Pages/CreateLeakTestReading.php @@ -0,0 +1,12 @@ +header('Authorization'); + $expectedToken = $expectedUser.':'.$expectedPw; + + if ('Bearer '.$expectedToken != $header_auth) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid authorization token!', + ], 403); + } + + $data = $request->all(); + + $plantCode = $data['plant_code'] ?? ''; + $itemCode = $data['item_code'] ?? ''; + $serialNumber = $data['serial_number'] ?? ''; + $testStatus = $data['test_status'] ?? 'F'; + + if ($plantCode == null || $plantCode == '' || ! $plantCode) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code can't be empty!", + ], 400); + } elseif (! is_numeric($plantCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code '{$plantCode}' should contain only numeric values!", + ], 400); + } elseif (Str::length($plantCode) < 4 || Str::length($plantCode) > 7) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code '{$plantCode}' must be between 4 and 7 digits only!", + ], 400); + } elseif (! preg_match('/^[1-9]\d{3,6}$/', $plantCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Invalid plant code '{$plantCode}' found!", + ], 400); + } + + if ($itemCode == null || $itemCode == '' || ! $itemCode) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code can't be empty!", + ], 404); + } elseif (Str::length($itemCode) < 6) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' should contain minimum 6 digits!", + ], 404); + } elseif (! ctype_alnum($itemCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' should contain only alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $itemCode)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Item code '{$itemCode}' should not begin with '0'!", + ], 404); + } + + if ($serialNumber == null || $serialNumber == '' || ! $serialNumber) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number can't be empty!", + ], 404); + } elseif (Str::length($serialNumber) < 9) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' should contain minimum 9 digits!", + ], 404); + } elseif (! ctype_alnum($serialNumber)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' should contain only alpha-numeric values!", + ], 404); + } elseif (! preg_match('/^[1-9][a-zA-Z0-9]{8,}$/', $serialNumber)) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Serial number '{$serialNumber}' should not begin with '0' or letter!", + ], 404); + } + + if ($testStatus == null || $testStatus == '') { + $testStatus = 'F'; + + } elseif (Str::contains($testStatus, 'P', ignoreCase: true)) { + $testStatus = 'P'; + } elseif (Str::contains($testStatus, 'F', ignoreCase: true)) { + $testStatus = 'F'; + } else { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Leak test status must be 'P' or 'F'!", + ], 404); + } + + $plant = Plant::where('code', $plantCode)->first(); + if (! $plant) { + // return response("Plant not found.", 400)->header('Content-Type', 'text/plain'); + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => "Plant code '{$plantCode}' not found!", + ], 400); + } + + $plantId = $plant->id; + + try { + LeakTestReading::create([ + 'plant_id' => $plantId, + 'item_code' => $itemCode, + 'serial_number' => $serialNumber, + 'test_status' => $testStatus, + ]); + + $existing = LeakTestReading::where('serial_number', $serialNumber)->where('item_code', $itemCode)->where('test_status', $testStatus)->where('plant_id', $plantId)->latest()->first(); + + if ($existing) { + return response()->json([ + 'status_code' => 'SUCCESS', + 'status_description' => 'Successfully updated leak test status.', + ], 200); + } else { + return response()->json([ + 'status_code' => 'SUCCESS', + 'status_description' => 'Failed to update leak test status!', + ], 200); + } + } catch (\Exception $e) { + // return response($e->getMessage(), 500)->header('Content-Type', 'text/plain'); + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Store leak test status internal server error : '.$e?->getCode(), + ], 500); + } + } + + /** + * Get leak test status. + */ + public function getLeakTestStatus(Request $request) + { + $expectedUser = env('API_AUTH_USER'); + $expectedPw = env('API_AUTH_PW'); + $header_auth = $request->header('Authorization'); + $expectedToken = $expectedUser.':'.$expectedPw; + + // $data = $request->all(); + if ('Bearer '.$expectedToken != $header_auth) { + return response()->json([ + 'status_code' => 'ERROR', + 'status_description' => 'Invalid authorization token!', + ], 403); + } + + // $plantCode = $request->header('plant-code'); + // $itemCode = $request->header('item-code'); + // // $description = $item ? $item->description : ''; + + // if ($plantCode == null || $plantCode == '') { + // // return response("ERROR: Plant Name can't be empty", 400) + // // ->header('Content-Type', 'text/plain'); + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => "Plant code can't be empty!", + // ], 400); + // } elseif (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => 'Invalid plant code found!', + // ], 400); + // } elseif ($itemCode == null || $itemCode == '' || ! $itemCode) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => "Item code can't be empty!", + // ], 404); + // } elseif (Str::length($itemCode) < 6) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => "Item code '{$itemCode}' should contain minimum 6 digits!", + // ], 404); + // } elseif (! ctype_alnum($itemCode)) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => "Item code '{$itemCode}' should contain only alpha-numeric values!", + // ], 404); + // } elseif (! preg_match('/^[a-zA-Z1-9][a-zA-Z0-9]{5,}$/', $itemCode)) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => "Item code '{$itemCode}' should not begin with '0'!", + // ], 404); + // } + + // $plant = Plant::where('code', $plantCode)->first(); + + // if (! $plant) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => 'Plant not found!', + // ], 400); + // } + + // $plantId = $plant->id; + + // $item = Item::where('code', $itemCode)->first(); + + // if (! $item) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => 'Item code not found in item table!', + // ], 404); + // } + + // $item = Item::where('plant_id', $plantId)->where('code', $itemCode)->first(); + + // if (! $item) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => "Item code not found in item table for the plant : '$plant->name'!", + // ], 404); + // } + + // $itemId = $item->id; + + // $description = $item ? $item->description : ''; + + // $category = $item ? $item->category : ''; + + // $motorTestingMaster = MotorTestingMaster::where('item_id', $itemId)->first(); + + // if (! $motorTestingMaster) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => 'Item code not found in motor testing master table!', + // ], 404); + // } + + // $motorTestingMaster = MotorTestingMaster::where('plant_id', $plantId)->where('item_id', $itemId)->first(); + + // if (! $motorTestingMaster) { + // return response()->json([ + // 'status_code' => 'ERROR', + // 'status_description' => "Item code not found in motor testing master table for the plant : '$plant->name'!", + // ], 404); + // } + + // $output = [ + // 'mot_subassembly_code' => $motorTestingMaster->subassembly_code ?? '', + // 'mot_model_name' => ($itemCode == '123456') ? 'SAMPLE TYPE' : $description, + // 'mot_non_isi_model' => $motorTestingMaster->isi_model ? '0' : '1', + // 'mot_phase' => $motorTestingMaster->phase ?? '', + // 'mot_hp' => $motorTestingMaster->hp ?? '', + // 'mot_kw' => $motorTestingMaster->kw ?? '', + // 'mot_volt' => $motorTestingMaster->volt ?? '', + // 'mot_cur' => $motorTestingMaster->current ?? '', + // 'mot_rpm' => $motorTestingMaster->rpm ?? '', + // 'mot_rate_torque_kg' => $motorTestingMaster->torque ?? '', + // 'mot_freq' => $motorTestingMaster->frequency ?? '', + // 'mot_conn' => $motorTestingMaster->connection ?? '', + // 'mot_ins_res_limit' => $motorTestingMaster->ins_res_limit ?? '', + // 'mot_ins_res_type' => $motorTestingMaster->ins_res_type ?? '', + // 'mot_category' => $category, + // 'mot_routine_test_time' => $motorTestingMaster->routine_test_time ?? '', + // 'mot_res_ry_ll' => $motorTestingMaster->res_ry_ll ?? '', + // 'mot_res_ry_ul' => $motorTestingMaster->res_ry_ul ?? '', + // 'mot_res_yb_ll' => $motorTestingMaster->res_yb_ll ?? '', + // 'mot_res_yb_ul' => $motorTestingMaster->res_yb_ul ?? '', + // 'mot_res_br_ll' => $motorTestingMaster->res_br_ll ?? '', + // 'mot_res_br_ul' => $motorTestingMaster->res_br_ul ?? '', + // 'mot_lock_volt_limit' => $motorTestingMaster->lock_volt_limit ?? '', + // 'mot_leak_cur_limit' => $motorTestingMaster->leak_cur_limit ?? '', + // 'mot_lock_cur_ll' => $motorTestingMaster->lock_cur_ll ?? '', + // 'mot_lock_cur_ul' => $motorTestingMaster->lock_cur_ul ?? '', + // 'mot_noload_cur_ll' => $motorTestingMaster->noload_cur_ll ?? '', + // 'mot_noload_cur_ul' => $motorTestingMaster->noload_cur_ul ?? '', + // 'mot_noload_pow_ll' => $motorTestingMaster->noload_pow_ll ?? '', + // 'mot_noload_pow_ul' => $motorTestingMaster->noload_pow_ul ?? '', + // 'mot_noload_spd_ll' => $motorTestingMaster->noload_spd_ll ?? '', + // 'mot_noload_spd_ul' => $motorTestingMaster->noload_spd_ul ?? '', + // ]; + + // return response()->json($output, 200); + } + /** * Display the specified resource. */ diff --git a/app/Models/LeakTestReading.php b/app/Models/LeakTestReading.php new file mode 100644 index 0000000..6194cf4 --- /dev/null +++ b/app/Models/LeakTestReading.php @@ -0,0 +1,25 @@ +belongsTo(Plant::class); + } +} diff --git a/app/Policies/LeakTestReadingPolicy.php b/app/Policies/LeakTestReadingPolicy.php new file mode 100644 index 0000000..9181880 --- /dev/null +++ b/app/Policies/LeakTestReadingPolicy.php @@ -0,0 +1,105 @@ +checkPermissionTo('view-any LeakTestReading'); + } + + /** + * Determine whether the user can view the model. + */ + public function view(User $user, LeakTestReading $leaktestreading): bool + { + return $user->checkPermissionTo('view LeakTestReading'); + } + + /** + * Determine whether the user can create models. + */ + public function create(User $user): bool + { + return $user->checkPermissionTo('create LeakTestReading'); + } + + /** + * Determine whether the user can update the model. + */ + public function update(User $user, LeakTestReading $leaktestreading): bool + { + return $user->checkPermissionTo('update LeakTestReading'); + } + + /** + * Determine whether the user can delete the model. + */ + public function delete(User $user, LeakTestReading $leaktestreading): bool + { + return $user->checkPermissionTo('delete LeakTestReading'); + } + + /** + * Determine whether the user can delete any models. + */ + public function deleteAny(User $user): bool + { + return $user->checkPermissionTo('delete-any LeakTestReading'); + } + + /** + * Determine whether the user can restore the model. + */ + public function restore(User $user, LeakTestReading $leaktestreading): bool + { + return $user->checkPermissionTo('restore LeakTestReading'); + } + + /** + * Determine whether the user can restore any models. + */ + public function restoreAny(User $user): bool + { + return $user->checkPermissionTo('restore-any LeakTestReading'); + } + + /** + * Determine whether the user can replicate the model. + */ + public function replicate(User $user, LeakTestReading $leaktestreading): bool + { + return $user->checkPermissionTo('replicate LeakTestReading'); + } + + /** + * Determine whether the user can reorder the models. + */ + public function reorder(User $user): bool + { + return $user->checkPermissionTo('reorder LeakTestReading'); + } + + /** + * Determine whether the user can permanently delete the model. + */ + public function forceDelete(User $user, LeakTestReading $leaktestreading): bool + { + return $user->checkPermissionTo('force-delete LeakTestReading'); + } + + /** + * Determine whether the user can permanently delete any models. + */ + public function forceDeleteAny(User $user): bool + { + return $user->checkPermissionTo('force-delete-any LeakTestReading'); + } +} diff --git a/routes/api.php b/routes/api.php index e3597b0..3314acc 100644 --- a/routes/api.php +++ b/routes/api.php @@ -157,7 +157,11 @@ Route::get('machine/get-data', [MachineController::class, 'get_data']); Route::get('testing/equipment/get-master-data', [EquipmentMasterController::class, 'equipmentMasterData']); -Route::post('testing/reading/store-data', [TestingPanelController::class, 'store']); +Route::post('testing/reading/store-data', [TestingPanelController::class, 'storeReadings']); + +Route::post('testing/leak-test/store-data', [TestingPanelController::class, 'storeLeakTestStatus']); + +Route::get('testing/leak-test/get-data', [TestingPanelController::class, 'getLeakTestStatus']); Route::get('get-pdf', [PdfController::class, 'getPdf']); // processorder/get-pdf