getValue(' SELECT COUNT(o.`id_order`) FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = o.`id_order`) WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = o.`id_order` GROUP BY moh.`id_order`) AND oh.`id_order_state` = 19 '); foreach(Db::getInstance()->ExecuteS(' SELECT lp.*, oh.`id_order_state` FROM `'._DB_PREFIX_.'logistics_pending` lp LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = lp.`id_order`) WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = lp.`id_order` GROUP BY moh.`id_order`) ORDER BY lp.`id_sale` ') as $row) { // If order status is not in pending, order is deleted from logistic_pending table if ((int)$row['id_order_state'] != 19) { Db::getInstance()->ExecuteS(' DELETE FROM `'._DB_PREFIX_.'logistics_pending` WHERE `id_order` = '.(int)$row['id_order'] ); continue; } // count of orders if (!in_array((int)$row['id_order'], $distinct_orders)) { $distinct_orders[] = (int)$row['id_order']; } if(!isset($sales_info[(int)$row['id_sale']])) { $s = new Sale((int)$row['id_sale']); $sales_info[(int)$row['id_sale']] = array( 'id_sale' => (int)$row['id_sale'], 'title' => $s->title[(int)$cookie->id_lang], 'date_start' => $s->date_start, 'orders' => array() ); } if (!isset($sales_info[(int)$row['id_sale']]['orders'][(int)$row['id_order']] )){ $order_infos = Db::getInstance()->getRow(' SELECT CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, o.`payment`, o.`total_paid` FROM `'._DB_PREFIX_.'orders` o LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`) WHERE o.`id_order` = '.(int)$row['id_order'] ); $sales_info[(int)$row['id_sale']]['orders'][(int)$row['id_order']] = array( 'id_order' => (int)$row['id_order'], 'customer' => $order_infos['customer'], 'payment' => $order_infos['payment'], 'total_paid' => $order_infos['total_paid'], 'products' => array(), 'id_state' => (int)$row['id_order_state'] ); } $p = Db::getInstance()->getRow(' SELECT od.`product_id`,od.`product_attribute_id`, od.`product_name`, od.`product_reference` FROM `'._DB_PREFIX_.'order_detail` od WHERE od.`id_order` = '.(int)$row['id_order'].' AND od.`product_id` = '.(int)(int)$row['id_product'] ); $p['id_image'] = 0; if((int) $p['product_attribute_id'] != 0) { $img = Db::getInstance()->getRow(' SELECT `id_image` FROM `'._DB_PREFIX_.'product_attribute_image` WHERE `id_product_attribute` = '.(int) $p['product_attribute_id'].' '); $p['id_image'] = $img['id_image']; } if($p['id_image'] == 0) { $img = Db::getInstance()->getRow(' SELECT `id_image` FROM `'._DB_PREFIX_.'image` WHERE `cover` = 1 AND `id_product` = '.(int) $p['product_id'].' '); $p['id_image'] = $img['id_image']; } $p['image'] = $link->getImageLink('image', $p['product_id'].'-'.$p['id_image'], 'home'); $sales_info[(int)$row['id_sale']]['orders'][(int)$row['id_order']]['products'][] = $p; } $helper = new HelperFormBootstrap(); $helper->_css .= ' '; $helper->_js .= ' '; $html = $helper->renderStyle(); $html .= '

'.$this->l('Liste des commandes en attente').'

'.$this->l('Commandes en attente avec produits retenus').' : '.(!empty($distinct_orders)?count($distinct_orders):'0').'
'.$this->l('Commandes en attente').' : '.$total_pending_orders.'
'; if (!empty($sales_info)) { $html .= '
'; foreach ($sales_info as $key => $sale) { $html .= ' '; } $html .= '
'.$this->l('Sale ID').' '.$this->l('Title').' '.$this->l('Date start').' '.$this->l('Nb orders').' '.$this->l('Check all').' '.$this->l('See orders').'
'.$sale['id_sale'].' '.$sale['title'].' '.date('d/m/Y H:i',strtotime($sale['date_start'])).' '.count($sale['orders']).' '.$this->l('+').'

'; } else { $html .= '

'.$this->l('Aucune Commandes en attente').'

'; } $html .= '
'; $html .= $helper->renderScript(); echo $html; } public function postProcess() { global $currentIndex; if(Tools::isSubmit('submitPrint')) { $orders = Tools::getValue('orders'); if (!empty($orders)) { $_orders = array(); 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`, d.`product_reference`, COUNT(d.id_order_detail) as `nb_p` FROM `'._DB_PREFIX_.'privatesale_category` c LEFT JOIN `'._DB_PREFIX_.'product` p ON c.`id_category` = p.`id_category_default` LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`product_id` = p.`id_product` WHERE d.`id_order` IN ('.implode(', ', $orders).') GROUP BY d.`id_order` ORDER BY `nb_p` ASC, d.`product_reference` ') as $row) { if(!isset($_orders[(int)$row['id_order']])) { $_orders[(int)$row['id_order']] = (int)$row['id_order']; } } $_orders = array_unique($_orders); Tools::redirectAdmin('pdf.php?pendingorders&orders='.implode(',', $_orders) .'&token='.$this->token); } else { $this->_errors[] = $this->l('No selected orders for these sales'); } } } }