<?php 
ob_start();
session_start();
include("inc/config.php");
                 
                    $awb = $_POST['awb'] ?? '';
                    $type = $_POST['type'];
                    if(isset($_POST['courier_id'])){ $courier_id = $_POST['courier_id']; }
                    
                    if($type=='pl3_awb'){
                        	$statement = $pdo->prepare("SELECT * FROM `tbl_awb` WHERE courier_id=$courier_id and status='0' and awb_code='$awb'");
							$statement->execute();
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
							$count = $statement->rowCount();
							if($count>0)
							{
							     $txt='3PL AWB is Available';
							    $error='0';
							   
							}
							else
							{
							     $txt='3PL AWB is Not Available';
							    $error='1';
							}
                            
                            }
                            
                            if($type=='hsncode'){
                        	$statement = $pdo->prepare("SELECT * FROM `tbl_hsncode` WHERE hsncode=$awb");
							$statement->execute();
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
							$count = $statement->rowCount();
							if($count>0)
							{
							    $txt='HSN Code is Available';
							    $error='0';
							   
							}
							else
							{
							     $txt='Invalid HSN Code';
							    $error='1';
							}
                            }
                            
                            
                          if($type=='cscs_awb'){
                        	$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE cscs_awb='$awb'");
							$statement->execute();
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
							$count = $statement->rowCount();
							if($count>0)
							{
							    $txt='AWB is already taken';
							    $error='1';
							}
							else
							{
							    $txt='AWB is available';
							    $error='0';
							}
                            
                            }
                            
                        if($type=='ref_no'){
                        	$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE ref_no='$awb'");
							$statement->execute();
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
							$count = $statement->rowCount();
							if($count>0)
							{
							    $txt='Ref Number is already taken';
							    $error='1';
							}
							else
							{
							    $txt='Ref Number is available';
							    $error='0';
							}
                            
                            }
                 if($type=='pod'){
                            $awb_type = $_POST['awb_type'];
                            if($awb_type=='cscs_awb'){ $var='AWB Number'; }elseif($awb_type=='ref_no'){ $var='Ref Number'; }elseif($awb_type=='3pl_awb'){ $var='3PL AWB Number'; }
                            
                        	$statement = $pdo->prepare("SELECT * FROM `pickup_entry` WHERE $awb_type='$awb'");
							$statement->execute();
							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
							$count = $statement->rowCount();
							if($count>0)
							{
							    $txt=$var.' is Available';
							    $error='0';
							}
							else
							{
							    $txt=$var.' is not available';
							    $error='1';
							}
                            
                            }
                              $datas[] = array('txt' => $txt, 'error' => $error);
                              
                         echo json_encode($datas);     
                         
?>