public function populateFromDoor(FormPopulatingEvent $event)
 {
     if (null !== ($id = $event->getParam('installation'))) {
         $install = $this->om->getRepository('JLMModelBundle:Door')->find($id);
         $entity = BillFactory::create(new DoorBillBuilder($install));
         $event->getForm()->setData($entity);
     }
 }
 public function populateFromQuote(FormPopulatingEvent $event)
 {
     if (null !== ($id = $event->getParam('quote'))) {
         $quote = $this->om->getRepository('JLMCommerceBundle:Quote')->find($id);
         $entity = BillFactory::create(new VariantBillBuilder($quote));
         $event->getForm()->setData($entity);
     }
 }
 public function populateFromAttribution(FormPopulatingEvent $event)
 {
     if (null !== ($attribution = $this->getAttribution($event))) {
         $options = array('port' => $this->om->getRepository('JLMProductBundle:Product')->find(134));
         $entity = BillFactory::create(new AttributionBillBuilder($attribution, $this->om->getRepository('JLMCommerceBundle:VAT')->find(1)->getRate(), $options));
         $event->getForm()->setData($entity);
         $event->getForm()->add('attribution', 'hidden', array('data' => $attribution->getId(), 'mapped' => false));
     }
 }
 public function populateFromIntervention(FormPopulatingEvent $event)
 {
     if (null !== ($interv = $this->getIntervention($event))) {
         $builder = $interv instanceof Work ? $interv->getQuote() !== null ? new WorkBillBuilder($interv) : null : null;
         $builder = $builder === null ? new InterventionBillBuilder($interv) : $builder;
         $entity = BillFactory::create($builder);
         $event->getForm()->setData($entity);
         $event->getForm()->add('intervention', 'hidden', array('data' => $interv->getId(), 'mapped' => false));
     }
 }
 /**
  * Generate bill
  *
  * @Route("/{id}/bill", name="transmitter_attribution_bill")
  */
 public function billAction(Attribution $entity)
 {
     $em = $this->getDoctrine()->getManager();
     if ($entity->getBill() !== null) {
         return $this->redirect($this->generateUrl('bill_edit', array('id' => $entity->getBill()->getId())));
     }
     // @todo trouver un autre solution que le codage brut
     $options = array('port' => $em->getRepository('JLMProductBundle:Product')->find(134), 'earlyPayment' => (string) $em->getRepository('JLMCommerceBundle:EarlyPaymentModel')->find(1), 'penalty' => (string) $em->getRepository('JLMCommerceBundle:PenaltyModel')->find(1), 'property' => (string) $em->getRepository('JLMCommerceBundle:PropertyModel')->find(1));
     $bill = BillFactory::create(new AttributionBillBuilder($entity, $em->getRepository('JLMCommerceBundle:VAT')->find(1)->getRate(), $options));
     $em->persist($bill);
     $entity->setBill($bill);
     $em->persist($entity);
     $em->flush();
     return $this->redirect($this->generateUrl('bill_edit', array('id' => $bill->getId())));
 }
 /**
  * @dataProvider builders
  */
 public function testBuilders($method)
 {
     $this->builder->expects($this->once())->method($method);
     $this->bill = BillFactory::create($this->builder);
 }
 /**
  * Edits an existing FeesFollower entity.
  *
  * @Route("/{id}/generate", name="fees_generate")
  * @Secure(roles="ROLE_USER")
  */
 public function generateAction(FeesFollower $entity)
 {
     $em = $this->getDoctrine()->getManager();
     $fees = $em->getRepository('JLMFeeBundle:Fee')->createQueryBuilder('a')->select('a')->leftJoin('a.contracts', 'b')->leftJoin('b.door', 'c')->leftJoin('c.site', 'd')->leftJoin('d.address', 'e')->leftJoin('e.city', 'f')->orderBy('f.name', 'asc')->getQuery()->getResult();
     $number = null;
     // @todo Ajouter pas de facture si sous garantie
     foreach ($fees as $fee) {
         $contracts = $fee->getActiveContracts($entity->getActivation());
         if (count($contracts)) {
             $gf = 'getFrequence' . $fee->getFrequence();
             if ($entity->{$gf}() !== null) {
                 // On fait l'augmentation dans le contrat
                 $majoration = $entity->{$gf}();
                 if ($majoration > 0) {
                     foreach ($contracts as $contract) {
                         $amount = $contract->getFee();
                         $amount *= 1 + $majoration;
                         $contract->setFee($amount);
                         $em->persist($contract);
                     }
                 }
                 $builder = new FeeBillBuilder($fee, $entity, array('number' => $number, 'product' => $em->getRepository('JLMProductBundle:Product')->find(284), 'penalty' => (string) $em->getRepository('JLMCommerceBundle:PenaltyModel')->find(1), 'earlyPayment' => (string) $em->getRepository('JLMCommerceBundle:EarlyPaymentModel')->find(1), 'vatTransmitter' => $em->getRepository('JLMCommerceBundle:VAT')->find(1)->getRate()));
                 $bill = BillFactory::create($builder);
                 if ($bill->getTotalPrice() > 0) {
                     $em->persist($bill);
                     $number = $bill->getNumber() + 1;
                 }
             }
         }
     }
     $entity->setGeneration(new \DateTime());
     $em->persist($entity);
     $em->flush();
     return $this->redirect($this->generateUrl('fees', array('id' => $entity->getId())));
 }