Ejemplo n.º 1
0
 /**
  * @param Product $product
  * @param int $quantity
  * @param string $memo
  * @param InventoryLocation $sourceLocation
  * @param InventoryLocation $destinationLocation
  * @param InventoryTransactionType $transactionType
  * @throws EntityValidatorException
  */
 private function transferProduct(Product $product, $quantity, $memo, InventoryLocation $sourceLocation = null, InventoryLocation $destinationLocation = null, InventoryTransactionType $transactionType = null)
 {
     $debitTransaction = new InventoryTransaction($sourceLocation, $transactionType);
     $debitTransaction->setProduct($product);
     $debitTransaction->setDebitQuantity($quantity);
     $debitTransaction->setMemo($memo);
     $creditTransaction = new InventoryTransaction($destinationLocation, $transactionType);
     $creditTransaction->setProduct($product);
     $creditTransaction->setCreditQuantity($quantity);
     $creditTransaction->setMemo($memo);
     $this->throwValidationErrors($debitTransaction);
     $this->throwValidationErrors($creditTransaction);
     $this->inventoryTransactionRepository->persist($debitTransaction);
     $this->inventoryTransactionRepository->persist($creditTransaction);
     $this->inventoryTransactionRepository->flush();
 }
Ejemplo n.º 2
0
 public function testReduceProductForShrinkage()
 {
     $product = $this->dummyData->getProduct();
     $inventoryLocation = $this->dummyData->getInventoryLocation($this->warehouse);
     $initialTransaction = $this->dummyData->getInventoryTransaction($inventoryLocation, $product);
     $this->entityManager->persist($product);
     $this->entityManager->persist($inventoryLocation);
     $this->entityManager->persist($initialTransaction);
     $this->entityManager->flush();
     $this->inventoryService->reduceProductForShrinkage($product, 1, $inventoryLocation->getId());
     $transactions = $this->inventoryTransactionRepository->findAllByProduct($product);
     $transactions = $this->getDebitCreditTransactions($transactions);
     $debitTransaction = $transactions[0];
     $creditTransaction = $transactions[1];
     $this->assertTrue($debitTransaction->getInventoryLocation() instanceof InventoryLocation);
     $this->assertTrue($debitTransaction->getType()->isShrinkage());
     $this->assertSame(-1, $debitTransaction->getQuantity());
     $this->assertSame('Adjusting inventory: Shrinkage', $debitTransaction->getMemo());
     $this->assertSame(null, $creditTransaction->getInventoryLocation());
     $this->assertTrue($creditTransaction->getType()->isShrinkage());
     $this->assertSame(1, $creditTransaction->getQuantity());
     $this->assertSame('Adjusting inventory: Shrinkage', $creditTransaction->getMemo());
 }
 public function testFindInventoryIdForProductAndQuantityThrowsException()
 {
     $this->setExpectedException(EntityNotFoundException::class, 'InventoryTransaction not found');
     $product = $this->dummyData->getProduct();
     $this->inventoryTransactionRepository->findInventoryIdForProductAndQuantity($product, 2);
 }