<?php
session_start();
include("../include/config.php");
include("../include/functions.php"); 
validate_admin();
$userlocationWhere='';
            $user_type = getFieldWhere('user_type', 'tbl_admin', 'id', $_SESSION['sess_admin_id']);
			$user_location=getFieldWhere('location', 'tbl_admin', 'id', $_SESSION['sess_admin_id']);
			$user_location=implode("','",explode(",",$user_location));
			//echo "select group_concat(distinct zip) as zip from tbl_store_zip where state in ('$user_location') and zip!=''";
			$userziparr=array();
			$userzip=$obj->query("select distinct(zip) as zip from tbl_store_zip where state in ('$user_location') and zip!=''");
			while($resuserZip=$obj->fetchNextObject($userzip)){
			array_push($userziparr,$resuserZip->zip);
			}
			$userLocationZip=implode(',',$userziparr);
			if($user_location!=''){
			$userlocationWhere='and tbl_order.ship_pincode in('.$userLocationZip.')';
			} 

	
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php echo SITE_TITLE; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="width=device-width, initial-scale=1" name="viewport" />
<link href="css/admin.css" rel="stylesheet" type="text/css" />
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
			<link rel="stylesheet" href="calender/css/jquery-ui.css">
                <script src="calender/js/jquery-ui.js"></script>
				<script>
 $(function () {
                $("#search_from_date").datepicker({
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: 'yy-mm-dd',
                    yearRange: '2021:<?php echo date('Y'); ?>',
					minDate: new Date('2021/04/01'),
                    onClose: function (selectedDate) {
                        $("#search_to_date").val(selectedDate);
                        $("#search_to_date").datepicker("option", "minDate", selectedDate);
                    }
                });
                $("#search_to_date").datepicker({
                    changeMonth: true,
                    changeYear: true,
                    numberOfMonths: 2,
                    dateFormat: 'yy-mm-dd',
                    yearRange: '2021:<?php echo date('Y'); ?>',
					minDate: new Date('2021/04/01'),
                })
                $("#search_from_date").datepicker({
                    changeMonth: true,
                    changeYear: true,
                    dateFormat: 'yy-mm-dd',
                    yearRange: '2021:<?php echo date('Y'); ?>',
					minDate: new Date('2021/04/01'),
                    onClose: function (selectedDate) {
                        $("#visit_date_to").val(selectedDate);
                        $("#visit_date_to").datepicker("option", "minDate", selectedDate);
                    }
                });
                $("#search_to_date").datepicker({
                    changeMonth: true,
                    changeYear: true,
                    numberOfMonths: 2,
                    dateFormat: 'yy-mm-dd',
                    yearRange: '2021:<?php echo date('Y'); ?>',
					minDate: new Date('2021/04/01'),
                })
            });
                </script>
<style>
img{max-width:100%;}
	*{transition: all .5s ease;-moz-transition: all .5s ease;-webkit-transition: all .5s ease}
