/**
  * Get or count items in pending orders
  *
  * @param bool $count Count instead of load
  *
  * @return CProductOrderItem[]|int[]
  */
 function getPendingOrderItems($count = true)
 {
     $leftjoin = array();
     $leftjoin['product_order'] = 'product_order.order_id = product_order_item.order_id';
     $leftjoin['product_reference'] = 'product_reference.reference_id = product_order_item.reference_id';
     $leftjoin['product'] = 'product.product_id = product_reference.product_id';
     $where = array("product.product_id" => "= '{$this->_id}'", "product_order.cancelled" => '= 0', "product_order.deleted" => '= 0', "product_order.date_ordered" => 'IS NOT NULL', "product_order.received" => "= '0'", "product_order_item.renewal" => "= '1'");
     /** @var CProductOrderItem[] $list */
     $item = new CProductOrderItem();
     if ($count) {
         $list = $item->countList($where, null, $leftjoin);
     } else {
         $list = $item->loadList($where, "date_ordered ASC", null, "product_order_item.order_item_id", $leftjoin);
     }
     foreach ($list as $_id => $_item) {
         if ($_item->isReceived()) {
             unset($list[$_id]);
         }
     }
     $this->_in_order = $list;
     if ($list) {
         foreach ($this->_in_order as $_item) {
             $_item->loadOrder();
         }
     }
     return $this->_in_order;
 }
$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');