MINI Sh3ll
<?
//x($orders);
$order_items = [];
?>
<div class="card mb-4">
<div class="card-body p-2">
<div class="row">
<div class="col-md-9 me-2 my-1">
</div>
<div class="col-md-3 col-sm-12">
<form method="post">
<select class="form-control" name="type" onchange="this.form.submit()">
<option value="0,1,2">All Orders</option>
<option value="0" <?=$type == '0' ? 'selected' : ''?>>Pending Orders</option>
<option value="1" <?=$type == '1' ? 'selected' : ''?>>Processed Orders</option>
<option value="2" <?=$type == '2' ? 'selected' : ''?>>Cancelled Orders</option>
</select>
</form>
</div>
</div>
</div>
</div>
<div class="card card-header-actions mb-4">
<div class="card-header"><?=$page_title?><div>
<a class="btn btn-primary btn-sm" href="<?=SITE_ROOT_URL.'export-data?rtype=download-orders'?>">Download</a>
</div></div>
<div class="card-body">
<table class="saathi_datatable" id="ordersTable" width="100%" cellspacing="0">
<thead>
<tr>
<th class="text-center" width="5%">#</th>
<th class="text-center" width="8%">Received</th>
<th class="text-center" width="20%">User</th>
<th class="text-center" width="25%">Products</th>
<th class="text-center" width="5%">Amount</th>
<th class="text-center" width="8%">Status</th>
<th class="text-center" width="8%">Action</th>
</tr>
</thead>
<tbody>
<? if($orders){
foreach($orders as $o){
$badge_css = 'dark';
if($o['status'] == 1){
$badge_css = 'success';
}
elseif($o['status'] == 2){
$badge_css = 'danger';
}
$oitems = $objOrder->getOrderItems($o['order_id']);
$o['products'] = '';
foreach($oitems as $oi){
$tr = '<tr>
<td class="text-center">'.$oi['product_code'].'</td>
<td class="text-left">'.$oi['description'].'</td>
<td class="text-right">'.$oi['cost'].'</td>
<td class="text-right">'.$oi['quantity'].'</td>
<td class="text-right">'.$oi['amount'].'</td>
</tr>';
$order_items[$o['order_id']] = (isset($order_items[$o['order_id']]) ? $order_items[$o['order_id']] : "").$tr;
$o['products'] .= $oi['description'].'('.$oi['product_code'].') =>'.$oi['quantity'].'<br/>';
}
?>
<tr>
<td class="text-center"><?=$o['order_id']?></td>
<td class="text-center"><?=date('d-M-Y', strtotime($o['created']))?></td>
<td class="text-left"><?=$o['username']?></td>
<td class="text-left"><?=$o['products']?></td>
<td class="text-right"><?=$o['total_amount']?></td>
<td class="text-center"><div class="badge badge-<?=$badge_css?> badge-pill"><?=$o['order_status']?></div></td>
<td class="text-center">
<input type="hidden" id="ostatus<?=$o['order_id']?>" value="<?=$o['status']?>" />
<a id="btnProcess<?=$o['order_id']?>" class="text-<?=$status_css?>" style="cursor:pointer;">Process</a>
</td>
</tr>
<? }
}?>
</tbody>
</table>
</div>
</div>
<form method="post" id="frmUserUpdate">
<input type="hidden" name="formtype" value="update-order-status" />
<input type="hidden" id="id" name="id" value="" />
<input type="hidden" id="status" name="status" value="" />
</form>
<!-- Modal -->
<div class="modal fade" id="orderModal" tabindex="-1" role="dialog" aria-labelledby="orderModalLabel" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="orderModalLabel">Order Details</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
</div>
<form id="orderForm" method="post" class="needs-validation" novalidate="">
<div class="modal-body">
<p>Order items are listed in detail below:</p>
<div id="orderItems"></div>
<hr/>
<div class="form-group text-left">
<label class="small mb-1" for="order_status">Order Status : </label>
<select class="form-control" id="order_status" name="order_status" required>
<option value="">Select Order Status</option>
<option value="0">Pending</option>
<option value="1">Processed</option>
<option value="2">Cancelled</option>
</select>
<div class="invalid-feedback">Please select the option</div>
</div>
</div>
<div class="modal-footer">
<input type="hidden" name="order_id" id="order_id" value="" />
<input type="hidden" name="formtype" value="update-order-status" />
<button id="btnSubmitOrder" class="btn btn-sm btn-primary" type="submit">Submit</button>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript">
var oitems = <?=json_encode($order_items)?>;
$("#ordersTable").on("click", "[id^=btnProcess]", function(){
var oid = this.id.replace('btnProcess', '');
var ost = $("#ostatus"+oid).val();
var ohtml = '<table class="saathi_datatable" id="oiTable" width="100%" cellspacing="0"> \
<thead> \
<tr> \
<th class="text-center" width="5%">#</th> \
<th class="text-left" width="25%">Product</th> \
<th class="text-right" width="8%">Cost</th> \
<th class="text-right" width="8%">Quantity</th> \
<th class="text-right" width="5%">Amount</th> \
</tr> \
</thead> \
<tbody>';
ohtml += oitems[oid];
ohtml += '</tbody> \
</html>';
$("#orderForm #order_id").val(oid);
$("#orderForm #orderItems").html(ohtml);
$("#orderForm #order_status").val(ost);
$("#orderModal").modal("show");
});
$("#btnSubmitOrder").on("click", function (e) {
var form = $("#orderForm")[0];
var isValid = form.checkValidity();
if (!isValid) {
e.preventDefault();
e.stopPropagation();
}
form.classList.add('was-validated');
//return false; // For testing only to stay on this page
});
$(document).ready(function() {
$('#ordersTable').DataTable({
"pageLength": 50,
"order": [[ 0, 'desc' ]]
});
});
</script>
OHA YOOOO