<?php
include "asset/fungsi/fungsi_rupiah.php"; 
?>
<script>
function printPDF(pdfUrl)
{
var w = window.open(pdfUrl);
w.print();
w.close();
}
</script>
<div class="col-md-9">
<div class="panel panel-default">
<div class="panel-body">
	

	<div class="page-header">
			<h2>Laporan Pemenang</h2>
			<ol class="breadcrumb">

				<li><a href="dashboard.php"><i class="fa fa-home"> Home</i></a></li>
				<li class="active"><i class="fa fa-trophy"> Laporan Pemenang  </i></li>
            </ol>


<?php
if(isset($_POST['keterangan'])){
  $rs=mysql_query("Update pemenang SET keterangan='1' Where id_paket='".$_POST['id_paket']."'");
  if($rs)
  {
    ?>
      <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-success  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Data Berhasil divalidasi</center>
          
          </div></div></div>
    <?php
  }else
  {
    ?>
      <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-danger  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Terjadi kesalahan</center>
          
          </div></div></div>
    <?php
  }

}


if(isset($_POST['batal_validasi'])){
  $rs=mysql_query("Update pemenang SET keterangan='0' Where id_paket='".$_POST['id_paket']."'");
  if($rs)
  {
    ?>
      <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-success  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Data Berhasil non validasi</center>
          
          </div></div></div>
    <?php
  }else
  {
    ?>
      <div class="row">
          <div class="col-md-offset-2 col-md-8">
          <div class="alert alert-danger  alert-dismissable">
          <button type="button" class="close" data-dismiss="alert">x</button>
            <center>Terjadi kesalahan</center>
          
          </div></div></div>
    <?php
  }

}
?>

<table id="tabel" class="table table-bordered display" cellspacing="0">
		<thead>
		<tr class="success">
			<th width="5%">No</th>
        	<th width="50%">Nama Paket</th>
            <th width="15%">Pemenang</th>
            <th width="15%">Status</th>
            <th width="15%"><center>Aksi</center></th>
         
		</tr>
		</thead>

		<tbody>
		<?php
  		$nomor=0;
      $lulus="lulus";
  		$rw=mysql_query("Select * from (select * from pemenang order by nilai_bcr DESC,harga_penawaran ASC ) AS pemenang Group by pemenang.id_paket ");
  		while($s=mysql_fetch_array($rw))
  		
  		{
  		$nomor++;
  		
  		?>
   		<tr>
    		<td align="center"><?php echo $nomor; ?></td>
    		<td><?php echo $s['nama_paket']; ?></td>
         <?php
        if($s['status']=='lulus'){
          ?> 
        <td ><?php echo $s['nama_perusahaan']; ?></td>
        <?php
        }else{
          ?>

        <td ><center>-</center></td>
          <?php
        }
        ?>
        <?php 
        if($_SESSION['jabatan']=='admin'){

        if($s['keterangan']==0){
          ?>
          <td align="center"><span class="label label-danger" >Belum Validasi</span></td>
          <td>
        <center>
              <form method="post">
        <button href="#" class="btn btn-default tooltipsku" type="button" data-placement="top" title="Lihat Rincian" data-toggle="modal" data-target="#modal_rincian<?php echo $s['id_paket'];?>"><i class="fa fa-folder-open" >  </i></button>
    
          <input type="hidden" name="id_paket" value="<?php echo $s['id_paket'];?>">
        <button href="#" class="btn btn-success tooltipsku" name="keterangan" type="submit" data-placement="top" title="Validasi"><i class="fa fa-check" >  </i></button>

      </form>
        </center>
        </td>
        <?php
        }else{  ?>
          <td align="center"><span class="label label-success" > Validasi</span></td>
          <td>
        <center>
              <form method="post">
        <button href="#" class="btn btn-default tooltipsku" type="button" data-placement="top" title="Lihat Rincian" data-toggle="modal" data-target="#modal_rincian<?php echo $s['id_paket'];?>"><i class="fa fa-folder-open" >  </i></button>
    
          <input type="hidden" name="id_paket" value="<?php echo $s['id_paket'];?>">
       <button href="#" class="btn btn-danger tooltipsku" name="batal_validasi" type="submit" data-placement="top" title="Batal Validasi"><i class="fa fa-times" >  </i></button>

      </form>
        </center>
        </td>
        <?php
        }
        }else if($_SESSION['jabatan']=='panitia'){
          if($s['keterangan']==0){
          ?>
          <td align="center"><span class="label label-danger" >Belum Validasi</span></td>
          <td>
        <center>
              <form method="post">
        <button href="#" class="btn btn-default tooltipsku" type="button" data-placement="top" title="Lihat Rincian" data-toggle="modal" data-target="#modal_rincian<?php echo $s['id_paket'];?>"><i class="fa fa-folder-open" >  </i></button>
    
          <input type="hidden" name="id_paket" value="<?php echo $s['id_paket'];?>">
        <button href="#" class="btn btn-success tooltipsku" name="keterangan" type="submit" data-placement="top" title="Validasi"><i class="fa fa-check" >  </i></button>

      </form>
        </center>
        </td>
        <?php
        }else{  ?>
          <td align="center"><span class="label label-success" > Validasi</span></td>
          <td>
        <center>
              <form method="post">
        <button href="#" class="btn btn-default tooltipsku" type="button" data-placement="top" title="Lihat Rincian" data-toggle="modal" data-target="#modal_rincian<?php echo $s['id_paket'];?>"><i class="fa fa-folder-open" >  </i></button>
    
          <input type="hidden" name="id_paket" value="<?php echo $s['id_paket'];?>">
       
      </form>
        </center>
        </td>
        <?php
        }
        }
        ?>
    		
		</tr>
		<?php
 		 }
 		?>
		</tbody>
