<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta charset="utf-8" />
<title>Sudila Printers</title>
<meta name="description" content="overview &amp; stats" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- bootstrap & fontawesome -->
<link rel="stylesheet" href="assets/css/bootstrap.min.css" />
<link rel="stylesheet" href="assets/font-awesome/4.5.0/css/font-awesome.min.css" />
<!-- page specific plugin styles -->
<!-- text fonts -->
<link rel="stylesheet" href="assets/css/fonts.googleapis.com.css" />
<!-- ace styles -->
<link rel="stylesheet" href="assets/css/ace.min.css" class="ace-main-stylesheet" id="main-ace-style" />
<!--[if lte IE 9]>
    <link rel="stylesheet" href="assets/css/ace-part2.min.css" class="ace-main-stylesheet" />
<![endif]-->
<link rel="stylesheet" href="assets/css/ace-skins.min.css" />
<link rel="stylesheet" href="assets/css/ace-rtl.min.css" />
<!--[if lte IE 9]>
  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
<![endif]-->
<!-- inline styles related to this page -->
<!-- ace settings handler -->
<script src="assets/js/ace-extra.min.js"></script>
<!-- HTML5shiv and Respond.js for IE8 to support HTML5 elements and media queries -->
<!--[if lte IE 8]>
    <script src="assets/js/html5shiv.min.js"></script>
    <script src="assets/js/respond.min.js"></script>
<![endif]-->
<style>
th {
	text-align:center
}
@media print {
body * {
	visibility: hidden;
}
#print_hide {
	display: none;
}
#print_view, #print_view * {
	visibility: visible;
}
#print_view {
	position: relative;
	font-size: 14px;
}
a[href]:after {
	content: none !important;
}
.col-md-8 {
	width: 66.66666667%;
}
.col-md-4 {
	width: 33.33333333%
}
.col-md-12,.col-sm-12, .list-unstyled {
	width: 100%
}
.lead {
	font-size: 21px;
}
.col-sm-7 {
	width: 70%;
	float: left;
}
.col-sm-5 {
	width: 30%;
	float: left;
}
}
</style>
</head>
<body class="no-skin">
<?php include 'common/navbar.php'; ?>
<div class="main-container ace-save-state" id="main-container">
  <?php include 'common/sidebar.php';
	$title = '';
	if(isset($_GET['oid'])) {
		$oid = htmlspecialchars(strip_tags(trim($_GET['oid'])), ENT_QUOTES, 'UTF-8');
		
		if(empty($oid)) {
			$redirectUrl = "online_orders?st=0";
			echo "<script type=\"text/javascript\">";
			echo "window.location.href = '$redirectUrl'";
			echo "</script>";
		}

	} else {
		$redirectUrl = "home";
		echo "<script type=\"text/javascript\">";
		echo "window.location.href = '$redirectUrl'";
		echo "</script>";
	}
  ?>
  <div class="main-content">
    <div class="main-content-inner">
      <div class="breadcrumbs ace-save-state" id="breadcrumbs">
        <ul class="breadcrumb">
          <li> <i class="ace-icon fa fa-home home-icon"></i> <a href="home">Home</a> </li>
		   <li><a href="online_orders?st=0">Order Pool</a></li>
          <li class="active">Order Details</li>
        </ul>
        <!-- /.breadcrumb --> 
      </div>
      <div class="page-content"> 
        <!-- /.page-header -->
        <div class="space-10"></div>
        <!-- PAGE CONTENT BEGINS -->
        <div class="row">
          <div class="col-sm-12">
            <?php $sql_ordr = mysqli_query( $conn, "SELECT *, DATE_FORMAT(order_date, '%Y-%m-%d') AS dt FROM order_details WHERE id='$oid'") or die();
			if(mysqli_num_rows($sql_ordr) == 0) {
				echo '<div class="well"><h5>Invalid Order Number</h5></div>';
			} else {
				$row_ordr = mysqli_fetch_array($sql_ordr);
				$order_id = $row_ordr['inv_no'];
			?>
            <div class="widget-box transparent" id="print_view">
              <div class="widget-body">
                <div class="widget-main">
                  <div class="row">
                    <div class="col-md-12">
                      <div class="widget-header-large1"> <img class="pull-right" src="../images/logo/logo.png" width=150>
                        <h4 class="widget-title"><u>Buddhist Books</u></h4>
                        <p>Reg. Address: <br>
                          Website: www.buddhistbooksonline.com<br>
                          Facebook: <br>
                          Contact No: (+94) 37 223 4446</p>
                      </div>
                    </div>
                  </div>
                  <div class="hr"></div>
                  <div class="row">
                    <div class="col-sm-12">
                      <h2 style="margin-top:0"><b>Invoice</b></h2>
                    </div>
                    <div class="col-sm-7">
                      <ul class="list-unstyled spaced">
                        <li> <b>Date: </b> <?php echo $row_ordr['dt'] ?> </li>
                        <li> <b>Invoice for: </b> <br>
                          <p><?php echo $row_ordr['f_name'].' '.$row_ordr['l_name']; ?> <br>
                          <?php echo $row_ordr['address_1'].' '.$row_ordr['address_2'] ?><br>
                          <?php echo $row_ordr['city']; ?> </p></li>
                        <li> <b>Tel: </b> <?php echo $row_ordr['tel_no'] ?> </li>
                      </ul>
					</div>
					<div class="col-sm-5">
                      <ul class="list-unstyled spaced">
                        <li> <b>WayBill # </b> <br> &nbsp;</li>
                        <li> <b>Invoice # </b> <br>
                          <?php echo $order_id; ?> </li>
                        <li> <b>Currency </b> <br>
                          SLRs </li>
                      </ul>
                    </div>
                  </div>
                  <!-- /.row -->
                  <div class="hr"></div>
                  <div class="space"></div>
                  <div class="table-responsive">
                    <table class="table table-striped table-bordered">
                      <thead>
                        <tr>
                          <th>#</th>
                          <th>Description</th>
                          <th>Qty</th>
                          <th>Unit Price</th>
                          <th>Discounted Price</th>
                          <th>Total Price</th>
                        </tr>
                      </thead>
                      <tbody>
                        <?php $sql_c = mysqli_query($conn, "SELECT * FROM cart_details WHERE inv_no = '$order_id'");
						$x = 0;
						$s_tot = $dis_tot = 0;
						while($row_c = mysqli_fetch_array($sql_c)) { $x++; ?>
                        <tr>
                          <td class="center"><?php echo $x; ?>.</td>
                          <td><?php echo $row_c['name']; ?></td>
                          <td align="right"><?php echo $row_c['Qty']; ?></td>
                          <td align="right"><?php echo $row_c['item_price']; ?></td>
                          <td align="right"><?php echo $row_c['price']; ?></td>
                          <td align="right"><?php $subtot = $row_c['price']*$row_c['Qty']; echo number_format($subtot, 2);  ?></td>
                        </tr>
                        <?php $dis_tot += $subtot; $s_tot += $row_c['item_price']*$row_c['Qty']; } ?>
                      </tbody>
                    </table>
                  </div>

                  <div class="row">
                    <div class="col-sm-7 text-right">
                      <h5> SubTotal: </h5>
                      <h5> Total Discount: </h5>
                      <h5> Total Amount: </h5>
                      <h5> Delivery Charges: </h5>
                      <h4><b> GRAND TOTAL: </b></h4>
                    </div>
                    <div class="col-sm-5 text-right">
                      <h5>LKR <?php echo number_format($s_tot, 2); ?> </h5>
                      <h5>LKR <?php echo number_format($s_tot-$dis_tot, 2); ?> </h5>
                      <h5>LKR <?php echo number_format($dis_tot, 2); ?> </h5>
                      <h5>LKR <?php echo $row_ordr['delivery_chg'] ?> </h5>
                      <h4><b>LKR <?php echo number_format($row_ordr['delivery_chg']+$dis_tot, 2); ?> </b></h4>
                    </div>
                  </div>
				  <div class="hr"></div>
                  <div class="row">
                    <div class="col-md-12">
                      <p>Remarks:</p>
                      <br>
                      <br>
                      <br>
                      <br>
                      <p>Checked by:</p>
                    </div>
                  </div>

                  <div id="print_hide" style="padding-top:30px">
                    <button class="btn btn-primary btn-sm" id="print"><i class="fa fa-print"></i> &nbsp;PRINT</button>
                  </div>
                </div>
              </div>
            </div>
            <?php } ?>
          </div>
        </div>
        <!-- PAGE CONTENT ENDS --> 
      </div>
      <!-- /.page-content --> 
    </div>
  </div>
  <!-- /.main-content -->
  <?php include 'common/footer.php'; ?>
