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
 /**
  * Edits an existing Stock entity and splits.
  *
  * @Route("/{id}/split", name="stock_split_update")
  * @Method("PUT")
  * @Template("CBWarehouseBundle:Stock:edit.html.twig")
  */
 public function splitAction(Request $request, $id)
 {
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository('CBWarehouseBundle:Stock')->find($id);
     if (!$entity) {
         throw $this->createNotFoundException('Unable to find Stock entity.');
     }
     $oldQuantity = $entity->getQuantity();
     $oldBaseQuantity = $entity->getBaseQuantity();
     $oldObjectId = $entity->getObjectId();
     $oldObjectType = $entity->getObjectType();
     $deleteForm = $this->createDeleteForm($id);
     $editForm = $this->createEditSplitForm($entity);
     $editForm->handleRequest($request);
     $this->CreateStockMerging($em, $entity, true, 'STOCK_SPLIT', 'STOCK_PICKING', 'UPDATE');
     //$em->persist($this->AddEventLog($em, 'desc', 'STOCK_SPLIT', 'STOCK_PICKING', 'UPDATE', $entity, $entity->getId(), 0));
     $newEntity = new Stock();
     $newEntity->setBestBeforeDate($entity->getBestBeforeDate());
     $newEntity->setExpiryDate($entity->getExpiryDate());
     $newEntity->setLot($entity->getLot());
     $newEntity->setObjectId($oldObjectId);
     $newEntity->setObjectType($oldObjectType);
     $newEntity->setPresentation($entity->getPresentation());
     $newEntity->setProduct($entity->getProduct());
     $newEntity->setProductionDate($entity->getProductionDate());
     $newEntity->setRecivedDate($entity->getRecivedDate());
     $newEntity->setSn($entity->getSn());
     $newEntity->setUpdatedDate($entity->getUpdatedDate());
     $newEntity->setQuantity($oldQuantity - $entity->getQuantity());
     $newEntity->setBaseQuantity($oldBaseQuantity - $entity->getBaseQuantity());
     $em->persist($newEntity);
     $this->CreateStockMerging($em, $newEntity, true, 'STOCK_SPLIT', 'STOCK_PICKING', 'CREATE');
     //$em->flush();
     //$em->persist($this->AddEventLog($em, 'desc', 'STOCK_SPLIT', 'STOCK_PICKING', 'CREATE', $newEntity, $newEntity->getId(), 0));
     //$em->flush();
     return $this->redirect($this->generateUrl('default_index'));
 }
Example #3
0
 /**
  * Compare $this attributes and $otherEntity attributes (except quantity), and return true if they are identical
  * 
  * @param type $otherEntity
  */
 public function equals(Stock $otherEntity)
 {
     if ($this->getBestBeforeDate() == $otherEntity->getBestBeforeDate() && $this->getExpiryDate() == $otherEntity->getExpiryDate() && $this->getLot() == $otherEntity->getLot() && $this->getObjectId() == $otherEntity->getObjectId() && $this->getObjectType() == $otherEntity->getObjectType() && $this->getPresentation() == $otherEntity->getPresentation() && $this->getProduct() == $otherEntity->getProduct() && $this->getSn() == $otherEntity->getSn()) {
         return true;
     } else {
         return false;
     }
 }
Example #4
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));
 }