|
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/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Shipping extends Customer_Controller {
private $last_tracking_warehouse;
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->helper('shipping');
$this->load->library('form_validation');
}
public function index() {
$this->session->unset_userdata('birthday_promo_percentage');
$this->session->unset_userdata('birthday_promo_amount');
$id_customer = (int) $this->session->userdata('customer')['customer_id'];
//get customer type
$this->db->select('type')->from('customers')->where('id_customers', $id_customer);
$customer_type = $this->db->get()->row()->type;
//calculate birthday promo
$birthdaypromo_config = $this->db->select('birthdaypromo_active, birthdaypromo_productids')->from('configuration')->where('id_configuration', 1)->get()->row();
if($birthdaypromo_config->birthdaypromo_active == 'yes' && $customer_type == 'regular') {
//promo is active
$customer_ktp = $this->db->select('ktp')->from('customers')->where('id_customers', $id_customer)->get()->row()->ktp;
if(!empty($customer_ktp)) {
//ktp exist, get customer birthday
$subktpstr = substr($customer_ktp, 6); //remove 6 strings from start
$subktpstr2 = substr($subktpstr, 0, -4); //remove 4 string from end
$birthdate = (int) substr($subktpstr2, 0, 2);
//check if male or female
if($birthdate > 31) {
//female
$birthdate = $birthdate - 40; //deduct 40 for female
}
$birthmonth = (int) substr($subktpstr2, 2, 2);
$birthyear = (int) substr($subktpstr2, 4, 2);
//get current month, and check if the same with customer birth month
$current_month = (int) date('m');
if($current_month == $birthmonth) {
//customer is eligible to get discount, but need to check if cart has eligible product ids
$birthdaypromo_productids = explode(',', $birthdaypromo_config->birthdaypromo_productids);
$total_amount_promo = 0;
foreach($this->cart->contents() as $item) {
if (in_array($item['id'], $birthdaypromo_productids)) {
//product is eligible for promo
$total_amount_promo += $item['subtotal'];
}
}
if($birthyear > 99) {
$birthyearfull = '20' . $birthyear;
} else {
$birthyearfull = '19' . $birthyear;
}
$customer_age = (int) date('Y') - (int) $birthyearfull;
if($customer_age > 17) {
if($customer_age > 50) {
$view_data['birthday_promo_percentage'] = 50;
$view_data['birthday_promo_amount'] = $total_amount_promo * 50/100;
} else {
$view_data['birthday_promo_percentage'] = $customer_age;
$view_data['birthday_promo_amount'] = $total_amount_promo * $customer_age/100;
}
}
$this->session->set_userdata('birthday_promo_percentage', $view_data['birthday_promo_percentage']);
$this->session->set_userdata('birthday_promo_amount', $view_data['birthday_promo_amount']);
}
} else {
//ktp empty, customer need to add ktp details
$this->session->unset_userdata('birthday_promo_percentage');
$this->session->unset_userdata('birthday_promo_amount');
}
}
//get all cities
$this->db->select('destination_city, id')->from('indah_cargo')->order_by('destination_city', 'ASC');
$view_data['cities'] = $this->db->get()->result();
//get all cities of Indah Cargo
$this->db->select('destination_city, id, destination_province')->from('indah_cargo')->order_by('destination_city', 'ASC');
$view_data['indahcargo_cities'] = $this->db->get()->result();
//SHIPPING PROVINCE, DISTRICT, SUBDISTRICT
//get customer shipping address detail
//SHIPPING PROVINCE, DISTRICT, SUBDISTRICT
//get customer shipping address detail
$view_data['shipping'] = $this->customer_m->get_shipping($id_customer);
//get all provinces data from provinces table
$this->db->select('rajaongkir_province_id, province')->from('indonesia_provinces')->order_by('rajaongkir_province_id', 'ASC');
$view_data['shipping_provinces'] = $this->db->get()->result();
$current_shipping_province_id = $view_data['shipping']->shipping_id_province;
//get all initial shipping districts based on stored province
$this->db->select('rajaongkir_id_district, district')->from('indonesia_districts')->where('indonesia_id_province', $current_shipping_province_id);
$view_data['shipping_district_lists'] = $this->db->get()->result();
$current_shipping_district_id = $view_data['shipping']->shipping_id_district;
//get all initial shipping subdistricts lists
$this->db->select('rajaongkir_id_subdistrict, subdistrict')->from('indonesia_subdistricts')->where('indonesia_id_district', $current_shipping_district_id);
$view_data['shipping_subdistrict_lists'] = $this->db->get()->result();
//unset voucher, shipping fee session
$this->session->unset_userdata('chosen_voucher_code');
$this->session->unset_userdata('chosen_voucher_type');
$this->session->unset_userdata('chosen_voucher_discount');
$this->session->unset_userdata('total_categoryproduct_promo');
$this->session->unset_userdata('total_brandproduct_promo');
$this->session->unset_userdata('redeemed_voucher_amount');
$this->session->unset_userdata('total_shipping_fee');
//$this->session->unset_userdata('free_shipping');
$this->session->unset_userdata('add_point_reward');
$this->session->unset_userdata('chosen_point');
$this->session->unset_userdata('chosen_point_discount');
$this->session->unset_userdata('shipping_cart');
$view_data['final_total_shipping_fee'] = 0;
// echo '<pre>';
// print_r($this->cart->contents());
// echo '</pre>';
// exit;
foreach ($this->cart->contents() as $item) {
//check if this item has indent
if($item['option']['is_backorder'] == 'yes') {
//check for in stock product
$current_stock = $this->db->select('stock')->from('stock')->where('id_product', $item['id'])->where('warehouse_id', $item['option']['warehouse_id'])->get()->row()->stock;
$indent_stock = $item['qty'] - $current_stock;
//create shipping cart for in stock
if($current_stock > 0) {
//need to check initial shipping fee
$shipping_info = calculate_shipping_fee('', $item['option']['warehouse_id'], $item['id'], $current_stock, '');
$total_shipping_fee = $shipping_info['total_shipping_fee'];
$shipping_cart = $this->session->userdata('shipping_cart');
$shipping_cart[uniqid()] = array(
'id' => $item['id'],
'name' => $item['name'],
'qty' => $current_stock,
'price' => $item['price'],
'subtotal' => $item['price'] * $current_stock,
'warehouse_name' => $item['option']['warehouse_name'],
'warehouse_id' => $item['option']['warehouse_id'],
'shipping_method_ids' => 3,
'chosen_shipping_id' => 3,
'shipping_fee' => $total_shipping_fee,
'is_backorder' => 'no',
'is_flashsale' => NULL,
'is_sale' => FALSE
);
$this->session->set_userdata('shipping_cart', $shipping_cart);
$view_data['final_total_shipping_fee'] = $view_data['final_total_shipping_fee'] + $total_shipping_fee;
}
//create shipping cart for indent
//need to check initial shipping fee
$shipping_info = calculate_shipping_fee('', $item['option']['warehouse_id'], $item['id'], $indent_stock, '');
$total_shipping_fee = $shipping_info['total_shipping_fee'];
$shipping_cart = $this->session->userdata('shipping_cart');
$shipping_cart[uniqid()] = array(
'id' => $item['id'],
'name' => $item['name'],
'qty' => $indent_stock,
'price' => $item['price'],
'subtotal' => $item['price'] * $indent_stock,
'warehouse_name' => $item['option']['warehouse_name'],
'warehouse_id' => $item['option']['warehouse_id'],
'shipping_method_ids' => 3,
'chosen_shipping_id' => 3,
'shipping_fee' => $total_shipping_fee,
'is_backorder' => 'yes',
'is_flashsale' => NULL,
'is_sale' => FALSE
);
$this->session->set_userdata('shipping_cart', $shipping_cart);
$view_data['final_total_shipping_fee'] = $view_data['final_total_shipping_fee'] + $total_shipping_fee;
} else {
//need to check initial shipping fee
$shipping_info = calculate_shipping_fee('', $item['option']['warehouse_id'], $item['id'], $item['qty'], '');
$total_shipping_fee = $shipping_info['total_shipping_fee'];
$shipping_cart = $this->session->userdata('shipping_cart');
$shipping_cart[uniqid()] = array(
'id' => $item['id'],
'name' => $item['name'],
'qty' => $item['qty'],
'price' => $item['price'],
'subtotal' => $item['price'] * $item['qty'],
'warehouse_name' => $item['option']['warehouse_name'],
'warehouse_id' => $item['option']['warehouse_id'],
'shipping_method_ids' => 3,
'chosen_shipping_id' => 3,
'shipping_fee' => $total_shipping_fee,
'is_backorder' => 'no',
'is_flashsale' => NULL,
'is_sale' => FALSE
);
$this->session->set_userdata('shipping_cart', $shipping_cart);
$view_data['final_total_shipping_fee'] = $view_data['final_total_shipping_fee'] + $total_shipping_fee;
}
}
//store total shipping fee into session
$this->session->set_userdata('total_shipping_fee', $view_data['final_total_shipping_fee']);
//get SEO
$this->data_header['browser_title'] = ucwords($this->data_header['website_name']) . ' - Shipping';
$this->data_header['meta_description'] = ucwords($this->data_header['website_name']) . ' - Shipping';
$this->load->view("themes/$this->theme_no/header", $this->data_header);
$this->load->view('shipping', $view_data);
$this->load->view("themes/$this->theme_no/footer", $this->data_footer);
}
public function save_shipping() {
if(!isset($_POST['indah_cargo_id'])) { redirect('shipping'); }
//from regular customer shipping
//save shipping id
$data = array(
'indah_cargo_id' => $this->input->post('indah_cargo_id'),
'postcode' => ''
);
$this->db->where('id_customers', $this->session->userdata('customer')['customer_id']);
$this->db->update('customers', $data);
redirect('shipping');
}
public function save_postcode() {
if(!isset($_POST['shipping_postcode'])) { redirect('shipping'); }
//from regular customer shipping
//save postcode
$data = array(
'postcode' => $this->input->post('shipping_postcode')
);
$this->db->where('id_customers', $this->session->userdata('customer')['customer_id']);
$this->db->update('customers', $data);
redirect('shipping');
}
public function save_kurir() {
if(!isset($_POST['choosekurir'])) { redirect('shipping'); }
$this->session->set_userdata('rex_service_name', $this->input->post('choosekurir'));
redirect('shipping');
}
public function get_vouchers() {
if(!isset($_POST['submit_voucher_code'])) { redirect('shipping'); }
//unset this userdata if user enter other voucher code than category or brand product code
$this->session->unset_userdata('total_categoryproduct_promo');
$this->session->unset_userdata('total_brandproduct_promo');
//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', (int) $voucher->discount_value);
if($voucher->voucher_type == 'category promo') {
if($voucher->discount_type == 'percentage') {
//discount type by percentage..here need to calculate discount for specific products whose categories are matched only..
$discount_rate = $voucher->discount_value;
//get categories id from voucher code
$this->db->select('categorypromo')->from('vouchers')->where('voucher_code', $voucher_code);
$categories = $this->db->get()->row()->categorypromo;
$categories_array = explode(',', $categories);
//get current cart content
$cart = $this->cart->contents();
$total_amount_promoted_categories = 0;
foreach ($cart as $item) {
//check if this item has category which is match with $categories_array
$this->db->select('id_category')->from('category_product')->where('id_product', $item['id']);
$categories_id = $this->db->get()->result();
$count_category_id = 0;
foreach($categories_id as $category_id) {
if(in_array($category_id->id_category, $categories_array)) {
$count_category_id = $count_category_id + 1;
}
}
if($count_category_id > 0) {
//this $item has category which is match with $categories_array, so we can add to percentage discounts
$total_amount_promoted_categories = $total_amount_promoted_categories + ($item['price'] * $item['qty'] * $discount_rate / 100);
}
}
$this->session->set_userdata('total_categoryproduct_promo', (int) $total_amount_promoted_categories);
}
}
if($voucher->voucher_type == 'brand promo') {
if($voucher->discount_type == 'percentage') {
//discount type by percentage..here need to calculate discount for specific products whose brands are matched only..
$discount_rate = $voucher->discount_value;
//get brands id from voucher code
$this->db->select('brandpromo')->from('vouchers')->where('voucher_code', $voucher_code);
$brands = $this->db->get()->row()->brandpromo;
$brands_array = explode(',', $brands);
//get current cart content
$cart = $this->cart->contents();
$total_amount_promoted_brands = 0;
foreach ($cart as $item) {
//check if this item has brand which is match with $brands_array
$this->db->select('brand_id')->from('products')->where('id_products', $item['id']);
$brand_id = $this->db->get()->row()->brand_id;
if(in_array($brand_id, $brands_array)) {
//this $item has brand which is match with $brands_array, so we can add to percentage discounts
$total_amount_promoted_brands = $total_amount_promoted_brands + ($item['price'] * $item['qty'] * $discount_rate / 100);
}
}
$this->session->set_userdata('total_brandproduct_promo', (int) $total_amount_promoted_brands);
}
}
$this->session->set_flashdata('summary_message', 'VOUCHER CODE REDEEMED');
$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->session->unset_userdata('total_categoryproduct_promo');
$this->session->unset_userdata('total_brandproduct_promo');
$this->session->unset_userdata('redeemed_voucher_amount');
$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;
case 'category promo':
//get categories id from voucher code
$this->db->select('categorypromo')->from('vouchers')->where('voucher_code', $str);
$categories = $this->db->get()->row()->categorypromo;
$categories_array = explode(',', $categories);
//get current cart content
$cart = $this->cart->contents();
$count_category_exist = 0;
foreach ($cart as $item) {
//get category_id from each item
$this->db->select('id_category')->from('category_product')->where('id_product', $item['id']);
$products_category = $this->db->get()->result();
foreach($products_category as $category_item) {
if(in_array($category_item->id_category, $categories_array)) {
$count_category_exist = $count_category_exist + 1;
}
}
}
if($count_category_exist == 0) {
$this->form_validation->set_message('_check_voucher_code', 'Sorry You did not choose Products with Promoted Category');
return FALSE;
}
break;
case 'brand promo':
//get brands id from voucher code
$this->db->select('brandpromo')->from('vouchers')->where('voucher_code', $str);
$brands = $this->db->get()->row()->brandpromo;
$brands_array = explode(',', $brands);
//get current cart content
$cart = $this->cart->contents();
$count_brand_exist = 0;
foreach ($cart as $item) {
//get brand_id from each item
$this->db->select('brand_id')->from('products')->where('id_products', $item['id']);
$product_brand_id = $this->db->get()->row()->brand_id;
if(in_array($product_brand_id, $brands_array)) {
$count_brand_exist = $count_brand_exist + 1;
}
}
if($count_brand_exist == 0) {
$this->form_validation->set_message('_check_voucher_code', 'Sorry You did not choose Products with Promoted Brand');
return FALSE;
}
break;
case 'product promo':
//get voucherproduct id
$product_id = $this->db->select('product_id')->from('voucers')->where('voucher_code', $str)->get()->row()->product_id;
//check if current cart has product_id
$count_product_exist = 0;
foreach ($cart as $item) {
if($item['id'] == $product_id) {
$count_product_exist = 1;
}
}
if($count_product_exist == 0) {
$this->form_validation->set_message('_check_voucher_code', 'Sorry You did not choose promoted product');
return FALSE;
}
break;
}
return true;
}
public function generate_penawaran_pdf() {
//add PDF attachment DOMPDF
$data['title'] = 'Surat Penawaran Harga';
//get customer detail
$this->db->select('*')->from('customers')->where('id_customers', $this->session->userdata('customer')['customer_id']);
$pdf_data['customer'] = $this->db->get()->row();
//get current month ij roman
$pdf_data['current_month'] = integerToRoman(date('n'));
//get current year 2 digits
$pdf_data['current_year'] = date('y');
$subtotal = 0;
foreach($this->session->userdata('shipping_cart') as $cart) {
$subtotal = $subtotal + ($cart['qty'] * $cart['price']);
}
//insert into penawaran harga table and get the id
$data = array(
'customer_id' => $pdf_data['customer']->id_customers,
'employee_id' => $this->session->userdata('chosen_sales_id'),
'cart_array' => serialize($this->session->userdata('shipping_cart')),
'sales_id' => $this->session->userdata('chosen_sales_id'),
'total_shipping_fee' => $this->session->userdata('total_shipping_fee'),
'free_shipping' => $this->session->userdata('free_shipping'),
'ppn' => $this->session->userdata('tax'),
'sub_total' => $subtotal
);
if($this->session->userdata('redeemed_voucher_amount')) {
$data['redeemed_voucher_amount'] = $this->session->userdata('redeemed_voucher_amount');
}
if($this->session->userdata('chosen_point_discount')) {
$data['minus_reward_amount'] = $this->session->userdata('chosen_point_discount');
}
$this->db->insert('penawaran_harga', $data);
$pdf_data['penawaran_id'] = $this->db->insert_id();
//insert into penawaran harga table and get the id
$data_update = array(
'no_penawaran_harga' => 'IBU/' . $pdf_data['current_month'] . '/'. $pdf_data['current_year'] . '/ECM/' . $pdf_data['penawaran_id'],
);
$this->db->where('id', $pdf_data['penawaran_id']);
$this->db->update('penawaran_harga', $data_update);
//create session for penawaran_id
$this->session->set_userdata('penawaran_harga_id', $pdf_data['penawaran_id']);
//get sales person data
$this->db->select('*')->from('sales_list')->where('employee_id', $this->session->userdata('chosen_sales_id'));
$pdf_data['sales_data'] = $this->db->get()->row();
$this->load->library('dompdf_gen');
$html = $this->load->view('penawaran_pdf', $pdf_data ,true);
/*tambahan*/
$html = preg_replace('/>\s+</', '><', $html);
/*tambahan*/
$this->dompdf->load_html($html);
$this->dompdf->set_paper('A4', 'portrait');
$this->dompdf->render();
$this->dompdf->stream('penawaran_harga.pdf', array("Attachment" => 0));
$output = $this->dompdf->output();
$file_to_save = 'uploads/pdf/penawaran_harga.pdf';
file_put_contents($file_to_save, $output);
//get website data
$this->db->select('logo, from_email, website_name, email_smtp_host, email_smtp_port, email_smtp_password, email_smtp')->from('configuration')->where('id_configuration', 1);
$website_data = $this->db->get()->row();
$data_pdf['logo'] = $website_data->logo;
$data_pdf['website_name'] = $website_data->website_name;
//----SEND EMAIL TO CUSTOMER
$this->load->library('email');
//get email setting
$config['protocol'] = 'smtp';
$config['smtp_host'] = $website_data->email_smtp_host;
$config['smtp_port'] = $website_data->email_smtp_port;
$config['smtp_user'] = $website_data->email_smtp;
$config['smtp_pass'] = $website_data->email_smtp_password;
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;
$config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard
$this->email->set_crlf( "\r\n" ); //must add this for hotmail
$this->email->initialize($config);
$this->email->from('ecommerce@indolok.id', $website_data->website_name);
$this->email->to($pdf_data['customer']->email);
$this->email->cc($pdf_data['sales_data']->email);
$this->email->bcc($pdf_data['sales_data']->email_manager);
$this->email->attach(base_url() . $file_to_save);
$this->email->subject('Penawaran Harga Indolok ' . 'Ref : IBU/' . $pdf_data['current_month'] . '/'. $pdf_data['current_year'] . '/ECM/' . $pdf_data['penawaran_id']);
$email = $this->load->view('email/indonesian/penawaran_harga', $data_pdf, TRUE);
$this->email->message($email);
$response = $this->email->send();
if (!$response) { var_dump($this->email->print_debugger()); exit(); }
}
}