/**
  * Maps the data of a list of forms into the properties of some data.
  *
  * @param FormInterface[] $forms A list of {@link FormInterface} instances.
  * @param mixed $data Structured data.
  *
  * @throws Exception\UnexpectedTypeException if the type of the data parameter is not supported.
  */
 public function mapFormsToData($forms, &$data)
 {
     $products = array();
     $method = 'NONE';
     foreach ($forms as $form) {
         if ($form->getName() == 'products') {
             $products = $form->getData();
         } elseif ($form->getName() == 'method') {
             $method = $form->getData();
         }
     }
     if ($method == 'NONE') {
         $data = array();
         return;
     }
     $result = array();
     $billId = Payment::generateUUID();
     /** @var Produit $product */
     foreach ($products as $product) {
         $p = new Payment();
         $p->setMethod($method);
         $p->setProduct($product);
         $p->setDate(new \DateTime());
         $p->setBillId($billId);
         $result[] = $p;
     }
     $data = $result;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $methodsMapping = array('Cheque' => 'CHQ', 'CB' => 'CB', 'Especes' => 'ESP');
     /** @var EntityManager $em */
     $em = $this->getContainer()->get("doctrine.orm.entity_manager");
     $em->beginTransaction();
     $output->writeln("Start loading old data ...");
     /** @var Paiement[] $results */
     $results = $em->createQuery("SELECT p FROM CvaGestionMembreBundle:Paiement as p")->getResult();
     $output->writeln("Create new entities ...");
     foreach ($results as $paiement) {
         $billId = $this->getGUID();
         foreach ($paiement->getProduits() as $produit) {
             $payment = new Payment();
             $payment->setBillId($billId);
             $payment->setProduct($produit);
             $payment->setMethod($methodsMapping[$paiement->getMoyenPaiement()]);
             $payment->setStudent($paiement->getIdEtudiant());
             $payment->setDate($paiement->getDateAchat());
             $em->persist($payment);
         }
     }
     $output->writeln("Start injecting in new table ...");
     $em->flush();
     $em->commit();
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get("doctrine.orm.entity_manager");
     $em->beginTransaction();
     $output->writeln("Start loading old data ...");
     $s = $em->getRepository("CvaGestionMembreBundle:Etudiant")->createQueryBuilder('student')->setMaxResults(450)->setFirstResult(500)->getQuery()->getResult();
     $product = $em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentWEI();
     $date = new \DateTime();
     /** @var Etudiant $student */
     foreach ($s as $student) {
         $payment = new Payment();
         $payment->setBillId(Payment::generateUUID());
         $payment->setMethod("CHQ");
         $payment->setProduct($product);
         $payment->setDate($date);
         $payment->setStudent($student);
         $em->persist($payment);
     }
     $em->flush();
     $em->commit();
 }
Ejemplo n.º 4
0
 public static function handleMultipleProducts(Payment $payment, Etudiant $student = null)
 {
     /*###############################################################################
      * Information about this strange engine: (READ IT)
      * The form to input a new payment allows to select multiple Produits
      * but for PERFORMANCES reason in SQL requests the model of Payment only
      * allow to refer one Produit per Payment so to recognise products which
      * has been bought together we use a bill number which is an UUID so
      * it's unique.
      */
     $result = array();
     if ($payment->getMethod() == 'NONE') {
         return $result;
     }
     if ($payment->getProduct() instanceof ArrayCollection) {
         $billId = Payment::generateUUID();
         /** @var Produit $product */
         foreach ($payment->getProduct() as $product) {
             $p = new Payment();
             $p->setMethod($payment->getMethod());
             $p->setProduct($product);
             $p->setDate(new \DateTime());
             $p->setBillId($billId);
             if ($student) {
                 $p->setStudent($student);
             }
             $result[] = $p;
         }
     } else {
         if ($student) {
             $payment->setStudent($student);
         }
         $payment->setBillId(Payment::generateUUID());
         $payment->setDate(new \DateTime());
         $result[] = $payment;
     }
     return $result;
 }
 private function _registerToWei(Etudiant $student, $paymentMethod = null)
 {
     $products = $this->em->getRepository("CvaGestionMembreBundle:Produit");
     $allowedProducts = [$products->getCurrentWEIPreInscription(), $products->getCurrentWEIPreWaiting(), $products->getCurrentWEIWaiting()];
     if (in_array($products->getCurrentWEI(), $student->getProducts())) {
         return true;
     }
     /** @var Payment $payment */
     foreach ($student->getPayments() as $payment) {
         if (in_array($payment->getProduct(), $allowedProducts)) {
             $this->em->remove($payment);
             if ($payment->getProduct()->hasWaitingList()) {
                 $this->removeFromWaitingList($student, $payment->getProduct());
             }
             $newPayment = new Payment();
             $newPayment->setBillId($payment->getBillId());
             $newPayment->setMethod($paymentMethod == null ? $payment->getMethod() : $paymentMethod);
             $newPayment->setStudent($payment->getStudent());
             $newPayment->setDate($payment->getDate());
             $newPayment->setProduct($products->getCurrentWEI());
             $this->em->persist($newPayment);
             $this->em->flush();
             return true;
         }
     }
     return false;
 }
 /**
  * @Route("/unregister/{id}",name="bde_wei_registration_delete",options={"expose"=true})
  * @template
  */
 public function unregisterAction($id)
 {
     $em = $this->get("doctrine.orm.entity_manager");
     $student = $em->getRepository("CvaGestionMembreBundle:Etudiant")->find($id);
     $products = $em->getRepository("CvaGestionMembreBundle:Produit");
     $studentProducts = $student->getProducts();
     if (in_array($products->getCurrentWEI(), $studentProducts) or in_array($products->getCurrentWEIWaiting(), $studentProducts)) {
         $payment = new Payment();
         $payment->setBillId(Payment::generateUUID());
         $payment->setProduct($products->getCurrentWEIRemboursement());
         $payment->setStudent($student);
         $payment->setDate(new \DateTime());
         $payment->setMethod("CHQ");
         $em->persist($payment);
     } else {
         /** @var Payment $payment */
         foreach ($student->getPayments() as $payment) {
             if ($payment->getProduct() == $products->getCurrentWEIPreInscription() || $payment->getProduct() == $products->getCurrentWEIPreWaiting()) {
                 $em->remove($payment);
             }
         }
     }
     $student->setBungalow(null);
     $student->setBus(null);
     $em->persist($student);
     foreach ($studentProducts as $product) {
         $this->get('bde.wei.registration_management')->removeFromWaitingList($student, $product);
     }
     $em->flush();
     return array();
 }