<?php
	include "header.php";
	include "../koneksi.php";
?>
<div class="row">
<div class="col-md-12">
	 <nav>
    <ol class="breadcrumb">
		<li class="breadcrumb-item">Dashbard</li>
        <li class="breadcrumb-item">Data Notifications</li>
    </ol>
</nav>
</div>
</div>
<div style="width:100%;height100px;overflow:scroll;" >
<div id="container1" style="position: relative; z-index: 1;">
<?php $data = mysqli_query ($koneksi, " select 
														plan.PlanID,
														plan.DatePlan,
														plan.MesinID,
														mesin.Mesin,
														plan.ProductID,
														product.ItemDescription,
														product.SLoc,
														plan.QtyPlan,
														plan.Prioritas,
														plan.MaterialID,
														material.RawMat,
														plan.POOR,
														plan.WH_Conf,
														plan.Pbb_Conf
												  from 
												  plan
												  INNER JOIN mesin
												  ON plan.MesinID=mesin.MesinID
												  INNER JOIN product
												  ON plan.ProductID=product.ProductID
												  INNER JOIN material
												  ON plan.MaterialID=material.MaterialID
												  WHERE plan.PlanID = '$_GET[id]'
												  order by plan.Prioritas ASC");
$row = mysqli_fetch_array ($data);
?>
<table class="table table-bordered">
        <thead>
		<tr>
			<th width="12%">
				Tanggal
			</th>
			<th width="7%">
				Mesin
			</th>
			<th width="22%">
				Product
			</th>
			<th width="22%">
				Material
			</th>
			<th width="5%">
				SLoc
			</th>
			<th width="5%">
				Quantity
			</th>
			<th width="7%">
				POOR
			</th>
			<th width="9.5%">
				STPJ
			</th>
			<th width="9.5%">
				PBB
			</th>
		</tr>
		</thead>
		<tbody>
		<tr>
			<td width="12%" style="vertical-align: middle;">
				<?php 
				$tanggal = $row['DatePlan'];
				$day = date('D', strtotime($tanggal));
				$dayList = array(
					'Sun' => 'Minggu',
					'Mon' => 'Senin',
					'Tue' => 'Selasa',
					'Wed' => 'Rabu',
					'Thu' => 'Kamis',
					'Fri' => 'Jumat',
					'Sat' => 'Sabtu'
				);
				echo date ("d-m-Y", strtotime($tanggal)).' '.$dayList[$day]; ?>
			</td>
			<td width="7%" style="vertical-align: middle;">
				<?php echo $row['Mesin']; ?>
			</td>
			<td width="22%" style="vertical-align: middle;">
				<?php echo $row['ItemDescription']; ?>
			</td>
			<td width="22%" style="vertical-align: middle;">
				<?php echo $row['RawMat']; ?>
			</td>
			<td width="5%" style="vertical-align: middle;">
				<?php echo $row['SLoc']; ?>
			</td>
			<td width="5%" style="vertical-align: middle;">
				<?php echo $row['QtyPlan']; ?>
			</td>
			<td width="7%" style="vertical-align: middle;">
				<?php echo $row['POOR']; ?>
			</td>
			<td width="9.5%" style="vertical-align: middle;">
				<?php if ($row['WH_Conf']=='1') { ?>
					<a href="../plan/stpj.php?id=<?php echo $row['PlanID']; ?>&qty=<?php echo $row['QtyPlan']; ?>" class="btn btn-success" style="width: 100%;">Confirmed</a>
				<?php } else if($row['WH_Conf']=='0') { ?>
			   		<a href="../plan/stpj.php?id=<?php echo $row['PlanID']; ?>&qty=<?php echo $row['QtyPlan']; ?>" class="btn btn-danger" style="width: 100%;">UnConfirmed</a>
				<?php } else { echo "<text style='font-weight: bold;'>On Progres..<text>"; } ?>
			</td>
			<td width="9.5%" style="vertical-align: middle;">
			    <?php if ($row['Pbb_Conf']==NULL) { ?>
					<a class='btn btn-danger' class='editbtn' id="material" data-id="<?php echo $_GET['id']; ?>" style="width: 100%;">Unconfirmed</a>
				<?php } else if($row['Pbb_Conf']=='0') { ?>
			   		<a class='btn btn-success' class='editbtn' id="material" data-id="<?php echo $_GET['id']; ?>" style="width: 100%;">Confirmed</a>
				<?php } else { echo "<text style='font-weight: bold;'>Release..<text>"; } ?>
			</td>
		</tr>
		</tbody>
	</table>

</div>
</div>

<div id="modal-material" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal">&times;</button>
          <h4 class="modal-title">PENYERAHAN BAHAN BAKU</h4>
        </div>
          <div class="modal-body">
            <div id="data-material">
            
            </div>        
          </div>
          
          <div class="modal-footer">
          <button type="button" class="btn btn-info btn-lg" data-dismiss="modal">Batal</button>
          <?php if ($row['Pbb_Conf']==NULL) { ?>
          	<a class="btn btn-success btn-lg" style="width: 30%" href="../dashboard/pbb_aprv.php?id=<?php echo $row['PlanID']; ?>&notif=1">Confirm</a>
          <?php } else { ?>
          <a class="btn btn-danger btn-lg" style="width: 30%" href="../dashboard/pbb_aprv.php?id=<?php echo $row['PlanID']; ?>&notif=1">Cancel</a>
          
      	<?php } ?>
          </div>
      </div>
    </div>
  </div>

  <script type="text/javascript">
  	$(document).on('click','#material',function(e){
    e.preventDefault();
    $("#modal-material").modal('show');
    $.post('pbb_conf.php',
      {
        id:$(this).attr('data-id')
      },
      function(html){
        $("#data-material").html(html);
      }   
    );
  });
  </script>

	

