/** * 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; }
/** * 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; } }