<style type="text/css">
.buttons-html5, .buttons-print{background: orange; color:#fff; border:0px; float: left; margin-right: 5px; margin-top: 7px}
.DTFC_LeftBodyWrapper{margin-top: -7px;}
table.dataTable{margin-top: 0px !important}
</style>

<div class="row" id="portlet-content">
    <div class="col-md-12">
        <div class="portlet light" style="position:relative">
            <div class="portlet-title">
                <div class="caption">
                    <?php $id_re_pasien = $this->Content_m->get_value('bbmc_tr_kunjungan','id_re_kunjungan',$id_re_kunjungan,'id_re_pasien')?>
                    <?php $nm_pasien = $this->Content_m->get_value('bbmc_tr_pasien','id_re_pasien',$id_re_pasien,'nama_pasien')?>
                    <?php $is_free = $this->Content_m->get_value('bbmc_tr_kunjungan','id_re_kunjungan',$id_re_kunjungan,'is_free')?>
                    <i class="fa fa-list"></i> <?=$nm_pasien?> - <?=$this->Content_m->get_value('bbmc_re_tipe_pasien','id_tipe_pasien',$id_tipe_pasien,'tipe_pasien');?>
                </div> 
                
                

                <?php 
                $a=$query_tindakan->num_rows() + $query_laboratorium->num_rows();

                $cek_bayar = $this->Content_m->get_value('bbmc_tr_kunjungan','id_re_kunjungan',$id_re_kunjungan,'sudah_dibayar');
                if($a != '0'){ 
                  if($cek_bayar == '0'){ ?>
                  

                  <?php if($is_free == '2'){ ?>
                  <div class="actions"  style="margin-right:5px !important;" >
                    <a class="btn" href="javascript:;">
                        <i class="fa fa-reply"></i> FREE PEGAWAI
                    </a> 
                  </div>
                  <?php }else{ ?>
                  
                  <div class="actions"  style="margin-right:5px !important;" >
                    <a class="btn" href="javascript:;" onclick="return alert('Belum Dibayar')">
                        <i class="fa fa-reply"></i> Belum Dibayar
                    </a> 
                  </div>

                  <div class="actions"  style="margin-right:5px !important;" >
                    <a class="btn green" onclick="return confirm('Bayar?')" href="<?=site_url()?>/front_office/reg_dir/kunjungan/receive_money_new/<?=$id_re_kunjungan?>">
                        <i class="fa fa-money"></i> Bayar
                    </a> 
                  </div>
                  <?php }?>
                  

                  <?php }else{ ?>

                 
                  <div class="actions"  style="margin-right:5px !important;" >
                    <a class="btn green" href="javascript:;" onclick="return alert('Sudah Dibayar')">
                        <i class="fa fa-check"></i> Sudah Dibayar
                    </a> 
                  </div>

                  <!--
                  <div class="actions"  style="margin-right:5px !important;" >
                    <a class="btn" target="_Blank" href="<?=site_url()?>/front_office/reg_dir/kunjungan/print_asuransi/<?=$id_re_kunjungan?>/<?=$id_tipe_pasien?>">
                        <i class="fa fa-print"></i> Nota Asuransi
                    </a> 
                  </div>
                  <div class="actions"  style="margin-right:5px !important;" >
                    <a class="btn" href="#" >
                        <i class="fa fa-print"></i> Nota Pasien
                    </a> 
                  </div>
                  -->

                  <?php }
                }

                ?>
            </div>     
             
            <?php 
            //$id_tipe_pasien = $this->Content_m->get_tipe_pasien_pertindakan($id_re_kunjungan);         
            
            if($a != 0){ ?>
            <div id="dataTables_processing">
                Loading Data..
            </div>
            <?php }?>

            
            <div class="portlet-body" id="page-content" style="<?=$a!=0?'display: none':''?>">
                <div class="table-responsive" style="border:0px;">
                    <?php 
                    if($a == 0){ ?>
                    <div class="" class="form-group" style="margin-bottom:40px; margin-top: 0px; margin-left:0px; padding-bottom: 30px; border-radius:4px; background: linear-gradient(to left, #d14415,#d16b49, #fad2d2 ,transparent,transparent,transparent,transparent)">
                      <div class="col-sm-12 col-md-12" style="text-align: right; color: #fff"><h2><strong>Tidak ada data</strong></h2></div><br><br>
                    </div>
                    <?php }else{ ?>
                    <table id="example" class="table table-bordered table-striped table-hover datatable" style="width: 100%">
                      <thead>
                        <tr style="background: #5578eb; color:#fff;">
                          <th class="text-left" style="min-width:30px; width: 30px !important" style="margin-left: 200px;">NO.</th>
                          <th class="text-left" style="min-width: 100%">DESKRIPSI</th>
                          <th class="text-right" style="min-width: 80px"> BIAYA </th>
                          <th class="text-right" style="min-width: 80px; <?=$id_tipe_pasien=='2'?'':'display: none'?>"> DITANGGUNG BPJS</th>
                          <th class="text-right" style="min-width: 80px; <?=$id_tipe_pasien=='3'?'':'display: none'?>"> DITANGGUNG SHHC</th>
                          <th class="text-right" style="min-width: 80px; <?=$id_tipe_pasien=='4'?'':'display: none'?>"> DITANGGUNG INHEALTH</th>
                          <th class="text-right" style="min-width: 80px; <?=$id_tipe_pasien=='5'?'':'display: none'?>"> DITANGGUNG MEGA</th>
                          <th class="text-right" style="min-width: 90px"> TOTAL BAYAR</th>
                        </tr>
                      </thead>
                      <tbody>

                        <?php 
                        $i=1; 
                        $harga_kamar_ttl = 0;
                        $cek_rawat_inap = @$this->Content_m->get_row('bbmc_tr_kunjungan','id_re_kunjungan',$id_re_kunjungan);
                        if(@$cek_rawat_inap->type_perawatan == '2'){ 
                        $id_tipe_kamar = @$cek_rawat_inap->id_tipe_kamar;
                        $nama_kamar = $this->Content_m->get_value('bbmc_re_tipe_kamar','id_tipe_kamar',$id_tipe_kamar,'tipe_kamar');
                        $harga_kamar = $this->Content_m->get_value('bbmc_re_tipe_kamar','id_tipe_kamar',$id_tipe_kamar,'harga');
                        
                        $tgl_kunjungan = @$cek_rawat_inap->tgl_kunjungan;
                        

                        ?>
                        <tr style="font-size:12px;">
                          <td align="left"> <?=$i;?> </td>
                          <td align="left">
                            Rawat Inap - <?=$nama_kamar?><br>
                            <?php 
                            $start_date = strtotime($tgl_kunjungan);
                            $end_date = strtotime(date('Y-m-d'));
                            $days_between = ceil(abs($end_date - $start_date) / 86400)+1;
                            $harga_kamar_ttl = $harga_kamar*$days_between;
                            ?>
                            <span style="font-size:12px">- Dari tanggal <?=$tgl_kunjungan?> sampai <?=date('Y-m-d')?> @<?=$this->Content_m->currency($harga_kamar)?> (<?=$days_between?> Hari)</span>
                          </td>
                          <td align="right"><?=$this->Content_m->currency($harga_kamar_ttl)?></td>
                          <td align="right" style="<?=$id_tipe_pasien=='2'?'':'display: none'?>"></td>
                          <td align="right" style="<?=$id_tipe_pasien=='3'?'':'display: none'?>"></td>
                          <td align="right" style="<?=$id_tipe_pasien=='4'?'':'display: none'?>"></td>
                          <td align="right" style="<?=$id_tipe_pasien=='5'?'':'display: none'?>"></td>
                          <td align="right"><?=$this->Content_m->currency($harga_kamar_ttl)?></td>
                        </tr>
                        <?php $i++;}?>



                        <?php 
                        $kurangi = 0;
                        $price_umum = 0;
                        $price_bpjs = 0;
                        $price_shhc = 0;
                        $price_inhealth = 0;
                        $price_mega = 0;
                        $grand_ttl = 0;


                        foreach($query_tindakan->result() as $key) {
                            
                            $price_umum = $key->price_umum;
                            if($id_tipe_pasien == '1'){
                                $kurangi = 0;
                            }else if($id_tipe_pasien == '2'){
                                $price_bpjs = $key->price_bpjs;
                                $kurangi = $kurangi + $price_bpjs;
                            }else if($id_tipe_pasien == '3'){
                                $price_shhc = $key->price_shhc;
                                $kurangi = $kurangi + $price_shhc;
                            }else if($id_tipe_pasien == '4'){
                                $price_inhealth = $key->price_inhealth;
                                $kurangi = $kurangi + $price_inhealth;
                            }else if($id_tipe_pasien == '5'){
                                $price_mega = $key->price_mega;
                                $kurangi = $kurangi + $price_mega;
                            }
                            


                            $ttl = $key->price_umum - $kurangi;
                            $grand_ttl = $grand_ttl + $ttl;
                         ?>
                          <tr style="font-size:12px;">
                            <td align="left"> <?=$i;?> </td>
                            <td align="left"><?=$key->name?></td>
                            <td align="right"><?=$this->Content_m->currency($price_umum)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='2'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_bpjs)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='3'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_shhc)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='4'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_inhealth)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='5'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_mega)?></td>
                            <td align="right"><?=$this->Content_m->currency($ttl)?></td>
                          </tr>
                        <?php $i++; $ttl=0; $kurangi=0;} ?>

                        <?php 
                        foreach($query_laboratorium->result() as $key) {
                            $price_umum = $key->price_umum;
                            if($id_tipe_pasien == '1'){
                                $kurangi = 0;
                            }else if($id_tipe_pasien == '2'){
                                $price_bpjs = $key->price_bpjs;
                                $kurangi = $kurangi + $price_bpjs;
                            }else if($id_tipe_pasien == '3'){
                                $price_shhc = $key->price_shhc;
                                $kurangi = $kurangi + $price_shhc;
                            }else if($id_tipe_pasien == '4'){
                                $price_inhealth = $key->price_inhealth;
                                $kurangi = $kurangi + $price_inhealth;
                            }else if($id_tipe_pasien == '5'){
                                $price_mega = $key->price_mega;
                                $kurangi = $kurangi + $price_mega;
                            }
                            $ttl = $key->price_umum - $kurangi;
                            $grand_ttl = $grand_ttl + $ttl;
                         ?>
                          <tr style="font-size:12px;">
                            <td align="left"> <?=$i;?> </td>
                            <td align="left"><?=$key->name?></td>
                            <td align="right"><?=$this->Content_m->currency($price_umum)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='2'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_bpjs)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='3'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_shhc)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='4'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_inhealth)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='5'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_mega)?></td>
                            <td align="right"><?=$this->Content_m->currency($ttl)?></td>
                          </tr>
                        <?php $i++; $ttl=0; $kurangi=0;} ?>

                        <?php 
                        foreach($query_radiologi->result() as $key) {
                            $price_umum = $key->price_umum;
                            if($id_tipe_pasien == '1'){
                                $kurangi = 0;
                            }else if($id_tipe_pasien == '2'){
                                $price_bpjs = $key->price_bpjs;
                                $kurangi = $kurangi + $price_bpjs;
                            }else if($id_tipe_pasien == '3'){
                                $price_shhc = $key->price_shhc;
                                $kurangi = $kurangi + $price_shhc;
                            }else if($id_tipe_pasien == '4'){
                                $price_inhealth = $key->price_inhealth;
                                $kurangi = $kurangi + $price_inhealth;
                            }else if($id_tipe_pasien == '5'){
                                $price_mega = $key->price_mega;
                                $kurangi = $kurangi + $price_mega;
                            }
                            $ttl = $key->price_umum - $kurangi;
                            $grand_ttl = $grand_ttl + $ttl;
                         ?>
                          <tr style="font-size:12px;">
                            <td align="left"> <?=$i;?> </td>
                            <td align="left"><?=$key->name?></td>
                            <td align="right"><?=$this->Content_m->currency($price_umum)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='2'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_bpjs)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='3'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_shhc)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='4'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_inhealth)?></td>
                            <td align="right" style="<?=$id_tipe_pasien=='5'?'':'display: none'?>"><?=$this->Content_m->currency2(-$price_mega)?></td>
                            <td align="right"><?=$this->Content_m->currency($ttl)?></td>
                          </tr>
                        <?php $i++; $ttl=0; $kurangi=0;} ?>


                        <?php 
                        $ttl_obat=0;
                        $cek_resep = $this->M_apotek->cek_resep($id_re_kunjungan);
                        if($cek_resep > 0){ ?>
                          <tr style="font-size:12px;">
                            <td align="left"> <?=$i;?> </td>
                            <td align="left">
                              Obat<br>
                              <?php 
                              //list nama obat
                              $this->M_apotek->get_list_obat_pasien($id_re_kunjungan, 'obat');?>
                            </td>
                            <td align="right">
                              <br>
                              <?php 
                              //harga umum
                              $this->M_apotek->get_list_obat_pasien($id_re_kunjungan, '1');?>
                            </td>
                            <td align="right" style="<?=$id_tipe_pasien=='2'?'':'display: none'?>">
                              <br>
                              <?php 
                              //harga bpjs
                              $this->M_apotek->get_list_obat_pasien($id_re_kunjungan, $id_tipe_pasien);?>
                            </td>
                            <td align="right" style="<?=$id_tipe_pasien=='3'?'':'display: none'?>">
                              <br>
                              <?php 
                              //harga shhc
                              $this->M_apotek->get_list_obat_pasien($id_re_kunjungan, $id_tipe_pasien);?>
                            </td>
                            <td align="right" style="<?=$id_tipe_pasien=='4'?'':'display: none'?>">
                              <br>
                              <?php 
                              //harga inhealth
                              $this->M_apotek->get_list_obat_pasien($id_re_kunjungan, $id_tipe_pasien);?>
                            </td>
                            <td align="right" style="<?=$id_tipe_pasien=='5'?'':'display: none'?>">
                              <br>
                              <?php 
                              //harga mega
                              $this->M_apotek->get_list_obat_pasien($id_re_kunjungan, $id_tipe_pasien);?>
                            </td>
                            <td align="right">
                              <br>
                              <?php 
                              //total 
                              $ttl_obat = $this->M_apotek->get_list_obat_pasien($id_re_kunjungan, $id_tipe_pasien, 'ttl');?>

                            </td>
                          </tr>
                          <?php }?>
                         
                         
                       
                      </tbody>  
                      <tr style="font-size:12px">
                          <td colspan="<?=$id_tipe_pasien=='1'?'3':'4'?>" style="text-align: right;">Sub Total</td>
                          <td class="text-right" style=""><?=$this->Content_m->currency($grand_ttl+$ttl_obat+$harga_kamar_ttl)?></td>
                      </tr>  

                      <?php 
                      $get_resep = $this->M_apotek->cek_biaya_racikan($id_re_kunjungan);
                      $cek_jumlah_racikan = $get_resep['jumlah_racikan'];
                      //echo $cek_jumlah_racikan."asd";

                      $cek_total_obat = $get_resep['total_obat'];
                      //echo $cek_total_obat."asd";
                      $biaya_racikan_obat = $this->Content_m->get_value('siak_re_data','id','17','value');
                      $biaya_satuan_obat = $this->Content_m->get_value('siak_re_data','id','18','value'); 
                      $jasa_racikan = $cek_jumlah_racikan*$biaya_racikan_obat;
                      $jumlah_obat_selain_racikan = $cek_total_obat - $cek_jumlah_racikan;
                      if($jumlah_obat_selain_racikan>3){$jumlah_obat_selain_racikan=3;}
                      $jasa_obat = $jumlah_obat_selain_racikan*$biaya_satuan_obat;
                      if($cek_jumlah_racikan >= '1'){ ?>
                      <tr style="font-size:12px; <?=$id_tipe_pasien != '1'?'text-decoration: line-through':''?>">
                          <td colspan="<?=$id_tipe_pasien=='1'?'3':'4'?>" style="text-align: right;">Jasa Racikan (<?=$cek_jumlah_racikan?>)</td>
                          <td class="text-right" style=""><?=$this->Content_m->currency($jasa_racikan)?></td>
                      </tr>  
                      <?php 
                      if($id_tipe_pasien == '1'){ $ttl_obat = $ttl_obat + $jasa_racikan; }
                      }?>

                      <?php if($cek_total_obat >= '1'){ ?>
                      <tr style="font-size:12px; <?=$id_tipe_pasien != '1'?'text-decoration: line-through':''?>">
                          <td colspan="<?=$id_tipe_pasien=='1'?'3':'4'?>" style="text-align: right;">Jasa Obat (<?=$jumlah_obat_selain_racikan?>)</td>
                          <td class="text-right" style=""><?=$this->Content_m->currency($jasa_obat)?></td>
                      </tr>  
                      <?php 
                      if($id_tipe_pasien == '1'){ $ttl_obat = $ttl_obat + $jasa_obat; }
                      }?>

                      <tr style="border-top:1px solid silver;">

                          <td colspan="<?=$id_tipe_pasien=='1'?'3':'4'?>" style="border-top:1px solid silver; text-align: right;"><b>Total</b></td>
                          <td class="text-right" style="border-top:1px solid silver">

                            <b><?=$this->Content_m->currency($grand_ttl+$ttl_obat+$harga_kamar_ttl)?></b>
                          </td>
                      </tr>  
                    </table>
                    <?php }?>



                </div>
            </div>
            
           


           
        </div>
    </div>
</div>


<script>
$(document).ready(function() {
    var buttonCommon = {
        exportOptions: {
            format: {
                body: function ( data, row, column, node ) {
                    return (column === 5) ? data.replace( /\n/g, '"&CHAR(10)&CHAR(13)&"' ) : data.replace(/(&nbsp;|<([^>]+)>)/ig, "\n");;
                }
            }
        },
        customize: function( xlsx ) {
          var sheet = xlsx.xl.worksheets['sheet1.xml'];
          $('row c', sheet).attr( 's', '55' );
       }
    };
 
    $('#example').DataTable( {

        lengthMenu: [ [10, 50, 200, -1], [10, 50, 200, 'All Data'] ],
        
        fnInitComplete: function(oSettings, json) {
          $('#dataTables_processing').css('display','none');
          $('#page-content').css('display','block');
          $('#fillter-content').css('display','block');
        }

    } );
} );

$('.tooltips').tooltip({ container: 'body' }) 
$(".date" ).datepicker({
    changeMonth: true,
    changeYear: true,
    yearRange: "-60:+0",
    dateFormat: 'yy-mm-dd'
});
</script>

