$sale) { $ids[] = $sale->id; } $extrafields = PrivateSales_ExtraFields::getFieldsForSale($ids); $employees = array(); foreach(Db::getInstance()->ExecuteS(' SELECT `id_employee`, `firstname`, `lastname` FROM `'._DB_PREFIX_.'employee` ') as $row) { $employees[(int) $row['id_employee']] = $row['firstname'].' '.$row['lastname']; } echo " ID Categorie Titre Début Fin Activée Nouveau Commercial FR ES Position Actions "; $export = true; foreach($sales as $key => $sale) { echo ' '.$sale->id.' '.$sale->id_category.' '.$sale->title[intval($cookie->id_lang)].'
'.$extrafields[$sale->id][1].' '.$sale->date_start.' '.$sale->date_end.' '.($sale->enabled? 'Oui':'Non').''; if($sale->new == 0){ echo "Non"; } else if($sale->new == 1){ echo "Oui"; } else if($sale->new == 3){ echo "Non défini"; } echo ''.((int) $sale->id_employee != 0? $employees[(int) $sale->id_employee]: '--').' versions) ? 'class="green"' : 'class="red"').'>FR versions) ? 'class="green"' : 'class="red"').'>ES '; if($key != 0){ echo 'Haut'; } if($key + 1 != count($sales)){ echo 'Bas'; } $category_link = Link::getCategoryLink($sale->id_category); echo ' '.($export? '': '').' '; } echo ""; die(); } function getSaleType($sale_type){ $type = ""; if(in_array(1, $sale_type)){ $type.= "Bébé "; } if(in_array(2, $sale_type)){ $type.= "Enfant "; } if(in_array(3, $sale_type)){ $type.= "Maman "; } if(empty($type)){ return "undefined"; } return $type; } if (isset($_GET['updatePosition'])){ $position = $_GET['position']; $way = $_GET['way']; if($way == 0){ $new_position = $position + 1; }elseif($way == 1){ $new_position = $position - 1; } updateSalePosition($position, $new_position); die(); } function updateSalePosition($position, $new_position){ $sale = Sale::getByPosition($position); $last_sale = Sale::getByPosition($new_position); // // update lactuelle new position Db::getInstance()->autoExecute( _DB_PREFIX_.'privatesale', array( 'position' => $position), 'UPDATE', 'id_sale = ' . $last_sale->id); // // update pour la nouvelle position Db::getInstance()->autoExecute( _DB_PREFIX_.'privatesale', array( 'position' => $new_position), 'UPDATE', 'id_sale = ' . $sale->id); return true; } if (isset($_GET['updatePositionDrag'])){ $id_sale = str_replace("item_", "", $_GET['id_sale']); $position = $_GET['position']; $sql = 'SELECT position FROM '._DB_PREFIX_.'privatesale WHERE id_sale =' . $id_sale; $position_initial = Db::getInstance()->getValue($sql); $new_position = $position_initial + $position; if($position > 0){ $sales_sql = "SELECT id_sale, position FROM "._DB_PREFIX_."privatesale WHERE position BETWEEN ". ($position_initial +1) .' AND ' .$new_position; $sales = Db::getInstance()->ExecuteS($sales_sql); foreach ($sales as $key => $sale){ Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = (position -1) WHERE id_sale = '. $sale['id_sale']); } }else{ $sales_sql = "SELECT id_sale, position FROM "._DB_PREFIX_."privatesale WHERE position BETWEEN ". $new_position . ' AND ' . ($position_initial - 1); $sales = Db::getInstance()->ExecuteS($sales_sql); foreach ($sales as $key => $sale){ Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = (position + 1) WHERE id_sale = '. $sale['id_sale']); } } Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = '. (int)$new_position.' WHERE id_sale = '. $id_sale); die(); } if (isset($_GET['updatePositionImg'])){ $id_image = str_replace("image_", "", $_GET['id_image']); $position = $_GET['position']; $sql = ' SELECT `position`, `id_product` FROM '._DB_PREFIX_.'image WHERE `id_image` =' . (int)$id_image; $position_initial = Db::getInstance()->getRow($sql); $id_product = $position_initial['id_product']; $new_position = $position_initial['position'] + $position; // fix bug duplicate entry Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'image` SET `position` = 0 WHERE `id_image` = '. (int)$id_image ); if ($position > 0) { Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'image` SET `position` = (`position` -1) WHERE `id_product` = '. (int)$id_product.' AND `position` BETWEEN '.(int)$position_initial['position'].' AND '.(int)$new_position ); } else { // fix bug duplicate entry foreach (Db::getInstance()->ExecuteS(' SELECT `id_image` FROM `'._DB_PREFIX_.'image` WHERE `id_product` = '. (int)$id_product .' AND `position` BETWEEN '.(int)$new_position.' AND '.(int)$position_initial['position'].' ORDER BY position DESC') as $key => $value) { Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'image` SET `position` = (`position` + 1) WHERE `id_image` = '. (int)$value['id_image'] ); } } Db::getInstance()->execute(' UPDATE `'._DB_PREFIX_.'image` SET `position` = '.(int)$new_position.' WHERE `id_image` = '. (int)$id_image ); die(); } if (isset($_GET['getStats'])) { $id_sale = Tools::getValue('id_sale'); if(Validate::isLoadedObject($sale = new Sale($id_sale))) { $exports = array(); $sold_products = array(); foreach(Db::getInstance()->ExecuteS(' SELECT DISTINCT `product_id`, `product_attribute_id` FROM `'._DB_PREFIX_.'order_detail`d INNER JOIN `'._DB_PREFIX_.'orders` o ON d.id_order = o.id_order WHERE `product_id` IN ( SELECT `id_product` FROM `'._DB_PREFIX_.'product_ps_cache` WHERE `id_sale` = '.(int) $sale->id.' ) AND o.valid = 1 ') as $row) { $sold_products[] = (int) $row['product_id'].'-'.(int) $row['product_attribute_id']; } $detail_sales = array(); foreach(Db::getInstance()->ExecuteS(' SELECT `product_id`, `product_attribute_id`, SUM(`product_quantity`) AS `quantity` FROM `'._DB_PREFIX_.'order_detail` d INNER JOIN `'._DB_PREFIX_.'orders` o ON o.id_order = d.id_order WHERE `product_id` IN ( SELECT `id_product` FROM `'._DB_PREFIX_.'product_ps_cache` WHERE `id_sale` = '.(int) $sale->id.' ) AND o.valid = 1 GROUP BY `product_id`, `product_attribute_id` ') as $row) { $detail_sales[(int) $row['product_id'].'-'.(int) $row['product_attribute_id']] = (int) $row['quantity']; } // get les produits avec attributs $query = Db::getInstance()->ExecuteS(' SELECT a.`id_product_attribute`, a.`id_product`, a.`quantity`, p.`reference`, pl.`name` FROM `'._DB_PREFIX_.'product_attribute` a LEFT JOIN `'._DB_PREFIX_.'product` p ON p.`id_product` = a.`id_product` LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.`id_product` = pl.`id_product` AND id_lang = '.(int)$cookie->id_lang.' WHERE a.`id_product` IN ( SELECT `id_product` FROM `'._DB_PREFIX_.'product_ps_cache` WHERE `id_sale` = '.(int) $sale->id.' ) AND p.`active` = 1 GROUP BY a.`id_product_attribute` '); $id_attributes = array(); foreach($query as $row) { if(in_array((int) $row['id_product'].'-'.(int) $row['id_product_attribute'], $sold_products)) { $stock_actual = $row['quantity']; $stock_sales = $detail_sales[(int) $row['id_product'].'-'.(int) $row['id_product_attribute']]; $stock_initial = (int)$stock_actual + (int)$stock_sales; $percent_sale = ((int)$stock_sales * 100) / (int)$stock_initial; if ($stock_actual == 0 || $percent_sale > 85) { $exports[] = [ 'id_product' => $row['id_product'] . '-'.(int) $row['id_product_attribute'], 'name' => $row['name'], 'reference' => $row['reference'], 'quantity' => $stock_actual, 'quantity_sale' => $stock_sales, 'percent_sale' => round((100 - $percent_sale), 2), ]; } } $id_attributes[] = (int) $row['id_product']; } // get les produits sans attributs $query_whitout_attributes = Db::getInstance()->ExecuteS(' SELECT p.`quantity`, p.`id_product`, pl.`name`, p.`reference` FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON p.`id_product` = pl.`id_product` AND id_lang = '.(int)$cookie->id_lang.' WHERE p.`id_product` IN ( SELECT `id_product` FROM `'._DB_PREFIX_.'product_ps_cache` WHERE `id_sale` = '.(int) $sale->id.' ) '.((count($id_attributes) > 0)? ' AND p.`id_product` NOT IN ('.implode(', ', $id_attributes).')': '').' GROUP BY p.`id_product` '); foreach($query_whitout_attributes as $row) { if(in_array((int) $row['id_product'].'-0', $sold_products)) { $stock_actual = $row['quantity']; $stock_sales = $detail_sales[(int) $row['id_product'].'-0']; $stock_initial = (int)$stock_actual + (int)$stock_sales; $percent_sale = ((int)$stock_sales * 100) / (int)$stock_initial; if ($stock_actual == 0 || $percent_sale > 85) { $exports[] = [ 'id_product' => $row['id_product'], 'name' => $row['name'], 'reference' => $row['reference'], 'quantity' => $stock_actual, 'quantity_sale' => $stock_sales, 'percent_sale' => round((100 - $percent_sale), 2), ]; } } } $result = ''; if (!empty($exports)) { $result .= ' '; foreach ($exports as $key => $product) { $id_image = Product::getCover($product['id_product']); $link = new Link(); if ($id_image) { $href = $link->getImageLink('image', $id_image['id_image'], 'small'); } $result.= ' '; } $result.= '
Image Référence Nom du produit Quantité vendue Quantité restante % vendu
'.$product['reference'].' '.$product['name'].' '.$product['quantity_sale'].' '.$product['quantity'].' '.(($product['percent_sale'] == 0) ? '100' : (100 - $product['percent_sale'])).'%
'; } echo $result; die; } }