ok
Direktori : /proc/thread-self/root/home2/selectio/www/wedding-info/api/ |
Current File : //proc/thread-self/root/home2/selectio/www/wedding-info/api/shipment-create.php |
<?php include_once('config/config.php'); include_once('config/custom-functions.php'); include 'config/send-sms.php'; $fn = new custom_functions(); include 'carrier-api/api.php'; $carrier = new carrier(); /* ------------------------------------------- APIs for Speedconnect ------------------------------------------- 1.shipment create api ------------------------------------------- */ if(isset($_POST['type']) && $_POST['type']=="create_shipment"){ try{ $pdo->beginTransaction(); if (!isset($_POST['buyer_mobile_no']) || $_POST['buyer_mobile_no']=='') { $response['error'] = true; $response['message'] = "buyer_mobile_no can't be empty!"; print_r(json_encode($response)); return false; exit(); }else if (!isset($_POST['buyer_full_name']) && $_POST['buyer_full_name']==''){ $response['error'] = true; $response['message'] = "buyer_full_name can't be empty!"; print_r(json_encode($response)); return false; exit(); }else if (!isset($_POST['buyer_address_line1']) || $_POST['buyer_address_line1']==''){ $response['error'] = true; $response['message'] = "buyer_address_line can't be empty!"; print_r(json_encode($response)); return false; exit(); }else if (!isset($_POST['buyer_pincode']) || $_POST['buyer_address_line1']==''){ $response['error'] = true; $response['message'] = "buyer_pincode can't be empty!"; print_r(json_encode($response)); return false; exit(); }else if (!isset($_POST['buyer_city']) || $_POST['buyer_address_line1']==''){ $response['error'] = true; $response['message'] = "buyer_city can't be empty!"; print_r(json_encode($response)); return false; exit(); }else if (!isset($_POST['buyer_state']) || $_POST['buyer_address_line1']==''){ $response['error'] = true; $response['message'] = "buyer_state can't be empty!"; print_r(json_encode($response)); return false; exit(); }else if (!isset($_POST['buyer_country']) || $_POST['buyer_address_line1']==''){ $response['error'] = true; $response['message'] = "buyer_country can't be empty!"; print_r(json_encode($response)); return false; exit(); }else if (!isset($_POST['address_id']) || $_POST['buyer_address_line1']==''){ $response['error'] = true; $response['message'] = "address_id can't be empty!"; print_r(json_encode($response)); return false; exit(); } /*Buyer Address Details Start*/ $buyer_mobile_no = (isset($_POST['buyer_mobile_no'])) ? $fn->xss_clean($_POST['buyer_mobile_no']) : ''; $buyer_full_name = (isset($_POST['buyer_full_name'])) ? $fn->xss_clean($_POST['buyer_full_name']) : ''; $buyer_email_id = (isset($_POST['buyer_email_id'])) ? $fn->xss_clean($_POST['buyer_email_id']) : ''; $buyer_alter_mobile_no = (isset($_POST['buyer_alter_mobile_no'])) ? $fn->xss_clean($_POST['buyer_alter_mobile_no']) : ''; $buyer_company_name = (isset($_POST['buyer_company_name'])) ? $fn->xss_clean($_POST['buyer_company_name']) : ''; $buyer_gstin = (isset($_POST['buyer_gstin'])) ? $fn->xss_clean($_POST['buyer_gstin']) : ''; $buyer_address_line1 = (isset($_POST['buyer_address_line1'])) ? $fn->xss_clean($_POST['buyer_address_line1']) : ''; $buyer_address_line2 = (isset($_POST['buyer_address_line2'])) ? $fn->xss_clean($_POST['buyer_address_line2']) : ''; $buyer_pincode = (isset($_POST['buyer_pincode'])) ? $fn->xss_clean($_POST['buyer_pincode']) : ''; $buyer_city = (isset($_POST['buyer_city'])) ? $fn->xss_clean($_POST['buyer_city']) : ''; $buyer_state = (isset($_POST['buyer_state'])) ? $fn->xss_clean($_POST['buyer_state']) : ''; $buyer_country = (isset($_POST['buyer_country'])) ? $fn->xss_clean($_POST['buyer_country']) : ''; /*Buyer Address Details End*/ if(isset($_POST['billing_address_is_same']) || !isset($_POST['buyer_billing_address_mobile_no'])){ /*put here same as buyer address*/ $buyer_billing_address_mobile_no = $buyer_mobile_no; $buyer_billing_address_name = $buyer_full_name; $buyer_billing_email_id = $buyer_email_id; $buyer_billing_address_line1 = $buyer_address_line1; $buyer_billing_address_line2 = $buyer_address_line2; $buyer_billing_address_pincode = $buyer_pincode; $buyer_billing_address_city = $buyer_city; $buyer_billing_address_state = $buyer_state; $buyer_billing_address_country = $buyer_country; }else{ /*Billing Address Details Start*/ $buyer_billing_address_mobile_no = (isset($_POST['buyer_billing_address_mobile_no'])) ? $fn->xss_clean($_POST['buyer_billing_address_mobile_no']) : ''; $buyer_billing_address_name = (isset($_POST['buyer_billing_address_name'])) ? $fn->xss_clean($_POST['buyer_billing_address_name']) : ''; $buyer_billing_email_id = (isset($_POST['buyer_billing_email_id'])) ? $fn->xss_clean($_POST['buyer_billing_email_id']) : ''; $buyer_billing_address_line1 = (isset($_POST['buyer_billing_address_line1'])) ? $fn->xss_clean($_POST['buyer_billing_address_line1']) : ''; $buyer_billing_address_line2 = (isset($_POST['buyer_billing_address_line2'])) ? $fn->xss_clean($_POST['buyer_billing_address_line2']) : ''; $buyer_billing_address_pincode = (isset($_POST['buyer_billing_address_pincode'])) ? $fn->xss_clean($_POST['buyer_billing_address_pincode']) : ''; $buyer_billing_address_city = (isset($_POST['buyer_billing_address_city'])) ? $fn->xss_clean($_POST['buyer_billing_address_city']) : ''; $buyer_billing_address_state = (isset($_POST['buyer_billing_address_state'])) ? $fn->xss_clean($_POST['buyer_billing_address_state']) : ''; $buyer_billing_address_country = (isset($_POST['buyer_billing_address_country'])) ? $fn->xss_clean($_POST['buyer_billing_address_country']) : ''; /*Billing Address Details End*/ } $address_id = (isset($_POST['address_id'])) ? $fn->xss_clean($_POST['address_id']) : 0; $rto_address_id = (isset($_POST['rto_address_id'])) ? $fn->xss_clean($_POST['rto_address_id']) : 0; $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=''; $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_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']) && $res[0]['rto_address']!='' && $res[0]['rto_address']!=0){ $statement = $pdo->prepare("SELECT * FROM `pickup_address` WHERE id='".$res[0]['rto_address']."'"); $statement->execute(); $res = $statement->fetchAll(PDO::FETCH_ASSOC); $num = $statement->rowCount(); if($num){ $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']; } } } /*Order Details Start*/ $order_id = (isset($_POST['order_id'])) ? $fn->xss_clean($_POST['order_id']) : 'XYZ'; $order_date = (isset($_POST['order_date'])) ? $fn->xss_clean($_POST['order_date']) : ''; $order_channel = (isset($_POST['order_channel'])) ? $fn->xss_clean($_POST['order_channel']) : ''; $order_tag = (isset($_POST['order_tag'])) ? $fn->xss_clean($_POST['order_tag']) : ''; $reseller_name = (isset($_POST['reseller_name'])) ? $fn->xss_clean($_POST['reseller_name']) : ''; if($order_id==''){$order_id='12345678';} /*Order Details End*/ /*Multiple Product Details Start*/ $product_name=array(); $product_qty=array(); $product_price=array(); $product_category=array(); $product_hsncode=array(); $product_sku=array(); $product_tax_rate=array(); $product_discount=array(); if(isset($_POST['product_name'])){ for($p=0;$p<count($_POST['product_name']);$p++){ $product_name[] = (isset($_POST['product_name'][$p])) ? $fn->xss_clean($_POST['product_name'][$p]) : ''; $product_price[] = (isset($_POST['unit_price'][$p])) ? $fn->xss_clean($_POST['unit_price'][$p]) : ''; $product_qty[] = (isset($_POST['quantity'][$p])) ? $fn->xss_clean($_POST['quantity'][$p]) : ''; $product_category[] = (isset($_POST['product_category'][$p])) ? $fn->xss_clean($_POST['product_category'][$p]) : ''; $product_hsncode[] = (isset($_POST['hsn_code'][$p])) ? $fn->xss_clean($_POST['hsn_code'][$p]) : ''; $product_sku[] = (isset($_POST['sku'][$p])) ? $fn->xss_clean($_POST['sku'][$p]) : ''; $product_tax_rate[] = (isset($_POST['tax_rate'][$p])) ? $fn->xss_clean($_POST['tax_rate'][$p]) : ''; $product_discount[] = (isset($_POST['product_discount'][$p])) ? $fn->xss_clean($_POST['product_discount'][$p]) : ''; } } /*Multiple Product Details End*/ $order_payment_type = (isset($_POST['order_payment_type'])) ? $fn->xss_clean($_POST['order_payment_type']) : ''; $shipping_charges = (isset($_POST['shipping_charges'])) ? $fn->xss_clean($_POST['shipping_charges']) : '0'; $cod_charges = (isset($_POST['cod_charges'])) ? $fn->xss_clean($_POST['cod_charges']) : '0'; $gift_wrap = (isset($_POST['gift_wrap'])) ? $fn->xss_clean($_POST['gift_wrap']) : '0'; $transaction_fee = (isset($_POST['transaction_fee'])) ? $fn->xss_clean($_POST['transaction_fee']) : '0'; $discounts = (isset($_POST['discounts'])) ? $fn->xss_clean($_POST['discounts']) : '0'; /*Package Details Start*/ $dead_weight = (isset($_POST['dead_weight'])) ? $fn->xss_clean($_POST['dead_weight']) : '0'; $vol_length = (isset($_POST['vol_length'])) ? $fn->xss_clean($_POST['vol_length']) : '0'; $vol_breadth = (isset($_POST['vol_breadth'])) ? $fn->xss_clean($_POST['vol_breadth']) : '0'; $vol_height = (isset($_POST['vol_height'])) ? $fn->xss_clean($_POST['vol_height']) : '0'; $total_vol_weight = (isset($_POST['total_vol_weight'])) ? $fn->xss_clean($_POST['total_vol_weight']) : '1200'; $total_applicable_weight = (isset($_POST['total_applicable_weight'])) ? $fn->xss_clean($_POST['total_applicable_weight']) : '1250'; /*Package Details End*/ $client_id =(isset($_POST['client_id'])) ? $fn->xss_clean($_POST['client_id']) : "1"; /*Extra Parameter Start*/ $send_notification =(isset($_POST['send_notification'])) ? $fn->xss_clean($_POST['send_notification']) : "1"; $comment =(isset($_POST['comment'])) ? $fn->xss_clean($_POST['comment']) : ""; $location_id =(isset($_POST['location_id'])) ? $fn->xss_clean($_POST['location_id']) : "1"; $latitude =(isset($_POST['latitude'])) ? $fn->xss_clean($_POST['latitude']) : ""; $longitute =(isset($_POST['longitute'])) ? $fn->xss_clean($_POST['longitute']) : ""; $verified_order =(isset($_POST['verified_order'])) ? $fn->xss_clean($_POST['verified_order']) : ""; $is_documents =(isset($_POST['is_documents'])) ? $fn->xss_clean($_POST['is_documents']) : ""; $order_type =(isset($_POST['order_type'])) ? $fn->xss_clean($_POST['order_type']) : ""; $shipment_status=2; $shipment_status_name='Ready To Ship'; $shipment_date=date("Y-m-d"); $customer_id =(isset($_POST['customer_id'])) ? $fn->xss_clean($_POST['customer_id']) : "1"; $status_location =(isset($_POST['status_location'])) ? $fn->xss_clean($_POST['status_location']) : ""; $carrier_awb_no="SPC2023".str_pad($fn->get_ai_id($pdo,'shipment'), 0, '0', STR_PAD_LEFT); /*Extra Parameter Start*/ $uuid=$fn->gen_uuid(); $statement = $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 = $statement->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(); $product_insert_query="INSERT INTO `shipment_products`(`sku`, `product_name`, `product_qty`, `shipment_id`, `tax`, `selling_price`, `discount`) VALUES "; if(count($product_name)>0){ $product_insert_values=array(); for($p=0;$p<count($product_name);$p++){ $product_insert_values[]='("'.$product_sku[$p].'","'.$product_name[$p].'","'.$product_qty[$p].'","'.$shipment_id.'","'.$product_tax_rate[$p].'","'.$product_price[$p].'","'.$product_discount[$p].'")'; } $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 details added successfuly $carrier_result_msg"; }else{ $response['error']=true; $response['message']='shipment creating time issues...'; } $pdo->commit(); echo json_encode($response); }catch(Exception $e){ $response['error']=true; $response['message']='something went wrong try again...'; $pdo->rollBack(); echo json_encode($response); } } ?>