$references_cahpp = array();
foreach ($changes as $_change) {
    if (!isset($references[$_change["reference_id"]])) {
        $_reference = new CProductReference();
        $_reference->load($_change["reference_id"]);
        $references[$_reference->_id] = $_reference;
        $article = new CCAHPPArticle();
        $where = array("reference_fournisseur" => $article->_spec->ds->prepare("=%", $_reference->supplier_code));
        if (!$article->loadObject($where)) {
            $where = array("cip" => $article->_spec->ds->prepare("=%", $_reference->loadRefProduct()->code));
            $article->loadObject($where);
        }
        $references_cahpp[$_reference->_id] = $article;
    }
    $_order_item = new CProductOrderItem();
    $_order_item->load($_change["order_item_id"]);
    $_order_item->loadOrder();
    $_change["order_item"] = $_order_item;
    $changes_struct[$_change["reference_id"]][] = $_change;
}
$order_item = new CProductOrderItem();
$total_order_items = $order_item->countList();
// Smarty template
$smarty = new CSmartyDP();
$smarty->assign('changes', $changes);
$smarty->assign('changes_struct', $changes_struct);
$smarty->assign('references', $references);
$smarty->assign('references_cahpp', $references_cahpp);
$smarty->assign('total_order_items', $total_order_items);
$smarty->assign('ratio', $ratio);
$smarty->display('vw_reference_price_changes.tpl');
 /**
  * @see parent::store()
  */
 function store()
 {
     $this->completeField("reception_id");
     $is_new = !$this->_id;
     if ($is_new && $this->cancelled === null) {
         $this->cancelled = 0;
     }
     if ($is_new) {
         $this->loadRefOrderItem();
         $this->_ref_order_item->loadOrder();
     }
     if ($is_new && !$this->reception_id) {
         $order = $this->_ref_order_item->_ref_order;
         $reception = new CProductReception();
         $reception->date = CMbDT::dateTime();
         $reception->societe_id = $order->societe_id;
         $reception->group_id = CProductStockGroup::getHostGroup();
         // Recherche de receptions ayant un numero de reception similaire pour gerer l'increment
         if ($order->order_number) {
             $where = array("reference" => "LIKE '{$order->order_number}%'");
             $number = $reception->countList($where) + 1;
             $reception->reference = "{$order->order_number}-{$number}";
         }
         if ($msg = $reception->store()) {
             return $msg;
         }
         $this->reception_id = $reception->_id;
     }
     if ($is_new) {
         $this->_ref_order_item->loadRefsFwd();
         $this->_ref_order_item->_ref_reference->loadRefsFwd();
         $this->_ref_order_item->_ref_reference->_ref_product->loadRefStock();
         $product =& $this->_ref_order_item->_ref_reference->_ref_product;
         $product->updateFormFields();
         if ($product->loadRefStock()) {
             $stock = $product->_ref_stock_group;
             $stock->quantity += $this->quantity;
         } else {
             $qty = $this->quantity;
             $stock = new CProductStockGroup();
             $stock->product_id = $product->_id;
             $stock->group_id = CProductStockGroup::getHostGroup();
             $stock->quantity = $qty;
             $stock->order_threshold_min = $qty;
             CAppUI::setMsg("Un nouveau stock a été créé", UI_MSG_OK);
             //CAppUI::setMsg("Un nouveau stock pour [%s] a été créé", UI_MSG_OK, $product->_view);
         }
         if ($msg = $stock->store()) {
             return $msg;
         }
     }
     if ($msg = parent::store()) {
         return $msg;
     }
     // If the order is received, we set the flag
     if ($is_new) {
         $order = $this->_ref_order_item->_ref_order;
         if (!$order->received) {
             $count_renewed = $order->countRenewedItems();
             $count_received = $order->countReceivedItems() - (count($order->_ref_order_items) - $count_renewed);
             if ($count_renewed && $count_received >= $count_renewed) {
                 $order->received = 1;
                 $order->store();
             }
         }
     }
     return null;
 }