https://t.me/RX1948
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/kamariallee.com/public_html/application/controllers/Summary_guest.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Summary_guest extends Public_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()) 
			{ 
					redirect('cart');
			} 

      if (!$this->session->userdata('shipping_details')) 
			{ 
					redirect('shipping_guest');
			} 
  
      //calculate subtotals
      $data['subtotals'] = 0;
      foreach($this->cart->contents() as $item)
      {
          $data['subtotals'] = $data['subtotals'] + $item['subtotal'];

          if(isset($item['options']['greetingcard_price_int']))
          {
            $data['subtotals'] = $data['subtotals'] + $item['options']['greetingcard_price_int'];
          }

          if(isset($item['options']['chosenHeelsTypePrice']))
          {
            $data['subtotals'] = $data['subtotals'] +  ($item['qty'] * $item['options']['chosenHeelsTypePrice']);
          }

          if(isset($item['options']['chosenHeelsHeightPrice']))
          {
            $data['subtotals'] = $data['subtotals'] +  ($item['qty'] * $item['options']['chosenHeelsHeightPrice']);
          } 

          if(isset($item['options']['chosenPlatformStylePrice']))
          {
            $data['subtotals'] = $data['subtotals'] +  ($item['qty'] * $item['options']['chosenPlatformStylePrice']);
          }

          if(isset($item['options']['chosenPlatformHeightPrice']))
          {
            $data['subtotals'] = $data['subtotals'] +  ($item['qty'] * $item['options']['chosenPlatformHeightPrice']);
          }

          if(isset($item['options']['chosenInitialEngravedPrice']))
          {
            $data['subtotals'] = $data['subtotals'] +  ($item['qty'] * $item['options']['chosenInitialEngravedPrice']);
          }
      } 
    
      $data['shipping'] = $this->session->userdata('shipping_details');

      //calculate shipping fee
      //get total weight
      $total_weight_gram = 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; 
      }

      //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; 

      //shipping to indonesia
      //shipping to outside indonesia
      // $this->session->set_userdata('carrier', 'jne');  
      // $this->session->set_userdata('carrier_name', 'JNE REGULAR');  

			if($data['shipping']['shipping_id_province'] == 6)
			{
					$carrier = 'jne_yes';
					$data['carrier_name_text'] = 'JNE YES';    
			}
			else
			{
					$carrier = 'jne_regular';
					$data['carrier_name_text'] = '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; 
            }	
          }		
      } 

			//check if product has international custom order, then shipping fee == 0
			$cart = $this->cart->contents();

			$international_custom_shipping = false;

      foreach ($cart as $item) 
      {    
          //get product international_custom_order status
          $this->db->select('international_custom_order')->from('products')->where('id_products', (int) $item['id']);
          $is_international = $this->db->get()->row()->international_custom_order;

					if($is_international == 'yes') 
					{
						$international_custom_shipping = true;
						break;
					}
      }

			if($international_custom_shipping)
			{
					$data['total_shipping_fee'] = 0;
			}

      $data['grand_total'] = $data['subtotals']  + $data['total_shipping_fee'] - $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 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_guest', $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>'; 
			// exit;

			//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 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;
	}

  //cart add quantity from summary page
  public function add_quantity($rowid)
  {
      $requested_qty = 0;
      $stock_enough = TRUE;

      foreach($this->cart->contents() as $item)
      {
          if($item['rowid'] == $rowid)
          {
              $requested_qty = $item['qty'] + 1;

              //check current stock
              $product_detail = $this->db->select('stock')->from('product_details')->where('product_id', $item['id'])->where('sku', $item['options']['sku'])->get()->row_array();

              if($product_detail['stock'] < $requested_qty)
              {
                  $stock_enough = FALSE;
              }
              
              break;
          }
      }

      if(!$stock_enough)
      {
          $this->session->set_flashdata('message', "Stock not enough");
          redirect(base_url('summary_guest')); 
      }

      $data_cart = array(
          'rowid'   => $rowid,
          'qty'     => $requested_qty
      );

      $this->cart->update($data_cart);

      redirect(base_url('summary_guest')); 
  }

  //cart remove quantity from summary page 
  public function remove_quantity($rowid)
  {
      $requested_qty = 0;
      $stock_enough = TRUE;

      foreach($this->cart->contents() as $item)
      {
          if($item['rowid'] == $rowid)
          {
              $requested_qty = $item['qty'] - 1;

              //check current stock
              $product_detail = $this->db->select('stock')->from('product_details')->where('product_id', $item['id'])->where('sku', $item['options']['sku'])->get()->row_array();

              if($product_detail['stock'] < $requested_qty)
              {
                  $stock_enough = FALSE;
              }
              
              break;
          }
      }

      if(!$stock_enough)
      {
          $this->session->set_flashdata('message', "Stock not enough");
          redirect(base_url('summary_guest')); 
      }

      $data_cart = array(
          'rowid'   => $rowid,
          'qty'     => $requested_qty
      );

      $this->cart->update($data_cart);

      redirect(base_url('summary_guest')); 
  }

  public function remove($rowid) 
	{
		if ($rowid=="all") {
				$this->cart->destroy();
		}
		else
		{
				$data = array(
					'rowid'   => $rowid,
					'qty'     => 0
				);

				$this->cart->update($data);
		}
		
		redirect('summary_guest');
	}	
}

https://t.me/RX1948 - 2025