umkm-app/application/controllers/admin/HapusAbsen.php

61 lines
1.6 KiB
PHP
Raw Permalink Normal View History

2021-09-15 21:00:06 +07:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class HapusAbsen extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model("UserModel");
$this->load->model("AbsenModel");
$this->load->model("AbsensiModel");
$this->load->model("LaporanModel");
if($this->UserModel->isNotLogin()) {
redirect(site_url('login'));
} elseif(!($this->UserModel->isAdmin())) {
redirect(site_url('dashboard'));
}
$get = $this->input->get();
if($get['id_absen']==NULL){
redirect(site_url('admin/daftarabsen'));
}
}
public function index()
{
$get = $this->input->get();
$absen = $this->AbsenModel->getAbsenById($get['id_absen']);
$count = $this->AbsensiModel->getSignedAbsensiCountByAbsenId($get['id_absen']);
$countlaporan = $this->LaporanModel->getLaporanCountByYear($get['tahun']);
if($countlaporan>0){
redirect(site_url('admin/daftarabsen?del_msg=errorlaporan&absen='.$absen->bulan.'&tahunabsen='.$get['tahun']));
} elseif($count>0){
redirect(site_url('admin/daftarabsen?del_msg=error&absen='.$absen->bulan.'&tahunabsen='.$get['tahun']));
} else {
$daftarabsensi = $this->AbsensiModel->getAbsensiByAbsenId($get['id_absen']);
foreach($daftarabsensi as $absensi){
$this->AbsensiModel->delete($absensi->id_absensi);
}
$this->AbsenModel->delete($get['id_absen']);
redirect(site_url('admin/daftarabsen?del_msg=success&tahunabsen='.$get['tahun'].'&absen='));
}
$data['absen'] = $absen;
$data['user_logged'] = $this->session->userdata('user_logged');
}
}