<?php
	include 'db_Connection.php'; // load file db_Connection.php
	
	//Generate random number_format
	$number = rand(100,100000);
	$t=time();
	$random = $number.''.$t;
	
	//get PO Number
	$_GET['id'];
	$PO_Number = $_GET['id'];
	//echo "<script>alert('".$PO_Number."');</script>";
	$sql = "SELECT * FROM purchase_order INNER JOIN principal on purchase_order.Principal_Code = principal.Principal_Code WHERE PO_Number = '".$PO_Number."'";
	$rs_result = $conn->query($sql);
	while($row = $rs_result->fetch_assoc()) {	
		$Principal_Name = $row['Principal_Name'];
		$Address = $row['Address'];
		$City = $row['City'];
		$Phone = $row['Phone'];
		$PO_Date = $row['PO_Date'];	
		$PO_Amount = $row['PO_Amount'];		
    }
	
	$sql = "SELECT * FROM po_detail WHERE PO_Number = '".$PO_Number."'";
	$rs_result = $conn->query($sql);	
?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Master Customer</title>
    <!-- plugins:css -->
    <link rel="stylesheet" href="../../assets/vendors/mdi/css/materialdesignicons.min.css">
    <link rel="stylesheet" href="../../assets/vendors/ti-icons/css/themify-icons.css">
    <link rel="stylesheet" href="../../assets/vendors/css/vendor.bundle.base.css">
    <link rel="stylesheet" href="../../assets/vendors/font-awesome/css/font-awesome.min.css">
    <!-- endinject -->
    <!-- Plugin css for this page -->
    <link rel="stylesheet" href="../../assets/vendors/select2/select2.min.css">
    <link rel="stylesheet" href="../../assets/vendors/select2-bootstrap-theme/select2-bootstrap.min.css">
    <!-- End plugin css for this page -->
    <!-- inject:css -->
    <!-- endinject -->
    <!-- Layout styles -->
    <link rel="stylesheet" href="../../assets/css/style.css">
    <!-- End layout styles -->
    <link rel="shortcut icon" href="../../assets/images/favicon.png" />
	<!--get jquery -->
	<script src="../js/jquery-3.4.1.min.js"></script>
	<!--<script src="../js/jspdf.min.js"></script>-->
	<script src="../js/jspdf.umd.min.js"></script>
	<script src="../js/html2canvas.min.js"></script>	
	<!--
	<script src="../js/html2canvas.min.js"
        integrity="sha512-BNaRQnYJYiPSqHHDb58B0yaPfCu+Wgds8Gp/gU33kqBtgNS4tSPHuGibyoeqMV/TJlSKda6FXzoEyYGjTe+vXA=="
        crossorigin="anonymous" referrerpolicy="no-referrer">
	</script>	
	-->		
	
<style>
	.rTable { display: table; }
	.rTableRow { display: table-row; }
	.rTableHeading { display: table-header-group; }
	.rTableBody { display: table-row-group; }
	.rTableFoot { display: table-footer-group; }
	.rTableCell, .rTableHead { display: table-cell; }
	
	.rTable{
		display: table;
		width: 100%;
	}	
	.rTableRow{
		display: table-row;		
	}
	.rTableHeading{
		display: table-header-group;
		background-color: #ddd;	
	}
	.rTableCell, .rTableHead{
		display: table-cell;
		padding: 3px 10px;
		border: 1px solid #999999;
	}
	.rTableHeading{
		display: table-header-group;
		background-color: #ddd;	
		font-weight: bold;
	}
	.rTableFoot{
		display: table-footer-group;			
		font-weight: bold;
		background-color: #ddd;		
	}
	.rTableBody{
		display: table-row-group;					
	}
	.rFooter{
		display: table-cell;
		background-color: white;
		border: none;
	}
</style>	
	
