<?php 

include("inc/config.php");
    $from = $_POST['from'];
    $to = $_POST['to'];
    $status = $_POST['status'];
    $role = $_POST['role'];
    $client_id = $_POST['client_id'];
    $courier_id = $_POST['courier_id'];
        
    if($role=="Admin") 
     {   
         
        
        if($status=='all' && $client_id=='all')
        {
           $condition='';  
        } 
        elseif($status!='all' && $client_id=='all')
        {
           $condition='WHERE pickup_entry.status_code="'.$status.'"';
        }
        elseif($status=='all' && $client_id!='all')
        {
           $condition='WHERE pickup_entry.client_id='.$client_id;
        }
        else
        {
            $condition='WHERE pickup_entry.status_code="'.$status.'" AND pickup_entry.client_id='.$client_id;
        }
        $statement = $pdo->prepare("SELECT pickup_entry.*,tbl_user.full_name as client_name,pickup_entry.date_added as added FROM pickup_entry INNER JOIN tbl_user on pickup_entry.client_id=tbl_user.id $condition order by pickup_entry.id DESC");   
     }
    else
    {
        
        if($status=='all')
        {
         $statement = $pdo->prepare("SELECT pickup_entry.*,tbl_user.full_name as client_name,pickup_entry.date_added as added FROM pickup_entry INNER JOIN tbl_user on pickup_entry.client_id=tbl_user.id and pickup_entry.client_id=$client_id order by pickup_entry.id DESC");   
        }
        else{
        
          $statement = $pdo->prepare("SELECT pickup_entry.*,tbl_user.full_name as client_name,pickup_entry.date_added as added FROM pickup_entry INNER JOIN tbl_user on pickup_entry.client_id=tbl_user.id where pickup_entry.status_code='$status' AND pickup_entry.client_id=$client_id order by pickup_entry.id DESC");   
        }
    }
            	$statement->execute();
            	$result = $statement->fetchAll(PDO::FETCH_ASSOC);							
                $i=1;
                
                
                
                echo'	<thead>';
						echo'	<tr>';
							echo'	<th width="30">SL</th>';
						 if($role=="Admin"){ 	echo'<th>Client</th>'; } 
							echo'	<th>CSCS AWB</th>';
						if($role=="Admin"){ echo'	<th>3PL AWB</th>'; }
								echo'<th>Ref No</th>';
							echo'	<th>Order Type</th>';
							echo'	<th>Status</th>';
							echo'	<th>Shipper Name</th>';
							echo'	<th>Shipper Address</th>';
							echo'	<th>Shipper City</th>';
								echo'<th>Shipper State</th>';
								echo'<th>Shipper Phone</th>';
								echo'<th>Shipper Pincode</th>';
								echo'<th>Consignee Name</th>';
								echo'<th>Consignee Address</th>';
								echo'<th>Consignee City</th>';
								echo'<th>Consignee State</th>';
								echo'<th>Consignee Phone</th>';
								echo'<th>Consignee Pincode</th>';
								echo'<th>Volumetric Weight</th>';
								echo'<th>Volumetric Length</th>';
								echo'<th>Volumetric Breadth</th>';
								echo'<th>Volumetric Height</th>';
								echo'<th>Collectable Amount</th>';
								echo'<th>Product Description</th>';
								echo'<th>Quantity</th>';
								echo'<th>No.Of Boxes</th>';
								echo'<th>Invoice Value</th>';
								echo'<th>Taxable Value</th>';
								echo'<th>Hsn Code</th>';
								echo'<th>Discount</th>';
								echo'<th>Gst Amount</th>';
								echo'<th>MRP</th>';
								echo'<th>Ewaybill</th>';
								echo'<th>Actual Weight</th>';
								echo'<th>Charged Weight</th>';
								echo'<th>Gst Type</th>';
								echo'<th>Buyer Gst</th>';
								echo'<th>Seller Gst</th>';
								echo'<th>RTO Name</th>';
								echo'<th>RTO Address</th>';
								echo'<th>RTO City</th>';
								echo'<th>RTO State</th>';
								echo'<th>RTO Phone</th>';
								echo'<th>RTO Pincode</th>';
								echo'<th>Date Added</th>';
							echo'</tr>';
						echo'</thead>';
						echo'<tbody>';
                 if($from!='' && $to!=''){
                foreach ($result as $row) {
                     $created=date_create($row['added']);
                     $da=date_format($created,'Y-m-d');
                     $cr_at=date_format($created,'d/m/Y');
                     if ($from <= $da && $to >= $da)
                    {
                            echo'<tr>';
                       echo '<td>'. $i.'</td>';
          if($role=='Admin'){ echo '<td>'. $row['client_name'] .'</td>'; }
                       echo '<td>'. $row['cscs_awb'] .'</td>';
         if($role=='Admin'){ echo '<td>'. $row['3pl_awb'] .'</td>'; }
                       echo '<td>'. $row['ref_no'] .'</td>';
	                   echo '<td>'. strtoupper($row['order_type']) .'</td>';
	                   echo '<td>'. ucwords($row['status']) .'</td>';
	                   echo '<td>'. $row['shipper_name'].'</td>';
	                   echo '<td>'. $row['shipper_address'].'</td>';
	                   echo '<td>'. $row['shipper_city'] .'</td>';
	                   echo '<td>'. $row['shipper_state'] .'</td>';
	                   echo '<td>'. $row['shipper_phone'] .'</td>';
	                   echo '<td>'. $row['shipper_pincode'].'</td>';
	                   echo '<td>'. $row['consignee_name'].'</td>';
	                   echo '<td>'. $row['consignee_address'].'</td>';
	                   echo '<td>'. $row['consignee_city'] .'</td>';
	                   echo '<td>'. $row['consignee_state'] .'</td>';
	                   echo '<td>'. $row['consignee_phone'] .'</td>';
	                   echo '<td>'. $row['consignee_pincode'].'</td>';
	                   echo '<td>'. $row['v_weight'] .'</td>';
	                   echo '<td>'. $row['vw_length'] .'</td>';
	                   echo '<td>'. $row['vw_breadth'] .'</td>';
	                   echo '<td>'. $row['vw_height'] .'</td>';
	                   echo '<td>'. $row['collectable_amount'] .'</td>';
	                   echo '<td>'. $row['product_description'] .'</td>';
	                   echo '<td>'. $row['quantity'] .'</td>';
	                   echo '<td>'. $row['boxes'] .'</td>';
	                   echo '<td>'. $row['invoice_value'] .'</td>';
	                   echo '<td>'. $row['taxable_value'] .'</td>';
	                   echo '<td>'. $row['hsn_code'] .'</td>';
	                   echo '<td>'. $row['discount'] .'</td>';
	                   echo '<td>'. $row['gst_amount'] .'</td>';
	                   echo '<td>'. $row['mrp'] .'</td>';
	                   echo '<td>'. $row['ewaybill'] .'</td>';
	                   echo '<td>'. $row['a_weight'] .'</td>';
	                   echo '<td>'. $row['c_weight'] .'</td>';
	                   echo '<td>'. $gst .'</td>';
	                   echo '<td>'. $row['buyer_gst'] .'</td>';
	                   echo '<td>'. $row['seller_gst'] .'</td>';
	                   echo '<td>'. $row['rto_name'].'</td>';
	                   echo '<td>'. $row['rto_address'].'</td>';
	                   echo '<td>'. $row['rto_city'] .'</td>';
	                   echo '<td>'. $row['rto_state'] .'</td>';
	                   echo '<td>'. $row['rto_phone'] .'</td>';
	                   echo '<td>'. $row['rto_pincode'].'</td>';
	                   echo '<td>'. date_format($created,'d/m/Y') .'</td>';
	                   echo '</tr>';
	  	                              $i++;
                    }
        } 
    }else{
        foreach ($result as $row) {
                     $created=date_create($row['added']);
                     $da=date_format($created,'Y-m-d');
                     $cr_at=date_format($created,'d/m/Y');
                           echo'<tr>';
                       echo '<td>'. $i.'</td>';
          if($role=='Admin'){ echo '<td>'. $row['client_name'] .'</td>'; }
                       echo '<td>'. $row['cscs_awb'] .'</td>';
                     if($role=='Admin'){   echo '<td>'. $row['3pl_awb'] .'</td>'; }
                       echo '<td>'. $row['ref_no'] .'</td>';
	                   echo '<td>'. strtoupper($row['order_type']) .'</td>';
	                   echo '<td>'. ucwords($row['status']) .'</td>';
	                   echo '<td>'. $row['shipper_name'].'</td>';
	                   echo '<td>'. $row['shipper_address'].'</td>';
	                   echo '<td>'. $row['shipper_city'] .'</td>';
	                   echo '<td>'. $row['shipper_state'] .'</td>';
	                   echo '<td>'. $row['shipper_phone'] .'</td>';
	                   echo '<td>'. $row['shipper_pincode'].'</td>';
	                   echo '<td>'. $row['consignee_name'].'</td>';
	                   echo '<td>'. $row['consignee_address'].'</td>';
	                   echo '<td>'. $row['consignee_city'] .'</td>';
	                   echo '<td>'. $row['consignee_state'] .'</td>';
	                   echo '<td>'. $row['consignee_phone'] .'</td>';
	                   echo '<td>'. $row['consignee_pincode'].'</td>';
	                   echo '<td>'. $row['v_weight'] .'</td>';
	                   echo '<td>'. $row['vw_length'] .'</td>';
	                   echo '<td>'. $row['vw_breadth'] .'</td>';
	                   echo '<td>'. $row['vw_height'] .'</td>';
	                   echo '<td>'. $row['collectable_amount'] .'</td>';
	                   echo '<td>'. $row['product_description'] .'</td>';
	                   echo '<td>'. $row['quantity'] .'</td>';
	                   echo '<td>'. $row['boxes'] .'</td>';
	                   echo '<td>'. $row['invoice_value'] .'</td>';
	                   echo '<td>'. $row['taxable_value'] .'</td>';
	                   echo '<td>'. $row['hsn_code'] .'</td>';
	                   echo '<td>'. $row['discount'] .'</td>';
	                   echo '<td>'. $row['gst_amount'] .'</td>';
	                   echo '<td>'. $row['mrp'] .'</td>';
	                   echo '<td>'. $row['ewaybill'] .'</td>';
	                   echo '<td>'. $row['a_weight'] .'</td>';
	                   echo '<td>'. $row['c_weight'] .'</td>';
	                   echo '<td>'. $gst .'</td>';
	                   echo '<td>'. $row['buyer_gst'] .'</td>';
	                   echo '<td>'. $row['seller_gst'] .'</td>';
	                   echo '<td>'. $row['rto_name'].'</td>';
	                   echo '<td>'. $row['rto_address'].'</td>';
	                   echo '<td>'. $row['rto_city'] .'</td>';
	                   echo '<td>'. $row['rto_state'] .'</td>';
	                   echo '<td>'. $row['rto_phone'] .'</td>';
	                   echo '<td>'. $row['rto_pincode'].'</td>';
	                   echo '<td>'. date_format($created,'d/m/Y') .'</td>';
	                   echo '</tr>';
	  	                              $i++;
        } 
    }
     echo'</tbody>';  
       
    //   if($row['status']=='pending'){ echo '<td><button class="btn btn-xs btn-danger">Pending</button></td>'; }
    //                   elseif($row['status']=='picked'){ echo '<td><button class="btn btn-xs btn-primary">Picked</button></td>'; }
    //                   elseif($row['status']=='manifest'){ echo '<td><button class="btn btn-xs btn-success">Manifest</button></td>'; }
    //                   elseif($row['status']=='In Transit'){ echo '<td><button class="btn btn-xs btn-success">In Transit</button></td>'; }
    //                   elseif($row['status']=='Received at destination'){ echo '<td><button class="btn btn-xs btn-success">Received at Destination</button></td>'; }
    //                   elseif($row['status']=='Out for delivery'){ echo '<td><button class="btn btn-xs btn-success">Out for Delivery</button></td>'; }
    //                   elseif($row['status']=='Delivered'){ echo '<td><button class="btn btn-xs btn-success">Delivered</button></td>'; }
    //                   elseif($row['status']=='Undelivery'){ echo '<td><button class="btn btn-xs btn-success">Undelivery</button></td>'; }
    //                     else{ echo '<td><button class="btn btn-xs btn-success">Nill</button></td>'; }
    ?>