public function generateCode() { $last = Rpd::select('kode')->orderBy('kode', 'desc')->first(); if (empty($last['kode'])) { return "RPD0001"; } else { $no = str_replace('RPD', '', $last['kode']); $no = (int) $no + 1; $new = 'RPD' . str_pad($no, 4, '0', STR_PAD_LEFT); return $new; } }
public function homepage() { $rpds = Rpd::mine()->where('status', 'BACK TO INITIATOR')->orWhere('status', 'SUBMIT')->paginate(10); $lpds = Lpd::mine()->where('status', 'BACK TO INITIATOR')->orWhere('status', 'SUBMIT')->orWhere('status', 'TAKE PAYMENT')->where('status', 'BACK TO INITIATOR')->orWhere('status', 'PROCESS PAYMENT')->paginate(10); return view('homepage', compact('rpds', 'lpds')); }
public function draft() { $approvedRpds = Rpd::approved()->mine()->paginate(15); return view('lpd.draft', compact('approvedRpds')); }
public function pelatihan(Request $request) { $month = $request->input('month', date('m')); $year = $request->input('year', date('Y')); // Cari Perjalanan Dinas pada waktu tertentu $rpds = Rpd::with('lpd')->whereRaw('(MONTH(tanggal_mulai) = ' . $month . ' OR MONTH(tanggal_selesai) = ' . $month . ')')->whereRaw('(YEAR(tanggal_mulai) = ' . $year . ' OR YEAR(tanggal_selesai) = ' . $year . ')')->where('status', 'APPROVED')->get(); $biayaPelatihan = []; if ($rpds->count() > 0) { // Cari pelatihan untuk semua kegiatan yang ada di perjalanan dinas foreach ($rpds as $rpd) { // Cek LPD if (!is_null($rpd->lpd)) { if ($rpd->lpd->status == 'PAID' || $rpd->lpd->status == 'PAYMENT RECEIVED') { $bobotKegiatan = []; // Hitung bobot tiap peserta foreach ($rpd->peserta as $peserta) { $bobotKegiatan[$peserta->nik] = $peserta->kegiatan->where('id_rpd', $rpd->id)->count(); } // Get data pengeluaran foreach ($rpd->lpd->pengeluaran()->whereRaw('MONTH(tanggal) = ' . $month)->whereRaw('YEAR(tanggal) = ' . $year)->get() as $pengeluaran) { $bobotPelatihan = []; $bobotPerPengeluaran = 0; // Hitung bobot pelatihan per pengeluaran foreach ($pengeluaran->personel as $personel) { $trainings = $personel->kegiatan()->where('jenis_kegiatan', 'pelatihan')->where('id_rpd', $rpd->id)->lists('kode_kegiatan'); foreach ($trainings as $pelatihan) { if (array_key_exists($pelatihan, $bobotPelatihan)) { $bobotPelatihan[$pelatihan] += 1; } else { $bobotPelatihan[$pelatihan] = 1; } } if (array_key_exists($personel->nik, $bobotKegiatan)) { $bobotPerPengeluaran += $bobotKegiatan[$personel->nik]; } } // Distribusi biaya if ($bobotPerPengeluaran > 0) { $biayaPerKegiatan = $pengeluaran->biaya / $bobotPerPengeluaran; } else { $biayaPerKegiatan = 0; } // Hitung biaya per pelatihan foreach ($bobotPelatihan as $id => $bobot) { if (array_key_exists($id, $biayaPelatihan)) { $biayaPelatihan[$id] += $bobot * $biayaPerKegiatan; } else { $biayaPelatihan[$id] = $bobot * $biayaPerKegiatan; } } } } } if (!isset($activities)) { $activities = $rpd->kegiatan()->where('jenis_kegiatan', 'pelatihan')->get(); } else { $activities = $activities->merge($rpd->kegiatan()->where('jenis_kegiatan', 'pelatihan')->get()); } } $activities = $activities->unique('kode_kegiatan'); } else { $activities = collect([]); } return view('reports.pelatihan', compact('activities', 'biayaPelatihan', 'request')); }