</table>

<?php

$rw=mysql_query("Select * from pemenang ");
while($s=mysql_fetch_array($rw)){ 
?>
<div id="modal_rincian<?php echo $s['id_paket'];?>" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">

                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Rincian Pemenang   </strong></h4>

            </div>
            <div class="modal-body">
              
<form class="form-horizontal" role="form" enctype="multipart/form-data">
<div class="form-group">
    <center>  <label for="nama_paket" class="col-sm-4 control-label" >Nama Paket</label></center>
      <div class="col-md-7">
         <input type="text" class="form-control" id="nama_paket<?php echo $s['id_paket'];?>" name="nama_paket" value="<?php echo $s['nama_paket'];  ?>" required readonly> 
      </div>
   </div>
   <div class="form-group">
    <center>  <label for="nama_proyek" class="col-sm-4 control-label" >Nama Proyek</label></center>
      <div class="col-md-7">
         <input type="text" class="form-control" id="nama_proyek<?php echo $s['id_paket'];?>" name="nama_proyek" value="<?php echo $s['nama_proyek'];  ?>" required readonly> 
      </div>
   </div>
   
    <div class="form-group">
    <center>  <label for="hps" class="col-sm-4 control-label">HPS </label></center>
      <div class="col-md-7">
       <div class="input-group">
      <div class="input-group-addon">Rp.</div>
         <input rows="3" class="form-control" id="hps<?php echo $s['id_paket'];?>" name="hps" value="<?php $hps=format_rupiah($s['hps']);  echo $hps;  ?>" required readonly> 
      <div class="input-group-addon">.00</div>
    </div>
      </div>
   </div>
   <div class="form-group">
    <center>  <label for="kecamatan" class="col-sm-4 control-label">Keterangan </label></center>
      <div class="col-md-6">
         <input type="text" class="form-control" id="kecamatan<?php echo $s['id_paket'];?>" name="kecamatan" value="<?php echo $s['kecamatan'];  ?>" required readonly> 
      </div>
   </div>
               
  <hr width="90%"/>
  <h5 align="center">Data Pemenang</h5>
  <div class="text-right ">
<a type="button" href="system/web/print_pemenang.php?id_paket=<?php echo $s['id_paket'];?>" target="_blank" class="btn btn-default tooltipsku" data-placement="right" title="Print"><i class="fa fa-print"></i></a>
<a type="button" href="system/web/pdf_pemenang.php?id_paket=<?php echo $s['id_paket'];?>" target="_blank" class="btn btn-default tooltipsku" data-placement="left" title="Download pdf"><i class="fa fa-download"></i></a>

</div><p></p>
  <table id="" class="table table-bordered display" cellspacing="0" width="100%">
		<thead>
		<tr class="success">
			<th width="2%">No</th>
        	<th>Nama Perusahaan</th>
          <th >Harga Penawaran</th>
          <th >Kualifikasi</th>
          <th >Administrasi</th>
           <th >Teknis</th>
            <th >Harga</th>
             <th >Total</th>
              <th >Nilai BCR</th>
              <th >Ket.</th>
         
		</tr>
		</thead>
		<tbody>
		<?php
        $id_paket=$s['id_paket'];
      $nomor=0;
      $query=mysql_query("select * from pemenang where id_paket='$id_paket' order by nilai_bcr DESC,harga_penawaran ASC ");
      while ($ss=mysql_fetch_array($query)) { 
        $nn=mysql_query("select min(harga_penawaran) AS min from pemenang where status='lulus'");
        $ff=mysql_fetch_array($nn);
        $nomor++;
        
   
 $harga=format_rupiah($ss['harga_penawaran']); 

      if($ss['jumlah_kual']<350){
        $gugur1="danger";
      }else{
        $gugur1="default";
      }

      if($ss['jumlah_adm']<350){
        $gugur2="danger";
      }else{
        $gugur2="default";
      }

      if($ss['jumlah_teknis']<350){
        $gugur3="danger";
      }else{
        $gugur3="default";
      }

      if($ss['jumlah_harga']<70){
        $gugur4="danger";
      }else{
        $gugur4="default";
      }
      if($ss['jumlah_total']<1120){
        $gugur5="danger";
      }else{
        $gugur5="default";
      }
      if($ss['nilai_bcr']<1){
        $gugur6="danger";
      }else{
        $gugur6="default";
      }




        ?>
   		<tr>
        

      <tr >
    		<td align="center"><?php echo $nomor; ?></td>
    		<td ><?php echo $ss['nama_perusahaan']; ?></td>
        <td><?php echo "Rp. "; echo $harga; ?></td>
        <td class="<?php echo $gugur1;?>"><?php echo $ss['jumlah_kual']; ?></td>
        <td class="<?php echo $gugur2;?>"><?php echo $ss['jumlah_adm']; ?></td>
        <td class="<?php echo $gugur3;?>"><?php echo $ss['jumlah_teknis']; ?></td>
        <td class="<?php echo $gugur4;?>"><?php echo $ss['jumlah_harga']; ?></td>
        <td class="<?php echo $gugur5;?>"><?php echo $ss['jumlah_total']; ?></td>
        <td class="<?php echo $gugur6;?>"><?php echo $ss['nilai_bcr']; ?></td>
      <?php
      if($ss['status']=='lulus' and $ff['min']==$ss['harga_penawaran']){
    
        echo"<td><center><span class='label label-success'>Pemenang</span></center></td>";
      }else if($ss['status']=='lulus'){
        echo"<td><center>-</center></td>";
      }else {
        echo"<td><center><span class='label label-danger'>GUGUR</span></center></td>";
      }
      ?>
		</tr>
    <?php
    }
    ?>

		</tbody>
</table>
  </form>
            </div>


        </div>
    </div>
</div>
<?php
}
?>
</div>
</div>
</div>
</div>