public function getDataGeneration()
    {
        $datas = array();
        $order_to_change_state = array();
        $saved_product = array();
        $datas_quantity = array();
        $customer_concerned = array();
        $concerned_id_order_detail = array();
        $orders = Db::getInstance()->executeS('
		SELECT a.id_order
		FROM `' . _DB_PREFIX_ . 'orders` a
		LEFT JOIN `' . _DB_PREFIX_ . 'customer` c ON (c.`id_customer` = a.`id_customer`)
		WHERE a.current_state = ' . (int) $this->generate_order_state . '
		ORDER BY a.`id_order` DESC');
        $unselected_orders_array = array();
        /* if (isset( $this->context->cookie->unselected_orders) && !empty( $this->context->cookie->unselected_orders))
        		{
        			  $unselected_orders_array = Tools::unSerialize( $this->context->cookie->unselected_orders);
        		} */
        if (Tools::getValue('unselected_orders_list', false)) {
            $unselected_orders_array = explode(',', Tools::getValue('unselected_orders_list'));
            $unselected_orders_array = array_map('trim', $unselected_orders_array);
        }
        if (!empty($orders)) {
            foreach ($orders as $order) {
                $id_order = (int) $order['id_order'];
                if (!in_array($id_order, $unselected_orders_array)) {
                    $order = new Order((int) $id_order);
                    if (!Validate::isLoadedObject($order)) {
                        throw new PrestaShopException('object oder simulate can\'t be loaded');
                    }
                    $order_details = $order->getOrderDetailList();
                    if (!empty($order_details)) {
                        $order_to_change_state[] = (int) $id_order;
                        foreach ($order_details as $order_detail) {
                            $id_supplier = 0;
                            $product_key = $order_detail['product_id'] . '_' . $order_detail['product_attribute_id'];
                            $product = new Product($order_detail['product_id'], $order_detail['product_attribute_id']);
                            // update selling price to purchase price
                            $order_detail['unit_price_tax_excl'] = ErpStock::getWholesalePrice($order_detail['product_id'], $order_detail['product_attribute_id']);
                            $order_detail['tax_rate'] = Tax::getProductTaxRate($order_detail['product_id']);
                            $order_detail['unit_price_tax_incl'] = $order_detail['unit_price_tax_excl'] * (1 + (double) $order_detail['tax_rate'] / 100);
                            if (empty($product->id_supplier)) {
                                // Get already associated suppliers
                                $associated_suppliers = new Collection('ProductSupplierCore');
                                $associated_suppliers->where('id_product', '=', (int) $product->id);
                                $associated_suppliers->groupBy('id_supplier');
                                foreach ($associated_suppliers as $associated_supplier) {
                                    $id_supplier = $associated_supplier->id_supplier;
                                }
                            } else {
                                $id_supplier = $product->id_supplier;
                            }
                            if (isset($saved_product[$product_key])) {
                                $datas_quantity[$product_key] += $order_detail['product_quantity'];
                                $customer_concerned[$product_key][] = $order->id_customer;
                                $concerned_id_order_detail[$product_key][] = array('id_order_detail' => $order_detail['id_order_detail'], 'id_customer' => $order->id_customer);
                                $order_detail['total_product_quantity'] = $datas_quantity[$product_key];
                                $order_detail['customer_concerned'] = $customer_concerned[$product_key];
                                $order_detail['concerned_id_order_detail'] = $concerned_id_order_detail[$product_key];
                                $datas[$id_supplier][$product_key] = $order_detail;
                            } else {
                                $product_quantity = $order_detail['product_quantity'];
                                $order_detail['total_product_quantity'] = $product_quantity;
                                $order_detail['customer_concerned'][] = $order->id_customer;
                                $order_detail['concerned_id_order_detail'][] = array('id_order_detail' => $order_detail['id_order_detail'], 'id_customer' => $order->id_customer);
                                $datas[$id_supplier][$product_key] = $order_detail;
                                $datas_quantity[$product_key] = $product_quantity;
                                $customer_concerned[$product_key][] = $order->id_customer;
                                $concerned_id_order_detail[$product_key][] = array('id_order_detail' => $order_detail['id_order_detail'], 'id_customer' => $order->id_customer);
                                $saved_product[$product_key] = true;
                            }
                        }
                    }
                }
            }
        }
        $data_return = array();
        foreach ($datas as $id_supplier => $data) {
            if ($id_supplier > 0) {
                $product_list = array();
                foreach ($data as $product_key => $product_info) {
                    $customer_concerned = '';
                    $customer_concerned_arr = array_unique($product_info['customer_concerned']);
                    foreach ($customer_concerned_arr as $id_customer) {
                        $customer = new Customer($id_customer);
                        $customer_concerned .= $customer->lastname . ' ' . $customer->firstname . ', ';
                    }
                    $total_te = $product_info['unit_price_tax_excl'] * $product_info['total_product_quantity'];
                    $total_ti = $product_info['unit_price_tax_incl'] * $product_info['total_product_quantity'];
                    $product_info['total_price_tax_excl'] = Tools::displayPrice($total_te);
                    $product_info['total_price_tax_incl'] = Tools::displayPrice($total_ti);
                    $product_info['unit_price_tax_excl'] = $product_info['unit_price_tax_excl'];
                    $product_info['customer_concerned'] = Tools::substr($customer_concerned, 0, Tools::strlen($customer_concerned) - 2);
                    $product_info['customer_id'] = $customer_concerned_arr;
                    $product_list[] = $product_info;
                }
                $data_return[$id_supplier] = $product_list;
            }
        }
        // for the order, get the orders list that the statuts should be update in provider order
        if ($this->display == 'ordering') {
            return array('data_return' => $data_return, 'order_to_change_state' => $order_to_change_state);
        } else {
            return $data_return;
        }
    }
 public function ajaxGetProductSupplierPrice()
 {
     //  If we have called the script with a term to search
     if (Tools::isSubmit('id_product') && Tools::isSubmit('id_product_attribute')) {
         require_once _PS_MODULE_DIR_ . 'erpillicopresta/classes/ErpProductSupplier.php';
         $id_product = Tools::getValue('id_product');
         $id_product_attribute = Tools::getValue('id_product_attribute');
         //$id_currency = Tools::getValue('id_currency', false) ? Tools::getValue('id_currency') : 1;
         /*  Price for all suppliers for the product */
         $supplier_prices = ErpProductSupplier::getAllProductSupplierPrice($id_product, $id_product_attribute, true);
         if (!empty($supplier_prices)) {
             echo '<table class="table">';
             foreach ($supplier_prices as $price) {
                 /*  If supplier price  = 0 we take the basic one */
                 if ($price['product_supplier_price_te'] == '0.000000') {
                     $supplier_price = ErpStock::getWholesalePrice($id_product, $id_product_attribute);
                 } else {
                     $supplier_price = $price['product_supplier_price_te'];
                 }
                 /*  writing of the HTML table */
                 echo '<tr>
                                                 <td>' . $price['supplier_name'] . ' : </td>
                                                 <td> &nbsp; ' . number_format($supplier_price, 2, '.', ' ') . '€</td>
                                             </tr>';
             }
             echo '</table>';
         } else {
             echo $this->l('No price found for this product!');
         }
     }
     die;
 }