src/MDS/EventsBundle/Controller/ProposalBudgetController.php line 1191

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Mediterranean Develup Solutions
  4.  * User: jorge.defreitas@develup.solutions
  5.  * Date: 11/10/2017
  6.  * Time: 10:27
  7.  */
  8. namespace App\MDS\EventsBundle\Controller;
  9. use App\Entity\Activities;
  10. use App\Entity\Cities;
  11. use App\Entity\Client;
  12. use App\Entity\Configuration;
  13. use App\Entity\Country;
  14. use App\Entity\Destination;
  15. use App\Entity\Ideas;
  16. use App\Entity\Provinces;
  17. use App\Entity\Regions;
  18. use App\Entity\SettingsCompany;
  19. use App\Entity\SettingsRol;
  20. use App\Entity\Supplier;
  21. use App\Entity\SupplierGallery;
  22. use App\Entity\SupplierIdeaServicesControl;
  23. use App\Entity\User;
  24. use App\MDS\EventsBundle\Entity\Proposal;
  25. use App\MDS\EventsBundle\Entity\ProposalAgendaPresupuestoControl;
  26. use App\MDS\EventsBundle\Entity\ProposalAgents;
  27. use App\MDS\EventsBundle\Entity\ProposalControl;
  28. use App\MDS\EventsBundle\Entity\ProposalSupplierControl;
  29. use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
  30. use App\MDS\EventsBundle\Entity\ProposalSupplierServicesBudget;
  31. use App\MDS\EventsBundle\Entity\ProposalSupplierServicesBudgetControl;
  32. use Swift_Mailer;
  33. use Swift_Message;
  34. use Swift_SmtpTransport;
  35. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  36. use Symfony\Component\Routing\Annotation\Route;
  37. use Symfony\Component\HttpFoundation\Request;
  38. use Symfony\Contracts\Translation\TranslatorInterface;
  39. class ProposalBudgetController  extends AbstractController
  40. {
  41.     private $translator;
  42.     public function __construct(TranslatorInterface $translator)
  43.     {
  44.         $this->translator $translator;
  45.     }
  46.     /**
  47.      * @Route("/proposal/makeyourbudget/budget/add/",  name="proposal_destination_supplier_makeyourbudget_Add")
  48.      */
  49.     public function MakeYourBudgetAddSupplierAction(Request $request)
  50.     {
  51.         $em $this->getDoctrine()->getManager();
  52.         $incluir "";
  53.         $proposalid $request->request->get('proposalid');
  54.         $incluir $request->request->get('incluir');
  55.         $incluir_sub $request->request->get('incluir_sub');
  56.         $services $request->request->get('services');
  57.         $recommended $request->request->get('recommended');
  58.         $priority $request->request->get('priority');
  59.         $name $request->request->get('name');
  60.         $byclient null;
  61.         if (is_null($recommended)) {
  62.             $recommended 0;
  63.         } else {
  64.             $recommended 1;
  65.         }
  66.         if (empty($priority)) {
  67.             $priority 0;
  68.         }
  69.         $status "Pending";
  70.         $proposal $em->getRepository(Proposal::class)->findOneById($proposalid);
  71.         /* Obtengo usuario logueado */
  72.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  73.         $user_id $user_logueado->getId();
  74.         if (!empty($incluir)) {
  75.             $control = new ProposalSupplierServicesBudgetControl();
  76.             $control->setProposalId($proposalid);
  77.             $control->setStatus($status);
  78.             $control->setName($name);
  79.             $control->setByClient($byclient);
  80.             $control->setRecommended($recommended);
  81.             $control->setPriority($priority);
  82.             $em->persist($control);
  83.             $em->flush();
  84.             $controlid $control->getId();
  85.             foreach ($incluir as $padentro) {
  86.                 $id $padentro['id'];
  87.                 if (array_key_exists($id$services)) {
  88.                     $services_proposal $em->getRepository(ProposalSupplierServices::class)->findOneById($id);
  89.                     //COLOR POR SERVICIO
  90.                     $contcolor "";
  91.                     switch ($services_proposal->getServiceCatName()) {
  92.                         case "Accommodation":
  93.                             $contcolor 'teal';
  94.                             break;
  95.                         case "Menu":
  96.                             $contcolor 'purple';
  97.                             break;
  98.                         case "Lounge":
  99.                             $contcolor 'warning';
  100.                             break;
  101.                         case "Activities":
  102.                             $contcolor 'blue';
  103.                             break;
  104.                         case "Itineraries":
  105.                             $contcolor 'indigo';
  106.                             break;
  107.                         case "Cruise":
  108.                             $contcolor 'brown';
  109.                             break;
  110.                         case "Transport":
  111.                             $contcolor 'grey';
  112.                             break;
  113.                         case "Av":
  114.                             $contcolor 'slate';
  115.                             break;
  116.                         case "Creative":
  117.                             $contcolor 'orange';
  118.                             break;
  119.                         case "Gifts":
  120.                             $contcolor 'pink';
  121.                             break;
  122.                         case "Entertainment":
  123.                             $contcolor 'green';
  124.                             break;
  125.                         case "Guide":
  126.                             $contcolor 'orange';
  127.                             break;
  128.                         case "Others":
  129.                             $contcolor 'danger';
  130.                             break;
  131.                         case "Technology":
  132.                             $contcolor 'grey-800';
  133.                             break;
  134.                         case "Assistant":
  135.                             $contcolor 'indigo-800';
  136.                             break;
  137.                         case "DDR":
  138.                             $contcolor 'green-300';
  139.                             break;
  140.                     }
  141.                     //                    $var = $services[$id];
  142.                     //                    $servicesBudget = new ProposalSupplierServicesBudget();
  143.                     //                    $servicesBudget->setControlId($controlid);
  144.                     //                    $servicesBudget->setItemsServiceId($id);
  145.                     //                    $servicesBudget->setItemsserviceIdFather('0');
  146.                     //                    $servicesBudget->setProposalId($proposalid);
  147.                     //                    $servicesBudget->setDestinationId($services_proposal->getDestinationId());
  148.                     //                    $servicesBudget->setSupplierId($services_proposal->getSupplierId());
  149.                     //                    $servicesBudget->setIdeaId($services_proposal->getIdeaId());
  150.                     //                    $servicesBudget->setServiceId($services_proposal->getServiceId());
  151.                     //                    $servicesBudget->setServiceCatId($services_proposal->getServiceCatId());
  152.                     //                    $servicesBudget->setServiceCatName($services_proposal->getServiceCatName());
  153.                     //                    $servicesBudget->setContColor($contcolor);
  154.                     //                    $servicesBudget->setName($services_proposal->getName());
  155.                     //                    $servicesBudget->setPrice($var['price']); // <--- OJO AQUI METER LO DE CON IVA Y SISN IVA
  156.                     //                    $servicesBudget->setCurrency($services_proposal->getCurrency());
  157.                     //                    $servicesBudget->setUnits($var['units']);
  158.                     //                    $servicesBudget->setPax($var['pax']);
  159.                     //                    $servicesBudget->setDays($var['days']);
  160.                     //                    $servicesBudget->setDateInAt($services_proposal->getDateInAt());
  161.                     //                    $servicesBudget->setDateOutAt($services_proposal->getDateOutAt());
  162.                     //                    $servicesBudget->setNetAmount($var['netamount']);
  163.                     //                    $servicesBudget->setIva($var['iva']);
  164.                     //                    $servicesBudget->setTotal($var['total']);
  165.                     //                    $servicesBudget->setStatus($status);
  166.                     //                    $servicesBudget->setRank($var['rank']);
  167.                     //                    $servicesBudget->setCreatedId($user_id);
  168.                     //                    $servicesBudget->setUpdatedId($user_id);
  169.                     //                    $em->persist($servicesBudget);
  170.                     //                    $em->flush();
  171.                     $var $services[$id];
  172.                     // UNITS
  173.                     if (empty($var['units']) or $var['units'] == 0) {
  174.                         $units "1";
  175.                     } else {
  176.                         $units $var['units'];
  177.                     }
  178.                     // PAX
  179.                     if (empty($var['pax']) or $var['pax'] == 0) {
  180.                         $pax "1";
  181.                     } else {
  182.                         $pax $var['pax'];
  183.                     }
  184.                     // Calculo Especial por categoria
  185.                     //Alojamientos
  186.                     if ($services_proposal->getServiceCatId() == "1") {
  187.                         $pax "1";
  188.                     }
  189.                     //Transporte
  190.                     elseif ($services_proposal->getServiceCatId() == "13") {
  191.                         $pax "1";
  192.                     }
  193.                     //Lounge
  194.                     elseif ($services_proposal->getServiceCatId() == "10") {
  195.                         $pax "1";
  196.                     }
  197.                     //Guia
  198.                     elseif ($services_proposal->getServiceCatId() == "8") {
  199.                         $pax "1";
  200.                     }
  201.                     // CALCULO DEL NETO
  202.                     $netamount $var['price'] * $units $pax $var['days'];
  203.                     // CALCULO DEL TOTAL
  204.                     $iva = ($var['iva'] / 100) + 1;
  205.                     $total $netamount $iva;
  206.                     $servicesBudget = new ProposalSupplierServicesBudget();
  207.                     $servicesBudget->setControlId($controlid);
  208.                     $servicesBudget->setItemsServiceId($id);
  209.                     $servicesBudget->setItemsserviceIdFather('0');
  210.                     $servicesBudget->setProposalId($proposalid);
  211.                     $servicesBudget->setDestinationId($services_proposal->getDestinationId());
  212.                     $servicesBudget->setSupplierId($services_proposal->getSupplierId());
  213.                     $servicesBudget->setIdeaId($services_proposal->getIdeaId());
  214.                     $servicesBudget->setActivityId($services_proposal->getActivityId());
  215.                     $servicesBudget->setServiceId($services_proposal->getServiceId());
  216.                     $servicesBudget->setServiceCatId($services_proposal->getServiceCatId());
  217.                     $servicesBudget->setServiceCatName($services_proposal->getServiceCatName());
  218.                     $servicesBudget->setContColor($contcolor);
  219.                     $servicesBudget->setName($services_proposal->getName());
  220.                     $servicesBudget->setPrice($var['price']);
  221.                     $servicesBudget->setCurrency($services_proposal->getCurrency());
  222.                     $servicesBudget->setUnits($var['units']);
  223.                     $servicesBudget->setPax($var['pax']);
  224.                     $servicesBudget->setDays($var['days']);
  225.                     $servicesBudget->setDateInAt($services_proposal->getDateInAt());
  226.                     $servicesBudget->setDateOutAt($services_proposal->getDateOutAt());
  227.                     $servicesBudget->setNetAmount($netamount);
  228.                     $servicesBudget->setIva($var['iva']);
  229.                     $servicesBudget->setTotal($total);
  230.                     $servicesBudget->setStatus($status);
  231.                     $servicesBudget->setRank($var['rank']);
  232.                     $servicesBudget->setCreatedId($user_id);
  233.                     $servicesBudget->setUpdatedId($user_id);
  234.                     $em->persist($servicesBudget);
  235.                     $em->flush();
  236.                 }
  237.                 //                if (!empty($incluir_sub)){
  238.                 //
  239.                 //                    foreach($incluir_sub as $idpapa => $incluirSub){
  240.                 //
  241.                 //                        if ($id == $idpapa){
  242.                 //
  243.                 //                            foreach($incluirSub as $hijopadentro){
  244.                 //
  245.                 //                                $idp = $hijopadentro['id'];
  246.                 //
  247.                 //                                if (array_key_exists($idp, $services)) {
  248.                 //                                    $services_proposal= $em->getRepository(ProposalSupplierServices::class)->findOneById($idp);
  249.                 //
  250.                 //                                    //COLOR POR SERVICIO
  251.                 //                                    $contcolor ="";
  252.                 //                                    switch ($services_proposal->getServiceCatName()) {
  253.                 //                                        case "Accommodation":
  254.                 //                                            $contcolor = 'teal';
  255.                 //                                            break;
  256.                 //                                        case "Menu" :
  257.                 //                                            $contcolor = 'purple';
  258.                 //                                            break;
  259.                 //                                        case "Lounge":
  260.                 //                                            $contcolor = 'warning';
  261.                 //                                            break;
  262.                 //                                        case "Activities":
  263.                 //                                            $contcolor = 'blue';
  264.                 //                                            break;
  265.                 //                                        case "Itineraries":
  266.                 //                                            $contcolor = 'indigo';
  267.                 //                                            break;
  268.                 //                                        case "Cruise":
  269.                 //                                            $contcolor = 'brown';
  270.                 //                                            break;
  271.                 //                                        case "Transport":
  272.                 //                                            $contcolor = 'grey';
  273.                 //                                            break;
  274.                 //                                        case "Av":
  275.                 //                                            $contcolor = 'slate';
  276.                 //                                            break;
  277.                 //                                        case "Creative":
  278.                 //                                            $contcolor = 'orange';
  279.                 //                                            break;
  280.                 //                                        case "Gifts":
  281.                 //                                            $contcolor = 'pink';
  282.                 //                                            break;
  283.                 //                                        case "Entertainment":
  284.                 //                                            $contcolor = 'green';
  285.                 //                                            break;
  286.                 //                                        case "Guide":
  287.                 //                                            $contcolor = 'orange';
  288.                 //                                            break;
  289.                 //                                        case "Others":
  290.                 //                                            $contcolor = 'danger';
  291.                 //                                            break;
  292.                 //                                        case "Technology":
  293.                 //                                            $contcolor = 'grey-800';
  294.                 //                                            break;
  295.                 //                                        case "Assistant":
  296.                 //                                            $contcolor = 'indigo-800';
  297.                 //                                            break;
  298.                 //                                    }
  299.                 //
  300.                 //                                    // UNITS
  301.                 //                                    if (empty($var['units']) or $var['units'] == 0){ $units = "1"; }else{ $units = $var['units']; }
  302.                 //                                    // PAX
  303.                 //                                    if (empty($var['pax']) or $var['pax'] == 0){ $pax = "1"; }else{ $pax = $var['pax']; }
  304.                 //
  305.                 //                                    // CALCULO DEL NETO
  306.                 //                                    $netamount = $services_proposal->getPrice() * $units * $pax * $var['days'];
  307.                 //                                    // CALCULO DEL TOTAL
  308.                 //                                    $total = $netamount * ($var['iva'] + 1);
  309.                 //
  310.                 //                                    $var = $services[$idp];
  311.                 //                                    $servicesBudget = new ProposalSupplierServicesBudget();
  312.                 //                                    $servicesBudget->setControlId($controlid);
  313.                 //                                    $servicesBudget->setItemsServiceId($idp);
  314.                 //                                    $servicesBudget->setItemsserviceIdFather($id);
  315.                 //                                    $servicesBudget->setProposalId($proposalid);
  316.                 //                                    $servicesBudget->setDestinationId($services_proposal->getDestinationId());
  317.                 //                                    $servicesBudget->setSupplierId($services_proposal->getSupplierId());
  318.                 //                                    $servicesBudget->setServiceId($services_proposal->getServiceId());
  319.                 //                                    $servicesBudget->setServiceCatId($services_proposal->getServiceCatId());
  320.                 //                                    $servicesBudget->setServiceCatName($services_proposal->getServiceCatName());
  321.                 //                                    $servicesBudget->setContColor($contcolor);
  322.                 //                                    $servicesBudget->setName($services_proposal->getName());
  323.                 //                                    $servicesBudget->setPrice($services_proposal->getPrice());
  324.                 //                                    $servicesBudget->setCurrency($services_proposal->getCurrency());
  325.                 //                                    $servicesBudget->setUnits($var['units']);
  326.                 //                                    $servicesBudget->setPax($var['pax']);
  327.                 //                                    $servicesBudget->setDays($var['days']);
  328.                 //                                    $servicesBudget->setDateInAt($services_proposal->getDateInAt());
  329.                 //                                    $servicesBudget->setDateOutAt($services_proposal->getDateOutAt());
  330.                 //                                    $servicesBudget->setNetAmount($netamount);
  331.                 //                                    $servicesBudget->setIva($var['iva']);
  332.                 //                                    $servicesBudget->setTotal($total);
  333.                 //                                    $servicesBudget->setStatus($status);
  334.                 //                                    $servicesBudget->setRank($var['rank']);
  335.                 //                                    $servicesBudget->setCreatedId($user_id);
  336.                 //                                    $servicesBudget->setUpdatedId($user_id);
  337.                 //                                    $em->persist($servicesBudget);
  338.                 //                                    $em->flush();
  339.                 //
  340.                 //                                }
  341.                 //
  342.                 //
  343.                 //                            }
  344.                 //                        }
  345.                 //
  346.                 //                    }
  347.                 //                }
  348.             }
  349.         } else {
  350.             $errorMessagebase $this->translator->trans('Error, you have not selected any service');
  351.             $this->addFlash('mensajeproposalbudgetserviceserror'$errorMessagebase);
  352.             return $this->redirectToRoute(
  353.                 'proposal_destination_supplier_makeyourbudget',
  354.                 array(
  355.                     'id' => $proposalid
  356.                 )
  357.             );
  358.         }
  359.         return $this->redirectToRoute(
  360.             'proposal_destination_supplier_makeyourbudget_view',
  361.             array(
  362.                 'id' => $proposalid,
  363.                 'idcontrol' => $controlid,
  364.             )
  365.         );
  366.     }
  367.     /**
  368.      * @Route("/proposal/makeyourbudget/budget/view/{id}/{idcontrol}",  name="proposal_destination_supplier_makeyourbudget_view")
  369.      */
  370.     public function MakeYourBudgetViewSupplierAction($id$idcontrolRequest $request)
  371.     {
  372.         $em $this->getDoctrine()->getManager();
  373.         $proposal $em->getRepository(Proposal::class)->findOneById($id);
  374.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  375.         $country $em->getRepository(Country::class)->findOneById($client->getCountry());
  376.         $client->setCountry($country->getCountry());
  377.         $regions $em->getRepository(Regions::class)->findOneById($client->getRegion());
  378.         $client->setRegion($regions->getRegion());
  379.         $province $em->getRepository(Provinces::class)->findOneById($client->getProvince());
  380.         $client->setProvince($province->getName());
  381.         $cities $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  382.         $client->setPopulation($cities->getCity());
  383.         $data_controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
  384.         $controlproposal $em->getRepository(ProposalControl::class)->findByProposalId($id);
  385.         $controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($id);
  386.         foreach ($controlbudgets as $controlbudge) {
  387.             $presupuesto['byclient'] = $controlbudge->getByClient();
  388.             $presupuesto['id'] = $controlbudge->getId();
  389.             $presupuesto['name'] = $controlbudge->getName();
  390.             $presupuesto['priority'] = $controlbudge->getPriority();
  391.             $presupuesto['proposalId'] = $controlbudge->getProposalId();
  392.             $presupuesto['recommended'] = $controlbudge->getRecommended();
  393.             $presupuesto['status'] = $controlbudge->getStatus();
  394.             $hasDiary $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
  395.                 array(
  396.                     'proposalId' => $controlbudge->getProposalId(),
  397.                     'controlId' => $controlbudge->getId(),
  398.                 )
  399.             );
  400.             if ($hasDiary) {
  401.                 $presupuesto['hasDiary'] = true;
  402.             } else {
  403.                 $presupuesto['hasDiary'] = false;
  404.             }
  405.             $controlbudget[$controlbudge->getRecommended()][] = $presupuesto;
  406.         }
  407.         $controlbudgetBoton $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
  408.         $filtro2 = array();
  409.         foreach ($controlproposal as $consultabudget2) {
  410.             $filtro2[] = $consultabudget2->getDestinationId();
  411.         }
  412.         $services_supplier = array();
  413.         $services_ideas = array();
  414.         $budget = array();
  415.         $content_data = array();
  416.         $destination = array();
  417.         $totales_neto "0";
  418.         $totales_total "0";
  419.         $totales_iva = array();
  420.         $data = array();
  421.         foreach ($filtro2 as $destinobudget) {
  422.             $destination $em->getRepository(Destination::class)->findOneById($destinobudget);
  423.             $destino $destination->getTitle();
  424.             $consulta_budget $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  425.                 array(
  426.                     'controlId' => $idcontrol,
  427.                     'destinationId' => $destinobudget,
  428.                     'itemsserviceIdFather' => '0'
  429.                 ),
  430.                 array(
  431.                     'rank' => 'DESC'
  432.                 )
  433.             );
  434.             $filtro = array();
  435.             foreach ($consulta_budget as $consultabudget) {
  436.                 if (!is_null($consultabudget->getActivityId())) {
  437.                     $filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
  438.                 }
  439.                 if (!is_null($consultabudget->getIdeaId())) {
  440.                     $filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
  441.                 }
  442.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
  443.                     $filtro['whiteservice']['0'][] = $consultabudget;
  444.                 }
  445.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
  446.                     $filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
  447.                 }
  448.                 //                $filtro[$consultabudget->getSupplierId()] = $consultabudget;
  449.             }
  450.             //            d($filtro);
  451.             //
  452.             $master "";
  453.             $services = array();
  454.             $whiteservice = array();
  455.             $idea = array();
  456.             $activity = array();
  457.             $supplier = array();
  458.             foreach ($filtro as $key => $ideaOsupplier) {
  459.                 //                d("·········································", $ideaOsupplier);
  460.                 foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
  461.                     //                    d($ideaOsupplierAdentro);
  462.                     $services = array();
  463.                     $total_neto null;
  464.                     $total_total null;
  465.                     foreach ($ideaOsupplierAdentro as $servicesbudget) {
  466.                         //                        d($servicesbudget);
  467.                         //                        $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva()/100);
  468.                         //                        if (empty($totales_iva[$servicesbudget->getIva()])){
  469.                         //                            $totales_iva[$servicesbudget->getIva()] = 0;
  470.                         //                        }
  471.                         //                        $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  472.                         //                        $total_neto += $servicesbudget->getNetAmount();
  473.                         //                        $totales_neto += $servicesbudget->getNetAmount();
  474.                         //                        $total_total += $servicesbudget->getTotal();
  475.                         //                        $totales_total += $servicesbudget->getTotal();
  476.                         if ($key == "whiteservice") {
  477.                             $services_white $em->getRepository(Configuration::class)->findOneById('1');
  478.                             $master "whiteservice";
  479.                             $services[] = array(
  480.                                 'service' => $servicesbudget
  481.                             );
  482.                             $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  483.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  484.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  485.                             }
  486.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  487.                             $totales_neto += $servicesbudget->getNetAmount();
  488.                             $total_total += $servicesbudget->getTotal();
  489.                             //                            if (is_numeric($servicesbudget->getNetAmount())){
  490.                             //                                $totales_neto += $servicesbudget->getNetAmount();
  491.                             //                            }else{
  492.                             //                                $totales_neto += 0;
  493.                             //                            }
  494.                             //                            if (is_numeric($servicesbudget->getTotal())){
  495.                             //                                $total_total += $servicesbudget->getTotal();
  496.                             //                            }else{
  497.                             //                                $total_total += 0;
  498.                             //                            }
  499.                             $totales_total += $servicesbudget->getTotal();
  500.                             $whiteservice[$services_white->getId()]  = array(
  501.                                 'datos' => $services_white,
  502.                                 'services' => $services,
  503.                                 'master' => $master,
  504.                                 'neto' => $total_neto,
  505.                                 'total' => $total_total
  506.                             );
  507.                             //                            $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  508.                             //                                array(
  509.                             //                                    'controlId' => $idcontrol,
  510.                             //                                    'destinationId' => $destinobudget,
  511.                             //                                    'supplierId' => '0',
  512.                             //                                ),
  513.                             //                                array(
  514.                             //                                    'rank' => 'ASC'
  515.                             //                                )
  516.                             //                            );
  517.                         }
  518.                         if ($key == "activity") {
  519.                             $services_activities $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
  520.                             $master "activity";
  521.                             $services[] = array(
  522.                                 'service' => $servicesbudget
  523.                             );
  524.                             $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  525.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  526.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  527.                             }
  528.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  529.                             $total_neto += $servicesbudget->getNetAmount();
  530.                             $totales_neto += $servicesbudget->getNetAmount();
  531.                             $total_total += $servicesbudget->getTotal();
  532.                             $totales_total += $servicesbudget->getTotal();
  533.                             $activity[$services_activities->getId()] = array(
  534.                                 'datos' => $services_activities,
  535.                                 'services' => $services,
  536.                                 'master' => $master,
  537.                                 'neto' => $total_neto,
  538.                                 'total' => $total_total
  539.                             );
  540.                             //                            foreach($services_ideas as $serviceideas){
  541.                             //
  542.                             //                                $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  543.                             //                                    array(
  544.                             //                                        'controlId' => $idcontrol,
  545.                             //                                        'destinationId' => $destinobudget,
  546.                             //                                        'ideaId' => $serviceideas->getId(),
  547.                             //                                    ),
  548.                             //                                    array(
  549.                             //                                        'rank' => 'ASC'
  550.                             //                                    )
  551.                             //                                );
  552.                             //
  553.                             //                            }
  554.                         }
  555.                         if ($key == "idea") {
  556.                             $services_ideas $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
  557.                             $master "idea";
  558.                             $services[] = array(
  559.                                 'service' => $servicesbudget
  560.                             );
  561.                             $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  562.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  563.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  564.                             }
  565.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  566.                             $total_neto += $servicesbudget->getNetAmount();
  567.                             $totales_neto += $servicesbudget->getNetAmount();
  568.                             $total_total += $servicesbudget->getTotal();
  569.                             $totales_total += $servicesbudget->getTotal();
  570.                             $idea[$services_ideas->getId()] = array(
  571.                                 'datos' => $services_ideas,
  572.                                 'services' => $services,
  573.                                 'master' => $master,
  574.                                 'neto' => $total_neto,
  575.                                 'total' => $total_total
  576.                             );
  577.                             //                            foreach($services_ideas as $serviceideas){
  578.                             //
  579.                             //                                $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  580.                             //                                    array(
  581.                             //                                        'controlId' => $idcontrol,
  582.                             //                                        'destinationId' => $destinobudget,
  583.                             //                                        'ideaId' => $serviceideas->getId(),
  584.                             //                                    ),
  585.                             //                                    array(
  586.                             //                                        'rank' => 'ASC'
  587.                             //                                    )
  588.                             //                                );
  589.                             //
  590.                             //                            }
  591.                         }
  592.                         if ($key == "supplier") {
  593.                             if (is_null($servicesbudget->getIdeaId()) and is_null($servicesbudget->getActivityId())) {
  594.                                 $servicessupplier $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
  595.                                 $master "supplier";
  596.                                 //                            foreach($services_supplier as $servicessupplier){
  597.                                 if (!is_null($servicessupplier)) {
  598.                                     switch ($servicessupplier->getStar()) {
  599.                                         case 1:
  600.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i>');
  601.                                             break;
  602.                                         case 2:
  603.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  604.                                             break;
  605.                                         case 3:
  606.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  607.                                             break;
  608.                                         case 4:
  609.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  610.                                             break;
  611.                                         case 5:
  612.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> SUP');
  613.                                             break;
  614.                                         case 6:
  615.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  616.                                             break;
  617.                                         case 7:
  618.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
  619.                                             break;
  620.                                         case 8:
  621.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
  622.                                             break;
  623.                                     }
  624.                                 }
  625.                                 //                                $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  626.                                 //                                    array(
  627.                                 //                                        'controlId' => $idcontrol,
  628.                                 //                                        'destinationId' => $destinobudget,
  629.                                 //                                        'supplierId' => $servicessupplier->getId(),
  630.                                 //                                    ),
  631.                                 //                                    array(
  632.                                 //                                        'rank' => 'ASC'
  633.                                 //                                    )
  634.                                 //                                );
  635.                                 //                            }
  636.                                 $services[] = array(
  637.                                     'service' => $servicesbudget
  638.                                 );
  639.                                 $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  640.                                 if (empty($totales_iva[$servicesbudget->getIva()])) {
  641.                                     $totales_iva[$servicesbudget->getIva()] = 0;
  642.                                 }
  643.                                 //                                d($servicesbudget); exit();
  644.                                 $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  645.                                 $total_neto += $servicesbudget->getNetAmount();
  646.                                 $totales_neto += $servicesbudget->getNetAmount();
  647.                                 $total_total += $servicesbudget->getTotal();
  648.                                 $totales_total += $servicesbudget->getTotal();
  649.                                 $supplier[$servicessupplier->getId()] = array(
  650.                                     'datos' => $servicessupplier,
  651.                                     'services' => $services,
  652.                                     'master' => $master,
  653.                                     'neto' => $total_neto,
  654.                                     'total' => $total_total
  655.                                 );
  656.                             }
  657.                         }
  658.                         //                        d($totales_neto, $totales_total );
  659.                     }
  660.                 }
  661.             }
  662.             //            d($supplier);
  663.             $content_data = array(
  664.                 'supplier' => $supplier,
  665.                 'idea' => $idea,
  666.                 'activity' => $activity,
  667.                 'whiteservice' => $whiteservice,
  668.             );
  669.             $data[] = array(
  670.                 'destination' => $destination,
  671.                 'container' => $content_data
  672.             );
  673.         }
  674.         //        d($controlbudget);
  675.         return $this->render(
  676.             'MDS/EventsBundle/budget/services-budget-proposal.html.twig',
  677.             array(
  678.                 'id' => $id,
  679.                 'token' => $proposal->getAccessKey(),
  680.                 'mcp' => $proposal->getMcp(),
  681.                 'client' => $client,
  682.                 'budgets' => $controlbudget,
  683.                 'budgetcontrol' => $data_controlbudgets,
  684.                 'data' => $data,
  685.                 'totales_neto' => $totales_neto,
  686.                 'ivas' => $totales_iva,
  687.                 'totales' => $totales_total,
  688.                 'confirm' => $controlbudgetBoton
  689.             )
  690.         );
  691.     }
  692.     /**
  693.      * @Route("/proposal/makeyourbudget/budget/viewprint/{id}/{idcontrol}",  name="proposal_destination_supplier_makeyourbudget_view_print")
  694.      */
  695.     public function MakeYourBudgetViewPrintSupplierAction($id$idcontrolRequest $request)
  696.     {
  697.         $em $this->getDoctrine()->getManager();
  698.         $proposal $em->getRepository(Proposal::class)->findOneById($id);
  699.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  700.         $country $em->getRepository(Country::class)->findOneById($client->getCountry());
  701.         $client->setCountry($country->getCountry());
  702.         $regions $em->getRepository(Regions::class)->findOneById($client->getRegion());
  703.         $client->setRegion($regions->getRegion());
  704.         $province $em->getRepository(Provinces::class)->findOneById($client->getProvince());
  705.         $client->setProvince($province->getName());
  706.         $cities $em->getRepository(Cities::class)->findOneById($client->getPopulation());
  707.         $client->setPopulation($cities->getCity());
  708.         $data_controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
  709.         $controlproposal $em->getRepository(ProposalControl::class)->findByProposalId($id);
  710.         $controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($id);
  711.         foreach ($controlbudgets as $controlbudge) {
  712.             $presupuesto['byclient'] = $controlbudge->getByClient();
  713.             $presupuesto['id'] = $controlbudge->getId();
  714.             $presupuesto['name'] = $controlbudge->getName();
  715.             $presupuesto['priority'] = $controlbudge->getPriority();
  716.             $presupuesto['proposalId'] = $controlbudge->getProposalId();
  717.             $presupuesto['recommended'] = $controlbudge->getRecommended();
  718.             $presupuesto['status'] = $controlbudge->getStatus();
  719.             $hasDiary $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
  720.                 array(
  721.                     'proposalId' => $controlbudge->getProposalId(),
  722.                     'controlId' => $controlbudge->getId(),
  723.                 )
  724.             );
  725.             if ($hasDiary) {
  726.                 $presupuesto['hasDiary'] = true;
  727.             } else {
  728.                 $presupuesto['hasDiary'] = false;
  729.             }
  730.             $controlbudget[$controlbudge->getRecommended()][] = $presupuesto;
  731.         }
  732.         $controlbudgetBoton $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
  733.         $filtro2 = array();
  734.         foreach ($controlproposal as $consultabudget2) {
  735.             $filtro2[] = $consultabudget2->getDestinationId();
  736.         }
  737.         $services_supplier = array();
  738.         $services_ideas = array();
  739.         $budget = array();
  740.         $content_data = array();
  741.         $destination = array();
  742.         $totales_neto "0";
  743.         $totales_total "0";
  744.         $totales_iva = array();
  745.         $data = array();
  746.         foreach ($filtro2 as $destinobudget) {
  747.             $destination $em->getRepository(Destination::class)->findOneById($destinobudget);
  748.             $destino $destination->getTitle();
  749.             $consulta_budget $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  750.                 array(
  751.                     'controlId' => $idcontrol,
  752.                     'destinationId' => $destinobudget,
  753.                     'itemsserviceIdFather' => '0'
  754.                 ),
  755.                 array(
  756.                     'rank' => 'DESC'
  757.                 )
  758.             );
  759.             $filtro = array();
  760.             foreach ($consulta_budget as $consultabudget) {
  761.                 if (!is_null($consultabudget->getActivityId())) {
  762.                     $filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
  763.                 }
  764.                 if (!is_null($consultabudget->getIdeaId())) {
  765.                     $filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
  766.                 }
  767.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
  768.                     $filtro['whiteservice']['0'][] = $consultabudget;
  769.                 }
  770.                 if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
  771.                     $filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
  772.                 }
  773.                 //                $filtro[$consultabudget->getSupplierId()] = $consultabudget;
  774.             }
  775.             //            d($filtro);
  776.             //
  777.             $master "";
  778.             $services = array();
  779.             $whiteservice = array();
  780.             $idea = array();
  781.             $activity = array();
  782.             $supplier = array();
  783.             foreach ($filtro as $key => $ideaOsupplier) {
  784.                 //                d("·········································", $ideaOsupplier);
  785.                 foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
  786.                     //                    d($ideaOsupplierAdentro);
  787.                     $services = array();
  788.                     $total_neto null;
  789.                     $total_total null;
  790.                     foreach ($ideaOsupplierAdentro as $servicesbudget) {
  791.                         //                        d($servicesbudget);
  792.                         //                        $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva()/100);
  793.                         //                        if (empty($totales_iva[$servicesbudget->getIva()])){
  794.                         //                            $totales_iva[$servicesbudget->getIva()] = 0;
  795.                         //                        }
  796.                         //                        $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  797.                         //                        $total_neto += $servicesbudget->getNetAmount();
  798.                         //                        $totales_neto += $servicesbudget->getNetAmount();
  799.                         //                        $total_total += $servicesbudget->getTotal();
  800.                         //                        $totales_total += $servicesbudget->getTotal();
  801.                         if ($key == "whiteservice") {
  802.                             $services_white $em->getRepository(Configuration::class)->findOneById('1');
  803.                             $master "whiteservice";
  804.                             $services[] = array(
  805.                                 'service' => $servicesbudget
  806.                             );
  807.                             $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  808.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  809.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  810.                             }
  811.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  812.                             $totales_neto += $servicesbudget->getNetAmount();
  813.                             $total_total += $servicesbudget->getTotal();
  814.                             //                            if (is_numeric($servicesbudget->getNetAmount())){
  815.                             //                                $totales_neto += $servicesbudget->getNetAmount();
  816.                             //                            }else{
  817.                             //                                $totales_neto += 0;
  818.                             //                            }
  819.                             //                            if (is_numeric($servicesbudget->getTotal())){
  820.                             //                                $total_total += $servicesbudget->getTotal();
  821.                             //                            }else{
  822.                             //                                $total_total += 0;
  823.                             //                            }
  824.                             $totales_total += $servicesbudget->getTotal();
  825.                             $whiteservice[$services_white->getId()]  = array(
  826.                                 'datos' => $services_white,
  827.                                 'services' => $services,
  828.                                 'master' => $master,
  829.                                 'neto' => $total_neto,
  830.                                 'total' => $total_total
  831.                             );
  832.                             //                            $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  833.                             //                                array(
  834.                             //                                    'controlId' => $idcontrol,
  835.                             //                                    'destinationId' => $destinobudget,
  836.                             //                                    'supplierId' => '0',
  837.                             //                                ),
  838.                             //                                array(
  839.                             //                                    'rank' => 'ASC'
  840.                             //                                )
  841.                             //                            );
  842.                         }
  843.                         if ($key == "activity") {
  844.                             $services_activities $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
  845.                             $master "activity";
  846.                             $services[] = array(
  847.                                 'service' => $servicesbudget
  848.                             );
  849.                             $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  850.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  851.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  852.                             }
  853.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  854.                             $total_neto += $servicesbudget->getNetAmount();
  855.                             $totales_neto += $servicesbudget->getNetAmount();
  856.                             $total_total += $servicesbudget->getTotal();
  857.                             $totales_total += $servicesbudget->getTotal();
  858.                             $activity[$services_activities->getId()] = array(
  859.                                 'datos' => $services_activities,
  860.                                 'services' => $services,
  861.                                 'master' => $master,
  862.                                 'neto' => $total_neto,
  863.                                 'total' => $total_total
  864.                             );
  865.                             //                            foreach($services_ideas as $serviceideas){
  866.                             //
  867.                             //                                $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  868.                             //                                    array(
  869.                             //                                        'controlId' => $idcontrol,
  870.                             //                                        'destinationId' => $destinobudget,
  871.                             //                                        'ideaId' => $serviceideas->getId(),
  872.                             //                                    ),
  873.                             //                                    array(
  874.                             //                                        'rank' => 'ASC'
  875.                             //                                    )
  876.                             //                                );
  877.                             //
  878.                             //                            }
  879.                         }
  880.                         if ($key == "idea") {
  881.                             $services_ideas $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
  882.                             $master "idea";
  883.                             $services[] = array(
  884.                                 'service' => $servicesbudget
  885.                             );
  886.                             $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  887.                             if (empty($totales_iva[$servicesbudget->getIva()])) {
  888.                                 $totales_iva[$servicesbudget->getIva()] = 0;
  889.                             }
  890.                             $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  891.                             $total_neto += $servicesbudget->getNetAmount();
  892.                             $totales_neto += $servicesbudget->getNetAmount();
  893.                             $total_total += $servicesbudget->getTotal();
  894.                             $totales_total += $servicesbudget->getTotal();
  895.                             $idea[$services_ideas->getId()] = array(
  896.                                 'datos' => $services_ideas,
  897.                                 'services' => $services,
  898.                                 'master' => $master,
  899.                                 'neto' => $total_neto,
  900.                                 'total' => $total_total
  901.                             );
  902.                             //                            foreach($services_ideas as $serviceideas){
  903.                             //
  904.                             //                                $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  905.                             //                                    array(
  906.                             //                                        'controlId' => $idcontrol,
  907.                             //                                        'destinationId' => $destinobudget,
  908.                             //                                        'ideaId' => $serviceideas->getId(),
  909.                             //                                    ),
  910.                             //                                    array(
  911.                             //                                        'rank' => 'ASC'
  912.                             //                                    )
  913.                             //                                );
  914.                             //
  915.                             //                            }
  916.                         }
  917.                         if ($key == "supplier") {
  918.                             if (is_null($servicesbudget->getIdeaId()) and is_null($servicesbudget->getActivityId())) {
  919.                                 $servicessupplier $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
  920.                                 $master "supplier";
  921.                                 //                            foreach($services_supplier as $servicessupplier){
  922.                                 if (!is_null($servicessupplier)) {
  923.                                     switch ($servicessupplier->getStar()) {
  924.                                         case 1:
  925.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i>');
  926.                                             break;
  927.                                         case 2:
  928.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  929.                                             break;
  930.                                         case 3:
  931.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  932.                                             break;
  933.                                         case 4:
  934.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  935.                                             break;
  936.                                         case 5:
  937.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> SUP');
  938.                                             break;
  939.                                         case 6:
  940.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  941.                                             break;
  942.                                         case 7:
  943.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
  944.                                             break;
  945.                                         case 8:
  946.                                             $servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
  947.                                             break;
  948.                                     }
  949.                                 }
  950.                                 //                                $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  951.                                 //                                    array(
  952.                                 //                                        'controlId' => $idcontrol,
  953.                                 //                                        'destinationId' => $destinobudget,
  954.                                 //                                        'supplierId' => $servicessupplier->getId(),
  955.                                 //                                    ),
  956.                                 //                                    array(
  957.                                 //                                        'rank' => 'ASC'
  958.                                 //                                    )
  959.                                 //                                );
  960.                                 //                            }
  961.                                 $services[] = array(
  962.                                     'service' => $servicesbudget
  963.                                 );
  964.                                 $totales_sub_iva $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
  965.                                 if (empty($totales_iva[$servicesbudget->getIva()])) {
  966.                                     $totales_iva[$servicesbudget->getIva()] = 0;
  967.                                 }
  968.                                 //                                d($servicesbudget); exit();
  969.                                 $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
  970.                                 $total_neto += $servicesbudget->getNetAmount();
  971.                                 $totales_neto += $servicesbudget->getNetAmount();
  972.                                 $total_total += $servicesbudget->getTotal();
  973.                                 $totales_total += $servicesbudget->getTotal();
  974.                                 $supplier[$servicessupplier->getId()] = array(
  975.                                     'datos' => $servicessupplier,
  976.                                     'services' => $services,
  977.                                     'master' => $master,
  978.                                     'neto' => $total_neto,
  979.                                     'total' => $total_total
  980.                                 );
  981.                             }
  982.                         }
  983.                         //                        d($totales_neto, $totales_total );
  984.                     }
  985.                 }
  986.             }
  987.             //            d($supplier);
  988.             $content_data = array(
  989.                 'supplier' => $supplier,
  990.                 'idea' => $idea,
  991.                 'activity' => $activity,
  992.                 'whiteservice' => $whiteservice,
  993.             );
  994.             $data[] = array(
  995.                 'destination' => $destination,
  996.                 'container' => $content_data
  997.             );
  998.         }
  999.         //        d($controlbudget);
  1000.         return $this->render(
  1001.             'MDS/EventsBundle/budget/services-budget-print-proposal.html.twig',
  1002.             array(
  1003.                 'id' => $id,
  1004.                 'token' => $proposal->getAccessKey(),
  1005.                 'mcp' => $proposal->getMcp(),
  1006.                 'client' => $client,
  1007.                 'budgets' => $controlbudget,
  1008.                 'budgetcontrol' => $data_controlbudgets,
  1009.                 'data' => $data,
  1010.                 'totales_neto' => $totales_neto,
  1011.                 'ivas' => $totales_iva,
  1012.                 'totales' => $totales_total,
  1013.                 'confirm' => $controlbudgetBoton
  1014.             )
  1015.         );
  1016.     }
  1017.     // Make Your Budget
  1018.     /**
  1019.      * @Route("/proposal/makeyourbudget/base/{id}",  name="proposal_destination_supplier_makeyourbudget")
  1020.      */
  1021.     public function MakeYourBudgetSupplierAction($idRequest $request)
  1022.     {
  1023.         $em $this->getDoctrine()->getManager();
  1024.         $proposal $em->getRepository(Proposal::class)->findOneById($id);
  1025.         $available_destination $em->getRepository(ProposalControl::class)->findBy(
  1026.             array(
  1027.                 'proposalId' => $id,
  1028.                 'disabled' => "0"
  1029.             )
  1030.         );
  1031.         $data_supplier = array();
  1032.         if (!empty($available_destination)) {
  1033.             foreach ($available_destination as $availabledestination) {
  1034.                 /* Data Supplier agregados */
  1035.                 $service_supplier $em->getRepository(ProposalSupplierControl::class)->findBy(
  1036.                     array(
  1037.                         'controlDestinationId' => $availabledestination->getId(),
  1038.                         'disabled' => "0"
  1039.                     ),
  1040.                     array(
  1041.                         'rank' => 'ASC'
  1042.                     )
  1043.                 );
  1044.                 $controlgeneral = array();
  1045.                 foreach ($service_supplier as $suppliercontrol) {
  1046.                     $destination $em->getRepository(Destination::class)->findOneById($suppliercontrol->getDestinoId());
  1047.                     //cambiar el estatus de colores
  1048.                     $colorlabel "";
  1049.                     switch ($suppliercontrol->getStatus()) {
  1050.                         case 'Pending':
  1051.                             $colorlabel "bg-danger";
  1052.                             break;
  1053.                         case 'Confirmed':
  1054.                             $colorlabel "bg-success";
  1055.                             break;
  1056.                     }
  1057.                     $sqlactivities "";
  1058.                     if (!is_null($suppliercontrol->getActivityId())) {
  1059.                         $master "activity";
  1060.                         $sqlactivities $em->getRepository(Activities::class)->findOneById($suppliercontrol->getActivityId());
  1061.                         /*CONTROL GENERAL*/
  1062.                         $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($suppliercontrol->getActivityId());
  1063.                     }
  1064.                     $sqlideas "";
  1065.                     if (!is_null($suppliercontrol->getIdeaId())) {
  1066.                         $master "idea";
  1067.                         $sqlideas $em->getRepository(Ideas::class)->findOneById($suppliercontrol->getIdeaId());
  1068.                         /*CONTROL GENERAL*/
  1069.                         $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($suppliercontrol->getIdeaId());
  1070.                     }
  1071.                     $sqlsuppliers "";
  1072.                     if (!is_null($suppliercontrol->getSupplierId()) && $suppliercontrol->getSupplierId() != "0") {
  1073.                         $master "supplier";
  1074.                         $sqlsuppliers $em->getRepository(Supplier::class)->findOneById($suppliercontrol->getSupplierId());
  1075.                         if (!is_null($sqlsuppliers)) {
  1076.                             switch ($sqlsuppliers->getStar()) {
  1077.                                 case 1:
  1078.                                     $sqlsuppliers->setStar('<i class="icon-star-full2"></i>');
  1079.                                     break;
  1080.                                 case 2:
  1081.                                     $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  1082.                                     break;
  1083.                                 case 3:
  1084.                                     $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  1085.                                     break;
  1086.                                 case 4:
  1087.                                     $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  1088.                                     break;
  1089.                                 case 5:
  1090.                                     $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> SUP');
  1091.                                     break;
  1092.                                 case 6:
  1093.                                     $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
  1094.                                     break;
  1095.                                 case 7:
  1096.                                     $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
  1097.                                     break;
  1098.                                 case 8:
  1099.                                     $sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i> GL');
  1100.                                     break;
  1101.                             }
  1102.                         }
  1103.                         /*CONTROL GENERAL*/
  1104.                         $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($suppliercontrol->getSupplierId());
  1105.                     }
  1106.                     $sqlcompany "";
  1107.                     if ($suppliercontrol->getSupplierId() == "0") {
  1108.                         $master "company";
  1109.                         $sqlcompany $em->getRepository(SettingsCompany::class)->findOneByPriority('1');
  1110.                         if (!is_null($sqlcompany)) {
  1111.                             $imagenSmall $sqlcompany->getPicture();
  1112.                         } else {
  1113.                             //Imagen no disponible (poner una generica)
  1114.                             $imagenSmall null;
  1115.                         }
  1116.                     } else {
  1117.                         $sqlsuppliers_gallery $em->getRepository(SupplierGallery::class)->findOneBy(
  1118.                             array(
  1119.                                 'supplierId' => $controlgeneral->getId(),
  1120.                                 'servicesCatId' => '0',
  1121.                                 'servicesCategory' => 'General',
  1122.                                 'servicesId' => '0',
  1123.                                 'controlId' => '0'
  1124.                             )
  1125.                         );
  1126.                         if (!is_null($sqlsuppliers_gallery)) {
  1127.                             $imagenSmall $sqlsuppliers_gallery->getImageSmall();
  1128.                         } else {
  1129.                             //Imagen no disponible (poner una generica)
  1130.                             $imagenSmall null;
  1131.                         }
  1132.                     }
  1133.                     // ORDEN DESCENDENTE Y POR SERVICES
  1134.                     $parameters = array(
  1135.                         'controlId' => $suppliercontrol->getId(),
  1136.                         'serviceIdFather' => '0',
  1137.                         'directPayment' => '0',
  1138.                     );
  1139.                     $dql 'SELECT p
  1140.                                     FROM EventsBundle:ProposalSupplierServices p
  1141.                                     WHERE p.controlId = :controlId 
  1142.                                     AND p.serviceIdFather = :serviceIdFather
  1143.                                     AND p.directPayment = :directPayment
  1144.                                     ORDER BY p.serviceCatId, p.rank ASC ';
  1145.                     $query $em->createQuery($dql)->setParameters($parameters);
  1146.                     $data_service_supplier $query->getResult();
  1147.                     $service_supplier_data = array();
  1148.                     $calculos_totatales = array();
  1149.                     $totales_neto '0';
  1150.                     $totales_iva '0';
  1151.                     $totales_con_iva '0';
  1152.                     $totales_paying '0';
  1153.                     $totales_pago '0';
  1154.                     $totales_benefit_moneda '0';
  1155.                     $totales_benefit_porsentaje '0';
  1156.                     foreach ($data_service_supplier as $data_service) {
  1157.                         //COLOR POR SERVICIO
  1158.                         $contcolor "";
  1159.                         switch ($data_service->getServiceCatName()) {
  1160.                             case "Accommodation":
  1161.                                 $contcolor 'teal';
  1162.                                 break;
  1163.                             case "Menu":
  1164.                                 $contcolor 'purple';
  1165.                                 break;
  1166.                             case "Lounge":
  1167.                                 $contcolor 'warning';
  1168.                                 break;
  1169.                             case "Activities":
  1170.                                 $contcolor 'blue';
  1171.                                 break;
  1172.                             case "Itineraries":
  1173.                                 $contcolor 'indigo';
  1174.                                 break;
  1175.                             case "Cruise":
  1176.                                 $contcolor 'brown';
  1177.                                 break;
  1178.                             case "Transport":
  1179.                                 $contcolor 'grey';
  1180.                                 break;
  1181.                             case "Av":
  1182.                                 $contcolor 'slate';
  1183.                                 break;
  1184.                             case "Creative":
  1185.                                 $contcolor 'orange';
  1186.                                 break;
  1187.                             case "Gifts":
  1188.                                 $contcolor 'pink';
  1189.                                 break;
  1190.                             case "Entertainment":
  1191.                                 $contcolor 'green';
  1192.                                 break;
  1193.                             case "Guide":
  1194.                                 $contcolor 'orange';
  1195.                                 break;
  1196.                             case "Others":
  1197.                                 $contcolor 'danger';
  1198.                                 break;
  1199.                             case "Technology":
  1200.                                 $contcolor 'grey-800';
  1201.                                 break;
  1202.                             case "Assistant":
  1203.                                 $contcolor 'indigo-800';
  1204.                                 break;
  1205.                             case "DDR":
  1206.                                 $contcolor 'green-300';
  1207.                                 break;
  1208.                         }
  1209.                         $idcat $data_service->getServiceCatId();
  1210.                         $price $data_service->getPrice();
  1211.                         $units $data_service->getUnits();
  1212.                         $pax $data_service->getPax();
  1213.                         $opcommission $data_service->getOpCommission();
  1214.                         $commission $data_service->getCommission();
  1215.                         $opover $data_service->getOpOver();
  1216.                         $over $data_service->getOver();
  1217.                         $opiva $data_service->getOpIva();
  1218.                         $iva $data_service->getIva();
  1219.                         $dateInAt $data_service->getDateInAt();
  1220.                         $dateOutAt $data_service->getDateOutAt();
  1221.                         if (!is_null($dateInAt) and !is_null($dateOutAt)) {
  1222.                             $days $dateInAt->diff($dateOutAt);
  1223.                             $day $days->days;
  1224.                         } else {
  1225.                             $day "0";
  1226.                         }
  1227.                         $directPayment $data_service->getDirectPayment();
  1228.                         $calculos $this->CalculoTotalesservices($price$units$pax$day$opcommission$commission$opover$over$opiva$iva$directPayment$idcat);
  1229.                         $data_service->setPrice($calculos['precio']); //ojo aqui
  1230.                         /*CONTROL GENERAL*/
  1231.                         $controlgeneral $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($data_service->getSupplierId());
  1232.                         $data_service->setPrice($calculos['precio']); //ojo aqui
  1233.                         $service_supplier_data[$data_service->getServiceCatName()][] = array(
  1234.                             //                        'idcat' => $idcat,
  1235.                             'calculos' => $calculos,
  1236.                             'services_data' => $data_service,
  1237.                             //                        'controlGeneralId' => $controlgeneral->getId(),
  1238.                             'contcolor' => $contcolor,
  1239.                             //                        'servicesSub' =>$service_supplier_data_sub
  1240.                         );
  1241.                         if ($data_service->getBreakdown() == false) {
  1242.                             $totales_neto += $calculos['total_neto'];
  1243.                             $totales_iva += $calculos['sub_total_iva'];
  1244.                             $totales_con_iva += $calculos['total'];
  1245.                             $totales_paying += $calculos['total_paying'];
  1246.                             $totales_pago += $calculos['total_pago'];
  1247.                             $totales_benefit_moneda += $calculos['benefit_moneda'];
  1248.                         } else {
  1249.                             $totales_neto += $totales_neto_sub;
  1250.                             $totales_iva += $totales_iva_sub;
  1251.                             $totales_con_iva += $totales_con_iva_sub;
  1252.                             $totales_paying += $totales_paying_sub;
  1253.                             $totales_pago += $totales_pago_sub;
  1254.                             $totales_benefit_moneda += $totales_benefit_moneda_sub;
  1255.                         }
  1256.                         //                    $totales_neto += $calculos['total_neto'];
  1257.                         //                    $totales_iva += $calculos['sub_total_iva'];
  1258.                         //                    $totales_con_iva += $calculos['total'];
  1259.                         //                    $totales_paying += $calculos['total_paying'];
  1260.                         //                    $totales_pago += $calculos['total_pago'];
  1261.                         //                    $totales_benefit_moneda += $calculos['benefit_moneda'];
  1262.                         if ($totales_benefit_moneda == '0') {
  1263.                             $totales_benefit_porsentaje =  '0';
  1264.                         } else {
  1265.                             //                        $totales_benefit_porsentaje =  $totales_benefit_moneda * 100 / $totales_neto;
  1266.                             if ($totales_pago != 0) {
  1267.                                 $totales_benefit_porsentaje $totales_benefit_moneda 100 $totales_pago;
  1268.                             } else {
  1269.                                 $totales_benefit_porsentaje 0;
  1270.                             }
  1271.                         }
  1272.                     }
  1273.                     $calculos_totatales = array(
  1274.                         'totales_neto' => $totales_neto,
  1275.                         'totales_iva' => $totales_iva,
  1276.                         'totales_con_iva' => $totales_con_iva,
  1277.                         'totales_paying' => $totales_paying,
  1278.                         'totales_benefit_moneda' => $totales_benefit_moneda,
  1279.                         'totales_benefit_porsentaje' => $totales_benefit_porsentaje
  1280.                     );
  1281.                     if ($master == "company") {
  1282.                         $typeMaster $sqlcompany->getCompany();
  1283.                     }
  1284.                     if ($master == "supplier") {
  1285.                         $typeMaster $sqlsuppliers->getType();
  1286.                     }
  1287.                     if ($master == "activity") {
  1288.                         $typeMaster "Activity";
  1289.                     }
  1290.                     if ($master == "idea") {
  1291.                         $typeMaster "Idea";
  1292.                     }
  1293.                     $data_supplier[$destination->getTitle()][$typeMaster][] = array(
  1294.                         'colorlabel' => $colorlabel,
  1295.                         'control' => $suppliercontrol,
  1296.                         'master' => $master,
  1297.                         'supplier' => $sqlsuppliers,
  1298.                         'idea' => $sqlideas,
  1299.                         'activity' => $sqlactivities,
  1300.                         'company' => $sqlcompany,
  1301.                         'image' => $imagenSmall,
  1302.                         'services' => $service_supplier_data,
  1303.                         'totales_services' => $calculos_totatales
  1304.                     );
  1305.                 }
  1306.             }
  1307.         }
  1308.         $controlbudgets $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($id);
  1309.         $controlbudget = array();
  1310.         //        $i = 0;
  1311.         foreach ($controlbudgets as $controlbudge) {
  1312.             //            $controlbudget[$controlbudge->getRecommended()][] = $controlbudge;
  1313.             $presupuesto['byclient'] = $controlbudge->getByClient();
  1314.             $presupuesto['id'] = $controlbudge->getId();
  1315.             $presupuesto['name'] = $controlbudge->getName();
  1316.             $presupuesto['priority'] = $controlbudge->getPriority();
  1317.             $presupuesto['proposalId'] = $controlbudge->getProposalId();
  1318.             $presupuesto['recommended'] = $controlbudge->getRecommended();
  1319.             $presupuesto['status'] = $controlbudge->getStatus();
  1320.             $hasDiary $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
  1321.                 array(
  1322.                     'proposalId' => $controlbudge->getProposalId(),
  1323.                     'controlId' => $controlbudge->getId(),
  1324.                 )
  1325.             );
  1326.             if ($hasDiary) {
  1327.                 $presupuesto['hasDiary'] = true;
  1328.             } else {
  1329.                 $presupuesto['hasDiary'] = false;
  1330.             }
  1331.             $controlbudget[$controlbudge->getRecommended()][] = $presupuesto;
  1332.         }
  1333.         $today = new \DateTime("now");
  1334.         return $this->render(
  1335.             'MDS/EventsBundle/budget/services-makeyourbudget-proposal.html.twig',
  1336.             array(
  1337.                 'id' => $id,
  1338.                 'today' => $today,
  1339.                 'token' => $proposal->getAccessKey(),
  1340.                 'mcp' => $proposal->getMcp(),
  1341.                 'datasupplier' => $data_supplier,
  1342.                 'budgets' => $controlbudget
  1343.             )
  1344.         );
  1345.     }
  1346.     /**
  1347.      * @Route("/proposal/makeyourbudget/budget/confirm/{id}/{idcontrol}",  name="proposal_destination_supplier_makeyourbudget_confirm")
  1348.      */
  1349.     public function MakeYourBudgetConfirmSupplierAction($id$idcontrolRequest $request)
  1350.     {
  1351.         $em $this->getDoctrine()->getManager();
  1352.         $proposal $em->getRepository(Proposal::class)->findOneById($id);
  1353.         // Envio correo a administracion en caso que de cambie el estatus y este como no enviado
  1354.         if ($proposal->getSendAdmin() != "yes") {
  1355.             $time = new \DateTime("now");
  1356.             $agent $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  1357.             if (is_null($agent)) {
  1358.                 $event 'The Budget has no agents.';
  1359.                 $successMessage $this->translator->trans($event);
  1360.                 $this->addFlash('mensajeproposalbudgetserviceserror'$successMessage);
  1361.                 return $this->redirectToRoute(
  1362.                     'proposal_destination_supplier_makeyourbudget',
  1363.                     array(
  1364.                         'id' => $id
  1365.                     )
  1366.                 );
  1367.             }
  1368.             $mailAgent[] = $agent->getEmail();
  1369.             $agentMail $agent->getEmail();
  1370.             $passGmail $agent->getPassGmail();
  1371.             $firmGmail $agent->getFirmGmail();
  1372.             $mailAgentSent = array(
  1373.                 $agent->getEmail() => $agent->getName() . ' ' $agent->getLastName()
  1374.             );
  1375.             $setting_rol $em->getRepository(SettingsRol::class)->findBy(
  1376.                 array(
  1377.                     'weight' => array('2''3'),
  1378.                     'madmin' => '1',
  1379.                 )
  1380.             );
  1381.             foreach ($setting_rol as $settingRol) {
  1382.                 $administration $em->getRepository(User::class)->findByUserrol($settingRol->getId());
  1383.                 foreach ($administration as $admin) {
  1384.                     $mailAdmin[] = $admin->getEmail();
  1385.                 }
  1386.             }
  1387.             $data = array(
  1388.                 'body' => 'P#' $proposal->getId() . ', ' $proposal->getTitle() . '<br><a href="http://' $request->server->get('HTTP_HOST') . '/events/proposal/edit/' $proposal->getId() . '">Ir al Proposal</a> - <a href="http://' $request->server->get('HTTP_HOST') . '/events/proposal/summary/prices/' $proposal->getId() . '">Ver Resumen</a><br><br>Alerta de Proposal Confirmado: ' $time->format('d/m/Y H:i:s') . '<br><br>',
  1389.                 'firm' => $firmGmail,
  1390.             );
  1391.             $mailTodos array_merge($mailAgent$mailAdmin);
  1392.             if (!is_null($passGmail) and (!empty($passGmail))) {
  1393.                 // EJECUTAR ENVIO DE ALERTA DE VISTO POR CLIENTE
  1394.                 $transporter = new Swift_SmtpTransport();
  1395.                 $transporter->setHost('smtp.gmail.com')
  1396.                     ->setEncryption('ssl'//ssl / tls
  1397.                     ->setPort(465// 465 / 587
  1398.                     ->setUsername('desarrollo@develup.solutions')
  1399.                     ->setPassword('utvh hzoi wfdo ztjs');
  1400.                 $mailer = new Swift_Mailer($transporter);
  1401.                 $message = new Swift_Message();
  1402.                 $message->setSubject('P#' $proposal->getId() . ', Alerta de Proposal Confirmado')
  1403.                     ->setSender($agentMail)
  1404.                     ->setFrom($mailAgentSent)
  1405.                     ->setReplyTo($mailAgentSent)
  1406.                     ->setTo($mailTodos)
  1407.                     ->setBody(
  1408.                         $this->renderView(
  1409.                             'mail/structure-mail.html.twig',
  1410.                             array('data' => $data)
  1411.                         ),
  1412.                         'text/html'
  1413.                     );
  1414.                 $mailer->send($message);
  1415.                 $proposal->setSendAdmin('yes');
  1416.             }
  1417.         }
  1418.         if (($proposal->getStatus() != "Invoiced") and ($proposal->getStatus() != "Unblocked")) {
  1419.             $proposal->setStatus('Confirmed');
  1420.         }
  1421.         $controlbudget $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
  1422.         $controlbudget->setStatus('Confirmed');
  1423.         $nameBudget = empty($controlbudget) ? '(Presupuesto sin nombre)' $controlbudget->getName();
  1424.         $budgets $em->getRepository(ProposalSupplierServicesBudget::class)->findByControlId($idcontrol);
  1425.         $montoMsj 0;
  1426.         foreach ($budgets as $budget) {
  1427.             $services $em->getRepository(ProposalSupplierServices::class)->findOneById($budget->getItemsserviceId());
  1428.             $montoMsj $montoMsj $budget->getTotal();
  1429.             $services->setStatus('Confirmed');
  1430.             $em->persist($services);
  1431.             $services_father $em->getRepository(ProposalSupplierServices::class)->findByServiceIdFather($budget->getItemsserviceId());
  1432.             foreach ($services_father as $servicesfather) {
  1433.                 $servicesfather->setStatus('Confirmed');
  1434.                 $em->persist($servicesfather);
  1435.             }
  1436.             $budget->setStatus('Confirmed');
  1437.             $em->persist($budget);
  1438.             $budgets_sub $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
  1439.                 array(
  1440.                     'controlId' => $idcontrol,
  1441.                     'itemsserviceIdFather' => $budget->getItemsServiceId(),
  1442.                 )
  1443.             );
  1444.             if (!empty($budgets_sub)) {
  1445.                 foreach ($budgets_sub as $budgetssub) {
  1446.                     $budgetssub->setStatus('Confirmed');
  1447.                     $em->persist($budgetssub);
  1448.                 }
  1449.             }
  1450.         }
  1451.         $em->persist($controlbudget);
  1452.         $em->persist($proposal);
  1453.         $em->flush();
  1454.         /* Obtengo usuario logueado */
  1455.         $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  1456.         // Usuario Anonimo es = "anon."
  1457.         if($user_logueado == "anon."){ $user_id '0'; } else { $user_id $user_logueado->getId(); }
  1458.         // Notificamos al agente y a Rafa lo que se ha confirmado
  1459.         $this->notifyBudgetConfirmation($montoMsj$proposal->getId(), $user_id$nameBudget);
  1460.         return $this->redirectToRoute(
  1461.             'proposal_destination_supplier_makeyourbudget_view',
  1462.             array(
  1463.                 'id' => $id,
  1464.                 //                'token' => $proposal->getAccessKey(),
  1465.                 'idcontrol' => $idcontrol,
  1466.             )
  1467.         );
  1468.     }
  1469.     public function CalculoTotalesservices($price$units$pax$days$opcommission$commission$opover$over$opiva$iva$directPayment$idcat)
  1470.     {
  1471.         $price trim($price);
  1472.         $over trim($over);
  1473.         $price str_replace(",""."$price);
  1474.         $over str_replace(",""."$over);
  1475.         if (empty($price)) {
  1476.             $price 0;
  1477.         }
  1478.         if (empty($commission)) {
  1479.             $commission 0;
  1480.         }
  1481.         if (empty($iva)) {
  1482.             $iva 0;
  1483.         }
  1484.         $iva $iva 100;
  1485.         if ($opiva == '0') {
  1486.             $price $price / ($iva 1);
  1487.         }
  1488.         if (!empty($commission)) {
  1489.             if ($opcommission == '0') {
  1490.                 $commission = (100 $commission) / 100;
  1491.                 $precio_units $price;
  1492.                 $price $price $commission;
  1493.             }
  1494.             if ($opcommission == '1') {
  1495.                 $commission = ($commission 100) + 1;
  1496.                 $precio_units $price $commission;
  1497.             }
  1498.         } else {
  1499.             $precio_units $price;
  1500.         }
  1501.         //Units
  1502.         if (empty($units) or $units == "0") {
  1503.             $units "1";
  1504.         }
  1505.         // Calculo Especial por categoria
  1506.         //Alojamientos
  1507.         if ($idcat == "1") {
  1508.             $informativo_days "si";
  1509.             $pax "1";
  1510.         }
  1511.         //Transporte
  1512.         elseif ($idcat == "13") {
  1513.             $informativo_days "no";
  1514.             $pax "1";
  1515.             //            if($days > "1"){
  1516.             //                $days = "2";
  1517.             //            }else{
  1518.             //                $days = "1";
  1519.             //            }
  1520.         }
  1521.         //Lounge
  1522.         elseif ($idcat == "10") {
  1523.             $informativo_days "no";
  1524.             $pax "1";
  1525.         }
  1526.         //Guia
  1527.         elseif ($idcat == "8") {
  1528.             $informativo_days "no";
  1529.             $pax "1";
  1530.         } else {
  1531.             $informativo_days "no";
  1532.         }
  1533.         //Pax
  1534.         if (empty($pax) or $pax == "0") {
  1535.             $pax "1";
  1536.         }
  1537.         //Over
  1538.         if (empty($over)) {
  1539.             $over "0";
  1540.         }
  1541.         if ($informativo_days == "no") {
  1542.             //Days
  1543.             if (empty($days) or $days == "0") {
  1544.                 $days "1";
  1545.             } else {
  1546.                 $days $days 1;
  1547.             }
  1548.         }
  1549.         $total_items $price $units $pax $days;
  1550.         //        $total_pdirect = $price * $units * $pax * $days;
  1551.         $total_over $over $units $pax $days;
  1552.         if (!empty($commission)) {
  1553.             if ($opcommission == '0') {
  1554.                 $total_neto $total_items $commission;
  1555.             }
  1556.             if ($opcommission == '1') {
  1557.                 $total_neto $total_items $commission;
  1558.             }
  1559.         } else {
  1560.             $total_neto $total_items;
  1561.         }
  1562.         if ($opover == '0') {
  1563.             $total_neto $total_neto $total_over;
  1564.             $precio_units $precio_units $over;
  1565.         }
  1566.         if ($opover == '1') {
  1567.             $total_neto $total_neto +  $total_over;
  1568.             $precio_units $precio_units $over;
  1569.         }
  1570.         $total_paying $total_items * ($iva 1);
  1571.         if ($directPayment == true) {
  1572.             $total_neto $total_neto $total_paying;
  1573.         }
  1574.         $total_comision "0";
  1575.         $total_pago $total_items;
  1576.         $total_iva $total_items $iva;
  1577.         $sub_total_iva $total_neto $iva;
  1578.         $total $total_neto $sub_total_iva;
  1579.         if ($directPayment == true) {
  1580.             $benefit_moneda $total_neto;
  1581.             $total_paying "0";
  1582.         } else {
  1583.             $benefit_moneda $total_neto $total_items;
  1584.         }
  1585.         $data_calculos = array(
  1586.             'precio' => $precio_units,
  1587.             'total_days' => $days,
  1588.             'sub_total' => $total_items,
  1589.             'sub_total_iva' => $sub_total_iva,
  1590.             'total_neto' => $total_neto,
  1591.             'total_iva' => $total_iva,
  1592.             'total_paying' => $total_paying,
  1593.             'total_pago' => $total_pago,
  1594.             'total_comision' => $total_comision,
  1595.             'total' => $total,
  1596.             'benefit_moneda' => $benefit_moneda,
  1597.             'commission' => $commission,
  1598.             //            'commission_1' => $commission_1,
  1599.             'units' => $units,
  1600.             'pax' => $pax,
  1601.             'over' => $over,
  1602.         );
  1603.         //        d($data_calculos);
  1604.         return $data_calculos;
  1605.     }
  1606.     //    public function CalculoTotalesservices($price, $units, $pax, $days, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat)
  1607.     //    {
  1608.     //
  1609.     //        $iva = $iva / 100;
  1610.     //
  1611.     //        if($opiva =='0'){
  1612.     //            $price = $price / ($iva + 1);
  1613.     //        }
  1614.     ////        if($opiva =='1'){
  1615.     ////
  1616.     ////        }
  1617.     //        $commission_1 = $commission / 100 + 1;
  1618.     //        $commission = (100 - $commission) / 100;
  1619.     //        if($opcommission=='0'){
  1620.     //            $precio_units = $price;
  1621.     //            $price = $price * $commission;
  1622.     //        }
  1623.     //
  1624.     //        if($opcommission=='1'){
  1625.     //            $precio_units = $price * $commission_1;
  1626.     //        }
  1627.     //
  1628.     //        //Units
  1629.     //        if(empty($units) or $units =="0"){
  1630.     ////            d('entre');
  1631.     //            $units = "1";
  1632.     //        }
  1633.     //
  1634.     //        // Calculo Especial por categoria
  1635.     //        //Alojamientos
  1636.     //        if($idcat =="1"){
  1637.     //            $informativo_days = "si";
  1638.     //            $pax = "1";
  1639.     //        }
  1640.     //        //Transporte
  1641.     //        elseif($idcat =="13"){
  1642.     //            $informativo_days = "no";
  1643.     //            $pax = "1";
  1644.     ////            if($days > "1"){
  1645.     ////                $days = "2";
  1646.     ////            }else{
  1647.     ////                $days = "1";
  1648.     ////            }
  1649.     //        }
  1650.     //        //Lounge
  1651.     //        elseif($idcat =="10"){
  1652.     //            $informativo_days = "no";
  1653.     //            $pax = "1";
  1654.     //        }
  1655.     //        //Guia
  1656.     //        elseif($idcat =="8"){
  1657.     //            $informativo_days = "no";
  1658.     //            $pax = "1";
  1659.     //        }else{
  1660.     //            $informativo_days = "no";
  1661.     //        }
  1662.     //
  1663.     //
  1664.     //        //Pax
  1665.     //        if(empty($pax) or $pax =="0"){
  1666.     //            $pax = "1";
  1667.     //        }
  1668.     //
  1669.     //        //Over
  1670.     //        if(empty($over)){
  1671.     //            $over = "0";
  1672.     //        }
  1673.     //
  1674.     //        if($informativo_days =="no"){
  1675.     //            //Days
  1676.     //            if(empty($days) or $days =="0"){
  1677.     //                $days = "1";
  1678.     //            }else{
  1679.     //                $days = $days + 1 ;
  1680.     //            }
  1681.     //        }
  1682.     //
  1683.     //        $total_items = $price * $units * $pax * $days;
  1684.     //        $total_pdirect = $price * $units * $pax * $days;
  1685.     //
  1686.     //        $total_over = $over * $units * $pax * $days;
  1687.     //
  1688.     //        if($opover=='0'){
  1689.     ////            $total_neto = $total_items * ($commission + 1) - $total_over ;
  1690.     ////            $total_neto = $total_items / 0.9 - $total_over ;
  1691.     ////            $total_neto = $total_items / $commission - $total_over ;
  1692.     //            $total_neto = $total_items / $commission - $total_over ;
  1693.     //            $precio_units = $precio_units - $over;
  1694.     //        }
  1695.     //
  1696.     //        if($opover=='1'){
  1697.     ////            $total_neto = $total_items * ($commission + 1) + $total_over;
  1698.     ////            $total_neto = $total_items / 0.9 + $total_over;
  1699.     ////            $total_neto = $total_items / $commission + $total_over;
  1700.     //            $total_neto = $total_items * $commission_1 + $total_over ;
  1701.     //            $precio_units = $precio_units + $over;
  1702.     //        }
  1703.     //
  1704.     //        $total_paying = $total_items * ($iva + 1);
  1705.     //
  1706.     //        if ($directPayment == true){
  1707.     //            $total_neto = $total_neto - $total_paying;
  1708.     //        }
  1709.     //
  1710.     //        $total_comision ="0";
  1711.     //        $total_pago = $total_items;
  1712.     //        $total_iva = $total_items * $iva;
  1713.     //        $sub_total_iva = $total_neto * $iva;
  1714.     //
  1715.     //        $total = $total_neto + $sub_total_iva;
  1716.     //
  1717.     //        if ($directPayment == true){
  1718.     //            $benefit_moneda = $total_neto;
  1719.     //            $total_paying = "0";
  1720.     //        }else{
  1721.     //            $benefit_moneda = $total_neto - $total_items;
  1722.     //        }
  1723.     //
  1724.     //        $data_calculos = array(
  1725.     //            'precio' => $precio_units,
  1726.     //            'total_days' => $days,
  1727.     //            'sub_total' => $total_items,
  1728.     //            'sub_total_iva' => $sub_total_iva,
  1729.     //            'total_neto' => $total_neto,
  1730.     //            'total_iva' => $total_iva,
  1731.     //            'total_paying' => $total_paying,
  1732.     //            'total_pago' => $total_pago,
  1733.     //            'total_comision' => $total_comision,
  1734.     //            'total' => $total,
  1735.     //            'benefit_moneda' => $benefit_moneda,
  1736.     //
  1737.     //            'commission' => $commission,
  1738.     //            'commission_1' => $commission_1,
  1739.     //            'units' => $units,
  1740.     //            'pax' => $pax,
  1741.     //            'over' => $over,
  1742.     //        );
  1743.     //        d($data_calculos);
  1744.     //        return $data_calculos;
  1745.     //    }
  1746.     /**
  1747.      * @Route("/proposal/makeyourbudget/budget/deleted/{id}/{idcontrol}",  name="proposal_destination_supplier_makeyourbudget_deleted")
  1748.      *
  1749.      */
  1750.     //    public function deleteAction($id, Request $request, LoggerInterface $logger)
  1751.     public function deleteAction($id$idcontrolRequest $request)
  1752.     {
  1753.         $em $this->getDoctrine()->getManager();
  1754.         $proposal $em->getRepository(Proposal::class)->findOneById($id);
  1755.         $delete $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
  1756.         $delete_services $em->getRepository(ProposalSupplierServicesBudget::class)->findByControlId($idcontrol);
  1757.         foreach ($delete_services as $delete_service) {
  1758.             $em->remove($delete_service);
  1759.         }
  1760.         $delete_diary $em->getRepository('EventsBundle:ProposalAgendaPresupuesto')->findBy(
  1761.             array(
  1762.                 'proposalId' => $id,
  1763.                 'controlId' => $idcontrol,
  1764.             )
  1765.         );
  1766.         $delete_diary_comment $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
  1767.             array(
  1768.                 'proposalId' => $id,
  1769.                 'controlId' => $idcontrol,
  1770.             )
  1771.         );
  1772.         if ($delete_diary) {
  1773.             foreach ($delete_diary as $diary_services) {
  1774.                 $em->remove($diary_services);
  1775.             }
  1776.         }
  1777.         if ($delete_diary_comment) {
  1778.             foreach ($delete_diary_comment as $diary_comment) {
  1779.                 $em->remove($diary_comment);
  1780.             }
  1781.         }
  1782.         $em->remove($delete);
  1783.         $em->flush();
  1784.         $event 'The Budget the has been Deleted.';
  1785.         $successMessage $this->translator->trans($event);
  1786.         $this->addFlash('mensajeproposalbudgetservices'$successMessage);
  1787.         //        /* Gestión de eventos en Log */
  1788.         //        /* Obtengo usuario logueado */
  1789.         //        $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
  1790.         //        $user_lastname = $user_logueado->getLastname();
  1791.         //        $user_name = $user_logueado->getName();
  1792.         //        $user_email = $user_logueado->getEmail();
  1793.         //        $user_rol = $user_logueado->getRoles();
  1794.         //        $event_url = $request->getPathInfo();
  1795.         //        $event_complete = $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
  1796.         //
  1797.         //        try{
  1798.         //            $em->remove($delete);
  1799.         //            $em->flush();
  1800.         //
  1801.         //            $event = 'The supplier services Accommodation has been Deleted.';
  1802.         //            $successMessage = $this->translator->trans($event);
  1803.         //            $this->addFlash('mensajeservices', $successMessage);
  1804.         //
  1805.         //            $logger->info($event_complete.' | '.$event);
  1806.         //
  1807.         //        } catch (\Exception $e){
  1808.         //
  1809.         //            $event = 'An error occurred: '.$e->getMessage().' | transport';
  1810.         //
  1811.         //            /* Para el log */
  1812.         //            $logger->error($event_complete.' | '.$event);
  1813.         //            /* Para el usuario */
  1814.         //            $errorMessage = $this->translator->trans($event);
  1815.         //            $this->addFlash('mensajeserviceserror', $errorMessage);
  1816.         //        }
  1817.         //        /* Fin Gestión de eventos en Log */
  1818.         return $this->redirectToRoute(
  1819.             'proposal_destination_supplier_makeyourbudget',
  1820.             array(
  1821.                 'id' => $id,
  1822.                 //                'token' => $proposal->getAccessKey(),
  1823.             )
  1824.         );
  1825.     }
  1826.     private function notifyBudgetConfirmation$monto$idProp$idUser$nameBudget ){
  1827.         // Se envia una notificación vía correo electronico al agente y a Rafa sobre la confirmacion del presupuesto
  1828.         // $monto (cuanto se confirma con IVA incluido), $idProp id del proposal, $idUser id del usuario
  1829.         $em $this->getDoctrine()->getManager();
  1830.         $mailArrayTo = array();
  1831.         // Quien confirmo sera notificado
  1832.         $mailArrayTo['rafael.guerrero@inout-travel.com'] = 'rafael.guerrero@inout-travel.com';
  1833.         $agentWhoConfirm = ($idUser == 0) ? null $em->getRepository(User::class)->findOneById($idUser);
  1834.         if (!empty($agentWhoConfirm)){ $agentWhoConfirmMail $agentWhoConfirm->getEmail(); }
  1835.         if (!empty($agentWhoConfirm)){ $mailArrayTo[$agentWhoConfirmMail] = $agentWhoConfirmMail; }
  1836.         // Buscamos los agentes del proposal
  1837.         $agents $em->getRepository(ProposalAgents::class)->findOneByIdProp($idProp);
  1838.         if (!empty($agents)){
  1839.             if ( !(empty($agents->getAgOne()) or ($agents->getAgOne() == 0)) ){
  1840.                 $agent $em->getRepository(User::class)->findOneById($agents->getAgOne());
  1841.                 $mailArrayTo[$agent->getEmail()] = $agent->getEmail();
  1842.             }
  1843.             if ( !(empty($agents->getAgTwo()) or ($agents->getAgTwo() == 0)) ){
  1844.                 $agent $em->getRepository(User::class)->findOneById($agents->getAgTwo());
  1845.                 $mailArrayTo[$agent->getEmail()] = $agent->getEmail();
  1846.             }
  1847.             if ( !(empty($agents->getAgThree()) or ($agents->getAgThree() == 0)) ){
  1848.                 $agent $em->getRepository(User::class)->findOneById($agents->getAgThree());
  1849.                 $mailArrayTo[$agent->getEmail()] = $agent->getEmail();
  1850.             }
  1851.             if ( !(empty($agents->getAgFour()) or ($agents->getAgFour() == 0)) ){
  1852.                 $agent $em->getRepository(User::class)->findOneById($agents->getAgFour());
  1853.                 $mailArrayTo[$agent->getEmail()] = $agent->getEmail();
  1854.             }
  1855.         }
  1856.         $proposal $em->getRepository(Proposal::class)->findOneById($idProp);
  1857.         $fecha = ($proposal->getDateEventStarAt())->format('d/m/Y');
  1858.         $agentWhoConfirm = empty($agentWhoConfirm) ? 'el cliente.' 'el agente ( '$agentWhoConfirm->getName().' '$agentWhoConfirm->getLastName().' ).';
  1859.         $mailSubject 'Presupuesto Confirmado. Proposal: '.$idProp.' de '.$monto.'€ '.', por '.$agentWhoConfirm.' Fecha de inicio: '.$fecha;
  1860.         $mailBody '<p>Presupuesto Confirmado. Proposal: '.$idProp.' de '.$monto.'€ (IVA incluido)'.', por '.$agentWhoConfirm.' Fecha de inicio: '.$fecha.'</p>';
  1861.         $mailBody $mailBody .'<br><br><p>Presupuesto: '.$nameBudget.'</p>';
  1862.         $mailBody $mailBody .'<br><p>Ver el proposal: <a href="//'.$_SERVER['HTTP_HOST'].'/events/proposal/edit/'.$idProp.'">'.$idProp.'</a> </p>';
  1863.         $replyTo $mailArrayTo;
  1864.         $agentMail 'desarrollo@develup.solutions';
  1865.         $mailAgent $agentMail;
  1866.         //Se prepara el correo con los agentes a notificar
  1867. //        $firmGmail = $agent->getFirmGmail();
  1868.         $data = array(
  1869.             'body' => $mailBody,
  1870. //            'firm' => $firmGmail,
  1871.         );
  1872.         // EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
  1873.         $transporter = new Swift_SmtpTransport();
  1874.         $transporter->setHost('smtp.gmail.com')
  1875.             ->setEncryption('ssl')//ssl / tls
  1876.             ->setPort(465)// 465 / 587
  1877.             ->setUsername('desarrollo@develup.solutions')
  1878.             ->setPassword('utvh hzoi wfdo ztjs');
  1879.         $mailer = new Swift_Mailer($transporter);
  1880.         $message = new Swift_Message();
  1881.         $message->setSubject($mailSubject)
  1882.             ->setSender($agentMail)
  1883.             ->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
  1884.             ->setReplyTo($agentMail)
  1885.             ->setTo($replyTo)
  1886.             ->setBody(
  1887.                 $this->renderView(
  1888.                     'mail/structure-mail.html.twig',
  1889.                     array('data' => $data)
  1890.                 ),
  1891.                 'text/html'
  1892.             );
  1893.         $mailer->send($message);
  1894.         return true;
  1895.     }
  1896. }