Ejemplo n.º 1
0
 /**
  * A product is shipped
  *
  * @param unknown            $qty
  * @param string             $comments
  * @param BaseEntityAbstract $entity
  *
  * @return Product
  */
 public function shipped($qty, $comments = '', BaseEntityAbstract $entity = null)
 {
     $order = $entity instanceof Order ? $entity : ($entity instanceof OrderItem ? $entity->getOrder() : null);
     $newQty = ($originStockOnOrder = $this->getStockOnOrder()) - $qty;
     if ($newQty < 0 && intval($qty) > 0 && intval(SystemSettings::getSettings(SystemSettings::TYPE_ALLOW_NEGTIVE_STOCK)) !== 1) {
         throw new Exception('Product (SKU:' . $this->getSKU() . ') can NOT be pick, as there is not enough stock.');
     }
     return $this->setStockOnOrder($newQty)->snapshotQty($entity instanceof BaseEntityAbstract ? $entity : $this, ProductQtyLog::TYPE_STOCK_MOVE_INTERNAL, 'Stock shipped. ' . ($order instanceof Order ? '[' . $order->getOrderNo() . ']' : ''))->save()->addLog('StockOnOrder(' . $originStockOnOrder . ' => ' . $this->getStockOnOrder() . ')', Log::TYPE_SYSTEM, 'STOCK_QTY_CHG', __CLASS__ . '::' . __FUNCTION__);
 }