.my-list {
    width: 100%;
    padding: 10px;
    border: 1px solid #999;
    float: left;
    margin: 10px 0;
    border-radius: 5px;
    box-shadow: 0px 0px 5px #999;
    position: relative;
    overflow: hidden;
}
.clearfix {
	clear:both;
}
a.btn.btn-success.mko {
    background: #000;
    color: #fff;
    margin: 0px auto;
    text-align: center;
    display: block;
    width: 95px;
    clear: both;
    font-size: 13px;
	border:1px solid #000;
}
.my-list h3 {
    text-align: left;
    font-size: 17px;
    line-height: 21px;
    margin: 0px;
    border-bottom: 1px solid #ccc4c4;
    margin-bottom: 5px;
    padding: 10px 6px;
    text-align: center;
    border: 1px solid #ddd;
    font-weight: 600;
}
	.my-list span{float:left;font-weight: bold;}
	.my-list span:last-child{float:right;}
	.my-list .offer{
    width: 100%;
    float: left;
    margin: 5px 0;
    border-top: 1px solid #ccc4c4;
	border-bottom: 1px solid #ccc4c4;
    margin-top: 5px;
    padding: 5px;
    color: #333;
	font-size:12px;
    }
	.detail {
    position: absolute;
    top: -100%;
    left: 0;
    text-align: center;
    background: #fff;height: 100%;width:100%;
	
}
.form-horizontal .form-group {
    margin-right: 0;
    margin-left: 0;
}
.row {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display:         flex;
  flex-wrap: wrap;
}
.row > [class*='col-'] {
  display: flex;
  flex-direction: column;
}
@media (min-width: 320px) and (max-width: 768px) {
button.btn.btn-default.searchbtn {	 
    display: block;
    width: 100%;
}
}	
.my-list:hover .detail{top:0;}
button.btn.btn-default.searchbtn {
    background: #333;
    color: #fff;
   
}
.topbottom {
    /* padding: 20px; */
    margin: 20px 0px;
}
.marked {
    position: absolute;
    font-size: 10px;
    left: 10px;
    color: #fff;
    font-weight: bold;
	top:10px;
	padding:3px;
}
.mknotcompletd {
	background: #e05959;
}
.mkcompletd {
	background: #28a745;
}
form.form-horizontal {
    padding: 20px 0px;
}
</style>

</head>
<body>
 <?php
                                                        $where = '';
                                                        if ($_REQUEST['search_order_id'] != '') {
                                                            $name = $_REQUEST['search_order_id'];
                                                            $where .= " and tbl_order.id='" . $name . "'";
                                                        }
                                                       
                                                       
                                                        if ($_REQUEST['search_orderstatus'] == '') {
															$where .= " and tbl_order.order_date>='2021-04-01'  and  tbl_order.order_status <> 3 and tbl_order.order_status <> 5 OR tbl_order.order_date=now()";
                                                            
                                                        } else {
															if($_REQUEST['search_orderstatus'] == 'all'){
																 if ($_REQUEST['search_from_date'] != '' && $_REQUEST['search_to_date'] != '') {
                                                            $where .= " and tbl_order.order_date>='" . $_REQUEST['search_from_date'] . "' and tbl_order.order_date<='" . $_REQUEST['search_to_date'] . "' ";
                                                        } else {
															$where .= " and tbl_order.order_date>='2021-04-01'";
														}															
															} else {
														    $name = $_REQUEST['search_orderstatus'];
                                                            $where .= " and tbl_order.order_status='" . $name . "'";
															}
															
														}
                                                    $sectionwhere="";
                                                       if ($_REQUEST['department'] != '') {
                                                            $name = $_REQUEST['department'];
                                                            $sectionwhere .= " and tbl_order_itmes.section='" . $name . "'";
                                                        }
                                                       
                                                        
                                                       
                                                        $start = 0;
                                                        if (isset($_GET['start']))
                                                            $start = $_GET['start'];
                                                        $pagesize = 20;
                                                        if (isset($_GET['pagesize']))
                                                         $pagesize = $_GET['pagesize'];
 												
 $sql = $obj->Query("select tbl_order_itmes.storeid,tbl_order.id,tbl_order.delivery_type,tbl_order.order_type,tbl_order.order_date,tbl_order.usps_expected_delivery,tbl_order.order_status,tbl_order.deliverby,tbl_order.total_amount,tbl_order.ship_pincode from $tbl_order inner join tbl_order_itmes on tbl_order.id=tbl_order_itmes.order_id where 1=1 $sectionwhere $userlocationWhere $where group by tbl_order.id order by tbl_order.id desc limit $start,$pagesize");
 $sql2 = $obj->query("select COUNT(*)  as recent from tbl_order inner join tbl_order_itmes on tbl_order.id=tbl_order_itmes.order_id where 1=1 $sectionwhere $userlocationWhere $where ", $debug = -1);
                                                   
