<?php include "header.php"; 
?>
<div id="content" class="main-content">

	<div class="layout-px-spacing">
		<div class="row layout-top-spacing" id="cancel-row">
  
			<div class="col-xl-12 col-lg-12 col-sm-12 layout-spacing m-auto">
			
			<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 ">
				<h1 class="title-4">Orders</h1>
				
				<div class="btn-toolbar mb-2 mb-md-0">
					<div class="btn-group mr-2">
						<a href="orders" class="btn btn-icon bg-warning text-white">
						<svg xmlns="http://www.w3.org/2000/svg" width="20" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-shopping-cart text-white"><circle cx="9" cy="21" r="1"></circle>
						<circle cx="20" cy="21" r="1"></circle><path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path></svg> &nbsp; All Orders </a>
					</div>
				</div>
			</div>

			
<?php
if($setup == "view" && !empty($prd)){
	
	$odcnt = $db_con->query("SELECT * FROM order_mart WHERE om_number = '$prd'");
	$odcnt->execute(); $ftcnt = $odcnt->fetch();
	if(!empty($ftcnt)){
		
	$prd_id = $ftcnt['om_id'];
	
	$odtt = $db_con->query("SELECT SUM(sub_cost) FROM omart_item WHERE om_id = '$prd_id'");
	$odtt->execute(); $tt_num = $odtt->fetchColumn();
	
	$oddly = $db_con->query("SELECT * FROM omart_address WHERE om_id = '$prd_id'");
	$oddly->execute(); $dvl = $oddly->fetch();
	
	if($ftcnt['delivery'] == "another"){
		$odaddrs = $db_con->query("SELECT * FROM omart_deliveryaddress WHERE om_id = '$prd_id'");
		$odaddrs->execute(); $ads = $odaddrs->fetch();
	}
	$ftitms = getAll("omart_item"," om_id = '$prd_id' ","oi_id ASC");
	
	?>
<style>
.breadcrumb-four .breadcrumb {
  display: inline-flex;
  padding: 0;
  background-color: transparent;
  margin-bottom: 0;
}

.breadcrumb-four .breadcrumb li {
  position: relative;
  font-size: 14px;
  background: #fff;
  margin-right: 20px;
  margin-bottom: 6px;
  padding: 7px 10px;
  border-radius: 10px;
  border: 1px solid #e0e6ed;
  -webkit-box-shadow: 2px 5px 17px 0 rgba(31, 45, 61, 0.1);
  box-shadow: 0px 1px 8px 0px rgba(31, 45, 61, 0.1);
}

.breadcrumb-four .breadcrumb li a {
  color: #555;
  vertical-align: sub;
}

.breadcrumb-four .breadcrumb li svg {
  color: #6f6f6f;
  vertical-align: text-bottom;
  width: 20px;
}

.breadcrumb-four .breadcrumb li:not(:first-child)::before {
  content: '~';
  position: absolute;
  color: #1b55e2;
  left: -19px;
  top: 50%;
  transform: translate(0%,-50%);
  font-family: 'Quicksand', sans-serif;
  font-size: 2rem;
}

.breadcrumb-four .breadcrumb li.active a {
  color: #1b55e2 !important;
  font-weight: 600;
}
.breadcrumb-four .breadcrumb li a {
  color: #555;
  vertical-align: sub;
}

.breadcrumb-four .breadcrumb li.active svg {
  color: #1b55e2;
}

.krdmd{
	display: flex;
	background: red;
	padding: 3px 5px 3px 0;
	border-radius: 5px;
	color: #fff;
	overflow: hidden;
	justify-content: space-between;
	align-content: center;
	font-size:16px;
}

.krdmd h5{
	font-weight: bold;
	margin: 0;
	background: #fff;
	padding: 7px;
	font-size:16px;
}

.krdmd h4{
	margin: 0;
	padding: 7px;
	color: #fff;
	font-size:16px;
}


.odr-lst {
    border-bottom: 1px solid #e6e6e6;
    padding-bottom: 30px;
    padding: 0;
    display: block;
    margin: 0;
}

ul.odr-lst li {
    list-style: none;
    display: block;
    margin: 0;
}

ul.odr-lst .lst-itm {
    display: table;
    width: 100%;
}

ul.odr-lst .lst-itm .product-thumb {
    width: 113px;
    font-size: 0;
    line-height: 0;
	display: table-cell;
    text-align: left;
}
.lst-itm .product-thumb a {
    width: 100%;
    height: 100%;
    display: block;
}

.lst-itm .product-thumb a img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    background: #fafafa;
}

.lst-itm .tname {
    font-size: 0;
    line-height: 0;
    vertical-align: top;
    padding-top: 21px;
    padding-left: 11px;
	display: table-cell;
    text-align: left;
}

.lst-itm .tname * {
    display: block;
    font-size: 17px;
    color: #222222;
    margin: 0;
    line-height: 20px;
    font-weight: 600;
}

.lst-itm .txt-quantity {
    display: flex;
}

.lst-itm .price {
    text-align: right;
	display: table-cell;
    text-align: left;
    font-size: 0;
    line-height: 1;
    margin-top: 6px;
	min-width: 10%;
}

.lst-itm  .price-contain ins{
    display: inline-block;
    text-decoration: none;
}

.lst-itm .price-contain ins .price-amount{
    font-size: 18px;
    color: #111111;
    font-weight: 700;
	line-height: 24px;
    display: inline-block;
    font-weight: 600;
    text-decoration: none;
}

.lst-itm .price-contain del {
    position: relative;
    margin-left: 6px;
    display: inline-block;
}


.lst-itm .price-contain .price-amount{
	line-height: 24px;
    color: #aaaaaa;
    font-size: 14px;
    display: inline-block;
    font-weight: 600;
    text-decoration: none;
}

.price-contain del::after {
    content: '';
    height: 1px;
    background-color: #aaaaaa;
    position: absolute;
    top: 50%;
    left: -1px;
    right: -1px;
    display: block;
    z-index: 1;
}
</style>
	<div class="row">
		<div class="col-md-12">
			<div class="widget-content widget-content-area bg-light br-6 mb-3">	
				<h5 class="mb-4 font-weight-bold text-warning">Order Data</h5>
				<div class="row">
					
					<div class="col-md-4 mb-3">
						<div class="krdmd">
							<h5>Order Nunmber</h5>
							<h4><?= $ftcnt['om_number']; ?></h4>
						</div>
					</div>
					
					<div class="col-md-4 mb-3">
						<div class="krdmd">
							<h5>Order Date:</h5>
							<h4><?= date('j-M-Y  h:i a', strtotime($ftcnt['dated'])); ?></h4>
						</div>
					</div>
					
					<div class="col-md-4 mb-3">
						<div class="krdmd">
							<h5>Total Cost:</h5>
							<h4>GH₵ <?= number_format($tt_num); ?></h4>
						</div>
					</div>
					
					<div class="col-md-4 mb-3">
						<div class="krdmd">
							<h5>Delivery:</h5>
							<h4><?= ($ftcnt['delivery'] == "another") ? 'Different Address' : 'Same as Billing'; ?> </h4>
						</div>
					</div>
					
					<div class="col-md-8 mb-3">
						<div class="krdmd">
							<h5>Note:</h5>
							<p class="text-white mb-0"><?= nl2br($ftcnt['remarks']); ?> </p>
						</div>
					</div>
					
					<div class="breadcrumb-four col-md-8">
						<ul class="breadcrumb">
							<li class="active text-center"><a href="javscript:void(0);">
							<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-box"><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"></path><polyline points="3.27 6.96 12 12.01 20.73 6.96"></polyline><line x1="12" y1="22.08" x2="12" y2="12"></line></svg> 
							<span class="d-block">Pending <br> 11/12/24</span></a>
							</li>
							<li><a href="javscript:void(0);"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-cpu"><rect x="4" y="4" width="16" height="16" rx="2" ry="2"></rect><rect x="9" y="9" width="6" height="6"></rect><line x1="9" y1="1" x2="9" y2="4"></line><line x1="15" y1="1" x2="15" y2="4"></line><line x1="9" y1="20" x2="9" y2="23"></line><line x1="15" y1="20" x2="15" y2="23"></line><line x1="20" y1="9" x2="23" y2="9"></line><line x1="20" y1="14" x2="23" y2="14"></line><line x1="1" y1="9" x2="4" y2="9"></line><line x1="1" y1="14" x2="4" y2="14"></line></svg> <span>UI Kit</span></a></li>
						</ul>
					</div>
					
					<div class="col-md-4">
						<button class="btn bg-secondary text-white  w-100 rounded" disabled>Process</button>
					</div>
					
				</div>
			</div>
		</div>
		
		<div class="col-md-6">
			<div class="widget-content widget-content-area bg-light br-6 mb-3">	
				<h5 class="mb-4 font-weight-bold text-warning">Order Items</h5>
				<div>
				<ul class="odr-lst">
					<?php
					if(!empty($ftitms)){
						foreach($ftitms as $dcv){
							
							$fdprp = $dcv['ksp_id'];
							
							$gt_prds = getOne("kmartstockprds","  ksp_id = '$fdprp' ",'ksp_id');
							if(!empty($gt_prds)){
							$chk_prdz = $db_con->prepare("SELECT * FROM kmartstockprds WHERE ksp_id = '$gt_prds' ");
							$chk_prdz->execute(); $pdz = $chk_prdz->fetch();	
							
							$chkct = $dcv['qty'];
							
							$gt_imgs = gtOne("kprdw_imgs"," prd_rec = '$pdz[pqrcode]' ORDER BY kmg_id ASC","pjm_pic");
							$prd_img = (!empty($gt_imgs) && file_exists('../prdimgs/'.$gt_imgs)) ? "../prdimgs/".$gt_imgs : '../img/kmart-icon.png';
							?>
						<li class="cart-elem">
							<div class="lst-itm">
								<div class="product-thumb">
									<a class="prd-thumb" href="../product?kmt=<?= $pdz['purl']; ?>" target="_blank">
										<figure><img src="<?= $prd_img; ?>" width="113" height="113" alt="item image"></figure>
									</a>
								</div>
								<div class="tname">
									<span class="txt-quantity">Qty:<b><?= (!empty($chkct)) ? $chkct : 1; ?></b></span>
									<a href="../product?kmt=<?= $pdz['purl']; ?>" target="_blank" class="pr-name text-primary"><?= $pdz['pname'] ?></a>
								</div>
								<div class="price price-contain">
									<ins><span class="price-amount"><span class="currencySymbol">GH₵</span><b class="mprc"><?= $dcv['sub_cost']; ?></b></span></ins>
								</div>
							</div>
						</li>
							<?php
							}
						}
					}				
					?>
					</ul>
				</div>
			</div>
			
			<div class="widget-content widget-content-area bg-light br-6 mb-3">	
				<h5 class="mb-4 font-weight-bold text-warning">Payment Info</h5>
				<div>
					
				</div>
			</div>
		</div>
		
		<div class="col-md-6">
			<div class="widget-content widget-content-area bg-light br-6 mb-3">	
				<h5 class="mb-4 font-weight-bold text-warning">Billing Info</h5>
				<div>
					<table class="table table-bordered">
						<thead>
							<tr><th width="30%"></th><th width="70%"></th></tr>
						</thead>
						<tbody>
							<tr> <td><b>First Name</b></td><td><big class="font-weight-bold"><?= $dvl['cf_name']; ?></big></td> </tr>
							<tr> <td><b>Last Name</b></td><td><big class="font-weight-bold"><?= $dvl['cl_name']; ?></big></td> </tr>
							<tr> <td><b>Country</b></td><td><big class="font-weight-bold"><?= $dvl['ccountry']; ?></big></td> </tr>
							<tr> <td><b>Street Address</b></td><td><big class="font-weight-bold"><?= $dvl['cstreet']; ?></big></td> </tr>
							<tr> <td><b>Apartment, Suit or Unit </b></td><td><big class="font-weight-bold"><?= $dvl['capartment']; ?></big></td> </tr>
							<tr> <td><b>Region</b></td><td><big class="font-weight-bold"><?= $dvl['cregion']; ?></big></td> </tr>
							<tr> <td><b>State / City </b></td><td><big class="font-weight-bold"><?= $dvl['cstate']; ?></big></td> </tr>
							<tr> <td><b>Postal Code / Zip </b></td><td><big class="font-weight-bold"><?= $dvl['cpostal']; ?></big></td> </tr>
							<tr> <td><b>Email Address</b></td><td><big class="font-weight-bold"><?= $dvl['cemail']; ?></big></td> </tr>
							<tr> <td><b>Phone</b></td><td><big class="font-weight-bold"><?= $dvl['cphone']; ?></big></td> </tr>
						</tbody>
					</table>
				</div>
			</div>
			
			<div class="widget-content widget-content-area bg-light br-6 mb-3">	
				<h5 class="mb-4 font-weight-bold text-warning">Address Info</h5>
				<div>
					<?php 
					
					if($ftcnt['delivery'] == "another" && !empty($ads)){
						?>
					<table class="table table-bordered">
						<thead>
							<tr><th width="30%"></th><th width="70%"></th></tr>
						</thead>
						<tbody>
							<tr> <td><b>First Name</b></td><td><big class="font-weight-bold"><?= $ads['cf_name']; ?></big></td> </tr>
							<tr> <td><b>Last Name</b></td><td><big class="font-weight-bold"><?= $ads['cl_name']; ?></big></td> </tr>
							<tr> <td><b>Company</b></td><td><big class="font-weight-bold"><?= $ads['ccompany']; ?></big></td> </tr>
							<tr> <td><b>Country</b></td><td><big class="font-weight-bold"><?= $ads['ccountry']; ?></big></td> </tr>
							<tr> <td><b>Street Address</b></td><td><big class="font-weight-bold"><?= $ads['cstreet']; ?></big></td> </tr>
							<tr> <td><b>Apartment, Suit or Unit </b></td><td><big class="font-weight-bold"><?= $ads['capartment']; ?></big></td> </tr>
							<tr> <td><b>Region</b></td><td><big class="font-weight-bold"><?= $ads['cregion']; ?></big></td> </tr>
							<tr> <td><b>State / City </b></td><td><big class="font-weight-bold"><?= $ads['cstate']; ?></big></td> </tr>
							<tr> <td><b>Postal Code / Zip </b></td><td><big class="font-weight-bold"><?= $ads['cpostal']; ?></big></td> </tr>
							<tr> <td><b>Email Address</b></td><td><big class="font-weight-bold"><?= $ads['cemail']; ?></big></td> </tr>
							<tr> <td><b>Phone</b></td><td><big class="font-weight-bold"><?= $ads['cphone']; ?></big></td> </tr>
						</tbody>
					</table>
						<?php
					}else{ echo '<h4>Same as Billing Addresss </h4>'; } ?>
				</div>
			</div>
		</div>
	</div>
	<?php
	}
}
else{
?>
		<div class="row">
		<div class="col-12 m-auto">
		<div class="widget-content widget-content-area br-6">	
			
			<div class="table-responsive col-md-12 bg-light">

			<table id="fetch_data" class="table table-bordered scores">
			 <thead>
				<tr>
					<th class="text-center vertical-align" data-sortable="false">#</th>
					<th class="vertical-align" data-sortable="true">Order Number</th>

					<th class="vertical-align" data-sortable="false">
					<select name="order_status" id="order_status" class="form-control">
					 <option value="">Order status</option>
					
						<option value="Pending">Pending</option>
						<option value="Processing" >Processing</option>
						<option value="InTransit" >In Transit</option>
						<option value="Completed" >Completed</option>

					</select>
					
				   </th>
			   
					<th class="vertical-align" data-sortable="false">Date</th>
					
					<th class="vertical-align" data-sortable="false">Action</th>
					
			 </thead>
			</table>
	
	<script type="text/javascript" language="javascript" >
	$(document).ready(function(){

	var dataTable = $('#fetch_data').DataTable({"processing":true, "serverSide":true,"order":[],
	"ajax":{ url:"actions/fetch_orders.php", type:"POST", data:{'fetch_all_orders':1}} 
	});

	function load_data(order_status){
		var dataTable = $('#fetch_data').DataTable({"processing":true,"serverSide":true,"order":[],"ajax":{
		url:"actions/fetch_orders.php", type:"POST", data:{'fetch_all_orders':1,order_status:order_status}} });
	}
	$(document).on('change', '#order_status', function(){ var state = $(this).val(); $('#fetch_data').DataTable().destroy();
	  if(state != '') { load_data(state); }
	  else {  load_data(); }  });   });
	</script>
			</div>
	
			</div>
			</div>	
		</div>
<?php
}
?>		
				
		
			</div>

		</div>

	</div>

</div>

<?php include "footer.php"; ?>