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

169 lines
5.8 KiB
PHP

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class TutupTahun extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model("AbsenModel");
$this->load->model("AbsensiModel");
$this->load->model("UserModel");
$this->load->model("KelurahanModel");
$this->load->model("LaporanModel");
$this->load->model("UmkmModel");
if($this->UserModel->isNotLogin()) {
redirect(site_url('login'));
} elseif(!($this->UserModel->isAdmin())) {
redirect(site_url('user/sdashboard'));
}
$get = $this->input->get();
if($get['tahun']==NULL){
redirect(site_url('admin/progresabsen'));
} else {
$this->tahun = $get['tahun'];
}
}
public function index()
{
$tahun = $this->tahun;
$coutAbsen = $this->AbsenModel->getAbsenCountByYear($tahun);
//cek absen lengkap 12 bulan atau tidak
if($coutAbsen<12){
redirect(site_url('admin/progresabsen?tahun='.$tahun.'&msg=error!'));
die();
} else {
$listabsen = $this->AbsenModel->getAbsensByTahun($tahun);
foreach($listabsen as $absen){
$this->AbsenModel->setCloseAbsen($absen->id_absen);
$omset = 0;
$aset = 0;
$karyawan_l = 0;
$karyawan_p = 0;
$listabsensi = $this->AbsensiModel->getAbsensiByBulanAndThn($absen->bulan,$tahun);
foreach($listabsensi as $absensi){
$this->AbsensiModel->absenBySystem($absensi->id_absensi);
$omset = $omset + $absensi->omset;
$aset = $aset + $absensi->aset;
$karyawan_l = $karyawan_l + $absensi->karyawan_l;
$karyawan_p = $karyawan_p + $absensi->karyawan_p;
$omset_tahunan_umkm=0;
$listabsensiumkm = $this->AbsensiModel->getAbsensiByTahunAndUmkmId($tahun,$absensi->id_umkm);
foreach($listabsensiumkm as $absensiumkm){
$omset_tahunan_umkm = $omset_tahunan_umkm + $absensiumkm->omset;
}
$this->UmkmModel->updateOmset($absensi->id_umkm,$omset_tahunan_umkm);
}
$this->AbsenModel->update($absen->id_absen,$omset,$aset,$karyawan_l,$karyawan_p);
}
$listkelurahan = $this->KelurahanModel->getKelurahan();
foreach($listkelurahan as $kelurahan){
$kecamatan = $kelurahan->kecamatan;
$aset=0;
$omset=0;
$jumlah_umkm = 0;
$karyawan_jenis1 = 0;
$karyawan_jenis2 = 0;
$karyawan_jenis3 = 0;
$omset_jenis1 = 0;
$omset_jenis2 = 0;
$omset_jenis3 = 0;
$aset_jenis1 = 0;
$aset_jenis2 = 0;
$aset_jenis3 = 0;
$karyawan_jen1_l = 0;
$karyawan_jen1_p = 0;
$karyawan_jen2_l = 0;
$karyawan_jen2_p = 0;
$karyawan_jen3_l = 0;
$karyawan_jen3_p = 0;
$umkm_jen1_kat1 = 0;
$umkm_jen1_kat2 = 0;
$umkm_jen1_kat3 = 0;
$umkm_jen2_kat1 = 0;
$umkm_jen2_kat2 = 0;
$umkm_jen2_kat3 = 0;
$umkm_jen3_kat1 = 0;
$umkm_jen3_kat2 = 0;
$umkm_jen3_kat3 = 0;
$listabsensiupdated = $this->AbsensiModel->getAbsensByTahunAndKelurahan($tahun,$kelurahan->kelurahan);
foreach($listabsensiupdated as $updatedabsensi){
$aset = $aset+$updatedabsensi->aset;
$omset = $omset+$updatedabsensi->omset;
$jumlah_umkm++;
$karyawan = $updatedabsensi->karyawan_l + $updatedabsensi->karyawan_p;
if($updatedabsensi->id_jenis=='1'){
$karyawan_jenis1 = $karyawan_jenis1 + $karyawan;
$omset_jenis1 = $omset_jenis1 + $updatedabsensi->omset;
$aset_jenis1 = $aset_jenis1 + $updatedabsensi->aset;
$karyawan_jen1_l = $karyawan_jen1_l +$updatedabsensi->karyawan_l;
$karyawan_jen1_p = $karyawan_jen1_p +$updatedabsensi->karyawan_p;
}elseif($updatedabsensi->id_jenis=='2'){
$karyawan_jenis2 = $karyawan_jenis2 + $karyawan;
$omset_jenis2 = $omset_jenis2 + $updatedabsensi->omset;
$aset_jenis2 = $aset_jenis2 + $updatedabsensi->aset;
$karyawan_jen2_l = $karyawan_jen2_l +$updatedabsensi->karyawan_l;
$karyawan_jen2_p = $karyawan_jen2_p +$updatedabsensi->karyawan_p;
}elseif($updatedabsensi->id_jenis=='3'){
$karyawan_jenis3 = $karyawan_jenis3 + $karyawan;
$omset_jenis3 = $omset_jenis3 + $updatedabsensi->omset;
$aset_jenis3 = $aset_jenis3 + $updatedabsensi->aset;
$karyawan_jen3_l = $karyawan_jen3_l +$updatedabsensi->karyawan_l;
$karyawan_jen3_p = $karyawan_jen3_p +$updatedabsensi->karyawan_p;
}
if(($updatedabsensi->id_jenis=='1')AND($updatedabsensi->id_kategori=='1')){
$umkm_jen1_kat1++;
}elseif(($updatedabsensi->id_jenis=='1')AND($updatedabsensi->id_kategori=='2')){
$umkm_jen1_kat2++;
}elseif(($updatedabsensi->id_jenis=='1')AND($updatedabsensi->id_kategori=='3')){
$umkm_jen1_kat3++;
}elseif(($updatedabsensi->id_jenis=='2')AND($updatedabsensi->id_kategori=='1')){
$umkm_jen2_kat1++;
}elseif(($updatedabsensi->id_jenis=='2')AND($updatedabsensi->id_kategori=='2')){
$umkm_jen2_kat2++;
}elseif(($updatedabsensi->id_jenis=='2')AND($updatedabsensi->id_kategori=='3')){
$umkm_jen2_kat3++;
}elseif(($updatedabsensi->id_jenis=='3')AND($updatedabsensi->id_kategori=='1')){
$umkm_jen3_kat1++;
}elseif(($updatedabsensi->id_jenis=='3')AND($updatedabsensi->id_kategori=='2')){
$umkm_jen3_kat2++;
}elseif(($updatedabsensi->id_jenis=='3')AND($updatedabsensi->id_kategori=='3')){
$umkm_jen3_kat3++;
}
$this->LaporanModel->save($tahun,$updatedabsensi->bulan,$kelurahan->kelurahan,$kecamatan,$aset,$omset,$jumlah_umkm,$karyawan_jenis1,$karyawan_jenis2,$karyawan_jenis3,$omset_jenis1,$omset_jenis2,$omset_jenis3,$aset_jenis1,$aset_jenis2,$aset_jenis3,$karyawan_jen1_l,$karyawan_jen1_p,$karyawan_jen2_l,$karyawan_jen2_p,$karyawan_jen3_l,$karyawan_jen3_p,$umkm_jen1_kat1,$umkm_jen1_kat2,$umkm_jen1_kat3,$umkm_jen2_kat1,$umkm_jen2_kat2,$umkm_jen2_kat3,$umkm_jen3_kat1,$umkm_jen3_kat2,$umkm_jen3_kat3);
}
}
}
redirect(site_url('admin/progresabsen?tahun='.$tahun.'&msg=success'));
die();
}
}