Ejemplo n.º 1
0
 /**
  * @param Quotation $quotation
  * @param $type
  * @return Quotation
  */
 public function calculateValues(Quotation $quotation, $type)
 {
     $em = $this->getDoctrine()->getManager();
     $coin = $quotation->getCountry()->getCoin();
     $isLocal = $coin->getIsLocalCountry();
     $idCoin = $coin->getId();
     $current = 1;
     //$agency = $em->getRepository('TSCYABundle:Agency')->getLastRecords(1);
     //$agency = $agency[0];
     $quotation->setTotalSemanas($quotation->getSemanas() + $quotation->getSemanasSummer());
     if (!$isLocal) {
         $current = $em->getRepository('TSCYABundle:ExchangeRateUSD')->getCurrentExchangeRateUSDByCoinId($idCoin);
     }
     $valueInscripcion = 0;
     if ($type == Quotation::FLEXIBLE) {
         $lodgingAmountSummer = round($quotation->getLodging()->getSummerPrice() * $quotation->getSemanasLodgingSummer(), 2);
         $lodgingAmountSingle = round($quotation->getLodging()->getPricePerWeek() * $quotation->getSemanasLodging(), 2);
         $lodgingAmount = $lodgingAmountSingle + $lodgingAmountSummer;
         $quotation->setAmountLodging($lodgingAmount);
         $courseValue = $quotation->getCourseValue() * $quotation->getTotalSemanas();
         $promocion = $em->getRepository('TSCYABundle:Promocion')->getSingleByCourse($quotation->getCourse()->getId());
         if ($promocion) {
             $quotation->setPromocion($promocion);
             $percentage = $promocion->getPercentage();
             $discount = $percentage * $courseValue;
             $courseValue -= $discount;
         }
         $quotation->setAmountCourse(round($courseValue, 2));
         $valueInscripcion = $quotation->getCourse()->getPriceInscription();
     } elseif ($type == Quotation::PACKAGE) {
         $package = $quotation->getPackage();
         $quotation->setSemanas($package->getSemanas());
         if ($quotation->getSemanasLodging() > 0) {
             $lodgingAmountSummer = round($quotation->getLodging()->getSummerPrice() * $quotation->getSemanasLodgingSummer(), 2);
             $lodgingAmountSingle = round($quotation->getLodging()->getPricePerWeek() * $quotation->getSemanasLodging(), 2);
             $lodgingAmount = $lodgingAmountSingle + $lodgingAmountSummer;
         } else {
             $lodgingAmount = round($quotation->getLodging()->getPricePerWeek() * $quotation->getSemanas(), 2);
         }
         if ($quotation->getSemanasLodging() == 0) {
             $packageLodging = $em->getRepository('TSCYABundle:PackageLodging')->getPriceLodgingById($quotation->getLodging()->getId());
             $lodgingPrice = $packageLodging ? $packageLodging->getLodgingPrice() : 0;
             $amountLodging = intval($lodgingPrice) > 0 ? $lodgingPrice : $lodgingAmount;
             $quotation->setAmountLodging(round($amountLodging, 2));
         } else {
             $quotation->setAmountLodging(round($lodgingAmount, 2));
         }
         $valuePackage = $package->getPrice();
         $promocion = $em->getRepository('TSCYABundle:Promocion')->getSingleByPackage($package->getId());
         if ($promocion) {
             $quotation->setPromocion($promocion);
             $percentage = $promocion->getPercentage();
             $discount = $percentage * $valuePackage;
             $valuePackage = $valuePackage - $discount;
         }
         $quotation->setAmountCourse(round($valuePackage, 2));
         $valueInscripcion = $package->getPriceInscription();
     } elseif ($type == Quotation::EXAM) {
         $lodgingAmountSummer = round($quotation->getLodging()->getSummerPrice() * $quotation->getSemanasLodgingSummer(), 2);
         $lodgingAmountSingle = round($quotation->getLodging()->getPricePerWeek() * $quotation->getSemanasLodging(), 2);
         $lodgingAmount = $lodgingAmountSingle + $lodgingAmountSummer;
         $quotation->setAmountLodging($lodgingAmount);
         $valueExam = $quotation->getExamValue() * $quotation->getTotalSemanas();
         $promocion = $em->getRepository('TSCYABundle:Promocion')->getSingleByExam($quotation->getExam()->getId());
         if ($promocion) {
             $quotation->setPromocion($promocion);
             $percentage = $promocion->getPercentage();
             $discount = $percentage * $valueExam;
             $valueExam -= $discount;
         }
         $quotation->setAmountCourse(round($valueExam, 2));
         $valueInscripcion = $quotation->getExam()->getPriceInscription();
     }
     $totalService = 0;
     foreach ($quotation->getService() as $service) {
         $totalService += $this->getPriceServiceByParameters($service, $quotation);
     }
     $quotation->setAmountService(round($totalService, 2));
     $totalLocal = $quotation->getAmountCourse() + $quotation->getAmountLodging() + $quotation->getAmountService() + $valueInscripcion;
     $quotation->setTotalLocal($totalLocal);
     $quotation->setTotalUSD(round($totalLocal * $current, 2));
     $quotation->setTotalLocalCountry(round($quotation->getTotalUSD(), 2));
     return $quotation;
 }
Ejemplo n.º 2
0
 /**
  * @Route("/invoice/pdf/{id}", name="to_pdf_invoice")
  * @ParamConverter("id", class="\TS\CYABundle\Entity\Quotation")
  *
  * @param Quotation $quotation
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function invoiceToPDFAction(Quotation $quotation)
 {
     $html = $this->renderView('@TSCYA/Main/invoice.html.twig', ['quotation' => $quotation]);
     $client = $quotation->getClient();
     $namePDF = sprintf('%s_%s_%s_%s', $client->getFirstName(), $client->getLastName(), $quotation->getSemanas(), $quotation->getHeadquarter()->getName());
     $attachment = sprintf('attachment; filename="%s.pdf"', $namePDF);
     // Nombre, número de semanas y sede
     return new Response($this->get('knp_snappy.pdf')->getOutputFromHtml($html), 200, array('Content-Type' => 'application/pdf', 'Content-Disposition' => $attachment));
 }