HEX
Server: Apache
System: Linux srv13.cpanelhost.cl 3.10.0-962.3.2.lve1.5.38.el7.x86_64 #1 SMP Thu Jun 18 05:28:41 EDT 2020 x86_64
User: cca63905 (4205)
PHP: 7.3.20
Disabled: NONE
Upload Files
File: /home4/cca63905/www/nueva/modules/roja45quotationsprofree/controllers/admin/AdminQuotationsPro.php
<?php
/**
 * AdminQuotationsProController.
 *
 * @author    Roja45
 * @copyright 2016 Roja45
 * @license   license.txt
 * @category  AdminQuotationsProController
 *
 *
 * 2016 ROJA45 - All rights reserved.
 *
 * DISCLAIMER
 * Changing this file will render any support provided by us null and void.
 */

/**
 * AdminQuotationsProController.
 *
 * @author    Roja45
 * @copyright 2016 Roja45
 * @license   license.txt
 * @category  Class
 *
 *
 * 2016 ROJA45 - All rights reserved.
 *
 * DISCLAIMER
 * Changing this file will render any support provided by us null and void.
 */

class AdminQuotationsProController extends ModuleAdminController
{
    /**
     * Constructor
     */
    public function __construct()
    {
        parent::__construct();
        $this->context = Context::getContext();
        $this->override_folder = 'roja45quotationsprofree/';
        $this->bootstrap = true;
        $this->table = 'roja45_quotationspro';
        $this->identifier = 'id_roja45_quotation';
        $this->submit_action = 'submitAdd'.$this->table;
        $this->show_cancel_button = true;
        $this->className = 'RojaQuotation';
        $this->deleted = false;
        $this->colorOnBackground = false;
        $this->multishop_context = Shop::CONTEXT_ALL;

        $this->_defaultOrderBy = $this->identifier = 'id_roja45_quotation';
        $this->list_id = 'id_roja45_quotation';
        $this->deleted = false;
        $this->_orderBy = 'date_upd';
        $this->_orderWay = 'DESC';

        $this->addRowAction('view');

        $this->fields_list = array(
            'id_roja45_quotation' => array(
                'title' => $this->module->l('ID'),
                'class' => 'fixed-width-xs'
            ),
            'code' => array(
                'title' => $this->module->l('Status'),
                'width' => 'auto',
                'color' => 'color',
                'filter_key' => 'id_roja45_quotation_status',
                'filter_type' => 'int',
                'order_key' => 'cname',
            ),
            'reference' => array(
                'title' => $this->module->l('Reference #'),
                'width' => 'auto',
            ),
            'email' => array(
                'title' => $this->module->l('Email'),
                'width' => 'auto',
            ),
            'total' => array(
                'title' => $this->module->l('Total'),
                'width' => 'auto',
            ),
            'date_add' => array(
                'title' => $this->module->l('Received'),
                'width' => 'auto',
            ),
            'date_upd' => array(
                'title' => $this->module->l('Last Update'),
                'width' => 'auto',
            ),
            'lang' => array(
                'title' => $this->module->l('Language'),
                'width' => 'auto',
            ),
            'owner' => array(
                'title' => $this->module->l('Owner'),
                'width' => 'auto',
            ),
            'quotesent' => array(
                'title' => $this->module->l('Quote Sent'),
                'width' => 'auto',
            ),
            'hasorder' => array(
                'title' => $this->module->l('Order Completed'),
                'width' => 'auto',
            ),
        );
    }

    /**
     * Initialise
     */
    public function init()
    {
        if (Tools::isSubmit('submiteditroja45_quotationspro')) {
            $this->display = 'edit';
        } elseif (Tools::isSubmit('viewroja45_quotationspro')) {
            $this->display = 'view';
        }

        return parent::init();
    }

