Server : Apache/2.4.18 (Ubuntu) System : Linux canvaswebdesign 3.13.0-71-generic #114-Ubuntu SMP Tue Dec 1 02:34:22 UTC 2015 x86_64 User : oppastar ( 1041) PHP Version : 7.0.33-0ubuntu0.16.04.15 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority, Directory : /var/www/angkasapuraretail.com/public_html/application/helpers/ |
Upload File : |
<?php //rex get shipping fee function calculate_shipping_fee($shipping_id, $warehouse_id, $item_id, $qty, $shipping_id_subdistrict) { $ci = & get_instance(); //get zip origin $origin_zip = $ci->db->select('postcode')->from('warehouse')->where('id', $warehouse_id)->get()->row()->postcode; //get zip destination $destination_zip = $ci->db->select('postcode')->from('customers')->where('id_customers', (int) $ci->session->userdata('customer')['customer_id'])->get()->row()->postcode; //get product weight $ci->db->select('dimension_weight, dimension_length, dimension_width, dimension_height')->from('products')->where('id_products', $item_id); $product_dimension = $ci->db->get()->row(); $product_weight = $product_dimension->dimension_weight; //gram $product_length = $product_dimension->dimension_length; //cm $product_width = $product_dimension->dimension_width; //cm $product_height = $product_dimension->dimension_height; //cm //check if volume is bigger than weight $volume_weight = $product_length * $product_width * $product_height / 4000; //kg if(($volume_weight * 1000) >= $product_weight) { $weight = $volume_weight * 1000; //gram } else { $weight = $product_weight; //gram } $total_weight = ceil($weight * $qty); //get rex shipping fee.. $customer_id = 'INDOLOK003'; $customer_password = md5('20200825'); $url = 'https://api.rex.co.id/KonosWs/v2/GetRate.aspx'; $ch = curl_init( $url ); # Setup request to send json via POST. $payload = json_encode( array( "customer_id" => $customer_id, "customer_password" => $customer_password, "zip_origin" => $origin_zip, "zip_destination" => $destination_zip, "weight" => $total_weight ) ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); # Return response instead of printing. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); # Send request. $result = json_decode(curl_exec($ch)); curl_close($ch); # Print response. // echo '<pre>'; // print_r($result); // echo '</pre>'; // exit; if($result->error_id && $result->error_id == 402) { $ci->session->set_userdata('rex_tariff_exist', 'no'); } else { $ci->session->set_userdata('rex_tariff_exist', 'yes'); } if($ci->session->userdata('rex_service_name')) { $service_name = $ci->session->userdata('rex_service_name'); } else { $ci->session->set_userdata('rex_service_name', 'REGULAR'); $service_name = 'REGULAR'; } $shipping_fee = 0; $etd = ''; foreach ($result->services as $service) { if($service->service_name == $service_name) { $shipping_fee = $service->finalprice; $etd = $service->etd; break; } } //if chosen rex service is not found on this city ($shipping_fee = 0), then choose other service if($shipping_fee == 0) { foreach ($result->services as $service) { if($service->finalprice && $service->finalprice > 0) { $shipping_fee = $service->finalprice; $etd = $service->etd; $service_name = $ci->session->set_userdata('rex_service_name', $service->service_name); break; } } } $shipping_info = array(); $shipping_info['total_shipping_fee'] = $shipping_fee; $shipping_info['shipping_name'] = "REX $service_name. Etd $etd"; // echo "<pre>"; // print_r($shipping_info); // echo '</pre>'; // exit; //free shipping, if this customer city is the same with warehouse city, then give free shipping// $customer_city_id = $ci->db->select('indah_cargo_id')->from('customers')->where('id_customers', (int) $ci->session->userdata('customer')['customer_id'])->get()->row()->indah_cargo_id; $warehouse_city_id = $ci->db->select('indah_cargo_id')->from('warehouse')->where('id', $warehouse_id)->get()->row()->indah_cargo_id; if($warehouse_city_id == 1) { //warehouse is from jakarta $free_shipping_cites_jakartawarehouse = [1,2,3,4,5,6,24,27]; if(in_array($customer_city_id, $free_shipping_cites_jakartawarehouse)) { $shipping_info['total_shipping_fee'] = 0; } } else { //warehouse is from other place if($customer_city_id == $warehouse_city_id) { $shipping_info['total_shipping_fee'] = 0; } } return $shipping_info; } function rex_generate_awb($data) { $ci = & get_instance(); //generate rex awb.. $customer_id = 'INDOLOK003'; $customer_password = '20200825'; $url = 'https://api.rex.co.id/KonosWs/v1/GenKonos.aspx'; $ch = curl_init( $url ); # Setup request to send json via POST. $payload = json_encode(array( "customer" => array( "id" => $customer_id, "hashed" => md5($customer_id . $data['shipper_postcode'] . $data['receiver_postcode'] . $data['service_code'] . $data['item_weight'] . $customer_password) ), "shipper" => array( "name" => $data['shipper_name'], "address" => $data['shipper_address'], "postcode" => $data['shipper_postcode'], "contact" => $data['shipper_hp'], "email" => $data['shipper_email'], ), "receiver" => array( "name" => $data['receiver_email'], "address" => $data['receiver_address'], "postcode" => $data['receiver_postcode'], "contact" => $data['receiver_hp'], "email" => $data['receiver_email'], ), "detail" => array( "use_insurance" => true, "tracking_ref_no" => $data['id_order'] . '-' . rand(), "items" => array( array( "weight" => $data['item_weight'], "item_desc" => $data['item_desc'], "name" => $data['item_name'], "price" => $data['item_price'], "category" => $data['item_category'], ) ), ), "note" => "", "service_code" => $data['service_code'] )); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); # Return response instead of printing. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); # Send request. $result = json_decode(curl_exec($ch)); $err = curl_error($ch); curl_close($ch); # Print response if ($err) { echo "cURL Error #:" . $err; exit(); } else { // echo'<pre>'; // print_r($result); // echo '</pre>'; // exit; $shipping_awb = array(); $shipping_awb['booking_id'] = $result->booking_id; $shipping_awb['tracking_ref_no'] = $result->tracking_ref_no; return $shipping_awb; } } function rex_tracking_awb($awb) { $ci = & get_instance(); //generate rex awb.. $customer_id = 'INDOLOK003'; $customer_password = md5('20200825'); $url = 'https://api.rex.co.id/KonosWs/v2/CekStatus.aspx'; $ch = curl_init( $url ); # Setup request to send json via POST. $payload = json_encode(array( "customer_id" => $customer_id, "customer_password" => $customer_password, "awb" => $awb )); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); # Return response instead of printing. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); # Send request. $result = json_decode(curl_exec($ch)); $err = curl_error($ch); curl_close($ch); # Print response if ($err) { echo "cURL Error #:" . $err; exit(); } else { // echo'<pre>'; // print_r($result); // echo '</pre>'; return $result; } } function rex_cancel_awb($awb) { $ci = & get_instance(); $customer_id = 'INDOLOK003'; $customer_password = '20200825'; $url = 'https://api.rex.co.id/KonosWs/v1/VoidKonos.aspx'; $ch = curl_init( $url ); # Setup request to send json via POST. $payload = json_encode(array( "cust_id" => $customer_id, "cust_pass" => $customer_password, "cust_hashed" => md5($customer_id . $customer_password . $awb), "awb" => $awb )); curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload ); curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); # Return response instead of printing. curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); # Send request. $result = json_decode(curl_exec($ch)); $err = curl_error($ch); curl_close($ch); # Print response if ($err) { echo "cURL Error #:" . $err; exit(); } else { return $result; } } //indah cargo function calculate_shipping_fee_indahcargo($shipping_id, $warehouse_id, $item_id, $qty, $shipping_id_subdistrict) { /* $test = array( 'shipping_id' => $shipping_id, 'warehouse_id' => $warehouse_id, '$item_id' => $item_id, 'shipping_id_subdistrict' => $shipping_id_subdistrict, ); echo '<pre>'; print_r($test); echo '</pre>'; exit(); */ $ci = & get_instance(); //get product weight $ci->db->select('dimension_weight, dimension_length, dimension_width, dimension_height')->from('products')->where('id_products', $item_id); $product_dimension = $ci->db->get()->row(); $product_weight = $product_dimension->dimension_weight; //gram $product_length = $product_dimension->dimension_length; //cm $product_width = $product_dimension->dimension_width; //cm $product_height = $product_dimension->dimension_height; //cm //check which is bigger, volume or weight //assuming using land transport /* indah cargo destination_price2 for first 11kg. > 11kg, weight x destination_price1. */ //check if volume is bigger than weight $volume_weight = $product_length * $product_width * $product_height / 4000; //kg if(($volume_weight * 1000) >= $product_weight) { $weight = $volume_weight; //kg } else { $weight = $product_weight / 1000; } $total_weight = ceil($weight * $qty); //calculate shipping rate //$rajaongkir_cost = get_rajaongkir_ongkos($warehouse_subdistrict_id, $shipping_id_subdistrict, $total_weight_gram, $shipping_carrier); /* echo '<pre>'; print_r($rajaongkir_cost); echo '</pre>'; exit(); */ //check if weight is zero. If zero, then rajaongkir cannot proceed.. if($total_weight > 0) { //get total weight for indah cargo $ci->db->select('indah_cargo_id')->from('customers')->where('id_customers', $ci->session->userdata('customer')['customer_id']); $indah_cargo = $ci->db->get()->row(); if($indah_cargo->indah_cargo_id != NULL) { $destinaton_id = $indah_cargo->indah_cargo_id; } else { $destinaton_id = 1; } $ci->db->select('destination_price')->from('indah_cargo')->where('id', $destinaton_id); $total_shipping_fee = $ci->db->get()->row()->destination_price * $total_weight; } else { //total weight gram is zero $total_shipping_fee = 0; //service is not available } $shipping_info = array(); $shipping_info['total_shipping_fee'] = $total_shipping_fee; $shipping_info['shipping_name'] = 'Indah Cargo'; return $shipping_info; } function integerToRoman($integer) { // Convert the integer into an integer (just to make sure) $integer = intval($integer); $result = ''; // Create a lookup array that contains all of the Roman numerals. $lookup = array('M' => 1000, 'CM' => 900, 'D' => 500, 'CD' => 400, 'C' => 100, 'XC' => 90, 'L' => 50, 'XL' => 40, 'X' => 10, 'IX' => 9, 'V' => 5, 'IV' => 4, 'I' => 1); foreach($lookup as $roman => $value){ // Determine the number of matches $matches = intval($integer/$value); // Add the same number of characters to the string $result .= str_repeat($roman,$matches); // Set the integer to be the remainder of the integer and the value $integer = $integer % $value; } // The Roman numeral should be built, return it return $result; }