src/MDS/EventsBundle/Controller/ProposalSummaryPricesController.php line 53

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by Mediterranean Develup Solutions
  4.  * User: jorge.defreitas@develup.solutions
  5.  * Date: 19/01/2018
  6.  * Time: 11:27
  7.  */
  8. namespace App\MDS\EventsBundle\Controller;
  9. use App\Entity\Client;
  10. use App\Entity\ProposalsStatistics;
  11. use App\Entity\Supplier;
  12. use App\Entity\User;
  13. use App\MDS\EventsBundle\Entity\Proposal;
  14. use App\MDS\EventsBundle\Entity\ProposalBenefitUnder;
  15. use App\MDS\EventsBundle\Entity\ProposalDiscount;
  16. use App\MDS\EventsBundle\Entity\ProposalFee;
  17. use App\MDS\EventsBundle\Entity\ProposalFeeInvoice;
  18. use App\MDS\EventsBundle\Entity\ProposalInvoice;
  19. use App\MDS\EventsBundle\Entity\ProposalPaymentsClient;
  20. use App\MDS\EventsBundle\Entity\ProposalSupplierServicesCosts;
  21. use App\MDS\EventsBundle\Entity\ProposalSupplierServicesCostsClient;
  22. use PhpOffice\PhpSpreadsheet\Style\Alignment;
  23. use PhpOffice\PhpSpreadsheet\Style\Fill;
  24. use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. use Symfony\Component\HttpFoundation\Request;
  28. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  29. use Symfony\Contracts\Translation\TranslatorInterface;
  30. use PhpOffice\PhpSpreadsheet\Spreadsheet;
  31. use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
  32. use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
  33. use Symfony\Component\HttpFoundation\StreamedResponse;
  34. class ProposalSummaryPricesController extends AbstractController
  35. {
  36.     private $translator;
  37.     public function __construct(TranslatorInterface $translator) {
  38.         $this->translator $translator;
  39.     }
  40.     
  41.     /*
  42.     * ATENCION LAS RAIZ DE @Route POR DEFECTO DEL BUNDLE: EventsBundle ES  /events/, NO PONERLO EN LA @Route("")
  43.     *
  44.     * */
  45.     /**
  46.      * @Route("/proposal/summary/prices/{id}",  name="proposal_summary_price")
  47.      */
  48.     public function SummaryPriceAction($idRequest $request)
  49.     {
  50.         $em $this->getDoctrine()->getManager();
  51.         $proposal $em->getRepository(Proposal::class)->findOneById($id);
  52.         $client $em->getRepository(Client::class)->findOneById($proposal->getClientId());
  53.         $services_supplier $em->getRepository(ProposalSupplierServicesCosts::class)->findBy( array( 'proposalId' => $id, ) );
  54.         $supplier_control = array();
  55.         foreach($services_supplier as $servicessupplier){
  56. //            if (!is_null($servicessupplier->getsupplierId()) && $servicessupplier->getsupplierId() != '0'){
  57.             if (!is_null($servicessupplier->getsupplierId())){
  58. //            if (!is_null($servicessupplier->getsupplierId())){
  59.                 $supplier_control[$servicessupplier->getSupplierId()] = $servicessupplier->getSupplierId();
  60.             }
  61.         }
  62.         $total_neto 0;
  63.         $total_iva 0;
  64.         $totales_gene_neto_client ="0";
  65.         $totales_gene_con_iva_client ="0";
  66.         $totales_gen_neto_costs ="0";
  67.         $totales_gen_masiva_costa ="0";
  68.         $totatles_beneficio_moneda "0";
  69.         $totatles_beneficio_porcentaje "0";
  70.         $totales_neto_client "0";
  71.         $iva_client '0';
  72.         $data_supplier = array();
  73.         $data_serviceCat = array();
  74.         foreach ($supplier_control as $suppliercontrol){
  75.             $parameters = array(
  76.                 'proposalId' => $id,
  77.                 'supplierId' => $suppliercontrol,
  78. //                'serviceCatId' => '0',
  79.                 'serviceCatName' => 'PAYMENTS',
  80.             );
  81.             $dql 'SELECT cs
  82.                         FROM EventsBundle:ProposalSupplierServicesCosts cs
  83.                         WHERE cs.proposalId = :proposalId AND cs.supplierId = :supplierId AND cs.serviceCatName != :serviceCatName';
  84.             $query $em->createQuery($dql)->setParameters($parameters);
  85.             $costs_supplier $query->getResult();
  86.             // pagos
  87.             $costs_supplier_pays $em->getRepository(ProposalSupplierServicesCosts::class)->findBy(
  88.                 array(
  89.                     'proposalId' => $id,
  90.                     'supplierId' => $suppliercontrol,
  91.                     'serviceCatId' => '0',
  92.                     'serviceCatName' => 'PAYMENTS',
  93.                 )
  94.             );
  95.             $pagos_realizados ="0";
  96.             foreach ($costs_supplier_pays as $costssupplierpays){
  97.                 $pagos_realizados += abs($costssupplierpays->getTotalServices());
  98.             }
  99.             $data_costs = array();
  100.             $totales_data = array();
  101.             $totales_neto_client  ='0';
  102.             $totales_iva_client  ='0';
  103.             $totales_con_iva_client  ='0';
  104.             $totales_neto_costs ='0';
  105.             $totales_masiva_costa ='0';
  106.             $beneficio_moneda "0";
  107.             $numerocuenta="1";
  108.             foreach ($costs_supplier as $costssupplier){
  109.                 $serviceIdProposal explode(","$costssupplier->getServicesId());
  110.                 $costs_client $em->getRepository(ProposalSupplierServicesCostsClient::class)->findBy(
  111.                     array(
  112.                         'proposalId' => $id,
  113.                         'serviceIdProposal' => $serviceIdProposal,
  114.                     )
  115.                 );
  116.                 $total_neto_client  ='0';
  117.                 $total_iva_client  ='0';
  118.                 $total_con_iva_client  ='0';
  119.                 foreach ($costs_client as $costsclient){
  120.                     $idcat $costsclient->getServiceCatId();
  121.                     $price = ($costsclient->getPrice() == "")? $costsclient->getPrice();
  122.                     $units = ($costsclient->getUnits() == "")? $costsclient->getUnits();
  123.                     $pax = ($costsclient->getPax() == "")? $costsclient->getPax();
  124.                     $opcommission $costsclient->getOpCommission();
  125.                     $commission $costsclient->getCommission();
  126.                     $opover $costsclient->getOpOver();
  127.                     $over $costsclient->getOver();
  128.                     $opiva $costsclient->getOpIva();
  129.                     $iva_client $costsclient->getIva();
  130.                     $dateInAt $costsclient->getDateInAt();
  131.                     $dateOutAt $costsclient->getDateOutAt();
  132.                     if (!is_null($dateInAt) and !is_null($dateOutAt)){
  133.                         $days $dateInAt->diff($dateOutAt);
  134.                         $day $days->days;
  135.                     }else{
  136.                         $day "0";
  137.                     }
  138.                     $calculos $this->CalculoTotalesservices($price$units$pax$day$opcommission$commission$opover$over$opiva$iva_client$idcat);
  139.                     $total_neto_client += $calculos['total_neto'];
  140.                     $total_iva_client += $calculos['sub_total_iva'];
  141.                     $total_con_iva_client += $calculos['total'];
  142. //                    $totales_paying += $calculos['total_paying'];
  143. //                    $totales_pago += $calculos['total_pago'];
  144. //                    $totales_benefit_moneda += $calculos['benefit_moneda'];
  145.                     $totales_neto_client += $calculos['total_neto'];
  146.                     $totales_iva_client += $calculos['sub_total_iva'];
  147.                     $totales_con_iva_client += $calculos['total'];
  148.                     $totales_gene_neto_client += $calculos['total_neto'];
  149.                     $totales_gene_con_iva_client += $calculos['total'];
  150. //                  /* base imponible por servicios */
  151.                     if (empty($base_imponible_service[$idcat])){
  152.                         $base_imponible_service[$idcat]= 0;
  153.                     }
  154.                     $base_imponible_service[$idcat] += $calculos['total_neto'];
  155.                     $data_serviceCat[$idcat] = array(
  156.                         'idcat' => $idcat,
  157.                         'total_neto' => $base_imponible_service[$idcat],
  158.                     );
  159.                 }
  160.                 if (empty($costssupplier->getCommission())){ $commission "0"; } else { $commission $costssupplier->getCommission(); }
  161.                 if (empty($costssupplier->getTotalServices())){ $cost_total "0"; } else { $cost_total $costssupplier->getTotalServices(); }
  162. //                $totales_neto = $costssupplier->getTotalServices() /  ($costssupplier->getCommission() /100 + 1);
  163.                 $totales_neto = (float)$cost_total * ( ( 100 - (float)$commission ) / 100);
  164.                 $ivaServices = empty($costssupplier->getIvaServices())? $costssupplier->getIvaServices();
  165.                 if ($costssupplier->getOpIva() == "0"){
  166.                     // Si es menos(-) es Entre(/)
  167.                     $totales_neto $totales_neto  /  ($ivaServices 100 1);
  168.                 }
  169.                 $total_neto += $totales_neto;
  170.                 $iva $totales_neto * ($ivaServices 100);
  171.                 $totales_iva $totales_neto * ($ivaServices 100 1);
  172.                 $total_iva += $totales_iva;
  173.                 $totales_neto_costs += $totales_neto;
  174.                 $totales_masiva_costa += $totales_iva;
  175.                 $totales_gen_neto_costs += $totales_neto;
  176.                 $totales_gen_masiva_costa += $totales_iva;
  177.                 /* Obtener y agregar el nombre del proveedor */
  178.                 if (!is_null($costssupplier->getSupplierIdExpenses()) and $costssupplier->getSupplierIdExpenses() != ){
  179.                     $supplierExp $em->getRepository(Supplier::class)->findOneById($costssupplier->getSupplierIdExpenses());
  180.                     if(!empty($supplierExp)){
  181.                         $costssupplier->setSupplierIdExpenses($supplierExp->getCompany());
  182.                     }else{
  183.                         $costssupplier->setSupplierIdExpenses('');
  184.                     }
  185.                 }else{
  186.                     $costssupplier->setSupplierIdExpenses('');
  187.                 }
  188.                 $data_costs[] = array(
  189.                     'data' => $costssupplier,
  190.                     'total_neto_client' => $total_neto_client,
  191.                     'iva_client' => $iva_client,
  192.                     'total_iva_client' => $total_con_iva_client,
  193.                     'total_neto' => $totales_neto,
  194.                     'iva' => $ivaServices,
  195.                     'total_iva' => $totales_iva
  196.                 );
  197.             }
  198.             $beneficio_moneda =  $totales_neto_client - ($totales_neto_costs);
  199.             if ($totales_neto_client == "0"){
  200.                 $beneficio_porsentaje "0";
  201.             }else{
  202.                 $beneficio_porsentaje =  $beneficio_moneda $totales_neto_client 100;
  203.             }
  204.             $totatles_beneficio_moneda +=  $beneficio_moneda;
  205.             $totatles_beneficio_porcentaje +=  $beneficio_porsentaje;
  206.             $numerocuenta += 1;
  207.             $Totales_pagos_realizados =   $totales_masiva_costa $pagos_realizados;
  208.             $totales_data = array(
  209.                 'totalesSu_neto_client' => $totales_neto_client,
  210.                 'totalesSu_masiva_client' => $totales_con_iva_client,
  211.                 'totalesSu_neto_cost' => $totales_neto_costs,
  212.                 'totalesSu_masiva_cost' => $totales_masiva_costa,
  213.                 'pagos' => $pagos_realizados,
  214.                 'totales_pagos' => $Totales_pagos_realizados,
  215.                 'beneficio' => $beneficio_moneda,
  216.                 'beneficio_por' => $beneficio_porsentaje,
  217.             );
  218.             if($suppliercontrol == '0'){
  219.                     $data_supplier[$suppliercontrol] = array(
  220.                         'master' => 'supplier',
  221.                         'supplier' => 'Internal Expenses',
  222.                         'data' => $data_costs,
  223.                         'totales' => $totales_data
  224.                     );
  225.             }else{
  226.                 $suppliers $em->getRepository(Supplier::class)->findById($suppliercontrol);
  227.                 foreach ($suppliers as $supplier){
  228.                     $data_supplier[$suppliercontrol] = array(
  229.                         'master' => 'supplier',
  230.                         'supplier' => $supplier->getName(),
  231.                         'data' => $data_costs,
  232.                         'totales' => $totales_data
  233.                     );
  234.                 }
  235.             }
  236.         }
  237.         $data_serviceOut = array(
  238.             'idcat' => null,
  239.             'total_neto' => $totales_neto_client,
  240.         );
  241.         array_push $data_serviceCat$data_serviceOut);
  242.         $consulta_discount $em->getRepository(ProposalDiscount::class)->findByProposalId($id);
  243.         $cuantosdiscount count($consulta_discount);
  244.         $totales_generales="";
  245.         $descuento =array();
  246.         if (!empty($consulta_discount)){
  247.             $quitar_en_todos=0;
  248.             $datos_total_neto_suma=0;
  249.             foreach($data_serviceCat as $dataserviceat) {
  250.                 $name ="";
  251.                 $amount "";
  252.                 $type_des "";
  253.                 $iva_discount="";
  254.                 $datos_idcat $dataserviceat['idcat'];
  255.                 $datos_total_neto $dataserviceat['total_neto'];
  256.                 $totales_neto_des $datos_total_neto;
  257.                 $datosiva_neto_des $datos_total_neto;
  258.                 $calculo_net_negativo="";
  259.                 $total_con_iva_desc="";
  260.                 $contarveces 1;
  261.                 foreach($consulta_discount as $consultadiscount) {
  262.                     if($dataserviceat['idcat'] == null){
  263.                         if($contarveces ){
  264.                             $totales_neto_des $datos_total_neto_suma;
  265.                             $datosiva_neto_des $datos_total_neto_suma;
  266.                             $datos_total_neto $datos_total_neto_suma;
  267.                         }else{
  268.                             if($cuantosdiscount 1){
  269.                                 $totales_neto_des $dataserviceat['total_neto'] - $quitar_en_todos;
  270.                                 $datosiva_neto_des $dataserviceat['total_neto'] - $quitar_en_todos;
  271.                                 $datos_total_neto $dataserviceat['total_neto'] - $quitar_en_todos;
  272.                             }
  273.                         }
  274.                         $contarveces += 1;
  275.                     }
  276.                     if ($dataserviceat['idcat'] == $consultadiscount->getServiceId()){
  277.                         $iva $consultadiscount->getIva() / 100;
  278.                         if ($consultadiscount->getType()=="0"){
  279.                             $por $consultadiscount->getAmount() / 100;
  280. //                            $datosiva_neto_des = $datosiva_neto_des / ($por + 1) ;
  281.                             $datosiva_neto_des $datosiva_neto_des - ($datosiva_neto_des $por) ;
  282.                             $name $consultadiscount->getName();
  283.                             $type_des $consultadiscount->getType();
  284.                             $amount $consultadiscount->getAmount();
  285.                         }
  286.                         if ($consultadiscount->getType()=="1"){
  287.                             $datosiva_neto_des $datosiva_neto_des $consultadiscount->getAmount();
  288.                             $name $consultadiscount->getName();
  289.                             $type_des $consultadiscount->getType();
  290.                             $amount $consultadiscount->getAmount();
  291.                         }
  292.                         // resultados en negativo
  293.                         $calculo_net_negativo =  $datosiva_neto_des $datos_total_neto;
  294.                         $total_desc "0";
  295.                         // resultados para calculos
  296.                         $calculo_net $datos_total_neto $datosiva_neto_des;
  297.                         if($consultadiscount->getOpIva() =='0'){
  298.                             $iva_discount $calculo_net - ($calculo_net / ($iva 1));
  299.                             $calculo_net_negativo $calculo_net_negativo $iva_discount;
  300.                             $totales_neto_des $totales_neto_des $iva_discount;
  301.                             $total_desc $iva_discount;
  302.                         }
  303.                         if($consultadiscount->getOpIva() =='1'){
  304.                             $iva_discount $calculo_net $iva;
  305.                             $total_desc $iva_discount;
  306.                         }
  307.                         if($type_des == 0){ $type_des "%"; }
  308.                         if($type_des == 1){ $type_des "€"; }
  309. //                        if($dataserviceat['idcat'] == null){
  310.                         $datos_total_neto_suma $datos_total_netoabs($calculo_net_negativo);
  311. //                        }
  312.                         $quitar_en_todos $quitar_en_todos abs($calculo_net_negativo);
  313. //                        $datosiva_neto_des = $datosiva_neto_des + $calculo_net_negativo;
  314.                         $total_con_iva_desc $calculo_net_negativo $iva_discount;
  315.                         $totales_gene_neto_client $totales_gene_neto_client abs($calculo_net_negativo);
  316.                         $totales_gene_con_iva_client $totales_gene_con_iva_client abs($total_con_iva_desc);
  317.                         $descuento[] = array(
  318.                             'name' => $name,
  319.                             'type' => $type_des,
  320.                             'amount' => $amount,
  321.                             'iva' => $consultadiscount->getIva(),
  322.                             'iva_amount' => $iva_discount,
  323.                             'totales_neto_des' => $calculo_net_negativo,
  324.                             'total' => $total_con_iva_desc,
  325.                         );
  326.                     }
  327.                 }
  328.             }
  329.             $totatles_beneficio_moneda_dis = ($totales_gene_neto_client $totales_gen_neto_costs) ;
  330.             if($totales_gene_neto_client == "0"){
  331.                 $totatles_beneficio_porcentaje_general_dis "0";
  332.             }else{
  333.                 $totatles_beneficio_porcentaje_general_dis =  ($totatles_beneficio_moneda_dis $totales_gene_neto_client) * 100;
  334.             }
  335.             $totales_generales = array(
  336.                 'totales_gen_neto_client' => $totales_gene_neto_client,
  337.                 'totales_gen_masiva_client' => $totales_gene_con_iva_client,
  338.                 'totales_gen_neto_cost' => $totales_gen_neto_costs,
  339.                 'totales_gen_masiva_cost' => $totales_gen_masiva_costa,
  340.                 'totatles_gen_beneficio_moneda' => $totatles_beneficio_moneda_dis,
  341.                 'totatles_gen_beneficio_por' => $totatles_beneficio_porcentaje_general_dis,
  342.             );
  343.         }else{
  344.             if($totales_gene_neto_client == "0"){
  345.                 $totatles_beneficio_porcentaje_general "0";
  346.             }else{
  347.                 $totatles_beneficio_porcentaje_general = ($totatles_beneficio_moneda $totales_gene_neto_client) * 100;
  348.             }
  349.             $totales_generales = array(
  350.                 'totales_gen_neto_client' => $totales_gene_neto_client,
  351.                 'totales_gen_masiva_client' => $totales_gene_con_iva_client,
  352.                 'totales_gen_neto_cost' => $totales_gen_neto_costs,
  353.                 'totales_gen_masiva_cost' => $totales_gen_masiva_costa,
  354.                 'totatles_gen_beneficio_moneda' => $totatles_beneficio_moneda,
  355.                 'totatles_gen_beneficio_por' => $totatles_beneficio_porcentaje_general,
  356.             );
  357.         }
  358.         $payments $em->getRepository(ProposalPaymentsClient::class)->findByProposalId($id);
  359.         $amount_pay =0;
  360.         foreach($payments as $payment) { $amount_pay $amount_pay $payment->getAmount(); }
  361.         if ($totales_generales['totatles_gen_beneficio_por'] < 9){
  362.             // Los expedientes con beneficio inferior al 9% se deben registrar en la tabla ProposalBenefitUnder para el control de administracion
  363.             $proposalBenUnder $em->getRepository(ProposalBenefitUnder::class)->findOneByProposalId($id);
  364.             $em->clear();
  365.             $user_logueado $this->get('security.token_storage')->getToken()->getUser();
  366.             $user_id $user_logueado->getId();
  367.             $hoy = new \DateTime("now"NULL);
  368.             if (empty($proposalBenUnder)){
  369.                 $prpBenUnd = new ProposalBenefitUnder();
  370.                 $prpBenUnd->setProposalId($id);
  371.                 $prpBenUnd->setBenefitCurrency((string)round($totales_generales['totatles_gen_beneficio_moneda'],2));
  372.                 $prpBenUnd->setBenefitPercentage((string)round($totales_generales['totatles_gen_beneficio_por'],2));
  373.                 $prpBenUnd->setCreatedId($user_id);
  374.                 $prpBenUnd->setUpdateId($user_id);
  375.                 $prpBenUnd->setCreatedAt($hoy);
  376.                 $prpBenUnd->setUpdatedAt($hoy);
  377.                 try {
  378.                     $em->persist($prpBenUnd);
  379.                     $em->flush();
  380.                 } catch (\Exception $e) {
  381.                     $event 'Advertencia ' $e->getMessage();
  382.                     /* Para el usuario */
  383.                     $errorMessage $this->translator->trans($event);
  384.                     $this->addFlash('mensajereservationerror'$errorMessage);
  385.                 }
  386.             } else {
  387.                 // Ya hay un registro, se procede a actualizar
  388.                 // Por problemas en la cache se vuelve a realizar la misma busqueda, para eliminar el elemento de la tabla e insertar su version actualizada
  389.                 $proposalBenUnder $em->getRepository(ProposalBenefitUnder::class)->findOneByProposalId($id);
  390.                 try {
  391.                     $em->remove($proposalBenUnder);
  392.                     $em->flush();
  393.                 } catch (\Exception $e) {
  394.                     $event 'Advertencia ' $e->getMessage();
  395.                     /* Para el usuario */
  396.                     $errorMessage $this->translator->trans($event);
  397.                     $this->addFlash('mensajereservationerror'$errorMessage);
  398.                 }
  399.                 $proposalBenUnder->setBenefitCurrency((string)round($totales_generales['totatles_gen_beneficio_moneda'],2));
  400.                 $proposalBenUnder->setBenefitPercentage((string)round($totales_generales['totatles_gen_beneficio_por'],2));
  401.                 $proposalBenUnder->setUpdateId($user_id);
  402.                 $proposalBenUnder->setUpdatedAt($hoy);
  403.                 try {
  404.                     $em->persist($proposalBenUnder);
  405.                     $em->flush();
  406.                 } catch (\Exception $e) {
  407.                     $event 'Advertencia ' $e->getMessage();
  408.                     /* Para el usuario */
  409.                     $errorMessage $this->translator->trans($event);
  410.                     $this->addFlash('mensajereservationerror'$errorMessage);
  411.                 }
  412.             }
  413.         } else {
  414.             // No es un expediente de bajo beneficio, si esta en la tabla de bajo beneficio se debe eliminar
  415.             $em->clear();
  416.             $proposalBenUnder $em->getRepository(ProposalBenefitUnder::class)->findOneByProposalId($id);
  417.             if (!empty($proposalBenUnder)){
  418.                 try {
  419.                     $em->remove($proposalBenUnder);
  420.                     $em->flush();
  421.                 } catch (\Exception $e) {
  422.                     $event 'Advertencia ' $e->getMessage();
  423.                     /* Para el usuario */
  424.                     $errorMessage $this->translator->trans($event);
  425.                     $this->addFlash('mensajereservationerror'$errorMessage);
  426.                 }
  427.             }
  428.         }
  429. // ************************************************  FEE    ************************************************************
  430.         $fees $em->getRepository(ProposalFee::class)->findByProposalId($id);
  431.         $feesInvoice $em->getRepository(ProposalFeeInvoice::class)->findByProposalId($id);
  432.         if (!empty($feesInvoice)) {
  433.             // Fee en factura
  434.             // Solo se haran los calculos si el Fee va a la factura, en caso contrario es un fee oculto y ya estará cargado en los servicios
  435.             if ($feesInvoice[0]->getToinvoice() == true) {
  436.                 foreach ($feesInvoice as $feeInv) {
  437.                     if ($feeInv->getType() == 0) {
  438.                         // Tenemos un porcentaje en el Fee de la factura, debe calcularse
  439.                         $feeNet = ($totales_generales['totales_gen_neto_client'] * $feeInv->getAmount()) / 100;
  440.                     } else {
  441.                         $feeNet $feeInv->getAmount();
  442.                     }
  443.                     $feeTotal $feeNet 1.21;                     //El fee siempre será al 21%, Esteban Rincón
  444.                     if ($feeInv->getToInvoice() == true) {
  445.                         $totales_generales['totales_gen_neto_client'] += $feeNet;
  446.                         $totales_generales['totales_gen_masiva_client'] += $feeTotal;
  447.                         $totales_generales['totatles_gen_beneficio_moneda'] += $feeNet;
  448. //                      $totales_generales['totatles_gen_beneficio_por'] = ($totales_generales['totatles_gen_beneficio_moneda'] / $totales_generales['totales_gen_neto_client'])* 100;
  449.                         $totales_generales['totatles_gen_beneficio_por'] = $totales_generales['totales_gen_neto_client'] == : ($totales_generales['totatles_gen_beneficio_moneda'] / $totales_generales['totales_gen_neto_client'])* 100;
  450.                     }
  451.                 }
  452.             }
  453.         } else {
  454.             // Fee en proforma
  455.             if (!empty($fees)) {
  456.                 // Solo se haran los calculos si el Fee va a la factura, en caso contrario es un fee oculto y ya estará cargado en los servicios
  457.                 if ($fees[0]->getToinvoice() == true) {
  458.                     foreach ($fees as $fee) {
  459.                         if ($fee->getType() == 0) {
  460.                             // Tenemos un porcentaje, debe calcularse
  461.                             $feeNet = ($totales_generales['totales_gen_neto_client'] * $fee->getAmount()) / 100;
  462.                         } else {
  463.                             $feeNet $fee->getAmount();
  464.                         }
  465.                         $feeTotal $feeNet 1.21;                     //El fee siempre será al 21%, Esteban Rincón
  466.                         if ($fee->getToInvoice() == true) {
  467.                             $totales_generales['totales_gen_neto_client'] += $feeNet;
  468.                             $totales_generales['totales_gen_masiva_client'] += $feeTotal;
  469.                             $totales_generales['totatles_gen_beneficio_moneda'] += $feeNet;
  470. //                          $totales_generales['totatles_gen_beneficio_por'] = ($totales_generales['totatles_gen_beneficio_moneda'] / $totales_generales['totales_gen_neto_client'])* 100;
  471.                             $totales_generales['totatles_gen_beneficio_por'] = $totales_generales['totales_gen_neto_client'] == : ($totales_generales['totatles_gen_beneficio_moneda'] / $totales_generales['totales_gen_neto_client'])* 100;
  472.                         }
  473.                     }
  474.                 }
  475.             }
  476.         }
  477. // ************************************************  FEE    ************************************************************
  478. $toXls $request->request->get('boolToXls');
  479. if (!empty($toXls)){
  480.     $phpExcelObject = new Spreadsheet();
  481.     // Solicita el servicio de excel
  482. //    $phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();
  483.     $phpExcelObject->getProperties()->setCreator("InOut Travel & Events")
  484.         ->setLastModifiedBy("InOut Travel & Events")
  485.         ->setTitle("InOut Travel & Events")
  486.         ->setSubject("InOut Travel & Events")
  487.         ->setDescription("InOut Travel & Events, generado usando clases de PHP")
  488.         ->setKeywords("office 2005 openxml php")
  489.         ->setCategory("Archivo de ejemplo");
  490.     $fill = new Fill();
  491.     $numberFormat = new NumberFormat();
  492.     $alignment = new Alignment();
  493.     $i 6;
  494.     $indiceInicial 7;
  495.     $indiceFinal 7;
  496. //    $activesheet = $phpExcelObject->getActiveSheet();
  497. //    $drawingobject = $this->get('phpexcel')->createPHPExcelWorksheetDrawing();
  498. //    $drawingobject->setName('Image name');
  499. //    $drawingobject->setDescription('Image description');
  500. //    $drawingobject->setPath(getcwd().'/assets/images/logo/logo2022.png');
  501. //    $drawingobject->setHeight(60);
  502. //    $drawingobject->setOffsetY(20);
  503. //    $drawingobject->setCoordinates('Q1');
  504. //    $drawingobject->setWorksheet($activesheet);
  505.     $phpExcelObject
  506.         ->getActiveSheet()
  507.         ->getStyle('B3:O3')
  508.         ->getFill()
  509.         ->setFillType($fill::FILL_SOLID)
  510.         ->getStartColor()
  511.         ->setRGB('188bab');
  512.     $phpExcelObject->setActiveSheetIndex(0)
  513.         ->setCellValue('C3','Resumen económico del expediente: '.$id)
  514.     ;
  515.     $phpExcelObject->setActiveSheetIndex(0)
  516.         ->setCellValue('B'.$i'Cliente: ')
  517.         ->setCellValue('C'.$i$client->getName())
  518.         ->setCellValue('B'.($i+1), 'CIF')
  519.         ->setCellValue('C'.($i+1), $client->getIdDocument())
  520.     ;
  521.     $data $data_supplier;
  522.     $i $i 4;
  523.     foreach ($data as $item) {
  524.         $backRed 'B'.$i.':C'.$i;
  525.         $phpExcelObject
  526.             ->getActiveSheet()
  527.             ->getStyle($backRed)
  528.             ->getFill()
  529.             ->setFillType($fill::FILL_SOLID)
  530.             ->getStartColor()
  531.             ->setRGB('f70000');
  532.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('B' $i$item['supplier']) ;
  533.         $i += 2;
  534.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('B' $i'Tipo de Servicios') ;
  535.         $backGreenLight 'D'.$i.':I'.($i+1);
  536.         $phpExcelObject
  537.             ->getActiveSheet()
  538.             ->getStyle($backGreenLight)
  539.             ->getFill()
  540.             ->setFillType($fill::FILL_SOLID)
  541.             ->getStartColor()
  542.             ->setRGB('78bf8f');
  543.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('F' $i'Confirmado Cliente') ;
  544.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('D' . ($i 1), 'Total Negocio') ;
  545.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('F' . ($i 1), 'Iva del Cliente') ;
  546.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('H' . ($i 1), 'Total del Cliente') ;
  547.         $backYellow 'K'.$i.':O'.($i+1);
  548.         $phpExcelObject
  549.             ->getActiveSheet()
  550.             ->getStyle($backYellow)
  551.             ->getFill()
  552.             ->setFillType($fill::FILL_SOLID)
  553.             ->getStartColor()
  554.             ->setRGB('e3c636');
  555.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('M' $i'Coste Proveedor') ;
  556.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('K' . ($i 1), 'Total Neto') ;
  557.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('M' . ($i 1), 'Iva') ;
  558.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('O' . ($i 1), 'Total') ;
  559.         $i += 3;
  560.         foreach ($item['data'] as $elem) {
  561.             // Tipo de servicio
  562.             $phpExcelObject->setActiveSheetIndex(0)
  563.                 ->setCellValue('B' $i$elem['data']->getServiceCatName())
  564.                 ->setCellValue('D' $i$elem['total_neto_client'])
  565.                 ->setCellValue('F' $i$elem['iva_client'])
  566.                 ->setCellValue('H' $i$elem['total_iva_client'])
  567.                 ->setCellValue('K' $inumber_format((float)$elem['total_neto'], 2','''))
  568.                 ->setCellValue('M' $i$elem['data']->getIvaServices())
  569.                 ->setCellValue('O' $inumber_format((float)$elem['total_iva'], 2','''))
  570.             ;
  571.             $i++;
  572.         }
  573.         $i ++;
  574.         $backBlue 'B'.$i.':O'.$i;
  575.         $phpExcelObject
  576.             ->getActiveSheet()
  577.             ->getStyle($backBlue)
  578.             ->getFill()
  579.             ->setFillType($fill::FILL_SOLID)
  580.             ->getStartColor()
  581.             ->setRGB('14a6a8');
  582.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('B' .$i'Totales') ;
  583.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('D' .$i$item['totales']['totalesSu_neto_client']) ;
  584.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('H' .$i$item['totales']['totalesSu_masiva_client']) ;
  585.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('K' .$i$item['totales']['totalesSu_neto_cost']) ;
  586.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('O' .$i$item['totales']['totalesSu_masiva_cost']) ;
  587.         $i++;
  588.         $backBluePay 'K'.$i.':O'.($i+2);
  589.         $phpExcelObject
  590.             ->getActiveSheet()
  591.             ->getStyle($backBluePay)
  592.             ->getFill()
  593.             ->setFillType($fill::FILL_SOLID)
  594.             ->getStartColor()
  595.             ->setRGB('14a6a8');
  596.         $i++;
  597.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('K' .$i'Pagos Anticipados') ;
  598.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('O' .$i$item['totales']['pagos']) ;
  599.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('K' .($i+1), 'Pagos Pendientes') ;
  600.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('O' .($i+1), $item['totales']['totales_pagos']) ;
  601.         $i += 3;
  602.         $backGreenBenef 'H'.$i.':K'.($i+1);
  603.         $phpExcelObject
  604.             ->getActiveSheet()
  605.             ->getStyle($backGreenBenef)
  606.             ->getFill()
  607.             ->setFillType($fill::FILL_SOLID)
  608.             ->getStartColor()
  609.             ->setRGB('1fc254');
  610.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('I' $i'Beneficio: '.  number_format((float)$item['totales']['beneficio'], 2',''') .' â‚¬') ;
  611.         $phpExcelObject->setActiveSheetIndex(0) ->setCellValue('I' . ($i 1), 'Beneficio (%): '.number_format((float)$item['totales']['beneficio_por'], 2',''').' %') ;
  612.         $i += 5;
  613.     }
  614.     $backRedClient 'D'.$i.':H'.$i;
  615.     $phpExcelObject
  616.         ->getActiveSheet()
  617.         ->getStyle($backRedClient)
  618.         ->getFill()
  619.         ->setFillType($fill::FILL_SOLID)
  620.         ->getStartColor()
  621.         ->setRGB('ff0303');
  622.     $phpExcelObject->setActiveSheetIndex(0)
  623.         ->setCellValue('D' $inumber_format((float)$totales_generales['totales_gen_neto_client'], 2','''))
  624.         ->setCellValue('H' $inumber_format((float)$totales_generales['totales_gen_masiva_client'], 2','''))
  625.     ;
  626.     $backRedSupplier 'K'.$i.':O'.$i;
  627.     $phpExcelObject
  628.         ->getActiveSheet()
  629.         ->getStyle($backRedSupplier)
  630.         ->getFill()
  631.         ->setFillType($fill::FILL_SOLID)
  632.         ->getStartColor()
  633.         ->setRGB('ff0303');
  634.     $phpExcelObject->setActiveSheetIndex(0)
  635.         ->setCellValue('K' $inumber_format((float)$totales_generales['totales_gen_neto_cost'], 2','''))
  636.         ->setCellValue('O' $inumber_format((float)$totales_generales['totales_gen_masiva_cost'], 2','''))
  637.     ;
  638.     $i += 2;
  639.     $backRedBen 'H'.$i.':K'.($i+1);
  640.     $phpExcelObject
  641.         ->getActiveSheet()
  642.         ->getStyle($backRedBen)
  643.         ->getFill()
  644.         ->setFillType($fill::FILL_SOLID)
  645.         ->getStartColor()
  646.         ->setRGB('ff0303');
  647.     $phpExcelObject->setActiveSheetIndex(0)
  648.         ->setCellValue('I' $i'Beneficio: 'number_format((float)$totales_generales['totatles_gen_beneficio_moneda'], 2',''').' â‚¬')
  649.         ->setCellValue('I' . ($i+1), 'Beneficio (%): 'number_format((float)$totales_generales['totatles_gen_beneficio_por'], 2','''). ' %')
  650.     ;
  651.     $i += 4;
  652.     $backGrayPay 'B'.$i.':O'.($i+1);
  653.     $phpExcelObject
  654.         ->getActiveSheet()
  655.         ->getStyle($backGrayPay)
  656.         ->getFill()
  657.         ->setFillType($fill::FILL_SOLID)
  658.         ->getStartColor()
  659.         ->setRGB('c4c4c4');
  660.     $phpExcelObject->setActiveSheetIndex(0)
  661.         ->setCellValue('C' $i'Cantidad')
  662.         ->setCellValue('G' $i'Fecha de Pago')
  663.         ->setCellValue('L' $i'Forma de Pago')
  664.     ;
  665.     $i+=2;
  666.     foreach ($payments as $item){
  667.         $backGrayPay 'B'.$i.':O'.$i;
  668.         $phpExcelObject
  669.             ->getActiveSheet()
  670.             ->getStyle($backGrayPay)
  671.             ->getFill()
  672.             ->setFillType($fill::FILL_SOLID)
  673.             ->getStartColor()
  674.             ->setRGB('c4c4c4');
  675.         $phpExcelObject->setActiveSheetIndex(0)
  676.             ->setCellValue('C' $i$item->getAmount())
  677.             ->setCellValue('G' $i$item->getDatePayAt()->format('d/m/Y'))
  678.             ->setCellValue('L' $i$item->getWaytopay())
  679.         ;
  680.         $i++;
  681.     }
  682.     $phpExcelObject->getActiveSheet()->setTitle('Estadísticas por sala');
  683.     // Define el indice de página al número 1, para abrir esa página al abrir el archivo
  684.     $phpExcelObject->setActiveSheetIndex(0);
  685.     // Creamos pagina de Datos en bruto para Esteban Rincon
  686.     // Add new sheet
  687.     $objWorkSheet $phpExcelObject->createSheet(1); //Setting index when creating
  688.     $phpExcelObject->setActiveSheetIndex(1);
  689.     $phpExcelObject->getActiveSheet()->setTitle('Datos en bruto');
  690.     $x 1;
  691.     $phpExcelObject->setActiveSheetIndex(1)
  692.         ->setCellValue('A'.$x'PROVEEDOR')
  693.         ->setCellValue('B'.$x'BENEFICIO (€)')
  694.         ->setCellValue('C'.$x'BENEFICIO (%)')
  695.         ->setCellValue('D'.$x'SUMA TOTAL NETO CLIENTE')
  696.         ->setCellValue('E'.$x'SUMA TOTAL CLIENTE')
  697.         ->setCellValue('F'.$x'SUMA TOTAL NETO PROVEEDOR')
  698.         ->setCellValue('G'.$x'SUMA TOTAL PROVEEDOR')
  699.         ->setCellValue('H'.$x'PAGOS ANTICIPADOS')
  700.         ->setCellValue('I'.$x'PAGOS PENDIENTES')
  701.         ->setCellValue('J'.$x'SERVICIO')
  702.         ->setCellValue('K'.$x'CLIENTE NEGOCIO')
  703.         ->setCellValue('L'.$x'IVA DEL CLIENTE')
  704.         ->setCellValue('M'.$x'TOTAL CLIENTE')
  705.         ->setCellValue('N'.$x'PROVEEDOR TOTAL NETO')
  706.         ->setCellValue('O'.$x'PROVEEDOR IVA')
  707.         ->setCellValue('P'.$x'TOTAL PROVEEDOR')
  708.     ;
  709.     $i $x 1;
  710.     foreach ($data as $item) {
  711.         $phpExcelObject->setActiveSheetIndex(1) ->setCellValue('A' $i$item['supplier']) ;
  712.         $phpExcelObject->setActiveSheetIndex(1)
  713.             ->setCellValue('B' $inumber_format((float)$item['totales']['beneficio'], 2','''))
  714.             ->setCellValue('C' $inumber_format((float)$item['totales']['beneficio_por'], 2','''))
  715.         ;
  716.         $phpExcelObject->setActiveSheetIndex(1) ->setCellValue('D' .$i$item['totales']['totalesSu_neto_client']) ;
  717.         $phpExcelObject->setActiveSheetIndex(1) ->setCellValue('E' .$i$item['totales']['totalesSu_masiva_client']) ;
  718.         $phpExcelObject->setActiveSheetIndex(1) ->setCellValue('F' .$i$item['totales']['totalesSu_neto_cost']) ;
  719.         $phpExcelObject->setActiveSheetIndex(1) ->setCellValue('G' .$i$item['totales']['totalesSu_masiva_cost']) ;
  720.         $phpExcelObject->setActiveSheetIndex(1) ->setCellValue('H' .$i$item['totales']['pagos']) ;
  721.         $phpExcelObject->setActiveSheetIndex(1) ->setCellValue('I' .$i$item['totales']['totales_pagos']) ;
  722.         foreach ($item['data'] as $elem) {
  723.             // Tipo de servicio
  724.             $phpExcelObject->setActiveSheetIndex(1)
  725.                 ->setCellValue('J' $i$elem['data']->getServiceCatName())
  726.                 ->setCellValue('K' $i$elem['total_neto_client'])
  727.                 ->setCellValue('L' $i$elem['iva_client'])
  728.                 ->setCellValue('M' $i$elem['total_iva_client'])
  729.                 ->setCellValue('N' $inumber_format((float)$elem['total_neto'], 2','''))
  730.                 ->setCellValue('O' $i$elem['data']->getIvaServices())
  731.                 ->setCellValue('P' $inumber_format((float)$elem['total_iva'], 2','''))
  732.             ;
  733.             $i++;
  734.         }
  735.     }
  736.     $i += 3;
  737.     $phpExcelObject->setActiveSheetIndex(1)
  738.         ->setCellValue('A' $i'CANTIDAD')
  739.         ->setCellValue('B' $i'FECHA DE PAGO')
  740.         ->setCellValue('C' $i'FORMA DE PAGO')
  741.     ;
  742.     $i++;
  743.     foreach ($payments as $item){
  744.         $phpExcelObject->setActiveSheetIndex(1)
  745.             ->setCellValue('A' $i$item->getAmount())
  746.             ->setCellValue('B' $i$item->getDatePayAt()->format('d/m/Y'))
  747.             ->setCellValue('C' $i$item->getWaytopay())
  748.         ;
  749.         $i++;
  750.     }
  751.     $phpExcelObject->setActiveSheetIndex(0);
  752.     // Crea el writer
  753. //    $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel2007');
  754.     $writer = new Xlsx($phpExcelObject);
  755.     // Envia la respuesta del controlador
  756. //    $response = $this->get('phpexcel')->createStreamedResponse($writer);
  757.     $response = new StreamedResponse( function () use ($writer) { $writer->save('php://output'); } );
  758.     // Agrega los headers requeridos
  759.     $dispositionHeader $response->headers->makeDisposition(
  760.         ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  761.         'InOut_Travel_Events'.'.xlsx'
  762.     );
  763.     $response->headers->set('Content-Type''application/vnd.ms-excel; charset=utf-8');
  764.     $response->headers->set('Pragma''public');
  765.     $response->headers->set('Cache-Control''maxage=1');
  766.     $response->headers->set('Content-Disposition'$dispositionHeader);
  767.     $phpExcelObject->getActiveSheet()->setTitle('InOut Travel & Events');
  768.     // Define el indice de página al número 1, para abrir esa página al abrir el archivo
  769.     $phpExcelObject->setActiveSheetIndex(0);
  770.     // Crea el writer
  771. //    $writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel2007');
  772.     $writer = new Xlsx($phpExcelObject);
  773.     // Envia la respuesta del controlador
  774. //    $response = $this->get('phpexcel')->createStreamedResponse($writer);
  775.     $response = new StreamedResponse( function () use ($writer) { $writer->save('php://output'); } );
  776.     // Agrega los headers requeridos
  777.     $dispositionHeader $response->headers->makeDisposition(
  778.         ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  779.         'InOut Travel and Events.xlsx'
  780.     );
  781.     $response->headers->set('Content-Type''application/vnd.ms-excel; charset=utf-8');
  782.     $response->headers->set('Pragma''public');
  783.     $response->headers->set('Cache-Control''maxage=1');
  784.     $response->headers->set('Content-Disposition'$dispositionHeader);
  785.     return $response;
  786. }
  787.         // ******************************** Statistics ********************************
  788.         $agentNewStats $em->getRepository(User::class)->findOneById($proposal->getAgentId());
  789.         $ivaNewStats $totales_generales['totales_gen_masiva_client'] - $totales_generales['totales_gen_neto_client'];
  790.         $stats $em->getRepository(ProposalsStatistics::class)->findOneByProposalId($id);
  791.         if ($proposal->getStatus() == 'Invoiced'){
  792.             $invoiceNewStats $em->getRepository(ProposalInvoice::class)->findOneByProposalId($id);
  793.             if (empty($stats)){
  794.                 $stats = new ProposalsStatistics();
  795.                 $stats->setProposalId($id);
  796.                 $stats->setProposalName($proposal->getName());
  797.                 $stats->setProposalStatus($proposal->getStatus());
  798.                 $stats->setInvoice($invoiceNewStats->getNumber());
  799.                 $stats->setAgentFullName($agentNewStats->getName() . ' ' $agentNewStats->getLastName());
  800.                 $stats->setAgentId($agentNewStats->getId());
  801.                 $stats->setClientName($client->getName());
  802.                 $stats->setClientId($client->getId());
  803.                 $stats->setProposalDateAt($proposal->getDateEventStarAt());
  804.                 $stats->setProposalNet($totales_generales['totales_gen_neto_client']);
  805.                 $stats->setProposalBenefit($totales_generales['totatles_gen_beneficio_moneda']);
  806.                 $stats->setProposalBenefitPerc($totales_generales['totatles_gen_beneficio_por']);
  807.                 $stats->setProposalIva($ivaNewStats);
  808.                 $stats->setProposalTotal($totales_generales['totales_gen_masiva_client']);
  809.                 $stats->setInvoiceDate($invoiceNewStats->getDateAt());
  810.                 $em->persist($stats);
  811.                 $em->flush();
  812.             } else {
  813.                 if ($stats->getProposalStatus() !== 'Invoiced'){
  814.                     // Estaba en confirmado y paso a facturado
  815.                     $stats->setProposalId($id);
  816.                     $stats->setProposalName($proposal->getName());
  817.                     $stats->setProposalStatus($proposal->getStatus());
  818.                     $stats->setInvoice($invoiceNewStats->getNumber());
  819.                     $stats->setAgentFullName($agentNewStats->getName() . ' ' $agentNewStats->getLastName());
  820.                     $stats->setAgentId($agentNewStats->getId());
  821.                     $stats->setClientName($client->getName());
  822.                     $stats->setClientId($client->getId());
  823.                     $stats->setProposalDateAt($proposal->getDateEventStarAt());
  824.                     $stats->setProposalNet($totales_generales['totales_gen_neto_client']);
  825.                     $stats->setProposalBenefit($totales_generales['totatles_gen_beneficio_moneda']);
  826.                     $stats->setProposalBenefitPerc($totales_generales['totatles_gen_beneficio_por']);
  827.                     $stats->setProposalIva($ivaNewStats);
  828.                     $stats->setProposalTotal($totales_generales['totales_gen_masiva_client']);
  829.                     $stats->setInvoiceDate($invoiceNewStats->getDateAt());
  830.                     $em->persist($stats);
  831.                     $em->flush();
  832.                 }
  833.             }
  834.         } else {
  835.             // La parte para los confirmados
  836.             if ($proposal->getStatus() == 'Confirmed'){
  837.                 if (empty($stats)){ $stats = new ProposalsStatistics(); }
  838.                 $stats->setProposalId($id);
  839.                 $stats->setProposalName($proposal->getName());
  840.                 $stats->setProposalStatus($proposal->getStatus());
  841.                 $stats->setInvoice('NF');
  842.                 $stats->setAgentFullName($agentNewStats->getName() . ' ' $agentNewStats->getLastName());
  843.                 $stats->setAgentId($agentNewStats->getId());
  844.                 $stats->setClientName($client->getName());
  845.                 $stats->setClientId($client->getId());
  846.                 $stats->setProposalDateAt($proposal->getDateEventStarAt());
  847.                 $stats->setProposalNet($totales_generales['totales_gen_neto_client']);
  848.                 $stats->setProposalBenefit($totales_generales['totatles_gen_beneficio_moneda']);
  849.                 $stats->setProposalBenefitPerc($totales_generales['totatles_gen_beneficio_por']);
  850.                 $stats->setProposalIva($ivaNewStats);
  851.                 $stats->setProposalTotal($totales_generales['totales_gen_masiva_client']);
  852.                 $stats->setInvoiceDate(null);
  853.                 $em->persist($stats);
  854.                 $em->flush();
  855.             }
  856.         }
  857.         // ******************************** Statistics ********************************
  858.         return $this->render('MDS/EventsBundle/summary/summary-price-proposal.html.twig',
  859.             array(
  860.                 'id' => $id,
  861.                 'token' => $proposal->getAccessKey(),
  862.                 'mcp' => $proposal->getMcp(),
  863.                 'client' => $client,
  864.                 'data' => $data_supplier,
  865.                 'general' => $totales_generales,
  866.                 'payments' => $payments,
  867.                 'discounts' => $descuento,
  868.             ));
  869.     }
  870.     public function CalculoTotalesservices($price$units$pax$days$opcommission$commission$opover$over$opiva$iva$idcat)
  871.     {
  872.         $price trim($price);
  873.         $over trim($over);
  874.         $price str_replace(",""."$price);
  875.         $over str_replace(",""."$over);
  876.         
  877.         if (empty($commission)){$commission ="0";}
  878.         $iva = (float)$iva 100;
  879.         if($opiva =='0'){
  880.             $price $price / ($iva 1);
  881.         }
  882. ////        $commission = $commission / 100;
  883. //        $commission = (100 - $commission) / 100;
  884. //        if($opcommission=='0'){
  885. //            $price = $price * $commission;
  886. //        }
  887.         if($opcommission=='0'){
  888.             $commission = (100 $commission) / 100;
  889.             $price $price $commission;
  890.         }
  891.         if($opcommission=='1'){
  892.             $commission = ($commission 100) + 1;
  893.         }
  894.                     //Units
  895.                     if(empty($units) or $units =="0"){
  896.                         $units "1";
  897.                     }
  898.                     // Calculo Especial por categoria
  899.                     //Alojamientos
  900.                     if($idcat =="1"){
  901.                         $informativo_days "si";
  902.                         $pax "1";
  903.                     }
  904.                     //Transporte
  905.                     elseif($idcat =="13"){
  906.                         $informativo_days "no";
  907.                         $pax "1";
  908.                     }
  909.                     //Guia
  910.                     elseif($idcat =="8"){
  911.                         $informativo_days "no";
  912.                         $pax "1";
  913.                     }
  914.                     //Lounge
  915.                     elseif($idcat =="10"){
  916.                         $informativo_days "no";
  917.                         $pax "1";
  918.                     }else{
  919.                         $informativo_days "no";
  920.                     }
  921.                     //Pax
  922.                     if(empty($pax) or $pax =="0"){
  923.                         $pax "1";
  924.                     }
  925.                     //Over
  926.                     if(empty($over)){
  927.                         $over "0";
  928.                     }
  929.                     if($informativo_days =="no"){
  930.                         //Days
  931.                         if(empty($days) or $days =="0"){
  932.                             $days "1";
  933.                         }else{
  934.                             $days $days ;
  935.                         }
  936.                     }
  937.         $total_items $price $units $pax $days;
  938.         $total_over $over $units $pax $days;
  939. //        if($opover=='0'){
  940. ////            $total_neto = $total_items * ($commission + 1) - $total_over ;
  941. //            $total_neto = $total_items / $commission - $total_over;
  942. //        }
  943. //        if($opover=='1'){
  944. ////            $total_neto = $total_items * ($commission + 1) + $total_over;
  945. //            $total_neto = $total_items / $commission + $total_over;
  946. //        }
  947.         if($opcommission=='0'){
  948.             $total_neto $total_items $commission;
  949.         }
  950.         if($opcommission=='1'){
  951.             $total_neto $total_items $commission;
  952.         }
  953.         if($opover=='0'){
  954.             $total_neto $total_neto $total_over ;
  955.         }
  956.         if($opover=='1'){
  957.             $total_neto $total_neto +  $total_over;
  958.         }
  959.         $total_paying $total_items * ($iva 1);
  960.         $total_comision ="0";
  961.         $total_pago $total_items;
  962.         $total_iva $total_items $iva;
  963.         $sub_total_iva $total_neto $iva;
  964.         $total $total_neto $sub_total_iva;
  965.         $benefit_moneda $total_neto $total_items;
  966.         $data_calculos = array(
  967.             'total_days' => $days,
  968.             'sub_total' => $total_items,
  969.             'sub_total_iva' => $sub_total_iva,
  970.             'total_neto' => $total_neto,
  971.             'total_iva' => $total_iva,
  972.             'total_paying' => $total_paying,
  973.             'total_pago' => $total_pago,
  974.             'total_comision' => $total_comision,
  975.             'total' => $total,
  976.             'benefit_moneda' => $benefit_moneda
  977.         );
  978.         return $data_calculos;
  979.     }
  980.     /**
  981.      * @Route("/proposal/lowbenefitlist",  name="proposal_lowbenefitlist")
  982.      */
  983.     public function ListLowBenefitAction(Request $request)
  984.     {
  985.         $em $this->getDoctrine()->getManager();
  986.         $proposal $em->getRepository(ProposalBenefitUnder::class)->findAll();
  987.         $proposalBenefitUnder = array();
  988.         foreach ($proposal as $prop){
  989.             $proposalData $em->getRepository(Proposal::class)->findOneById($prop->getProposalId());
  990.             $agentId $proposalData->getAgentId();
  991.             $agent '';
  992.             if (!empty($agentId)) {
  993.                 $agent = ($em->getRepository(User::class)->findOneById($agentId))->getName() . ' ' . ($em->getRepository(User::class)->findOneById($agentId))->getLastName();
  994.             }
  995.             $proposalBenefitUnder[] = array(
  996.                 'proposalId' => $prop->getProposalId(),
  997.                 'proposalName' => $proposalData->getName(),
  998.                 'proposalAgent' => $agent,
  999.                 'benefitCurrency' => $prop->getBenefitCurrency(),
  1000.                 'benefitPercentage' => $prop->getBenefitPercentage(),
  1001.             );
  1002.         }
  1003. //d($proposalBenefitUnder);exit();
  1004.         return $this->render('MDS/EventsBundle/summary/low-benefit-proposal-list.html.twig',
  1005.             array(
  1006.                 'proposalBenefitUnder' => $proposalBenefitUnder,
  1007.                 'id' => 0,
  1008.                 'token' => '',
  1009.                 'mcp' => '',
  1010.                 'unassigned' => '',
  1011.             ));
  1012.     }
  1013. }