<?php
session_start();
if(!isset($_SESSION['user'])) {
	header("location: ../index.php");
	exit;
}
include('Pagination.php');
include("../header.php");

?>
	
	
				<div class="row">
					<div class="col-lg-12">
						<form>
							<div class="row">
								<div class="col-lg-4 col-sm-4 col-md-4">
									<div class="row">
										<div class="col-lg-4 col-sm-4 col-md-4">
											<div class="form-group">
												<label for="">Outlet</label>
												<select id="outlet" name="" class="form-control">
													<option value="all">All</option>
													<?php
													$ot_qry = mysql_query("SELECT DISTINCT(`outlet_name`) FROM `feedback_response` ");
													while ($ot_row = mysql_fetch_array($ot_qry)) {
														?>
														<option value="<?php echo $ot_row['outlet_name']; ?>"><?php echo $ot_row['outlet_name']; ?></option>
														<?php
                                                    }
                                                    ?>
												</select>
											</div>
										</div>
										
										<div class="col-lg-6 col-sm-6 col-md-6">	
											<div class="form-group">
												<label for="">Date Range</label>
												<input type="text" class="form-control textbox" id="callbackdatepick">
											</div>
										</div>

										<div class="col-lg-2 col-sm-2 col-md-2">	
											<div class="form-group">
												<button type="button" name="submit-btn" class="btn btn-outline-primary txtbtn-submit" onclick="feedbackCallData('callback', document.getElementById('outlet').value, document.getElementById('callbackdatepick').value )">Submit</button>
											</div>
										</div>

									</div>
								</div>
							
							</div>
						</form>
					</div>
				</div>
		
				<div class="row">
					<div class="col-lg-12">
						
						<div class="card">
							<div class="card-body">
						
								<div class="row">
									<div class="col-lg-6">
										<div id="paginate-customer" class="blade-callback">
										<?php
										/*$limit = 3;
										$qry_pgn = mysql_query("SELECT count(*) AS pgnNum FROM `guest_order_history` WHERE `feedback_done` = 0");
										$row_pgn = mysql_fetch_assoc($qry_pgn);
										$rowCount = $row_pgn['pgnNum'];

										$pagConfig = array('baseURL'=>'getData.php', 'totalRows'=>$rowCount, 'perPage'=>$limit, 'contentDiv'=>'paginate-customer');
    									$pagination =  new Pagination($pagConfig);*/

										$goh_qry = mysql_query("SELECT fbr.*, goh.`feedback_done` FROM `guest_order_history` AS goh RIGHT JOIN `feedback_response` AS fbr ON goh.`SaleDate` = fbr.`sale_date` WHERE goh.`feedback_done` = 0 ORDER BY fbr.`response_date_time` DESC");
										if(mysql_num_rows($goh_qry) > 0) {
											while($goh_row = mysql_fetch_array($goh_qry)) {
												$gunitId = $goh_row['UnitId'];
												
												$date_time = $goh_row['response_date_time'];
												$fbno = $goh_row['fb_no'];
												$rate_qry = mysql_query("SELECT (SUM(`ans_wt`) / count(`fb_no`)) AS rate FROM `feedback_response_details` WHERE `fb_no` = '$fbno'");
												$rate_row = mysql_fetch_array($rate_qry);
												$avg_rate = number_format($rate_row['rate'], 1);
												?>
												<div class="view-customer">
													<div class="shadow"></div>
													<div class="row">
														<div class="col-lg-6">
															<p class="customer-name text-logs" style="font-weight: 800;"><?php echo $goh_row['guest_name']; ?></p>
														</div>
														<div class="col-lg-6 text-right">
															<p class="customer-name text-logs">Invoice No. - <span class="text-bold"><?php echo $goh_row['invoice_no']; ?></span></p>
															<p class="customer-name text-logs">Order Source - <span class="text-bold"><?php echo $goh_row['order_source_name']; ?></span></p>
															<p class="customer-name text-logs">outlet - <span class="text-bold"><?php echo $goh_row['outlet_name']; ?></span></p>
														</div>
													</div>
													<div class="row">
														<div class="col-lg-8">
															<!-- <p class="text-logs">Response On <span class="text-bold"><?php //echo date('d-m-Y H:i:s', strtotime($goh_row['response_date_time'])); ?></span></p>
															<p class="text-logs"><span class="help-block text-bold"><?php //echo $goh_row['fb_comments']; ?></span></p> -->
															<p class="text-logs">Sale Date <span class="text-bold"><?php echo date('d-m-Y', strtotime($goh_row['sale_date'])); ?></span></p>
														</div>
														<div class="col-lg-4">
															<!-- <button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails('details', <?php //echo $row1['fb_no']; ?>, <?php //echo $row1['outlet_id']; ?>, <?php //echo $row1['invoice_id']; ?> )">View Details</button> -->
															<?php
															
															if ($goh_row['feedback_done'] == 0) {
																?>
																<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerTakeFeedback('takefb', <?php echo $goh_row['fb_no']; ?>, <?php echo $goh_row['outlet_id']; ?>, <?php echo $goh_row['invoice_id']; ?> )">Take Feedback</button>
																<br>
																<br>
																<button type="button" name="submit-btn" class="btn btn-outline-danger btn-not-interest float-right" onclick="notInterested('notint', <?php echo $goh_row['fb_no']; ?>, <?php echo $goh_row['outlet_id']; ?>, <?php echo $goh_row['invoice_id']; ?> )">Not Interested</button>
																<?php
															} else {
																?>
																<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails('calldetails', <?php echo $goh_row['fb_no']; ?>, <?php echo $goh_row['outlet_id']; ?>, <?php echo $goh_row['invoice_id']; ?> )">View Details</button>
																<?php
															}
															?>
														</div>
													</div>
												</div>
												<?php
												
											}
											// echo $pagination->createLinks();
										}
										
										?>
										</div>
									</div>
									
									<!-- <div class="col-lg-6">
										<div class="customer-detail" id="callFixed">
											<div class="tabbable-panel">
												<div class="tabbable-line">
													<ul class="nav nav-tabs ">
														<li class="active">
															<a href="#feedback_datails" data-toggle="tab">
															Feedback Details </a>
														</li>
														<li>
															<a href="#order_info" data-toggle="tab">
															Order Info </a>
														</li>
													</ul>
													<div class="tab-content">
														
														<div class="tab-pane active" id="feedback_datails">
															<div id="customer-cb-detail">
																
															</div>
														</div>
														
														<div class="tab-pane" id="order_info">
															<div id="customer-cb-info">
																
															</div>
														</div>
													</div>
												</div>
											</div>
										</div>
									</div> -->
								</div>
								
							</div>
						</div>
						
					</div>
				</div>

				<div id="callbackModal" class="modal">

					<div class="modal-content">
						<div class="modal-header">
							<span class="close" onClick="CloseModal('callbackModal')">&times;</span>
						</div>
						<div class="modal-body">
							<div class="col-lg-12">
								<div class="customer-detail" id="callFixed">
									<div class="tabbable-panel">
										<div class="tabbable-line">
											<ul class="nav nav-tabs ">
												<li class="active">
													<a href="#feedback_datails" data-toggle="tab">
													Feedback Details </a>
												</li>
												<li>
													<a href="#order_info" data-toggle="tab">
													Order Info </a>
												</li>
											</ul>
											<div class="tab-content">
												
												<div class="tab-pane active" id="feedback_datails">
													<div id="customer-cb-detail">
														
													</div>
												</div>
												
												<div class="tab-pane" id="order_info">
													<div id="customer-cb-info">
														
													</div>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>

				</div>
	
<?php include("../footer.php"); ?>

<script>
$( function(){
	$('#cbdob, #cbanniversary').datepicker({
		format: 'dd-mm-yyyy',
		autoclose: true,
		todayHighlight: true,
		orientation: "bottom auto"
	});
});

jQuery(function($) {
  	function fixDiv() {
    var $cache = $('#callFixed');
    if ($(window).scrollTop() > 100)
      	$cache.css({
	        'position': 'fixed',
	        'top': '10%',
	        'width': '38%',
	        'max-height': '67%'
      	});
    else
      	$cache.css({
	        'position': 'relative',
	        'top': 'auto',
	        'width': 'auto',
	        'max-height': '56%'
      	});
  	}
  	$(window).scroll(fixDiv);
  	fixDiv();
});



</script>


<!-- Include Required Prerequisites -->
<script type="text/javascript" src="//cdn.jsdelivr.net/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>

<!-- Include Date Range Picker -->
<script type="text/javascript" src="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />
<script>
$('#callbackdatepick').daterangepicker(
	{
	    locale: {
	      format: 'DD/MM/Y'
	    }
	}
);
</script>