<?php if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);

/**
 * function list index
 * need to list the details and function called
 *
index:
 *
delivery_address:
 *
customer_update_billing_address_form
 *	In customer part->delivery address, update billing address data
 *
cust_info_form
 * list out current customer information and pass to cust_info_form_update

cust_info_form_update
 * update customer information

customer_delivery_address_update
 *
customer_add_delivery_address_form
 *
customer_delivery_address_add
 *
customer_update_delivery_address_form
 *
shop_cart
 *
order_record_detail
 *
order_detail_pdf
 *
 *
newstyle
 *
order_record
 *
logout
 *
edit_profile
 *
update_profile
 *
change_password_form
 *
change_password
 *
select_city_country_id
 *
cust_wish_list
 *
wish_listinfo
 *
wishlist
 *
wishlist_delete
 *

 * end function list index
 **/
class Customer_dashboard extends MX_Controller {

	function __construct() {
		parent::__construct();
		$this->load->model('dashboard/Soft_settings');
		$this->load->model('dashboard/Customer_dashboards');
		$this->load->model('web/customer/Invoices');
		$this->load->model('web/customer/Orders');
		$this->load->model('dashboard/Wishlists');
		// $this->load->model('dashboard/soft_settings');

		//category
		$this->load->model('web/Categories');
		//end category

		//added customer info
		//$this->load->model('dashboard/Companies');
		//$this->load->model('dashboard/Themes');
		$this->load->model('web/Homes');
		$this->load->model('dashboard/Subscribers');
		$this->load->model('dashboard/web_settings');
		$this->load->model('dashboard/Blocks');
		$this->load->model('dashboard/themes');
		$this->load->model('dashboard/color_frontends');
		$this->load->model('dashboard/Orders');
		$this->load->model('template/Template_model');
		$this->load->model('dashboard/companies');
		$this->load->model('dashboard/pay_withs');
		$this->load->model('web/customer/Signups');
		$this->load->model('web/wishlist', 'custwishlist');

		$this->load->model('web/customer/Customerinfo');
		$this->load->model('dashboard/Customers');
		$this->load->model('web/Custpoint_model');
		//end added customer info

		//added model for setting
		$this->load->model('web/Settings');

		//end added model for setting

		$this->user_auth->check_customer_auth();
	}
	//function list

	//order_record_detail->Display customer order record detail after customer login
	//shop_cart->show current shoping cart of system

	//end function list

