<?php
/*error_reporting(E_ALL^(E_NOTICE|E_WARNING));
ini_set('display_errors',1);
error_reporting(0);*/
?>

<!-- Content Header (Page header) -->
<div class="content-header">
  <div class="container-fluid">
    <div class="row mb-1">
      <div class="col-sm-12">
        <!-- <h1 class="m-0 text-dark">Laporan Neraca []</h1> -->
      </div><!-- /.col -->
    </div><!-- /.row -->
  </div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->

<!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-12">
            <!-- Default box -->
            <div class="card">
              <div class="card-header bg-info">
                <h3 class="card-title ">Jadwal Angsuran</h3>
                <div class="card-tools">
                  <button type="button" class="btn btn-tool" data-card-widget="collapse" title="Collapse">
                    <i class="fas fa-minus"></i>
                  </button>
                  <button type="button" class="btn btn-tool" data-card-widget="remove" title="Remove">
                    <i class="fas fa-times"></i>
                  </button>
                </div>
              </div>

              <!-- /.card-header -->
      <div class="card-body">
        
          <?php          
          $kode=$_SESSION['kode'];
          if(isset($_POST['rekening'])){

            $rekening=$_POST['rekening'];

            if($_POST['rekening']=='Pilih')
              $where="where rekening='0'";
            else
              $where="where a.rekening='$rekening' ";

          }else{
            $par1="";
            $par2="";
            $rekening="";

            $where="where a.rekening='$rekening'";
           
          }
          ?>
          <form role="form" id="quickForm" action="" method="POST">
            <div class="form-group row">
              <label for="nama" class="col-1 m-2">Rekening</label>
              <input type="text" id="rekening" name="rekening" maxlength="13" value="<?php if(isset($_POST['rekening'])){echo $_POST['rekening'];} ?>" class="form-control col-sm-2" autofocus >
                     
              
                <button type="submit" name="proses" class="btn btn-primary" style="float: right" value="Cari"  onchange="this.form.submit();" class="btn btn-info"><i class="fas fa-search"></i></button>
              </div>
                <?php 
               if(isset($_POST['rekening'])){
                $_SESSION['jangsuran']['judul']="JADWAL ANGSURAN";
                $_SESSION['jangsuran']['unit']="BMT UGT NUSANTARA";
                $_SESSION['jangsuran']['rekening']=$_POST['rekening'];
                
                if($_POST['rekening']=='Pilih')
                  $_SESSION['laporan']['rekening']='Pilih';
                else
                  $_SESSION['laporan']['rekening']="select * from pinjaman where rekening='".$_POST['rekening']."'";

                ?>
                <div>
                  
                <a href="pdf/lap_jadwal_angsuranpdf.php" target="_blank" style="float: right;margin-top: 10px;" class="btn btn-success"><i class="fa fa-print"></i> PDF</a>

              <?php } ?>


              </div>          
          </form>
                   
          <hr>

            <?php
            function buatrp($angka){
              $jadi =number_format($angka,2,'.',',');
            //$jadi ="Rp. " .number_format($angka,2,'.',',');
              return $jadi;
            }

            include 'koneksi.php';
              $queryp = "SELECT a.tgl as tgl,a.rekening as rekening, a.plafond AS plafond, a.margin AS margin, a.jangkawaktu/15 AS jangkawaktu,b.nama AS nama,b.alamat AS alamat from pinjaman a LEFT JOIN registrasi b ON a.register=b.id $where  ";
              $query  =mysqli_query($koneksi,$queryp);
             
                if(mysqli_num_rows($query)){
                while ($data = mysqli_fetch_assoc($query)) {
                   
                  extract($data);
                  $tgl=$tgl;
                  }
                  ?>
<?php
 $nama_bln=array(1=>"01","02","03","04","05","06","07","08","09","10","11","12");
list($awal,$tengah,$akhir)=explode('-',$tgl,3);


 $tanggal=$akhir;
 "-";
if ($tengah < 10)  {
$bulan=str_replace("0","",$tengah);
}else{
$bulan=$tengah;
}

//$bulan=$tengah;
$nama_bln[$bulan];
"-";
$tahun=$awal;

   /* $bunga_perbulan=$bunga_pertahun/12;*/

    $bunga_rp = $plafond/$margin;

    $angsuran_margin=$plafond*$margin/100;

    $angsuran_pokok = $plafond/$jangkawaktu;

    $jumlah = $angsuran_pokok+$angsuran_margin;
    
    echo "<pre>";
    echo "Nama                     = "."<b>".$nama."</b>"."<br>";

    echo "Alamat                   = "."<b>".$alamat."</b>"."<br>";
    echo "Tgl Setuju               = "."<b>".date('d-m-Y',strtotime($tgl))."</b>"."<br>";
    echo "Jumlah                   = "."<b>".buatrp($plafond)."</b>"."<br>";

    echo "Jangka Waktu             = "."<b>".$jangkawaktu." Hari"."</b>"."<br>";

    /*echo "Ujroh %                  = "."<b>".$margin.' %'."</b>"."<br>";

    echo "Ujroh Rp                 = "."<b>".buatrp($angsuran_margin).''."</b>".'<br>';*/

/*    echo "<br>";*/

    /*echo "________________________________________ ( + )<br>";

    echo "Total Angsuran Per Bulan = "."<b>".buatrp($jumlah)."</b>";*/

    echo "</pre>";



    $row=$plafond;

  $no=1;

?>
<hr>

          <table id="example3" class="table table-bordered table-hover">
            <thead>
    <tr>
     <th>Ke</th>
      <th style="text-align: center;">Tanggal</th>
      <th style="text-align: center;">Bayar</th>
      <!-- <th style="text-align: center;">Angsuran Margin</th> -->
      <!-- <th style="text-align: center;">Total Bayar</th> -->
      <th style="text-align: center;">Sisa</th>
    </tr>
            </thead>
            <tbody>
          
    <tr>
      <td align="center">1</td>
      <td align="center">2</td>
      <td align="center">3</td>
     <!--  <td align="center">4</td>
      <td align="center">5</td> -->
      <td align="right"><b><?php echo buatrp($plafond);?></b></td>
    </tr>

<?php while ( $row > 1){ 

$bulan=$bulan+1;
if ($bulan > 12){
$bulan=1;
$tahun=$tahun+1;
}else{
$bulan=$bulan;
}

  $row=$row-$angsuran_pokok; ?>
            
      <tr>
      <td align="center"><?php echo $no++;?></td>
      <td align="center"><?php echo $tanggal."-";echo $nama_bln[$bulan];echo "-". $tahun;?></td>
      <td align="right"><?php echo buatrp($angsuran_pokok);?></td>
     <!--  <td align="right"><?php echo buatrp($angsuran_margin);?></td> 
      <td align="right"><?php echo buatrp($jumlah);?></td>-->
      <td align="right"><?php echo buatrp($row);?></td>
    </tr>  

  <?php }

    $tot_ang_pokok=$angsuran_pokok*$jangkawaktu;
    $tot_ang_margin=$angsuran_margin*$jangkawaktu;
    $tot_jumlah=$jumlah*$jangkawaktu;
  ?>

    <tr>
      <td><b>100</td></b>
      <td><b>Total</td></b>
      <td><b><?php echo buatrp($tot_ang_pokok);?></b></td>
      <!-- <td><b><?php echo buatrp($tot_ang_margin);?></b></td> -->
      <!-- <td><b><?php echo buatrp($tot_jumlah);?></b></td> -->
      <td></td>
    </tr>
  </table>
</div>

<div class="container"><br></div>


                <?php }?>
              </tbody>
              </table>

               <?php 
               if(isset($_POST['rekening'])){
                $_SESSION['jangsuran']['sql']= $queryp;
                }
                ?>
              
            </div>
            <!-- /.card-body -->
          </div>
          <!-- /.card -->
        </div>
        <!-- /.col -->
      </div>

      <!-- /.row -->
    </section>
    <!-- /.content -->


