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; }
public function __construct() { $this->table = 'erpip_zone'; $this->className = 'ErpZone'; $this->lang = false; $this->context = Context::getContext(); if (_PS_VERSION_ < 1.6) { $this->no_link = true; } else { $this->list_no_link = true; } $this->addRowAction('view'); $this->addRowAction('edit'); $this->addRowAction('delete'); // template path $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/'; $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selection'), 'confirm' => $this->l('Delete selected items?'))); $this->is_1_6 = version_compare(_PS_VERSION_, '1.6') > 0; $this->_select = ' IFNULL(ez.name, \'' . $this->l('Home') . '\') as parent_name, w.name as warehouse_name, w.id_warehouse'; $this->_join = 'LEFT JOIN `' . _DB_PREFIX_ . 'erpip_zone` as ez ON (ez.`id_erpip_zone` = a.`id_parent`)'; $this->_join .= 'LEFT JOIN `' . _DB_PREFIX_ . 'warehouse` as w ON (w.`id_warehouse` = a.`id_warehouse`)'; if (Tools::isSubmit('id_erpip_zone') && (int) Tools::getValue('id_erpip_zone') > 0 || Tools::isSubmit('id_parent') && (int) Tools::getValue('id_parent') > 0) { $id_erpip_zone = (int) Tools::getValue('id_erpip_zone') > 0 ? (int) Tools::getValue('id_erpip_zone') : (int) Tools::getValue('id_parent'); $this->_where .= ' AND a.id_parent = ' . $id_erpip_zone; $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA : '); $this->toolbar_title .= implode(' > ', array_reverse(ErpZone::getZoneBreadcrumbs($id_erpip_zone))); } else { $this->_where .= ' AND a.id_parent = 0'; $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA : Home zones'); } $this->fields_list = array('id_erpip_zone' => array('title' => $this->l('ID'), 'width' => '30', 'remove_onclick' => true), 'name' => array('title' => $this->l('Zone name'), 'width' => 'auto', 'filter_key' => 'a!name', 'remove_onclick' => true), 'parent_name' => array('title' => $this->l('Parent zone'), 'width' => 'auto', 'search' => false, 'remove_onclick' => true), 'warehouse_name' => array('title' => $this->l('Warehouse'), 'width' => 'auto', 'filter_key' => 'w!name', 'remove_onclick' => true), 'active' => array('title' => $this->l('Enabled'), 'width' => 70, 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'remove_onclick' => true)); $this->context->smarty->assign(array('template_path' => $this->template_path, 'erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code))); // get controller status $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedOrder')); parent::__construct(); }
public function renderList() { $this->toolbar_title = $this->l('Order Management'); $statuses_array = array(); $statuses = ErpOrderState::getOrderStates((int) $this->context->language->id); foreach ($statuses as $status) { $statuses_array[$status['id_order_state']] = $status['name']; } require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php'; $this->context->smarty->assign(array('token_mr' => ModuleCore::isEnabled('mondialrelay') ? MondialRelay::getToken('back') : 'false', 'token_expeditor' => ModuleCore::isEnabled('expeditor') ? Tools::getAdminToken('AdminExpeditor' . (int) Tab::getIdFromClassName('AdminExpeditor') . (int) $this->context->employee->id) : 'false', 'id_employee' => (int) $this->context->employee->id, 'order_statuses' => $statuses_array, 'controller_status' => $this->controller_status, 'erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path, 'expeditor_status' => Configuration::get('EXPEDITOR_STATE_EXP'), '_module_dir_' => _MODULE_DIR_)); $this->tpl_list_vars['has_bulk_actions'] = 'true'; // handle may contain error messages $handle = Tools::getValue('handle'); switch (trim($handle)) { case '': break; case 'false': $this->confirmations[] = $this->l('All orders have been updated') . '<br/>'; break; default: if (!empty($handle)) { // $handle = str_replace('u00e9', 'é', $handle); // $handle = str_replace('u00ea', 'ê', $handle); $handle = Tools::replaceAccentedChars($handle); // We take note about orders with error: no valid carrier (split on order number #) $orderWithoutShipping = strstr($handle, '#') != false ? true : false; $errors = explode('<br/>', str_replace('#', '<br/>', $handle)); foreach ($errors as $key => $error) { if (!empty($error)) { if (!$orderWithoutShipping) { $message = $error; } else { $message = $error; } $this->errors[] = Tools::displayError($message); } } } break; } if (Tools::getValue('linkPDF') != '' && Tools::getValue('newState') != '') { // if state need invoice generation if (ErpOrderState::invoiceAvailable(Tools::getValue('newState'))) { $pdf_link = new Link(); $pdf_link = $pdf_link->getAdminLink("AdminAdvancedOrder", true) . '&submitAction=generateInvoicesPDF3&id_orders=' . Tools::getValue('linkPDF'); $this->confirmations[] = ' <a target="_blank" href="' . $pdf_link . '" alt="invoices">' . $this->l('Download all invoices') . '<br/></a>'; } // if state need delivery slip generation if (ErpOrderState::deliverySlipAvailable(Tools::getValue('newState'))) { $pdf_link = new Link(); $pdf_link = $pdf_link->getAdminLink("AdminAdvancedOrder", true) . '&submitAction=generateDeliverySlipsPDF2&id_orders=' . Tools::getValue('linkPDF'); $this->confirmations[] = ' <a target="_blank" href="' . $pdf_link . '" alt="delivery">' . $this->l('Download all delivery slip') . '<br/></a>'; } } if (Tools::getValue('linkPDFPrint') != '') { if ($this->controller_status == STATUS1 && count(explode(',', Tools::getValue('linkPDFPrint'))) > ERP_ORDERFR) { $this->informations[] = sprintf($this->l('You are using the free version of 1-Click ERP which limits the possible number of documents to print to %d orders'), ERP_ORDERFR); } else { $invoices = ''; $delivery = ''; foreach (explode(',', Tools::getValue('linkPDFPrint')) as $id_order) { if (ErpOrderState::invoiceAvailable(ErpOrder::getIdStateByIdOrder($id_order))) { $invoices .= $id_order . ','; } if (ErpOrderState::deliverySlipAvailable(ErpOrder::getIdStateByIdOrder($id_order))) { $delivery .= $id_order . ','; } } if ($invoices != '') { $pdf_link = new Link(); $pdf_link = $pdf_link->getAdminLink("AdminAdvancedOrder", true) . '&submitAction=generateInvoicesPDF3&id_orders=' . Tools::substr($invoices, 0, -1); $this->confirmations[] = ' <a target="_blank" href="' . $pdf_link . '" alt="invoices">' . $this->l('Download all invoices') . '</br></a>'; } if ($delivery != '') { $pdf_link = new Link(); $pdf_link = $pdf_link->getAdminLink("AdminAdvancedOrder", true) . '&submitAction=generateDeliverySlipsPDF2&id_orders=' . Tools::substr($delivery, 0, -1); $this->confirmations[] = ' <a target="_blank" href="' . $pdf_link . '" alt="delivery">' . $this->l('Download all delivery slip') . '</br></a>'; } if ($invoices == '' && $delivery == '') { $this->errors[] = $this->l('The selected orders have no invoice or delivery !') . '<br/>'; } } } if (Tools::getValue('etiquettesMR') != '') { // Downlad all pdf and zip then delete and display link to zip file $etiquettesMR = explode(' ', Tools::getValue('etiquettesMR')); unset($etiquettesMR[count($etiquettesMR) - 1]); $zipPath = '../modules/erpillicopresta/export/mondialrelay.zip'; $zip = new ZipArchive(); if ($zip->open($zipPath, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) { throw new Exception($this->l('Impossible to create the zip archive containing the shipping labels to Mondial Relay carrier !') . '<br/>'); } foreach ($etiquettesMR as $key => $i) { $zip->addFromString('mondialrelay_' . $key . '.pdf', Tools::file_get_contents($i)); } $zip->close(); //Display link to dl zip file $this->confirmations[] = ' <a target="_blank" href="' . $zipPath . '" alt="zip_file">' . $this->l('Download zip archive which contents all labels for Mondial Relay shipment') . '<br/></a>'; if (Tools::getValue('deliveryNumbersMR') != '') { // Get all tracking numbers $numbers = explode(" ", Tools::getValue('deliveryNumbersMR')); unset($numbers[count($numbers) - 1]); foreach ($numbers as $number) { $tabNumber = explode("-", $number); $order_carrier = new OrderCarrier(ErpOrder::getIdCarrierbyIdOrder((int) $tabNumber[1])); $order = new ErpOrder((int) $tabNumber[1]); // Update carrier $order->shipping_number = $tabNumber[0]; $order->update(); // Update order_carrier $order_carrier->tracking_number = pSQL($tabNumber[0]); $order_carrier->update(); } } } if (Tools::getValue('expeditorCSV') != '') { // CSV file creation $csvPath = '../modules/erpillicopresta/export/expeditor_inet.csv'; $fileCSV = fopen($csvPath, 'w'); // Fill in file fwrite($fileCSV, str_replace(',', '', Tools::getValue('expeditorCSV'))); //Close fclose($fileCSV); // link creation $this->confirmations[] = ' <a target="_blank" href="' . $csvPath . '" alt="csv_file">' . $this->l('Download export file (CSV) for ExpeditorInet') . '</br></a>'; } if (Tools::getValue('idOthers') != '') { //BEGIN Initialisations for TNT if (Module::isEnabled('tntcarrier')) { $TNTCheck = false; require_once _PS_MODULE_DIR_ . '/tntcarrier/classes/PackageTnt.php'; if (class_exists('ZipArchive', false) && ($tnt_zip = new ZipArchive())) { // Protection du ZIP $dateday = new DateTime(); $uniqid_file = uniqid('file_'); $token = md5($dateday->getTimestamp() . $uniqid_file); // Put all tnt pdf into a zip $tnt_zip_path = 'erpillicopresta/export/tnt_' . date('Y-m-d_His') . '_' . $uniqid_file . $token . '.zip'; if ($tnt_zip->open(_PS_MODULE_DIR_ . $tnt_zip_path, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE) !== true) { $this->errors[] = Tools::displayError($this->l('Failed to create a ZIP archive containing the shipping labels to TNT carrier !') . '<br/>'); } else { // one or several id orders $id_others_order_array = strpos(Tools::getValue('idOthers'), ',') !== false ? explode(',', Tools::getValue('idOthers')) : (int) Tools::getValue('idOthers'); // Browse all orders not in ExpeditorInet nor MondialRelay foreach ((array) $id_others_order_array as $i => $id_order) { // BEGIN Commande TNT $id_order = (int) $id_order; if (ErpOrder::isTntOrder($id_order)) { // status change $currOrder = new ErpOrder($id_order); $currOrder->setCurrentState(4, $this->context->employee->id); // Start to check that weight order is valid if not tnt crash ! //echo($data['poid'] * 1000);die; // Get tracking number : dedicated class created for this action // Execution of the hook generating the tracking number at an order opening ... So ctrl c / ctrl v to execute here /*$erp_tntCarrier = new ErpTntCarrier(); $generate = $erp_tntCarrier->generateShipping($id_order);*/ $generateShipping = Hook::exec('adminOrder', array('id_order' => $id_order)); $tnt = new PackageTnt($id_order); $tntNumber = $tnt->getShippingNumber(); if (count($tntNumber) == 0) { $this->errors[] = Tools::displayError($this->l('Failed to get shipping number from TNT services : you have to fit the weight of the order.')); continue; } $tntNumber = $tntNumber[0]['shipping_number']; // Update order $order_carrier = new OrderCarrier(ErpOrder::getIdCarrierbyIdOrder((int) $id_order)); $order = new ErpOrder((int) $id_order); $order->shipping_number = $tntNumber; $order->update(); $order_carrier->tracking_number = pSQL($tntNumber); $order_carrier->update(); // Add pdf to zip $tnt_zip->addFile(_PS_MODULE_DIR_ . '/tntcarrier/pdf/' . $tntNumber . '.pdf', $tntNumber . '.pdf'); $TNTCheck = true; } // END Order TNT // SPLICE idOther if (is_array($id_others_order_array)) { unset($id_others_order_array[$i]); } else { unset($id_others_order_array); } } //Display dl zip link $tnt_zip->close(); if ($TNTCheck) { $this->confirmations[] = ' <a target="_blank" href="' . _MODULE_DIR_ . $tnt_zip_path . '" alt="zip_file">' . $this->l('Download zip archive which contents all labels for TNT shipment') . '<br/></a>'; } } } else { $this->errors[] = Tools::displayError($this->l('Class ZipArchive does not exist !') . '<br/>'); } //END Initialisations for TNT } // Display for order not processed : idothers if (isset($id_others_order_array)) { if (count($id_others_order_array) == 1) { //var_dump($id_others_order_array);die(); if (is_array($id_others_order_array)) { $id_others_order_array = $id_others_order_array[1]; } $this->errors[] = Tools::displayError($this->l('The following order has not been processed : order #') . $id_others_order_array . '. ' . $this->l('Please make sure that the carrier is either TNT, ExpeditorInet, or MondialRelay and that the order fits the carrier requirements.')); } elseif (count($id_others_order_array) > 1) { $this->errors[] = Tools::displayError($this->l('The following orders have not been processed : orders #') . implode(", ", $id_others_order_array) . '. ' . $this->l('Please make sure that the carrier is either TNT, ExpeditorInet, or MondialRelay and that the orders fit the carrier requirements.')); } } } return parent::renderList(); }
public function renderForm() { $feature = ErpFeature::getFeatureById((int) Tools::getValue('id_erpip_feature'), $this->context->language->iso_code); Tools::redirectAdmin($this->context->link->getAdminLink($feature['controller'])); }
public function uninstallModuleTabs() { // uninstall module tabs only if the module is installed // else,module tables do not exist if (Module::isInstalled('erpillicopresta')) { // get controllers list $erp_features = ErpFeature::getFeatures($this->context->language->iso_code); if (!empty($erp_features)) { foreach ($erp_features as $feature) { $id_tab = Tab::getIdFromClassName($feature['controller']); if ($id_tab != 0) { $tab = new Tab($id_tab); if (!$tab->delete()) { $this->_errors[] = $this->l('Error while uninstalling module tabs !'); } } // get controller status name $controller_status_name = self::getControllerStatusName($feature['controller']); // save feature statut Configuration::deleteByName($controller_status_name); } } } return true; }
/** * AdminController::postProcess() override * @see AdminController::postProcess() */ public function postProcess() { require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php'; $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path)); if (Tools::isSubmit('export_csv')) { $this->renderCSV(); } // checks access if (Tools::isSubmit('submitAdd' . $this->table) && !($this->tabAccess['add'] === '1')) { $this->errors[] = Tools::displayError($this->l('You do not have permission to add suppliers.')); return parent::postProcess(); } if (Tools::isSubmit('submitAdd' . $this->table)) { if (Tools::isSubmit('id_supplier') && !($obj = $this->loadObject(true))) { return; } // updates/creates address if it does not exist if (Tools::isSubmit('id_address') && (int) Tools::getValue('id_address') > 0) { $address = new Address((int) Tools::getValue('id_address')); } else { $address = new Address(); } // creates address $address->alias = Tools::getValue('name', null); $address->lastname = 'supplier'; // skip problem with numeric characters in supplier name $address->firstname = 'supplier'; // skip problem with numeric characters in supplier name $address->address1 = Tools::getValue('address', null); $address->address2 = Tools::getValue('address2', null); $address->postcode = Tools::getValue('postcode', null); $address->phone = Tools::getValue('phone', null); $address->id_country = Tools::getValue('id_country', null); $address->id_state = Tools::getValue('id_state', null); $address->city = Tools::getValue('city', null); $validation = $address->validateController(); // checks address validity if (count($validation) > 0) { foreach ($validation as $item) { $this->errors[] = $item; } $this->errors[] = Tools::displayError($this->l('The address is not correct. Please make sure all of the required fields are completed.')); } else { if (Tools::isSubmit('id_address') && Tools::getValue('id_address') > 0) { $address->update(); } else { $address->save(); $_POST['id_address'] = $address->id; } } //--ERP informations // updates/creates erp_supplier if it does not exist if (Tools::isSubmit('id_erpip_supplier') && (int) Tools::getValue('id_erpip_supplier') > 0) { $erp_supplier = new ErpSupplier((int) Tools::getValue('id_erpip_supplier')); } else { $erp_supplier = new ErpSupplier(); } // creates erp_supplier $erp_supplier->email = Tools::getValue('email', null); $erp_supplier->fax = Tools::getValue('fax', null); $erp_supplier->franco_amount = Tools::getValue('franco_amount', null); $erp_supplier->discount_amount = Tools::getValue('discount_amount', null); $erp_supplier->shipping_amount = Tools::getValue('shipping_amount', null); $erp_supplier->escompte = Tools::getValue('escompte', null); $erp_supplier->delivery_time = Tools::getValue('delivery_time', null); $erp_supplier->account_number_accounting = Tools::getValue('account_number_accounting', null); $validation2 = $erp_supplier->validateController(); //print_r($validation2); // checks erp_supplier validity if (count($validation2) > 0) { foreach ($validation2 as $item) { $this->errors[] = $item; } $this->errors[] = Tools::displayError($this->l('The ErpIllicopresta Supplier is not correct. Please make sure all of the required fields are completed.')); } else { if (Tools::isSubmit('id_erpip_supplier') && Tools::getValue('id_erpip_supplier') > 0) { $erp_supplier->update(); } else { $erp_supplier->save(); $_POST['id_erpip_supplier'] = $erp_supplier->id; } } return parent::postProcess(); } else { if (Tools::isSubmit('delete' . $this->table)) { if (!($obj = $this->loadObject(true))) { return; } else { if (SupplyOrder::supplierHasPendingOrders($obj->id)) { $this->errors[] = $this->l('It is not possible to delete a supplier if there are pending supplier orders.'); } else { //delete all product_supplier linked to this supplier Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'product_supplier` WHERE `id_supplier`=' . (int) $obj->id); $id_address = Address::getAddressIdBySupplierId($obj->id); $address = new Address($id_address); if (Validate::isLoadedObject($address)) { $address->deleted = 1; $address->save(); } //delete erp supplier $id_erpip_supplier = ErpSupplier::getErpSupplierIdBySupplierId($obj->id); $erp_supplier = new ErpSupplier($id_erpip_supplier); if (Validate::isLoadedObject($erp_supplier)) { $erp_supplier->delete(); } return parent::postProcess(); } } } else { return parent::postProcess(); } } }
public function __construct() { $this->bootstrap = true; $this->context = Context::getContext(); $this->table = 'supply_order'; $this->className = 'SupplyOrder'; $this->identifier = 'id_supply_order'; $this->lang = false; $this->is_template_list = false; $this->multishop_context = Shop::CONTEXT_ALL; // get controller status $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedSupplyOrder')); if ($this->controller_status == STATUS1) { $sql = 'SELECT count(*) from ' . _DB_PREFIX_ . 'erpip_supply_order'; $query = new DbQuery(); $query->select('count(distinct so.id_supply_order)'); $query->from('erpip_supply_order', 'so'); $query->innerJoin('supply_order', 's', 'so.id_supply_order = s.id_supply_order'); $query->where("s.date_add >= '" . pSQL(Configuration::get('ERP_FIRST_INSTALL_DATE')) . "'"); $this->nbcmdfou = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); } // template path for avdanced supply ordr $this->template_path = _PS_MODULE_DIR_ . 'erpillicopresta/views/templates/admin/'; $this->toolbar_title = $this->l('1 Click ERP ILLICOPRESTA'); //get if advanced stock enabled $this->advanced_stock_management = Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT'); $this->is_1_6 = version_compare(_PS_VERSION_, '1.6') > 0; $this->token = Tools::getAdminToken('AdminAdvancedSupplyOrder' . (int) Tab::getIdFromClassName('AdminAdvancedSupplyOrder') . (int) $this->context->employee->id); $this->addRowAction('updatereceipt'); $this->addRowAction('changestate'); $this->addRowAction('edit'); $this->addRowAction('view'); $this->addRowAction('details'); $this->list_no_link = true; $statuses_array = array(); $statuses = SupplyOrderState::getSupplyOrderStates((int) $this->context->language->id); foreach ($statuses as $status) { $statuses_array[$status['id_supply_order_state']] = $status['name']; } $this->fields_list = array('id_supply_order' => array('title' => 'ID', 'width' => 100, 'search' => false, 'havingFilter' => false, 'orderby' => true, 'callback' => 'renderIdSupplyOrderColumn'), 'reference' => array('title' => $this->l('Reference'), 'width' => 100, 'havingFilter' => true, 'callback' => 'renderReferenceColumn'), 'with_description' => array('title' => $this->l('Description'), 'width' => 25, 'align' => 'center', 'class' => 'view_description', 'callback' => 'renderWithDescriptionColumn', 'search' => false, 'orderby' => false)); if ($this->controller_status) { $this->fields_list = array_merge($this->fields_list, array('invoice_number' => array('title' => $this->l('Invoice Number'), 'width' => 100, 'havingFilter' => true), 'date_to_invoice' => array('title' => $this->l('Invoice Date'), 'width' => 100, 'type' => 'date', 'havingFilter' => true))); } $this->fields_list = array_merge($this->fields_list, array('supplier' => array('title' => $this->l('Supplier'), 'width' => 100, 'filter_key' => 's!name'), 'warehouse' => array('title' => $this->l('Warehouse'), 'width' => 100, 'filter_key' => 'w!name'), 'state' => array('title' => $this->l('Status'), 'color' => 'color', 'width' => 150, 'type' => 'select', 'list' => $statuses_array, 'filter_key' => 'stl!name', 'filter_type' => 'int', 'color' => 'color', 'callback' => 'renderSupplyOrderStatesColumn'), 'date_add' => array('title' => $this->l('Creation'), 'width' => 150, 'align' => 'left', 'type' => 'date', 'havingFilter' => true, 'filter_key' => 'a!date_add'), 'date_upd' => array('title' => $this->l('Last modification'), 'width' => 150, 'align' => 'left', 'type' => 'date', 'havingFilter' => true, 'filter_key' => 'a!date_upd'), 'date_delivery_expected' => array('title' => $this->l('Expected delivery date'), 'width' => 150, 'align' => 'left', 'type' => 'date', 'havingFilter' => true, 'filter_key' => 'a!date_delivery_expected'), 'id_export' => array('title' => $this->l('Export'), 'width' => 80, 'callback' => 'printExportIcons', 'orderby' => false, 'search' => false))); // gets the list of warehouses available $this->warehouses = Warehouse::getWarehouses(true); // gets the final list of warehouses array_unshift($this->warehouses, array('id_warehouse' => -1, 'name' => $this->l('All warehouses'))); require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php'; // send var to template $this->context->smarty->assign(array('is_1_6' => $this->is_1_6, 'erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'inheritance_merge_compiled_includes' => false)); // get controller status $this->controller_status = Configuration::get(ErpIllicopresta::getControllerStatusName('AdminAdvancedOrder')); parent::__construct(); }
public function postProcess() { // record all order unselected $this->saveUnselectedOrders(); // Export PDF of supply order if (Tools::isSubmit('submitAction') && Tools::getValue('submitAction') == 'generateSupplyOrderFormPDF') { $this->processGenerateSupplyOrderFormPDF(); } require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php'; $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path)); parent::postProcess(); }
public function postProcess() { // Warehouse $warehouses = Warehouse::getWarehouses(true); // if we already pick a warehouse source and location, we filter on twice to not display selections of the other if (Tools::isSubmit('warehouseA') && Tools::getValue('warehouseA') != -1 && Tools::isSubmit('warehouseB') && Tools::getValue('warehouseB') != -1) { $warehouseA = Tools::getValue('warehouseA'); $warehouseB = Tools::getValue('warehouseB'); $warehousesA = array(); $warehousesB = array(); foreach ($warehouses as $warehouse) { if ($warehouse['id_warehouse'] != $warehouseA) { array_push($warehousesB, $warehouse); } if ($warehouse['id_warehouse'] != $warehouseB) { array_push($warehousesA, $warehouse); } } } elseif (Tools::isSubmit('warehouseA') && Tools::getValue('warehouseA') != -1) { $warehouseA = Tools::getValue('warehouseA'); $warehousesB = array(); foreach ($warehouses as $warehouse) { if ($warehouse['id_warehouse'] != $warehouseA) { array_push($warehousesB, $warehouse); } } $warehousesA = $warehouses; // Restaure B list on no selection $this->context->smarty->assign(array('warehouseB' => -1)); } elseif (Tools::isSubmit('warehouseB') && Tools::getValue('warehouseB') != -1) { $warehouseB = Tools::getValue('warehouseB'); $warehousesA = array(); foreach ($warehouses as $warehouse) { if ($warehouse['id_warehouse'] != $warehouseB) { array_push($warehousesA, $warehouse); } } $warehousesB = $warehouses; } else { $warehousesA = $warehouses; $warehousesB = $warehouses; } // validate_transfer if (Tools::isSubmit('validate_transfer')) { $transfer_ok = false; if (Tools::isSubmit('id_stockA') && Tools::isSubmit('id_stockB') && Tools::isSubmit('id_employee') && Tools::isSubmit('firstname') && Tools::isSubmit('lastname') && Tools::isSubmit('values')) { // After transfert, delete cookies to get a blank display if (Tools::isSubmit('deleteCookie')) { $cookie = new Cookie('psAdmin'); $cookie->warehouseA = ''; $cookie->warehouseB = ''; } /* Initialisation */ $ids_mvt = array(); // Call the helper "traducteur" of the chain transfert require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/helpers/StockTransferHelper.php'; require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/stock/ErpStock.php'; $values = StockTransferHelper::getTransfertDataAsArray(Tools::getValue('values')); /* For each movement recorded */ foreach ($values as $value) { $id_product = $value['id_product']; $id_product_attribute = $value['id_product_attribute']; $transfer_quantity = $value['quantity']; $id_stock_s1 = $value['id_stock_s1']; $id_stock_s2 = $value['id_stock_s2']; if (empty($id_stock_s1)) { $this->errors[] = 'Error while updating the stock for a product : stock id missing !'; return true; } // update stock un warehouse A (source) $stock = new ErpStock((int) $id_stock_s1); $stock->physical_quantity -= $transfer_quantity; $stock->usable_quantity -= $transfer_quantity; if ($stock->physical_quantity < 0) { $stock->physical_quantity = 0; } if ($stock->usable_quantity < 0) { $stock->usable_quantity = 0; } /* Update Stock */ if ($stock->update()) { /* Movment A to B */ $stock_mvt = new ErpStockMvt(); $stock_mvt->id_stock = $stock->id; $stock_mvt->id_order = 0; $stock_mvt->id_supply_order = 0; $stock_mvt->id_stock_mvt_reason = 6; $stock_mvt->id_employee = Tools::getValue('id_employee'); $stock_mvt->employee_firstname = Tools::getValue('firstname'); $stock_mvt->employee_lastname = Tools::getValue('lastname'); $stock_mvt->price_te = $stock->getPriceTe(); $stock_mvt->current_wa = $stock->getPriceTe(); $stock_mvt->sign = -1; $stock_mvt->physical_quantity = $transfer_quantity; // if movment OK, update stock in B warehouse (location) if ($stock_mvt->add(true)) { // add id movment stock generated (useful to generate the warehouse delivery notice) array_push($ids_mvt, $stock_mvt->getLastId()); if ((int) $id_stock_s2 > 0) { $stock_s2 = new ErpStock((int) $id_stock_s2); $stock_s2->physical_quantity += $transfer_quantity; $stock_s2->usable_quantity += $transfer_quantity; } else { require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/ErpProduct.php'; //get product information $product_stock = new ProductCore((int) $id_product, (int) $id_product_attribute); // stock not existe we add row in stock table $stock_s2 = new ErpStock(); $stock_s2->physical_quantity += $transfer_quantity; $stock_s2->usable_quantity += $transfer_quantity; $stock_s2->id_product = (int) $id_product; $stock_s2->id_product_attribute = (int) $id_product_attribute; $stock_s2->id_warehouse = (int) Tools::getValue('id_stockB'); $stock_s2->price_te = $product_stock->wholesale_price; $stock_s2->ean13 = $product_stock->ean13; $stock_s2->upc = $product_stock->upc; } /* of OK, movment from B to A */ if ($stock_s2->save()) { $stock_mvt->id_stock = $stock_s2->id; $stock_mvt->id_stock_mvt_reason = 7; $stock_mvt->sign = 1; // add id movment stock generated (useful to generate warehouse inter delivery) if ($stock_mvt->add(true)) { array_push($ids_mvt, $stock_mvt->getLastId()); } else { $this->errors[] = 'Error while updating the stock for a product'; } } else { $this->errors[] = 'Error while updating the stock for a product'; } } else { $this->errors[] = 'Error while updating the stock for a product'; } } else { $this->errors[] = 'Error while updating the stock for a product'; } // synchronize availbale stock ::quantity StockAvailable::synchronize($id_product); } $ids_mvt = implode('|', $ids_mvt); // we reset values $transfer_ok = true; } } // transfer is ok, we redirect the user to home page of transfer if (Tools::isSubmit('validate_transfer') && isset($transfer_ok) && $transfer_ok) { $url_redirect = self::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminStockTransfer'); $url_redirect .= '&validate_transfer&ids_mvt=' . $ids_mvt . '&ids_mvt_csv=' . Tools::getValue('ids_mvt_csv'); $url_redirect .= '&id_warehouse_src=' . Tools::getValue('id_warehouse_src') . '&id_warehouse_dst=' . Tools::getValue('id_warehouse_dst'); Tools::redirectAdmin($url_redirect); } if (Tools::isSubmit('ids_mvt_csv') && Tools::isSubmit('get_csv_transfer')) { $this->renderCSV(); } // Generate PDF of tranfert if (Tools::isSubmit('ids_mvt') && Tools::isSubmit('action') && Tools::getValue('action') == 'generateTransferPDF') { $this->processGenerateTransferPDF(); } // to get erp feature list require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php'; // send warehouse liste to template $this->context->smarty->assign(array('warehousesA' => $warehousesA, 'warehousesB' => $warehousesB, 'categories' => Category::getSimpleCategories((int) $this->context->language->id), 'suppliers' => Supplier::getSuppliers(), 'manufacturers' => Manufacturer::getManufacturers(), 'id_category' => -1, 'id_supplier' => -1, 'id_manufacturer' => -1, 'name_or_ean' => '', 'erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path)); }
public function postProcess() { if (Tools::isSubmit('submitFilterconfiguration')) { // get an array with first paramettre id_product, second paramettre id_product attribute, third area // fourth id_wharehouse_product_location, fifth id_erpip_warhouse_product_location $areas = Tools::getValue('data_location'); if (!empty($areas) && is_array($areas)) { foreach ($areas as $id_product => $product) { foreach ($product as $id_attribute => $attribute) { // data already exists in warehouse product location table if (!empty($attribute['id_warehouse_product_location']) && $attribute['id_warehouse_product_location'] != '0') { $warehouse = new WarehouseProductLocationCore((int) $attribute['id_warehouse_product_location']); } else { $warehouse = new WarehouseProductLocationCore(); $warehouse->id_product = (int) $id_product; $warehouse->id_product_attribute = (int) $id_attribute; $warehouse->id_warehouse = (int) Tools::getValue('id_warehouse'); } //save location $warehouse->location = empty($attribute['location']) ? null : $attribute['location']; $warehouse->save(); // data not exists in ERP warehouse product location table if ($attribute['id_erpip_warehouse_product_location'] == '0') { $erp_warehouse = new ErpWarehouseProductLocation(); } else { $erp_warehouse = new ErpWarehouseProductLocation((int) $attribute['id_erpip_warehouse_product_location']); } // save area and sub area $erp_warehouse->id_warehouse_product_location = (int) $warehouse->id; $erp_warehouse->id_zone_parent = empty($attribute['area']) ? null : (int) $attribute['area']; //id_zone_parent = area $erp_warehouse->id_zone = empty($attribute['sub_area']) ? null : (int) $attribute['sub_area']; //id_zone = sub_area $erp_warehouse->save(); } } $this->confirmations[] = $this->l('Locations updated successfully'); } } if (Tools::isSubmit('createImageStock')) { // list of stock images $images = Tools::getValue('images'); if (!empty($images) && is_array($images)) { foreach ($images as $image) { //if isset id_image then this is the selected images stock if (isset($image['id_stock_image'])) { $stock_image = new StockImage(); $stock_image->createImage((int) $image['id_stock_image'], $image['name_stock_image']); break; } } } } //Display Information or confirmation message / error of end of inventory switch (Tools::getValue('submitFilterstock')) { case 0: $this->displayInformation($this->l('You may create a new stock image or select an older one')); break; case 1: $this->confirmations[] = $this->l('New image saved'); break; case 2: $this->errors[] = Tools::displayError('Error while handling products'); break; default: $this->displayInformation($this->l('You may create a new stock image or select an older one')); break; } // Stock image selection $this->context->smarty->assign(array('images' => StockImage::getStockImages(), 'pack' => ERP_SLOT_IPTIMEMACHINE, 'id_warehouse' => Tools::getValue('id_warehouse'))); $this->getCurrentValue('id_image'); // Get context link and display toolbar $this->context_link = $this->context->link; $this->initToolbar(); $this->initPageHeaderToolbar(); require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php'; $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path)); return parent::postProcess(); }
public function postProcess() { require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php'; $this->context->smarty->assign(array('erp_feature' => ErpFeature::getFeaturesWithToken($this->context->language->iso_code), 'template_path' => $this->template_path)); // Export CSV if (Tools::isSubmit('export_csv')) { $this->renderCSV(); } parent::postProcess(); }
public function renderList() { $this->toolbar_title = $this->l('Products list'); if (Tools::isSubmit('id_display')) { self::$currentIndex .= '&id_display=' . (int) Tools::getValue('id_display'); } if (Tools::isSubmit('id_warehouse') && Tools::getValue('id_warehouse') != '-1') { self::$currentIndex .= '&id_warehouse=' . (int) Tools::getValue('id_warehouse'); } if (Tools::isSubmit('areaFilter')) { self::$currentIndex .= '&areaFilter=' . Tools::getValue('areaFilter'); } if (Tools::isSubmit('subareaFilter')) { self::$currentIndex .= '&subareaFilter=' . Tools::getValue('subareaFilter'); } if (Tools::isSubmit('id_category') && Tools::getValue('id_category') != '-1') { self::$currentIndex .= '&id_category=' . (int) Tools::getValue('id_category'); } if (Tools::isSubmit('id_supplier') && Tools::getValue('id_supplier') != '-1') { self::$currentIndex .= '&id_supplier=' . (int) Tools::getValue('id_supplier'); } if (Tools::isSubmit('id_manufacturer') && Tools::getValue('id_manufacturer') != '-1') { self::$currentIndex .= '&id_manufacturer=' . (int) Tools::getValue('id_manufacturer'); } // Get display type $id_display = $this->getCurrentValue('id_display'); // qubquery : return the first provider reference for principal product $this->_select = ' cl.name as category_name, i.id_image, a.id_product as mvt_reason, area.name as area_name, sub_area.name as sub_area_name, wpl.location as location, a.id_product as new_quantity, ( SELECT ps.product_supplier_reference FROM ' . _DB_PREFIX_ . 'product_supplier ps WHERE ps.id_product = a.id_product AND ps.id_product_attribute = 0 LIMIT 1 )as first_supplier_ref, ( EXISTS(SELECT pa.id_product FROM ' . _DB_PREFIX_ . 'product_attribute pa WHERE pa.id_product = a.id_product LIMIT 1) ) as have_attribute, '; $this->_join = ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON (pa.id_product = a.id_product)' . 'INNER JOIN ' . _DB_PREFIX_ . 'product_lang pl ON (a.id_product = pl.id_product AND pl.id_lang = ' . (int) $this->context->language->id . ') INNER JOIN ' . _DB_PREFIX_ . 'category_lang cl ON (a.id_category_default = cl.id_category AND cl.id_lang = ' . (int) $this->context->language->id . ') LEFT JOIN ' . _DB_PREFIX_ . 'image i ON a.id_product = i.id_product '; $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'warehouse_product_location wpl ON (wpl.id_product = a.id_product AND wpl.id_product_attribute = IFNULL(pa.id_product_attribute, 0))'; $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'erpip_warehouse_product_location ewpl ON wpl.id_warehouse_product_location = ewpl.id_warehouse_product_location '; $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'erpip_zone area ON area.id_erpip_zone = ewpl.id_zone_parent '; $this->_join .= ' LEFT JOIN ' . _DB_PREFIX_ . 'erpip_zone sub_area ON sub_area.id_erpip_zone = ewpl.id_zone '; // Render 1 : mix products and declination to sort by area if ($id_display == 1) { $this->_select .= 'IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(DISTINCT agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as product_name, IFNULL((CONCAT(a.id_product, ";", pa.id_product_attribute)), a.id_product) as id_product,'; $this->_join .= ' LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute_combination` pac ON (pac.id_product_attribute = pa.id_product_attribute) LEFT JOIN `' . _DB_PREFIX_ . 'attribute` atr ON (atr.id_attribute = pac.id_attribute) LEFT JOIN `' . _DB_PREFIX_ . 'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = ' . (int) $this->context->language->id . ') LEFT JOIN `' . _DB_PREFIX_ . 'attribute_group_lang` agl ON (agl.id_attribute_group = atr.id_attribute_group AND agl.id_lang = ' . (int) $this->context->language->id . ') '; } else { $this->_select .= 'pl.name as product_name,'; } $this->tpl_list_vars['advanced_stock_token'] = $this->advanced_stock_token; // FILTERS // Init filters variables $this->tpl_list_vars['id_category'] = -1; $this->tpl_list_vars['id_supplier'] = -1; $this->tpl_list_vars['id_manufacturer'] = -1; $this->tpl_list_vars['id_warehouse'] = -1; $this->tpl_list_vars['areaFilter'] = -1; $this->tpl_list_vars['subareaFilter'] = -1; $this->tpl_list_vars['id_display'] = 0; // Add additional filters $this->tpl_list_vars['warehouses'] = Warehouse::getWarehouses(); $this->tpl_list_vars['categories'] = Category::getSimpleCategories((int) $this->context->language->id); $this->tpl_list_vars['suppliers'] = Supplier::getSuppliers(); $this->tpl_list_vars['manufacturers'] = Manufacturer::getManufacturers(); $this->tpl_list_vars['controller_status'] = $this->controller_status; // Get inventory containers $this->tpl_list_vars['containers'] = ErpInventory::getContainers(); // get conf stock gap $this->tpl_list_vars['gap_stock'] = Configuration::getGlobalValue('ERP_GAP_STOCK'); require_once _PS_MODULE_DIR_ . 'erpillicopresta/models/ErpFeature.php'; $this->tpl_list_vars['erp_feature'] = ErpFeature::getFeaturesWithToken($this->context->language->iso_code); $this->tpl_list_vars['template_path'] = $this->template_path; // get default inventory reasons if ($this->context->language->iso_code == 'fr') { $this->tpl_list_vars['reason_increase'] = ErpStockMvtReason::existsByName('Augmentation d\'inventaire'); $this->tpl_list_vars['reason_decrease'] = ErpStockMvtReason::existsByName('Diminution d\'inventaire'); } else { $this->tpl_list_vars['reason_increase'] = ErpStockMvtReason::existsByName('Increase of inventory'); $this->tpl_list_vars['reason_decrease'] = ErpStockMvtReason::existsByName('Decrease of inventory'); } // specify advanced stock manager or not if ($this->advanced_stock_management) { // Get the selected warehouse, if there's not, get the first one if (($id_warehouse = $this->getCurrentValue('id_warehouse')) == false) { $id_warehouse = $this->getCookie('id_warehouse'); $this->tpl_list_vars['id_warehouse'] = $id_warehouse; } // filters warehouse location $area = $this->getCurrentValue('areaFilter'); $subarea = $this->getCurrentValue('subareaFilter'); $this->tpl_list_vars['areas'] = ErpZone::getZonesName($id_warehouse); $this->tpl_list_vars['sub_areas'] = $area ? ErpZone::getZonesName($id_warehouse, 'sub_area', $area) : array(); // if an area AND an under area are specified, we filter the area and the under area for the specified area if ($area != false && $subarea != false) { $this->_where .= ' AND wpl.id_warehouse = ' . (int) $id_warehouse . ' AND area.id_erpip_zone = "' . (int) $area . '" AND sub_area.id_erpip_zone = ' . (int) $subarea; $this->_group = 'GROUP BY a.id_product'; } elseif ($area != false) { $this->_where .= ' AND wpl.id_warehouse=' . (int) $id_warehouse . ' AND area.id_erpip_zone = ' . (int) $area; //$this->_where .= ' AND area.id_erpip_zone = '.(int)$area; if ($id_display == 1) { $this->_group = 'GROUP BY a.id_product, pa.id_product_attribute'; } else { $this->_group = 'GROUP BY a.id_product'; } } else { $this->_where .= ' AND wpl.id_warehouse = ' . (int) $id_warehouse; if ($id_display == 1) { $this->_group = 'GROUP BY a.id_product, pa.id_product_attribute'; } else { $this->_group = 'GROUP BY a.id_product'; } } } else { if ($id_display == 1) { $this->_group = 'GROUP BY a.id_product, pa.id_product_attribute'; } else { $this->_group = 'GROUP BY a.id_product'; } } // filter the query with applied filters //category filter if (($id_category = $this->getCurrentValue('id_category')) != false) { $this->_where .= ' AND a.id_product IN ( SELECT cp.id_product FROM ' . _DB_PREFIX_ . 'category_product cp WHERE cp.id_category = ' . (int) $id_category . ' )'; } // provider filter if (($id_supplier = $this->getCurrentValue('id_supplier')) != false) { $this->_where .= ' AND a.id_product IN ( SELECT ps.id_product FROM ' . _DB_PREFIX_ . 'product_supplier ps WHERE ps.id_supplier = ' . (int) $id_supplier . ' )'; } // Brand filter if (($id_manufacturer = $this->getCurrentValue('id_manufacturer')) != false) { $this->_where .= ' AND a.id_manufacturer = ' . (int) $id_manufacturer; } $this->displayInformation($this->l('Be careful, if you are using advanced [respectively simple] stock management, only products using advanced [respectively simple] stock management will be exported.')); $this->displayInformation($this->l('In advanced sotck managment, products that are not stocked in a warehouse will not appear.')); // Show information or confirm message / error at the end of the inventory /*switch(Tools::getValue('submitFilterproduct')) { case 0: $this->displayInformation($this->l('New inventory')); break; case 1: $this->confirmations[] = $this->l('Inventory completed'); break; case 2: $this->errors[] = Tools::displayError('There has been a problem while handling products'); break; default: $this->displayInformation($this->l('New inventory')); break; }*/ // Add plugin simple tooltip $this->addJqueryPlugin('cluetip', _MODULE_DIR_ . 'erpillicopresta/js/cluetip/'); // add jquery dialog $this->addJqueryUI('ui.dialog'); // add plugin validity $this->addJqueryPlugin('validity.min', _MODULE_DIR_ . 'erpillicopresta/js/validity/'); // Load JS $this->addJS(_MODULE_DIR_ . 'erpillicopresta/js/inventory_tools.js'); $this->addJS(_MODULE_DIR_ . 'erpillicopresta/js/inventory.js'); // Load CSS $this->addCSS(_MODULE_DIR_ . 'erpillicopresta/css/jquery.validity.css'); $this->addCSS(_MODULE_DIR_ . 'erpillicopresta/css/jquery.cluetip.css'); $list = parent::renderList(); return $list; }