<?php 
ob_start();
session_start();
include("inc/config.php");
/*select the login details for checking client and admin*/
if($_SESSION['user']['role']=='Modicare')
{
$clientId=$_SESSION['user']['id'];
$clientLocation=$_SESSION['user']['location'];
$clientType=$_SESSION['user']['role'];
}else
{
$session_id=$_SESSION['user']['id'];
$statement = $pdo->prepare("SELECT * FROM `tbl_user` WHERE id=1");
$statement->execute();
$response = $statement->fetchAll(PDO::FETCH_ASSOC);
 foreach($response as $res)
 {
$clientId=$res['id'];
$clientLocation=$res['location'];
$clientType=$res['role'];
 }
}

   // var_dump($_POST);
	    $valid = 1;
        $cscs_awb='';
        $pl3_awb='';
        
    if(!empty($_POST['3pl_awb']))
    {
        
        $statement = $pdo->prepare("SELECT * FROM tbl_awb WHERE status=0 AND awb_code=?");
		$statement->execute(array($_POST['3pl_awb']));
		$rcount = $statement->rowCount();
        if($rcount>0){
        $statement = $pdo->prepare("UPDATE tbl_awb set status=1 WHERE awb_code=?");
		$statement->execute(array($_POST['3pl_awb']));
        }
    }
    
    
    if($_POST['cscs_awb']==$_POST['old_cscs_awb'])
    {
      $cscs_awb=$_POST['old_cscs_awb']; 
    }
    else
    {
        $cscs_awb=$_POST['cscs_awb']; 
    }
                            
    if($valid==1)
    {
        	$statement = $pdo->prepare("UPDATE pickup_entry set cscs_awb=?,courier_id=?,client_id=?,3pl_awb=?,ref_no=?,order_type=?,collectable_amount=?,boxes=?,
        	shipper_name=?,shipper_address=?,shipper_city=?,shipper_state=?,shipper_pincode=?,shipper_phone=?,
        	consignee_name=?,consignee_address=?,consignee_city=?,consignee_state=?,consignee_pincode=?,consignee_phone=?,
        	product_description=?,quantity=?,invoice_value=?,taxable_value=?,hsn_code=?,discount=?,gst_amount=?,mrp=?,ewaybill=?,
        	rto_name=?,rto_address=?,rto_city=?,rto_state=?,rto_pincode=?,rto_phone=?,a_weight=?,
        	c_weight=?,gst_rate=?,buyer_gst=?,seller_gst=?,date_added=?,business_mode=?,business_type=? 
        	WHERE id=? ");
	        $result=$statement->execute(array($cscs_awb,$_POST['courier_id'],$_POST['client_id'],$_POST['3pl_awb'],$_POST['ref_no'],$_POST['order_type'],$_POST['collectable_amount'],$_POST['boxes'],
	        $_POST['shipper_name'],$_POST['shipper_address'],$_POST['shipper_city'],$_POST['shipper_state'],$_POST['shipper_pincode'],$_POST['shipper_phone'],
	        $_POST['consignee_name'],$_POST['consignee_address'],$_POST['consignee_city'],$_POST['consignee_state'],$_POST['consignee_pincode'],$_POST['consignee_phone'],
	        $_POST['product_description'],$_POST['quantity'],$_POST['invoice_value'],$_POST['taxable_value'],$_POST['hsn_code'],$_POST['discount'],$_POST['gst_amount'],$_POST['mrp'],$_POST['ewaybill'],
	        $_POST['rto_name'],$_POST['rto_address'],$_POST['rto_city'],$_POST['rto_state'],$_POST['rto_pincode'],$_POST['rto_phone'],$_POST['a_weight'],
	        $_POST['c_weight'],$_POST['gst_rate'],$_POST['buyer_gst'],$_POST['seller_gst'],$_POST['date_added'],$_POST['pincode_mode'],$_POST['pincode_type'],
	        $_REQUEST['pickup_id']));
    }	       
        if($result)
		{
		    $txt='Success..! Shipment was Updated';
		    $error='0';
		}
		else
		{
		    $txt='Failed..! Try Again';
		    $error='1';
		}
        
          $datas[] = array('txt' => $txt, 'error' => $error);
     echo json_encode($datas);     
                        
	
?>