    public function getList(
        $id_lang,
        $orderBy = null,
        $orderWay = null,
        $start = 0,
        $limit = null,
        $id_lang_shop = null
    ) {
        parent::getList($id_lang, $orderBy, $orderWay, $start, $limit, $id_lang_shop);

        foreach ($this->_list as &$list_item) {
            $quotation = new RojaQuotation($list_item['id_roja45_quotation']);
            $currency = new Currency($quotation->id_currency);
            $list_item['currency'] = $currency->iso_code;
            if ($list_item['id_employee'] > 0) {
                $employee = new Employee($list_item['id_employee']);
                $list_item['owner'] = $employee->firstname . ' ' . $employee->lastname;
            }

            if ($list_item['id_lang'] > 0) {
                $language = new Language($list_item['id_lang'], $id_lang);
                $list_item['lang'] = $language->name;
            }

            $id_status = $list_item['id_roja45_quotation_status'];
            $status = new QuotationStatus($id_status, $this->context->language->id);

            if ($status->code == QuotationStatus::$DLTD) {
                $list_item['class'] = 'deleted';
            }
            $list_item['total'] = $this->module->l('UPGRADE TO VIEW');
            $list_item['quotesent'] = $this->module->l('UPGRADE TO VIEW');
            $list_item['hasorder'] = $this->module->l('UPGRADE TO VIEW');
            $list_item['incart'] = $this->module->l('UPGRADE TO VIEW');
        }
    }

    public function renderView()
    {
        if (!($quotation = $this->loadObject(true))) {
            return;
        }
        return $this->buildForm($quotation);
    }

    public function renderForm()
    {
        $quotation = $this->loadObject(true);
        if (!Validate::isLoadedObject($quotation)) {
            $id_country = (int) $this->context->country->id;
            $quotation = new RojaQuotation();
            $quotation->id_roja45_quotation = (int) 0;
            $quotation->id_lang = (int) $this->context->language->id;
            $quotation->id_shop = (int) $this->context->shop->id;
            $quotation->id_currency = (int) $this->context->currency->id;
            $quotation->id_country = $id_country;
            $quotation->id_employee = $this->context->employee->id;
            $quotation->id_customer = 0;
            $quotation->valid_days = Configuration::get('ROJA45_QUOTATIONSPRO_QUOTE_VALID_DAYS');
            $quotation->form_data = '';

            if (Group::getDefaultPriceDisplayMethod()==0) {
                $quotation->calculate_taxes = 1;
            } else {
                $quotation->calculate_taxes = 0;
            }
        }
        return $this->buildForm($quotation);
    }

    public function initToolbarTitle()
    {
        $this->toolbar_title = is_array($this->breadcrumbs) ? array_unique($this->breadcrumbs) : array($this->breadcrumbs);
        /** @var RojaQuotation $quotation */
        $quotation = $this->loadObject(true);

        switch ($this->display) {
            case 'view':
                $this->toolbar_title[] = $this->module->l('View Quotation: ') . $quotation->reference;
                $this->addMetaTitle($this->module->l('View Quotation: ') . $quotation->reference);
                break;
            default:
                $this->toolbar_title[] = $this->module->l('Quotations');
                $this->addMetaTitle($this->module->l('Quotations'));
        }

        if ($filter = $this->addFiltersToBreadcrumbs()) {
            $this->toolbar_title[] = $filter;
        }
    }

    protected function renderQuotationForm()
    {
        if (!($this->loadObject(true))) {
            return;
        }

        return parent::renderForm();
    }

    protected function getFieldsValues()
    {
        return array (
            'ROJA45_QUOTATIONSPRO_USE_CS' => Tools::getValue(
                'ROJA45_QUOTATIONSPRO_USE_CS',
                Configuration::get('ROJA45_QUOTATIONSPRO_USE_CS')
            ),
        );
    }

    /**
     * @param $quotation RojaQuotation
     * @return string
     */
    private function buildForm($quotation)
    {
        $tpl = $this->context->smarty->createTemplate(
            $this->getTemplatePath('quotationview.tpl') . 'quotationview.tpl'
        );
        $requestJSON = Tools::jsonDecode($quotation->form_data);
        $request = array();

        if ($requestJSON) {
            $counter = 0;
            foreach ($requestJSON->columns as $column) {
                foreach ($column->fields as $field) {
                    if (($field->name != 'FIRSTNAME') && ($field->name != 'LASTNAME') && ($field->name != 'CONTACT_EMAIL')) {
                        $request[$counter]['name'] = $field->name;
                        $request[$counter]['value'] = $field->value;
                        $request[$counter]['label'] = $field->label;
                        ++$counter;
                    }
                }
            }
        }

        $use_taxes = !Group::getPriceDisplayMethod(
            Customer::getDefaultGroupId($quotation->id_customer)
        );

        $currency = new Currency($quotation->id_currency);

        $tpl->assign(
            array(
                'id_roja45_quotation' => $quotation->id_roja45_quotation,
                'request' => $request,
                'currency' => $currency,
                'quotation' => $quotation,
                'use_taxes' => $use_taxes,
                'quotation_products' => $quotation->getProducts()
            )
        );
        return $tpl->fetch();
    }
}