/**
  * @return static
  */
 public function withProduct()
 {
     $product = $this->entity->getProduct();
     if (!empty($product)) {
         $this->entityDTO->product = $this->dtoBuilderFactory->getProductDTOBuilder($product)->build();
     }
     return $this;
 }
Exemple #2
0
 public function getInventoryTransaction(InventoryLocation $inventoryLocation = null, Product $product = null)
 {
     if ($inventoryLocation === null) {
         $inventoryLocation = $this->getInventoryLocation();
     }
     if ($product === null) {
         $product = $this->getProduct();
     }
     $inventoryTransaction = new InventoryTransaction($inventoryLocation);
     $inventoryTransaction->setCreditQuantity(2);
     $inventoryTransaction->setProduct($product);
     $inventoryTransaction->setMemo('Initial Inventory');
     return $inventoryTransaction;
 }
 public function testInventoryTransactionFailsIfMoveTypeAndMissingInventoryLocation()
 {
     $product = $this->dummyData->getProduct();
     $inventoryTransaction = new InventoryTransaction();
     $inventoryTransaction->setProduct($product);
     $inventoryTransaction->setDebitQuantity(2);
     $inventoryTransaction->setMemo('Move 2 Widgets');
     $errors = $this->getValidationErrors($inventoryTransaction);
     $this->assertSame(1, count($errors));
     $this->assertSame('inventoryLocation', $errors->get(0)->getPropertyPath());
     $this->assertSame('InventoryLocation must be set for Move operation', $errors->get(0)->getMessage());
 }
 /**
  * @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();
 }