<?php
namespace App\Imports;
use App\Models\KalenderJadwal;
use App\Models\Karyawan;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
class KalendersImport implements ToCollection
{
public function collection(Collection $rows)
{
# jika datanya banyak
ini_set('memory_limit','1024M');
# max execution time
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
$tanggals = [];
foreach ($rows as $row) {
if (count($row) > 3) {
if (strtolower($row[0]) == "no") {
for ($i = 4; $i < count($row); $i++) {
$tanggals[] = trim($row[$i]);
}
} else if(isset($row[4]) && count($tanggals) > 0) {
$karyawan = Karyawan::where('nik', trim($row[1]))
// ->where('nama', $row[2])
->first();
if($karyawan){
for ($i = 4; $i < count($row); $i++) {
if(isset($tanggals[$i-4])){
KalenderJadwal::updateOrCreate([
'karyawan_id' => $karyawan->id,
'tanggal' => $tanggals[$i-4],
],[
'status' => strtolower(trim($row[$i]))
]);
}
}
}
}
}
}
// return new KalenderJadwal([
// //
// ]);
}
}
Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]