ok

Mini Shell

Direktori : /home2/selectio/public_html/y1jobportal.in/admin/api/bulk-upload/
Upload File :
Current File : /home2/selectio/public_html/y1jobportal.in/admin/api/bulk-upload/shipment-upload-api.php

<?php 
include_once('../config/config.php');
include_once('../config/custom-functions.php');
$fn = new custom_functions();

include '../carrier-api/api.php';
$carrier = new carrier();

if(isset($_FILES['upload_file'])){
    try{
    $file=$_FILES["upload_file"]["tmp_name"];
    if (($handle = fopen($file, 'r')) === false) {
        $response['error']=true;
        $response['data']='no data found';
        print_r($response);
        return 0;
    }
    
    $headers = fgetcsv($handle, 1024, ',');
    $complete = array();
    while ($row = fgetcsv($handle, 1024, ',')) {
        $complete[] = array_combine($headers, $row);
    }
    fclose($handle);
    
    date_default_timezone_set('Asia/Kolkata');
$order_date = date('Y-m-d', time());
    
    $pdo->beginTransaction(); 
    

                  
    foreach($complete as $data){  

$uuid=$fn->gen_uuid();
$order_id=$data['Order ID'];
$carrier_awb_no=$data['AWB Number'];


$order_channel='1';
$order_payment_type=$data['Payment Method'];

/*Sender address start*/    
    $buyer_full_name=$data['Customer Name'];
    $buyer_email_id=$data['Customer Email'];
    $buyer_mobile_no=$data['Customer Mobile'];
    $buyer_alter_mobile_no=$data['Customer Alter Mobile'];
    $buyer_gstin='';
    $buyer_address_line1=$data['Address Line 1'];
    $buyer_address_line2=$data['Address Line 2'];
    $buyer_country=$data['Address Country'];
    $buyer_state=$data['Address State'];
    $buyer_city=$data['Address City'];
    $buyer_pincode=$data['Address Pincode'];
/*Sender address end*/

/*Receiver address start*/
$buyer_billing_full_name=$data['Billing Customer Name'];
$buyer_billing_email_id=$data['Billing Customer Email'];
$buyer_billing_mobile_no=$data['Billing Customer Mobile'];
$buyer_billing_alter_mobile_no=$data['Billing Customer Alter Mobile'];
$buyer_billing_address_line1=$data['Billing Address Line 1'];
$buyer_billing_address_line2=$data['Billing Address Line 2'];
$buyer_billing_address_country=$data['Billing Address State'];
$buyer_billing_address_state=$data['Billing Address State'];
$buyer_billing_address_city=$data['Billing Address City'];
$buyer_billing_address_pincode=$data['Billing Address Pincode'];
/*Receiver address End*/

/*Pickup & RTO Address Details*/ //Pickup Address Code
$pickup_type='';
$pickup_name='';
$pickup_mobile='';
$pickup_email='';
$pickup_alter_mobile='';
$pickup_address_line1='';
$pickup_address_line2='';
$pickup_pincode='';
$pickup_city='';
$pickup_state='';
$pickup_country='';
$rto_pickup_type='';
$rto_pickup_name='';
$rto_pickup_mobile='';
$rto_pickup_email='';
$rto_pickup_alter_mobile='';
$rto_pickup_address_line1='';
$rto_pickup_address_line2='';
$rto_pickup_pincode='';
$rto_pickup_city='';
$rto_pickup_state='';
$rto_pickup_country='';
$address_id=$data['Pickup Address Code'];
$rto_address_id=0;
/*Pickup & RTO Address Details*/

$statement = $pdo->prepare("SELECT * FROM `pickup_address` WHERE id='$address_id'");
    $statement->execute();
    $res = $statement->fetchAll(PDO::FETCH_ASSOC);
    $num = $statement->rowCount();
    if($num>0){
        $pickup_type=$res[0]['type'];
        $pickup_name=$res[0]['name'];
        $pickup_mobile=$res[0]['mobile'];
        $pickup_email=$res[0]['email'];
        $pickup_alter_mobile=$res[0]['alter_mobile'];
        $pickup_address_line1=$res[0]['address_line1'];
        $pickup_address_line2=$res[0]['address_line2'];
        $pickup_pincode=$res[0]['pincode'];
        $pickup_city=$res[0]['city'];
        $pickup_state=$res[0]['state'];
        $pickup_country=$res[0]['country'];
        
        if(isset($res[0]['rto_address'])){
            $rto_pickup_type=$res[0]['type'];
            $rto_address_id=$res[0]['rto_address'];
            $rto_pickup_name=$res[0]['name'];
            $rto_pickup_mobile=$res[0]['mobile'];
            $rto_pickup_email=$res[0]['email'];
            $rto_pickup_alter_mobile=$res[0]['alter_mobile'];
            $rto_pickup_address_line1=$res[0]['address_line1'];
            $rto_pickup_address_line2=$res[0]['address_line2'];
            $rto_pickup_pincode=$res[0]['pincode'];
            $rto_pickup_city=$res[0]['city'];
            $rto_pickup_state=$res[0]['state'];
            $rto_pickup_country=$res[0]['country'];
        }
    }else{
        $response['error']=true;
        $response['message']='some...';
        print_r($response);
        return 0;
    }
    
    


$vol_length=$data['Length (CM)'];
$vol_breadth=$data['Breadth (CM)'];
$vol_height=$data['Height (CM)'];
$total_applicable_weight=$data['Weight of Shipment (KG)'];



$shipping_charges=0;
$cod_charges=0;
$gift_wrap=0;

$discounts=0;

$send_notification=1;
$comment='';
$location_id=0;
$reseller_name='';
$buyer_company_name='';
$latitude='';
$longitute='';
$verified_order='';
$is_documents='';
$order_type=$data['Payment Method'];
$order_tag='';
$shipment_status='2';
$shipment_date=$order_date;
$client_id=$_POST['client_id'];
$customer_id=0;
$shipment_status_name='Ready To Ship';



$product_sku=$data['Master SKU'];
$product_qty=0;
$product_tax_rate=0;
$product_price=0;
$product_discount=0;
$product_name='';$status_location='';


/*$valus='"'.$uuid.'","'. $order_id.'","'.$carrier_awb_no.'","'.$order_date.'","'.$order_channel.'","'.$order_payment_type.'","'.$buyer_full_name.'","'.$buyer_email_id.'","'.$buyer_mobile_no.'","'.$buyer_alter_mobile_no.'","'.$buyer_gstin.'","'.$buyer_address_line1.'","'.$buyer_address_line2.'","'.$buyer_country.'","'.$buyer_state.'","'.$buyer_city.'","'.$buyer_pincode.'","'.$buyer_billing_address_line1.'","'.$buyer_billing_address_line2.'","'.$buyer_billing_address_country.'","'.$buyer_billing_address_state.'","'.$buyer_billing_address_city.'","'.$buyer_billing_address_pincode.'","'.$shipping_charges.'","'.$cod_charges.'","'.$gift_wrap.'","'.$discounts.'","'.$vol_length.'","'.$vol_breadth.'","'.$vol_height.'","'.$total_applicable_weight.'","'.$send_notification.'","'.$comment.'","'.$location_id.'","'.$reseller_name.'","'.$buyer_company_name.'","'.$latitude.'","'.$longitute.'","'.$verified_order.'","'.$is_documents.'","'.$order_type.'","'.$order_tag.'","'.$shipment_status.'","'.$shipment_date.'","'.$shipment_status.'","'.$shipment_date.'","'.$client_id.'","'.$customer_id.'","'.$shipment_status_name.'","'.$shipment_status_name.'","'.$pickup_type.'","'.$pickup_name.'","'.$pickup_mobile.'","'.$pickup_email.'","'.$pickup_alter_mobile.'","'.$pickup_address_line1.'","'.$pickup_address_line2.'","'.$pickup_pincode.'","'.$pickup_city.'","'.$pickup_state.'","'.$pickup_country.'","'.$rto_pickup_type.'","'.$rto_pickup_name.'","'.$rto_pickup_mobile.'","'.$rto_pickup_email.'","'.$rto_pickup_alter_mobile.'","'.$rto_pickup_address_line1.'","'.$rto_pickup_address_line2.'","'.$rto_pickup_pincode.'","'.$rto_pickup_city.'","'.$rto_pickup_state.'","'.$rto_pickup_country.'","'.$address_id.'","'.$rto_address_id.'"';   
	   
$sql="INSERT INTO `shipment`(
    `uuid`, `order_id`, carrier_awb,`order_date`, `channel_id`, `payment_method`, `cust_firstname`, `cust_email`, `cust_mobile`, `cust_alter_mobile`, 
    `cust_gst`, `shipping_address1`, `shipping_address2`, `shipping_address_country`, `shipping_address_state`, `shipping_address_city`,
    `shipping_address_pincode`, `billing_address1`, `billing_address2`, `billing_address_country`, `billing_address_state`, `billing_address_city`,
    `billing_address_pincode`, `shipping_charges`, `cod_charges`, `gift_wrap_charges`, `total_discount`, `length`, `breath`, `height`, `weight_of_shipment`, 
    `send_notification`, `comment`, `location_id`, `reseller_name`, `company_name`, `latitude`, `longitute`, `verified_order`, `is_documents`,
    `order_type`, `order_tag`, `shipment_status`, `shipment_date`, `shipment_updated_status`, `shipment_updated_date`, `client_id`, `customer_id`,
    `shipment_status_name`, `shipment_updated_status_name`,
    `pickup_type`, `pickup_name`, `pickup_mobile`, `pickup_email`, `pickup_alter_mobile`, `pickup_address_line1`, `pickup_address_line2`, `pickup_pincode`, `pickup_city`, `pickup_state`, `pickup_country`, `rto_pickup_type`, `rto_pickup_name`, `rto_pickup_mobile`, `rto_pickup_email`, `rto_pickup_alter_mobile`, `rto_pickup_address_line1`, `rto_pickup_address_line2`, `rto_pickup_pincode`, `rto_pickup_city`, `rto_pickup_state`, `rto_pickup_country`, `pickup_id`, `rto_pickup_id`)
    
    VALUES ($valus)";*/	   
//error_log('Sql:'.$sql);



	   
	    $statements = $pdo->prepare("INSERT INTO `shipment`(
    `uuid`, `order_id`, carrier_awb,`order_date`, `channel_id`, `payment_method`, `cust_firstname`, `cust_email`, `cust_mobile`, `cust_alter_mobile`, 
    `cust_gst`, `shipping_address1`, `shipping_address2`, `shipping_address_country`, `shipping_address_state`, `shipping_address_city`,
    `shipping_address_pincode`, `billing_address1`, `billing_address2`, `billing_address_country`, `billing_address_state`, `billing_address_city`,
    `billing_address_pincode`, `shipping_charges`, `cod_charges`, `gift_wrap_charges`, `total_discount`, `length`, `breath`, `height`, `weight_of_shipment`, 
    `send_notification`, `comment`, `location_id`, `reseller_name`, `company_name`, `latitude`, `longitute`, `verified_order`, `is_documents`,
    `order_type`, `order_tag`, `shipment_status`, `shipment_date`, `shipment_updated_status`, `shipment_updated_date`, `client_id`, `customer_id`,
    `shipment_status_name`, `shipment_updated_status_name`,
    `pickup_type`, `pickup_name`, `pickup_mobile`, `pickup_email`, `pickup_alter_mobile`, `pickup_address_line1`, `pickup_address_line2`, `pickup_pincode`, `pickup_city`, `pickup_state`, `pickup_country`, `rto_pickup_type`, `rto_pickup_name`, `rto_pickup_mobile`, `rto_pickup_email`, `rto_pickup_alter_mobile`, `rto_pickup_address_line1`, `rto_pickup_address_line2`, `rto_pickup_pincode`, `rto_pickup_city`, `rto_pickup_state`, `rto_pickup_country`, `pickup_id`, `rto_pickup_id`)
    
                VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
      
	    
	$result = $statements->execute(array(
	    $uuid, $order_id,$carrier_awb_no,$order_date,$order_channel,$order_payment_type,$buyer_full_name,$buyer_email_id,$buyer_mobile_no,$buyer_alter_mobile_no,
	    $buyer_gstin,$buyer_address_line1,$buyer_address_line2,$buyer_country,$buyer_state,$buyer_city,
	    $buyer_pincode,$buyer_billing_address_line1,$buyer_billing_address_line2,$buyer_billing_address_country,$buyer_billing_address_state,$buyer_billing_address_city,
	    $buyer_billing_address_pincode,$shipping_charges,$cod_charges,$gift_wrap,$discounts,$vol_length,$vol_breadth,$vol_height,$total_applicable_weight,
	    $send_notification,$comment,$location_id,$reseller_name,$buyer_company_name,$latitude,$longitute,$verified_order,$is_documents,
	    $order_type,$order_tag,$shipment_status,$shipment_date,$shipment_status,$shipment_date,$client_id,$customer_id,
	    $shipment_status_name,$shipment_status_name,
	    $pickup_type,$pickup_name,$pickup_mobile,$pickup_email,$pickup_alter_mobile,$pickup_address_line1,$pickup_address_line2,$pickup_pincode,$pickup_city,$pickup_state,$pickup_country,$rto_pickup_type,$rto_pickup_name,$rto_pickup_mobile,$rto_pickup_email,$rto_pickup_alter_mobile,$rto_pickup_address_line1,$rto_pickup_address_line2,$rto_pickup_pincode,$rto_pickup_city,$rto_pickup_state,$rto_pickup_country,$address_id,$rto_address_id));


            	if($result){
    	    $shipment_id = $pdo->lastInsertId(); 
    	    error_log("ID INSERT ".$shipment_id);
    	    
    	    $product_insert_query="INSERT INTO `shipment_products`(`sku`, `product_name`, `product_qty`, `shipment_id`, `tax`, `selling_price`, `discount`) VALUES ";     
    	        $product_insert_values=array();
                    $product_insert_values[]='("'.$product_sku.'","'.$product_name.'","'.$product_qty.'","'.$shipment_id.'","'.$product_tax_rate.'","'.$product_price.'","'.$product_discount.'")';
                $product_insert_query.= implode(',', $product_insert_values);
            $statement = $pdo->prepare($product_insert_query);   
            $product_result = $statement->execute();
            
            $uuid=$fn->gen_uuid();
            $statement = $pdo->prepare("INSERT INTO `shipment_tracking`( `uuid`, `shipment_id`, `status`, `status_name`,`status_location`, `status_updated_date`)
        VALUES (?,?,?,?,?,?)");
    	$result = $statement->execute(array($uuid, $shipment_id,$shipment_status,$shipment_status_name,$status_location,$shipment_date));
    	
    	$carrier_result_msg='';
                    	/*carrier Call api Start*/
                    	   /* $data=array(
                                'dp_code' => $order_id,
                                'client_id' => '3',
                                'pincode' => $buyer_pincode,
                                'city' => $buyer_city,
                                'state' => $buyer_state,
                                'area_code' => $buyer_city,
                                'customer_name' => $buyer_full_name,
                                'mobile_number' => $buyer_mobile_no,
                                'address' => $buyer_address_line1.' '.$buyer_address_line2,
                                'no_of_box' => '1',
                                'picklist_no' => $order_id,
                                'invoice_value' => '',
                                'weight' => $total_applicable_weight,
                                );
                            $carrier_results=$carrier->expo_speed($data);
                            $carrier_results=json_decode($carrier_results, true);
                            
                            if($carrier_results['status_code']==200){
                                $carrier_result_msg=$carrier_results['message'];
                                $statement = $pdo->prepare("UPDATE `shipment` SET `carrier_awb`=? WHERE id=?");
                                $results = $statement->execute(array($carrier_results['awb_number'],$shipment_id));
                            }else{
                                $carrier_result_msg=$carrier_results['message'];
                            }*/
                    	/*carrier Call api End*/
		    $response['error']=false;
		    $response['message']='shipment uploaded completed...';
            /*$response['header_count']=count($headers);
            $response['record_count']=count($complete);
            $response['data']=json_encode($complete);*/
		}else{
		    $response['error']=true;
		    $response['error']='hi';
		    $response['message']='shipment creating time issues...';
		}
    }//foreach end...
$pdo->commit();
/*$response['error']=false;
		    $response['message']='shipment uploaded completed...';
            $response['header_count']=count($headers);
            $response['header_count']=$headers;
            $response['record_count']=count($complete);
            $response['data']=json_encode($complete);*/

    }catch(Exception $e){
        $response['error']=true;
        $response['error']='his';
        $pdo->rollBack();
        $response['message']='.sd went wrong...'.$e;
        error_log('Ganesan:'.$e);
    }
    print_r($response);
}else{
    $response['error']=true;
    $response['data']='no data found';
    print_r($response);
}
    
?>

Zerion Mini Shell 1.0