<?php 
include "db.php";

    $awb_id = $_POST['awb_id'];
    $t_name = $_POST['t_name'];
    $e_date = $_POST['e_date'];
    $ori = $_POST['orig'];
    $dest = $_POST['dest'];
  //  $cid = $_POST['cid'];
    $send = $_POST['send'];
    $no_of_entry=count($awb_id);
    
    
// //    **********************************  Generate Manifest No Start ********************************************
                    
                                    $g=mysqli_query($con,"SELECT MAX(manifest_id) as max_mani FROM manifest ORDER BY id DESC LIMIT 1");
                                    $response=mysqli_fetch_array($g);
                                    $bid=$response['max_mani'];
                                    if($bid!='')
                                    {
                                        $manifest_id=$bid+1;
                                    } 
                                    else
                                    {
                                        $manifest_id=100001;
                                    }

							
	
                      // // 	**********************************  Generate Manifest No End ********************************************
    
    
                            	$sql1="INSERT INTO `manifest`(`manifest_id`, `origin`,`client_id` , `entry_date`, `transport_name`, `sending_through`, `no_of_entry`) 
                            	VALUES ('$manifest_id','$ori','$clientId','$e_date','$t_name','$send','$no_of_entry')";
                                $result1=$con->query($sql1);
                                if($result1)
                                {
                                foreach($awb_id as $awb) {
                                 $sql2="UPDATE `pickup_entry` SET manifest_id='$manifest_id',status='manifest',status_code='3' WHERE id='$awb'";
                                 $result2=$con->query($sql2);
                                if($result2)
                                {
                                  $resp=1;
                                }
                                else
                                {
                                  $resp=0;
                                }
                                	/*Tracking Module Start*/
	
		                                $statement ="INSERT INTO tbl_tracking (created_at,pickup_entry_id,manifest_id,user_id,location,status,status_code,description,remark) VALUES ('$e_date',$awb,$manifest_id,$clientId,'$clientLocation','manifest','3','Manifest Created Successfully','')";
	                                    $results=$con->query($statement);
			
		                            /*Tracking Module End*/
                                
                                   }
                                }
                      echo json_encode($resp);
                      ?>