<?php
/**
* 2007-2020 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@buy-addons.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author    Buy-Addons <contact@buy-addons.com>
*  @copyright 2007-2020 PrestaShop SA
*  @license   http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
* @since 1.6
*/

class Askforaquotemodul extends Module
{

    private $ps_where = array();
    public $demoMode = false;

    public function __construct()
    {
        $this->name = "askforaquotemodul";
        $this->tab = "merchandizing";
        $this->version = "1.0.45";
        $this->author = "buy-addons";
        $this->need_instance = 0;
        $this->secure_key = Tools::encrypt($this->name);
        $this->bootstrap = true;
        $this->module_key = '1329d924d1338d69b1c76d1fac7522ae';
        $this->displayName = $this->l('Request a Quote');
        $this->description = $this->l('Allows customers add products to a Quote and submit an it to manager');
        parent::__construct();
    }

    public function install()
    {
        if (parent::install() == false) {
            return false;
        }
        
        $this->installTab('AdminCheckDelivery', 'Check Delivery');
        $this->installTab('AdminSendProcessPayment', 'Send Process Payment');
        if ($this->registerHook("displayTop") == false
        || $this->registerHook("displayProductButtons") == false
        || $this->registerHook("CustomerAccount") == false
        || $this->registerHook("BackOfficeHeader") == false
        || $this->registerHook("displayProductListFunctionalButtons") == false
        || $this->registerHook("displayHeader") == false
        || $this->registerHook("displayNav2") == false
        || $this->registerHook("displayOrderConfirmation") == false
        || $this->registerHook("displayProductPriceBlock") == false) {
            return false;
        }
       
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $sql = 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'product_doubleboo (
                id_user varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                id_product int(11),
                id_combination int(11),
                count_product int(11)
        )  ';
        $db->query($sql);
        $quote = 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'product_quote_dbboo (
                    id_quote int(11) unsigned NOT NULL auto_increment,
                    id_currency int(11),
                    id_lang int(11),
                    id_customer int(11),
                    first_name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    last_name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    company_name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    phone varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    email varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    quote_name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    message    varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    date_quote datetime,
                    file_attached varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    total_pri  DECIMAL(20,3),
                    nb_mess_ud int(11),
                    shipping_cost  DECIMAL(20,3),
                    tax_cost DECIMAL(20,3),
                    shipping_option int(11),
                    total_pri_fixed DECIMAL(20,3),
                    coupon_code varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    source_check varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                    id_order_create int(11) DEFAULT 0,
                    id_cart_create int(11) DEFAULT 0,
                    company_address VARCHAR(255) NULL,
                    shipping_cost_tax DECIMAL(20,3) NOT NULL DEFAULT 0,
                    PRIMARY KEY (`id_quote`)
            ) ';
        $db->query($quote);
        
        $coupon_quote = 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'coupon_quote (
                id int(11),
                id_quote int(11),
                coupon_type int(11),
                reduction_amount DECIMAL(20,3),
                reduction_product int(11),
                free_shipping int(11),
                pri_coupon DECIMAL(20,3)
        )  ';
        $db->query($coupon_quote);
        
        $quote_detail = 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'product_quote_detail (
                id_quote int(11),
                id_currency int(11),
                id_lang int(11),
                link_img varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                id_product int(11),
                product_name varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                reference varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                id_combination int(11),
                combination varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                product_pri DECIMAL(20,3),
                product_qty int(11),
                total_pri DECIMAL(20,3),
                product_pri_incl_tax DECIMAL(20,3) NULL,
                total_pri_incl_tax DECIMAL(20,3) NULL,
                id_tax_rules_group int(11) NULL,
                position INT(11) NOT NULL DEFAULT "1"
        )  ';
        $db->query($quote_detail);

        $message_dbboo = 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'message_dbboo (
                id int(11) unsigned NOT NULL auto_increment,
                id_quote int(11),
                email varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                content_mes varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                date_send datetime,
                type int(11),
                status int(11),
                PRIMARY KEY (`id`)
        )';
        $db->query($message_dbboo);

        $cus_message_dbboo = 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'cus_message_dbboo (
                id_quote int(11),
                id_customer int(11),
                so_luong_mes int(11)
        )';
        $db->query($cus_message_dbboo);

        $include_product_dbboo = 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'include_product_dbboo (
                id_product int(11),
                name_product varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                type int(11),
                PRIMARY KEY (`id_product`)
        )';
        $db->query($include_product_dbboo);
        $include_product_dbboo_save = 'CREATE TABLE IF NOT EXISTS ' . _DB_PREFIX_ . 'include_product_dbboo_save (
                id_product int(11),
                name_product varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci,
                type int(11),
                PRIMARY KEY (`id_product`)
        )';
        $db->query($include_product_dbboo_save);
        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
            $this->ps_cipherTool = new PhpEncryption(_NEW_COOKIE_KEY_);
        } else {
            $this->ps_cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
        }
        $this->context->smarty->assign('path', $this->_path);
        $Email_new_quote = $this->display(__FILE__, 'views/templates/admin/contentnewmess.tpl');
        $encode_new_quote = $this->ps_cipherTool->encrypt($Email_new_quote);
        Configuration::UpdateValue('email_new_quote', $encode_new_quote);

        $Email_notice_quote = $this->display(__FILE__, 'views/templates/admin/contentmessnotice.tpl');
        $encode_notice_quote = $this->ps_cipherTool->encrypt($Email_notice_quote);
        Configuration::UpdateValue('Email_notes_quote', $encode_notice_quote);
        
        $Email_price_quote = $this->display(__FILE__, 'views/templates/admin/contentpricemess.tpl');
        $encode_price_quote = $this->ps_cipherTool->encrypt($Email_price_quote);
        Configuration::UpdateValue('Email_price_quote', $encode_price_quote);
        
        $pdf_templates = $this->display(__FILE__, 'views/templates/admin/quotepdfeditor.tpl');
        $pdf_tpl = $this->ps_cipherTool->encrypt($pdf_templates);
        Configuration::UpdateValue('pdf_templates', $pdf_tpl);

        $email_admin_setting = Configuration::get('PS_SHOP_EMAIL');
        Configuration::UpdateValue('email_adm_setting', $email_admin_setting);
        $email_from_setting = Configuration::get('PS_SHOP_EMAIL');
        Configuration::UpdateValue('email_from_setting', $email_from_setting);
        $name_from_setting = Configuration::get('PS_SHOP_NAME');
        Configuration::UpdateValue('name_from_setting', $name_from_setting);
        $Option_email_newquote_adm = 1;
        Configuration::UpdateValue('Option_email_newquote_adm', $Option_email_newquote_adm);
        $Option_email_newquote_cus = 1;
        Configuration::UpdateValue('Option_email_newquote_cus', $Option_email_newquote_cus);
        $Option_email_noticequote_adm = 1;
        Configuration::UpdateValue('Option_email_noticequote_adm', $Option_email_noticequote_adm);
        $Option_email_noticequote_cus = 1;
        Configuration::UpdateValue('Option_email_noticequote_cus', $Option_email_noticequote_cus);
        $Option_price_total = 1;
        Configuration::UpdateValue('Option_price_total', $Option_price_total);
        $Option_addtocart = 1;
        Configuration::UpdateValue('Option_addtocart', $Option_addtocart);
        $Option_product_out_of_stock = 0;
        Configuration::UpdateValue('Option_product_out_of_stock', $Option_product_out_of_stock);
        $Option_product_priced_0 = 0;
        Configuration::UpdateValue('Option_product_priced_0', $Option_product_priced_0);
        $Option_login_customer = 0;
        Configuration::UpdateValue('Option_login_customer', $Option_login_customer);
        $Option_button_category = 1;
        Configuration::UpdateValue('Option_button_category', $Option_button_category);
        $Option_button_pdf = 1;
        Configuration::UpdateValue('Option_button_pdf', $Option_button_pdf);
        Configuration::UpdateValue('option_price_excl_tax', 0);
        Configuration::UpdateValue('option_convert_cart', 0);
        $Option_button_smtp = 0;
        Configuration::UpdateValue('Option_button_smtp', $Option_button_smtp);
        $format_currency = 1;
        Configuration::UpdateValue('format_currency', $format_currency);
        $Option_show_captcha = 1;
        Configuration::UpdateValue('Option_show_captcha', $Option_show_captcha);
        Configuration::UpdateValue('id_category_dbboo', null);
        $Option_order_date = 30;
        Configuration::UpdateValue('Option_order_date', $Option_order_date);
        $option_num_display = 5;
        Configuration::UpdateValue('Option_num_display', $option_num_display);
        $Option_file_extension = 'jpg, png, jeg, gif, pdf, doc, docx, zip';
        Configuration::UpdateValue('Option_file_extension', $Option_file_extension);
        $Option_company_name = 0;
        Configuration::UpdateValue('Option_company_name', $Option_company_name);
        $arr_language = Language::getLanguages(false);
        foreach ($arr_language as $key => $value_lang) {
            $value_lang;
            $iso = $arr_language[$key]['iso_code'];
            Configuration::updateValue('label_new_' . $iso, $encode_new_quote);
            Configuration::updateValue('label_notice_' . $iso, $encode_notice_quote);
            Configuration::updateValue('label_price_' . $iso, $encode_price_quote);
            Configuration::updateValue('label_pdf_' . $iso, $pdf_tpl);
        }
        Configuration::UpdateValue('id_product_show_btn', null);
        // Save groups
        $id_lang = $this->context->language->id;
        $groups_tmp = Group::getGroups($id_lang, true);
        if (!empty($groups_tmp)) {
            $groups = array();
            foreach ($groups_tmp as $g) {
                $groups[] = $g['id_group'];
            }
            $groups = Tools::jsonEncode($groups);
            Configuration::UpdateValue('askforaquotemodul_groups', $groups);
        }

        return true;
    }

    public function uninstall()
    {
        if (parent::uninstall() == false) {
            return false;
        }
        $tab = new Tab((int) Tab::getIdFromClassName('AdminCheckDelivery'));
        $tab->delete();
        $tab = new Tab((int) Tab::getIdFromClassName('AdminSendProcessPayment'));
        $tab->delete();
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $sql = 'DROP table IF EXISTS ' . _DB_PREFIX_ . 'product_doubleboo';
        $db->query($sql);
        $sql_1 = 'DROP table IF EXISTS ' . _DB_PREFIX_ . 'product_quote_dbboo';
        $db->query($sql_1);
        $sql_2 = 'drop table IF EXISTS ' . _DB_PREFIX_ . 'product_quote_detail';
        $db->query($sql_2);
        $sql_3 = 'DROP table IF EXISTS ' . _DB_PREFIX_ . 'message_dbboo';
        $db->query($sql_3);
        $sql_4 = 'DROP table IF EXISTS ' . _DB_PREFIX_ . 'cus_message_dbboo';
        $db->query($sql_4);
        $sql_5 = 'DROP table IF EXISTS ' . _DB_PREFIX_ . 'include_product_dbboo';
        $db->query($sql_5);
        $sql_6 = 'DROP table IF EXISTS ' . _DB_PREFIX_ . 'include_product_dbboo_save';
        $db->query($sql_6);
        return true;
    }

    public function hookdisplayCustomerAccount(&$params)
    {
        // check groups of customer can allowed to use this module? since 1.0.38+
        if (!$this->isAllowedUseQuote()) {
            return '';
        }

        $html = '';
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $customer = $this->context->customer->id;
        $id_currency_dbboo = $this->context->currency->id;
        $web_version = Tools::getShopProtocol() . Tools::getHttpHost() . __PS_BASE_URI__;
        $sl_mess = 'Select * from ' . _DB_PREFIX_ . 'message_dbboo INNER JOIN '._DB_PREFIX_.'product_quote_dbboo on ';
        $sl_mess .= _DB_PREFIX_ . 'message_dbboo.id_quote = ' . _DB_PREFIX_ . 'product_quote_dbboo.id_quote where ';
        $sl_mess .= _DB_PREFIX_ . 'product_quote_dbboo.id_customer like "';
        $sl_mess .= (int) $customer . '" and  status like "0" and type like "1"';

        $count_mess = $db->ExecuteS($sl_mess, true, false);
        $number_unread = Count($count_mess);
        $link = new Link();
        $link_to_account = $link->getPageLink('my-account');
        $this->context->smarty->assign('link_to_account', $link_to_account);
        $this->context->smarty->assign('number_unread', $number_unread);
        $this->context->smarty->assign('version', $web_version);
        $this->context->smarty->assign("currency_dbboo", $id_currency_dbboo);
        $this->context->smarty->assign('_path', $this->_path);
        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) { // for PrestaShop 1.7+
            $this->context->controller->addCSS($this->_path . 'views/css/style17.css');
            $html .= $this->display(__FILE__, 'views/templates/hook/myquote17.tpl');
        } else {
            $this->context->controller->addCSS($this->_path . 'views/css/style_new.css');
            $html .= $this->display(__FILE__, 'views/templates/hook/myquote.tpl');
        }
        
        $this->context->controller->addJS(_PS_MODULE_DIR_ . 'askforaquotemodul/views/js/showquotedetail.js');
        return $html;
    }

    public function hookdisplayBackOfficeHeader(&$params)
    {
        $html = '';
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $url = Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__;

        $sign_currency = $this->context->currency->sign;
        $id_currency = $this->context->currency->id;

        if (Tools::getValue("viewaskforaquotemodul") !== false) {
            $id_quote = (int) Tools::getValue("id_quote");
            $currency = $this->findQuoteCurrencyById($id_quote);
            $sign_currency = $currency->sign;
            $id_currency = $currency->id;
        }
        $token = Tools::getAdminTokenLite('AdminModules');
        $admin_folder = basename(_PS_ADMIN_DIR_);
        $link_module = $url . $admin_folder . '/index.php?controller=AdminModules&token=' . $token;
        $sl_mess_cus = 'Select * from ' . _DB_PREFIX_ . 'message_dbboo where status like "0" and type like "0"';
        $count_mess_cus = $db->ExecuteS($sl_mess_cus, true, false);
        $number_unread_cus = Count($count_mess_cus);
        $check_vs = 0;
        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) { // for PrestaShop 1.7+
            $check_vs = 1;
        }
        $link_to_admin = $url . $admin_folder;
        $this->context->smarty->assign('_path', $this->_path);
        $this->context->smarty->assign('url_php', Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__);
        $this->context->smarty->assign('sl_mess_cus', $number_unread_cus);
        $this->context->smarty->assign('sign_currency', $sign_currency);
        $this->context->smarty->assign('td_id_currency', $id_currency);
        $this->context->smarty->assign('link_module', $link_module);
        $this->context->smarty->assign('link_to_admin', $link_to_admin);
        $this->context->smarty->assign('check_vs', $check_vs);
        $translate_quote = $this->l('Quotation');
        $this->context->smarty->assign('translate_quote', $translate_quote);
        $html .= $this->display(__FILE__, 'views/templates/admin/jshookquoteadm.tpl');
        $link_awesome = '//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css';
        $this->context->controller->addCSS($link_awesome);
        return $html;
    }
    public function hookdisplayProductPriceBlock(&$params)
    {
        // check groups of customer can allowed to use this module? since 1.0.38+
        if (!$this->isAllowedUseQuote()) {
            return '';
        }

        if ($params['type'] == 'before_price') {
            if ($this->enableQuoteButtons() == false) {
                return ;
            }
            if (Tools::version_compare(_PS_VERSION_, '1.7', '<')) { // for PrestaShop 1.7+
                return ;
            }
            $option_button_category = Configuration::get('Option_button_category');
            $html = '';
            if ($option_button_category == 1) {
                $id = $params['product']['id_product'];
                $this->context->controller->addJS($this->_path . 'views/js/checkoptcategory.js');
                $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
                $this->context->smarty->assign("id_p", $id);
                $id_lang = $this->context->language->id;
                $product = new Product($id, false, $id_lang);
                $check_show_quan = 0;
                $check_show_price = 0;
                $check_show_button_quote = 0;
                $check_show_button_quote;
                $hide_price_category = 0;
                $hide_quantity_category = 0;
                $check_opt_quan_price = 0;
                $option_product_out_of_stock = Configuration::get('Option_product_out_of_stock');
                $option_product_priced_0 = Configuration::get('Option_product_priced_0');
                $list_id_product_show = Configuration::get('id_product_show_btn');
                $id_category_dbboo = Configuration::get('id_category_dbboo');

                if (!empty($list_id_product_show)) {
                    $sql_id_combi = 'Select id_product,id_product_attribute from ' . _DB_PREFIX_ . 'stock_available ';
                    $sql_id_combi .= 'where id_product IN(' . pSQL($list_id_product_show) . ')';
                    $list_id_combi = $db->executeS($sql_id_combi, true, false);
                    foreach ($list_id_combi as $key_combi => $value_combi) {
                        $value_combi;
                        if ($id == $list_id_combi[$key_combi]['id_product']) {
                            $sql_quantity = 'SELECT ' . _DB_PREFIX_ . 'stock_available.quantity, id_product_attribute ';
                            $sql_quantity .= ' FROM ';
                            $sql_quantity .= _DB_PREFIX_ . 'stock_available ';
                            $sql_quantity .= 'inner join ' . _DB_PREFIX_ . 'product';
                            $sql_quantity .= ' on ' . _DB_PREFIX_ . 'stock_available.id_product =  ';
                            $sql_quantity .= _DB_PREFIX_ . 'product.id_product where ';
                            $sql_quantity .= _DB_PREFIX_ . 'stock_available.id_product like "' . (int) $id . '"';
                            $sql_quantity .= ' and id_product_attribute like "0"';
                            $show_quanti = $db->executeS($sql_quantity, true, false);
                            $pri_pro_tax = $product->getPrice(true, $show_quanti[0]['id_product_attribute'], 2);
                            if ($option_product_out_of_stock == 1) {
                                if ($show_quanti[0]['quantity'] == 0) {
                                    $check_show_quan = 1;
                                    $hide_quantity_category = 1;
                                }
                            }
                            if ($option_product_priced_0 == 1) {
                                if ($pri_pro_tax == 0) {
                                    $check_show_price = 1;
                                    $hide_price_category = 1;
                                }
                            }
                            if ($option_product_out_of_stock == 0 && $option_product_priced_0 == 0) {
                                $check_opt_quan_price = 1;
                            }
                        }
                    }
                }
                if (!empty($id_category_dbboo)) {
                    $category_product = 'Select id_category FROM ';
                    $category_product .= _DB_PREFIX_.'category_product where id_product like"';
                    $category_product .= (int) $id . '"';
                    $list_category_product = $db->executeS($category_product, true, false);

                    $id_category_arr_dbboo = explode(',', $id_category_dbboo);
                    foreach ($list_category_product as $key_cate_pr => $value_cate_pr) {
                        $value_cate_pr;
                        foreach ($id_category_arr_dbboo as $key_cate => $value_cate) {
                            $value_cate;
                            $id_category_tmp = $list_category_product[$key_cate_pr]['id_category'];
                            if ($id_category_arr_dbboo[$key_cate] == $id_category_tmp) {
                                $sql_quantity = 'Select '._DB_PREFIX_.'stock_available.quantity,id_product_attribute';
                                $sql_quantity .= ' FROM ';
                                $sql_quantity .= _DB_PREFIX_ . 'stock_available ';
                                $sql_quantity .= 'inner join ' . _DB_PREFIX_ . 'product';
                                $sql_quantity .= ' on ' . _DB_PREFIX_ . 'stock_available.id_product =  ';
                                $sql_quantity .= _DB_PREFIX_ . 'product.id_product where ';
                                $sql_quantity .= _DB_PREFIX_ . 'stock_available.id_product like "' . (int) $id . '"';
                                $sql_quantity .= ' and id_product_attribute like "0"';
                                $show_quanti = $db->executeS($sql_quantity, true, false);
                                $pri_pro_tax = $product->getPrice(true, $show_quanti[0]['id_product_attribute'], 2);
                                if ($option_product_out_of_stock == 1) {
                                    if ($show_quanti[0]['quantity'] == 0) {
                                        $check_show_quan = 1;
                                        $hide_quantity_category = 1;
                                    }
                                }
                                if ($option_product_priced_0 == 1) {
                                    if ($pri_pro_tax == 0) {
                                        $check_show_price = 1;
                                        $hide_price_category = 1;
                                    }
                                }
                                if ($option_product_out_of_stock == 0 && $option_product_priced_0 == 0) {
                                    $check_opt_quan_price = 1;
                                }
                            }
                        }
                    }
                }
                if (empty($list_id_product_show) && empty($id_category_dbboo)) {
                    $sql_quantity = 'Select ' . _DB_PREFIX_ . 'stock_available.quantity,id_product_attribute from ';
                    $sql_quantity .= _DB_PREFIX_ . 'stock_available ';
                    $sql_quantity .= 'inner join ' . _DB_PREFIX_ . 'product';
                    $sql_quantity .= ' on ' . _DB_PREFIX_ . 'stock_available.id_product =  ';
                    $sql_quantity .= _DB_PREFIX_ . 'product.id_product where ';
                    $sql_quantity .= _DB_PREFIX_ . 'stock_available.id_product like "' . (int) $id . '"';
                    $sql_quantity .= ' and id_product_attribute like "0"';
                    $show_quanti = $db->executeS($sql_quantity, true, false);
                    $pri_pro_tax = $product->getPrice(true, $show_quanti[0]['id_product_attribute'], 2);
                    if ($option_product_out_of_stock == 1) {
                        if ($show_quanti[0]['quantity'] == 0) {
                            $check_show_quan = 1;
                            $hide_quantity_category = 1;
                        }
                    }
                    if ($option_product_priced_0 == 1) {
                        if ($pri_pro_tax == 0) {
                            $check_show_price = 1;
                            $hide_price_category = 1;
                        }
                    }
                    if ($option_product_out_of_stock == 0 && $option_product_priced_0 == 0) {
                        $check_opt_quan_price = 1;
                    }
                }
                $this->context->smarty->assign('hide_price_category', $hide_price_category);
                $this->context->smarty->assign('hide_quantity_category', $hide_quantity_category);
                $this->context->smarty->assign("module_dir", __PS_BASE_URI__);
                if ($check_show_quan == 1 || $check_show_price == 1 || $check_opt_quan_price == 1) {
                    $html .= $this->display(__FILE__, 'views/templates/hook/addaquotecategory.tpl');
                    $check_show_button_quote = 1;
                }
            }
            return $html;
        }
    }

    public function hookdisplayProductListFunctionalButtons(&$params)
    {
        // check groups of customer can allowed to use this module? since 1.0.38+
        if (!$this->isAllowedUseQuote()) {
            return '';
        }

        if ($this->enableQuoteButtons() == false) {
            return ;
        }
        $option_button_category = Configuration::get('Option_button_category');
        $html = '';
        if ($option_button_category == 1) {
            $id = $params['product']['id_product'];
            $this->context->controller->addJS($this->_path . 'views/js/checkoptcategory.js');
            $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
            $this->context->smarty->assign("id_p", $id);
            $id_lang = $this->context->language->id;
            $product = new Product($id, false, $id_lang);
            $check_show_quan = 0;
            $check_show_price = 0;
            $check_show_button_quote = 0;
            $check_show_button_quote;
            $hide_price_category = 0;
            $hide_quantity_category = 0;
            $check_opt_quan_price = 0;
            $option_product_out_of_stock = Configuration::get('Option_product_out_of_stock');
            $option_product_priced_0 = Configuration::get('Option_product_priced_0');
            $list_id_product_show = Configuration::get('id_product_show_btn');
            $id_category_dbboo = Configuration::get('id_category_dbboo');

            if (!empty($list_id_product_show)) {
                $sql_id_combi = 'Select id_product,id_product_attribute from ' . _DB_PREFIX_ . 'stock_available ';
                $sql_id_combi .= 'where id_product IN(' . pSQL($list_id_product_show) . ')';
                $list_id_combi = $db->executeS($sql_id_combi, true, false);
                foreach ($list_id_combi as $key_combi => $value_combi) {
                    $value_combi;
                    if ($id == $list_id_combi[$key_combi]['id_product']) {
                        $sql_quantity = 'Select ' . _DB_PREFIX_ . 'stock_available.quantity,id_product_attribute from ';
                        $sql_quantity .= _DB_PREFIX_ . 'stock_available ';
                        $sql_quantity .= 'inner join ' . _DB_PREFIX_ . 'product';
                        $sql_quantity .= ' on ' . _DB_PREFIX_ . 'stock_available.id_product =  ';
                        $sql_quantity .= _DB_PREFIX_ . 'product.id_product where ';
                        $sql_quantity .= _DB_PREFIX_ . 'stock_available.id_product like "' . (int) $id . '"';
                        $sql_quantity .= ' and id_product_attribute like "0"';
                        $show_quanti = $db->executeS($sql_quantity, true, false);
                        $pri_pro_tax = $product->getPrice(true, $show_quanti[0]['id_product_attribute'], 2);
                        if ($option_product_out_of_stock == 1) {
                            if ($show_quanti[0]['quantity'] == 0) {
                                $check_show_quan = 1;
                                $hide_quantity_category = 1;
                            }
                        }
                        if ($option_product_priced_0 == 1) {
                            if ($pri_pro_tax == 0) {
                                $check_show_price = 1;
                                $hide_price_category = 1;
                            }
                        }
                        if ($option_product_out_of_stock == 0 && $option_product_priced_0 == 0) {
                            $check_opt_quan_price = 1;
                        }
                    }
                }
            }
            if (!empty($id_category_dbboo)) {
                $category_product = 'Select id_category from '._DB_PREFIX_.'category_product where id_product like"';
                $category_product .= (int) $id . '"';
                $list_category_product = $db->executeS($category_product, true, false);

                $id_category_arr_dbboo = explode(',', $id_category_dbboo);
                foreach ($list_category_product as $key_cate_pr => $value_cate_pr) {
                    $value_cate_pr;
                    foreach ($id_category_arr_dbboo as $key_cate => $value_cate) {
                        $value_cate;
                        if ($id_category_arr_dbboo[$key_cate] == $list_category_product[$key_cate_pr]['id_category']) {
                            $sql_quantity = 'Select '._DB_PREFIX_.'stock_available.quantity,id_product_attribute from ';
                            $sql_quantity .= _DB_PREFIX_ . 'stock_available ';
                            $sql_quantity .= 'inner join ' . _DB_PREFIX_ . 'product';
                            $sql_quantity .= ' on ' . _DB_PREFIX_ . 'stock_available.id_product =  ';
                            $sql_quantity .= _DB_PREFIX_ . 'product.id_product where ';
                            $sql_quantity .= _DB_PREFIX_ . 'stock_available.id_product like "' . (int) $id . '"';
                            $sql_quantity .= ' and id_product_attribute like "0"';
                            $show_quanti = $db->executeS($sql_quantity, true, false);
                            $pri_pro_tax = $product->getPrice(true, $show_quanti[0]['id_product_attribute'], 2);
                            if ($option_product_out_of_stock == 1) {
                                if ($show_quanti[0]['quantity'] == 0) {
                                    $check_show_quan = 1;
                                    $hide_quantity_category = 1;
                                }
                            }
                            if ($option_product_priced_0 == 1) {
                                if ($pri_pro_tax == 0) {
                                    $check_show_price = 1;
                                    $hide_price_category = 1;
                                }
                            }
                            if ($option_product_out_of_stock == 0 && $option_product_priced_0 == 0) {
                                $check_opt_quan_price = 1;
                            }
                        }
                    }
                }
            }
            if (empty($list_id_product_show) && empty($id_category_dbboo)) {
                $sql_quantity = 'Select ' . _DB_PREFIX_ . 'stock_available.quantity,id_product_attribute from ';
                $sql_quantity .= _DB_PREFIX_ . 'stock_available ';
                $sql_quantity .= 'inner join ' . _DB_PREFIX_ . 'product';
                $sql_quantity .= ' on ' . _DB_PREFIX_ . 'stock_available.id_product =  ';
                $sql_quantity .= _DB_PREFIX_ . 'product.id_product where ';
                $sql_quantity .= _DB_PREFIX_ . 'stock_available.id_product like "' . (int) $id . '"';
                $sql_quantity .= ' and id_product_attribute like "0"';
                $show_quanti = $db->executeS($sql_quantity, true, false);
                $pri_pro_tax = $product->getPrice(true, $show_quanti[0]['id_product_attribute'], 2);
                if ($option_product_out_of_stock == 1) {
                    if ($show_quanti[0]['quantity'] == 0) {
                        $check_show_quan = 1;
                        $hide_quantity_category = 1;
                    }
                }
                if ($option_product_priced_0 == 1) {
                    if ($pri_pro_tax == 0) {
                        $check_show_price = 1;
                        $hide_price_category = 1;
                    }
                }
                if ($option_product_out_of_stock == 0 && $option_product_priced_0 == 0) {
                    $check_opt_quan_price = 1;
                }
            }
            $this->context->smarty->assign('hide_price_category', $hide_price_category);
            $this->context->smarty->assign('hide_quantity_category', $hide_quantity_category);
            $this->context->smarty->assign("module_dir", __PS_BASE_URI__);
            if ($check_show_quan == 1 || $check_show_price == 1 || $check_opt_quan_price == 1) {
                $html .= $this->display(__FILE__, 'views/templates/hook/addaquotecategory.tpl');
                $check_show_button_quote = 1;
            }
        }

        return $html;
    }

    public function hookdisplayProductButtons(&$params)
    {
        // check groups of customer can allowed to use this module? since 1.0.38+
        if (!$this->isAllowedUseQuote()) {
            return '';
        }

        if ($this->enableQuoteButtons() == false) {
            return ;
        }
        $this->context->controller->addJS($this->_path . 'views/js/checkoptadm.js');
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $id = Tools::getValue("id_product");
        $option_addtocart = Configuration::get('Option_addtocart');
        $id_lang = $this->context->language->id;
        $product = new Product($id, false, $id_lang);
        $ten_sp = $product->name;
        $id_user = Context::getContext()->cookie->client;
        $this->context->smarty->assign("id_p", $id);
        $this->context->smarty->assign('name', $ten_sp);
        $sign_currency = $this->context->currency->sign;

        $option_product_out_of_stock = Configuration::get('Option_product_out_of_stock');
        $option_product_priced_0 = Configuration::get('Option_product_priced_0');

        $html = '';
        $check_show_quan = 0;
        $check_show_price = 0;
        $check_show_button_quote = 0;
        $check_opt_quan_price = 0;
        $check_vs = 0;

        $list_id_product_show = Configuration::get('id_product_show_btn');
        $id_category_dbboo = Configuration::get('id_category_dbboo');

        if (!empty($list_id_product_show)) {
            $sql_id_combi = 'Select id_product,id_product_attribute from ' . _DB_PREFIX_ . 'stock_available ';
            $sql_id_combi .= 'where id_product IN(' . pSQL($list_id_product_show) . ')';
            $list_id_combi = $db->executeS($sql_id_combi, true, false);
            foreach ($list_id_combi as $key_combi => $value_combi) {
                $value_combi;
                if ($id == $list_id_combi[$key_combi]['id_product']) {
                    $sql_quantity = 'Select ' . _DB_PREFIX_ . 'stock_available.quantity,id_product_attribute from ';
                    $sql_quantity .= _DB_PREFIX_ . 'stock_available ';
                    $sql_quantity .= 'inner join ' . _DB_PREFIX_ . 'product';
                    $sql_quantity .= ' on ' . _DB_PREFIX_ . 'stock_available.id_product =  ';
                    $sql_quantity .= _DB_PREFIX_ . 'product.id_product where ';
                    $sql_quantity .= _DB_PREFIX_ . 'stock_available.id_product like "' . (int) $id . '"';
                    $sql_quantity .= ' and id_product_attribute like "0"';
                    $show_quanti = $db->executeS($sql_quantity, true, false);
                    $pri_pro_tax = $product->getPrice(true, $show_quanti[0]['id_product_attribute'], 2);
                    if ($option_product_out_of_stock == 1) {
                        if ($show_quanti[0]['quantity'] == 0) {
                            $check_show_quan = 1;
                        }
                    }
                    if ($option_product_priced_0 == 1) {
                        if ($pri_pro_tax == 0) {
                            $check_show_price = 1;
                        }
                    }
                    if ($option_product_out_of_stock == 0 && $option_product_priced_0 == 0) {
                        $check_opt_quan_price = 1;
                    }
                }
            }
        }
        if (!empty($id_category_dbboo)) {
            $category_product = 'Select id_category from ' . _DB_PREFIX_ . 'category_product where id_product like"';
            $category_product .= (int) $id . '"';
            $list_category_product = $db->executeS($category_product, true, false);

            $id_category_arr_dbboo = explode(',', $id_category_dbboo);
            foreach ($list_category_product as $key_cate_pr => $value_cate_pr) {
                $value_cate_pr;
                foreach ($id_category_arr_dbboo as $key_cate => $value_cate) {
                    $value_cate;
                    if ($id_category_arr_dbboo[$key_cate] == $list_category_product[$key_cate_pr]['id_category']) {
                        $sql_quantity = 'Select ' . _DB_PREFIX_ . 'stock_available.quantity,id_product_attribute from ';
                        $sql_quantity .= _DB_PREFIX_ . 'stock_available ';
                        $sql_quantity .= 'inner join ' . _DB_PREFIX_ . 'product';
                        $sql_quantity .= ' on ' . _DB_PREFIX_ . 'stock_available.id_product =  ';
                        $sql_quantity .= _DB_PREFIX_ . 'product.id_product where ';
                        $sql_quantity .= _DB_PREFIX_ . 'stock_available.id_product like "' . (int) $id . '"';
                        $sql_quantity .= ' and id_product_attribute like "0"';
                        $show_quanti = $db->executeS($sql_quantity, true, false);
                        $pri_pro_tax = $product->getPrice(true, $show_quanti[0]['id_product_attribute'], 2);
                        if ($option_product_out_of_stock == 1) {
                            if ($show_quanti[0]['quantity'] == 0) {
                                $check_show_quan = 1;
                            }
                        }
                        if ($option_product_priced_0 == 1) {
                            if ($pri_pro_tax == 0) {
                                $check_show_price = 1;
                            }
                        }
                        if ($option_product_out_of_stock == 0 && $option_product_priced_0 == 0) {
                            $check_opt_quan_price = 1;
                        }
                    }
                }
            }
        }
        if (empty($list_id_product_show) && empty($id_category_dbboo)) {
            $sql_quantity = 'Select ' . _DB_PREFIX_ . 'stock_available.quantity,id_product_attribute from ';
            $sql_quantity .= _DB_PREFIX_ . 'stock_available ';
            $sql_quantity .= 'inner join ' . _DB_PREFIX_ . 'product';
            $sql_quantity .= ' on ' . _DB_PREFIX_ . 'stock_available.id_product =  ';
            $sql_quantity .= _DB_PREFIX_ . 'product.id_product where ';
            $sql_quantity .= _DB_PREFIX_ . 'stock_available.id_product like "' . (int) $id . '"';
            $sql_quantity .= ' and id_product_attribute like "0"';
            $show_quanti = $db->executeS($sql_quantity, true, false);
            $pri_pro_tax = $product->getPrice(true, $show_quanti[0]['id_product_attribute'], 2);
            if ($option_product_out_of_stock == 1) {
                if ($show_quanti[0]['quantity'] == 0) {
                    $check_show_quan = 1;
                }
            }
            if ($option_product_priced_0 == 1) {
                if ($pri_pro_tax == 0) {
                    $check_show_price = 1;
                }
            }
            if ($option_product_out_of_stock == 0 && $option_product_priced_0 == 0) {
                $check_opt_quan_price = 1;
            }
        }
        if ($check_show_quan == 1 || $check_show_price == 1 || $check_opt_quan_price == 1) {
            $html .= $this->display(__FILE__, 'views/templates/hook/addaquote.tpl');
            $check_show_button_quote = 1;
        }
        $this->context->smarty->assign('url_php', Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__);
        $this->context->smarty->assign('sign_currency', $sign_currency);
        $this->context->smarty->assign('option_addtocart', $option_addtocart);
        $this->context->smarty->assign('ss_id', $id_user);
        $this->context->smarty->assign('check_show_button_quote', $check_show_button_quote);
        $this->context->smarty->assign('option_product_out_of_stock', $option_product_out_of_stock);
        $this->context->smarty->assign('option_product_priced_0', $option_product_priced_0);
        $this->context->smarty->assign('check_show_quan', $check_show_quan);
        $this->context->smarty->assign('check_show_price', $check_show_price);
        $this->context->smarty->assign('token_askaquotemodule', md5(sha1(_COOKIE_KEY_.'askforaquotemodul')));
        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
            $check_vs = 1;
            $this->context->controller->addCSS($this->_path . 'views/css/style17.css');
        } else {
            $this->context->controller->addCSS($this->_path . 'views/css/style_new.css');
        }
        $this->context->smarty->assign('check_vs', $check_vs);
        $html .= $this->display(__FILE__, 'views/templates/hook/jsbuttonaskquote.tpl');
        
        $this->context->controller->addJS($this->_path . 'views/js/showdetails.js');
        return $html;
    }
    
    public function hookdisplayHeader(&$params)
    {
        // check groups of customer can allowed to use this module? since 1.0.38+
        if (!$this->isAllowedUseQuote()) {
            return '';
        }

        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
            $this->context->controller->addCSS($this->_path . 'views/css/style17.css');
        } else {
            $this->context->controller->addCSS($this->_path . 'views/css/style_new.css');
        }
        $this->context->controller->addJS(_PS_MODULE_DIR_ . 'askforaquotemodul/views/js/showquotedetail.js');
        $this->context->smarty->assign('path', $this->_path);
        $option_addtocart = Configuration::get('Option_addtocart');
        $this->context->smarty->assign('option_addtocart', $option_addtocart);
       
        $this->context->controller->addJS($this->_path . 'views/js/checkoptcategory.js');
        $this->context->controller->addJS($this->_path . 'views/js/showdetails.js');
        $this->context->controller->addJS($this->_path . 'views/js/updownbtn.js');
        $this->context->controller->addJS($this->_path . 'views/js/handviewlist.js');
        $this->context->controller->addJS($this->_path . 'views/js/emailadminsetting.js');
        $this->context->controller->addJS($this->_path . 'views/js/languagesaveform.js');
        $this->context->controller->addJS($this->_path . 'views/js/searchajax.js');
        $this->context->controller->addJS($this->_path . 'views/js/addproduct.js');
        $this->context->controller->addJS($this->_path . 'views/js/delproductstore.js');
        $this->context->controller->addJS($this->_path . 'views/js/delmes.js');
        $this->context->controller->addJS($this->_path . 'views/js/dateFormat.js');
        $this->context->controller->addJS($this->_path . 'views/js/jquery.dateFormat.js');
        $this->context->controller->addJS($this->_path . 'views/js/checkmess.js');
        $html ='';
        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
            $this->context->controller->addJS($this->_path . 'views/js/checkoptadm.js');
            $currency = $this->context->currency;
            $this->context->smarty->assign('_PS_JS_DIR_TOOLS', $this->_path . 'views/js/tools.js');

            $c_format = $this->getFormatCurrency($currency->format);
            $this->context->smarty->assign('currencySign', $currency->sign);
            $this->context->smarty->assign('currencyFormat', $c_format);
            $this->context->smarty->assign('currencyBlank', $currency->blank);
            $html .= $this->display(__FILE__, 'views/templates/hook/hookheader17.tpl');
        } else {
            $this->context->controller->addJS($this->_path . 'views/js/checkoptadm.js');
            if (Tools::strtolower(Tools::getvalue("controller")) == 'quotes') {
                $currency = $this->context->currency;
                $c_format = $this->getFormatCurrency($currency->format);
                $this->context->smarty->assign('currencySign', $currency->sign);
                $this->context->smarty->assign('currencyFormat', $c_format);
                $this->context->smarty->assign('currencyBlank', $currency->blank);
                $html .= $this->display(__FILE__, 'views/templates/hook/hookheader160.tpl');
            }
        }
        $option_num_display = Configuration::get('Option_num_display');
        $this->context->smarty->assign('option_num_display', $option_num_display);
        $html .= '
            <script language="javascript" type="text/javascript">
                var askquote_base_url="' . __PS_BASE_URI__ . '";
                var num_display="' . $option_num_display . '";
            </script>';
        /** since 1.0.38 **/
        $html .= $this->displayConvertCartButton();
        return $html;
    }
    
    public function hookdisplayNav2(&$params)
    {
        // check groups of customer can allowed to use this module? since 1.0.38+
        if (!$this->isAllowedUseQuote()) {
            return '';
        }

        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
            $check_id_customer = (int) $this->context->cookie->id_customer;
            $this->context->controller->addJS($this->_path . 'views/js/checkoptcategory.js');
            $id_currency = $this->context->currency->id;
            $option_addtocart = Configuration::get('Option_addtocart');
            $product_total_price = 0;
            $check_vs = 0;
            $option_price_total = Configuration::get('Option_price_total');
            $option_show_captcha = Configuration::get('Option_show_captcha');
            if (empty(Context::getContext()->cookie->client)) {
                Context::getContext()->cookie->client = md5(time());
            }
            $link = new Link();
            $link_quote_seo = $link->getModuleLink('askforaquotemodul', 'quotes');
            $link_myquote_seo = $link->getModuleLink('askforaquotemodul', 'myquotecustomer');
            
            $id_user = Context::getContext()->cookie->client;
            $db = Db::getInstance(_PS_USE_SQL_SLAVE_);

            $id_lang = $this->context->language->id;
            
            $sign_currency = $this->context->currency->sign;

            $dp_idpro = 'SELECT id_product from ' . _DB_PREFIX_ . 'product_doubleboo where id_user like "';
            $dp_idpro .= pSQL($id_user) . '"';
            $id_p = $db->ExecuteS($dp_idpro, true, false);
            $count_sp = Count($id_p);
            $store = array();
            if ($count_sp > 0) {
                foreach ($id_p as $key => $value) {
                    $id_pro = $value['id_product'];
                    $product = new Product($id_pro, false, $id_lang);
                    $attribute_df = $product->getDefaultAttribute($id_pro);
                    $attribute_pro = $product->getAttributeCombinations($id_lang);

                    $find_id = 'Select id_combination from ' . _DB_PREFIX_ . 'product_doubleboo where id_user like "';
                    $find_id .= pSQL($id_user) . '" ';

                    $id_combination = $db->ExecuteS($find_id, true, false);

                    $id_combi_dbboo = $id_combination[$key]['id_combination'];

                    $dp_so_sp = 'Select count_product from ' . _DB_PREFIX_ . 'product_doubleboo where id_product like ';
                    $dp_so_sp .= (int)$id_pro.' and id_combination like "' .(int)$id_combi_dbboo.'" and id_user like "';
                    $dp_so_sp .= pSQL($id_user) . '" ';
                    $so_luong_sp = $db->ExecuteS($dp_so_sp, true, false);

                    if ($attribute_df == '') {
                        $pri_pro = $product->price;
                        $image = new Image();
                        $dp_image = $image->getImages($id_lang, $id_pro);

                        $link_rew = $product->link_rewrite;

                        $linkimages = new Link();
                        if ($dp_image == null) {
                            $link_img = Tools::getServerName();
                            $link_img .= __PS_BASE_URI__ . 'modules/askforaquotemodul/views/img/noimg.png';
                        } else {
                            $id_img = Product::getCover($id_pro);
                            $id_img = $id_img['id_image'];
                            if (!isset($id_img)) {
                                $id_img = 0;
                            }
                            $image_type_1 = '';
                            if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                                // for PrestaShop 1.7+
                                $image_type_1 = ImageType::getFormattedName('cart');
                            } else {
                                $image_type_1 = ImageType::getFormatedName('cart');
                            }
                            $link_img = $linkimages->getImageLink($link_rew, $id_img, $image_type_1);
                        }
                        $link_pro = $linkimages->getProductLink($id_pro);
                        $pri_pro_tax = $product->getPrice($this->useTax(), $id_combi_dbboo, 2);
                        $product->price_tax = $pri_pro_tax;
                        $product->img_doubleboo = Tools::getShopProtocol() . $link_img;
                        $product->link_pro = $link_pro;
                        $product->price = $pri_pro;
                        $product->so_luong_sp = $so_luong_sp;
                        $product->id_combi_dbboo = $id_combi_dbboo;
                        $product->price_full = Tools::displayPrice($pri_pro_tax, $id_currency).$this->prefixTax();
                        $store[$key] = $product;
                    } else {
                        $attr_group = new AttributeGroup();
                        $get_attr = $attr_group->getAttributesGroups($id_lang);
                        $size_attr = '';
                        $link_rew = $product->link_rewrite;
                        $linkimages = new Link();
                        $image = new Image();
                        $dp_image = $image->getImages($id_lang, $id_pro);
                        foreach ($get_attr as $key_gr => $value_attr) {
                            $value_attr;
                            foreach ($attribute_pro as $key_idattr => $value_idattr) {
                                if ($id_combi_dbboo == $value_idattr['id_product_attribute']) {
                                    $gr_name_attr = $attribute_pro[$key_idattr]['group_name'];
                                    if ($gr_name_attr == $get_attr[$key_gr]['name']) {
                                        $id_pro_attribute = $attribute_pro[$key_idattr]['id_product_attribute'];
                                        $id_image_attr = 'Select id_image from ';
                                        $id_image_attr .= _DB_PREFIX_ . 'product_attribute_image';
                                        $id_image_attr .= ' where id_product_attribute like "'.$id_pro_attribute.'"';
                                        $id_image_attribute = $db->ExecuteS($id_image_attr, true, false);
                                        if (empty($id_image_attribute)) {
                                            $id_img = Product::getCover($id_pro);
                                            $id_img = $id_img['id_image'];

                                            if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                                                // for PrestaShop 1.7+
                                                $type_img = ImageType::getFormattedName('cart');
                                            } else {
                                                $type_img = ImageType::getFormatedName('cart');
                                            }
                                            if (!isset($id_img)) {
                                                $id_img = 0;
                                            }
                                            $link_img = $linkimages->getImageLink($link_rew, $id_img, $type_img);
                                            $product->img_doubleboo = Tools::getShopProtocol() . $link_img;
                                        } else {
                                            foreach ($id_image_attribute as $key_img => $value_img) {
                                                $value_img;
                                                $img_attr = $id_image_attribute[$key_img]['id_image'];
                                                if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                                                    // for PrestaShop 1.7+
                                                    $type_img = ImageType::getFormattedName('cart');
                                                } else {
                                                    $type_img = ImageType::getFormatedName('cart');
                                                }
                                                $link_img = $linkimages->getImageLink($link_rew, $img_attr, $type_img);
                                                $product->img_doubleboo = Tools::getShopProtocol() . $link_img;
                                            }
                                        }
                                        $size_attr = $attribute_pro[$key_idattr]['attribute_name'] . ',' . $size_attr;
                                    } else {
                                        $size_attr .= '';
                                    }
                                }
                                $result = Tools::substr($size_attr, 0, -1);
                                $product->attr_dbboo = $result;
                            }
                        }

                        $pri_pro = $product->price;
                        $link_pro = $linkimages->getProductLink($id_pro);
                        $pri_pro_tax = $product->getPrice($this->useTax(), $id_combi_dbboo, 2);
                        $product->price_tax = $pri_pro_tax;
                        $product->link_pro = $link_pro;
                        $product->price = $pri_pro;
                        $product->so_luong_sp = $so_luong_sp;
                        $product->id_combi_dbboo = $id_combi_dbboo;
                        $product->price_full = Tools::displayPrice($pri_pro_tax, $id_currency).$this->prefixTax();
                        $store[$key] = $product;
                    }
                    $total_product_qty = ((double) $pri_pro_tax * (int) $product->so_luong_sp[0]['count_product']);
                    $product_total_price = (double) $product_total_price + $total_product_qty;
                }
                $num_total = array();
                $num_total['number'] = $count_sp;
                $num_total['total_price'] = $product_total_price;
                $f = Tools::displayPrice($product_total_price, $id_currency).$this->prefixTax();
                $num_total['total_price_full'] = $f;
            } else {
                $num_total = array();
                $num_total['number'] = 0;
                $num_total['total_price'] = '0.00' . $sign_currency;
                $num_total['total_price_full'] = Tools::displayPrice('0.00', $id_currency);
            }
            $this->context->smarty->assign("currency_dbboo", $id_currency);
            $this->context->smarty->assign("details_product", $store);
            $this->context->smarty->assign("num_total", $num_total);
            $html = '';

            $web_version = Tools::getShopProtocol() . Tools::getHttpHost() . __PS_BASE_URI__;
            $this->context->smarty->assign('option_price_total', $option_price_total);
            $this->context->smarty->assign('_path', $this->_path);
            $this->context->smarty->assign('version', $web_version);
            $this->context->smarty->assign('option_show_captcha', $option_show_captcha);
            $this->context->smarty->assign('check_id_customer', $check_id_customer);
            $this->context->smarty->assign('option_addtocart', $option_addtocart);
            $this->context->smarty->assign('sign_currency', $sign_currency);
            $this->context->smarty->assign('link_quote_seo', $link_quote_seo);
            $this->context->smarty->assign('link_myquote_seo', $link_myquote_seo);
            $url_php = Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__;
            $this->context->smarty->assign('url_php', $url_php);
            $this->context->smarty->assign('ss_id', $id_user);
            $this->context->smarty->assign('token_askaquotemodule', md5(sha1(_COOKIE_KEY_.'askforaquotemodul')));
            $this->context->smarty->assign('hook', 'hookdisplayNav2');
            if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                $this->context->controller->addCSS($this->_path . 'views/css/style17.css');
                $check_vs = 1;
                $this->context->smarty->assign('check_vs', $check_vs);
                $html .= $this->display(__FILE__, 'views/templates/hook/cartquote.tpl');
            } else {
                $this->context->smarty->assign('check_vs', $check_vs);
                $this->context->controller->addCSS($this->_path . 'views/css/style_new.css');
                $html .= $this->display(__FILE__, 'views/templates/hook/cartquote.tpl');
            }
            $this->context->controller->addJS($this->_path . 'views/js/updownbtn.js');
            $this->context->controller->addJS($this->_path . 'views/js/handviewlist.js');
            $this->context->controller->addJS($this->_path . 'views/js/showdetails.js');
            return $html;
        } else {
            return ;
        }
    }

    public function hookDisplayOrderConfirmation(&$params)
    {
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $id_order = Tools::getValue('id_order');
        $id_cart = Tools::getValue('id_cart');
        $sql = 'UPDATE '._DB_PREFIX_.'product_quote_dbboo SET id_order_create=\''.(int)$id_order.'\' ';
        $sql .= 'WHERE id_cart_create=\''.(int)$id_cart.'\'';
        $db->query($sql);
    }
    
    public function hookdisplayTop(&$params)
    {
        // check groups of customer can allowed to use this module? since 1.0.38+
        if (!$this->isAllowedUseQuote()) {
            return '';
        }

        $check_id_customer = (int) $this->context->cookie->id_customer;
        $this->context->controller->addJS($this->_path . 'views/js/checkoptcategory.js');
        $id_currency = $this->context->currency->id;
        $option_addtocart = Configuration::get('Option_addtocart');
        $product_total_price = 0;
        $check_vs = 0;
        $option_price_total = Configuration::get('Option_price_total');
        $option_show_captcha = Configuration::get('Option_show_captcha');
        if (empty(Context::getContext()->cookie->client)) {
            Context::getContext()->cookie->client = md5(time());
        }
        $link = new Link();
        $link_quote_seo = $link->getModuleLink('askforaquotemodul', 'quotes');
        $link_myquote_seo = $link->getModuleLink('askforaquotemodul', 'myquotecustomer');
        
        $id_user = Context::getContext()->cookie->client;
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $id_lang = $this->context->language->id;
        $sign_currency = $this->context->currency->sign;
        $dp_idpro = 'SELECT id_product from ' . _DB_PREFIX_ . 'product_doubleboo where id_user like "';
        $dp_idpro .= pSQL($id_user) . '"';
        $id_p = $db->ExecuteS($dp_idpro, true, false);
        $count_sp = Count($id_p);
        $store = array();
        if ($count_sp > 0) {
            foreach ($id_p as $key => $value) {
                    $id_pro = $value['id_product'];
                    $product = new Product($id_pro, false, $id_lang);
                    
                    $attribute_df = $product->getDefaultAttribute($id_pro);
                    $attribute_pro = $product->getAttributeCombinations($id_lang);

                    $find_id = 'Select id_combination from ' . _DB_PREFIX_ . 'product_doubleboo where id_user like "';
                    $find_id .= pSQL($id_user) . '" ';

                    $id_combination = $db->ExecuteS($find_id, true, false);

                    $id_combi_dbboo = $id_combination[$key]['id_combination'];

                    $dp_so_sp = 'Select count_product from ' . _DB_PREFIX_ . 'product_doubleboo where id_product like ';
                    $dp_so_sp .= (int)$id_pro.' and id_combination like "' .(int)$id_combi_dbboo.'" and id_user like "';
                    $dp_so_sp .= pSQL($id_user) . '" ';
                    $so_luong_sp = $db->ExecuteS($dp_so_sp, true, false);

                if ($attribute_df == '') {
                    $pri_pro = $product->price;
                    $image = new Image();
                    $dp_image = $image->getImages($id_lang, $id_pro);

                    $link_rew = $product->link_rewrite;

                    $linkimages = new Link();
                    if ($dp_image == null) {
                        $link_img = Tools::getServerName();
                        $link_img .= __PS_BASE_URI__ . 'modules/askforaquotemodul/views/img/noimg.png';
                    } else {
                        $id_img = Product::getCover($id_pro);
                        $id_img = $id_img['id_image'];
                        if (!isset($id_img)) {
                                $id_img = 0;
                        }
                            $image_type_1 = '';
                        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) { // for PrestaShop 1.7+
                                $image_type_1 = ImageType::getFormattedName('cart');
                        } else {
                                $image_type_1 = ImageType::getFormatedName('cart');
                        }
                            $link_img = $linkimages->getImageLink($link_rew, $id_img, $image_type_1);
                    }
                    $link_pro = $linkimages->getProductLink($id_pro);
                    $pri_pro_tax = $product->getPrice($this->useTax(), $id_combi_dbboo, 2);
                    $product->price_tax = $pri_pro_tax;
                    $product->img_doubleboo = Tools::getShopProtocol() . $link_img;
                    $product->link_pro = $link_pro;
                    $product->price = $pri_pro;
                    $product->so_luong_sp = $so_luong_sp;
                    $product->id_combi_dbboo = $id_combi_dbboo;
                    $product->price_full = Tools::displayPrice($pri_pro_tax, $id_currency).$this->prefixTax();
                    $store[$key] = $product;
                } else {
                    $attr_group = new AttributeGroup();
                    $get_attr = $attr_group->getAttributesGroups($id_lang);
                    $size_attr = '';
                    $link_rew = $product->link_rewrite;
                    $linkimages = new Link();
                    $image = new Image();
                    $dp_image = $image->getImages($id_lang, $id_pro);
                    foreach ($get_attr as $key_gr => $value_attr) {
                        $value_attr;
                        foreach ($attribute_pro as $key_idattr => $value_idattr) {
                            if ($id_combi_dbboo == $value_idattr['id_product_attribute']) {
                                    $gr_name_attr = $attribute_pro[$key_idattr]['group_name'];
                                if ($gr_name_attr == $get_attr[$key_gr]['name']) {
                                        $id_pro_attribute = $attribute_pro[$key_idattr]['id_product_attribute'];
                                        $id_image_attr = 'Select id_image from ';
                                        $id_image_attr .= _DB_PREFIX_ . 'product_attribute_image';
                                        $id_image_attr .= ' where id_product_attribute like "'.$id_pro_attribute.'"';
                                        $id_image_attribute = $db->ExecuteS($id_image_attr, true, false);
                                    if (empty($id_image_attribute)) {
                                            $id_img = Product::getCover($id_pro);
                                            $id_img = $id_img['id_image'];

                                        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                                                // for PrestaShop 1.7+
                                                $type_img = ImageType::getFormattedName('cart');
                                        } else {
                                                $type_img = ImageType::getFormatedName('cart');
                                        }
                                        if (!isset($id_img)) {
                                                $id_img = 0;
                                        }
                                            $link_img = $linkimages->getImageLink($link_rew, $id_img, $type_img);
                                            $product->img_doubleboo = Tools::getShopProtocol() . $link_img;
                                    } else {
                                        foreach ($id_image_attribute as $key_img => $value_img) {
                                                $value_img;
                                                $img_attr = $id_image_attribute[$key_img]['id_image'];
                                            if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                                                    $type_img = ImageType::getFormattedName('cart');
                                            } else {
                                                    $type_img = ImageType::getFormatedName('cart');
                                            }
                                                $link_img = $linkimages->getImageLink($link_rew, $img_attr, $type_img);
                                                $product->img_doubleboo = Tools::getShopProtocol() . $link_img;
                                        }
                                    }
                                        $size_attr = $attribute_pro[$key_idattr]['attribute_name'] . ',' . $size_attr;
                                } else {
                                        $size_attr .= '';
                                }
                            }
                                $result = Tools::substr($size_attr, 0, -1);
                                $product->attr_dbboo = $result;
                        }
                    }

                    $pri_pro = $product->price;
                    $link_pro = $linkimages->getProductLink($id_pro);
                    $pri_pro_tax = $product->getPrice($this->useTax(), $id_combi_dbboo, 2);
                    $product->price_tax = $pri_pro_tax;
                    $product->link_pro = $link_pro;
                    $product->price = $pri_pro;
                    $product->so_luong_sp = $so_luong_sp;
                    $product->id_combi_dbboo = $id_combi_dbboo;
                    $product->price_full = Tools::displayPrice($pri_pro_tax, $id_currency).$this->prefixTax();
                    $store[$key] = $product;
                }
                    $total_product_qty = ((double) $pri_pro_tax * (int) $product->so_luong_sp[0]['count_product']);
                    $product_total_price = (double) $product_total_price + $total_product_qty;
            }
            $num_total = array();
            $num_total['number'] = $count_sp;
            $num_total['total_price'] = $product_total_price;
            $num_total['total_price_full'] = Tools::displayPrice($product_total_price, $id_currency).$this->prefixTax();
        } else {
            $num_total = array();
            $num_total['number'] = 0;
            $num_total['total_price'] = '0.00' . $sign_currency;
            $num_total['total_price_full'] = Tools::displayPrice('0.00', $id_currency);
        }
        $this->context->smarty->assign("currency_dbboo", $id_currency);
        $this->context->smarty->assign("details_product", $store);
        $this->context->smarty->assign("num_total", $num_total);
        $html = '';

        $web_version = Tools::getShopProtocol() . Tools::getHttpHost() . __PS_BASE_URI__;
        $option_num_display = Configuration::get('Option_num_display');
        $this->context->smarty->assign('option_price_total', $option_price_total);
        $this->context->smarty->assign('option_num_display', $option_num_display);
        $this->context->smarty->assign('_path', $this->_path);
        $this->context->smarty->assign('version', $web_version);
        $this->context->smarty->assign('option_show_captcha', $option_show_captcha);
        $this->context->smarty->assign('check_id_customer', $check_id_customer);
        $this->context->smarty->assign('option_addtocart', $option_addtocart);
        $this->context->smarty->assign('sign_currency', $sign_currency);
        $this->context->smarty->assign('link_quote_seo', $link_quote_seo);
        $this->context->smarty->assign('link_myquote_seo', $link_myquote_seo);
        $url_php = Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__;
        $this->context->smarty->assign('url_php', $url_php);
        $this->context->smarty->assign('ss_id', $id_user);
        $this->context->smarty->assign('token_askaquotemodule', md5(sha1(_COOKIE_KEY_.'askforaquotemodul')));
        $this->context->smarty->assign('hook', 'hookdisplayTop');
        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                $this->context->controller->addCSS($this->_path . 'views/css/style17.css');
                $check_vs = 1;
                $this->context->smarty->assign('check_vs', $check_vs);
        } else {
                $this->context->smarty->assign('check_vs', $check_vs);
                $this->context->controller->addCSS($this->_path . 'views/css/style_new.css');
        }
        $html .= $this->display(__FILE__, 'views/templates/hook/cartquote.tpl');
        $html .= $this->displayPopupQuote();
        $this->context->controller->addJS($this->_path . 'views/js/updownbtn.js');
        $this->context->controller->addJS($this->_path . 'views/js/handviewlist.js');
        $this->context->controller->addJS($this->_path . 'views/js/showdetails.js');
        return $html;
    }
    public function displayPopupQuote()
    {
        $option_price_total = Configuration::get('Option_price_total');
        $link = new Link();
        $link_quote_seo = $link->getModuleLink('askforaquotemodul', 'quotes');
        $this->context->smarty->assign('option_price_total', $option_price_total);
        $this->context->smarty->assign('link_quote_seo', $link_quote_seo);
        $html = $this->display(__FILE__, 'views/templates/hook/popupquotesuccess.tpl');
        return $html;
    }
    public function getContent()
    {
        $this->test();
        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) { // for PrestaShop 1.7+
            $this->ps_cipherTool = new PhpEncryption(_NEW_COOKIE_KEY_);
        } else {
            $this->ps_cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
        }
        $this->context->controller->addJqueryUI('ui.sortable');
        // if maintaince mode enabled
        $remote_ip = Tools::getRemoteAddr();
        if (!(int)Configuration::get('PS_SHOP_ENABLE')) {
            if (!in_array($remote_ip, explode(',', Configuration::get('PS_MAINTENANCE_IP')))) {
                if (!Configuration::get('PS_MAINTENANCE_IP')) {
                    Configuration::updateValue('PS_MAINTENANCE_IP', $remote_ip);
                } else {
                    $new_ips = Configuration::get('PS_MAINTENANCE_IP') . ',' . $remote_ip;
                    Configuration::updateValue('PS_MAINTENANCE_IP', $new_ips);
                }
            }
        }

        $id_default_language = (int) (Configuration::get('PS_LANG_DEFAULT'));
        $iso_default_l = Language::getIsoById($id_default_language);
        $id_currency_dbboo = $this->context->currency->id;
        $bamodule = AdminController::$currentIndex;
        $sign_currency = $this->context->currency->sign;
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);

        $token = Tools::getAdminTokenLite('AdminModules');
        $token_adm = Tools::getValue('token');
        $task_menu = 'Quote';
        $url = Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__;
        $admin_folder = basename(_PS_ADMIN_DIR_);

        $buttonDemoArr = array(
            'btn_send',
            'save_form',
            'save_option'
        );
        $buttonDemoArr1 = array(
            Tools::getValue('deleteaskforaquotemodul')
        );
        if ($this->demoMode == true) {
            foreach ($buttonDemoArr as $buttonDemo) {
                if (Tools::isSubmit($buttonDemo)) {
                    Tools::redirectAdmin($bamodule . '&token=' . $token . '&configure=' . $this->name . '&demoMode=1');
                }
            }
            foreach ($buttonDemoArr1 as $buttonDemo1) {
                if ($buttonDemo1 !== false) {
                    Tools::redirectAdmin($bamodule . '&token=' . $token . '&configure=' . $this->name . '&demoMode=1');
                }
            }
        }
        $demoMode = 0;
        if (Tools::getValue('demoMode') == "1") {
            $demoMode = Tools::getValue('demoMode');
        }
        $this->smarty->assign('demoMode', $demoMode);

        $link_module = $url . $admin_folder . '/index.php?controller=AdminModules&token=';
        $link_module .= $token . '&configure=askforaquotemodul&module_name=askforaquotemodul';
        $this->context->smarty->assign('path', $this->_path);
        $this->context->smarty->assign('sign_currency', $sign_currency);
        $this->context->smarty->assign("bamodul", $bamodule);
        $this->context->smarty->assign("currency_dbboo", $id_currency_dbboo);
        $this->context->smarty->assign("token_adm", $token_adm);

        if (Tools::getValue('task')) {
            $task_menu = Tools::getValue('task');
        }
        $html = '';
        if (Tools::getValue('sendmail') === '0') {
            $html .= $this->displayError($this->l('Error in sending the email to your customer.'));
        }
        if (Tools::getValue('sendmail') === '1') {
            $html .= $this->displayConfirmation($this->l('The email was sent to your customer.'));
        }
        if (Tools::getValue('make_order_success') === '0') {
            $html .= $this->displayError($this->l('Error in creating the order'));
        }
        if (Tools::getValue('make_order_success') === '1') {
            $html .= $this->displayConfirmation($this->l('Create a successful order'));
        }

        $send_success = Tools::getValue('send_success');
        $save_success = Tools::getValue('save_success');
        if ($send_success == 1) {
            $html .= $this->displayConfirmation($this->l('Send message successful'));
        }
        if ($save_success == 1) {
            $html .= $this->displayConfirmation($this->l('Update successful'));
        }
        $this->context->smarty->assign('link_module', $link_module);
        $this->context->smarty->assign('task_menu', $task_menu);
        $html .= $this->display(__FILE__, 'views/templates/admin/tab.tpl');

        $email_new = Configuration::get('email_new_quote');
        $email_new_form = $this->ps_cipherTool->decrypt($email_new);
        $this->context->smarty->assign('email_new', $email_new_form);

        $email_quote_notes = Configuration::get('Email_notes_quote');
        $format_currency = Configuration::get('format_currency');
        $email_notes_form = $this->ps_cipherTool->decrypt($email_quote_notes);
        $this->context->smarty->assign('format_currency', $format_currency);
        $this->context->smarty->assign('email_quote_notes', $email_notes_form);

        $email_adm_check = Configuration::get('email_adm_setting');
        $this->context->smarty->assign('email_admin_setting', $email_adm_check);
        if (Tools::isSubmit('addaskforaquotemodul')) {
            $id_currency_dbboo = $this->context->currency->id;
            $bamodule = AdminController::$currentIndex;
            $sign_currency = $this->context->currency->sign;
            $token = Tools::getAdminTokenLite('AdminModules');
            // $search_1 = '';
            if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                $this->ps_cipherTool = new PhpEncryption(_NEW_COOKIE_KEY_);
            } else {
                $this->ps_cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
            }
            $token_adm = Tools::getValue('token');
            $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
            $html = '';
            if (Tools::isSubmit('submitResetaskforaquotemodul')) {
                unset($this->context->cookie->{'askforaquotemodulFilter_id_quote'});
                unset($this->context->cookie->{'askforaquotemodulFilter_first_name'});
                unset($this->context->cookie->{'askforaquotemodulFilter_last_name'});
                unset($this->context->cookie->{'askforaquotemodulFilter_phone'});
                unset($this->context->cookie->{'askforaquotemodulFilter_date_quote'});
                unset($this->context->cookie->{'askforaquotemodulFilter_total_pri'});
                unset($this->context->cookie->{'askforaquotemodulFilter_nb_mess_ud'});
                unset($this->context->cookie->{'askforaquotemodulFilter_id_lang'});
                $this->context->cookie->{'order_by'} = 'date_quote';
                $this->context->cookie->{'order_way'} = 'desc';
                Tools::redirectAdmin($bamodule . '&token=' . $token . '&configure=' . $this->name . '');
            }
            $id_carrier = array();
            $op_login_customer = Configuration::get('Option_login_customer');
            $op_company_name = Configuration::get('Option_company_name');
            $id_carrierr = array();
            $id_lang = $this->context->language->id;
            $sqll = 'SELECT id_carrier FROM ' . _DB_PREFIX_ . 'carrier WHERE active = "1" and deleted = "0"';
            $id_carrierr[] = $db->executeS($sqll);
            foreach ($id_carrierr as $value1) {
                $arrays = $value1;
                foreach ($arrays as $val) {
                    $id_carrier[] = $val['id_carrier'];
                }
            }
            $id_carrierrr = implode(",", $id_carrier);
            $sql_delay = 'SELECT name, id_carrier FROM ' . _DB_PREFIX_ . 'carrier WHERE ';
            $sql_delay .= 'id_carrier in ';
            $sql_delay .= '(' . $id_carrierrr . ')';
            $name_carrier = $db->executeS($sql_delay);
            
            $this->context->smarty->assign("delay", $name_carrier);
            $this->context->smarty->assign("PS_SHOP_NAME", Configuration::get('PS_SHOP_NAME'));
            $this->context->smarty->assign("token_dbboo", $token_adm);
            $this->context->smarty->assign("op_login_customer", $op_login_customer);
            $this->context->smarty->assign("op_company_name", $op_company_name);
            $this->context->smarty->assign("sign_currency", $sign_currency);
            $a = "url_php";
            $this->context->smarty->assign($a, Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__);
            $this->context->smarty->assign("demo_mod", $this->demoMode);
            $this->context->smarty->assign("token_askaquotemodule", md5(sha1(_COOKIE_KEY_.'askforaquotemodul')));
            if (Tools::isSubmit('save_new_quote')) {
                $id_currency = (int) $this->context->currency->id;
                $id_lang = (int) $this->context->language->id;
                $first_name = Tools::getValue('first_name');
                $last_name = Tools::getValue('last_name');
                $company_name = Tools::getValue('company_name');
                $company_address = Tools::getValue('company_address');
                $phone = Tools::getValue('phone');
                $email = Tools::getValue('email');
                $message_newquote = Tools::getValue('message_dbboo');
                $quote_name = Tools::getValue('quote_name');
                $edit_price = Tools::getValue('infor_quote');
                
                $shipping_cost_tax = (float) Tools::getValue('shipping_cost_tax_plain');
                $date_now_h_i_s = date('Y-m-d H:i:s');
                $file_attached = '';
                $nb_mess_ud = '0';
                if (empty($quote_name)) {
                    $quote_name = $this->l('New Quote from your website.');
                }
                if ($edit_price['id_customer'] == 0) {
                    $creatcustomer = new Customer();
                    $password = md5(time()._COOKIE_KEY_);
                    $creatcustomer->firstname = $first_name;
                    $creatcustomer->lastname = $last_name;
                    $creatcustomer->email = $email;
                    $creatcustomer->newsletter = 1;
                    $creatcustomer->active = 1;
                    $creatcustomer->is_guest = 1;
                    $creatcustomer->passwd = $password;
                    $creatcustomer->add();
                    if (!empty($creatcustomer->id)) {
                        $edit_price['id_customer'] = $creatcustomer->id;
                    }
                }
                $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
                
                $is_quote = 'INSERT INTO ' . _DB_PREFIX_ . 'product_quote_dbboo ';
                $is_quote .= '(id_currency, id_lang, id_customer, first_name, last_name,';
                $is_quote .= 'company_name, phone, email, quote_name, message, date_quote,';
                $is_quote .= 'file_attached, total_pri, nb_mess_ud, shipping_cost, tax_cost,';
                $is_quote .= 'shipping_option, company_address, shipping_cost_tax) VALUES ';
                $is_quote .= '("' . $id_currency . '","' . $id_lang . '","' . (int) $edit_price['id_customer'] . '",';
                $is_quote .= '"' . pSQL($first_name) . '","' . pSQL($last_name) . '","' . pSQL($company_name) . '",';
                $is_quote .= '"'. pSQL($phone) . '","' . pSQL($email) . '","' . pSQL($quote_name) . '","';
                $is_quote .= pSQL($message_newquote) . '",';
                $is_quote .= '"' . pSQL($date_now_h_i_s) . '","' . pSQL($file_attached) . '",';
                $is_quote .= '"' . (float) $edit_price['total_price_all'] . '",';
                $is_quote .= '"' . (int)$nb_mess_ud . '","' . (float) $edit_price['shipping_cost'] . '",';
                $is_quote .= '"' . (float) $edit_price['tax_cost'] . '","';
                $is_quote .= (int)$edit_price['shipping_option'] . '",';
                $is_quote .= "'".pSQL($company_address)."'";
                $is_quote .= ",".$shipping_cost_tax;
                $is_quote .= ")";
                $db->query($is_quote);
                
                $id_quote = (int) Db::getInstance()->Insert_ID();
                $mess_newquote = 'INSERT INTO ' . _DB_PREFIX_ . 'message_dbboo ';
                $mess_newquote .= '(id_quote, email, content_mes, date_send, type, status) VALUES';
                $mess_newquote .= '("' . $id_quote . '","' . pSQL($email) . '","' . pSQL($message_newquote) . '",';
                $mess_newquote .= '"' . pSQL($date_now_h_i_s) . '",';
                $mess_newquote .= '"0","1");';

                $db->query($mess_newquote);
                // since 1.0.42
                $baproduct = Tools::getValue('baproduct');
                foreach ($edit_price as $key => $value) {
                    $a = 'total_price_all';
                    $b = 'id_customer';
                    $c = 'tax_cost';
                    $d = 'shipping_cost';
                    $e = 'shipping_option';
                    if ($key !== $a && $key !== $b && $key !== $c && $key !== $d && $key !== $e) {
                        $value['combination'] = Tools::htmlentitiesDecodeUTF8($value['combination']);
                        $value['name_product'] = Tools::htmlentitiesDecodeUTF8($value['name_product']);
                        $value['link_images'] = Tools::htmlentitiesDecodeUTF8($value['link_images']);
                        $value['reference'] = Tools::htmlentitiesDecodeUTF8($value['reference']);
                        // since 1.0.39+, update product with Tax
                        $ip = $value['id_product'];
                        $unit_price = $value['pri_pro'];
                        $id_cus = $edit_price['id_customer'];
                        $pq = (int) $value['qty_product'];
                        $unitprice_incl_tax = (float) $this->getProductPriceTax($unit_price, $ip, $id_cus, $id_lang);
                        $totalprice_incl_tax = (float) $unitprice_incl_tax * $pq;
                        $id_tax_rules_group = (int) $this->getIdTaxRulesGroupByIdProduct($value['id_product']);
                        // since 1.0.42
                        $n_key = str_replace('-', '_', $key);
                        $position = (int) @$baproduct[$n_key]['position'];

                        $is_quote_detail = 'INSERT INTO ' . _DB_PREFIX_ . 'product_quote_detail ';
                        $is_quote_detail .= '(id_quote, id_currency, id_lang, link_img, id_product,';
                        $is_quote_detail .= 'product_name, reference, id_combination, combination, product_pri,';
                        $is_quote_detail .= 'product_qty,total_pri,product_pri_incl_tax';
                        $is_quote_detail .= ', id_tax_rules_group, total_pri_incl_tax, position) VALUES ';
                        $is_quote_detail .= '("' . $id_quote . '","' . $id_currency . '","' . $id_lang . '",';
                        $is_quote_detail .= '"' . pSQL($value['link_images']) . '",';
                        $is_quote_detail .= '"' . (int)$value['id_product'] . '",';
                        $is_quote_detail .= '"' . pSQL($value['name_product']) . '",';
                        $is_quote_detail .= '"' . pSQL($value['reference']) . '",';
                        $is_quote_detail .= '"' . (int) $value['id_combi_pro'] . '",';
                        $is_quote_detail .= '"' . pSQL($value['combination']) . '",';
                        $is_quote_detail .= '"' . (float) $value['pri_pro'] . '",';
                        $is_quote_detail .= '"' . (int) $value['qty_product'] . '",';
                        $is_quote_detail .= '"' . (float) $value['total_price_product'] . '"';
                        $is_quote_detail .= ',' . $unitprice_incl_tax;
                        $is_quote_detail .= ',' . $id_tax_rules_group;
                        $is_quote_detail .= ',' . $totalprice_incl_tax;
                        $is_quote_detail .= ',' . $position;
                        $is_quote_detail .= ')';
                        
                        $db->query($is_quote_detail);
                    }
                }
                $dp_id_q = 'Select id_quote from ' . _DB_PREFIX_ . 'product_quote_dbboo ORDER BY id_quote DESC';
                $dp_id_quote = $db->getrow($dp_id_q, false);
                $id_quote_db = $dp_id_quote['id_quote'];
                $cus_mes = 'INSERT INTO ' . _DB_PREFIX_ . 'cus_message_dbboo ';
                $cus_mes .= '(id_quote, id_customer, so_luong_mes) ';
                $cus_mes .= 'VALUES ("'. $id_quote_db .'", "'. $edit_price['id_customer'] .'", 0)';
                $db->query($cus_mes);
                $head_link = $bamodule . '&token=' . $token . '&configure='.$this->name.'&save_success=1';
                Tools::redirectAdmin($head_link);
            }
            $url = Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__;
            $admin_folder = basename(_PS_ADMIN_DIR_);
            $link_to_admin = $url . $admin_folder;
            $format_currency = Configuration::get('format_currency');
            $html .= '<script language="javascript" type="text/javascript">
                var productttt="' . $this->l('Product:') . '";
                var link_to_admin="' . $link_to_admin . '";
                var selectstate="' . $this->l('Select State') . '";
                var cheapest_product="' . $this->l('Cheapest Product') . '";
                var free_shipping="' . $this->l('Free shipping') . '";
                var error_js="' . $this->l('Invalid coupon code') . '";
                var enter_coupon="' . $this->l('Please enter your coupon') . '";
                var jsshopid="' . (int)$this->context->shop->id . '";
                var jslanguageid="' . (int)$this->context->language->id . '";
                var textcombination="' . $this->l('Combination') . '";
                var textproduct="' . $this->l('Price (Excl Tax)') . '";
                var batokencus="' . Tools::getAdminTokenLite('AdminProducts') . '";
                var format_currency="' . $format_currency . '";
            </script>';
            $html .= $this->display(__FILE__, 'views/templates/admin/addnewquote.tpl');
            $this->context->controller->addCSS($this->_path . 'views/css/style_new.css');
            $this->context->controller->addJS($this->_path . 'views/js/customernewquote.js');
            $this->context->controller->addJS($this->_path . 'views/js/addnewproduct.js');
            $this->context->controller->addJS($this->_path . 'views/js/addproduct_newquote.js');
            $this->context->controller->addJS($this->_path . 'views/js/delmes.js');
            $this->context->controller->addJS($this->_path . 'views/js/dateFormat.js');
            $this->context->controller->addJS($this->_path . 'views/js/jquery.dateFormat.js');
            return $html;
        }
        if (Tools::isSubmit('save_form')) {
            $arr_language = Language::getLanguages(false);
            $iso_default_language = Language::getIsoById($id_default_language);
            foreach ($arr_language as $key => $value_lang) {
                $value_lang;
                $content_new_all_lang = Tools::getValue('content_new_' . $arr_language[$key]['iso_code']);
                $content_new_all_lang_encrypt = $this->ps_cipherTool->encrypt($content_new_all_lang);

                $content_notice_all_lang = Tools::getValue('content_notice_' . $arr_language[$key]['iso_code']);
                $content_notice_all_lang_encrypt = $this->ps_cipherTool->encrypt($content_notice_all_lang);
                
                $content_price_all_lang = Tools::getValue('content_price_' . $arr_language[$key]['iso_code']);
                $content_price_all_lang_encrypt = $this->ps_cipherTool->encrypt($content_price_all_lang);
                
                $content_pdf_all_lang = Tools::getValue('content_pdf_' . $arr_language[$key]['iso_code']);
                $content_pdf_all_lang_encrypt = $this->ps_cipherTool->encrypt($content_pdf_all_lang);

                $content_new_default_lang = Tools::getValue('content_new_' . $iso_default_language);
                $content_new_default_lang_encrypt = $this->ps_cipherTool->encrypt($content_new_default_lang);

                $content_notice_default_lang = Tools::getValue('content_notice_' . $iso_default_language);
                $content_notice_default_lang_encrypt = $this->ps_cipherTool->encrypt($content_notice_default_lang);
                
                $content_price_default_lang = Tools::getValue('content_price_' . $iso_default_language);
                $content_price_default_lang_encrypt = $this->ps_cipherTool->encrypt($content_price_default_lang);
                
                $content_pdf_default_lang = Tools::getValue('content_pdf_' . $iso_default_language);
                $content_pdf_default_lang_encrypt = $this->ps_cipherTool->encrypt($content_pdf_default_lang);
                $iso = $arr_language[$key]['iso_code'];
                Configuration::updateValue('label_new_' . $iso, $content_new_all_lang_encrypt);
                Configuration::updateValue('label_notice_' . $iso, $content_notice_all_lang_encrypt);
                Configuration::updateValue('label_price_' . $iso, $content_price_all_lang_encrypt);
                Configuration::updateValue('label_pdf_' . $iso, $content_pdf_all_lang_encrypt);
                if ($arr_language[$key]['iso_code'] != $iso_default_language && $content_new_all_lang == '') {
                    Configuration::updateValue('label_new_' . $iso, $content_new_default_lang_encrypt);
                }
                if ($arr_language[$key]['iso_code'] != $iso_default_language && $content_notice_all_lang == '') {
                    Configuration::updateValue('label_notice_' . $iso, $content_notice_default_lang_encrypt);
                }
                if ($arr_language[$key]['iso_code'] != $iso_default_language && $content_price_all_lang == '') {
                    Configuration::updateValue('label_price_' . $iso, $content_price_default_lang_encrypt);
                }
                if ($arr_language[$key]['iso_code'] != $iso_default_language && $content_pdf_all_lang == '') {
                    Configuration::updateValue('label_pdf_' . $iso, $content_pdf_default_lang_encrypt);
                }
            }
            Tools::redirectAdmin($link_module . '&task=Email&save_success=1');
        }
        
        if (Tools::isSubmit('add_new_product')) {
            $attr_couple_array = array();
            $id_lang = $this->context->language->id;
            $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
            $id_currency = $this->context->currency->id;
            $currency = new Currency($id_currency);
            $id_currencyy = $currency->id;
            $id_product_new = Tools::getValue('id_product_new');
            $id_attrbute_pro = Tools::getValue('id_attrbute_pro');
            $id_quote_view = Tools::getValue('id_quote');
            $product_qty = Tools::getValue('product_qty');
            $product = new Product($id_product_new, false, $id_lang);
            $product_name = $product->name;
            $product_attr = $product->getAttributeCombinationsById($id_attrbute_pro, $id_lang);
            $pri_pro = $product->getPrice(false, $id_attrbute_pro, 2);
            $total_pri = $pri_pro * $product_qty;
            foreach ($product_attr as $key => $value) {
                $group_name_attr = $value['group_name'];
                $attribute_name_attr = $value['attribute_name'];
                $attr_couple = $group_name_attr . ":" . $attribute_name_attr;
                $attr_couple_array[] = $attr_couple;
                $combination = implode(',', $attr_couple_array);
            }
            $image = new Image();
            $dp_image = $image->getImages($id_lang, $id_product_new);
            $link_rew = $product->link_rewrite;
            $linkimages = new Link();
            if ($dp_image == null) {
                $link_img = '' . Tools::getServerName() . '' . __PS_BASE_URI__ . '';
                $link_img .= 'modules/askforaquotemodul/views/img/noimg.png';
            } else {
                $id_img = Product::getCover($id_product_new);
                $id_img = $id_img['id_image'];
                if (!isset($id_img)) {
                    $id_img = 0;
                }
                $imagetype =  '';
                if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                    $imagetype = ImageType::getFormattedName('cart');
                } else {
                    $imagetype = ImageType::getFormatedName('cart');
                }
                $link_img = $linkimages->getImageLink($link_rew, $id_img, $imagetype);
            }
            $link_img_full = Tools::getShopProtocol() . $link_img;
            $reference = $product->reference;
            $sql_check = 'Select id_product,id_combination,product_qty from ' . _DB_PREFIX_ . 'product_quote_detail';
            $sql_check .= ' where id_quote = "'.$id_quote_view . '"';
            $check_pro = $db->executeS($sql_check);
            foreach ($check_pro as $value) {
                if ($value['id_product'] == $id_product_new && $value['id_combination'] == $id_attrbute_pro) {
                    $a = 1;
                    $sql = 'update ' . _DB_PREFIX_ . 'product_quote_detail';
                    $sql .= 'set product_qty = "' . (int) $product_qty . '"';
                    $sql .= 'where id_quote = "'. (int) $id_quote_view . '" and ';
                    $sql .= 'id_product = "'.(int) $id_product_new . '"';
                    $db->query($sql);
                } else {
                    $a = 0;
                }
            }
            if ($a == 0) {
                $sql = 'Insert into ' . _DB_PREFIX_ . 'product_quote_detail';
                $sql .= '(id_quote,id_currency,id_lang,link_img,id_product,product_name,reference,';
                $sql .= 'id_combination,combination,product_pri,product_qty,total_pri) values("';
                $sql .= (int) $id_quote_view . '","' . (int) $id_currencyy . '",';
                $sql .= '"' . (int) $id_lang . '","' . $link_img_full . '","';
                $sql .= (int) $id_product_new . '","' . $product_name . '","' . $reference . '",';
                $sql .= '"' . (int) $id_attrbute_pro . '","' . $combination . '","' . $pri_pro . '",';
                $sql .= '"' . (int) $product_qty . '","' . $total_pri . '")';
                $db->query($sql);
            }
            $bamodule = AdminController::$currentIndex;
            $token = Tools::getAdminTokenLite('AdminModules');
            $select_total_pri = 'Select total_pri from ' . _DB_PREFIX_ . 'product_quote_dbboo where id_quote like "';
            $select_total_pri .= (int) $id_quote_view . '"';
            $total_pri_old = $db->ExecuteS($select_total_pri, true, false);
            $total_pri_new = $total_pri + $total_pri_old[0]['total_pri'];
            $update_total_pri = 'UPDATE ' . _DB_PREFIX_ . 'product_quote_dbboo SET total_pri="' . $total_pri_new . '"';
            $update_total_pri .= 'where id_quote like "' . (int) $id_quote_view . '"';
            $db->query($update_total_pri);
            $head_link = $bamodule . '&token=' . $token . '&configure='.$this->name.'&id_quote='.$id_quote_view;
            Tools::redirectAdmin($head_link . '&viewaskforaquotemodul&save_success=1');
        }
        if (Tools::isSubmit('save_option')) {
            $email_admin_setting = Tools::getValue('email_adm_name');
            if ($email_admin_setting != '') {
                Configuration::UpdateValue('email_adm_setting', $email_admin_setting);
            }
            $email_from_setting = Tools::getValue('email_from_name');
            if ($email_from_setting != '') {
                Configuration::UpdateValue('email_from_setting', $email_from_setting);
            }
            $name_from_setting = Tools::getValue('name_adm_name');
            if ($name_from_setting != '') {
                Configuration::UpdateValue('name_from_setting', $name_from_setting);
            }
            $opt_email_newquote_adm = Tools::getValue('choice1');
            Configuration::UpdateValue('Option_email_newquote_adm', $opt_email_newquote_adm);
            $opt_email_newquote_cus = Tools::getValue('choice2');
            Configuration::UpdateValue('Option_email_newquote_cus', $opt_email_newquote_cus);
            $opt_email_noticequote_adm = Tools::getValue('choice3');
            Configuration::UpdateValue('Option_email_noticequote_adm', $opt_email_noticequote_adm);
            $opt_email_noticequote_cus = Tools::getValue('choice4');
            Configuration::UpdateValue('Option_email_noticequote_cus', $opt_email_noticequote_cus);
            $opt_price_total = Tools::getValue('choice5');
            Configuration::UpdateValue('Option_price_total', $opt_price_total);
            $opt_addtocart = Tools::getValue('choice6');
            Configuration::UpdateValue('Option_addtocart', $opt_addtocart);
            $opt_product_out_of_stock = Tools::getValue('choice7');
            Configuration::UpdateValue('Option_product_out_of_stock', $opt_product_out_of_stock);
            $opt_product_priced_0 = Tools::getValue('choice8');
            Configuration::UpdateValue('Option_product_priced_0', $opt_product_priced_0);
            $opt_login_customer = Tools::getValue('choice9');
            Configuration::UpdateValue('Option_login_customer', $opt_login_customer);
            $option_button_category = Tools::getValue('choice11');
            Configuration::UpdateValue('Option_button_category', $option_button_category);
            
            $option_button_pdf = Tools::getValue('choice_pdf');
            Configuration::UpdateValue('Option_button_pdf', $option_button_pdf);
            $option_price_excl_tax = (int) Tools::getValue('option_price_excl_tax');
            Configuration::UpdateValue('option_price_excl_tax', $option_price_excl_tax);
            
            $option_convert_cart = (int) Tools::getValue('option_convert_cart');
            Configuration::UpdateValue('option_convert_cart', $option_convert_cart);
            
            $option_button_smtp = Tools::getValue('choice_smtp');
            Configuration::UpdateValue('Option_button_smtp', $option_button_smtp);
            $sever_smpt = Tools::getValue('sever_smpt');
            Configuration::UpdateValue('sever_smpt', $sever_smpt);
            $port_smtp = Tools::getValue('port_smtp');
            Configuration::UpdateValue('port_smtp', $port_smtp);
            $user_smpt = Tools::getValue('user_smpt');
            Configuration::UpdateValue('user_smpt', $user_smpt);
            $pass_smtp = Tools::getValue('pass_smtp');
            Configuration::UpdateValue('pass_smtp', $pass_smtp);
            $secure_smtp = Tools::getValue('secure_smtp');
            Configuration::UpdateValue('secure_smtp', $secure_smtp);
            $format_currency = Tools::getValue('format_currency');
            Configuration::UpdateValue('format_currency', $format_currency);
            $option_show_captcha = Tools::getValue('choice10');
            Configuration::UpdateValue('Option_show_captcha', $option_show_captcha);
            $option_company_name = Tools::getValue('choice12');
            Configuration::UpdateValue('Option_company_name', $option_company_name);
            $option_order_date = Tools::getValue('order_date');
            if ($option_order_date == null) {
                $option_order_date = 30;
            }
            Configuration::UpdateValue('Option_order_date', $option_order_date);
            $option_num_display = Tools::getValue('num_display');
            if ($option_num_display == null) {
                $option_num_display = 5;
            }
            Configuration::UpdateValue('Option_num_display', $option_num_display);
            $option_file_extension = Tools::getValue('file_extension');
            Configuration::UpdateValue('Option_file_extension', $option_file_extension);
            $include_pro_save = 'Select * from ' . _DB_PREFIX_ . 'include_product_dbboo';
            $include_product_save = $db->executeS($include_pro_save, true, false);
            foreach ($include_product_save as $key => $value) {
                $value;
                $sql_save_product = 'Insert into ' . _DB_PREFIX_ . '';
                $sql_save_product .= 'include_product_dbboo_save(id_product,name_product,type)';
                $sql_save_product .= ' values("' . (int) $include_product_save[$key]['id_product'] . '","';
                $sql_save_product .= pSQL($include_product_save[$key]['name_product']) . '","1")';
                $db->query($sql_save_product);
            }
            $id_product_save = 'Select id_product from ' . _DB_PREFIX_ . 'include_product_dbboo_save';
            $idproduct_save = $db->executeS($id_product_save, true, false);
            $id_product_show = '';
            foreach ($idproduct_save as $key_id => $value_id) {
                $value_id;
                $id_product_show = $idproduct_save[$key_id]['id_product'] . ',' . $id_product_show;
            }
            $list_id_product_show = Tools::substr($id_product_show, 0, -1);
            Configuration::UpdateValue('id_product_show_btn', $list_id_product_show);
            $id_category_Arr = Tools::getValue('categoryBox');
            if (!empty($id_category_Arr)) {
                $id_category = implode(",", $id_category_Arr);
                Configuration::UpdateValue('id_category_dbboo', $id_category);
            } else {
                $id_category = null;
                Configuration::UpdateValue('id_category_dbboo', $id_category);
            }
            // Save groups
            $groups = Tools::getValue('groupBox');
            $groups = Tools::jsonEncode($groups);
            Configuration::UpdateValue('askforaquotemodul_groups', $groups);
            
            Tools::redirectAdmin($link_module . '&task=Settings&save_success=1');
        }

        if (Tools::getValue('task') == false) {
            $html .= $this->adminquote();
        }
        if (Tools::getValue('task') == "Quote") {
            $html .= $this->adminquote();
        }
        if (Tools::getValue('task') == "Email") {
            $arr_language = Language::getLanguages(false);
            $this->smarty->assign('arr_language', $arr_language);

            $id_default_language = (int) (Configuration::get('PS_LANG_DEFAULT'));
            $this->smarty->assign('id_default_language', $id_default_language);

            $iso_default_language = Language::getIsoById($id_default_language);
            $this->smarty->assign('iso_default_language', $iso_default_language);
            $display_contenteditor_new = array();
            $display_contenteditor_notice = array();
            $display_contenteditor_price = array();
            $display_contenteditor_pdf = array();
            foreach ($arr_language as $key => $value_lang) {
                $array_language_iso_code = $arr_language[$key]['iso_code'];

                $content_mess_language_encript_new = Configuration::get('label_new_' . $array_language_iso_code);
                $content_mess_language_new = $this->ps_cipherTool->decrypt($content_mess_language_encript_new);
                $display_contenteditor_new[$key] = $content_mess_language_new;

                $content_mess_language_encript_notice = Configuration::get('label_notice_' . $array_language_iso_code);
                $content_mess_language_notice = $this->ps_cipherTool->decrypt($content_mess_language_encript_notice);
                $display_contenteditor_notice[$key] = $content_mess_language_notice;
                
                $content_mess_language_encript_price = Configuration::get('label_price_' . $array_language_iso_code);
                $content_mess_language_price = $this->ps_cipherTool->decrypt($content_mess_language_encript_price);
                $display_contenteditor_price[$key] = $content_mess_language_price;
                
                $content_pdf_templates = Configuration::get('label_pdf_' . $array_language_iso_code);
                $content_language_pdf_templates = $this->ps_cipherTool->decrypt($content_pdf_templates);
                $display_contenteditor_pdf[$key] = $content_language_pdf_templates;
            }
            $this->smarty->assign('display_contenteditor_new', $display_contenteditor_new);
            $this->smarty->assign('display_contenteditor_notice', $display_contenteditor_notice);
            $this->smarty->assign('display_contenteditor_price', $display_contenteditor_price);
            $this->smarty->assign('display_contenteditor_pdf', $display_contenteditor_pdf);
            $this->context->smarty->assign('path', $this->_path);
            $html .= $this->display(__FILE__, 'views/templates/admin/tabemail.tpl');
        }
        if (Tools::getValue('task') == "Settings") {
            $email_adm_check = Configuration::get('email_adm_setting');
            $email_from_check = Configuration::get('email_from_setting');
            $name_from_check = Configuration::get('name_from_setting');

            $check_email_newquote_adm = Configuration::get('Option_email_newquote_adm');
            $check_email_newquote_cus = Configuration::get('Option_email_newquote_cus');
            $check_email_noticequote_adm = Configuration::get('Option_email_noticequote_adm');
            $check_email_noticequote_cus = Configuration::get('Option_email_noticequote_cus');
            $option_price_total = Configuration::get('Option_price_total');
            $option_addtocart = Configuration::get('Option_addtocart');
            $option_button_pdf = Configuration::get('Option_button_pdf');
            $option_price_excl_tax = Configuration::get('option_price_excl_tax');
            $option_convert_cart = Configuration::get('option_convert_cart');
            $option_button_smtp = Configuration::get('Option_button_smtp');
            $option_product_out_of_stock = Configuration::get('Option_product_out_of_stock');
            $option_product_priced_0 = Configuration::get('Option_product_priced_0');
            $option_login_customer = Configuration::get('Option_login_customer');
            $option_button_category = Configuration::get('Option_button_category');
            $option_show_captcha = Configuration::get('Option_show_captcha');
            $option_order_date = Configuration::get('Option_order_date');
            $option_num_display = Configuration::get('Option_num_display');
            $option_file_extension = Configuration::get('Option_file_extension');
            $option_company_name = Configuration::get('Option_company_name');
            $sever_smpt = Configuration::get('sever_smpt');
            $port_smtp = Configuration::get('port_smtp');
            $user_smpt = Configuration::get('user_smpt');
            $pass_smtp = Configuration::get('pass_smtp');
            $secure_smtp = Configuration::get('secure_smtp');
            $this->context->smarty->assign('sever_smpt', $sever_smpt);
            $this->context->smarty->assign('port_smtp', $port_smtp);
            $this->context->smarty->assign('user_smpt', $user_smpt);
            $this->context->smarty->assign('pass_smtp', $pass_smtp);
            $this->context->smarty->assign('secure_smtp', $secure_smtp);
            $this->context->smarty->assign('email_admin_setting', $email_adm_check);
            $this->context->smarty->assign('email_from_setting', $email_from_check);
            $this->context->smarty->assign('name_from_setting', $name_from_check);

            $this->context->smarty->assign('check_email_newquote_adm', $check_email_newquote_adm);
            $this->context->smarty->assign('check_email_newquote_cus', $check_email_newquote_cus);
            $this->context->smarty->assign('check_email_noticequote_adm', $check_email_noticequote_adm);
            $this->context->smarty->assign('check_email_noticequote_cus', $check_email_noticequote_cus);
            $this->context->smarty->assign('option_price_total', $option_price_total);
            $this->context->smarty->assign('option_addtocart', $option_addtocart);
            $this->context->smarty->assign('option_button_pdf', $option_button_pdf);
            $this->context->smarty->assign('option_price_excl_tax', $option_price_excl_tax);
            $this->context->smarty->assign('option_convert_cart', $option_convert_cart);
            $this->context->smarty->assign('option_button_smtp', $option_button_smtp);
            $this->context->smarty->assign('option_product_out_of_stock', $option_product_out_of_stock);
            $this->context->smarty->assign('option_product_priced_0', $option_product_priced_0);
            $this->context->smarty->assign('option_login_customer', $option_login_customer);
            $this->context->smarty->assign('option_button_category', $option_button_category);
            $this->context->smarty->assign('option_show_captcha', $option_show_captcha);
            $this->context->smarty->assign('option_order_date', $option_order_date);
            $this->context->smarty->assign('option_num_display', $option_num_display);
            $this->context->smarty->assign('option_file_extension', $option_file_extension);
            $this->context->smarty->assign('option_company_name', $option_company_name);

            $rs_include_product = 'DELETE FROM ' . _DB_PREFIX_ . 'include_product_dbboo';
            $db->query($rs_include_product);
            $include_pro = 'Select * from ' . _DB_PREFIX_ . 'include_product_dbboo_save';
            $include_product = $db->executeS($include_pro, true, false);
            $category_name = 'Select * from ' . _DB_PREFIX_ . 'category_lang';
            $list_category_name = $db->executeS($category_name, true, false);
            $id_category_dbboo = Configuration::get('id_category_dbboo');
            $id_category_arr = explode(',', $id_category_dbboo);
            $tree = new HelperTreeCategories('categories-tree');
            $tree->setRootCategory((Shop::getContext() == Shop::CONTEXT_SHOP ? Category::getRootCategory()
                                    ->id_category : 0))
                    ->setUseCheckBox(true)
                    ->setUseSearch(true)
                    ->setSelectedCategories($id_category_arr);
            $menu = $this->tpl_list_vars['category_tree'] = $tree->render();
            $this->context->smarty->assign("tree", $menu);
            $this->context->smarty->assign('include_product', $include_product);
            $this->context->smarty->assign('list_category_name', $list_category_name);
            // get groups
            $id_lang = $this->context->language->id;
            $groups = Group::getGroups($id_lang, true);
            $groups_checked = Configuration::get('askforaquotemodul_groups');
            $groups_checked = Tools::jsonDecode($groups_checked, true);
            if (empty($groups_checked)) {
                $groups_checked = array();
            }
            $this->context->smarty->assign('groups', $groups);
            $this->context->smarty->assign('groups_checked', $groups_checked);

            $html .= $this->display(__FILE__, 'views/templates/admin/tabsettings.tpl');
        }
        $iso = $this->context->language->iso_code;
        $html .= '
            <script type="text/javascript">
                var iso = \''.(file_exists(__PS_BASE_URI__.'/js/tiny_mce/langs/' . $iso . '.js') ? $iso : 'en') . '\' ;
                var pathCSS = \'' . _THEME_CSS_DIR_ . '\' ;
                var ad = \'' . dirname($_SERVER['PHP_SELF']) . '\' ;
            </script>';
        if (file_exists(_PS_ROOT_DIR_ . '/js/tiny_mce/tiny_mce.js')) {
            $html .= '<script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/tiny_mce/tiny_mce.js"></script>';
        }
        if (file_exists(_PS_ROOT_DIR_ . '/js/tinymce.inc.js')) {
            $html .= '<script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/tinymce.inc.js"></script>';
        }
        if (file_exists(_PS_ROOT_DIR_ . '/js/admin/tinymce.inc.js')) {
            $html .= '<script type="text/javascript" src="' . __PS_BASE_URI__ . 'js/admin/tinymce.inc.js"></script>';
        }
        $html .='<script language="javascript" type="text/javascript">
            var bashippinglabel_token = "' . sha1(_COOKIE_KEY_ . 'bashippinglabel') . '";
            var id_language = Number(' . $this->context->language->id . ');
            var base_url="' . Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__ . '";
            tinySetup({
                convert_urls: false,
                relative_urls:false,
                remove_script_host:false,
                extended_valid_elements : "em[class|name|id]",
            });
            var jsshopid="' . (int)$this->context->shop->id . '";
            var jslanguageid="' . (int)$this->context->language->id . '";
            var textcombination="' . $this->l('Combination') . '";
            var textproduct="' . $this->l('Price (Excl Tax)') . '";
            var batokencus="' . Tools::getAdminTokenLite('AdminProducts') . '";
        </script>';
        $this->context->smarty->assign('url_php', Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__);
        $this->context->smarty->assign('demo_mod', $this->demoMode);
        $this->context->smarty->assign('token_askaquotemodule', md5(sha1(_COOKIE_KEY_.'askforaquotemodul')));
        $this->context->smarty->assign('iso_default_l', $iso_default_l);
        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
            $this->context->controller->addCSS($this->_path . 'views/css/style17.css');
        } else {
            $this->context->controller->addCSS($this->_path . 'views/css/style_new.css');
        }
        $html .= $this->display(__FILE__, 'views/templates/admin/jsgetcontent.tpl');
        $this->context->controller->addJS($this->_path . 'views/js/emailadminsetting.js');
        $this->context->controller->addJS($this->_path . 'views/js/languagesaveform.js');
        $this->context->controller->addJS($this->_path . 'views/js/searchajax.js');
        $this->context->controller->addJS($this->_path . 'views/js/addnewproduct.js');
        $this->context->controller->addJS($this->_path . 'views/js/savetemplates.js');
        $this->context->controller->addJS($this->_path . 'views/js/addproduct.js');
        $this->context->controller->addJS($this->_path . 'views/js/addproduct_newquote.js');
        $this->context->controller->addJS($this->_path . 'views/js/delproductstore.js');
        $this->context->controller->addJS($this->_path . 'views/js/delcsshelperlist.js');
        $this->context->controller->addJS($this->_path . 'views/js/editpriceproduct.js');
        return $html;
    }

    public function adminquote()
    {
        require_once(_PS_MODULE_DIR_.'askforaquotemodul/libs/phpmailer/vendor/autoload.php');
        require_once(_PS_MODULE_DIR_ . "askforaquotemodul/libs/mpdf/vendor/autoload.php");

        $id_currency_dbboo = $this->context->currency->id;
        $bamodule = AdminController::$currentIndex;
        $sign_currency = $this->context->currency->sign;
        $token = Tools::getAdminTokenLite('AdminModules');
        $search_1 = '';
        if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
            $this->ps_cipherTool = new PhpEncryption(_NEW_COOKIE_KEY_);
        } else {
            $this->ps_cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
        }
        $token_adm = Tools::getValue('token');
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $html = '';
        
        $email_admin_setting = Configuration::get('email_adm_setting');
        $email_from = Configuration::get('email_from_setting');
        $name_from = Configuration::get('name_from_setting');
        $shop_name = Configuration::get('PS_SHOP_NAME');
        $add_1 = Configuration::get('PS_SHOP_ADDR1');
        $add_2 = Configuration::get('PS_SHOP_ADDR2');
        $city_shop = Configuration::get('PS_SHOP_CITY');
        $state_shop =Configuration::get('PS_SHOP_STATE');
        $zip_shop = Configuration::get('PS_SHOP_CODE');
        $country_shop = Configuration::get('PS_SHOP_COUNTRY');
        $phone_shop = Configuration::get('PS_SHOP_PHONE');
        $option_order_date = Configuration::get('Option_order_date');
        $option_num_display = Configuration::get('Option_num_display');
        $format_currency = Configuration::get('format_currency');
        $this->context->smarty->assign('path', $this->_path);
        $this->context->smarty->assign('moduledir', _PS_MODULE_DIR_);
        $this->context->smarty->assign('format_currency', $format_currency);
        $this->context->smarty->assign('option_num_display', $option_num_display);
        $this->context->smarty->assign("link_img_pdf", _PS_ROOT_DIR_);
        $this->context->smarty->assign('sign_currency', $sign_currency);
        $this->context->smarty->assign("bamodul", $bamodule);
        $this->context->smarty->assign("currency_dbboo", $id_currency_dbboo);
        $this->context->smarty->assign("token_adm", $token_adm);

        $date_q_search = Tools::getValue('askforaquotemodulFilter_date_quote');
        $first_name_search = $this->context->cookie->{'askforaquotemodulFilter_first_name'};
        $last_name_search = $this->context->cookie->{'askforaquotemodulFilter_last_name'};
        $phone_number_search = $this->context->cookie->{'askforaquotemodulFilter_phone'};
        $date_search_Adm = $this->context->cookie->{'askforaquotemodulFilter_date_quote'};
        $tt_price_search = $this->context->cookie->{'askforaquotemodulFilter_total_pri'};
        $number_ur = $this->context->cookie->{'askforaquotemodulFilter_nb_mess_ud'};
        $quote_lang = $this->context->cookie->{'askforaquotemodulFilter_id_lang'};
        $search_quote = 'SELECT * FROM ' . _DB_PREFIX_ . 'product_quote_dbboo
                               WHERE first_name LIKE  "%' . pSQL($first_name_search) . '%"
                               AND last_name LIKE "%' . pSQL($last_name_search) . '%"
                               AND phone LIKE "%' . pSQL($phone_number_search) . '%"
                               AND id_currency LIKE "%' . pSQL($tt_price_search) . '%"
                               AND id_lang LIKE "%' . pSQL($quote_lang) . '%"
                               AND nb_mess_ud LIKE "%' . pSQL($number_ur) . '%"';
        if ($date_q_search[0] != '') {
            $search_quote .= 'AND date_quote >="' . pSQL($date_q_search[0].' 00:00:00') . '"';
        }if ($date_q_search[1] != '') {
            $search_quote .= 'AND date_quote <="' . pSQL($date_q_search[1].' 23:59:59') . '"';
        }
        $search_1 = $search_quote;

        if (Tools::isSubmit('submitFilter')) {
            $id_quote = Tools::getValue('askforaquotemodulFilter_id_quote');
            $first_name_search = Tools::getValue('askforaquotemodulFilter_first_name');
            $last_name_search = Tools::getValue('askforaquotemodulFilter_last_name');
            $phone_number_search = Tools::getValue('askforaquotemodulFilter_phone');
            $date_q_search = Tools::getValue('askforaquotemodulFilter_date_quote');
            $tt_price_search = Tools::getValue('askforaquotemodulFilter_total_pri');
            $language_quote = Tools::getValue('askforaquotemodulFilter_id_lang');
            $number_ur = Tools::getValue('askforaquotemodulFilter_nb_mess_ud');
            $date_search_Adm = serialize($date_q_search);
            $this->context->cookie->{'askforaquotemodulFilter_id_quote'} = $id_quote;
            $this->context->cookie->{'askforaquotemodulFilter_first_name'} = $first_name_search;
            $this->context->cookie->{'askforaquotemodulFilter_last_name'} = $last_name_search;
            $this->context->cookie->{'askforaquotemodulFilter_phone'} = $phone_number_search;
            $this->context->cookie->{'askforaquotemodulFilter_date_quote'} = $date_search_Adm;
            $this->context->cookie->{'askforaquotemodulFilter_total_pri'} = $tt_price_search;
            $this->context->cookie->{'askforaquotemodulFilter_nb_mess_ud'} = $number_ur;
            $this->context->cookie->{'askforaquotemodulFilter_id_lang'} = $language_quote;

            $search_quote = 'SELECT * FROM ' . _DB_PREFIX_ . 'product_quote_dbboo
                               WHERE first_name LIKE  "%' . pSQL($first_name_search) . '%"
                               AND id_quote LIKE  "%' . pSQL($id_quote) . '%"
                               AND last_name LIKE "%' . pSQL($last_name_search) . '%"
                               AND phone LIKE "%' . pSQL($phone_number_search) . '%"
                               AND id_currency LIKE "%' . pSQL($tt_price_search) . '%"
                               AND id_lang LIKE "%' . pSQL($language_quote) . '%"
                               AND nb_mess_ud LIKE "%' . pSQL($number_ur) . '%"';
            if ($date_q_search[0] != '') {
                $search_quote .= 'AND date_quote >="' . pSQL($date_q_search[0].' 00:00:00') . '"';
            }if ($date_q_search[1] != '') {
                $search_quote .= 'AND date_quote <="' . pSQL($date_q_search[1].' 23:59:59') . '"';
            }

            $search_1 = $search_quote;
        }
        $condi_del = Tools::getValue('deleteaskforaquotemodul');
        if ($condi_del !== false) {
            $id_quote_del = Tools::getValue('id_quote');
            $delete_q = 'DELETE FROM ' . _DB_PREFIX_ . 'product_quote_dbboo WHERE id_quote like "';
            $delete_q .= (int) $id_quote_del . '"';

            $db->query($delete_q);
            
            $delete_dq = 'DELETE FROM ' . _DB_PREFIX_ . 'product_quote_detail WHERE id_quote like "';
            $delete_dq .= (int) $id_quote_del . '"';
            
            $db->query($delete_dq);
            
            $del_db_mess = 'DELETE FROM ' . _DB_PREFIX_ . 'message_dbboo WHERE id_quote like "';
            $del_db_mess .= (int) $id_quote_del . '"';
            $db->query($del_db_mess);
            
            $del_db_cus_mess = 'DELETE FROM ' . _DB_PREFIX_ . 'cus_message_dbboo WHERE id_quote like "';
            $del_db_cus_mess .= (int) $id_quote_del . '"';
            $db->query($del_db_cus_mess);
            
            $html .= $this->initList($search_1);
        }
        $condi_view = Tools::getValue('viewaskforaquotemodul');

        if ($condi_view !== false) {
            $this->context->controller->addJS($this->_path . 'views/js/checkmess.js');
            $date_now_h_i_s = date('Y-m-d H:i:s');
            $id_default_language_adm = (int) (Configuration::get('PS_LANG_DEFAULT'));
            $id_quote_view = Tools::getValue('id_quote');
            $id_quote_format_pdf = $this->getIDQuoteformatted($id_quote_view);
            $ud_mess = 'UPDATE ' . _DB_PREFIX_ . 'message_dbboo SET status = "1" where id_quote like "';
            $ud_mess .= (int) $id_quote_view . '" and type = "0"';
            $db->query($ud_mess);

            $ud_pro_mess_cus = 'UPDATE '._DB_PREFIX_.'product_quote_dbboo SET nb_mess_ud = "0" where id_quote like "';
            $ud_pro_mess_cus .= (int) $id_quote_view . '"';
            $db->query($ud_pro_mess_cus);

            $dp_info_cus = 'Select * from ' . _DB_PREFIX_ . 'product_quote_dbboo where id_quote like "';
            $dp_info_cus .= (int) $id_quote_view . '"';
            $info_customer = $db->ExecuteS($dp_info_cus, true, false);
            $check_guest_sql = 'SELECT is_guest FROM ' . _DB_PREFIX_ . 'customer ';
            $check_guest_sql .= 'WHERE id_customer='.(int) $info_customer[0]['id_customer'];
            $check_guest = $db->getValue($check_guest_sql);
            $info_customer[0]['check_guest'] = $check_guest;
            $time_now = time();
            $check_coupon_sql = 'Select * from ' . _DB_PREFIX_ . 'cart_rule where ';
            $check_coupon_sql .= 'code="'.$info_customer[0]['coupon_code'].'"';
            $check_coupon = $db->executeS($check_coupon_sql, true, false);
            if (empty($check_coupon)) {
                $infor_coupon = '0';
            }
            if (!empty($check_coupon)) {
                if ($check_coupon[0]['active'] == '1') {
                    $time_check = strtotime($check_coupon[0]['date_to']);
                    if ($time_check > $time_now) {
                        if ($info_customer[0]['total_pri_fixed'] > $check_coupon[0]['minimum_amount']) {
                            $infor_coupon_sql = 'Select * from ' . _DB_PREFIX_ . 'coupon_quote where ';
                            $infor_coupon_sql .= 'id_quote="'.$info_customer[0]['id_quote'].'"';
                            $infor_coupon = $db->executeS($infor_coupon_sql, true, false);
                            $aaaaa = @$infor_coupon[0]['reduction_product'];
                            if ($aaaaa != 0 && $infor_coupon[0]['reduction_product'] != 1) {
                                $select = 'Select * from ' . _DB_PREFIX_ . 'product_quote_detail';
                                $select .= ' where id_quote="'.$info_customer[0]['id_quote'].'" ';
                                $select .= 'and id_product="'.$infor_coupon[0]['reduction_product'].'"';
                                $infor_pro_coupon = $db->executeS($select, true, false);
                            }
                            if (empty($infor_coupon)) {
                                $infor_coupon = '0';
                            }
                            if (empty($infor_pro_coupon)) {
                                $infor_pro_coupon = '0';
                            }
                            $this->context->smarty->assign("infor_pro_coupon", $infor_pro_coupon);
                        } else {
                            $infor_coupon = '0';
                        }
                    } else {
                        $infor_coupon = '0';
                    }
                } else {
                    $infor_coupon = '0';
                }
            }
            $this->context->smarty->assign("infor_coupon", $infor_coupon);
            $id_carrierr = array();
            $id_carrier = array();
            $sqll = 'SELECT id_carrier FROM ' . _DB_PREFIX_ . 'carrier WHERE active = "1" and deleted = "0"';
            $id_carrierr[] = $db->executeS($sqll);
            foreach ($id_carrierr as $value1) {
                $arrays = $value1;
                foreach ($arrays as $val) {
                    $id_carrier[] = $val['id_carrier'];
                }
            }
            $id_carrierrr = implode(",", $id_carrier);
            $sql_delay = 'SELECT name, id_carrier FROM ' . _DB_PREFIX_ . 'carrier WHERE ';
            $sql_delay .= 'id_carrier in ';
            $sql_delay .= '(' . $id_carrierrr . ')';
            $delay = $db->executeS($sql_delay);

            $this->context->smarty->assign("delay", $delay);
            $this->context->smarty->assign("PS_SHOP_NAME", Configuration::get('PS_SHOP_NAME'));
            $file_attached = $info_customer[0]['file_attached'];
            $total_price_quote = (float) $info_customer[0]['total_pri'];
            $total_price_quote = round($total_price_quote, 4);
            $id_currency_product_quote = (int) $info_customer[0]['id_currency'];
            $g = $info_customer[0]['shipping_cost'];
            $t = $info_customer[0]['tax_cost'];
            $notax = (float) $total_price_quote - (float) $t;
            $sign_currency_quote = (int)$info_customer[0]['id_currency'];
            $obj_currency = new Currency($sign_currency_quote);
            $info_customer[0]['sign'] = $obj_currency->sign;
            $info_customer[0]['price_full'] = Tools::displayPrice($total_price_quote, $id_currency_product_quote);
            $info_customer[0]['total_pri_notax_noformat'] = $notax;
            $info_customer[0]['price_full_noformat'] = $total_price_quote;
            $info_customer[0]['shipping_cost'] = $g;
            $info_customer[0]['tax_cost'] = $t;
            $payment_method = $this->bagetPaymentModules($info_customer[0]['id_customer']);
            
            $infor_order = 0;
            if ($info_customer[0]['id_order_create'] != 0) {
                $sql_infor_order = 'Select * from ' . _DB_PREFIX_ . 'orders where id_order like "';
                $sql_infor_order .= (int) $info_customer[0]['id_order_create'] . '"';
                $infor_order = $db->ExecuteS($sql_infor_order, true, false);
                $linkk = new link();
                $link_mid = trim(dirname($_SERVER['PHP_SELF']), '/');
                $link_midd = Tools::getServerName();
                $protocol = Tools::getShopProtocol();
                $saj = $info_customer[0]['id_order_create'];
                $last_link = $linkk->getAdminLink('AdminOrders', true).'&id_order='.$saj.'&vieworder';
                if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) { // for PrestaShop 1.7+
                    $link_order = $last_link;
                } else {
                    $link_order = $protocol.$link_midd.'/'.$link_mid.'/'.$last_link;
                }
                $this->context->smarty->assign("link_order", $link_order);
            }
            $zeroo = Tools::displayPrice(0, $id_currency_product_quote);
            $this->context->smarty->assign("zeroo", $zeroo);
            $this->context->smarty->assign("info_customer", $info_customer);
            $this->context->smarty->assign("infor_order", $infor_order);
            $this->context->smarty->assign("payment_method", $payment_method);
            $this->context->smarty->assign("g", $g);
            $this->context->smarty->assign("t", $t);
            $count_sp = 'SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'product_quote_detail where id_quote like "';
            $count_sp .= (int) $id_quote_view . '"';

            $count_product = $db->Executes($count_sp, true, false);
            
            $product_Qty_view = $count_product[0]['COUNT(*)'];
            $dp_imess = 'Select * from ' . _DB_PREFIX_ . 'message_dbboo where id_quote like "';
            $dp_imess .= (int) $id_quote_view . '"';

            $detail_mess = $db->ExecuteS($dp_imess, true, false);
            if (!empty($detail_mess)) {
                $id_lang_q = (int) $info_customer[0]['id_lang'];
                foreach ($detail_mess as &$mess) {
                    $mess['date_send_format'] = $this->displayDate($mess['date_send'], $id_lang_q);
                    $mess['date_send_format_2'] = Tools::displayDate($mess['date_send'], null, true);
                }
            }

            $this->context->smarty->assign('shop_name', $shop_name);
            $this->context->smarty->assign("add_1", $add_1);
            $this->context->smarty->assign('add_2', $add_2);
            $this->context->smarty->assign("city_shop", $city_shop);
            $this->context->smarty->assign("state_shop", $state_shop);
            $this->context->smarty->assign("zip_shop", $zip_shop);
            $this->context->smarty->assign("country_shop", $country_shop);
            $this->context->smarty->assign("phone_shop", $phone_shop);
            $this->context->smarty->assign("option_order_date", $option_order_date);
            $this->context->smarty->assign("id_quote_format_pdf", $id_quote_format_pdf);
            $this->context->smarty->assign("file_attached", $file_attached);
            $this->context->smarty->assign("count", $product_Qty_view);
            $this->context->smarty->assign("detail_mess", $detail_mess);
            if ($product_Qty_view > 0) {
                $dp_product_quote = 'Select * from ' . _DB_PREFIX_ . 'product_quote_detail where id_quote like "';
                $dp_product_quote .= (int) $id_quote_view . '"';
                $dp_product_quote .= ' ORDER BY position ASC, id_product ASC, id_combination ASC';
                $product_quote = $db->ExecuteS($dp_product_quote, true, false);
                foreach ($product_quote as $key_link => $value_link) {
                    $value_link;
                    $id_currency_quote = (int)$product_quote[$key_link]['id_currency'];
                    $obj_currency = new Currency($id_currency_quote);
                    $id_pro_quote = $product_quote[$key_link]['id_product'];
                    $adminControllers='index.php?controller=AdminProducts';
                    $batokenan='&token='.Tools::getAdminTokenLite('AdminProducts');
                    $url_id_product='&id_product='.$id_pro_quote.'&updateproduct';
                    $link_product = $adminControllers.$batokenan.$url_id_product;
                    $product_quote[$key_link]['link_product'] = $link_product;
                    $product_price = Tools::displayPrice($product_quote[$key_link]['product_pri'], $id_currency_quote);
                    $total_pr_price = Tools::displayPrice($product_quote[$key_link]['total_pri'], $id_currency_quote);
                    $product_quote[$key_link]['product_pri'] = $product_quote[$key_link]['product_pri'];
                    $product_quote[$key_link]['total_pri'] = $product_quote[$key_link]['total_pri'];
                    $product_quote[$key_link]['sign'] = $obj_currency->sign;
                    $check_pack = 'SELECT cache_is_pack FROM ' . _DB_PREFIX_ . 'product WHERE id_product =';
                    $check_pack .= '"' . $id_pro_quote . '"';
                    $checking = $db->executeS($check_pack);
                    $id_lang = $this->context->language->id;
                    $quantityy = array();
                    $name_pro_pack = array();
                    $combination = array();
                    if ($checking[0]['cache_is_pack'] == 1) {
                        $sql_select_pro_pack = 'SELECT * FROM ' . _DB_PREFIX_ . 'pack WHERE id_product_pack =';
                        $sql_select_pro_pack .= '"' . $id_pro_quote . '"';
                        $pro_pack = $db->executeS($sql_select_pro_pack);
                        foreach ($pro_pack as $key => $value) {
                            $combinationn = '';
                            $quantityy[] = $value['quantity'];
                            $attr_couple = array();
                            $sql_name = 'Select name from '._DB_PREFIX_.'product_lang';
                            $sql_name .= ' where id_product = "'.$value['id_product_item'].'"';
                            $name_pro_pack[] = $db->ExecuteS($sql_name, true, false);
                            $product = new Product($value['id_product_item'], false, $id_lang);
                            $id_product_attribute_ite = $value['id_product_attribute_item'];
                            $product_attr = $product->getAttributeCombinationsById($id_product_attribute_ite, $id_lang);
                            foreach ($product_attr as $value) {
                                $group_name_attr = $value['group_name'];
                                $attribute_name_attr = $value['attribute_name'];
                                $attr_couple[] = $group_name_attr . ": " . $attribute_name_attr;
                            }
                            $combinationn = implode(',', $attr_couple);
                            $combination[$key] = $combinationn;
                        }
                        $product_quote[$key_link]['pro_pack'] = $pro_pack;
                        $product_quote[$key_link]['name_pro_pack'] = $name_pro_pack;
                        $product_quote[$key_link]['combinationn'] = $combination;
                        $product_quote[$key_link]['quantityy'] = $quantityy;
                    } else {
                        $product_quote[$key_link]['pro_pack'] = 0;
                    }
                }
                
                $this->context->smarty->assign("product_quote", $product_quote);
            }
            $this->context->smarty->assign("id_quote_view", $id_quote_view);
            $name_country = array();
            $id_lang = $this->context->language->id;
            $select_country = 'Select * from '._DB_PREFIX_.'country_lang cl';
            $select_country .= ' INNER JOIN '._DB_PREFIX_.'country c ON cl.id_country=c.id_country ';
            $select_country .= 'where cl.id_lang = "'.$id_lang.'" AND c.active=1';
            $name_country = $db->ExecuteS($select_country, true, false);
            $this->context->smarty->assign("name_country", $name_country);
            
            if (Tools::isSubmit('btn_send')) {
                $arr_language = Language::getLanguages(false);
                $opt_email_noticequote_cus = Configuration::get('Option_email_noticequote_cus');
                $opt_email_noticequote_adm = Configuration::get('Option_email_noticequote_adm');
                $name_from = Configuration::get('name_from_setting');
                $date_now = date('Y-m-d H:i:s');
                $email_cus = $info_customer[0]['email'];
                $subject_mess = $info_customer[0]['quote_name'];
                $id_quote_dbboo_view = "id_quote=" . $id_quote_view;
                if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) {
                    $this->_cipherTool = new PhpEncryption(_NEW_COOKIE_KEY_);
                } else {
                    $this->_cipherTool = new Blowfish(_COOKIE_KEY_, _COOKIE_IV_);
                }
                $encode = $this->_cipherTool->encrypt($id_quote_dbboo_view);
                $link = new Link();
                if (Tools::version_compare(_PS_VERSION_, '1.7', '>=')) { // for PrestaShop 1.7+
                    $link_cus_rep_seo = $link->getModuleLink('askforaquotemodul', 'formrepcustomquote', array(
                        'data' => $encode,
                       ));
                } else {
                    $link_cus_rep_seo = $link->getModuleLink('askforaquotemodul', 'formrepcustom', array(
                        'data' => $encode,
                       ));
                }

                $this->context->smarty->assign("link_cus_rep", $link_cus_rep_seo);
                $link_cus_rep = $this->display(__FILE__, 'views/templates/admin/linkmessquoteadm.tpl');
                $content_mess = Tools::getvalue('message_dbboo');
                $id_format = $this->getIDQuoteformatted($id_quote_view);
                if ($content_mess != null) {
                    if ($email_from != '' && $name_from != '') {
                        foreach ($arr_language as $key => $value_lang) {
                            $value_lang;
                            $array_id_language = $arr_language[$key]['id_lang'];
                            if ($array_id_language == $id_default_language_adm) {
                                $array_language_iso_code = $arr_language[$key]['iso_code'];
                                $zero = Tools::displayPrice('0', $id_currency_product_quote);
                                $this->context->smarty->assign("zero", $zero);
                                $content_mess_noti_lang = Configuration::get('label_notice_'.$array_language_iso_code);
                                $noti_mess_adm = $this->ps_cipherTool->decrypt($content_mess_noti_lang);
                                $first_name = $info_customer[0]['first_name'];
                                $last_name = $info_customer[0]['last_name'];
                                $company_name = $info_customer[0]['company_name'];
                                $company_address = $info_customer[0]['company_address'];
                                $phone = $info_customer[0]['phone'];
                                $email = $info_customer[0]['email'];
                                $quote_name = $info_customer[0]['quote_name'];
                                $shipping_cost = $info_customer[0]['shipping_cost'];
                                $tax_cost = $info_customer[0]['tax_cost'];
                                $full_name = trim($first_name.' '.$last_name);
                                $noti_mess_adm = str_replace("[first_name]", $first_name, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[last_name]", $last_name, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[company_name]", $company_name, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[company_address]", $company_address, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[shipping_cost]", $shipping_cost, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[phone]", $phone, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[quote_name]", $quote_name, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[tax_cost]", $tax_cost, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[email]", $email, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[name]", $full_name, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[quote_id]", $id_format, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[message]", nl2br($content_mess), $noti_mess_adm);
                                $noti_mess_adm = str_replace("[messages]", nl2br($content_mess), $noti_mess_adm);
                                $noti_mess_adm = str_replace("[quote_link]", $link_cus_rep, $noti_mess_adm);
                                $noti_mess_adm = str_replace("[quote_url]", $link_cus_rep_seo, $noti_mess_adm);

                                $mail_cus = new PHPMailer\PHPMailer\PHPMailer;
                                $mail_cus->CharSet = 'UTF-8';
                                $mail_cus->Encoding = "base64";
                                $mail_cus->SetFrom($email_from, $name_from);
                                $option_button_smtp = Configuration::get('Option_button_smtp');
                                if ($option_button_smtp == '1') {
                                    $mail_cus->isSMTP();
                                    $mail_cus->Host = Configuration::get('sever_smpt');
                                    $mail_cus->SMTPAuth = true;
                                    $mail_cus->SMTPAutoTLS = false;
                                    $mail_cus->Username = Configuration::get('user_smpt');
                                    $mail_cus->Password = Configuration::get('pass_smtp');
                                    $mail_cus->SMTPSecure = Configuration::get('secure_smtp');
                                    $mail_cus->Port = Configuration::get('port_smtp');
                                }
                                if ($opt_email_noticequote_cus == 1) {
                                    $mail_cus->AddAddress($email_cus);
                                    $mail_cus->Subject = $subject_mess;
                                    $mail_cus->MsgHTML($noti_mess_adm);
                                    $mail_cus->Send();
                                }
                                $mail_adm = new PHPMailer\PHPMailer\PHPMailer;
                                $mail_adm->CharSet = 'UTF-8';
                                $mail_adm->Encoding = "base64";
                                $mail_adm->SetFrom($email_from, $name_from);
                                if ($option_button_smtp == '1') {
                                    $mail_adm->isSMTP();
                                    $mail_adm->Host = Configuration::get('sever_smpt');
                                    $mail_adm->SMTPAuth = true;
                                    $mail_adm->SMTPAutoTLS = false;
                                    $mail_adm->Username = Configuration::get('user_smpt');
                                    $mail_adm->Password = Configuration::get('pass_smtp');
                                    $mail_adm->SMTPSecure = Configuration::get('secure_smtp');
                                    $mail_adm->Port = Configuration::get('port_smtp');
                                }
                                if ($opt_email_noticequote_adm == 1) {
                                    if ($email_admin_setting != '') {
                                        $mail_adm->AddAddress($email_admin_setting);
                                        $mail_adm->Subject = $subject_mess;
                                        $mail_adm->MsgHTML($noti_mess_adm);
                                        $mail_adm->Send();
                                    }
                                }
                            }
                        }
                        $message_rep = Tools::getValue('message_dbboo');
                        $ins_mes = 'Insert into ' . _DB_PREFIX_ . '';
                        $ins_mes .= 'message_dbboo(id_quote,email,content_mes,date_send,type,status)';
                        $ins_mes .= ' values("' . (int) $id_quote_view . '","' . pSQL($email_from) . '","';
                        $ins_mes .= pSQL($message_rep) . '","' . pSQL($date_now) . '","1","0")';
                        $db->query($ins_mes);
                        $sl_mess_adm = 'Select * from ' . _DB_PREFIX_ . 'message_dbboo where id_quote like "';
                        $sl_mess_adm .= (int) $id_quote_view . '" and status like "0" and type like "1"';
                        $count_mess_adm = $db->ExecuteS($sl_mess_adm, true, false);
                        $number_unread_adm = Count($count_mess_adm);
                        $ud_pro_mess_adm = 'UPDATE ' . _DB_PREFIX_ . 'cus_message_dbboo SET so_luong_mes = "';
                        $ud_pro_mess_adm .= (int)$number_unread_adm.'" where id_quote like "'.(int)$id_quote_view.'"';
                        $db->query($ud_pro_mess_adm);
                    }
                }
                $head_link = $bamodule . '&token=' . $token . '&configure='.$this->name.'&id_quote='.$id_quote_view;
                Tools::redirectAdmin($head_link . '&viewaskforaquotemodul&data=' . $encode . '&send_success=1');
            }
            if (Tools::isSubmit('add_order')) {
                $id_quote = (int) Tools::getValue('td_id_quoteee');
                $td_id_customer = Tools::getValue('td_id_customer');
               
                $id_cart = (int) Tools::getValue('td_id_cart');
                $msg = Tools::getValue('order_message');
                $td_payment_name = Tools::getValue('td_payment_name');
                $id_state = (int) Tools::getValue('id_order_state');
                $pd = $this->findPaymentDisplayNameByID($td_payment_name, $td_id_customer);
                $module = $this->findModuleByPayment($td_payment_name);
                $payment_module = Module::getInstanceByName($module);

                $cart = new Cart($id_cart);
                $this->context->cookie->id_cart = (int)($id_cart);
                $this->context->cart = $cart;
                Context::getContext()->currency = new Currency((int)$cart->id_currency);
                Context::getContext()->customer = new Customer((int)$cart->id_customer);

                $amount = $cart->getOrderTotal(true, Cart::BOTH);
                $s = $cart->secure_key;
                $payment_module->validateOrder($cart->id, $id_state, $amount, $pd, $msg, array(), null, false, $s);
                $id_order = $payment_module->currentOrder;
                if (!empty($id_order)) {
                    $sql_update_id_order = 'UPDATE ' . _DB_PREFIX_ . 'product_quote_dbboo';
                    $sql_update_id_order .= ' SET id_order_create="'.pSQL($id_order).'"';
                    $sql_update_id_order .= ' ,id_cart_create="'.pSQL($id_cart).'"';
                    $sql_update_id_order .= ' where id_quote="'.$id_quote.'"';
                    $db->query($sql_update_id_order);

                    $head_link = $bamodule . '&token=' . $token . '&configure='.$this->name.'&id_quote='.$id_quote;
                    Tools::redirectAdmin($head_link . '&viewaskforaquotemodul&make_order_success=1');
                } else {
                    return $this->l('You do not have permission to add this.');
                }
            }
            if (Tools::isSubmit('save_quote_form')) {
                $edit_price = Tools::getValue('baproduct');
                $shipping_cost_tax = (float) Tools::getValue('shipping_cost_tax_plain');
                $id_cus = (int) $info_customer[0]['id_customer'];
                $il = (int) $info_customer[0]['id_lang'];

                $format_currency = Configuration::get('format_currency');
                $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
                foreach ($edit_price as $key => $value) {
                    if ($key !== 'total_price_quote' && $key !== 'shipping_cost' && $key !== 'tax_cost') {
                        $total_pri_pro = $edit_price[$key]['total_price_product'];
                        $edit_price[$key]['price'] = $this->toNumber($value['price']);
                        $edit_price[$key]['price'] = $this->toNumber($value['price']);
                        $total_pri_pro = $this->toNumber($total_pri_pro);
                        $edit_price[$key]['total_price_product'] = $this->toNumber($total_pri_pro);
                        $position = (int) $value['position'];

                        $id_pro_id_combi = explode("_", $key);
                        $id_pro1 = $id_pro_id_combi[0];
                        $id_combination1 = $id_pro_id_combi[1];
                        // since 1.0.39+, update product with Tax
                        $unit_price = $edit_price[$key]['price'];
                        $pq = (int) $edit_price[$key]['quantity'];
                        $unitprice_incl_tax = (float) $this->getProductPriceTax($unit_price, $id_pro1, $id_cus, $il);
                        $totalprice_incl_tax = (float) $unitprice_incl_tax * $pq;
                        $id_tax_rules_group = (int) $this->getIdTaxRulesGroupByIdProduct($id_pro1);
                        
                        $ud_quote_detail = 'UPDATE ' . _DB_PREFIX_ . 'product_quote_detail SET product_pri = "';
                        $ud_quote_detail .= $this->toNumber($edit_price[$key]['price']) . '", product_qty = "';
                        $ud_quote_detail .= (int)$edit_price[$key]['quantity'].'", total_pri = "';
                        $ud_quote_detail .= $this->toNumber($edit_price[$key]['total_price_product']).'" ';
                        $ud_quote_detail .= ',product_pri_incl_tax = '.$unitprice_incl_tax;
                        $ud_quote_detail .= ',id_tax_rules_group = '.$id_tax_rules_group;
                        $ud_quote_detail .= ',total_pri_incl_tax = '.$totalprice_incl_tax;
                        $ud_quote_detail .= ',position = '.$position;
                
                        $ud_quote_detail .= ' WHERE id_combination like "' . (int) $id_combination1 . '" ';
                        $ud_quote_detail .= ' and id_product like "'.(int)$id_pro1.'"';
                        $ud_quote_detail .= ' and id_quote like "'.(int)$id_quote_view.'"';
                        $db->query($ud_quote_detail);
                    }
                }

                $shipping_cost = str_replace(",", "", $edit_price['shipping_cost']);
                $tax_cost = str_replace(",", "", $edit_price['tax_cost']);
                
                $ud_pro_mess_cus = 'UPDATE '._DB_PREFIX_.'product_quote_dbboo SET total_pri = "';
                $ud_pro_mess_cus .= pSQL($edit_price['total_price_quote']).'", shipping_cost = "';
                $ud_pro_mess_cus .= pSQL($shipping_cost).'", tax_cost = "';
                $ud_pro_mess_cus .= pSQL($tax_cost).'"';
                $ud_pro_mess_cus .= ',shipping_cost_tax='.$shipping_cost_tax;
                $ud_pro_mess_cus .= ' where id_quote like "' . (int) $id_quote_view . '"';
                $db->query($ud_pro_mess_cus);

                $head_link = $bamodule . '&token=' . $token . '&configure='.$this->name.'&id_quote='.$id_quote_view;
                Tools::redirectAdmin($head_link . '&viewaskforaquotemodul&save_success=1');
            }
            if (Tools::isSubmit('mail_quote_form')) {
                $option_button_pdf = Configuration::get('Option_button_pdf');
                $option_button_smtp = Configuration::get('Option_button_smtp');
                $id_lang_quote = $info_customer[0]['id_lang'];
                $translations = $this->translateEmail($id_lang_quote);
                $this->context->smarty->assign("translations", $translations);
                $language = new Language($id_lang_quote);
                $iso_code = $language->iso_code;
                $arr_language = Language::getLanguages(false);
                $name_from = Configuration::get('name_from_setting');
                $date_now = date('Y-m-d H:i:s');
                $email_cus = $info_customer[0]['email'];
                $subject_mess = $info_customer[0]['quote_name'];
                $date_quote_create = $info_customer[0]['date_quote'];
                $date_quote_create = $this->displayDate($date_quote_create);
                $source_check = md5($id_quote_view.$date_now);
                $link = new Link();
                $link_cus_rep_seo = $link->getModuleLink('askforaquotemodul', 'myquotedetail', array(
                    'id_quote' => $id_quote_view,
                    'soucrce' => $source_check,
                   ));
                $sql_up_checkexist = 'SELECT * FROM '._DB_PREFIX_.'product_quote_dbboo WHERE';
                $sql_up_checkexist .= ' id_quote = "'.$id_quote_view.'"';
                $checkee = $db->ExecuteS($sql_up_checkexist, true, false);
                foreach ($checkee as $key => $value) {
                    foreach ($value as $key1 => $value1) {
                        if ($key1 == 'source_check') {
                            $checkexist = '1';
                            break;
                        } else {
                            $checkexist = '0';
                        }
                    }
                }
                if ($checkexist == '0') {
                    $sql_up_aaaheck = 'ALTER TABLE `'._DB_PREFIX_.'product_quote_dbboo`';
                    $sql_up_aaaheck .= 'ADD `source_check` VARCHAR(255) NULL AFTER `coupon_code`';
                    $db->query($sql_up_aaaheck);
                }
                $sql_up_sourcecheck = 'UPDATE '._DB_PREFIX_.'product_quote_dbboo SET source_check =';
                $sql_up_sourcecheck .= '"'.$source_check.'" where id_quote like "';
                $sql_up_sourcecheck .= (int) $id_quote_view . '"';
                $db->query($sql_up_sourcecheck);
                $this->context->smarty->assign("link_cus_rep", $link_cus_rep_seo);
                $this->context->smarty->assign("shipping_cost", $info_customer[0]['shipping_cost']);
                $this->context->smarty->assign("tax_cost", $info_customer[0]['tax_cost']);
                $zero = Tools::displayPrice('0', $id_currency_product_quote);
                $this->context->smarty->assign("zero", $zero);
                $this->context->smarty->assign("infor_coupon", $infor_coupon);
                $this->context->smarty->assign("infor_pro_coupon", $infor_pro_coupon);
                $link_cus_rep = $this->display(__FILE__, 'views/templates/admin/linkmessquoteadm.tpl');
                $product_table = $this->display(__FILE__, 'views/templates/admin/viewtableproduct.tpl');
                $id_format = $this->getIDQuoteformatted($id_quote_view);
                if ($email_from != '' && $name_from != '') {
                    foreach ($arr_language as $key => $value_lang) {
                        $value_lang;
                        $array_language_iso_code = $iso_code;
                        $content_mess_price_lang = Configuration::get('label_price_'.$array_language_iso_code);
                        $price_mess_adm = $this->ps_cipherTool->decrypt($content_mess_price_lang);
                        $first_name = $info_customer[0]['first_name'];
                        $last_name = $info_customer[0]['last_name'];
                        $company_name = $info_customer[0]['company_name'];
                        $company_address = $info_customer[0]['company_address'];
                        $shipping_cost = $info_customer[0]['shipping_cost'];
                        $price_mess_adm = str_replace("[first_name]", $first_name, $price_mess_adm);
                        $price_mess_adm = str_replace("[last_name]", $last_name, $price_mess_adm);
                        $price_mess_adm = str_replace("[shipping_cost]", $shipping_cost, $price_mess_adm);
                        $price_mess_adm = str_replace("[company_name]", $company_name, $price_mess_adm);
                        $price_mess_adm = str_replace("[company_address]", $company_address, $price_mess_adm);
                        $price_mess_adm = str_replace("[tax_cost]", $info_customer[0]['tax_cost'], $price_mess_adm);
                        $price_mess_adm = str_replace("[quote_id]", $id_format, $price_mess_adm);
                        $price_mess_adm = str_replace("[quote_ID]", $id_format, $price_mess_adm);
                        $price_mess_adm = str_replace("[email]", $email_cus, $price_mess_adm);
                        $price_mess_adm = str_replace("[phone]", $info_customer[0]['phone'], $price_mess_adm);
                        $price_mess_adm = str_replace("[date]", $date_quote_create, $price_mess_adm);
                        $price_mess_adm = str_replace("[product_table]", $product_table, $price_mess_adm);
                        $price_mess_adm = str_replace("[quote_link]", $link_cus_rep, $price_mess_adm);
                        $price_mess_adm = str_replace("[quote_url]", $link_cus_rep_seo, $price_mess_adm);
                        $mail_cus = new PHPMailer\PHPMailer\PHPMailer;
                        if ($option_button_smtp == '1') {
                            $mail_cus->isSMTP();
                            $mail_cus->Host = Configuration::get('sever_smpt');
                            $mail_cus->SMTPAuth = true;
                            $mail_cus->SMTPAutoTLS = false;
                            $mail_cus->Port = Configuration::get('port_smtp');
                            $mail_cus->Username = Configuration::get('user_smpt');
                            $mail_cus->Password = Configuration::get('pass_smtp');
                            $mail_cus->SMTPSecure = Configuration::get('secure_smtp');
                        }
                        $mail_cus->CharSet = 'UTF-8';
                        $mail_cus->Encoding = "base64";
                        if ($option_button_pdf == '1') {
                            $attach_pdf = $this->genpdf($info_customer, $id_quote_view);
                            $mail_cus->addAttachment($attach_pdf);
                        }
                        $mail_cus->SetFrom($email_from, $name_from);
                        $mail_cus->AddAddress($email_cus);
                        $mail_cus->Subject = $subject_mess;
                        $mail_cus->MsgHTML($price_mess_adm);
                    }
                    $mail_cus->Send();
                }
                $head_link = $bamodule . '&token=' . $token . '&configure='.$this->name.'&id_quote='.$id_quote_view;
                Tools::redirectAdmin($head_link . '&viewaskforaquotemodul&data=' . $encode . '&send_success=1');
            }

            if (Tools::isSubmit('file_pdf_name')) {
                $id_lang_quote = $info_customer[0]['id_lang'];
                $id_currency_q = (int) $info_customer[0]['id_currency'];
                $translations = $this->translateEmail($id_lang_quote);
                $this->context->smarty->assign("translations", $translations);
                $language = new Language($id_lang_quote);
                $iso_code = $language->iso_code;
                $arr_language = Language::getLanguages(false);
                $date_format_lang = $this->displayDate($date_now_h_i_s, $id_lang_quote);
                $quote_date = $this->displayDate($info_customer[0]['date_quote'], $id_lang_quote);
                $ship_cost = $info_customer[0]['shipping_cost'];
                $ship_cost = Tools::displayPrice($ship_cost, $id_currency_q);
                $tax_c = $info_customer[0]['tax_cost'];
                $tax_c = Tools::displayPrice($tax_c, $id_currency_q);
                $this->context->smarty->assign("infor_coupon", $infor_coupon);
                $this->context->smarty->assign("id_currency_q", $id_currency_q);
                $this->context->smarty->assign("infor_pro_coupon", $infor_pro_coupon);
                $this->context->smarty->assign("shipping_cost", $ship_cost);
                $this->context->smarty->assign("tax_cost", $tax_c);
                $this->context->smarty->assign("shipping_cost_check", $g);
                $this->context->smarty->assign("tax_cost_check", $t);
                $zero = Tools::displayPrice('0', $id_currency_product_quote);
                $this->context->smarty->assign("zero", $zero);
                $tb_product_pdf = $this->display(__FILE__, 'views/templates/admin/tbproductpdf.tpl');

                $subtotalpdf = $this->display(__FILE__, 'views/templates/admin/subtotalpdf.tpl');
                $messagespdf = $this->display(__FILE__, 'views/templates/admin/messagespdf.tpl');
                $this->context->smarty->assign("date_format_lang", $date_format_lang);
                $array_language_iso_code = $iso_code;
                $content_pdf_lang = Configuration::get('label_pdf_'.$array_language_iso_code);
                $pdf_adm = $this->ps_cipherTool->decrypt($content_pdf_lang);
                $pdf_adm = str_replace("[shop_name]", $shop_name, $pdf_adm);
                $pdf_adm = str_replace("[quote_ID]", $id_quote_format_pdf, $pdf_adm);
                $pdf_adm = str_replace("[quote_id]", $id_quote_format_pdf, $pdf_adm);
                $pdf_adm = str_replace("[quote_date]", $quote_date, $pdf_adm);
                $pdf_adm = str_replace("[shop_add1]", $add_1, $pdf_adm);
                $pdf_adm = str_replace("[shop_add2]", $add_2, $pdf_adm);
                $pdf_adm = str_replace("[shop_city]", $city_shop, $pdf_adm);
                $pdf_adm = str_replace("[shop_state]", $state_shop, $pdf_adm);
                $pdf_adm = str_replace("[shop_zip]", $zip_shop, $pdf_adm);
                $pdf_adm = str_replace("[shop_country]", $country_shop, $pdf_adm);
                $pdf_adm = str_replace("[shop_phone]", $phone_shop, $pdf_adm);
                $pdf_adm = str_replace("[first_name]", $info_customer[0]['first_name'], $pdf_adm);
                $pdf_adm = str_replace("[last_name]", $info_customer[0]['last_name'], $pdf_adm);
                $pdf_adm = str_replace("[company_name]", $info_customer[0]['company_name'], $pdf_adm);
                $pdf_adm = str_replace("[company_address]", $info_customer[0]['company_address'], $pdf_adm);
                $pdf_adm = str_replace("[shipping_cost]", $info_customer[0]['shipping_cost'], $pdf_adm);
                $pdf_adm = str_replace("[tax_cost]", $info_customer[0]['tax_cost'], $pdf_adm);
                $pdf_adm = str_replace("[phone]", $info_customer[0]['phone'], $pdf_adm);
                $pdf_adm = str_replace("[email]", $info_customer[0]['email'], $pdf_adm);
                $pdf_adm = str_replace("[product_table]", $tb_product_pdf, $pdf_adm);
                $pdf_adm = str_replace("[messages]", $messagespdf, $pdf_adm);
                $pdf_adm = str_replace("[subtotal]", $subtotalpdf, $pdf_adm);
                $pdf_adm = str_replace("[order_date]", $option_order_date, $pdf_adm);
                $pdf_adm = str_replace("[gen_pdf_date]", $date_format_lang, $pdf_adm);
                $pdf_adm = $this->stripBreakLinePDF($pdf_adm);

                $config = array();
                $mpdf = new \Mpdf\Mpdf($config);
                $pdf_quote = $pdf_adm;
                $mpdf->AddPage();
                $mpdf->WriteHTML($pdf_quote);
                $file = $this->getPDFFileName($id_quote_view);
                $mpdf->Output($file, 'D');
            }
            $export = Tools::getValue('export');
            if ($export == 1) {
                $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
                $list_product_quote = 'Select id_currency,link_img,product_name,reference,combination,';
                $list_product_quote .= 'product_pri,product_qty';
                $list_product_quote.= ',total_pri from ' . _DB_PREFIX_ . 'product_quote_detail where id_quote like "';
                $list_product_quote .= (int) $id_quote_view . '"';
                $list_product_quote .= 'ORDER BY position ASC, id_product ASC, id_combination ASC';
                $list_product = $db->ExecuteS($list_product_quote, true, false);
                foreach ($list_product as $key_list => $value_list) {
                    $value_list;
                    $id_currency_quote_e = (int)$list_product[$key_list]['id_currency'];
                    $obj_currency = new Currency($id_currency_quote);
                    $product_price = Tools::displayPrice($list_product[$key_list]['product_pri'], $id_currency_quote_e);
                    $total_pr_price = Tools::displayPrice($list_product[$key_list]['total_pri'], $id_currency_quote_e);
                    $list_product[$key_list]['product_pri'] = $product_price;
                    $list_product[$key_list]['total_pri'] = $total_pr_price;
                    unset($list_product[$key_list]['id_currency']);
                }
                $columns_product_quote_detail = 'select COLUMN_NAME from Information_schema.columns where ';
                $columns_product_quote_detail .= 'TABLE_NAME like "' . _DB_PREFIX_ . 'product_quote_detail"';
                $colums_name = $db->ExecuteS($columns_product_quote_detail, true, false);
                $list_colum = array();
                $total = array();
                $list_product_key = array_keys($list_product[0]);
                for ($i = 1; $i < count($list_product_key); $i++) {
                    $total[$i] = '';
                }
                $total_price_quote_decima = (float) $total_price_quote;
                $id_cr_quote = (int) $id_currency_product_quote ;
                $total_price_quote_dp = Tools::displayPrice($total_price_quote_decima, $id_cr_quote);
                $total['total_price_quote'] = $total_price_quote_dp;
                $list_product[] = $total;
                foreach ($colums_name as $key_col => $value_col) {
                    $value_col;
                    foreach ($list_product_key as $key => $value) {
                        $value;
                        if ($colums_name[$key_col]['COLUMN_NAME'] == $list_product_key[$key]) {
                            $list_colum[] = $colums_name[$key_col]['COLUMN_NAME'];
                        }
                    }
                }
                $list_colum = str_replace("link_img", "Images", $list_colum);
                $list_colum = str_replace("product_name", "Product Name", $list_colum);
                $list_colum = str_replace("reference", "Product Reference", $list_colum);
                $list_colum = str_replace("combination", "Combination", $list_colum);
                $list_colum = str_replace("product_pri", "Price", $list_colum);
                $list_colum = str_replace("product_qty", "Quantity", $list_colum);
                $list_colum = str_replace("total_pri", "Total Price", $list_colum);
                
                header('Content-type: text/csv');
                header('Content-Disposition: attachment;filename="ExportProduct ' . date('Y-m-d H:i') . '.csv"');
                header('Pragma: no-cache');
                header('Expires: 0');
                $file = fopen('php://output', 'w');

                fputcsv($file, $list_colum);

                foreach ($list_product as $row) {
                    fputcsv($file, $row);
                }
                exit();
            }
            
            if (Tools::isSubmit('file_attached_name')) {
                $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
                $attach_file = 'Select file_attached from ' . _DB_PREFIX_ . 'product_quote_dbboo where id_quote like "';
                $attach_file .= (int) $id_quote_view . '"';
                $file_attached = $db->ExecuteS($attach_file, true, false);
                $file = $file_attached[0]['file_attached'];
                $this->installFile($file);
            }
            
            $head_link_exp = $bamodule . '&token=' . $token . '&configure='.$this->name.'&id_quote='.$id_quote_view;
            $head_link_exp .= '&viewaskforaquotemodul&export=1';
            $order_state = OrderState::getOrderStates($id_lang);
            $tran_alert_order = $this->l('This quote has been made into a order');
            $html = '';
            
            if ($infor_order[0]['id_order'] != 0) {
                $html .= '<script>var check_order = '.$infor_order[0]['id_order'].'</script>';
                $html .= '<script>var tran_alert_order = "'.$tran_alert_order.'"</script>';
            } else {
                $html .= '<script>var check_order = 0</script>';
            }
            if ($info_customer[0]['id_cart_create'] != 0) {
                $html .= '<script>var id_cart = '.$info_customer[0]['id_cart_create'].'</script>';
            } else {
                $html .= '<script>var id_cart = 0</script>';
            }
            $ship_tax_rate = 0;
            if ($info_customer[0]['shipping_cost'] > 0) {
                $ship_tax_rate = (float) $info_customer[0]['shipping_cost_tax'] / $info_customer[0]['shipping_cost'];
            }
            $this->context->smarty->assign("order_state", $order_state);
            $this->context->smarty->assign("link_export", $head_link_exp);
            $this->context->smarty->assign("shipping_cost", $info_customer[0]['shipping_cost']);
            $this->context->smarty->assign("shipping_cost_tax_rate", $ship_tax_rate);
            $this->context->smarty->assign("tax_cost", $info_customer[0]['tax_cost']);
            $id_carrierrrr = Configuration::get('td_id_carrier');
            $this->context->smarty->assign("id_carrier", (int)$id_carrierrrr);
            $html .= '<script>var selectstate="' . $this->l('Select State') . '"</script>';
            $html .= $this->display(__FILE__, 'views/templates/admin/view.tpl');
        }
        if ($condi_del === false && $condi_view === false) {
            $html .= $this->initList($search_1);
        }
        if (Tools::isSubmit('submitResetaskforaquotemodul')) {
            unset($this->context->cookie->{'askforaquotemodulFilter_id_quote'});
            unset($this->context->cookie->{'askforaquotemodulFilter_first_name'});
            unset($this->context->cookie->{'askforaquotemodulFilter_last_name'});
            unset($this->context->cookie->{'askforaquotemodulFilter_phone'});
            unset($this->context->cookie->{'askforaquotemodulFilter_date_quote'});
            unset($this->context->cookie->{'askforaquotemodulFilter_total_pri'});
            unset($this->context->cookie->{'askforaquotemodulFilter_nb_mess_ud'});
            unset($this->context->cookie->{'askforaquotemodulFilter_id_lang'});
            $this->context->cookie->{'order_by'} = 'date_quote';
            $this->context->cookie->{'order_way'} = 'desc';
            Tools::redirectAdmin($bamodule . '&token=' . $token . '&configure=' . $this->name . '');
        }
        $this->context->smarty->assign("token_dbboo", $token_adm);
        $this->context->smarty->assign("sign_currency", $sign_currency);
        $this->context->smarty->assign("email_admin_setting", $email_admin_setting);
        $this->context->smarty->assign("email_from", $email_from);
        $this->context->smarty->assign("name_from", $name_from);
        $this->context->smarty->assign("url_php", Tools::getShopProtocol() . Tools::getServerName() . __PS_BASE_URI__);
        $this->context->smarty->assign("demo_mod", $this->demoMode);
        $this->context->smarty->assign("token_askaquotemodule", md5(sha1(_COOKIE_KEY_.'askforaquotemodul')));
        $html .= $this->display(__FILE__, 'views/templates/admin/jsadminquote.tpl');
        $this->context->controller->addJS($this->_path . 'views/js/delmes.js');
        $this->context->controller->addJS($this->_path . 'views/js/dateFormat.js');
        $this->context->controller->addJS($this->_path . 'views/js/jquery.dateFormat.js');
        $html .= '<script language="javascript" type="text/javascript">
                var productttt="' . $this->l('Product:') . '";
                var cheapest_product="' . $this->l('Cheapest Product') . '";
                var free_shipping="' . $this->l('Free shipping') . '";
                var error_js="' . $this->l('Invalid coupon code') . '";
                var enter_coupon="' . $this->l('Please enter your coupon') . '";
            </script>';


        return $html;
    }
    public function displayDate($date, $id_lang = null)
    {
        if (!$date || !($time = strtotime($date))) {
            return $date;
        }
        if ($date == '0000-00-00 00:00:00' || $date == '0000-00-00') {
            return '';
        }

        if (!Validate::isDate($date)) {
            return $date;
        }
        if ($id_lang == null) {
            $id_lang = $this->context->language->id;
        }
        $context = Context::getContext();
        $lang = empty($id_lang) ? $context->language : new Language($id_lang);
        $date_format = $lang->date_format_full;
        return date($date_format, $time);
    }
    
    public function installFile($file)
    {
        if (file_exists($file)) {
            header('Content-Description: File Transfer');
            header('Content-Type: application/octet-stream');
            header('Content-Disposition: attachment; filename="'.basename($file).'"');
            header('Expires: 0');
            header('Cache-Control: must-revalidate');
            header('Pragma: public');
            header('Content-Length: ' . filesize($file));
            readfile($file);
            exit;
        }
    }

    public function initList($search_1)
    {
        $helper = new HelperList();
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $name_currency = 'SELECT * FROM ' . _DB_PREFIX_ . 'currency';
        $name_cur = $db->executeS($name_currency, true, false);
        $name_language = 'SELECT * FROM ' . _DB_PREFIX_ . 'lang';
        $language = $db->executeS($name_language, true, false);
        $lang = array();
        
        foreach ($language as $key_l => $value_l) {
            $value_l;
            $lang[$language[$key_l]['id_lang']] = $this->l(''.$language[$key_l]['name'].'');
        }
        
        $name_lang = array();
        
        foreach ($name_cur as $key => $value) {
            $value;
            $name_lang[$name_cur[$key]['id_currency']] = $this->l(''.$name_cur[$key]['name'].'');
        }
        $helper->shopLinkType = '';
        $helper->simple_header = false;
        $helper->actions = array('view', 'delete');

        $helper->toolbar_btn['new'] = array(
            'href' => AdminController::$currentIndex . '&configure=' . $this->name . '&add'
            . $this->name . '&token=' . Tools::getAdminTokenLite('AdminModules'),
            'desc' => $this->l('Add new')
        );

        $helper->identifier = 'id_quote'; // t?o kh?a
        
        $helper->show_toolbar = true;
        $helper->title = 'Quote';
        $helper->table = $this->name;
        $helper->list_id = $this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name . '';
        $fields_list = array(
            'id_quote' => array(
                'title' => $this->l('#ID'),
                'width' => 50,
                'type' => 'text'
            ),
            'first_name' => array(
                'title' => $this->l('First Name'),
                'width' => 135,
                'type' => 'text'
            ),
            'last_name' => array(
                'title' => $this->l('Last Name'),
                'width' => 135,
                'type' => 'text'
            ),
            'phone' => array(
                'title' => $this->l('Phone'),
                'width' => 135,
                'type' => 'text'
            ),
            'date_quote' => array(
                'title' => $this->l('Date'),
                'width' => 140,
                'type' => 'datetime'
            ),
            'total_pri' => array(
                'title' => $this->l('Total price'),
                'width' => 100,
                'type' => 'select',
                'list' => $name_lang,
                'filter_key' => 'total_pri',
                'callback' => 'setOrderCurrency',
                'callback_object' => $this
            ),
            'nb_mess_ud' => array(
                'title' => $this->l('UnRead'),
                'width' => 50,
                'type' => 'int'
            ),
            'id_lang' => array(
                'title' => $this->l('Language'),
                'width' => 100,
                'type' => 'select',
                'list' => $lang,
                'filter_key' => 'id_lang',
                'callback' => 'getNameByIDLang',
                'callback_object' => $this
            ),
            'id_order_create' => array(
                'title' => $this->l('ID Order'),
                'width' => 50,
                'type' => 'int',
                'remove_onclick' => true,
                'callback' => 'getidorder',
                'callback_object' => $this
            )
        );
        $this->orderby = pSQL(Tools::getValue($helper->list_id . "Orderby", $this->context->cookie->{'order_by'}));
        $this->orderway = pSQL(Tools::getValue($helper->list_id . "Orderway", $this->context->cookie->{'order_way'}));

        $helper->orderBy = $this->orderby;
        $helper->orderWay = Tools::strtoupper($this->orderway);
        $helper->listTotal = $this->getTotalList($helper, $search_1);
        $html = $helper->generateList($this->getListContent($helper, $search_1), $fields_list);
        return $html;
    }
    public function setOrderCurrency($value, $currency)
    {
        $value;
        $total_price = Tools::displayPrice((float) $currency['total_pri'], (int)$currency['id_currency']);
        return $total_price;
    }
    public function getNameByIDLang($value)
    {
        $name_language = '';
        $array_language = Language::getLanguages(false);
        foreach ($array_language as $key => $value_l) {
            $value_l;
            if ($value == $array_language[$key]['id_lang']) {
                $name_language = $array_language[$key]['name'];
            }
        }
        return $name_language;
    }
    public function getidorder($value)
    {
        $link_order = '#';
        if ($value == 0) {
            $value = '--';
        } else {
            $adminControllers='index.php?controller=AdminOrders';
            $batokenan='&token='.Tools::getAdminTokenLite('AdminOrders');
            $url_id_order='&id_order='.$value.'&vieworder';
            $link_order = $adminControllers.$batokenan.$url_id_order;
        }
        $this->context->smarty->assign('link_order', $link_order);
        $this->context->smarty->assign('value', $value);
        $linkorder = "askforaquotemodul/views/templates/admin/linkorder.tpl";
        return $this->context->smarty->fetch(_PS_MODULE_DIR_ . $linkorder);
    }

    public function getListContent($helper, $search_1)
    {
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        if ($this->context->cookie->{$helper->list_id . '_pagination'} == 10) {
            $this->context->cookie->{$helper->list_id . '_pagination'} = 20;
        }
        $pagi = $this->context->cookie->{$helper->list_id . '_pagination'};
        $selected_pagination = (int) Tools::getValue($helper->list_id . '_pagination', $pagi);
        if ($selected_pagination <= 0) {
            $selected_pagination = 20;
        }

        $this->context->cookie->{$helper->list_id . '_pagination'} = $selected_pagination;
        $page = (int) Tools::getValue('submitFilter' . $helper->list_id);
        if (!$page) {
            $page = 1;
        }
        $start = ($page - 1 ) * $selected_pagination;
        $orderby = pSQL(Tools::getValue($helper->list_id . "Orderby"));
        $orderway = pSQL(Tools::getValue($helper->list_id . "Orderway"));

        $order_by_cookie = $this->context->cookie->{'order_by'};
        $order_way_cookie = $this->context->cookie->{'order_way'};
        if ($orderby == '' || $orderway == '') {
            if ($order_by_cookie == false || $order_way_cookie == false) {
                $order_by_cookie = 'date_quote';
                $order_way_cookie = 'desc';
            }
            $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'product_quote_dbboo';
            $sql .= ' ORDER BY ' . pSQL($order_by_cookie) . ' ' . pSQL($order_way_cookie) . ' LIMIT ';
            $sql .= (int) $start . ',' . (int) $selected_pagination;
            $rows = $db->ExecuteS($sql, true, false);
        } else {
            $this->context->cookie->{'order_by'} = $orderby;
            $this->context->cookie->{'order_way'} = $orderway;
            $sql = 'SELECT * FROM ' . _DB_PREFIX_ . 'product_quote_dbboo';
            $sql .= ' ORDER BY ' . pSQL($orderby) . ' ' . pSQL($orderway) . ' LIMIT ';
            $sql .= (int) $start . ',' . (int) $selected_pagination;
            $rows = $db->ExecuteS($sql, true, false);
        }
        if ($search_1 != null) {
            if ($orderby == '' || $orderway == '') {
                if ($order_by_cookie == false || $order_way_cookie == false) {
                    $order_by_cookie = 'date_quote';
                    $order_way_cookie = 'desc';
                }
                $search_1 = $search_1 . ' ORDER BY ' . pSQL($order_by_cookie) . ' ' . pSQL($order_way_cookie) . '';
                $search_1 .= ' LIMIT ' . (int) $start . ',' . (int) $selected_pagination;
                $rows = $db->ExecuteS($search_1, true, false);
            } else {
                $search_1 = $search_1 . ' ORDER BY ' . pSQL($orderby) . ' ' . pSQL($orderway) . ' LIMIT ';
                $search_1.= (int) $start . ',' . (int) $selected_pagination;
                $rows = $db->ExecuteS($search_1, true, false);
            }
        }
        return $rows;
    }

    private function getTotalList($helper, $search_1)
    {
        $db = Db::getInstance(_PS_USE_SQL_SLAVE_);
        $rows = $db->ExecuteS($search_1, true, false);
        $count_quote = Count($rows);
        $orderby = pSQL(Tools::getValue($helper->list_id . "Orderby"));
        $orderway = pSQL(Tools::getValue($helper->list_id . "Orderway"));

        if ($orderby == '' || $orderway == '') {
            $sql = 'SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'product_quote_dbboo';
        } else {
            $sql = 'SELECT COUNT(*) FROM ' . _DB_PREFIX_ . 'product_quote_dbboo';
            $sql .= 'ORDER BY ' . pSQL($orderby) . ' ' . pSQL($orderway);
        }
        return $count_quote;
    }
    public function enableQuoteButtons()
    {
        $controller = Tools::strtolower(Tools::getValue('controller'));
        if ($controller !='category' && $controller!='product') {
            return false;
        }
        return true;
    }
    public function toNumber($str)
    {
        return (float) preg_replace("/([^0-9\\.])/i", "", $str);
    }
    public function getFormatCurrency($c_format)
    {
        $c_format = str_replace('¤', 'X', $c_format);
        $c_format = str_replace('#', '0', $c_format);
        switch ($c_format) {
            case '0 000,00X':
                return 2;
            case 'X0.000,00':
                return 3;
            case '0,000.00X':
                return 4;
            case "0'000.00X":
                return 5;
            default:
                return 1;
        }
    }
    public function translateEmail($id_lang)
    {
        $translations = array(
            'Image' => $this->l('Image'),
            'Product Name' => $this->l('Product Name'),
            'Unit Price' => $this->l('Unit Price'),
            'Qty' => $this->l('Qty'),
            'Total' => $this->l('Total'),
            'Total excl Tax' => $this->l('Total excl Tax'),
            'Total incl Tax' => $this->l('Total incl Tax'),
            'SKU' => $this->l('SKU'),
            'Unsubscribe' => $this->l('Unsubscribe'),
            'Resume your order' => $this->l('Resume your order'),
        );
        $_MODULES = array();
        $_MODULE = array();
        $name = $this->name;
        $source = $this->name;
        $language = new Language($id_lang);
        $iso_code = $language->iso_code;
        $filesByPriority = array(
            // Translations in theme
            _PS_THEME_DIR_.'modules/'.$name.'/translations/'.$iso_code.'.php',
            _PS_THEME_DIR_.'modules/'.$name.'/'.$iso_code.'.php',
            // PrestaShop 1.5 translations
            _PS_MODULE_DIR_.$name.'/translations/'.$iso_code.'.php',
            // PrestaShop 1.4 translations
            _PS_MODULE_DIR_.$name.'/'.$iso_code.'.php'
        );
        foreach ($filesByPriority as $file) {
            if (file_exists($file)) {
                include($file);
                $_MODULES = !empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE;
            }
        }
        foreach ($translations as $string => & $value) {
            $value;
            $value = str_replace('"', '&quot;', $string);
            $key = md5(str_replace('\'', '\\\'', $string));
            $current_key = Tools::strtolower('<{'.$name.'}'._THEME_NAME_.'>'.$source).'_'.$key;
            $default_key = Tools::strtolower('<{'.$name.'}prestashop>'.$source).'_'.$key;
            
            if (isset($_MODULES[$current_key])) {
                $value = Tools::stripslashes($_MODULES[$current_key]);
            } elseif (isset($_MODULES[$default_key])) {
                $value = Tools::stripslashes($_MODULES[$default_key]);
            }
        }
        return $translations;
    }
    public function genpdf($info_customer, $id_quote_view)
    {
        $id_lang_quote = $info_customer[0]['id_lang'];
        $translations = $this->translateEmail($id_lang_quote);
        $option_order_date = Configuration::get('order_date');
        if ($option_order_date == null) {
            $option_order_date = 30;
        }
        $shop_name = Configuration::get('PS_SHOP_NAME');
        $add_1 = Configuration::get('PS_SHOP_ADDR1');
        $add_2 = Configuration::get('PS_SHOP_ADDR2');
        $city_shop = Configuration::get('PS_SHOP_CITY');
        $state_shop =Configuration::get('PS_SHOP_STATE');
        $zip_shop = Configuration::get('PS_SHOP_CODE');
        $country_shop = Configuration::get('PS_SHOP_COUNTRY');
        $phone_shop = Configuration::get('PS_SHOP_PHONE');
        $this->context->smarty->assign("translations", $translations);
        $language = new Language($id_lang_quote);
        $iso_code = $language->iso_code;
        $id_currency_product_quote = (int) $info_customer[0]['id_currency'];
        $date_now_h_i_s = date('Y-m-d H:i:s');
        $date_format_lang = $this->displayDate($date_now_h_i_s, $id_lang_quote);
        $quote_date = $this->displayDate($info_customer[0]['date_quote'], $id_lang_quote);
        $ship_cost = $info_customer[0]['shipping_cost'];
        $ship_cost = Tools::displayPrice($ship_cost, $id_currency_product_quote);
        $tax_c = $info_customer[0]['tax_cost'];
        $tax_c = Tools::displayPrice($tax_c, $id_currency_product_quote);
                
        $this->context->smarty->assign("shipping_cost", $ship_cost);
        $this->context->smarty->assign("tax_cost", $tax_c);
        $g = $info_customer[0]['shipping_cost'];
        $t = $info_customer[0]['tax_cost'];
        $this->context->smarty->assign("shipping_cost_check", $g);
        $this->context->smarty->assign("tax_cost_check", $t);

        $zero = Tools::displayPrice('0', $id_currency_product_quote);
        $this->context->smarty->assign("zero", $zero);
        
        $tb_product_pdf = $this->display(__FILE__, 'views/templates/admin/tbproductpdf.tpl');
        $subtotalpdf = $this->display(__FILE__, 'views/templates/admin/subtotalpdf.tpl');
        $messagespdf = $this->display(__FILE__, 'views/templates/admin/messagespdf.tpl');
        $this->context->smarty->assign("date_format_lang", $date_format_lang);
        $array_language_iso_code = $iso_code;
        $content_pdf_lang = Configuration::get('label_pdf_'.$array_language_iso_code);
        $id_format = $this->getIDQuoteformatted($id_quote_view);
        $pdf_adm = $this->ps_cipherTool->decrypt($content_pdf_lang);
        $pdf_adm = str_replace("[shop_name]", $shop_name, $pdf_adm);
        $pdf_adm = str_replace("[quote_ID]", $id_format, $pdf_adm);
        $pdf_adm = str_replace("[quote_id]", $id_format, $pdf_adm);
        $pdf_adm = str_replace("[quote_date]", $quote_date, $pdf_adm);
        $pdf_adm = str_replace("[shop_add1]", $add_1, $pdf_adm);
        $pdf_adm = str_replace("[shop_add2]", $add_2, $pdf_adm);
        $pdf_adm = str_replace("[shop_city]", $city_shop, $pdf_adm);
        $pdf_adm = str_replace("[shop_state]", $state_shop, $pdf_adm);
        $pdf_adm = str_replace("[shop_zip]", $zip_shop, $pdf_adm);
        $pdf_adm = str_replace("[shop_country]", $country_shop, $pdf_adm);
        $pdf_adm = str_replace("[shop_phone]", $phone_shop, $pdf_adm);
        $pdf_adm = str_replace("[first_name]", $info_customer[0]['first_name'], $pdf_adm);
        $pdf_adm = str_replace("[last_name]", $info_customer[0]['last_name'], $pdf_adm);
        $pdf_adm = str_replace("[company_name]", $info_customer[0]['company_name'], $pdf_adm);
        $pdf_adm = str_replace("[company_address]", $info_customer[0]['company_address'], $pdf_adm);
        $pdf_adm = str_replace("[shipping_cost]", $info_customer[0]['shipping_cost'], $pdf_adm);
        $pdf_adm = str_replace("[tax_cost]", $info_customer[0]['tax_cost'], $pdf_adm);
        $pdf_adm = str_replace("[phone]", $info_customer[0]['phone'], $pdf_adm);
        $pdf_adm = str_replace("[email]", $info_customer[0]['email'], $pdf_adm);
        $pdf_adm = str_replace("[product_table]", $tb_product_pdf, $pdf_adm);
        $pdf_adm = str_replace("[messages]", $messagespdf, $pdf_adm);
        $pdf_adm = str_replace("[subtotal]", $subtotalpdf, $pdf_adm);
        $pdf_adm = str_replace("[order_date]", $option_order_date, $pdf_adm);
        $pdf_adm = str_replace("[gen_pdf_date]", $date_format_lang, $pdf_adm);
        $pdf_adm = $this->stripBreakLinePDF($pdf_adm);

        $config = array();
        $mpdf = new \Mpdf\Mpdf($config);
        $pdf_quote = $pdf_adm;
        $mpdf->AddPage();
        $mpdf->WriteHTML($pdf_quote);
        $file = $this->getPDFFileName($id_quote_view);
        $mpdf->Output(_PS_MODULE_DIR_ . 'askforaquotemodul/stories/'.$file, 'F');
        return _PS_MODULE_DIR_ . 'askforaquotemodul/stories/'.$file;
    }
    public function installTab($className, $tabName)
    {
        $tab = new Tab();
        $tab->active = 1;
        $tab->class_name = $className;
        $tab->name = array();
        $tab->position = 7;
        foreach (Language::getLanguages(true) as $lang) {
            $tab->name[$lang['id_lang']] = $tabName;
        }
        $tab->id_parent = -1;
        $tab->module = $this->name;
        $tab->add();
        $tab->save();
    }
    public function getOs($userAgent)
    {
        $osArray = array(
            'Windows 8' => 'Windows NT 6.2',
            'Windows 7' => 'Windows NT 6.1',
            'Windows Vista' => 'Windows NT 6.0',
            'Windows XP' => 'Windows NT 5',
            'MacOsX' => 'Mac OS X',
            'Android' => 'Android',
            'Linux' => 'X11'
        );

        foreach ($osArray as $k => $value) {
            if (strstr($userAgent, $value)) {
                $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
                SELECT `id_operating_system`
                FROM `'._DB_PREFIX_.'operating_system` os
                WHERE os.`name` = \''.pSQL($k).'\'');

                return $result['id_operating_system'];
            }
        }
        return null;
    }
    public function getproductlistt($mail_type, $product_list)
    {
        $html= '';
        $this->context->smarty->assign('product_list', $product_list);
        if ($mail_type == 'txt') {
            $html .= $this->display(__FILE__, 'views/templates/admin/mail_product_list_txt.txt');
        } else {
            $html .= $this->display(__FILE__, 'views/templates/admin/mail_product_list_html.tpl');
        }
        return $html;
    }
    public function getcouponlistt($mail_type, $name, $reduction)
    {
        $html= '';
        $this->context->smarty->assign('name', $name);
        $this->context->smarty->assign('reduction', $reduction);
        if ($mail_type == 'txt') {
            $html .= $this->display(__FILE__, 'views/templates/admin/order_cart_rules.txt');
        } else {
            $html .= $this->display(__FILE__, 'views/templates/admin/order_cart_rules.tpl');
        }
        return $html;
    }
    public function convertToArrayRowProduct($row_product)
    {
        $result = array();
        $row_product = ltrim($row_product, '|');
        $row_product = explode('|', $row_product);
        $total_price = 0;
        foreach ($row_product as $key_row_product => $value_row_product) {
            $value_row_product = explode('-', $value_row_product);
            foreach ($value_row_product as $key_vrp => $value_vrp) {
                if ($key_vrp == 0) {
                    $result[$key_row_product]['id_product'] = $value_vrp;
                }
                if ($key_vrp == 1) {
                    $result[$key_row_product]['id_combination'] = $value_vrp;
                }
                if ($key_vrp == 2) {
                    $result[$key_row_product]['price_product'] = Tools::ps_round($value_vrp, 4);
                }
                if ($key_vrp == 3) {
                    $result[$key_row_product]['quantity'] = $value_vrp;
                }
                if ($key_vrp == 4) {
                    $result[$key_row_product]['total_price_product'] = Tools::ps_round($value_vrp, 4);
                    $total_price += (float) Tools::ps_round($value_vrp, 4);
                }
            }
        }
        $result['total_price'] = $total_price;
        $result['total_tax'] = 0;
        return $result;
    }
    /**** by hatt on Apri 23, 2019 ******/
    public function getCustomerQuote($id_quote)
    {
        $sql = 'SELECT * FROM '._DB_PREFIX_.'product_quote_dbboo';
        $sql .= ' WHERE id_quote = '.(int) $id_quote;
        return Db::getInstance()->getRow($sql);
    }
    public function findQuoteCurrencyById($id_quote)
    {
        $sql = 'SELECT id_currency FROM '._DB_PREFIX_.'product_quote_dbboo';
        $sql .= ' WHERE id_quote = '.(int) $id_quote;
        $id_currency = (int) Db::getInstance()->getValue($sql);
        if (empty($id_currency)) {
            $id_currency_default = (int) Configuration::get('PS_CURRENCY_DEFAULT');
            return Currency::getCurrencyInstance($id_currency_default);
        }
        return Currency::getCurrencyInstance($id_currency);
    }
    public function findQuoteCurrencyBySource($source_check)
    {
        $sql = 'SELECT id_currency FROM '._DB_PREFIX_.'product_quote_dbboo';
        $sql .=" WHERE source_check = '".pSQL($source_check)."'";
        $id_currency = Db::getInstance()->getValue($sql);
        if (empty($id_currency)) {
            $id_currency_default = (int)Configuration::get('PS_CURRENCY_DEFAULT');
            return Currency::getCurrencyInstance($id_currency_default);
        }
        return Currency::getCurrencyInstance($id_currency);
    }
    public function setCurrencyQuote($id_quote, $cookie = true)
    {
        if (!empty($id_quote)) {
            $id_quote = (int) $id_quote;
            $currency = $this->findQuoteCurrencyById($id_quote);
            $context = Context::getContext();
            $context->currency = $currency;
            if ($cookie == true) {
                $this->context->cookie->id_currency = (int) $currency->id;
                Tools::setCurrency($context->cookie);
                $this->context->cookie->update();
            }
            return $currency;
        }
        return false;
    }
    public function getQuoteCartSummary($id_cart)
    {
        $id_cart = (int) $id_cart;
        $obsummary = array();
        $cart = new Cart($id_cart);
        $id_currency = (int) $cart->id_currency;
        $obcart = $cart->getSummaryDetails(null, true);
        $obsummary['total_products'] = $obcart['total_products'];
        $obsummary['total_products_format'] = Tools::displayPrice($obcart['total_products'], $id_currency);
        $obsummary['total_discounts'] = $obcart['total_discounts_tax_exc'];
        $obsummary['total_discounts_tax_exc'] = $obcart['total_discounts_tax_exc'];
        $obsummary['total_shipping'] = $obcart['total_shipping_tax_exc'];
        $obsummary['total_tax'] = $obcart['total_tax'];
        $obsummary['total_price_without_tax'] = $obcart['total_price_without_tax'];
        $obsummary['total_price'] = $obcart['total_price'];
        $obsummary['total_discounts_format'] = Tools::displayPrice($obcart['total_discounts_tax_exc'], $id_currency);
        $obsummary['total_shipping_format'] = Tools::displayPrice($obcart['total_shipping_tax_exc'], $id_currency);
        $obsummary['total_tax_format'] = Tools::displayPrice($obcart['total_tax'], $id_currency);
        $obcarttpwt = $obcart['total_price_without_tax'];
        $obsummary['total_price_without_tax_format'] = Tools::displayPrice($obcarttpwt, $id_currency);
        $obsummary['total_price_format'] = Tools::displayPrice($obcart['total_price'], $id_currency);
        return $obsummary;
    }
    public function bagetPaymentModules($id_customer)
    {
        $customer = new Customer($id_customer);
        $modules = Module::getAuthorizedModules($customer->id_default_group);
        $authorized_modules = array();
        if (!is_array($modules)) {
            return false;
        }
        foreach ($modules as $module) {
            if ($module['name'] != 'custompaymentmethod') {
                $authorized_modules[] = (int)$module['id_module'];
            }
        }
        $payment_modules = array();
        foreach (PaymentModule::getInstalledPaymentModules() as $p_module) {
            if (in_array((int)$p_module['id_module'], $authorized_modules)) {
                $m = Module::getInstanceById((int)$p_module['id_module']);
                $payment_modules[] = array(
                        'name' => @$m->name,
                        'displayName' => @$m->displayName
                    );
            }
        }
        $payment_path = _PS_MODULE_DIR_.'custompaymentmethod/classes/CustomPayment.php';
        if (file_exists($payment_path)) {
            require_once($payment_path);
            $c = @CustomPayment::getCustomPaymentMethodsCollection($this->context->language->id, true, $customer);
            if (is_array($c) && count($c)) {
                foreach ($c as $payment) {
                    $payment_modules[] = array(
                        'name' => 'custompaymentmethod_'.$payment->id,
                        'displayName' => $payment->name
                    );
                }
            }
        }
        return $payment_modules;
    }
    public function findPaymentDisplayNameByID($name, $id_customer)
    {
        $payment_modules = $this->bagetPaymentModules($id_customer);
        if (empty($payment_modules)) {
            return $name;
        }
        foreach ($payment_modules as $p) {
            if ($p['name'] == $name) {
                return $p['displayName'];
            }
        }
        return $name;
    }
    public function findModuleByPayment($name)
    {
        if (strpos($name, 'custompaymentmethod_') === false) {
            return $name;
        } else {
            return 'custompaymentmethod';
        }
    }
    public function useTax()
    {
        $option_price_excl_tax = (int) Configuration::get('option_price_excl_tax');
        if ($option_price_excl_tax == 1) {
            return false;
        }
        return true;
    }
    public function prefixTax()
    {
        if ($this->useTax() == false) {
            return $this->l('(tax excl.)');
        } else {
            return '';
        }
    }
    /** since 1.0.38+ by hatt **/
    public function displayConvertCartButton()
    {
        $option_convert_cart = (int) Configuration::get('option_convert_cart');
        if ($option_convert_cart != 1) {
            return '';
        }
        // Kiem tra co phai dang o Cart page?
        $controller = Tools::strtolower(Tools::getValue('controller'));
        $cart_controller = array('order-opc', 'order', 'orderopc', 'cart');
        if (!in_array($controller, $cart_controller)) {
            return '';
        }
        // Neu cart rong -> hidden
        $cart = $this->context->cart;
        $products = $cart->getProducts();
        if (empty($cart) || empty($products)) {
            return '';
        }
        $link = new Link();
        $convert_controller = $link->getModuleLink('askforaquotemodul', 'convert');
        $this->smarty->assign('convert_controller', $convert_controller);
        $html = $this->display(__FILE__, 'views/templates/front/convert_cart.tpl');
        return $html;
    }
    public function isAllowedUseQuote()
    {
        $groups_checked = Configuration::get('askforaquotemodul_groups');
        $groups_checked = Tools::jsonDecode($groups_checked, true);
        if (empty($groups_checked)) {
            // module khong cho phep bat ky group nao su dung
            return false;
        }
        $customer = Context::getContext()->customer;
        $current_group = $customer->getGroups();
        if (empty($current_group)) {
            // User hien tai khong thuoc group nao nen khong duoc su dung
            return false;
        }
        // kiem tra xem co group nao cua user hien tai duoc cho phep khong?
        foreach ($current_group as $id_group) {
            if (in_array($id_group, $groups_checked)) {
                return true;
            }
        }
        return false;
    }
    public function convertArrayProductsIntoCart($products, $id_cus, $id_currency, $id_lang, $id_carrier = null)
    {
        $db = Db::getInstance();
        if (empty($products)) {
            return false;
        }
        $cart = new Cart();
        $date_now = date('Y-m-d H:i:s');
        $id_customer = (int) $id_cus;
        $id_currency = (int) $id_currency;
        $id_lang = (int) $id_lang;
        $currency = new Currency($id_currency);
        $id_currency = $currency->id;
        $currency_default = new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT'));
        $customer = new Customer($id_customer);
        
        if ($customer->is_guest || $id_customer == 0) {
            $cart->secure_key = md5($date_now);
        } else {
            $cart->secure_key = $customer->secure_key;
            $address = $this->getActivedAddress($customer, $id_lang);
            if (isset($address[0])) {
                $cart->id_address_delivery = (int) $address[0]['id_address'];
                $cart->id_address_invoice = (int) $address[0]['id_address'];
            }
        }
        $cart->id_carrier = (int) $id_carrier;
        $cart->id_customer = $id_customer;
        $cart->id_shop_group = $this->context->shop->id_shop_group;
        $cart->id_lang = $id_lang;
        $cart->id_currency = $id_currency;
        $cart->add();
        $cart->setNoMultishipping();
        $id_cart = (int) $cart->id;
        if (empty($id_cart) || $id_cart == 0) {
            return false;
        }
        foreach ($products as $product) {
            $qty = (int) $product['quantity'];
            $id_product = (int) $product['id_product'];
            if ($id_product == 0) {
                continue;
            }
            $id_product_attribute = (int) $product['id_combination'];
            // cập nhật cho phép thêm sản phẩm stock = 0 vào cart
            $sql = 'UPDATE '._DB_PREFIX_.'stock_available SET out_of_stock = 1 WHERE id_product='. $id_product;
            $db->query($sql);
            // thêm sản phẩm vào Cart
            $cart->updateQty($qty, $id_product, $id_product_attribute, null, 'up');
            // cập nhật giá đúng giá Quote, ko phụ thuộc giá sản phẩm
            $default_price = Tools::convertPriceFull($product['price_product'], $currency, $currency_default);
            SpecificPrice::deleteByIdCart($id_cart, $id_product, $id_product_attribute);
            $specific_price = new SpecificPrice();
            $specific_price->id_cart = $id_cart;
            $specific_price->id_shop = 0;
            $specific_price->id_shop_group = 0;
            $specific_price->id_currency = 0;
            $specific_price->id_country = 0;
            $specific_price->id_group = 0;
            $specific_price->id_customer = $id_customer;
            $specific_price->id_product = $id_product;
            $specific_price->id_product_attribute = $id_product_attribute;
            $specific_price->price = (float) $default_price;
            $specific_price->from_quantity = 1;
            $specific_price->reduction = 0;
            $specific_price->reduction_type = 'amount';
            $specific_price->from = '0000-00-00 00:00:00';
            $specific_price->to = '0000-00-00 00:00:00';
            $specific_price->add();
        }
        $cart->update();
        $this->flushPriceCache();
        return $cart;
    }
    public function flushPriceCache()
    {
        require_once(_PS_MODULE_DIR_ . $this->name . '/classes/BASpecificPrice.php');
        AskforaquotemodulSpecificPrice::flushPriceCache();
        Cache::clean('getPackageShippingCost_*');
        Cache::clean('Cart::*');
    }
    /** since 1.0.39 **/
    public function test()
    {
    }
    public function deleteACart($cart)
    {
        $cart->delete();
        SpecificPrice::deleteByIdCart($cart->id);
        $this->flushPriceCache();
        return true;
    }
    public function updateQuotePrice($id_quote)
    {
        $id_quote = (int) $id_quote;
        $db = Db::getInstance();
        $sql = 'SELECT id_quote, SUM(total_pri_incl_tax - total_pri) as total_tax ';
        $sql .= ', SUM(total_pri_incl_tax) as total_price_incl ';
        $sql .= ' FROM '._DB_PREFIX_.'product_quote_detail';
        $sql .= ' WHERE id_quote = '.$id_quote;
        $sql .= ' GROUP BY id_quote';
        $row = $db->getrow($sql);
        if (empty($row)) {
            return false;
        }
        // update
        $tax_cost = $row['total_tax'] > 0 ? $row['total_tax'] : 0;
        $total_price_incl = $row['total_price_incl'];
        $sql = 'UPDATE '._DB_PREFIX_.'product_quote_dbboo SET';
        $sql .= " tax_cost = ".$tax_cost;
        $sql .= ", total_pri = IFNULL(shipping_cost,0) + ".$total_price_incl;
        $sql .= ", total_pri_fixed = IFNULL(shipping_cost,0) + ".$total_price_incl;
        $sql .= ' WHERE id_quote = '.$id_quote;
        $row = $db->query($sql);
        return true;
    }
    public function getActivedAddress($customer, $id_lang, $only_first = false)
    {
        $customerAddresses = $customer->getAddresses($id_lang);
        if (empty($customerAddresses)) {
            return null;
        }
        foreach ($customerAddresses as $i => $address) {
            if (!Address::isCountryActiveById((int)($address['id_address']))) {
                unset($customerAddresses[$i]);
            }
        }
        if (key($customerAddresses) != 0) {
            $customerAddresses = array_values($customerAddresses);
        }
        if ($only_first == true) {
            return new Address($customerAddresses[0]['id_address']);
        } else {
            return $customerAddresses;
        }
    }
    public function getProductPriceTax($price, $id_product, $id_customer, $id_lang = null, $id_shop = null)
    {
        $key = 'getProductPriceTax_'.$id_product.'_'.$id_shop.'_'.$id_customer.'_'.$id_lang.'_'.$price;
        if (Cache::isStored($key)) {
            return Cache::retrieve($key);
        }
        if (empty($id_lang)) {
            $id_lang =  (int) $this->context->language->id;
        }
        if (empty($id_shop)) {
            $id_shop =  (int) $this->context->shop->id;
        }
        $customer = new Customer((int) $id_customer);
        $address = $this->getActivedAddress($customer, $id_lang, true);
        $id_tax_rules_group =$this->getIdTaxRulesGroupByIdProduct($id_product, $id_shop);
        $tax_rate = $this->getTaxesRate($id_tax_rules_group, $address);

        $price_incl = (float) $price * (1 + $tax_rate/100);
        Cache::store($key, $price_incl);
        return $price_incl;
    }
    public function getIdTaxRulesGroupByIdProduct($id_product, $id_shop = null)
    {
        if (empty($id_shop)) {
            $id_shop =  (int) $this->context->shop->id;
        }
        $key = 'product_id_tax_rules_group_'.(int)$id_product.'_'.(int)$id_shop;
        if (!Cache::isStored($key)) {
            $sql = 'SELECT `id_tax_rules_group`
                FROM `'._DB_PREFIX_.'product_shop`
                WHERE `id_product` = '.(int)$id_product.' AND id_shop='.(int)$id_shop;
            $id_tax_rules_group = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
            Cache::store($key, $id_tax_rules_group);
        }
        return Cache::retrieve($key);
    }
    public function getTaxesRate($id_tax_rules_group, Address $address = null)
    {
        if (!$address || !$address->id_country) {
            $address = Address::initialize();
        }
        $tax_manager = TaxManagerFactory::getManager($address, $id_tax_rules_group);
        $tax_calculator = $tax_manager->getTaxCalculator();

        return $tax_calculator->getTotalRate();
    }
    public function stripBreakLinePDF($text)
    {
        $text = str_replace('<div>,</div>', '', $text);
        $text = str_replace('<div>, </div>', '', $text);
        $text = str_replace('<div>,  </div>', '', $text);
        return $text;
    }
    public function getPDFFileName($id_quote)
    {
        $id_quote = (int) $id_quote;
        $prefix = $this->l('Quote_');
        $suffix = $this->l('_');
        $today = date("Y_m_d", time());
        $filename = $prefix.$id_quote.$suffix.$today.'.pdf';
        return $filename;
    }
    public function getIDQuoteformatted($id_quote, $hash = false, $prefix = false, $suffix = false)
    {
        $id_quote = (int) str_replace('#', '', $id_quote);
        $format = str_pad($id_quote, 6, '0', STR_PAD_LEFT);
        if ($prefix !== false) {
            $format = $prefix.$format;
        }
        if ($suffix !== false) {
            $format = $format.$suffix;
        }
        if ($hash == true) {
            $format = '#'.$format;
        }
        return $format;
    }
}
