<?php
/**
* Created by PhpStorm.
* Date: 19/06/2025
* Time: 14:49
*/
namespace App\MDS\GreenPatioBundle\Controller;
use App\Entity\Cities;
use App\Entity\Client;
use App\Entity\Country;
use App\Entity\Regions;
use App\Entity\SettingsCompany;
use App\Entity\Supplier;
use App\MDS\GreenPatioBundle\Entity\ReservationBudgetItems;
use App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceItems;
use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceProformaItems;
use App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceRecItems;
use App\MDS\GreenPatioBundle\Entity\ReservationPaymentsClient;
use App\MDS\GreenPatioBundle\Entity\ReservationProforma;
use App\MDS\GreenPatioBundle\Entity\BlvReservationInvoice;
use App\MDS\GreenPatioBundle\Entity\BlvReservationInvoiceRec;
use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceDepositControl;
use App\MDS\GreenPatioBundle\Entity\Reservation;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceDepositItems;
use App\MDS\GreenPatioBundle\Entity\ReservationLoungeSimple;
use App\MDS\GreenPatioBundle\Entity\ReservationService;
use DateTime;
use PHPExcel_Style_Fill;
use PHPExcel_Style_NumberFormat;
use PHPExcel_Style_Alignment;
use PHPExcel_Shared_Font;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use FOS\RestBundle\Controller\Annotations as Rest;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
class BlvReservationsInvoiceController extends AbstractController
{
/**
* @Route("/blv/reservations/invoice/generatenew", name="reservations_generatenew_invoice_blv")
* Generar una nueva factura Bella View
*/
public function generatenewInvoiceAction(EntityManagerInterface $em, Request $request)
{
// Se genera y muestra en nueva pantalla la nueva proforma
$arrayBools = array( 'lounge' => null, 'service' => null, 'payment' => null, );
$arrayBools['lounge'] = $request->query->get('lounge');
$arrayBools['service'] = $request->query->get('service');
$arrayBools['payment'] = $request->query->get('payment');
$clientName = $request->query->get('clientName');
$clientAddress = $request->query->get('clientAddress');
$clientDocument = $request->query->get('clientDocument');
$clientType = $request->query->get('clientType');
$id = $request->query->get('id');
//INICIO: buscamos el ID de la factura
$allFacturas = $em->getRepository(BlvReservationInvoice::class)->findAll();
if (!empty($allFacturas)){ $invoiceId = end($allFacturas)->getId() + 1; } else { $invoiceId = 100; }
$boolMakeInvoice = false; // Control para verificar si se debe hacer factura o todos los indicadores (sala, servicios y pagos) estaban en falso
//FIN: buscamos el ID de la factura
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
//Acumuladores de datos globales de la factura
$valorTotalNet = 0; $valorVat = 0;
//INICIO: Creamos los items de la factura
if (!empty($arrayBools['lounge'])) {
foreach ($arrayBools['lounge'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$sala = $em->getRepository(ReservationLoungeSimple::class)->findOneById($key);
$itemInvoice = new BlvReservationInvoiceItems();
$itemInvoice->setReservationId($id);
$itemInvoice->setInvoiceId($invoiceId);
$itemInvoice->setItemType('LOUNGE');
$itemInvoice->setLngControlId($key);
$itemInvoice->setLngLoungeName($sala->getLoungeName());
$itemInvoice->setLngIdLounge($sala->getIdLounge());
$itemInvoice->setLngIdLounge($sala->getIdLounge());
$itemInvoice->setLngDateStart($sala->getDateStart());
$itemInvoice->setLngDateEnd($sala->getDateEnd());
$itemInvoice->setLngServicePrice($sala->getServicePrice());
$itemInvoice->setLngPax($sala->getPax());
$itemInvoice->setLngType($sala->getType());
$itemInvoice->setLngIva($sala->getIva());
$itemInvoice->setLngOpIva($sala->getOpIva());
$itemInvoice->setCreatedId($user_id);
$itemInvoice->setCreatedAt(new DateTime('now'));
$itemInvoice->setUpdatedId($user_id);
$itemInvoice->setUpdatedAt(new DateTime('now'));
$itemInvoice->setLngHourStart($sala->getHourStart());
$itemInvoice->setLngMinStart($sala->getMinStart());
$itemInvoice->setLngHourEnd($sala->getHourEnd());
$itemInvoice->setLngMinEnd($sala->getMinEnd());
$em->persist($itemInvoice);
$em->flush();
//Acumulamos neto e iva para la factura
$valorTotalNet += $itemInvoice->getLngServicePrice();
$valorVat += round(($itemInvoice->getLngServicePrice() * ($itemInvoice->getLngIva() / 100)),2,PHP_ROUND_HALF_UP);
}
}
}
if (!empty($arrayBools['service'])) {
foreach ($arrayBools['service'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$servicio = $em->getRepository(ReservationService::class)->findOneById($key);
$itemInvoice = new BlvReservationInvoiceItems();
$itemInvoice->setReservationId($id);
$itemInvoice->setInvoiceId($invoiceId);
$itemInvoice->setItemType('SERVICE');
$itemInvoice->setSrvControlId($key);
$itemInvoice->setSrvName($servicio->getName());
$itemInvoice->setSrvSupplierId($servicio->getSupplierId());
$itemInvoice->setSrvServiceId($servicio->getServiceId());
$itemInvoice->setSrvServiceCatId($servicio->getServiceCatId());
$itemInvoice->setSrvServiceCatName($servicio->getServiceCatName());
$itemInvoice->setSrvPrice($servicio->getPrice());
$itemInvoice->setSrvCurrency($servicio->getCurrency());
$itemInvoice->setSrvUnits($servicio->getUnits());
$itemInvoice->setSrvOpCommission($servicio->getOpCommission());
$itemInvoice->setSrvCommission($servicio->getCommission());
$itemInvoice->setSrvOpOver($servicio->getOpOver());
$itemInvoice->setSrvOver($servicio->getOver());
$itemInvoice->setSrvOpIva($servicio->getOpIva());
$itemInvoice->setSrvIva($servicio->getIva());
$itemInvoice->setSrvPax($servicio->getPax());
$itemInvoice->setSrvHour($servicio->getHour());
$itemInvoice->setSrvDateInAt($servicio->getDateInAt());
$itemInvoice->setSrvDateOutAt($servicio->getDateOutAt());
$itemInvoice->setSrvContcolor($servicio->getContcolor());
$itemInvoice->setSrvRank($servicio->getRank());
$itemInvoice->setSrvAssistantId($servicio->getAssistantId());
$itemInvoice->setSrvActivityId($servicio->getActivityId());
$itemInvoice->setSrvPay($servicio->getPay());
$itemInvoice->setCreatedAt(new DateTime('now'));
$itemInvoice->setUpdatedAt(new DateTime('now'));
$itemInvoice->setCreatedId($user_id);
$itemInvoice->setUpdatedId($user_id);
$em->persist($itemInvoice);
$em->flush();
//Acumulamos neto e iva para la factura
if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())){
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $itemInvoice->getSrvPrice();
$subneto = $itemInvoice->getSrvPrice();
// Commission
if ($itemInvoice->getSrvOpCommission()=='1'){
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvCommission()/100));
$subneto = $subneto * (1 + ($itemInvoice->getSrvCommission()/100));
} else {
$subtotalService = $subtotalService * (1 - ($itemInvoice->getSrvCommission()/100));
$subneto = $subneto * (1 - ($itemInvoice->getSrvCommission()/100));
}
// Over
if ($itemInvoice->getSrvOpOver()=='1'){
$subtotalService = $subtotalService + $itemInvoice->getSrvOver();
$subneto = $subneto + $itemInvoice->getSrvOver();
} else {
$subtotalService = $subtotalService - $itemInvoice->getSrvOver();
$subneto = $subneto - $itemInvoice->getSrvOver();
}
// IVA
if ($itemInvoice->getSrvOpIva()=='1'){
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvIva()/100));
} else {
$subtotalService = $itemInvoice->getSrvPrice();
$subneto = ($subneto * 100) / (100 + $itemInvoice->getSrvIva());
}
switch ($itemInvoice->getSrvServiceCatId()){
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $itemInvoice->getSrvUnits();
break;
case 2: //Actividades
// El número de personas es considerado en el calculo
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$subtotal = $subtotalService * $days * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $itemInvoice->getSrvUnits();
break;
case 3: // AV
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 4: //Creative
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 5: //Cruise
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 6: //Entertaiment
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 7: // Gifts
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 8: //Guide
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 9: //Itineraries
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 10: //Lounge -- No Aplica
break;
case 11: //Menu (Catering)
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 12: //Others
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 13: //Transport
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 14: //Technology
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 15: //Assisstant
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 16: //DDR
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 17: //Seguridad
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 18: //WiFi
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 19: //Mobiliario
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 20: //Parking
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 21: //Limpieza
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
default: //Others (por default)
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($subneto,2,PHP_ROUND_HALF_UP);
$valorTotalNet = $valorTotalNet + $neto;
$valorVat = $valorVat + ($subtotal - $neto);
}
}
}
}
if (!empty($arrayBools['payment'])) {
foreach ($arrayBools['payment'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
$itemInvoice = new BlvReservationInvoiceItems();
$itemInvoice->setReservationId($id);
$itemInvoice->setInvoiceId($invoiceId);
$itemInvoice->setItemType('PAYMENT');
$itemInvoice->setPayControlId($key);
$itemInvoice->setPayAmount($pago->getAmount());
$itemInvoice->setPayVat($pago->getVat());
$itemInvoice->setPayAmountTotal($pago->getAmountTotal());
$itemInvoice->setPayDatePayAt($pago->getDatePayAt());
$itemInvoice->setPayWayToPay($pago->getWayToPay());
$itemInvoice->setCreatedAt(new DateTime('now'));
$itemInvoice->setUpdatedAt(new DateTime('now'));
$itemInvoice->setCreatedId($user_id);
$itemInvoice->setUpdatedId($user_id);
$em->persist($itemInvoice);
$em->flush();
//Acumulamos neto e iva para la factura
//$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount(); // El pago no puede afectar el neto de la factura
$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount();
$valorVat = $valorVat - round(($itemInvoice->getPayAmount() * ($itemInvoice->getPayVat()/100)),2,PHP_ROUND_HALF_UP);
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la factura
$newInvoice = new BlvReservationInvoice();
$newInvoice->setNumber("LGD-".date('dmy')."-".$id);
$newInvoice->setDateAt(new DateTime('now'));
$newInvoice->setType('Invoice');
$newInvoice->setReservationId($id);
$newInvoice->setTotalNet($valorTotalNet);
$newInvoice->setVat($valorVat);
$newInvoice->setTotal($valorTotal);
$newInvoice->setCreatedAt(new DateTime('now'));
$newInvoice->setCreatedId($user_id);
$newInvoice->setUpdatedAt(new DateTime('now'));
$newInvoice->setUpdatedId($user_id);
$newInvoice->setMaster('master');
$newInvoice->setClientName($clientName);
$newInvoice->setClientAddress($clientAddress);
$newInvoice->setClientDocument($clientDocument);
$newInvoice->setClientType($clientType);
if ($boolMakeInvoice){
// Solo se debe crear factura si hay un elemento
$em->persist($newInvoice);
$em->flush();
$newInvoice->setNumber($newInvoice->getNumber().'-'.$newInvoice->getId());
$em->persist($newInvoice);
$em->flush();
} else {
// Se llama a la vista de facturas del expediente
return $this->redirectToRoute('reservations_viewreservation_invoices',array('id' => $id));
}
//FIN: Creamos la factura
$data = [];
$data = $this->baseInvoiceSelectedReservation($id, $arrayBools,'I'.$newInvoice->getId());
$paymentsClient = new ReservationPaymentsClient();
$paymentsClient->setReservationId($id);
$reserva = $em->getRepository(Reservation::class)->findOneById($id);
if ($boolMakeInvoice){
// Si se creo la factura se cambia el estado de la reserva a Facturado
$reserva->setStatus('Invoiced');
$em->persist($reserva);
$em->flush();
}
$reservaInv = new BlvReservationInvoice();
$reservaInv->setReservationId($id);
$idLounges = [];
$loungesBoolToInvoice = [];
if (array_key_exists('lounge',$data['datasupplier'])) {
foreach ($data['datasupplier']['lounge'] as $item) {
$idLounges[] = $item['id'];
$loungesBoolToInvoice[] = 1;
}
$idLounges = implode(',', $idLounges);
$loungesBoolToInvoice = implode(',', $loungesBoolToInvoice);
} else {
$idLounges = '0';
$loungesBoolToInvoice = '0';
}
$idPayments = [];
$paymentsBoolToInvoice = [];
if (array_key_exists('payment',$data['datasupplier'])) {
foreach ($data['datasupplier']['payment'] as $item) {
$idPayments[] = $item['id'];
$paymentsBoolToInvoice[] = 1;
}
$idPayments = implode(',', $idPayments);
$paymentsBoolToInvoice = implode(',', $paymentsBoolToInvoice);
} else {
$idPayments = '0';
$paymentsBoolToInvoice = '0';
}
if(empty($data['type'])){$data['type'] = 'Invoice';}
return $this->redirectToRoute('reservations_viewnew_invoice_blv',array('id' => $newInvoice->getId()));
}
/**
* @Route("/blv/reservations/invoice/viewnew/{id}", name="reservations_viewnew_invoice_blv")
* Ver factura Bella View
*/
public function viewNewInvoiceAction($id, EntityManagerInterface $em, Request $request)
{
// Se genera y muestra en nueva pantalla la nueva proforma
$arrayBools = array( 'lounge' => null, 'service' => null, 'payment' => null, );
$arrayBools['lounge'] = $request->request->get('inv_lounge_hidden_bool');
$arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
$arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
//Acumuladores de datos globales de la factura
$valorTotalNet = 0;
$valorVat = 0;
//INICIO: Creamos los items de la factura
$arrayInvoicedItems = $em->getRepository(BlvReservationInvoiceItems::class)->findByInvoiceId($id);
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'LOUNGE') {
//Acumulamos neto e iva para la factura
$valorTotalNet = $valorTotalNet + $itemInvoice->getLngServicePrice();
$valorVat = $valorVat + round(($itemInvoice->getLngServicePrice() * ($itemInvoice->getLngIva() / 100)),2,PHP_ROUND_HALF_UP);
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'SERVICE') {
//Acumulamos neto e iva para la factura
if (is_null($itemInvoice->getSrvPrice())){
$subtotal = $neto = $subtotalService = 0;
} else {
$subtotalService = $itemInvoice->getSrvPrice();
$subtotalService = str_replace(',','.',$subtotalService);
$subtotalService = floatval($subtotalService);
$subneto = $itemInvoice->getSrvPrice();
// Commission
if ($itemInvoice->getSrvOpCommission()=='1'){
if (!($itemInvoice->getSrvCommission()=='0')) {
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvCommission() / 100));
$subneto = $subneto * (1 + ($itemInvoice->getSrvCommission() / 100));
}
} else {
$subtotalService = $subtotalService * (1 - ($itemInvoice->getSrvCommission()/100));
$subneto = $subneto * (1 - ($itemInvoice->getSrvCommission()/100));
}
// Over
if ($itemInvoice->getSrvOpOver()=='1'){
if (!($itemInvoice->getSrvOver()=='0')) {
$subtotalService = $subtotalService + $itemInvoice->getSrvOver();
$subneto = $subneto + $itemInvoice->getSrvOver();
}
} else {
$subtotalService = $subtotalService - $itemInvoice->getSrvOver();
$subneto = $subneto - $itemInvoice->getSrvOver();
}
// IVA
if ($itemInvoice->getSrvOpIva()=='1'){
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvIva()/100));
} else {
$subtotalService = $itemInvoice->getSrvPrice();
$subneto = ($subneto * 100) / (100 + $itemInvoice->getSrvIva());
}
$subneto = str_replace(',','.',$subneto);
$subneto = floatval($subneto);
switch ($itemInvoice->getSrvServiceCatId()){
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $itemInvoice->getSrvUnits();
break;
case 2: //Actividades
// El número de personas es considerado en el calculo
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$subtotal = $subtotalService * $days * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $itemInvoice->getSrvUnits();
break;
case 3: // AV
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 4: //Creative
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 5: //Cruise
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 6: //Entertaiment
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 7: // Gifts
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 8: //Guide
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 9: //Itineraries
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 10: //Lounge -- No Aplica
break;
case 11: //Menu
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 12: //Others
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; } else { $unitsServ = intval($unitsServ); }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 13: //Transport
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 14: //Technology
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 15: //Assisstant
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 16: //DDR
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 17: //Seguridad
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 18: //WiFi
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 19: //Mobiliario
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 20: //Parking
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 21: //Limpieza
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
default: //Others (por default)
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; } else { $unitsServ = intval($unitsServ); }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($subneto,2,PHP_ROUND_HALF_UP);
$valorTotalNet = $valorTotalNet + $neto;
$valorVat = $valorVat + ($subtotal - $neto);
}
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'PAYMENT') {
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la factura
$newInvoice = $em->getRepository(BlvReservationInvoice::class)->findOneById($id);
//FIN: Creamos la factura
$data = [];
$data = $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'I');
$paymentsClient = new ReservationPaymentsClient();
$paymentsClient->setReservationId($id);
$reservaInv = new BlvReservationInvoice();
$reservaInv->setReservationId($id);
$idLounges = [];
$loungesBoolToInvoice = [];
if (array_key_exists('lounge',$data['datasupplier'])) {
foreach ($data['datasupplier']['lounge'] as $item) {
$idLounges[] = $item['id'];
$loungesBoolToInvoice[] = 1;
}
$idLounges = implode(',', $idLounges);
$loungesBoolToInvoice = implode(',', $loungesBoolToInvoice);
} else {
$idLounges = '0';
$loungesBoolToInvoice = '0';
}
$idPayments = [];
$paymentsBoolToInvoice = [];
if (array_key_exists('payment',$data['datasupplier'])) {
foreach ($data['datasupplier']['payment'] as $item) {
$idPayments[] = $item['id'];
$paymentsBoolToInvoice[] = 1;
}
$idPayments = implode(',', $idPayments);
$paymentsBoolToInvoice = implode(',', $paymentsBoolToInvoice);
} else {
$idPayments = '0';
$paymentsBoolToInvoice = '0';
}
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(BlvReservationInvoiceRec::class)->findOneByInvoiceToRec($id);
$boolToRec = empty($rectf);
$allInvoices = $em->getRepository(BlvReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
$allInvoicesRec = $em->getRepository(BlvReservationInvoiceRec::class)->findByReservationId($newInvoice->getReservationId());
foreach ($allInvoicesRec as $item){ array_push($allInvoices, $item); }
$allProformas = $em->getRepository(ReservationProforma::class)->findByReservationId($newInvoice->getReservationId());
if(empty($data['type'])){$data['type'] = 'Invoice';}
$reservaEquis = $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
$newInvoice = $this->clientDataToInvoice($newInvoice, 'Client', $reservaEquis->getClient(), $newInvoice->getReservationId());
}
return $this->render('MDS/GreenPatioBundle/blv/invoice-new-invoice.html.twig',
array(
'id' => $newInvoice->getReservationId(),
'cid' => '',
'fid' => $id,
'invoice' => $allInvoices,
'proformas' => $allProformas,
'boolToRec' => $boolToRec,
'numberadmin' => '',
'type' => $data['type'],
'number' => $newInvoice->getId(),
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $data['token'],
'reservation' => $data['reservation'],
'company' => $data['company'],
'clients' => $data['clients'],
'user' => $user_logueado,
'invoicedeposititems' => '',
'arrayItems' => $data['arrayItems'],
'datasupplier' => $data['datasupplier'],
'totales_neto' => $data['totales_neto'],
'totales_iva' => '',
'totales' => $data['totales'],
'bases_imponibles' => $data['bases_imponibles'],
'balance' => $data['balance'],
'paymentInvoice' => $data['paymentInvoice'],
'currency' => $data['currency'],
'clientName' => $newInvoice->getClientName(),
'clientAddress' => $newInvoice->getClientAddress(),
'clientDocument' => $newInvoice->getClientDocument(),
)
);
}
/**
* @Route("/blv/reservations/invoice/viewrec/{id}", name="reservations_viewrec_invoice_blv")
* Ver la factura rectificativa
*/
public function viewRecInvoiceAction($id, EntityManagerInterface $em, Request $request)
{
// Se genera y muestra en nueva pantalla la nueva proforma
$arrayBools = array( 'lounge' => null, 'service' => null, 'payment' => null, );
$arrayBools['lounge'] = $request->request->get('inv_lounge_hidden_bool');
$arrayBools['service'] = $request->request->get('inv_service_hidden_bool');
$arrayBools['payment'] = $request->request->get('inv_payment_hidden_bool');
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
//Acumuladores de datos globales de la factura
$valorTotalNet = $valorVat = 0;
//INICIO: Creamos los items de la factura
$arrayInvoicedItems = $em->getRepository(BlvReservationInvoiceRecItems::class)->findByInvoiceId($id);
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'LOUNGE') {
$ivaNew = $itemInvoice->getLngIva();
//Acumulamos neto e iva para la factura
$valorTotalNet = $valorTotalNet + $itemInvoice->getLngServicePrice();
$valorVat = $valorVat + round(($itemInvoice->getLngServicePrice() * ($ivaNew / 100)),2,PHP_ROUND_HALF_UP);
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'SERVICE') {
//Acumulamos neto e iva para la factura
if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())){
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotal = 0;
$subtotalService = $itemInvoice->getSrvPrice();
$subneto = $itemInvoice->getSrvPrice();
// Commission
if ($itemInvoice->getSrvOpCommission()=='1'){
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvCommission()/100));
$subneto = $subneto * (1 + ($itemInvoice->getSrvCommission()/100));
} else {
$subtotalService = $subtotalService * (1 - ($itemInvoice->getSrvCommission()/100));
$subneto = $subneto * (1 - ($itemInvoice->getSrvCommission()/100));
}
// Over
if ($itemInvoice->getSrvOpOver()=='1'){
$subtotalService = $subtotalService + $itemInvoice->getSrvOver();
$subneto = $subneto + $itemInvoice->getSrvOver();
} else {
$subtotalService = $subtotalService - $itemInvoice->getSrvOver();
$subneto = $subneto - $itemInvoice->getSrvOver();
}
// IVA
if ($itemInvoice->getSrvOpIva()=='1'){
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvIva()/100));
} else {
$subtotalService = $itemInvoice->getSrvPrice();
$subneto = ($subneto * 100) / (100 + $itemInvoice->getSrvIva());
}
switch ($itemInvoice->getSrvServiceCatId()){
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $itemInvoice->getSrvUnits();
break;
case 2: //Actividades
// El número de personas es considerado en el calculo
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$subtotal = $subtotalService * $days * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $itemInvoice->getSrvUnits();
break;
case 3: // AV
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 4: //Creative
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 5: //Cruise
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 6: //Entertaiment
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 7: // Gifts
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = 1;
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 8: //Guide
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 9: //Itineraries
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 10: //Lounge -- No Aplica
break;
case 11: //Menu
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 12: //Others
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 13: //Transport
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 14: //Technology
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = 1;
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 15: //Assisstant
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 16: //DDR
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
if ($days > 1){
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
}
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") {
$unitsServ = 1;
}
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
default:
break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($subneto,2,PHP_ROUND_HALF_UP);
$valorTotalNet = $valorTotalNet + $neto;
$valorVat = $valorVat + ($subtotal - $neto);
}
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'PAYMENT') {
//Acumulamos neto e iva para la factura
//$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount(); // El pago no puede afectar el neto de la factura
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la factura
$newInvoice = $em->getRepository(BlvReservationInvoiceRec::class)->findOneById($id);
//FIN: Creamos la factura
$data = [];
$data = $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'R');
$paymentsClient = new ReservationPaymentsClient();
$paymentsClient->setReservationId($id);
$reservaInv = new BlvReservationInvoice();
$reservaInv->setReservationId($id);
$idLounges = array();
$loungesBoolToInvoice = array();
if (array_key_exists('lounge',$data['datasupplier'])) {
foreach ($data['datasupplier']['lounge'] as $item) {
$idLounges[] = $item['id'];
$loungesBoolToInvoice[] = 1;
}
$idLounges = implode(',', $idLounges);
$loungesBoolToInvoice = implode(',', $loungesBoolToInvoice);
} else {
$idLounges = '0';
$loungesBoolToInvoice = '0';
}
$idPayments = [];
$paymentsBoolToInvoice = [];
if (array_key_exists('payment',$data['datasupplier'])) {
foreach ($data['datasupplier']['payment'] as $item) {
$idPayments[] = $item['id'];
$paymentsBoolToInvoice[] = 1;
}
$idPayments = implode(',', $idPayments);
$paymentsBoolToInvoice = implode(',', $paymentsBoolToInvoice);
} else {
$idPayments = '0';
$paymentsBoolToInvoice = '0';
}
// Una factura solo se puede rectificar una vez
$boolToRec = false; // Estas viendo una factura rectificativa
$allInvoices = $em->getRepository(BlvReservationInvoice::class)->findByReservationId($newInvoice->getReservationId());
$allInvoicesRec = $em->getRepository(BlvReservationInvoiceRec::class)->findByReservationId($newInvoice->getReservationId());
foreach ($allInvoicesRec as $item){ array_push($allInvoices, $item); }
$allProformas = $em->getRepository(ReservationProforma::class)->findByReservationId($newInvoice->getReservationId());
// Por ser una factura rectificativa multiplicamos por -1 el balance
if(empty($data['type'])){$data['type'] = 'Invoice Rec';}
$reservaEquis = $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
$newInvoice = $this->clientDataToInvoice($newInvoice, 'Client', $reservaEquis->getClient(), $newInvoice->getReservationId());
}
return $this->render('MDS/GreenPatioBundle/blv/invoice-new-invoice.html.twig',
array(
'id' => $newInvoice->getReservationId(),
'invoiceIdToRec' => $newInvoice->getInvoiceToRec(),
'cid' => '',
'fid' => $id,
'invoice' => $allInvoices,
'proformas' => $allProformas,
'boolToRec' => $boolToRec,
'numberadmin' => '',
'type' => $data['type'],
'number' => $newInvoice->getId(),
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $data['token'],
'reservation' => $data['reservation'],
'company' => $data['company'],
'clients' => $data['clients'],
'user' => $user_logueado,
'invoicedeposititems' => '',
'arrayItems' => $data['arrayItems'],
'datasupplier' => $data['datasupplier'],
'totales_neto' => $data['totales_neto'],
'totales_iva' => '',
'totales' => $data['totales'],
'bases_imponibles' => $data['bases_imponibles'],
'balance' => $data['balance'],
'paymentInvoice' => $data['paymentInvoice'],
'currency' => $data['currency'],
'clientName' => $newInvoice->getClientName(),
'clientAddress' => $newInvoice->getClientAddress(),
'clientDocument' => $newInvoice->getClientDocument(),
)
);
}
/**
* @Route("/blv/reservations/invoice/invoice-proforma/print/{type}/{id}", name="reservations_invoiceorproforma_print_blv")
*/
public function detailsInvoiceProformaPrintAction($type, $id, EntityManagerInterface $em, Request $request)
{
$data = [];
// Si el ID de factura viene vacio regresamos a ver facturas
if (empty($type)){ return $this->redirectToRoute('reservations_viewreservation_invoices',array('id' => $id)); }
//Acumuladores de datos globales de la factura o proforma
$valorTotalNet = 0;
$valorVat = 0;
if ($type == 'I'){
//Es una factura
//INICIO: Creamos los items de la factura
$arrayInvoicedItems = $em->getRepository(BlvReservationInvoiceItems::class)->findByInvoiceId($id);
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'LOUNGE') {
//Acumulamos neto e iva para la factura
$valorTotalNet = $valorTotalNet + $itemInvoice->getLngServicePrice();
$valorVat = $valorVat + round(($itemInvoice->getLngServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'SERVICE') {
//Acumulamos neto e iva para la factura
if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())){
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $itemInvoice->getSrvPrice();
$subtotalService = str_replace(',','.',$subtotalService);
$subtotalService = floatval($subtotalService);
$subneto = $itemInvoice->getSrvPrice();
$subneto = str_replace(',','.',$subneto);
$subneto = floatval($subneto);
// Commission
if ($itemInvoice->getSrvOpCommission()=='1'){
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvCommission()/100));
$subneto = $subneto * (1 + ($itemInvoice->getSrvCommission()/100));
} else {
$subtotalService = $subtotalService * (1 - ($itemInvoice->getSrvCommission()/100));
$subneto = $subneto * (1 - ($itemInvoice->getSrvCommission()/100));
}
// Over
if ($itemInvoice->getSrvOpOver()=='1'){
$subtotalService = $subtotalService + $itemInvoice->getSrvOver();
$subneto = $subneto + $itemInvoice->getSrvOver();
} else {
$subtotalService = $subtotalService - $itemInvoice->getSrvOver();
$subneto = $subneto - $itemInvoice->getSrvOver();
}
// IVA
if ($itemInvoice->getSrvOpIva()=='1'){
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvIva()/100));
} else {
$subtotalService = $itemInvoice->getSrvPrice();
$subneto = ($subneto * 100) / (100 + $itemInvoice->getSrvIva());
}
switch ($itemInvoice->getSrvServiceCatId()){
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $itemInvoice->getSrvUnits();
break;
case 2: //Actividades
// El número de personas es considerado en el calculo
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$subtotal = $subtotalService * $days * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $itemInvoice->getSrvUnits();
break;
case 3: // AV
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 4: //Creative
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 5: //Cruise
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 6: //Entertaiment
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 7: // Gifts
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 8: //Guide
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 9: //Itineraries
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 10: //Lounge -- No Aplica
break;
case 11: //Menu (Catering)
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 12: //Others
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 13: //Transport
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 14: //Technology
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 15: //Assisstant
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 16: //DDR
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 17: //Seguridad
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 18: //WiFi
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 19: //Mobiliario
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 20: //Parking
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 21: //Limpieza
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
default: //Others (por default)
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($subneto,2,PHP_ROUND_HALF_UP);
$valorTotalNet = $valorTotalNet + $neto;
$valorVat = $valorVat + ($subtotal - $neto);
}
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'PAYMENT') {
//Acumulamos neto e iva para la factura
//$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount(); // El pago no puede afectar el neto de la factura
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la factura
$newInvoice = $em->getRepository(BlvReservationInvoice::class)->findOneById($id);
//FIN: Creamos la factura
$data = [];
$data = $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'I');
$paymentsClient = new ReservationPaymentsClient();
$paymentsClient->setReservationId($id);
$reservaInv = new BlvReservationInvoice();
$reservaInv->setReservationId($id);
$idLounges = array();
$loungesBoolToInvoice = array();
if (array_key_exists('lounge',$data['datasupplier'])) {
foreach ($data['datasupplier']['lounge'] as $item) {
$idLounges[] = $item['id'];
$loungesBoolToInvoice[] = 1;
}
$idLounges = implode(',', $idLounges);
$loungesBoolToInvoice = implode(',', $loungesBoolToInvoice);
} else {
$idLounges = '0';
$loungesBoolToInvoice = '0';
}
$idPayments = array();
$paymentsBoolToInvoice = array();
if (array_key_exists('payment',$data['datasupplier'])) {
foreach ($data['datasupplier']['payment'] as $item) {
$idPayments[] = $item['id'];
$paymentsBoolToInvoice[] = 1;
}
$idPayments = implode(',', $idPayments);
$paymentsBoolToInvoice = implode(',', $paymentsBoolToInvoice);
} else {
$idPayments = '0';
$paymentsBoolToInvoice = '0';
}
//Es una proforma
$proforma = $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
$invoiceIdToRec = null;
$reservaEquis = $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
$newInvoice = $this->clientDataToInvoice($newInvoice, 'Client', $reservaEquis->getClient(), $newInvoice->getReservationId());
}
} else {
if ($type == 'R'){
//El tipo es una factura rectificativa
//INICIO: Creamos los items de la factura rectficativa
$arrayInvoicedItems = $em->getRepository(BlvReservationInvoiceRecItems::class)->findByInvoiceRecId($id);
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'LOUNGE') {
//Acumulamos neto e iva para la factura rectificativa
$valorTotalNet = $valorTotalNet + $itemInvoice->getLngServicePrice();
$valorVat = $valorVat + round(($itemInvoice->getLngServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'SERVICE') {
//Acumulamos neto e iva para la factura
if (is_null($itemInvoice->getSrvPrice()) or empty($itemInvoice->getSrvPrice())){
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $itemInvoice->getSrvPrice();
$subneto = $itemInvoice->getSrvPrice();
// Commission
if ($itemInvoice->getSrvOpCommission()=='1'){
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvCommission()/100));
$subneto = $subneto * (1 + ($itemInvoice->getSrvCommission()/100));
} else {
$subtotalService = $subtotalService * (1 - ($itemInvoice->getSrvCommission()/100));
$subneto = $subneto * (1 - ($itemInvoice->getSrvCommission()/100));
}
// Over
if ($itemInvoice->getSrvOpOver()=='1'){
$subtotalService = $subtotalService + $itemInvoice->getSrvOver();
$subneto = $subneto + $itemInvoice->getSrvOver();
} else {
$subtotalService = $subtotalService - $itemInvoice->getSrvOver();
$subneto = $subneto - $itemInvoice->getSrvOver();
}
// IVA
if ($itemInvoice->getSrvOpIva()=='1'){
$subtotalService = $subtotalService * (1 + ($itemInvoice->getSrvIva()/100));
} else {
$subtotalService = $itemInvoice->getSrvPrice();
$subneto = ($subneto * 100) / (100 + $itemInvoice->getSrvIva());
}
switch ($itemInvoice->getSrvServiceCatId()){
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $itemInvoice->getSrvUnits();
break;
case 2: //Actividades
// El número de personas es considerado en el calculo
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$subtotal = $subtotalService * $days * $itemInvoice->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $itemInvoice->getSrvUnits();
break;
case 3: // AV
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 4: //Creative
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 5: //Cruise
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 6: //Entertaiment
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 7: // Gifts
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 8: //Guide
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 9: //Itineraries
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 10: //Lounge -- No Aplica
break;
case 11: //Catering
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 12: //Others
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 13: //Transport
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 14: //Technology
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 15: //Assisstant
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 16: //DDR
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 17: //Seguridad
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 18: //WiFi
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 19: //Mobiliario
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 20: //Parking
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 21: //Limpieza
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
default: //Others (por default)
$pax = $itemInvoice->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemInvoice->getSrvDateOutAt())->diff($itemInvoice->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemInvoice->getSrvDateInAt())->format('d/m/Y'). ' - '.($itemInvoice->getSrvDateOutAt())->format('d/m/Y') : ($itemInvoice->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $itemInvoice->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($subneto,2,PHP_ROUND_HALF_UP);
$valorTotalNet = $valorTotalNet + $neto;
$valorVat = $valorVat + ($subtotal - $neto);
}
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'PAYMENT') {
//Acumulamos neto e iva para la factura
//$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount(); // El pago no puede afectar el neto de la factura
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la factura rectificativa
$newInvoice = $em->getRepository(BlvReservationInvoiceRec::class)->findOneById($id);
//FIN: Creamos la factura rectificativa
$data = array();
$data = $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'R');
$paymentsClient = new ReservationPaymentsClient();
$paymentsClient->setReservationId($id);
$reservaInv = new BlvReservationInvoice();
$reservaInv->setReservationId($id);
$idLounges = array();
$loungesBoolToInvoice = array();
if (array_key_exists('lounge',$data['datasupplier'])) {
foreach ($data['datasupplier']['lounge'] as $item) {
$idLounges[] = $item['id'];
$loungesBoolToInvoice[] = 1;
}
$idLounges = implode(',', $idLounges);
$loungesBoolToInvoice = implode(',', $loungesBoolToInvoice);
} else {
$idLounges = '0';
$loungesBoolToInvoice = '0';
}
$idPayments = array();
$paymentsBoolToInvoice = array();
if (array_key_exists('payment',$data['datasupplier'])) {
foreach ($data['datasupplier']['payment'] as $item) {
$idPayments[] = $item['id'];
$paymentsBoolToInvoice[] = 1;
}
$idPayments = implode(',', $idPayments);
$paymentsBoolToInvoice = implode(',', $paymentsBoolToInvoice);
// Se han generado dos arreglos, cada uno dividido en 2 strings
// array( [5]=>0, [8]=>1, [10]=>0) ==>> '5,8,10' y '0,1,0'
// Para manipularlos entre la vista y el JS
} else {
$idPayments = '0';
$paymentsBoolToInvoice = '0';
}
//Es una proforma
$proforma = $em->getRepository(ReservationProforma::class)->findOneByReservationId($id);
$invoiceIdToRec = $newInvoice->getInvoiceToRec();
$data['number'] = $data['number']->getNumber();
$data['balance'] = $data['balance'] *(-1);
$reservaEquis = $em->getRepository(Reservation::class)->findOneById($newInvoice->getReservationId());
if(empty($newInvoice->getClientName()) and empty($newInvoice->getClientAddress()) and empty($newInvoice->getClientDocument())){
$newInvoice = $this->clientDataToInvoice($newInvoice, 'Client', $reservaEquis->getClient(), $newInvoice->getReservationId());
}
} else {
// El tipo es una proforma
//INICIO: Creamos los items de la proforma
$arrayInvoicedItems = $em->getRepository(ReservationInvoiceProformaItems::class)->findByProformaId($id);
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getType() == 'LOUNGE') {
$itemPro = $em->getRepository(ReservationLoungeSimple::class)->findOneById($itemInvoice->getControlId());
//Acumulamos neto e iva para la factura
$valorTotalNet = $valorTotalNet + $itemPro->getServicePrice();
$valorVat = $valorVat + round(($itemPro->getServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getType() == 'SERVICE') {
$itemPro = $em->getRepository(ReservationService::class)->findOneById($itemInvoice->getControlId());
//Acumulamos neto e iva para la factura
if (is_null($itemPro->getPrice()) or empty($itemPro->getPrice())){
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $itemPro->getPrice();
$subneto = $itemPro->getPrice();
// Commission
if ($itemPro->getOpCommission()=='1'){
$subtotalService = $subtotalService * (1 + ($itemPro->getCommission()/100));
$subneto = $subneto * (1 + ($itemPro->getCommission()/100));
} else {
$subtotalService = $subtotalService * (1 - ($itemPro->getCommission()/100));
$subneto = $subneto * (1 - ($itemPro->getCommission()/100));
}
// Over
if ($itemPro->getOpOver()=='1'){
$subtotalService = $subtotalService + $itemPro->getOver();
$subneto = $subneto + $itemPro->getOver();
} else {
$subtotalService = $subtotalService - $itemPro->getOver();
$subneto = $subneto - $itemPro->getOver();
}
// IVA
if ($itemPro->getOpIva()=='1'){
$subtotalService = $subtotalService * (1 + ($itemPro->getIva()/100));
} else {
$subtotalService = $itemPro->getPrice();
$subneto = ($subneto * 100) / (100 + $itemPro->getIva());
}
switch ($itemPro->getServiceCatId()){
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $itemPro->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $itemPro->getUnits();
break;
case 2: //Actividades
// El número de personas es considerado en el calculo
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$subtotal = $subtotalService * $days * $itemPro->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $itemPro->getUnits();
break;
case 3: // AV
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 4: //Creative
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 5: //Cruise
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 6: //Entertaiment
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 7: // Gifts
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 8: //Guide
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 9: //Itineraries
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 10: //Lounge -- No Aplica
break;
case 11: //Menu
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 12: //Others
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 13: //Transport
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 14: //Technology
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 15: //Assisstant
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 16: //DDR
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 17: //Seguridad
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 18: //WiFi
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 19: //Mobiliario
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 20: //Parking
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
case 21: //Limpieza
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
default: //Others (por default)
$pax = $itemPro->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($itemPro->getDateOutAt())->diff($itemPro->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($itemPro->getDateInAt())->format('d/m/Y'). ' - '.($itemPro->getDateOutAt())->format('d/m/Y') : ($itemPro->getDateInAt())->format('d/m/Y');
$unitsServ = $itemPro->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($subneto,2,PHP_ROUND_HALF_UP);
$valorTotalNet = $valorTotalNet + $neto;
$valorVat = $valorVat + ($subtotal - $neto);
}
}
}
}
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getType() == 'PAYMENT') {
//Acumulamos neto e iva para la factura
//$valorTotalNet = $valorTotalNet - $itemInvoice->getPayAmount(); // El pago no puede afectar el neto de la factura
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la factura
$newInvoice = $em->getRepository(ReservationProforma::class)->findOneById($id);
//FIN: Creamos la factura
$data = array();
$data = $this->baseInvoiceDoneReservation($newInvoice->getReservationId(), $id,'P');
$paymentsClient = new ReservationPaymentsClient();
$paymentsClient->setReservationId($id);
$reservaInv = new BlvReservationInvoice();
$reservaInv->setReservationId($id);
$idLounges = array();
$loungesBoolToInvoice = array();
if (array_key_exists('lounge',$data['datasupplier'])) {
foreach ($data['datasupplier']['lounge'] as $item) {
$idLounges[] = $item['id'];
$loungesBoolToInvoice[] = 1;
}
$idLounges = implode(',', $idLounges);
$loungesBoolToInvoice = implode(',', $loungesBoolToInvoice);
} else {
$idLounges = '0';
$loungesBoolToInvoice = '0';
}
$idPayments = array();
$paymentsBoolToInvoice = array();
if (array_key_exists('payment',$data['datasupplier'])) {
foreach ($data['datasupplier']['payment'] as $item) {
$idPayments[] = $item['id'];
$paymentsBoolToInvoice[] = 1;
}
$idPayments = implode(',', $idPayments);
$paymentsBoolToInvoice = implode(',', $paymentsBoolToInvoice);
} else {
$idPayments = '0';
$paymentsBoolToInvoice = '0';
}
//Es una proforma
$proforma = $em->getRepository(ReservationProforma::class)->findOneById($id);
$invoiceIdToRec = null;
$reservaEquis = $em->getRepository(Reservation::class)->findOneById($proforma->getReservationId());
if(true){ $newInvoice = $this->clientDataToInvoice(null, 'Client', $reservaEquis->getClient(), $reservaEquis->getId()); }
}
}
return $this->render('MDS/GreenPatioBundle/blv/services-proforma-print-reservation.html.twig',
array(
'id' => $id,
'type' => $data['type'],
'number' => $data['number'],
'invoiceIdToRec' => $invoiceIdToRec,
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => '',
'company' => $data['company'],
'clients' => $data['clients'],
'datasupplier' => $data['datasupplier'],
'totales_neto' => $data['totales_neto'],
'bases_imponibles' => $data['bases_imponibles'],
'totales' => $data['totales'],
'balance' => $data['balance'],
'currency' => $data['currency'],
'paymentInvoice' => $data['paymentInvoice'],
'clientName' => $newInvoice->getClientName(),
'clientAddress' => $newInvoice->getClientAddress(),
'clientDocument' => $newInvoice->getClientDocument(),
)
);
}
private function baseInvoiceSelectedReservation($id, $arrayBools, $number)
{
$em = $this->getDoctrine()->getManager();
$reservation = $em->getRepository(Reservation::class)->findOneById($id);
$items = $em->getRepository(ReservationInvoiceProformaItems::class)->findByReservationId($reservation->getId());
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
$client = $em->getRepository(Client::class)->findById($reservation->getClient());
if (!empty($client)){
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$client['city'] = $city; $client['region'] = $region; $client['country'] = $country;
} else {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => 0,
);
//INICIO: Determinamos el numero de factura o proforma
if (substr($number,0,1) == 'I'){
// Es una Factura
$numberInvoiceOrProforma = substr($number,1);
$number = $numberInvoiceOrProforma;
$number = $em->getRepository(BlvReservationInvoice::class)->findOneById($number);
$number = $number->getNumber();
$type = 'Invoice';
} else {
// Es una Proforma
$numberInvoiceOrProforma = substr($number,1);
$number = $numberInvoiceOrProforma;
$number = $em->getRepository(ReservationProforma::class)->findOneById($number);
$number = $number->getPrefix().$number->getReservationId();
$type = 'Proforma';
}
//FIN: Determinamos el numero de factura o proforma
// Buscamos las salas reservadas, pagos y servicios para el evento
$arrayItems = array();
$reservationLounges = array();
if (!empty($arrayBools['lounge'])) {
foreach ($arrayBools['lounge'] as $key => $item) {
if ($item == 'true') {
$reservationLounges[] = $em->getRepository(ReservationLoungeSimple::class)->findOneById($key);
}
}
}
$payments = array();
if (!empty($arrayBools['payment'])) {
foreach ($arrayBools['payment'] as $key => $item) {
if ($item == 'true') {
$payments[] = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
}
}
}
$services = array();
if (!empty($arrayBools['service'])) {
foreach ($arrayBools['service'] as $key => $item) {
if ($item == 'true') {
$services[] = $em->getRepository(ReservationService::class)->findOneById($key);
}
}
}
$data_supplier = array();
$i = 0;
$iva = '21'; // Esteban Rincon: "Por Ley de localización del impuesto, siempre será un 21%"
$pax = '-';
$qty = '1';
$lounge = array(
'neto' => 0,
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$service = array(
'neto' => 0,
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
foreach ($reservationLounges as $item){
if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
$subtotal = 0;
$neto = 0;
$subnetoMounting = 0;
$subtotalLounge = 0;
$subnetoRemoval = 0;
} else {
$subtotalLounge = $item->getServicePrice() * 1.21;
$subneto = $item->getServicePrice();
$subtotal = $subtotalLounge;
$neto = $subneto;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($neto,2,PHP_ROUND_HALF_UP);
$arrayItems[] = array(
'type' => 'Lounge',
'name' => $item->getLoungeName(),
'amount' => $neto,
'iva' => $iva,
'total' => $subtotal,
);
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
switch ($iva){
case 21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21); break;
case 10: $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * 0.1); break;
case 0: break;
default: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21); break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$totales_neto_all = round($totales_neto_all,2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$lounge['neto'] = $lounge['neto'] + $neto;
$lounge['sumSubT'] = $lounge['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$lounge['neto'] = round($lounge['neto'],2,PHP_ROUND_HALF_UP);
$lounge['sumSubT'] = round($lounge['sumSubT'],2,PHP_ROUND_HALF_UP);
$data_supplier['lounge'][$i] = array (
'id' => $item->getId(),
'loungeName' => $item->getLoungeName(),
'idLounge' => $item->getIdLounge(),
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'servicePrice' => $item->getServicePrice(),
'subtotalLounge' => $subtotalLounge,
'iva' => $iva,
'pax' => $pax,
'qty' => $qty,
'type' => $item->getType(),
'subtotal' => $subtotal,
);
$i++;
}
$data_supplier['loungeSubTotal'] = array(
'neto' => $lounge['neto'],
'sumSubT' => $lounge['sumSubT'],
);
$payment = array(
'neto' => 0,
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$i = 0;
foreach ($payments as $item){
$payment['neto'] = $payment['neto'] + ($item->getAmount()*(-1));
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$payment['neto'] = round($payment['neto'],2,PHP_ROUND_HALF_UP);
$payment['sumSubT'] = $payment['sumSubT'] + ($item->getAmountTotal()*(-1));
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$payment['sumSubT'] = round($payment['sumSubT'],2,PHP_ROUND_HALF_UP);
$data_supplier['payment'][$i] = array (
'id' => $item->getId(),
'amount' => $item->getAmount()*(-1),
'amountTotal' => $item->getAmountTotal()*(-1),
'vat' => $item->getVat(),
'datePayAt' => $item->getDatePayAt(),
'wayToPay' => $item->getWayToPay(),
);
$arrayItems[] = array(
'type' => 'Payment',
'name' => $item->getWayToPay(),
'amount' => $item->getAmount()*(-1),
'total' => $item->getAmountTotal()*(-1),
'iva' => $item->getVat(),
);
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + ($item->getAmount()*(-1));
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + (($item->getAmount()*(-1)) * 0.21);
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$totales_neto_all = round($totales_neto_all,2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$i++;
}
if (!empty($payments)) {
$data_supplier['paymentSubTotal'] = array(
'neto' => $payment['neto'],
'sumSubT' => $payment['sumSubT'],
);
}
foreach ($services as $item){
if (is_null($item->getPrice()) or empty($item->getPrice())){
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
// Manejar Comision y Over en precio unitario
$priceExtra = (float)$item->getPrice();
$commissionExtra = (float)$item->getCommission();
$subnetoUnitExtra = ($item->getOpCommission() == '1')
? ($priceExtra + ($priceExtra * $commissionExtra / 100))
: ($priceExtra - ($priceExtra * $commissionExtra / 100));
$subnetoUnitExtra = ($item->getOpOver() == '1') ? ($subnetoUnitExtra + $item->getOver()) : ($subnetoUnitExtra - $item->getOver());
$subneto = $subnetoUnitExtra;
$subtotalService = $subnetoUnitExtra;
// IVA
if ($item->getOpIva()=='1'){
$subtotalService = $subtotalService * (1 + ($item->getIva()/100));
} else {
$subtotalService = $item->getPrice();
$subneto = ($subneto * 100) / (100 + $item->getIva());
}
switch ($item->getServiceCatId()){
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $item->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $item->getUnits();
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Hotel',
'date' => ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y'),
'qty' => $item->getUnits(),
'iva' => $item->getIva(),
'pax' => '-',
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 2: //Actividades
// El número de personas es considerado en el calculo
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$subtotal = $subtotalService * $days * $item->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $item->getUnits();
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Actividad',
'date' => $dateServ,
'qty' => $item->getUnits(),
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 3: // AV
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 4: //Creative
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Creativo',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 5: //Cruise
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Crucero',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 6: //Entertaiment
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Entretenimiento',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 7: // Gifts
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Regalos',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 8: //Guide
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Guía',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
break;
case 11: //Menu (Catering)
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Catering',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 12: //Others
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 13: //Transport
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Transporte',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 14: //Technology
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Tecnología',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 15: //Assisstant
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 16: //DDR
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 17: //Seguridad
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Seguridad',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 18: //WiFi
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'WiFi',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 19: //Mobiliario
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Mobiliario',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 20: //Parking
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Parking',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 21: //Limpieza
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Limpieza',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
default: //Others (por default)
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array (
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($subneto,2,PHP_ROUND_HALF_UP);
$arrayItems[] = array(
'type' => 'Service',
'name' => $item->getName(),
'amount' => $neto,
'iva' => $item->getIva(),
'total' => $subtotal,
);
}
switch ($item->getIva()){
// Acumula IVA
case 21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva()/100)); break;
case 10: $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva()/100)); break;
case 0: break;
default: break;
}
$totales_neto_all = $totales_neto_all + $neto;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$totales_neto_all = round($totales_neto_all,2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$service['neto'] = $service['neto'] + $neto;
$service['sumSubT'] = $service['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$service['neto'] = round($service['neto'],2,PHP_ROUND_HALF_UP);
$service['sumSubT'] = round($service['sumSubT'],2,PHP_ROUND_HALF_UP);
$i++;
}
$data_supplier['serviceSubTotal'] = array(
'neto' => $service['neto'],
'sumSubT' => $service['sumSubT'],
);
$currency = '€';
$totales_total = $totales_neto_all + $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
if (!empty($payments)) {
$amount_pay = $data_supplier['paymentSubTotal']['sumSubT'];
} else {
$amount_pay = 0;
}
$totales_all = $totales_total - $amount_pay;
if ($type == 'Invoice'){
$em->clear(); // sin este clear se producia error al guardar
$newInvoice = $em->getRepository(BlvReservationInvoice::class)->findOneById($numberInvoiceOrProforma);
$newInvoice->setBalance($totales_all);
$em->persist($newInvoice);
$em->flush();
}
$data = array(
'id' => $id,
'type' => $type,
'number' => $number,
'prefix' => 'LGD-'.(new DateTime('now'))->format('dmy').'-',
'date' => new DateTime('now'),
'reservation' => $reservation,
'token' => $reservation->getAccessKey(),
'company' => $company,
'clients' => $client,
'arrayItems' => $arrayItems,
'datasupplier' => $data_supplier,
'currency' => $currency,
'totales_neto' => $totales_neto_all,
'bases_imponibles' => $data_iva,
'totales' => $totales_total,
'balance' => $totales_all,
'paymentInvoice' => $amount_pay,
);
return $data;
}
private function baseInvoiceDoneReservation($reservationId, $invoiceId, $typeBase)
{
$em = $this->getDoctrine()->getManager();
$reservation = $em->getRepository(Reservation::class)->findOneById($reservationId);
$dateDocument = null; //Fecha final del documento
if (($typeBase == 'I') or ($typeBase == 'P')) {
if ($typeBase == 'I') {
$items = $em->getRepository(BlvReservationInvoiceItems::class)->findBy(array('reservationId' => $reservationId, 'invoiceId' => $invoiceId));
} else {
// Es factura ni proforma
$items = $em->getRepository(ReservationInvoiceProformaItems::class)->findBy(array('reservationId' => $reservationId, 'proformaId' => $invoiceId));
}
} else {
// No es factura ni proforma, es una rectificativa
$items = $em->getRepository(BlvReservationInvoiceRecItems::class)->findBy(array('reservationId' => $reservationId, 'invoiceRecId' => $invoiceId));
}
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
$client = $em->getRepository(Client::class)->findById($reservation->getClient());
if (!empty($client)){
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$client['city'] = $city; $client['region'] = $region; $client['country'] = $country;
} else {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => 0,
);
//INICIO: Determinamos el numero de factura o proforma
if ($typeBase == 'I'){
// Es una Factura
$number = $em->getRepository(BlvReservationInvoice::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$number = $number->getNumber();
$type = 'Invoice';
} else {
if ($typeBase == 'R'){
// Es una factura rectificativa
$number = $em->getRepository(BlvReservationInvoiceRec::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$type = 'Invoice Rec';
} else {
// Es una Proforma
$number = $invoiceId;
$type = 'Proforma';
}
}
//FIN: Determinamos el numero de factura o proforma
// Buscamos las salas reservadas, pagos y servicios para el evento
$arrayItems = [];
$reservationLounges = [];
$payments = [];
$services = [];
if (!empty($items)) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
foreach ($items as $item) {
switch ($item->getItemType()) {
case 'LOUNGE': // Salon
$reservationLounges[] = $item;
break;
case 'PAYMENT': // Pago
$payments[] = $item;
break;
case 'SERVICE': // Servicio
$services[] = $item;
break;
default:
break;
}
}
} else {
// Es una proforma
foreach ($items as $item) {
switch ($item->getType()) {
case 'LOUNGE': // Salon
$loungePro = $em->getRepository(ReservationLoungeSimple::class)->findOneById($item->getControlId());
if (!empty($loungePro)) {
$reservationLounges[] = $loungePro;
}
break;
case 'PAYMENT': // Pago
$paymentPro = $em->getRepository(ReservationPaymentsClient::class)->findOneById($item->getControlId());
if (!empty($paymentPro)) {
$payments[] = $paymentPro;
}
break;
case 'SERVICE': // Servicio
$servicePro = $em->getRepository(ReservationService::class)->findOneById($item->getControlId());
if (!empty($servicePro)) {
$services[] = $servicePro;
}
break;
default: break;
}
}
}
}
$data_supplier = [];
$i = 0;
$iva = '21'; // Esteban Rincon: "Por Ley de localización del impuesto, siempre será un 21%"
$pax = '-';
$qty = '1';
$lounge = array(
'neto' => 0,
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$service = array(
'neto' => 0,
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
foreach ($reservationLounges as $item){
if (($typeBase == 'I') or $typeBase == 'R') { $iva = $item->getLngIva(); } else { $iva = $item->getIva(); }
if (($typeBase == 'I') or ($typeBase == 'R')) {
if (is_null($item->getLngServicePrice()) or empty($item->getLngServicePrice())){
$subtotal = $neto = $subnetoMounting = $subtotalLounge = $subnetoRemoval = 0;
} else {
$subtotalLounge = $item->getLngServicePrice() * (1 + ($iva / 100));
$subneto = $item->getLngServicePrice();
$subtotal = $subtotalLounge;
$neto = $subneto;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($neto,2,PHP_ROUND_HALF_UP);
$arrayItems[] = array(
'type' => 'Lounge',
'name' => $item->getLngLoungeName(),
'amount' => $neto,
'iva' => $iva,
'total' => $subtotal,
);
}
} else {
// Es proforma
if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
$subtotal = $neto = $subnetoMounting = $subtotalLounge = $subnetoRemoval = 0;
} else {
$subtotalLounge = $item->getServicePrice() * (1 + ($iva / 100));
$subneto = $item->getServicePrice();
$subtotal = $subtotalLounge;
$neto = $subneto;
$iva = $item->getIva();
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal,2,PHP_ROUND_HALF_UP);
$neto = round($neto,2,PHP_ROUND_HALF_UP);
$arrayItems[] = array(
'type' => 'Lounge',
'name' => $item->getLoungeName(),
'amount' => $neto,
'iva' => $iva,
'total' => $subtotal,
);
}
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
switch ($iva){
case 21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21); break;
case 10: $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * 0.1); break;
case 0: break;
default: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21); break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$totales_neto_all = round($totales_neto_all,2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$lounge['neto'] = $lounge['neto'] + $neto;
$lounge['sumSubT'] = $lounge['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$lounge['neto'] = round($lounge['neto'],2,PHP_ROUND_HALF_UP);
$lounge['sumSubT'] = round($lounge['sumSubT'],2,PHP_ROUND_HALF_UP);
if (($typeBase == 'I') or ($typeBase == 'R')) {
$data_supplier['lounge'][$i] = array(
'id' => $item->getId(),
'loungeName' => $item->getLngLoungeName(),
'idLounge' => $item->getLngIdLounge(),
'dateStart' => $item->getLngDateStart(),
'dateEnd' => $item->getLngDateEnd(),
'servicePrice' => $item->getLngServicePrice(),
'subtotalLounge' => $subtotalLounge,
'iva' => $iva,
'pax' => $pax,
'qty' => $qty,
'type' => $item->getLngType(),
'subtotal' => $subtotal,
);
} else {
// Es proforma
$data_supplier['lounge'][$i] = array(
'id' => $item->getId(),
'loungeName' => $item->getLoungeName(),
'idLounge' => $item->getIdLounge(),
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'servicePrice' => $item->getServicePrice(),
'subtotalLounge' => $subtotalLounge,
'iva' => $iva,
'pax' => $pax,
'qty' => $qty,
'type' => $item->getType(),
'subtotal' => $subtotal,
);
}
$i++;
}
$data_supplier['loungeSubTotal'] = array(
'neto' => $lounge['neto'],
'sumSubT' => $lounge['sumSubT'],
);
$payment = array(
'neto' => 0,
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$i = 0;
foreach ($payments as $item){
if (($typeBase == 'I') or ($typeBase == 'R')) {
if ($typeBase == 'I') {
$payment['neto'] = $payment['neto'] + ($item->getPayAmount() * (-1));
$payment['sumSubT'] = $payment['sumSubT'] + ($item->getPayAmountTotal() * (-1));
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$payment['sumSubT'] = round($payment['sumSubT'], 2, PHP_ROUND_HALF_UP);
$payment['neto'] = round($payment['neto'], 2, PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + ($item->getPayAmount() * (-1));
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($item->getPayAmount() * (-1)*($item->getPayVat()/100));
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$totales_neto_all = round($totales_neto_all, 2, PHP_ROUND_HALF_UP);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2, PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$data_supplier['payment'][$i] = array(
'id' => $item->getId(),
'amount' => $item->getPayAmount() * (-1),
'amountTotal' => $item->getPayAmountTotal() * (-1),
'vat' => $item->getPayVat(),
'datePayAt' => $item->getPayDatePayAt(),
'wayToPay' => $item->getPayWayToPay(),
);
$arrayItems[] = array(
'type' => 'Payment',
'name' => $item->getPayWayToPay(),
'amount' => $item->getPayAmount() * (-1),
'total' => $item->getPayAmountTotal() * (-1),
'iva' => $item->getPayVat(),
);
} else {
//Es una rectificativa
$payment['neto'] = $payment['neto'] + ($item->getPayAmount());
$payment['sumSubT'] = $payment['sumSubT'] + ($item->getPayAmountTotal());
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$payment['sumSubT'] = round($payment['sumSubT'], 2, PHP_ROUND_HALF_UP);
$payment['neto'] = round($payment['neto'], 2, PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + ($item->getPayAmount());
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($item->getPayAmount()*(0.21));
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$totales_neto_all = round($totales_neto_all,2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$data_supplier['payment'][$i] = array(
'id' => $item->getId(),
'amount' => $item->getPayAmount(),
'amountTotal' => $item->getPayAmountTotal(),
'vat' => $item->getPayVat(),
'datePayAt' => $item->getPayDatePayAt(),
'wayToPay' => $item->getPayWayToPay(),
);
$arrayItems[] = array(
'type' => 'Payment',
'name' => $item->getPayWayToPay(),
'amount' => $item->getPayAmount(),
'total' => $item->getPayAmountTotal(),
'iva' => $item->getPayVat(),
);
}
} else {
// Es una proforma
$payment['neto'] = $payment['neto'] + ($item->getAmount()*(-1));
$payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal()*(-1);
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$payment['sumSubT'] = round($payment['sumSubT'], 2, PHP_ROUND_HALF_UP);
$payment['neto'] = round($payment['neto'], 2, PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + ($item->getAmount()*(-1));
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($item->getAmount()*(-0.21));
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$totales_neto_all = round($totales_neto_all,2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$data_supplier['payment'][$i] = array(
'id' => $item->getId(),
'amount' => $item->getAmount()*(-1),
'amountTotal' => $item->getAmountTotal()*(-1),
'vat' => $item->getVat(),
'datePayAt' => $item->getDatePayAt(),
'wayToPay' => $item->getWayToPay(),
);
$arrayItems[] = array(
'type' => 'Payment',
'name' => $item->getWayToPay(),
'amount' => $item->getAmount()*(-1),
'total' => $item->getAmountTotal()*(-1),
'iva' => $item->getVat(),
);
}
$i++;
}
if (!empty($payments)) {
$data_supplier['paymentSubTotal'] = array(
'neto' => $payment['neto'],
'sumSubT' => $payment['sumSubT'],
);
}
foreach ($services as $item){
if (($typeBase == 'I') or ($typeBase == 'R')) {
if (is_null($item->getSrvPrice())) {
$subtotal = $neto = $subtotalService = 0;
} else {
$subtotalService = $item->getSrvPrice();
$subtotalService = str_replace(',','.',$subtotalService);
$subtotalService = floatval($subtotalService);
$subneto = $item->getSrvPrice();
$subneto = str_replace(',','.',$subneto);
$subneto = floatval($subneto);
// Commission
if ($item->getSrvOpCommission() == '1') {
$subtotalService = $subtotalService * (1 + ($item->getSrvCommission() / 100));
$subneto = $subneto * (1 + ($item->getSrvCommission() / 100));
} else {
$subtotalService = $subtotalService * (1 - ($item->getSrvCommission() / 100));
$subneto = $subneto * (1 - ($item->getSrvCommission() / 100));
}
// Over
if ($item->getSrvOpOver() == '1') {
$subtotalService = $subtotalService + $item->getSrvOver();
$subneto = $subneto + $item->getSrvOver();
} else {
$subtotalService = $subtotalService - $item->getSrvOver();
$subneto = $subneto - $item->getSrvOver();
}
// IVA
if ($item->getSrvOpIva() == '1') {
$subtotalService = $subtotalService * (1 + ($item->getSrvIva() / 100));
} else {
$subtotalService = $item->getSrvPrice();
$subneto = ($subneto * 100) / (100 + $item->getSrvIva());
}
switch ($item->getSrvServiceCatId()) {
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $item->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $item->getSrvUnits();
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Hotel',
'date' => ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y'),
'qty' => $item->getSrvUnits(),
'iva' => $item->getSrvIva(),
'pax' => '-',
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 2: //Actividades
// El número de personas es considerado en el calculo
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$subtotal = $subtotalService * $days * $item->getSrvUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $item->getSrvUnits();
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Actividad',
'date' => $dateServ,
'qty' => $item->getSrvUnits(),
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 3: // AV
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 4: //Creative
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Creativo',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 5: //Cruise
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Crucero',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 6: //Entertaiment
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Entretenimiento',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 7: // Gifts
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Regalos',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 8: //Guide
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Guía',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 9: //Itineraries
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
break;
case 11: //Menu (Catering)
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : $dateServ = ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Catering',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 12: //Others
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 13: //Transport
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Transporte',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 14: //Technology
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Tecnología',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 15: //Assisstant
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 16: //DDR
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 17: //Seguridad
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Seguridad',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 18: //WiFi
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'WiFi',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 19: //Mobiliario
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Mobiliario',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 20: //Parking
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Parking',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 21: //Limpieza
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Limpieza',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
default: //Others (por default)
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y') : ($item->getSrvDateInAt())->format('d/m/Y');
$unitsServ = $item->getSrvUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getSrvServiceCatId(),
'serviceName' => $item->getSrvName(),
'serviceType' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal, 2, PHP_ROUND_HALF_UP);
$neto = round($subneto, 2, PHP_ROUND_HALF_UP);
$arrayItems[] = array(
'type' => 'Service',
'name' => $item->getSrvName(),
'amount' => $neto,
'iva' => $item->getSrvIva(),
'total' => $subtotal,
);
}
switch ($item->getSrvIva()) {
// Acumula IVA
case 21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getSrvIva() / 100)); break;
case 10: $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getSrvIva() / 100)); break;
case 0: break;
default: break;
}
} else {
// Es una proforma
if (is_null($item->getPrice()) or empty($item->getPrice())) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
// Manejar Comision y Over en precio unitario
$priceExtra = (float)$item->getPrice();
$commissionExtra = (float)$item->getCommission();
$subnetoUnitExtra = ($item->getOpCommission() == '1')
? ($priceExtra + ($priceExtra * $commissionExtra / 100))
: ($priceExtra - ($priceExtra * $commissionExtra / 100));
$subnetoUnitExtra = ($item->getOpOver() == '1') ? ($subnetoUnitExtra + $item->getOver()) : ($subnetoUnitExtra - $item->getOver());
$subneto = $subnetoUnitExtra;
$subtotalService = $subnetoUnitExtra;
// IVA
if ($item->getOpIva() == '1') {
$subtotalService = $subtotalService * (1 + ($item->getIva() / 100));
} else {
$subtotalService = $item->getPrice();
$subneto = ($subneto * 100) / (100 + $item->getIva());
}
switch ($item->getServiceCatId()) {
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($item->getDateOutAt())->diff($item->getDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $item->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $item->getUnits();
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Hotel',
'date' => ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y'),
'qty' => $item->getUnits(),
'iva' => $item->getIva(),
'pax' => '-',
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 2: //Actividades
// El número de personas es considerado en el calculo
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$subtotal = $subtotalService * $days * $item->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $item->getUnits();
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Actividad',
'date' => $dateServ,
'qty' => $item->getUnits(),
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 3: // AV
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 4: //Creative
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Creativo',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 5: //Cruise
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Crucero',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 6: //Entertaiment
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Entretenimiento',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 7: // Gifts
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Regalos',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 8: //Guide
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Guía',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
break;
case 11: //Catering (Menu)
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Catering',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 12: //Others
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 13: //Transport
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Transporte',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 14: //Technology
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = 1;
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Tecnología',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 15: //Assisstant
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 16: //DDR
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 17: //Seguridad
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Seguridad',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 18: //WiFi
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'WiFi',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 19: //Mobiliario
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Mobiliario',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 20: //Parking
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Parking',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 21: //Limpieza
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Limpieza',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
default: //Others (por default)
$pax = $item->getPax();
if (empty($pax) or $pax == "0") { $pax = 1; }
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$dateServ = ($days > 1) ? ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y') : ($item->getDateInAt())->format('d/m/Y');
$unitsServ = $item->getUnits();
if (empty($unitsServ) or $unitsServ == "0") { $unitsServ = 1; }
$subtotal = $subtotalService * $days * $unitsServ * $pax;
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $unitsServ * $pax;
$data_supplier['service'][$i] = array(
'id' => $item->getId(),
'serviceCatId' => $item->getServiceCatId(),
'serviceName' => $item->getName(),
'serviceType' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnitExtra,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
}
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP),
$subtotal = round($subtotal, 2, PHP_ROUND_HALF_UP);
$neto = round($subneto, 2, PHP_ROUND_HALF_UP);
$arrayItems[] = array(
'type' => 'Service',
'name' => $item->getName(),
'amount' => $neto,
'iva' => $item->getIva(),
'total' => $subtotal,
);
}
switch ($item->getIva()) {
// Acumula IVA
case 21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * ($item->getIva() / 100)); break;
case 10: $data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100)); break;
case 0: break;
default: break;
}
}
$totales_neto_all = $totales_neto_all + $neto;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$totales_neto_all = round($totales_neto_all,2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'],2,PHP_ROUND_HALF_UP);
$data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'],2,PHP_ROUND_HALF_UP);
// Acumula netos totales e IVA
$service['neto'] = $service['neto'] + $neto;
$service['sumSubT'] = $service['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$service['neto'] = round($service['neto'],2,PHP_ROUND_HALF_UP);
$service['sumSubT'] = round($service['sumSubT'],2,PHP_ROUND_HALF_UP);
$i++;
}
$data_supplier['serviceSubTotal'] = array(
'neto' => $service['neto'],
'sumSubT' => $service['sumSubT'],
);
$currency = '€';
$totales_total = $totales_neto_all + $data_iva['ivaMontoVeintiUno'] + $data_iva['ivaMontoDiez'];
if (!empty($payments)) {
$amount_pay = $data_supplier['paymentSubTotal']['sumSubT'];
} else {
$amount_pay = 0;
}
$totales_all = $totales_total - $amount_pay;
if (empty($dateDocument)){ $dateDocument = new DateTime('now'); }
$data = array(
'id' => $reservationId,
'type' => $type,
'number' => $number,
'prefix' => 'GP-'.(new DateTime('now'))->format('dmy').'-',
'date' => $dateDocument,
'reservation' => $reservation,
'token' => $reservation->getAccessKey(),
'company' => $company,
'clients' => $client,
'arrayItems' => $arrayItems,
'datasupplier' => $data_supplier,
'currency' => $currency,
'totales_neto' => $totales_neto_all,
'bases_imponibles' => $data_iva,
'totales' => $totales_total,
'balance' => $totales_all,
'paymentInvoice' => $amount_pay,
);
return $data;
}
/**
* @Route("/blv/invoicerec/{id}", name="reservations_invoice_rec_blv")
* Generar factura rectificativa Bella View
*/
public function generateReservationInvoiceRecAction($id, EntityManagerInterface $em, Request $request)
{
$invoice = $em->getRepository(BlvReservationInvoice::class)->findOneById($id);
if (true){
// Verificamos que no exista una factura rectificativa previa sobre la misma factura
$previusInvoiceRec = $em->getRepository(BlvReservationInvoiceRec::class)->findOneByInvoiceToRec($id);
if (!empty($previusInvoiceRec)){ return $this->redirectToRoute('reservations_viewrec_invoice_blv', array('id' => $previusInvoiceRec->getId())); }
}
$now = new DateTime();
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$invoiceRec = new BlvReservationInvoiceRec();
$invoiceRec->setInvoiceToRec($id);
$invoiceRec->setCreatedAt($now);
$invoiceRec->setUpdatedAt($now);
$invoiceRec->setCreatedId($user_id);
$invoiceRec->setUpdatedId($user_id);
$invoiceRec->setDateAt($now);
$invoiceRec->setMaster($invoice->getMaster());
$invoiceRec->setNumber('REC-'.$invoice->getNumber());
$invoiceRec->setPrefix('RL');
$invoiceRec->setReservationId($invoice->getReservationId());
$invoiceRec->setTotal($invoice->getTotal()*(-1));
$invoiceRec->setTotalNet($invoice->getTotalNet()*(-1));
$invoiceRec->setType('Invoice Rec');
$invoiceRec->setVat($invoice->getVat()*(-1));
$invoiceRec->setBalance($invoice->getBalance()*(-1));
$invoiceRec->setClientName($invoice->getClientName());
$invoiceRec->setClientAddress($invoice->getClientAddress());
$invoiceRec->setClientDocument($invoice->getClientDocument());
$invoiceRec->setClientType($invoice->getClientType());
$em->persist($invoiceRec);
$em->flush();
$invoiceItems = $em->getRepository(BlvReservationInvoiceItems::class)->findByInvoiceId($id);
// Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
foreach ($invoiceItems as $item){
$itemRec = new BlvReservationInvoiceRecItems();
$itemRec->setReservationId($item->getReservationId());
$itemRec->setInvoiceId($item->getInvoiceId());
$itemRec->setItemType($item->getItemType());
$itemRec->setInvoiceRecId($invoiceRec->getId());
$itemRec->setLngControlId($item->getLngControlId());
$itemRec->setLngLoungeName($item->getLngLoungeName());
$itemRec->setLngIdLounge($item->getLngIdLounge());
$itemRec->setLngIdLounge($item->getLngIdLounge());
$itemRec->setLngDateStart($item->getLngDateStart());
$itemRec->setLngDateEnd($item->getLngDateEnd());
$itemRec->setLngServicePrice($item->getLngServicePrice()*(-1));
$itemRec->setLngPax($item->getLngPax());
$itemRec->setLngType($item->getLngType());
$itemRec->setLngHourStart($item->getLngHourStart());
$itemRec->setLngMinStart($item->getLngMinStart());
$itemRec->setLngHourEnd($item->getLngHourEnd());
$itemRec->setLngMinEnd($item->getLngMinEnd());
$itemRec->setLngIva($item->getLngIva());
$itemRec->setLngOpIva($item->getLngOpIva());
$itemRec->setSrvControlId($item->getSrvControlId());
$itemRec->setSrvSupplierId($item->getSrvSupplierId());
$itemRec->setSrvServiceId($item->getSrvServiceId());
$itemRec->setSrvServiceCatId($item->getSrvServiceCatId());
$itemRec->setSrvServiceCatName($item->getSrvServiceCatName());
$itemRec->setSrvPrice($item->getSrvPrice()*(-1));
$itemRec->setSrvCurrency($item->getSrvCurrency());
$itemRec->setSrvUnits($item->getSrvUnits());
$itemRec->setSrvOpCommission($item->getSrvOpCommission());
$itemRec->setSrvCommission($item->getSrvCommission());
$itemRec->setSrvOpOver($item->getSrvOpOver());
$itemRec->setSrvOver($item->getSrvOver()*(-1));
$itemRec->setSrvOpIva($item->getSrvOpIva());
$itemRec->setSrvIva($item->getSrvIva());
$itemRec->setSrvPax($item->getSrvPax());
$itemRec->setSrvHour($item->getSrvHour());
$itemRec->setSrvDateInAt($item->getSrvDateInAt());
$itemRec->setSrvDateOutAt($item->getSrvDateOutAt());
$itemRec->setSrvContcolor($item->getSrvContcolor());
$itemRec->setSrvRank($item->getSrvRank());
$itemRec->setSrvAssistantId($item->getSrvAssistantId());
$itemRec->setSrvActivityId($item->getSrvActivityId());
$itemRec->setSrvPay($item->getSrvPay());
$itemRec->setSrvName($item->getSrvName());
$itemRec->setPayControlId($item->getPayControlId());
$itemRec->setPayAmount($item->getPayAmount()); // Los pagos han pasado a ser las facturas de deposito, en la tabla su amount se encuentra en positivo, en la rectificativa, este valor lo necesitamos en positivo
$itemRec->setPayDatePayAt($item->getPayDatePayAt());
$itemRec->setPayWayToPay($item->getPayWayToPay());
$itemRec->setPayAmountTotal($item->getPayAmountTotal()); // Los pagos han pasado a ser las facturas de deposito, en la tabla su amount se encuentra en positivo, en la rectificativa, este valor lo necesitamos en positivo
$itemRec->setPayVat($item->getPayVat());
$itemRec->setCreatedId($user_id);
$itemRec->setCreatedAt(new DateTime('now'));
$itemRec->setUpdatedId($user_id);
$itemRec->setUpdatedAt(new DateTime('now'));
$em->persist($itemRec);
$em->flush();
// Se libera asignando ID = 0
$item->setLngControlId(0);
$item->setSrvControlId(0);
$item->setPayControlId(0);
$em->persist($item);
$em->flush();
}
$allInvoices = $em->getRepository(BlvReservationInvoice::class)->findByReservationId($invoice->getReservationId());
$allInvoicesRec = $em->getRepository(BlvReservationInvoiceRec::class)->findByReservationId($invoice->getReservationId());
foreach ($allInvoicesRec as $item){ array_push($allInvoices, $item); }
$reservation = $em->getRepository(Reservation::class)->findOneById($invoice->getReservationId());
$client = $em->getRepository(Client::class)->findOneById($reservation->getClient());
$data = array();
$data['clients'][0] = $client;
$data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
$data['datasupplier'] = '';
$data['totales_neto'] = '';
$data['totales'] = '';
$data['bases_imponibles'] = '';
$data['balance'] = '';
$data['paymentInvoice'] = '';
$data['currency'] = '';
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(BlvReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$invoice->getNumber()));
$boolToRec = empty($rectf);
return $this->redirectToRoute('reservations_viewrec_invoice_blv', array('id' => $invoiceRec->getId()));
}
/**
* @Route("/blv/reservations/invoice/list", name="reservation_invoice_list_blv")
* Listar las facturas de Bella View
*/
public function indexAction( EntityManagerInterface $em, Request $request) {
$todayTwoYearAgo = new DateTime('now -2 year');
$parameters = array( 'dateStart' => $todayTwoYearAgo, );
$dql = 'SELECT p
FROM GreenPatioBundle:BlvReservationInvoice p
WHERE p.dateAt > :dateStart';
$query = $em->createQuery($dql)->setParameters($parameters);
$invoicedBlv = $query->getResult();
$parameters = array( 'dateStart' => $todayTwoYearAgo, );
$dql = 'SELECT p
FROM GreenPatioBundle:BlvReservationInvoiceRec p
WHERE p.dateAt > :dateStart';
$query = $em->createQuery($dql)->setParameters($parameters);
$invoicedRec = $query->getResult();
$invoiced = [];
foreach ($invoicedBlv as $item){ $invoiced['B'.$item->getId()] = $item; }
// Agregamos las rectificativas al arreglo de facturas con el indice "R(id)"
foreach ($invoicedRec as $idRecArray => $item){ $invoiced['R'.$item->getId()] = $item; }
$sumatoriaTotalNet = $sumatoriaTotalVat = $sumatoriaTotal = 0;
foreach ($invoiced as $idArray => $item){
$reserva = $em->getRepository(Reservation::class)->findOneById($item->getReservationId());
$invoiced[$idArray]->setNumber($reserva->getTitle());
$client = $em->getRepository(Client::class)->findOneById($reserva->getClient());
if(!empty($client)){ $invoiced[$idArray]->setPrefix($client->getName()); } else { $invoiced[$idArray]->setPrefix(''); }
$estaEnFactura = false; $estaEnFacturaRectificativa = false;
if ($item->getType() == 'Invoice Deposit'){
// Si la factura de deposito se encuentra en una factura sumara 0
// INICIO: Verificamos factura de deposito dentro de alguna factura
$payOfInvoiceDeposit = $em->getRepository(ReservationPaymentsClient::class)->findOneByInvoiceId($item->getId());
if (!empty($payOfInvoiceDeposit)){
// Verificamos si el deposito esta dentro de una factura
$itemInvoiceOfInvoiceDeposit = $em->getRepository(BlvReservationInvoiceItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
}
if (!empty($itemInvoiceOfInvoiceDeposit)){
$estaEnFactura = true;
} else {
// Verificamos que el control Id no haya sido seteado a 0 por rectificar la factura
if (!empty($payOfInvoiceDeposit)) {
$itemInvoiceOfInvoiceDeposit = $em->getRepository(BlvReservationInvoiceRecItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
if (!empty($itemInvoiceOfInvoiceDeposit)) {
$estaEnFactura = true;
}
}
}
if (!empty($payOfInvoiceDeposit)){
// Verificamos si el deposito esta dentro de una factura rectificativa
$itemInvoiceOfInvoiceDepositRec = $em->getRepository(BlvReservationInvoiceRecItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
}
if (!empty($itemInvoiceOfInvoiceDepositRec)){
$estaEnFacturaRectificativa = true;
}
// FIN: Verificamos factura de deposito dentro de alguna factura
$invoicedDepositItems = $em->getRepository(ReservationInvoiceDepositItems::class)->findByControlId($item->getMaster());
foreach ($invoicedDepositItems as $itemDep){
$invoiced[$idArray]->setTotalNet($invoiced[$idArray]->getTotalNet() + $itemDep->getAmount());
$invoiced[$idArray]->setVat($invoiced[$idArray]->getVat() + (($itemDep->getAmount() * $itemDep->getIva())/100));
$invoiced[$idArray]->setTotal($invoiced[$idArray]->getTotal() + ($itemDep->getAmount() + (($itemDep->getAmount() * $itemDep->getIva())/100)));
}
}
// Sumara cuando ambos esten en false (no esta en factura ni en fact rect) o en true en ambas (fue facturado pero luego rectificado)
if ((!$estaEnFactura and !$estaEnFacturaRectificativa) or ($estaEnFactura and $estaEnFacturaRectificativa)) {
$sumatoriaTotalNet = $sumatoriaTotalNet + $item->getTotalNet();
$sumatoriaTotalVat = $sumatoriaTotalVat + $item->getVat();
$sumatoriaTotal = $sumatoriaTotal + $item->getTotal();
}
}
$toXls = $request->request->get('boolToXls');
if (!empty($toXls)){
$id = 0;
// Solicita el servicio de excel
$phpExcelObject = $this->get('phpexcel')->createPHPExcelObject();
$phpExcelObject->getProperties()->setCreator("InOut Travel & Events")
->setLastModifiedBy("InOut Travel & Events")
->setTitle("InOut Travel & Events")
->setSubject("InOut Travel & Events")
->setDescription("InOut Travel & Events, generado usando clases de PHP")
->setKeywords("office 2005 openxml php")
->setCategory("Archivo de ejemplo");
$fill = new PHPExcel_Style_Fill();
$numberFormat = new PHPExcel_Style_NumberFormat();
$alignment = new PHPExcel_Style_Alignment();
$i = 6;
$indiceInicial = 7;
$indiceFinal = 7;
$activesheet = $phpExcelObject->getActiveSheet();
$drawingobject = $this->get('phpexcel')->createPHPExcelWorksheetDrawing();
$drawingobject->setName('Image name');
$drawingobject->setDescription('Image description');
$drawingobject->setPath(getcwd().'/assets/images/logo/logo_green_patio.png');
$drawingobject->setHeight(60);
$drawingobject->setOffsetY(20);
$drawingobject->setCoordinates('Q1');
$drawingobject->setWorksheet($activesheet);
$phpExcelObject
->getActiveSheet()
->getStyle('B3:O3')
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9fc4a6');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('C3','LISTADO DE FACTURACION')
;
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('B'.$i, 'Fecha')
->setCellValue('D'.$i, 'Número')
->setCellValue('F'.$i, 'Expediente')
->setCellValue('H'.$i, 'Nombre del Evento')
->setCellValue('L'.$i, 'Cliente')
->setCellValue('O'.$i, 'Tipo')
->setCellValue('Q'.$i, 'Neto')
->setCellValue('S'.$i, 'Total')
;
$data = [];
$data = $invoiced;
foreach ($data as $item) {
$time = $item->getDateAt()->format('d/m/Y');
$idExp = ($item->getType() == 'Invoice Rec') ? 'RL'.$item->getId() : 'L'.$item->getId();
$clientTypeText = ($item->getClientType() == 'Client') ? 'Cliente' : 'Proveedor';
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('B' . ($i + 1), $time)
->setCellValue('D' . ($i + 1), $idExp)
->setCellValue('F' . ($i + 1), $item->getReservationId())
->setCellValue('H' . ($i + 1), $item->getNumber())
->setCellValue('L' . ($i + 1), $item->getClientName())
->setCellValue('O' . ($i + 1), $clientTypeText)
->setCellValue('Q' . ($i + 1), $item->getTotalNet())
->setCellValue('S' . ($i + 1), $item->getTotal())
;
$i++;
$indiceFinal++;
}
$indiceFinal--;
$indicesResta = $indiceFinal - $indiceInicial + 1;
$phpExcelObject
->getActiveSheet()
->getStyle('Q' . ($indiceFinal + 3) . ':' . 'S' . ($indiceFinal + 3))
->getFill()
->setFillType($fill::FILL_SOLID)
->getStartColor()
->setRGB('9fc4a6');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('Q' . ($indiceFinal + 3), 'Total Neto')
->setCellValue('S' . ($indiceFinal + 3), 'Total');
$phpExcelObject->setActiveSheetIndex(0)
->setCellValue('Q' . ($indiceFinal + 4), '=SUM(' . 'Q' . $indiceInicial . ' : Q' . $indiceFinal . ')')
->setCellValue('S' . ($indiceFinal + 4), '=SUM(' . 'S' . $indiceInicial . ' : U' . $indiceFinal . ')');
$phpExcelObject->getActiveSheet()->setTitle('Estadísticas por sala');
// Define el indice de página al número 1, para abrir esa página al abrir el archivo
$phpExcelObject->setActiveSheetIndex(0);
// Creamos pagina de Datos en bruto para Esteban Rincon
// Add new sheet
$objWorkSheet = $phpExcelObject->createSheet(1); //Setting index when creating
$phpExcelObject->setActiveSheetIndex(1);
$phpExcelObject->getActiveSheet()->setTitle('Datos en bruto');
$x = 1;
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A'.$x, 'Fecha')
->setCellValue('B'.$x, 'Número')
->setCellValue('C'.$x, 'Expediente')
->setCellValue('D'.$x, 'Nombre del Evento')
->setCellValue('E'.$x, 'Cliente')
->setCellValue('F'.$x, 'Tipo')
->setCellValue('G'.$x, 'Neto')
->setCellValue('H'.$x, 'Total')
;
foreach ($data as $item) {
$time = $item->getDateAt()->format('d/m/Y');
$idExp = ($item->getType() == 'Invoice Rec') ? 'RL'.$item->getId() : 'L'.$item->getId();
$clientTypeText = ($item->getClientType() == 'Client') ? 'Cliente' : 'Proveedor';
$phpExcelObject->setActiveSheetIndex(1)
->setCellValue('A' . ($x + 1), $time)
->setCellValue('B' . ($x + 1), $idExp)
->setCellValue('C' . ($x + 1), $item->getReservationId())
->setCellValue('D' . ($x + 1), $item->getNumber())
->setCellValue('E' . ($x + 1), $item->getClientName())
->setCellValue('F' . ($x + 1), $clientTypeText)
->setCellValue('G' . ($x + 1), $item->getTotalNet())
->setCellValue('H' . ($x + 1), $item->getTotal())
;
$x++;
}
$phpExcelObject->setActiveSheetIndex(0);
// Crea el writer
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel2007');
// Envia la respuesta del controlador
$response = $this->get('phpexcel')->createStreamedResponse($writer);
// Agrega los headers requeridos
$dispositionHeader = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'InOut_Travel_Events'.'.xlsx'
);
$response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
$response->headers->set('Content-Disposition', $dispositionHeader);
$phpExcelObject->getActiveSheet()->setTitle('Facturación Bella View');
// Define el indice de página al número 1, para abrir esa página al abrir el archivo
$phpExcelObject->setActiveSheetIndex(0);
// Crea el writer
$writer = $this->get('phpexcel')->createWriter($phpExcelObject, 'Excel2007');
// Envia la respuesta del controlador
$response = $this->get('phpexcel')->createStreamedResponse($writer);
// Agrega los headers requeridos
$dispositionHeader = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
'Green Patio - Listado Facturacion Legends.xlsx'
);
$response->headers->set('Content-Type', 'application/vnd.ms-excel; charset=utf-8');
$response->headers->set('Pragma', 'public');
$response->headers->set('Cache-Control', 'maxage=1');
$response->headers->set('Content-Disposition', $dispositionHeader);
return $response;
}
return $this->render('MDS/GreenPatioBundle/blv/list-reservations-invoice.html.twig',
array(
'invocied' => $invoiced,
'sumatoriaTotalNet' => $sumatoriaTotalNet,
'sumatoriaTotalVat' => $sumatoriaTotalVat,
'sumatoriaTotal' => $sumatoriaTotal,
)
);
}
private function clientDataToInvoice($invoice, $typeClient, $idClient, $reservationId){
//Recibe una ReservationInvoice y se le agregan los datos del cliente
$em = $this->getDoctrine()->getManager();
$address = null; $name = '';
if (empty($invoice)){
// Venimos de un selector y vamos a cotizar
$reserva = $em->getRepository(Reservation::class)->findOneById($reservationId);
$typeClient = 'Client'; $idClient = $reserva->getClient();
$invoice = new BlvReservationInvoice();
}
if ($typeClient == 'Client'){
$client = $em->getRepository(Client::class)->findOneById($idClient); $typeClient = 'Client';
if (!empty($client)){ $name = $client->getName(); $address = $client->getAddress() . ' ' . $client->getAddressNumber(); }
} else {
// Proveedor (Para facturas de comision)
$client = $em->getRepository(Supplier::class)->findOneById($idClient); $typeClient = 'Supplier';
if (!empty($client)){ $name = $client->getCompany(); $address = $client->getAddress(); }
}
if(empty($client)){
// No se encontro el cliente o proveedor, se utilizará por defecto el de la reserva
$reserva = $em->getRepository(Reservation::class)->findOneById($invoice->getReservationId()); $typeClient = 'Client';
$client = $em->getRepository(Client::class)->findOneById($reserva->getClient());
if (!empty($client)){ $name = $client->getName(); $address = $client->getAddress() . ' ' . $client->getAddressNumber(); }
}
$region = $em->getRepository(Regions::class)->findOneById($client->getRegion());
$country = $em->getRepository(Country::class)->findOneById($client->getCountry());
$address = (empty($client->getRegion())) ? $address : $address. ', ' . $region->getRegion();
$address = (empty($client->getZipCode())) ? $address : $address. ' - ' . $client->getZipCode();
$address = (empty($client->getCountry())) ? $address : $address. ', ' . $country->getCountry();
$invoice->setClientAddress($address);
$invoice->setClientName($name);
$clientDocument = null;
$clientDocument = (empty($client->getTypeDocument())) ? $clientDocument : $client->getTypeDocument();
$clientDocument = (empty($client->getIdDocument())) ? ' ' : $clientDocument. ': ' . $client->getIdDocument();
$invoice->setClientDocument($clientDocument);
$invoice->setClientType($typeClient);
return $invoice;
}
}