Example #1
0
 /**
  * Gets the first stock that has the same attributes (except quantity) that
  * the stock passed as a parameter in the same location
  * 
  * @return \CB\WarehouseBundle\Entity\Stock or null if not found
  */
 public function findEqualInSameLocation(\CB\WarehouseBundle\Entity\Stock $stock)
 {
     //This sentence doesn't works in tests
     //$repository = $this->getDoctrine()->getManager()->getRepository('CBWarehouseBundle:Stock');
     //This sentence works in tests
     $repository = $this->getEntityManager()->getRepository('CBWarehouseBundle:Stock');
     //Stocks found in the same container/location
     $stocksFound = $repository->findBy(array('objectId' => $stock->getObjectId(), 'objectType' => $stock->getObjectType()));
     //Compare with all stocks found and return the first with the same attributes (except quantity)
     foreach ($stocksFound as $s) {
         if ($stock->equals($s)) {
             return $s;
         }
     }
     //If not found an equal stock return null
     return null;
 }
Example #2
0
 public function testEquals()
 {
     //Get a product
     $productOne = $this->CreateTestProduct(10);
     $productTwo = $this->CreateTestProduct(11);
     //Get a pesentation
     $presentation = $this->CreateTestProductPresentation(10);
     //Get a baseQuantity
     $baseQuantity = $stock = new Stock();
     $stock->setProduct($productOne);
     $stock->setLot('L001');
     $stock->setSn('SN0001');
     $stock->setObjectId(2);
     $stock->setObjectType(Stock::OBJECT_TYPE_CONTAINER);
     $stock->setPresentation($presentation);
     $stock->setBaseQuantity(300);
     $stock->setQuantity(300);
     $stock->setBestBeforeDate(new \DateTime('2014-08-20'));
     $stock->setCreatedDate(new \DateTime('2014-08-20'));
     $stock->setExpiryDate(new \DateTime('2014-08-20'));
     $stock->setProductionDate(new \DateTime('2014-08-20'));
     $stock->setRecivedDate(new \DateTime('2014-08-20'));
     $stock->setUpdatedDate(new \DateTime('2014-08-20'));
     //Get the second stock to compare
     $stockTwo = new Stock();
     $stockTwo->setProduct($productOne);
     $stockTwo->setLot('L001');
     $stockTwo->setSn('SN0001');
     $stockTwo->setObjectId(2);
     $stockTwo->setObjectType(Stock::OBJECT_TYPE_CONTAINER);
     $stockTwo->setPresentation($presentation);
     $stockTwo->setBaseQuantity(300);
     $stockTwo->setQuantity(300);
     $stockTwo->setBestBeforeDate(new \DateTime('2014-08-20'));
     $stockTwo->setCreatedDate(new \DateTime('2014-08-20'));
     $stockTwo->setExpiryDate(new \DateTime('2014-08-20'));
     $stockTwo->setProductionDate(new \DateTime('2014-08-20'));
     $stockTwo->setRecivedDate(new \DateTime('2014-08-20'));
     $stockTwo->setUpdatedDate(new \DateTime('2014-08-20'));
     //Verify that two stocks are equal if all the fields are equal
     $this->assertTrue($stock->equals($stockTwo));
     //Verify that stocks with different created, updated, producted, received dates are equal
     $stockTwo->setCreatedDate(new \DateTime('2014-08-21'));
     $stockTwo->setProductionDate(new \DateTime('2014-08-21'));
     $stockTwo->setRecivedDate(new \DateTime('2014-08-21'));
     $stockTwo->setUpdatedDate(new \DateTime('2014-08-21'));
     $this->assertTrue($stock->equals($stockTwo));
     //Verify that stocks with different quantity are equal
     $stockTwo->setBaseQuantity(100);
     $stockTwo->setQuantity(100);
     $this->assertTrue($stock->equals($stockTwo));
     //Verify that stocks with different objectId aren't equal
     $stockTwo->setObjectId(3);
     $this->assertFalse($stock->equals($stockTwo));
     //Verify that stocks with different product aren't equal
     $stock->setProduct($productTwo);
     $this->assertFalse($stock->equals($stockTwo));
     $stock->setProduct($productOne);
     //Verify that stocks with different bestbefore date aren't equal
     $stockTwo->setBestBeforeDate(new \DateTime('2014-08-21'));
     $this->assertFalse($stock->equals($stockTwo));
     $stockTwo->setBestBeforeDate(new \DateTime('2014-08-20'));
     //Verify that stocks with different bestbefore date aren't equal
     $stockTwo->setExpiryDate(new \DateTime('2014-08-21'));
     $this->assertFalse($stock->equals($stockTwo));
 }