<?php 
include("inc/config.php");
  
    $from = $_POST['from'];
    $to = $_POST['to'];
    $client_id = $_POST['client_id'];
    $client_type = $_POST['client_type'];
    
            if($client_id!='all'){
                $statement = $pdo->prepare("SELECT pickup_entry.*,tbl_user.full_name as client_name FROM pickup_entry INNER JOIN tbl_user
                on pickup_entry.client_id=tbl_user.id where pickup_entry.client_id='$client_id' and pickup_entry.status='delivered' order by pickup_entry.id DESC");   
  
            	$statement->execute();
            	$result = $statement->fetchAll(PDO::FETCH_ASSOC);	
            	$total_count = $statement->rowCount();
                $i=1;
            }
            else{
                 $statement = $pdo->prepare("SELECT pickup_entry.*,tbl_user.full_name as client_name FROM pickup_entry INNER JOIN tbl_user
    	       on pickup_entry.client_id=tbl_user.id where pickup_entry.status='delivered' order by pickup_entry.id DESC");   
  
            	$statement->execute();
            	$result = $statement->fetchAll(PDO::FETCH_ASSOC);	
            	$total_count = $statement->rowCount();
                $i=1;
                
            }
                
                if($total_count>0)
                {
                
                if($from!='' && $to!=''){
                foreach ($result as $row) {
                     $created=date_create($row['date_added']);
                     $da=date_format($created,'Y-m-d');
                     if ($from <= $da && $to >= $da)
                    {
                        if($row['gst_rate']=='gr_igst'){ $gst='IGST'; }elseif($row['gst_rate']=='gr_cgst'){ $gst='CGST'; }
                        
                        echo'<tr>';
                       echo '<td>'. $i.'</td>';
          if($client_type=='Admin'){ echo '<td>'. $row['client_name'] .'</td>'; }
                       echo '<td>'. $row['cscs_awb'] .'</td>';
          if($client_type=='Admin'){   echo '<td>'. $row['3pl_awb'] .'</td>'; }
                       echo '<td>'. $row['ref_no'] .'</td>';
	                   echo '<td>'. strtoupper($row['order_type']) .'</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['date_added']);
                     $da=date_format($created,'Y-m-d');
                     if($row['gst_rate']=='gr_igst'){ $gst='IGST'; }elseif($row['gst_rate']=='gr_cgst'){ $gst='CGST'; }
                     
                     
                       echo'<tr>';
                       echo '<td>'. $i.'</td>';
          if($client_type=='Admin'){ echo '<td>'. $row['client_name'] .'</td>'; }
                       echo '<td>'. $row['cscs_awb'] .'</td>';
          if($client_type=='Admin'){       echo '<td>'. $row['3pl_awb'] .'</td>'; }
                       echo '<td>'. $row['ref_no'] .'</td>';
	                   echo '<td>'. strtoupper($row['order_type']) .'</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{
                    echo 'No Data Available';
                }
                
    ?>