<section class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1>
                </h1>
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="<?php echo base_url();?>">Dashboard</a></li>
                    <li class="breadcrumb-item"><?php echo $parent;?></li>
                    <li class="breadcrumb-item active"><?php echo $title;?></li>
                </ol>
            </div>
        </div>
    </div>
</section>
<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <div class="card card-default">
                    <div class="card-header">
                        <h3 class="card-title"><?php 
                        echo $title;
                        $tglawal = $awal;
                        $tglakhir= $akhir;
                        $tglgabung = date("m/d/Y", strtotime($awal))." - ".date("m/d/Y", strtotime($akhir));
                        ?></h3>
                    </div>
                    <form action="<?php echo(base_url()); ?>index.php/lp_simrs_report/rekamedikrl32" method="post" autocomplete="off">
                        <div class="card-body">
                            <div class="form-group row">
                                <label class="col-sm-1 col-form-label">Tanggal :</label>
                                <div class="col-sm-4">
                                    <div class="input-group">
                                        <div class="input-group-prepend">
                                            <span class="input-group-text">
                                                <i class="far fa-calendar-alt"></i>
                                            </span>
                                        </div>
                                        <input type="text" name="tanggal" class="form-control float-right" id="reservation" value="<?php echo $tglgabung;?>">
                                    </div>
                                </div>
                                <div class="col-sm-2">
                                    <button type="submit" class="btn btn-outline-info">Search </button>
                                </div>
                            </div>
                        </div>
                    </form>
                    <div class="card-body">
                        <?php if($this->session->flashdata('message')){?>
                        <div id="alert" class="alert alert-success alert-dismissable">
                            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                            <i class="icon fa fa-check"></i> Alert!
                            <?php echo $this->session->flashdata('message');?>
                        </div>
                        <?php }?>
                        <script> 
                            setTimeout(function() {
                                $('#alert').hide('fast');
                            }, 3000);
                        </script>
                        <table id="example1" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>No</th>
                                    <th>SMF</th>
                                    <th>Jenis Pelayanan</th>
                                    <th>PX Awal</th>
                                    <th>PX Masuk</th>
                                    <th>PX Pindahan</th>
                                    <th>PX Dipindahkan</th>
                                    <th>PX Keluar Hidup</th>
                                    <th>PX L MT < 48</th>
                                    <th>PX L MT >= 48</th>
                                    <th>PX P MT < 48</th>
                                    <th>PX P MT >= 48</th>
                                    <th>Jumlah Lama Dirawat</th>
                                    <th>Pasien akhir bulan</th>
                                    <th>Jumlah Hari Perawatan</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $no = 0;
                                    foreach ($datanya as $dat){
                                        $no++;

                                        $re11   = str_replace('{', '', $dat->jenispelayanan);
                                        $re12   = str_replace('}', '', $re11);
                                        $ex13   = explode(",",$re12);
                                        $jenispelayanan = "";
                                        foreach ($ex13 as $data) {
                                            $jenispelayanan = $data;
                                        }

                                        $re21   = str_replace('{', '', $dat->pasienmasuk);
                                        $re22   = str_replace('}', '', $re21);
                                        $ex23   = explode(",",$re22);
                                        $pasienmasuk = "";
                                        foreach ($ex23 as $data) {
                                            $pasienmasuk = $data;
                                        }

                                        $re31   = str_replace('{', '', $dat->pindahan);
                                        $re32   = str_replace('}', '', $re31);
                                        $ex33   = explode(",",$re32);
                                        $pindahan = "";
                                        foreach ($ex33 as $data) {
                                            $pindahan = $data;
                                        }

                                        $re41   = str_replace('{', '', $dat->pindahan);
                                        $re42   = str_replace('}', '', $re41);
                                        $ex43   = explode(",",$re42);
                                        $pindahan = "";
                                        foreach ($ex43 as $data) {
                                            $pindahan = $data;
                                        }

                                        $re51   = str_replace('{', '', $dat->dipindahkan);
                                        $re52   = str_replace('}', '', $re51);
                                        $ex53   = explode(",",$re52);
                                        $dipindahkan = "";
                                        foreach ($ex53 as $data) {
                                            $dipindahkan = $data;
                                        }

                                        $datlakimeninggal = "";
                                        $datperempuanmeninggal = "";

                                        $lamakur48 = 0;
                                        $lamaleb48 = 0;

                                        $pemakur48 = 0;
                                        $pemaleb48 = 0;

                                        $re61   = str_replace('{', '', $dat->keluarhidup);
                                        $re62   = str_replace('}', '', $re61);
                                        $ex63   = explode(",",$re62);
                                        $keluarhidup = "";
                                        foreach ($ex63 as $data) {
                                            $keluarhidup = $data;
                                        }

                                        $re71   = str_replace('{', '', $dat->lakimeningal);
                                        $re72   = str_replace('}', '', $re71);
                                        $ex73   = explode(",",$re72);
                                        $lakimeningal = "";
                                        foreach ($ex73 as $data) {
                                            $datint = (int)$data;
                                            if($datint>=48){
                                                $lamaleb48 ++;
                                            }else{
                                                $lamakur48 ++;
                                            }
                                        }

                                        $re81   = str_replace('{', '', $dat->perempuanmeningal);
                                        $re82   = str_replace('}', '', $re81);
                                        $ex83   = explode(",",$re82);
                                        $perempuanmeningal = "";
                                        foreach ($ex83 as $data) {
                                            $datint = (int)$data;
                                            if($datint>=48){
                                                $pemaleb48 ++;
                                            }else{
                                                $pemakur48 ++;
                                            }
                                        }

                                        $re91   = str_replace('{', '', $dat->pasienawal);
                                        $re92   = str_replace('}', '', $re91);
                                        $ex93   = explode(",",$re92);
                                        $pasienawal = "";
                                        foreach ($ex93 as $data) {
                                            $pasienawal = $data;
                                        }

                                        $pasienakhirbulan = ($pasienawal+$pasienmasuk+$pindahan) - $dipindahkan - $keluarhidup - $lamakur48 - $lamaleb48 - $pemakur48 - $pemaleb48;

                                        $re101   = str_replace('{', '', $dat->jumlahlamadirawat);
                                        $re102   = str_replace('}', '', $re101);
                                        $ex103   = explode(",",$re102);
                                        $jumlahlamadirawat = "";
                                        foreach ($ex103 as $data) {
                                            $jumlahlamadirawat = $data;
                                        }

                                        $datsmf='';
                                        // foreach($datjum as $datajumlah){
                                        //     if($datajumlah->msf==$dat->smf){
                                        //         $datsmf = $datsmf.$datajumlah->tglmasuk." - ".$datajumlah->keluarrs."</br>";
                                        //     }
                                        // }

                                        echo("
                                            <tr>
                                                <td>".$no."</td>
                                                <td>".$dat->smf."</td>
                                                <td>".$jenispelayanan."</td>
                                                <td>".$pasienawal."</td>
                                                <td>".$pasienmasuk."</td>
                                                <td>".$pindahan."</td>
                                                <td>".$dipindahkan."</td>
                                                <td>".$keluarhidup."</td>
                                                <td>".$lamakur48."</td>
                                                <td>".$lamaleb48."</td>
                                                <td>".$pemakur48."</td>
                                                <td>".$pemaleb48."</td>
                                                <td>".$jumlahlamadirawat."</td>
                                                <td>".$pasienakhirbulan."</td>
                                                <td>".$datsmf."</td>
                                            </tr>
                                        ");
                                    }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>