$totalorder = $obj->fetchNextObject($sql2);
$reccnt = $totalorder->recent;
?>
<div class="container">
 
  <form class="form-horizontal" action="order-list-responsive.php" method="post">
  <div class="col-xs-6 col-sm-6 col-md-4">
  <div class="form-group">
    <label for="exampleFormControlSelect1">Order List By</label>
    <select class="form-control" id="exampleFormControlSelect1" name="search_orderstatus">
      <option value="" <?php if($_REQUEST['search_orderstatus']==''){?> selected <?php } ?>>Today</option>
      <option value="all" <?php if($_REQUEST['search_orderstatus']=='all'){?> selected <?php } ?>>All</option>

    </select>
  </div>
  </div>
  <div class="col-xs-6 col-sm-6 col-md-4">
  <div class="form-group">
    <label for="exampleFormControlSelect1">Select Department</label>
    <select class="form-control" id="exampleFormControlSelect1" name="department">
       <option value="">Select</option>
     
	<?php  $sectionsql = $obj->query("SELECT id,section_slug,section_name FROM `tbl_section` WHERE status=1");
        while ($secresuslt = $obj->fetchNextObject($sectionsql)) {?>
		 <option value="<?php echo $secresuslt->section_slug;?>" <?php if($_REQUEST['department']==$secresuslt->section_slug){?> selected <?php } ?>><?php echo $secresuslt->section_name;?></option>
		<?php } ?>

    </select>
  </div>
  </div>
  <div class="col-xs-6 col-sm-6 col-md-4">
    <div class="form-group">
      <label for="email">Order ID:</label>
      <input type="text" class="form-control" placeholder="Order ID" name="search_order_id" value="<?php echo $_REQUEST['search_order_id']; ?>">
    </div>
	</div>
	<?php if($_REQUEST['search_orderstatus']!=''){?>
	<div class="col-xs-6 col-sm-6 col-md-6">
    <div class="form-group">
      <label for="pwd">From Date:</label>
      <input type="text" class="form-control" id="search_from_date" name="search_from_date" value="<?php echo $_REQUEST['search_from_date']; ?>" autocomplete="off">
    </div>
	</div>
	<div class="col-xs-6 col-sm-6 col-md-6">
	<div class="form-group">
      <label for="pwd">To date:</label>
      <input type="text" class="form-control" id="search_to_date" name="search_to_date" value="<?php echo $_REQUEST['search_to_date']; ?>" autocomplete="off">
    </div>
    </div>
	<?php } ?>
	<div class="col-xs-12 col-sm-12 col-md-12">
    <button type="submit" class="btn btn-default searchbtn">Search</button>
	</div>
  </form>
