/** * a product is returned for into stock on hand * * @param unknown $qty * @param dobuble $unitCost * @param string $comments * @param BaseEntityAbstract $entity */ public function returnedIntoSOH($qty, $unitCost, $comments, BaseEntityAbstract $entity = null) { $creditNote = $entity instanceof CreditNote ? $entity : ($entity instanceof CreditNoteItem ? $entity->getCreditNote() : null); $order = $creditNote instanceof CreditNote ? $creditNote->getOrder() : null; return $this->setStockOnHand(($originalStockOnHand = $this->getStockOnHand()) + $qty)->setTotalOnHandValue(($originalTotalOnHandValue = $this->getTotalOnHandValue()) + $qty * $unitCost)->snapshotQty($entity instanceof BaseEntityAbstract ? $entity : $this, ProductQtyLog::TYPE_RMA, 'Return StockOnHand ' . ($creditNote instanceof CreditNote ? ' from CreditNote[' . $creditNote->getCreditNoteNo() . ']' : '') . ($order instanceof Order ? ' generated from Order[' . $order->getOrderNo() . ']' : '') . (trim($comments) === '' ? '.' : ': ' . $comments))->save()->addLog('StockOnHand(' . $originalStockOnHand . ' => ' . $this->getStockOnHand() . '), TotalRMAValue(' . $originalTotalOnHandValue . ' => ' . $this->getTotalOnHandValue() . ')' . (trim($comments) === '' ? '.' : ': ' . $comments), Log::TYPE_SYSTEM, 'STOCK_QTY_CHG', __CLASS__ . '::' . __FUNCTION__); }