 <div>
    <h4 class="form-section" style="margin:30px 0px 10px 0px !important; padding-bottom:0px !important">
        <i class="fa fa-align-justify"></i> <strong> Tindakan Perawatan Pasien<hr style="margin:10px 0px !important" > </strong>
    </h4>

    <div class="row" >
      <div class="col-md-12">
        


         <div class="row">
            <div class="col-md-12">
              <div class="form-group" id="icd">
                <div class="table-responsive">
                  <input type="hidden" name="id_re_kunjungan" value="<?=$id_re_kunjungan?>">
                  <input type="hidden" name="status_resep" value="<?=$get_kunjungan->status_resep?>">

                  <table id="<?= $controller ?>_table" class="table table-bordered table-striped table-hover" style="margin-bottom:0px; width:100%; font-size:11px !important">
                      
                      <thead>
                        <tr style="border-top:0px;" class="">  
                            <th class="col-md-9" style="font-size:10px !important" align="left">Nama Tindakan</th>
                            <th class="col-md-2 text-right" style="font-size:10px !important">Harga </th>
                            <th class="col-md-1" align="center" style="font-size:10px !important; text-align: center; vertical-align: middle;">Aksi</th>
                        </tr>
                         
                      </thead>
                      <tbody>
                        <?php 
                        $i=1;

                        
                        $ttl=0;
                        $arr = array();
                        $this->db->where('id_re_kunjungan',$id_kunjungan);
                        foreach ($this->Content_m->select_db('bbmc_tr_tindakan')->result() as $key ) { 
                                
                        $sub = $this->Content_m->get_value('siak_re_account_chart','id',$key->tindakan,'price_umum');
                        $id_tindakan = $this->Content_m->get_value('siak_re_account_chart','id',$key->tindakan,'id_tindakan');
                        $grup_tindakan = str_replace("Penerimaan Tindakan", "", $this->Content_m->get_value('bbmc_re_tindakan','id_tindakan',$id_tindakan,'tindakan'));
                        
                        $ttl=$ttl+$sub;

                        ?>
                          
                          <tr style="border-top:0px;" class="">  
                            <td class="col-md-9" align="left"><?=ucwords(strtolower($grup_tindakan))?> - <?=$this->Content_m->get_value('siak_re_account_chart','id',$key->tindakan,'name')?></td>
                            <td class="col-md-2 text-right"><?=$this->Content_m->currency($sub)?> </td>
                            <td class="col-md-1" align="center" style="text-align: center; vertical-align: middle;"><a data-toggle="tooltip" data-placement="top" title="Hapus Tindakan" href="<?=site_url()?>/front_office/ugd_dir/ugd/del_tindakan/<?=$key->id_re_tindakan?>/<?=$id_kunjungan?>" onclick="return confirm('Apakah anda yakin menghapus tindakan ini ?')" ><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></td>
                          </tr>
                         
                        <?php } ?>

                        <tr>
                          <td style="border:1px solid #fff"></td>
                          <td style="border:1px solid #fff; font-weight: bold" class="text-right"><?=$this->Content_m->currency($ttl)?></td>
                          <td style="border:1px solid #fff"></td>
                        </tr>
                        
                        
                        
                        <?php for ($ii=$i; $ii < 10; $ii++) { ?>
                        <tr style="border-top:0px; <?=$ii<='0'?'display: table-row':'display: none'?>" class="tindakan<?=$ii?>">   
                         
                          <td colspan="2" class="col-md-10" align="left">
                            <select name="tindakan[]" class="form-control sel2">
                                <option value=""></option>
                                <?php 
                                $this->db->order_by('name');
                                $i=1;
                                $this->db->where('id_tindakan >','0');
                                foreach ($this->Content_m->select_db('siak_re_account_chart')->result() as $key ) { 
                                $grup_tindakan = str_replace("Penerimaan Tindakan", "", $this->Content_m->get_value('bbmc_re_tindakan','id_tindakan',$key->id_tindakan,'tindakan'));
                                ?>
                                 <option value="<?=$key->id?>" ><?=ucwords(strtolower($grup_tindakan))?> - <?=ucwords(strtolower($key->name))?> - <?=$this->Content_m->currency($key->price_umum)?></option>
                                <?php $i++;}?>
                            </select>     
                          </td>
                          <td class="col-md-1" align="center" style="text-align: center; vertical-align: middle;"><a data-toggle="tooltip" data-placement="top" title="Hapus Tindakan" href="javascript:;" class="del_tindakan" data-id="<?=$ii?>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></td>
                        </tr>
                        <?php }?>
                      </tbody>
                    </table>
                    <a class="btn btn-xs blue add_tindakan" href="javascript:;" style="margin-top:10px !important">
                      <i class="fa fa-plus"></i>
                    </a>                           
                </div>
              </div> 
            </div>
          </div>
          <script type="text/javascript">

            var a2="5";
            $(".add_tindakan").click(function(){
                $(".tindakan"+a2).css('display','table-row');
                a2++;
            });

            $(".del_tindakan").click(function(){
                var b2= $(this).attr('data-id');
                $(".tindakan"+b2).css('display','none');
                if(confirm("Hapus entry ini?")){
                  return true;
                }
            });


            $(".sel2").select2({
              placeholder: "Pilih .. ",
              language: "id"
            });

          </script>       


      </div>
      
    </div>

   
      
  
