<?php

	include 'header.php';
	include 'navbar.php';

	require_once('includes/API_Config.php');
    $obj = new API_Config;
	$data = array();
	$data['refer_id'] = $_SESSION['refer_id'];
	$data['user_id'] = $_SESSION['user_id'];
	$response = json_decode($obj->call_API("API_getRewardStatus.php", $data));
	error_reporting(0);
	//var_dump($response->data);

?>

<style>

.table td img{

    width: 15.2rem;
    height: 7.2rem;
}

.table td{

    font-weight:bold;
}


.table td img, .jsgrid .jsgrid-table td img, .table th img, .jsgrid .jsgrid-table th img {
    /*width: 30px;
    height: 30px;*/
    border-radius: 5px;
}

</style>

		<div class="card">
            <div class="card-body">
              <h4 class="card-title">My Rewards (* Denotes Terms & conditions apply)</h4>
              <div class="row">
                <div class="col-12 table-responsive">
                  <table id="order-listing" class="table">
                    <thead>
                      <tr>
                          <th>Sr No.</tH>
                          <th>Reward Name</th>
                          <th>Squad A <br/><br/>Target(PV)</th>
                          <th>Squad B <br/><br/>Target(PV)</th>
						  <th>Required in <br/><br/>Squad A(PV)</th>
                          <th>Required in <br/><br/>Squad B(PV)</th>
						  <th>Days Left</th>
						  <th>Status</th>
                      </tr>
                    </thead>
                    <tbody>
                     <?php
					 if(!empty($response->data))
					  {
							$count = 1;
							foreach($response->data as $row)
							{
								echo "<tr>";
								echo "<td>" . $count++                  . "</td>";
								echo "<td>" . "<img src='../images/reward" . ($count-1) . ".png' class='img-responsive'/><br/><br/>" . ucWords($row->rewardName) . "</td>";
								echo "<td>" . number_format($row->leftLegTarget,0, ",", ",")       . "</td>";
								echo "<td>" . number_format($row->rightLegTarget,0, ",", ",")      . "</td>";
								
								echo "<td>";
								if($row->rewardLeftVolume< $row->leftLegTarget)
								{
									echo number_format($row->leftLegTarget - $row->rewardLeftVolume,0, ",", ",");

								}

								else
									echo "---";
									
								echo "</td>";



								echo "<td>";
								if($row->rewardRightVolume< $row->rightLegTarget)
								{
									echo number_format($row->rightLegTarget - $row->rewardRightVolume,0, ",", ",");

								}
								else
									echo "---";
								echo "</td>";

								
								
								
								echo "<td>"; 
								

								if($row->daysLeft == 'Lifetime')
									echo trim($row->daysLeft,'+');


								else if($row->daysLeft <= 0)
									echo "Closed";

								else
									echo trim($row->daysLeft,'+') . " Days Left";
									
								
												
								echo "</td>";






								echo "<td>";


								if(($row->rewardLeftVolume >= $row->leftLegTarget) && ($row->rewardRightVolume >= $row->rightLegTarget))
								{
									echo "Achieved*";

								}


								else
								{

									if($row->daysLeft == 'Lifetime')
										echo "Pending";

									else if($row->daysLeft <= 0)
										echo "Not Applicable";
									
									else
									echo "Pending";
								}
								
								echo "</td>";
								echo "</tr>";
							}
					  }

					 else
					 {
						echo "<tr><td>No Data Available</td><tr>";

					 }

					?>                     
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>


<?php
	include 'footer.php';
?>