Refactor export actions in TestingPanelReadingResource for improved readability and maintainability
This commit is contained in:
@@ -6,15 +6,12 @@ use AlperenErsoy\FilamentExport\Actions\FilamentExportBulkAction;
|
|||||||
use App\Filament\Exports\TestingPanelReadingExporter;
|
use App\Filament\Exports\TestingPanelReadingExporter;
|
||||||
use App\Filament\Imports\TestingPanelReadingImporter;
|
use App\Filament\Imports\TestingPanelReadingImporter;
|
||||||
use App\Filament\Resources\TestingPanelReadingResource\Pages;
|
use App\Filament\Resources\TestingPanelReadingResource\Pages;
|
||||||
use App\Filament\Resources\TestingPanelReadingResource\RelationManagers;
|
|
||||||
use App\Models\Configuration;
|
use App\Models\Configuration;
|
||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
use App\Models\Line;
|
use App\Models\Line;
|
||||||
use App\Models\Machine;
|
use App\Models\Machine;
|
||||||
use App\Models\MotorTestingMaster;
|
use App\Models\MotorTestingMaster;
|
||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use App\Models\QualityValidation;
|
|
||||||
use App\Models\StickerMaster;
|
|
||||||
use App\Models\TestingPanelReading;
|
use App\Models\TestingPanelReading;
|
||||||
use Barryvdh\DomPDF\Facade\Pdf;
|
use Barryvdh\DomPDF\Facade\Pdf;
|
||||||
use Filament\Facades\Filament;
|
use Filament\Facades\Filament;
|
||||||
@@ -805,274 +802,150 @@ class TestingPanelReadingResource extends Resource
|
|||||||
Tables\Actions\ForceDeleteBulkAction::make(),
|
Tables\Actions\ForceDeleteBulkAction::make(),
|
||||||
Tables\Actions\RestoreBulkAction::make(),
|
Tables\Actions\RestoreBulkAction::make(),
|
||||||
BulkAction::make('export_pdf')
|
BulkAction::make('export_pdf')
|
||||||
->label('Export Readings PDF')
|
->label('Export Readings PDF')
|
||||||
->action(function ($records)
|
->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) {
|
//$records->load('item');
|
||||||
return [
|
$records->load('motorTestingMaster.item');
|
||||||
// 'Date' => $record['created_at'] ?? '',
|
$plantId = $records->first()?->plant_id;
|
||||||
'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 ?? '',
|
$plant = $plantId ? Plant::find($plantId) : null;
|
||||||
'hp' => $record->motorTestingMaster->hp ?? '',
|
|
||||||
'phase' => $record->motorTestingMaster->phase ?? '',
|
|
||||||
'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
|
||||||
|
|
||||||
// BEFORE FREE RUN
|
// Check if all records are Star-Delta type
|
||||||
'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
$isAllStarDelta = $records->every(function ($record) {
|
||||||
'Current_Before' => $record['before_fr_cur'] ?? '',
|
return $record->motorTestingMaster?->connection === 'Star-Delta';
|
||||||
'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'] ?? '',
|
|
||||||
];
|
|
||||||
});
|
});
|
||||||
}
|
// $hasStarDelta = $records->contains(function ($record) {
|
||||||
|
// return $record->motorTestingMaster?->connection === 'Star-Delta';
|
||||||
$view = $isAllStarDelta ? 'exports.export-three-phase-pdf' : 'exports.testingpanel-pdf';
|
// });
|
||||||
|
|
||||||
|
|
||||||
$pdf = Pdf::loadView($view, [
|
//dd($isAllStarDelta);
|
||||||
'records' => $mappedData,
|
if(!$isAllStarDelta)
|
||||||
'plant' => $plant,
|
{
|
||||||
]);
|
$mappedData = collect($records)->map(function ($record) {
|
||||||
|
|
||||||
// $pdf = Pdf::loadView('exports.testingpanel-pdf',[
|
|
||||||
// // ['records' => $mappedData]
|
|
||||||
// 'records' => $mappedData,
|
|
||||||
// 'plant' => $plant,
|
|
||||||
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
return response()->streamDownload(
|
|
||||||
fn () => print($pdf->stream()),
|
|
||||||
'TestingPanelReading.pdf'
|
|
||||||
);
|
|
||||||
|
|
||||||
})
|
|
||||||
->icon('heroicon-o-document-arrow-down'),
|
|
||||||
BulkAction::make('export_isi_pdf')
|
|
||||||
->label('Export ISI Readings PDF')
|
|
||||||
->action(function ($records)
|
|
||||||
{
|
|
||||||
$records->load('motorTestingMaster.item');
|
|
||||||
$plantId = $records->first()?->plant_id;
|
|
||||||
|
|
||||||
$plant = $plantId ? Plant::find($plantId) : null;
|
|
||||||
|
|
||||||
$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 [
|
return [
|
||||||
// 'Date' => $record['created_at'] ?? '',
|
// 'Date' => $record['created_at'] ?? '',
|
||||||
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||||
'Output' => $record['output'] ?? '',
|
'Output' => $record['output'] ?? '',
|
||||||
'Motor SNo' => $record['serial_number'] ?? '',
|
'Motor SNo' => $record['serial_number'] ?? '',
|
||||||
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||||
'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||||
|
|
||||||
'kw' => $record->motorTestingMaster->kw ?? '',
|
'kw' => $record->motorTestingMaster->kw ?? '',
|
||||||
'hp' => $record->motorTestingMaster->hp ?? '',
|
'hp' => $record->motorTestingMaster->hp ?? '',
|
||||||
'phase' => $record->motorTestingMaster->phase ?? '',
|
'phase' => $record->motorTestingMaster->phase ?? '',
|
||||||
'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||||
|
|
||||||
// AFTER FREE RUN
|
// BEFORE FREE RUN
|
||||||
'Voltage_After' => $record['after_fr_vol'] ?? '',
|
'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||||
'Current_After' => $record['after_fr_cur'] ?? '',
|
'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||||
'Power_After' => $record['after_fr_pow'] ?? '',
|
'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||||
'IR_Hot' => $record['after_fr_ir_hot'] ?? '',
|
'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||||
'IR_Cool' => $record['after_fr_ir_cool'] ?? '',
|
'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||||
'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||||
'Frequency_After' => $record['after_fr_freq'] ?? '',
|
'Insulation_Resistance' => $record['before_fr_ir'] ?? '',
|
||||||
'Speed_After' => $record['after_fr_speed'] ?? '',
|
'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||||
|
'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||||
|
|
||||||
// LOCKED ROTOR TEST
|
// AFTER FREE RUN
|
||||||
'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||||
'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
'Current_After' => $record['after_fr_cur'] ?? '',
|
||||||
'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
'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'] ?? '',
|
||||||
|
|
||||||
// Last 8 columns
|
// LOCKED ROTOR TEST
|
||||||
'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||||
'Room_Temp' => $record['room_temperature'] ?? '',
|
'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||||
'High_Voltage_Test' => $record['hv_test'] ?? '',
|
'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||||
'Result' => $record['result'] ?? '',
|
|
||||||
'Remark' => $record['remark'] ?? '',
|
// 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
|
else
|
||||||
{
|
{
|
||||||
$mappedData = collect($records)->map(function ($record) {
|
|
||||||
|
$mappedData = collect($records)->map(function ($record) {
|
||||||
return [
|
return [
|
||||||
// 'Date' => $record['created_at'] ?? '',
|
//'Date' => $record['created_at'] ?? '',
|
||||||
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
'Date' =>date('Y-m-d', strtotime($record['created_at'] ?? '')),
|
||||||
'Output' => $record['output'] ?? '',
|
'Output' => $record['output'] ?? '',
|
||||||
'Motor SNo' => $record['serial_number'] ?? '',
|
'Motor SNo' => $record['serial_number'] ?? '',
|
||||||
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
'Item Code' => $record->motorTestingMaster->item->code ?? '',
|
||||||
'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
'Motor Type' => $record->motorTestingMaster->item->description ?? '',
|
||||||
|
|
||||||
'kw' => $record->motorTestingMaster->kw ?? '',
|
'kw' => $record->motorTestingMaster->kw ?? '',
|
||||||
'hp' => $record->motorTestingMaster->hp ?? '',
|
'hp' => $record->motorTestingMaster->hp ?? '',
|
||||||
'phase' => $record->motorTestingMaster->phase ?? '',
|
'phase' => $record->motorTestingMaster->phase ?? '',
|
||||||
'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
'isi_model' => $record->motorTestingMaster->isi_model ?? '',
|
||||||
|
|
||||||
// AFTER FREE RUN
|
// BEFORE FREE RUN
|
||||||
'Voltage_After' => $record['after_fr_vol'] ?? '',
|
'Voltage_Before' => $record['before_fr_volt'] ?? '',
|
||||||
'Current_After' => $record['after_fr_cur'] ?? '',
|
'Current_Before' => $record['before_fr_cur'] ?? '',
|
||||||
'Power_After' => $record['after_fr_pow'] ?? '',
|
'Power_Before' => $record['before_fr_pow'] ?? '',
|
||||||
'IR_Hot_R' => $record['after_fr_ir_hot_r'] ?? '',
|
'Resistance_RY' => $record['before_fr_res_ry'] ?? '',
|
||||||
'IR_Hot_Y' => $record['after_fr_ir_hot_y'] ?? '',
|
'Resistance_YB' => $record['before_fr_res_yb'] ?? '',
|
||||||
'IR_Hot_B' => $record['after_fr_ir_hot_b'] ?? '',
|
'Resistance_BR' => $record['before_fr_res_br'] ?? '',
|
||||||
'IR_Cool_R' => $record['after_fr_ir_cool_r'] ?? '',
|
'Insulation_Resistance_R' => $record['before_fr_ir_r'] ?? '',
|
||||||
'IR_Cool_Y' => $record['after_fr_ir_cool_y'] ?? '',
|
'Insulation_Resistance_Y' => $record['before_fr_ir_y'] ?? '',
|
||||||
'IR_Cool_B' => $record['after_fr_ir_cool_b'] ?? '',
|
'Insulation_Resistance_B' => $record['before_fr_ir_b'] ?? '',
|
||||||
'Leakage_Current' => $record['after_fr_leak_cur'] ?? '',
|
'Frequency_Before' => $record['before_fr_freq'] ?? '',
|
||||||
'Frequency_After' => $record['after_fr_freq'] ?? '',
|
'Speed_Before' => $record['before_fr_speed'] ?? '',
|
||||||
'Speed_After' => $record['after_fr_speed'] ?? '',
|
|
||||||
|
|
||||||
// LOCKED ROTOR TEST
|
// AFTER FREE RUN
|
||||||
'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
'Voltage_After' => $record['after_fr_vol'] ?? '',
|
||||||
'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
'Current_After' => $record['after_fr_cur'] ?? '',
|
||||||
'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
'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'] ?? '',
|
||||||
|
|
||||||
// Last 8 columns
|
// LOCKED ROTOR TEST
|
||||||
'No_Load_Pickup_Voltage' => $record['no_load_pickup_volt'] ?? '',
|
'Voltage_Locked' => $record['locked_rt_volt'] ?? '',
|
||||||
'Room_Temp' => $record['room_temperature'] ?? '',
|
'Current_Locked' => $record['locked_rt_cur'] ?? '',
|
||||||
'High_Voltage_Test' => $record['hv_test'] ?? '',
|
'Power_Locked' => $record['locked_rt_pow'] ?? '',
|
||||||
'Result' => $record['result'] ?? '',
|
|
||||||
'Remark' => $record['remark'] ?? '',
|
|
||||||
];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 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';
|
||||||
|
|
||||||
$view = $isAllStarDelta ? 'exports.export-isi-three-phase-pdf' : 'exports.export-isi-pdf';
|
|
||||||
|
|
||||||
$pdf = Pdf::loadView($view, [
|
$pdf = Pdf::loadView($view, [
|
||||||
'records' => $mappedData,
|
'records' => $mappedData,
|
||||||
'plant' => $plant,
|
'plant' => $plant,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// $pdf = Pdf::loadView('exports.export-isi-pdf',[
|
// $pdf = Pdf::loadView('exports.testingpanel-pdf',[
|
||||||
// // ['records' => $mappedData]
|
// // ['records' => $mappedData]
|
||||||
// 'records' => $mappedData,
|
// 'records' => $mappedData,
|
||||||
// 'plant' => $plant,
|
// 'plant' => $plant,
|
||||||
@@ -1084,9 +957,132 @@ class TestingPanelReadingResource extends Resource
|
|||||||
'TestingPanelReading.pdf'
|
'TestingPanelReading.pdf'
|
||||||
);
|
);
|
||||||
|
|
||||||
})
|
})
|
||||||
->icon('heroicon-o-document-arrow-down'),
|
->icon('heroicon-o-document-arrow-down'),
|
||||||
|
BulkAction::make('export_isi_pdf')
|
||||||
|
->label('Export ISI Readings PDF')
|
||||||
|
->action(function ($records)
|
||||||
|
{
|
||||||
|
$records->load('motorTestingMaster.item');
|
||||||
|
$plantId = $records->first()?->plant_id;
|
||||||
|
|
||||||
|
$plant = $plantId ? Plant::find($plantId) : null;
|
||||||
|
|
||||||
|
$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 ?? '',
|
||||||
|
|
||||||
|
// 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'] ?? '',
|
||||||
|
'Result' => $record['result'] ?? '',
|
||||||
|
'Remark' => $record['remark'] ?? '',
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
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 ?? '',
|
||||||
|
|
||||||
|
// 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'] ?? '',
|
||||||
|
'Result' => $record['result'] ?? '',
|
||||||
|
'Remark' => $record['remark'] ?? '',
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$view = $isAllStarDelta ? 'exports.export-isi-three-phase-pdf' : 'exports.export-isi-pdf';
|
||||||
|
|
||||||
|
$pdf = Pdf::loadView($view, [
|
||||||
|
'records' => $mappedData,
|
||||||
|
'plant' => $plant,
|
||||||
|
]);
|
||||||
|
|
||||||
|
// $pdf = Pdf::loadView('exports.export-isi-pdf',[
|
||||||
|
// // ['records' => $mappedData]
|
||||||
|
// 'records' => $mappedData,
|
||||||
|
// 'plant' => $plant,
|
||||||
|
|
||||||
|
// ]);
|
||||||
|
|
||||||
|
return response()->streamDownload(
|
||||||
|
fn () => print($pdf->stream()),
|
||||||
|
'TestingPanelReading.pdf'
|
||||||
|
);
|
||||||
|
|
||||||
|
})
|
||||||
|
->icon('heroicon-o-document-arrow-down'),
|
||||||
]),
|
]),
|
||||||
|
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user