<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Rekap_chasmix extends MBELINK_Controller {
	
	public function __construct()
	{
		parent::__construct();
		
		$this->load->library(array('session'));
		$this->load->helper(array('rsonline'));
				 
		// User Login Information
		$this->data['user'] = user_info();
		$this->data['instansi'] = orgInfo();
		
		// Cek Sesi
		 if(! $this->session->userdata('userid')):
			redirect(base_url('login-system.html'), 'refresh');
		endif;
		//Ngaeng-ngaeng
		$this->load->model('masuk_model');
		$this->load->model('report/rekap_chasmix_model');
		//$this->load->model('info_model');
	}
	
	public function index()
	{
		$this->load->view('report/rekap_chasmix');
	}
	
	function hasilRekapChasmix()
	{
		$this->data['followup']=$this->input->post('followup');
		//$this->data['statusx']=$this->input->post('statusx');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		
		if(! $this->data['followup']==''){
			$followupx="a.`FollowUp`='".$this->data['followup']."' AND";
		}else{
			$followupx="";
		}
		
		/* if(! $this->data['statusx']==''){
			$status_pasien="a.`Pulang`='".$this->data['statusx']."' AND";
		}else{
			$status_pasien="";
		} */
		
		if($this->data['tglakhir'] < $this->data['tglawal']){
			$this->session->set_flashdata('error', 'Tanggal Akhir yang di masukkan Harus Lebih Besar atau Sama dengan Tanggal Awal');	
			redirect(base_url('rekap-chasmix.html'));
		}else{
			$this->data['result']=$this->rekap_chasmix_model->hasilRekapChasmixBPJS($followupx,$this->data['tglawal'],$this->data['tglakhir']);
		
			//print_r($_POST);
			$this->load->view('report/result_rekap_bpjs_chasmix', $this->data);
		}
	}
	
	function exspToExcelChasmix()
	{
		$this->data['followup']=$this->input->post('followup');		
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		
		if(! $this->data['followup']==''){
			$followupx="a.`FollowUp`='".$this->data['followup']."' AND";
		}else{
			$followupx="";
		}
				
		$this->data['result']=$this->rekap_chasmix_model->hasilRekapChasmixBPJS($followupx,$this->data['tglawal'],$this->data['tglakhir']);
	
		//print_r($_POST);
		$this->load->view('report/result_rekap_bpjs_chasmix_to_excel', $this->data);
		
	}
	
	function hasilRekapChasmixLab()
	{
		$this->data['followup']=$this->input->post('followup');
		//$this->data['statusx']=$this->input->post('statusx');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		if(isset($_POST['bProses'])){
			if(! $this->data['followup']==''){
				$followupx="a.`FollowUp`='".$this->data['followup']."' AND";
			}else{
				$followupx="";
			}
			
			/* if(! $this->data['statusx']==''){
				$status_pasien="a.`Pulang`='".$this->data['statusx']."' AND";
			}else{
				$status_pasien="";
			} */
			
			if($this->data['tglakhir'] < $this->data['tglawal']){
				$this->session->set_flashdata('error', 'Tanggal Akhir yang di masukkan Harus Lebih Besar atau Sama dengan Tanggal Awal');	
				redirect(base_url('rekap-chasmix-laborat.html'));
			}else{
				$this->data['result']=$this->rekap_chasmix_model->hasilRekapChasmixBPJSLab($followupx,$this->data['tglawal'],$this->data['tglakhir']);
			
				
			}
		}
		//print_r($_POST);
		$this->load->view('report/rekap_chasmix_lab', $this->data);
	}
	
	function hasilRekapChasmixRadio()
	{
		$this->data['followup']=$this->input->post('followup');
		//$this->data['statusx']=$this->input->post('statusx');
		$this->data['tglawal']=$this->input->post('tglawal');
		$this->data['tglakhir']=$this->input->post('tglakhir');
		if(isset($_POST['bProses'])){
			if(! $this->data['followup']==''){
				$followupx="a.`FollowUp`='".$this->data['followup']."' AND";
			}else{
				$followupx="";
			}
			
			/* if(! $this->data['statusx']==''){
				$status_pasien="a.`Pulang`='".$this->data['statusx']."' AND";
			}else{
				$status_pasien="";
			} */
			
			if($this->data['tglakhir'] < $this->data['tglawal']){
				$this->session->set_flashdata('error', 'Tanggal Akhir yang di masukkan Harus Lebih Besar atau Sama dengan Tanggal Awal');	
				redirect(base_url('rekap-chasmix-radiologi.html'));
			}else{
				$this->data['result']=$this->rekap_chasmix_model->hasilRekapChasmixBPJSRadio($followupx,$this->data['tglawal'],$this->data['tglakhir']);
			
				
			}
		}
		//print_r($_POST);
		$this->load->view('report/rekap_chasmix_rad', $this->data);
	}
	
}
