Exemplo n.º 1
0
 /**
  * Load order items
  *
  * @param object $reception reception
  *
  * @return CProductOrderItem[]
  */
 function loadRefsaddItems()
 {
     $_reception = new CProductReception();
     $where = array();
     $where["reference"] = "LIKE '{$this->order_number}-%'";
     $receptions = $_reception->loadIds($where);
     $where = array();
     $where[] = "product_order_item_reception.reception_id " . CSQLDataSource::prepareIn(array_values($receptions)) . " OR product_order_item.order_id = '{$this->_id}'";
     $ljoin = array();
     $ljoin["product_order_item_reception"] = "product_order_item_reception.order_item_id = product_order_item.order_item_id";
     $order_item = new CProductOrderItem();
     /* @var CProductOrderItem[] $order_items*/
     $order_items = $order_item->loadList($where, "order_item_id", null, null, $ljoin);
     foreach ($order_items as $_order) {
         if (!$_order->order_id) {
             $_order->quantity = 0;
         }
         $_order->updatePriceTVA();
     }
     return $this->_ref_order_items_add = $order_items;
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 3
0
 $logs[$dummy_log->date][] = $dummy_log;
 foreach ($logs as $_date => $_logs) {
     foreach ($_logs as $_log) {
         if ($_date == $old_date) {
             //mbTrace("DATE IDEM");
             continue;
         }
         //mbTrace("$_log->object_class : $old_date >> $_date");
         //mbTrace($quantity_product, 'quantity_product');
         //mbTrace($quantity_reference, 'quantity_reference');
         //mbTrace($price_reference, 'price_reference');
         // CProductOrderItem : quantity and price
         // need to join on the latest log :(
         $oi_where["user_log.date"] = " > '{$_date}' AND user_log.date <= '{$old_date}'";
         $oi_where["product.product_id"] = "= '{$_product->_id}'";
         $ois = $oi->loadList($oi_where, "user_log.date DESC", null, "product_order_item.order_item_id", $oi_ljoin);
         foreach ($ois as $_oi) {
             $_oi->quantity = $_oi->quantity * $quantity_reference * $quantity_product;
             $_oi->unit_price = $_oi->unit_price / ($quantity_reference * $quantity_product);
             $_oi->units_fixed = 1;
             $_oi->store();
         }
         // CProductOrderItemReception : quantity
         $oir_where["product_order_item_reception.date"] = " > '{$_date}' AND product_order_item_reception.date <= '{$old_date}'";
         $oir_where["product.product_id"] = "= '{$_product->_id}'";
         $oirs = $oir->loadList($oir_where, null, null, null, $oir_ljoin);
         foreach ($oirs as $_oir) {
             //mbTrace(sprintf("%d\t >> %d\t", $_oir->quantity, $_oir->quantity * $quantity_reference * $quantity_product), "OIR QTY");
             $_oir->quantity = $_oir->quantity * $quantity_reference * $quantity_product;
             $_oir->units_fixed = 1;
             $_oir->store();