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