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/indolok.id/application/controllers/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Payment extends Customer_Controller { private $order_id = NULL; function __construct() { parent::__construct(); $this->load->model('order_m'); $this->load->model('order_detail_m'); $this->load->model('product_m'); $this->load->model('configuration_m'); $this->load->library('cart'); } function index() { if(!$this->session->userdata('shipping_cart')) { redirect('cart'); } //INSERT NEW ORDERS $grand_total = 0; foreach ($this->session->userdata('shipping_cart') as $rowid => $item) { $grand_total = $grand_total + $item['subtotal']; } //get shipping address, province, district and subdistrict $this->db->select('email, shipping_name, shipping_address, indah_cargo_id, shipping_handphone, postcode')->from('customers')->where('id_customers', $this->session->userdata('customer')['customer_id']); $customer_data = $this->db->get()->row(); //get indah cargo $this->db->select('*')->from('indah_cargo')->where('id', $customer_data->indah_cargo_id); $indah_cargo = $this->db->get()->row(); //insert new order to orders table $check_t_shipping_fee = $this->session->userdata('total_shipping_fee'); if ($check_t_shipping_fee == null || empty($check_t_shipping_fee)) { $this->session->set_userdata('total_shipping_fee',0); } $data = array( 'customer_id' => (int) $this->session->userdata('customer')['customer_id'], 'recipient_name' => $customer_data->shipping_name, 'address' => $customer_data->shipping_address, 'district' => $indah_cargo->destination_city, 'province' => $indah_cargo->destination_province, 'phone' => $customer_data->shipping_handphone, 'email' => $customer_data->email, 'postcode' => $customer_data->postcode, 'country' => 'Indonesia', 'total_amount' => $grand_total, 'order_date' => date('Y-m-d H:i:s'), 'shipping_fee' => $this->session->userdata('total_shipping_fee'), // 'free_shipping_fee' => $this->session->userdata('free_shipping'), 'kurir' => $this->session->userdata('rex_service_name') ); //add birthday promo if ($this->session->userdata('birthday_promo_percentage')) { $data['birthday_promo_percentage'] = $this->session->userdata('birthday_promo_percentage'); $data['birthday_promo_amount'] = $this->session->userdata('birthday_promo_amount'); } //add voucher if ($this->session->userdata('chosen_voucher_code')) { $data['redeemed_voucher_code'] = $this->session->userdata('chosen_voucher_code'); $data['redeemed_voucher_type'] = $this->session->userdata('chosen_voucher_type'); $data['redeemed_voucher_value'] = $this->session->userdata('chosen_voucher_discount'); $data['redeemed_voucher_amount'] = $this->session->userdata('redeemed_voucher_amount'); } //add tax if($this->session->userdata('tax')) { $data['ppn'] = (int) $this->session->userdata('tax'); } //insert to orders table $this->db->insert('orders', $data); $order_id = $this->db->insert_id(); $data['order_id'] = $order_id; //insert new order details to order details table foreach ($this->session->userdata('shipping_cart') as $item) { $item_data = array( 'orders_id' => $order_id, 'item_id' => (int) $item['id'], 'item_name' => $item['name'], 'item_price' => (int) $item['price'], 'quantity' => (int) $item['qty'], 'subtotal' => (int) $item['subtotal'], 'warehouse_id' => $item['warehouse_id'], 'chosen_shipping_id' => $item['chosen_shipping_id'], 'shipping_fee' => $item['shipping_fee'], 'is_backorder' => $item['is_backorder'], 'is_flashsale' => $item['is_flashsale'], ); if($item['is_sale'] == TRUE) { $item_data['is_sale'] = 'yes'; } else { $item_data['is_sale'] = 'no'; } $this->order_detail_m->save($item_data, $id = NULL); //DEDUCT VOUCHERS FROM VOUCHER TABLE if ($this->session->userdata('chosen_voucher_code')) { $this->db->select('qty_ready')->from('vouchers')->where('voucher_code', $this->session->userdata('chosen_voucher_code')); $qty_ready = $this->db->get()->row()->qty_ready; if ($qty_ready != NULL) { $new_qty_ready = $qty_ready - 1; $data = array( 'qty_ready' => $new_qty_ready, ); $this->db->where('voucher_code', $this->session->userdata('chosen_voucher_code')); $this->db->update('vouchers', $data); } } //UPDATE VOUCHER USER TABLE //get voucher id if ($this->session->userdata('chosen_voucher_code')) { $this->db->select('id_vouchers')->from('vouchers')->where('voucher_code', $this->session->userdata('chosen_voucher_code')); $voucher_id = (int) $this->db->get()->row()->id_vouchers; //check if this voucher already been used before in voucher user table $this->db->select('id_voucher_users')->from('voucher_users')->where('voucher_id', $voucher_id)->where('customer_id', (int) $this->session->userdata('customer')['customer_id']); $count_voucher = $this->db->get()->num_rows(); if ($count_voucher == 0) { //voucher not exist yet, insert new voucher $data = array( 'voucher_id' => $voucher_id, 'customer_id' => (int) $this->session->userdata('customer')['customer_id'], 'voucher_used' => 1, ); $this->db->insert('voucher_users', $data); } else { //voucher already exist //get current used voucher quantity, and add 1 $this->db->select('id_voucher_users, voucher_used')->from('voucher_users')->where('voucher_id', (int) $voucher_id)->where('customer_id', (int) $this->session->userdata('customer')['customer_id']); $voucher_user = $this->db->get()->row(); $new_voucher_used = $voucher_user->voucher_used + 1; $data = array( 'voucher_used' => (int) $new_voucher_used, ); $this->db->where('id_voucher_users', $voucher_user->id_voucher_users); $this->db->update('voucher_users', $data); } } } //DEDUCT CURRENT STOCK WITH PURCHASE QUANTITY foreach ($this->session->userdata('shipping_cart') as $rowid => $item) { if($item['is_backorder'] == 'no') { //get current stock from stock table $this->db->select('stock')->from('stock')->where('id_product', (int) $item['id'])->where('warehouse_id', (int) $item['warehouse_id']); $current_stock = (int) $this->db->get()->row()->stock; $new_item_stock = $current_stock - (int) $item['qty']; $stock_data = array( 'stock' => $new_item_stock, ); //update the product item stock in database $this->db->where('id_product', (int) $item['id']); $this->db->where('warehouse_id', (int) $item['warehouse_id']); $this->db->update('stock', $stock_data); } } //get payment method $data['configuration'] = $this->db->select('*')->from('configuration')->where('id_configuration', 1)->get()->row(); $data['order_id'] = $order_id; $this->db->select('*')->from('orders')->where('id_orders', $order_id); $get_order = $this->db->get()->row(); $grand_final_total = ($get_order->total_amount - $get_order->redeemed_voucher_amount - $get_order->minus_reward_amount) + ($get_order->shipping_fee - $get_order->free_shipping_fee) + (int) $this->session->userdata('tax'); //load payment view $this->db->select('website_name')->from('configuration')->where('id_configuration', 1); $website_name = $this->db->get()->row(); $this->data_header['browser_title'] = ucwords($website_name->website_name) . ' - Payment'; $this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - Payment'; $this->load->view("themes/$this->theme_no/header", $this->data_header); $this->load->view('payment', $data); $this->load->view("themes/$this->theme_no/footer", $this->data_footer); } public function process_payment() { if (!isset($_POST['process_payment'])) { redirect('shipping'); } $order_id = (int) $this->input->post('order_id'); $this->order_id = $order_id; $this->db->select('*')->from('orders')->where('id_orders', $order_id); $order = $this->db->get()->row(); //get order detail $this->db->select('*')->from('orders_detail')->where('orders_id', $order_id); $order_details = $this->db->get()->result(); //get customer district / city name $this->db->select('name, email, handphone, shipping_address, indah_cargo_id')->from('customers')->where('id_customers', (int) $this->session->userdata('customer')['customer_id']); $customer_data = $this->db->get()->row(); //get indah cargo $this->db->select('*')->from('indah_cargo')->where('id', $customer_data->indah_cargo_id); $indah_cargo = $this->db->get()->row(); //MITRANS if ($this->input->post('payment_type') == 'midtrans') { $payment_type = 'midtrans'; //update payment status to become 0 $data = array( 'payment_status' => 1, 'payment_type' => $payment_type ); $this->db->where('id_orders', $order_id); $this->db->update('orders', $data); $this->session->set_userdata('midtrans_order_id',$order_id); //$this->send_email('midtrans'); //MIDTRANS IN ACTION require_once APPPATH . 'third_party/Veritrans.php'; //get key $this->db->select('veritrans_server_key, veritrans_sandbox_server_key, veritrans_client_key, veritrans_sandbox_client_key, veritrans_production_mode')->from('configuration')->where('id_configuration', 1); $veritrans = $this->db->get()->row(); $production_mode = $veritrans->veritrans_production_mode; //Set Your server key if ($production_mode == 'true') { Veritrans_Config::$isProduction = true; Veritrans_Config::$serverKey = $veritrans->veritrans_server_key; $data['client_key'] = $veritrans->veritrans_client_key; $data['snap_url'] = 'https://app.midtrans.com/snap/snap.js'; } else { Veritrans_Config::$isProduction = false; Veritrans_Config::$serverKey = $veritrans->veritrans_sandbox_server_key; $data['client_key'] = $veritrans->veritrans_sandbox_client_key; $data['snap_url'] = 'https://app.sandbox.midtrans.com/snap/snap.js'; } // Enable sanitization Veritrans_Config::$isSanitized = true; // Enable 3D-Secure Veritrans_Config::$is3ds = true; $transaction_details = array( 'order_id' => (int) $order_id, 'gross_amount' => (int) (($order->total_amount - $order->redeemed_voucher_amount - $order->minus_reward_amount) + ($order->shipping_fee - $order->free_shipping_fee)) ); // Populate items // define a two-dimensional array foreach($order_details as $item) { $items[] = array( 'id' => $item->item_id, 'price' => (int) $item->item_price, 'quantity' => $item->quantity, 'name' => strip_tags(substr($item->item_name, 0, 48)) . '..', ); } //add birthday promo if ($order->birthday_promo_percentage != NULL) { $items[] = array( 'id' => 'birthdaypromo', 'price' => -$order->birthday_promo_amount, 'quantity' => 1, 'name' => 'Birthday Promo: ' . $birthday_promo_percentage . '%', ); } //add voucher discount into the item if ($order->redeemed_voucher_amount != NULL) { if ($order->redeemed_voucher_type == 'amount') { //by amount //deduct voucher into item, so gross == total items $items[] = array( 'id' => 'voucher', 'price' => -$order->redeemed_voucher_amount, 'quantity' => 1, 'name' => 'Voucher: ' . $order->redeemed_voucher_code, ); } else { //by percentage //deduct voucher into item, so gross == total items $items[] = array( 'id' => 'voucher', 'price' => -$order->redeemed_voucher_amount, 'quantity' => 1, 'name' => 'Voucher: ' . $order->redeemed_voucher_code, ); } } //add point rewards discount if($order->minus_reward_amount != NULL) { $items[] = array( 'id' => 'pointrewards', 'price' => -$order->minus_reward_amount, 'quantity' => 1, 'name' => 'Point Rewards', ); } //add shipping fee into the item $items[] = array( 'id' => 'shipping', 'price' => $order->shipping_fee, 'quantity' => 1, 'name' => 'Shipping Fee', ); //add free shipping if($order->free_shipping_fee != NULL) { $items[] = array( 'id' => 'freeshipping', 'price' => -$order->free_shipping_fee, 'quantity' => 1, 'name' => 'Free Shipping', ); } //add creditcard total fee (transaction fee + admin fee) if ($this->session->userdata('chosen_payment_type') == 'veritrans') { $items[] = array( 'id' => 'veritrans_fee', 'price' => (int) $this->session->userdata('veritrans_total_fee'), 'quantity' => 1, 'name' => 'Credit Card Admin', ); } //add virtualaccount total fee (admin fee) if ($this->session->userdata('chosen_payment_type') == 'virtualaccount') { $items[] = array( 'id' => 'virtualaccount_fee', 'price' => (int) $this->session->userdata('virtualaccount_total_fee'), 'quantity' => 1, 'name' => 'Virtual Account Admin', ); } //add tax if($this->session->userdata('tax')) { $items[] = array( 'id' => 'tax', 'price' => (int) $this->session->userdata('tax'), 'quantity' => 1, 'name' => 'Tax', ); } // Populate customer's billing address $billing_address = array( 'first_name' => $customer_data->name, 'last_name' => '', 'address' => $customer_data->shipping_address, 'city' => $subdistrict . '. ' . $district . '. ' . $province, 'postal_code' => '', 'phone' => $customer_data->phone, 'country_code' => 'IDN' ); // Populate customer's shipping address $shipping_address = array( 'first_name' => $customer_data->name, 'last_name' => '', 'address' => $customer_data->shipping_address, 'city' => $subdistrict . '. ' . $district . '. ' . $province, 'postal_code' => '', 'phone' => $customer_data->phone, 'country_code' => 'IDN' ); // Populate customer's Info $customer_details = array( 'first_name' => $customer_data->name, 'last_name' => '', 'email' => $customer_data->email, 'phone' => $customer_data->phone, 'billing_address' => $billing_address, 'shipping_address' => $shipping_address ); // Optional, remove this to display all available payment methods //$enable_payments = array('credit_card','cimb_clicks','mandiri_clickpay','echannel'); //$enable_payments = array('credit_card'); // Fill transaction details $transaction = array( 'enabled_payments' => $enable_payments, 'transaction_details' => $transaction_details, 'customer_details' => $customer_details, 'item_details' => $items, ); $data['snapToken'] = Veritrans_Snap::getSnapToken($transaction); //LOAD PAYMENT RETURN PAGE $data['bank'] = $this->configuration_m->get_bank(); $data['email'] = $this->session->userdata('customer')['customer_email']; $data['order'] = $this->order_m->get_order($this->session->userdata('order_id')); $this->destroy_session_data(); //get SEO $this->db->select('website_name')->from('configuration')->where('id_configuration', 1); $website_name = $this->db->get()->row(); $this->data_header['browser_title'] = ucwords($website_name->website_name) . ' - Midtrans Payment'; $this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - Midtrans Payment'; $this->load->view("themes/$this->theme_no/header", $this->data_header); $this->load->view('midtrans', $data); $this->load->view("themes/$this->theme_no/footer", $this->data_footer); } //BCA manual bank transfer if ($this->input->post('payment_type') == 'bca') { $payment_type = 'bank transfer BCA'; //update payment status to become 1 $data = array( 'payment_status' => 1, //not paid 'payment_type' => $payment_type ); $this->db->where('id_orders', $order_id); $this->db->update('orders', $data); $this->send_email($payment_type); //LOAD PAYMENT RETURN PAGE $data['bank'] = $this->configuration_m->get_bank(); $data['email'] = $customer_data->email; $data['order_id'] = $order_id; $this->db->select('id_orders,order_date,payment_status,payment_confirm,recipient_name,address,district,subdistrict,province,postcode'); $this->db->from('orders'); $this->db->where('id_orders',$order_id); $data['order_info'] = $this->db->get()->row(); $data['grand_total'] = (($order->total_amount - $order->redeemed_voucher_amount - $order->minus_reward_amount - $order->birthday_promo_amount) + ($order->shipping_fee - $order->free_shipping_fee + $order->ppn)); //check if one of products is owa $data['owa'] = 'no'; foreach($this->session->userdata('shipping_cart') as $rowid => $item) { //get product item $this->db->select('product_type')->from('products')->where('id_products', $item['id']); $product_type_id = $this->db->get()->row()->product_type; if($product_type_id == 1) { $data['owa'] = 'yes'; } break; } $this->destroy_session_data(); if($this->session->userdata('site_lang') == 'english') { $this->lang->load('order_history', 'english'); } else { $this->lang->load('order_history', 'indonesian'); } //get SEO $this->db->select('website_name')->from('configuration')->where('id_configuration', 1); $website_name = $this->db->get()->row(); $this->data_header['browser_title'] = ucwords($website_name->website_name) . ' - BCA Manual Bank Transfer'; $this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - BCA Manual Bank Transfer'; $this->load->view("themes/$this->theme_no/header", $this->data_header); $this->load->view('banktransfer', $data); $this->load->view("themes/$this->theme_no/footer", $this->data_footer); } //MANDIRI manual bank transfer if ($this->input->post('payment_type') == 'mandiri') { $payment_type = 'bank transfer MANDIRI'; //update payment status to become 1 // not paid $data = array( 'payment_status' => 1, 'payment_type' => $payment_type ); $this->db->where('id_orders', $order_id); $this->db->update('orders', $data); $this->send_email($payment_type); //LOAD PAYMENT RETURN PAGE $data['bank'] = $this->configuration_m->get_bank1(); $data['email'] = $customer_data->email; $data['order_id'] = $order_id; $this->db->select('id_orders,order_date,payment_status,payment_confirm,recipient_name,address,district,subdistrict,province,postcode'); $this->db->from('orders'); $this->db->where('id_orders',$order_id); $data['order_info'] = $this->db->get()->row(); $data['grand_total'] = ($order->total_amount - $order->redeemed_voucher_amount - $order->minus_reward_amount - $order->birthday_promo_amount) + ($order->shipping_fee - $order->free_shipping_fee) + $order->ppn; $this->destroy_session_data(); if($this->session->userdata('site_lang') == 'english') { $this->lang->load('order_history', 'english'); } else { $this->lang->load('order_history', 'indonesian'); } //get SEO $this->db->select('website_name')->from('configuration')->where('id_configuration', 1); $website_name = $this->db->get()->row(); $this->data_header['browser_title'] = ucwords($website_name->website_name) . ' - MANDIRI Manual Bank Transfer'; $this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - MANDIRI Manual Bank Transfer'; $this->load->view("themes/$this->theme_no/header", $this->data_header); $this->load->view('banktransfer', $data); $this->load->view("themes/$this->theme_no/footer", $this->data_footer); } $this->cart->destroy(); $this->session->unset_userdata('chosen_sales_id'); $this->session->unset_userdata('penawaran_harga_id'); $this->session->unset_userdata('penawaran_harga_to_shipping'); } public function payment_as_po() { $internal_po = $this->security->xss_clean($this->input->post('internal_po')); if($internal_po == null){ redirect('cart'); } if(!$this->session->userdata('shipping_cart')) { redirect('cart'); } $type = $this->db->select('type')->from('customers')->where('id_customers', $this->session->userdata('customer')['customer_id'])->get()->row()->type; if($type == "regular"){ redirect('welcome'); } //check shipping_cart if the stock is available for each warehouse //check if the current stocks are enough. $have_stock = true; foreach ($this->session->userdata('shipping_cart') as $rowid => $item) { //get product name $this->db->select('title')->from('products')->where('id_products', $item['id']); $product_name = $this->db->get()->row()->title; //get total stok from warehouse $this->db->select('stock')->from('stock')->where('id_product', $item['id'])->where('warehouse_id', $item['warehouse_id']); $current_stock = $this->db->get()->row()->stock; if($current_stock < $item['qty']) { if($item['is_backorder'] == 'no') { $this->session->set_flashdata('no_stock' . $rowid, 'Stok tidak cukup'); $have_stock = false; } } } if($have_stock == false) { redirect('shipping/no_stock'); } //INSERT NEW ORDERS $grand_total = 0; foreach ($this->session->userdata('shipping_cart') as $rowid => $item) { $grand_total = $grand_total + $item['subtotal']; } //get shipping address, province, district and subdistrict $this->db->select('company_name, email, shipping_name, shipping_address, indah_cargo_id, shipping_handphone')->from('customers')->where('id_customers', $this->session->userdata('customer')['customer_id']); $customer_data = $this->db->get()->row(); //get indah cargo $this->db->select('*')->from('indah_cargo')->where('id', $customer_data->indah_cargo_id); $indah_cargo = $this->db->get()->row(); //insert new order to orders table $check_t_shipping_fee = $this->session->userdata('total_shipping_fee'); if ($check_t_shipping_fee == null || empty($check_t_shipping_fee)) { $this->session->set_userdata('total_shipping_fee',0); } $data = array( 'customer_id' => (int) $this->session->userdata('customer')['customer_id'], 'total_amount' => $grand_total, 'order_date' => date('Y-m-d H:i:s'), 'payment_status' => 1, 'payment_type' => 'PO order', 'recipient_name' => $customer_data->shipping_name, 'address' => $customer_data->shipping_address, 'district' => $indah_cargo->destination_city, 'province' => $indah_cargo->destination_province, 'phone' => $customer_data->shipping_handphone, 'email' => $customer_data->email, 'country' => 'Indonesia', 'shipping_fee' => $this->session->userdata('total_shipping_fee'), 'free_shipping_fee' => $this->session->userdata('free_shipping'), 'sales_id' => $this->session->userdata('chosen_sales_id'), 'no_po' => $internal_po, 'penawaran_harga_id' => $this->session->userdata('penawaran_harga_id') ); //add voucher if ($this->session->userdata('chosen_voucher_code')) { $data['redeemed_voucher_code'] = $this->session->userdata('chosen_voucher_code'); $data['redeemed_voucher_type'] = $this->session->userdata('chosen_voucher_type'); $data['redeemed_voucher_value'] = $this->session->userdata('chosen_voucher_discount'); $data['redeemed_voucher_amount'] = $this->session->userdata('redeemed_voucher_amount'); } //add tax if($this->session->userdata('tax')) { $data['ppn'] = (int) $this->session->userdata('tax'); } //insert to orders table $this->db->insert('orders', $data); $order_id = $this->db->insert_id(); $data['order_id'] = $order_id; //insert new order details to order details table foreach ($this->session->userdata('shipping_cart') as $item) { $item_data = array( 'orders_id' => $order_id, 'item_id' => (int) $item['id'], 'item_name' => $item['name'], 'item_price' => (int) $item['price'], 'quantity' => (int) $item['qty'], 'subtotal' => (int) $item['subtotal'], 'warehouse_id' => $item['warehouse_id'], 'chosen_shipping_id' => $item['chosen_shipping_id'], 'shipping_fee' => $item['shipping_fee'], 'is_backorder' => $item['is_backorder'], 'is_flashsale' => $item['is_flashsale'], ); if($item['is_sale'] == TRUE) { $item_data['is_sale'] = 'yes'; } else { $item_data['is_sale'] = 'no'; } $this->order_detail_m->save($item_data, $id = NULL); //DEDUCT VOUCHERS FROM VOUCHER TABLE if ($this->session->userdata('chosen_voucher_code')) { $this->db->select('qty_ready')->from('vouchers')->where('voucher_code', $this->session->userdata('chosen_voucher_code')); $qty_ready = $this->db->get()->row()->qty_ready; if ($qty_ready != NULL) { $new_qty_ready = $qty_ready - 1; $data = array( 'qty_ready' => $new_qty_ready, ); $this->db->where('voucher_code', $this->session->userdata('chosen_voucher_code')); $this->db->update('vouchers', $data); } } //UPDATE VOUCHER USER TABLE //get voucher id if ($this->session->userdata('chosen_voucher_code')) { $this->db->select('id_vouchers')->from('vouchers')->where('voucher_code', $this->session->userdata('chosen_voucher_code')); $voucher_id = (int) $this->db->get()->row()->id_vouchers; //check if this voucher already been used before in voucher user table $this->db->select('id_voucher_users')->from('voucher_users')->where('voucher_id', $voucher_id)->where('customer_id', (int) $this->session->userdata('customer')['customer_id']); $count_voucher = $this->db->get()->num_rows(); if ($count_voucher == 0) { //voucher not exist yet, insert new voucher $data = array( 'voucher_id' => $voucher_id, 'customer_id' => (int) $this->session->userdata('customer')['customer_id'], 'voucher_used' => 1, ); $this->db->insert('voucher_users', $data); } else { //voucher already exist //get current used voucher quantity, and add 1 $this->db->select('id_voucher_users, voucher_used')->from('voucher_users')->where('voucher_id', (int) $voucher_id)->where('customer_id', (int) $this->session->userdata('customer')['customer_id']); $voucher_user = $this->db->get()->row(); $new_voucher_used = $voucher_user->voucher_used + 1; $data = array( 'voucher_used' => (int) $new_voucher_used, ); $this->db->where('id_voucher_users', $voucher_user->id_voucher_users); $this->db->update('voucher_users', $data); } } } //DEDUCT CURRENT STOCK WITH PURCHASE QUANTITY foreach ($this->session->userdata('shipping_cart') as $rowid => $item) { if($item['is_backorder'] == 'no') { //get current stock from stock table $this->db->select('stock')->from('stock')->where('id_product', (int) $item['id'])->where('warehouse_id', (int) $item['warehouse_id']); $current_stock = (int) $this->db->get()->row()->stock; $new_item_stock = $current_stock - (int) $item['qty']; $stock_data = array( 'stock' => $new_item_stock, ); //update the product item stock in database $this->db->where('id_product', (int) $item['id']); $this->db->where('warehouse_id', (int) $item['warehouse_id']); $this->db->update('stock', $stock_data); } } //update penawaran table $data = array( 'status' => 'po', 'no_po' => $internal_po ); $this->db->where('id', $this->session->userdata('penawaran_harga_id')); $this->db->update('penawaran_harga', $data); //get payment method /*destroy all season*/ $this->destroy_session_data(); $data['configuration'] = $this->db->select('*')->from('configuration')->where('id_configuration', 1)->get()->row(); $data['order_id'] = $order_id; //get order date $this->db->select('order_date, address, district, province')->from('orders')->where('id_orders', $order_id); $order_info = $this->db->get()->row(); $data['order_date'] = $order_info->order_date; $data['address'] = $order_info->address . '. ' . ucwords($order_info->district) . '. ' . ucwords($order_info->province); $data['customer_id'] = $this->session->userdata('customer')['customer_id']; //load payment view $this->db->select('website_name')->from('configuration')->where('id_configuration', 1); $website_name = $this->db->get()->row(); $this->data_header['browser_title'] = ucwords($website_name->website_name) . ' - Payment as PO'; $this->data_header['meta_description'] = ucwords($website_name->website_name) . ' - Payment as PO'; $this->load->view("themes/$this->theme_no/header", $this->data_header); $this->load->view('payment_as_po', $data); $this->load->view("themes/$this->theme_no/footer", $this->data_footer); $this->cart->destroy(); $this->session->unset_userdata('chosen_sales_id'); $this->session->unset_userdata('penawaran_harga_id'); $this->session->unset_userdata('penawaran_harga_to_shipping'); } private function send_email($payment_type) { //----SEND EMAIL TO CUSTOMER //get customer name if($this->session->userdata('customer')['customer_id'] != null){ $customer_id = (int) $this->session->userdata('customer')['customer_id']; } else{ $customer_id = $this->db->select('customer_id')->from('orders')->where('id_orders',$this->order_id)->get()->row()->customer_id; } $this->db->select('name,handphone,type')->from('customers')->where('id_customers', $customer_id); $data['customer_name'] = $this->db->get()->row(); //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['logo'] = $website_data->logo; $data['website_name'] = $website_data->website_name; $data['emails'] = $this->configuration_m->get_emails(); /*$data['bank'] = $this->configuration_m->get_bank(); */ if($payment_type == 'bank transfer BCA'){ $this->db->select('bank')->from('configuration')->where('id_configuration', 1); $data['bank'] = $this->db->get()->row()->bank; } elseif($payment_type == 'bank transfer MANDIRI'){ $this->db->select('bank1')->from('configuration')->where('id_configuration', 1); $data['bank'] = $this->db->get()->row()->bank1; } $data['title'] = 'Order Confirmation'; //get order detail and customer detail $data['order'] = $this->order_m->get_order($this->order_id); $data['order_details'] = $this->order_detail_m->get_orders_detail($this->order_id); //get vouchers detail if ($this->session->userdata('chosen_voucher_code')) { $data['chosen_voucher_code'] = $this->session->userdata('chosen_voucher_code'); $data['chosen_voucher_type'] = $this->session->userdata('chosen_voucher_type'); $data['chosen_voucher_discount'] = $this->session->userdata('chosen_voucher_discount'); $data['redeemed_voucher_amount'] = $this->session->userdata('redeemed_voucher_amount'); } //add birthday promo if ($this->session->userdata('birthday_promo_percentage')) { $data['birthday_promo_percentage'] = $this->session->userdata('birthday_promo_percentage'); $data['birthday_promo_amount'] = $this->session->userdata('birthday_promo_amount'); } //get shipping fee total $data['carrier_name'] = $this->session->userdata('carrier_name'); $data['total_shipping_fee'] = $this->session->userdata('total_shipping_fee'); //add tax to email, if exist.. if($this->session->userdata('tax')) { $data['tax'] = $this->session->userdata('tax'); } $this->load->library('email'); //get email setting $config['protocol'] = 'smtp'; $config['smtp_crypto'] = 'tls'; $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'] = 'utf-8'; $config['wordwrap'] = TRUE; $config['newline'] = "\r\n"; //use double quotes to comply with RFC 822 standard $this->email->initialize($config); $this->email->from('ecommerce@gunnebo.com', $website_data->website_name); $this->email->to($this->session->userdata('customer')['customer_email']); // $this->email->cc($data['emails']->from_email); $this->email->subject('Order Confirmation'); switch($payment_type) { case 'bank transfer BCA': if($this->session->userdata('site_lang') == 'english') { /*$email = $this->load->view('email/english/bank_transfer', $data, TRUE); */ $email = $this->load->view('email/indonesian/bank_transfer_indo', $data, TRUE); } else { $email = $this->load->view('email/indonesian/bank_transfer_indo', $data, TRUE); } break; case 'bank transfer MANDIRI': if($this->session->userdata('site_lang') == 'english') { /*$email = $this->load->view('email/english/bank_transfer', $data, TRUE); */ $email = $this->load->view('email/indonesian/bank_transfer_indo', $data, TRUE); } else { $email = $this->load->view('email/indonesian/bank_transfer_indo', $data, TRUE); } break; case 'cod': if($this->session->userdata('site_lang') == 'english') { $email = $this->load->view('email/english/cod', $data, TRUE); } else { $email = $this->load->view('email/indonesian/cod', $data, TRUE); } break; case 'midtrans': if($this->session->userdata('site_lang') == 'english') { /*$email = $this->load->view('email/english/bank_transfer', $data, TRUE); */ $email = $this->load->view('email/indonesian/bank_transfer_indo', $data, TRUE); } else { $email = $this->load->view('email/indonesian/bank_transfer_indo', $data, TRUE); } break; } $this->email->message($email); $this->email->send(); $this->email->print_debugger(); //----end send email } private function destroy_session_data() { if($this->session->userdata('customer')['customer_type'] == 'guest') { $this->session->unset_userdata('customer'); } //DESTROY CART AND UNSET SOME SESSION, BUT NOT CUSTOMER SESSION $this->session->unset_userdata('grand_total'); $this->session->unset_userdata('recipient_name'); $this->session->unset_userdata('address'); $this->session->unset_userdata('id_district'); $this->session->unset_userdata('id_subdistrict'); $this->session->unset_userdata('id_province'); $this->session->unset_userdata('district'); $this->session->unset_userdata('subdistrict'); $this->session->unset_userdata('province'); $this->session->unset_userdata('country'); $this->session->unset_userdata('postcode'); $this->session->unset_userdata('phone'); $this->session->unset_userdata('order_id'); $this->session->unset_userdata('is_from_cart'); $this->session->unset_userdata('chosen_voucher_type'); $this->session->unset_userdata('chosen_voucher_discount'); $this->session->unset_userdata('chosen_voucher_code'); $this->session->unset_userdata('total_categoryproduct_promo'); $this->session->unset_userdata('redeemed_voucher_amount'); $this->session->unset_userdata('total_shipping_fee'); $this->session->unset_userdata('carrier'); $this->session->unset_userdata('carrier_name'); $this->session->unset_userdata('summary_message'); $this->session->unset_userdata('add_point_reward'); $this->session->unset_userdata('minus_point_reward'); $this->session->unset_userdata('chosen_point'); $this->session->unset_userdata('chosen_point_discount'); $this->session->unset_userdata('chosen_payment_type'); $this->session->unset_userdata('tax'); $this->session->unset_userdata('productpage_to_cart'); $this->session->unset_userdata('choose_dropship_status'); $this->session->unset_userdata('destination_latitude'); $this->session->unset_userdata('destination_longitude'); $this->session->unset_userdata('current_viewed_category_id'); $this->session->unset_userdata('shipping_cart'); $this->session->unset_userdata('prescription_uniqid'); $this->session->unset_userdata('chosen_sales_id'); $this->session->unset_userdata('penawaran_harga_id'); $this->session->unset_userdata('penawaran_harga_to_shipping'); } }