<?php

	include 'header.php';
	include 'navbar.php';
	include 'includes/admin_API_Config.php';

	$obj = new API_Config;
	$data = array();
	$data['admin_username'] = $_SESSION['admin_username'];
	$data['typeRequest'] = 1;
	$response = json_decode($obj->call_API("API_order_list.php", $data));
	error_reporting(0);
	//var_dump($response->orderList);

?>

	 <div class="card">
            <div class="card-body">
              <h4 class="card-title">Order List</h4>
              <div class="row">
                <div class="col-12 table-responsive">
                  <table id="payment-listing" class="table">
                    <thead>
                      <tr>
                          <th>Sr. #</th>
                          <th>Order ID</th>
                          <th>Source</th>
						  <th>Username</th>
						  <th>Member ID</th>
                          <th>Purchase Date</th>
						  <th>Total Amount</th>
                          <th>Payment Info</th>
                      </tr>
                    </thead>
                    <tbody>
					 <?php
					 if(!empty($response->orderList))
					  {
							$count = 0;
							foreach($response->orderList as $row)
							{
								echo "<tr>";
								echo "<td>" . ++$count . "</td>";
								echo "<td><a href=\"view-order-details.php?order_id=" . $row->id . "\" target=\"blank\">" . $row->id . "</a></td>";
								echo "<td>";
								
								if($row->order_type == 1)
									echo "Online";
								
								else
									echo "Offline";
								
								echo "</td>";

								echo "<td>" . ucwords($row->name) . " " . ucwords($row->last_name) . "</td>";
								echo "<td>" . $row->refer_id . "</td>";
								echo "<td>" . date('d-m-y', strtotime($row->date_entered)) . "</td>";
								echo "<td>" . $row->total_amount . "</td>";
																
								if($row->status==0)
								{
									echo "<td><a href=\"add-order-payment.php?order_id=" . $row->id . "\" target=\"blank\"><i class=\"icon icon-pencil s-4\">Add Payment Info</i></a></td>";
									echo "</tr>";
								}

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


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

						}

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

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

   <script type="text/javascript">
        
        $(document).ready(function(){


			  $('#payment-listing').DataTable({
			  "aLengthMenu": [
				[5, 10, 15, -1],
				[5, 10, 15, "All"]
			  ],
			  "iDisplayLength": 10,
			  "language": {
				search: ""
			  }
			});

				 
			 $('#payment-listing').each(function() {
			  var datatable = $(this);
			  // SEARCH - Add the placeholder for Search and Turn this into in-line form control
			  var search_input = datatable.closest('.dataTables_wrapper').find('div[id$=_filter] input');
			  search_input.attr('placeholder', 'Search');
			  search_input.removeClass('form-control-sm');
			  // LENGTH - Inline-Form control
			  var length_sel = datatable.closest('.dataTables_wrapper').find('div[id$=_length] select');
			  length_sel.removeClass('form-control-sm');
			});

	
        });

   </script>

    </body>
</html>
