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

class DashboardLaporan extends CI_Controller
{

    // CONSTRUCT
    public function __construct()
    {
        parent::__construct();
        $this->load->helper('form');
        $this->load->library('form_validation');
        $this->load->model('M_Utama');
        $this->load->model('M_user');
        $this->load->helper('url');

        if (!$this->session->userdata('username')) {
            redirect('login');
        }
    }

    public function index()
    {
        $tgl = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();

        $this->load->view('laporan/index', $data);
    }

    public function icd()
    {
        extract($_GET);
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['icd'] = $this->db->query("select e.diagnosa_primer,i.DESCRPTION, COUNT(e.diagnosa_primer) as total  from erm_pemeriksaan_fisik e 
        join ICD9 i on i.ICD_CODE = e.diagnosa_primer
        join cases c on c.[Case ID] = e.case_id
        where c.[Intake Date] between '$tgl1' and '$tgl1'
        group by e.diagnosa_primer,i.DESCRPTION order by total desc")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/icd', $data);
        $this->load->view('properti/footer', $data);
    }

    public function cariicd()
    {
        extract($_GET);
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();

        $data['icd'] = $this->db->query("select e.diagnosa_primer,i.DESCRPTION, COUNT(e.diagnosa_primer) as total  from erm_pemeriksaan_fisik e 
        join ICD9 i on i.ICD_CODE = e.diagnosa_primer
        join cases c on c.[Case ID] = e.case_id
        where c.[Intake Date] between '$tgl1' and '$tgl2'
        group by e.diagnosa_primer,i.DESCRPTION order by total desc")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/icd', $data);
        $this->load->view('properti/footer', $data);
    }

    public function exportICD()
	{
        extract($_GET);
		ini_set('memory_limit', '5120M'); // This also needs to be increased in some cases. Can be changed to a higher value as per need)
		ini_set('sqlsrv.ClientBufferMaxKBSize', '4718592'); // Setting to 512M
		ini_set('pdo_sqlsrv.client_buffer_max_kb_size', '4718592'); // Setting to 512M - for pdo_sqlsrv

		$this->load->library('excel');
		$fileName = 'Top 10 ICD' . ' ' . date('dmYHis') . '.xlsx';

		$qdata = $this->db->query("select e.diagnosa_primer,i.DESCRPTION, COUNT(e.diagnosa_primer) as total  from erm_pemeriksaan_fisik e 
        join ICD9 i on i.ICD_CODE = e.diagnosa_primer
        join cases c on c.[Case ID] = e.case_id
        where c.[Intake Date] between '$tglpertama' and '$tglkedua'
        group by e.diagnosa_primer,i.DESCRPTION order by total desc")->result_array();

		$objPHPExcel = new PHPExcel();
		$objPHPExcel->setActiveSheetIndex(0);

		$objPHPExcel->getActiveSheet()->setCellValue('A1', 'No');
		$objPHPExcel->getActiveSheet()->setCellValue('B1', 'ICD CODE');
        $objPHPExcel->getActiveSheet()->setCellValue('C1', 'Description');
		$objPHPExcel->getActiveSheet()->setCellValue('D1', 'Jumlah');

		$rowCount = 2;
		foreach ($qdata as $list) {
			$objPHPExcel->getActiveSheet()->setCellValue('A'  . $rowCount, $no++);
			$objPHPExcel->getActiveSheet()->setCellValue('B'  . $rowCount, $list["diagnosa_primer"]);
			$objPHPExcel->getActiveSheet()->setCellValue('C'  . $rowCount, $list["DESCRPTION"]);
            $objPHPExcel->getActiveSheet()->setCellValue('D'  . $rowCount, $list["total"]);

			$rowCount++;
		}

		$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);
		$objWriter->save($fileName);

		header("Content-Type: application/vnd.ms-excel");
		redirect(site_url() . $fileName);
	}

    public function Lhp()
    {
        extract($_GET);
        $datenow  = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['lhp'] = $this->db->query("SELECT
        VPENJUALANRAWATJALAN.FARMASI, VPENJUALANRAWATJALAN.ADM, VPENJUALANRAWATJALAN.LABORATORY,
        VPENJUALANRAWATJALAN.UMUM, VPENJUALANRAWATJALAN.TINDAKAN, VPENJUALANRAWATJALAN.POLI_GIGI,
        VPENJUALANRAWATJALAN.PAYMENT, VPENJUALANRAWATJALAN.[Case ID],
        Cases.Description, Cases.[Intake Date], Cases.RegStatus,Company.CompanyName,
        VTotalCharge.Total,VTotalPayment.TotalPayment
         FROM VPENJUALANRAWATJALAN INNER JOIN Cases ON
         VPENJUALANRAWATJALAN.[Case ID] = Cases.[Case ID]
         INNER JOIN  VTotalCharge ON Cases.[Case ID] = VTotalCharge.[Case Id]
         INNER JOIN Company ON Cases.CompanyCode = Company.CompanyCode
         LEFT OUTER JOIN VTotalPayment ON VTotalCharge.[Case Id] = VTotalPayment.[Case ID] 
         where Cases.[Intake Date] between '$datenow' and '$datenow' and Company.CompanyCode != 102")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/LHP', $data);
        $this->load->view('properti/footer', $data);
    }

    public function carilhp()
    {
        extract($_GET);
        $datenow  = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['lhp'] = $this->db->query("SELECT
        VPENJUALANRAWATJALAN.FARMASI, VPENJUALANRAWATJALAN.ADM, VPENJUALANRAWATJALAN.LABORATORY,
        VPENJUALANRAWATJALAN.UMUM, VPENJUALANRAWATJALAN.TINDAKAN, VPENJUALANRAWATJALAN.POLI_GIGI,
        VPENJUALANRAWATJALAN.PAYMENT, VPENJUALANRAWATJALAN.[Case ID],
        Cases.Description, Cases.[Intake Date], Cases.RegStatus,Company.CompanyName,
        VTotalCharge.Total,VTotalPayment.TotalPayment
         FROM VPENJUALANRAWATJALAN INNER JOIN Cases ON
         VPENJUALANRAWATJALAN.[Case ID] = Cases.[Case ID]
         INNER JOIN  VTotalCharge ON Cases.[Case ID] = VTotalCharge.[Case Id]
         INNER JOIN Company ON Cases.CompanyCode = Company.CompanyCode
         LEFT OUTER JOIN VTotalPayment ON VTotalCharge.[Case Id] = VTotalPayment.[Case ID] 
         where Cases.[Intake Date] between '$tgl1' and '$tgl2' and Company.CompanyCode != 102")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/LHP', $data);
        $this->load->view('properti/footer', $data);
    }

    public function lhpbpjs()
    {
        extract($_GET);
        $datenow  = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['lhpbpjs'] = $this->db->query("SELECT 
        VPENJUALANRAWATJALAN.FARMASI, VPENJUALANRAWATJALAN.ADM, VPENJUALANRAWATJALAN.LABORATORY, 
        VPENJUALANRAWATJALAN.UMUM, VPENJUALANRAWATJALAN.TINDAKAN, VPENJUALANRAWATJALAN.POLI_GIGI,
        VPENJUALANRAWATJALAN.PAYMENT, VPENJUALANRAWATJALAN.TOTAL, VPENJUALANRAWATJALAN.PHYSIOTERAPI,
        VPENJUALANRAWATJALAN.INHALASI, VPENJUALANRAWATJALAN.BIDAN, VPENJUALANRAWATJALAN.MESSAGE, 
        VPENJUALANRAWATJALAN.ALKES, VPENJUALANRAWATJALAN.[Case ID], VPENJUALANRAWATJALAN.CompanyName,
        Cases.Description, Cases.[Intake Date],
        Company.CompanyName,VTotalCharge.Total, VTotalPayment.TotalPayment
        FROM VPENJUALANRAWATJALAN INNER JOIN  Cases ON
            VPENJUALANRAWATJALAN.[Case ID] = Cases.[Case ID]
         INNER JOIN Company Company ON
            Cases.CompanyCode = Company.CompanyCode
         LEFT OUTER JOIN Kalideres.dbo.VTotalCharge VTotalCharge ON
            Cases.[Case ID] = VTotalCharge.[Case Id]
         LEFT OUTER JOIN Kalideres.dbo.VTotalPayment VTotalPayment ON
            VTotalCharge.[Case Id] = VTotalPayment.[Case ID] WHERE
        VPENJUALANRAWATJALAN.CompanyName = 'BPJS KESEHATAN' and Cases.[Intake Date] between '$datenow' and '$datenow'")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/LHPBPJS', $data);
        $this->load->view('properti/footer', $data);
    }

    public function carilhpbpjs()
    {
        extract($_GET);
        $datenow  = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['lhpbpjs'] = $this->db->query("SELECT 
        VPENJUALANRAWATJALAN.FARMASI, VPENJUALANRAWATJALAN.ADM, VPENJUALANRAWATJALAN.LABORATORY, 
        VPENJUALANRAWATJALAN.UMUM, VPENJUALANRAWATJALAN.TINDAKAN, VPENJUALANRAWATJALAN.POLI_GIGI,
        VPENJUALANRAWATJALAN.PAYMENT, VPENJUALANRAWATJALAN.TOTAL, VPENJUALANRAWATJALAN.PHYSIOTERAPI,
        VPENJUALANRAWATJALAN.INHALASI, VPENJUALANRAWATJALAN.BIDAN, VPENJUALANRAWATJALAN.MESSAGE, 
        VPENJUALANRAWATJALAN.ALKES, VPENJUALANRAWATJALAN.[Case ID], VPENJUALANRAWATJALAN.CompanyName,
        Cases.Description, Cases.[Intake Date],
        Company.CompanyName,VTotalCharge.Total, VTotalPayment.TotalPayment
        FROM VPENJUALANRAWATJALAN INNER JOIN  Cases ON
            VPENJUALANRAWATJALAN.[Case ID] = Cases.[Case ID]
         INNER JOIN Company Company ON
            Cases.CompanyCode = Company.CompanyCode
         LEFT OUTER JOIN Kalideres.dbo.VTotalCharge VTotalCharge ON
            Cases.[Case ID] = VTotalCharge.[Case Id]
         LEFT OUTER JOIN Kalideres.dbo.VTotalPayment VTotalPayment ON
            VTotalCharge.[Case Id] = VTotalPayment.[Case ID] WHERE
        VPENJUALANRAWATJALAN.CompanyName = 'BPJS KESEHATAN' and Cases.[Intake Date] between '$tgl1' and '$tgl2'")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/LHPBPJS', $data);
        $this->load->view('properti/footer', $data);  
    }

    public function totalpatientbycompany()
    {
        extract($_GET);
        $datenow  = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['patientbycompany'] = $this->db->query("SELECT 
        Company.CompanyName,
        count(company.CompanyName) as total,
        sum(VTotalCharge.Total) as charge,
        sum(VPaymentOK.AmountPaid) as slisih
        FROM Cases INNER JOIN VTotalCharge ON Cases.[Case ID] = VTotalCharge.[Case Id]
         INNER JOIN Company ON Cases.CompanyCode = Company.CompanyCode
         LEFT OUTER JOIN VPaymentOK ON
         Cases.[Case ID] = VPaymentOK.[Case ID] where Cases.[Intake Date] = '$datenow'
        group BY Company.CompanyCode, Company.CompanyName")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/TotalPatientByCompany', $data);
        $this->load->view('properti/footer', $data);

    }

    public function caritotalCompany()
    {
        extract($_GET);
        $datenow  = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['patientbycompany'] = $this->db->query("SELECT 
        Company.CompanyName,
        count(company.CompanyName) as total,
        sum(VTotalCharge.Total) as charge,
        sum(VPaymentOK.AmountPaid) as slisih
        FROM Cases INNER JOIN VTotalCharge ON Cases.[Case ID] = VTotalCharge.[Case Id]
         INNER JOIN Company ON Cases.CompanyCode = Company.CompanyCode
         LEFT OUTER JOIN VPaymentOK ON
         Cases.[Case ID] = VPaymentOK.[Case ID] where Cases.[Intake Date] between '$tgl1' and '$tgl2'
        group BY Company.CompanyCode, Company.CompanyName")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/TotalPatientByCompany', $data);
        $this->load->view('properti/footer', $data);
    }

    public function totalpatientbytretment()
    {
        extract($_GET);
        $datenow  = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['ass'] = $this->db->query("SELECT
        VPatientVisitPerUnit.Category,count(Cases.CompanyCode) as Ass FROM
        VPatientVisitPerUnit INNER JOIN  Cases 
        ON VPatientVisitPerUnit.[Case ID] = Cases.[Case ID] WHERE
         Cases.[Case Status] = 'CLOSED' and Cases.CompanyCode= 102 and 
         Cases.[Intake Date] between '$datenow' and '$datenow'
         group by VPatientVisitPerUnit.Category,
         Cases.CompanyCode")->result_array();

        $data['case'] = $this->db->query("SELECT
        VPatientVisitPerUnit.Category,count(Cases.CompanyCode) as cash FROM
        VPatientVisitPerUnit INNER JOIN  Cases 
        ON VPatientVisitPerUnit.[Case ID] = Cases.[Case ID] WHERE
        Cases.[Case Status] = 'CLOSED' and Cases.CompanyCode= 1 and 
        Cases.[Intake Date] between '$datenow' and '$datenow'
        group by VPatientVisitPerUnit.Category,
        Cases.CompanyCode")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/TotalPatientBytratment', $data);
        $this->load->view('properti/footer', $data);
    }

    public function caripatientbytretment()
    {
        extract($_GET);
        $datenow  = date('Y-m-d');
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['ass'] = $this->db->query("SELECT
        VPatientVisitPerUnit.Category,count(Cases.CompanyCode) as Ass FROM
        VPatientVisitPerUnit INNER JOIN  Cases 
        ON VPatientVisitPerUnit.[Case ID] = Cases.[Case ID] WHERE
         Cases.[Case Status] = 'CLOSED' and Cases.CompanyCode= 102 and 
         Cases.[Intake Date] between '$tgl1' and '$tgl2'
         group by VPatientVisitPerUnit.Category,
         Cases.CompanyCode")->result_array();

        $data['case'] = $this->db->query("SELECT
        VPatientVisitPerUnit.Category,count(Cases.CompanyCode) as cash FROM
        VPatientVisitPerUnit INNER JOIN  Cases 
        ON VPatientVisitPerUnit.[Case ID] = Cases.[Case ID] WHERE
        Cases.[Case Status] = 'CLOSED' and Cases.CompanyCode= 1 and 
        Cases.[Intake Date] between '$tgl1' and '$tgl2'
        group by VPatientVisitPerUnit.Category,
        Cases.CompanyCode")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/TotalPatientBytratment', $data);
        $this->load->view('properti/footer', $data);
    }

    public function DashboardRujukan()
    {
     $tgl = date('Y-m-d');
     $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
     $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
     $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
     $data['judul'] = $pageAbdulRadjak;
     $data['user'] = $this->M_user->getUserSession()->row_array();
     $data['pasien'] = $this->db->query("Select c.[Case ID],c.Description,c.Category,c.[Case Status],c.[Intake Time],c.[Intake Date],co.CompanyName,p.instansi_tujuan,poli_tujuan
     from Cases c join erm_pemeriksaan_fisik p on c.[Case ID] = p.case_id 
     join Company co on c.CompanyCode = co.CompanyCode
     where p.instansi_tujuan !=''")->result_array();
 
     $data['total'] = $this->db->query("Select count(p.instansi_tujuan) as total
     from Cases c join erm_pemeriksaan_fisik p on c.[Case ID] = p.case_id 
     join Company co on c.CompanyCode = co.CompanyCode
     where p.instansi_tujuan !=''")->row_array();
 
     $this->load->view('properti/header', $data);
     $this->load->view('properti/menu', $data);
     $this->load->view('laporan/indexrujukan', $data);
     $this->load->view('properti/footer', $data);
    }
 
    public function cetakrujukan($id)
    {
     $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
     $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
     $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
     $data['judul'] = $pageAbdulRadjak;
        ob_start();
        $data['pasien'] = $this->db->query("SELECT C.[Case ID] AS ID, C.PatientCode AS MR, C.Description AS Nama, C.[Intake Date] AS Kunjungan, P.DOB AS TTL, D.[FirstName] AS Dokter, CA.Unit AS Poli, C.CompanyCode FROM Cases C, CaseAdmin CA, Doctor D, Patient P WHERE C.[Case ID] = '$id' AND C.[Case ID]=CA.[Case ID] AND CA.[DoctorID] = D.[DoctorID] AND C.[PatientCode]=P.[PatientCode]")->row_array();
 
        $data['qdata'] = $this->db->query("SELECT c.[Case ID],c.PatientCode,c.Description,p.Sex,p.Age,p.HomeAddress1,
        p.CellPhone,dt.FirstName,dt.LastName,er.pemeriksaan_fisik,er.diagnosa_primer,er.obat,er.keluhan_utama,i.DESCRPTION,
        er.poli_tujuan,er.instansi_tujuan
        FROM Cases c join Patient p on c.PatientCode = p.PatientCode
        join CaseDetail d on c.[Case ID] = d.[Case ID]
        join Doctor dt on d.DoctorID = dt.DoctorID
        join erm_pemeriksaan_fisik er on er.case_id = c.[Case ID]
        join ICD9 i on i.ICD_CODE = er.diagnosa_primer
        WHERE c.[Case ID] = '$id'")->row_array();
 
        $this->load->view('cetak/cetakrujukan', $data);
        $isi = ob_get_clean();
 
        require_once('./aset/html2pdf/html2pdf.class.php');
 
        try {
         $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(20, 10, 15, 10));
         $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
         $html2pdf->Output('resume.pdf');
     } catch (HTML2PDF_exception $e) {
         echo $e;
         exit;
     }
  
    } 

    public function CashierIncomeShift()
    {
        extract($_GET);
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $tgl = date('Y-m-d');

        $data['kasir'] = $this->db->query("SELECT
        Payment.[Case ID], Payment.PatientCode, Payment.PaidBy, Payment.[Invoice ID], Payment.[Transaction Type], Payment.AmountPaid, Payment.Status, Payment.CardNo, Payment.Bank, Payment.Shift, Payment.Type, Payment.UserCreated, Payment.PatientName, Payment.ReportDate
    FROM
         Payment
    WHERE
        Payment.[Status] = 'OK' AND ReportDate = '$tgl'
    ORDER BY
        Payment.[Type] DESC,
        Payment.[Transaction Type] ASC,
        Payment.[Invoice ID] ASC")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/CashierIncomeShift', $data);
        $this->load->view('properti/footer', $data);
    }

    public function cariCashierIncomeShift()
    {
        extract($_GET);
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $tgl = date('Y-m-d');

        $data['kasir'] = $this->db->query("SELECT
        Payment.[Case ID], Payment.PatientCode, Payment.PaidBy, Payment.[Invoice ID], Payment.[Transaction Type], Payment.AmountPaid, Payment.Status, Payment.CardNo, Payment.Bank, Payment.Shift, Payment.Type, Payment.UserCreated, Payment.PatientName, Payment.ReportDate
    FROM
         Payment
    WHERE
        Payment.[Status] = 'OK' AND ReportDate between '$tgl1' AND '$tgl2'
    ORDER BY
        Payment.[Type] DESC,
        Payment.[Transaction Type] ASC,
        Payment.[Invoice ID] ASC")->result_array();

        $this->load->view('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('laporan/cariCashierIncomeShift', $data);
        $this->load->view('properti/footer', $data);
    }

    public function exportincome()
    {
        ob_start();
        // extract($_GET);
        $tgl1 = $this->uri->segment(3);
        $tgl2 = $this->uri->segment(3);
        $data['kasir'] = $this->db->query("SELECT
        Payment.[Case ID], Payment.PatientCode, Payment.PaidBy, Payment.[Invoice ID], Payment.[Transaction Type], Payment.AmountPaid, Payment.Status, Payment.CardNo, Payment.Bank, Payment.Shift, Payment.Type, Payment.UserCreated, Payment.PatientName, Payment.ReportDate
    FROM
         Payment
    WHERE
        Payment.[Status] = 'OK' AND ReportDate between '$tgl1' AND '$tgl2'
    ORDER BY
        Payment.[Type] DESC,
        Payment.[Transaction Type] ASC,
        Payment.[Invoice ID] ASC")->result_array();
        $this->load->view('laporan/cetakCashierIncomeShift', $data);
        $isi = ob_get_clean();

        require_once('./aset/html2pdf/html2pdf.class.php');

        try {
            // $width_in_mm = '60';
            // $height_in_mm = '60';

            $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 5, 2));
            // $html2pdf = new HTML2PDF('P', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(2, 10, 2, 10));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));
            $html2pdf->Output('cover.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }
    
}