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

$client_id = '62';
$outlet_id = '1';
// Data and graph of current month
if ($_GET['act'] == 'cm') {
	$date = date('Y-m-d');
	$expdate = explode('-', $date);
	$today = $expdate[2];
	$bgdate = $expdate[0]."-".$expdate[1]."-01";
	$mnth_yr = date('F')." ".$expdate[0];

	$crdate = array();
	$respond = array();
	$respond_all_star = array();
	$qlty_star = array();
	$package_star = array();
	$visit_star = array();
	
	$qry = mysql_query("SELECT DISTINCT(`sale_date`) FROM `feedback_response` WHERE (`sale_date` >= '$bgdate' AND `sale_date` <= '$date') AND `client_id` = '$client_id'");
	while ($row = mysql_fetch_array($qry)) {
		$fbdate = $row['sale_date'];

		$frd_qry = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND fbr.`sale_date` = '$fbdate' AND frd.`fb_ques_id` = '1'");
		$frd_row = mysql_fetch_array($frd_qry);
		
		$respond[] = $frd_row['avg'];
		$crdate[] = date('d M', strtotime($fbdate));
	}

	$frd_qry1 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '1' AND (fbr.`sale_date` >= '$bgdate' AND fbr.`sale_date` <= '$date')");
	$frd_row1 = mysql_fetch_array($frd_qry1);
	$respond_all = number_format($frd_row1['avg_all'], 1);
	for ($i=1; $i <= 5; $i++) { 
		
		if ($i <= $respond_all) {
			$checked = "star-checked";
			$star = "fa-star";
			
		} else if( $respond_all > $j AND $respond_all < $i ) { 
			$checked = "star-checked";
			$star = "fa-star-half-o";
		} else {
			$checked = "";
			$star = "fa-star-o";
		}	
		$j = $i;

		$respond_all_star[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';

	}

	$total_sent = 0;
	$sentData = array();
	$sentDate = array();
	$sqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_sent`) as sent FROM `guest_order_history` WHERE (`SaleDate` >= '$bgdate' AND `SaleDate` <= '$date') AND `feedback_sent` = '1' GROUP BY `SaleDate`");
	while ($srow = mysql_fetch_array($sqry)) {
		$total_sent += $srow['sent'];
		$sdate = $srow['saledate'];
		$sentData[] = $srow['sent'];
		$sentDate[] = date('d-m-Y', strtotime($sdate));
	}	

	$total_done = 0;
	$recData = array();
	$recDate = array();
	$dqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_done`) as done FROM `guest_order_history` WHERE (`SaleDate` >= '$bgdate' AND `SaleDate` <= '$date') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
	while ($drow = mysql_fetch_array($dqry)) {
		$total_done += $drow['done'];
		$ddate = $drow['saledate'];
		$recData[] = $drow['done'];
		$recDate[] = date('d-m-Y', strtotime($ddate));
	}

	$nqry = mysql_query("SELECT count(`feedback_done`) as notinterst FROM `guest_order_history` WHERE (`SaleDate` >= '$bgdate' AND `SaleDate` <= '$date') AND `feedback_sent` = '1' AND `feedback_done` = '2'");
	while ($nrow = mysql_fetch_array($nqry)) {
		$total_notint = $nrow['notinterst'];
	}

	$percentData = array();
	$percentDate = array();
	$per_qry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, ((SUM(`feedback_done`) / SUM(`feedback_sent`))*100) AS percent FROM `guest_order_history` WHERE (`SaleDate` >= '$bgdate' AND `SaleDate` <= '$date') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
	while ($per_row = mysql_fetch_array($per_qry)) {
		$per_date = $per_row['saledate'];
		$percentData[] = $per_row['percent'];
		$percentDate[] = date('d-m-Y', strtotime($per_date));
	}

	if ($total_sent == 0) {
		$total_done_per = 0;
	} else {
		$total_done_per = number_format(($total_done/$total_sent)*100, 2)."%";
	}

	// dynamic for feedback question details
	
	$dy_ques_data = array();
	$dy_qry = mysql_query("SELECT DISTINCT(`fb_ques_id`), `fb_ques` FROM `feedback_response_details` WHERE `fb_ques_id` != 1");
	while ($dy_row = mysql_fetch_array($dy_qry)) {
		$ques_id = $dy_row['fb_ques_id'];
		$ques_name = $dy_row['fb_ques'];
		$expquesname = explode('_', $ques_name);
		$fdqlty_fbno = 0;
		$ans_wt = 0;
		$fdqlty_five_star11 = 0;
		$fdqlty_four_star11 = 0;
		$fdqlty_three_star11 = 0;
		$fdqlty_two_star11 = 0;
		$fdqlty_one_star11 = 0;
		$fdqlty_five_per11 = 0;
		$fdqlty_four_per11 = 0;
		$fdqlty_three_per11 = 0;
		$fdqlty_two_per11 = 0;
		$fdqlty_one_per11 = 0;
		$frd_qry121 = mysql_query("SELECT COUNT( DISTINCT(frd.`fb_no`) ) AS fdqlty_fbno, `ans_wt` FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$bgdate' AND fbr.`sale_date` <= '$date') GROUP BY frd.`fb_no`");
			while ($frd_row121 = mysql_fetch_array($frd_qry121)) {

				$fdqlty_fbno = $frd_row121['fdqlty_fbno'];
				$ans_wt = $frd_row121['ans_wt'];
				if ($ans_wt == 5) {
					$fdqlty_five_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_five_per11 = 0;
					} else {
						$fdqlty_five_per11 = ($fdqlty_five_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 4) {
					$fdqlty_four_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_four_per11 = 0;
					} else {
						$fdqlty_four_per11 = ($fdqlty_four_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 3) {
					$fdqlty_three_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_three_per11 = 0;
					} else {
						$fdqlty_three_per11 = ($fdqlty_three_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 2) {
					$fdqlty_two_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_two_per11 = 0;
					} else {
						$fdqlty_two_per11 = ($fdqlty_two_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 1) {
					$fdqlty_one_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_one_per11 = 0;
					} else {
						$fdqlty_one_per11 = ($fdqlty_one_star11/$total_done)*100;
					}
				}
			}
		$qlty_star_rate = array();
		$frd_qry12 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all12 FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$bgdate' AND fbr.`sale_date` <= '$date')");
		while ($frd_row12 = mysql_fetch_array($frd_qry12)) {
			$respond_all12 = number_format($frd_row12['avg_all12'], 1);
			for ($i=1; $i <= 5; $i++) { 
																	
				if ($i <= $respond_all12) {
					$checked = "star-checked";
					$star = "fa-star";
					
				} else if( $respond_all12 > $j AND $respond_all12 < $i ) { 
					$checked = "star-checked";
					$star = "fa-star-half-o";
				} else {
					$checked = "";
					$star = "fa-star-o";
				}	
				$j = $i;

				$qlty_star_rate[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';

			}
			
			$dy_ques_data[] = '<div class="col-sm-6 col-lg-4"><div class="social-box facebook"><div class="box-title py-2"><div class="title">'.ucwords(implode(' ', $expquesname)).'</div><p class="dash-rating-count">'.$respond_all12.'</p><p class="star-rating fb-fdqlty-star">'.implode('',$qlty_star_rate).'</p></div><div class="custom-star-progress"><div class="row"><div class="col-xs-12 col-md-12"><div class="row fd-rating-desc"><div class="col-xs-3 col-md-3 col-lg-3">5 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_five_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_five_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">4 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_four_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_four_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">3 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_three_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_three_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">2 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_two_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_two_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">1 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_one_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_one_star11.'</span></div></div></div></div></div></div></div>';
		}
	}

	$data = array('date'=>$crdate, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'sentData'=>$sentData, 'sentDate'=>$sentDate, 'recData'=>$recData, 'recDate'=>$recDate, 'fbdone'=>$total_done, 'notinterest' => $total_notint, 'fbdoneper'=>$total_done_per, 'percentData'=>$percentData, 'percentDate'=>$percentDate, 'dyquesdata'=>$dy_ques_data);

	//$data = array('date'=>$crdate, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'fbdone'=>$total_done, 'fbdoneper'=>$total_done_per, 'fdqlty'=>$respond_all2, 'qltystar'=>$qlty_star, 'package'=>$respond_all3, 'packagestar'=>$package_star, 'visit'=>$respond_all4, 'visitstar'=>$visit_star);
	
	echo json_encode($data);
}


// Data and graph of last month
if ($_GET['act'] == 'lm') {
	
	$date = date('Y/m', strtotime(date('Y-m-d')." -1 month"));
	$expdate = explode('/', $date);
	$monthname = date('F', mktime(0,0,0, $expdate[1]));
	$pv_mnth_yr = $monthname." ".$expdate[0];
	$pv_frst_day = $expdate[0]."-".$expdate[1]."-01";
	$total_day = date('t', mktime(0,0,0, $expdate[1]));
	$pv_last_day = $expdate[0]."-".$expdate[1]."-".$total_day;
	$mnth_yr = $expdate[0];
	$mnth_yr = date('F Y', strtotime(date('Y-m-d')." -1 month"));

	$crdate = array();
	$respond = array();
	$respond_all_star = array();
	$qlty_star = array();
	$package_star = array();
	$visit_star = array();

	$qry = mysql_query("SELECT DISTINCT(`sale_date`) FROM `feedback_response` WHERE (`sale_date` >= '$pv_frst_day' AND `sale_date` <= '$pv_last_day') AND `client_id` = '$client_id'");
	while ($row = mysql_fetch_array($qry)) {
		$fbdate = $row['sale_date'];

		$frd_qry = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND fbr.`sale_date` = '$fbdate' AND frd.`fb_ques_id` = '1'");
		$frd_row = mysql_fetch_array($frd_qry);
		
		$respond[] = $frd_row['avg'];
		$crdate[] = date('d M', strtotime($fbdate));
	}

	$frd_qry2 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '1' AND (fbr.`sale_date` >= '$pv_frst_day' AND fbr.`sale_date` <= '$pv_last_day')");
	$frd_row2 = mysql_fetch_array($frd_qry2);
	$respond_all = number_format($frd_row2['avg_all'], 1);
	for ($i=1; $i <= 5; $i++) { 
		
		if ($i <= $respond_all) {
			$checked = "star-checked";
			$star = "fa-star";
			
		} else if( $respond_all > $j AND $respond_all < $i ) { 
			$checked = "star-checked";
			$star = "fa-star-half-o";
		} else {
			$checked = "";
			$star = "fa-star-o";
		}	
		$j = $i;

		$respond_all_star[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';

	}

	$total_sent = 0;
	$sentData = array();
	$sentDate = array();	
	$sqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_sent`) as sent FROM `guest_order_history` WHERE (`SaleDate` >= '$pv_frst_day' AND `SaleDate` <= '$pv_last_day') AND `feedback_sent` = '1' GROUP BY `SaleDate`");
	while ($srow = mysql_fetch_array($sqry)) {
		$total_sent += $srow['sent'];
		$sdate = $srow['saledate'];
		$sentData[] = $srow['sent'];
		$sentDate[] = date('d-m-Y', strtotime($sdate));
	}

	$total_done = 0;
	$recData = array();
	$recDate = array();
	$dqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_done`) as done FROM `guest_order_history` WHERE (`SaleDate` >= '$pv_frst_day' AND `SaleDate` <= '$pv_last_day') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
	while ($drow = mysql_fetch_array($dqry)) {
		$total_done += $drow['done'];
		$ddate = $drow['saledate'];
		$recData[] = $drow['done'];
		$recDate[] = date('d-m-Y', strtotime($ddate));
	}

	$nqry = mysql_query("SELECT count(`feedback_done`) as notinterst FROM `guest_order_history` WHERE (`SaleDate` >= '$pv_frst_day' AND `SaleDate` <= '$pv_last_day') AND `feedback_sent` = '1' AND `feedback_done` = '2'");
	while ($nrow = mysql_fetch_array($nqry)) {
		$total_notint = $nrow['notinterst'];
	}
	
	if ($total_sent == 0) {
		$total_done_per = 0;
	} else {
		$total_done_per = number_format(($total_done/$total_sent)*100, 2)."%";
	}


	$percentData = array();
	$percentDate = array();
	$per_qry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, ((SUM(`feedback_done`) / SUM(`feedback_sent`))*100) AS percent FROM `guest_order_history` WHERE (`SaleDate` >= '$pv_frst_day' AND `SaleDate` <= '$pv_last_day') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
	while ($per_row = mysql_fetch_array($per_qry)) {
		$per_date = $per_row['saledate'];
		$percentData[] = $per_row['percent'];
		$percentDate[] = date('d-m-Y', strtotime($per_date));
	}


	// dynamic for feedback question details	
	$dy_ques_data = array();
	$dy_qry = mysql_query("SELECT DISTINCT(`fb_ques_id`), `fb_ques` FROM `feedback_response_details` WHERE `fb_ques_id` != 1");
	while ($dy_row = mysql_fetch_array($dy_qry)) {
		$ques_id = $dy_row['fb_ques_id'];
		$ques_name = $dy_row['fb_ques'];
		$expquesname = explode('_', $ques_name);
		$fdqlty_fbno = 0;
		$ans_wt = 0;
		$fdqlty_five_star11 = 0;
		$fdqlty_four_star11 = 0;
		$fdqlty_three_star11 = 0;
		$fdqlty_two_star11 = 0;
		$fdqlty_one_star11 = 0;
		$fdqlty_five_per11 = 0;
		$fdqlty_four_per11 = 0;
		$fdqlty_three_per11 = 0;
		$fdqlty_two_per11 = 0;
		$fdqlty_one_per11 = 0;
		$frd_qry121 = mysql_query("SELECT COUNT( DISTINCT(frd.`fb_no`) ) AS fdqlty_fbno, `ans_wt` FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$pv_frst_day' AND fbr.`sale_date` <= '$pv_last_day') GROUP BY frd.`fb_no`");
			while ($frd_row121 = mysql_fetch_array($frd_qry121)) {

				$fdqlty_fbno = $frd_row121['fdqlty_fbno'];
				$ans_wt = $frd_row121['ans_wt'];
				if ($ans_wt == 5) {
					$fdqlty_five_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_five_per11 = 0;
					} else {
						$fdqlty_five_per11 = ($fdqlty_five_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 4) {
					$fdqlty_four_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_four_per11 = 0;
					} else {
						$fdqlty_four_per11 = ($fdqlty_four_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 3) {
					$fdqlty_three_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_three_per11 = 0;
					} else {
						$fdqlty_three_per11 = ($fdqlty_three_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 2) {
					$fdqlty_two_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_two_per11 = 0;
					} else {
						$fdqlty_two_per11 = ($fdqlty_two_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 1) {
					$fdqlty_one_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_one_per11 = 0;
					} else {
						$fdqlty_one_per11 = ($fdqlty_one_star11/$total_done)*100;
					}
				}
			}
		$qlty_star_rate = array();
		$frd_qry12 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all12 FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$pv_frst_day' AND fbr.`sale_date` <= '$pv_last_day')");
		while ($frd_row12 = mysql_fetch_array($frd_qry12)) {
			$respond_all12 = number_format($frd_row12['avg_all12'], 1);
			for ($i=1; $i <= 5; $i++) { 
																	
				if ($i <= $respond_all12) {
					$checked = "star-checked";
					$star = "fa-star";
					
				} else if( $respond_all12 > $j AND $respond_all12 < $i ) { 
					$checked = "star-checked";
					$star = "fa-star-half-o";
				} else {
					$checked = "";
					$star = "fa-star-o";
				}	
				$j = $i;

				$qlty_star_rate[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';

			}
			
			$dy_ques_data[] = '<div class="col-sm-6 col-lg-4"><div class="social-box facebook"><div class="box-title py-2"><div class="title">'.ucwords(implode(' ', $expquesname)).'</div><p class="dash-rating-count">'.$respond_all12.'</p><p class="star-rating fb-fdqlty-star">'.implode('',$qlty_star_rate).'</p></div><div class="custom-star-progress"><div class="row"><div class="col-xs-12 col-md-12"><div class="row fd-rating-desc"><div class="col-xs-3 col-md-3 col-lg-3">5 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_five_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_five_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">4 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_four_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_four_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">3 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_three_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_three_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">2 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_two_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_two_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">1 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_one_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_one_star11.'</span></div></div></div></div></div></div></div>';
		}
	}

	$data = array('date'=>$crdate, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'sentData'=>$sentData, 'sentDate'=>$sentDate, 'recData'=>$recData, 'recDate'=>$recDate, 'fbdone'=>$total_done, 'notinterest' => $total_notint, 'fbdoneper'=>$total_done_per, 'percentData'=>$percentData, 'percentDate'=>$percentDate, 'dyquesdata'=>$dy_ques_data);

	// $data = array('date'=>$crdate, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'fbdone'=>$total_done, 'fbdoneper'=>$total_done_per, 'fdqlty'=>$respond_all2, 'qltystar'=>$qlty_star, 'package'=>$respond_all3, 'packagestar'=>$package_star, 'visit'=>$respond_all4, 'visitstar'=>$visit_star);
	
	echo json_encode($data);
}


// Data and graph of last 12 months
if ($_GET['act'] == 'cy') {
	$date = date('d/m/Y');	
	$ldate = date('d/m/Y', strtotime('-11 months'));
	$codates15=explode("/",$ldate);
	$dates15 = new DateTime($codates15[2]."-".$codates15[1]."-".$codates15[0]);
	$sd9 = $dates15->format("Y-m-d");
	$mnth_yr = date('M Y', strtotime(date('Y-m-d', strtotime("-11 months"))))." - ".date('M Y', strtotime(date('Y-m-d')));

	$monthname = array();
	$crdate = array();
	$respond = array();
	$respond_all_star = array();
	$qlty_star = array();
	$package_star = array();
	$visit_star = array();

	$total_ans_wt = 0;
	$total_fb_no = 0;
	$total_sent = 0;
	$total_done = 0;

	$ques_id = '';

	for ($i=0; $i < 12; $i++) {
		$LastDayInMonth = cal_days_in_month(CAL_GREGORIAN, $dates15->format("m"), $dates15->format("Y"));
		$FromDate = $dates15->format("Y-m-01");
		$ToDate = $dates15->format("Y-m-$LastDayInMonth");
		$monthname[] = $dates15->format("F");
		
		// $qry = mysql_query("SELECT DISTINCT(MONTHNAME(`sale_date`)) as month FROM `feedback_response` WHERE (`sale_date` >= '$FromDate' AND `sale_date` <= '$ToDate') AND `client_id` = '$client_id'");
		// $row = mysql_fetch_array($qry);
		// $monthname = $row['month'];

		$frd_qry = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND fbr.`sale_date` BETWEEN '$FromDate' and '$ToDate' AND frd.`fb_ques_id` = '1'");
		$frd_row = mysql_fetch_array($frd_qry);
		$respond[] = $frd_row['avg'];

		$frd_qry2 = mysql_query("SELECT SUM(  frd.`ans_wt` ) AS ans_wt, COUNT( DISTINCT(frd.`fb_no`) ) AS fb_no FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '1' AND fbr.`sale_date` >= '$FromDate' and fbr.`sale_date` <= '$ToDate'");
		while ($frd_row2 = mysql_fetch_array($frd_qry2)) {
			$ans_wt = $frd_row2['ans_wt'];
			$fb_no = $frd_row2['fb_no'];
			
			$total_ans_wt = $total_ans_wt+ $ans_wt;
			$total_fb_no += $fb_no;
		}
		
		$ls = $dates15->modify("1 month");
	}
	
	
	if ($total_fb_no == 0) {
		$avg_all_yr = 0;
	} else {
		$avg_all_yr = ($total_ans_wt/$total_fb_no);
	}
	$respond_all = number_format($avg_all_yr, 1);
	for ($i=1; $i <= 5; $i++) { 
		
		if ($i <= $respond_all) {
			$checked = "star-checked";
			$star = "fa-star";
			
		} else if( $respond_all > $j AND $respond_all < $i ) { 
			$checked = "star-checked";
			$star = "fa-star-half-o";
		} else {
			$checked = "";
			$star = "fa-star-o";
		}	
		$j = $i;

		$respond_all_star[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';

	}	


	// dynamic for feedback question details	
	$date2 = date('Y-m-d');	
	$ldate2 = date('d/m/Y', strtotime('-11 months'));
	$codates2=explode("/",$ldate2);
	$dates2 = new DateTime($codates2[2]."-".$codates2[1]."-".$codates2[0]);
	$sd2 = $dates2->format("Y-m-d");
	$fsd = $dates2->format("Y-m-01");


	$total_sent = 0;
	$sentData = array();
	$sentDate = array();
	$sqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_sent`) as sent FROM `guest_order_history` WHERE (`SaleDate` >= '$fsd' AND `SaleDate` <= '$date2') AND `feedback_sent` = '1' GROUP BY `SaleDate`");
	while ($srow = mysql_fetch_array($sqry)) {
		$total_sent += $srow['sent'];
		$sdate = $srow['saledate'];
		$sentData[] = $srow['sent'];
		$sentDate[] = date('d-m-Y', strtotime($sdate));
	}	

	$total_done = 0;
	$recData = array();
	$recDate = array();
	$dqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_done`) as done FROM `guest_order_history` WHERE (`SaleDate` >= '$fsd' AND `SaleDate` <= '$date2') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
	while ($drow = mysql_fetch_array($dqry)) {
		$total_done += $drow['done'];
		$ddate = $drow['saledate'];
		$recData[] = $drow['done'];
		$recDate[] = date('d-m-Y', strtotime($ddate));
	}

	$nqry = mysql_query("SELECT count(`feedback_done`) as notinterst FROM `guest_order_history` WHERE (`SaleDate` >= '$fsd' AND `SaleDate` <= '$date2') AND `feedback_sent` = '1' AND `feedback_done` = '2'");
	while ($nrow = mysql_fetch_array($nqry)) {
		$total_notint = $nrow['notinterst'];
	}

	$percentData = array();
	$percentDate = array();
	$per_qry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, ((SUM(`feedback_done`) / SUM(`feedback_sent`))*100) AS percent FROM `guest_order_history` WHERE (`SaleDate` >= '$fsd' AND `SaleDate` <= '$date2') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
	while ($per_row = mysql_fetch_array($per_qry)) {
		$per_date = $per_row['saledate'];
		$percentData[] = $per_row['percent'];
		$percentDate[] = date('d-m-Y', strtotime($per_date));
	}

	if ($total_done == 0) {
		$total_done_per = 0;
	} else {
		$total_done_per = number_format(($total_done/$total_sent)*100, 2)."%";
	}


	
	$dy_ques_data = array();
	$dy_qry = mysql_query("SELECT DISTINCT(`fb_ques_id`), `fb_ques` FROM `feedback_response_details` WHERE `fb_ques_id` != 1");
	while ($dy_row = mysql_fetch_array($dy_qry)) {
		$ques_id = $dy_row['fb_ques_id'];
		$ques_name = $dy_row['fb_ques'];
		$expquesname = explode('_', $ques_name);
		$fdqlty_fbno = 0;
		$ans_wt = 0;
		$fdqlty_five_star11 = 0;
		$fdqlty_four_star11 = 0;
		$fdqlty_three_star11 = 0;
		$fdqlty_two_star11 = 0;
		$fdqlty_one_star11 = 0;
		$fdqlty_five_per11 = 0;
		$fdqlty_four_per11 = 0;
		$fdqlty_three_per11 = 0;
		$fdqlty_two_per11 = 0;
		$fdqlty_one_per11 = 0;		

		$frd_qry121 = mysql_query("SELECT COUNT( DISTINCT(frd.`fb_no`) ) AS fdqlty_fbno, `ans_wt` FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$fsd' AND fbr.`sale_date` <= '$date2') GROUP BY frd.`fb_no`");
		while ($frd_row121 = mysql_fetch_array($frd_qry121)) {
			// print_r($frd_row121);
			$fdqlty_fbno = $frd_row121['fdqlty_fbno'];
			$ans_wt = $frd_row121['ans_wt'];
			if ($ans_wt == 5) {
				$fdqlty_five_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_five_per11 = 0;
				} else {
					$fdqlty_five_per11 = ($fdqlty_five_star11/$total_done)*100;
				}
			}
			if ($ans_wt == 4) {
				$fdqlty_four_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_four_per11 = 0;
				} else {
					$fdqlty_four_per11 = ($fdqlty_four_star11/$total_done)*100;
				}
			}
			if ($ans_wt == 3) {
				$fdqlty_three_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_three_per11 = 0;
				} else {
					$fdqlty_three_per11 = ($fdqlty_three_star11/$total_done)*100;
				}
			}
			if ($ans_wt == 2) {
				$fdqlty_two_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_two_per11 = 0;
				} else {
					$fdqlty_two_per11 = ($fdqlty_two_star11/$total_done)*100;
				}
			}
			if ($ans_wt == 1) {
				$fdqlty_one_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_one_per11 = 0;
				} else {
					$fdqlty_one_per11 = ($fdqlty_one_star11/$total_done)*100;
				}
			}
		}

		$qlty_star_rate = array();
		// $total_ques_ans_wt = 0;
		// $total_ques_fb_no = 0;
		$frd_qry12 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all12 FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$fsd' AND fbr.`sale_date` <= '$date2')");
		while ($frd_row12 = mysql_fetch_array($frd_qry12)) {
			/*$ans_wt1 = $frd_row12['ans_wt1'];
			$fb_no1 = $frd_row12['fb_no1'];
			
			$total_ques_ans_wt = $total_ques_ans_wt+ $ans_wt1;
			$total_ques_fb_no += $fb_no1;

			if ($total_ques_fb_no == 0) {
				$avg_ques_all_yr = 0;
			} else {
				$avg_ques_all_yr = ($total_ques_ans_wt/$total_ques_fb_no);
			}*/
			$respond_all12 = number_format($frd_row12['avg_all12'], 1);

			for ($i=1; $i <= 5; $i++) { 
		
				if ($i <= $respond_all12) {
					$checked = "star-checked";
					$star = "fa-star";
					
				} else if( $respond_all12 > $j AND $respond_all12 < $i ) { 
					$checked = "star-checked";
					$star = "fa-star-half-o";
				} else {
					$checked = "";
					$star = "fa-star-o";
				}	
				$j = $i;

				$qlty_star_rate[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';
			}

			$dy_ques_data[] = '<div class="col-sm-6 col-lg-4"><div class="social-box facebook"><div class="box-title py-2"><div class="title">'.ucwords(implode(' ', $expquesname)).'</div><p class="dash-rating-count">'.$respond_all12.'</p><p class="star-rating fb-fdqlty-star">'.implode('',$qlty_star_rate).'</p></div><div class="custom-star-progress"><div class="row"><div class="col-xs-12 col-md-12"><div class="row fd-rating-desc"><div class="col-xs-3 col-md-3 col-lg-3">5 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_five_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_five_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">4 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_four_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_four_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">3 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_three_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_three_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">2 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_two_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_two_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">1 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_one_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_one_star11.'</span></div></div></div></div></div></div></div>';
		}
	}

	
	

	
	$data = array('date'=>$monthname, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'sentData'=>$sentData, 'sentDate'=>$sentDate, 'recData'=>$recData, 'recDate'=>$recDate, 'fbdone'=>$total_done, 'notinterest' => $total_notint, 'fbdoneper'=>$total_done_per, 'percentData'=>$percentData, 'percentDate'=>$percentDate, 'dyquesdata'=>$dy_ques_data);

	// $data = array('date'=>$monthname, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'fbdone'=>$total_done, 'fbdoneper'=>$total_done_per, 'fdqlty'=>$respond_all2, 'qltystar'=>$qlty_star, 'package'=>$respond_all3, 'packagestar'=>$package_star, 'visit'=>$respond_all4, 'visitstar'=>$visit_star);

	echo json_encode($data);
}


// Data and graph of this financial year
if ($_GET['act'] == 'fy') {
	
	$monthname = array();
	$crdate = array();
	$respond = array();
	$respond_all_star = array();
	$qlty_star = array();
	$package_star = array();
	$visit_star = array();
	$total_ans_wt = 0;
	$total_fb_no = 0;
	$total_sent = 0;
	$total_done = 0;
	

	$pst = date('m');

	if($pst>4) {
		
		$y=date('Y');
		$dtt=$y."-04-01";
		$codates15=explode("-",$dtt);
		$dates15 = new DateTime($codates15[0]."-".$codates15[1]."-".$codates15[2]);
		$sd9 = $dates15->format("Y-m-d"); //2017-04-01
		$fn_fst_mnth = date('M', strtotime($sd9));
		for ($i=0; $i < 12; $i++) {
			$LastDayInMonth = cal_days_in_month(CAL_GREGORIAN, $dates15->format("m"), $dates15->format("Y"));
			$FromDate = $dates15->format("Y-m-01");
			$ToDate = $dates15->format("Y-m-$LastDayInMonth");
			$monthname[] = $dates15->format("F");

			$frd_qry = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND fbr.`sale_date` BETWEEN '$FromDate' and '$ToDate' AND frd.`fb_ques_id` = '1'");
			$frd_row = mysql_fetch_array($frd_qry);
			$respond[] = $frd_row['avg'];

			$frd_qry2 = mysql_query("SELECT SUM(  frd.`ans_wt` ) AS ans_wt, COUNT( DISTINCT(frd.`fb_no`) ) AS fb_no FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '1' AND fbr.`sale_date` >= '$FromDate' and fbr.`sale_date` <= '$ToDate'");
			while ($frd_row2 = mysql_fetch_array($frd_qry2)) {
				$ans_wt = $frd_row2['ans_wt'];
				$fb_no = $frd_row2['fb_no'];
				
				$total_ans_wt = $total_ans_wt+ $ans_wt;
				$total_fb_no += $fb_no;
			}

			$dates15->modify("1 month");
		}
		$pt = date('Y', strtotime('+1 year'));
		$ptt=$pt."-03-31";
		$codates=explode("-",$ptt);
		$dates = new DateTime($codates[0]."-".$codates[1]."-".$codates[2]);
		$sd = $dates->format("Y-m-d"); //2017-04-01
		$fn_lst_mnth = date('M', strtotime($sd));
		$mnth_yr = $fn_fst_mnth." ".$y." - ".$fn_lst_mnth." ".$pt;

	} else {
		
		$y=date('Y', strtotime('-1 year'));
		$dtt=$y."-04-01";
		$codates15=explode("-",$dtt);
		$dates15 = new DateTime($codates15[0]."-".$codates15[1]."-".$codates15[2]);
		$sd9 = $dates15->format("Y-m-d"); //2017-04-01
		$fn_fst_mnth = date('M', strtotime($sd9));
		for ($i=0; $i < 12; $i++) {
			$LastDayInMonth = cal_days_in_month(CAL_GREGORIAN, $dates15->format("m"), $dates15->format("Y"));
			$FromDate = $dates15->format("Y-m-01");
			$ToDate = $dates15->format("Y-m-$LastDayInMonth");
			$monthname[] = $dates15->format("F");

			$frd_qry = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND fbr.`sale_date` BETWEEN '$FromDate' and '$ToDate' AND frd.`fb_ques_id` = '1'");
			$frd_row = mysql_fetch_array($frd_qry);
			$respond[] = $frd_row['avg'];

			$frd_qry2 = mysql_query("SELECT SUM(  frd.`ans_wt` ) AS ans_wt, COUNT( DISTINCT(frd.`fb_no`) ) AS fb_no FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '1' AND fbr.`sale_date` >= '$FromDate' and fbr.`sale_date` <= '$ToDate'");
			while ($frd_row2 = mysql_fetch_array($frd_qry2)) {
				$ans_wt = $frd_row2['ans_wt'];
				$fb_no = $frd_row2['fb_no'];
				
				$total_ans_wt = $total_ans_wt+ $ans_wt;
				$total_fb_no += $fb_no;
			}

			$dates15->modify("1 month");
		}
		$pt =date('Y');
		$ptt=$pt."-03-31";
		$codates=explode("-",$ptt);
		$dates = new DateTime($codates[0]."-".$codates[1]."-".$codates[2]);
		$sd = $dates->format("Y-m-d"); //2017-04-01
		$fn_lst_mnth = date('M', strtotime($sd));
		$mnth_yr = $fn_fst_mnth." ".$y." - ".$fn_lst_mnth." ".$pt;

	}

	if ($total_fb_no == 0) {
		$avg_all_yr = 0;
	} else {
		$avg_all_yr = ($total_ans_wt/$total_fb_no);
	}
	$respond_all = number_format($avg_all_yr, 1);
	for ($i=1; $i <= 5; $i++) { 
		if ($i <= $respond_all) {
			$checked = "star-checked";
			$star = "fa-star";
			
		} else if( $respond_all > $j AND $respond_all < $i ) { 
			$checked = "star-checked";
			$star = "fa-star-half-o";
		} else {
			$checked = "";
			$star = "fa-star-o";
		}	
		$j = $i;

		$respond_all_star[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';
	}


	$pst1 = date('m');
	if($pst1>4) {
		$y1=date('Y');
		$dtt1=$y1."-04-01";
		$codates3=explode("-",$dtt1);
		$dates3 = new DateTime($codates3[0]."-".$codates3[1]."-".$codates3[2]);
		$sd3 = $dates3->format("Y-m-d");
		$date3 = date('Y-m-d');


		$total_sent = 0;
		$sentData = array();
		$sentDate = array();
		$sqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_sent`) as sent FROM `guest_order_history` WHERE (`SaleDate` >= '$sd3' AND `SaleDate` <= '$date3') AND `feedback_sent` = '1' GROUP BY `SaleDate`");
		while ($srow = mysql_fetch_array($sqry)) {
			$total_sent += $srow['sent'];
			$sdate = $srow['saledate'];
			$sentData[] = $srow['sent'];
			$sentDate[] = date('d-m-Y', strtotime($sdate));
		}	

		$total_done = 0;
		$recData = array();
		$recDate = array();
		$dqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_done`) as done FROM `guest_order_history` WHERE (`SaleDate` >= '$sd3' AND `SaleDate` <= '$date3') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
		while ($drow = mysql_fetch_array($dqry)) {
			$total_done += $drow['done'];
			$ddate = $drow['saledate'];
			$recData[] = $drow['done'];
			$recDate[] = date('d-m-Y', strtotime($ddate));
		}

		$nqry = mysql_query("SELECT count(`feedback_done`) as notinterst FROM `guest_order_history` WHERE (`SaleDate` >= '$sd3' AND `SaleDate` <= '$date3') AND `feedback_sent` = '1' AND `feedback_done` = '2'");
		while ($nrow = mysql_fetch_array($nqry)) {
			$total_notint = $nrow['notinterst'];
		}

		$percentData = array();
		$percentDate = array();
		$per_qry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, ((SUM(`feedback_done`) / SUM(`feedback_sent`))*100) AS percent FROM `guest_order_history` WHERE (`SaleDate` >= '$sd3' AND `SaleDate` <= '$date3') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
		while ($per_row = mysql_fetch_array($per_qry)) {
			$per_date = $per_row['saledate'];
			$percentData[] = $per_row['percent'];
			$percentDate[] = date('d-m-Y', strtotime($per_date));
		}

		if ($total_done == 0) {
			$total_done_per = 0;
		} else {
			$total_done_per = number_format(($total_done/$total_sent)*100, 2)."%";
		}

		// dynamic for feedback question details	
		$dy_ques_data = array();
		$dy_qry = mysql_query("SELECT DISTINCT(`fb_ques_id`), `fb_ques` FROM `feedback_response_details` WHERE `fb_ques_id` != 1");
		while ($dy_row = mysql_fetch_array($dy_qry)) {
			$ques_id = $dy_row['fb_ques_id'];
			$ques_name = $dy_row['fb_ques'];
			$expquesname = explode('_', $ques_name);
			$fdqlty_fbno = 0;
			$ans_wt = 0;
			$fdqlty_five_star11 = 0;
			$fdqlty_four_star11 = 0;
			$fdqlty_three_star11 = 0;
			$fdqlty_two_star11 = 0;
			$fdqlty_one_star11 = 0;
			$fdqlty_five_per11 = 0;
			$fdqlty_four_per11 = 0;
			$fdqlty_three_per11 = 0;
			$fdqlty_two_per11 = 0;
			$fdqlty_one_per11 = 0;		

			$frd_qry121 = mysql_query("SELECT COUNT( DISTINCT(frd.`fb_no`) ) AS fdqlty_fbno, `ans_wt` FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$sd3' AND fbr.`sale_date` <= '$date3') GROUP BY frd.`fb_no`");
			while ($frd_row121 = mysql_fetch_array($frd_qry121)) {
				// print_r($frd_row121);
				$fdqlty_fbno = $frd_row121['fdqlty_fbno'];
				$ans_wt = $frd_row121['ans_wt'];
				if ($ans_wt == 5) {
					$fdqlty_five_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_five_per11 = 0;
					} else {
						$fdqlty_five_per11 = ($fdqlty_five_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 4) {
					$fdqlty_four_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_four_per11 = 0;
					} else {
						$fdqlty_four_per11 = ($fdqlty_four_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 3) {
					$fdqlty_three_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_three_per11 = 0;
					} else {
						$fdqlty_three_per11 = ($fdqlty_three_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 2) {
					$fdqlty_two_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_two_per11 = 0;
					} else {
						$fdqlty_two_per11 = ($fdqlty_two_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 1) {
					$fdqlty_one_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_one_per11 = 0;
					} else {
						$fdqlty_one_per11 = ($fdqlty_one_star11/$total_done)*100;
					}
				}
			}

			$qlty_star_rate = array();
			$frd_qry12 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all12 FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$sd3' AND fbr.`sale_date` <= '$date3')");
			while ($frd_row12 = mysql_fetch_array($frd_qry12)) {
				
				$respond_all12 = number_format($frd_row12['avg_all12'], 1);

				for ($i=1; $i <= 5; $i++) { 
			
					if ($i <= $respond_all12) {
						$checked = "star-checked";
						$star = "fa-star";
						
					} else if( $respond_all12 > $j AND $respond_all12 < $i ) { 
						$checked = "star-checked";
						$star = "fa-star-half-o";
					} else {
						$checked = "";
						$star = "fa-star-o";
					}	
					$j = $i;

					$qlty_star_rate[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';
				}

				$dy_ques_data[] = '<div class="col-sm-6 col-lg-4"><div class="social-box facebook"><div class="box-title py-2"><div class="title">'.ucwords(implode(' ', $expquesname)).'</div><p class="dash-rating-count">'.$respond_all12.'</p><p class="star-rating fb-fdqlty-star">'.implode('',$qlty_star_rate).'</p></div><div class="custom-star-progress"><div class="row"><div class="col-xs-12 col-md-12"><div class="row fd-rating-desc"><div class="col-xs-3 col-md-3 col-lg-3">5 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_five_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_five_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">4 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_four_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_four_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">3 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_three_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_three_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">2 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_two_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_two_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">1 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_one_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_one_star11.'</span></div></div></div></div></div></div></div>';
			}
		}

	} else {
		$y1=date('Y', strtotime('-1 year'));
		$dtt1=$y1."-04-01";
		$codates3=explode("-",$dtt1);
		$dates3 = new DateTime($codates3[0]."-".$codates3[1]."-".$codates3[2]);
		$sd3 = $dates3->format("Y-m-d");
		$date3 = date('Y-m-d');


		$total_sent = 0;
		$sentData = array();
		$sentDate = array();
		$sqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_sent`) as sent FROM `guest_order_history` WHERE (`SaleDate` >= '$sd3' AND `SaleDate` <= '$date3') AND `feedback_sent` = '1' GROUP BY `SaleDate`");
		while ($srow = mysql_fetch_array($sqry)) {
			$total_sent += $srow['sent'];
			$sdate = $srow['saledate'];
			$sentData[] = $srow['sent'];
			$sentDate[] = date('d-m-Y', strtotime($sdate));
		}	

		$total_done = 0;
		$recData = array();
		$recDate = array();
		$dqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_done`) as done FROM `guest_order_history` WHERE (`SaleDate` >= '$sd3' AND `SaleDate` <= '$date3') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
		while ($drow = mysql_fetch_array($dqry)) {
			$total_done += $drow['done'];
			$ddate = $drow['saledate'];
			$recData[] = $drow['done'];
			$recDate[] = date('d-m-Y', strtotime($ddate));
		}

		$nqry = mysql_query("SELECT count(`feedback_done`) as notinterst FROM `guest_order_history` WHERE (`SaleDate` >= '$sd3' AND `SaleDate` <= '$date3') AND `feedback_sent` = '1' AND `feedback_done` = '2'");
		while ($nrow = mysql_fetch_array($nqry)) {
			$total_notint = $nrow['notinterst'];
		}

		$percentData = array();
		$percentDate = array();
		$per_qry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, ((SUM(`feedback_done`) / SUM(`feedback_sent`))*100) AS percent FROM `guest_order_history` WHERE (`SaleDate` >= '$sd3' AND `SaleDate` <= '$date3') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
		while ($per_row = mysql_fetch_array($per_qry)) {
			$per_date = $per_row['saledate'];
			$percentData[] = $per_row['percent'];
			$percentDate[] = date('d-m-Y', strtotime($per_date));
		}

		if ($total_done == 0) {
			$total_done_per = 0;
		} else {
			$total_done_per = number_format(($total_done/$total_sent)*100, 2)."%";
		}

		// dynamic for feedback question details	
		$dy_ques_data = array();
		$dy_qry = mysql_query("SELECT DISTINCT(`fb_ques_id`), `fb_ques` FROM `feedback_response_details` WHERE `fb_ques_id` != 1");
		while ($dy_row = mysql_fetch_array($dy_qry)) {
			$ques_id = $dy_row['fb_ques_id'];
			$ques_name = $dy_row['fb_ques'];
			$expquesname = explode('_', $ques_name);
			$fdqlty_fbno = 0;
			$ans_wt = 0;
			$fdqlty_five_star11 = 0;
			$fdqlty_four_star11 = 0;
			$fdqlty_three_star11 = 0;
			$fdqlty_two_star11 = 0;
			$fdqlty_one_star11 = 0;
			$fdqlty_five_per11 = 0;
			$fdqlty_four_per11 = 0;
			$fdqlty_three_per11 = 0;
			$fdqlty_two_per11 = 0;
			$fdqlty_one_per11 = 0;		

			$frd_qry121 = mysql_query("SELECT COUNT( DISTINCT(frd.`fb_no`) ) AS fdqlty_fbno, `ans_wt` FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$sd3' AND fbr.`sale_date` <= '$date3') GROUP BY frd.`fb_no`");
			while ($frd_row121 = mysql_fetch_array($frd_qry121)) {
				// print_r($frd_row121);
				$fdqlty_fbno = $frd_row121['fdqlty_fbno'];
				$ans_wt = $frd_row121['ans_wt'];
				if ($ans_wt == 5) {
					$fdqlty_five_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_five_per11 = 0;
					} else {
						$fdqlty_five_per11 = ($fdqlty_five_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 4) {
					$fdqlty_four_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_four_per11 = 0;
					} else {
						$fdqlty_four_per11 = ($fdqlty_four_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 3) {
					$fdqlty_three_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_three_per11 = 0;
					} else {
						$fdqlty_three_per11 = ($fdqlty_three_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 2) {
					$fdqlty_two_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_two_per11 = 0;
					} else {
						$fdqlty_two_per11 = ($fdqlty_two_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 1) {
					$fdqlty_one_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_one_per11 = 0;
					} else {
						$fdqlty_one_per11 = ($fdqlty_one_star11/$total_done)*100;
					}
				}
			}

			$qlty_star_rate = array();
			$frd_qry12 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all12 FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$sd3' AND fbr.`sale_date` <= '$date3')");
			while ($frd_row12 = mysql_fetch_array($frd_qry12)) {
				
				$respond_all12 = number_format($frd_row12['avg_all12'], 1);

				for ($i=1; $i <= 5; $i++) { 
			
					if ($i <= $respond_all12) {
						$checked = "star-checked";
						$star = "fa-star";
						
					} else if( $respond_all12 > $j AND $respond_all12 < $i ) { 
						$checked = "star-checked";
						$star = "fa-star-half-o";
					} else {
						$checked = "";
						$star = "fa-star-o";
					}	
					$j = $i;

					$qlty_star_rate[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';
				}

				$dy_ques_data[] = '<div class="col-sm-6 col-lg-4"><div class="social-box facebook"><div class="box-title py-2"><div class="title">'.ucwords(implode(' ', $expquesname)).'</div><p class="dash-rating-count">'.$respond_all12.'</p><p class="star-rating fb-fdqlty-star">'.implode('',$qlty_star_rate).'</p></div><div class="custom-star-progress"><div class="row"><div class="col-xs-12 col-md-12"><div class="row fd-rating-desc"><div class="col-xs-3 col-md-3 col-lg-3">5 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_five_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_five_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">4 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_four_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_four_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">3 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_three_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_three_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">2 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_two_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_two_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">1 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_one_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_one_star11.'</span></div></div></div></div></div></div></div>';
			}
		}
	}

	
	$data = array('date'=>$monthname, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'sentData'=>$sentData, 'sentDate'=>$sentDate, 'recData'=>$recData, 'recDate'=>$recDate, 'fbdone'=>$total_done, 'notinterest' => $total_notint, 'fbdoneper'=>$total_done_per, 'percentData'=>$percentData, 'percentDate'=>$percentDate, 'dyquesdata'=>$dy_ques_data);

	// $data = array('date'=>$monthname, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'fbdone'=>$total_done, 'fbdoneper'=>$total_done_per, 'fdqlty'=>$respond_all2, 'qltystar'=>$qlty_star, 'package'=>$respond_all3, 'packagestar'=>$package_star, 'visit'=>$respond_all4, 'visitstar'=>$visit_star);

	echo json_encode($data);
}


// Data and graph of current month by default on main dashboard
if ($_GET['act'] == 'crmonth') {
	$date = date('Y-m-d');
	$expdate = explode('-', $date);
	$today = $expdate[2];
	$bgdate = $expdate[0]."-".$expdate[1]."-01";
	$mnth_yr = date('F')." ".$expdate[0];
	// $cr_year = $expdate[0];

	$crdate = array();
	$respond = array();
	$respond_all_star = array();
	$qlty_star = array();
	$package_star = array();
	$visit_star = array();
	
	$qry = mysql_query("SELECT DISTINCT(`sale_date`) AS saledate FROM `feedback_response` WHERE (`sale_date` >= '$bgdate' AND `sale_date` <= '$date') AND `client_id` = '$client_id'");
	while ($row = mysql_fetch_array($qry)) {
		$fbdate = $row['saledate'];

		$frd_qry = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND fbr.`sale_date` = '$fbdate' AND frd.`fb_ques_id` = '1'");
		$frd_row = mysql_fetch_array($frd_qry);
		
		$respond[] = $frd_row['avg'];
		$crdate[] = date('d M', strtotime($fbdate));
	}

	$frd_qry1 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '1' AND (fbr.`sale_date` >= '$bgdate' AND fbr.`sale_date` <= '$date')");
	$frd_row1 = mysql_fetch_array($frd_qry1);
	$respond_all = number_format($frd_row1['avg_all'], 1);
	for ($i=1; $i <= 5; $i++) { 
																
		if ($i <= $respond_all) {
			$checked = "star-checked";
			$star = "fa-star";
			
		} else if( $respond_all > $j AND $respond_all < $i ) { 
			$checked = "star-checked";
			$star = "fa-star-half-o";
		} else {
			$checked = "";
			$star = "fa-star-o";
		}	
		$j = $i;

		$respond_all_star[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';

	}

	$total_sent = 0;
	$sentData = array();
	$sentDate = array();
	$sqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_sent`) as sent FROM `guest_order_history` WHERE (`SaleDate` >= '$bgdate' AND `SaleDate` <= '$date') AND `feedback_sent` = '1' GROUP BY `SaleDate`");
	while ($srow = mysql_fetch_array($sqry)) {
		$total_sent += $srow['sent'];
		$sdate = $srow['saledate'];
		$sentData[] = $srow['sent'];
		$sentDate[] = date('d-m-Y', strtotime($sdate));
	}	

	$total_done = 0;
	$recData = array();
	$recDate = array();
	$dqry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, count(`feedback_done`) as done FROM `guest_order_history` WHERE (`SaleDate` >= '$bgdate' AND `SaleDate` <= '$date') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
	while ($drow = mysql_fetch_array($dqry)) {
		$total_done += $drow['done'];
		$ddate = $drow['saledate'];
		$recData[] = $drow['done'];
		$recDate[] = date('d-m-Y', strtotime($ddate));
	}

	// $total_notint = 0;
	$nqry = mysql_query("SELECT count(`feedback_done`) as notinterst FROM `guest_order_history` WHERE (`SaleDate` >= '$bgdate' AND `SaleDate` <= '$date') AND `feedback_sent` = '1' AND `feedback_done` = '2'");
	while ($nrow = mysql_fetch_array($nqry)) {
		$total_notint = $nrow['notinterst'];
	}

	$percentData = array();
	$percentDate = array();
	$per_qry = mysql_query("SELECT DISTINCT(`SaleDate`) AS saledate, ((SUM(`feedback_done`) / SUM(`feedback_sent`))*100) AS percent FROM `guest_order_history` WHERE (`SaleDate` >= '$bgdate' AND `SaleDate` <= '$date') AND `feedback_sent` = '1' AND `feedback_done` = '1' GROUP BY `SaleDate`");
	while ($per_row = mysql_fetch_array($per_qry)) {
		$per_date = $per_row['saledate'];
		$percentData[] = $per_row['percent'];
		$percentDate[] = date('d-m-Y', strtotime($per_date));
	}

	if ($total_sent == 0) {
		$total_done_per = 0;
	} else {
		$total_done_per = number_format(($total_done/$total_sent)*100, 2)."%";
	}


	// dynamic for feedback question details	
	$dy_ques_data = array();
	$dy_qry = mysql_query("SELECT DISTINCT(`fb_ques_id`), `fb_ques` FROM `feedback_response_details` WHERE `fb_ques_id` != 1");
	while ($dy_row = mysql_fetch_array($dy_qry)) {
		$ques_id = $dy_row['fb_ques_id'];
		$ques_name = $dy_row['fb_ques'];
		$expquesname = explode('_', $ques_name);
		$fdqlty_fbno = 0;
		$ans_wt = 0;
		$fdqlty_five_star11 = 0;
		$fdqlty_four_star11 = 0;
		$fdqlty_three_star11 = 0;
		$fdqlty_two_star11 = 0;
		$fdqlty_one_star11 = 0;
		$fdqlty_five_per11 = 0;
		$fdqlty_four_per11 = 0;
		$fdqlty_three_per11 = 0;
		$fdqlty_two_per11 = 0;
		$fdqlty_one_per11 = 0;
		// echo "SELECT COUNT( DISTINCT(frd.`fb_no`) ) AS fdqlty_fbno, `ans_wt` FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$bgdate' AND fbr.`sale_date` <= '$date') GROUP BY frd.`fb_no`";
		$frd_qry121 = mysql_query("SELECT COUNT( DISTINCT(frd.`fb_no`) ) AS fdqlty_fbno, `ans_wt` FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$bgdate' AND fbr.`sale_date` <= '$date') GROUP BY frd.`fb_no`");
			while ($frd_row121 = mysql_fetch_array($frd_qry121)) {
				//print_r($frd_row121);
				$fdqlty_fbno = $frd_row121['fdqlty_fbno'];
				$ans_wt = $frd_row121['ans_wt'];
				if ($ans_wt == 5) {
					$fdqlty_five_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_five_per11 = 0;
					} else {
						$fdqlty_five_per11 = ($fdqlty_five_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 4) {
					$fdqlty_four_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_four_per11 = 0;
					} else {
						$fdqlty_four_per11 = ($fdqlty_four_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 3) {
					$fdqlty_three_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_three_per11 = 0;
					} else {
						$fdqlty_three_per11 = ($fdqlty_three_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 2) {
					$fdqlty_two_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_two_per11 = 0;
					} else {
						$fdqlty_two_per11 = ($fdqlty_two_star11/$total_done)*100;
					}
				}
				if ($ans_wt == 1) {
					$fdqlty_one_star11 += $fdqlty_fbno;
					if ($total_done == 0) {
						$fdqlty_one_per11 = 0;
					} else {
						$fdqlty_one_per11 = ($fdqlty_one_star11/$total_done)*100;
					}
				}
			}
		$qlty_star_rate = array();
		$frd_qry12 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all12 FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$bgdate' AND fbr.`sale_date` <= '$date')");
		while ($frd_row12 = mysql_fetch_array($frd_qry12)) {
			$respond_all12 = number_format($frd_row12['avg_all12'], 1);
			for ($i=1; $i <= 5; $i++) { 
																	
				if ($i <= $respond_all12) {
					$checked = "star-checked";
					$star = "fa-star";
					
				} else if( $respond_all12 > $j AND $respond_all12 < $i ) { 
					$checked = "star-checked";
					$star = "fa-star-half-o";
				} else {
					$checked = "";
					$star = "fa-star-o";
				}	
				$j = $i;

				$qlty_star_rate[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';

			}
			
			$dy_ques_data[] = '<div class="col-sm-6 col-lg-4"><div class="social-box facebook"><div class="box-title py-2"><div class="title">'.ucwords(implode(' ', $expquesname)).'</div><p class="dash-rating-count">'.$respond_all12.'</p><p class="star-rating fb-fdqlty-star">'.implode('',$qlty_star_rate).'</p></div><div class="custom-star-progress"><div class="row"><div class="col-xs-12 col-md-12"><div class="row fd-rating-desc"><div class="col-xs-3 col-md-3 col-lg-3">5 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_five_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_five_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">4 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_four_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_four_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">3 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_three_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_three_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">2 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_two_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_two_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">1 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_one_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_one_star11.'</span></div></div></div></div></div></div></div>';
		}
	}

	$data = array('date'=>$crdate, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'sentData'=>$sentData, 'sentDate'=>$sentDate, 'recData'=>$recData, 'recDate'=>$recDate, 'fbdone'=>$total_done, 'notinterest' => $total_notint, 'fbdoneper'=>$total_done_per, 'percentData'=>$percentData, 'percentDate'=>$percentDate, 'dyquesdata'=>$dy_ques_data);
	echo json_encode($data);
}


// get outlet name on change of city
if ($_GET['act'] == 'scity') {
	$city = $_GET['city'];
	if ($city == 'all') {
		echo '<option value="all">All</option>';
	} else {
		$sql1 = mysql_query("SELECT DISTINCT(`outlet_name`), `outlet_id` FROM `feedback_response` WHERE `city_name` = '$city'");
		while ($row1 = mysql_fetch_array($sql1)) {
			echo '<option value="'.$row1['outlet_id'].'">'.$row1['outlet_name'].'</option>';
		}
	}
}

// Data and graph of custom date from feedback dashboard
if ($_GET['act'] == 'dd') {
	$city = $_GET['city'];
	$outlet = $_GET['outlet'];
	$ordtype = $_GET['ordtype'];
	$ordsrc = $_GET['ordsrc'];
	$dateran = $_GET['dateran'];
	
	$date = explode('-', $dateran);
	$fst_date = trim($date[0], " ");
	$expdate1 = explode('/', $fst_date);
	$fdate = $expdate1[2]."-".$expdate1[1]."-".$expdate1[0];
	// $ftdate = new DateTime($expdate1[2]."-".$expdate1[1]."-".$expdate1[0]);
	// $fdate = $ftdate->format("Y-m-d");
	$fst_mnth = date('d M Y',strtotime($fdate));

	$lst_date = trim($date[1], " ");
	$expdate2 = explode('/', $lst_date);
	$ldate = $expdate2[2]."-".$expdate2[1]."-".$expdate2[0];
	// $ltdate = new DateTime($expdate2[2]."-".$expdate2[1]."-".$expdate2[0]);
	// $ldate = $ltdate->format("Y-m-d");
	$last_mnth = date('d M Y',strtotime($ldate));

	$mnth_yr = $fst_mnth." - ".$last_mnth;
	//$days = date('d-m-Y',strtotime($ldate))-date('d-m-Y',strtotime($fdate));

	$crdate = array();
	$respond = array();
	$respond_all_star = array();
	$qlty_star = array();
	$package_star = array();
	$visit_star = array();
	
	// filter sql for graph and all question details
	if($city == 'all'){
		$city_sql = '';
	} else {
		$city_sql = 'AND fbr.`city_name` = \''.$city.'\'';
	}

	if($outlet == 'all'){
		$outlet_sql = '';
	} else {
		$outlet_sql = 'AND  fbr.`outlet_name` = \''.$outlet.'\'';
	}

	if($ordtype == 'all'){
		$ordtype_sql = '';
	} else {
		$ordtype_sql = 'AND fbr.`order_type` = \''.$ordtype.'\'';
	}

	if($ordsrc == 'all'){
		$ordsrc_sql = '';
	} else {
		$ordsrc_sql = 'AND fbr.`order_source_name` = \''.$ordsrc.'\'';
	}
	
	// filter sql for feedback sent and received
	if($city == 'all'){
		$city_sql1 = '';
	} else {
		$city_sql1 = 'AND goh.`City` = \''.$city.'\'';
	}

	if($outlet == 'all'){
		$outlet_sql1 = '';
	} else {
		$outlet_sql1 = 'AND  goh.`UnitId` = \''.$outlet.'\'';
	}

	if($ordtype == 'all'){
		$ordtype_sql1 = '';
	} else {
		$ordtype_sql1 = 'AND goh.`OrderType` = \''.$ordtype.'\'';
	}

	if($ordsrc == 'all'){
		$ordsrc_sql1 = '';
	} else {
		$ordsrc_sql1= 'AND goh.`SourceOfOrder` = \''.$ordsrc.'\'';
	}

	
	$qry = mysql_query("SELECT DISTINCT(`sale_date`) FROM `feedback_response` AS fbr WHERE (`sale_date` >= '$fdate' AND `sale_date` <= '$ldate') AND `client_id` = '$client_id' $city_sql $outlet_sql $ordtype_sql $ordsrc_sql");
	while ($row = mysql_fetch_array($qry)) {
		$fbdate = $row['sale_date'];

		$frd_qry = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND fbr.`sale_date` = '$fbdate' AND frd.`fb_ques_id` = '1'");
		$frd_row = mysql_fetch_array($frd_qry);
		
		$respond[] = $frd_row['avg'];
		$crdate[] = date('d-m-Y', strtotime($fbdate));
	}

	
	$frd_qry2 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '1' AND (fbr.`sale_date` >= '$fdate' AND fbr.`sale_date` <= '$ldate') $city_sql $outlet_sql $ordtype_sql $ordsrc_sql");
	$frd_row2 = mysql_fetch_array($frd_qry2);
	$respond_all = number_format($frd_row2['avg_all'], 1);
	for ($i=1; $i <= 5; $i++) { 
		
		if ($i <= $respond_all) {
			$checked = "star-checked";
			$star = "fa-star";
			
		} else if( $respond_all > $j AND $respond_all < $i ) { 
			$checked = "star-checked";
			$star = "fa-star-half-o";
		} else {
			$checked = "";
			$star = "fa-star-o";
		}	
		$j = $i;

		$respond_all_star[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';

	}


	$total_sent = 0;
	$sentData = array();
	$sentDate = array();
	$sqry11 = mysql_query("SELECT DISTINCT(goh.`SaleDate`) AS saledate, count(goh.`feedback_sent`) as sent FROM `guest_order_history` AS goh WHERE (goh.`SaleDate` >= '$fdate' AND goh.`SaleDate` <= '$ldate') $city_sql1 $outlet_sql1 $ordtype_sql1 $ordsrc_sql1 AND goh.`feedback_sent` = '1' GROUP BY goh.`SaleDate`");
	while ($srow11 = mysql_fetch_array($sqry11)) {
		$total_sent += $srow11['sent'];
		$sdate = $srow11['saledate'];
		$sentData[] = $srow11['sent'];
		$sentDate[] = date('d-m-Y', strtotime($sdate));
	}

	$total_done = 0;
	$recData = array();
	$recDate = array();
	$dqry11 = mysql_query("SELECT DISTINCT(goh.`SaleDate`) AS saledate, count(goh.`feedback_done`) as done FROM `guest_order_history` AS goh WHERE (goh.`SaleDate` >= '$fdate' AND goh.`SaleDate` <= '$ldate') $city_sql1 $outlet_sql1 $ordtype_sql1 $ordsrc_sql1 AND goh.`feedback_done` = '1' GROUP BY goh.`SaleDate`");
	while ($drow11 = mysql_fetch_array($dqry11)) {
		$total_done += $drow11['done'];
		$ddate = $drow11['saledate'];
		$recData[] = $drow11['done'];
		$recDate[] = date('d-m-Y', strtotime($ddate));
	}

	$nqry = mysql_query("SELECT count(`feedback_done`) as notinterst FROM `guest_order_history` WHERE (`SaleDate` >= '$fdate' AND `SaleDate` <= '$ldate') $city_sql1 $outlet_sql1 $ordtype_sql1 $ordsrc_sql1 AND `feedback_sent` = '1' AND `feedback_done` = '2'");
	while ($nrow = mysql_fetch_array($nqry)) {
		$total_notint = $nrow['notinterst'];
	}

	$percentData = array();
	$percentDate = array();
	$per_qry = mysql_query("SELECT DISTINCT(goh.`SaleDate`) AS saledate, ((SUM(goh.`feedback_done`) / SUM(goh.`feedback_sent`))*100) AS percent FROM `guest_order_history` AS goh WHERE (goh.`SaleDate` >= '$fdate' AND goh.`SaleDate` <= '$ldate') $city_sql1 $outlet_sql1 $ordtype_sql1 $ordsrc_sql1 AND goh.`feedback_done` = '1' GROUP BY `SaleDate`");
	while ($per_row = mysql_fetch_array($per_qry)) {
		$per_date = $per_row['saledate'];
		$percentData[] = $per_row['percent'];
		$percentDate[] = date('d-m-Y', strtotime($per_date));
	}
	
	if ($total_sent == 0) {
		$total_done_per = 0;
	} else {
		$total_done_per = number_format(($total_done/$total_sent)*100, 2)."%";
	}
	


	// dynamic for feedback question details	
	$dy_ques_data = array();
	$dy_qry = mysql_query("SELECT DISTINCT(`fb_ques_id`), `fb_ques` FROM `feedback_response_details` WHERE `fb_ques_id` != 1");
	while ($dy_row = mysql_fetch_array($dy_qry)) {
		$ques_id = $dy_row['fb_ques_id'];
		$ques_name = $dy_row['fb_ques'];
		$expquesname = explode('_', $ques_name);
		$fdqlty_fbno = 0;
		$ans_wt = 0;
		$fdqlty_five_star11 = 0;
		$fdqlty_four_star11 = 0;
		$fdqlty_three_star11 = 0;
		$fdqlty_two_star11 = 0;
		$fdqlty_one_star11 = 0;
		$fdqlty_five_per11 = 0;
		$fdqlty_four_per11 = 0;
		$fdqlty_three_per11 = 0;
		$fdqlty_two_per11 = 0;
		$fdqlty_one_per11 = 0;
		$frd_qry121 = mysql_query("SELECT COUNT( DISTINCT(frd.`fb_no`) ) AS fdqlty_fbno, `ans_wt` FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$fdate' AND fbr.`sale_date` <= '$ldate') $city_sql $outlet_sql $ordtype_sql $ordsrc_sql GROUP BY frd.`fb_no`");
		while ($frd_row121 = mysql_fetch_array($frd_qry121)) {

			$fdqlty_fbno = $frd_row121['fdqlty_fbno'];
			$ans_wt = $frd_row121['ans_wt'];
			if ($ans_wt == 5) {
				$fdqlty_five_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_five_per11 = 0;
				} else {
					$fdqlty_five_per11 = ($fdqlty_five_star11/$total_done)*100;
				}
			}
			if ($ans_wt == 4) {
				$fdqlty_four_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_four_per11 = 0;
				} else {
					$fdqlty_four_per11 = ($fdqlty_four_star11/$total_done)*100;
				}
			}
			if ($ans_wt == 3) {
				$fdqlty_three_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_three_per11 = 0;
				} else {
					$fdqlty_three_per11 = ($fdqlty_three_star11/$total_done)*100;
				}
			}
			if ($ans_wt == 2) {
				$fdqlty_two_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_two_per11 = 0;
				} else {
					$fdqlty_two_per11 = ($fdqlty_two_star11/$total_done)*100;
				}
			}
			if ($ans_wt == 1) {
				$fdqlty_one_star11 += $fdqlty_fbno;
				if ($total_done == 0) {
					$fdqlty_one_per11 = 0;
				} else {
					$fdqlty_one_per11 = ($fdqlty_one_star11/$total_done)*100;
				}
			}
		}
		$qlty_star_rate = array();
		$frd_qry12 = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg_all12 FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND frd.`fb_ques_id` = '$ques_id' AND (fbr.`sale_date` >= '$fdate' AND fbr.`sale_date` <= '$ldate') $city_sql $outlet_sql $ordtype_sql $ordsrc_sql");
		while ($frd_row12 = mysql_fetch_array($frd_qry12)) {
			$respond_all12 = number_format($frd_row12['avg_all12'], 1);
			for ($i=1; $i <= 5; $i++) { 
																	
				if ($i <= $respond_all12) {
					$checked = "star-checked";
					$star = "fa-star";
					
				} else if( $respond_all12 > $j AND $respond_all12 < $i ) { 
					$checked = "star-checked";
					$star = "fa-star-half-o";
				} else {
					$checked = "";
					$star = "fa-star-o";
				}	
				$j = $i;

				$qlty_star_rate[] = '<i class="fa  '.$star." ".$checked.'" aria-hidden="true"></i>';

			}
			
			$dy_ques_data[] = '<div class="col-sm-6 col-lg-4"><div class="social-box facebook"><div class="box-title py-2"><div class="title">'.ucwords(implode(' ', $expquesname)).'</div><p class="dash-rating-count">'.$respond_all12.'</p><p class="star-rating fb-fdqlty-star">'.implode('',$qlty_star_rate).'</p></div><div class="custom-star-progress"><div class="row"><div class="col-xs-12 col-md-12"><div class="row fd-rating-desc"><div class="col-xs-3 col-md-3 col-lg-3">5 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_five_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_five_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">4 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_four_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_four_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">3 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_three_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_three_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">2 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_two_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_two_star11.'</span></div><div class="col-xs-3 col-md-3 col-lg-3">1 <span class="fa fa-star star-checked"></span></div><div class="col-xs-6 col-md-6 col-lg-6"><div class="progress progress-sm mt-2 progress-custom"><div class="progress-bar bg-success" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: '.$fdqlty_one_per11.'%"></div></div></div><div class="col-xs-2 col-md-2 col-lg-2"><span class="sr-only">'.$fdqlty_one_star11.'</span></div></div></div></div></div></div></div>';
		}
	}

	$data = array('date'=>$crdate, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'sentData'=>$sentData, 'sentDate'=>$sentDate, 'recData'=>$recData, 'recDate'=>$recDate, 'fbdone'=>$total_done, 'notinterest' => $total_notint, 'fbdoneper'=>$total_done_per, 'percentData'=>$percentData, 'percentDate'=>$percentDate, 'dyquesdata'=>$dy_ques_data);

	// $data = array('date'=>$crdate, 'fbvalue'=>$respond, 'mtyr'=>$mnth_yr, 'overall'=>$respond_all, 'overallstar'=>$respond_all_star, 'fbsent'=>$total_sent, 'fbdone'=>$total_done, 'fbdoneper'=>$total_done_per, 'fdqlty'=>$respond_all2, 'qltystar'=>$qlty_star, 'package'=>$respond_all3, 'packagestar'=>$package_star, 'visit'=>$respond_all4, 'visitstar'=>$visit_star);

	// $data = array('date'=>$crdate, 'fbvalue'=>$respond);
	echo json_encode($data);
}


// Individual customer datails for feedback log
if ($_GET['act'] == 'details') {
	$outletid = $_GET['outletid'];
	$invoiceid = $_GET['invoiceid'];
	$fbno = $_GET['fbno'];
	
	$feedback_details = '';
	$fbdt = array();
	// echo "SELECT * FROM `feedback_response` WHERE `outlet_id` = '$outletid' AND `invoice_id` = '$invoiceid'";
	$qry = mysql_query("SELECT * FROM `feedback_response` WHERE `outlet_id` = '$outletid' AND `invoice_id` = '$invoiceid'");
	while ($row = mysql_fetch_array($qry)) {
		$invid = $row['invoice_id'];
		$st_qry = mysql_query("SELECT `SaleTime` FROM `guest_order_history` WHERE `InvoiceId` = '$invid'");
		$st_row = mysql_fetch_array($st_qry);
		$feedback_details = '<p class="customer-name text-logs" style="font-weight: 800;">'.$row['guest_name'].'</p><div class="row"><div class="col-lg-6 col-md-6 fb-detail-left"><p class="detail-left text-logs">'.$row['guest_email'].'</p><p class="detail-left text-logs">'.$row['guest_mob_no'].'</p><p class="detail-left text-logs">Sale Date <span class="text-bold">'.date('d-m-Y', strtotime($row['sale_date'])).' '.$st_row['SaleTime'].'</span></p><p class="text-logs">Response On <span class="text-bold">'.date('d-m-Y H:i:s', strtotime($row['response_date_time'])).'</span></p></div><div class="col-lg-6 col-md-6 fb-detail-right text-right"><p class="detail-right text-logs">Invoice No. - <span class="text-bold">'.$row['invoice_no'].'</span></p><p class="detail-right text-logs">Order Source - <span class="text-bold">'.$row['order_source_name'].'</span></p><p class="detail-right text-logs">Outlet Name - <span class="text-bold">'.$row['outlet_name'].'</span></p></div></div><div class="row">';
		$fb_qry = mysql_query("SELECT `fb_ques`, `ans_wt` FROM `feedback_response_details` WHERE `fb_no` = '$fbno'");
		while ($fb_row = mysql_fetch_array($fb_qry)) {
			$ans_wt = $fb_row['ans_wt'];
			$fb_ques = $fb_row['fb_ques'];
			$expques = explode('_', $fb_ques);
			$count_word = count($expques);
			$feedback_details .= '<div class="col-lg-6"><p class="dash-rating-count">'.$fb_row['ans_wt'].'</p><p class="star-rating">';
			for ($i=1; $i <= $ans_wt; $i++) { 
				$feedback_details .= '<span class="fa fa-star star-checked"></span>';
			}
			
			$feedback_details .= '</p><p class="dash-header">';
				$q = 0;
				if ($q <= $count_word) {
					$feedback_details .= ucwords(implode(" ", $expques));
					$q++;
				}
				
			$fb_row['fb_ques'];
			$feedback_details .= '</p></div>';
		}
		$feedback_details .= '</div>';
		
		if ($row['fb_comments'] == '') {
			$feedback_details .= "";
		} else {
			$feedback_details .= '<p style="font-weight: 300; color: #999;">Comments</p><p class="text-logs"><span class="help-block">'.$row['fb_comments'].'</span></p>';
		}
	}
	$fbdt[] = $feedback_details;

	// details of order info
	$order_info_detail = '';
	$orderinfo = array();
	$qry1 = mysql_query("SELECT * FROM `feedback_response` WHERE `outlet_id` = '$outletid' AND `invoice_id` = '$invoiceid'");
	while ($row1 = mysql_fetch_array($qry1)) {
		$invid1 = $row1['invoice_id'];
		$st_qry1 = mysql_query("SELECT `SaleTime` FROM `guest_order_history` WHERE `InvoiceId` = '$invid1'");
		$st_row1 = mysql_fetch_array($st_qry1);
		$order_info_detail = '<p class="customer-name text-logs" style="font-weight: 800;">'.$row1['guest_name'].'</p><div class="row"><div class="col-lg-6 col-md-6 fb-detail-left"><p class="detail-left text-logs">'.$row1['guest_email'].'</p><p class="detail-left text-logs">'.$row1['guest_mob_no'].'</p><p class="detail-left text-logs">Sale Date <span class="text-bold">'.date('d-m-Y', strtotime($row1['sale_date'])).' '.$st_row['SaleTime'].'</span></p><p class="text-logs">Response On <span class="text-bold">'.date('d-m-Y H:i:s', strtotime($row1['response_date_time'])).'</span></p></div><div class="col-lg-6 col-md-6 fb-detail-right text-right"><p class="detail-right text-logs">Invoice No. - <span class="text-bold">'.$row1['invoice_no'].'</span></p><p class="detail-right text-logs">Order Source - <span class="text-bold">'.$row1['order_source_name'].'</span></p><p class="detail-right text-logs">Outlet Name - <span class="text-bold">'.$row1['outlet_name'].'</span></p></div></div>';
		
		$order_info_detail .= '<table class="table table-striped table-sm table-fb-order"><thead class="thead-default"><tr><th>Item</th><th>Qty</th><th>Price</th></tr></thead><tbody>';
		$odr_qry = mysql_query("SELECT * FROM `sale_item_record` WHERE `UnitId` = '$outletid' AND `InvoiceId` = '$invoiceid'");
		while ($odr_row = mysql_fetch_array($odr_qry)) {
			$order_info_detail .= '<tr><td>'.$odr_row['ItemName'].'</td><td>'.$odr_row['Quantity'].'</td><td>'.$odr_row['Price'].'</td></tr>';
		}
		$order_info_detail .= '</tbody></table>';
		$sale_qry = mysql_query("SELECT * FROM `sale_record` WHERE `UnitId` = '$outletid' AND `InvoiceId` = '$invoiceid'");
		$sale_row = mysql_fetch_array($sale_qry);
		$order_info_detail .= '<div class="row"><div class="col-lg-12 text-right"><p>Discount: <span class="text-bold">'.$sale_row['DiscAmt'].'</span></p><p>Total Bill Amount: <span class="text-bold">'.$sale_row['TotalAmt'].'</span></p></div></div>';
	}
	$orderinfo[] = $order_info_detail;

	$data = array('feedbackDetail' => $fbdt, 'orderInfo' => $orderinfo);
	echo json_encode($data);
}


// filter data on submit button for feedback log
if ($_GET['act'] == 'fld') {
	$city = $_GET['city'];
	$outlet = $_GET['outlet'];
	$ordtype = $_GET['type'];
	$dateran = $_GET['logdate'];
	$operator = $_GET['operator'];
	$starnum = $_GET['starnum'];

	$date = explode('-', $dateran);
	// print_r($date);
	$fst_date = trim($date[0], " ");
	$expdate1 = explode('/', $fst_date);
	$fdate = $expdate1[2]."-".$expdate1[1]."-".$expdate1[0];

	$lst_date = trim($date[1], " ");
	$expdate2 = explode('/', $lst_date);
	$ldate = $expdate2[2]."-".$expdate2[1]."-".$expdate2[0];

	if($city == 'all'){
		$city_sql = '';
	} else {
		$city_sql = 'AND fbr.`city_name` = \''.$city.'\'';
	}

	if($outlet == 'all'){
		$outlet_sql = '';
	} else {
		$outlet_sql = 'AND  fbr.`outlet_name` = \''.$outlet.'\'';
	}

	if($ordtype == 'all'){
		$ordtype_sql = '';
	} else {
		$ordtype_sql = 'AND fbr.`order_type` = \''.$ordtype.'\'';
	}
	
	$customer_details = '';
	$custdt = array();

	/*$limit = 3;
	
	$qry_pgn = mysql_query("SELECT count(*) AS pgnNum FROM `feedback_response` AS fbr WHERE (fbr.`sale_date` >= '$fdate' AND fbr.`sale_date` <= '$ldate') AND fbr.`client_id` = '$client_id' $city_sql $outlet_sql $ordtype_sql");
	$row_pgn = mysql_fetch_assoc($qry_pgn);
	$rowCount = $row_pgn['pgnNum'];

	// $filterData = array('baseURL'=>'pageData.php', 'city'=>$city_sql, 'outlet'=>$outlet_sql, 'ordertype'=>$ordtype_sql, 'firstDate'=>$fdate, 'lastDate'=>$ldate, 'operator'=>$operator, 'starNumber'=>$starnum);

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

	$qry1 = mysql_query("SELECT (SUM(frd.`ans_wt`) / count(frd.`fb_no`)) AS rate, fbr.`guest_name`, fbr.`invoice_no`, fbr.`order_source_name`, fbr.`outlet_name`, fbr.`response_date_time`, fbr.`fb_comments`, fbr.`fb_no`, fbr.`outlet_id`, fbr.`invoice_id`, fbr.`response_by`, fbr.`agent_name` FROM `feedback_response_details` AS frd INNER JOIN `feedback_response` AS fbr ON frd.`fb_no` = fbr.`fb_no` WHERE (fbr.`sale_date` >= '$fdate' AND fbr.`sale_date` <= '$ldate') AND fbr.`client_id` = '$client_id' $city_sql $outlet_sql $ordtype_sql group by frd.`fb_no` HAVING rate $operator '$starnum' ORDER BY fbr.`response_date_time` DESC");
	if (mysql_num_rows($qry1) > 0) {
		while ($row1 = mysql_fetch_array($qry1)) {
			$date_time = $row1['response_date_time'];
			$fbno = $row1['fb_no'];
			// echo "SELECT (SUM(`ans_wt`) / count(`fb_no`)) AS rate FROM `feedback_response_details` WHERE `fb_no` = '$fbno' AND (SELECT (SUM(`ans_wt`) / count(`fb_no`)) $operator '$starnum' FROM `feedback_response_details`)";
			// $rate_qry = mysql_query("SELECT (SUM(`ans_wt`) / count(`fb_no`)) AS rate FROM `feedback_response_details` WHERE `fb_no` = '$fbno' AND (SUM(`ans_wt`) / count(`fb_no`)) $operator '$starnum' ");
			// $rate_qry = mysql_query("SELECT (SUM(`ans_wt`) / count(`fb_no`)) AS rate FROM `feedback_response_details` WHERE `fb_no` = '$fbno' AND (SELECT (SUM(`ans_wt`) / count(`fb_no`)) $operator '$starnum' FROM `feedback_response_details`)");
			// $rate_row = mysql_fetch_array($rate_qry);
			$avg_rate = number_format($row1['rate'], 1);
			
			if($row1['agent_name']==NULL OR $row1['agent_name']=='NULL'){ $name = 'Guest'; } else { $name =$row1['agent_name']; }

				$customer_details = '<div class="view-customer">';
					$customer_details .= '<div class="shadow"></div>';
					$customer_details .= '<div class="row">';
						$customer_details .= '<div class="col-lg-6">';
							$customer_details .= '<p class="customer-name text-logs" style="font-weight: 800;">'.$row1['guest_name'].'</p>';
							$customer_details .= '<p class="text-logs">Response By <span class="text-bold">'. $name .'</span></p>';
							$customer_details .= '<p class="text-logs">Response On <span class="text-bold">'.date('d-m-Y H:i:s', strtotime($row1['response_date_time'])).'</span></p>';
							$customer_details .= '<p class="text-logs">';
								for ($i=1; $i <= 5; $i++) { 
									
									if ($i <= $avg_rate) {
										$checked = "star-checked";
										$star = "fa-star";
									} else if( $avg_rate > $j AND $avg_rate < $i ) { 
										$checked = "star-checked";
										$star = "fa-star-half-o";
									} else {
										$checked = "";
										$star = "fa-star-o";
									}	
									$j = $i;

									$customer_details .= '<i class="fa '.$star." ".$checked.'" aria-hidden="true"></i>';

								}
								$customer_details .= '<span class="text-bold">Rated '.number_format($row1['rate'], 1).'</span>';
							$customer_details .= '</p>';	
						$customer_details .= '</div>';
						$customer_details .= '<div class="col-lg-6 text-right">';
							$customer_details .= '<p class="customer-name text-logs" style="font-weight: 500;">&nbsp;</p>';
							$customer_details .= '<p class="customer-name text-logs" style="font-weight: 500;">Invoice No. -'.$row1['invoice_no'].'</p>';
							$customer_details .= '<p class="customer-name text-logs" style="font-weight: 500;">Order Source - '.$row1['order_source_name'].'</p>';
							$customer_details .= '<p class="customer-name text-logs" style="font-weight: 500;">Outlet -'.$row1['outlet_name'].'</p>';
						$customer_details .= '</div>';
					$customer_details .= '</div>';

					$customer_details .= '<div class="row">';
						$customer_details .= '<div class="col-lg-8">';
						$customer_details .= '<p class="text-logs"><span class="help-block text-bold">'.$row1['fb_comments'].'</span></p>';
						$customer_details .= '</div>';
						$customer_details .= '<div class="col-lg-4">';
							//echo '<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails("details", '.$row1['fb_no'].', '.$row1['outlet_id'].', '.$row1['invoice_id'].' )">View Details</button>';
						
						$customer_details .= "<button type=\"button\" name=\"submit-btn\" class=\"btn btn-outline-primary view-details float-right\" onclick=\"customerViewDetails('details', '".$row1['fb_no']."', '".$row1['outlet_id']."', '".$row1['invoice_id']."')\">View Details</button>";
						
						$customer_details .= '</div>';
					$customer_details .= '</div>';
				
				$customer_details .= '</div>';
				$custdt[] = $customer_details;
			
		}
		
		//echo $pagination->createLinks();
	}
	

	// $exl_link = '';
	// $exl_arr = array();
	$exl_link = '<a href="exl_logs_customer.php?city='.$city.'&outlet='.$outlet.'&ordertype='.$ordtype.'&fdate='.$fdate.'&ldate='.$ldate.'&operator='.$operator.'&starnum='.$starnum.'">Download Excel</a>';
	// $exl_arr[] = $exl_link;

	$data = array('customerDetails' => $custdt, 'exlLink' => $exl_link);
	echo json_encode($data);
}




if ($_GET['act'] == 'custName') {
	$cname = $_GET['name'];
	
	/*$limit = 3;
	$qry_pgn = mysql_query("SELECT count(*) AS pgnNum FROM `feedback_response`");
	$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);*/

	if ($cname == '') {
		$cnqry = mysql_query("SELECT * FROM `feedback_response` ORDER BY `response_date_time` DESC");
		while ($cnrow = mysql_fetch_array($cnqry)) {

			$date_time = $cnrow['response_date_time'];
			$fbno = $cnrow['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);
			echo '<div class="view-customer">';
				echo '<div class="shadow"></div>';
				echo '<div class="row">';
					echo '<div class="col-lg-6">';
						echo '<p class="customer-name text-logs" style="font-weight: 800;">'.$cnrow['guest_name'].'</p>';
					echo '</div>';
					echo '<div class="col-lg-6 text-right">';
						echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['invoice_no'].'</p>';
						echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['order_source_name'].'</p>';
						echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['outlet_name'].'</p>';
					echo '</div>';
				echo '</div>';
				echo '<div class="row">';
					echo '<div class="col-lg-8">';
						echo '<p class="text-logs">Response On <span class="text-bold">'.date('d-m-Y H:i:s', strtotime($cnrow['response_date_time'])).'</span></p>';
						echo '<p class="text-logs">';
							for ($i=1; $i <= 5; $i++) { 
								
								if ($i <= $avg_rate) {
									$checked = "star-checked";
									$star = "fa-star";
								} else if( $avg_rate > $j AND $avg_rate < $i ) { 
									$checked = "star-checked";
									$star = "fa-star-half-o";
								} else {
									$checked = "";
									$star = "fa-star-o";
								}	
								$j = $i;

								echo '<i class="fa '.$star." ".$checked.'" aria-hidden="true"></i>';

							}
							echo '<span class="text-bold">Rated '.number_format($rate_row['rate'], 1).'</span>';
						echo '</p>';
						echo '<p class="text-logs"><span class="help-block text-bold">'.$cnrow['fb_comments'].'</span></p>';
					echo '</div>';
					echo '<div class="col-lg-4">';
						//echo '<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails("details", '.$row1['fb_no'].', '.$row1['outlet_id'].', '.$row1['invoice_id'].' )">View Details</button>';
					?>
					<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails('details', <?php echo $cnrow['fb_no']; ?>, <?php echo $cnrow['outlet_id']; ?>, <?php echo $cnrow['invoice_id']; ?> )">View Details</button>
					<?php
					echo '</div>';
				echo '</div>';
			echo '</div>';
		}
		// echo $pagination->createLinks();
	} else {

		$cnqry = mysql_query("SELECT * FROM `feedback_response` WHERE `guest_name` LIKE '%$cname%' OR `guest_email` LIKE '%$cname%' ORDER BY `response_date_time` DESC");
		while ($cnrow = mysql_fetch_array($cnqry)) {
				
			$date_time = $cnrow['response_date_time'];
			$fbno = $cnrow['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);
			echo '<div class="view-customer">';
				echo '<div class="shadow"></div>';
				echo '<div class="row">';
					echo '<div class="col-lg-6">';
						echo '<p class="customer-name text-logs" style="font-weight: 800;">'.$cnrow['guest_name'].'</p>';
					echo '</div>';
					echo '<div class="col-lg-6 text-right">';
						echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['invoice_no'].'</p>';
						echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['order_source_name'].'</p>';
						echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['outlet_name'].'</p>';
					echo '</div>';
				echo '</div>';
				echo '<div class="row">';
					echo '<div class="col-lg-8">';
						echo '<p class="text-logs">Response On <span class="text-bold">'.date('d-m-Y H:i:s', strtotime($cnrow['response_date_time'])).'</span></p>';
						echo '<p class="text-logs">';
							for ($i=1; $i <= 5; $i++) { 
								
								if ($i <= $avg_rate) {
									$checked = "star-checked";
									$star = "fa-star";
								} else if( $avg_rate > $j AND $avg_rate < $i ) { 
									$checked = "star-checked";
									$star = "fa-star-half-o";
								} else {
									$checked = "";
									$star = "fa-star-o";
								}	
								$j = $i;

								echo '<i class="fa '.$star." ".$checked.'" aria-hidden="true"></i>';

							}
							echo '<span class="text-bold">Rated '.number_format($rate_row['rate'], 1).'</span>';
						echo '</p>';
						echo '<p class="text-logs"><span class="help-block text-bold">'.$cnrow['fb_comments'].'</span></p>';
					echo '</div>';
					echo '<div class="col-lg-4">';
						//echo '<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails("details", '.$row1['fb_no'].', '.$row1['outlet_id'].', '.$row1['invoice_id'].' )">View Details</button>';
					?>
					<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails('details', <?php echo $cnrow['fb_no']; ?>, <?php echo $cnrow['outlet_id']; ?>, <?php echo $cnrow['invoice_id']; ?> )">View Details</button>
					<?php
					echo '</div>';
				echo '</div>';
			echo '</div>';
		}
		// echo $pagination->createLinks();
	}


	/*if ($cname == 'username') {
		$cnqry = mysql_query("SELECT * FROM `feedback_response` ORDER BY `response_date_time` DESC");
		while ($cnrow = mysql_fetch_array($cnqry)) {
			
		

		$date_time = $cnrow['response_date_time'];
		$fbno = $cnrow['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);
		echo '<div class="view-customer">';
			echo '<div class="shadow"></div>';
			echo '<div class="row">';
				echo '<div class="col-lg-6">';
					echo '<p class="customer-name text-logs" style="font-weight: 800;">'.$cnrow['guest_name'].'</p>';
				echo '</div>';
				echo '<div class="col-lg-6 text-right">';
					echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['invoice_no'].'</p>';
					echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['order_source_name'].'</p>';
					echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['outlet_name'].'</p>';
				echo '</div>';
			echo '</div>';
			echo '<div class="row">';
				echo '<div class="col-lg-8">';
					echo '<p class="text-logs">Response On <span class="text-bold">'.date('d-m-Y H:i:s', strtotime($cnrow['response_date_time'])).'</span></p>';
					echo '<p class="text-logs">';
						for ($i=1; $i <= 5; $i++) { 
							
							if ($i <= $avg_rate) {
								$checked = "star-checked";
								$star = "fa-star";
							} else if( $avg_rate > $j AND $avg_rate < $i ) { 
								$checked = "star-checked";
								$star = "fa-star-half-o";
							} else {
								$checked = "";
								$star = "fa-star-o";
							}	
							$j = $i;

							echo '<i class="fa '.$star." ".$checked.'" aria-hidden="true"></i>';

						}
						echo '<span class="text-bold">Rated '.number_format($rate_row['rate'], 1).'</span>';
					echo '</p>';
					echo '<p class="text-logs"><span class="help-block text-bold">'.$cnrow['fb_comments'].'</span></p>';
				echo '</div>';
				echo '<div class="col-lg-4">';
					//echo '<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails("details", '.$row1['fb_no'].', '.$row1['outlet_id'].', '.$row1['invoice_id'].' )">View Details</button>';
				?>
				<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails('details', <?php echo $cnrow['fb_no']; ?>, <?php echo $cnrow['outlet_id']; ?>, <?php echo $cnrow['invoice_id']; ?> )">View Details</button>
				<?php
				echo '</div>';
			echo '</div>';
		echo '</div>';
		}
	} else {
		$cnqry = mysql_query("SELECT * FROM `feedback_response` WHERE `guest_name` = '$cname' ORDER BY `response_date_time` DESC");
		$cnrow = mysql_fetch_array($cnqry);

		$date_time = $cnrow['response_date_time'];
		$fbno = $cnrow['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);
		echo '<div class="view-customer">';
			echo '<div class="shadow"></div>';
			echo '<div class="row">';
				echo '<div class="col-lg-6">';
					echo '<p class="customer-name text-logs" style="font-weight: 800;">'.$cnrow['guest_name'].'</p>';
				echo '</div>';
				echo '<div class="col-lg-6 text-right">';
					echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['invoice_no'].'</p>';
					echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['order_source_name'].'</p>';
					echo '<p class="customer-name text-logs" style="font-weight: 500;">'.$cnrow['outlet_name'].'</p>';
				echo '</div>';
			echo '</div>';
			echo '<div class="row">';
				echo '<div class="col-lg-8">';
					echo '<p class="text-logs">Response On <span class="text-bold">'.date('d-m-Y H:i:s', strtotime($cnrow['response_date_time'])).'</span></p>';
					echo '<p class="text-logs">';
						for ($i=1; $i <= 5; $i++) { 
							
							if ($i <= $avg_rate) {
								$checked = "star-checked";
								$star = "fa-star";
							} else if( $avg_rate > $j AND $avg_rate < $i ) { 
								$checked = "star-checked";
								$star = "fa-star-half-o";
							} else {
								$checked = "";
								$star = "fa-star-o";
							}	
							$j = $i;

							echo '<i class="fa '.$star." ".$checked.'" aria-hidden="true"></i>';

						}
						echo '<span class="text-bold">Rated '.number_format($rate_row['rate'], 1).'</span>';
					echo '</p>';
					echo '<p class="text-logs"><span class="help-block text-bold">'.$cnrow['fb_comments'].'</span></p>';
				echo '</div>';
				echo '<div class="col-lg-4">';
					//echo '<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails("details", '.$row1['fb_no'].', '.$row1['outlet_id'].', '.$row1['invoice_id'].' )">View Details</button>';
				?>
				<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerViewDetails('details', <?php echo $cnrow['fb_no']; ?>, <?php echo $cnrow['outlet_id']; ?>, <?php echo $cnrow['invoice_id']; ?> )">View Details</button>
				<?php
				echo '</div>';
			echo '</div>';
		echo '</div>';
	}*/
}


/* NO USE - CHECK UPDATED*/
if ($_GET['act'] == 'takefb') {
	$outletid = $_GET['outletid'];
	$invoiceid = $_GET['invoiceid'];

	$feedback_details = '';
	$fbdt = array();
	
	// echo "SELECT * FROM `guest_order_history` WHERE `feedback_done` = 0 AND (OrderStatus != 'Rejected' AND OrderStatus != 'Cancelled') AND `UnitId` = '$outletid' AND `InvoiceId` = '$invoiceid'";
	$qry = mysql_query("SELECT * FROM `guest_order_history` WHERE `feedback_done` = 0 AND (OrderStatus != 'Rejected' AND OrderStatus != 'Cancelled') AND `UnitId` = '$outletid' AND `InvoiceId` = '$invoiceid'");
	while ($row = mysql_fetch_array($qry)) {
		$ord_src = $row['SourceOfOrder'];
		$UnitId = $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'];

		$feedback_details = '<script src="../plug/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script><p class="customer-name text-logs" style="font-weight: 800;">'.$row['FirstName'].' '.$row['LastName'].'</p><div class="row"><div class="col-lg-6 col-md-6 fb-detail-left"><p class="detail-left text-logs">'.$row['GuestPhone'].'</p><p class="detail-left text-logs">Sale Date <span class="text-bold">'.date('d-m-Y', strtotime($row['SaleDate'])).' '.$row['SaleTime'].'</span></p></div><div class="col-lg-6 col-md-6 fb-detail-right text-right"><p class="detail-right text-logs">Invoice No. - <span class="text-bold">'.$row['InvoiceNumber'].'</span></p><p class="detail-right text-logs">Order Source - <span class="text-bold">'.$row['SourceOfOrder'].'</span></p><p class="detail-right text-logs">Outlet Name - <span class="text-bold">'.$unit_name.'</span></p></div></div><div class="row"><div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"><form id="frm_callback" name="frm" action="save_fb_settings_data.php"><input type="hidden" name="outletid" id="cboutletid" value="'.$outletid.'"><input type="hidden" name="invoiceid" id="cbinvoiceid" value="'.$invoiceid.'"> ';
		$i = 1;
	
		//		$que_qry = mysql_query("SELECT * FROM `feedback_ques` WHERE `fb_ques_enable` = 1 AND `client_id` = '$client_id' AND `outlet_id` = '$UnitId'");
		$que_qry = mysql_query("SELECT * FROM `feedback_ques` WHERE `fb_ques_enable` = 1 AND `client_id` = '$client_id' AND `outlet_id` = '$outlet_id'");
		while($que_row = mysql_fetch_array($que_qry)) {
			$ques_for = $que_row['fb_ques_for'];
			$fb_ques_id = $que_row['fb_ques_id'];
			$fb_ques = $que_row['fb_ques'];
			if($ord_src == 'Outlet') {
				if ($ques_for == 'Both' || $ques_for == 'Dine-In') {
					$feedback_details .= '<div class="form-group"><div class="row form-label"><div class="col-lg-6 col-md-4 col-sm-4 col-xs-12">';
					$feedback_details .= '<label id="fb_topic_name<?php if($fb_ques_id != 1 && $fb_ques_id != 2) { echo $fb_ques_id; }?>" style="font-weight: 800;">'.ucwords($fb_ques).'</label>';
					$feedback_details .= '</div></div><div class="row"><div class="cc-selector callback col-lg-12 col-md-12 col-sm-12 col-xs-12">';
					
					// echo "SELECT * FROM `feedback_ques_details` WHERE `outlet_id` = '$outletid'";
		//					$fb_qry = mysql_query("SELECT * FROM `feedback_ques_details` WHERE `outlet_id` = '$UnitId'");
					$fb_qry = mysql_query("SELECT * FROM `feedback_ques_details` WHERE `outlet_id` = 1");
					while($fb_row = mysql_fetch_array($fb_qry)) {
						
						$fbinputid = strtolower(str_replace(' ', '_', $que_row['fb_ques']).'_'.str_replace(' ', '_', $fb_row['fb_option_text']));
						$ques_value = strtolower(str_replace(' ', '_', $que_row['fb_ques'])).'#'.$que_row['fb_ques_id'].'-'.$fb_row['fb_option_wt'].'-'.str_replace(' ', '_', $fb_row['fb_option_text']);
						// $fbinputname = strtolower(str_replace(' ', '_', $que_row['fb_ques']));
						// $fb_option_text = $fb_row['fb_option_text'];
						$fb_option_image = $fb_row['fb_option_image'];
						$fboptiontext = ucfirst($fb_row['fb_option_text']);
						
						$feedback_details .= '<div class="selector col-lg-2 col-md-2 col-sm-2 col-xs-2"><input id="'.$fbinputid.'" type="radio" name="call_'.$i.'" value="'.$ques_value.'" /><label class="drinkcard-cc" for="'.$fbinputid.'"><img src="../img/emoji-img/'.$fb_option_image.'"></label><p class="text">'.$fboptiontext.'</p></div>';
						
					}
					$feedback_details .= '<input type="hidden" name="no_ques" value="'.$i.'">';
					$feedback_details .= '</div></div></div>';
				}
			} elseif ($ord_src != 'Outlet') {
				if ($ques_for == 'Both' || $ques_for == 'Delivery') {
					$feedback_details .= '<div class="form-group"><div class="row form-label"><div class="col-lg-6 col-md-4 col-sm-4 col-xs-12">';
					$feedback_details .= '<label id="fb_topic_name<?php if($fb_ques_id != 1 && $fb_ques_id != 2) { echo $fb_ques_id; }?>">'.ucwords($fb_ques).'</label>';
					$feedback_details .= '</div></div><div class="row"><div class="cc-selector callback col-lg-12 col-md-12 col-sm-12 col-xs-12">';
					
					//					$fb_qry = mysql_query("SELECT * FROM `feedback_ques_details` WHERE `outlet_id` = '$UnitId'");
					$fb_qry = mysql_query("SELECT * FROM `feedback_ques_details` WHERE `outlet_id` =1");
					while($fb_row = mysql_fetch_array($fb_qry)) {
						$fbinputid = strtolower(str_replace(' ', '_', $que_row['fb_ques']).'_'.str_replace(' ', '_', $fb_row['fb_option_text']));
						$ques_value = strtolower(str_replace(' ', '_', $que_row['fb_ques'])).'#'.$que_row['fb_ques_id'].'-'.$fb_row['fb_option_wt'].'-'.str_replace(' ', '_', $fb_row['fb_option_text']);
						// $fbinputname = strtolower(str_replace(' ', '_', $que_row['fb_ques']));
						// $fb_option_text = $fb_row['fb_option_text'];
						$fb_option_image = $fb_row['fb_option_image'];
						$fboptiontext = ucfirst($fb_row['fb_option_text']);

						$feedback_details .= '<div class="selector col-lg-2 col-md-2 col-sm-2 col-xs-2"><input id="'.$fbinputid.'" type="radio" name="call_'.$i.'" value="'.$ques_value.'" /><label class="drinkcard-cc" for="'.$fbinputid.'"><img src="../img/emoji-img/'.$fb_option_image.'"></label><p class="text">'.$fboptiontext.'</p></div>';
						
					}
					$feedback_details .= '<input type="hidden" name="no_ques" value="'.$i.'">';
					$feedback_details .= '</div></div></div>';
				}
			}
			$i++;
		}
		/*$no_ques = $i-1;
		$feedback_details .= '<input type="hidden" name="no_ques" value="'.$no_ques.'">';*/
		$feedback_details .= "<div class=\"form-group\"><label>Email</label><input type=\"text\" name=\"cbemail\" id=\"cbemail\" class=\"form-control\" placeholder=\"Enter your email\"></div><div class=\"row\"><div class=\"col-lg-6\"><div class=\"form-group\"><label>Birthday</label><input type=\"text\" name=\"cbdob\" id=\"cbdob\" class=\"form-control\"  placeholder=\"Select your birthday\"></div></div><div class=\"col-lg-6\"><div class=\"form-group\"><label>Anniversary</label><input type=\"text\" name=\"cbanniversary\" id=\"cbanniversary\" class=\"form-control\"  placeholder=\"Select your anniversary date\"></div></div></div><div class=\"form-group\"><label>Comments</label><textarea class=\"form-control\" name=\"cbcomments\" id=\"cbcomments\" placeholder=\"Comments please...\" rows=\"5\"></textarea></div><div class=\"form-group\"><input type=\"button\" class=\"btn btn-success btn-save-setting\" name=\"cbSubmit\" id=\"btnsubmit\" value=\"Save Fedback\"></div></form></div></div>";
		
	}
	$fbdt[] = $feedback_details;

	// details of order info
	$order_info_detail = '';
	$orderinfo = array();
	$qry1 = mysql_query("SELECT * FROM `guest_order_history` WHERE `feedback_done` = 0 AND (OrderStatus != 'Rejected' AND OrderStatus != 'Cancelled') AND `UnitId` = '$outletid' AND `InvoiceId` = '$invoiceid'");
	while ($row1 = mysql_fetch_array($qry1)) {
		$UnitId = $row1['UnitId'];
		$invoiceId = $row1['InvoiceId'];

		$unit_sql1 = mysql_query("SELECT UnitName FROM unit_master WHERE UnitId=$UnitId");
		$unit_row1 = mysql_fetch_assoc($unit_sql1);
		$unit_name1 = $unit_row1['UnitName'];

		$order_info_detail = '<p class="customer-name text-logs" style="font-weight: 800;">'.$row1['FirstName'].' '.$row1['LastName'].'</p><div class="row"><div class="col-lg-6 col-md-6 fb-detail-left"><p class="detail-left text-logs">'.$row1['GuestPhone'].'</p><p class="detail-left text-logs">Sale Date <span class="text-bold">'.date('d-m-Y', strtotime($row1['SaleDate'])).'</span></p></div><div class="col-lg-6 col-md-6 fb-detail-right text-right"><p class="detail-right text-logs">Invoice No. - <span class="text-bold">'.$row1['InvoiceNumber'].'</span></p><p class="detail-right text-logs">Order Source - <span class="text-bold">'.$row1['SourceOfOrder'].'</span></p><p class="detail-right text-logs">Outlet Name - <span class="text-bold">'.$unit_name1.'</span></p></div></div>';
		
		$order_info_detail .= '<table class="table table-striped table-sm table-fb-order"><thead class="thead-default"><tr><th>Item</th><th>Qty</th><th>Price</th></tr></thead><tbody>';
		$odr_qry = mysql_query("SELECT * FROM `sale_item_record` WHERE `UnitId` = '$UnitId' AND `InvoiceId` = '$invoiceId'");
		while ($odr_row = mysql_fetch_array($odr_qry)) {
			$order_info_detail .= '<tr><td>'.$odr_row['ItemName'].'</td><td>'.$odr_row['Quantity'].'</td><td>'.$odr_row['Price'].'</td></tr>';
		}
		$order_info_detail .= '</tbody></table>';
		$sale_qry = mysql_query("SELECT * FROM `sale_record` WHERE `UnitId` = '$UnitId' AND `InvoiceId` = '$invoiceId'");
		$sale_row = mysql_fetch_array($sale_qry);
		$order_info_detail .= '<div class="row"><div class="col-lg-12 text-right"><p>Discount: <span class="text-bold">'.$sale_row['DiscAmt'].'</span></p><p>Total Bill Amount: <span class="text-bold">'.$sale_row['TotalAmt'].'</span></p></div></div>';
	}
	$orderinfo[] = $order_info_detail;

	$data = array('feedbackDetail' => $fbdt, 'orderInfo' => $orderinfo);
	echo json_encode($data);
}



if ($_GET['act'] == 'callback') {
	$outlet = $_GET['outlet'];
	$daterange = $_GET['daterange'];
	$expdate1 = explode('/', $daterange);
	$fdate = $expdate1[2]."-".$expdate1[1]."-".$expdate1[0];
	$ldate = $expdate1[2]."-".$expdate1[1]."-".$expdate1[0];
	/*
	$date = explode('/', $daterange);

	$fst_date = trim($date[0], " ");
	$expdate1 = explode('/', $fst_date);
	$fdate = $expdate1[2]."-".$expdate1[1]."-".$expdate1[0];

	$lst_date = trim($date[1], " ");
	$expdate2 = explode('/', $lst_date);
	$ldate = $expdate2[2]."-".$expdate2[1]."-".$expdate2[0];*/

	if($outlet == 'all'){
		$outlet_sql = '';
	} else {
		$outlet_sql = 'AND  umr.`UnitId` = \''.$outlet.'\'';
	}

	$goh_qry = mysql_query("SELECT umr.`UnitName`, goh.* FROM `guest_order_history` AS goh LEFT JOIN `unit_master` AS umr ON goh.`UnitId` = umr.`UnitId` WHERE goh.`feedback_sent` = 1 AND goh.`feedback_done` = 0 AND (goh.`SaleDate` >= '$fdate' AND goh.`SaleDate` <= '$ldate') AND goh.`OrderStatus` != 'Rejected' AND goh.`OrderStatus` != 'Cancelled' AND goh.`OrderStatus` != 'Cancelled' $outlet_sql");
	while($goh_row = mysql_fetch_array($goh_qry)) {
		$gunitId = $goh_row['UnitId'];
		
		echo '<div class="view-customer">';
			echo '<div class="shadow"></div>';
			echo '<div class="row">';
				echo '<div class="col-lg-6">';
					echo '<p class="customer-name text-logs" style="font-weight: 800;">'.$goh_row['FirstName'].' '.$goh_row['LastName'].'</p>';
				echo '</div>';
				echo '<div class="col-lg-6 text-right">';
					echo '<p class="customer-name text-logs">Invoice No - <span class="text-bold">'.$goh_row['InvoiceNumber'].'</span></p>';
					echo '<p class="customer-name text-logs">Order Source - <span class="text-bold">'.$goh_row['SourceOfOrder'].'</span></p>';
					echo '<p class="customer-name text-logs">Outlet - <span class="text-bold">'.$goh_row['UnitName'].'</span></p>';
				echo '</div>';
			echo '</div>';
			echo '<div class="row">';
				echo '<div class="col-lg-8">';
					echo '<p class="text-logs">Sale Date <span class="text-bold">'.date('d-m-Y', strtotime($goh_row['SaleDate'])).'</span></p>';
				echo '</div>';
				echo '<div class="col-lg-4">';
					
					?>
					<button type="button" name="submit-btn" class="btn btn-outline-primary view-details float-right" onclick="customerTakeFeedback('takefb', <?php echo $goh_row['UnitId']; ?>, <?php echo $goh_row['InvoiceId']; ?> )">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['UnitId']; ?>, <?php echo $goh_row['InvoiceId']; ?> )">Not Interested</button>
					
					<!-- <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
					
				echo '</div>';
			echo '</div>';
		echo '</div>';
	}
}