</div>

 <div class="container">
	<div class="row">
	<?php if ($reccnt == 0) {?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-center"><h3 style="font-size:16px;">No Record</h3></div>
<?php
} else {?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 text-center"><h3 style="font-size:16px;"><?php echo $reccnt; ?> Records Found</h3></div>
 <?php $i = 0;
       while ($line = $obj->fetchNextObject($sql)) {

		   ?>
		<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
		<div class="my-list">
		<?php 
		$shopperoderstatus = $obj->query("SELECT count(*) as marked FROM `tbl_order_shopper` where order_id='$line->id' and shopper_status=0");
		$shopperoderstatusres=$obj->fetchNextObject($shopperoderstatus);
		 
	
		if($shopperoderstatusres->marked==0){
			
			echo '<div class="marked mkcompletd">Done</div>';
			
		} else {
			echo '<div class="marked mknotcompletd">Not done</div>';
		}
	   
		?>
			<h3>Order Id: <?php echo stripslashes($line->id);?></h3>
		
			<p class="pull-left"><strong>Order Type:</strong>  <?php if ($line->usps_expected_delivery == '' && $line->order_type !== 'Suburb' && $line->order_type !== 'Wholesale') { echo "Local";
                          } elseif ($line->order_type == 'UPS' || $line->usps_expected_delivery !== '') {
                            echo "UPS";
                           ?>
						   <?php
                            } else {
                           echo $line->order_type;
                            }
                          ?></p>
						 <p class="pull-right text-right"><strong>Status: </strong><?php echo getField('order_status', $tbl_order_status, $line->order_status);?></p>
						 <div class="clearfix"></div>
			<p class="pull-left"><strong>Order Date: </strong><?php echo date('d M Y H:i', strtotime($line->order_date));?></p>
			<p class="pull-right text-right"><strong>Amount: </strong><?php  echo $website_currency_symbol . "" . number_format($line->total_amount, 2);?></p>
			
			<div class="store offer"><strong>Stores: </strong>
			<?php
                                                                                            $sqlstore = $obj->query("SELECT storename FROM stores as a left join tbl_order_itmes as b on a.storeid=b.storeid where b.order_id='$line->id; ?>'");
                                                                                            $strarr = '';
                                                                                            while ($storeres = $obj->fetchNextObject($sqlstore)) {
                                                                                                $strarr[] = $storeres->storename;
                                                                                            }
                                                                                            $storearray = array_values(array_unique($strarr));
                                                                                            
                                                                                           echo $storeList = implode(',', $storearray);
                                                                                            ?>
           
								</div>
								<div class="store offer"><strong>Section: </strong>
				  <?php
                                                                           $section_qry = "SELECT  tbl_order_itmes.section , GROUP_CONCAT( DISTINCT tbl_order_itmes.storeid) storeids   FROM tbl_order_itmes  WHERE tbl_order_itmes.order_id = '" . $line->id . "' group by tbl_order_itmes.section";
                                                                             $sectiondetail = $obj->query($section_qry);

                                                                             while ($sectionDetailRslt = $obj->fetchNextObject($sectiondetail)) {
                                                                             $section = $sectionDetailRslt->section;
                                                                             $storeids = $sectionDetailRslt->storeids;
																			 if ($section == 'grocery') {
                                                                             $grocery_delivery_partner = "SELECT 

                                                                              GROUP_CONCAT(DISTINCT  tbl_store_zip.grocery_delivery_partner) grocery FROM tbl_store_zip WHERE
                                                                               tbl_store_zip.zip = '" . $line->ship_pincode . "' AND tbl_store_zip.storeid IN( $storeids) group by   tbl_store_zip.zip";
                                                                               $grocery_delivery_partnerRslt = $obj->query($grocery_delivery_partner);
                                                                               $grocery_partner = $obj->fetchNextObject($grocery_delivery_partnerRslt);
                                                                               echo "(". ucwords($section . " / " . $grocery_partner->grocery) . "),";
                                                                                } else if ($section != 'grocery') {
                                                                               $food_delivery_partner = "SELECT  GROUP_CONCAT( DISTINCT  tbl_store_zip.food_delivery_partner) food
                                                                               FROM tbl_store_zip
                                                                               WHERE tbl_store_zip.zip = '" . $line->ship_pincode . "' AND 
                                                                               tbl_store_zip.storeid IN( $storeids)
                                                                               group by    tbl_store_zip.zip";
                                                                                                    $food_delivery_partnerRslt = $obj->query($food_delivery_partner);
                                                                                                    $food_partner = $obj->fetchNextObject($food_delivery_partnerRslt);
                                                                                                    echo "(". ucwords($section . " / " . $food_partner->food) . "),";
                                                                                                }
                                                                                            }
                                                                                            ?>	
</div>																							
			<a class="btn btn-success mko" href="shopper-order-view-detail.php?order_id=<?php  echo stripslashes($line->id);?>">Make Order</a>
			<!--<div class="detail">
			<p>Glyphicons in Bootstrap : Bootstrap Includes over 250 glyphs in font format </p>
			<img src="http://hpservicecenterschennai.in/images/hp_laptop_service_centers_in_guindy.png" alt="dsadas" />
			<a href="#" class="btn btn-info">Add To Cart</a>
			<a href="#" class="btn btn-info">Deatil</a>
			</div>-->
			
				<script>
                  $(document).ready(function () {
                 $(".iframeadres<?php echo $line->id; ?>").colorbox({iframe: true, width: "700px;", height: "500px;", frameborder: "0", scrolling: true});
                  });
              </script>
		</div>
		
		</div>
		<?php } ?>
		<?php } ?>
		</div>
		<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 topbottom"><?php include("../include/paging.inc.php"); ?></div>
		
    </div>

</body>
</html>
