getActiveSheet(); $rows = $sheet->toArray(null, true, true, true); $service = new InceptNebAllocation(); $now = date('Y-m-d H:i:s'); $count = 0; foreach ($rows as $index => $row) { if ($index === 1) { continue; } $empId = $service->normalizeEmpId($row['A'] ?? ''); if ($empId === '' || strcasecmp($empId, 'EMP ID') === 0) { continue; } DB::table('incept_neb_allocations')->updateOrInsert( ['emp_id' => $empId], [ 'emp_name' => $this->clean($row['B'] ?? ''), 'team' => $this->clean($row['C'] ?? ''), 'designation' => $this->clean($row['D'] ?? ''), 'robust_qty' => max(0, (int) ($row['E'] ?? 0)), 'mini_qty' => max(0, (int) ($row['F'] ?? 0)), 'control_d_qty' => max(0, (int) ($row['G'] ?? 0)), 'updated_at' => $now, 'created_at' => $now, ] ); $count++; } if (isset($this->command)) { $this->command->info('Imported ' . $count . ' nebulizer allocations.'); } } private function clean($value) { $value = str_replace("\xc2\xa0", ' ', (string) $value); $value = preg_replace('/\s+/', ' ', $value); return trim($value); } }