<script>
window.jsPDF = window.jspdf.jsPDF;
function generatePdf() {	
    let jsPdf = new jsPDF('p', 'pt', [900, 900]);
    var htmlElement = document.getElementById('doc-target');
    // you need to load html2canvas (and dompurify if you pass a string to html)
    const opt = {
        callback: function (jsPdf) {
            jsPdf.save("PO.pdf");
            // to open the generated PDF in browser window
            // window.open(jsPdf.output('bloburl'));
        },
        margin: [50, 50, 50, 75],
        autoPaging: 'text',
        html2canvas: {
            allowTaint: true,
            dpi: 300,
            letterRendering: true,
            logging: false,
            scale: .8
        }
    };

    jsPdf.html(htmlElement, opt);
}
</script>
	
  </head>
  <body>
    <div class="container-scroller">
      <!-- partial:../../partials/_navbar.html -->
      <nav class="navbar default-layout-navbar col-lg-12 col-12 p-0 fixed-top d-flex flex-row">
        <div class="text-center navbar-brand-wrapper d-flex align-items-center justify-content-start">
          <a class="navbar-brand brand-logo" href="../../index.php"><img src="../../assets/images/logo_IMS.svg" alt="logo" /></a>
          <a class="navbar-brand brand-logo-mini" href="../../index.php"><img src="../../assets/images/logo-mini.svg" alt="logo" /></a>
        </div>
        <div class="navbar-menu-wrapper d-flex align-items-stretch">
		<!-- hapus ini -->
          <button class="navbar-toggler navbar-toggler align-self-center" type="button" data-toggle="minimize">
            <span class="mdi mdi-menu"></span>
          </button>
		<!-- end hapus ini -->	
          <ul class="navbar-nav navbar-nav-right">
            <li class="nav-item nav-profile dropdown">
              <a class="nav-link dropdown-toggle" id="profileDropdown" href="#" data-bs-toggle="dropdown" aria-expanded="false">
                <div class="nav-profile-img">
                  <img src="../../assets/images/faces/blank.png" alt="image">
                  <span class="availability-status online"></span>
                </div>
                <div class="nav-profile-text">
                  <p class="mb-1 text-black">User Name</p>
                </div>
              </a>
              <div class="dropdown-menu navbar-dropdown" aria-labelledby="profileDropdown">
                <a class="dropdown-item" href="#">
                  <i class="mdi mdi-cached me-2 text-success"></i> Activity Log </a>
                <div class="dropdown-divider"></div>
                <a class="dropdown-item" href="#">
                  <i class="mdi mdi-logout me-2 text-primary"></i> Signout </a>
              </div>
            </li>
			
            </li>
			
            <li class="nav-item nav-settings d-none d-lg-block">
              <a class="nav-link" href="#">
                <i class="mdi mdi-format-line-spacing"></i>
              </a>
            </li>
			
          </ul>
		  <button class="navbar-toggler navbar-toggler-right d-lg-none align-self-center" type="button" data-toggle="offcanvas">
            <span class="mdi mdi-menu"></span>
          </button>
		</div>
      </nav>
      <!-- partial -->
      <div class="container-fluid page-body-wrapper">
        <!-- partial:../../partials/_sidebar.html -->
        <nav class="sidebar sidebar-offcanvas" id="sidebar">
          <ul class="nav">
            <li class="nav-item nav-profile">
              <a href="#" class="nav-link">
                <div class="nav-profile-image">
                  <img src="../../assets/images/faces/blank.png" alt="profile" />
                  <span class="login-status online"></span>
                  <!--change to offline or busy as needed-->
                </div>
                <div class="nav-profile-text d-flex flex-column">
                  <span class="font-weight-bold mb-2">User Name</span>
                  <span class="text-secondary text-small">Project Manager</span>
                </div>
                <i class="mdi mdi-bookmark-check text-success nav-profile-badge"></i>
              </a>
            </li>

            <li class="nav-item">
              <a class="nav-link" data-bs-toggle="collapse" href="#forms" aria-expanded="false" aria-controls="forms">
                <span class="menu-title">Manage</span>
                <i class="mdi mdi-format-list-bulleted menu-icon"></i>
              </a>
              <div class="collapse" id="forms">
                <ul class="nav flex-column sub-menu">
                  <li class="nav-item">
                    <a class="nav-link" href="../../pages/forms/Principal.php">Principal</a>
					<a class="nav-link" href="../../pages/forms/Customer.php">Customer</a>
                  </li>
                </ul>
              </div>
            </li>	

			<li class="nav-item">
              <a class="nav-link" data-bs-toggle="collapse" href="#maintance" aria-expanded="false" aria-controls="maintance">
                <span class="menu-title">Maintance</span>
                <i class="mdi mdi-table-large menu-icon"></i>
              </a>
              <div class="collapse" id="maintance">
                <ul class="nav flex-column sub-menu">
                  <li class="nav-item">
                    <a class="nav-link" href="Principal_Maintance.php">Principal</a>
					<a class="nav-link" href="Customer_Maintance.php">Customer</a>
                  </li>
                </ul>
              </div>
            </li>			
          </ul>
        </nav>
        <!-- partial -->
        <div class="main-panel">
          <div class="content-wrapper">            
            <div class="col-12 grid-margin">
                <div class="card">
                  <div class="card-body">
                    <!--<form class="form-sample" method='POST'>--> 						
                      <div class="" id="doc-target" style="letter-spacing: 0.01px;">
					                          					  
					  <div class="">
						  <div class="">
                            <label class=""><b><h1>Purchase Order</h1></b></label>  
							<img src="../../pages/images/logo.png" width="125" height="125" style="float:right">	
                          </div>
                          <div>									
							<label class="col-sm-3"><b><?php echo $Principal_Name; ?></b></label><label><b>PO Number</b></label>						
							<p style="padding: 0px; margin: 0px;">
							<label class="col-sm-3"><b><?php echo $Address; ?></b></label><label><b><?php echo $PO_Number; ?></b></label>
							</p>
							<p style="padding: 0px; margin: 0px;">
							<label class="col-sm-3"><b><?php echo $City; ?></b></label></label><label><b>Date</b></label>
							</p>
							<p style="padding: 0px; margin: 0px;">
							<label class="col-sm-3"><b><?php echo $Phone; ?></b></label><label><b><?php echo $PO_Date; ?></b></label>
							</p>	
						</div>						  
                        </div>                        																		
						<p>		
						<br>
						<br>
					  						
					<p><b>List Product Item Section</b></p>
					<!--start-->
                    <div class="rTable">
					<div class="rTableRow">
					<div class="rTableHead"><strong>Product Code</strong></div>
					<div class="rTableHead"><strong>Product Name</strong></div>
					<div class="rTableHead"><strong>Product Type</strong></div>
					<div class="rTableHead"><strong>Description</strong></div>
					<div class="rTableHead"><strong>Price</strong></div>
					<div class="rTableHead"><strong>Quantity</strong></div>
					<div class="rTableHead"><strong>Total</strong></div>					
					</div>					
					<?php 
                            while($row = $rs_result->fetch_assoc()) {						
                            echo '
								<div class="rTableRow">
								<div class="rTableCell">'.$row['Product_Code'].'</div>	
								<div class="rTableCell">'.$row['Product_Name'].'</div>	
                                <div class="rTableCell">'.$row['Product_Type'].'</div>
								<div class="rTableCell">'.$row['Description'].'</div>
								<div class="rTableCell">'.$row['Purchase_Price'].'</div>	
                                <div class="rTableCell">'.$row['Quantity'].'</div>
								<div class="rTableCell">'.$row['Total'].'</div>	
								</div>	
								';			
                        }							
						?>
					<div class="rFooter">&nbsp;</div>
					<div class="rFooter">&nbsp;</div>
					<div class="rFooter">&nbsp;</div>
					<div class="rFooter">&nbsp;</div>
					<div class="rFooter">&nbsp;</div>
					<div class="rTableHead"><span style="font-weight: bold;">Total:</span></div>
					<div class="rTableHead"><strong><?php echo $PO_Amount; ?></strong></div>
					</div>
				<!--end-->						
                 </div>
					  <p> </p>
					  <button class="btn btn-light" onclick="document.location.href='../../pages/forms/view_po.php'">Back</button>	
					  <button id="print" type="submit" class="btn btn-gradient-primary me-2" onclick="generatePdf()">Print</button>                      
                    <!--</form>-->
                  </div>
                </div>
              </div>
          <!-- content-wrapper ends -->
          <!-- partial:../../partials/_footer.html -->
          <footer class="footer">		  
          </footer>
          <!-- partial -->
        </div>
        <!-- main-panel ends -->
      </div>
      <!-- page-body-wrapper ends -->
    </div>
    <!-- container-scroller -->
    <!-- plugins:js -->
    <script src="../../assets/vendors/js/vendor.bundle.base.js"></script>
    <!-- endinject -->
    <!-- Plugin js for this page -->
    <script src="../../assets/vendors/select2/select2.min.js"></script>
    <script src="../../assets/vendors/typeahead.js/typeahead.bundle.min.js"></script>
    <!-- End plugin js for this page -->
    <!-- inject:js -->
    <script src="../../assets/js/off-canvas.js"></script>
    <script src="../../assets/js/misc.js"></script>
    <script src="../../assets/js/settings.js"></script>
    <script src="../../assets/js/todolist.js"></script>
    <script src="../../assets/js/jquery.cookie.js"></script>
    <!-- endinject -->
    <!-- Custom js for this page -->
    <script src="../../assets/js/file-upload.js"></script>
    <script src="../../assets/js/typeahead.js"></script>
    <script src="../../assets/js/select2.js"></script>
    <!-- End custom js for this page -->
  </body>
</html>