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

/*$outletid = 9; //$_GET['outletid'];
$invoiceid = 17183240; //$_GET['invoiceid'];
$fbno = 647; //$_GET['fbno'];*/

$outletid = $_GET['outletid'];
$invoiceid =$_GET['invoiceid'];
$fbno = $_GET['fbno'];

$feedback_details = '';
$fbdt = array();

$qry = mysql_query("SELECT * FROM `feedback_response` WHERE `outlet_id` = '$outletid' AND `invoice_id` = '$invoiceid'");
$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);



?>
<div class="tab-content" style="margin-top: -3px;background-color: #fff;border: 0;border-top: 1px solid #eee;padding: 15px 0;width: 80%;margin-left: auto;margin-right: auto;border: 1px solid #ccc;">
	<div class="tab-pane active" id="feedback_datails" style="padding: 1rem;">
    <div style="font-size: 20px;font-weight: 800;border-bottom: 4px solid #b166b5;width: 30%;">Customer Details</div>
    <div id="customer-fb-detail">
      <p class="customer-name text-logs" style="font-weight: 800;background-color: #dedede;padding: 10px;"><?php echo $row['guest_name']; ?></p>
      <div class="row" style="display: inline-block;width: 100%;">
        <div class="col-lg-6 col-md-6 fb-detail-left" style="float: left;display: block;width: 50%;">
          <p class="detail-left text-logs" style="margin: 5px 0 0;"><?php echo $row['guest_email']; ?></p>
          <p class="detail-left text-logs" style="margin: 5px 0 0;"><?php echo $row['guest_mob_no']; ?></p>
          <p class="detail-left text-logs" style="margin: 5px 0 0;">Sale Date <span class="text-bold"><?php echo date('d-m-Y', strtotime($row['sale_date'])).' '.$st_row['SaleTime']; ?></span></p>
          <p class="text-logs" style="margin: 5px 0 0;">Response On <span class="text-bold"><?php echo 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" style="width: 50%;float: right;text-align: right;">
          <p class="detail-right text-logs" style="margin: 5px 0 0;">Invoice No. - <span class="text-bold"><?php echo $row['invoice_no'] ?></span></p>
          <p class="detail-right text-logs" style="margin: 5px 0 0;">Order Source - <span class="text-bold"><?php echo $row['order_source_name'] ?></span></p>
          <p class="detail-right text-logs" style="margin: 5px 0 0;">Outlet Name - <span class="text-bold"><?php echo $row['outlet_name'] ?></span></p>
        </div>
      </div>
      <div style="font-size: 20px;font-weight: 800;border-bottom: 4px solid #b166b5;width: 28%;margin-bottom: 10px;margin-top: 15px;">Feedback Details</div>
      <div class="row" style="display: inline-block;">
        <?php 
        $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);
       ?>
        <div class="col-lg-6" style="width: 32%;float: left;text-align: center;border: 0px solid #6bccf1;background-color: #edeeef;margin-right: 2px;margin-bottom: 2px;">
          <p class="dash-rating-count"><?php echo $ans_wt; ?></p>
           <p class="star-rating">
          <?php 
          $feedback_details = '';
          for ($i=1; $i <= $ans_wt; $i++) { 
            echo $feedback_details = '<img src="http://rezol.in/bbk_feedback/img/star-icon.png">';
          }
           ?>
         </p>
         <?php 
        $q = 0;
        $feedback_details = '';
        if ($q <= $count_word) {
          $feedback_details .= ucwords(implode(" ", $expques));
          $q++;
        }

          ?>
         
          <p class="dash-header"><?php echo $feedback_details; ?></p>
        </div> 
        <?php } ?>       
      </div>

      <div style="font-size: 20px;font-weight: 800;border-bottom: 4px solid #b166b5;width: 28%;margin-bottom: 10px;margin-top: 15px;">Feedback Comments</div>
      <div style="padding: 1rem;">
        <p><?php echo $row['fb_comments'] ?></p>
      </div>
  
    </div>
  </div>
  
  

  <div class="tab-pane active" id="order_info" style=" padding: 1rem;margin-top: 5px;">
    <div id="customer-order-info">
      <div style="font-size: 20px;font-weight: 800;border-bottom: 4px solid #b166b5;width: 23%;">Order Details</div>
      <table class="table table-striped table-sm table-fb-order" cellspacing="0" style="width: 100%;text-align: left;margin-top: 15px;">
        <thead class="thead-default">
          <tr style="text-align: left;">
            <th style="border-bottom: 1px solid #ccc;padding: 5px 0;">Item</th>
            <th style="border-bottom: 1px solid #ccc;padding: 5px 0;">Qty</th>
            <th style="border-bottom: 1px solid #ccc;padding: 5px 0;">Price</th>
          </tr>
        </thead>
        <tbody>
          <?php 
          $odr_qry = mysql_query("SELECT * FROM `sale_item_record` WHERE `UnitId` = '$outletid' AND `InvoiceId` = '$invoiceid'");
    while ($odr_row = mysql_fetch_array($odr_qry)) {

           ?>
          <tr>
            <td style="border-bottom: 1px solid #ccc;padding: 5px 0;"><?php echo $odr_row['ItemName'] ?></td>
            <td style="border-bottom: 1px solid #ccc;padding: 5px 0;"><?php echo $odr_row['Quantity'] ?></td>
            <td style="border-bottom: 1px solid #ccc;padding: 5px 0;"><?php echo $odr_row['Price'] ?></td>
          </tr>
          <?php } ?>
        </tbody>
      </table>
      <?php 
    $sale_qry = mysql_query("SELECT * FROM `sale_record` WHERE `UnitId` = '$outletid' AND `InvoiceId` = '$invoiceid'");
    $sale_row = mysql_fetch_array($sale_qry);
       ?>
      <div class="row">
        <div class="col-lg-12 text-right" style="text-align: right;">
          <p>Discount: <span class="text-bold"><?php echo $sale_row['DiscAmt'] ?></span></p>
          <p>Total Bill Amount: <span class="text-bold"><?php echo $sale_row['TotalAmt'] ?></span></p>
        </div>
      </div>
    </div>
  </div>
</div>