/** * Deleting an entity from database * * @param BaseEntityAbstract $entity The entity that we are trying to delete * * @return int The number rows affected */ public function delete(BaseEntityAbstract $entity) { return $this->deleteByCriteria('`id` = ? ', array($entity->getId())); }
/** * add Comments * * @param BaseEntityAbstract $entity The entity * @param string $comments The comemnts * @param string $groupId The groupId */ public static function addComments(BaseEntityAbstract $entity, $comments = '', $type = self::TYPE_NORMAL, $groupId = '') { $className = __CLASS__; $en = new $className(); return $en->setEntityId($entity->getId())->setEntityName(get_class($entity))->setComments($comments)->setType($type)->setGroupId(($groupId = trim($groupId)) === '' ? self::genGroupId() : $groupId)->save(); }
/** * A product is picked * * @param int $qty * @param string $comments * @param BaseEntityAbstract $entity * * @return Product */ public function picked($qty, $comments = '', BaseEntityAbstract $entity = null) { $order = $entity instanceof Order ? $entity : ($entity instanceof OrderItem ? $entity->getOrder() : null); $unitCost = $this->getUnitCost(); $totalCost = $qty * $unitCost; $action = intval($qty) > 0 ? 'Stock picked' : 'stock UNPICKED'; $newQty = ($originStockOnHand = $this->getStockOnHand()) - $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 ' . $action . ' , as there is not enough stock: stock on hand will fall below zero'); } if ($entity instanceof OrderItem) { $kits = array_map(create_function('$a', 'return $a->getKit();'), SellingItem::getAllByCriteria('orderItemId = ? and kitId is not null', array($entity->getId()))); $kits = array_unique($kits); if (count($kits) > 0) { $totalCost = 0; $barcodes = array(); foreach ($kits as $kit) { $totalCost = $kit->getCost(); $barcodes[] = $kit->getBarcode(); } $comments .= ' ' . $action . ' KITS[' . implode(',', $barcodes) . '] with total cost value:' . StringUtilsAbstract::getCurrency($totalCost); } } $newStockOnOrder = ($originStockOnOrder = $this->getStockOnOrder()) + $qty; if ($newStockOnOrder < 0 && intval(SystemSettings::getSettings(SystemSettings::TYPE_ALLOW_NEGTIVE_STOCK)) !== 1) { throw new Exception('Product (SKU:' . $this->getSKU() . ') can NOT be ' . $action . ' , as there is not enough stock: new stock on order will fall below zero'); } return $this->setStockOnHand($newQty)->setStockOnOrder($newStockOnOrder)->setTotalOnHandValue(($origTotalOnHandValue = $this->getTotalOnHandValue()) - $totalCost)->snapshotQty($entity instanceof BaseEntityAbstract ? $entity : $this, ProductQtyLog::TYPE_SALES_ORDER, $action . ': ' . ($order instanceof Order ? '[' . $order->getOrderNo() . ']' : '') . $comments)->save()->addLog('StockOnHand(' . $originStockOnHand . ' => ' . $this->getStockOnHand() . ')', Log::TYPE_SYSTEM, 'STOCK_QTY_CHG', __CLASS__ . '::' . __FUNCTION__)->addLog('StockOnOrder(' . $originStockOnOrder . ' => ' . $this->getStockOnOrder() . ')', Log::TYPE_SYSTEM, 'STOCK_QTY_CHG', __CLASS__ . '::' . __FUNCTION__)->addLog('TotalOnHandValue(' . $origTotalOnHandValue . ' => ' . $this->getTotalOnHandValue() . ')', Log::TYPE_SYSTEM, 'STOCK_VALUE_CHG', __CLASS__ . '::' . __FUNCTION__); }
/** * Logging the entity * * @param BaseEntityAbstract $entity * @param string $msg * @param string $type * @param string $comments */ public static function LogEntity(BaseEntityAbstract $entity, $msg, $type, $comments = '', $funcName = '') { self::logging($entity->getId(), get_class($entity), $msg, $type, $comments, $funcName); }
/** * creating a task * * @param UDate $dueDate * @param string $instructions * @param UserAccount $tech * * @return Task */ public static function create(Customer $customer, UDate $dueDate = null, $instructions = '', UserAccount $tech = null, BaseEntityAbstract $fromEntity = null) { $task = new Task(); $task->setDueDate($dueDate)->setCustomer($customer)->setInstructions($instructions = trim($instructions))->setTechnician($tech); if ($fromEntity instanceof BaseEntityAbstract) { $task->setFromEntityId($fromEntity->getId())->setFromEntityName(get_class($fromEntity)); } $task->save()->addComment('Task created with(Customer: ' . $customer->getName() . ', DueDate:' . $dueDate . '(UTC), ' . ($instructions === '' ? 'no insturctions' : ' some instructions ') . ', tech ' . ($tech instanceof UserAccount ? $tech->getPerson() : '')); return $task; }