Merge branch 'ticket-invoiceOrderBy'

This commit is contained in:
Marion Muszynski 2016-07-13 10:59:09 +02:00
commit 2b9fd29308
3 changed files with 16 additions and 11 deletions

View File

@ -105,7 +105,7 @@ function generateInvoicesPDFPrivateSales()
include(dirname(__FILE__).'/../modules/privatesales/Sale.php'); include(dirname(__FILE__).'/../modules/privatesales/Sale.php');
if($sale = new Sale((int) Tools::getValue('id_sale'))) { if($sale = new Sale((int) Tools::getValue('id_sale'))) {
$statuts = array(17, Configuration::get('PS_OS_PAYMENT')); $statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = $sale->getOrdersFromSale($statuts); $orders = $sale->getOrdersFromSale($statuts);
if(count($orders) == 0) { if(count($orders) == 0) {
die (Tools::displayError('No invoices found')); die (Tools::displayError('No invoices found'));
} }

View File

@ -836,7 +836,7 @@ class PDFCore extends PDF_PageGroupCore
if (isset(self::$order->products) AND sizeof(self::$order->products)) if (isset(self::$order->products) AND sizeof(self::$order->products))
$products = self::$order->products; $products = self::$order->products;
else else
$products = self::$order->getProducts(); $products = self::$order->getProducts(false,false,false,true);
} }
else else
$products = self::$orderSlip->getOrdersSlipProducts(self::$orderSlip->id, self::$order); $products = self::$orderSlip->getOrdersSlipProducts(self::$orderSlip->id, self::$order);

View File

@ -860,6 +860,7 @@ class Sale {
if(count($orders) > 0) { if(count($orders) > 0) {
$_orders = array(); $_orders = array();
$_nb_product = array();
foreach(Db::getInstance()->ExecuteS(' foreach(Db::getInstance()->ExecuteS('
SELECT d.`id_order`, p.`id_product`, c.`id_sale`, GREATEST(d.`product_quantity` - d.`product_quantity_return`, 0) AS `product_quantity` SELECT d.`id_order`, p.`id_product`, c.`id_sale`, GREATEST(d.`product_quantity` - d.`product_quantity_return`, 0) AS `product_quantity`
FROM `'._DB_PREFIX_.'privatesale_category` c FROM `'._DB_PREFIX_.'privatesale_category` c
@ -872,6 +873,9 @@ class Sale {
') as $row) { ') as $row) {
if(!isset($_orders[(int)$row['id_order']])) { if(!isset($_orders[(int)$row['id_order']])) {
$_orders[(int)$row['id_order']] = array(); $_orders[(int)$row['id_order']] = array();
$_nb_product[(int)$row['id_order']] = 1;
} else {
$_nb_product[(int)$row['id_order']]++;
} }
if(!isset($_orders[(int)$row['id_order']][$row['id_sale']]) ) { if(!isset($_orders[(int)$row['id_order']][$row['id_sale']]) ) {
$_orders[(int)$row['id_order']][$row['id_sale']] = 1; $_orders[(int)$row['id_order']][$row['id_sale']] = 1;
@ -931,15 +935,16 @@ class Sale {
if ($multi_only) { if ($multi_only) {
return $order_print; return $order_print;
} else { } else {
// tri par date pour les M2+ asort($_nb_product);
sort($order_print); $result_to_print = array();
/*usort($order_print, function ($a, $b) { foreach ($_nb_product as $key => $value) {
if ($order_sales[$a] == $order_sales[$b]) { if (in_array($key,$order_print)) {
return 0; $result_to_print[]=$key;
} } else {
return ($order_sales[$a] < $order_sales[$b]) ? -1 : 1; continue;
});*/ }
return $order_print; }
return $result_to_print;
} }
return $order_print; return $order_print;