</div>






 <div>
    <h4 class="form-section" style="margin:30px 0px 10px 0px !important; padding-bottom:0px !important">
        <i class="fa fa-align-justify"></i> <strong> Medikasi / Obat<hr style="margin:10px 0px !important" > </strong>
    </h4>

    <div class="row" >
      <div class="col-md-12">
        

         <div class="row">
            <div class="col-md-12">
              <div class="form-group" id="icd">
                <div class="table-responsive">
                 
                  <div class="table-responsive">
                          <?php 
                          $get_stok = $this->M_apotek->get_all_stok_static();
                          $this->db->where('id_re_kunjungan',$id_re_kunjungan);
                          $q = $this->Content_m->select_db('bbmc_tr_pengobatan'); 
                          ?>
                          <table id="<?= $controller ?>_table" class="table table-bordered table-striped table-hover" style="margin-bottom:0px; width:100%; font-size:11px !important">
                              <thead>
                                <tr>
                                  <?php if($q->num_rows() == 0){ ?>
                                  <th colspan="5" class="text-left col-md-4" style="font-size:10px !important">Obat
                                  </th>
                                  <?php }else{ ?>
                                  <th class="text-center col-md-1" style="font-size:10px !important">No</th>
                                  <th class="text-left col-md-3" style="font-size:10px !important">Nama Obat</th>
                                  
                                  <?php if($get_kunjungan->status_resep != '3'){ ?>
                                  <th class="text-left col-md-1" style="font-size:10px !important">Tersedia</th>
                                  <?php }?>
                                  <?php }?>
                                  <th class="text-left col-md-1" style="font-size:10px !important">Jumlah</th>
                                  <th class="text-left col-md-3" style="font-size:10px !important">Dosis dan cara pemakaian</th>
                                  <th class="text-right col-md-2" style="font-size:10px !important">Harga</th>
                                  <?php if($get_kunjungan->status_resep != '3'){ ?>
                                  <th class="text-center col-md-1" style="font-size:10px !important">Aksi</th>
                                  <?php }?>
                                </tr>
                              </thead>
                              <tbody>
                                <?php 
                                $i=1;
                                $ttl_obat=0;
                                foreach ($q->result() as $key ) { ?>
                                <tr style="" class="pengobatan<?=$i?>">   
                                  <input type="hidden" name="id_re_pengobatan[]" value="<?=$key->id_re_pengobatan?>">
                                  <td align="center"><?=$i?></td>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                        <input type="hidden" class="form-control " name="id_obat[<?=$i?>][]" value="<?=$keyb->id_obat?>" placeholder="">
                                        <?=$this->Content_m->get_value('bbmc_re_apotik_obat','id_re_apotik_obat',$keyb->id_obat,'nama_obat')."<br>"?>
                                      <?php }?>
                                      
                                  </td>
                                  
                                  <?php if($get_kunjungan->status_resep != '3'){ ?>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                       
                                        <span class="stok stok<?=$keyb->id_obat?> minstoka<?=$keyb->id_obat?>" data-id="<?=$keyb->id_obat?>">Loading... </span>
                                        <br>
                                      <?php }?>
                                  </td>
                                  <?php }?>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                        <input type="hidden" class="form-control " name="qty[<?=$i?>][]" value="<?=$keyb->qty?>" placeholder="">
                                        <?=$keyb->qty."<br>"?>
                                      <?php }?>
                                  </td>
                                  <td align="left">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { ?>
                                        <input type="hidden" class="form-control " name="cara_pemakaian[<?=$i?>][]" value="<?=$keyb->cara_pemakaian?>" placeholder="">
                                        <?=$keyb->cara_pemakaian."<br>"?>
                                      <?php }?>
                                  </td>
                                  <td align="right">
                                      <?php 
                                      $this->db->where('id_pengobatan',$key->id_re_pengobatan);
                                      foreach ($this->Content_m->select_db('bbmc_tr_pengobatan_pasien')->result() as $keyb ) { 
                                        $harga = $this->Content_m->get_value('bbmc_re_apotik_obat','id_re_apotik_obat',$keyb->id_obat,'harga_jual');
                                        $ttl_obat = $ttl_obat+($harga*$keyb->qty);
                                        ?>

                                        <?=$this->Content_m->currency($harga*$keyb->qty)."<br>"?>
                                      <?php }?>
                                  </td>
                                  <?php if($get_kunjungan->status_resep != '3'){ ?>
                                  <td align="center"><a data-toggle="tooltip" data-placement="top" title="Hapus Obat" href="<?=site_url()?>/front_office/ugd_dir/ugd/del_pengobatan/<?=$key->id_re_pengobatan?>/<?=$id_re_kunjungan?>" onclick="return confirm('Apakah anda yakin menghapus entry ini?')" data-id="<?=$i?>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></td>
                                  <?php }?>
                                </tr>
                                <?php $i++; $id_pengobatan = $key->id_re_pengobatan; }?>
                                <tr style="border: 0px">
                                  <td colspan='5' style="border: 0px"></td>
                                  <td class="text-right" style="font-weight: bold; border: 0px"><?=$this->Content_m->currency($ttl_obat)?></td>
                                  <td style="border: 0px"></td>
                                </tr>


                                <?php for ($ii=$i; $ii < 10; $ii++) { ?>
                                <tr style="border-top:0px; <?=$ii=='1'?'display: table-row':'display: none'?>" class="pengobatan<?=$ii?>">   
                                  <input type="hidden" name="id_re_pengobatan[]" value="tidakada">
                                  <td colspan="3" class="col-md-6" align="left">
                                    <?php for ($z1=0; $z1 < 10; $z1++) { ?>
                                    <div style="<?=$z1==0?'display: block;':'display: none;'?>" class="sel2<?=$ii?>_<?=$z1?>">
                                      <select name="id_obat[<?=$ii?>][]" class="sel2" style="padding: 0px; width: 100%;">
                                          <option value=""></option>
                                          <?php foreach ($this->Content_m->select_db('bbmc_re_apotik_obat')->result() as $key ) { 
                                          $jmlh_stok = $get_stok[$key->id_re_apotik_obat];?>
                                          <option value="<?=$key->id_re_apotik_obat?>"><?=$key->nama_obat?> <?=$key->jenis_obat?> <?=$jmlh_stok?> <?=$key->sediaan?></option>
                                          <?php }?>
                                      </select>
                                    </div>
                                    <?php }?>
                                    
                                    <a class="btn btn-xs add_puyer" data-id="<?=$ii?>" href="javascript:;" style="margin-top:10px !important; padding:0px">
                                      <i class="fa fa-plus"></i>
                                    </a>   
                                  </td>
                                  <td colspan="1" class="col-md-1" align="left">
                                    <?php for ($z2=0; $z2 < 10; $z2++) { ?>
                                    <div style="<?=$z2==0?'display: block;':'display: none;'?>" class="qty<?=$ii?>_<?=$z2?>">
                                    <input type="number" class="form-control " name="qty[<?=$ii?>][]" value="" placeholder="Jml..">
                                    </div>
                                    <?php }?>
                                  </td>

                                  <td colspan="2" class="col-md-4" align="left">
                                    <?php for ($z3=0; $z3 < 10; $z3++) { ?>
                                    <div style="<?=$z3==0?'display: block;':'display: none;'?>" class="ket<?=$ii?>_<?=$z3?>">
                                    <input type="text" class="form-control" name="cara_pemakaian[<?=$ii?>][]" value="" placeholder="Ketik cara pemakaian ..">
                                    </div>
                                    <?php }?>
                                  </td>
                                  <td class="col-md-1" align="center" style="text-align: center; vertical-align: top; padding-top: 15px"><a data-toggle="tooltip" data-placement="top" title="Hapus Pengobatan" href="javascript:;" class="del_pengobatan" data-id="<?=$ii?>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a></td>
                                </tr>
                                <?php }?>
                              </tbody>
                            </table>
                            <?php if($get_kunjungan->status_resep != '3'){ ?>
                            <a class="btn btn-xs blue add_pengobatan" href="javascript:;" style="margin-top:10px !important">
                              <i class="fa fa-plus"></i>
                            </a>  
                            <?php }?>                         
                        </div>

                                          
                </div>
              </div> 
            </div>
          </div>
          <script type="text/javascript">

            var a2="5";
          
            $(".del_tindakan").click(function(){
                var b2= $(this).attr('data-id');
                $(".tindakan"+b2).css('display','none');
                if(confirm("Hapus entry ini?")){
                  return true;
                }
            });


            $(".sel2").select2({
              placeholder: "Pilih .. ",
              language: "id"
            });

          </script>    
          <script type="text/javascript">

            var a2="<?=$i=='1'?'2':$i?>";
            $(".add_pengobatan").click(function(){
                $(".pengobatan"+a2).css('display','table-row');
                a2++;
            });

            $(".del_pengobatan").click(function(){
                var b2= $(this).attr('data-id');
                $(".pengobatan"+b2).css('display','none');
                if(confirm("Hapus entry ini?")){
                  return true;
                }
            });

            var zz='1';
            $(".add_puyer").click(function(){

              var dataid = $(this).attr('data-id');
              $(".sel2"+dataid+"_"+zz).css('display','block');
              $(".qty"+dataid+"_"+zz).css('display','block');
             //alert(dataid);
              zz++;
            });

          </script>

   
          <script type="text/javascript">
          $(document).ready(function(){
            //alert(1);
           
            function stok(textloading) {
              //alert(textloading);
              $(".stok").text(textloading);
              $(".harga_beli_tertinggi").text(textloading);
              var id = null;
              $.ajax({
                type: "GET",
                url: '<?= site_url('front_office/ajax/val_stok_obat') ?>',
                data: { id: id},
                success: function(data)
                {
                  //alert(data);
                  data = JSON.parse(data);
              
                  var json = data;
                  var forum = json.val_stok;
                  for (var i = 0; i < forum.length; i++) {
                      var object = forum[i];
                      for (property in object) {
                          var value = object[property];
                          //alert(property + "=" + value); // This alerts "id=1", "created=2010-03-19", etc..
                          $(".stok"+property).text(value);
                          if(value <= '0'){
                             $(".minstoka"+property).css('color','red');
                             $(".minstoka"+property).css('font-weight','bold');
                          }
                          else if(value <= '30'){  
                             $(".minstoka"+property).css('color','red');
                             $(".minstoka"+property).css('font-weight','bold');
                          }
                      }
                  }
                
                 
                },
                error: function(data)
                {
                  //$(".stok"+id).text('Failed !!');
                  //$(".stok"+id).css('color','red');
                  //$(".refresh_stok"+id).css('display','inline-block');
                }
              }); 
            }
            setTimeout(stok('Loading ..'), 1000);

          });

          </script>

      </div>
      
    </div>

   
      
  
</div>

