<?php
session_start();
if(!isset($_SESSION['user'])) {
	header("location: ../index.php");
	exit;
}
include('Pagination.php');
include("../header.php");
$days_ago = date('d/m/Y', strtotime('-4 days', time()));
?>	
				<div class="row">
					<div class="col-lg-12">
						<form>
							<div class="row">
								<div class="col-lg-6 col-sm-8 col-md-6">
									<div class="row">
										<div class="col-lg-4 col-sm-4 col-md-4">
											<div class="form-group">
												<label for="">Select Outlet</label>
												<select id="outlet" name="" class="form-control">
													<option value="all">All</option>
													<?php
													$ot_qry = mysql_query("SELECT `UnitName`,`UnitId` FROM `unit_master` WHERE `IsActive` = 1");
													while ($ot_row = mysql_fetch_array($ot_qry)) {
														?>
														<option value="<?php echo $ot_row['UnitId']; ?>"><?php echo $ot_row['UnitName']; ?></option>
														<?php
						                            }
						                            ?>
												</select>
											</div>
										</div>
										
										<div class="col-lg-6 col-sm-6 col-md-6">	
											<div class="form-group">
												<label for="">Select Sale Date</label>
												<input type="text" class="form-control textbox" id="callbackdatepick" value="<?php echo $days_ago; ?>">
											</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
										
    									$today = date('Y-m-d');
    									// $lastDay = date('Y-m-d', strtotime('-1 day'));
    									$lastDay = date('Y-m-d', strtotime('-4 days', time()));

										$goh_qry = mysql_query("SELECT `UnitId`, `FirstName`, `LastName`, `InvoiceNumber`, `SourceOfOrder`, `SaleDate`, `SaleTime`, `InvoiceId` FROM `guest_order_history` WHERE  `feedback_done` = 0 AND (OrderStatus!='Rejected' AND OrderStatus!='Cancelled') AND `SaleDate` = '$lastDay' limit 6");
										if(mysql_num_rows($goh_qry) > 0) {
											while($goh_row = mysql_fetch_array($goh_qry)) {
												$unitId = $goh_row['UnitId'];
												
												$unit_sql = mysql_query("SELECT UnitName FROM unit_master WHERE UnitId=$unitId");
												$unit_row = mysql_fetch_assoc($unit_sql);
												$unit_name = $unit_row['UnitName'];
												?>
												<div class="view-callback-customer">
													<div class="shadow"></div>
													<div class="row">
														<div class="col-lg-8">
															<p class="customer-name text-logs" style="font-weight: 800;"><?php echo $goh_row['FirstName'].' '.$goh_row['LastName']; ?></p>
															<p class="customer-name text-logs">Invoice No. - <span class="text-bold"><?php echo $goh_row['InvoiceNumber']; ?></span></p>
															<p class="customer-name text-logs">Order Source - <span class="text-bold"><?php echo $goh_row['SourceOfOrder']; ?></span></p>
															<p class="customer-name text-logs">Outlet - <span class="text-bold"><?php echo $unit_name; ?></span></p>
															<p class="text-logs">Sale Date <span class="text-bold"><?php echo date('d-m-Y', strtotime($goh_row['SaleDate'])).' '.$goh_row['SaleTime']; ?></span></p>
														</div>
														<div class="col-lg-4 text-right pull-right jalign-self-center">
															<div class="row justify-content-center">
																<button type="button" name="submit-btn" class="btn btn-outline-primary view-details<?php echo $goh_row['InvoiceId']; ?> float-right" onclick="customerTakeFeedback('takefb', <?php echo $goh_row['UnitId']; ?>, <?php echo $goh_row['InvoiceId']; ?> )">Take Feedback</button>
															</div>
															<div class="row justify-content-center">
																<button type="button" name="submit-btn" class="btn btn-outline-danger btn-not-interest btnint<?php echo $goh_row['InvoiceId']; ?> float-right" onclick="notInterested('notint', <?php echo $goh_row['UnitId']; ?>, <?php echo $goh_row['InvoiceId']; ?> )">Not Interested</button>
															</div>
														</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="loader" id="loader" style="display: none"></div>
														<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>

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

<script>

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>

$(function() {
		/* Date Picker */
    $('#callbackdatepick').daterangepicker({
        singleDatePicker: true,        
        minDate: moment().subtract(4, 'days'),
        maxDate: moment().subtract(2, 'days'),        
        locale: {
	      format: 'DD/MM/Y'
	    }
    });
});




</script>
<script src="../assets/js/jquery-confirm.js"></script>
<script type="text/javascript">
function notInterested(notint,outletid,invoiceid) {
	
	$.confirm({
	    title: 'Confirm!',
    	content: 'Are you sure you are not interested?',
    	type: 'green',
    	closeIcon: true,
    	closeIconClass: 'fa fa-close',
    	buttons	: {
			'Yes'	: {
				'btnClass'	: 'blue',
				'action': function(){
					$.ajax({
						url: 'save_fb_settings_data.php?act='+notint+'&oid='+outletid+'&invid='+invoiceid,
						success : function(data){
							console.log(data);
							$(".view-details"+invoiceid).hide();
							$(".btnint"+invoiceid).css({"background-color":"#de4847", "color": "#fff"});
						}
					});
				}
			},
			'No'	: {
				'btnClass'	: 'gray',
				'action': function(){}	// Nothing to do in this case. You can as well omit the action property.
			}
		}
	});
}
</script>
<style>
.loader {
  border: 16px solid #f3f3f3;
  border-radius: 50%;
  border-top: 16px solid #3498db;
  width: 120px;
  height: 120px;
  -webkit-animation: spin 2s linear infinite; /* Safari */
  animation: spin 2s linear infinite;
}

/* Safari */
@-webkit-keyframes spin {
  0% { -webkit-transform: rotate(0deg); }
  100% { -webkit-transform: rotate(360deg); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
</style>