public function getFormConfigurationController()
 {
     // get all status
     $advanced_order_status = Configuration::get(self::getControllerStatusName('AdminAdvancedOrder'));
     $fields_form = array();
     // configure stock gap
     $fields_form[2]['form'] = array('legend' => array('title' => $this->l('General settings'), 'image' => '../img/admin/cog.gif'), 'input' => array(array('type' => 'radio', 'label' => $this->l('Disable original menus of PrestaShop'), 'name' => 'erp_disable_original_menus', 'required' => true, 'br' => true, 'class' => 't', 'default_value' => '1', 'values' => array(array('id' => 'erp_disable_original_menus' . _PS_SMARTY_NO_COMPILE_, 'value' => '1', 'label' => $this->l('Yes')), array('id' => 'erp_disable_original_menus' . _PS_SMARTY_CHECK_COMPILE_, 'value' => '0', 'label' => $this->l('No'))), 'desc' => $this->l('This option allows you to disable the menus :  orders, supply order and supplier'))), 'submit' => array('title' => $this->l('Save'), 'class' => $this->is_1_6 ? null : 'button', 'name' => 'submitGeneralSettings'));
     // Get activate module table
     $features = ErpFeature::getFeaturesWithToken($this->context->language->iso_code);
     //Display controller parameters if activ and good state
     foreach ($features as $feature) {
         //INVENTORY
         if ($feature['active'] && $feature['controller'] == 'AdminInventory' && Configuration::get(self::getControllerStatusName('AdminInventory'))) {
             // configure stock gap
             $fields_form[3]['form'] = array('legend' => array('title' => sprintf($this->l('%s settings'), $feature['name']), 'image' => '../modules/erpillicopresta/img/features/inventory.png'), 'input' => array(array('type' => 'text', 'label' => $this->l('Maximum authorized stock gap'), 'name' => 'erp_gap_stock', 'size' => 20, 'required' => true, 'desc' => $this->l('If the difference between the found quantity and the expected quantity is greater than this value, an alert will be generated. (0 to disable)'))), 'submit' => array('title' => $this->l('Save'), 'class' => $this->is_1_6 ? null : 'button', 'name' => 'submitInventorySettings'));
         }
         //ORDER
         if ($feature['active'] && $feature['controller'] == 'AdminAdvancedOrder' && $advanced_order_status != STATUS0 && $advanced_order_status != STATUS1) {
             // Get default Language
             $states = OrderState::getOrderStates((int) Configuration::get('PS_LANG_DEFAULT'));
             $fields_form[4]['form'] = array('legend' => array('title' => sprintf($this->l('%s settings'), $feature['name']), 'image' => '../modules/erpillicopresta/img/features/order.png'), 'input' => array(array('type' => 'text', 'label' => $this->l('Stock level - ALERT'), 'name' => 'erp_level_stock_alert', 'desc' => $this->l('Please indicate the stock quantity above which an alert will notify you : from 1 to [X]'), 'size' => 4), array('type' => 'text', 'label' => $this->l('Stock level - NORMAL'), 'name' => 'erp_level_stock_normal', 'desc' => $this->l('Please indicate the stock quantity corresponding to a normal stock level : from ALERT to [X]'), 'size' => 4), array('type' => 'checkbox', 'label' => $this->l('Order status to notify'), 'name' => 'erp_status_warning_stock', 'required' => true, 'values' => array('query' => $states, 'id' => 'id_order_state', 'name' => 'name'), 'desc' => $this->l('Select all status which are concerned by stock warnings'))), 'submit' => array('title' => $this->l('Save'), 'class' => $this->is_1_6 ? null : 'button', 'name' => 'submitAdvancedOrderSettings'));
         }
         //SUPPLIER ORDER
         if ($feature['active'] && $feature['controller'] == 'AdminAdvancedSupplyOrder') {
             $fields_form[5]['form'] = array('legend' => array('title' => sprintf($this->l('%s settings'), $feature['name']), 'image' => '../modules/erpillicopresta/img/features/supply_order.png'), 'input' => array(array('type' => 'text', 'label' => $this->l('References prefix'), 'name' => 'erp_prefix_reference', 'desc' => $this->l('References prefixes for the supplier order: maximum of two characters. Default prefix is SO.'), 'size' => 2, 'maxlength' => 2, 'required' => true), array('type' => 'radio', 'label' => $this->l('Activate email sending to suppliers'), 'name' => 'erp_enable_sending_mail_supplier', 'required' => true, 'br' => true, 'class' => 't', 'default_value' => '0', 'values' => array(array('id' => 'erp_enable_sending_mail_supplier' . _PS_SMARTY_NO_COMPILE_, 'value' => '1', 'label' => $this->l('Yes')), array('id' => 'erp_enable_sending_mail_supplier' . _PS_SMARTY_CHECK_COMPILE_, 'value' => '0', 'label' => $this->l('No'))), 'desc' => $this->l('If you select this option, please define the default status to be considered.')), array('type' => 'select', 'label' => $this->l('Status of supplier orders that activates an email sending'), 'name' => 'erp_so_state_to_send_mail', 'desc' => $this->l('In the selected status, an email will be sent to the supplier. Default : 2 - Order validated.'), 'required' => true, 'options' => array('query' => SupplyOrderState::getStates(), 'id' => 'id_supply_order_state', 'name' => 'name'))), 'submit' => array('title' => $this->l('Save'), 'class' => $this->is_1_6 ? null : 'button', 'name' => 'submitAdvancedSupplyOrderSettings'));
             if (Configuration::get(self::getControllerStatusName('AdminAdvancedSupplyOrder'))) {
                 // configure stock gap
                 $fields_form[5]['form']['input'][] = array('type' => 'select', 'label' => $this->l('Status of customer orders that generates supplier orders'), 'name' => 'erp_generate_order_state', 'desc' => $this->l('Please choose here the status of customer orders that will generate an automatic supplier order.'), 'required' => true, 'options' => array('query' => OrderState::getOrderStates((int) $this->context->language->id), 'id' => 'id_order_state', 'name' => 'name'));
                 $fields_form[5]['form']['input'][] = array('type' => 'select', 'label' => $this->l('Status of customer orders after generation of supplier orders'), 'name' => 'erp_generate_order_state_to', 'desc' => $this->l('Select the state to apply to customer orders after the automatic generation of supplier orders occured.'), 'required' => true, 'options' => array('query' => OrderState::getOrderStates((int) $this->context->language->id), 'id' => 'id_order_state', 'name' => 'name'));
                 // configure stock gap
                 $fields_form[5]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Number of rolling months'), 'name' => 'erp_rolling_months_nb_so', 'size' => 20, 'required' => true, 'desc' => $this->l('Used to display the quantities sold for x rolling months.'));
                 $fields_form[5]['form']['input'][] = array('type' => 'select', 'label' => $this->l('Status of customer orders that count for the product sales statistic'), 'name' => 'erp_so_state_to_product_sales', 'desc' => $this->l('In the selected status, the products of the order will be counted in the product sales statistic.'), 'required' => true, 'options' => array('query' => OrderState::getOrderStates((int) $this->context->language->id), 'id' => 'id_order_state', 'name' => 'name'));
                 $fields_form[5]['form']['input'][] = array('type' => 'radio', 'label' => $this->l('Sales forecast type'), 'name' => 'erp_sales_forecast_choice', 'br' => true, 'class' => 't', 'values' => array(array('id' => 'none', 'value' => 0, 'label' => $this->l('No projected sales')), array('id' => 'forecast_six_last_month', 'value' => 1, 'label' => $this->l('Weighted average sales on the six last rolling months')), array('id' => 'forecast_period', 'value' => 2, 'label' => $this->l('Sales forecast by period'))), 'desc' => $this->l('Sales forecast will be calculated during supplier orders.') . '</br>' . $this->l('The "Sales forecast by period" method calculates ') . $this->l('the sales growth factor based on the comparison between ') . $this->l('x rolling months of the current year ') . $this->l('and the same x rolling months of the previous year at the same date. ') . $this->l('Sales for the choosen projection period are then estimated by multiplying ') . $this->l('this sales growth factor by the sales performed during that period on the previous year.'));
                 $fields_form[5]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Weighting coefficients'), 'name' => 'erp_coefficients', 'desc' => $this->l('Coefficients that will be used to calculate the "Weighted average sales on the six last rolling months". Positive numbers expected.') . '<br/>' . $this->l('Syntax : M-1;M-2;M-3;M-4;M-5;M-6 (coefficient of the month M-1; etc.)'), 'size' => 20);
                 $fields_form[5]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Projection period'), 'name' => 'erp_projected_period', 'suffix' => $this->l('days'), 'desc' => $this->l('The "Sales forecast by period" method will return the total sales estimation for the filled out period.'), 'size' => 20);
                 $fields_form[5]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Comparison period for the growth factor calculation'), 'name' => 'erp_comparison_period', 'suffix' => $this->l('month'), 'desc' => $this->l('Number of months preceding the current date that will be used to calculate the sales growth factor in the "Sales forecast by period" method.'), 'size' => 20);
                 $fields_form[5]['form']['input'][] = array('type' => 'text', 'label' => $this->l('Exceptional sales threshold'), 'name' => 'erp_exceptional_order_limit', 'desc' => $this->l('Above this value, a sale will be considered exceptional and will not be taken into account in forecasts. 0 if non applicable.'), 'size' => 20, 'required' => true);
             }
         }
     }
     return $fields_form;
 }
 /**
  * Init the content of change state action
  */
 public function initChangeStateContent()
 {
     $id_supply_order = (int) Tools::getValue('id_supply_order', 0);
     if ($id_supply_order <= 0) {
         $this->errors[] = Tools::displayError('The specified supply order is not valid');
         return parent::initContent();
     }
     $supply_order = new SupplyOrder($id_supply_order);
     $supply_order_state = new SupplyOrderState($supply_order->id_supply_order_state);
     if (!Validate::isLoadedObject($supply_order) || !Validate::isLoadedObject($supply_order_state)) {
         $this->errors[] = Tools::displayError('The specified supply order is not valid');
         return parent::initContent();
     }
     // change the display type in order to add specific actions to
     $this->display = 'update_order_state';
     // overrides parent::initContent();
     $this->initToolbar();
     $this->initPageHeaderToolbar();
     // given the current state, loads available states
     $states = SupplyOrderState::getSupplyOrderStates($supply_order->id_supply_order_state);
     // gets the state that are not allowed
     $allowed_states = array();
     foreach ($states as &$state) {
         $allowed_states[] = $state['id_supply_order_state'];
         $state['allowed'] = 1;
     }
     $not_allowed_states = SupplyOrderState::getStates($allowed_states);
     // generates the final list of states
     $index = count($allowed_states);
     foreach ($not_allowed_states as &$not_allowed_state) {
         $not_allowed_state['allowed'] = 0;
         $states[$index] = $not_allowed_state;
         ++$index;
     }
     // loads languages
     $this->getlanguages();
     // defines the fields of the form to display
     $this->fields_form[0]['form'] = array('legend' => array('title' => $this->l('Supply order status'), 'icon' => 'icon-pencil'), 'input' => array(), 'submit' => array('title' => $this->l('Save')));
     $this->displayInformation($this->l('Be careful when changing status. Some of those changes cannot be canceled. '));
     // sets up the helper
     $helper = new HelperForm();
     $helper->submit_action = 'submitChangestate';
     $helper->currentIndex = self::$currentIndex;
     $helper->toolbar_btn = $this->toolbar_btn;
     $helper->toolbar_scroll = false;
     $helper->token = $this->token;
     $helper->id = null;
     // no display standard hidden field in the form
     $helper->languages = $this->_languages;
     $helper->default_form_language = $this->default_form_language;
     $helper->allow_employee_form_lang = $this->allow_employee_form_lang;
     $helper->title = sprintf($this->l('Stock: Change supply order status #%s'), $supply_order->reference);
     $helper->show_cancel_button = true;
     $helper->override_folder = 'supply_orders_change_state/';
     // assigns our content
     $helper->tpl_vars['show_change_state_form'] = true;
     $helper->tpl_vars['supply_order_state'] = $supply_order_state;
     $helper->tpl_vars['supply_order'] = $supply_order;
     $helper->tpl_vars['supply_order_states'] = $states;
     // generates the form to display
     $content = $helper->generateForm($this->fields_form);
     $this->context->smarty->assign(array('content' => $content, 'url_post' => self::$currentIndex . '&token=' . $this->token, 'show_page_header_toolbar' => $this->show_page_header_toolbar, 'page_header_toolbar_title' => $this->page_header_toolbar_title, 'page_header_toolbar_btn' => $this->page_header_toolbar_btn));
 }
 public function getSupplyOrderStats($id_supply_order_state)
 {
     // given the current state, loads available states
     $states = SupplyOrderState::getSupplyOrderStates($id_supply_order_state);
     // gets the state that are not allowed
     $allowed_states = array();
     foreach ($states as &$state) {
         $allowed_states[] = $state['id_supply_order_state'];
         $state['allowed'] = 1;
     }
     $not_allowed_states = SupplyOrderState::getStates($allowed_states);
     // generates the final list of states
     $index = count($allowed_states);
     foreach ($not_allowed_states as &$not_allowed_state) {
         $not_allowed_state['allowed'] = 0;
         $states[$index] = $not_allowed_state;
         ++$index;
     }
     return $states;
 }