/**
  * Creates a new Contract entity.
  *
  * @Template("JLMModelBundle:Contract:new.html.twig")
  * @Secure(roles="ROLE_USER")
  */
 public function createAction()
 {
     $entity = new Contract();
     $request = $this->getRequest();
     $form = $this->createForm(new ContractType(), $entity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $em->persist($entity);
         // Temporaire : se fera jour par jour
         // ***********************************
         if ($entity->getInProgress()) {
             $fee = new Fee();
             $fee->addContract($entity);
             $fee->setTrustee($entity->getTrustee());
             $fee->setAddress($entity->getDoor()->getSite()->getAddress()->toString());
             $fee->setPrelabel($entity->getDoor()->getSite()->getBillingPrelabel());
             $fee->setVat($entity->getDoor()->getSite()->getVat());
             $em->persist($fee);
         }
         //***************************************
         $em->flush();
         return $this->redirect($this->generateUrl('door_show', array('id' => $entity->getDoor()->getId())));
     }
     return array('entity' => $entity, 'form' => $form->createView());
 }
 public function testGetGroup()
 {
     $number = '12345';
     $site = $this->getMock('JLM\\ModelBundle\\Entity\\Site');
     $site->expects($this->once())->method('getGroupNumber')->will($this->returnValue($number));
     $door = $this->getMock('JLM\\ModelBundle\\Entity\\Door');
     $door->expects($this->once())->method('getSite')->will($this->returnValue($site));
     $contract = $this->getMock('JLM\\ContractBundle\\Model\\ContractInterface');
     $contract->expects($this->once())->method('getDoor')->will($this->returnValue($door));
     $this->entity->addContract($contract);
     $this->assertSame($number, $this->entity->getGroup());
 }
 public function feeCreate(ContractEvent $event)
 {
     $entity = $event->getContract();
     if ($entity->getInProgress()) {
         $fee = new Fee();
         $fee->addContract($entity);
         $fee->setTrustee($entity->getTrustee());
         $fee->setAddress($entity->getDoor()->getSite()->getAddress()->toString());
         $fee->setPrelabel($entity->getDoor()->getSite()->getBillingPrelabel());
         $fee->setVat($entity->getDoor()->getSite()->getVat());
         $this->om->persist($fee);
         $this->om->flush();
     }
 }
 /**
  * Action temporaire
  * 
  * Création à la volée des redevances
  * 
  * @Route("/autocreate")
  * @Template()
  */
 public function autocreatefeeAction()
 {
     $em = $this->getDoctrine()->getManager();
     $contracts = $em->getRepository('JLMContractBundle:Contract')->findAll();
     foreach ($contracts as $contract) {
         if ($contract->getInProgress()) {
             $fee = new Fee();
             $fee->addContract($contract);
             $fee->setTrustee($contract->getTrustee());
             $fee->setAddress($contract->getDoor()->getSite()->getAddress()->toString());
             $fee->setPrelabel($contract->getDoor()->getSite()->getBillingPrelabel());
             $fee->setVat($contract->getDoor()->getSite()->getVat());
             $em->persist($fee);
         }
     }
     $em->flush();
     return array();
 }