PK

ADDRLIN : /home/anibklip/aelogifts.com/cms/
FLL :
Current File : /home/anibklip/aelogifts.com/cms/orders_view.php

<?php


if($_SESSION['msg']){$msg=$_SESSION['msg']; unset($_SESSION['msg']);}
if($_SESSION['errmsg']){$errmsg=$_SESSION['errmsg']; unset($_SESSION['errmsg']);}
?>
<div class="content-wrapper">
	<!-- Content Header (Page header) -->
	<section class="content-header">
		<div class="container-fluid">
			<div class="row mb-2">
				<div class="col-sm-6">
					<h1>View Orders</h1>
				</div>
				<div class="col-sm-6">
					<ol class="breadcrumb float-sm-right">
						<li class="breadcrumb-item"><a href="#">Home</a></li>
						<li class="breadcrumb-item active">View Orders</li>
					</ol>
				</div>
			</div>
		</div><!-- /.container-fluid -->
	</section>

	<!-- Main content -->
	<section class="content">

		<div class="row">
			<div class="col-md-12">
				<?php if($msg){?><div class="alert alert-success"><strong>Success!</strong> <?php echo $msg;?></div><?php }?>
				<?php if($errmsg){?><div class="alert alert-danger"><strong>Error!</strong> <?php echo $errmsg;?></div><?php }?>
				
				<div class="card card-outline card-info">
					<!-- <div class="card-header">
						<h3 class="card-title">Body</h3>
					</div> -->
					<!-- /.card-header -->
					<!-- /.card-header -->
					  
						<div class="card-body table-responsive p-0">
							<div class="card-header">
								<form method="GET" action="" class="form-inline">
									<input type="hidden" name="action" value="<?php echo $_GET['action']; ?>">
									
									<div class="form-group mx-2">
										<label class="mr-2">Quick Date:</label>
										<select name="date_filter" class="form-control form-control-sm" onchange="updateDateRange(this.value)">
											<option value="">Custom Range</option>
											<option value="today" <?php echo ($_GET['date_filter'] == 'today' ? 'selected' : ''); ?>>Today</option>
											<option value="yesterday" <?php echo ($_GET['date_filter'] == 'yesterday' ? 'selected' : ''); ?>>Yesterday</option>
											<option value="this_week" <?php echo ($_GET['date_filter'] == 'this_week' ? 'selected' : ''); ?>>This Week</option>
											<option value="last_week" <?php echo ($_GET['date_filter'] == 'last_week' ? 'selected' : ''); ?>>Last Week</option>
											<option value="this_month" <?php echo ($_GET['date_filter'] == 'this_month' ? 'selected' : ''); ?>>This Month</option>
											<option value="last_month" <?php echo ($_GET['date_filter'] == 'last_month' ? 'selected' : ''); ?>>Last Month</option>
										</select>
									</div>

									<div class="form-group mx-2">
										<label class="mr-2">Custom Date Range:</label>
										<input type="date" name="frm" value="<?php echo $_GET['frm']; ?>" class="form-control form-control-sm" id="date_from">
										<input type="date" name="to" value="<?php echo $_GET['to']; ?>" class="form-control form-control-sm ml-2" id="date_to">
									</div>

									<div class="form-group mx-2">
										<label class="mr-2">Payment Mode:</label>
										<select name="payment_method" class="form-control form-control-sm">
											<option value="">All</option>
											<option value="razorpay" <?php echo ($_GET['payment_method'] == 'razorpay' ? 'selected' : ''); ?>>Razorpay</option>
											<option value="cod" <?php echo ($_GET['payment_method'] == 'cod' ? 'selected' : ''); ?>>COD</option>
										</select>
									</div>

									<div class="form-group mx-2">
										<label class="mr-2">City:</label>
										<input type="text" name="city" value="<?php echo $_GET['city']; ?>" class="form-control form-control-sm">
									</div>

									<div class="form-group mx-2">
										<label class="mr-2">Order Status:</label>
										<select name="sts" class="form-control form-control-sm">
											<option value="">All</option>
											<option <?php echo ($editrow['status'] == "Delivered" ? "selected='selected'" : "") ?>>Delivered</option>
											<option <?php echo ($_GET['sts'] == "Shipped" ? "selected='selected'" : "") ?>>Shipped</option>
											<option <?php echo ($_GET['sts'] == "Canceled" ? "selected='selected'" : "") ?>>Canceled</option>
											<option <?php echo ($_GET['sts'] == "On Hold" ? "selected='selected'" : "") ?>>On Hold</option>
											<option <?php echo ($_GET['sts'] == "Processing" ? "selected='selected'" : "") ?>>Processing</option>
										</select>
									</div>

									<button type="submit" class="btn btn-primary btn-sm">Filter</button>
									<a href="?action=<?php echo $_GET['action']; ?>" class="btn btn-secondary btn-sm ml-2">Reset</a>
									<button type="button" class="btn btn-success btn-sm ml-2" onclick="exportToExcel()">Export to Excel</button>
								</form>
							</div>
							<table  class="table table-bordered table-striped">
								<thead>
									<tr>
										<th>#</th>
										<th>Order Id </th>
										<th>Member ID/Name</th>
										<th>Mobile</th>
										<th>Address </th>
										<th>City</th>
										<th>Zip </th>
										<!-- <th>Country</th> -->
										<!-- <th>GST</th> -->
										<th>Amount</th>
										<th>Date</th>
										<th>Payment Mode</th>
										<th>AWB No</th>
										<!-- <th>Payment</th> -->
										<th>Order Status</th>
									</tr>
								</thead>
								<tbody>
									<?php
									$noprd=50;
									$cpage=$_GET['page'];
									if ($cpage == 0){
										$cpage=1;
										$cnt=1;
									}else{
										$cnt=($cpage * $noprd) - $noprd + 1;
									}
									$frm=($cpage * $noprd) - $noprd;
									
									// Replace the existing where clause with this:

									$whr = 1;
									if($_GET['date_filter']!="") {
										switch ($_GET['date_filter']) {
											case 'today':
												$whr .= " and DATE(o.dt) = CURDATE() ";
												break;
											case 'yesterday':
												$whr .= " and DATE(o.dt) = CURDATE() - INTERVAL 1 DAY ";
												break;
											case 'this_week':
												$whr .= " and WEEK(o.dt) = WEEK(CURDATE()) AND YEAR(o.dt) = YEAR(CURDATE()) ";
												break;
											case 'last_week':
												$whr .= " and WEEK(o.dt) = WEEK(CURDATE()) - 1 AND YEAR(o.dt) = YEAR(CURDATE()) ";
												break;
											case 'this_month':
												$whr .= " and MONTH(o.dt) = MONTH(CURDATE()) AND YEAR(o.dt) = YEAR(CURDATE()) ";
												break;
											case 'last_month':
												$whr .= " and MONTH(o.dt) = MONTH(CURDATE()) - 1 AND YEAR(o.dt) = YEAR(CURDATE()) ";
												break;
										}
									} else if($_GET['frm']!="" && $_GET['to']!="") {
										$whr .= " and o.dt >= '$_GET[frm] 00:00:00' and o.dt <= '$_GET[to] 23:59:59' ";
									}
									if($_GET['payment_method']!="") {
										$whr .= " and payment_method='$_GET[payment_method]' ";
									}
									if($_GET['city']!="") {
										$whr .= " and city LIKE '%$_GET[city]%' ";
									}
									if($_GET['sts']!="") {
										$whr .= " and status='$_GET[sts]' ";
									}
									/* if($_GET['typ']=="F"){
										//$whr.=" and payment_method='shmart' and payment_response not like '%success%' ";
										$whr.=" and payment_response not like '%success%' ";
									}else{
										//$whr.=" and (payment_method='cod' or (payment_method='shmart' and payment_response like '%success%')) ";
										$whr.=" and (payment_method='cod' or (payment_response like '%success%')) ";
									} */
							
									$orderby=" order by o.dt desc ";
							
									//$query = "select * from orders as o, order_details as od where o.order_id=od.order_id and o.member_id='$_SESSION[member_id]' $dtt order by o.dt desc";
									$query = "SELECT * from orders as o where $whr ";
									$sql=$query;
									// echo $query;
									$query.=" $orderby LIMIT $frm, $noprd";
									$query = mysqli_query($conn, $query) or die (mysqli_error($conn));
									while($row = mysqli_fetch_array($query,MYSQLI_ASSOC)){
										// var_dump($row);
										?>
										<tr>
											<td><?php echo $cnt?></td>
											<td><?php echo $row['order_id'];?><br />[<a href="main.php?action=order_details&order_id=<?php echo $row['order_id']?>">Details</a>]</td>
											<td>
												<a href="main.php?action=users_details&member_id=<?php echo $row['member_id'];?>"><?php echo $row['member_id'];?></a> | 
												<?php echo $row['fname'];?> <?php echo $row['lname'];?>
											</td>
											<td><?php echo $row['mobile'];?></td>
											<td><?php echo $row['address'];?><br /><?php echo $row['address1'];?></td>
											<td><?php echo $row['city'];?></td>
											<td><?php echo $row['postcode'];?></td>
											<!-- <td><?php echo $row['country'];?></td> -->
											<!-- <td><?php echo $row['tax']?> %</td> -->
											<td>Rs.<?php echo number_format($row['total'],2)?></td>
											<td nowrap><?php echo date("d M Y h:i:s a", strtotime($row['dt']));?></td>
											<td>
												<?php 
												echo strtoupper($row['payment_method']);
												if($row['payment_method']=='razorpay'){
													$ar=json_decode($row['payment_response']);
													// echo "<pre>";print_r($ar);echo "</pre>";
													echo "<br /><br />TXNID: ".$ar->id;
													// echo "<br />ORDERID: ".$ar->ORDERID;
													echo "<br />TXNAMOUNT: ".$ar->amount/100;
													echo "<br />TXNDATE: ".date('d-m-Y', $ar->created_at);
													// echo "<br />RESPMSG: ".$ar->RESPMSG;
													echo "<br><b style='color: red;'>".strtoupper(($ar->status?$ar->status:""))."</b>";
												}
												?>
											</td>
											<td><?php echo $row['awbno']?></td>
											<!-- <td>
												<?php echo ($row['payment_status']?"Payment Received":"Payment Pending");
												if($row['payment_status']==0){
													?> 
													<a href="?action=<?php echo $_GET['action']?>&order_id=<?php echo $row['order_id']?>&pstatus=1">Mark Received</a>
													<?php
												}
												?>
											</td> -->
											<td>
												<span style="font-weight:bold; color:<?php echo ($row['status']=="Canceled"?"#0000ff":"")?> <?php echo ($row['status']=="Shipped"?"#009900":"")?> "><?php echo $row['status'];?></span> <br />
												<a href="main.php?action=order_status&order_id=<?php echo $row['order_id']?>" class="btn btn-sm btn-info">Update</a>
											</td>
											</tr>
											<?php
											$cate_id=$row['cate_id'];
											$cnt++;
									}
									?>
								</tbody>
								<!-- <tfoot>
									<tr>
										<th>#</th>
										<th>Category</th>
										<th>Action(s)</th>
									</tr> -->
								</tfoot>
							</table>
						</div>
					 
					<!-- /.card-body -->
				</div>
			</div>
			<!-- /.col-->
		</div>
	</section>
	<!-- /.content -->
