<?php
/**
* Created by Mediterranean Develup Solutions
* User: jorge.defreitas@develup.solutions
* Date: 11/10/2017
* Time: 10:27
*/
namespace App\MDS\EventsBundle\Controller;
use App\Entity\Activities;
use App\Entity\Cities;
use App\Entity\Client;
use App\Entity\Configuration;
use App\Entity\Country;
use App\Entity\Destination;
use App\Entity\Ideas;
use App\Entity\Provinces;
use App\Entity\Regions;
use App\Entity\SettingsCompany;
use App\Entity\SettingsRol;
use App\Entity\Supplier;
use App\Entity\SupplierGallery;
use App\Entity\SupplierIdeaServicesControl;
use App\Entity\User;
use App\MDS\EventsBundle\Entity\Proposal;
use App\MDS\EventsBundle\Entity\ProposalAgendaPresupuestoControl;
use App\MDS\EventsBundle\Entity\ProposalAgents;
use App\MDS\EventsBundle\Entity\ProposalControl;
use App\MDS\EventsBundle\Entity\ProposalSupplierControl;
use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
use App\MDS\EventsBundle\Entity\ProposalSupplierServicesBudget;
use App\MDS\EventsBundle\Entity\ProposalSupplierServicesBudgetControl;
use Swift_Mailer;
use Swift_Message;
use Swift_SmtpTransport;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\Translation\TranslatorInterface;
class ProposalBudgetController extends AbstractController
{
private $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* @Route("/proposal/makeyourbudget/budget/add/", name="proposal_destination_supplier_makeyourbudget_Add")
*/
public function MakeYourBudgetAddSupplierAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$incluir = "";
$proposalid = $request->request->get('proposalid');
$incluir = $request->request->get('incluir');
$incluir_sub = $request->request->get('incluir_sub');
$services = $request->request->get('services');
$recommended = $request->request->get('recommended');
$priority = $request->request->get('priority');
$name = $request->request->get('name');
$byclient = null;
if (is_null($recommended)) {
$recommended = 0;
} else {
$recommended = 1;
}
if (empty($priority)) {
$priority = 0;
}
$status = "Pending";
$proposal = $em->getRepository(Proposal::class)->findOneById($proposalid);
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
if (!empty($incluir)) {
$control = new ProposalSupplierServicesBudgetControl();
$control->setProposalId($proposalid);
$control->setStatus($status);
$control->setName($name);
$control->setByClient($byclient);
$control->setRecommended($recommended);
$control->setPriority($priority);
$em->persist($control);
$em->flush();
$controlid = $control->getId();
foreach ($incluir as $padentro) {
$id = $padentro['id'];
if (array_key_exists($id, $services)) {
$services_proposal = $em->getRepository(ProposalSupplierServices::class)->findOneById($id);
//COLOR POR SERVICIO
$contcolor = "";
switch ($services_proposal->getServiceCatName()) {
case "Accommodation":
$contcolor = 'teal';
break;
case "Menu":
$contcolor = 'purple';
break;
case "Lounge":
$contcolor = 'warning';
break;
case "Activities":
$contcolor = 'blue';
break;
case "Itineraries":
$contcolor = 'indigo';
break;
case "Cruise":
$contcolor = 'brown';
break;
case "Transport":
$contcolor = 'grey';
break;
case "Av":
$contcolor = 'slate';
break;
case "Creative":
$contcolor = 'orange';
break;
case "Gifts":
$contcolor = 'pink';
break;
case "Entertainment":
$contcolor = 'green';
break;
case "Guide":
$contcolor = 'orange';
break;
case "Others":
$contcolor = 'danger';
break;
case "Technology":
$contcolor = 'grey-800';
break;
case "Assistant":
$contcolor = 'indigo-800';
break;
case "DDR":
$contcolor = 'green-300';
break;
}
// $var = $services[$id];
// $servicesBudget = new ProposalSupplierServicesBudget();
// $servicesBudget->setControlId($controlid);
// $servicesBudget->setItemsServiceId($id);
// $servicesBudget->setItemsserviceIdFather('0');
// $servicesBudget->setProposalId($proposalid);
// $servicesBudget->setDestinationId($services_proposal->getDestinationId());
// $servicesBudget->setSupplierId($services_proposal->getSupplierId());
// $servicesBudget->setIdeaId($services_proposal->getIdeaId());
// $servicesBudget->setServiceId($services_proposal->getServiceId());
// $servicesBudget->setServiceCatId($services_proposal->getServiceCatId());
// $servicesBudget->setServiceCatName($services_proposal->getServiceCatName());
// $servicesBudget->setContColor($contcolor);
// $servicesBudget->setName($services_proposal->getName());
// $servicesBudget->setPrice($var['price']); // <--- OJO AQUI METER LO DE CON IVA Y SISN IVA
// $servicesBudget->setCurrency($services_proposal->getCurrency());
// $servicesBudget->setUnits($var['units']);
// $servicesBudget->setPax($var['pax']);
// $servicesBudget->setDays($var['days']);
// $servicesBudget->setDateInAt($services_proposal->getDateInAt());
// $servicesBudget->setDateOutAt($services_proposal->getDateOutAt());
// $servicesBudget->setNetAmount($var['netamount']);
// $servicesBudget->setIva($var['iva']);
// $servicesBudget->setTotal($var['total']);
// $servicesBudget->setStatus($status);
// $servicesBudget->setRank($var['rank']);
// $servicesBudget->setCreatedId($user_id);
// $servicesBudget->setUpdatedId($user_id);
// $em->persist($servicesBudget);
// $em->flush();
$var = $services[$id];
// UNITS
if (empty($var['units']) or $var['units'] == 0) {
$units = "1";
} else {
$units = $var['units'];
}
// PAX
if (empty($var['pax']) or $var['pax'] == 0) {
$pax = "1";
} else {
$pax = $var['pax'];
}
// Calculo Especial por categoria
//Alojamientos
if ($services_proposal->getServiceCatId() == "1") {
$pax = "1";
}
//Transporte
elseif ($services_proposal->getServiceCatId() == "13") {
$pax = "1";
}
//Lounge
elseif ($services_proposal->getServiceCatId() == "10") {
$pax = "1";
}
//Guia
elseif ($services_proposal->getServiceCatId() == "8") {
$pax = "1";
}
// CALCULO DEL NETO
$netamount = $var['price'] * $units * $pax * $var['days'];
// CALCULO DEL TOTAL
$iva = ($var['iva'] / 100) + 1;
$total = $netamount * $iva;
$servicesBudget = new ProposalSupplierServicesBudget();
$servicesBudget->setControlId($controlid);
$servicesBudget->setItemsServiceId($id);
$servicesBudget->setItemsserviceIdFather('0');
$servicesBudget->setProposalId($proposalid);
$servicesBudget->setDestinationId($services_proposal->getDestinationId());
$servicesBudget->setSupplierId($services_proposal->getSupplierId());
$servicesBudget->setIdeaId($services_proposal->getIdeaId());
$servicesBudget->setActivityId($services_proposal->getActivityId());
$servicesBudget->setServiceId($services_proposal->getServiceId());
$servicesBudget->setServiceCatId($services_proposal->getServiceCatId());
$servicesBudget->setServiceCatName($services_proposal->getServiceCatName());
$servicesBudget->setContColor($contcolor);
$servicesBudget->setName($services_proposal->getName());
$servicesBudget->setPrice($var['price']);
$servicesBudget->setCurrency($services_proposal->getCurrency());
$servicesBudget->setUnits($var['units']);
$servicesBudget->setPax($var['pax']);
$servicesBudget->setDays($var['days']);
$servicesBudget->setDateInAt($services_proposal->getDateInAt());
$servicesBudget->setDateOutAt($services_proposal->getDateOutAt());
$servicesBudget->setNetAmount($netamount);
$servicesBudget->setIva($var['iva']);
$servicesBudget->setTotal($total);
$servicesBudget->setStatus($status);
$servicesBudget->setRank($var['rank']);
$servicesBudget->setCreatedId($user_id);
$servicesBudget->setUpdatedId($user_id);
$em->persist($servicesBudget);
$em->flush();
}
// if (!empty($incluir_sub)){
//
// foreach($incluir_sub as $idpapa => $incluirSub){
//
// if ($id == $idpapa){
//
// foreach($incluirSub as $hijopadentro){
//
// $idp = $hijopadentro['id'];
//
// if (array_key_exists($idp, $services)) {
// $services_proposal= $em->getRepository(ProposalSupplierServices::class)->findOneById($idp);
//
// //COLOR POR SERVICIO
// $contcolor ="";
// switch ($services_proposal->getServiceCatName()) {
// case "Accommodation":
// $contcolor = 'teal';
// break;
// case "Menu" :
// $contcolor = 'purple';
// break;
// case "Lounge":
// $contcolor = 'warning';
// break;
// case "Activities":
// $contcolor = 'blue';
// break;
// case "Itineraries":
// $contcolor = 'indigo';
// break;
// case "Cruise":
// $contcolor = 'brown';
// break;
// case "Transport":
// $contcolor = 'grey';
// break;
// case "Av":
// $contcolor = 'slate';
// break;
// case "Creative":
// $contcolor = 'orange';
// break;
// case "Gifts":
// $contcolor = 'pink';
// break;
// case "Entertainment":
// $contcolor = 'green';
// break;
// case "Guide":
// $contcolor = 'orange';
// break;
// case "Others":
// $contcolor = 'danger';
// break;
// case "Technology":
// $contcolor = 'grey-800';
// break;
// case "Assistant":
// $contcolor = 'indigo-800';
// break;
// }
//
// // UNITS
// if (empty($var['units']) or $var['units'] == 0){ $units = "1"; }else{ $units = $var['units']; }
// // PAX
// if (empty($var['pax']) or $var['pax'] == 0){ $pax = "1"; }else{ $pax = $var['pax']; }
//
// // CALCULO DEL NETO
// $netamount = $services_proposal->getPrice() * $units * $pax * $var['days'];
// // CALCULO DEL TOTAL
// $total = $netamount * ($var['iva'] + 1);
//
// $var = $services[$idp];
// $servicesBudget = new ProposalSupplierServicesBudget();
// $servicesBudget->setControlId($controlid);
// $servicesBudget->setItemsServiceId($idp);
// $servicesBudget->setItemsserviceIdFather($id);
// $servicesBudget->setProposalId($proposalid);
// $servicesBudget->setDestinationId($services_proposal->getDestinationId());
// $servicesBudget->setSupplierId($services_proposal->getSupplierId());
// $servicesBudget->setServiceId($services_proposal->getServiceId());
// $servicesBudget->setServiceCatId($services_proposal->getServiceCatId());
// $servicesBudget->setServiceCatName($services_proposal->getServiceCatName());
// $servicesBudget->setContColor($contcolor);
// $servicesBudget->setName($services_proposal->getName());
// $servicesBudget->setPrice($services_proposal->getPrice());
// $servicesBudget->setCurrency($services_proposal->getCurrency());
// $servicesBudget->setUnits($var['units']);
// $servicesBudget->setPax($var['pax']);
// $servicesBudget->setDays($var['days']);
// $servicesBudget->setDateInAt($services_proposal->getDateInAt());
// $servicesBudget->setDateOutAt($services_proposal->getDateOutAt());
// $servicesBudget->setNetAmount($netamount);
// $servicesBudget->setIva($var['iva']);
// $servicesBudget->setTotal($total);
// $servicesBudget->setStatus($status);
// $servicesBudget->setRank($var['rank']);
// $servicesBudget->setCreatedId($user_id);
// $servicesBudget->setUpdatedId($user_id);
// $em->persist($servicesBudget);
// $em->flush();
//
// }
//
//
// }
// }
//
// }
// }
}
} else {
$errorMessagebase = $this->translator->trans('Error, you have not selected any service');
$this->addFlash('mensajeproposalbudgetserviceserror', $errorMessagebase);
return $this->redirectToRoute(
'proposal_destination_supplier_makeyourbudget',
array(
'id' => $proposalid
)
);
}
return $this->redirectToRoute(
'proposal_destination_supplier_makeyourbudget_view',
array(
'id' => $proposalid,
'idcontrol' => $controlid,
)
);
}
/**
* @Route("/proposal/makeyourbudget/budget/view/{id}/{idcontrol}", name="proposal_destination_supplier_makeyourbudget_view")
*/
public function MakeYourBudgetViewSupplierAction($id, $idcontrol, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$country = $em->getRepository(Country::class)->findOneById($client->getCountry());
$client->setCountry($country->getCountry());
$regions = $em->getRepository(Regions::class)->findOneById($client->getRegion());
$client->setRegion($regions->getRegion());
$province = $em->getRepository(Provinces::class)->findOneById($client->getProvince());
$client->setProvince($province->getName());
$cities = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
$client->setPopulation($cities->getCity());
$data_controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
$controlproposal = $em->getRepository(ProposalControl::class)->findByProposalId($id);
$controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($id);
foreach ($controlbudgets as $controlbudge) {
$presupuesto['byclient'] = $controlbudge->getByClient();
$presupuesto['id'] = $controlbudge->getId();
$presupuesto['name'] = $controlbudge->getName();
$presupuesto['priority'] = $controlbudge->getPriority();
$presupuesto['proposalId'] = $controlbudge->getProposalId();
$presupuesto['recommended'] = $controlbudge->getRecommended();
$presupuesto['status'] = $controlbudge->getStatus();
$hasDiary = $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
array(
'proposalId' => $controlbudge->getProposalId(),
'controlId' => $controlbudge->getId(),
)
);
if ($hasDiary) {
$presupuesto['hasDiary'] = true;
} else {
$presupuesto['hasDiary'] = false;
}
$controlbudget[$controlbudge->getRecommended()][] = $presupuesto;
}
$controlbudgetBoton = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
$filtro2 = array();
foreach ($controlproposal as $consultabudget2) {
$filtro2[] = $consultabudget2->getDestinationId();
}
$services_supplier = array();
$services_ideas = array();
$budget = array();
$content_data = array();
$destination = array();
$totales_neto = "0";
$totales_total = "0";
$totales_iva = array();
$data = array();
foreach ($filtro2 as $destinobudget) {
$destination = $em->getRepository(Destination::class)->findOneById($destinobudget);
$destino = $destination->getTitle();
$consulta_budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
array(
'controlId' => $idcontrol,
'destinationId' => $destinobudget,
'itemsserviceIdFather' => '0'
),
array(
'rank' => 'DESC'
)
);
$filtro = array();
foreach ($consulta_budget as $consultabudget) {
if (!is_null($consultabudget->getActivityId())) {
$filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
}
if (!is_null($consultabudget->getIdeaId())) {
$filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
$filtro['whiteservice']['0'][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
$filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
}
// $filtro[$consultabudget->getSupplierId()] = $consultabudget;
}
// d($filtro);
//
$master = "";
$services = array();
$whiteservice = array();
$idea = array();
$activity = array();
$supplier = array();
foreach ($filtro as $key => $ideaOsupplier) {
// d("·········································", $ideaOsupplier);
foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
// d($ideaOsupplierAdentro);
$services = array();
$total_neto = null;
$total_total = null;
foreach ($ideaOsupplierAdentro as $servicesbudget) {
// d($servicesbudget);
// $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva()/100);
// if (empty($totales_iva[$servicesbudget->getIva()])){
// $totales_iva[$servicesbudget->getIva()] = 0;
// }
// $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
// $total_neto += $servicesbudget->getNetAmount();
// $totales_neto += $servicesbudget->getNetAmount();
// $total_total += $servicesbudget->getTotal();
// $totales_total += $servicesbudget->getTotal();
if ($key == "whiteservice") {
$services_white = $em->getRepository(Configuration::class)->findOneById('1');
$master = "whiteservice";
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
// if (is_numeric($servicesbudget->getNetAmount())){
// $totales_neto += $servicesbudget->getNetAmount();
// }else{
// $totales_neto += 0;
// }
// if (is_numeric($servicesbudget->getTotal())){
// $total_total += $servicesbudget->getTotal();
// }else{
// $total_total += 0;
// }
$totales_total += $servicesbudget->getTotal();
$whiteservice[$services_white->getId()] = array(
'datos' => $services_white,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
// $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
// array(
// 'controlId' => $idcontrol,
// 'destinationId' => $destinobudget,
// 'supplierId' => '0',
// ),
// array(
// 'rank' => 'ASC'
// )
// );
}
if ($key == "activity") {
$services_activities = $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
$master = "activity";
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
$activity[$services_activities->getId()] = array(
'datos' => $services_activities,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
// foreach($services_ideas as $serviceideas){
//
// $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
// array(
// 'controlId' => $idcontrol,
// 'destinationId' => $destinobudget,
// 'ideaId' => $serviceideas->getId(),
// ),
// array(
// 'rank' => 'ASC'
// )
// );
//
// }
}
if ($key == "idea") {
$services_ideas = $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
$master = "idea";
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
$idea[$services_ideas->getId()] = array(
'datos' => $services_ideas,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
// foreach($services_ideas as $serviceideas){
//
// $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
// array(
// 'controlId' => $idcontrol,
// 'destinationId' => $destinobudget,
// 'ideaId' => $serviceideas->getId(),
// ),
// array(
// 'rank' => 'ASC'
// )
// );
//
// }
}
if ($key == "supplier") {
if (is_null($servicesbudget->getIdeaId()) and is_null($servicesbudget->getActivityId())) {
$servicessupplier = $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
$master = "supplier";
// foreach($services_supplier as $servicessupplier){
if (!is_null($servicessupplier)) {
switch ($servicessupplier->getStar()) {
case 1:
$servicessupplier->setStar('<i class="icon-star-full2"></i>');
break;
case 2:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 3:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 4:
$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>');
break;
case 5:
$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');
break;
case 6:
$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>');
break;
case 7:
$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');
break;
case 8:
$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');
break;
}
}
// $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
// array(
// 'controlId' => $idcontrol,
// 'destinationId' => $destinobudget,
// 'supplierId' => $servicessupplier->getId(),
// ),
// array(
// 'rank' => 'ASC'
// )
// );
// }
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
// d($servicesbudget); exit();
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
$supplier[$servicessupplier->getId()] = array(
'datos' => $servicessupplier,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
}
}
// d($totales_neto, $totales_total );
}
}
}
// d($supplier);
$content_data = array(
'supplier' => $supplier,
'idea' => $idea,
'activity' => $activity,
'whiteservice' => $whiteservice,
);
$data[] = array(
'destination' => $destination,
'container' => $content_data
);
}
// d($controlbudget);
return $this->render(
'MDS/EventsBundle/budget/services-budget-proposal.html.twig',
array(
'id' => $id,
'token' => $proposal->getAccessKey(),
'mcp' => $proposal->getMcp(),
'client' => $client,
'budgets' => $controlbudget,
'budgetcontrol' => $data_controlbudgets,
'data' => $data,
'totales_neto' => $totales_neto,
'ivas' => $totales_iva,
'totales' => $totales_total,
'confirm' => $controlbudgetBoton
)
);
}
/**
* @Route("/proposal/makeyourbudget/budget/viewprint/{id}/{idcontrol}", name="proposal_destination_supplier_makeyourbudget_view_print")
*/
public function MakeYourBudgetViewPrintSupplierAction($id, $idcontrol, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findOneById($proposal->getClientId());
$country = $em->getRepository(Country::class)->findOneById($client->getCountry());
$client->setCountry($country->getCountry());
$regions = $em->getRepository(Regions::class)->findOneById($client->getRegion());
$client->setRegion($regions->getRegion());
$province = $em->getRepository(Provinces::class)->findOneById($client->getProvince());
$client->setProvince($province->getName());
$cities = $em->getRepository(Cities::class)->findOneById($client->getPopulation());
$client->setPopulation($cities->getCity());
$data_controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
$controlproposal = $em->getRepository(ProposalControl::class)->findByProposalId($id);
$controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($id);
foreach ($controlbudgets as $controlbudge) {
$presupuesto['byclient'] = $controlbudge->getByClient();
$presupuesto['id'] = $controlbudge->getId();
$presupuesto['name'] = $controlbudge->getName();
$presupuesto['priority'] = $controlbudge->getPriority();
$presupuesto['proposalId'] = $controlbudge->getProposalId();
$presupuesto['recommended'] = $controlbudge->getRecommended();
$presupuesto['status'] = $controlbudge->getStatus();
$hasDiary = $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
array(
'proposalId' => $controlbudge->getProposalId(),
'controlId' => $controlbudge->getId(),
)
);
if ($hasDiary) {
$presupuesto['hasDiary'] = true;
} else {
$presupuesto['hasDiary'] = false;
}
$controlbudget[$controlbudge->getRecommended()][] = $presupuesto;
}
$controlbudgetBoton = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
$filtro2 = array();
foreach ($controlproposal as $consultabudget2) {
$filtro2[] = $consultabudget2->getDestinationId();
}
$services_supplier = array();
$services_ideas = array();
$budget = array();
$content_data = array();
$destination = array();
$totales_neto = "0";
$totales_total = "0";
$totales_iva = array();
$data = array();
foreach ($filtro2 as $destinobudget) {
$destination = $em->getRepository(Destination::class)->findOneById($destinobudget);
$destino = $destination->getTitle();
$consulta_budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
array(
'controlId' => $idcontrol,
'destinationId' => $destinobudget,
'itemsserviceIdFather' => '0'
),
array(
'rank' => 'DESC'
)
);
$filtro = array();
foreach ($consulta_budget as $consultabudget) {
if (!is_null($consultabudget->getActivityId())) {
$filtro['activity'][$consultabudget->getActivityId()][] = $consultabudget;
}
if (!is_null($consultabudget->getIdeaId())) {
$filtro['idea'][$consultabudget->getIdeaId()][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() == "0")) {
$filtro['whiteservice']['0'][] = $consultabudget;
}
if ((!is_null($consultabudget->getSupplierId())) && ($consultabudget->getSupplierId() != "0")) {
$filtro['supplier'][$consultabudget->getSupplierId()][] = $consultabudget;
}
// $filtro[$consultabudget->getSupplierId()] = $consultabudget;
}
// d($filtro);
//
$master = "";
$services = array();
$whiteservice = array();
$idea = array();
$activity = array();
$supplier = array();
foreach ($filtro as $key => $ideaOsupplier) {
// d("·········································", $ideaOsupplier);
foreach ($ideaOsupplier as $ideaOsupplierAdentro) {
// d($ideaOsupplierAdentro);
$services = array();
$total_neto = null;
$total_total = null;
foreach ($ideaOsupplierAdentro as $servicesbudget) {
// d($servicesbudget);
// $totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva()/100);
// if (empty($totales_iva[$servicesbudget->getIva()])){
// $totales_iva[$servicesbudget->getIva()] = 0;
// }
// $totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
// $total_neto += $servicesbudget->getNetAmount();
// $totales_neto += $servicesbudget->getNetAmount();
// $total_total += $servicesbudget->getTotal();
// $totales_total += $servicesbudget->getTotal();
if ($key == "whiteservice") {
$services_white = $em->getRepository(Configuration::class)->findOneById('1');
$master = "whiteservice";
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
// if (is_numeric($servicesbudget->getNetAmount())){
// $totales_neto += $servicesbudget->getNetAmount();
// }else{
// $totales_neto += 0;
// }
// if (is_numeric($servicesbudget->getTotal())){
// $total_total += $servicesbudget->getTotal();
// }else{
// $total_total += 0;
// }
$totales_total += $servicesbudget->getTotal();
$whiteservice[$services_white->getId()] = array(
'datos' => $services_white,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
// $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
// array(
// 'controlId' => $idcontrol,
// 'destinationId' => $destinobudget,
// 'supplierId' => '0',
// ),
// array(
// 'rank' => 'ASC'
// )
// );
}
if ($key == "activity") {
$services_activities = $em->getRepository(Activities::class)->findOneById($servicesbudget->getActivityId());
$master = "activity";
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
$activity[$services_activities->getId()] = array(
'datos' => $services_activities,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
// foreach($services_ideas as $serviceideas){
//
// $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
// array(
// 'controlId' => $idcontrol,
// 'destinationId' => $destinobudget,
// 'ideaId' => $serviceideas->getId(),
// ),
// array(
// 'rank' => 'ASC'
// )
// );
//
// }
}
if ($key == "idea") {
$services_ideas = $em->getRepository(Ideas::class)->findOneById($servicesbudget->getIdeaId());
$master = "idea";
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
$idea[$services_ideas->getId()] = array(
'datos' => $services_ideas,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
// foreach($services_ideas as $serviceideas){
//
// $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
// array(
// 'controlId' => $idcontrol,
// 'destinationId' => $destinobudget,
// 'ideaId' => $serviceideas->getId(),
// ),
// array(
// 'rank' => 'ASC'
// )
// );
//
// }
}
if ($key == "supplier") {
if (is_null($servicesbudget->getIdeaId()) and is_null($servicesbudget->getActivityId())) {
$servicessupplier = $em->getRepository(Supplier::class)->findOneById($servicesbudget->getSupplierId());
$master = "supplier";
// foreach($services_supplier as $servicessupplier){
if (!is_null($servicessupplier)) {
switch ($servicessupplier->getStar()) {
case 1:
$servicessupplier->setStar('<i class="icon-star-full2"></i>');
break;
case 2:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 3:
$servicessupplier->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 4:
$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>');
break;
case 5:
$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');
break;
case 6:
$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>');
break;
case 7:
$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');
break;
case 8:
$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');
break;
}
}
// $budget = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
// array(
// 'controlId' => $idcontrol,
// 'destinationId' => $destinobudget,
// 'supplierId' => $servicessupplier->getId(),
// ),
// array(
// 'rank' => 'ASC'
// )
// );
// }
$services[] = array(
'service' => $servicesbudget
);
$totales_sub_iva = $servicesbudget->getNetAmount() * ($servicesbudget->getIva() / 100);
if (empty($totales_iva[$servicesbudget->getIva()])) {
$totales_iva[$servicesbudget->getIva()] = 0;
}
// d($servicesbudget); exit();
$totales_iva[$servicesbudget->getIva()] += $totales_sub_iva;
$total_neto += $servicesbudget->getNetAmount();
$totales_neto += $servicesbudget->getNetAmount();
$total_total += $servicesbudget->getTotal();
$totales_total += $servicesbudget->getTotal();
$supplier[$servicessupplier->getId()] = array(
'datos' => $servicessupplier,
'services' => $services,
'master' => $master,
'neto' => $total_neto,
'total' => $total_total
);
}
}
// d($totales_neto, $totales_total );
}
}
}
// d($supplier);
$content_data = array(
'supplier' => $supplier,
'idea' => $idea,
'activity' => $activity,
'whiteservice' => $whiteservice,
);
$data[] = array(
'destination' => $destination,
'container' => $content_data
);
}
// d($controlbudget);
return $this->render(
'MDS/EventsBundle/budget/services-budget-print-proposal.html.twig',
array(
'id' => $id,
'token' => $proposal->getAccessKey(),
'mcp' => $proposal->getMcp(),
'client' => $client,
'budgets' => $controlbudget,
'budgetcontrol' => $data_controlbudgets,
'data' => $data,
'totales_neto' => $totales_neto,
'ivas' => $totales_iva,
'totales' => $totales_total,
'confirm' => $controlbudgetBoton
)
);
}
// Make Your Budget
/**
* @Route("/proposal/makeyourbudget/base/{id}", name="proposal_destination_supplier_makeyourbudget")
*/
public function MakeYourBudgetSupplierAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneById($id);
$available_destination = $em->getRepository(ProposalControl::class)->findBy(
array(
'proposalId' => $id,
'disabled' => "0"
)
);
$data_supplier = array();
if (!empty($available_destination)) {
foreach ($available_destination as $availabledestination) {
/* Data Supplier agregados */
$service_supplier = $em->getRepository(ProposalSupplierControl::class)->findBy(
array(
'controlDestinationId' => $availabledestination->getId(),
'disabled' => "0"
),
array(
'rank' => 'ASC'
)
);
$controlgeneral = array();
foreach ($service_supplier as $suppliercontrol) {
$destination = $em->getRepository(Destination::class)->findOneById($suppliercontrol->getDestinoId());
//cambiar el estatus de colores
$colorlabel = "";
switch ($suppliercontrol->getStatus()) {
case 'Pending':
$colorlabel = "bg-danger";
break;
case 'Confirmed':
$colorlabel = "bg-success";
break;
}
$sqlactivities = "";
if (!is_null($suppliercontrol->getActivityId())) {
$master = "activity";
$sqlactivities = $em->getRepository(Activities::class)->findOneById($suppliercontrol->getActivityId());
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByActivityId($suppliercontrol->getActivityId());
}
$sqlideas = "";
if (!is_null($suppliercontrol->getIdeaId())) {
$master = "idea";
$sqlideas = $em->getRepository(Ideas::class)->findOneById($suppliercontrol->getIdeaId());
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneByIdeaId($suppliercontrol->getIdeaId());
}
$sqlsuppliers = "";
if (!is_null($suppliercontrol->getSupplierId()) && $suppliercontrol->getSupplierId() != "0") {
$master = "supplier";
$sqlsuppliers = $em->getRepository(Supplier::class)->findOneById($suppliercontrol->getSupplierId());
if (!is_null($sqlsuppliers)) {
switch ($sqlsuppliers->getStar()) {
case 1:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i>');
break;
case 2:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 3:
$sqlsuppliers->setStar('<i class="icon-star-full2"></i><i class="icon-star-full2"></i><i class="icon-star-full2"></i>');
break;
case 4:
$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>');
break;
case 5:
$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');
break;
case 6:
$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>');
break;
case 7:
$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');
break;
case 8:
$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');
break;
}
}
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($suppliercontrol->getSupplierId());
}
$sqlcompany = "";
if ($suppliercontrol->getSupplierId() == "0") {
$master = "company";
$sqlcompany = $em->getRepository(SettingsCompany::class)->findOneByPriority('1');
if (!is_null($sqlcompany)) {
$imagenSmall = $sqlcompany->getPicture();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
} else {
$sqlsuppliers_gallery = $em->getRepository(SupplierGallery::class)->findOneBy(
array(
'supplierId' => $controlgeneral->getId(),
'servicesCatId' => '0',
'servicesCategory' => 'General',
'servicesId' => '0',
'controlId' => '0'
)
);
if (!is_null($sqlsuppliers_gallery)) {
$imagenSmall = $sqlsuppliers_gallery->getImageSmall();
} else {
//Imagen no disponible (poner una generica)
$imagenSmall = null;
}
}
// ORDEN DESCENDENTE Y POR SERVICES
$parameters = array(
'controlId' => $suppliercontrol->getId(),
'serviceIdFather' => '0',
'directPayment' => '0',
);
$dql = 'SELECT p
FROM EventsBundle:ProposalSupplierServices p
WHERE p.controlId = :controlId
AND p.serviceIdFather = :serviceIdFather
AND p.directPayment = :directPayment
ORDER BY p.serviceCatId, p.rank ASC ';
$query = $em->createQuery($dql)->setParameters($parameters);
$data_service_supplier = $query->getResult();
$service_supplier_data = array();
$calculos_totatales = array();
$totales_neto = '0';
$totales_iva = '0';
$totales_con_iva = '0';
$totales_paying = '0';
$totales_pago = '0';
$totales_benefit_moneda = '0';
$totales_benefit_porsentaje = '0';
foreach ($data_service_supplier as $data_service) {
//COLOR POR SERVICIO
$contcolor = "";
switch ($data_service->getServiceCatName()) {
case "Accommodation":
$contcolor = 'teal';
break;
case "Menu":
$contcolor = 'purple';
break;
case "Lounge":
$contcolor = 'warning';
break;
case "Activities":
$contcolor = 'blue';
break;
case "Itineraries":
$contcolor = 'indigo';
break;
case "Cruise":
$contcolor = 'brown';
break;
case "Transport":
$contcolor = 'grey';
break;
case "Av":
$contcolor = 'slate';
break;
case "Creative":
$contcolor = 'orange';
break;
case "Gifts":
$contcolor = 'pink';
break;
case "Entertainment":
$contcolor = 'green';
break;
case "Guide":
$contcolor = 'orange';
break;
case "Others":
$contcolor = 'danger';
break;
case "Technology":
$contcolor = 'grey-800';
break;
case "Assistant":
$contcolor = 'indigo-800';
break;
case "DDR":
$contcolor = 'green-300';
break;
}
$idcat = $data_service->getServiceCatId();
$price = $data_service->getPrice();
$units = $data_service->getUnits();
$pax = $data_service->getPax();
$opcommission = $data_service->getOpCommission();
$commission = $data_service->getCommission();
$opover = $data_service->getOpOver();
$over = $data_service->getOver();
$opiva = $data_service->getOpIva();
$iva = $data_service->getIva();
$dateInAt = $data_service->getDateInAt();
$dateOutAt = $data_service->getDateOutAt();
if (!is_null($dateInAt) and !is_null($dateOutAt)) {
$days = $dateInAt->diff($dateOutAt);
$day = $days->days;
} else {
$day = "0";
}
$directPayment = $data_service->getDirectPayment();
$calculos = $this->CalculoTotalesservices($price, $units, $pax, $day, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat);
$data_service->setPrice($calculos['precio']); //ojo aqui
/*CONTROL GENERAL*/
$controlgeneral = $em->getRepository(SupplierIdeaServicesControl::class)->findOneBySupplierId($data_service->getSupplierId());
$data_service->setPrice($calculos['precio']); //ojo aqui
$service_supplier_data[$data_service->getServiceCatName()][] = array(
// 'idcat' => $idcat,
'calculos' => $calculos,
'services_data' => $data_service,
// 'controlGeneralId' => $controlgeneral->getId(),
'contcolor' => $contcolor,
// 'servicesSub' =>$service_supplier_data_sub
);
if ($data_service->getBreakdown() == false) {
$totales_neto += $calculos['total_neto'];
$totales_iva += $calculos['sub_total_iva'];
$totales_con_iva += $calculos['total'];
$totales_paying += $calculos['total_paying'];
$totales_pago += $calculos['total_pago'];
$totales_benefit_moneda += $calculos['benefit_moneda'];
} else {
$totales_neto += $totales_neto_sub;
$totales_iva += $totales_iva_sub;
$totales_con_iva += $totales_con_iva_sub;
$totales_paying += $totales_paying_sub;
$totales_pago += $totales_pago_sub;
$totales_benefit_moneda += $totales_benefit_moneda_sub;
}
// $totales_neto += $calculos['total_neto'];
// $totales_iva += $calculos['sub_total_iva'];
// $totales_con_iva += $calculos['total'];
// $totales_paying += $calculos['total_paying'];
// $totales_pago += $calculos['total_pago'];
// $totales_benefit_moneda += $calculos['benefit_moneda'];
if ($totales_benefit_moneda == '0') {
$totales_benefit_porsentaje = '0';
} else {
// $totales_benefit_porsentaje = $totales_benefit_moneda * 100 / $totales_neto;
if ($totales_pago != 0) {
$totales_benefit_porsentaje = $totales_benefit_moneda * 100 / $totales_pago;
} else {
$totales_benefit_porsentaje = 0;
}
}
}
$calculos_totatales = array(
'totales_neto' => $totales_neto,
'totales_iva' => $totales_iva,
'totales_con_iva' => $totales_con_iva,
'totales_paying' => $totales_paying,
'totales_benefit_moneda' => $totales_benefit_moneda,
'totales_benefit_porsentaje' => $totales_benefit_porsentaje
);
if ($master == "company") {
$typeMaster = $sqlcompany->getCompany();
}
if ($master == "supplier") {
$typeMaster = $sqlsuppliers->getType();
}
if ($master == "activity") {
$typeMaster = "Activity";
}
if ($master == "idea") {
$typeMaster = "Idea";
}
$data_supplier[$destination->getTitle()][$typeMaster][] = array(
'colorlabel' => $colorlabel,
'control' => $suppliercontrol,
'master' => $master,
'supplier' => $sqlsuppliers,
'idea' => $sqlideas,
'activity' => $sqlactivities,
'company' => $sqlcompany,
'image' => $imagenSmall,
'services' => $service_supplier_data,
'totales_services' => $calculos_totatales
);
}
}
}
$controlbudgets = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findByProposalId($id);
$controlbudget = array();
// $i = 0;
foreach ($controlbudgets as $controlbudge) {
// $controlbudget[$controlbudge->getRecommended()][] = $controlbudge;
$presupuesto['byclient'] = $controlbudge->getByClient();
$presupuesto['id'] = $controlbudge->getId();
$presupuesto['name'] = $controlbudge->getName();
$presupuesto['priority'] = $controlbudge->getPriority();
$presupuesto['proposalId'] = $controlbudge->getProposalId();
$presupuesto['recommended'] = $controlbudge->getRecommended();
$presupuesto['status'] = $controlbudge->getStatus();
$hasDiary = $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
array(
'proposalId' => $controlbudge->getProposalId(),
'controlId' => $controlbudge->getId(),
)
);
if ($hasDiary) {
$presupuesto['hasDiary'] = true;
} else {
$presupuesto['hasDiary'] = false;
}
$controlbudget[$controlbudge->getRecommended()][] = $presupuesto;
}
$today = new \DateTime("now");
return $this->render(
'MDS/EventsBundle/budget/services-makeyourbudget-proposal.html.twig',
array(
'id' => $id,
'today' => $today,
'token' => $proposal->getAccessKey(),
'mcp' => $proposal->getMcp(),
'datasupplier' => $data_supplier,
'budgets' => $controlbudget
)
);
}
/**
* @Route("/proposal/makeyourbudget/budget/confirm/{id}/{idcontrol}", name="proposal_destination_supplier_makeyourbudget_confirm")
*/
public function MakeYourBudgetConfirmSupplierAction($id, $idcontrol, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneById($id);
// Envio correo a administracion en caso que de cambie el estatus y este como no enviado
if ($proposal->getSendAdmin() != "yes") {
$time = new \DateTime("now");
$agent = $em->getRepository(User::class)->findOneById($proposal->getAgentId());
if (is_null($agent)) {
$event = 'The Budget has no agents.';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajeproposalbudgetserviceserror', $successMessage);
return $this->redirectToRoute(
'proposal_destination_supplier_makeyourbudget',
array(
'id' => $id
)
);
}
$mailAgent[] = $agent->getEmail();
$agentMail = $agent->getEmail();
$passGmail = $agent->getPassGmail();
$firmGmail = $agent->getFirmGmail();
$mailAgentSent = array(
$agent->getEmail() => $agent->getName() . ' ' . $agent->getLastName()
);
$setting_rol = $em->getRepository(SettingsRol::class)->findBy(
array(
'weight' => array('2', '3'),
'madmin' => '1',
)
);
foreach ($setting_rol as $settingRol) {
$administration = $em->getRepository(User::class)->findByUserrol($settingRol->getId());
foreach ($administration as $admin) {
$mailAdmin[] = $admin->getEmail();
}
}
$data = array(
'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>',
'firm' => $firmGmail,
);
$mailTodos = array_merge($mailAgent, $mailAdmin);
if (!is_null($passGmail) and (!empty($passGmail))) {
// EJECUTAR ENVIO DE ALERTA DE VISTO POR CLIENTE
$transporter = new Swift_SmtpTransport();
$transporter->setHost('smtp.gmail.com')
->setEncryption('ssl') //ssl / tls
->setPort(465) // 465 / 587
->setUsername('desarrollo@develup.solutions')
->setPassword('utvh hzoi wfdo ztjs');
$mailer = new Swift_Mailer($transporter);
$message = new Swift_Message();
$message->setSubject('P#' . $proposal->getId() . ', Alerta de Proposal Confirmado')
->setSender($agentMail)
->setFrom($mailAgentSent)
->setReplyTo($mailAgentSent)
->setTo($mailTodos)
->setBody(
$this->renderView(
'mail/structure-mail.html.twig',
array('data' => $data)
),
'text/html'
);
$mailer->send($message);
$proposal->setSendAdmin('yes');
}
}
if (($proposal->getStatus() != "Invoiced") and ($proposal->getStatus() != "Unblocked")) {
$proposal->setStatus('Confirmed');
}
$controlbudget = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
$controlbudget->setStatus('Confirmed');
$nameBudget = empty($controlbudget) ? '(Presupuesto sin nombre)' : $controlbudget->getName();
$budgets = $em->getRepository(ProposalSupplierServicesBudget::class)->findByControlId($idcontrol);
$montoMsj = 0;
foreach ($budgets as $budget) {
$services = $em->getRepository(ProposalSupplierServices::class)->findOneById($budget->getItemsserviceId());
$montoMsj = $montoMsj + $budget->getTotal();
$services->setStatus('Confirmed');
$em->persist($services);
$services_father = $em->getRepository(ProposalSupplierServices::class)->findByServiceIdFather($budget->getItemsserviceId());
foreach ($services_father as $servicesfather) {
$servicesfather->setStatus('Confirmed');
$em->persist($servicesfather);
}
$budget->setStatus('Confirmed');
$em->persist($budget);
$budgets_sub = $em->getRepository(ProposalSupplierServicesBudget::class)->findBy(
array(
'controlId' => $idcontrol,
'itemsserviceIdFather' => $budget->getItemsServiceId(),
)
);
if (!empty($budgets_sub)) {
foreach ($budgets_sub as $budgetssub) {
$budgetssub->setStatus('Confirmed');
$em->persist($budgetssub);
}
}
}
$em->persist($controlbudget);
$em->persist($proposal);
$em->flush();
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// Usuario Anonimo es = "anon."
if($user_logueado == "anon."){ $user_id = '0'; } else { $user_id = $user_logueado->getId(); }
// Notificamos al agente y a Rafa lo que se ha confirmado
$this->notifyBudgetConfirmation($montoMsj, $proposal->getId(), $user_id, $nameBudget);
return $this->redirectToRoute(
'proposal_destination_supplier_makeyourbudget_view',
array(
'id' => $id,
// 'token' => $proposal->getAccessKey(),
'idcontrol' => $idcontrol,
)
);
}
public function CalculoTotalesservices($price, $units, $pax, $days, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat)
{
$price = trim($price);
$over = trim($over);
$price = str_replace(",", ".", $price);
$over = str_replace(",", ".", $over);
if (empty($price)) {
$price = 0;
}
if (empty($commission)) {
$commission = 0;
}
if (empty($iva)) {
$iva = 0;
}
$iva = $iva / 100;
if ($opiva == '0') {
$price = $price / ($iva + 1);
}
if (!empty($commission)) {
if ($opcommission == '0') {
$commission = (100 - $commission) / 100;
$precio_units = $price;
$price = $price * $commission;
}
if ($opcommission == '1') {
$commission = ($commission / 100) + 1;
$precio_units = $price * $commission;
}
} else {
$precio_units = $price;
}
//Units
if (empty($units) or $units == "0") {
$units = "1";
}
// Calculo Especial por categoria
//Alojamientos
if ($idcat == "1") {
$informativo_days = "si";
$pax = "1";
}
//Transporte
elseif ($idcat == "13") {
$informativo_days = "no";
$pax = "1";
// if($days > "1"){
// $days = "2";
// }else{
// $days = "1";
// }
}
//Lounge
elseif ($idcat == "10") {
$informativo_days = "no";
$pax = "1";
}
//Guia
elseif ($idcat == "8") {
$informativo_days = "no";
$pax = "1";
} else {
$informativo_days = "no";
}
//Pax
if (empty($pax) or $pax == "0") {
$pax = "1";
}
//Over
if (empty($over)) {
$over = "0";
}
if ($informativo_days == "no") {
//Days
if (empty($days) or $days == "0") {
$days = "1";
} else {
$days = $days + 1;
}
}
$total_items = $price * $units * $pax * $days;
// $total_pdirect = $price * $units * $pax * $days;
$total_over = $over * $units * $pax * $days;
if (!empty($commission)) {
if ($opcommission == '0') {
$total_neto = $total_items / $commission;
}
if ($opcommission == '1') {
$total_neto = $total_items * $commission;
}
} else {
$total_neto = $total_items;
}
if ($opover == '0') {
$total_neto = $total_neto - $total_over;
$precio_units = $precio_units - $over;
}
if ($opover == '1') {
$total_neto = $total_neto + $total_over;
$precio_units = $precio_units + $over;
}
$total_paying = $total_items * ($iva + 1);
if ($directPayment == true) {
$total_neto = $total_neto - $total_paying;
}
$total_comision = "0";
$total_pago = $total_items;
$total_iva = $total_items * $iva;
$sub_total_iva = $total_neto * $iva;
$total = $total_neto + $sub_total_iva;
if ($directPayment == true) {
$benefit_moneda = $total_neto;
$total_paying = "0";
} else {
$benefit_moneda = $total_neto - $total_items;
}
$data_calculos = array(
'precio' => $precio_units,
'total_days' => $days,
'sub_total' => $total_items,
'sub_total_iva' => $sub_total_iva,
'total_neto' => $total_neto,
'total_iva' => $total_iva,
'total_paying' => $total_paying,
'total_pago' => $total_pago,
'total_comision' => $total_comision,
'total' => $total,
'benefit_moneda' => $benefit_moneda,
'commission' => $commission,
// 'commission_1' => $commission_1,
'units' => $units,
'pax' => $pax,
'over' => $over,
);
// d($data_calculos);
return $data_calculos;
}
// public function CalculoTotalesservices($price, $units, $pax, $days, $opcommission, $commission, $opover, $over, $opiva, $iva, $directPayment, $idcat)
// {
//
// $iva = $iva / 100;
//
// if($opiva =='0'){
// $price = $price / ($iva + 1);
// }
//// if($opiva =='1'){
////
//// }
// $commission_1 = $commission / 100 + 1;
// $commission = (100 - $commission) / 100;
// if($opcommission=='0'){
// $precio_units = $price;
// $price = $price * $commission;
// }
//
// if($opcommission=='1'){
// $precio_units = $price * $commission_1;
// }
//
// //Units
// if(empty($units) or $units =="0"){
//// d('entre');
// $units = "1";
// }
//
// // Calculo Especial por categoria
// //Alojamientos
// if($idcat =="1"){
// $informativo_days = "si";
// $pax = "1";
// }
// //Transporte
// elseif($idcat =="13"){
// $informativo_days = "no";
// $pax = "1";
//// if($days > "1"){
//// $days = "2";
//// }else{
//// $days = "1";
//// }
// }
// //Lounge
// elseif($idcat =="10"){
// $informativo_days = "no";
// $pax = "1";
// }
// //Guia
// elseif($idcat =="8"){
// $informativo_days = "no";
// $pax = "1";
// }else{
// $informativo_days = "no";
// }
//
//
// //Pax
// if(empty($pax) or $pax =="0"){
// $pax = "1";
// }
//
// //Over
// if(empty($over)){
// $over = "0";
// }
//
// if($informativo_days =="no"){
// //Days
// if(empty($days) or $days =="0"){
// $days = "1";
// }else{
// $days = $days + 1 ;
// }
// }
//
// $total_items = $price * $units * $pax * $days;
// $total_pdirect = $price * $units * $pax * $days;
//
// $total_over = $over * $units * $pax * $days;
//
// if($opover=='0'){
//// $total_neto = $total_items * ($commission + 1) - $total_over ;
//// $total_neto = $total_items / 0.9 - $total_over ;
//// $total_neto = $total_items / $commission - $total_over ;
// $total_neto = $total_items / $commission - $total_over ;
// $precio_units = $precio_units - $over;
// }
//
// if($opover=='1'){
//// $total_neto = $total_items * ($commission + 1) + $total_over;
//// $total_neto = $total_items / 0.9 + $total_over;
//// $total_neto = $total_items / $commission + $total_over;
// $total_neto = $total_items * $commission_1 + $total_over ;
// $precio_units = $precio_units + $over;
// }
//
// $total_paying = $total_items * ($iva + 1);
//
// if ($directPayment == true){
// $total_neto = $total_neto - $total_paying;
// }
//
// $total_comision ="0";
// $total_pago = $total_items;
// $total_iva = $total_items * $iva;
// $sub_total_iva = $total_neto * $iva;
//
// $total = $total_neto + $sub_total_iva;
//
// if ($directPayment == true){
// $benefit_moneda = $total_neto;
// $total_paying = "0";
// }else{
// $benefit_moneda = $total_neto - $total_items;
// }
//
// $data_calculos = array(
// 'precio' => $precio_units,
// 'total_days' => $days,
// 'sub_total' => $total_items,
// 'sub_total_iva' => $sub_total_iva,
// 'total_neto' => $total_neto,
// 'total_iva' => $total_iva,
// 'total_paying' => $total_paying,
// 'total_pago' => $total_pago,
// 'total_comision' => $total_comision,
// 'total' => $total,
// 'benefit_moneda' => $benefit_moneda,
//
// 'commission' => $commission,
// 'commission_1' => $commission_1,
// 'units' => $units,
// 'pax' => $pax,
// 'over' => $over,
// );
// d($data_calculos);
// return $data_calculos;
// }
/**
* @Route("/proposal/makeyourbudget/budget/deleted/{id}/{idcontrol}", name="proposal_destination_supplier_makeyourbudget_deleted")
*
*/
// public function deleteAction($id, Request $request, LoggerInterface $logger)
public function deleteAction($id, $idcontrol, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proposal = $em->getRepository(Proposal::class)->findOneById($id);
$delete = $em->getRepository(ProposalSupplierServicesBudgetControl::class)->findOneById($idcontrol);
$delete_services = $em->getRepository(ProposalSupplierServicesBudget::class)->findByControlId($idcontrol);
foreach ($delete_services as $delete_service) {
$em->remove($delete_service);
}
$delete_diary = $em->getRepository('EventsBundle:ProposalAgendaPresupuesto')->findBy(
array(
'proposalId' => $id,
'controlId' => $idcontrol,
)
);
$delete_diary_comment = $em->getRepository(ProposalAgendaPresupuestoControl::class)->findBy(
array(
'proposalId' => $id,
'controlId' => $idcontrol,
)
);
if ($delete_diary) {
foreach ($delete_diary as $diary_services) {
$em->remove($diary_services);
}
}
if ($delete_diary_comment) {
foreach ($delete_diary_comment as $diary_comment) {
$em->remove($diary_comment);
}
}
$em->remove($delete);
$em->flush();
$event = 'The Budget the has been Deleted.';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajeproposalbudgetservices', $successMessage);
// /* Gestión de eventos en Log */
// /* Obtengo usuario logueado */
// $user_logueado = $this->get('security.token_storage')->getToken()->getUser();
// $user_lastname = $user_logueado->getLastname();
// $user_name = $user_logueado->getName();
// $user_email = $user_logueado->getEmail();
// $user_rol = $user_logueado->getRoles();
// $event_url = $request->getPathInfo();
// $event_complete = $user_name.' '.$user_lastname.' - '.$user_email.' - '.$user_rol[0].' | '.$event_url;
//
// try{
// $em->remove($delete);
// $em->flush();
//
// $event = 'The supplier services Accommodation has been Deleted.';
// $successMessage = $this->translator->trans($event);
// $this->addFlash('mensajeservices', $successMessage);
//
// $logger->info($event_complete.' | '.$event);
//
// } catch (\Exception $e){
//
// $event = 'An error occurred: '.$e->getMessage().' | transport';
//
// /* Para el log */
// $logger->error($event_complete.' | '.$event);
// /* Para el usuario */
// $errorMessage = $this->translator->trans($event);
// $this->addFlash('mensajeserviceserror', $errorMessage);
// }
// /* Fin Gestión de eventos en Log */
return $this->redirectToRoute(
'proposal_destination_supplier_makeyourbudget',
array(
'id' => $id,
// 'token' => $proposal->getAccessKey(),
)
);
}
private function notifyBudgetConfirmation( $monto, $idProp, $idUser, $nameBudget ){
// Se envia una notificación vía correo electronico al agente y a Rafa sobre la confirmacion del presupuesto
// $monto (cuanto se confirma con IVA incluido), $idProp id del proposal, $idUser id del usuario
$em = $this->getDoctrine()->getManager();
$mailArrayTo = array();
// Quien confirmo sera notificado
$mailArrayTo['rafael.guerrero@inout-travel.com'] = 'rafael.guerrero@inout-travel.com';
$agentWhoConfirm = ($idUser == 0) ? null : $em->getRepository(User::class)->findOneById($idUser);
if (!empty($agentWhoConfirm)){ $agentWhoConfirmMail = $agentWhoConfirm->getEmail(); }
if (!empty($agentWhoConfirm)){ $mailArrayTo[$agentWhoConfirmMail] = $agentWhoConfirmMail; }
// Buscamos los agentes del proposal
$agents = $em->getRepository(ProposalAgents::class)->findOneByIdProp($idProp);
if (!empty($agents)){
if ( !(empty($agents->getAgOne()) or ($agents->getAgOne() == 0)) ){
$agent = $em->getRepository(User::class)->findOneById($agents->getAgOne());
$mailArrayTo[$agent->getEmail()] = $agent->getEmail();
}
if ( !(empty($agents->getAgTwo()) or ($agents->getAgTwo() == 0)) ){
$agent = $em->getRepository(User::class)->findOneById($agents->getAgTwo());
$mailArrayTo[$agent->getEmail()] = $agent->getEmail();
}
if ( !(empty($agents->getAgThree()) or ($agents->getAgThree() == 0)) ){
$agent = $em->getRepository(User::class)->findOneById($agents->getAgThree());
$mailArrayTo[$agent->getEmail()] = $agent->getEmail();
}
if ( !(empty($agents->getAgFour()) or ($agents->getAgFour() == 0)) ){
$agent = $em->getRepository(User::class)->findOneById($agents->getAgFour());
$mailArrayTo[$agent->getEmail()] = $agent->getEmail();
}
}
$proposal = $em->getRepository(Proposal::class)->findOneById($idProp);
$fecha = ($proposal->getDateEventStarAt())->format('d/m/Y');
$agentWhoConfirm = empty($agentWhoConfirm) ? 'el cliente.' : 'el agente ( '. $agentWhoConfirm->getName().' '. $agentWhoConfirm->getLastName().' ).';
$mailSubject = 'Presupuesto Confirmado. Proposal: '.$idProp.' de '.$monto.'€ '.', por '.$agentWhoConfirm.' Fecha de inicio: '.$fecha;
$mailBody = '<p>Presupuesto Confirmado. Proposal: '.$idProp.' de '.$monto.'€ (IVA incluido)'.', por '.$agentWhoConfirm.' Fecha de inicio: '.$fecha.'</p>';
$mailBody = $mailBody .'<br><br><p>Presupuesto: '.$nameBudget.'</p>';
$mailBody = $mailBody .'<br><p>Ver el proposal: <a href="//'.$_SERVER['HTTP_HOST'].'/events/proposal/edit/'.$idProp.'">'.$idProp.'</a> </p>';
$replyTo = $mailArrayTo;
$agentMail = 'desarrollo@develup.solutions';
$mailAgent = $agentMail;
//Se prepara el correo con los agentes a notificar
// $firmGmail = $agent->getFirmGmail();
$data = array(
'body' => $mailBody,
// 'firm' => $firmGmail,
);
// EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
$transporter = new Swift_SmtpTransport();
$transporter->setHost('smtp.gmail.com')
->setEncryption('ssl')//ssl / tls
->setPort(465)// 465 / 587
->setUsername('desarrollo@develup.solutions')
->setPassword('utvh hzoi wfdo ztjs');
$mailer = new Swift_Mailer($transporter);
$message = new Swift_Message();
$message->setSubject($mailSubject)
->setSender($agentMail)
->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
->setReplyTo($agentMail)
->setTo($replyTo)
->setBody(
$this->renderView(
'mail/structure-mail.html.twig',
array('data' => $data)
),
'text/html'
);
$mailer->send($message);
return true;
}
}