diff --git a/app/Exports/MotorFreeRunExport.php b/app/Exports/MotorFreeRunExport.php new file mode 100644 index 0000000..f72d553 --- /dev/null +++ b/app/Exports/MotorFreeRunExport.php @@ -0,0 +1,231 @@ + $this->records, +// // ]); +// // } + +// public function collection() +// { +// return $this->records; +// } + +// public function headings(): array +// { +// // Top two rows (Company info + Motor KW/HP) +// return [ +// ['C.R.I. Pumps Private Limited', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Unit: MOTOR FREE RUN TEST REGISTER'], +// ['Motor KW/HP : - / -', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', 'Phase : -'], +// // Column headers +// [ +// 'Date', 'Motor SNo', 'Item Code', 'Motor Type', +// 'Voltage', 'Current', 'Power', 'IR.Hot', 'IR.Cool', 'Frequency', 'Speed', 'Leakage Current', // AFTER FREE RUN +// 'Voltage', 'Current', 'Power', // LOCKED ROTOR TEST +// 'No Load Pickup Voltage', 'Room Temp.', 'High Voltage Test', 'Result', 'Remark' +// ] +// ]; +// } + +// public function registerEvents(): array +// { +// return [ +// AfterSheet::class => function (AfterSheet $event) { +// $sheet = $event->sheet->getDelegate(); + +// // Merge top rows for company info +// $sheet->mergeCells('A1:S1'); // Company Name +// $sheet->mergeCells('T1:T1'); // Unit/Register info +// $sheet->mergeCells('A2:S2'); // Motor KW/HP row +// $sheet->mergeCells('T2:T2'); // Phase + +// // Merge headers for grouped columns (AFTER FREE RUN & LOCKED ROTOR TEST) +// $sheet->mergeCells('E3:L3'); // AFTER FREE RUN +// $sheet->mergeCells('M3:O3'); // LOCKED ROTOR TEST + +// // Optional: style headers +// $sheet->getStyle('A1:T3')->getFont()->setBold(true); +// $sheet->getStyle('A1:T3')->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_CENTER); +// $sheet->getStyle('A1:T3')->getBorders()->getAllBorders()->setBorderStyle(\PhpOffice\PhpSpreadsheet\Style\Border::BORDER_THIN); + +// // Set column widths (optional for better visibility) +// $columns = range('A', 'T'); +// foreach ($columns as $col) { +// $sheet->getColumnDimension($col)->setAutoSize(true); +// } +// }, +// ]; +// } + + +// } + +// class MotorFreeRunExport implements FromCollection, WithMapping, WithStartRow +// { +// protected Collection $records; + +// public function __construct(Collection $records) +// { +// $this->records = $records; +// } + +// public function collection() +// { +// return $this->records; +// } + +// public function startRow(): int +// { +// return 3; // insert data starting from row 3 +// } + +// public function map($record): array +// { +// return [ +// $record['Date'] ?? '', +// $record['Output'] ?? '', +// $record['Motor SNo'] ?? '', +// $record['Item Code'] ?? '', +// $record['Motor Type'] ?? '', +// $record['kw'] ?? '', +// $record['hp'] ?? '', +// $record['phase'] ?? '', +// $record['isi_model'] ?? '', +// $record['Voltage_Before'] ?? '', +// $record['Current_Before'] ?? '', +// $record['Power_Before'] ?? '', +// $record['Resistance_RY'] ?? '', +// $record['Resistance_YB'] ?? '', +// $record['Resistance_BR'] ?? '', +// $record['Insulation_Resistance'] ?? '', +// $record['Frequency_Before'] ?? '', +// $record['Speed_Before'] ?? '', +// $record['Voltage_After'] ?? '', +// $record['Current_After'] ?? '', +// $record['Power_After'] ?? '', +// $record['IR_Hot'] ?? '', +// $record['IR_Cool'] ?? '', +// $record['Leakage_Current'] ?? '', +// $record['Frequency_After'] ?? '', +// $record['Speed_After'] ?? '', +// $record['Voltage_Locked'] ?? '', +// $record['Current_Locked'] ?? '', +// $record['Power_Locked'] ?? '', +// $record['No_Load_Pickup_Voltage'] ?? '', +// $record['Room_Temp'] ?? '', +// $record['High_Voltage_Test'] ?? '', +// $record['Batch_Number'] ?? '', +// $record['Batch_Count'] ?? '', +// $record['Result'] ?? '', +// $record['Remark'] ?? '', +// $record['Tested_By'] ?? '', +// ]; +// } +// } + + +class MotorFreeRunExport implements WithCustomStartCell, WithMapping, WithStartRow, WithChunkReading +{ + protected $records; + protected $templatePath; + + public function __construct($records) + { + $this->records = $records; + // dd($this->records); + } + + public function collection() + { + return $this->records; + } + + public function startRow(): int + { + return 7; // Start inserting data from row 7 + } + + public function startCell(): string + { + return 'A7'; // Start inserting data from row 7 column A + } + + public function map($record): array + { + return [ + $record['Date'] ?? '', + $record['Output'] ?? '', + $record['Motor SNo'] ?? '', + $record['Item Code'] ?? '', + $record['Motor Type'] ?? '', + $record['kw'] ?? '', + $record['hp'] ?? '', + $record['phase'] ?? '', + $record['isi_model'] ?? '', + $record['Voltage_Before'] ?? '', + $record['Current_Before'] ?? '', + $record['Power_Before'] ?? '', + $record['Resistance_RY'] ?? '', + $record['Resistance_YB'] ?? '', + $record['Resistance_BR'] ?? '', + $record['Insulation_Resistance'] ?? '', + $record['Frequency_Before'] ?? '', + $record['Speed_Before'] ?? '', + $record['Voltage_After'] ?? '', + $record['Current_After'] ?? '', + $record['Power_After'] ?? '', + $record['IR_Hot'] ?? '', + $record['IR_Cool'] ?? '', + $record['Leakage_Current'] ?? '', + $record['Frequency_After'] ?? '', + $record['Speed_After'] ?? '', + $record['Voltage_Locked'] ?? '', + $record['Current_Locked'] ?? '', + $record['Power_Locked'] ?? '', + $record['No_Load_Pickup_Voltage'] ?? '', + $record['Room_Temp'] ?? '', + $record['High_Voltage_Test'] ?? '', + $record['Batch_Number'] ?? '', + $record['Batch_Count'] ?? '', + $record['Result'] ?? '', + $record['Remark'] ?? '', + $record['Tested_By'] ?? '', + ]; + } + + public function chunkSize(): int + { + return 1000; // load 1000 records at a time + } +} diff --git a/app/Exports/TestingPanelReadingExport.php b/app/Exports/TestingPanelReadingExport.php new file mode 100644 index 0000000..1905771 --- /dev/null +++ b/app/Exports/TestingPanelReadingExport.php @@ -0,0 +1,159 @@ +ids = $ids; +// } +// public function query() +// { +// return TestingPanelReading::query() +// ->whereIn('id', $this->ids) +// ->select('id', 'plant_id', 'line_id', 'motor_testing_master_id', 'machine_id', 'output', 'serial_number', 'winded_serial_number', 'before_fr_volt', 'before_fr_cur', 'before_fr_pow', 'before_fr_res_ry', 'before_fr_res_yb', 'before_fr_res_br', 'before_fr_ir', 'before_fr_ir_r', 'before_fr_ir_y', 'before_fr_ir_b', 'before_fr_freq', 'before_fr_speed', 'after_fr_vol', 'after_fr_cur', 'after_fr_pow', 'after_fr_ir_hot','after_fr_ir_hot_r', 'after_fr_ir_hot_y', 'after_fr_ir_hot_b', 'after_fr_ir_cool', 'after_fr_ir_cool_r', 'after_fr_ir_cool_y', 'after_fr_ir_cool_b', 'after_fr_freq', 'after_fr_speed', 'after_fr_leak_cur', 'locked_rt_volt', 'locked_rt_cur', 'locked_rt_pow', 'no_load_pickup_volt', 'room_temperature', 'hv_test', 'batch_number', 'batch_count', 'result', 'remark', 'rework_count', 'update_count', 'output_flag', 'tested_by', 'updated_by', 'created_at', 'updated_at', 'scanned_at', 'created_at'); +// } + +// public function chunkSize(): int +// { +// return 1000; // process 1000 rows at a time +// } + +// public function headings(): array +// { +// return ['NO', 'PLANT', 'LINE', 'MOTORTESTINGMASTER', 'MACHINE', 'OUTPUT', 'SERIAL NUMBER', 'WINDED SERIAL NUMBER', 'BEFORE FR VOLT', 'BEFORE FR CUR', 'BEFORE FR POW', 'BEFORE FR RES RY', 'BEFORE FR RES YB', 'BEFORE FR RES BR', 'BEFORE FR IR', 'BEFORE FR IR R', 'BEFORE FR IR Y', 'BEFORE FR IR B', 'BEFORE FR FREQ', 'BEFORE FR SPEED', 'AFTER FR VOL', 'AFTER FR CUR', 'AFTER FR POW', 'AFTER FR IR HOT', 'AFTER FR IR HOT R', 'AFTER FR IR HOT Y', 'AFTER FR IR HOT B', 'AFTER FR IR COOL', 'AFTER FR IR COOL R', 'AFTER FR IR COOL Y', 'AFTER FR IR COOL B', 'AFTER FR FREQ', 'AFTER FR SPEED', 'AFTER FR LEAK CUR', 'LOCKED RT VOLT', 'LOCKED RT CUR', 'LOCKED RT POW', 'NO LOAD PICKUP VOLT', 'ROOM TEMPERATURE', 'HV TEST', 'BATCH NUMBER', 'BATCH COUNT', 'RESULT', 'REMARK', 'REWORK COUNT', 'UPDATE COUNT', 'OUTPUT FLAG', 'TETSED BY', 'UPDATED BY', 'CREATED AT', 'UPDATED AT', 'SCANNED AT', 'CREATED AT']; +// } + +// public function map($record): array +// { +// $this->counter++; +// return [ +// $this->counter, // No. +// $record->plant_id, +// $record->line_id, +// $record->motor_testing_master_id, +// $record->machine_id, +// $record->output, +// $record->serial_number, +// $record->winded_serial_number, +// $record->before_fr_volt, +// $record->before_fr_cur, +// $record->before_fr_pow, +// $record->before_fr_res_ry, +// $record->before_fr_res_yb, +// $record->before_fr_res_br, +// $record->before_fr_ir, +// $record->before_fr_ir_r, +// $record->before_fr_ir_y, +// $record->before_fr_ir_b, +// $record->before_fr_freq, +// $record->before_fr_speed, +// $record->after_fr_vol, +// $record->after_fr_cur, +// $record->after_fr_pow, +// $record->after_fr_ir_hot, +// $record->after_fr_ir_hot_r, +// $record->after_fr_ir_hot_y, +// $record->after_fr_ir_hot_b, +// $record->after_fr_ir_cool, +// $record->after_fr_ir_cool_r, +// $record->after_fr_ir_cool_y, +// $record->after_fr_ir_cool_b, +// $record->after_fr_freq, +// $record->after_fr_speed, +// $record->after_fr_leak_cur, +// $record->locked_rt_volt, +// $record->locked_rt_cur, +// $record->locked_rt_pow, +// $record->no_load_pickup_volt, +// $record->room_temperature, +// $record->hv_test, +// $record->batch_number, +// $record->batch_count, +// $record->result, +// $record->remark, +// $record->rework_count, +// $record->update_count, +// $record->output_flag, +// $record->tested_by, +// $record->updated_by, +// // $record->created_at, +// $record->updated_at, +// $record->scanned_at, +// $record->created_at, +// ]; +// } +// } + +class TestingPanelReadingExport implements FromCollection, WithHeadings +{ + protected $records; + protected $isAllStarDelta; + + public function __construct($records, $isAllStarDelta) + { + $this->records = $records; + $this->isAllStarDelta = $isAllStarDelta; + } + + public function collection() + { + return collect($this->records)->map(function ($record) { + if (!$this->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 ?? '', + 'IR_Hot' => $record['after_fr_ir_hot'] ?? '', + 'IR_Cool' => $record['after_fr_ir_cool'] ?? '', + 'Leakage_Current' => $record['after_fr_leak_cur'] ?? '', + ]; + } else { + 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 ?? '', + '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'] ?? '', + ]; + } + }); + } + + public function headings(): array + { + return array_keys($this->collection()->first() ?? []); + } +}