Example #1
0
 /**
  * @param StockItem $stockItem
  * @param int $page
  * @param int $pageSize
  * @param callable $callback
  * @return \Zend\Paginator\Paginator
  */
 public function getPagedChangelog(StockItem $stockItem, $page = 1, $pageSize = 100, callable $callback = null)
 {
     $builder = $this->em()->createQueryBuilder();
     $builder->select(LevelChange::ALIAS, Stock::ALIAS, StockItem::ALIAS, StockUnit::ALIAS, User::ALIAS)->from(LevelChange::class, LevelChange::ALIAS)->leftJoin(sprintf('%s.stock', LevelChange::ALIAS), Stock::ALIAS)->leftJoin(sprintf('%s.stock_item', Stock::ALIAS), StockItem::ALIAS)->leftJoin(sprintf('%s.storage_unit', StockItem::ALIAS), StockUnit::ALIAS)->leftJoin(sprintf('%s.corrector', LevelChange::ALIAS), User::ALIAS)->where(sprintf('%s.id = :id', StockItem::ALIAS))->orderBy(sprintf('%s.created_at', LevelChange::ALIAS), 'desc')->setParameter('id', $stockItem->getId());
     if ($callback) {
         $callback($builder);
     }
     return $this->paginateQueryBuilder($builder, $page, $pageSize);
 }
Example #2
0
 /**
  * @param $itemName
  * @param $unitId
  * @param $currentLevel
  * @param $unitPrice
  * @return callable
  */
 private function createStockItemFormItemLine($itemName, $unitId, $currentLevel, $unitPrice)
 {
     return function (Event $e) use($itemName, $unitId, $currentLevel, $unitPrice) {
         $stockItem = new StockItem();
         $stockItem->setName($itemName);
         /** @var StockUnit $unit */
         $unit = $this->mapper(StockUnit::class)->ref($unitId);
         $stockItem->setUsageUnit($unit);
         $stockItem->setStorageUnit($unit);
         $this->persist($stockItem)->commit();
         $this->getStockService()->addToAllWarehouse($stockItem);
         $warehouse = $e->getParam('warehouse');
         if ($warehouse instanceof Warehouse) {
             $stock = $this->em()->getRepository(Stock::class)->findOneBy(['warehouse' => $warehouse, 'stock_item' => $stockItem]);
             if ($stock instanceof Stock) {
                 $units = $this->getAssocStockUnit();
                 if (isset($units[$unitId])) {
                     $unit = $units[$unitId];
                     $stock->setCurrentLevel($currentLevel * $unit->getRatio());
                     $stock->setCurrentUnitPrice($unitPrice);
                     $this->persist($stock)->commit();
                 }
             }
         }
     };
 }
Example #3
0
 /**
  * @return int|null
  */
 public function getRecordIdOrNull()
 {
     return $this->existingRecord ? $this->existingRecord->getId() : null;
 }