</div>
<script>
function updateDateRange(value) {
    const fromInput = document.getElementById('date_from');
    const toInput = document.getElementById('date_to');
    
    const today = new Date();
    
    switch(value) {
        case 'today':
            fromInput.value = today.toISOString().split('T')[0];
            toInput.value = today.toISOString().split('T')[0];
            break;
            
        case 'yesterday':
            const yesterday = new Date(today);
            yesterday.setDate(yesterday.getDate() - 1);
            fromInput.value = yesterday.toISOString().split('T')[0];
            toInput.value = yesterday.toISOString().split('T')[0];
            break;
            
        case 'this_week':
            const thisWeekStart = new Date(today);
            thisWeekStart.setDate(today.getDate() - today.getDay());
            fromInput.value = thisWeekStart.toISOString().split('T')[0];
            toInput.value = today.toISOString().split('T')[0];
            break;
            
        case 'last_week':
            const lastWeekStart = new Date(today);
            lastWeekStart.setDate(today.getDate() - today.getDay() - 7);
            const lastWeekEnd = new Date(today);
            lastWeekEnd.setDate(today.getDate() - today.getDay() - 1);
            fromInput.value = lastWeekStart.toISOString().split('T')[0];
            toInput.value = lastWeekEnd.toISOString().split('T')[0];
            break;
            
        case 'this_month':
            const thisMonthStart = new Date(today.getFullYear(), today.getMonth(), 1);
            fromInput.value = thisMonthStart.toISOString().split('T')[0];
            toInput.value = today.toISOString().split('T')[0];
            break;
            
        case 'last_month':
            const lastMonthStart = new Date(today.getFullYear(), today.getMonth() - 1, 1);
            const lastMonthEnd = new Date(today.getFullYear(), today.getMonth(), 0);
            fromInput.value = lastMonthStart.toISOString().split('T')[0];
            toInput.value = lastMonthEnd.toISOString().split('T')[0];
            break;
            
        default:
            // Reset the date inputs when "Custom Range" is selected
            fromInput.value = '';
            toInput.value = '';
    }
}

function exportToExcel() {
    // Get current form values
    var formData = new FormData(document.querySelector('form'));
    var queryString = new URLSearchParams(formData).toString();
    
    // Redirect to export script with current filters
    window.location.href = 'export_orders.php?' + queryString;
}
</script>


PK 99