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/kamariallee.com/public_html/application/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Summary extends Customer_Controller { function __construct() { parent::__construct(); $this->load->model('cart_model'); $this->load->model('product_m'); $this->load->model('customer_m'); $this->load->library('cart'); $this->load->helper('rajaongkir'); $this->load->library('form_validation'); } public function index($carrier = NULL) { if (!$this->cart->contents()) { $data['message'] = '<p style="background:#564E52; color:white; padding:10px; margin-bottom:100px;">Your cart is empty</p>'; } else { $data['message'] = $this->session->flashdata('message'); $id_customer = (int) $this->session->userdata('customer')['customer_id']; //get customer shipping address detail $data['shipping'] = $this->customer_m->get_shipping($id_customer); //get toc $this->db->select('toc')->from('toc')->where('id_toc', 1); $data['toc'] = $this->db->get()->row(); //check if Tax is active $this->db->select('ppn_active')->from('configuration')->where('id_configuration', 1); $data['tax_active'] = $this->db->get()->row()->ppn_active; //get veritrans fee $this->db->select('veritrans_fee, veritrans_admin, virtualaccount_admin')->from('configuration')->where('id_configuration', 1); $veritrans = $this->db->get()->row(); $veritrans_fee = $veritrans->veritrans_fee; $veritrans_admin = $veritrans->veritrans_admin; $virtualaccount_admin = $veritrans->virtualaccount_admin; $this->session->set_userdata('veritrans_transaction_fee', $veritrans_fee); $this->session->set_userdata('veritrans_admin_fee', $veritrans_admin); $this->session->set_userdata('virtualaccount_admin_fee', $virtualaccount_admin); //if session not exist yet, then initialize new session on bank transfer if (!$this->session->userdata('chosen_payment_type')) { $this->session->set_userdata('chosen_payment_type', 'bank_transfer'); } //calculate shipping fee //get total weight $total_weight_gram = 0; $data['product_grand_total'] = 0; $cart = $this->cart->contents(); foreach ($cart as $item) { $item_id = (int) $item['id']; //get product weight $this->db->select('weight')->from('product_details')->where('product_id', $item_id)->where('sku', $item['options']['sku']); $item_weight = $this->db->get()->row()->weight * $item['qty']; $total_weight_gram = $total_weight_gram + $item_weight; $data['product_grand_total'] = $data['product_grand_total'] + ($item['price'] * $item['qty']); } //get active carrier from configuration table.. $this->db->select('jne_reg, jne_yes, jne_oke, tiki_eco, tiki_reg, tiki_ons, pos_regular, pos_express, rpx_regular, rpx_retail, shop_delivery, shopdelivery_duration, shopdelivery_fee')->from('configuration')->where('id_configuration', 1); $data['active_carrier'] = $this->db->get()->row(); $data['shopdelivery_duration'] = $data['active_carrier']->shopdelivery_duration; //get subdistrict shop ID from configuration table $this->db->select('shop_subdistrict_id')->from('configuration')->where('id_configuration', 1); $shop_subdistrict_id = (int) $this->db->get()->row()->shop_subdistrict_id; //get district shop ID from configuration table (for interantional shipping) $this->db->select('shop_district_id')->from('configuration')->where('id_configuration', 1); $shop_district_id = (int) $this->db->get()->row()->shop_district_id; //get destination country //shipping_id_country 0 is indonesia, else other countries $destination_country_id = (int) $data['shipping']->shipping_id_country; if($destination_country_id == 0) { //shipping to indonesia //shipping to outside indonesia $this->session->set_userdata('carrier', 'jne'); $this->session->set_userdata('carrier_name', 'JNE REGULAR'); //get subdistrict destination ID $destination_subdistrict_id = (int) $data['shipping']->shipping_id_subdistrict; //set shipping switch ($carrier) { case 'jne_regular': $data['total_shipping_fee'] = $this->get_carrier_cost('jne', 'JNE REGULAR', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'REG', 'CTC'); break; case 'jne_yes': $data['total_shipping_fee'] = $this->get_carrier_cost('jne', 'JNE YES', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'YES', 'CTCYES'); break; case 'jne_oke': $data['total_shipping_fee'] = $this->get_carrier_cost('jne', 'JNE OKE', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'OKE'); break; case 'tiki_reg': $data['total_shipping_fee'] = $this->get_carrier_cost('tiki', 'TIKI REGULAR', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'REG'); break; case 'tiki_ons': $data['total_shipping_fee'] = $this->get_carrier_cost('tiki', 'TIKI ONS', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'ONS'); break; case 'tiki_eco': $data['total_shipping_fee'] = $this->get_carrier_cost('tiki', 'TIKI ECO', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'ECO'); break; case 'pos_regular': $data['total_shipping_fee'] = $this->get_carrier_cost('pos', 'POS KILAT KHUSUS', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'Surat Kilat Khusus'); break; case 'pos_express': $data['total_shipping_fee'] = $this->get_carrier_cost('pos', 'POS EXPRESS', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'Express Next Day'); break; case 'rpx_regular': $data['total_shipping_fee'] = $this->get_carrier_cost('rpx', 'RPX REGULAR', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'RGP'); break; case 'rpx_retail': $data['total_shipping_fee'] = $this->get_carrier_cost('rpx', 'RPX RETAIL', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'REP'); break; case 'shop_delivery': $this->session->set_userdata('carrier', 'shop_delivery'); $this->session->set_userdata('carrier_name', 'SHOP DELIVERY'); $data['total_shipping_fee'] = $data['active_carrier']->shopdelivery_fee; break; default: if($this->session->userdata('carrier')) { if($this->session->userdata('carrier_name') == 'JNE REGULAR') { $data['total_shipping_fee'] = $this->get_carrier_cost('jne', 'JNE REGULAR', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'REG', 'CTC'); } elseif($this->session->userdata('carrier_name') == 'JNE YES') { $data['total_shipping_fee'] = $this->get_carrier_cost('jne', 'JNE YES', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'YES', 'CTCYES'); break; } elseif($this->session->userdata('carrier_name') == 'JNE OKE') { $data['total_shipping_fee'] = $this->get_carrier_cost('jne', 'JNE OKE', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'OKE'); break; } elseif($this->session->userdata('carrier_name') == 'TIKI REGULAR') { $data['total_shipping_fee'] = $this->get_carrier_cost('tiki', 'TIKI REGULAR', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'REG'); break; } elseif($this->session->userdata('carrier_name') == 'TIKI ONS') { $data['total_shipping_fee'] = $this->get_carrier_cost('tiki', 'TIKI ONS', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'ONS'); break; } elseif($this->session->userdata('carrier_name') == 'TIKI ECO') { $data['total_shipping_fee'] = $this->get_carrier_cost('tiki', 'TIKI ECO', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'ECO'); break; } elseif($this->session->userdata('carrier_name') == 'POS KILAT KHUSUS') { $data['total_shipping_fee'] = $this->get_carrier_cost('pos', 'POS KILAT KHUSUS', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'Surat Kilat Khusus'); break; } elseif($this->session->userdata('carrier_name') == 'POS EXPRESS') { $data['total_shipping_fee'] = $this->get_carrier_cost('pos', 'POS EXPRESS', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'Express Next Day'); break; } elseif($this->session->userdata('carrier_name') == 'RPX REGULAR') { $data['total_shipping_fee'] = $this->get_carrier_cost('rpx', 'RPX REGULAR', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'RGP'); break; } elseif($this->session->userdata('carrier_name') == 'RPX RETAIL') { $data['total_shipping_fee'] = $this->get_carrier_cost('rpx', 'RPX RETAIL', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'REP'); break; } elseif($this->session->userdata('carrier_name') == 'SHOP DELIVERY') { $this->session->set_userdata('carrier', 'shop_delivery'); $this->session->set_userdata('carrier_name', 'SHOP DELIVERY'); $data['total_shipping_fee'] = $data['active_carrier']->shopdelivery_fee; break; } } else { if($data['active_carrier']->jne_reg == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('jne', 'JNE REGULAR', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'REG', 'CTC'); break; } elseif($data['active_carrier']->jne_yes == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('jne', 'JNE YES', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'YES', 'CTCYES'); break; } elseif($data['active_carrier']->jne_oke == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('jne', 'JNE OKE', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'OKE'); break; } elseif($data['active_carrier']->tiki_reg == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('tiki', 'TIKI REGULAR', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'REG'); break; } elseif($data['active_carrier']->tiki_ons == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('tiki', 'TIKI ONS', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'ONS'); break; } elseif($data['active_carrier']->tiki_eco == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('tiki', 'TIKI ECO', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'ECO'); break; } elseif($data['active_carrier']->pos_regular == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('pos', 'POS KILAT KHUSUS', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'Surat Kilat Khusus'); break; } elseif($data['active_carrier']->pos_express == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('pos', 'POS EXPRESS', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'Express Next Day'); break; } elseif($data['active_carrier']->rpx_regular == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('rpx', 'RPX REGULAR', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'RGP'); break; } elseif($data['active_carrier']->rpx_retail == 1) { $data['total_shipping_fee'] = $this->get_carrier_cost('rpx', 'RPX RETAIL', $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, 'REP'); break; } elseif($data['active_carrier']->shop_delivery == 1) { $this->session->set_userdata('carrier', 'shop_delivery'); $this->session->set_userdata('carrier_name', 'SHOP DELIVERY'); $data['total_shipping_fee'] = $data['active_carrier']->shopdelivery_fee; break; } } } /*----end shipping to indonesia ---*/ } else { //shipping to outside indonesia $this->session->set_userdata('carrier', 'Tiki International'); $this->session->set_userdata('carrier_name', 'Tiki International'); $rajaongkir_cost = get_rajaongkir_ongkos_overseas($shop_district_id, $destination_country_id, $total_weight_gram); /* echo '<pre>'; print_r($rajaongkir_cost); echo '</pre>'; */ //check if weight is zero. If zero, then rajaongkir cannot proceed.. if($total_weight_gram > 0) { if(count($rajaongkir_cost['rajaongkir']['results'][0]['costs']) != 0) { //cost is available because have cost array... foreach($rajaongkir_cost['rajaongkir']['results'][0]['costs'] as $key => $result) { if($result['service'] == 'Paket') { //means paket is available. so use paket price.. $data['total_shipping_fee'] = $result['cost']; break; } else { //means paket is not available, so use dokumen price $data['total_shipping_fee'] = $result['cost']; } } } else { //cost is not available, because cost array is empty.. $data['total_shipping_fee'] = NULL; //service is not available } } else { //total weight gram is zero $data['total_shipping_fee'] = NULL; //service is not available } } //get free shipping min purchase amount from configuration table $this->db->select('free_shipping')->from('configuration')->where('id_configuration', 1); $data['free_shipping'] = $this->db->get()->row()->free_shipping; if ($data['free_shipping'] != NULL) { if ($data['product_grand_total'] >= $data['free_shipping']) { $data['total_shipping_fee'] = 0; } } /* //check if voucher type is free shipping if($this->session->userdata('chosen_voucher_type') == 'free shipping') { $data['total_shipping_fee'] = 0; } */ //CHECK IF DELIVERY ADDRESS IS ALSO JAKARTA, FREE SHIPPING FOR JAKARTA; $this->db->select('free_shipping_jakarta')->from('configuration')->where('id_configuration', 1); $free_shipping_jakarta = $this->db->get()->row()->free_shipping_jakarta; //if province id is 6 (DKI Jakarta), then shipping fee is free //get shipping province id if($free_shipping_jakarta == 'yes') { $this->db->select('shipping_id_province')->from('customers')->where('id_customers', (int) $this->session->userdata('customer')['customer_id']); $destination_province_id = $this->db->get()->row()->shipping_id_province; if($destination_province_id == 6) { $data['total_shipping_fee'] = 0; $data['free_shipping_jakarta'] = 'Free Shipping Jakarta Area'; } } //SET GRAND TOTAL if($data['tax_active'] == 'yes') { //add tax 10% $data['grand_total'] = $data['total_shipping_fee'] + $data['product_grand_total'] + (10/100*$data['product_grand_total']) - $this->session->userdata('chosen_point_discount') ; } else { $data['grand_total'] = $data['total_shipping_fee'] + $data['product_grand_total'] - $this->session->userdata('chosen_point_discount'); } if($this->session->userdata('chosen_voucher_type') == 'amount') { $data['grand_total'] = $data['grand_total'] - $this->session->userdata('chosen_voucher_discount'); $this->session->set_userdata('redeemed_voucher_amount', $this->session->userdata('chosen_voucher_discount')); } elseif($this->session->userdata('chosen_voucher_type') == 'percentage') { $data['grand_total'] = $data['grand_total'] - ($data['product_grand_total'] * $this->session->userdata('chosen_voucher_discount')/100); $this->session->set_userdata('redeemed_voucher_amount', $data['product_grand_total'] * $this->session->userdata('chosen_voucher_discount')/100); } else { //voucher type is free shipping //do nothing... } //get point rewards setting $this->db->select('*')->from('point_rewards')->where('id_point_rewards', 1); $data['point_rewards'] = $this->db->get()->row(); //get customer current point reward $this->db->select('current_pointreward')->from('customers')->where('id_customers', $id_customer); $data['current_point'] = $this->db->get()->row()->current_pointreward; //get payment displaysetting $this->db->select('bank_transfer, credit_card, virtual_account')->from('configuration')->where('id_configuration', 1); $data['payment_display'] = $this->db->get()->row(); } /*---end if(!$this->cart->contents() --*/ //get SEO $this->db->select('website_name, meta_keywords')->from('configuration')->where('id_configuration', 1); $website_name = $this->db->get()->row(); $this->data_header['browser_title'] = ucwords($website_name->website_name) . ' - My Summary'; $this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - My Summary'; $this->data_header['meta_keywords'] = $website_name->meta_keywords; $this->load->view('template/header', $this->data_header); $this->load->view('summary', $data); $this->load->view('template/footer', $this->data_footer); } private function get_carrier_cost($carrier, $carrier_name, $shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, $service_code1, $service_code2 = NULL) { $this->session->set_userdata('carrier', $carrier); $this->session->set_userdata('carrier_name', $carrier_name); $rajaongkir_cost = get_rajaongkir_ongkos($shop_subdistrict_id, $destination_subdistrict_id, $total_weight_gram, $carrier); /* echo '<pre>'; print_r($rajaongkir_cost); echo '</pre>'; */ //check if weight is zero. If zero, then rajaongkir cannot proceed.. if($total_weight_gram > 0) { //check which key has carrier name if($service_code2 != NULL) { if(isset($rajaongkir_cost['rajaongkir'])) { if(count($rajaongkir_cost['rajaongkir']['results'][0]['costs']) != 0) { foreach($rajaongkir_cost['rajaongkir']['results'][0]['costs'] as $key => $result) { if($result['service'] == $service_code1 || $result['service'] == $service_code2) { $total_shipping_fee = $result['cost'][0]['value']; break; } else { $total_shipping_fee = NULL; //service is not available } } } else { $total_shipping_fee = NULL; //service is not available } } else { $total_shipping_fee = NULL; //service is not available } } else { if(count($rajaongkir_cost['rajaongkir']['results'][0]['costs']) != 0) { foreach($rajaongkir_cost['rajaongkir']['results'][0]['costs'] as $key => $result) { if($result['service'] == $service_code1) { $total_shipping_fee = $result['cost'][0]['value']; break; } else { $total_shipping_fee = NULL; //service is not available } } } else { $total_shipping_fee = NULL; //service is not available } } } else { //total weight gram is zero $total_shipping_fee = NULL; //service is not available } return $total_shipping_fee; } public function remove($rowid) { if ($rowid=='all'){ $this->cart->destroy(); } else { $data = array( 'rowid' => $rowid, 'qty' => 0 ); $this->cart->update($data); } redirect('summary'); } public function get_vouchers() { if(!isset($_POST['submit_voucher_code'])) { redirect('summary'); } //validation in action $config = array( array( 'field' => 'voucher_code', 'label' => 'voucher code', 'rules' => 'trim|required|alpha_numeric|callback__check_voucher_code' ), ); $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run($this) == TRUE) { $voucher_code = $this->security->xss_clean($this->input->post('voucher_code')); //get discount type and amount $this->db->select('*')->from('vouchers')->where('voucher_code', $voucher_code); $voucher = $this->db->get()->row(); $this->session->set_userdata('chosen_voucher_code', $voucher->voucher_code); $this->session->set_userdata('chosen_voucher_type', $voucher->discount_type); $this->session->set_userdata('chosen_voucher_discount', $voucher->discount_value); $this->index(); } else { //form validation not pass.. $this->session->unset_userdata('chosen_voucher_code'); $this->session->unset_userdata('chosen_voucher_type'); $this->session->unset_userdata('chosen_voucher_discount'); $this->index(); } } public function _check_voucher_code($str) { //check if input voucher code is really exist $this->db->select('id_vouchers')->from('vouchers')->where('voucher_code', $str); $count_voucher = $this->db->get()->num_rows(); if ($count_voucher == 0) { $this->form_validation->set_message('_check_voucher_code', 'Voucher Code Not Exist!'); return FALSE; } //check if the voucher quantity already empty $this->db->select('qty_ready')->from('vouchers')->where('voucher_code', $str); $qty_ready = $this->db->get()->row()->qty_ready; if ($qty_ready == 0 && $qty_ready != NULL) { $this->form_validation->set_message('_check_voucher_code', 'Voucher Code Used Up!'); return FALSE; } //check if the voucher usage already exceed max customer usage //get max quantity $this->db->select('maxqty_per_person')->from('vouchers')->where('voucher_code', $str); $maxqty_per_person = $this->db->get()->row()->maxqty_per_person; if ($maxqty_per_person != NULL) { //get customer current voucher usage $customer_id = (int) $this->session->userdata('customer')['customer_id']; //get voucher id $this->db->select('id_vouchers')->from('vouchers')->where('voucher_code', $str); $voucher_id = (int) $this->db->get()->row()->id_vouchers; //check on customer voucher_user table, if exist $this->db->select('*')->from('voucher_users')->where('voucher_id', $voucher_id)->where('customer_id', $customer_id); $count_user = $this->db->get()->num_rows(); if ($count_user > 0) { //get current voucher usage $this->db->select('voucher_used')->from('voucher_users')->where('voucher_id', $voucher_id)->where('customer_id', $customer_id); $voucher_used = (int) $this->db->get()->row()->voucher_used; //if the user voucher already exceed max quota if ($voucher_used >= $maxqty_per_person) { $this->form_validation->set_message('_check_voucher_code', 'You have used max allowed no. of vouchers / customer'); return FALSE; } } } //check for minimum order $grand_total_without_shipping = (int) $this->session->userdata('grand_total_without_shipping'); //this value is taken from summary page //get minimum order from voucher table $this->db->select('min_order')->from('vouchers')->where('voucher_code', $str); $min_order = $this->db->get()->row()->min_order; if ($min_order != NULL) { if ($grand_total_without_shipping < (int) $min_order) { $this->form_validation->set_message('_check_voucher_code', 'Sorry Your order amount is not enough'); return FALSE; } } //Check for expired date //get expired date for this voucher $this->db->select('expired_date')->from('vouchers')->where('voucher_code', $str); $expired_date = $this->db->get()->row()->expired_date; if ($expired_date != NULL) { $expired_date_numbers = strtotime($expired_date); $current_date_numbers = strtotime(date('Y-m-d H:i:s')); if ($current_date_numbers > $expired_date_numbers) { $this->form_validation->set_message('_check_voucher_code', 'Sorry Your Voucher Code Already Expired'); return FALSE; } } //get voucher type $this->db->select('voucher_type')->from('vouchers')->where('voucher_code', $str); $voucher_type = $this->db->get()->row()->voucher_type; $customer_id = (int) $this->session->userdata('customer')['customer_id']; switch ($voucher_type) { case 'normal promo': # do nothing... break; case 'birthday promo': //get birthmonth $this->db->select('birthmonth')->from('vouchers')->where('voucher_code', $str); $voucher_birthmonth = (int) $this->db->get()->row()->birthmonth; //get customer birthmonth $this->db->select('birthday')->from('customers')->where('id_customers', $customer_id); $birthday = $this->db->get()->row()->birthday; $birthday_array = explode('-',$birthday); $customer_birthmonth = (int) $birthday_array[1]; if ($voucher_birthmonth != $customer_birthmonth) { $this->form_validation->set_message('_check_voucher_code', 'Sorry It is not Your Birth Month'); return FALSE; } break; case 'gender promo': //get gender $this->db->select('gender')->from('vouchers')->where('voucher_code', $str); $voucher_gender = $this->db->get()->row()->gender; //get customer gender $this->db->select('title')->from('customers')->where('id_customers', $customer_id); $customer_title = $this->db->get()->row()->title; if ($customer_title == 'mr') { $customer_gender = 'male'; } else { $customer_gender = 'female'; } if ($voucher_gender != $customer_gender) { $this->form_validation->set_message('_check_voucher_code', 'Sorry It is not Your Gender'); return FALSE; } break; case 'time promo': //strtotime means convert date string d-m-Y to time froom 1970 unix time //get start promo time $this->db->select('promostart')->from('vouchers')->where('voucher_code', $str); $promostart = strtotime($this->db->get()->row()->promostart); //get end promo time $this->db->select('promoend')->from('vouchers')->where('voucher_code', $str); $promoend = strtotime($this->db->get()->row()->promoend); //get current date and time $currentdatetime = strtotime(date('Y-m-d H:i:s')); if ($currentdatetime > $promostart && $currentdatetime < $promoend) { //time range is correct, promo is valid //do nothing.. } else { //time range is false, so promo is not valid $this->form_validation->set_message('_check_voucher_code', 'Sorry Promo Time expired'); return FALSE; } break; case 'province promo': //get province_id $this->db->select('provincepromo')->from('vouchers')->where('voucher_code', $str); $voucher_province_id = (int) $this->db->get()->row()->provincepromo; //get customer province_id $this->db->select('id_province')->from('customers')->where('id_customers', $customer_id); $customer_province_id = $this->db->get()->row()->id_province; if ($voucher_province_id != $customer_province_id) { $this->form_validation->set_message('_check_voucher_code', 'Sorry It is not Your Province'); return FALSE; } break; case 'quantity promo': //get min quantity at checkout $this->db->select('quantitypromo')->from('vouchers')->where('voucher_code', $str); $voucher_quantitypromo = (int) $this->db->get()->row()->quantitypromo; //get current combined product quantity at cart $cart = $this->cart->contents(); $total_cart_quantity = 0; foreach ($cart as $item) { $total_cart_quantity = $total_cart_quantity + $item['qty']; } if ($total_cart_quantity < $voucher_quantitypromo) { $this->form_validation->set_message('_check_voucher_code', 'Sorry Your Total Cart Quantity not enough'); return FALSE; } break; } return true; } public function choose_payment() { if(!isset($_POST['payment_type'])) { redirect('summary'); } //unset first $this->session->unset_userdata('veritrans_transaction_fee'); $this->session->unset_userdata('veritrans_admin_fee'); $this->session->unset_userdata('virtualaccount_admin_fee'); $payment_type = $this->input->post('payment_type'); if ($payment_type == 'veritrans') { //get veritrans fee $this->db->select('veritrans_fee, veritrans_admin')->from('configuration')->where('id_configuration', 1); $veritrans = $this->db->get()->row(); $veritrans_fee = $veritrans->veritrans_fee; $veritrans_admin = $veritrans->veritrans_admin; $this->session->set_userdata('veritrans_transaction_fee', $veritrans_fee); $this->session->set_userdata('veritrans_admin_fee', $veritrans_admin); //set initial payment type to session $this->session->set_userdata('chosen_payment_type', 'veritrans'); } elseif($payment_type == 'virtualaccount') { //get virtualaccount fee $this->db->select('virtualaccount_admin')->from('configuration')->where('id_configuration', 1); $virtualaccount_admin = $this->db->get()->row()->virtualaccount_admin; $this->session->set_userdata('virtualaccount_admin_fee', $virtualaccount_admin); //set initial payment type to session $this->session->set_userdata('chosen_payment_type', 'virtualaccount'); } else { //set initial payment type to session $this->session->set_userdata('chosen_payment_type', 'bank_transfer'); } $this->index(); } public function get_pointrewards() { if(!isset($_POST['submit_point_rewards'])) { redirect('summary'); } //validation in action $config = array( array( 'field' => 'point_rewards', 'label' => 'point rewards', 'rules' => 'trim|required|numeric|callback__check_point_rewards' ), ); $this->form_validation->set_rules($config); $this->form_validation->set_error_delimiters('<div class="error">', '</div>'); if($this->form_validation->run($this) == TRUE) { $point = (int) $this->security->xss_clean($this->input->post('point_rewards')); //get point rewards setting $this->db->select('*')->from('point_rewards')->where('id_point_rewards', 1); $point_rewards = $this->db->get()->row(); $point_discount = $point * (int) $point_rewards->conversion; $this->session->set_userdata('chosen_point', $point); $this->session->set_userdata('chosen_point_discount', $point_discount); $this->index(); } else { //form validation not pass.. $this->session->unset_userdata('chosen_point'); $this->session->unset_userdata('chosen_point_discount'); $this->index(); } } public function _check_point_rewards($str) { if ($str == 0) { $this->form_validation->set_message('_check_point_rewards', 'Point cannot be empty, 0 or non numbers!'); return FALSE; } //get customer current point reward $this->db->select('current_pointreward')->from('customers')->where('id_customers', (int) $this->session->userdata('customer')['customer_id']); $current_point = $this->db->get()->row()->current_pointreward; if((int) $str > (int) $current_point) { $this->form_validation->set_message('_check_point_rewards', "Point cannot bigger than {$current_point}"); return FALSE; } return TRUE; } }