</div>
<!-- /.main-container --> 

<!-- basic scripts --> 
<!--[if !IE]> -->
<script src="assets/js/jquery-2.1.4.min.js"></script>
<!-- <![endif]--> 
<!--[if IE]>
<script src="assets/js/jquery-1.11.3.min.js"></script>
<![endif]--> 
<script type="text/javascript">
	if('ontouchstart' in document.documentElement) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
</script> 
<script src="assets/js/bootstrap.min.js"></script> 
<!-- page specific plugin scripts --> 
<!--[if lte IE 8]>
  <script src="assets/js/excanvas.min.js"></script>
<![endif]--> 
<script src="assets/js/jquery.dataTables.min.js"></script> 
<script src="assets/js/jquery.dataTables.bootstrap.min.js"></script> 
<!-- ace scripts --> 
<script src="assets/js/ace-elements.min.js"></script> 
<script src="assets/js/ace.min.js"></script> 
<script src="assets/jquery.validate.min.js"></script>
<link rel="stylesheet" href="bootstrap-sweetalert/lib/sweet-alert.css" />
<script src="bootstrap-sweetalert/lib/sweet-alert.min.js"></script> 
<script src="assets/js/bootbox.js"></script> 
<!-- inline scripts related to this page --> 
<script type="text/javascript">
jQuery(function ($) {
	window.print();
	//initiate dataTables plugin
	var myTable =
	$('#dynamic-table')
	//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
	.DataTable({
		bAutoWidth: false,
		"aaSorting": [],
	});
});

document.querySelector("#print").addEventListener("click", function() {
	window.print();
});
</script>
</body>
</html>