	//Default customer index load.
	public function index() {

		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer_id = $this->session->userdata('customer_id');
		$total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		$total_order = $this->Orders->total_customer_order($customer_id);

		$currency_details = $this->Soft_settings->retrieve_currency_info();
		$currency_info = $this->Homes->currency_info();
		//added company info
		// $company_info = $this->Companies->company_list();
		// $theme = $this->Themes->get_theme();
		//end added company info
		$data = array(
			'title' => display('dashboard'),
			'total_invoice' => $total_invoice,
			'total_order' => $total_order,
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'currency_info' => $currency_info,
			//added company info
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info
		);
		$content = $this->parser->parse('web/customer/include/customer_home', $data, true);

		$this->template_lib->full_customer_html_view($content);
	}
	//added customer delivery address
	public function delivery_address() {

		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');
		// $total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		// $total_order = $this->Orders->total_customer_order($customer_id);

		// $currency_details = $this->Soft_settings->retrieve_currency_info();
		// $currency_info = $this->Homes->currency_info();
		// $selected_currency_info = $this->Homes->selected_currency_info();

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		$customerinfo = $this->Customerinfo->get_customer_details();
		$selected_country_info = $this->Homes->selected_country_info();
		$deliveryaddress = $this->Customerinfo->get_customer_billing_address();
		//end added get customer info

		$customer_id = $this->session->userdata('customer_id');

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'delivery_address',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,
			//added details
			'customerinfo' => $customerinfo,
			'selected_country_info' => $selected_country_info,
			'deliveryaddress' => $deliveryaddress,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info

			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,

		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);
		$content = $this->parser->parse('web/customer/delivery_address', $data, true);
		$this->template_lib->full_website_html_view($content);

	}
	//end added customer delivery address
	public function customer_update_billing_address_form() {
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');
		// $total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		// $total_order = $this->Orders->total_customer_order($customer_id);

		// $currency_details = $this->Soft_settings->retrieve_currency_info();
		// $currency_info = $this->Homes->currency_info();
		// $selected_currency_info = $this->Homes->selected_currency_info();

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		$customerinfo = $this->Customerinfo->get_customer_details();
		$selected_country_info = $this->Homes->selected_country_info();
		$state_list = $this->Customers->select_city_country_id($customer->country);
		// var_dump($selected_country_info);
		//end added get customer info

		$customer_id = $this->session->userdata('customer_id');

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'delivery_address',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,

			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,

			//added details
			'customerinfo' => $customerinfo,
			'selected_country_info' => $selected_country_info,
			'state_list' => $state_list,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info
		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);
		$content = $this->parser->parse('web/customer/customer_update_billing_address_form', $data, true);
		$this->template_lib->full_website_html_view($content);

	}
	public function cust_info_form() {
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');
		// $total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		// $total_order = $this->Orders->total_customer_order($customer_id);

		// $currency_details = $this->Soft_settings->retrieve_currency_info();
		// $currency_info = $this->Homes->currency_info();
		// $selected_currency_info = $this->Homes->selected_currency_info();

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		$customerinfo = $this->Customerinfo->get_customer_details();
		// $selected_country_info = $this->Homes->selected_country_info();
		// $deliveryaddress = $this->Customerinfo->get_customer_billing_address();
		//end added get customer info

		$customer_id = $this->session->userdata('customer_id');

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'cust_info',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,
			//added details
			'customerinfo' => $customerinfo,
			// 'selected_country_info' => $selected_country_info,
			// 'deliveryaddress' => $deliveryaddress,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info

			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,

		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);
		$content = $this->parser->parse('web/customer/cust_info_form', $data, true);
		$this->template_lib->full_website_html_view($content);
	} //public function cust_info_form() {
	public function cust_info_form_update() {
		$this->form_validation->set_rules('first_name', display('first_name'), 'trim|required');
		$this->form_validation->set_rules('last_name', display('last_name'), 'trim|required');
		// $this->form_validation->set_rules('email', display('email'), 'trim|required|is_unique[customer_information.customer_email]');
		$this->form_validation->set_rules('email', display('email'), 'trim|required');
		$this->form_validation->set_rules('phone', display('phone'), 'trim|required');
		// $this->form_validation->set_rules('password', display('password'), 'trim|required');

		//added confirm password
		$changePassword = false;
		if (!empty($this->input->post('user_current_pw', TRUE))) {
			$this->form_validation->set_rules('user_current_pw', display('user_current_pw'), 'trim|required');
			$this->form_validation->set_rules('password', display('password'), 'trim|required');
			$this->form_validation->set_rules('confirm_password', 'Confirm Password', 'required|matches[password]');
			$changePassword = true;
		}

		//end added confirm password

		// if ($this->Settings->googlecaptchaverify("abd") == true) {
		// 	echo "true";
		// }

		// echo $this->input->post('recaptcha_response');
		// if ($this->googlecaptchaverify($this->input->post('recaptcha_response')) == true) {
		// 	echo "true";
		// }
		// if ($this->googlecaptchaverify($this->input->post('recaptcha_response')) == false) {
		// 	echo "false";
		// }

		$customerinfo = $this->Customerinfo->get_customer_details();
		// echo $customerinfo[0]['customer_email'];

		// echo md5("gef" . $this->input->post('password', TRUE));

		if (!empty($this->input->post('recaptcha_response'))) {
			if ($this->Settings->googlecaptchaverify($this->input->post('recaptcha_response')) == true) {

				//get receive email checkbox
				$receive_email = 0;
				if ($this->input->post('receive_email', TRUE) == "on") {
					$receive_email = 1;
				}
				//end get receive email checkbox

				//check email is register or not

				$registerEmail = $this->Homes->check_customer_not_tempUser($this->input->post('email', TRUE));
				// echo $this->db->last_query();
				// echo "registerEmail";
				// var_dump($registerEmail);
				if ($registerEmail != false && trim($customerinfo[0]['customer_email']) != trim($this->input->post('email', TRUE))) {
					$this->session->set_userdata(array('error_message' => display('this_email_already_exists')));
					// echo "email already exist.";
					// $this->index();
					// redirect('signup');
					redirect('customer/cust_info');
					// echo "have user ema";
				} //if ($registerEmail == TRUE) {

				if ($changePassword == true) {
					$inputpassword = md5("gef" . $this->input->post('user_current_pw', TRUE));
					if ($customerinfo[0]['password'] != $inputpassword) {
						$this->session->set_userdata(array('error_message' => display('password_not_match')));
						// echo "email already exist.";
						// $this->index();
						// redirect('signup');
						// echo "not match password";
						redirect('customer/cust_info');
					}
				}
				//end check email is register or not

				if ($this->form_validation->run() == TRUE) {
					$data = array(
						// 'customer_id' => $this->generator(15),
						'first_name' => $this->input->post('first_name', TRUE),
						'last_name' => $this->input->post('last_name', TRUE),
						'customer_name' => $this->input->post('first_name', TRUE) . ' ' . $this->input->post('last_name', TRUE),
						'customer_email' => $this->input->post('email', TRUE),
						'customer_mobile' => $this->input->post('phone', TRUE),
						// 'image' => 'assets/dist/img/user.png',
						// 'password' => md5("gef" . $this->input->post('password', TRUE)),
						'status' => 1,
						//added receive email
						'receive_email' => $receive_email,
						//end added receive email
						//added introducer email
						'introducer_email' => $this->input->post('introducer_email', TRUE),
						//end added introducer email
						// 'tempUser' => 0, //for mark as tempUser
					);
					if ($changePassword == true) {
						$data['password'] = md5("gef" . $this->input->post('password', TRUE));
					}
					// var_dump($data);
					// $result = $this->Signups->user_update($data);
					$result = $this->Customerinfo->user_update($data);

					if ($result) {

						$this->session->set_userdata(array(
							'message' => display('you_have_successfully_signup'),
							'customer_email' => $this->input->post('email', TRUE),
						));

						$email = $this->input->post('email', TRUE);
						$password = $this->input->post('password', TRUE);
						$login = $this->user_auth->login($email, $password);
						redirect('customer/cust_info'); //hide when in production
						// redirect(''); //redirect to front page

					} else {
						$this->session->set_userdata(array('error_message' => display('you_have_not_sign_up')));
						//update error
					}
				} else {
					// redirect('customer/cust_info');
					$this->session->set_userdata(array('error_message' => validation_errors()));
					redirect('customer/cust_info');
				}
			} //if ($this->Settings->googlecaptchaverify($this->input->post('recaptcha_response')) == true) {
		} //if (!empty($this->input->post('recaptcha_response'))) {

		// $this->index();
		redirect('customer/cust_info');
	} //public function cust_info_form_update(){

	public function customer_delivery_address_update() {
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}

		$customer_id = $this->session->userdata('customer_id');
		//Customer  basic information adding.
		$data = array(
			'delivery_id' => $this->input->post('delivery_id', TRUE),

			'customer_name' => $this->input->post('first_name', TRUE) . " " . $this->input->post('last_name', TRUE),
			'first_name' => $this->input->post('first_name', TRUE),
			'last_name' => $this->input->post('last_name', TRUE),
			'customer_email' => $this->input->post('email', TRUE),
			'customer_mobile' => $this->input->post('mobile2', TRUE),
			'customer_address_1' => $this->input->post('customer_address_1', TRUE),
			'customer_address_2' => $this->input->post('customer_address_2', TRUE),
			'city' => $this->input->post('city', TRUE),
			'state' => $this->input->post('state', TRUE),
			'country' => $this->input->post('country', TRUE),
			'zip' => $this->input->post('zip', TRUE),
		);
		$result = $this->Customerinfo->update_delivery_address($data, $customer_id);
		if ($result == TRUE) {

			$this->session->set_userdata(array('message' => display('successfully_updated')));
			redirect('customer/customer_update_delivery_address_form' . '/' . $this->input->post('delivery_id', TRUE));
		} else {
			$this->session->set_userdata(array('message' => display('failed')));
			redirect('customer/customer_update_delivery_address_form' . '/' . $this->input->post('delivery_id', TRUE));
		}

	} //public function customer_delivery_address_update() {

	public function customer_add_delivery_address_form() {
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');
		// $total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		// $total_order = $this->Orders->total_customer_order($customer_id);

		// $currency_details = $this->Soft_settings->retrieve_currency_info();
		// $currency_info = $this->Homes->currency_info();
		// $selected_currency_info = $this->Homes->selected_currency_info();

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		$customerinfo = $this->Customerinfo->get_customer_details();
		$selected_country_info = $this->Homes->selected_country_info();
		$state_list = $this->Customers->select_city_country_id($customer->country);
		// var_dump($selected_country_info);
		//end added get customer info

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		// $customer_id = $this->session->userdata('customer_id');
		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'delivery_address',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,

			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,

			//added details
			'customerinfo' => $customerinfo,
			'selected_country_info' => $selected_country_info,
			'state_list' => $state_list,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info
		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);
		$content = $this->parser->parse('web/customer/customer_add_delivery_address_form', $data, true);
		$this->template_lib->full_website_html_view($content);
	} //public function customer_add_delivery_address_form() {
	// public function customer_billing_address_add() {
	// 	if (!$this->user_auth->is_logged()) {
	// 		$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
	// 	}

	// 	// $customer_id = $this->session->userdata('customer_id');
	// 	//Customer  basic information adding.

	// 	$data = array(
	// 		// 'customer_id' => $customer_id,
	// 		'customer_name' => $this->input->post('first_name', TRUE) . " " . $this->input->post('last_name', TRUE),
	// 		'first_name' => $this->input->post('first_name', TRUE),
	// 		'last_name' => $this->input->post('last_name', TRUE),
	// 		'customer_email' => $this->input->post('email', TRUE),
	// 		'customer_mobile' => $this->input->post('mobile2', TRUE),
	// 		'customer_address_1' => $this->input->post('customer_address_1', TRUE),
	// 		'customer_address_2' => $this->input->post('customer_address_2', TRUE),
	// 		'city' => $this->input->post('city', TRUE),
	// 		'state' => $this->input->post('state', TRUE),
	// 		'country' => $this->input->post('country', TRUE),
	// 		'zip' => $this->input->post('zip', TRUE),
	// 	);
	// 	$result = $this->Customerinfo->insert_billing_address($data);

	// 	if ($result == TRUE) {
	// 		$this->session->set_userdata(array('message' => display('successfully_added')));
	// 		redirect('customer/customer_add_delivery_address_form');
	// 	} else {
	// 		$this->session->set_userdata(array('error_message' => display('failed')));
	// 		redirect(base_url('customer/customer_add_delivery_address_form'));
	// 	}

	// }
	public function customer_delivery_address_add() {
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}

		// $customer_id = $this->session->userdata('customer_id');
		//Customer  basic information adding.

		$data = array(
			// 'customer_id' => $customer_id,
			'customer_name' => $this->input->post('first_name', TRUE) . " " . $this->input->post('last_name', TRUE),
			'first_name' => $this->input->post('first_name', TRUE),
			'last_name' => $this->input->post('last_name', TRUE),
			'customer_email' => $this->input->post('email', TRUE),
			'customer_mobile' => $this->input->post('mobile2', TRUE),
			'customer_address_1' => $this->input->post('customer_address_1', TRUE),
			'customer_address_2' => $this->input->post('customer_address_2', TRUE),
			'city' => $this->input->post('city', TRUE),
			'state' => $this->input->post('state', TRUE),
			'country' => $this->input->post('country', TRUE),
			'zip' => $this->input->post('zip', TRUE),
		);
		$result = $this->Customerinfo->insert_delivery_address($data);

		if ($result == TRUE) {
			$this->session->set_userdata(array('message' => display('successfully_added')));
			redirect('customer/customer_add_delivery_address_form');
		} else {
			$this->session->set_userdata(array('error_message' => display('failed')));
			redirect(base_url('customer/customer_add_delivery_address_form'));
		}
	} //public function customer_delivery_address_add() {

	public function customer_update_delivery_address_form($delivery_id) {
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		// $customerinfo = $this->Customerinfo->get_customer_details();
		$selected_country_info = $this->Homes->selected_country_info();
		$state_list = $this->Customers->select_city_country_id($customer->country);

		$delivery_detail = $this->Customerinfo->get_delivery_address($delivery_id);

		// var_dump($selected_country_info);
		//end added get customer info

		$customer_id = $this->session->userdata('customer_id');

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'delivery_address',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,

			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,

			//added details
			// 'customerinfo' => $customerinfo,
			'selected_country_info' => $selected_country_info,
			'state_list' => $state_list,
			'delivery_id' => $delivery_id,
			'delivery_detail' => $delivery_detail,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info
		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);
		$content = $this->parser->parse('web/customer/customer_update_delivery_address_form', $data, true);
		$this->template_lib->full_website_html_view($content);
	} //public function customer_update_delivery_address_form($delivery_id) {
	public function shop_cart() {
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$this->load->model('web/Products_model');
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');
		// $total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		// $total_order = $this->Orders->total_customer_order($customer_id);

		// $currency_details = $this->Soft_settings->retrieve_currency_info();
		// $currency_info = $this->Homes->currency_info();
		// $selected_currency_info = $this->Homes->selected_currency_info();

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		// $customerinfo = $this->Customerinfo->get_customer_details();
		// $selected_country_info = $this->Homes->selected_country_info();
		// $state_list = $this->Customers->select_city_country_id($customer->country);
		// var_dump($selected_country_info);
		//end added get customer info

		//load shopping cart details
		$cartlistArray = array();
		foreach ($this->cart->contents() as $items) {
			$itemList = array();
			$itemList['rowid'] = $items['rowid'];
			$itemList['name'] = $items['name'];
			$itemList['variant'] = $items['variant'];
			$itemList['variant_color'] = $items['variant_color'];
			$itemList['price'] = $items['price'];
			$itemList['qty'] = $items['qty'];

			//check have stock of not
			$cartinfo = $this->cart->get_item($items['rowid']);
			// $stock = $CI->Products_model->check_variant_wise_stock($cartinfo['variant'], $cartinfo['product_id']); //compare issue invoice stock - sell greater then purchase stock

			$stock = $this->Products_model->check_order_variant_wise_stock($cartinfo['variant'], $cartinfo['product_id']); //compare against order to purchase stock - sell same as purchase

			//0 stand for have stock
			//1 means out of stock
			$itemList['withoutstock'] = 0;
			if ($items['qty'] > $stock) {
				$itemList['withoutstock'] = 1;
			}
			//end check have stock of not

			array_push($cartlistArray, $itemList);
		} //foreach ($CI->cart->contents() as $items) {
		// var_dump($cartlistArray);
		//end load shopping cart details

		//added currency data
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$currency = $currency_details[0]['currency_icon'];
		$position = $currency_details[0]['currency_position'];

		//Currency wise price change
		$default_currency_id = $this->session->userdata('currency_id');
		$currency_new_id = $this->session->userdata('currency_new_id');

		if (empty($currency_new_id)) {
			$result = $cur_info = $this->db->select('*')
				->from('currency_info')
				->where('default_status', '1')
				->get()
				->row();
			$currency_new_id = $result->currency_id;
		}

		if (!empty($currency_new_id)) {
			$cur_info = $this->db->select('*')
				->from('currency_info')
				->where('currency_id', $currency_new_id)
				->get()
				->row();

			$target_con_rate = $cur_info->convertion_rate;
			$position1 = $cur_info->currency_position;
			$currency1 = $cur_info->currency_icon;
		}
		//Currency wise price change

		//end added currency data

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		// $customer_id = $this->session->userdata('customer_id');
		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'shop_cart',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,
			//added details
			'cartlistArray' => $cartlistArray,
			'target_con_rate' => $target_con_rate,
			// 'customerinfo' => $customerinfo,
			// 'selected_country_info' => $selected_country_info,
			// 'state_list' => $state_list,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info

			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,
		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);
		$content = $this->parser->parse('web/customer/shop_cart', $data, true);
		$this->template_lib->full_website_html_view($content);
	} //public function shop_cart() {

	public function order_record_detail($order_id) {
		//Display customer order record detail
		// if (!$this->user_auth->is_logged()) {
		// 	$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		// }
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');

		//added to get customer information
		$order_record = $this->Orders->get_order_by_orderid($order_id);
		$order_array = array();
		$order_array['order_id'] = $order_record->order_id;
		$order_array['customer_id'] = $order_record->customer_id;
		$order_array['store_id'] = $order_record->store_id;
		$order_array['user_id'] = $order_record->user_id;
		$order_array['date'] = $order_record->date;
		$order_array['total_amount'] = $order_record->total_amount;
		$order_array['order'] = $order_record->order;
		$order_array['details'] = $order_record->details;
		$order_array['total_discount'] = $order_record->total_discount;
		$order_array['order_discount'] = $order_record->order_discount;
		$order_array['service_charge'] = $order_record->service_charge;
		$order_array['paid_amount'] = $order_record->paid_amount;
		$order_array['due_amount'] = $order_record->due_amount;
		$order_array['file_path'] = $order_record->file_path;
		$order_array['coupon'] = $order_record->coupon;
		$order_array['status'] = $order_record->status;
		$order_array['created_at'] = $order_record->created_at;

		$order_productlist = $this->Orders->get_order_productlist($order_id);

		$order_paymentmethod = $this->Orders->get_order_paymentmethodWithOutPoint($order_id); //not so usful
		$order_status = $this->Orders->checkOrderStatus($order_id);

		//need to get coupon amount

		//end need to get coupon amount

		//need to get used point amount
		$order_usedrewardpoint = $this->Orders->getOrderUsedRewardPoint($order_id);
		//end need to get used point amount

		// echo "order";
		// var_dump($order);
		// echo "<br>";
		// echo "<br>";
		// echo "order_productlist";
		// var_dump($order_productlist);
		// if ($order_detail[0]['customer_id'] != $customer_id) {
		// 	return;
		// }

		//end added to get customer information

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		// $customerinfo = $this->Customerinfo->get_customer_details();
		// $selected_country_info = $this->Homes->selected_country_info();
		// $state_list = $this->Customers->select_city_country_id($customer->country);

		// $delivery_detail = $this->Customerinfo->get_delivery_address($delivery_id);

		// var_dump($selected_country_info);
		//end added get customer info

		$customer_id = $this->session->userdata('customer_id');

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		$data = array(
			'title' => display('sign_up'),
			// 'category_id' => 'order_record_detail',//actucal
			'category_id' => 'order_record',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,
			// 'order_record' => $order_record,
			'order_array' => $order_array,
			'order_productlist' => $order_productlist,
			'order_paymentmethod' => $order_paymentmethod,
			'order_status' => $order_status,
			'order_usedrewardpoint' => $order_usedrewardpoint,
			//added details
			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,
			// 'customerinfo' => $customerinfo,
			// 'selected_country_info' => $selected_country_info,
			// 'state_list' => $state_list,
			// 'delivery_id' => $delivery_id,
			// 'delivery_detail' => $delivery_detail,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info
		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);
		$content = $this->parser->parse('web/customer/order_record_detail', $data, true);
		$this->template_lib->full_website_html_view($content);
	} //public function order_record_detail($order_id)
	public function order_detail_pdf($order_id) {
		$this->load->library('occational');
		$this->load->library('pdfgenerator');
		//Pdf generator not support chinese
		$customer_id = $this->session->userdata('customer_id');
		$order_detail = $this->Orders->retrieve_order_html_data($order_id);
		if ($order_detail[0]['customer_id'] != $customer_id) {
			return;
		}
		// echo $this->db->last_query();
		//it get duplicated record of information
		// var_dump($order_detail);
		$payinfo = $this->Orders->get_order_payinfo($order_id);
		$subTotal_quantity = 0;
		$subTotal_cartoon = 0;
		$subTotal_discount = 0;

		if (!empty($order_detail)) {
			foreach ($order_detail as $k => $v) {
				$order_detail[$k]['final_date'] = $this->occational->dateConvert($order_detail[$k]['date']);
				$subTotal_quantity = $subTotal_quantity + $order_detail[$k]['quantity'];
			}
			$i = 0;
			foreach ($order_detail as $k => $v) {
				$i++;
				$order_detail[$k]['sl'] = $i;
			}
		}

		$currency_details = $this->Soft_settings->retrieve_currency_info();

		//may be ignore
		$company_info = $this->Orders->retrieve_company();

		//added to get company details
		$this->load->model('dashboard/Web_settings');
		$Web_settings = $this->Web_settings->retrieve_setting_editdata();
		//end

		//get ship country name
		$country = $this->db->select('*')
			->from('countries')
			->where('id', $order_detail[0]['country'])
			->get()
			->row();
		// var_dump($country);

		$ship_country = $this->db->select('*')
			->from('countries')
			->where('id', $order_detail[0]['ship_country'])
			->get()
			->row();
		//end get ship country name

		// order used point
		//need to get used point amount
		$order_usedrewardpoint = $this->Orders->getOrderUsedRewardPoint($order_id);
		//end need to get used point amount

		// end order used point

		$data = array(
			'title' => display('order_details'),
			'order_id' => $order_detail[0]['order_id'],
			'order_no' => $order_detail[0]['order'],
			'customer_address' => $order_detail[0]['customer_short_address'],
			'customer_name' => $order_detail[0]['customer_name'],
			'customer_mobile' => $order_detail[0]['customer_mobile'],
			'customer_email' => $order_detail[0]['customer_email'],
			'final_date' => $order_detail[0]['final_date'],
			'total_amount' => $order_detail[0]['total_amount'],
			'order_discount' => $order_detail[0]['order_discount'],
			'service_charge' => $order_detail[0]['service_charge'],
			'paid_amount' => $order_detail[0]['paid_amount'],
			'due_amount' => $order_detail[0]['due_amount'],
			'details' => $order_detail[0]['details'],
			'subTotal_quantity' => $subTotal_quantity,
			'order_all_data' => $order_detail,
			'company_info' => $company_info,
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'payinfo' => $payinfo,
			'mobile1' => '123',
			'companytitle' => $Web_settings[0]['companytitle'],
			'email' => $Web_settings[0]['email'],
			'phone' => $Web_settings[0]['phone'],
			'whatsapp' => $Web_settings[0]['whatsapp'],
			'customer_address_1' => $order_detail[0]['customer_address_1'],
			'customer_address_2' => $order_detail[0]['customer_address_2'],
			'city' => $order_detail[0]['city'],
			'state' => $order_detail[0]['state'],
			'country_code' => $order_detail[0]['country'],
			'country' => $country->name,
			'zip' => $order_detail[0]['zip'],
			'ship_customer_name' => $order_detail[0]['ship_customer_name'],
			'ship_first_name' => $order_detail[0]['ship_first_name'],
			'ship_last_name' => $order_detail[0]['ship_last_name'],
			'ship_customer_short_address' => $order_detail[0]['ship_customer_short_address'],
			'ship_customer_address_1' => $order_detail[0]['ship_customer_address_1'],
			'ship_customer_address_2' => $order_detail[0]['ship_customer_address_2'],
			'ship_customer_mobile' => $order_detail[0]['ship_customer_mobile'],
			'ship_customer_email' => $order_detail[0]['ship_customer_email'],
			'ship_city' => $order_detail[0]['ship_city'],
			'ship_state' => $order_detail[0]['ship_state'],
			'ship_country_code' => $order_detail[0]['ship_country'],
			'ship_country' => $ship_country->name,
			'ship_zip' => $order_detail[0]['ship_zip'],
			'order_usedrewardpoint' => $order_usedrewardpoint,
			'order_detail' => $order_detail,
		);

		// var_dump($order_detail);
		// $pdfhtml = $this->parser->parse('dashboard/order/order_pdf', $data, true);
		$pdfhtml = $this->parser->parse('dashboard/order/customer_order_pdf', $data, true);
		// var_dump($pdfhtml);
		$file_path = $this->pdfgenerator->generate_order($order_id, $pdfhtml);
		$this->load->helper('download');
		force_download($file_path, NULL);
		redirect('dashboard/Corder/manage_order');
	} //public function order_detail_pdf() {

	//added to redirect to new style
	public function newstyle() {
		//may be move one level up of template

		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');
		// $total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		// $total_order = $this->Orders->total_customer_order($customer_id);

		// $currency_details = $this->Soft_settings->retrieve_currency_info();
		// $currency_info = $this->Homes->currency_info();
		// $selected_currency_info = $this->Homes->selected_currency_info();

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		$customer_id = $this->session->userdata('customer_id');
		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'customer_dashboard',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,

			//added company info
			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,

			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info
		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);
		$content = $this->parser->parse('web/customer/customer_home_newstyle', $data, true);
		$this->template_lib->full_website_html_view($content);
	}
	public function order_record() {
		$this->load->library('occational');
		//http://bigmacmall3.artech-system.com/customer/order_record
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}

		//added general details
		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//end added general details

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		$customer_id = $this->session->userdata('customer_id');
		$total_order = $this->Orders->total_customer_order($customer_id);
		$order_list = $this->Orders->order_list();

		//convert order list

		if (!empty($order_list)) {
			foreach ($order_list as $k => $v) {
				$order_list[$k]['final_date'] = $this->occational->dateConvertYmd($order_list[$k]['date']);

				// $order_list[$k]['customer_order_details'] = $this->Orders->customer_order_details($order_list[$k]['order_id']);
				$order_list[$k]['customer_order_details'] = $this->Orders->get_order_productlist($order_list[$k]['order_id']);

				$order_list[$k]['customer_order_paymentmethod'] = $this->Orders->get_order_paymentmethod($order_list[$k]['order_id']);
				$order_list[$k]['customer_order_status'] = $this->Orders->checkOrderStatus($order_list[$k]['order_id']);
			}
			$i = 0;
			foreach ($order_list as $k => $v) {
				$i++;
				$order_list[$k]['sl'] = $i;
			}
		}

		//end convert order list

		$currency_details = $this->Soft_settings->retrieve_currency_info();

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'order_record',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],

			//added company info
			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,
			// 'customer' => $customer,
			'order_list' => $order_list,
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info
		);
		$content = $this->parser->parse('web/customer/order/customer_order', $data, true);
		$this->template_lib->full_website_html_view($content);
	}

	//end added to redirect to new style
	#========Logout=======#
	public function logout() {
		if ($this->user_auth->logout()) {
			$this->output->set_header("Location: " . base_url(), TRUE, 302);
		}

	}

	//Update user profile from
	public function edit_profile() {
		$this->load->model('dashboard/Customers');
		$edit_data = $this->Customer_dashboards->profile_edit_data();
		$state_list = $this->Customers->select_city_country_id($edit_data->country);
		$country_list = $this->Customers->country_list();

		$data = array(
			'title' => display('update_profile'),
			'first_name' => $edit_data->first_name,
			'last_name' => $edit_data->last_name,
			'email' => $edit_data->customer_email,
			'image' => base_url() . $edit_data->image,
			'customer_short_address' => $edit_data->customer_short_address,
			'customer_address_1' => $edit_data->customer_address_1,
			'customer_address_2' => $edit_data->customer_address_2,
			'city' => $edit_data->city,
			'state' => $edit_data->state,
			'state_name' => $edit_data->state,
			'country' => $edit_data->country,
			'country_id' => $edit_data->country,
			'zip' => $edit_data->zip,
			'customer_mobile' => $edit_data->customer_mobile,
			'company' => $edit_data->company,
			'state_list' => $state_list,
			'country_list' => $country_list,
		);

		$data['Soft_settings'] = $this->soft_settings->retrieve_setting_editdata();
		$data['module'] = "web";
		$data['page'] = "customer/edit_profile";

		$this->parser->parse('customer/customer_html_template', $data);

	}

	#=============Update Profile========#
	public function update_profile() {
		$this->Customer_dashboards->profile_update();
		$this->session->set_userdata(array('message' => display('successfully_updated')));
		redirect(base_url('web/customer/customer_dashboard/edit_profile'));
	}

	#=============Change Password Form=========#
	public function change_password_form() {
		$data['Soft_settings'] = $this->soft_settings->retrieve_setting_editdata();
		$data['title'] = display('change_password');
		$data['module'] = "web";
		$data['page'] = "customer/change_password";

		$this->parser->parse('customer/customer_html_template', $data);

	}

	#============Change Password===========#
	public function change_password() {
		$error = '';
		$email = $this->input->post('email', TRUE);
		$old_password = $this->input->post('old_password', TRUE);
		$new_password = $this->input->post('password', TRUE);
		$repassword = $this->input->post('repassword', TRUE);

		$edit_data = $this->Customer_dashboards->profile_edit_data();
		$old_email = $edit_data->customer_email;

		if ($email == '' || $old_password == '' || $new_password == '') {
			$error = display('blank_field_does_not_accept');
		} else if ($email != $old_email) {
			$error = display('you_put_wrong_email_address');
		} else if (strlen($new_password) < 6) {
			$error = display('new_password_at_least_six_character');
		} else if ($new_password != $repassword) {
			$error = display('password_and_repassword_does_not_match');
		} else if ($this->Customer_dashboards->change_password($email, $old_password, $new_password) === FALSE) {
			$error = display('you_are_not_authorised_person');
		}

		if ($error != '') {
			$this->session->set_userdata(array('error_message' => $error));
			$this->output->set_header("Location: " . base_url() . 'web/customer/customer_dashboard/change_password_form', TRUE, 302);
		} else {
			$logout = $this->user_auth->logout();
			if ($logout) {
				$this->session->set_userdata(array('message' => display('successfully_changed_password')));
				$this->output->set_header("Location: " . base_url() . 'login', TRUE, 302);
			}
		}
	}

	//Select city by country id
	public function select_city_country_id() {
		$this->load->model('dashboard/Customers');
		$country_id = $this->input->post('country_id', TRUE);
		$states = $this->Customers->select_city_country_id($country_id);

		$html = "";
		if ($states) {
			$html .= "<select class=\"form-control select2\" id=\"country\" name=\"country\" style=\"width: 100%\">";
			foreach ($states as $state) {
				$html .= "<option value='" . $state->name . "'>" . $state->name . "</option>";
			}
			$html .= "</select>";
		}
		echo $html;
	}
	public function cust_wish_list() {

		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');
		// $total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		// $total_order = $this->Orders->total_customer_order($customer_id);

		// $currency_details = $this->Soft_settings->retrieve_currency_info();
		// $currency_info = $this->Homes->currency_info();
		// $selected_currency_info = $this->Homes->selected_currency_info();

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		$customerinfo = $this->Customerinfo->get_customer_details();
		$selected_country_info = $this->Homes->selected_country_info();
		$deliveryaddress = $this->Customerinfo->get_customer_billing_address();
		//end added get customer info

		$customer_id = $this->session->userdata('customer_id');

		//wish list data
		$brand = $this->input->get('brand', TRUE);
		if (is_numeric($brand)) {
			$brand = '';
		}
		$price_range = $this->input->get('price', TRUE);
		$size = $this->input->get('size', TRUE);
		$rate = $this->input->get('rate', TRUE);

		$displaynum = $this->input->get('displaynum', TRUE);
		if (empty($displaynum)) {
			// $displaynum = 6;
			// $displaynum = 1;
			$displaynum = 6;
		}
		$sorting = $this->input->get('sorting', TRUE);

		if (empty($sorting)) {
			$sorting = 'lastest'; //default sorting of product
		}

		$filter = array(
			'price_range' => $price_range,
			'size' => $size,
			'rate' => $rate,
			'brand' => $brand,
			'displaynum' => $displaynum,

		);
		$customer_id = $this->session->userdata('customer_id');
		// $config["base_url"] = base_url('customer/wish_list_info' . $customer_id);
		$config["base_url"] = base_url('customer/wish_list');

		$config["total_rows"] = $this->custwishlist->customer_wish_list_count($customer_id, $filter);
		// $config["total_rows"] = 10;

		$config["per_page"] = $displaynum; //change to displayorder

		$config["uri_segment"] = 3;
		$config["num_links"] = 5;
		/* This Application Must Be Used With BootStrap 3 * */
		$config['full_tag_open'] = "<ul class='pagination justify-content-center'>";
		$config['full_tag_close'] = "</ul>";
		$config['num_tag_open'] = "<li class='page-item'>";
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='page-item active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li class='page-item'>";
		$config['next_tag_close'] = "</li>";
		$config['prev_tag_open'] = "<li class='page-item'>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li class='page-item'>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li class='page-item'>";
		$config['last_tagl_close'] = "</li>";
		// $config['prev_link'] = 'Previous';
		// $config['next_link'] = 'Next';
		$config['prev_link'] = '<';
		$config['next_link'] = '>';

		$config['first_link'] = '<<';
		$config['last_link'] = '>>';

		//added reuse get string
		$config['reuse_query_string'] = true;
		//end added reuse get string

		/* ends of bootstrap */
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		$links = $this->pagination->create_links();

		// echo "control link";
		// var_dump($links);

		$displayorder = 1;
		$max_value = 0;
		$min_value = 0;
		$cat_id = "";
		$wish_list_product = $this->custwishlist->customer_wish_list_product($cat_id, $links, $config["per_page"], $page, $price_range, $size, $brand, $rate, $displayorder, $sorting, $customer_id);

		$num_wish_list_product = $this->custwishlist->count_wish_list_product($cat_id, $links, $config["per_page"], $page, $price_range, $size, $brand, $rate, $displayorder, $sorting, $customer_id);

		$total = 0;

		//end wish list data

		//added to get target con rate
		$default_currency_id = $this->session->userdata('currency_id');
		$currency_new_id = $this->session->userdata('currency_new_id');
		if (empty($currency_new_id)) {
			$result = $cur_info = $this->db->select('*')
				->from('currency_info')
				->where('default_status', '1')
				->get()
				->row();
			$currency_new_id = $result->currency_id;
		}

		if (!empty($currency_new_id)) {
			$cur_info = $this->db->select('*')
				->from('currency_info')
				->where('currency_id', $currency_new_id)
				->get()
				->row();

			$target_con_rate = $cur_info->convertion_rate;
			$position1 = $cur_info->currency_position;
			$currency1 = $cur_info->currency_icon;
		}

		//end added to get target con rate

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'wisht_list',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,
			//added details
			'customerinfo' => $customerinfo,
			'selected_country_info' => $selected_country_info,
			'deliveryaddress' => $deliveryaddress,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,

			//end added company info
			//wish list data
			'links' => $links,
			'page' => $page,
			'wish_list_product' => $wish_list_product,
			'target_con_rate' => $target_con_rate,
			'position1' => $position1,
			'currency1' => $currency1,
			'totalwishlist' => $config["total_rows"],
			//end wish list data

		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);

		$content = $this->parser->parse('web/customer/wishlistinfo', $data, true);
		// $content = $this->parser->parse('web/customer/delivery_address', $data2, true);
		$this->template_lib->full_website_html_view($content);
		// echo "cust_wish_list";
	}
	// show wishlist

	//added wish list info
	public function wish_listinfo() {
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');
		// $total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		// $total_order = $this->Orders->total_customer_order($customer_id);

		// $currency_details = $this->Soft_settings->retrieve_currency_info();
		// $currency_info = $this->Homes->currency_info();
		// $selected_currency_info = $this->Homes->selected_currency_info();

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		$customerinfo = $this->Customerinfo->get_customer_details();
		$selected_country_info = $this->Homes->selected_country_info();
		$deliveryaddress = $this->Customerinfo->get_customer_billing_address();
		//end added get customer info

		$customer_id = $this->session->userdata('customer_id');
		$data = array(
			'title' => display('sign_up'),
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,
			//added details
			'customerinfo' => $customerinfo,
			'selected_country_info' => $selected_country_info,
			'deliveryaddress' => $deliveryaddress,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info
		);

		$content = $this->parser->parse('web/customer/wishlistinfo', $data, true);
		$this->template_lib->full_website_html_view($content);
	} //public function wishlistinfo() {
	//end 	added wish list info

	public function wishlist() {
		$customer_id = $this->session->userdata('customer_id');

		$this->db->select('a.*,b.product_name,b.product_model');
		$this->db->from('wishlist a');
		$this->db->join('product_information b', 'b.product_id = a.product_id');
		$this->db->where('a.user_id', $customer_id);
		$this->db->order_by('wishlist_id', 'desc');
		$query = $this->db->get();
		if ($query->num_rows() > 0) {
			$wishlists = $query->result_array();
		} else {
			$wishlists = '';
		}

		$data = [
			'wishlists' => $wishlists,
		];

		$content = $this->parser->parse('web/customer/wishlist', $data, true);
		$this->template_lib->full_customer_html_view($content);
	}

	//delete wishlist
	public function wishlist_delete($wishlist_id) {
		$this->Wishlists->delete_wishlist($wishlist_id);
		$this->session->set_userdata(array('message' => display('successfully_delete')));
		redirect('web/customer/customer_dashboard/wishlist');
	}

	//fun record
	public function fun_record() {
		if (!$this->user_auth->is_logged()) {
			$this->output->set_header("Location: " . base_url('login'), TRUE, 302);
		}
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customer_id = $this->session->userdata('customer_id');
		// $total_invoice = $this->Invoices->total_customer_invoice($customer_id);
		// $total_order = $this->Orders->total_customer_order($customer_id);

		// $currency_details = $this->Soft_settings->retrieve_currency_info();
		// $currency_info = $this->Homes->currency_info();
		// $selected_currency_info = $this->Homes->selected_currency_info();

		$parent_category_list = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Signups->best_sales();
		$footer_block = $this->Signups->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//added get customer info
		$customerinfo = $this->Customerinfo->get_customer_details();
		// $selected_country_info = $this->Homes->selected_country_info();
		// $deliveryaddress = $this->Customerinfo->get_customer_billing_address();
		//end added get customer info

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		//customer fun record
		$customer_id = $this->session->userdata('customer_id');

		$user_point = $this->Custpoint_model->getUserPoint($customer_id, 'yes');
		$customer_fun_record = $this->Custpoint_model->getCustomerPointRecord($customer_id, 'yes');
		$customer_usedfun_record = $this->Custpoint_model->getCustomerUsedPointRecord($customer_id, 'yes');

		$customer_all_point_record = array();

		//customer fun record
		foreach ($customer_fun_record as $fun_record) {
			$customer_record = array();
			$customer_record['order_id'] = $fun_record->order_id;
			$customer_record['customer_id'] = $fun_record->customer_id;

			$order_details = $this->Orders->get_order_by_orderid_nolimit_custid($fun_record->order_id);
			$order_product_list = $this->Orders->get_order_productlist($fun_record->order_id);
			$customer_info = $this->Customerinfo->get_customer_details_nolimit_custom_id($order_details[0]['customer_id']);

			$customer_record['date'] = $fun_record->date;
			$customer_record['available_date'] = $this->Custpoint_model->getAvailableDate($fun_record->date);
			$customer_record['order_details'] = $order_product_list;
			// var_dump($order_product_list);
			$customer_record['total_amount'] = $order_details[0]['total_amount'];
			$customer_record['custname'] = $customer_info[0]['customer_name'];
			$customer_record['referlevel'] = $this->Custpoint_model->getIntroducerLevel($fun_record->customer_id, $fun_record->referer_id, $fun_record->referer);
			$customer_record['amount'] = $fun_record->amount;

			// echo "---------<br><br>";
			// var_dump($order_details);
			// echo "---------<br><br>";

			// echo "---------<br><br>";
			// var_dump($customer_info);
			// echo "---------<br><br>";
			array_push($customer_all_point_record, $customer_record);
		} //foreach ($customer_fun_record as $fun_record) {
		//end customer fun record

		//customer used fun record

		foreach ($customer_usedfun_record as $usedfun_record) {
			$customer_usedrecord = array();
			$customer_usedrecord['order_id'] = $usedfun_record->order_id;
			$customer_usedrecord['customer_id'] = $usedfun_record->customer_id;
			$order_details = $this->Orders->get_order_by_orderid_nolimit_custid($usedfun_record->order_id);
			$order_product_list = $this->Orders->get_order_productlist($usedfun_record->order_id);
			$customer_info = $this->Customerinfo->get_customer_details_nolimit_custom_id($order_details[0]['customer_id']);

			$customer_usedrecord['date'] = $usedfun_record->date;
			$customer_usedrecord['available_date'] = "";
			$customer_usedrecord['order_details'] = $order_product_list;
			// var_dump($order_product_list);
			$customer_usedrecord['total_amount'] = $order_details[0]['total_amount'];
			$customer_usedrecord['custname'] = $customer_info[0]['customer_name'];
			$customer_usedrecord['referlevel'] = '-';
			$customer_usedrecord['amount'] = -$usedfun_record->actual_value;
			array_push($customer_all_point_record, $customer_usedrecord);
		} //foreach ($customer_usedfun_record as $usedfun_record) {

		//end customer used fun record

		// var_dump($customer_fun_record);
		// var_dump($customer_usedfun_record);
		// echo "<br>";
		// var_dump($customer_all_point_record);
		//end customer fun record

		$data = array(
			'title' => display('sign_up'),
			'category_id' => 'fun_record',
			'category_list' => $parent_category_list,
			'pro_category_list' => $pro_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'customerDetails' => $customerDetails,
			'customer_id' => $customer_id,
			//added details
			'customerinfo' => $customerinfo,
			'user_point' => $user_point,
			// 'selected_country_info' => $selected_country_info,
			// 'deliveryaddress' => $deliveryaddress,
			// 'company_info' => $company_info,
			// 'company_name' => $company_info[0]['company_name'],
			// 'email' => $company_info[0]['email'],
			// 'address' => $company_info[0]['address'],
			// 'mobile' => $company_info[0]['mobile'],
			// 'website' => $company_info[0]['website'],
			// 'theme' => $theme,

			//end added company info
			'customer_all_point_record' => $customer_all_point_record,
			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,

		);
		// $content = $this->parser->parse('web/customer/include/customer_home_newstyle', $data, true);
		$content = $this->parser->parse('web/customer/fun_record', $data, true);
		$this->template_lib->full_website_html_view($content);
	}
	public function fun_shop() {

		// $cat_id = "J6CKE58L8XEWKDL"; //special for reward point shop
		$cat_id = $this->config->item('reward_shop_category');
		//reward category id
		// if (is_numeric($brand)) {
		$brand = '';
		// }
		// $price_range = $this->input->get('price', TRUE);
		$price_range = '';
		// $size = $this->input->get('size', TRUE);
		$size = '';
		// $rate = $this->input->get('rate', TRUE);
		$rate = '';
		//added get order
		// $displayorder = $this->input->get('displayorder', TRUE); //for displayperpage 6, 9,18,
		$displayorder = ''; //for displayperpage 6, 9,18,
		if (empty($displayorder)) {
			$displayorder = 6;
			$per_page = 6;
		}

		// $sorting = $this->input->get('sorting', TRUE);
		$sorting = '';

		if (empty($sorting)) {
			$sorting = 'lastest'; //default sorting of product
		}
		//for sorting order

		//end added get order
		$filter = array(
			'price_range' => $price_range,
			'size' => $size,
			'rate' => $rate,
			'brand' => $brand,
			'displayorder' => $displayorder,

		);
		#
		#pagination starts
		#
		// $config["base_url"] = base_url('customer/fun_shop/' . $cat_id);
		$config["base_url"] = base_url('customer/fun_shop/');
		$config["total_rows"] = $this->Categories->cat_product_list_count($cat_id, $filter);
		// $config["per_page"] = 20;

		// if (empty($displayorder)) {
		// 	$config["per_page"] = 6; //change to 6 at 2021-05-04
		// } else {
		// 	$config["per_page"] = $displayorder;
		// }
		$config["per_page"] = $displayorder; //change to displayorder

		$config["uri_segment"] = 3;
		$config["num_links"] = 5;
		/* This Application Must Be Used With BootStrap 3 * */
		$config['full_tag_open'] = "<ul class='pagination justify-content-center'>";
		$config['full_tag_close'] = "</ul>";
		$config['num_tag_open'] = "<li class='page-item'>";
		$config['num_tag_close'] = '</li>';
		$config['cur_tag_open'] = "<li class='page-item active'><a href='#'>";
		$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
		$config['next_tag_open'] = "<li class='page-item'>";
		$config['next_tag_close'] = "</li>";
		$config['prev_tag_open'] = "<li class='page-item'>";
		$config['prev_tagl_close'] = "</li>";
		$config['first_tag_open'] = "<li class='page-item'>";
		$config['first_tagl_close'] = "</li>";
		$config['last_tag_open'] = "<li class='page-item'>";
		$config['last_tagl_close'] = "</li>";
		// $config['prev_link'] = 'Previous';
		// $config['next_link'] = 'Next';
		$config['prev_link'] = '<';
		$config['next_link'] = '>';

		$config['first_link'] = '<<';
		$config['last_link'] = '>>';

		//added reuse get string
		$config['reuse_query_string'] = true;
		//end added reuse get string

		/* ends of bootstrap */
		$this->pagination->initialize($config);
		$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
		$links = $this->pagination->create_links();
		#
		#pagination ends
		#

		// $content = $this->lcategory->category_product($cat_id, $links, $config["per_page"], $page, $price_range, $size, $brand, $rate, $displayorder, $sorting);

		//load category data
		$this->load->model('web/Categories');

		$this->load->model('web/Homes');
		$this->load->model('dashboard/web_settings');
		$this->load->model('dashboard/Soft_settings');
		$this->load->model('dashboard/Blocks');
		$this->load->model('dashboard/Variants');
		$this->load->model('dashboard/Themes');
		$theme = $this->Themes->get_theme();
		$max_value = 0;
		$min_value = 0;
		$category_product = $this->Categories->category_product($cat_id, $per_page, $page, $price_range, $size, $brand, $rate, $sorting);
		//added num of category product
		$num_category_product = $this->Categories->count_category_product($cat_id, $per_page, $page, $price_range, $size, $brand, $rate, $sorting);

		//end added num of category product

		$category = $this->Categories->select_single_category($cat_id);

		$categoryList = $this->Homes->parent_category_list();
		$pro_category_list = $this->Homes->category_list();
		$best_sales = $this->Homes->best_sales();
		$footer_block = $this->Homes->footer_block();
		$block_list = $this->Blocks->block_list();
		$currency_details = $this->Soft_settings->retrieve_currency_info();
		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();
		$selected_default_currency_info = $this->Homes->selected_default_currency_info();
		$variant_list = $this->Variants->category_wise_variant_list($cat_id);
		$max_value = $this->Categories->select_max_value_of_cat_pro($cat_id, 1);
		$min_value = $this->Categories->select_max_value_of_cat_pro($cat_id, 0);
		$select_category_adds = $this->Homes->select_category_adds();
		//Max value and min value
		if ($max_value == $min_value) {
			$min_value = 0;
		}

		//Price range
		$from_price = 0;
		$to_price = 0;
		if (!(empty($price_range))) {
			$ex = explode("-", $price_range);
			$from_price = $ex[0];
			$to_price = $ex[1];
		}

		if (empty($category_product)) {
			$total = 0;
		} else {
			$total = count($category_product);
		}

		//added currency data
		$currency_details = $this->Soft_settings->retrieve_currency_info();

		$currency = $currency_details[0]['currency_icon'];
		$position = $currency_details[0]['currency_position'];

		//Currency wise price change
		$default_currency_id = $this->session->userdata('currency_id');
		$currency_new_id = $this->session->userdata('currency_new_id');

		if (empty($currency_new_id)) {
			$result = $cur_info = $this->db->select('*')
				->from('currency_info')
				->where('default_status', '1')
				->get()
				->row();
			$currency_new_id = $result->currency_id;
		}

		if (!empty($currency_new_id)) {
			$cur_info = $this->db->select('*')
				->from('currency_info')
				->where('currency_id', $currency_new_id)
				->get()
				->row();

			$target_con_rate = $cur_info->convertion_rate;
			$position1 = $cur_info->currency_position;
			$currency1 = $cur_info->currency_icon;
		}
		//Currency wise price change

		//end added currency data

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		$data = array(
			'title' => $category[0]['category_name'],
			'category_id' => 'fun_shop',
			'category_product' => $category_product,
			'pro_category_list' => $pro_category_list,
			'category_id' => $cat_id,
			'total' => $total,
			'keyword' => $category[0]['category_name'],
			'category_list' => $categoryList,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'default_currency_icon' => $selected_default_currency_info->currency_icon,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'category_name' => $category[0]['category_name'],
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'links' => $links,
			'variant_list' => $variant_list,
			'max_value' => (!empty($max_value) ? $max_value : 0),
			'min_value' => (!empty($min_value) ? $min_value : 0),
			'from_price' => $from_price,
			'to_price' => $to_price,
			'select_category_adds' => $select_category_adds,
			//added display order
			'displayorder' => $displayorder,
			'brand' => $brand,
			'sorting' => $sorting,
			//end display order
			//added category info
			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,
			'num_category_product' => $num_category_product,
			'page' => $page,
			//end added category info
			//customer details
			'customerDetails' => $customerDetails,
			//end customer details
			//added target con rate
			'target_con_rate' => $target_con_rate,
			'position1' => $position1,
			'currency1' => $currency1,
			//end added target con rate
		);

		//end load category data

		// echo "displayorder";
		// echo $displayorder;
		// $this->template_lib->full_website_html_view($content);

		$content = $this->parser->parse('web/customer/funshop', $data, true);
		$this->template_lib->full_website_html_view($content);

	}
	public function fun_shop_product_details($p_id) {
		// echo $p_id;

		//fun product details
		//reference to lproduct -> product_details
		$this->load->model('web/products_model', 'Products_model');
		$this->load->model('web/Homes');
		$this->load->model('dashboard/web_settings');
		$this->load->model('dashboard/Soft_settings');
		$this->load->model('dashboard/Blocks');
		$this->load->model('dashboard/themes');

		//added category
		$this->load->model('web/Categories');
		$this->load->model('web/Wishlist');

		//end added category

		$theme = $this->themes->get_theme();

		$pro_category_list = $this->Homes->category_list();
		$parent_category_list = $this->Homes->parent_category_list();
		$best_sales = $this->Homes->best_sales();
		$footer_block = $this->Homes->footer_block();
		$slider_list = $this->web_settings->slider_list();
		$block_list = $this->Blocks->block_list();
		$product_info = $this->Products_model->product_info($p_id);

		$price = $product_info->price;
		$onsale = $product_info->onsale;
		$onsale_price = $product_info->onsale_price;
		$default_color = '';

		if ($product_info->variant_price) {
			$varprices = $this->Products_model->get_variant_prices($p_id, $product_info->variants, $product_info->default_variant);
			if (!empty($varprices)) {
				$price = $varprices['price'];
				$default_color = $varprices['var_color_id'];
			}
		}

		// $stock_report_single_item = $this->Products_model->stock_report_single_item_by_store($p_id); //against  store to invoice quantity

		$stock_report_single_item = $this->Products_model->stock_report_single_item_by_store_by_order_quantity($p_id); //against  store to order quantity

		$best_sales_category = $this->Products_model->best_sales_category($p_id);
		$product_gallery_img = $this->Products_model->product_gallery_img($p_id);
		$category_id = $product_info->category_id;
		$product_id = $product_info->product_id;
		$review_list = $this->Products_model->review_list_with_customer($p_id);
		$related_product = $this->Products_model->related_product($category_id, $product_id);
		$currency_details = $this->Soft_settings->retrieve_currency_info();
		$web_settings = $this->web_settings->retrieve_setting_editdata();
		$Soft_settings = $this->Soft_settings->retrieve_setting_editdata();
		$languages = $this->Homes->languages();
		$currency_info = $this->Homes->currency_info();
		$selected_currency_info = $this->Homes->selected_currency_info();
		$select_details_adds = $this->Homes->select_details_adds();

		// Insert Site Analytics
		$this->Homes->insert_product_page_visit($p_id);

		// check affiliate
		$is_affiliate = 0;
		$affiliate_url = "javascript:void(0)";
		if (check_module_status('affiliate_products') == 1) {
			$is_affiliate = $product_info->is_affiliate;
			$affiliate_url = $product_info->affiliate_url;
		}

		//Currency wise price change
		$default_currency_id = $this->session->userdata('currency_id');
		$currency_new_id = $this->session->userdata('currency_new_id');

		if (empty($currency_new_id)) {
			$result = $cur_info = $this->db->select('*')
				->from('currency_info')
				->where('default_status', '1')
				->get()
				->row();
			$currency_new_id = $result->currency_id;
		}

		if (!empty($currency_new_id)) {
			$cur_info = $this->db->select('*')
				->from('currency_info')
				->where('currency_id', $currency_new_id)
				->get()
				->row();

			$target_con_rate = $cur_info->convertion_rate;
			$position1 = $cur_info->currency_position;
			$currency1 = $cur_info->currency_icon;
		}
		//Currency wise price change

		//end added currency data

		//convert customer object to customer array
		$customer = $this->Customer_dashboards->profile_edit_data();
		$customerDetails = array();
		$customerDetails['first_name'] = $customer->first_name;
		$customerDetails['last_name'] = $customer->last_name;
		//end convert customer object to customer array

		//all_main_category
		$all_main_category = $this->Categories->all_main_category();
		$all_sub_category = $this->Categories->all_sub_category();
		//end all_main_category

		//added to get wish list of item
		$isWishList = false;
		// if user login

		if (!empty($this->session->userdata('customer_id'))) {
			//if user logged in
			$customer_id = $this->session->userdata('customer_id');
			$isWishList = $this->Wishlist->is_wishlist_product($p_id, $customer_id);
		}
		// $isWishList = $user_id;
		// $isWishList = $CI->session->userdata('customer_id');
		//

		$data = array(
			'title' => display('product_details'),
			'category_id' => 'fun_shop',
			'category_list' => $parent_category_list,
			'slider_list' => $slider_list,
			'block_list' => $block_list,
			'best_sales' => $best_sales,
			'footer_block' => $footer_block,
			'product_name' => $product_info->product_name,
			'brand_name' => $product_info->brand_name,
			'brand_id' => $product_info->brand_id,
			'product_id' => $product_info->product_id,
			'product_details' => $product_info->product_details,
			'product_model' => $product_info->product_model,
			'type' => $product_info->type,
			'price' => $price,
			'onsale' => $onsale,
			'onsale_price' => $onsale_price,
			'image_thumb' => $product_info->image_thumb,
			'variant' => $product_info->variants,
			'default_variant' => $product_info->default_variant,
			'default_color' => $default_color,
			'category_name' => $product_info->category_name,
			'variant_price' => $product_info->variant_price,
			'video' => $product_info->video,
			'category_id' => $category_id,
			'stok' => $stock_report_single_item,
			'related_product' => $related_product,
			'image_large_details' => $product_info->image_large_details,
			'product_gallery_img' => $product_gallery_img,
			'review' => $product_info->review,
			'description' => $product_info->description,
			'tag' => $product_info->tag,
			'specification' => $product_info->specification,
			'pro_category_list' => $pro_category_list,
			'web_settings' => $web_settings,
			'Soft_settings' => $Soft_settings,
			'languages' => $languages,
			'currency_info' => $currency_info,
			'selected_cur_id' => (($selected_currency_info->currency_id) ? $selected_currency_info->currency_id : ""),
			'currency' => $currency_details[0]['currency_icon'],
			'position' => $currency_details[0]['currency_position'],
			'best_sales_category' => $best_sales_category,
			'review_list' => $review_list,
			'select_details_adds' => $select_details_adds,
			'is_affiliate' => $is_affiliate,
			'affiliate_url' => $affiliate_url,
			//added product details
			'product_name_ch' => $product_info->product_name_ch,
			'product_name_in' => $product_info->product_name_in,
			'product_details_ch' => $product_info->product_details_ch,
			'product_details_in' => $product_info->product_details_in,
			'reward_point' => $product_info->reward_point,

			//end added product details
			//added category list
			'all_main_category' => $all_main_category,
			'all_sub_category' => $all_sub_category,
			//end added category list
			//added wish list
			'isWishList' => $isWishList,
			//end added wish list
			//customer details
			'customerDetails' => $customerDetails,
			//end customer details
			//added target con rate
			'target_con_rate' => $target_con_rate,
			'position1' => $position1,
			'currency1' => $currency1,
			//end added target con rate
		);

		//end reference to lproduct -> product_details
		//end fun product details

		$content = $this->parser->parse('web/customer/funshop_product_details', $data, true);

		$this->template_lib->full_website_html_view($content);
	} //public function fun_shop_product_details($p_id){

	public function check_quantity_wise_stock_and_point() {
		//reference to Product check_quantity_wise_stock
		$quantity = $this->input->post('product_quantity', TRUE);
		$product_id = $this->input->post('product_id', TRUE);
		$variant = $this->input->post('variant', TRUE);
		$variant_color = $this->input->post('variant_color', TRUE);
		//end reference to Product check_quantity_wise_stock
		$this->load->model('web/products_model', 'Products_model');

		$stock = $this->Products_model->check_order_variant_wise_stock($variant, $product_id, $variant_color);

		$product_reward_point = $this->Products_model->get_product_reward_point($product_id);

		// echo $reward_point;

		$customer_id = $this->session->userdata('customer_id');
		$this->load->model('web/Custpoint_model');

		$user_reward_point = $this->Custpoint_model->getUserPoint($customer_id, 'yes');

		// echo $user_reward_point;

		//added to get cart reward point
		//to do
		//end added to get cart reward point

		$result = "";

		if ($stock >= $quantity) {
			$result = "yes";
		} else {
			$result = "no";
		}
		//check have enough reward point
		if ($user_reward_point >= $this->cart->reward_total() + ($product_reward_point * $quantity)) {
			$result = "yes";
		} else {
			$result = "no2";
		}
		//end check have enough reward point

		echo $result;

	}
}
