/**
  * Lists all races and payment amounts for a specific club.
  *
  * @Route("/event/{event}/billing/{club}", name="billing_show")
  * @Method("GET")
  */
 public function showAction(Event $event, Club $club)
 {
     $em = $this->getDoctrine()->getManager();
     /** @var RaceRepository $raceRepo */
     $raceRepo = $em->getRepository('AppBundle:Race');
     // $paid = $repo->findBy(array('event' => $event->getId(), 'club' => $club->getId()));
     $races = $raceRepo->getAllRacesThatHaveRegistrations($event->getId());
     $billingPositions = array();
     $total = 0.0;
     /** @var Race $race */
     foreach ($races as $race) {
         $price = $race->getPricePerStarter();
         /** @var RaceSection $section */
         foreach ($race->getSections() as $section) {
             /** @var Registration $registration */
             foreach ($section->getRegistrations() as $registration) {
                 /** @var Club $myClub */
                 $myClub = $registration->getTeam()->getClub();
                 if ($club->getId() == $myClub->getId()) {
                     // TODO handle de-registered and those from other races
                     if (array_key_exists($race->getId(), $billingPositions)) {
                         $billingPositions[$race->getId()]['teams'] += 1;
                         $billingPositions[$race->getId()]['amount'] += $price;
                     } else {
                         $billingPositions[$race->getId()] = array('teams' => 1, 'amount' => $price, 'race' => $race);
                     }
                     $total += $price;
                 }
             }
         }
     }
     return $this->render('billing/show.html.twig', array('club' => $club, 'event' => $event, 'positions' => $billingPositions, 'rr' => $raceRepo, 'total' => $total));
 }
 /**
  * Check if the total paid is equal to the total of open payments
  *
  * @param Event $event The event to inspect.
  * @param Club $club The club for that the check should be done.
  * @return bool <tt>true</tt> if everything was paid
  */
 public function hasPaidEverything(Event $event, Club $club)
 {
     // search for all billings
     $billings = $this->findBy(array('event' => $event->getId(), 'club' => $club->getId()));
     $totalPaid = 0.0;
     /** @var Billing $billing */
     foreach ($billings as $billing) {
         $totalPaid += $billing->getEuro() + $billing->getCent() / 100.0;
     }
     $toPay = $this->getTotalToPay($event, $club);
     return 0 <= $toPay - $totalPaid;
 }
Example #3
0
 /**
  * Creates a form to delete a Club entity.
  *
  * @param Club $club The Club entity
  *
  * @return \Symfony\Component\Form\Form The form
  */
 private function createDeleteForm(Club $club)
 {
     return $this->createFormBuilder()->setAction($this->generateUrl('club_delete', array('id' => $club->getId())))->setMethod('DELETE')->getForm();
 }
Example #4
0
 /**
  * @param \AppBundle\DRV_Import\Club $club the reference for updating
  * @param LoggerInterface $logger for debugging messages
  * @return \AppBundle\Entity\Club the created or updated club entity
  * @throws \Doctrine\ORM\NonUniqueResultException
  */
 public function createOrUpdate(\AppBundle\DRV_Import\Club $club, LoggerInterface $logger)
 {
     /**
      * @var \AppBundle\Entity\Club $dbItem
      */
     $dbItem = null;
     // first try to find by ID
     if ($club->drv_id > 0) {
         $dbItem = $this->findOneByDrvId($club->drv_id);
     }
     // if this does not help, do a fuzzy search by name
     if (null == $dbItem) {
         $logger->debug("Searching club by name [{$club->name}]");
         $dbItem = $this->createQueryBuilder('c')->where('c.name LIKE :name')->setParameter('name', $club->name)->getQuery()->getOneOrNullResult();
     }
     if (null != $dbItem) {
         $logger->debug("Found club with id [{$dbItem->getId()}] for DRV-ID [{$club->drv_id}]");
         // check and update if necessary
         $updates = false;
         if ($dbItem->getDrvId() != $club->drv_id) {
             $dbItem->setDrvId($club->drv_id);
             $updates = true;
         }
         if ($dbItem->getName() != $club->name) {
             $dbItem->setName($club->name);
             $updates = true;
         }
         if ($dbItem->getShortname() != $club->shortname) {
             $dbItem->setShortname($club->shortname);
             $updates = true;
         }
         if ($dbItem->getAbbreviation() != $club->abbreviation) {
             $dbItem->setAbbreviation($club->abbreviation);
             $updates = true;
         }
         if ($dbItem->getCity() != $club->location) {
             $dbItem->setCity($club->location);
             $updates = true;
         }
         if ($updates) {
             $logger->debug("Updating club with id [{$dbItem->getId()}]");
             $this->getEntityManager()->persist($dbItem);
         }
     } else {
         $logger->debug("Found nothing. Create a new club.");
         // create
         $dbItem = new Club();
         $dbItem->setName($club->name);
         $dbItem->setShortname($club->shortname);
         $dbItem->setAbbreviation($club->abbreviation);
         $dbItem->setDrvId($club->drv_id);
         $dbItem->setCity($club->location);
         $this->getEntityManager()->persist($dbItem);
     }
     return $dbItem;
 }