/** * 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(); }
/** * @Route(path="/import", name="cva_membership_payments_import") * @param Request $request * @return \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function importAction(Request $request) { if ($request->isMethod('POST')) { $out = ""; $var = $request->request->get('students'); $em = $this->get('doctrine.orm.entity_manager'); $em->beginTransaction(); $product = $em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentVA()[0]; $out .= '<b>Importation de ' . count($var) . ' étudiant(s) :</b><br>'; if ($var != null) { foreach ($var as $student) { if ($student['student'] == '') { $out .= '<span class="text-error">' . $student['firstname'] . ' ' . $student['lastname'] . ' (' . $student['mail'] . ') est déjà adhérant</span><br>'; continue; } $new = false; $r = $em->getRepository("CvaGestionMembreBundle:Etudiant")->findOneBy(array('numEtudiant' => $student['student'])); if ($r == null) { $r = new Etudiant(); $r->setFirstName($student['firstname']); $r->setName($student['lastname']); $r->setCivilite($student['sex']); $r->setMail($student['mail']); $r->setNumEtudiant($student['student']); if ($student['birthday'] != null) { $birthday = new \DateTime(); $birthday->setTimestamp(strtotime($student['birthday'])); $r->setBirthday($birthday); } $new = true; } else { $c = $em->getRepository("CvaGestionMembreBundle:Payment")->createQueryBuilder('p')->select('COUNT(p.id)')->where('p.student = ?1')->andWhere('p.product IN (?2)')->setParameter(1, $r)->setParameter(2, $em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentVAIds())->getQuery()->getSingleScalarResult(); if ($c > 0) { $out .= '<span class="text-warning">' . $r . ' (' . $r->getNumEtudiant() . ') est déjà adhérant</span><br>'; continue; } } $r->setAnnee($student['year']); $r->setDepartement($student['depart']); $em->persist($r); $payment = Payment::generate($r, $product, $student['payment']); $em->persist($payment); $out .= '<span class="text-' . ($new ? 'success' : 'info') . '">' . $r . ' (' . $r->getNumEtudiant() . ')' . ($new ? ' a été créé et' : '') . ' a acheté le produit ' . $product->getName() . '</span><br>'; } } $em->flush(); $em->commit(); return $this->render("CvaGestionMembreBundle:Payments:importResult.html.twig", array('out' => $out)); } else { return $this->render("CvaGestionMembreBundle:Payments:import.html.twig"); } }
/** * {@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(); }
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; }
/** * @Route(path="/student/{id}", name="wizard_student") * @param Request $request * @return \Symfony\Component\HttpKernel\Exception\NotFoundHttpException */ public function studentAction($id, Request $request) { $em = $this->get('doctrine.orm.entity_manager'); $students = $em->getRepository("CvaGestionMembreBundle:Etudiant"); if ($id == "new") { $student = new Etudiant(); $student->setDepartement("PC"); } else { $student = $students->find($id); if (!$student) { throw $this->createNotFoundException('Not found student ' . $id); } } $preRegisteredForWEI = $this->_is_preregistered_for_wei($student) || $student->hasProduct($em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentWEI()) || $student->hasProduct($em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentWEIWaiting()); $formBuilder = $this->createFormBuilder(); $formBuilder->add('student', new StudentType(), array('label' => false, 'data' => $student)); $hasVa = $this->get("bde.va_check")->checkVA($student); $hasWei = $student->hasProduct($em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentWEI()) || $student->hasProduct($em->getRepository("CvaGestionMembreBundle:Produit")->getCurrentWEIWaiting()); if (!$hasVa) { $formBuilder->add('wei', 'choice', ["label" => "WEI", "choices" => ["WEI" => $preRegisteredForWEI ? "Confirme qu'il vient au WEI" : "Veut s'inscrire au WEI", "NOWEI" => $preRegisteredForWEI ? "Ne veut plus aller au WEI" : "Ne veut pas s'inscrire au WEI"], "expanded" => true, 'required' => true, "multiple" => false, 'data' => $preRegisteredForWEI ? "WEI" : "NOWEI", 'disabled' => $hasWei]); $formBuilder->add('va', 'choice', ["label" => "Adhesion VA", "choices" => ["VA" => "Veut adhérer à la VA", "NOVA" => "Ne veut pas adhérer à la VA"], "expanded" => true, 'required' => true, "multiple" => false, "disabled" => $this->get("bde.va_check")->checkVA($student), 'data' => "VA"]); $formBuilder->add('methodPayment', 'choice', array('choices' => array('CHQ' => 'Cheque', 'CB' => 'Carte Bancaire', 'ESP' => 'Espèces'), 'mapped' => true, 'required' => true, 'expanded' => true, "disabled" => $this->get("bde.va_check")->checkVA($student), 'label' => "Moyen de paiement", 'data' => 'CHQ')); } $formBuilder->add('target', 'hidden'); $form = $formBuilder->getForm(); $form->handleRequest($request); if ($form->isValid()) { $data = $form->getData(); /** @var Etudiant $student */ $student = $data['student']; if ($student->getAnnee() == '1' || $student->getAnnee() == '2') { $student->setDepartement('PC'); $this->addFlash('info', "L'étudiant a été réaffecté en Premier Cycle car il est en 1A ou 2A"); } $em->persist($student); $em->flush(); $wantWei = isset($data['wei']) ? $data['wei'] == 'WEI' && !$hasWei : false; $wantVA = isset($data['va']) ? $data['va'] == 'VA' && !$hasVa : false; $methodPayement = $data['methodPayment']; if (!$wantVA && !$this->get("bde.va_check")->checkVA($student)) { $this->addFlash("warning", "L'Etudiant a refusé l'adhésion VA !"); } else { if ($wantVA) { $va = null; if (!$this->get("bde.va_check")->checkVA($student)) { // if the current user is not VA if ($student->getAnnee() == '1') { $va = $em->getRepository("CvaGestionMembreBundle:Produit")->getVAProduct('B'); } else { $va = $em->getRepository("CvaGestionMembreBundle:Produit")->getVAProduct('A'); } $paymentVA = Payment::generate($student, $va, $methodPayement); $em->persist($paymentVA); } if ($wantWei && $student->getAnnee() == '1') { $this->get("bde.wei.registration_management")->register($student, $methodPayement); } elseif ($student->getAnnee() == '1') { $this->get("bde.wei.registration_management")->unregister($student); } $em->flush(); } } return $this->redirectToRoute("wizard_student_abstract", array('id' => $student->getId())); } $products = $em->getRepository("CvaGestionMembreBundle:Produit")->createQueryBuilder('p')->where('p.active = true')->getQuery()->getArrayResult(); $productsIndexed = []; foreach ($products as $product) { if (isset($product['name'])) { $productsIndexed[$product['name']] = $product; } } return $this->render("CvaGestionMembreBundle:Wizard:edit.html.twig", array('form' => $form->createView(), 'products' => $productsIndexed, 'va' => $this->get('bde.va_check'), 'student' => $student)); }
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(); }