public function renderView() { $badges_feature = new Collection('badge', $this->context->language->id); $badges_feature->where('type', '=', 'feature'); $badges_feature->orderBy('id_group'); $badges_feature->orderBy('group_position'); $badges_achievement = new Collection('badge', $this->context->language->id); $badges_achievement->where('type', '=', 'achievement'); $badges_achievement->orderBy('id_group'); $badges_achievement->orderBy('group_position'); $badges_international = new Collection('badge', $this->context->language->id); $badges_international->where('type', '=', 'international'); $badges_international->orderBy('id_group'); $badges_international->orderBy('group_position'); $groups = array(); $query = new DbQuery(); $query->select('DISTINCT(b.`id_group`), bl.group_name, b.type'); $query->from('badge', 'b'); $query->join(' LEFT JOIN `' . _DB_PREFIX_ . 'badge_lang` bl ON bl.`id_badge` = b.`id_badge`'); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); foreach ($result as $res) { $groups['badges_' . $res['type']][$res['id_group']] = $res['group_name']; } $badges_type = array('badges_feature' => array('name' => $this->l('Features'), 'badges' => $badges_feature), 'badges_achievement' => array('name' => $this->l('Achievements'), 'badges' => $badges_achievement), 'badges_international' => array('name' => $this->l('International'), 'badges' => $badges_international)); $levels = array(1 => $this->l('1. Beginner'), 2 => $this->l('2. Pro'), 3 => $this->l('3. Expert'), 4 => $this->l('4. Wizard'), 5 => $this->l('5. Guru'), 6 => $this->l('6. Legend')); $this->tpl_view_vars = array('badges_type' => $badges_type, 'current_level_percent' => (int) Configuration::get('GF_CURRENT_LEVEL_PERCENT'), 'current_level' => (int) Configuration::get('GF_CURRENT_LEVEL'), 'groups' => $groups, 'levels' => $levels); return parent::renderView(); }
public function testQueryException() { $this->setExpectedException("\\ModelException"); $this->object->orderBy("nesmysl"); $this->object[0]; // init }
public static function getThemes() { $themes = new Collection('Theme'); $themes->orderBy('name'); return $themes; }
protected function renderCSV() { if (Tools::isSubmit('export_csv')) { $stckmgtfr = ERP_STCKMGTFR; // get all filter // // category filer $id_category = Tools::isSubmit('id_category') ? (int) Tools::getValue('id_category') : -1; $query = new DbQuery(); $query->select('id_product'); $query->from('category_product'); $query->where('id_category = ' . $id_category); $categories_exec = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); $categories = null; foreach ($categories_exec as $category) { $categories[] = (int) $category['id_product']; } //If no data if ($id_category != -1 && $categories == null) { $this->displayWarning($this->l('No data to export in this category !')); return; } if ($categories != null) { $categories = array_unique($categories); } // supplier filter $id_supplier = Tools::isSubmit('id_supplier') ? (int) Tools::getValue('id_supplier') : -1; $query = null; $query = new DbQuery(); $query->select('id_product'); $query->from('product_supplier'); $query->where('id_supplier = ' . $id_supplier); $suppliers_exec = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); $suppliers = null; foreach ($suppliers_exec as $supplier) { $suppliers[] = (int) $supplier['id_product']; } //If no data if ($id_supplier != -1 && $suppliers == null) { $this->displayWarning($this->l('No data to export with this supplier !')); return; } if ($suppliers != null) { $suppliers = array_unique($suppliers); } // Filter by manufacturer $id_manufacturer = Tools::isSubmit('id_manufacturer') ? (int) Tools::getValue('id_manufacturer') : -1; $query = null; $query = new DbQuery(); $query->select('id_product'); $query->from('manufacturer', 'm'); $query->innerjoin('product', 'p', 'm.id_manufacturer = p.id_manufacturer'); $query->where('m.id_manufacturer = ' . $id_manufacturer); $manufacturers_exec = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); $manufacturers = null; foreach ($manufacturers_exec as $manufacturer) { $manufacturers[] = (int) $manufacturer['id_product']; } //If no data if ($id_manufacturer != -1 && $manufacturers == null) { $this->displayWarning($this->l('No data to export with this manufacturer !')); return; } if ($manufacturers != null) { $manufacturers = array_unique($manufacturers); } // Quantity filter $table_quantity = 'quantity'; $moreless = Tools::isSubmit('moreless') && in_array(Tools::getValue('moreless'), array('=', '>', '<')) ? Tools::getValue('moreless') : -1; $quantity = Tools::isSubmit('quantity_filter') ? (int) Tools::getValue('quantity_filter') : -1; if ($this->advanced_stock_management) { $id_warehouse = $this->getCurrentCoverageWarehouse(); header('Content-type: text/csv'); header('Cache-Control: no-store, no-cache'); header('Content-disposition: attachment; filename=stock_' . date('Y-m-d_His') . '.csv'); header('charset=iso-8859-1'); // product attribute $combination = new DbQuery(); $combination->select(' pa.id_product as id_product, pa.id_product_attribute as id_product_attribute, pa.reference as reference, pa.ean13 as ean13, w.name as warehouse, wpl.id_warehouse_product_location, wpl.location as location, area.name as areaname, subarea.name as subareaname'); //if ($id_warehouse != -1) $combination->select('IFNULL(s.physical_quantity, 0) as physical_quantity, IFNULL(s.usable_quantity, 0) as usable_quantity'); //else //$combination->select('SUM(IFNULL(s.physical_quantity, 0)) as physical_quantity, SUM(IFNULL(s.usable_quantity, 0)) as usable_quantity'); $combination->from('product_attribute', 'pa'); $combination->innerjoin('product', 'p', 'pa.id_product = p.id_product'); $combination->leftjoin('warehouse_product_location', 'wpl', '(wpl.id_product = p.id_product AND wpl.id_product_attribute = IFNULL(pa.id_product_attribute, 0)' . ($id_warehouse != -1 ? ' AND wpl.id_warehouse = ' . (int) $id_warehouse : '') . ')'); $combination->leftjoin('stock', 's', '(s.id_product = pa.id_product AND s.id_product_attribute = IFNULL(pa.id_product_attribute, 0))'); $combination->leftjoin('warehouse', 'w', 's.id_warehouse = w.id_warehouse'); $combination->leftjoin('erpip_warehouse_product_location', 'ewpl', '(wpl.id_warehouse_product_location = ewpl.id_warehouse_product_location)'); $combination->leftjoin('erpip_zone', 'area', '(area.id_erpip_zone = ewpl.id_zone_parent)'); $combination->leftjoin('erpip_zone', 'subarea', '(subarea.id_erpip_zone = ewpl.id_zone)'); // apply filters // warehouse if ($id_warehouse != -1) { $combination->where('s.id_warehouse = ' . (int) $id_warehouse . ' OR wpl.id_warehouse = ' . (int) $id_warehouse); // area if (Tools::isSubmit('area')) { $combination->where('ewpl.id_zone_parent= ' . Tools::getValue('area')); // sub area if (Tools::isSubmit('subarea')) { $combination->where('ewpl.id_zone= ' . Tools::getValue('subarea')); } } } if ($id_category != -1) { $combination->where('pa.id_product IN (' . implode(',', array_map('intval', $categories)) . ')'); } if ($id_supplier != -1) { $combination->where('pa.id_product IN (' . implode(',', array_map('intval', $suppliers)) . ')'); } if ($id_manufacturer != -1) { $combination->where('pa.id_product IN (' . implode(',', array_map('intval', $manufacturers)) . ')'); } if ($moreless != -1) { if ($quantity > 0) { $where_quantity_filter = ' physical_quantity ' . $moreless . ' ' . (int) $quantity; if ($moreless == '=' && $quantity == 0 || $moreless == "<" && $quantity > 0) { $where_quantity_filter .= ' OR physical_quantity IS NULL '; } } $combination->where($where_quantity_filter); } $combination->groupBy('pa.id_product, pa.id_product_attribute, w.id_warehouse'); $combination->orderBy('pa.id_product, pa.id_product_attribute'); if ($this->controller_status == STATUS1) { $combination->limit($stckmgtfr); $this->informations[] = sprintf($this->l('You are using the free version of 1-Click ERP which limits document editing to %d products'), $stckmgtfr); } $combinations = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($combination); // List of product id $ids = array(); foreach ($combinations as $combination) { $ids[] = $combination['id_product']; } $ids = array_unique($ids); // Product without attribute $product = new DbQuery(); $product->select('p.id_product as id_product, 0 as id_product_attribute, p.reference as reference, p.ean13 as ean13, w.name as warehouse, wpl.id_warehouse_product_location, wpl.location as location, area.name as areaname, subarea.name as subareaname'); //if ($id_warehouse != -1) $product->select('IFNULL(s.physical_quantity, 0) as physical_quantity, IFNULL(s.usable_quantity, 0) as usable_quantity'); // else //$product->select('SUM(IFNULL(s.physical_quantity, 0)) as physical_quantity, SUM(IFNULL(s.usable_quantity, 0)) as usable_quantity'); $product->from('product', 'p'); $product->leftjoin('warehouse_product_location', 'wpl', '(wpl.id_product = p.id_product AND wpl.id_product_attribute = 0' . ($id_warehouse != -1 ? ' AND wpl.id_warehouse = ' . (int) $id_warehouse : '') . ')'); $product->leftjoin('stock', 's', '(s.id_product = p.id_product)'); $product->leftjoin('erpip_warehouse_product_location', 'ewpl', '(wpl.id_warehouse_product_location = ewpl.id_warehouse_product_location)'); $product->leftjoin('warehouse', 'w', 's.id_warehouse = w.id_warehouse'); $product->leftjoin('erpip_zone', 'area', '(area.id_erpip_zone = ewpl.id_zone_parent)'); $product->leftjoin('erpip_zone', 'subarea', '(subarea.id_erpip_zone = ewpl.id_zone)'); // apply filters if ($id_warehouse != -1) { $product->where('s.id_warehouse = ' . (int) $id_warehouse . ' OR wpl.id_warehouse = ' . (int) $id_warehouse); // Area if (Tools::isSubmit('area')) { $product->where('ewpl.id_zone_parent= ' . intval(Tools::getValue('area'))); // sub area if (Tools::isSubmit('subarea')) { $product->where('ewpl.id_zone= ' . intval(Tools::getValue('subarea'))); } } } if ($id_category != -1) { $product->where('p.id_product IN (' . implode(', ', array_map('intval', $categories)) . ')'); } if ($id_supplier != -1) { $product->where('p.id_product IN (' . implode(', ', array_map('intval', $suppliers)) . ')'); } if ($id_manufacturer != -1) { $product->where('p.id_product IN (' . implode(', ', array_map('intval', $manufacturers)) . ')'); } if ($moreless != -1) { if ($quantity > 0) { $where_quantity_filter = ' physical_quantity ' . $moreless . ' ' . (int) $quantity; if ($moreless == '=' && $quantity == 0 || $moreless == "<" && $quantity > 0) { $where_quantity_filter .= ' OR physical_quantity IS NULL'; } } $product->where($where_quantity_filter); } if (count($ids) > 0) { $product->where("p.id_product NOT IN (" . implode(',', array_map('intval', $ids)) . ")"); } $product->groupBy('p.id_product, w.id_warehouse'); $product->orderBy('p.id_product'); if ($this->controller_status == STATUS1) { $product->limit($stckmgtfr); $this->informations[] = sprintf($this->l('You are using the free version of 1-Click ERP which limits document editing to %d products'), $stckmgtfr); } $products = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($product); // $query = array_merge($products, $combinations); $query = array_merge($products, $combinations); // we sort by id_product and id_product_attribute usort($query, array($this, "idproductSort")); if ($this->controller_status == STATUS1) { $query = array_splice($query, 0, $stckmgtfr); } $csv_header_columns = array($this->l('EAN13'), $this->l('ID_PRODUCT'), $this->l('ID_PRODUCT_ATTRIBUTE'), $this->l('REFERENCE'), $this->l('PHYSICAL_QUANTITY'), $this->l('USABLE_QUANTITY'), self::transformText($this->l('WAREHOUSE')), $this->l('AREA'), $this->l('SUBAREA'), $this->l('LOCATION'), $this->l('WARNING')); echo implode(';', $csv_header_columns) . "\r\n"; // generate csv file foreach ($query as $product) { //alert in the case where the product has stock in warehouse without be located in this warehouse $warning = ''; if (is_null($product['id_warehouse_product_location'])) { $warning = sprintf($this->l('Product has stock in %s warehouse without being registered in this warehouse !'), $product['warehouse']); } $csv_value_columns = array(self::transformText($product['ean13']), $product['id_product'], $product['id_product_attribute'], self::transformText($product['reference']), self::transformText($product['physical_quantity']), self::transformText($product['usable_quantity']), self::transformText($product['warehouse']), self::transformText($product['areaname']), self::transformText($product['subareaname']), self::transformText($product['location']), self::transformText($warning)); echo implode(';', $csv_value_columns) . "\r\n"; } echo sprintf($this->l('You are using the free version of 1-Click ERP which limits the export to %d products'), $stckmgtfr); } else { // we work in different stock table while advanced stock is disabled $table_stock = 'StockAvailable'; $table_quantity = 'quantity'; // create collection width current filter $id_lang = Context::getContext()->language->id; $stock = new Collection($table_stock, $id_lang); if ($id_category != -1) { $stock->where('id_product', 'in', $categories); } if ($id_supplier != -1) { $stock->where('id_product', 'in', $suppliers); } if ($id_manufacturer != -1) { $stock->where('id_product', 'in', $manufacturers); } if ($moreless != -1) { if ($quantity > 0) { $where_quantity_filter = $table_quantity . ' ' . $moreless . ' ' . $quantity; if ($moreless == '=' && $quantity == 0 || $moreless == "<" && $quantity > 0) { $where_quantity_filter .= ' OR ' . $table_quantity . ' IS NULL'; } } $stock->sqlWhere($where_quantity_filter); } $stock->orderBy('id_product'); $stock->orderBy('id_product_attribute'); $stock->getAll(); if ($this->controller_status == STATUS1) { $stock = array_splice($stock, 0, $stckmgtfr); $this->informations[] = sprintf($this->l('You are using the free version of 1-Click ERP which limits document editing to %d products'), $stckmgtfr); } // generation of CSV $csv = new CSV($stock, $this->l('stock') . '_' . date('Y-m-d_His')); $csv->export(); } die; } }