<!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>
#preloader{
	background:#efefef4f url(assets/images/loading5.gif) no-repeat center center; height:100%;position:fixed;z-index:9999999;right:0;left:0;bottom:0;top:0;overflow-y:hidden;display:none
}
.red {
	color: red !important
}
</style>
</head>
<body class="no-skin">
<div id="preloader"></div>
<?php include 'common/navbar.php'; ?>
<div class="main-container ace-save-state" id="main-container">
  <?php include 'common/sidebar.php';
	$title = '';
	
	// 0 - Pending orders
	// 1 - Accepted orders
	// 2 - Rejected Orders
	// 3 - Post/Courier
	// 4 - Delivered  Orders
	// 5 - Finished  Orders
	// 6 - Search  Orders
	
	if(isset($_GET['st']) && isset($_GET['oid'])) {
		$oid = htmlspecialchars(strip_tags(trim($_GET['oid'])), ENT_QUOTES, 'UTF-8');
		$st = htmlspecialchars(strip_tags(trim($_GET['st'])), ENT_QUOTES, 'UTF-8');
		
		if(empty($oid)) {
			$redirectUrl = "online_orders?st=$st";
			echo "<script type=\"text/javascript\">";
			echo "window.location.href = '$redirectUrl'";
			echo "</script>";
		
		} else {
			if($st == 0 || empty($st)) {
				$st = 0;
				$title = 'Order Pool';
				
			} else if($st == 1) {
				$title = 'Accepted Orders';
			
			} else if($st == 2) {
				$title = 'Rejected Orders';
			
			} else if($st == 3) {
				$title = 'Post/Courier Orders';
			
			} else if($st == 4) {
				$title = 'Delivered Orders';
			
			} else if($st == 5) {
				$title = 'Finished Orders';
			
			} else if($st == 6) {
				$title = 'Search Orders';
			
			} else {
				$redirectUrl = "home";
				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=<?php echo $st; ?>"><?php echo $title; ?></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 * 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'];
					$uid = $row_ordr['user_id']; $gst = $row_ordr['guest'];
					$grand_tot1=$row_ordr['grand_total'];
					$del_chrg=$row_ordr['delivery_chg'];

					
					if($gst == 0) {
						$cus_type = 'Registered User';
					
					} else {
						$cus_type = 'Guest User';
					}
				?>
					<div class="widget-box transparent">
						<div class="widget-header widget-header-large">
							<h3 class="widget-title grey lighter">
								Order ID: <b><?php echo $order_id; ?></b>
							</h3>
							<div class="widget-toolbar no-border invoice-info">
								<!--<span class="invoice-info-label">Invoice:</span>
								<span class="red">#121212</span>
								<br />-->
								<span class="invoice-info-label">Order Date:</span>
								<span class="blue"><?php echo $row_ordr['order_date']; ?></span>
							</div>
							<!--<div class="widget-toolbar hidden-480">
								<a href="#">
									<i class="ace-icon fa fa-print"></i>
								</a>
							</div>-->
						</div>
						<div class="widget-body">
							<div class="widget-main">
								<div class="row">
									<div class="col-md-8">
										<h5><u>Customer Details</u>&nbsp;&nbsp;&nbsp;
											<div class="label label-lg label-yellow">
												<?php echo $cus_type; ?>
											</div>
										</h5><div class="space-6"></div>
										<div>
											<ul class="list-unstyled spaced">
												<li>
													<b>Name: </b> <?php echo $row_ordr['f_name'].' '.$row_ordr['l_name']; ?>
												</li>
												<li>
													<b>Delivery Address: </b> <?php echo $row_ordr['address_1'].' '.$row_ordr['address_2'] ?>
												</li>
												<li>
													<b>City: </b> <?php echo $row_ordr['city']; ?>
												</li>
												<li>
													<b>District: </b> <?php echo $row_ordr['district']; ?>
												</li>
												<br>
												<li>
													<i><b>Special Instructions: </b> <span class="blue"><?php echo $row_ordr['special_msg'] ?></span></i>
												</li>
											</ul>
										</div>
									</div><!-- /.col -->
									<div class="col-md-4">
										<div><div class="space-6"></div>
											<ul class="list-unstyled  spaced">
												<li>
													<b>Country: </b> <?php echo $country = $row_ordr['country']; ?>
												</li>
												<li>
													<b>Post Code/Zip Code: </b> <?php echo $row_ordr['postal_code'] ?>
												</li>
												<li>
													<b>Contact No: </b> <?php echo $row_ordr['tel_no'] ?>
												</li>
												<li>
													<b>Email: </b> <?php echo $row_ordr['email'] ?>
												</li>
											</ul>
										</div>
									</div><!-- /.col -->
								</div><!-- /.row -->
								<div class="space"></div>
								<div class="table-responsive">
									<table class="table table-striped table-bordered">
										<thead>
											<tr>
												<th class="center">#</th>
												<th>Image</th>
												<th>Name</th>
												<th>ISBN</th>
												<th>Weight (g)</th>
												<th>Unit Price (Rs)</th>
												<th>Discounted Price (Rs)</th>
												<th>Qty</th>
												<th>Subtotal (Rs)</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 = $tot_weight = $tot_qty = 0;
										while($row_c = mysqli_fetch_array($sql_c)) { $x++; ?>
											<tr>
												<td class="center"><?php echo $x; ?>.</td>
												<td><img src="../image/books/thumb/<?php echo $row_c['img']; ?>" width="50px"></td>
												<td><?php echo $row_c['name']; ?></td>
												<td><?php echo $row_c['isbn']; ?></td>
												<td><?php echo $row_c['weight']; ?></td>
												<td align="right"><?php echo $row_c['item_price']; ?></td>
												<td align="right"><?php echo $row_c['price']; ?></td>
												<td align="right"><?php echo $row_c['Qty']; ?></td>
												<td align="right"><?php $subtot = $row_c['price']*$row_c['Qty']; echo number_format($subtot, 2);  ?></td>
											</tr>
										<?php 
										$tot_weight += $row_c['weight']*$row_c['Qty'];
										$tot_qty += $row_c['Qty'];
										$dis_tot += $subtot;
										$s_tot += $row_c['item_price']*$row_c['Qty']; } ?>
										</tbody>
									</table>
								</div>

								<div class="hr hr8 hr-double hr-dotted"></div>

								<?php
								$sql_cou = mysqli_fetch_assoc(mysqli_query($conn, "SELECT * FROM courier_charges"));
								$cash_on_del = $sql_cou['cash_on_del'];
								$cash_on_1kg = $sql_cou['cash_on_1kg'];
								$courier_fee = $sql_cou['courier_fee'];
								$courier_1kg = $sql_cou['courier_1kg'];
								
								if($row_ordr['delivery_type'] == 1) { // Postal
									$sql_del = mysqli_fetch_assoc(mysqli_query($conn, "SELECT fee FROM postal_charges WHERE low_w < '$tot_weight' AND high_w >='$tot_weight'"));
									$del_fee = $sql_del['fee'];
								
								} else if($row_ordr['delivery_type'] == 2) { // Courier
									$a = floor($tot_weight/1000);
									
									if($tot_weight >= 0 && $tot_weight <= 1000) {
										$del_fee = $courier_fee;
									
									} else {
										$del_fee = $courier_fee + ($a * $courier_1kg);
									}
								
								} else if($row_ordr['delivery_type'] == 4) { // Cash on Delivery
									$a = floor($tot_weight/1000);
									
									if($tot_weight >= 0 && $tot_weight <= 1000) {
										$del_fee = $cash_on_del;
									
									} else {
										$del_fee = $cash_on_del + ($a * $cash_on_1kg);
									}
								
								} else if($row_ordr['delivery_type'] == 3) { // EMS
									$sql_wgt = mysqli_query($conn, "SELECT * FROM ems_charges WHERE country='$country'");
									if(mysqli_num_rows($sql_wgt) == 0) {
										$del_fee = 0;
											
									} else {
										$row_wgt = mysqli_fetch_assoc($sql_wgt);
										$max_w = $row_wgt['max_kg']*1000;
										
										if($row_wgt['max_kg'] == 20) {
											if($tot_weight > $max_w) {
												$del_fee = 0;
											
											} else {
												if($tot_weight > 10000) { // 10001-20000 Grams
													$f = $row_wgt['kg_20'];
													
													$r = $tot_weight - 1000;
													$w = ceil($r/500);
													$del_fee = $row_wgt['kg_1'] + ($w * $f);
												
												} else if($tot_weight > 1000) { // 1001-10000 Grams
													$f = $row_wgt['kg_10'];
													
													$r = $tot_weight - 1000;
													$w = ceil($r/500);
													$del_fee = $row_wgt['kg_1'] + ($w * $f);
												
												} else if($tot_weight > 500) { // 501-1000 Grams
													$del_fee = $row_wgt['kg_1'];
												
												} else if($tot_weight > 250) { // 251-500 Grams
													$del_fee = $row_wgt['g_500'];
												
												} else { // 0-250 Grams
													$del_fee = $row_wgt['g_250'];
												}
												
												$del_fee += 250; // Packing Charges
											}
										
										} else if($row_wgt['max_kg'] == 30) {
											if($tot_weight > $max_w) {
												$del_fee = 0;
											
											} else {
												if($tot_weight > 20000) { // 20001-30000 Grams
													$f = $row_wgt['kg_30'];
													
													$r = $tot_weight - 1000;
													$w = ceil($r/500);
													$del_fee = $row_wgt['kg_1'] + ($w * $f);
												
												} else if($tot_weight > 10000) { // 10001-20000 Grams
													$f = $row_wgt['kg_20'];
													
													$r = $tot_weight - 1000;
													$w = ceil($r/500);
													$del_fee = $row_wgt['kg_1'] + ($w * $f);
												
												} else if($tot_weight > 1000) { // 1001-10000 Grams
													$f = $row_wgt['kg_10'];
													
													$r = $tot_weight - 1000;
													$w = ceil($r/500);
													$del_fee = $row_wgt['kg_1'] + ($w * $f);
												
												} else if($tot_weight > 500) { // 501-1000 Grams
													$del_fee = $row_wgt['kg_1'];
												
												} else if($tot_weight > 250) { // 251-500 Grams
													$del_fee = $row_wgt['g_500'];
												
												} else { // 0-250 Grams
													$del_fee = $row_wgt['g_250'];
												}
												
												$del_fee += 250; // Packing Charges
											}
											
										} else {
											$del_fee = 0;
										}
									}
								
								} else {
									$del_fee = 0;
								}

								?>
								
								<div class="row">
									<div class="col-md-10 col-sm-9 col-xs-6 text-right">
										<h5>
											Total Qty:
										</h5>
										<h5>
											Total Amount:
										</h5>
										<h5>
											Total Discount:
										</h5>
										<h5>
											Sub Total:
										</h5>
										<h5>
											Delivery Charges (<?php echo $tot_weight; ?>g):
										</h5>
										<!--<h4><b>
											GRAND TOTAL:</b>
										</h4>-->
									</div>
									<div class="col-md-2 col-sm-3 col-xs-6 text-right">
										<h5>
											<span class="red"> <?php echo $tot_qty; ?></span>
										</h5>
										<h5>
											<span class="red">LKR <?php echo number_format($s_tot, 2); ?></span>
										</h5>
										<h5>
											<span class="red">LKR <?php echo number_format($s_tot-$dis_tot, 2); ?></span>
										</h5>
										<h5>
											<span class="red">LKR <?php echo number_format($dis_tot, 2); ?></span>
										</h5>
										<h5>
											<!-- <span class="red">LKR <?php //echo number_format($del_fee, 2); // echo $row_ordr['delivery_chg'] ?></span> -->
											<span class="red">LKR <?php  echo $row_ordr['delivery_chg'] ?></span>
										</h5>
										<!--<h4><b>
											<span class="red">LKR <?php //echo number_format($row_ordr['delivery_chg']+$dis_tot, 2); ?></span>
											</b>
										</h4>-->
									</div>
								</div>
<?php
	// $grand_tot = $dis_tot + $del_fee;
	$grand_tot = $grand_tot1;
	$pay_tbl = '';
	$pay_status = false;

	if($row_ordr['pay_method'] == 3) { // Bank Deposit
		if($row_ordr['delivery_type'] == 4) {
			$sts = '<span class="label label-lg label-danger">Pending</span>';
		
		} else {
			$sql_inv = mysqli_query($conn, "SELECT * FROM bank_deposit_verify WHERE order_id='$order_id'");
			if(mysqli_num_rows($sql_inv) == 0) {
				if($row_ordr['payment_status'] == 0) {
					$sts = '<span class="label label-lg label-danger">Pending</span>';
				
				} else {
					$sts = '<span class="label label-lg label-warning">Rejected</span>';
				}
				
			} else {
				$row_inv = mysqli_fetch_assoc($sql_inv);
				if($row_inv['status'] == 1 && $row_ordr['grand_total'] == $grand_tot) {
					$sts = '<span class="label label-lg label-success">Success</span>';
					$pay_status = true;
				
				} else {
					$sts = '<span class="label label-lg label-warning">Invalid</span>';
				}
				
				$pay_tbl = '<table class="table" border="0">
				<tr><td width="20%"><strong>Date:</strong></td><td>'.$row_inv['accept_date'].'</td></tr>
				<tr><td><strong>Slip No:</strong></td><td>'.$row_inv['slip_no'].'</td></tr>
				</table>';
			}
		}
	
	} else if($row_ordr['pay_method'] == 1 || $row_ordr['pay_method'] == 2 || $row_ordr['pay_method'] == 5) { // Online Payment
		if($row_ordr['delivery_type'] == 4) {
			$sts = '<span class="label label-lg label-danger">Pending</span>';
		
		} else {
			$sql_inv = mysqli_query($conn, "SELECT * FROM order_verify WHERE order_id='$order_id'");
			if(mysqli_num_rows($sql_inv) == 0) {
				$sts = '<span class="label label-lg label-danger">Pending</span>';
				$paid = '';
				
			} else {
				$row_inv = mysqli_fetch_assoc($sql_inv);
				$paid = $row_inv['payhere_amount'];
				
				if($row_inv['status'] == 2 && $row_inv['payhere_amount'] == $grand_tot) {
					$sts = '<span class="label label-lg label-success">Success</span>';
					$pay_status = true;
				
				} else {
					$sts = '<span class="label label-lg label-warning">Invalid</span>';
				}
				
				
				$pay_tbl = '<div class="table-responsive">
					<table class="table table-bordered">
						<tbody>
							<tr><td>Payment ID</td><td id="txt_pid">'.$row_inv['payment_id'].'</td></tr>
							<tr><td>Paid Amount (Rs)</td><td id="txt_amt"><font color="red" size="3">'.$row_inv['payhere_amount'].'</font></td></tr>
							<tr><td>Date</td><td id="txt_date">'.$row_inv['date'].'</td></tr>
						</tbody>
					</table>
				</div>';
				
				
				$pay_tbl .= '<u><b>Payment Error Log</b></u><br><br>';
				
	// 2 - success
	// 0 - pending
	// -1 - canceled
	// -2 - failed
	// -3 - chargedback
				
				$sql_invf = mysqli_query($conn, "SELECT * FROM order_verify_log WHERE order_id='$order_id'");
				$pay_tbl .= '<table class="table table-bordered" id="verify_log">
					<thead>
						<tr>
							<th>#</th>
							<th>Date</th>
							<th>Payment ID</th>
							<th>Payment (Rs)</th>
							<th>Status</th>
						</tr>
					</thead>
					<tbody>';
				
				$xy = 0; $pst = '';
				while($row_invf = mysqli_fetch_array($sql_invf)) { $xy++;
					$pay_st = $row_invf['status'];
					
					if($pay_st == 0) {
						$pst = 'Pending';
					
					} else if($pay_st == -1) {
						$pst = 'Canceled';
					
					} else if($pay_st == -2) {
						$pst = 'Failed';
					
					} else if($pay_st == -3) {
						$pst = 'Charged-back';
					
					} else {
						$pst = '';
					}
					
					$pay_tbl .= '<tr>
							<td>'.$xy.'.</td>
							<td>'.$row_invf['date'].'</td>
							<td>'.$row_invf['payment_id'].'</td>
							<td>'.$row_invf['payhere_amount'].'</td>
							<td>'.$pst.'</td>
						</tr>';
				}
				
				$pay_tbl .= '</tbody>
				</table>';
			}
		}
	
	} else if($row_ordr['pay_method'] == 4) { // Cash on Delivery
		if($row_ordr['delivery_type'] == 4) {
			$sts = '<span class="label label-lg label-danger">Pending</span>';
			$pay_status = true;
			
			$sql_inv = mysqli_query($conn, "SELECT * FROM cashon_del_verify WHERE order_id='$order_id'");
			if(mysqli_num_rows($sql_inv) == 0) {
				if($row_ordr['payment_status'] == 0) {
					$sts = '<span class="label label-lg label-danger">Pending</span>';
				
				} else {
					$sts = '<span class="label label-lg label-warning">Rejected</span>';
				}
				
			} else {
				$row_inv = mysqli_fetch_assoc($sql_inv);
				if($row_inv['status'] == 1) {
					$sts = '<span class="label label-lg label-success">Success</span>';
				
				} else {
					$sts = '<span class="label label-lg label-warning">Invalid</span>';
				}
				
				$pay_tbl = '<table class="table" border="0">
				<tr><td width="30%"><strong>Date:</strong></td><td>'.$row_inv['accept_date'].'</td></tr>
				<tr><td><strong>Reference No:</strong></td><td>'.$row_inv['ref_no'].'</td></tr>
				</table>';
			}
		
		} else {
			$sts = '<span class="label label-lg label-danger">Pending</span>';
		}
		
	} else {
		$sts = '<span class="label label-lg label-danger">Pending</span>';
	}
?>
        <div class="row">
          <!-- accepted payments column -->
          <div class="col-xs-12">
            <h3 class=" pull-right red">GRAND TOTAL: &nbsp;&nbsp;LKR. <?php echo number_format($grand_tot, 2); ?></h3>
          </div><!-- /.col -->
        </div><!-- /.col -->
		 <hr>
		 <div class="well">
		 <div class="row">
		  <div class="col-xs-12 col-md-6 invoice-col">
			<h5><b><u>Order Details</u></b></h5>
			<address><br>
				
				<p><strong>Delivery Method: </strong><font color="red" size="3"><?php if($row_ordr['delivery_type'] == 1) { echo 'Postal'; } else if($row_ordr['delivery_type'] == 2) { echo 'Courier Service'; } else if($row_ordr['delivery_type'] == 3) { echo 'Expedited Mail Service (EMS)'; } else if($row_ordr['delivery_type'] == 4) { echo 'Cash on Delivery'; } ?></font><p>
				<p><strong>Order Status: </strong>&nbsp;<?php
				
				$tbl = '<table class="table" border="0"><tr><td width="50%"><strong>Order Date</strong></td><td>'.$row_ordr['order_date'].'</td></tr>';
				
				if($row_ordr['order_status'] == 0) {
					echo '<font color="red" size="3">Pending</font>';
				}
				
				if($row_ordr['order_status'] == 1) {
					echo '<font color="green" size="3">Accepted</font>';
					$tbl .= '<tr><td><strong>Accepted Date</strong></td><td>'.$row_ordr['date_accept'].'</td></tr>';
				}
				
				if($row_ordr['order_status'] == 2) {
					echo '<font color="red" size="3">Rejected</font>';
					$tbl .= '<tr><td><strong>Rejected Date</strong></td><td>'.$row_ordr['date_accept'].'</td></tr>';
				}
				
				if($row_ordr['order_status'] == 3) {
					echo '<font color="red" size="3">Delivery Pending</font>';
					$tbl .= '<tr><td><strong>Accepted Date</strong></td><td>'.$row_ordr['date_accept'].'</td></tr>';
					$tbl .= '<tr><td><strong>Post/Courier Date</strong></td><td>'.$row_ordr['date_delivery'].'</td></tr>';
				}
				
				if($row_ordr['order_status'] == 5) {
					echo '<font color="green" size="3">Finish Order</font>';
					$tbl .= '<tr><td><strong>Accepted Date</strong></td><td>'.$row_ordr['date_accept'].'</td></tr>';
					$tbl .= '<tr><td><strong>Post/Courier Date</strong></td><td>'.$row_ordr['date_delivery'].'</td></tr>';
					$tbl .= '<tr><td><strong>Delivery Confirmed Date</strong></td><td>'.$row_ordr['date_del_confirm'].'</td></tr>';
					$tbl .= '<tr><td><strong>Order Finished Date</strong></td><td>'.$row_ordr['date_finish'].'</td></tr>';
				}
				
				if($row_ordr['order_status'] == 4) {
					echo '<font color="green" size="3">Confirmed Delivery</font>';
					$tbl .= '<tr><td><strong>Accepted Date</strong></td><td>'.$row_ordr['date_accept'].'</td></tr>';
					$tbl .= '<tr><td><strong>Post/Courier Date</strong></td><td>'.$row_ordr['date_delivery'].'</td></tr>';
					$tbl .= '<tr><td><strong>Delivery Confirmed Date</strong></td><td>'.$row_ordr['date_del_confirm'].'</td></tr>';
				
				} ?></p>
				
				
				<?php $tbl .= '</table>'; echo $tbl; ?>
				<br>
				<strong>Payment Status: </strong><font color="red" size="3">&nbsp;<?php echo $sts; ?></font>
            </address>
		  </div>
		  
		  <div class="col-xs-12 col-md-6 invoice-col">
			<h5><b><u>Payment Details</u></b></h5>
			<address><br>
                <strong>Payment Method: </strong><font color="red" size="3"><?php
				     if($row_ordr['pay_method'] == 1) { $pay_type = 'Credit/Debit Card'; }
				else if($row_ordr['pay_method'] == 2) { $pay_type = 'Mobile Wallet'; }
				else if($row_ordr['pay_method'] == 3) { $pay_type = 'Bank Deposit'; }
				else if($row_ordr['pay_method'] == 4) { $pay_type = 'Cash on Delivery'; }
				else if($row_ordr['pay_method'] == 5) { $pay_type = 'Internet Banking'; }
				else { $pay_type = ''; } echo $pay_type;  ?></font><br><br>
				
				<?php echo $pay_tbl; ?>
				
			</address>
			
		  </div>
		  
        </div><!-- /.row -->
        </div><!-- /.row -->
<hr><br>


								<div class="space-6"></div>

	<!--
								<div>
								  <?php //if($row_ordr['order_status'] == 0) { ?>
									<button class="btn btn-success btn-sm btn_accept" value="<?php //echo $row_ordr['id']; ?>">ACCEPT ORDER</button>
									<button class="btn btn-sm btn-danger btn_reject" value="<?php //echo $row_ordr['id']; ?>">REJECT ORDER</button>
								  
								  <?php //} else if($row_ordr['order_status'] == 1) { ?>
									<button class="btn btn-success btn-sm btn_deliver" value="<?php //echo $row_ordr['id']; ?>">DELIVER ORDER</button>
								  
								  <?php //} else if($row_ordr['order_status'] == 3) { ?>
									<button class="btn btn-success btn-sm btn_finish" value="<?php //echo $row_ordr['id']; ?>">FINISH ORDER</button>

								  <?php //} if($row_ordr['order_status'] != 0 && $row_ordr['order_status'] != 2) { ?>
									<a class="btn btn-primary btn-sm" href="invoicePrint?oid=<?php //echo $oid; ?>" target="_blank"><i class="fa fa-print"></i> &nbsp;PRINT</a>
								  <?php //}  ?>
								</div>
						-->

	<div id="print_hide">
	  <?php if($row_ordr['order_status'] == 0) { // Order Pool ?>
		<?php if($pay_status) { ?>
		<button class="btn btn-success btn-sm btn_accept" value="<?php echo $row_ordr['id']; ?>">ACCEPT</button>
		<?php } ?>
		<button class="btn btn-danger btn-sm btn_reject" value="<?php echo $row_ordr['id']; ?>">REJECT</button>
	  
	  <?php } else if($row_ordr['order_status'] == 1) { // Accepted Order ?>
		<button class="btn btn-success btn-sm btn_post" value="<?php echo $row_ordr['id']; ?>">Post/Courier</button>
	    <button class="btn btn-danger btn-sm btn_reject" value="<?php echo $row_ordr['id']; ?>">REJECT</button>
	    
	  <?php } else if($row_ordr['order_status'] == 3) { // Post/Courier Orders ?>
		<button class="btn btn-success btn-sm btn_conf_delv" value="<?php echo $row_ordr['id']; ?>">Confirm Delivery</button>
	  
	  <?php } else if($row_ordr['order_status'] == 4) { // Delivered Orders
			if($row_ordr['pay_method'] == 4) { ?>
		<button class="btn btn-success btn-sm btn_finish_cash" value="<?php echo $row_ordr['id']; ?>" data-inv="<?php echo $order_id; ?>">Finish Order</button>
		<?php	} else { ?>
		<button class="btn btn-success btn-sm btn_finish" value="<?php echo $row_ordr['id']; ?>">Finish Order</button>
	  <?php }} ?>
	</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 ($) {
	//initiate dataTables plugin
	var myTable =
	$('#dynamic-table')
	//.wrap("<div class='dataTables_borderWrap' />")   //if you are applying horizontal scrolling (sScrollX)
	.DataTable({
		bAutoWidth: false,
		"aaSorting": [],
	});
});

$(".btn_accept").click(function(){
  var row_id = $(this).val();
	swal({
	  title: "",
	  text: "Are you sure you want to accept this order?",
	  type: "warning",
	  showCancelButton: true,
	  confirmButtonClass: "btn-danger",
	  confirmButtonText: "Yes, Accept!",
	  cancelButtonText: "No, Cancel!",
	  closeOnConfirm: false,
	  closeOnCancel: true
	},
	function(isConfirm) {
	  if (isConfirm) {
		$("#preloader").fadeIn();
		$.post( "connection/online_order_conn", {accept_order: "data", oid : row_id, pay_status: '<?php echo $pay_status; ?>'}, function( data ) {
			if (data.msgType === 1) {
			  $("#preloader").fadeOut("slow");
			  swal({
				title: "",
				text: "Successfully Accepted!",
				type: "success",
				confirmButtonText: "OK"
				  },
				  function (isConfirm) {
				if (isConfirm) {
					window.location.href = "online_orders?st=<?php echo $st; ?>";
				}
			  });
			
			} else if (data.msgType === 4) {
			  swal("", "Already Accepted!", "warning");
			  setTimeout(function () { location.reload(); }, 3000);
			
			} else{
			  $("#preloader").fadeOut("slow");
			  swal("", "Something went wrong! Please Try Again!", "warning");
			}
		}, "json");
	  }
	});
});

$(".btn_post").click(function(){
  var row_id = $(this).val();
	swal({
	  title: "",
	  text: "Are you sure you want to deliver this order?",
	  type: "warning",
	  showCancelButton: true,
	  confirmButtonClass: "btn-danger",
	  confirmButtonText: "Yes, Accept!",
	  cancelButtonText: "No, Cancel!",
	  closeOnConfirm: false,
	  closeOnCancel: true
	},
	function(isConfirm) {
	  if (isConfirm) {
		$("#preloader").fadeIn();
		$.post( "connection/online_order_conn", {deliver_order: "data", oid : row_id}, function( data ) {
			if (data.msgType === 1) {
			  $("#preloader").fadeOut("slow");
			  swal({
				title: "",
				text: "Successfully Updated!",
				type: "success",
				confirmButtonText: "OK"
				  },
				  function (isConfirm) {
				if (isConfirm) {
					window.location.href = "online_orders?st=<?php echo $st; ?>";
				}
			  });
			
			} else if (data.msgType === 4) {
			  swal("", "Already Finished!", "warning");
			  setTimeout(function () { location.reload(); }, 3000);
			
			} else{
			  $("#preloader").fadeOut("slow");
			  swal("", "Something went wrong! Please Try Again!", "warning");
			}
		}, "json");
	  }
	});
});

$(".btn_conf_delv").click(function(){
  var row_id = $(this).val();
	swal({
	  title: "",
	  text: "Are you sure you want to confirm the delivery?",
	  type: "warning",
	  showCancelButton: true,
	  confirmButtonClass: "btn-danger",
	  confirmButtonText: "Yes, Accept!",
	  cancelButtonText: "No, Cancel!",
	  closeOnConfirm: false,
	  closeOnCancel: true
	},
	function(isConfirm) {
	  if (isConfirm) {
		$.post( "connection/online_order_conn", {deliver_order_finish: "data", oid : row_id,}, function( data ) {
			if (data.msgType === 1) {
			  swal({
				title: "",
				text: "Successfully Updated!",
				type: "success",
				confirmButtonText: "OK"
				  },
				  function (isConfirm) {
				if (isConfirm) {
					window.location.href = "online_orders?st=<?php echo $st; ?>";
				}
			  });
			
			} else if (data.msgType === 4) {
			  swal("", "Already Finished!", "warning");
			  setTimeout(function () { location.reload(); }, 3000);
			
			} else{
			  swal("", "Something went wrong! Please Try Again!", "warning");
			}
		}, "json");
	  }
	});
});

$(".btn_finish").click(function(){
  var row_id = $(this).val();
	swal({
	  title: "",
	  text: "Are you sure you want to confirm the delivery?",
	  type: "warning",
	  showCancelButton: true,
	  confirmButtonClass: "btn-danger",
	  confirmButtonText: "Yes, Accept!",
	  cancelButtonText: "No, Cancel!",
	  closeOnConfirm: false,
	  closeOnCancel: true
	},
	function(isConfirm) {
	  if (isConfirm) {
		$.post( "connection/online_order_conn", {order_finish: "data", oid : row_id,}, function( data ) {
			if (data.msgType === 1) {
			  swal({
				title: "",
				text: "Successfully Updated!",
				type: "success",
				confirmButtonText: "OK"
				  },
				  function (isConfirm) {
				if (isConfirm) {
					window.location.href = "online_orders?st=<?php echo $st; ?>";
				}
			  });
			
			} else if (data.msgType === 4) {
			  swal("", "Already Finished!", "warning");
			  setTimeout(function () { location.reload(); }, 3000);
			
			} else{
			  swal("", "Something went wrong! Please Try Again!", "warning");
			}
		}, "json");
	  }
	});
});

$(".btn_reject").on(ace.click_event, function() {
	 var row_id = $(this).val();
	 var bb = bootbox.prompt({
		title: "Authentication Required!",
		placeholder: "Enter Administrator Password",
		inputType: 'password',
		onEscape: true,
		required : true,
		callback: function (result) {
            //result is null when Cancel is clicked
            //empty when OK is clicked
            if (result === null) {
                return;
           
		    } else if (result === '') {
			    alert('Please Enter Administrator Password');
                bb.find('.bootbox-input-password').addClass('input-validation-error');
                return false;
            
			} else {
			  $.post('connection/online_order_conn', {'validate_admin_pw': 'data' , pwd: result}, function (data){
				if(data.msgType === 1) {
					swal({
					  title: "",
					  text: "Are you sure you want to reject this order?",
					  type: "warning",
					  showCancelButton: true,
					  confirmButtonClass: "btn-danger",
					  confirmButtonText: "Yes, Reject!",
					  cancelButtonText: "No, Cancel!",
					  closeOnConfirm: false,
					  closeOnCancel: true
					},
					function(isConfirm) {
					  if (isConfirm) {
						$.post( "connection/online_order_conn", {reject_order: "data", oid : row_id,}, function( data ) {
							if (data.msgType === 1) {
							  swal({
								title: "",
								text: "Successfully Rejected!",
								type: "success",
								confirmButtonText: "OK"
								  },
								  function (isConfirm) {
								if (isConfirm) {
									window.location.href = "online_orders?st=<?php echo $st; ?>";
								}
							  });
							
							} else if (data.msgType === 4) {
							  swal("", "Already Accepted!", "warning");
							  setTimeout(function () { location.reload(); }, 3000);
							
							} else{
							  swal("", "Something went wrong! Please Try Again!", "warning");
							}
						}, "json");
					  }
					});
					
				} else if(data.msgType === 2) {
				  swal("", "Incorrect Password. Please try again!", "warning");
				  return false;
				
				} else if(data.msgType === 3) {
				  swal("", "Please Enter Administrator Password!", "warning");
				  return false;
					
				} else {
				  swal("", "Something went wrong! Please Try Again!", "warning");
				}
				
			  }, "json");
			}
		}
	});
});

$(".btn_finish_cash").on(ace.click_event, function() {
	 var row_id = $(this).val();
	 var inv = $(this).attr('data-inv');
	 var bb = bootbox.prompt({
		title: "Courier Service Details",
		placeholder: "Enter Reference No",
		inputType: 'text',
		onEscape: true,
		required : true,
		callback: function (result) {
            //result is null when Cancel is clicked
            //empty when OK is clicked
            if (result === null) {
                return;
           
		    } else if (result === '') {
			    alert('Please Enter Reference No!');
                bb.find('.bootbox-input-text').addClass('input-validation-error');
                return false;
            
			} else {
			  $.post('connection/online_order_conn', {'update_ref_no': 'data' , ref_no: result, inv : inv}, function (data) {
				if(data.msgType === 1) {
					swal({
					  title: "",
					  text: "Are you sure you want to finish this order?",
					  type: "warning",
					  showCancelButton: true,
					  confirmButtonClass: "btn-danger",
					  confirmButtonText: "Yes, Finish!",
					  cancelButtonText: "No, Cancel!",
					  closeOnConfirm: false,
					  closeOnCancel: true
					},
					function(isConfirm) {
					  if (isConfirm) {
						$.post( "connection/online_order_conn", {order_finish_cash: "data", oid : row_id,}, function( data ) {
							if (data.msgType === 1) {
							  swal({
								title: "",
								text: "Successfully Updated!",
								type: "success",
								confirmButtonText: "OK"
								  },
								  function (isConfirm) {
								if (isConfirm) {
									window.location.href = "online_orders?st=<?php echo $st; ?>";
								}
							  });
							
							} else if (data.msgType === 4) {
							  swal("", "Already Finished!", "warning");
							  setTimeout(function () { location.reload(); }, 3000);
							
							} else if (data.msgType === 5) {
							  swal("", "Invalid Reference No. Please try again", "warning");
							  setTimeout(function () { location.reload(); }, 3000);
							
							} else {
							  swal("", "Something went wrong! Please Try Again!", "warning");
							}
						}, "json");
					  }
					});
					
				} else if(data.msgType === 2) {
				  swal("", "Reference No Already Exist. Please try again!", "warning");
				  return false;
				
				} else if(data.msgType === 3) {
				  swal("", "Please Enter Reference No!", "warning");
				  return false;
					
				} else {
				  swal("", "Something went wrong! Please Try Again!", "warning");
				}
				
			  }, "json");
			}
		}
	});
});

</script>
</body>
</html>