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

class Kasir 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_Kasir');
        $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();
        $data['kasir'] = $this->M_Kasir->idxkasir()->result_array();

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

    public function Search()
    {
        $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();

        extract($_GET);
        if ($jenis == 1) {
            $data['cari'] = $this->M_Kasir->CaribyCases($cari)->result_array();

            $this->load->view('properti/header', $data);
            $this->load->view('properti/menu', $data);
            $this->load->view('kasir/Search', $data);
            $this->load->view('properti/footer', $data);
        } else if ($jenis == 2) {
            $data['cari'] = $this->M_Kasir->CaribyMR($cari)->result_array();

            $this->load->view('properti/header', $data);
            $this->load->view('properti/menu', $data);
            $this->load->view('kasir/detailmr', $data);
            $this->load->view('properti/footer', $data);
        } else if ($jenis == 3) {
            $data['cari'] = $this->M_Kasir->CaribyNama($cari)->result_array();

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

    public function detailchasir($cari)
    {
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['shift'] = $this->session->userdata('shift');
        $data['user'] = $this->M_user->getUserSession()->row_array();
        $data['cari'] = $this->M_Kasir->CaribyCases($cari)->result_array();
        $data['Payment'] = $this->M_Kasir->Payment($cari)->result_array();
        $data['rincian'] =  $this->db->query("exec SP_CashierDetail  '" . $cari . "'   ")->result_array();
        $data['totalcharge'] =  $this->db->query("SELECT [Case Id],[Total] FROM [sudirman].[dbo].[VTotalCharge] where [Case Id]= '$cari' ")->row_array();
        $data['idinv'] = $this->db->query("select top 1 * from SystemNo where SystemName = 'Trans'")->row_array();
        $data['paymentype'] = $this->db->query("Select * from TransactionType ")->result_array();

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

    public function savebayar()
    {
        date_default_timezone_set("Asia/Jakarta");
        $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();

        $invoice    = $this->input->post('invoice');
        $status     = $this->input->post('status');
        $transactionid = '4' . $this->input->post('transactionid');
        $caseid     = $this->input->post('caseid');
        $tanggal    = $this->input->post('tanggal');
        $waktu      = $this->input->post('waktu');
        $mr         = $this->input->post('mr');
        $nama       = $this->input->post('nama');
        $tujuannama = $this->input->post('tujuannama');
        $kategori = $this->input->post('kategori');
        $rounding = $this->input->post('rounding');
        $amountpaid = $this->input->post('amountpaid');
        $bankname = $this->input->post('bankname');
        $total = $this->input->post('total');
        $cardtype = $this->input->post('cardtype');
        $description = $this->input->post('description');
        $pengirim = $this->input->post('pengirim');
        $shift = $this->input->post('shift');
        $tgl = date('Y-m-d');
        $waktu = date('H:i:a');
        $tglwaktu = date('Y-m-d H:i:s');

        $no = $this->db->query("SELECT * FROM SystemNo WHERE SystemName = 'ReceivedNo'")->row_array();
        $nomor =  $no['NoNumeric'];
        $noAwal = $no['NoNumeric'] + 1;
        $this->db->query("UPDATE SystemNo SET NoNumeric = '$noAwal' WHERE SystemName = 'ReceivedNo'");

        $this->db->query("
        INSERT INTO Payment ( 
            [Case ID],
            PatientCode,
            PaidBy,
            [Payment Date],
            [Payment Time],
            [Invoice ID],
            [Transaction Type],
            [AmountPaid],
            [AmountTotal],
            [Status],
            CardType,
            Bank,
            Shift,
            Type,
            UserCreated,
            DateCreated,
            [Description],
            [PrintDate],
            [PrintBy],
            [iPrint],
            PatientName,
            TransactionID,
            [ReportDate],
            CashierLocation
            )
            Values (
            '$caseid',
            '$mr',
            '$nama',
            '$tgl',
            '$waktu',
            '$nomor',
            '$kategori',
            '$amountpaid',
            '$total',
            '$status',
            '$cardtype',
            '$bankname',
            '$shift',
            'PAYMENT',
            '$pengirim',
            '$tgl',
            '$description',
            '$tglwaktu',
            '$pengirim',
            '1',
            '$nama',
            '$transactionid',
            '$tgl',
            '1'
                )
            ");

        //INSERTTLOG
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }

        $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
        $this->db->query("exec ACC_Payment '" . $transactionid . "', '" . $pengirim . "', '" . $hostname . "' ");
        $this->db->query("exec ACC_CaseClose '" . $caseid . "', '0','" . $pengirim . "', '" . $hostname . "' ");
        $cek = $this->db->query("Select Transaction_Date From TransactionHeader where  [Case ID] = '$caseid'")->row_array();
        $tgl =  date('Y-m-d', strtotime($cek['Transaction_Date']));
        $this->db->query("UPDATE Cases SET [Case Status] = 'CLOSED',[Closed Date] = '$tgl' WHERE [Case ID] = '$caseid'");

        $time = date('H:i');
        $this->db->query("INSERT INTO TLOG (sKey,sTableName,sAction,dDate,sTime,sUser,sCompName) VALUES ('$caseid','Payment','ADD','$tgl','$time','web-$pengirim','$hostname')");

        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Data Berhasil DiTambahkan </div>');
        redirect($_SERVER['HTTP_REFERER']);
    }

    public function PrintCreatePayment($inv, $caseid)
    {
        $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();
        ob_start();
        $data['printpayment'] = $this->db->query("exec Sp_WebPrintInvoice  '" . $inv . "'")->result_array();
        $this->load->view('cetak/createPayment', $data);
        $isi = ob_get_clean();

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

        try {
            $width_in_mm = '170';
            $height_in_mm = '120';

            // $html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 5, 2));
            $html2pdf = new HTML2PDF('L', 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('PrintInvoice.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function menukasir()
    {
        $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('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('kasir/MenuKasir', $data);
        $this->load->view('properti/footer', $data);
    }

    public function VoidClaimNote()
    {
        $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('properti/header', $data);
        $this->load->view('properti/menu', $data);
        $this->load->view('kasir/VoidClaimNote', $data);
        $this->load->view('properti/footer', $data);
    }

    public function void()
    {
        $cari = $this->input->post('cari');
        $query = $this->db->query("select * from Payment where [Invoice ID] = '$cari'")->result_array();
        if ($cari != '') {
            $query =  $this->db->query("select * from Payment where [Invoice ID] = '$cari'")->result_array();
        }

        echo json_encode($query);;
    }

    public function searchVoid()
    {
        $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();

        $cari = $this->input->post('nokwitansi');
        $data['result'] = $this->M_Kasir->CariVoid($cari)->result_array();

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

    public function VoidInv()
    {
        date_default_timezone_set("Asia/Jakarta");
        $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();

        $CaseID      = $this->input->post('CaseID');
        $nokwitansi  = $this->input->post('nokwitansi');
        $PaymenDate  = $this->input->post('PaymenDate');
        $Mr          = $this->input->post('Mr');
        $Nama        = $this->input->post('Nama');
        $Amount      = $this->input->post('Amount');
        $Reson       = $this->input->post('Reson');
        $pengirim    = 'Web-penguiu';
        $tgl         = date('Y-m-d H:i:s');

        $this->db->query("UPDATE Payment SET Status = 'VOID', Reason = '$Reson' WHERE [Invoice ID] = '$nokwitansi'");
        $this->db->query("
       INSERT INTO VoidClaimNote (
        [Case ID]
       ,[VoidBy]
       ,[VoidDate]
       ,[Type]
       )
       Values (
        '$CaseID',
        '$pengirim',
        '$tgl',
        'Invoice'
        )
    ");

        //INSERTTLOG
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }

        $tgl = date('Y-m-d');
        $time = date('H:i');
        $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
        $this->db->query("INSERT INTO TLOG (sKey,sTableName,sAction,dDate,sTime,sUser,sCompName) VALUES ('$CaseID','Payment','VOID INVOICE','$tgl','$time','web-$pengirim','$hostname')");
        $this->session->set_flashdata('message', '<div class="alert alert-success" role="alert"> Berhasil di Void </div>');

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

    public function PrintClaimNote($id)
    {
        $data['abdulradjak'] = $this->M_Utama->abdulradjak()->row_array();
        $abdulradjak = $this->M_Utama->abdulradjak()->row_array();
        $pageAbdulRadjak = $abdulradjak['NamaPerusahaan'];
        $data['judul'] = $pageAbdulRadjak;
        $data['user'] = $user = $this->M_user->getUserSession()->row_array();
        $data['data'] = $this->M_Kasir->PrintClaimNote($id)->row_array();
        $data['result'] = $this->M_Kasir->VStatementDetail($id)->result_array();
        $data['payment'] = $this->M_Kasir->Paymentbayar($id)->row_array();
        $data['ttl'] =  $this->M_Kasir->ttl($id)->row_array();
        $data['drugs'] = $this->M_Kasir->obat($id)->result_array();

        $tgl = date('Y-m-d');
        $time = date('H:i');
        $pengirim = 'Web-' . $user['nama'];

        $cekjurnal = $this->db->query("select  * from VoidClaimNote	where [Case ID] = '$id' ")->num_rows();

        if ($cekjurnal > 0) {
            $this->session->set_flashdata("error", "Maaf Transaksi sudah pernah di buat !!!");
            redirect($_SERVER['HTTP_REFERER']);
        } else {

            $this->db->query("
        INSERT INTO VoidClaimNote (
         [Case ID]
        ,[VoidBy]
        ,[VoidDate]
        ,[Type]
        )
        Values (
         '$id',
         '$pengirim',
         '$tgl',
         'Invoice'
         )
     ");
            //INSERTTLOG
            if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
                $ip = $_SERVER['HTTP_CLIENT_IP'];
            } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
            } else {
                $ip = $_SERVER['REMOTE_ADDR'];
            }

            $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
            $this->db->query("exec ACC_CaseClose '" . $id . "', '0','" . $pengirim . "', '" . $hostname . "' ");
            $cek = $this->db->query("Select Transaction_Date From TransactionHeader where  [Case ID] = '$id'")->row_array();
            $tgl =  date('Y-m-d', strtotime($cek['Transaction_Date']));
            $this->db->query("UPDATE Cases SET [Case Status] = 'CLOSED',[Closed Date] = '$tgl' WHERE [Case ID] = '$id'");
            $this->db->query("INSERT INTO TLOG (sKey,sTableName,sAction,dDate,sTime,sUser,sCompName) VALUES ('$id','ACC_CaseClose','ADD','$tgl','$time','web-$pengirim','$hostname')");

            ob_start();
            redirect('kasir/StatmentDetailNo/' . $id);
            $isi = ob_get_clean();

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

            try {
                $width_in_mm = '110';
                $height_in_mm = '170';

                //$html2pdf = new HTML2PDF('P', 'A4', 'en', false, 'ISO-8859-15', array(5, 2, 5, 2));
                $html2pdf = new HTML2PDF('L', 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;
            }
        }
    }

    public function PrintStatmentDetail()
    {
        extract($_GET);
        if ($item == 'Yes') {
            redirect('kasir/StatmentDetail/' . $caseid);
        } else if ($item == 'No') {
            redirect('kasir/StatmentDetailNo/' . $caseid);
        }
    }

    public function StatmentDetail($caseid)
    {
        $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();
        ob_start();
        $data['dt'] = $this->db->query("exec Sp_TransactionDetail  '" . $caseid . "'   ")->row_array();
        $data['StatmentDetail'] = $StatmentDetail = $this->db->query("exec Sp_TransactionDetail  '" . $caseid . "'   ")->result_array();
        $data['tpayment'] = $this->db->query("Select * From Payment where [Case ID] = '$caseid'")->row_array();
        $data['ttd'] = $this->db->query("Select * From TandatanganGeneralConsent where CaseID = '$caseid'")->row_array();

        $this->load->view('cetak/PrintStatmentDetail', $data);
        // $isi = ob_get_clean();

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

        // try {
        //     // Ukuran kertas termal 80mm x panjang fleksibel
        //     $width_in_mm = 80;  // Lebar kertas termal
        //     $height_in_mm = 200; // Tinggi awal, bisa panjang dinamis

        //     // Inisialisasi HTML2PDF dengan ukuran kertas termal
        //     $html2pdf = new HTML2PDF('P', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(5, 2, 5, 2));
        //     $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));

        //     // Tentukan direktori tempat menyimpan file PDF
        //     $folderPath = './aset/pdf_kasir/';
        //     if (!is_dir($folderPath)) {
        //         mkdir($folderPath, 0777, true); // Buat folder jika belum ada
        //     }

        // // Nama file
        // $fileName = $caseid . '_' . date('Ymd') . '.pdf';
        // $filePath = $folderPath . $fileName;

        // // Simpan file PDF ke folder
        // $html2pdf->Output($filePath, 'F'); // 'F' untuk save ke file
        // echo "File berhasil disimpan di: " . $filePath;
        //     $html2pdf->Output('thermal-print.pdf');
        // } catch (HTML2PDF_exception $e) {
        //     echo $e;
        //     exit;
        // }
    }

    public function printstruk($caseid)
    {
        $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();
        ob_start();
        $data['dt'] = $this->db->query("exec Sp_TransactionDetail  '" . $caseid . "'   ")->row_array();
        $data['StatmentDetail'] = $StatmentDetail = $this->db->query("exec Sp_TransactionDetail  '" . $caseid . "'   ")->result_array();
        $data['tpayment'] = $this->db->query("Select * From Payment where [Case ID] = '$caseid'")->row_array();
        $data['ttd'] = $this->db->query("Select * From TandatanganGeneralConsent where CaseID = '$caseid'")->row_array();

        $this->load->view('cetak/PrintStatmentDetail', $data);
        $isi = ob_get_clean();

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

        try {
            // Ukuran kertas termal 80mm x panjang fleksibel
            $width_in_mm = 80;  // Lebar kertas termal
            $height_in_mm = 200; // Tinggi awal, bisa panjang dinamis

            // Inisialisasi HTML2PDF dengan ukuran kertas termal
            $html2pdf = new HTML2PDF('P', array($width_in_mm, $height_in_mm), 'en', false, 'ISO-8859-15', array(5, 2, 5, 2));
            $html2pdf->writeHTML($isi, isset($_GET['vuehtml']));

            //     // Tentukan direktori tempat menyimpan file PDF
            //     $folderPath = './aset/pdf_kasir/';
            //     if (!is_dir($folderPath)) {
            //         mkdir($folderPath, 0777, true); // Buat folder jika belum ada
            //     }

            // // Nama file
            // $fileName = $caseid . '_' . date('Ymd') . '.pdf';
            // $filePath = $folderPath . $fileName;

            // // Simpan file PDF ke folder
            // $html2pdf->Output($filePath, 'F'); // 'F' untuk save ke file
            // echo "File berhasil disimpan di: " . $filePath;
            $html2pdf->Output('thermal-print.pdf');
        } catch (HTML2PDF_exception $e) {
            echo $e;
            exit;
        }
    }

    public function StatmentDetailNo($caseid)
    {
        $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();
        ob_start();
        // $caseid = $this->input->post('caseid');
        $data['dt'] = $this->db->query("exec Sp_TransactionDetail  '" . $caseid . "'   ")->row_array();
        $data['StatmentDetailNo'] = $StatmentDetail = $this->db->query("Select * from VSatementDetailDrugs where [Case ID] = '$caseid'")->result_array();
        $data['StatmentDetail'] = $StatmentDetail = $this->db->query("exec Sp_TransactionDetail  '" . $caseid . "'   ")->result_array();
        $data['trxdata'] = $this->db->query("SELECT top 100 dbo.Activity.[Case ID],dbo.MedicalProcedure.Category ,
        dbo.MedicalProcedure.Description, 
        SUM(dbo.Activity.Charge) AS Total, 
        COUNT(dbo.Activity.[Case ID]) AS [Activity Count],
        Case When dbo.Doctor.FirstName is Null then '' else dbo.Doctor.FirstName end as [First Name],
        Case When dbo.Doctor.LastName is Null then '' else dbo.Doctor.LastName end as [Last Name],dbo.Activity.Charge
        
        FROM dbo.Activity (nolock) INNER JOIN dbo.MedicalProcedure (nolock) ON 
        dbo.Activity.Activity = dbo.MedicalProcedure.ProcedureCode INNER JOIN
        dbo.CategoryDetail (nolock) ON dbo.MedicalProcedure.Category = dbo.CategoryDetail.Category
        Left Join dbo.Doctor (nolock) on dbo.Activity.DoctorID=dbo.Doctor.DoctorID
        where dbo.Activity.Activity <> '1005' and [Case ID]='$caseid'
        GROUP BY dbo.MedicalProcedure.Description,dbo.Activity.[Case ID],dbo.Doctor.FirstName,dbo.Doctor.Lastname,
        dbo.MedicalProcedure.Category,dbo.Activity.Charge")->result_array();

        $this->load->view('cetak/PrintStatmentDetailNo', $data);
        $isi = ob_get_clean();

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

        try {
            $width_in_mm = '170';
            $height_in_mm = '110';

            //$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;
        }
    }

    public function caribycaseid()
    {
        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['kasir'] = $this->db->query("SELECT c.PatientCode,c.[Case ID],c.Category,c.Description,c.[Intake Date],c.[Closed Date],cp.CompanyName,c.[Case Status] FROM Cases c join Company cp on c.CompanyCode = cp.CompanyCode WHERE c.[Case ID]= '$src' order by c.[Case Status] Desc")->result_array();

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

    public function caribymr()
    {
        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['kasir'] = $this->db->query("SELECT c.PatientCode,c.[Case ID],c.Category,c.Description,c.[Intake Date],c.[Closed Date],cp.CompanyName,c.[Case Status] FROM Cases c join Company cp on c.CompanyCode = cp.CompanyCode WHERE c.[PatientCode]= '$src' order by c.[Case Status] Desc")->result_array();

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

    public function caribytgl()
    {
        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['kasir'] = $this->db->query("SELECT c.PatientCode,c.[Case ID],c.Category,c.Description,c.[Intake Date],c.[Closed Date],cp.CompanyName,c.[Case Status] FROM Cases c join Company cp on c.CompanyCode = cp.CompanyCode WHERE c.[Intake Date]= '$tgl' order by c.[Intake Date] Desc")->result_array();

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