Implement feature X to enhance user experience and optimize performance
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user