<?php
require_once("../../../loader.php");

$db = new Conexion;
$user = new User;
$core = new Core;
$userData = $user->cdp_getUserData();
$month = date('m');
$year = date('Y');
$return = '';
if(isset($_POST["query"]))
{
 $search = mysqli_real_escape_string($conn, $_POST["query"]);
 $query = "SELECT a.total_declared_value, a.total_weight, a.total_tax_discount, a.sub_total, a.total_tax_insurance, a.total_tax_custom_tariffis, a.total_tax, a.status_invoice,  a.is_consolidate, a.is_pickup,  a.total_order, a.order_id, a.order_prefix, a.order_no, a.order_date, a.sender_id, a.receiver_id, a.order_courier,a.status_courier,
            a.currency, a.total_fixed_value, b.mod_style, b.color, c.phone, c.fname, c.lname FROM
			 cdb_add_order as a
			 INNER JOIN cdb_styles as b ON a.status_courier = b.id
			 INNER JOIN cdb_users as c ON a.sender_id = c.id
             WHERE c.phone LIKE '%".$search."%'
             OR c.fname LIKE '%".$search."%'
             OR c.lname LIKE '%".$search."%'
             OR CONCAT(a.order_prefix,a.order_no) LIKE '%".$search."%'
             
             and a.status_courier!=22
	             order by order_id desc
 ";}
else
{
 $query = "SELECT a.total_declared_value, a.total_weight, a.total_tax_discount, a.sub_total, a.total_tax_insurance, a.total_tax_custom_tariffis, a.total_tax, a.status_invoice,  a.is_consolidate, a.is_pickup,  a.total_order, a.order_id, a.order_prefix, a.order_no, a.order_date, a.sender_id, a.receiver_id, a.order_courier,a.status_courier,
            a.currency, a.total_fixed_value, b.mod_style, b.color, c.phone, c.fname, c.lname FROM
			 cdb_add_order as a
			 INNER JOIN cdb_styles as b ON a.status_courier = b.id
			 INNER JOIN cdb_users as c ON a.sender_id = c.id";
}
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0)
{
 $return .='
 <div class="table-responsive">
 <table class="table table bordered">
 <tr style="background-color: #3e5569; color: white">

					<th><b><?php echo $lang['ltracking'] ?></b></th>
					<th class="text-center"><b><?php echo $lang['ddate'] ?></b></th>
					<th class="text-center"><b>Sender</b></th>
					<th class="text-center"><b>S.Phone</b></th>
					<th class="text-center"><b>Receiver</b></th>
					<th class="text-center"><b>R.Phone</b></th>
					<th class="text-center"><b><?php echo $lang['lorigin'] ?></b></th>
					<th class="text-center"><b>Destination</b></th>
					<th class="text-center"><b>Invoice Status</b></th>
					<th class="text-center"><b>Pay Method</b></th>
					<th class="text-center"><b>Total</b></th>
					<th class="text-center"><b>Payment Status</b></th>


				</tr>';
 while($row1 = mysqli_fetch_array($result))
 {
  $return .= '
  <tr class="card-hover">

							<td><b><a href="courier_view.php?id=<?php echo $row->order_id; ?>"><?php echo $row->order_prefix . $row->order_no; ?></a></b></td>
							<td class="text-center">
								<?php echo $row->order_date; ?>
							</td>

							<td class="text-center">
								<?php echo $sender_data->fname; ?> <?php echo $sender_data->lname; ?>
							</td>

                            <td class="text-center">
								<?php echo $sender_data->phone; ?>
							</td>
							
							<td class="text-center">
								<?php echo $receiver_data->fname; ?> <?php echo $receiver_data->lname; ?>
							</td>

                            <td class="text-center">
								<?php echo $receiver_data->phone; ?>
							</td>

							<td class="text-center"><?php echo $address_order->sender_country; ?>-<?php echo $address_order->sender_city; ?></td>

                            <td class="text-center"><?php echo $address_order->recipient_country; ?>-<?php echo $address_order->recipient_city; ?></td>
                            
							<td class="">

								<span style="background: <?php echo $row->color; ?>;" class="label label-large"><?php echo $row->mod_style; ?></span>
								<br>

								<?php
								if ($row->is_pickup == true) { ?>

									<span style="background: <?php echo $status_style_pickup->color; ?>;" class="label label-large"><?php echo $status_style_pickup->mod_style; ?></span>
								<?php
								}
								?>

								<?php
								if ($row->is_consolidate == true) { ?>

									<span style="background: <?php echo $status_style_consolidate->color; ?>;" class="label label-large"><?php echo $status_style_consolidate->mod_style; ?></span>
								<?php
								}
								?>
							</td>

							<td class="text-center">
								<?php print_r($pay_name->PayType); ?>

							</td>


							<td class="text-center">
								<b><?php echo $curr->currency; ?></b> <?php echo $row->total_order; ?>
							</td>

							<td>
								<span class="label label-large <?php echo $label_class; ?>"><?php echo $text_status; ?></span>

							</td>


						</tr>';
 }
 echo $return;
 }
else
{ echo 'No results found.'; }?>