<?php
namespace App\MDS\AvexpressBundle\Controller;
use App\Entity\Cities;
use App\Entity\Supplier;
use App\MDS\AvexpressBundle\Entity\AveBenefitsPermissions;
use App\MDS\AvexpressBundle\Entity\AveBenefitsInvoiceInvoiceRec;
use App\MDS\GreenPatioBundle\Entity\Reservation;
use App\MDS\GreenPatioBundle\Entity\ReservationInvoice;
use App\MDS\GreenPatioBundle\Entity\CvrReservationInvoice;
use App\MDS\GreenPatioBundle\Entity\BlvReservationInvoice;
use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceItems;
use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRec;
use App\Service\CommissionEnterprisesService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use DateTime;
use App\MDS\AvexpressBundle\Entity\AveFiles;
use App\MDS\AvexpressBundle\Entity\AveProductFile;
use App\MDS\AvexpressBundle\Entity\AvePaymentsClient;
use App\MDS\AvexpressBundle\Entity\AveDocProformaDeposit;
use App\MDS\AvexpressBundle\Entity\AveDocInvoice;
use App\MDS\AvexpressBundle\Entity\AveDocInvoiceRec;
use App\MDS\AvexpressBundle\Entity\AveDocProformaItems;
use App\MDS\AvexpressBundle\Entity\AveDocProforma;
use App\MDS\AvexpressBundle\Entity\AveDocInvoiceItems;
use App\MDS\AvexpressBundle\Entity\AveDocInvoiceRecItems;
use App\MDS\AvexpressBundle\Entity\AveBudgetToProforma;
use App\Entity\Client;
use App\Entity\Configuration;
use App\Entity\Country;
use App\Entity\Regions;
use App\Entity\SettingsCompany;
use App\Entity\User;
use App\MDS\AvexpressBundle\Entity\AveBenefitsSupplier;
use App\MDS\AvexpressBundle\Entity\AveBriefings;
use App\MDS\AvexpressBundle\Entity\AveBudgetPending;
use App\MDS\AvexpressBundle\Entity\AveProduct;
use App\MDS\AvexpressBundle\Entity\AveServices;
use App\MDS\AvexpressBundle\Entity\AveTemplateItems;
use App\MDS\DevelupBundle\Entity\MdvDocProformaItems;
use App\MDS\DevelupBundle\Entity\MdvTelegramUser;
use App\MDS\EventsBundle\Entity\ProposalAgents;
use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
use App\MDS\GreenPatioBundle\Entity\ReservationInvoiceRecItems;
use Swift_Mailer;
use Swift_Message;
use Swift_SmtpTransport;
class InvoiceController extends AbstractController
{
private $commisionEnterpriseService;
public function __construct(CommissionEnterprisesService $commisionEnterpriseService)
{
$this->commisionEnterpriseService = $commisionEnterpriseService;
}
/**
* @Route("/listpaydep/{id}", name="ave_list_payments_deposits")
* Listar pagos y depositos de un expediente
*/
public function listPaymentsDespositsAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$paymentsInFile = $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
$proformaDepositsInFile = $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
$proformas = array();
$allProformas = $em->getRepository(AveDocProforma::class)->findByFileId($id);
foreach ($allProformas as $item) {
$data = $this->baseInvoiceDoneFileTwo($id, $item->getId(), 'P');
$bases = 0;
if (is_numeric($data['totales']) and is_numeric($data['totales_neto'])) {
$bases = $data['totales'] - $data['totales_neto'];
}
$proformas[] = array(
'id' => $data['number'],
'date' => $data['date'],
'neto' => $data['totales_neto'],
'bases_imponibles' => $bases,
'total' => $data['totales'],
);
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/list-payments-deposits.html.twig',
array(
'id' => $id,
'proformas' => $proformas,
'payments' => $paymentsInFile,
'allInvoiceDeposit' => null,
'proformaDepositsInFile' => $proformaDepositsInFile,
)
);
}
/**
* @Route("/paymentadd/{id}", name="ave_add_payment")
* Agregar pago a un expediente
*/
public function addPaymentsAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$newRequest = $request->request->get('invoicepay');
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
if (!empty($newRequest['amount']) and !empty($newRequest['datePayAt']) and !empty($newRequest['wayToPay'])) {
if (is_numeric($newRequest['amount'])) {
$pay = new AvePaymentsClient();
$pay->setAmount($newRequest['amount']);
$pay->setConcept($newRequest['concept']);
$pay->setDatePayAt(new \DateTime($newRequest['datePayAt']));
$pay->setWayToPay($newRequest['wayToPay']);
$pay->setFileId($id);
$pay->setUpdatedId($user_id);
$pay->setUpdatedAt(new \DateTime("now"));
$pay->setCreatedId($user_id);
$pay->setCreatedAt(new \DateTime("now"));
$em->persist($pay);
$em->flush();
}
}
return $this->redirectToRoute(
'ave_list_payments_deposits',
array(
'id' => $id
)
);
}
/**
* @Route("/paymentdelete/{id}", name="ave_delete_payment")
* Eliminar pago de un expediente
*/
public function deletePaymentsAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$payment = $em->getRepository(AvePaymentsClient::class)->findOneById($id);
$fileId = $payment->getFileId();
$em->remove($payment);
$em->flush();
return $this->redirectToRoute(
'ave_list_payments_deposits',
array(
'id' => $fileId
)
);
}
/**
* @Route("/newproformadeposit/{id}", name="ave_new_proforma_deposit")
* Crear nueva proforma de deposito en un expediente
*/
public function newProformaDepositAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$newRequest = $request->request->get('invoicedep');
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$proforma = new AveDocProformaDeposit();
if (!empty($newRequest['amount']) and !empty($newRequest['name']) and !empty($newRequest['iva'])) {
if (is_numeric($newRequest['amount']) and is_numeric($newRequest['iva'])) {
$proforma->setAmount($newRequest['amount']);
$proforma->setName($newRequest['name']);
$proforma->setFileId($id);
$proforma->setIva($newRequest['iva']);
$proforma->setTotal($newRequest['amount'] + ($newRequest['amount'] * ($newRequest['iva'] / 100)));
$proforma->setUpdatedId($user_id);
$proforma->setUpdatedAt(new \DateTime("now"));
$proforma->setCreatedId($user_id);
$proforma->setCreatedAt(new \DateTime("now"));
$em->persist($proforma);
$em->flush();
}
} else {
// Falta algun dato
return $this->redirectToRoute('ave_list_payments_deposits', array('id' => $id));
}
return $this->redirectToRoute(
'ave_view_proforma_deposit',
array(
'id' => $proforma->getId()
)
);
}
/**
* @Route("/viewproformadeposit/{id}", name="ave_view_proforma_deposit")
* Ver una proforma de deposito
*/
public function viewProformaDepositAction($id, Request $request)
{
$docType = 'Proforma de Deposito';
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(AveDocProformaDeposit::class)->findOneById($id);
$id = $proforma->getFileId();
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount() * 0.21;
$allProformas = $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
// Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito //6*6*6
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($id);
if ($fileAv->getCommentsInPro()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
// Obtengo usuario logueado
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => $proforma,
'company' => $company,
'clients' => $clientNew,
'date' => $proforma->getCreatedAt(),
'number' => $proforma->getId(),
'invoice' => null,
'fid' => $proforma->getId(),
'boolToRec' => false,
'proformas' => $allProformas,
'currency' => '€',
'totales_neto' => $proforma->getAmount(),
'totales' => $proforma->getTotal(),
'balance' => $proforma->getTotal(),
'bases_imponibles' => $bases_imponibles,
'file' => $fileAv,
'user' => $user_logueado,
'services' => null,
'facturas' => null,
'paymentNotIvoiced' => null,
'paymentsAll' => null,
'totales_global_servicios_con_iva' => 0, //$data['totales_global_servicios_con_iva'],
'totales_global_servicios_neto' => 0, //$data['totales_global_servicios_neto'],
'totales_global_servicios_iva' => 0, //$data['totales_global_servicios_iva'],
'sumatoria_totales_global_con_iva' => 0, //$data['sumatoria_totales_global_con_iva'],
'sumatoria_totales_global_neto' => 0, //$data['sumatoria_totales_global_neto'],
'sumatoria_totales_global_iva' => 0, //$data['sumatoria_totales_global_iva'],
'comments' => $comments,
)
);
}
/**
* @Route("/avexternal/printproformadeposit/{id}", name="ave_print_proforma_deposit")
* Imprimir una proforma de deposito
*/
public function printProformaDepositAction($id, Request $request)
{
$docType = 'Proforma de Deposito';
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(AveDocProformaDeposit::class)->findOneById($id);
$id = $proforma->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount() * 0.21;
$allProformas = $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
// Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito //6*6*6
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($id);
if ($fileAv->getCommentsInPro()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => $proforma,
'company' => $company,
'clients' => $clientNew,
'date' => $proforma->getCreatedAt(),
'number' => $proforma->getId(),
'invoice' => null,
'fid' => $proforma->getId(),
'boolToRec' => false,
'proformas' => $allProformas,
'currency' => '€',
'totales_neto' => $proforma->getAmount(),
'totales' => $proforma->getTotal(),
'balance' => $proforma->getTotal(),
'bases_imponibles' => $bases_imponibles,
'comments' => $comments,
'file' => $fileAv,
'services' => null,
'facturas' => null,
'paymentNotIvoiced' => null,
'paymentsAll' => null,
'totales_global_servicios_con_iva' => 0, //$data['totales_global_servicios_con_iva'],
'totales_global_servicios_neto' => 0, //$data['totales_global_servicios_neto'],
'totales_global_servicios_iva' => 0, //$data['totales_global_servicios_iva'],
'sumatoria_totales_global_con_iva' => 0, //$data['sumatoria_totales_global_con_iva'],
'sumatoria_totales_global_neto' => 0, //$data['sumatoria_totales_global_neto'],
'sumatoria_totales_global_iva' => 0, //$data['sumatoria_totales_global_iva'],
)
);
}
/**
* @Route("/newinvoicedeposit/{id}", name="ave_new_invoice_deposit")
* Crear nueva factura de deposito en un expediente
*/
public function newInvoiceDepositAction($id, Request $request)
{
$docType = 'Factura de Deposito';
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(AveDocProformaDeposit::class)->findOneById($id);
$id = $proforma->getFileId();
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
}
// Buscamos el cliente
// Generamos la factura con la proforma especificada
$invoice = new AveDocInvoice();
$invoice->setAccessKey(md5(rand() * time()));
$invoice->setFileId($proforma->getFileId());
$invoice->setDateAt(new \DateTime("now"));
$invoice->setName($proforma->getName());
$invoice->setTotalNet($proforma->getAmount());
$invoice->setIva($proforma->getIva());
$invoice->setVat(($proforma->getAmount() * $proforma->getIva()) / 100);
$totalInv = $invoice->getTotalNet() + $invoice->getVat();
$invoice->setTotal($totalInv);
$invoice->setMaster(null);
$invoice->setNumber(null);
$invoice->setPrefix(null);
$invoice->setBalance($totalInv * (-1));
$invoice->setType('Factura de Deposito');
$invoice->setUpdatedId($user_id);
$invoice->setUpdatedAt(new \DateTime("now"));
$invoice->setCreatedId($user_id);
$invoice->setCreatedAt(new \DateTime("now"));
$em->persist($invoice);
$em->flush();
$bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount() * 0.21;
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($id);
$allProformas = null;
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy(array('invoiceToRec' => $invoice->getId()));
$boolToRec = empty($rectf);
return $this->redirectToRoute(
'ave_view_invoice_deposit',
array(
'id' => $invoice->getId()
)
);
}
/**
* @Route("/viewinvoicedeposit/{id}", name="ave_view_invoice_deposit")
* Ver una factura de deposito en un expediente
*/
public function viewInvoiceDepositAction($id, Request $request)
{
$docType = 'Factura de Deposito';
$em = $this->getDoctrine()->getManager();
$invoice = $em->getRepository(AveDocInvoice::class)->findOneById($id);
$id = $invoice->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Buscamos el cliente
// Obtengo usuario logueado
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($id);
$allInvoicesRec = $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
foreach ($allInvoicesRec as $item) {
array_push($allInvoices, $item);
}
$allProformas = null;
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy(array('invoiceToRec' => $invoice->getId()));
$boolToRec = empty($rectf);
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($id);
if ($fileAv->getCommentsInInv()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => null,
'company' => $company,
'clients' => $clientNew,
'file' => $file,
'date' => $invoice->getDateAt(),
'number' => $invoice->getId(),
'invoice' => $invoice,
'fid' => $invoice->getId(),
'boolToRec' => $boolToRec,
'proformas' => $allProformas,
'facturas' => $allInvoices,
'currency' => '€',
'user' => $user_logueado,
'totales_neto' => $invoice->getTotalNet(),
'totales' => $invoice->getTotal(),
'balance' => $invoice->getTotal(),
'bases_imponibles' => $bases_imponibles,
'services' => null,
// 'facturas' => null,
'paymentNotIvoiced' => null,
'paymentsAll' => null,
'totales_global_servicios_con_iva' => 0, //$data['totales_global_servicios_con_iva'],
'totales_global_servicios_neto' => 0, //$data['totales_global_servicios_neto'],
'totales_global_servicios_iva' => 0, //$data['totales_global_servicios_iva'],
'sumatoria_totales_global_con_iva' => 0, //$data['sumatoria_totales_global_con_iva'],
'sumatoria_totales_global_neto' => 0, //$data['sumatoria_totales_global_neto'],
'sumatoria_totales_global_iva' => 0, //$data['sumatoria_totales_global_iva'],
'comments' => $comments,
)
);
}
/**
* @Route("/avexternal/printinvoicedeposit/{id}", name="ave_print_invoice_deposit")
* Imprimir una factura de deposito
*/
public function printInvoiceDepositAction($id, Request $request)
{
$docType = 'Factura de Deposito';
$em = $this->getDoctrine()->getManager();
$invoice = $em->getRepository(AveDocInvoice::class)->findOneById($id);
$id = $invoice->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($id);
$allProformas = null;
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy(array('invoiceToRec' => $invoice->getId()));
$boolToRec = empty($rectf);
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($id);
if ($fileAv->getCommentsInPro()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => null,
'company' => $company,
'clients' => $clientNew,
'file' => $file,
'date' => $invoice->getDateAt(),
'number' => $invoice->getId(),
'invoice' => $invoice,
'fid' => $invoice->getId(),
'boolToRec' => $boolToRec,
'proformas' => $allProformas,
'facturas' => $allInvoices,
'currency' => '€',
'totales_neto' => $invoice->getTotalNet(),
'totales' => $invoice->getTotal(),
'balance' => $invoice->getTotal(),
'bases_imponibles' => $bases_imponibles,
'services' => null,
'paymentNotIvoiced' => null,
'paymentsAll' => null,
'totales_global_servicios_con_iva' => 0, //$data['totales_global_servicios_con_iva'],
'totales_global_servicios_neto' => 0, //$data['totales_global_servicios_neto'],
'totales_global_servicios_iva' => 0, //$data['totales_global_servicios_iva'],
'sumatoria_totales_global_con_iva' => 0, //$data['sumatoria_totales_global_con_iva'],
'sumatoria_totales_global_neto' => 0, //$data['sumatoria_totales_global_neto'],
'sumatoria_totales_global_iva' => 0, //$data['sumatoria_totales_global_iva'],
'comments' => $comments,
)
);
}
/**
* @Route("/newinvoicedepositrec/{id}", name="ave_invoice_deposit_rec")
* Crear nueva factura rectificativa de deposito
*/
public function newInvoiceDepositRecAction($id, Request $request)
{
$docType = 'Factura Rectificativa de Deposito';
$em = $this->getDoctrine()->getManager();
// Verificamos que no exista una factura rectificativa previa sobre la misma factura
$previusInvoiceRec = $em->getRepository(AveDocInvoiceRec::class)->findOneByInvoiceToRec($id);
if (!empty($previusInvoiceRec)) {
return $this->redirectToRoute('ave_view_invoice_deposit_rec', array('id' => $previusInvoiceRec->getId()));
}
$invoice = $em->getRepository(AveDocInvoice::class)->findOneById($id);
$id = $invoice->getFileId();
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Buscamos el cliente
// Generamos la factura con la proforma especificada
$invoiceRec = new AveDocInvoiceRec();
$invoiceRec->setFileId($invoice->getFileId());
$invoiceRec->setInvoiceToRec($invoice->getId());
$invoiceRec->setDateAt(new \DateTime("now"));
$invoiceRec->setName($invoice->getName());
$invoiceRec->setTotalNet($invoice->getTotalNet() * (-1));
$invoiceRec->setIva($invoice->getIva());
$invoiceRec->setVat((($invoice->getTotalNet() * $invoice->getIva()) / 100) * (-1));
$totalInv = $invoice->getTotalNet() + $invoice->getVat();
$invoiceRec->setTotal($totalInv * (-1));
$invoiceRec->setMaster(null);
$invoiceRec->setNumber(null);
// $invoiceRec->setPrefix(null);
$invoiceRec->setPrefix('R');
$invoiceRec->setBalance($totalInv);
$invoiceRec->setType('Factura Rectificativa de Deposito');
$invoiceRec->setUpdatedId($user_id);
$invoiceRec->setUpdatedAt(new \DateTime("now"));
$invoiceRec->setCreatedId($user_id);
$invoiceRec->setCreatedAt(new \DateTime("now"));
$em->persist($invoiceRec);
$em->flush();
return $this->redirectToRoute('ave_view_invoice_deposit_rec', array('id' => $invoiceRec->getId()));
}
/**
* @Route("/viewinvoicedepositrec/{id}", name="ave_view_invoice_deposit_rec")
* Ver una factura rectificativa de deposito
*/
public function viewInvoiceDepositRecAction($id, Request $request)
{
$docType = 'Factura Rectificativa de Deposito';
$em = $this->getDoctrine()->getManager();
$invoice = $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
$id = $invoice->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($id);
$allProformas = null;
// Una factura solo se puede rectificar una vez
// $rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
$boolToRec = false;
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($id);
if ($fileAv->getCommentsInInv()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
// Obtengo usuario logueado
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => null,
'company' => $company,
'clients' => $clientNew,
'file' => $file,
'date' => $invoice->getDateAt(),
'number' => $invoice->getId(),
'invoice' => $invoice,
'fid' => $invoice->getId(),
'boolToRec' => $boolToRec,
'proformas' => $allProformas,
'facturas' => $allInvoices,
'currency' => '€',
'totales_neto' => $invoice->getTotalNet(),
'totales' => $invoice->getTotal(),
'balance' => $invoice->getTotal(),
'bases_imponibles' => $bases_imponibles,
'user' => $user_logueado,
'services' => null,
// 'facturas' => null,
'paymentNotIvoiced' => null,
'paymentsAll' => null,
'totales_global_servicios_con_iva' => 0, //$data['totales_global_servicios_con_iva'],
'totales_global_servicios_neto' => 0, //$data['totales_global_servicios_neto'],
'totales_global_servicios_iva' => 0, //$data['totales_global_servicios_iva'],
'sumatoria_totales_global_con_iva' => 0, //$data['sumatoria_totales_global_con_iva'],
'sumatoria_totales_global_neto' => 0, //$data['sumatoria_totales_global_neto'],
'sumatoria_totales_global_iva' => 0, //$data['sumatoria_totales_global_iva'],
'comments' => $comments,
)
);
}
/**
* @Route("/avexternal/printinvoicedepositrec/{id}", name="ave_print_invoice_deposit_rec")
* Imprimir una factura rectificativa de deposito
*/
public function printInvoiceDepositRecAction($id, Request $request)
{
$docType = 'Factura Rectificativa de Deposito';
$em = $this->getDoctrine()->getManager();
$invoice = $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
$id = $invoice->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet() * 0.21;
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($id);
$allProformas = null;
// Una factura solo se puede rectificar una vez
// $rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
$boolToRec = false;
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($id);
if ($fileAv->getCommentsInPro()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => null,
'company' => $company,
'clients' => $clientNew,
'file' => $file,
'date' => $invoice->getDateAt(),
'number' => $invoice->getId(),
'invoice' => $invoice,
'fid' => $invoice->getId(),
'boolToRec' => $boolToRec,
'proformas' => $allProformas,
'facturas' => $allInvoices,
'currency' => '€',
'totales_neto' => $invoice->getTotalNet(),
'totales' => $invoice->getTotal(),
'balance' => $invoice->getTotal(),
'bases_imponibles' => $bases_imponibles,
'services' => null,
'paymentNotIvoiced' => null,
'paymentsAll' => null,
'totales_global_servicios_con_iva' => 0, //$data['totales_global_servicios_con_iva'],
'totales_global_servicios_neto' => 0, //$data['totales_global_servicios_neto'],
'totales_global_servicios_iva' => 0, //$data['totales_global_servicios_iva'],
'sumatoria_totales_global_con_iva' => 0, //$data['sumatoria_totales_global_con_iva'],
'sumatoria_totales_global_neto' => 0, //$data['sumatoria_totales_global_neto'],
'sumatoria_totales_global_iva' => 0, //$data['sumatoria_totales_global_iva'],
'comments' => $comments,
)
);
}
/**
* @Route("/selinvoice/{id}", name="ave_select_invoice")
* Seleccionar los items que pasaran a la proforma o factura
*/
public function selectItemsInvoiceAction($id, EntityManagerInterface $em, Request $request)
{
$paymentsClient = new AvePaymentsClient();
$paymentsClient->setFileId($id);
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$payments = $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
$allProformas = $em->getRepository(AveDocProforma::class)->findAll();
$number = (!empty($allProformas)) ? (end($allProformas)->getId() + 1) : 1;
$type = 'Proforma';
$docType = 'Proforma';
$date = new DateTime('now');
$prefix = "AVE-" . $date->format('dmy') . "-";
$fileInv = new AveDocInvoice();
$fileInv->setAccessKey(md5(rand() * time()));
$fileInv->setFileId($id);
$data = $this->baseInvoiceFile($id, $type, $number, $prefix, $date);
$token = $data['token'];
$idProducts = array();
if (array_key_exists('product', $data['datasupplier'])) {
foreach ($data['datasupplier']['product'] as $key => $item) {
$existe = $em->getRepository(AveDocInvoiceItems::class)->findOneByPrdControlId($item['id']);
if (empty($existe)) {
$data['datasupplier']['product'][$key]['enabledToInvoice'] = true;
} else {
$data['datasupplier']['product'][$key]['enabledToInvoice'] = false;
}
}
}
if (array_key_exists('service', $data['datasupplier'])) {
foreach ($data['datasupplier']['service'] as $key => $item) {
$existe = $em->getRepository(AveDocInvoiceItems::class)->findOneBySrvControlId($item['id']);
if (empty($existe)) {
$data['datasupplier']['service'][$key]['enabledToInvoice'] = true;
} else {
$data['datasupplier']['service'][$key]['enabledToInvoice'] = false;
}
}
}
$idPayments = array();
if (array_key_exists('payment', $data['datasupplier'])) {
foreach ($data['datasupplier']['payment'] as $key => $item) {
$existe = $em->getRepository(AveDocInvoiceItems::class)->findOneByPayControlId($item['id']);
if (empty($existe)) {
$data['datasupplier']['payment'][$key]['enabledToInvoice'] = true;
} else {
$data['datasupplier']['payment'][$key]['enabledToInvoice'] = false;
}
}
}
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-select-items.html.twig',
array(
'id' => $id,
'idLounges' => $idProducts,
'file' => $file,
'idPayments' => $idPayments,
'type' => $data['type'],
'docType' => $docType,
'number' => $data['number'],
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $token,
'company' => $data['company'],
'clients' => $data['clients'],
'datasupplier' => $data['datasupplier'],
'currency' => $data['currency'],
'totales_neto' => $data['totales_neto'],
'bases_imponibles' => $data['bases_imponibles'],
'totales' => $data['totales'],
'balance' => $data['balance'],
'paymentInvoice' => $data['paymentInvoice'],
'payments' => $payments,
'user_id' => $user_id,
)
);
}
/**
* @Route("/selproforma/{id}", name="ave_select_proforma")
* Seleccionar los items que pasaran a la proforma o factura a partir de los datos de una proforma
*/
public function selectItemsProformaAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
//Se cambia el ID de proforma a ID file
$proforma = $em->getRepository(AveDocProforma::class)->findOneById($id);
$id = $proforma->getFileId();
$proformaId = $proforma->getId();
$paymentsClient = new AvePaymentsClient();
$paymentsClient->setFileId($id);
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$payments = $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
$allProformas = $em->getRepository(AveDocProforma::class)->findAll();
if (!empty($allProformas)) {
$number = end($allProformas)->getId() + 1;
} else {
// Primer registro de proformas
$number = 1;
}
$type = 'Proforma';
$docType = 'Proforma';
$date = new DateTime('now');
$prefix = "AVE-" . $date->format('dmy') . "-";
$fileInv = new AveDocInvoice();
$fileInv->setAccessKey(md5(rand() * time()));
$fileInv->setFileId($id);
$data = $this->baseProformaSelect($id, $type, $number, $prefix, $date, $proformaId);
$token = $data['token'];
$idProducts = array();
if (array_key_exists('product', $data['datasupplier'])) {
foreach ($data['datasupplier']['product'] as $key => $item) {
$existe = $em->getRepository(AveDocInvoiceItems::class)->findOneByPrdControlId($item['id']);
if (empty($existe)) {
$data['datasupplier']['product'][$key]['enabledToInvoice'] = true;
} else {
$data['datasupplier']['product'][$key]['enabledToInvoice'] = false;
}
}
}
if (array_key_exists('service', $data['datasupplier'])) {
foreach ($data['datasupplier']['service'] as $key => $item) {
$existe = $em->getRepository(AveDocInvoiceItems::class)->findOneBySrvControlId($item['id']);
if (empty($existe)) {
$data['datasupplier']['service'][$key]['enabledToInvoice'] = true;
} else {
$data['datasupplier']['service'][$key]['enabledToInvoice'] = false;
}
}
}
$idPayments = array();
if (array_key_exists('payment', $data['datasupplier'])) {
foreach ($data['datasupplier']['payment'] as $key => $item) {
$existe = $em->getRepository(AveDocInvoiceItems::class)->findOneByPayControlId($item['id']);
if (empty($existe)) {
$data['datasupplier']['payment'][$key]['enabledToInvoice'] = true;
} else {
$data['datasupplier']['payment'][$key]['enabledToInvoice'] = false;
}
}
}
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-select-items.html.twig',
array(
'id' => $id,
'idLounges' => $idProducts,
'file' => $file,
'idPayments' => $idPayments,
'type' => $data['type'],
'docType' => $docType,
'number' => $data['number'],
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $token,
'company' => $data['company'],
'clients' => $data['clients'],
'datasupplier' => $data['datasupplier'],
'currency' => $data['currency'],
'totales_neto' => $data['totales_neto'],
'bases_imponibles' => $data['bases_imponibles'],
'totales' => $data['totales'],
'balance' => $data['balance'],
'paymentInvoice' => $data['paymentInvoice'],
'payments' => $payments,
'user_id' => $user_id,
)
);
}
/**
* @Route("/newmultiproforma/", name="ave_new_multi_proforma")
* Crear nueva proforma con los elementos seleccionados y retornar al selector
*/
public function generateNewMultiProformaAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
// Se genera y muestra en nueva pantalla la nueva proforma
$arrayBools = array(
'product' => null,
'service' => null,
'payment' => null,
);
$arrayBools['product'] = $request->request->get('multi_lounge_hidden_bool');
$arrayBools['service'] = $request->request->get('multi_service_hidden_bool');
$arrayBools['payment'] = $request->request->get('multi_payment_hidden_bool');
$id = $request->request->get('multi_file_id');
$proforma_number = $request->request->get('multi_proforma_number');
$proforma_prefix = $request->request->get('multi_proforma_prefix') . $proforma_number . '-' . $id;
//INICIO: buscamos el ID de la factura
$boolMakeInvoice = false; // Control para verificar si se debe hacer (PROFORMA) 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 proforma
if (!empty($arrayBools['product'])) {
foreach ($arrayBools['product'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$product = $em->getRepository(AveProductFile::class)->findOneById($key);
$boolKeyChange = false;
//INICIO: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
// Si el producto esta contenido en una proforma debemos crear un nuevo porducto
$productInProforma = $em->getRepository(AveDocProformaItems::class)->findOneByControlId($key);
if (!empty($productInProforma)) {
//INICIO: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
$boolKeyChange = true;
$newProductFile = new AveProductFile();
//INICIO: Duplicamos en Eventos
if (!empty($product->getOriginId())) {
$serviceEvent = $em->getRepository(ProposalSupplierServices::class)->findOneById($product->getOriginId());
if (!empty($serviceEvent)) {
$newServiceEvent = new ProposalSupplierServices();
$newServiceEvent->setServiceIdFather($serviceEvent->getServiceIdFather());
$newServiceEvent->setControlId($serviceEvent->getControlId());
$newServiceEvent->setProposalId($serviceEvent->getProposalId());
$newServiceEvent->setDestinationId($serviceEvent->getDestinationId());
$newServiceEvent->setSupplierId($serviceEvent->getSupplierId());
$newServiceEvent->setIdeaId($serviceEvent->getIdeaId());
$newServiceEvent->setActivityId($serviceEvent->getActivityId());
$newServiceEvent->setServiceId($serviceEvent->getServiceId());
$newServiceEvent->setServiceCatId($serviceEvent->getServiceCatId());
$newServiceEvent->setServiceCatName($serviceEvent->getServiceCatName());
$newServiceEvent->setName($serviceEvent->getName());
$newServiceEvent->setPrice($serviceEvent->getPrice());
$newServiceEvent->setCurrency($serviceEvent->getCurrency());
$newServiceEvent->setUnits($serviceEvent->getUnits());
$newServiceEvent->setCommission($serviceEvent->getCommission());
$newServiceEvent->setOver($serviceEvent->getOver());
$newServiceEvent->setIva($serviceEvent->getIva());
$newServiceEvent->setPax($serviceEvent->getPax());
$newServiceEvent->setHour($serviceEvent->getHour());
$newServiceEvent->setDateInAt($serviceEvent->getDateInAt());
$newServiceEvent->setDateOutAt($serviceEvent->getDateOutAt());
$newServiceEvent->setDirectPayment($serviceEvent->getDirectPayment());
$newServiceEvent->setStatus($serviceEvent->getStatus());
$newServiceEvent->setCreatedAt(new DateTime('now'));
$newServiceEvent->setCreatedId($user_id);
$newServiceEvent->setUpdatedAt(new DateTime('now'));
$newServiceEvent->setUpdatedId($user_id);
$newServiceEvent->setStatusinternal($serviceEvent->getStatusinternal());
$newServiceEvent->setPreCommission($serviceEvent->getPreCommission());
$newServiceEvent->setPreIva($serviceEvent->getPreIva());
$newServiceEvent->setDateBlockLimit($serviceEvent->getDateBlockLimit());
$newServiceEvent->setOpCommission($serviceEvent->getOpCommission());
$newServiceEvent->setOpOver($serviceEvent->getOpOver());
$newServiceEvent->setOpIva($serviceEvent->getOpIva());
$newServiceEvent->setBreakdown($serviceEvent->getBreakdown());
$newServiceEvent->setIsFather($serviceEvent->getIsFather());
$newServiceEvent->setRank($serviceEvent->getRank());
$newServiceEvent->setOriginalopIva($serviceEvent->getOriginalopIva());
$newServiceEvent->setOriginalIva($serviceEvent->getOriginalIva());
$newServiceEvent->setOriginalPrice($serviceEvent->getOriginalPrice());
$newServiceEvent->setStatusRec($serviceEvent->getStatusRec()); //setStatusRecommended
$newServiceEvent->setAssistantId($serviceEvent->getAssistantId());
$em->persist($newServiceEvent);
$em->flush();
}
if (!empty($serviceEvent)) {
$newProductFile->setOriginId($newServiceEvent->getId());
} else {
$newProductFile->setOriginId(null);
}
}
//FIN: Duplicamos en Eventos
//FIN: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
$newProductFile->setProductName($product->getProductName());
$newProductFile->setProductId($product->getProductId());
$newProductFile->setDateStart($product->getDateStart());
$newProductFile->setDateEnd($product->getDateEnd());
$newProductFile->setServicePrice($product->getServicePrice());
$newProductFile->setFileId($product->getFileId());
$newProductFile->setPax($product->getPax());
$newProductFile->setType($product->getType());
$newProductFile->setHourStart($product->getHourStart());
$newProductFile->setMinStart($product->getMinStart());
$newProductFile->setHourEnd($product->getHourEnd());
$newProductFile->setMinEnd($product->getMinEnd());
$newProductFile->setDescription($product->getDescription());
$newProductFile->setServiceIdProposal($product->getServiceIdProposal());
$newProductFile->setServiceIdFather($product->getServiceIdFather());
$newProductFile->setControlId($product->getControlId());
$newProductFile->setProposalId($product->getProposalId());
$newProductFile->setDestinationId($product->getDestinationId());
$newProductFile->setIdeaId($product->getIdeaId());
$newProductFile->setActivityId($product->getActivityId());
$newProductFile->setSupplierId($product->getSupplierId());
$newProductFile->setAssistantId($product->getAssistantId());
$newProductFile->setServiceId($product->getServiceId());
$newProductFile->setServiceCatId($product->getServiceCatId());
$newProductFile->setServiceCatName($product->getServiceCatName());
$newProductFile->setName($product->getName());
$newProductFile->setPrice($product->getPrice());
$newProductFile->setCurrency($product->getCurrency());
$newProductFile->setUnits($product->getUnits());
$newProductFile->setOpCommission($product->getOpCommission());
$newProductFile->setCommission($product->getCommission());
$newProductFile->setOpOver($product->getOpOver());
$newProductFile->setOver($product->getOver());
$newProductFile->setOpIva($product->getOpIva());
$newProductFile->setIva($product->getIva());
$newProductFile->setHour($product->getHour());
$newProductFile->setDateInAt($product->getDateInAt());
$newProductFile->setDateOutAt($product->getDateOutAt());
$newProductFile->setContcolor($product->getContcolor());
$newProductFile->setRank($product->getRank());
$newProductFile->setRenovate($product->getRenovate());
$newProductFile->setPay($product->getPay());
$newProductFile->setSubTotalPrice($product->getSubTotalPrice());
$newProductFile->setDays($product->getDays());
$newProductFile->setCreatedAt(new DateTime('now'));
$newProductFile->setCreatedId($user_id);
$newProductFile->setUpdatedAt(new DateTime('now'));
$newProductFile->setUpdatedId($user_id);
$em->persist($newProductFile);
$em->flush();
}
//FIN: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
$itemProforma = new AveDocProformaItems();
$itemProforma->setType('PRODUCT');
$itemProforma->setFileId($id);
$itemProforma->setProformaId($proforma_number);
if ($boolKeyChange) {
$itemProforma->setControlId($newProductFile->getId());
} else {
$itemProforma->setControlId($key);
}
$em->persist($itemProforma);
$em->flush();
//Acumulamos neto e iva para la factura (PROFORMA)
// $valorTotalNet = $valorTotalNet + $product->getServicePrice();
$valorTotalNet = $valorTotalNet + $product->getSubTotalPrice();
// $valorVat = $valorVat + round(($product->getServicePrice() * 0.21), 2, PHP_ROUND_HALF_UP);
$valorVat = $valorVat + round(($product->getSubTotalPrice() * 0.21), 2, PHP_ROUND_HALF_UP);
}
}
}
if (!empty($arrayBools['service'])) {
foreach ($arrayBools['service'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$servicio = $em->getRepository(AveServices::class)->findOneById($key);
$itemProforma = new AveDocProformaItems();
$itemProforma->setType('SERVICE');
$itemProforma->setFileId($id);
$itemProforma->setProformaId($proforma_number);
$itemProforma->setControlId($key);
$em->persist($itemProforma);
$em->flush();
//Acumulamos neto e iva para la factura
if (is_null($servicio->getPrice()) or empty($servicio->getPrice())) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $servicio->getPrice();
$subneto = $servicio->getPrice();
// Commission
if ($servicio->getOpCommission() == '1') {
$subtotalService = $subtotalService * (1 + ($servicio->getCommission() / 100));
$subneto = $subneto * (1 + ($servicio->getCommission() / 100));
} else {
$subtotalService = $subtotalService * (1 - ($servicio->getCommission() / 100));
$subneto = $subneto * (1 - ($servicio->getCommission() / 100));
}
// Over
if ($servicio->getOpOver() == '1') {
$subtotalService = $subtotalService + $servicio->getOver();
$subneto = $subneto + $servicio->getOver();
} else {
$subtotalService = $subtotalService - $servicio->getOver();
$subneto = $subneto - $servicio->getOver();
}
// IVA
if ($servicio->getOpIva() == '1') {
$subtotalService = $subtotalService * (1 + ($servicio->getIva() / 100));
} else {
$subtotalService = $servicio->getPrice();
$subneto = ($subneto * 100) / (100 + $servicio->getIva());
}
switch ($servicio->getServiceCatId()) {
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $servicio->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $servicio->getUnits();
break;
case 2: //Actividades
// El nĂºmero de personas es considerado en el calculo
$pax = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$subtotal = $subtotalService * $days * $servicio->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $servicio->getUnits();
break;
case 3: // AV
$pax = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = 1;
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 6*6*6 en GreenPatio no, pero en Develup ???
break;
case 11: //Menu
$pax = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = 1;
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->getUnits();
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($arrayBools['payment'])) {
foreach ($arrayBools['payment'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$pago = $em->getRepository(AvePaymentsClient::class)->findOneById($key);
$itemProforma = new AveDocProformaItems();
$itemProforma->setType('PAYMENT');
$itemProforma->setFileId($id);
$itemProforma->setProformaId($proforma_number);
$itemProforma->setControlId($key);
$em->persist($itemProforma);
$em->flush();
}
}
}
//FIN: Creamos los items de la proforma
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la proforma
$newProforma = new AveDocProforma();
$newProforma->setPrefix($proforma_prefix);
$newProforma->setDateAt(new DateTime('now'));
$newProforma->setFileId($id);
$newProforma->setCreatedAt(new DateTime('now'));
$newProforma->setCreatedId($user_id);
$newProforma->setUpdatedAt(new DateTime('now'));
$newProforma->setUpdatedId($user_id);
$newProforma->setItems(null);
$newProforma->setAccessKey(null);
if ($boolMakeInvoice) {
// Solo se debe crear proforma si hay un elemento
$em->persist($newProforma);
$em->flush();
} else {
// Se llama a la vista de editar el expediente
return $this->redirectToRoute('ave_edit_file', array('id' => $id));
}
//FIN: Creamos la proforma
return $this->redirectToRoute('ave_select_invoice', array('id' => $id));
}
/**
* @Route("/newproforma/", name="ave_new_proforma")
* Crear nueva proforma con los elementos seleccionados
*/
public function generateNewProformaAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
// Se genera y muestra en nueva pantalla la nueva proforma
$arrayBools = array(
'product' => null,
'service' => null,
'payment' => null,
);
$arrayBools['product'] = $request->request->get('lounge_hidden_bool');
$arrayBools['service'] = $request->request->get('service_hidden_bool');
$arrayBools['payment'] = $request->request->get('payment_hidden_bool');
$id = $request->request->get('file_id');
$proforma_number = $request->request->get('proforma_number');
$proforma_prefix = $request->request->get('proforma_prefix') . $proforma_number . '-' . $id;
//INICIO: buscamos el ID de la factura
$boolMakeInvoice = false; // Control para verificar si se debe hacer (PROFORMA) 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 proforma
if (!empty($arrayBools['product'])) {
foreach ($arrayBools['product'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$product = $em->getRepository(AveProductFile::class)->findOneById($key);
$boolKeyChange = false;
//INICIO: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
// Si el producto esta contenido en una proforma debemos crear un nuevo porducto
$productInProforma = $em->getRepository(AveDocProformaItems::class)->findOneByControlId($key);
$productInProforma = null; // Duplicacion innecesaria
if (!empty($productInProforma)) {
//INICIO: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
$boolKeyChange = true;
$newProductFile = new AveProductFile();
//INICIO: Duplicamos en Eventos
if (!empty($product->getOriginId())) {
$serviceEvent = $em->getRepository(ProposalSupplierServices::class)->findOneById($product->getOriginId());
if (!empty($serviceEvent)) {
$newServiceEvent = new ProposalSupplierServices();
$newServiceEvent->setServiceIdFather($serviceEvent->getServiceIdFather());
$newServiceEvent->setControlId($serviceEvent->getControlId());
$newServiceEvent->setProposalId($serviceEvent->getProposalId());
$newServiceEvent->setDestinationId($serviceEvent->getDestinationId());
$newServiceEvent->setSupplierId($serviceEvent->getSupplierId());
$newServiceEvent->setIdeaId($serviceEvent->getIdeaId());
$newServiceEvent->setActivityId($serviceEvent->getActivityId());
$newServiceEvent->setServiceId($serviceEvent->getServiceId());
$newServiceEvent->setServiceCatId($serviceEvent->getServiceCatId());
$newServiceEvent->setServiceCatName($serviceEvent->getServiceCatName());
$newServiceEvent->setName($serviceEvent->getName());
$newServiceEvent->setPrice($serviceEvent->getPrice());
$newServiceEvent->setCurrency($serviceEvent->getCurrency());
$newServiceEvent->setUnits($serviceEvent->getUnits());
$newServiceEvent->setCommission($serviceEvent->getCommission());
$newServiceEvent->setOver($serviceEvent->getOver());
$newServiceEvent->setIva($serviceEvent->getIva());
$newServiceEvent->setPax($serviceEvent->getPax());
$newServiceEvent->setHour($serviceEvent->getHour());
$newServiceEvent->setDateInAt($serviceEvent->getDateInAt());
$newServiceEvent->setDateOutAt($serviceEvent->getDateOutAt());
$newServiceEvent->setDirectPayment($serviceEvent->getDirectPayment());
$newServiceEvent->setStatus($serviceEvent->getStatus());
$newServiceEvent->setCreatedAt(new DateTime('now'));
$newServiceEvent->setCreatedId($user_id);
$newServiceEvent->setUpdatedAt(new DateTime('now'));
$newServiceEvent->setUpdatedId($user_id);
$newServiceEvent->setStatusinternal($serviceEvent->getStatusinternal());
$newServiceEvent->setPreCommission($serviceEvent->getPreCommission());
$newServiceEvent->setPreIva($serviceEvent->getPreIva());
$newServiceEvent->setDateBlockLimit($serviceEvent->getDateBlockLimit());
$newServiceEvent->setOpCommission($serviceEvent->getOpCommission());
$newServiceEvent->setOpOver($serviceEvent->getOpOver());
$newServiceEvent->setOpIva($serviceEvent->getOpIva());
$newServiceEvent->setBreakdown($serviceEvent->getBreakdown());
$newServiceEvent->setIsFather($serviceEvent->getIsFather());
$newServiceEvent->setRank($serviceEvent->getRank());
$newServiceEvent->setOriginalopIva($serviceEvent->getOriginalopIva());
$newServiceEvent->setOriginalIva($serviceEvent->getOriginalIva());
$newServiceEvent->setOriginalPrice($serviceEvent->getOriginalPrice());
$newServiceEvent->setStatusRec($serviceEvent->getStatusRec()); //setStatusRecommended
$newServiceEvent->setAssistantId($serviceEvent->getAssistantId());
$em->persist($newServiceEvent);
$em->flush();
}
if (!empty($serviceEvent)) {
$newProductFile->setOriginId($newServiceEvent->getId());
} else {
$newProductFile->setOriginId(null);
}
}
//FIN: Duplicamos en Eventos
//FIN: Si el producto esta sincronizado con un proposal debemos crear un servicio nuevo en el proposal
$newProductFile->setProductName($product->getProductName());
$newProductFile->setProductId($product->getProductId());
$newProductFile->setDateStart($product->getDateStart());
$newProductFile->setDateEnd($product->getDateEnd());
$newProductFile->setServicePrice($product->getServicePrice());
$newProductFile->setFileId($product->getFileId());
$newProductFile->setPax($product->getPax());
$newProductFile->setType($product->getType());
$newProductFile->setHourStart($product->getHourStart());
$newProductFile->setMinStart($product->getMinStart());
$newProductFile->setHourEnd($product->getHourEnd());
$newProductFile->setMinEnd($product->getMinEnd());
$newProductFile->setDescription($product->getDescription());
$newProductFile->setServiceIdProposal($product->getServiceIdProposal());
$newProductFile->setServiceIdFather($product->getServiceIdFather());
$newProductFile->setControlId($product->getControlId());
$newProductFile->setProposalId($product->getProposalId());
$newProductFile->setDestinationId($product->getDestinationId());
$newProductFile->setIdeaId($product->getIdeaId());
$newProductFile->setActivityId($product->getActivityId());
$newProductFile->setSupplierId($product->getSupplierId());
$newProductFile->setAssistantId($product->getAssistantId());
$newProductFile->setServiceId($product->getServiceId());
$newProductFile->setServiceCatId($product->getServiceCatId());
$newProductFile->setServiceCatName($product->getServiceCatName());
$newProductFile->setName($product->getName());
$newProductFile->setPrice($product->getPrice());
$newProductFile->setCurrency($product->getCurrency());
$newProductFile->setUnits($product->getUnits());
$newProductFile->setOpCommission($product->getOpCommission());
$newProductFile->setCommission($product->getCommission());
$newProductFile->setOpOver($product->getOpOver());
$newProductFile->setOver($product->getOver());
$newProductFile->setOpIva($product->getOpIva());
$newProductFile->setIva($product->getIva());
$newProductFile->setHour($product->getHour());
$newProductFile->setDateInAt($product->getDateInAt());
$newProductFile->setDateOutAt($product->getDateOutAt());
$newProductFile->setContcolor($product->getContcolor());
$newProductFile->setRank($product->getRank());
$newProductFile->setRenovate($product->getRenovate());
$newProductFile->setPay($product->getPay());
$newProductFile->setSubTotalPrice($product->getSubTotalPrice());
$newProductFile->setDays($product->getDays());
$newProductFile->setCreatedAt(new DateTime('now'));
$newProductFile->setCreatedId($user_id);
$newProductFile->setUpdatedAt(new DateTime('now'));
$newProductFile->setUpdatedId($user_id);
$em->persist($newProductFile);
$em->flush();
}
//FIN: Creamos el nuevo ProductFile para evitar cruce de datos entre proformas
$itemProforma = new AveDocProformaItems();
$itemProforma->setType('PRODUCT');
$itemProforma->setFileId($id);
$itemProforma->setProformaId($proforma_number);
if ($boolKeyChange) {
$itemProforma->setControlId($newProductFile->getId());
} else {
$itemProforma->setControlId($key);
}
$em->persist($itemProforma);
$em->flush();
//Acumulamos neto e iva para la factura (PROFORMA)
// $valorTotalNet = $valorTotalNet + $product->getServicePrice();
$valorTotalNet = $valorTotalNet + $product->getSubTotalPrice();
if ($product->getIva() == '21') {
$valorVat = $valorVat + round(($product->getSubTotalPrice() * 0.21), 2, PHP_ROUND_HALF_UP);
}
if ($product->getIva() == '10') {
$valorVat = $valorVat + round(($product->getSubTotalPrice() * 0.1), 2, PHP_ROUND_HALF_UP);
}
if ($product->getIva() == '0') {
$valorVat = $valorVat + round(($product->getSubTotalPrice() * 0), 2, PHP_ROUND_HALF_UP);
}
}
}
}
if (!empty($arrayBools['service'])) {
foreach ($arrayBools['service'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$servicio = $em->getRepository(AveServices::class)->findOneById($key);
$itemProforma = new AveDocProformaItems();
$itemProforma->setType('SERVICE');
$itemProforma->setFileId($id);
$itemProforma->setProformaId($proforma_number);
$itemProforma->setControlId($key);
$em->persist($itemProforma);
$em->flush();
//Acumulamos neto e iva para la factura
if (is_null($servicio->getPrice()) or empty($servicio->getPrice())) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $servicio->getPrice();
$subneto = $servicio->getPrice();
// Commission
if ($servicio->getOpCommission() == '1') {
$subtotalService = $subtotalService * (1 + ($servicio->getCommission() / 100));
$subneto = $subneto * (1 + ($servicio->getCommission() / 100));
} else {
$subtotalService = $subtotalService * (1 - ($servicio->getCommission() / 100));
$subneto = $subneto * (1 - ($servicio->getCommission() / 100));
}
// Over
if ($servicio->getOpOver() == '1') {
$subtotalService = $subtotalService + $servicio->getOver();
$subneto = $subneto + $servicio->getOver();
} else {
$subtotalService = $subtotalService - $servicio->getOver();
$subneto = $subneto - $servicio->getOver();
}
// IVA
if ($servicio->getOpIva() == '1') {
$subtotalService = $subtotalService * (1 + ($servicio->getIva() / 100));
} else {
$subtotalService = $servicio->getPrice();
$subneto = ($subneto * 100) / (100 + $servicio->getIva());
}
switch ($servicio->getServiceCatId()) {
case 1: // Alojamiento
// el numero de noches $numNoches; precio unitario $subneto
$numNoches = (($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days;
// La personas no afectan este calculo
$subtotal = $subtotalService * $numNoches * $servicio->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $numNoches * $servicio->getUnits();
break;
case 2: //Actividades
// El nĂºmero de personas es considerado en el calculo
$pax = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$subtotal = $subtotalService * $days * $servicio->getUnits();
$subnetoUnit = $subneto;
$subneto = $subneto * $days * $servicio->getUnits();
break;
case 3: // AV
$pax = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = 1;
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 6*6*6 en GreenPatio no, pero en Develup ???
break;
case 11: //Menu
$pax = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = 1;
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->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 = $servicio->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($servicio->getDateOutAt())->diff($servicio->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y') . ' - ' . ($servicio->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($servicio->getDateInAt())->format('d/m/Y');
}
$unitsServ = $servicio->getUnits();
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($arrayBools['payment'])) {
foreach ($arrayBools['payment'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$pago = $em->getRepository(AvePaymentsClient::class)->findOneById($key);
$itemProforma = new AveDocProformaItems();
$itemProforma->setType('PAYMENT');
$itemProforma->setFileId($id);
$itemProforma->setProformaId($proforma_number);
$itemProforma->setControlId($key);
$em->persist($itemProforma);
$em->flush();
}
}
}
//FIN: Creamos los items de la proforma
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la proforma
$newProforma = new AveDocProforma();
// $newProforma->setPrefix("GPP-".date('dmy')."-".$id);
$newProforma->setPrefix($proforma_prefix);
$newProforma->setDateAt(new DateTime('now'));
$newProforma->setFileId($id);
$newProforma->setCreatedAt(new DateTime('now'));
$newProforma->setCreatedId($user_id);
$newProforma->setUpdatedAt(new DateTime('now'));
$newProforma->setUpdatedId($user_id);
$newProforma->setItems(null);
$newProforma->setAccessKey(null);
if ($boolMakeInvoice) {
// Solo se debe crear proforma si hay un elemento
$em->persist($newProforma);
$em->flush();
} else {
// Se llama a la vista de editar el expediente
return $this->redirectToRoute('ave_edit_file', array('id' => $id));
}
//FIN: Creamos la proforma
return $this->redirectToRoute('ave_view_proforma', array('id' => $newProforma->getId()));
}
/**
* @Route("/discardproforma/{id}", name="ave_discard_proforma")
* Descartar la proforma especificada en el ID
*/
public function discardProformaAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(AveDocProforma::class)->findOneById($id);
$fileId = $proforma->getFileId();
//Buscamos en la tabla de proformas a enviar
$budToPro = $em->getRepository(AveBudgetToProforma::class)->findOneByProformaId($id);
if (!empty($budToPro)) {
$em->remove($budToPro);
$em->flush();
}
//Eliminamos los productos dentro de la proforma
$proformaItems = $em->getRepository(AveDocProformaItems::class)->findByProformaId($id);
foreach ($proformaItems as $item) {
$em->remove($item);
$em->flush();
}
//No se puede eliminar el registro porque es necesario mantener la numeraciĂ³n de las proformas si se desean generar correctamente
$proforma->setFileId(0);
$em->persist($proforma);
$em->flush();
return $this->redirectToRoute('ave_edit_file', array('id' => $fileId));
}
/**
* @Route("/viewproforma/{id}", name="ave_view_proforma")
* Ver una proforma
*/
public function viewProformaAction($id, Request $request)
{
$docType = 'Proforma';
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(AveDocProforma::class)->findOneById($id);
$id = $proforma->getFileId();
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Buscamos el cliente
$data = $this->baseInvoiceDoneDocument($file->getId(), $proforma->getId(), 'P');
$allProformas = $em->getRepository(AveDocProforma::class)->findByFileId($id);
// Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito //6*6*6
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($id);
if ($fileAv->getCommentsInPro()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
// Obtengo usuario logueado
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
//dd(
//
// 'id', $id,
// 'docType', $docType,
// 'proforma', $proforma,
// 'company', $company,
// 'clients', $clientNew,
// 'file', $file,
// 'date', $proforma->getDateAt(),
// 'number', $proforma->getId(),
// 'invoice', null,
// 'fid', $proforma->getId(),
// 'boolToRec', false,
// 'proformas', $allProformas,
// 'currency', '€',
// 'user', $user_logueado,
// 'totales_neto', $data['totales_neto'],
// 'totales', $data['totales'],
// 'balance', $data['balance'],
// 'bases_imponibles', $data['bases_imponibles'],
// 'datasupplier', $data['datasupplier']
//
//);
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => $proforma,
'company' => $company,
'clients' => $clientNew,
'file' => $file,
'date' => $proforma->getDateAt(),
'number' => $proforma->getId(),
'invoice' => null,
'fid' => $proforma->getId(),
'boolToRec' => false,
'proformas' => $allProformas,
'currency' => '€',
'user' => $user_logueado,
'totales_neto' => $data['totales_neto'],
'totales' => $data['totales'],
'balance' => $data['balance'],
'bases_imponibles' => $data['bases_imponibles'],
'datasupplier' => $data['datasupplier'],
'services' => null,
'facturas' => null,
'paymentNotIvoiced' => null,
'paymentsAll' => null,
'totales_global_servicios_con_iva' => 0, //$data['totales_global_servicios_con_iva'],
'totales_global_servicios_neto' => 0, //$data['totales_global_servicios_neto'],
'totales_global_servicios_iva' => 0, //$data['totales_global_servicios_iva'],
'sumatoria_totales_global_con_iva' => 0, //$data['sumatoria_totales_global_con_iva'],
'sumatoria_totales_global_neto' => 0, //$data['sumatoria_totales_global_neto'],
'sumatoria_totales_global_iva' => 0, //$data['sumatoria_totales_global_iva'],
'comments' => $comments,
)
);
}
/**
* @Route("/avexternal/printproforma/{id}", name="ave_print_proforma")
* Imprimir una proforma
*/
public function printProformaAction($id, Request $request)
{
$docType = 'Proforma';
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(AveDocProforma::class)->findOneById($id);
$id = $proforma->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
if ($id == 0) {
// La proforma ha sido descartada o eliminada desde AV
d('La proforma ha sido descartada o eliminada desde AV');
exit();
}
// Buscamos el cliente
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Buscamos el cliente
$data = $this->baseInvoiceDoneDocument($file->getId(), $proforma->getId(), 'P');
$allProformas = $em->getRepository(AveDocProformaDeposit::class)->findByFileId($id);
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($id);
if ($fileAv->getCommentsInPro()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => $proforma,
'company' => $company,
'clients' => $clientNew,
'file' => $file,
'date' => $proforma->getDateAt(),
'number' => $proforma->getId(),
'invoice' => null,
'fid' => $proforma->getId(),
'boolToRec' => false,
'proformas' => $allProformas,
'currency' => '€',
'totales_neto' => $data['totales_neto'],
'totales' => $data['totales'],
'balance' => $data['balance'],
'bases_imponibles' => $data['bases_imponibles'],
'datasupplier' => $data['datasupplier'],
'services' => null,
'facturas' => null,
'paymentNotIvoiced' => null,
'paymentsAll' => null,
'totales_global_servicios_con_iva' => 0, //$data['totales_global_servicios_con_iva'],
'totales_global_servicios_neto' => 0, //$data['totales_global_servicios_neto'],
'totales_global_servicios_iva' => 0, //$data['totales_global_servicios_iva'],
'sumatoria_totales_global_con_iva' => 0, //$data['sumatoria_totales_global_con_iva'],
'sumatoria_totales_global_neto' => 0, //$data['sumatoria_totales_global_neto'],
'sumatoria_totales_global_iva' => 0, //$data['sumatoria_totales_global_iva'],
'comments' => $comments,
)
);
}
/**
* @Route("/newinvoice/", name="ave_new_invoice")
* Crear nueva factura con los elementos seleccionados
*/
public function generateNewInvoiceAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
// Se genera y muestra en nueva pantalla la nueva proforma
$arrayBools = array(
'product' => null,
'service' => null,
'payment' => null,
);
$arrayBools['product'] = $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');
$id = $request->request->get('inv_file_id');
//INICIO: buscamos el ID de la factura
$allFacturas = $em->getRepository(AveDocInvoice::class)->findAll();
if (!empty($allFacturas)) {
$invoiceId = end($allFacturas)->getId() + 1;
} else {
$invoiceId = 1;
// $invoiceId = 10; //La primera factura de AV en el sistema serĂ¡ la 10, se cambia el numero de serie a A1, A2,...
}
$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['product'])) {
foreach ($arrayBools['product'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$sala = $em->getRepository(AveProductFile::class)->findOneById($key);
$itemInvoice = new AveDocInvoiceItems();
$itemInvoice->setFileId($id);
$itemInvoice->setInvoiceId($invoiceId);
$itemInvoice->setItemType('PRODUCT');
$itemInvoice->setPrdControlId($key);
$itemInvoice->setPrdName($sala->getProductName());
$itemInvoice->setPrdProductId($sala->getProductId());
$itemInvoice->setPrdType($sala->getType());
$itemInvoice->setPrdDateStart($sala->getDateStart());
$itemInvoice->setPrdDateEnd($sala->getDateEnd());
$itemInvoice->setPrdServicePrice($sala->getServicePrice());
$itemInvoice->setPrdSubTotalPrice($sala->getSubTotalPrice());
$itemInvoice->setPrdQty($sala->getUnits());
$itemInvoice->setPrdDays($sala->getDays());
$itemInvoice->setPrdPax($sala->getPax());
$itemInvoice->setCreatedId($user_id);
$itemInvoice->setCreatedAt(new DateTime('now'));
$itemInvoice->setUpdatedId($user_id);
$itemInvoice->setUpdatedAt(new DateTime('now'));
$itemInvoice->setPrdHourStart($sala->getHourStart());
$itemInvoice->setPrdMinStart($sala->getMinStart());
$itemInvoice->setPrdHourEnd($sala->getHourEnd());
$itemInvoice->setPrdMinEnd($sala->getMinEnd());
if (empty($sala->getLocation())) {
$itemInvoice->setLocation(null);
} else {
$itemInvoice->setLocation($sala->getLocation());
}
$itemInvoice->setRankAv($sala->getRankAv());
$itemInvoice->setPrdIva($sala->getIva());
$itemInvoice->setPrdOpIva($sala->getOpIva());
$em->persist($itemInvoice);
$em->flush();
//Acumulamos neto e iva para la factura
// $valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
$valorTotalNet = $valorTotalNet + $itemInvoice->getPrdSubTotalPrice();
// $valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
$valorVat = $valorVat + round(($itemInvoice->getPrdSubTotalPrice() * ($sala->getIva() / 100)), 2, PHP_ROUND_HALF_UP);
}
}
}
if (!empty($arrayBools['service'])) {
foreach ($arrayBools['service'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$servicio = $em->getRepository(AveServices::class)->findOneById($key);
$itemInvoice = new AveDocInvoiceItems();
$itemInvoice->setFileId($id);
$itemInvoice->setInvoiceId($invoiceId);
$itemInvoice->setItemType('SERVICE');
$itemInvoice->setSrvControlId($key);
$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);
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($arrayBools['payment'])) {
foreach ($arrayBools['payment'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$pago = $em->getRepository(AvePaymentsClient::class)->findOneById($key);
$itemInvoice = new AveDocInvoiceItems();
$itemInvoice->setFileId($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
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la factura
$newInvoice = new AveDocInvoice();
$newInvoice->setAccessKey(md5(rand() * time()));
$newInvoice->setNumber('AVE-' . date('dmy') . "-" . $id);
$newInvoice->setDateAt(new DateTime('now'));
$newInvoice->setType('Invoice');
$newInvoice->setFileId($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');
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('ave_view_invoice', array('id' => $id));
}
//FIN: Creamos la factura
$data = array();
$data = $this->baseInvoiceSelectedFile($id, $arrayBools, 'I' . $newInvoice->getId());
$paymentsClient = new AvePaymentsClient();
$paymentsClient->setFileId($id);
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$payments = $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
$services = $em->getRepository(AveServices::class)->findByFileId($id);
$proforma = $em->getRepository(AveDocProforma::class)->findOneByFileId($id);
$reservaInv = new AveDocInvoice();
$reservaInv->setAccessKey(md5(rand() * time()));
$reservaInv->setFileId($id);
$idProducts = array();
$productsBoolToInvoice = array();
if (array_key_exists('lounge', $data['datasupplier'])) {
foreach ($data['datasupplier']['lounge'] as $item) {
$idProducts[] = $item['id'];
$productsBoolToInvoice[] = 1;
}
$idProducts = implode(',', $idProducts);
$productsBoolToInvoice = implode(',', $productsBoolToInvoice);
} else {
$idProducts = '0';
$productsBoolToInvoice = '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';
}
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' . $newInvoice->getNumber()));
$boolToRec = empty($rectf);
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($id);
$allInvoicesRec = $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
foreach ($allInvoicesRec as $item) {
array_push($allInvoices, $item);
}
$allProformas = $em->getRepository(AveDocProforma::class)->findByFileId($id);
if (empty($data['type'])) {
$data['type'] = 'Invoice';
}
if (array_key_exists('paymentSubTotal', $data['datasupplier'])) {
$paymentInvoice = $data['datasupplier']['paymentSubTotal']['sumSubT'];
} else {
$paymentInvoice = 0;
}
$this->calculoBeneficiosDocumento($newInvoice->getId(), 'Invoice');
return $this->redirectToRoute(
'ave_view_invoice',
array(
'id' => $newInvoice->getId()
)
);
}
/**
* @Route("/newinvoicefromproforma/{id}", name="ave_new_invoice_from_proforma")
* Crear nueva factura con los elementos seleccionados en una proforma
*/
public function generateNewInvoiceFromProformaAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proformaOrigen = $em->getRepository(AveDocProforma::class)->findOneById($id);
//INICIO: Buscamos los elementos de la proforma y verificamos disponibilidad
$proformaOrigenItems = $em->getRepository(AveDocProformaItems::class)->findByProformaId($id);
$algunItemEstaFacturado = false;
foreach ($proformaOrigenItems as $item) {
if ($item->getType() == 'PRODUCT') {
$estaFacturado = $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getControlId());
if (!empty($estaFacturado)) {
$algunItemEstaFacturado = true;
}
}
if ($item->getType() == 'PAYMENT') {
$estaFacturado = $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getControlId());
if (!empty($estaFacturado)) {
$algunItemEstaFacturado = true;
}
}
if ($item->getType() == 'SERVICE') {
$estaFacturado = $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getControlId());
if (!empty($estaFacturado)) {
$algunItemEstaFacturado = true;
}
}
}
//FIN: Buscamos los elementos de la proforma y verificamos disponibilidad
// Obtengo usuario logueado
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
if ($algunItemEstaFacturado) {
$id = $proformaOrigen->getFileId();
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
array(
'id' => $id,
'docType' => 'Error Elementos ya Facturados',
'proforma' => '',
'company' => '',
'clients' => '',
'date' => '',
'number' => '',
'invoice' => null,
'fid' => '',
'boolToRec' => false,
'proformas' => '',
'currency' => '',
'totales_neto' => '',
'totales' => '',
'balance' => '',
'bases_imponibles' => '',
'user' => $user_logueado,
'comments' => null,
'services' => null,
'facturas' => null,
'paymentNotIvoiced' => null,
'paymentsAll' => null,
'totales_global_servicios_con_iva' => 0, //$data['totales_global_servicios_con_iva'],
'totales_global_servicios_neto' => 0, //$data['totales_global_servicios_neto'],
'totales_global_servicios_iva' => 0, //$data['totales_global_servicios_iva'],
'sumatoria_totales_global_con_iva' => 0, //$data['sumatoria_totales_global_con_iva'],
'sumatoria_totales_global_neto' => 0, //$data['sumatoria_totales_global_neto'],
'sumatoria_totales_global_iva' => 0, //$data['sumatoria_totales_global_iva'],
)
);
} else {
// Se genera y muestra en nueva pantalla la nueva proforma
$arrayBools = array(
'product' => null,
'service' => null,
'payment' => null,
);
foreach ($proformaOrigenItems as $item) {
if ($item->getType() == 'PRODUCT') {
$arrayBools['product'][$item->getControlId()] = 'true';
}
if ($item->getType() == 'SERVICE') {
$arrayBools['service'][$item->getControlId()] = 'true';
}
if ($item->getType() == 'PAYMENT') {
$arrayBools['payment'][$item->getControlId()] = 'true';
}
}
// $arrayBools['product'] = $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');
$id = $proformaOrigen->getFileId();
//INICIO: buscamos el ID de la factura
$allFacturas = $em->getRepository(AveDocInvoice::class)->findAll();
if (!empty($allFacturas)) {
$invoiceId = end($allFacturas)->getId() + 1;
} else {
$invoiceId = 1;
// $invoiceId = 10; //La primera factura de AV en el sistema serĂ¡ la 10, se cambia el numero de serie a A1, A2,...
}
$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['product'])) {
foreach ($arrayBools['product'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$sala = $em->getRepository(AveProductFile::class)->findOneById($key);
$itemInvoice = new AveDocInvoiceItems();
$itemInvoice->setFileId($id);
$itemInvoice->setInvoiceId($invoiceId);
$itemInvoice->setItemType('PRODUCT');
$itemInvoice->setPrdControlId($key);
$itemInvoice->setPrdName($sala->getProductName());
$itemInvoice->setPrdProductId($sala->getProductId());
$itemInvoice->setPrdProductId($sala->getProductId());
$itemInvoice->setPrdDateStart($sala->getDateStart());
$itemInvoice->setPrdType($sala->getType());
if (empty($sala->getLocation())) {
$itemInvoice->setLocation(null);
} else {
$itemInvoice->setLocation($sala->getLocation());
}
$itemInvoice->setRankAv($sala->getRankAv());
$itemInvoice->setPrdDateEnd($sala->getDateEnd());
$itemInvoice->setPrdServicePrice($sala->getServicePrice());
$itemInvoice->setPrdSubTotalPrice($sala->getSubTotalPrice());
$itemInvoice->setPrdQty($sala->getUnits());
$itemInvoice->setPrdPax($sala->getPax());
$itemInvoice->setPrdDays($sala->getDays());
$itemInvoice->setCreatedId($user_id);
$itemInvoice->setCreatedAt(new DateTime('now'));
$itemInvoice->setUpdatedId($user_id);
$itemInvoice->setUpdatedAt(new DateTime('now'));
$itemInvoice->setPrdHourStart($sala->getHourStart());
$itemInvoice->setPrdMinStart($sala->getMinStart());
$itemInvoice->setPrdHourEnd($sala->getHourEnd());
$itemInvoice->setPrdMinEnd($sala->getMinEnd());
$itemInvoice->setPrdIva($sala->getIva());
$itemInvoice->setPrdOpIva($sala->getOpIva());
$em->persist($itemInvoice);
$em->flush();
//Acumulamos neto e iva para la factura
// $valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
$valorTotalNet = $valorTotalNet + $itemInvoice->getPrdSubTotalPrice();
// $valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 0.21), 2, PHP_ROUND_HALF_UP);
$valorVat = $valorVat + round(($itemInvoice->getPrdSubTotalPrice() * 0.21), 2, PHP_ROUND_HALF_UP);
}
}
}
if (!empty($arrayBools['service'])) {
foreach ($arrayBools['service'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$servicio = $em->getRepository(AveServices::class)->findOneById($key);
$itemInvoice = new AveDocInvoiceItems();
$itemInvoice->setFileId($id);
$itemInvoice->setInvoiceId($invoiceId);
$itemInvoice->setItemType('SERVICE');
$itemInvoice->setSrvControlId($key);
$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);
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($arrayBools['payment'])) {
foreach ($arrayBools['payment'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$pago = $em->getRepository(AvePaymentsClient::class)->findOneById($key);
$itemInvoice = new AveDocInvoiceItems();
$itemInvoice->setFileId($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
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Creamos la factura
$newInvoice = new AveDocInvoice();
$newInvoice->setAccessKey(md5(rand() * time()));
$newInvoice->setNumber('AVE-' . date('dmy') . "-" . $id);
$newInvoice->setDateAt(new DateTime('now'));
$newInvoice->setType('Invoice');
$newInvoice->setFileId($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');
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('ave_view_invoice', array('id' => $id));
}
//FIN: Creamos la factura
$data = array();
$data = $this->baseInvoiceSelectedFile($id, $arrayBools, 'I' . $newInvoice->getId());
$paymentsClient = new AvePaymentsClient();
$paymentsClient->setFileId($id);
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$payments = $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
$services = $em->getRepository(AveServices::class)->findByFileId($id);
$proforma = $em->getRepository(AveDocProforma::class)->findOneByFileId($id);
$reservaInv = new AveDocInvoice();
$reservaInv->setAccessKey(md5(rand() * time()));
$reservaInv->setFileId($id);
$idProducts = array();
$productsBoolToInvoice = array();
if (array_key_exists('lounge', $data['datasupplier'])) {
foreach ($data['datasupplier']['lounge'] as $item) {
$idProducts[] = $item['id'];
$productsBoolToInvoice[] = 1;
}
$idProducts = implode(',', $idProducts);
$productsBoolToInvoice = implode(',', $productsBoolToInvoice);
} else {
$idProducts = '0';
$productsBoolToInvoice = '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';
}
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' . $newInvoice->getNumber()));
$boolToRec = empty($rectf);
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($id);
$allInvoicesRec = $em->getRepository(AveDocInvoiceRec::class)->findByFileId($id);
foreach ($allInvoicesRec as $item) {
array_push($allInvoices, $item);
}
$allProformas = $em->getRepository(AveDocProforma::class)->findByFileId($id);
if (empty($data['type'])) {
$data['type'] = 'Invoice';
}
if (array_key_exists('paymentSubTotal', $data['datasupplier'])) {
$paymentInvoice = $data['datasupplier']['paymentSubTotal']['sumSubT'];
} else {
$paymentInvoice = 0;
}
return $this->redirectToRoute(
'ave_view_invoice',
array(
'id' => $newInvoice->getId()
)
);
}
}
/**
* @Route("/viewinvoice/{id}", name="ave_view_invoice")
* Ver una factura
*/
public function viewNewInvoiceAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
// Se genera y muestra en nueva pantalla la nueva proforma
$arrayBools = array(
'product' => null,
'service' => null,
'payment' => null,
);
$arrayBools['product'] = $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(AveDocInvoiceItems::class)->findByInvoiceId($id);
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'PRODUCT') {
//Buscamos el iva
$zProductFile = $em->getRepository(AveProductFile::class)->findOneById($itemInvoice->getPrdControlId());
if (empty($zProductFile)) {
$zProductFile = $em->getRepository(AveProductFile::class)->findOneById((-1) * $itemInvoice->getPrdControlId());
}
$ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
if (!empty($itemInvoice->getPrdIva()) or ($itemInvoice->getPrdIva() == 0)) {
$ivaFactor = ($itemInvoice->getPrdIva()) / 100;
} // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
//Acumulamos neto e iva para la factura
// $valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
$valorTotalNet = $valorTotalNet + $itemInvoice->getPrdSubTotalPrice();
// $valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 0.21),2,PHP_ROUND_HALF_UP);
$valorVat = $valorVat + round(($itemInvoice->getPrdSubTotalPrice() * $ivaFactor), 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);
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') {
// $pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
//
// $itemInvoice = new ReservationInvoiceItems();
// $itemInvoice->setReservationId($id);
// $itemInvoice->setInvoiceId($invoiceId);
// $itemInvoice->setItemType('PAYMENT');
// $itemInvoice->setPayControlId($key);
// $itemInvoice->setPayAmount($pago->getAmount());
// $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
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Buscamos la factura
$newInvoice = $em->getRepository(AveDocInvoice::class)->findOneById($id);
//FIN: Buscamos la factura
$data = array();
$data = $this->baseInvoiceDoneFile($newInvoice->getFileId(), $id, 'I');
$paymentsClient = new AvePaymentsClient();
$paymentsClient->setFileId($id);
$fileInv = new AveDocInvoice();
$fileInv->setAccessKey(md5(rand() * time()));
$fileInv->setFileId($id);
$idProducts = array();
$productsBoolToInvoice = array();
if (array_key_exists('product', $data['datasupplier'])) {
foreach ($data['datasupplier']['product'] as $item) {
$idProducts[] = $item['id'];
$productsBoolToInvoice[] = 1;
}
$idProducts = implode(',', $idProducts);
$productsBoolToInvoice = implode(',', $productsBoolToInvoice);
} else {
$idProducts = '0';
$productsBoolToInvoice = '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';
}
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' . $newInvoice->getNumber()));
$boolToRec = empty($rectf);
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($newInvoice->getFileId());
$allInvoicesRec = $em->getRepository(AveDocInvoiceRec::class)->findByFileId($newInvoice->getFileId());
foreach ($allInvoicesRec as $item) {
array_push($allInvoices, $item);
}
$allProformas = $em->getRepository(AveDocProforma::class)->findByFileId($newInvoice->getFileId());
if (empty($data['type'])) {
$data['type'] = 'Invoice';
}
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($newInvoice->getFileId());
if ($fileAv->getCommentsInInv()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
array(
'id' => $newInvoice->getFileId(),
'cid' => '',
'fid' => $id,
'invoice' => $newInvoice,
'facturas' => $allInvoices,
'proformas' => $allProformas,
'boolToRec' => $boolToRec,
'numberadmin' => '',
'type' => $data['type'],
'docType' => 'Factura',
'number' => $newInvoice->getId(),
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $data['token'],
'file' => $data['file'],
'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'],
'comments' => $comments,
)
);
}
/**
* @Route("/avexternal/printinvoice/{id}", name="ave_print_invoice")
* Imprimir una factura
*/
public function printInvoiceAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
// Se genera y muestra en nueva pantalla la nueva proforma
$arrayBools = array(
'product' => null,
'service' => null,
'payment' => null,
);
$arrayBools['product'] = $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');
//Acumuladores de datos globales de la factura
$valorTotalNet = 0;
$valorVat = 0;
//INICIO: Creamos los items de la factura
$arrayInvoicedItems = $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
if (!empty($arrayInvoicedItems)) {
foreach ($arrayInvoicedItems as $itemInvoice) {
if ($itemInvoice->getItemType() == 'PRODUCT') {
//Acumulamos neto e iva para la factura
$valorTotalNet = $valorTotalNet + $itemInvoice->getPrdServicePrice();
$valorVat = $valorVat + round(($itemInvoice->getPrdServicePrice() * 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);
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') {
// $pago = $em->getRepository(ReservationPaymentsClient::class)->findOneById($key);
//
// $itemInvoice = new ReservationInvoiceItems();
// $itemInvoice->setReservationId($id);
// $itemInvoice->setInvoiceId($invoiceId);
// $itemInvoice->setItemType('PAYMENT');
// $itemInvoice->setPayControlId($key);
// $itemInvoice->setPayAmount($pago->getAmount());
// $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
}
}
}
//FIN: Creamos los items de la factura
$valorTotal = $valorTotalNet + $valorVat;
//INICIO: Buscamos la factura
$newInvoice = $em->getRepository(AveDocInvoice::class)->findOneById($id);
//FIN: Buscamos la factura
$data = array();
$data = $this->baseInvoiceDoneFile($newInvoice->getFileId(), $id, 'I');
$paymentsClient = new AvePaymentsClient();
$paymentsClient->setFileId($id);
$fileInv = new AveDocInvoice();
$fileInv->setAccessKey(md5(rand() * time()));
$fileInv->setFileId($id);
$idProducts = array();
$productsBoolToInvoice = array();
if (array_key_exists('product', $data['datasupplier'])) {
foreach ($data['datasupplier']['product'] as $item) {
$idProducts[] = $item['id'];
$productsBoolToInvoice[] = 1;
}
$idProducts = implode(',', $idProducts);
$productsBoolToInvoice = implode(',', $productsBoolToInvoice);
} else {
$idProducts = '0';
$productsBoolToInvoice = '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';
}
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(AveDocInvoiceRec::class)->findBy(array('number' => 'REC-' . $newInvoice->getNumber()));
$boolToRec = empty($rectf);
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($newInvoice->getFileId());
$allInvoicesRec = $em->getRepository(AveDocInvoiceRec::class)->findByFileId($newInvoice->getFileId());
foreach ($allInvoicesRec as $item) {
array_push($allInvoices, $item);
}
$allProformas = $em->getRepository(AveDocProforma::class)->findByFileId($newInvoice->getFileId());
if (empty($data['type'])) {
$data['type'] = 'Invoice';
}
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($newInvoice->getFileId());
if ($fileAv->getCommentsInInv()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
array(
'id' => $newInvoice->getFileId(),
'cid' => '',
'fid' => $id,
'invoice' => $newInvoice,
'facturas' => $allInvoices,
'proformas' => $allProformas,
'boolToRec' => $boolToRec,
'numberadmin' => '',
'type' => $data['type'],
'docType' => 'Factura',
'number' => $newInvoice->getId(),
'prefix' => $data['prefix'],
'date' => $data['date'],
'token' => $data['token'],
'file' => $data['file'],
'company' => $data['company'],
'clients' => $data['clients'],
'user' => '',
'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'],
'comments' => $comments,
)
);
}
/**
* @Route("/newinvoicerec/{id}", name="ave_new_invoice_rec")
* Crear una factura rectificativa
*/
public function generateNewInvoiceRecAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoice = $em->getRepository(AveDocInvoice::class)->findOneById($id);
$invoiceComAvGp = $em->getRepository(ReservationInvoice::class)->findOneByNumber('GPF-Automatic commission invoice-Av_File-'.$invoice->getFileId().'-Invoice-'.$invoice->getId());
if (empty($invoiceComAvGp)){
$invoiceComAvGp = $em->getRepository(CvrReservationInvoice::class)->findOneByNumber('GPF-Automatic commission invoice-Av_File-'.$invoice->getFileId().'-Invoice-'.$invoice->getId());
if (empty($invoiceComAvGp)) {
$invoiceComAvGp = $em->getRepository(BlvReservationInvoice::class)->findOneByNumber('GPF-Automatic commission invoice-Av_File-' . $invoice->getFileId() . '-Invoice-' . $invoice->getId());
}
}
//dd('$invoiceComAvGp', $invoiceComAvGp, 'id', $id,
//
// 'GPF-Automatic commission invoice-Av_File-'.$invoice->getFileId().'-Invoice-'.$invoice->getId()
//);
// Verificamos que no exista una factura rectificativa previa sobre la misma factura
$previusInvoiceRec = $em->getRepository(AveDocInvoiceRec::class)->findOneByInvoiceToRec($id);
if (!empty($previusInvoiceRec)) { return $this->redirectToRoute('ave_view_invoice_rec', 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 AveDocInvoiceRec();
$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('R');
$invoiceRec->setFileId($invoice->getFileId());
$invoiceRec->setTotal($invoice->getTotal() * (-1));
$invoiceRec->setTotalNet($invoice->getTotalNet() * (-1));
$invoiceRec->setType('Invoice Rec');
$invoiceRec->setVat($invoice->getVat() * (-1));
$invoiceRec->setBalance($invoice->getBalance() * (-1));
$em->persist($invoiceRec);
$em->flush();
$invoiceItems = $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
// Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
foreach ($invoiceItems as $item) {
$itemRec = new AveDocInvoiceRecItems();
$itemRec->setFileId($item->getFileId());
$itemRec->setInvoiceId($item->getInvoiceId());
$itemRec->setItemType($item->getItemType());
$itemRec->setInvoiceRecId($invoiceRec->getId());
$itemRec->setLocation($item->getLocation());
$itemRec->setRankAv($item->getRankAv());
$itemRec->setPrdControlId($item->getPrdControlId());
$itemRec->setPrdName($item->getPrdName());
$itemRec->setPrdProductId($item->getPrdProductId());
$itemRec->setPrdDateStart($item->getPrdDateStart());
$itemRec->setPrdDateEnd($item->getPrdDateEnd());
$itemRec->setPrdServicePrice($item->getPrdServicePrice() * (-1));
$itemRec->setPrdSubTotalPrice($item->getPrdSubTotalPrice() * (-1));
$itemRec->setPrdQty($item->getPrdQty());
$itemRec->setPrdDays($item->getPrdDays());
$itemRec->setPrdPax($item->getPrdPax());
$itemRec->setPrdType($item->getPrdType());
$itemRec->setPrdHourStart($item->getPrdHourStart());
$itemRec->setPrdMinStart($item->getPrdMinStart());
$itemRec->setPrdHourEnd($item->getPrdHourEnd());
$itemRec->setPrdMinEnd($item->getPrdMinEnd());
$itemRec->setPrdIva($item->getPrdIva());
$itemRec->setPrdOpIva($item->getPrdOpIva());
$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());
$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->setPayControlId($item->getPayControlId());
$itemRec->setPayAmount($item->getPayAmount() * (-1));
$itemRec->setPayDatePayAt($item->getPayDatePayAt());
$itemRec->setPayWayToPay($item->getPayWayToPay());
$itemRec->setPayAmountTotal($item->getPayAmountTotal() * (-1));
$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();
$item->setPrdControlId((-1) * $item->getPrdControlId());
$item->setSrvControlId((-1) * $item->getSrvControlId());
$item->setPayControlId((-1) * $item->getPayControlId());
$em->persist($item);
$em->flush();
}
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($invoice->getFileId());
$allInvoicesRec = $em->getRepository(AveDocInvoiceRec::class)->findByFileId($invoice->getFileId());
foreach ($allInvoicesRec as $item) { array_push($allInvoices, $item); }
$file = $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
$client = $em->getRepository(Client::class)->findOneById($file->getClient());
$data = array();
$data = $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $invoiceRec->getId(), 'R');
$data['clients'][0] = $client;
$data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Se elimina la ComisiĂ³n de AV a GreenPatio y la factura de comision
$aveFile = $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
$reserva = $em->getRepository(Reservation::class)->findOneById($aveFile->getReservation());
$description = $id.' - ComisiĂ³n MANTE de Green Patio (Generado automaticamente)';
$benSup = $em->getRepository(AveBenefitsSupplier::class)->findOneByDescription($description); // Beneficio de Green Patio sobre una factura
if(!empty($benSup)){
$em->remove($benSup);
$em->flush();
}
if(!empty($invoiceComAvGp)){
$dataService = $this->commisionEnterpriseService->rectCommissionAvExpressGreenPatio($invoice->getId(), $user_id);
}
$this->calculoBeneficiosDocumento($invoiceRec->getId(), 'Invoice Rec');
return $this->redirectToRoute( 'ave_view_invoice_rec', array('id' => $invoiceRec->getId()));
}
/**
* @Route("/viewinvoicerec/{id}", name="ave_view_invoice_rec")
* Ver una factura rectificativa
*/
public function viewInvoiceRecAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoiceRec = $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$invoiceItems = $em->getRepository(AveDocInvoiceRecItems::class)->findByInvoiceId($id);
// Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($invoiceRec->getFileId());
$allInvoicesRec = $em->getRepository(AveDocInvoiceRec::class)->findByFileId($invoiceRec->getFileId());
foreach ($allInvoicesRec as $item) { array_push($allInvoices, $item); }
$file = $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
$data = array();
$data = $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $id, 'R');
$data['clients'] = $client;
$data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Una factura solo se puede rectificar una vez
// $rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$invoice->getNumber()));
$boolToRec = false;
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
if ($fileAv->getCommentsInInv()) { $commentsBool = true; }
if ($commentsBool) { $comments = $fileAv->getComments(); }
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep.html.twig',
array(
'id' => $invoiceRec->getFileId(),
'cid' => '',
'fid' => $invoiceRec->getId(),
'invoice' => $invoiceRec,
'facturas' => $allInvoices,
'boolToRec' => $boolToRec,
'numberadmin' => '',
'type' => 'Invoice Rec',
'docType' => 'Factura Rectificativa',
'number' => $invoiceRec->getId(),
'prefix' => '',
'date' => $invoiceRec->getDateAt(),
'invoiceIdToRec' => $invoiceRec->getInvoiceToRec(),
'token' => '',
'file' => $file,
'company' => $data['company'],
'clients' => $clientNew,
'user' => $user_logueado,
'invoicedeposititems' => '',
'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'],
'comments' => $comments,
)
);
}
/**
* @Route("/avexternal/printinvoicerec/{id}", name="ave_print_invoice_rec")
* Imprimir una factura rectificativa
*/
public function printInvoiceRecAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoiceRec = $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
$invoiceItems = $em->getRepository(AveDocInvoiceRecItems::class)->findByInvoiceId($id);
$allInvoices = $em->getRepository(AveDocInvoice::class)->findByFileId($invoiceRec->getFileId());
$allInvoicesRec = $em->getRepository(AveDocInvoiceRec::class)->findByFileId($invoiceRec->getFileId());
foreach ($allInvoicesRec as $item) {
array_push($allInvoices, $item);
}
$file = $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
$client = $em->getRepository(Client::class)->findOneById($file->getClient());
$data = array();
$data = $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $invoiceRec->getId(), 'R');
$data['clients'][0] = $client;
$data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
// Una factura solo se puede rectificar una vez
// $rectf = $em->getRepository(ReservationInvoiceRec::class)->findBy( array('number' => 'REC-'.$invoice->getNumber()));
$boolToRec = false;
$commentsBool = false;
$comments = null;
$fileAv = $em->getRepository(AveFiles::class)->findOneById($invoiceRec->getFileId());
if ($fileAv->getCommentsInPro()) {
$commentsBool = true;
}
if ($commentsBool) {
$comments = $fileAv->getComments();
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-proforma-invdep-print.html.twig',
array(
'id' => $invoiceRec->getFileId(),
'cid' => '',
'fid' => $invoiceRec->getId(),
'invoice' => $invoiceRec,
'facturas' => $allInvoices,
'boolToRec' => $boolToRec,
'numberadmin' => '',
'type' => 'Invoice Rec',
'docType' => 'Factura Rectificativa',
'number' => $invoiceRec->getId(),
'prefix' => '',
'date' => $invoiceRec->getDateAt(),
'invoiceIdToRec' => $invoiceRec->getInvoiceToRec(),
'token' => '',
'file' => $file,
'company' => $data['company'],
'clients' => $data['clients'],
'user' => '',
'invoicedeposititems' => '',
'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'],
'comments' => $comments,
)
);
}
/**
* @Route("/listinvoice/", name="ave_list_invoices")
* Listar facturas
*/
public function listInvoicesAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoiced = $em->getRepository(AveDocInvoice::class)->findAll();
$invoicedRec = $em->getRepository(AveDocInvoiceRec::class)->findAll();
// Agregamos las rectificativas al arreglo de facturas con el indice "R(id)"
foreach ($invoicedRec as $idRecArray => $item) {
$invoiced['R' . $item->getId()] = $item;
}
$sumatoriaTotalNet = 0;
$sumatoriaTotalVat = 0;
$sumatoriaTotal = 0;
foreach ($invoiced as $idArray => $item) {
$file = $em->getRepository(AveFiles::class)->findOneById($item->getFileId());
$invoiced[$idArray]->setNumber(is_null($file) ? 0 : $file->getTitle());
$client = is_null($file) ? '' : $em->getRepository(Client::class)->findOneById($file->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(AvePaymentsClient::class)->findOneByInvoiceId($item->getId());
if (!empty($payOfInvoiceDeposit)) {
// Verificamos si el deposito esta dentro de una factura
$itemInvoiceOfInvoiceDeposit = $em->getRepository(AveDocInvoiceItems::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(AveDocInvoiceRecItems::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(AveDocInvoiceRecItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
}
if (!empty($itemInvoiceOfInvoiceDepositRec)) {
$estaEnFacturaRectificativa = true;
}
// FIN: Verificamos factura de deposito dentro de alguna factura
$invoicedDepositItems = $em->getRepository(AveDocInvoiceItems::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();
}
}
return $this->render(
'MDS/AvexpressBundle/Avexpress/invoice-list.html.twig',
array(
'invocied' => $invoiced,
'sumatoriaTotalNet' => $sumatoriaTotalNet,
'sumatoriaTotalVat' => $sumatoriaTotalVat,
'sumatoriaTotal' => $sumatoriaTotal,
)
);
}
/**
* @Route("/listpendingbud/", name="ave_list_pending_bud")
* Listar presupuestos pendientes para aprobar y los pendientes por facturar
*/
public function listPendingBudgetsAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$pendingBuds = $em->getRepository(AveBudgetPending::class)->findAll();
$pBuds = array();
$budInPro = array();
// Creamos la agrupacion por proposal
foreach ($pendingBuds as $item) {
if (!(array_key_exists($item->getProposalId(), $pBuds))) {
if (!empty($item->getOriginId())) { // Los vacios solo contienen briefings
$pBuds[$item->getProposalId()] = null;
}
}
}
// Metemos los items en el arreglo clasificado por proposal
foreach ($pendingBuds as $item) {
if (!empty($item->getOriginId())) { // Los vacios solo contienen briefings
$pBuds[$item->getProposalId()][] = $item;
}
}
ksort($pBuds);
$keysPbuds = array_keys($pBuds);
$budToProforma = $em->getRepository(AveBudgetToProforma::class)->findBy(
array(
'status' => 'Confirmed', // Pending -> Tosend -> Confirmed -> Invoiced
)
);
$budToInvoice = array();
foreach ($budToProforma as $item) {
if (!array_key_exists($item->getFileId(), $budToInvoice)) {
$budToInvoice[$item->getFileId()] = null;
}
}
foreach ($budToProforma as $item) {
$budToInvoice[$item->getFileId()]['file'] = $em->getRepository(AveFiles::class)->findOneById($item->getFileId());
// INICIO: Agrupamos las proformas y dentro ponemos los items de cada una
//Obtenemos el Id de la proforma que contiene el producto
$idPro = $em->getRepository(AveDocProformaItems::class)->findOneByControlId($item->getProductFileId());
$idPro = $idPro->getProformaId();
// Guardamos la info del agente
$budToInvoice[$item->getFileId()]['agente'] = $item->getUserConfirmedFullName();
$budToInvoice[$item->getFileId()]['idAgente'] = $item->getUserConfirmedId();
//Buscamos el elemento que va dentro de la proforma
$elemento = $em->getRepository(AveProductFile::class)->findOneById($item->getProductFileId());
$budToInvoice[$item->getFileId()]['proformas'][$idPro][] = $elemento;
// FIN: Agrupamos las proformas y dentro ponemos los items de cada una
}
ksort($budToInvoice);
//INICIO: Buscamos los budgets que ya se han metido en proformas
$budInProforma = $em->getRepository(AveBudgetToProforma::class)->findBy(
array(
'status' => 'Tosend', // Pending -> Tosend -> Confirmed -> Invoiced
)
);
$budInPro = array();
foreach ($budInProforma as $item) {
$budInPro[$item->getFileId()]['file'] = $em->getRepository(AveFiles::class)->findOneById($item->getFileId());
// INICIO: Agrupamos las proformas y dentro ponemos los items de cada una
//Obtenemos el Id de la proforma que contiene el producto
$idPro = $em->getRepository(AveDocProformaItems::class)->findOneByControlId($item->getProductFileId());
$idPro = $idPro->getProformaId();
// Guardamos la info del agente
$budInPro[$item->getFileId()]['agente'] = $item->getUserConfirmedFullName();
$budInPro[$item->getFileId()]['idAgente'] = $item->getUserConfirmedId();
//Buscamos el elemento que va dentro de la proforma
$elemento = $em->getRepository(AveProductFile::class)->findOneById($item->getProductFileId());
if (!empty($elemento)) {
$budInPro[$item->getFileId()]['proformas'][$idPro][] = $elemento;
if (empty($budInPro[$item->getFileId()]['proformasMontos'][$idPro])) {
$budInPro[$item->getFileId()]['proformasMontos'][$idPro] = $elemento->getServicePrice() * 1.21;
} else {
$budInPro[$item->getFileId()]['proformasMontos'][$idPro] = $budInPro[$item->getFileId()]['proformasMontos'][$idPro] + $elemento->getServicePrice() * 1.21;
}
}
// FIN: Agrupamos las proformas y dentro ponemos los items de cada una
}
ksort($budInPro);
//Verificamos que no haya expedientes sin elementos (proformas)
foreach ($budInPro as $key => $item) {
if (!array_key_exists('proformas', $item)) {
if (sizeof($budInPro) == 1) {
unset($budInPro, $key);
$budInPro = array();
} else {
unset($budInPro, $key);
}
}
}
//FIN: Buscamos los budgets que ya se han metido en proformas
//Buscamos los budgets que solo contienen Briefing
$briefings = $em->getRepository(AveBudgetPending::class)->findBy(
array(
'serviceId' => null, // Pending -> Tosend -> Confirmed -> Invoiced
)
);
return $this->render(
'MDS/AvexpressBundle/Avexpress/list-budgets-pending.html.twig',
array(
'pendingBudgets' => $pBuds,
'keysPendingBudgets' => $keysPbuds,
'budToInvoice' => $budToInvoice,
'budInProforma' => $budInPro,
'briefings' => $briefings,
)
);
}
/**
* @Route("/budgetadd/", name="ave_list_budget_add")
* Crear los presupuestos (proformas) y los expedientes (si es necesario)
*/
public function budgetsAddAction(Request $request)
{
$services = $request->request->get('services_hidden');
$backToEditFile = $request->request->get('backToEditFile');
$logTelegram = false;
//Modificar precios en Eventos (si es necesario)
foreach ($services as $item) {
$em = $this->getDoctrine()->getManager();
$pendingBud = $em->getRepository(AveBudgetPending::class)->findOneById($item['id']);
//INICIO: Creamos el expediente de AVEXPRESS (en caso de ser necesario)
$file = $em->getRepository(AveFiles::class)->findOneByIdProposal($pendingBud->getProposalId());
if (empty($file)) {
$file = new AveFiles();
if (array_key_exists('proposalTitle', $item)) {
$file->setTitle($pendingBud->getProposalId() . ' -- ' . $item['proposalTitle']);
} else {
if (array_key_exists('title', $item)) {
$file->setTitle($item['title']);
} else {
$file->setTitle($pendingBud->getProposalId() . ' - ');
}
}
$file->setClient('262'); // 262 es In Out Travel & Events
$file->setPriority(null);
$file->setSupplier(null);
$file->setStatus('Confirmed');
$file->setDaysBlock(null);
$file->setAdvancePayment(null);
$file->setIdProposal($pendingBud->getProposalId());
$file->setCateringName(null);
$file->setBoolCatering(null);
$file->setDateStart(null);
$file->setDateEnd(null);
$file->setPax(null);
$file->setDeposit(null);
$file->setAccessKey(null);
$file->setDescription(null);
$file->setCreatedAt(new DateTime('now'));
$file->setCreatedId(14); // Usuario de Salvador Guerrero
$file->setUpdatedAt(new DateTime('now'));
$file->setUpdatedId(14); // Usuario de Salvador Guerrero
$em->persist($file);
$em->flush();
//Actualizamos los Briefings que esten en FileId null con el recien generado fileId en base al proposalId
$allBriefings = $em->getRepository(AveBriefings::class)->findByProposalId($file->getIdProposal());
foreach ($allBriefings as $itemBrief) {
if (empty($itemBrief->getFileId())) {
$itemBrief->setFileId($file->getId());
$em->persist($itemBrief);
$em->flush();
}
}
}
//FIN: Creamos el expediente de AVEXPRESS (en caso de ser necesario)
//INICIO: Creamos el producto dentro del expediente
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$newProductFile = new AveProductFile();
if (!($pendingBud->getStatusinternal() == 'AV TEMPLATE')) {
$aveProductSelected = $em->getRepository(AveProduct::class)->findOneById($pendingBud->getServiceId());
$newProductFile->setProductName($aveProductSelected->getName());
if (!empty($item['price'])) {
$newProductFile->setServicePrice($item['price']);
if (!($item['price'] == $aveProductSelected->getPrice())) {
// Se ha modificado el precio en el presupuesto y se debe cambiar en el origen (Proposal de eventos)
$itemOrigin = $em->getRepository(ProposalSupplierServices::class)->findOneById($pendingBud->getOriginId());
if (!empty($itemOrigin)) {
$itemOrigin->setPrice($item['price']);
$em->persist($itemOrigin);
$em->flush();
}
}
} else {
// Si el precio viene vacio tomamos el valor por defecto del producto
$newProductFile->setServicePrice($aveProductSelected->getPrice());
}
//Unidades
if (!empty($item['units'])) {
$newProductFile->setUnits($item['units']);
if (!($item['units'] == 1)) {
// Se ha modificado el numero de unidades en el presupuesto y se debe cambiar en el origen (Proposal de eventos)
$itemOrigin = $em->getRepository(ProposalSupplierServices::class)->findOneById($pendingBud->getOriginId());
if (!empty($itemOrigin)) {
$itemOrigin->setUnits($item['units']);
$itemOrigin->setUnits(1);
$em->persist($itemOrigin);
$em->flush();
}
}
} else {
// Si las unidades viene vacio tomamos el valor por defecto del producto
$newProductFile->setUnits('1');
}
$newProductFile->setSubTotalPrice($newProductFile->getServicePrice() * $newProductFile->getUnits());
} else {
// Es un Template
$aveProductSelected = $em->getRepository(AveTemplateItems::class)->findOneById($pendingBud->getServiceId());
// d($pendingBud,$pendingBud->getServiceId(),$aveProductSelected);
$newProductFile->setProductName($aveProductSelected->getProductName());
$newProductFile->setServicePrice($aveProductSelected->getServicePrice());
$newProductFile->setUnits($aveProductSelected->getUnits());
$newProductFile->setSubTotalPrice($aveProductSelected->getSubTotalPrice());
$newProductFile->setSupplierExt($aveProductSelected->getSupplierExt());
$newProductFile->setSupplierExtId($aveProductSelected->getSupplierExtId());
$newProductFile->setUnits($aveProductSelected->getUnits());
$newProductFile->setOpCommission($aveProductSelected->getOpCommission());
$newProductFile->setCommission($aveProductSelected->getCommission());
$newProductFile->setOpOver($aveProductSelected->getOpOver());
$newProductFile->setOver($aveProductSelected->getOver());
$newProductFile->setOpIva($aveProductSelected->getOpIva());
$newProductFile->setIva($aveProductSelected->getIva());
$newProductFile->setDays($aveProductSelected->getDays());
}
$newProductFile->setProductId($aveProductSelected->getId());
$newProductFile->setOriginId($pendingBud->getOriginId());
$newProductFile->setDescription($aveProductSelected->getDescription());
$newProductFile->setFileId($file->getId());
if (true) { // No recibimos fechas // (!empty($newRequest['dateStart'])) {
$newProductFile->setDateStart(new DateTime('now')); //$newRequest['dateStart'].' '.$newRequest['hourStart']));
}
if (true) { // No recibimos fechas // (!empty($newRequest['dateEnd'])) {
$newProductFile->setDateEnd(new DateTime('now')); // (new \DateTime($newRequest['dateStart'].' '.$newRequest['hourEnd']));
}
$newProductFile->setCreatedId($user_id);
$newProductFile->setUpdatedId($user_id);
$newProductFile->setCreatedAt(new DateTime('now'));
$newProductFile->setUpdatedAt(new DateTime('now'));
$em->persist($newProductFile);
$em->flush();
$logTelegram = true;
//FIN: Creamos el producto dentro del expediente
//INICIO: Creamos una orden de hacer proforma
$order = new AveBudgetToProforma();
$order->setStatus('Pending');
$order->setFileId($file->getId());
$order->setProductFileId($newProductFile->getId());
$order->setUserConfirmedId($pendingBud->getUserConfirmedId());
$order->setUserConfirmedFullName($pendingBud->getUserConfirmedFullName());
$order->setProposalTitle($pendingBud->getProposalTitle());
$em->persist($order);
$em->flush();
//FIN: Creamos una orden de hacer proforma
// Se elimina el presupuesto pendiente
$em->remove($pendingBud);
$em->flush();
}
//INICIO: Creamos el presupuesto (proforma)
$budToPro = $em->getRepository(AveBudgetToProforma::class)->findByStatus('Pending');
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
// $arrayIdPro = array(); // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
//INICIO: Se agrupan por expediente (fileId)
$proformas = array();
foreach ($budToPro as $item) {
$proformas[$item->getFileId()][] = $item;
}
//FIN: Se agrupan por expediente (fileId)
if (empty($backToEditFile)) { // Las proforma no se creara si venimos de editar file
if (!empty($budToPro)) {
foreach ($proformas as $key => $elemento) {
//INICIO: Creamos las proformas
//INICIO: Calculamos el ID de la proforma
$numberToPrefix = $em->getRepository(AveDocProforma::class)->findAll();
if (empty($numberToPrefix)) {
$numberToPrefix = 0;
} else {
$numberToPrefix = end($numberToPrefix)->getId();
}
$numberToPrefix++;
//FIN: Calculamos el ID de la proforma
$newProforma = new AveDocProforma();
$newProforma->setPrefix('AVE-' . (new DateTime('now'))->format('dmy') . '-' . $numberToPrefix . '-' . $key);
$newProforma->setDateAt(new DateTime('now'));
$newProforma->setFileId($key);
$newProforma->setCreatedId($user_id);
$newProforma->setUpdatedId($user_id);
$newProforma->setCreatedAt(new DateTime('now'));
$newProforma->setUpdatedAt(new DateTime('now'));
$em->persist($newProforma);
$em->flush();
//FIN: Creamos las proformas
foreach ($elemento as $item) {
//$key es el id del expediente
// $arrayIdPro[$numberToPrefix] = $item->getUserConfirmedId(); // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
//INICIO: Creamos los elemento que iran dentro de las proformas
$itemProforma = new AveDocProformaItems();
$itemProforma->setType('PRODUCT');
$itemProforma->setFileId($key);
$itemProforma->setProformaId($newProforma->getId());
$itemProforma->setControlId($item->getProductFileId());
$em->persist($itemProforma);
$em->flush();
//INICIO: Confirmamos el BudToProforma
$item->setStatus('Tosend'); // El elemento se ha pasado a la proforma, solo falta enviar
$item->setProformaId($newProforma->getId());
$em->persist($item);
$em->flush();
//FIN: Confirmamos el BudToProforma
//FIN: Creamos los elemento que iran dentro de las proformas
}
}
}
}
//INICIO: Notificamos al agente por Telegram
if ($logTelegram) {
//Buscamos todos los agentes del proposal
$proposalAgents = $em->getRepository(ProposalAgents::class)->findOneByIdProp($file->getIdProposal());
//Buscamos el Destino
// $proposalDestino = $em->getRepository(Destination::class)->findOneById($control->getDestinoId());
//Buscamos el agente de Develup
$userData = $em->getRepository(User::class)->findOneById($user_id);
if (!empty($proposalAgents)) {
if ((!empty($proposalAgents->getAgOne())) and (!($proposalAgents->getAgOne() == 0))) {
$this->sendTelegram($proposalAgents->getAgOne(), '1. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' . $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' . $userData->getName() . ' ' . $userData->getLastName());
}
if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))) {
$this->sendTelegram($proposalAgents->getAgTwo(), '2. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' . $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' . $userData->getName() . ' ' . $userData->getLastName());
}
if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))) {
$this->sendTelegram($proposalAgents->getAgThree(), '3. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' . $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' . $userData->getName() . ' ' . $userData->getLastName());
}
if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))) {
$this->sendTelegram($proposalAgents->getAgFour(), '4. PRESUPUESTO APROBADO DESDE AVEXPRESS __ ID: ' . $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' . $userData->getName() . ' ' . $userData->getLastName());
}
}
}
//FIN: Notificamos al agente por Telegram
//FIN: Creamos el presupuesto (proforma)
if (!empty($backToEditFile)) {
return $this->redirectToRoute('ave_edit_file', array('id' => $backToEditFile));
}
return $this->redirectToRoute('ave_list_pending_bud');
}
/**
* @Route("/budgetsend/", name="ave_budget_send")
* Envio automatico de los presupuestos forzado por usuario
*/
public function budgetSendAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$budToPro = $em->getRepository(AveBudgetToProforma::class)->findByStatus('Tosend');
$logTelegram = false;
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$arrayIdPro = array(); // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
//INICIO: Se agrupan por expediente (fileId)
$proformas = array();
foreach ($budToPro as $item) {
$proformas[$item->getFileId()][] = $item;
// $fileDevelup = $item->getFileId();
}
//FIN: Se agrupan por expediente (fileId)
if (!empty($budToPro)) {
foreach ($proformas as $key => $elemento) {
//INICIO: Creamos las proformas
foreach ($elemento as $item) {
//$key es el id del expediente
if (!empty($item->getProformaId())) {
$arrayIdPro[$item->getProformaId()] = $item->getUserConfirmedId(); // $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
}
//INICIO: Confirmamos el BudToProforma
$item->setStatus('Confirmed'); // El elemento se ha pasado a confirmado porque se enviara por correo
$em->persist($item);
$em->flush();
//FIN: Confirmamos el BudToProforma
//FIN: Creamos los elemento que iran dentro de las proformas
}
}
}
//INICIO: Notificamos de todos los presupuestos (proformas) que se han creado
foreach ($arrayIdPro as $key => $item) {
$logTelegram = true;
//Buscamos los agentes a notificar
// $arrayIdPro['X'] = 'Y'; al agente 'Y' se le informa del presupuesto 'X'
$agent = $em->getRepository(User::class)->findOneById($item);
$agentMail = $agent->getEmail();
$mailAgent = $agentMail;
// $mailAgent = 'gustavo.ayala@develup.solutions';
//Se prepara el correo con los agentes a notificar
$firmGmail = $agent->getFirmGmail();
$data = array(
'body' => 'Presupuesto AvExpress #' . $key . ', ' . '<br><a href="http://' . $request->server->get('HTTP_HOST') . '/pdf/avexpressproforma/' . $key . '">Ver el PDF del presupuesto</a><br><br>NotificaciĂ³n de nuevo presupuesto: Este presupuesto ha sido creado de forma automatica.' . '<br><br>',
'firm' => $firmGmail,
);
// EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
$transporter = new Swift_SmtpTransport();
$transporter->setHost('smtp.gmail.com')
->setEncryption('ssl') //ssl / tls
->setPort(465) // 465 / 587
->setUsername('desarrollo@develup.solutions')
->setPassword('utvh hzoi wfdo ztjs');
$mailer = new Swift_Mailer($transporter);
$message = new Swift_Message();
$message->setSubject('Presupuesto #' . $key . ', NotificaciĂ³n de nuevo presupuesto')
->setSender($agentMail)
->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
->setReplyTo($agentMail)
->setTo($mailAgent)
->setBody(
$this->renderView(
'mail/structure-mail.html.twig',
array('data' => $data)
),
'text/html'
);
$mailer->send($message);
//INICIO: Notificamos al agente por Telegram
if ($logTelegram) {
//Buscamos el id proposal a partir del id de la proforma
$prof = $em->getRepository(AveDocProforma::class)->findOneById($key);
$file = $em->getRepository(AveFiles::class)->findOneById($prof->getFileId());
//Buscamos todos los agentes del proposal
$proposalAgents = $em->getRepository(ProposalAgents::class)->findOneByIdProp($file->getIdProposal());
//Buscamos el Destino
// $proposalDestino = $em->getRepository(Destination::class)->findOneById($control->getDestinoId());
//Buscamos el agente de AvExpress
$userData = $em->getRepository(User::class)->findOneById($user_id);
if (!empty($proposalAgents)) {
if ((!empty($proposalAgents->getAgOne())) and (!($proposalAgents->getAgOne() == 0))) {
$this->sendTelegram($proposalAgents->getAgOne(), '1. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' . $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' . $userData->getName() . ' ' . $userData->getLastName());
}
if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))) {
$this->sendTelegram($proposalAgents->getAgTwo(), '2. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' . $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' . $userData->getName() . ' ' . $userData->getLastName());
}
if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))) {
$this->sendTelegram($proposalAgents->getAgThree(), '3. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' . $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' . $userData->getName() . ' ' . $userData->getLastName());
}
if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))) {
$this->sendTelegram($proposalAgents->getAgFour(), '4. PRESUPUESTO DE AVEXPRESS ENVIADO POR CORREO __ ID: ' . $file->getIdProposal() . ' __ PROVEEDOR: AvExpress __ CONTACTO: ' . $userData->getName() . ' ' . $userData->getLastName());
}
}
}
//FIN: Notificamos al agente por Telegram
}
//FIN: Notificamos de todos los presupuestos (proformas) que se han creado
return $this->redirectToRoute('ave_list_pending_bud');
}
/**
* @Route("/budgetdel/{id}", name="ave_list_budget_del")
* Eliminar el producto de la solicitud de presupuesto
*/
public function budgetsDeleteAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$budget = $em->getRepository(AveBudgetPending::class)->findOneById($id);
$proposal_services_supplier = $em->getRepository(ProposalSupplierServices::class)->findOneById($budget->getOriginId());
// Se elimina el servicio de In Out
if (!empty($proposal_services_supplier)) {
$em->remove($proposal_services_supplier);
$em->flush();
}
// Se elimina el servicio del presupuesto
$em->remove($budget);
$em->flush();
return $this->redirectToRoute('ave_list_pending_bud');
}
/**
* @Route("/newinvoicefrombudget/{id}", name="ave_new_invoice_from_budget")
* Crear nueva factura desde un presupuesto (proforma)
*/
public function generateNewInvoiceFromBudgetAction($id, Request $request)
{
// Antes de redirigir a la funcion que crea presupuesto a partir de proformas se deben modificar las tablas de los presupuestos
$em = $this->getDoctrine()->getManager();
// Buscamos los elementos de la proforma
$elemProf = $em->getRepository(AveDocProformaItems::class)->findByProformaId($id);
$fileId = $elemProf[0]->getFileId();
// Buscamos los elementos de budgetToProforma para cambiar su status a Invoiced
// los que pertenezcan a la proforma y a Discard los que pertenezcan a otra proforma
$elemBudToProf = $em->getRepository(AveBudgetToProforma::class)->findByFileId($fileId);
foreach ($elemBudToProf as $key => $item) {
//con los $item busco en $elemBudToProf para poner invoiced
foreach ($elemProf as $elem) {
if ($elem->getControlId() == $item->getProductFileId()) {
// Se debe poner en Invoiced
$item->setStatus('Invoiced');
}
}
// Si al terminar de revisar el status sigue en Confirmado, lo pasaremos
// a descartado, es un elemento de un presupuesto que no fue aprobado
// mientras que otro presupuesto si fue aprobado y paso a facturacion.
// Al estar descartado no se muestra mas el presupuesto en los listados
// aunque la proforma sigue existiendo.
if ($item->getStatus() == 'Confirmed') {
$item->setStatus('Discarded');
}
$em->persist($item);
$em->flush();
}
return $this->redirectToRoute('ave_new_invoice_from_proforma', array('id' => $id));
}
/**
* @Route("/budgetdiscard/{id}", name="ave_budget_discard")
* Crear nueva factura desde un presupuesto (proforma)
*/
public function discardBudgetAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
// Buscamos los elementos de la proforma
$elemProf = $em->getRepository(MdvDocProformaItems::class)->findByProformaId($id);
foreach ($elemProf as $item) {
// Buscamos los elementos de budgetToProforma para cambiar su status a Discarded
$elemBudToProf = $em->getRepository(AveBudgetToProforma::class)->findOneByProductFileId($item->getControlId());
$elemBudToProf->setStatus('Discarded');
$em->persist($item);
$em->flush();
}
return $this->redirectToRoute('ave_list_pending_bud');
}
/**
* @Route("/updateinvoicedate/", name="ave_update_invoice_date")
* Actualizar servicios develup desde inout events (Controlador inaccesible)
*/
public function updateInvoiceDateAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoiceId = $request->request->get('invoice_id');
$invoiceNewDate = $request->request->get('new_invoice_date');
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$invoice = $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
$newDate = new DateTime($invoiceNewDate);
$invoice->setDateAt($newDate);
// Modificamos el number para que se adapte a la nueva fecha
$invoice->setNumber('AVE-' . $newDate->format('dmy') . substr($invoice->getNumber(), 10));
$invoice->setUpdatedId($user_id);
$invoice->setUpdatedAt(new DateTime('now'));
$em->persist($invoice);
$em->flush();
return $this->redirectToRoute('ave_list_invoices');
}
/**
* @Route("/budgetbriefdiscard/{id}", name="ave_budget_briefing_discard")
* Eliminar un budget que es de tipo Briefing
*/
public function budgetBriefDiscardAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$pendingBud = $em->getRepository(AveBudgetPending::class)->findOneById($id);
// Se elimina el presupuesto pendiente
$em->remove($pendingBud);
$em->flush();
return $this->redirectToRoute('ave_list_pending_bud');
}
/**
* @Route("/sendinvoicemail/", name="ave_send_invoice_mail")
* Enviar enlace de la factura al cliente con copia
*/
public function sendInvoiceMailAction(Request $request)
{
$fileId = $request->request->get('fileId');
$invoiceId = $request->request->get('invoiceId');
$ccToMail = $request->request->get('ccToMail');
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$mailArrayTo = array();
$mailArrayTo['salvador@avexpress.tv'] = 'salvador@avexpress.tv';
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(AveFiles::class)->findOneById($fileId);
$invoice = $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
if (!empty($file->getClient())) {
$client = $em->getRepository(Client::class)->findOneById($file->getClient());
if (!empty($client->getEmail())) {
$mailArrayTo[$client->getEmail()] = $client->getEmail();
}
}
if (!empty($ccToMail)) {
$mailArrayTo[$ccToMail] = $ccToMail;
}
$agente = $em->getRepository(User::class)->findOneById($user_id);
$mailAddressFrom = $agente->getEmail();
$mailSubject = 'Factura del expediente: ' . $file->getTitle();
$mailBody = 'Estimado cliente,' .
'<br><br> En el siguiente enlace ponemos a su disposiciĂ³n la factura del expediente: ' .
'<br><br><a href="https://inout.mante.solutions/pdf/avexpressinvoiceext/' . $invoice->getAccessKey() . '">Ver la factura</a>' .
'<br><br>Muchas gracias por confiar en nuestros servicios.<br><br>';
$this->sendMailLot($mailAddressFrom, $mailArrayTo, $mailSubject, $mailBody);
return $this->redirectToRoute('ave_edit_file', array('id' => $fileId));
}
/**
* @Route("/filltokens/", name="ave_fill_tokens")
* Llenar el campo token
*/
public function fillTokensAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoices = $em->getRepository(AveDocInvoice::class)->findAll();
foreach ($invoices as $item) {
if (empty($item->getAccessKey())) {
$item->setAccessKey(md5(rand() * time()));
$em->persist($item);
$em->flush();
}
}
exit();
}
/**
* @Route("/sendatch/", name="ave_sendatch")
* prueba de envio de correo con datos adjuntos
*/
public function sendAtchAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$mailBody = 'Mensaje del correo';
$mailArrayTo = array();
$mailAddressFrom = 'gustavo.ayala@develup.solutions';
$mailSubject = 'Asunto del correo';
$agent = $em->getRepository(User::class)->findOneByEmail($mailAddressFrom);
$replyTo = array();
foreach ($mailArrayTo as $item) {
// Verificamos que los correos sean validos
if (filter_var($item, FILTER_VALIDATE_EMAIL)) {
$replyTo[$item] = $item;
}
}
$agentMail = $mailAddressFrom;
$mailAgent = $agentMail;
//Se prepara el correo con los agentes a notificar
$firmGmail = $agent->getFirmGmail();
$data = array(
'body' => $mailBody,
'firm' => $firmGmail,
);
// EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
$transporter = new Swift_SmtpTransport();
$transporter->setHost('smtp.gmail.com')
->setEncryption('ssl') //ssl / tls
->setPort(465) // 465 / 587
->setUsername('desarrollo@develup.solutions')
->setPassword('utvh hzoi wfdo ztjs');
$mailer = new Swift_Mailer($transporter);
$message = new Swift_Message();
$message->setSubject($mailSubject)
->setSender($agentMail)
->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
->setReplyTo($agentMail)
->setTo($replyTo)
->setBody(
$this->renderView(
'mail/structure-mail.html.twig',
array('data' => $data)
),
'text/html'
);
$message->attach(Swift_Attachment::fromPath('http://site.tld/logo.png'));
$mailer->send($message);
exit();
}
/**
* @Route("/maketableinfo/", name="ave_make_table_info")
* crea la info de la tabla AveBenefitsInvoiceInvoiceRec
*/
public function aveBenefitsAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
if (true) {
//Buscamos todas las facturas
$invoices = $em->getRepository(AveDocInvoice::class)->findAll();
foreach ($invoices as $invoice) {
// Verificamos si esta ya en la tabla
$isInTable = $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneBy(array('docId' => $invoice->getId(), 'docType' => 'Invoice'));
// Solo se hace en facturas, se descartan facturas de deposito ya que estas no se consideran ventas reales (Isa)
if ($invoice->getType() == 'Invoice') {
// Solo creamos si no existe en la tabla
if (empty($isInTable)) {
$this->calculoBeneficiosDocumento($invoice->getId(), 'Invoice');
}
}
}
}
if (true) {
//Buscamos todas las facturas rectificativas
$invoices = $em->getRepository(AveDocInvoiceRec::class)->findAll();
foreach ($invoices as $invoice) {
// Verificamos si esta ya en la tabla
// $isInTable = $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByDocId($invoice->getId());
$isInTable = $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneBy(array('docId' => $invoice->getId(), 'docType' => 'Invoice Rec'));
// Solo se hace en facturas, se descartan facturas de deposito ya que estas no se consideran ventas reales (Isa)
if ($invoice->getType() == 'Invoice Rec') {
// Solo creamos si no existe en la tabla
if (empty($isInTable)) {
$this->calculoBeneficiosDocumento($invoice->getId(), 'Invoice Rec');
}
}
}
}
d('Fin del procesamiento');
exit();
}
/**
* @Route("/openbenefitssuppliers/{id}", name="ave_open_benefits_suppliers")
* abre el expediente para permitir escritura AveBenefitsInvoiceInvoiceRec
*/
public function aveOpenBenefitsSuppliersAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$benefits = $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByFileId($id);
if (!empty($benefits)) {
$benefits->setBenefitEuro(0);
$benefits->setBenefitPerc(0);
$em->persist($benefits);
$em->flush();
}
$benefitsPer = $em->getRepository(AveBenefitsPermissions::class)->findOneByFileId($id);
if (empty($benefitsPer)) {
$benefitsPer = new AveBenefitsPermissions();
$benefitsPer->setCreatedId($user_id);
$benefitsPer->setCreatedAt(new \DateTime("now"));
}
$benefitsPer->setStatus('Open');
$benefitsPer->setFileId($id);
$benefitsPer->setUpdatedId($user_id);
$benefitsPer->setUpdatedAt(new \DateTime("now"));
$em->persist($benefitsPer);
$em->flush();
return $this->redirectToRoute('ave_supplier_list', array('id' => $id));
}
/**
* @Route("/closebenefitssuppliers/{id}", name="ave_close_benefits_suppliers")
* cierra el expediente para crear su AveBenefitsInvoiceInvoiceRec
*/
public function aveCloseBenefitsSuppliersAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$benefitsOLD = $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findBy(
array(
'fileId' => $id,
'docType' => 'Invoice',
)
);
if (!empty($benefitsOLD)) {
if (!(($benefitsOLD[0]->getClientName() == 'Green Patio') and ($benefitsOLD[0]->getClientId() == 2556))) {
$this->calculoBeneficiosDocumento($benefitsOLD[0]->getDocId(), $benefitsOLD[0]->getDocType());
$em->remove($benefitsOLD[0]);
$em->flush();
}
}
$benefitsPer = $em->getRepository(AveBenefitsPermissions::class)->findOneByFileId($id);
if (!empty($benefitsPer)) {
$benefitsPer->setStatus('Close');
$benefitsPer->setUpdatedId($user_id);
$benefitsPer->setUpdatedAt(new \DateTime("now"));
$em->persist($benefitsPer);
$em->flush();
}
return $this->redirectToRoute('ave_supplier_list', array('id' => $id));
}
private function baseInvoiceFile($id, $type, $number, $prefix, $date)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => null,
);
// Buscamos las salas reservadas, pagos y servicios para el evento
// Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
$allProductFile = $em->getRepository(AveProductFile::class)->findByFileId($id);
$arrayLocation = [];
$arrayLocationWithNull = false;
foreach ($allProductFile as $item) {
if (!empty($item->getLocation())) {
$arrayLocation[$item->getLocation()] = $item->getLocation();
} else {
$arrayLocationWithNull = true;
}
}
if ($arrayLocationWithNull) { $arrayLocation['null'] = 'null'; }
$productsInFile = [];
foreach ($arrayLocation as $item) {
// VIDEO
$parameters = array(
'fileId' => $id,
'type' => 'VĂdeo',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $id,
'type' => 'Sonido',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $id,
'type' => 'IluminaciĂ³n',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// PAQUETE
$parameters = array(
'fileId' => $id,
'type' => 'Paquete',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFilePackage = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $id,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'typeP' => 'Paquete',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.type != :typeP AND i.location = :location)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $id,
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE (i.fileId = :fileId AND i.type IS NULL AND i.location = :location)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
// Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
if ($item == 'null') {
// VIDEO
$parameters = array(
'fileId' => $id,
'type' => 'VĂdeo',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $id,
'type' => 'Sonido',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $id,
'type' => 'IluminaciĂ³n',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// PAQUETE
// $parameters = array(
// 'fileId' => $id,
// 'type' => 'Paquete',
// 'location' => '',
// );
// $dql = 'SELECT i
// FROM AvexpressBundle:AveProductFile i
// WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location)
// ORDER BY i.rankAv ASC';
// $query = $em->createQuery($dql)->setParameters($parameters);
// $productsInFilePackage = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $id,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE (i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND (i.location IS NULL OR i.location = :location))
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $id,
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
WHERE (i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location))
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
}
$productsInFile = array_merge($productsInFile, $productsInFileVid, $productsInFileSound, $productsInFileLights, $productsInFileOther, $productsInFileNull);
}
$payments = $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
$services = $em->getRepository(AveServices::class)->findByFileId($id);
$data_supplier = [];
$i = 0;
$product = 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 ($productsInFile as $item) {
$days = ((($item->getDateEnd())->diff($item->getDateStart()))->days + 1);
// Verificamos que el producto no se encuentre ya en una factura
$existe = $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getId());
$pax = $item->getPax();
$qty = $item->getUnits();
if (!empty($item->getDays())) { $days = $item->getDays(); }
if (is_null($item->getServicePrice()) or empty($item->getServicePrice()) or !empty($existe)) {
$subtotal = $neto = $subtotalProduct = 0;
} else {
$subtotalProduct = 0;
if ($item->getIva() == '21') {
$subtotalProduct = $item->getSubTotalPrice() * 1.21;
} // Iva a 21%
if ($item->getIva() == '10') {
$subtotalProduct = $item->getSubTotalPrice() * 1.1;
} // Iva a 10%
if ($item->getIva() == '0') {
$subtotalProduct = $item->getSubTotalPrice() * 1;
} // Iva a 0%
$subneto = $item->getSubTotalPrice();
$subtotal = $subtotalProduct;
$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);
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
if ($item->getIva() == '21') {
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21);
} // Iva a 21%
if ($item->getIva() == '10') {
$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * 0.1);
} // Iva a 10%
if ($item->getIva() == '0') {
$data_iva['ivaMontoCero'] = $neto * 0;
} // Iva a 0%, estaba inicializado en null para que aparezca en la factura solo si estĂ¡ a cero
// 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);
if ($item->getIva() == '21') {
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2, PHP_ROUND_HALF_UP);
} // Iva a 21%
if ($item->getIva() == '10') {
$data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2, PHP_ROUND_HALF_UP);
} // Iva a 10%
if ($item->getIva() == '0') {
$data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2, PHP_ROUND_HALF_UP);
} // Iva a 0%
// Acumula netos totales e IVA
$product['neto'] = $product['neto'] + $neto;
$product['sumSubT'] = $product['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$product['neto'] = round($product['neto'], 2, PHP_ROUND_HALF_UP);
$product['sumSubT'] = round($product['sumSubT'], 2, PHP_ROUND_HALF_UP);
// Calculo del precio unitario despues de aplicar Over y Comision
$multiplo = (float)$qty * (float)$days;
$item->setServicePrice($item->getSubTotalPrice() / $multiplo);
$data_supplier['product'][$i] = array(
'id' => $item->getId(),
'productName' => $item->getProductName(),
'productId' => $item->getProductId(),
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'location' => $item->getLocation(),
'servicePrice' => $item->getServicePrice(),
'subTotalPrice' => $item->getSubTotalPrice(),
'subtotalProduct' => $subtotalProduct,
'iva' => $item->getIva(),
'pax' => $pax,
'qty' => $qty,
'days' => $days,
'type' => $item->getType(),
'subtotal' => $subtotal,
);
$i++;
}
$data_supplier['productSubTotal'] = array(
'neto' => $product['neto'],
'sumSubT' => $product['sumSubT'],
);
$payment = array(
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$i = 0;
foreach ($payments as $item) {
// Verificamos que el pago no se encuentre ya en una factura
$existe = $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getId());
if (!empty($existe)) {
$payment['sumSubT'] = $payment['sumSubT'] + 0;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$payment['sumSubT'] = round($payment['sumSubT'], 2, PHP_ROUND_HALF_UP);
} else {
$payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
// 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(),
'datePayAt' => $item->getDatePayAt(),
'wayToPay' => $item->getWayToPay(),
'amountTotal' => $item->getAmountTotal(),
'vat' => $item->getVat(),
);
$i++;
}
if (!empty($payments)) {
$data_supplier['paymentSubTotal'] = array(
'sumSubT' => $payment['sumSubT'],
);
}
foreach ($services as $item) {
// Verificamos que el servicio no se encuentre ya en una factura
$existe = $em->getRepository(AveDocInvoiceItems::class)->findBySrvControlId($item->getId());
if (is_null($item->getPrice()) or empty($item->getPrice()) or !empty($existe)) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
$subneto = 0;
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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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;
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
// $pax = $item->getPax();
// if (empty($pax) or $pax == "0") {
// $pax = 1;
// }
//
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $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' => 'Itinerarios',
// 'date' => $dateServ,
// 'qty' => $unitsServ,
// 'iva' => $item->getIva(),
// 'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
// 'subneto' => $subneto,
// 'subtotal' => $subtotal,
// );
break;
case 11: //Menu
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
default:
break;
}
} else {
$subtotalService = $item->getPrice();
$subneto = $item->getPrice();
// Commission
if ($item->getOpCommission() == '1') {
$subtotalService = $subtotalService * (1 + ($item->getCommission() / 100));
$subneto = $subneto * (1 + ($item->getCommission() / 100));
} else {
$subtotalService = $subtotalService * (1 - ($item->getCommission() / 100));
$subneto = $subneto * (1 - ($item->getCommission() / 100));
}
// Over
if ($item->getOpOver() == '1') {
$subtotalService = $subtotalService + $item->getOver();
$subneto = $subneto + $item->getOver();
} else {
$subtotalService = $subtotalService - $item->getOver();
$subneto = $subneto - $item->getOver();
}
// 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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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;
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
// $pax = $item->getPax();
// if (empty($pax) or $pax == "0") {
// $pax = 1;
// }
//
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $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' => 'Itinerarios',
// 'date' => $dateServ,
// 'qty' => $unitsServ,
// 'iva' => $item->getIva(),
// 'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
// 'subneto' => $subneto,
// 'subtotal' => $subtotal,
// );
break;
case 11: //Menu
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
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);
}
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;
$data = array(
'id' => $id,
'type' => $type,
'number' => $number,
'prefix' => $prefix,
'date' => $date,
'file' => $file,
'token' => '', // $file->getAccessKey(),
'company' => $company,
'clients' => $clientNew,
'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 baseInvoiceSelectedFile($id, $arrayBools, $number)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$items = $em->getRepository(AveDocProformaItems::class)->findByFileId($file->getId());
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => null, // Si toma el valor de cero, indica que hay un iva en 0 y se pone en la factura de resto no
);
//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(AveDocInvoice::class)->findOneById($number);
$number = $number->getNumber();
$type = 'Invoice';
} else {
// Es una Proforma
$numberInvoiceOrProforma = substr($number, 1);
$number = $numberInvoiceOrProforma;
$number = $em->getRepository(AveDocProforma::class)->findOneById($number);
$number = $number->getPrefix() . $number->getFileId();
$type = 'Proforma';
}
//FIN: Determinamos el numero de factura o proforma
// Buscamos las salas reservadas, pagos y servicios para el evento
$arrayItems = array();
$fileProducts = array();
if (!empty($arrayBools['product'])) {
foreach ($arrayBools['product'] as $key => $item) {
if ($item == 'true') {
$fileProducts[] = $em->getRepository(AveProductFile::class)->findOneById($key);
///***---
}
}
}
$payments = array();
if (!empty($arrayBools['payment'])) {
foreach ($arrayBools['payment'] as $key => $item) {
if ($item == 'true') {
$payments[] = $em->getRepository(AvePaymentsClient::class)->findOneById($key);
}
}
}
$services = array();
if (!empty($arrayBools['service'])) {
foreach ($arrayBools['service'] as $key => $item) {
if ($item == 'true') {
$services[] = $em->getRepository(AveServices::class)->findOneById($key);
}
}
}
$data_supplier = array();
$i = 0;
$iva = '21'; // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
$pax = '1';
$qty = '1';
$product = 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 ($fileProducts as $item) {
if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
} else {
// $subtotalProduct = $item->getServicePrice() * 1.21;
$subtotalProduct = $item->getSubTotalPrice() * (1 + ($item->getIva() / 100));
// $subneto = $item->getServicePrice();
$subneto = $item->getSubTotalPrice();
$subtotal = $subtotalProduct;
$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' => 'Product',
'name' => $item->getProductName(),
'amount' => $neto,
'iva' => $item->getIva(),
'total' => $subtotal,
);
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
switch ($item->getIva()) {
case 21:
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2, PHP_ROUND_HALF_UP);
break;
case 10:
$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * 0.1);
$data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2, PHP_ROUND_HALF_UP);
break;
case 0:
$data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto * 0);
$data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2, PHP_ROUND_HALF_UP);
break;
default:
$data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
$data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2, PHP_ROUND_HALF_UP);
break;
}
// $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 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);
// Acumula netos totales e IVA
$product['neto'] = $product['neto'] + $neto;
$product['sumSubT'] = $product['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$product['neto'] = round($product['neto'], 2, PHP_ROUND_HALF_UP);
$product['sumSubT'] = round($product['sumSubT'], 2, PHP_ROUND_HALF_UP);
// Calculo del precio unitario despues de aplicar Over y Comision
$multiplo = $qty * $item->getDays();
$item->setServicePrice($item->getSubTotalPrice() / $multiplo);
$data_supplier['product'][$i] = array(
'id' => $item->getId(),
'productName' => $item->getProductName(),
'productId' => $item->getProductId(),
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'servicePrice' => $item->getServicePrice(),
'subtotalProduct' => $subtotalProduct,
'iva' => $item->getIva(),
'pax' => $pax,
'qty' => $qty,
'type' => $item->getType(),
'subtotal' => $subtotal,
);
$i++;
}
$data_supplier['productSubTotal'] = array(
'neto' => $product['neto'],
'sumSubT' => $product['sumSubT'],
);
$payment = array(
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$i = 0;
foreach ($payments as $item) {
$payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
// 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(),
'amountTotal' => $item->getAmountTotal(),
'vat' => $item->getVat(),
'datePayAt' => $item->getDatePayAt(),
'wayToPay' => $item->getWayToPay(),
);
$arrayItems[] = array(
'type' => 'Payment',
'name' => $item->getWayToPay(),
'amount' => $item->getAmount(),
'total' => $item->getAmountTotal(),
'iva' => $item->getVat(),
);
$i++;
}
if (!empty($payments)) {
$data_supplier['paymentSubTotal'] = array(
'sumSubT' => $payment['sumSubT'],
);
}
foreach ($services as $item) {
if (is_null($item->getPrice()) or empty($item->getPrice())) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $item->getPrice();
$subneto = $item->getPrice();
// Commission
if ($item->getOpCommission() == '1') {
$subtotalService = $subtotalService * (1 + ($item->getCommission() / 100));
$subneto = $subneto * (1 + ($item->getCommission() / 100));
} else {
$subtotalService = $subtotalService * (1 - ($item->getCommission() / 100));
$subneto = $subneto * (1 - ($item->getCommission() / 100));
}
// Over
if ($item->getOpOver() == '1') {
$subtotalService = $subtotalService + $item->getOver();
$subneto = $subneto + $item->getOver();
} else {
$subtotalService = $subtotalService - $item->getOver();
$subneto = $subneto - $item->getOver();
}
// 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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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;
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
// $pax = $item->getPax();
// if (empty($pax) or $pax == "0") {
// $pax = 1;
// }
//
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $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' => 'Itinerarios',
// 'date' => $dateServ,
// 'qty' => $unitsServ,
// 'iva' => $item->getIva(),
// 'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
// 'subneto' => $subneto,
// 'subtotal' => $subtotal,
// );
break;
case 11: //Menu
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $dateServ = ($item->getDateInAt())->format('d/m/Y');
// }
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
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);
$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));
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2, PHP_ROUND_HALF_UP);
break;
case 10:
$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * ($item->getIva() / 100));
$data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2, PHP_ROUND_HALF_UP);
break;
case 0:
$data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto * ($item->getIva() / 100));
break;
default:
$data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
$data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2, PHP_ROUND_HALF_UP);
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);
// 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(AveDocInvoice::class)->findOneById($numberInvoiceOrProforma);
$newInvoice->setBalance($totales_all);
$em->persist($newInvoice);
$em->flush();
}
$data = array(
'id' => $id,
'type' => $type,
'number' => $number,
'prefix' => $number,
'date' => new DateTime('now'),
'file' => $file,
'company' => $company,
'clients' => $clientNew,
'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 baseInvoiceDoneDocument($fileId, $invoiceId, $typeBase)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(AveFiles::class)->findOneById($fileId);
$dateDocument = null; //Fecha final del documento
if (($typeBase == 'I') or ($typeBase == 'P')) {
if ($typeBase == 'I') {
// Es una factura
$items = $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId, 'invoiceId' => $invoiceId));
// Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
$allProductFile = $em->getRepository(AveProductFile::class)->findBy(array('fileId' => $fileId));
$arrayLocation = array();
$arrayLocationWithNull = false;
foreach ($allProductFile as $item) {
if (!empty($item->getLocation())) {
$arrayLocation[$item->getLocation()] = $item->getLocation();
} else {
$arrayLocationWithNull = true;
}
}
if ($arrayLocationWithNull) {
$arrayLocation['null'] = 'null';
}
$arrayItemsSorted = array();
$productsInFile = array();
foreach ($arrayLocation as $item) {
// VIDEO
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'VĂdeo',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'Sonido',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'IluminaciĂ³n',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type IS NULL AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
// Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
if ($item == 'null') {
// VIDEO
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'VĂdeo',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'Sonido',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'IluminaciĂ³n',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocInvoiceItems c WITH c.prdControlId = i.id
WHERE i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
}
$arrayItemsSorted = array_merge($arrayItemsSorted, $productsInFileVid, $productsInFileSound, $productsInFileLights, $productsInFileOther, $productsInFileNull);
}
$items = array();
foreach ($arrayItemsSorted as $elem) {
$items[] = $em->getRepository(AveDocInvoiceItems::class)->findOneBy(array('fileId' => $fileId, 'invoiceId' => $invoiceId, 'prdControlId' => $elem->getId()));
}
} else {
// Es una proforma
// $items = $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
// Salvador Guerrero indico, el orden de los productos en la factura o proforma serĂ¡ (Video - Sonido - Iluminacion - Otros)
$allProductFile = $em->getRepository(AveProductFile::class)->findBy(array('fileId' => $fileId));
$arrayLocation = array();
$arrayLocationWithNull = false;
foreach ($allProductFile as $item) {
if (!empty($item->getLocation())) {
$arrayLocation[$item->getLocation()] = $item->getLocation();
} else {
$arrayLocationWithNull = true;
}
}
if ($arrayLocationWithNull) {
$arrayLocation['null'] = 'null';
}
$arrayItemsSorted = array();
$productsInFile = array();
foreach ($arrayLocation as $item) {
// VIDEO
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'VĂdeo',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'Sonido',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'IluminaciĂ³n',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'location' => $item,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type IS NULL AND i.location = :location AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
// Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
if ($item == 'null') {
// VIDEO
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'VĂdeo',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'Sonido',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'type' => 'IluminaciĂ³n',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type = :type AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type != :typeV AND i.type != :typeS AND i.type != :typeI AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL DEL TIPO (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $fileId,
'proformaId' => $invoiceId,
'location' => '',
);
$dql = 'SELECT i
FROM AvexpressBundle:AveProductFile i
INNER JOIN AvexpressBundle:AveDocProformaItems c WITH c.controlId = i.id
WHERE i.fileId = :fileId AND i.type IS NULL AND (i.location IS NULL OR i.location = :location) AND c.proformaId =:proformaId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
}
$arrayItemsSorted = array_merge($arrayItemsSorted, $productsInFileVid, $productsInFileSound, $productsInFileLights, $productsInFileOther, $productsInFileNull);
}
$items = array();
foreach ($arrayItemsSorted as $elem) {
$items[] = $em->getRepository(AveDocProformaItems::class)->findOneBy(array('fileId' => $fileId, 'proformaId' => $invoiceId, 'controlId' => $elem->getId()));
}
}
} else {
// No es factura ni proforma, es una rectificativa
$items = $em->getRepository(ReservationInvoiceRecItems::class)->findBy(array('reservationId' => $fileId, 'invoiceRecId' => $invoiceId));
}
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => null,
);
//INICIO: Determinamos el numero de factura o proforma
if ($typeBase == 'I') {
// Es una Factura
$number = $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$number = $number->getNumber();
$type = 'Invoice';
} else {
if ($typeBase == 'R') {
// Es una factura rectificativa
$number = $em->getRepository(AveDocInvoiceRec::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$type = 'Invoice Rec';
} else {
// Es una Proforma
// $number = $em->getRepository('DevelupBundle:ReservationProforma')->findOneById($invoiceId);
// $number = $number->getNumber();
$number = $invoiceId;
// $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();
$fileProducts = array();
$payments = array();
$services = array();
if (!empty($items)) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
foreach ($items as $item) {
switch ($item->getItemType()) {
case 'PRODUCT': // Salon
$fileProducts[] = $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 'PRODUCT': // Producto
$productPro = $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
if (!empty($productPro)) {
$fileProducts[] = $productPro;
}
break;
case 'PAYMENT': // Pago
$paymentPro = $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
if (!empty($paymentPro)) {
$payments[] = $paymentPro;
}
break;
case 'SERVICE': // Servicio
$servicePro = $em->getRepository(AveServices::class)->findOneById($item->getControlId());
if (!empty($servicePro)) {
$services[] = $servicePro;
}
break;
default:
break;
}
}
}
}
$data_supplier = array();
$i = 0;
$iva = '21'; // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
$pax = '1';
$qty = '1';
$product = 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 ($fileProducts as $item) {
// $days = '1';
$days = ((($item->getDateEnd())->diff($item->getDateStart()))->days + 1);
if (($typeBase == 'I') or ($typeBase == 'R')) {
if (is_null($item->getSubTotalPrice()) or empty($item->getSubTotalPrice())) {
$subtotal = 0;
$neto = 0;
$subnetoMounting = 0;
$subtotalLounge = 0;
$subnetoRemoval = 0;
} else {
if ($item->getIva() == '21') {
$subtotalLounge = $item->getSubTotalPrice() * 1.21;
}
if ($item->getIva() == '10') {
$subtotalLounge = $item->getSubTotalPrice() * 1.1;
}
if ($item->getIva() == '0') {
$subtotalLounge = $item->getSubTotalPrice() * 1;
}
$subneto = $item->getSubTotalPrice();
$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' => 'Product',
'name' => $item->getLngLoungeName(),
'amount' => $item->getServicePrice(),
'iva' => $item->getIva(),
'amountSubTotal' => $neto,
// 'iva' => '21',
'total' => $subtotal,
);
}
} else {
// Es proforma
if (is_null($item->getSubTotalPrice()) or empty($item->getSubTotalPrice())) {
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
} else {
if ($item->getIva() == '21') {
$subtotalProduct = $item->getSubTotalPrice() * 1.21;
}
if ($item->getIva() == '10') {
$subtotalProduct = $item->getSubTotalPrice() * 1.1;
}
if ($item->getIva() == '0') {
$subtotalProduct = $item->getSubTotalPrice() * 1;
}
$subneto = $item->getSubTotalPrice();
$subtotal = $subtotalProduct;
$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' => 'Product',
'name' => $item->getProductName(),
'amount' => $item->getServicePrice(),
'amountSubTotal' => $neto,
// 'iva' => '21',
'iva' => $item->getIva(),
'total' => $subtotal,
);
}
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
if ($item->getIva() == '21') {
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21);
}
if ($item->getIva() == '10') {
$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * 0.1);
}
if ($item->getIva() == '0') {
$data_iva['ivaMontoCero'] = $neto * 0;
}
// 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
$product['neto'] = $product['neto'] + $neto;
$product['sumSubT'] = $product['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$product['neto'] = round($product['neto'], 2, PHP_ROUND_HALF_UP);
$product['sumSubT'] = round($product['sumSubT'], 2, PHP_ROUND_HALF_UP);
$pax = $item->getPax();
$qty = $item->getUnits();
if (!empty($item->getDays())) {
$days = $item->getDays();
}
// Calculo del precio unitario despues de aplicar Over y Comision
$multiplo = (float)$qty * (float)$days;
$item->setServicePrice($item->getSubTotalPrice() / $multiplo);
if (($typeBase == 'I') or ($typeBase == 'R')) {
$data_supplier['product'][$i] = array(
'id' => $item->getId(),
'loungeName' => $item->getLngLoungeName(),
'idLounge' => $item->getLngIdLounge(),
'dateStart' => $item->getLngDateStart(),
'dateEnd' => $item->getLngDateEnd(),
// 'servicePrice' => $item->getLngServicePrice(),
'servicePrice' => $item->getServicePrice(),
'serviceSubTotalPrice' => $item->getSubTotalPrice(),
'subtotalLounge' => $subtotalLounge,
// 'iva' => $iva,
'iva' => $item->getIva(),
'pax' => $pax,
'qty' => $qty,
'days' => $days,
'type' => $item->getLngType(),
'subtotal' => $subtotal,
);
} else {
// Es proforma
$data_supplier['product'][$i] = array(
'id' => $item->getId(),
'productName' => $item->getProductName(),
'productId' => $item->getProductId(),
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'location' => $item->getLocation(),
// 'servicePrice' => $item->getServicePrice(),
'servicePrice' => $item->getServicePrice(),
'serviceSubTotalPrice' => $item->getSubTotalPrice(),
'subtotalProduct' => $subtotalProduct,
// 'iva' => $iva,
'iva' => $item->getIva(),
'pax' => $pax,
'qty' => $qty,
'days' => $days,
'type' => $item->getType(),
'subtotal' => $subtotal,
);
}
$i++;
}
$data_supplier['productSubTotal'] = array(
'neto' => $product['neto'],
'sumSubT' => $product['sumSubT'],
);
$payment = array(
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$i = 0;
foreach ($payments as $item) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
// $payment['sumSubT'] = $payment['sumSubT'] + $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);
$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(),
// 'iva' => '',
// 'total' => $item->getPayAmount(),
);
} else {
// Es una proforma
// $payment['sumSubT'] = $payment['sumSubT'] + $item->getAmount();
$payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
// 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(),
'amountTotal' => $item->getAmountTotal(),
'vat' => $item->getVat(),
'datePayAt' => $item->getDatePayAt(),
'wayToPay' => $item->getWayToPay(),
);
$arrayItems[] = array(
'type' => 'Payment',
'name' => $item->getWayToPay(),
'amount' => $item->getAmount(),
'total' => $item->getAmountTotal(),
'iva' => $item->getVat(),
// 'iva' => '',
// 'total' => $item->getAmount(),
);
}
$i++;
}
if (!empty($payments)) {
$data_supplier['paymentSubTotal'] = array(
'sumSubT' => $payment['sumSubT'],
);
}
foreach ($services as $item) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $item->getSrvPrice();
$subneto = $item->getSrvPrice();
// 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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
// $pax = $item->getPax();
// if (empty($pax) or $pax == "0") {
// $pax = 1;
// }
//
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $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' => 'Itinerarios',
// 'date' => $dateServ,
// 'qty' => $unitsServ,
// 'iva' => $item->getIva(),
// 'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
// 'subneto' => $subneto,
// 'subtotal' => $subtotal,
// );
break;
case 11: //Menu
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $dateServ = ($item->getDateInAt())->format('d/m/Y');
// }
$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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
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);
$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 {
$subtotalService = $item->getPrice();
$subneto = $item->getPrice();
// Commission
if ($item->getOpCommission() == '1') {
$subtotalService = $subtotalService * (1 + ($item->getCommission() / 100));
$subneto = $subneto * (1 + ($item->getCommission() / 100));
} else {
$subtotalService = $subtotalService * (1 - ($item->getCommission() / 100));
$subneto = $subneto * (1 - ($item->getCommission() / 100));
}
// Over
if ($item->getOpOver() == '1') {
$subtotalService = $subtotalService + $item->getOver();
$subneto = $subneto + $item->getOver();
} else {
$subtotalService = $subtotalService - $item->getOver();
$subneto = $subneto - $item->getOver();
}
// 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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
// $pax = $item->getPax();
// if (empty($pax) or $pax == "0") {
// $pax = 1;
// }
//
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $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' => 'Itinerarios',
// 'date' => $dateServ,
// 'qty' => $unitsServ,
// 'iva' => $item->getIva(),
// 'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
// 'subneto' => $subneto,
// 'subtotal' => $subtotal,
// );
break;
case 11: //Menu
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $dateServ = ($item->getDateInAt())->format('d/m/Y');
// }
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
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);
$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' => $fileId,
'type' => $type,
'number' => $number,
'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' . $fileId,
'date' => $dateDocument,
'file' => $file,
'company' => $company,
'clients' => $clientNew,
'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 baseInvoiceDoneFile($fileId, $invoiceId, $typeBase)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(AveFiles::class)->findOneById($fileId);
$dateDocument = null; //Fecha final del documento
$subneto = 0;
if (($typeBase == 'I') or ($typeBase == 'P')) {
if ($typeBase == 'I') {
$items = $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId, 'invoiceId' => $invoiceId));
$arrayLocation = array();
$arrayLocationWithNull = false;
foreach ($items as $item) {
if (!empty($item->getLocation())) {
$arrayLocation[$item->getLocation()] = $item->getLocation();
} else {
$arrayLocationWithNull = true;
}
}
if ($arrayLocationWithNull) {
$arrayLocation['null'] = 'null';
}
$productsInFile = array();
foreach ($arrayLocation as $item) {
// VIDEO
$parameters = array(
'fileId' => $fileId,
'type' => 'VĂdeo',
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $fileId,
'type' => 'Sonido',
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $fileId,
'type' => 'IluminaciĂ³n',
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $fileId,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location = :location AND i.invoiceId = :invoiceId)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $fileId,
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location = :location AND i.invoiceId = :invoiceId)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
// Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
if ($item == 'null') {
// VIDEO
$parameters = array(
'fileId' => $fileId,
'type' => 'VĂdeo',
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $fileId,
'type' => 'Sonido',
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $fileId,
'type' => 'IluminaciĂ³n',
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $fileId,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location IS NULL AND i.invoiceId = :invoiceId)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $fileId,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceItems i
WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location IS NULL AND i.invoiceId = :invoiceId)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
}
$productsInFile = array_merge($productsInFile, $productsInFileVid, $productsInFileSound, $productsInFileLights, $productsInFileOther, $productsInFileNull);
}
$items = $productsInFile; // En Items estaban todos pero sin ordenamiento, ahora estan organizados por location y tipo
} else {
// Es factura ni proforma
$items = $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
}
} else {
// No es factura ni proforma, es una rectificativa
$items = $em->getRepository(AveDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId, 'invoiceRecId' => $invoiceId));
$arrayLocation = array();
$arrayLocationWithNull = false;
foreach ($items as $item) {
if (!empty($item->getLocation())) {
$arrayLocation[$item->getLocation()] = $item->getLocation();
} else {
$arrayLocationWithNull = true;
}
}
if ($arrayLocationWithNull) {
$arrayLocation['null'] = 'null';
}
$productsInFile = array();
foreach ($arrayLocation as $item) {
// VIDEO
$parameters = array(
'fileId' => $fileId,
'type' => 'VĂdeo',
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $fileId,
'type' => 'Sonido',
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $fileId,
'type' => 'IluminaciĂ³n',
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location = :location AND i.invoiceRecId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $fileId,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location = :location AND i.invoiceRecId = :invoiceId)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $fileId,
'location' => $item,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location = :location AND i.invoiceRecId = :invoiceId)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
// Para el location en NULL el SQL tiene que ser diferente por eso el siguiente condicional
if ($item == 'null') {
// VIDEO
$parameters = array(
'fileId' => $fileId,
'type' => 'VĂdeo',
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileVid = $query->getResult();
// SONIDO
$parameters = array(
'fileId' => $fileId,
'type' => 'Sonido',
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileSound = $query->getResult();
// ILUMINACION
$parameters = array(
'fileId' => $fileId,
'type' => 'IluminaciĂ³n',
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE i.fileId = :fileId AND i.prdType = :type AND i.location IS NULL AND i.invoiceRecId = :invoiceId
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileLights = $query->getResult();
// OTROS
$parameters = array(
'fileId' => $fileId,
'typeV' => 'VĂdeo',
'typeS' => 'Sonido',
'typeI' => 'IluminaciĂ³n',
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE (i.fileId = :fileId AND i.prdType != :typeV AND i.prdType != :typeS AND i.prdType != :typeI AND i.location IS NULL AND i.invoiceRecId = :invoiceId)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileOther = $query->getResult();
// CASO NULL (Los casos EMPTY estan considerados en las consultas previas)
$parameters = array(
'fileId' => $fileId,
'invoiceId' => $invoiceId,
);
$dql = 'SELECT i
FROM AvexpressBundle:AveDocInvoiceRecItems i
WHERE (i.fileId = :fileId AND i.prdType IS NULL AND i.location IS NULL AND i.invoiceRecId = :invoiceId)
ORDER BY i.rankAv ASC';
$query = $em->createQuery($dql)->setParameters($parameters);
$productsInFileNull = $query->getResult();
}
$productsInFile = array_merge($productsInFile, $productsInFileVid, $productsInFileSound, $productsInFileLights, $productsInFileOther, $productsInFileNull);
}
$items = $productsInFile; // En Items estaban todos pero sin ordenamiento, ahora estan organizados por location y tipo
}
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority(4);
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => null,
);
//INICIO: Determinamos el numero de factura o proforma
if ($typeBase == 'I') {
// Es una Factura
$number = $em->getRepository(AveDocInvoice::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$number = $number->getNumber();
$type = 'Invoice';
} else {
if ($typeBase == 'R') {
// Es una factura rectificativa
$number = $em->getRepository(AveDocInvoiceRec::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 los productos, pagos y servicios
$arrayItems = array();
$fileProducts = array();
$payments = array();
$services = array();
if (!empty($items)) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
foreach ($items as $item) {
switch ($item->getItemType()) {
case 'PRODUCT': // Producto
$fileProducts[] = $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 'PRODUCT': // Producto
$productPro = $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
if (!empty($productPro)) {
$fileProducts[] = $productPro;
}
break;
case 'PAYMENT': // Pago
$paymentPro = $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
if (!empty($paymentPro)) {
$payments[] = $paymentPro;
}
break;
case 'SERVICE': // Servicio
$servicePro = $em->getRepository(AveServices::class)->findOneById($item->getControlId());
if (!empty($servicePro)) {
$services[] = $servicePro;
}
break;
default:
break;
}
}
}
}
$data_supplier = array();
$i = 0;
$pax = '1';
$qty = '1';
$product = 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 ($fileProducts as $item) {
$days = ((($item->getPrdDateEnd())->diff($item->getPrdDateStart()))->days + 1);
if (!is_null($item->getPrdDays()) or !empty($item->getPrdDays())) {
$days = $item->getPrdDays();
}
if (!is_null($item->getPrdQty()) or !empty($item->getPrdQty())) {
$qty = $item->getPrdQty();
}
if (!empty($item->getPrdDays())) {
$days = $item->getPrdDays();
}
if (($typeBase == 'I') or ($typeBase == 'R')) {
if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())) {
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
} else {
//Buscamos el iva
$zProductFile = $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
if (empty($zProductFile)) {
$zProductFile = $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId());
}
if (empty($zProductFile)) {
$zProductFile = new AveProductFile;
$zProductFile->setIva(21);
} // No se consigue el iva, se obliga a 21%
$ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)) {
$ivaFactor = ($item->getPrdIva()) / 100;
} // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
$subtotalProduct = $item->getPrdSubTotalPrice() * (1 + $ivaFactor);
$subneto = $item->getPrdSubTotalPrice();
$subtotal = $subtotalProduct;
$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' => 'Product',
'name' => $item->getPrdName(),
'amount' => $neto,
'iva' => $zProductFile->getIva(),
'total' => $subtotal,
);
$ivaFactor = ($ivaFactor * 100);
switch ($ivaFactor){
case 21:
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2, PHP_ROUND_HALF_UP);
break;
case 10:
$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * 0.1);
$data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2, PHP_ROUND_HALF_UP);
break;
case 0:
$data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto * 0);
$data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2, PHP_ROUND_HALF_UP);
break;
default:
$data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
$data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2, PHP_ROUND_HALF_UP);
break;
}
}
} else {
// Es proforma
if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
} else {
//Buscamos el iva
$zProductFile = $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
if (empty($zProductFile)){ $zProductFile = $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
$ivaFactor = empty($zProductFile) ? 0.21 : ($zProductFile->getIva() / 100);
$subtotalProduct = $item->getSubTotalPrice() * (1 + $ivaFactor);
$subneto = $item->getSubTotalPrice();
$subtotal = $subtotalProduct;
$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' => 'Product',
'name' => $item->getProductName(),
'amount' => $neto,
'iva' => $zProductFile->getIva(),
'total' => $subtotal,
);
switch ($zProductFile->getIva()) {
case 21:
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21);
$data_iva['ivaMontoVeintiUno'] = round($data_iva['ivaMontoVeintiUno'], 2, PHP_ROUND_HALF_UP);
break;
case 10:
$data_iva['ivaMontoDiez'] = $data_iva['ivaMontoDiez'] + ($neto * 0.1);
$data_iva['ivaMontoDiez'] = round($data_iva['ivaMontoDiez'], 2, PHP_ROUND_HALF_UP);
break;
case 0:
$data_iva['ivaMontoCero'] = $data_iva['ivaMontoCero'] + ($neto * 0);
$data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 2, PHP_ROUND_HALF_UP);
break;
default:
$data_iva[$item->getIva()] = $data_iva[$item->getIva()] + ($neto * ($item->getIva() / 100));
$data_iva[$item->getIva()] = round($data_iva[$item->getIva()], 2, PHP_ROUND_HALF_UP);
break;
}
}
}
// Acumula netos totales e IVA
$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);
// Acumula netos totales e IVA
$product['neto'] = $product['neto'] + $neto;
$product['sumSubT'] = $product['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$product['neto'] = round($product['neto'], 2, PHP_ROUND_HALF_UP);
$product['sumSubT'] = round($product['sumSubT'], 2, PHP_ROUND_HALF_UP);
// Calculo del precio unitario despues de aplicar Over y Comision
$multiplo = $qty * (float)$days;
$item->setPrdServicePrice($subneto / $multiplo);
//Buscamos el iva
$zProductFile = $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
if (empty($zProductFile)){ $zProductFile = $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
$ivaFactor = empty($zProductFile) ? 21 : $zProductFile->getIva();
if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)){ $ivaFactor = $item->getPrdIva(); } // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
if (($typeBase == 'I') or ($typeBase == 'R')) {
$data_supplier['product'][$i] = array(
'id' => $item->getId(),
'productName' => $item->getPrdName(),
'productId' => $item->getPrdProductId(),
'dateStart' => $item->getPrdDateStart(),
'dateEnd' => $item->getPrdDateEnd(),
'location' => $item->getLocation(),
'servicePrice' => $item->getPrdServicePrice(),
'serviceSubTotalPrice' => $subneto, //antes de IVA
'subtotalProduct' => $subtotalProduct,
'iva' => $ivaFactor,
'pax' => $pax,
'qty' => $qty,
'days' => $days,
'type' => $item->getPrdType(),
'subtotal' => $subtotal,
);
} else {
// Es proforma
$data_supplier['product'][$i] = array(
'id' => $item->getId(),
'productName' => $item->getProductName(),
'productId' => $item->getProductId(),
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'servicePrice' => $item->getServicePrice(),
'subtotalProduct' => $subtotalProduct,
'iva' => $ivaFactor,
'pax' => $pax,
'qty' => $qty,
'days' => $days,
'type' => $item->getType(),
'subtotal' => $subtotal,
);
}
$i++;
}
$data_supplier['productSubTotal'] = array(
'neto' => $product['neto'],
'sumSubT' => $product['sumSubT'],
);
$payment = array(
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$i = 0;
foreach ($payments as $item) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
$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);
$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['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
// 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(),
'amountTotal' => $item->getAmountTotal(),
'vat' => $item->getVat(),
'datePayAt' => $item->getDatePayAt(),
'wayToPay' => $item->getWayToPay(),
);
$arrayItems[] = array(
'type' => 'Payment',
'name' => $item->getWayToPay(),
'amount' => $item->getAmount(),
'total' => $item->getAmountTotal(),
'iva' => $item->getVat(),
);
}
$i++;
}
if (!empty($payments)) {
$data_supplier['paymentSubTotal'] = array(
'sumSubT' => $payment['sumSubT'],
);
}
foreach ($services as $item) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $item->getSrvPrice();
$subneto = $item->getSrvPrice();
// 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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $dateServ = ($item->getDateInAt())->format('d/m/Y');
// }
$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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
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);
$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:
$data_iva['ivaMontoCero'] = 0;
break;
default:
break;
}
} else {
// Es una proforma
if (is_null($item->getPrice()) or empty($item->getPrice())) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $item->getPrice();
$subneto = $item->getPrice();
// Commission
if ($item->getOpCommission() == '1') {
$subtotalService = $subtotalService * (1 + ($item->getCommission() / 100));
$subneto = $subneto * (1 + ($item->getCommission() / 100));
} else {
$subtotalService = $subtotalService * (1 - ($item->getCommission() / 100));
$subneto = $subneto * (1 - ($item->getCommission() / 100));
}
// Over
if ($item->getOpOver() == '1') {
$subtotalService = $subtotalService + $item->getOver();
$subneto = $subneto + $item->getOver();
} else {
$subtotalService = $subtotalService - $item->getOver();
$subneto = $subneto - $item->getOver();
}
// 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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $dateServ = ($item->getDateInAt())->format('d/m/Y');
// }
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
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);
$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:
$data_iva['ivaMontoCero'] = 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);
$data_iva['ivaMontoCero'] = round($data_iva['ivaMontoCero'], 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' => $fileId,
'type' => $type,
'number' => $number,
'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' . $invoiceId,
'date' => $dateDocument,
'file' => $file,
'token' => $file->getAccessKey(),
'company' => $company,
'clients' => $clientNew,
'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 baseInvoiceDoneFileTwo($fileId, $invoiceId, $typeBase)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(AveFiles::class)->findOneById($fileId);
$dateDocument = null; //Fecha final del documento
$subneto = 0;
if (($typeBase == 'I') or ($typeBase == 'P')) {
if ($typeBase == 'I') {
$items = $em->getRepository(AveDocInvoiceItems::class)->findBy(array('fileId' => $fileId, 'invoiceId' => $invoiceId));
} else {
// Es factura ni proforma
$items = $em->getRepository(AveDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
}
} else {
// No es factura ni proforma, es una rectificativa
$items = $em->getRepository(AveDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId, 'invoiceRecId' => $invoiceId));
}
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// 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(AveDocInvoice::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$number = $number->getNumber();
$type = 'Invoice';
} else {
if ($typeBase == 'R') {
// Es una factura rectificativa
$number = $em->getRepository(AveDocInvoiceRec::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 los productos, pagos y servicios
$arrayItems = array();
$fileProducts = array();
$payments = array();
$services = array();
if (!empty($items)) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
foreach ($items as $item) {
switch ($item->getItemType()) {
case 'PRODUCT': // Producto
$fileProducts[] = $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 'PRODUCT': // Producto
$productPro = $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
if (!empty($productPro)) {
$fileProducts[] = $productPro;
}
break;
case 'PAYMENT': // Pago
$paymentPro = $em->getRepository(AvePaymentsClient::class)->findOneById($item->getControlId());
if (!empty($paymentPro)) {
$payments[] = $paymentPro;
}
break;
case 'SERVICE': // Servicio
$servicePro = $em->getRepository(AveServices::class)->findOneById($item->getControlId());
if (!empty($servicePro)) {
$services[] = $servicePro;
}
break;
default:
break;
}
}
}
}
$data_supplier = array();
$i = 0;
$iva = '21'; // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
$pax = '1';
$qty = '1';
$product = 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 ($fileProducts as $item) {
if (!is_null($item->getUnits()) or !empty($item->getUnits())) {
$qty = $item->getUnits();
}
if (($typeBase == 'I') or ($typeBase == 'R')) {
if (is_null($item->getPrdServicePrice()) or empty($item->getPrdServicePrice())) {
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
$ivaFactor = 0;
} else {
//Buscamos el iva
$zProductFile = $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
if (empty($zProductFile)){ $zProductFile = $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
// $subtotalProduct = $item->getPrdServicePrice() * 1.21;
$ivaFactor = empty($zProductFile) ? 21 : $zProductFile->getIva();
if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)){ $ivaFactor = $item->getPrdIva(); } // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
$ivaFactor = (1 + ($ivaFactor/100));
$subtotalProduct = $item->getPrdSubTotalPrice() * $ivaFactor;
$ivaFactor = (($ivaFactor - 1) * 100);
$subneto = $item->getPrdSubTotalPrice();
$subtotal = $subtotalProduct;
$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' => 'Product',
'name' => $item->getPrdName(),
'amount' => $neto,
'iva' => $ivaFactor,
'total' => $subtotal,
);
}
} else {
// Es proforma
if (is_null($item->getServicePrice()) or empty($item->getServicePrice())) {
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
$ivaFactor = 0;
} else {
//Buscamos el iva
// d($item);
// $zProductFile = $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
$zProductFile = $item;
if (empty($zProductFile)){ $zProductFile = $em->getRepository(AveProductFile::class)->findOneById((-1) * $item->getPrdControlId()); }
// $subtotalProduct = $item->getServicePrice() * 1.21;
$ivaFactor = empty($zProductFile) ? 21 : $zProductFile->getIva();
// if (!empty($item->getPrdIva()) or ($item->getPrdIva() == 0)){ $ivaFactor = $item->getPrdIva(); } // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
if (!empty($item->getIva()) or ($item->getIva() == 0)){ $ivaFactor = $item->getIva(); } // El iva se incorporo en la entidad despues del año 2024 por eso las lineas anteriores del iva
$ivaFactor = (1 + ($ivaFactor/100));
$subtotalProduct = $item->getSubTotalPrice() * $ivaFactor;
$ivaFactor = (($ivaFactor - 1) * 100);
$subneto = $item->getSubTotalPrice();
$subtotal = $subtotalProduct;
$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' => 'Product',
'name' => $item->getProductName(),
'amount' => $neto,
'iva' => '21',
'total' => $subtotal,
);
}
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
switch ($ivaFactor) {
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: $data_iva['ivaMontoCero'] = 0; break;
default: 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);
// Acumula netos totales e IVA
$product['neto'] = $product['neto'] + $neto;
$product['sumSubT'] = $product['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$product['neto'] = round($product['neto'], 2, PHP_ROUND_HALF_UP);
$product['sumSubT'] = round($product['sumSubT'], 2, PHP_ROUND_HALF_UP);
if (($typeBase == 'I') or ($typeBase == 'R')) {
$data_supplier['product'][$i] = array(
'id' => $item->getId(),
'productName' => $item->getPrdName(),
'productId' => $item->getPrdProductId(),
'dateStart' => $item->getPrdDateStart(),
'dateEnd' => $item->getPrdDateEnd(),
'servicePrice' => $item->getPrdServicePrice(),
'serviceSubTotalPrice' => $subneto, //antes de IVA
'subtotalProduct' => $subtotalProduct,
'iva' => $iva,
'pax' => $pax,
'qty' => $qty,
'type' => $item->getPrdType(),
'subtotal' => $subtotal,
);
} else {
// Es proforma
$data_supplier['product'][$i] = array(
'id' => $item->getId(),
'productName' => $item->getProductName(),
'productId' => $item->getProductId(),
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'servicePrice' => $item->getServicePrice(),
'subtotalProduct' => $subtotalProduct,
'iva' => $iva,
'pax' => $pax,
'qty' => $qty,
'type' => $item->getType(),
'subtotal' => $subtotal,
);
}
$i++;
}
$data_supplier['productSubTotal'] = array(
'neto' => $product['neto'],
'sumSubT' => $product['sumSubT'],
);
$payment = array(
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$i = 0;
foreach ($payments as $item) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
$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);
$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['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
// 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(),
'amountTotal' => $item->getAmountTotal(),
'vat' => $item->getVat(),
'datePayAt' => $item->getDatePayAt(),
'wayToPay' => $item->getWayToPay(),
);
$arrayItems[] = array(
'type' => 'Payment',
'name' => $item->getWayToPay(),
'amount' => $item->getAmount(),
'total' => $item->getAmountTotal(),
'iva' => $item->getVat(),
);
}
$i++;
}
if (!empty($payments)) {
$data_supplier['paymentSubTotal'] = array(
'sumSubT' => $payment['sumSubT'],
);
}
foreach ($services as $item) {
if (($typeBase == 'I') or ($typeBase == 'R')) {
if (is_null($item->getSrvPrice()) or empty($item->getSrvPrice())) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
} else {
$subtotalService = $item->getSrvPrice();
$subneto = $item->getSrvPrice();
// 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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
// $pax = $item->getPax();
// if (empty($pax) or $pax == "0") {
// $pax = 1;
// }
//
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $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' => 'Itinerarios',
// 'date' => $dateServ,
// 'qty' => $unitsServ,
// 'iva' => $item->getIva(),
// 'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
// 'subneto' => $subneto,
// 'subtotal' => $subtotal,
// );
break;
case 11: //Menu
$pax = $item->getSrvPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getSrvDateOutAt())->diff($item->getSrvDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $dateServ = ($item->getDateInAt())->format('d/m/Y');
// }
$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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getSrvDateInAt())->format('d/m/Y') . ' - ' . ($item->getSrvDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getSrvIva(),
'pax' => $item->getSrvPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
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);
$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 {
$subtotalService = $item->getPrice();
$subneto = $item->getPrice();
// Commission
if ($item->getOpCommission() == '1') {
$subtotalService = $subtotalService * (1 + ($item->getCommission() / 100));
$subneto = $subneto * (1 + ($item->getCommission() / 100));
} else {
$subtotalService = $subtotalService * (1 - ($item->getCommission() / 100));
$subneto = $subneto * (1 - ($item->getCommission() / 100));
}
// Over
if ($item->getOpOver() == '1') {
$subtotalService = $subtotalService + $item->getOver();
$subneto = $subneto + $item->getOver();
} else {
$subtotalService = $subtotalService - $item->getOver();
$subneto = $subneto - $item->getOver();
}
// 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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
// $pax = $item->getPax();
// if (empty($pax) or $pax == "0") {
// $pax = 1;
// }
//
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $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' => 'Itinerarios',
// 'date' => $dateServ,
// 'qty' => $unitsServ,
// 'iva' => $item->getIva(),
// 'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
// 'subneto' => $subneto,
// 'subtotal' => $subtotal,
// );
break;
case 11: //Menu
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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 = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = 1;
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $dateServ = ($item->getDateInAt())->format('d/m/Y');
// }
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
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);
$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' => $fileId,
'type' => $type,
'number' => $number,
'prefix' => 'AVE-' . (new DateTime('now'))->format('dmy') . '-' . $invoiceId,
'date' => $dateDocument,
'file' => $file,
'token' => $file->getAccessKey(),
'company' => $company,
'clients' => $clientNew,
'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 sendTelegram($id, $text)
{
$em = $this->getDoctrine()->getManager();
$telegUser = $em->getRepository(MdvTelegramUser::class)->findOneByUserId($id);
if (empty($telegUser)) {
return true;
}
$parameters = array(
'chat_id' => $telegUser->getChatId(),
'text' => $text,
);
$bot_token = $telegUser->getBotToken();
$url = "https://api.telegram.org/bot$bot_token/sendMessage";
if (!$curl = curl_init()) {
exit();
}
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($curl);
curl_close($curl);
return true;
}
private function baseProformaSelect($id, $type, $number, $prefix, $date, $proformaId)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(AveFiles::class)->findOneById($id);
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('4');
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
} else {
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
// $client[0]->setPopulation($city->getCity());
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
// $client[0]->setRegion($region->getRegion());
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
// $client[0]->setCountry($country->getCountry());
}
}
if (empty($client)) {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
$clientNew = array(
'name' => '',
'title' => '',
'idDocument' => '',
'population' => '',
'region' => '',
'country' => '',
'address' => '',
'addressNumber' => '',
'zipCode' => '',
'typeDocument' => '',
);
} else {
$clientNew = array(
'name' => $client[0]->getName(),
'title' => $client[0]->getTitle(),
'idDocument' => $client[0]->getIdDocument(),
'population' => '',
'region' => '',
'country' => '',
'address' => $client[0]->getAddress(),
'addressNumber' => $client[0]->getAddressNumber(),
'zipCode' => $client[0]->getZipCode(),
'typeDocument' => $client[0]->getTypeDocument(),
);
if (is_numeric($client[0]->getPopulation())) {
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$clientNew['population'] = $city->getCity();
}
if (is_numeric($client[0]->getRegion())) {
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$clientNew['region'] = $region->getRegion();
}
if (is_numeric($client[0]->getCountry())) {
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$clientNew['country'] = $country->getCountry();
}
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => null,
);
// Buscamos las salas reservadas, pagos y servicios para el evento
// Buscamos los productos de la proforma
$productsInProforma = $em->getRepository(AveDocProformaItems::class)->findByProformaId($proformaId);
$productsInFile = array();
foreach ($productsInProforma as $item) {
$producto = $em->getRepository(AveProductFile::class)->findOneById($item->getControlId());
if (!empty($producto)) {
$productsInFile[] = $producto;
}
}
// $productsInFile = $em->getRepository(AveProductFile::class)->findByFileId($id);
$payments = $em->getRepository(AvePaymentsClient::class)->findByFileId($id);
$services = $em->getRepository(AveServices::class)->findByFileId($id);
$data_supplier = array();
$i = 0;
$iva = '21'; // Esteban Rincon: "Por Ley de localizaciĂ³n del impuesto, siempre serĂ¡ un 21%"
$pax = '1';
$qty = '1';
$product = 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 ($productsInFile as $item) {
// $days = '1';
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
$days = ((($item->getDateEnd())->diff($item->getDateStart()))->days + 1);
// Verificamos que el producto no se encuentre ya en una factura
$existe = $em->getRepository(AveDocInvoiceItems::class)->findByPrdControlId($item->getId());
$pax = $item->getPax();
$qty = $item->getUnits();
if (!empty($item->getDays())) {
$days = $item->getDays();
}
if (is_null($item->getServicePrice()) or empty($item->getServicePrice()) or !empty($existe)) {
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
} else {
// $subtotalProduct = $item->getServicePrice() * 1.21;
$subtotalProduct = $item->getSubTotalPrice() * 1.21;
// $subneto = $item->getServicePrice();
$subneto = $item->getSubTotalPrice();
$subtotal = $subtotalProduct;
$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);
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
$data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 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
$product['neto'] = $product['neto'] + $neto;
$product['sumSubT'] = $product['sumSubT'] + $subtotal;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$product['neto'] = round($product['neto'], 2, PHP_ROUND_HALF_UP);
$product['sumSubT'] = round($product['sumSubT'], 2, PHP_ROUND_HALF_UP);
$data_supplier['product'][$i] = array(
'id' => $item->getId(),
'productName' => $item->getProductName(),
'productId' => $item->getProductId(),
'dateStart' => $item->getDateStart(),
'dateEnd' => $item->getDateEnd(),
'servicePrice' => $item->getServicePrice(),
'subTotalPrice' => $item->getSubTotalPrice(),
'subtotalProduct' => $subtotalProduct,
'iva' => $iva,
'pax' => $pax,
'qty' => $qty,
'days' => $days,
'type' => $item->getType(),
'subtotal' => $subtotal,
);
$i++;
}
$data_supplier['productSubTotal'] = array(
'neto' => $product['neto'],
'sumSubT' => $product['sumSubT'],
);
$payment = array(
'sumSubT' => 0,
); // Acumula sumatoria de netos y sumantoria de subtotales
$i = 0;
foreach ($payments as $item) {
// Verificamos que el pago no se encuentre ya en una factura
$existe = $em->getRepository(AveDocInvoiceItems::class)->findByPayControlId($item->getId());
if (!empty($existe)) {
$payment['sumSubT'] = $payment['sumSubT'] + 0;
// Se lleva a 2 decimales round($totales_neto_antes,2,PHP_ROUND_HALF_UP)
$payment['sumSubT'] = round($payment['sumSubT'], 2, PHP_ROUND_HALF_UP);
} else {
$payment['sumSubT'] = $payment['sumSubT'] + $item->getAmountTotal();
// 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(),
'datePayAt' => $item->getDatePayAt(),
'wayToPay' => $item->getWayToPay(),
'amountTotal' => $item->getAmountTotal(),
'vat' => $item->getVat(),
);
$i++;
}
if (!empty($payments)) {
$data_supplier['paymentSubTotal'] = array(
'sumSubT' => $payment['sumSubT'],
);
}
foreach ($services as $item) {
// Verificamos que el servicio no se encuentre ya en una factura
$existe = $em->getRepository(AveDocInvoiceItems::class)->findBySrvControlId($item->getId());
if (is_null($item->getPrice()) or empty($item->getPrice()) or !empty($existe)) {
$subtotal = 0;
$neto = 0;
$subtotalService = 0;
$subneto = 0;
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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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;
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
// $pax = $item->getPax();
// if (empty($pax) or $pax == "0") {
// $pax = 1;
// }
//
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $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' => 'Itinerarios',
// 'date' => $dateServ,
// 'qty' => $unitsServ,
// 'iva' => $item->getIva(),
// 'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
// 'subneto' => $subneto,
// 'subtotal' => $subtotal,
// );
break;
case 11: //Menu
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
default:
break;
}
} else {
$subtotalService = $item->getPrice();
$subneto = $item->getPrice();
// Commission
if ($item->getOpCommission() == '1') {
$subtotalService = $subtotalService * (1 + ($item->getCommission() / 100));
$subneto = $subneto * (1 + ($item->getCommission() / 100));
} else {
$subtotalService = $subtotalService * (1 - ($item->getCommission() / 100));
$subneto = $subneto * (1 - ($item->getCommission() / 100));
}
// Over
if ($item->getOpOver() == '1') {
$subtotalService = $subtotalService + $item->getOver();
$subneto = $subneto + $item->getOver();
} else {
$subtotalService = $subtotalService - $item->getOver();
$subneto = $subneto - $item->getOver();
}
// 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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$dateServ = ($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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'AV',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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;
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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 9: //Itineraries
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Itinerarios',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
break;
case 10: //Lounge -- No Aplica
// $pax = $item->getPax();
// if (empty($pax) or $pax == "0") {
// $pax = 1;
// }
//
// $days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
// if ($days > 1){
// $dateServ = ($item->getDateInAt())->format('d/m/Y'). ' - '.($item->getDateOutAt())->format('d/m/Y');
// } else {
// $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' => 'Itinerarios',
// 'date' => $dateServ,
// 'qty' => $unitsServ,
// 'iva' => $item->getIva(),
// 'pax' => $item->getPax(),
// 'precioUnit' => $subnetoUnit,
// 'subneto' => $subneto,
// 'subtotal' => $subtotal,
// );
break;
case 11: //Menu
$pax = $item->getPax();
if (empty($pax) or $pax == "0") {
$pax = 1;
}
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'MenĂº',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Otros',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => '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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'Asistente',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'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);
if ($days > 1) {
$dateServ = ($item->getDateInAt())->format('d/m/Y') . ' - ' . ($item->getDateOutAt())->format('d/m/Y');
} else {
$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' => 'DDR',
'date' => $dateServ,
'qty' => $unitsServ,
'iva' => $item->getIva(),
'pax' => $item->getPax(),
'precioUnit' => $subnetoUnit,
'subneto' => $subneto,
'subtotal' => $subtotal,
);
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);
}
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;
$data = array(
'id' => $id,
'type' => $type,
'number' => $number,
'prefix' => $prefix,
'date' => $date,
'file' => $file,
'token' => '', // $file->getAccessKey(),
'company' => $company,
'clients' => $clientNew,
'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 sendMailLot($mailAddressFrom, $mailArrayTo, $mailSubject, $mailBody)
{
$em = $this->getDoctrine()->getManager();
$agent = $em->getRepository(User::class)->findOneByEmail($mailAddressFrom);
// $client = $em->getRepository(User::class)->findOneByEmail($mailAddressTo);
$replyTo = array();
foreach ($mailArrayTo as $item) {
// Verificamos que los correos sean validos
if (filter_var($item, FILTER_VALIDATE_EMAIL)) {
$replyTo[$item] = $item;
}
}
$agentMail = $mailAddressFrom;
$mailAgent = $agentMail;
//Se prepara el correo con los agentes a notificar
$firmGmail = $agent->getFirmGmail();
$data = array(
'body' => $mailBody,
'firm' => $firmGmail,
);
// EJECUTAR ENVIO DE ALERTA PARA EL AGENTE
$transporter = new Swift_SmtpTransport();
$transporter->setHost('smtp.gmail.com')
->setEncryption('ssl') //ssl / tls
->setPort(465) // 465 / 587
->setUsername('desarrollo@develup.solutions')
->setPassword('utvh hzoi wfdo ztjs');
$mailer = new Swift_Mailer($transporter);
$message = new Swift_Message();
$message->setSubject($mailSubject)
->setSender($agentMail)
->setFrom(array("desarrollo@develup.solutions" => "System Mante 3.0"))
->setReplyTo($agentMail)
->setTo($replyTo)
->setBody(
$this->renderView(
'mail/structure-mail.html.twig',
array('data' => $data)
),
'text/html'
);
$mailer->send($message);
return true;
}
private function calculoBeneficiosDocumento($id, $typeDoc)
{
// Funcion para registrar los beneficios al crear facturas o facturas rectificativas
$em = $this->getDoctrine()->getManager();
if ($typeDoc == 'Invoice') {
// Es factura
$invoice = $em->getRepository(AveDocInvoice::class)->findOneById($id);
$invoiceItems = $em->getRepository(AveDocInvoiceItems::class)->findByInvoiceId($id);
// ComisiĂ³n de AV a GreenPatio
$aveFile = $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
$reserva = $em->getRepository(Reservation::class)->findOneById($aveFile->getReservation());
if (!empty($reserva)){
if (!is_null($reserva->getComAvGp())) {
$supplierNet = $invoice->getTotalNet() * ($reserva->getComAvGp()/100);
} else {
// Valor por defecto de la Comision de Av 10%
$supplierNet = $invoice->getTotalNet() * (10/100);
}
$description = $id.' - ComisiĂ³n MANTE de Green Patio (Generado automaticamente)';
$supplier = $em->getRepository(Supplier::class)->findOneById(2028); // Green Patio como proveedor
$benSup = new AveBenefitsSupplier();
$benSup->setFileId($aveFile->getId());
$benSup->setDocId(0);
$benSup->setDocType('.');
$benSup->setSupplierId(2028);
$benSup->setSupplierName($supplier->getCompany() . ' | ' . $supplier->getName());
$benSup->setDescription($description);
$benSup->setBenefitSupplier($supplierNet);
$em->persist($benSup);
$em->flush();
}
} else {
// Es factura rectificativa
// Se busca la entrada de los beneficios de la factura y se genera su contraparte. Tambien se necesita el ID de la factura rectificativa
$invoiceRec = $em->getRepository(AveDocInvoiceRec::class)->findOneById($id);
if (empty($invoiceRec)) { return true; }
$ben = $em->getRepository(AveBenefitsInvoiceInvoiceRec::class)->findOneByDocId($invoiceRec->getInvoiceToRec());
$benefits = new AveBenefitsInvoiceInvoiceRec();
$benefits->setDocId($invoiceRec->getId());
$benefits->setFileId($ben->getFileId());
$benefits->setDocType('Invoice Rec');
$benefits->setDateAt($invoiceRec->getDateAt());
$benefits->setFileName($ben->getFileName());
$benefits->setClientId($ben->getClientId());
$benefits->setClientName($ben->getClientName());
$benefits->setBenefitEuro($ben->getBenefitEuro() * (-1));
$benefits->setBenefitPerc($ben->getBenefitPerc());
$benefits->setNetSale($ben->getNetSale() * (-1));
$benefits->setTotalSale($ben->getTotalSale() * (-1));
$em->persist($benefits);
$em->flush();
return true;
}
$productsItems = array();
// Buscamos los productos de la factura para determinar el proveedor
foreach ($invoiceItems as $item) {
$prdItem = $em->getRepository(AveProductFile::class)->findOneById($item->getPrdControlId());
$sup = (empty($prdItem) or empty($prdItem->getSupplierExt())) ? 'AV EXPRESS S.L.' : $prdItem->getSupplierExt();
$iva = (empty($prdItem) or empty($prdItem->getIva())) ? '21' : $prdItem->getSupplierExt();
switch ($iva) {
case '21':
if (empty($prdItem)) {
$ivaxPlus = 1.21;
} else {
$ivaxPlus = ($prdItem->getOpIva() == 0) ? 0.83 : 1.21; // 100/121 = 0.826
}
break;
case '10':
if (empty($prdItem)) {
$ivaxPlus = 1.10;
} else {
$ivaxPlus = ($prdItem->getOpIva() == 0) ? 0.91 : 1.10; // 100/110 = 0.909
}
break;
case '0':
$ivaxPlus = 1;
break;
default:
$ivaxPlus = 1.21;
break;
}
$productsItems[] = array(
'invoiceItemOrInvoiceRecItem' => $item,
'productFile' => $prdItem,
'supplier' => $sup,
'iva' => $ivaxPlus,
'typeDoc' => $typeDoc
);
}
$data = array();
foreach ($productsItems as $elem) {
if (empty($data[$invoice->getFileId()])) {
$data[$invoice->getFileId()] = array(
'id' => $invoice->getFileId(),
'benefitEuro' => 0,
'benefitPerc' => 0,
'netSale' => 0,
'totalSale' => 0,
);
}
$benefitEuro = $data[$invoice->getFileId()]['benefitEuro'];
$benefitPerc = $data[$invoice->getFileId()]['benefitPerc'];
$netSale = $data[$invoice->getFileId()]['netSale'];
$totalSale = $data[$invoice->getFileId()]['totalSale'];
// Con los factores se sumarĂ¡ o restarĂ¡ el beneficio
// Se verifica si es una factura o factura rectificativa
if ($typeDoc == 'Invoice') {
$indiceOpOver = (empty($elem['productFile']) or empty($elem['productFile']->getOpOver())) ? 1 : $elem['productFile']->getOpOver();
$indiceOpComission = (empty($elem['productFile']) or empty($elem['productFile']->getOpCommission())) ? 1 : $elem['productFile']->getOpCommission();
$indicePax = $elem['invoiceItemOrInvoiceRecItem']->getPrdPax();
$indiceQty = $elem['invoiceItemOrInvoiceRecItem']->getPrdQty();
$indiceDays = $elem['invoiceItemOrInvoiceRecItem']->getPrdDays();
$indicePriceProduct = $elem['invoiceItemOrInvoiceRecItem']->getPrdServicePrice();
$indiceOver = (empty($elem['productFile']) or empty($elem['productFile']->getOver())) ? 0 : $elem['productFile']->getOver();
$indiceCommission = (empty($elem['productFile']) or empty($elem['productFile']->getCommission())) ? 0 : $elem['productFile']->getCommission();
} else {
$indiceOpOver = (empty($elem['productFile']) or empty($elem['productFile']->getOpOver())) ? 1 : $elem['productFile']->getOpOver();
$indiceOpComission = (empty($elem['productFile']) or empty($elem['productFile']->getOpCommission())) ? 1 : $elem['productFile']->getOpCommission();
$indicePax = $elem['invoiceItemOrInvoiceRecItem']->getPrdPax();
$indiceQty = $elem['invoiceItemOrInvoiceRecItem']->getPrdQty();
$indiceDays = $elem['invoiceItemOrInvoiceRecItem']->getPrdDays();
$indicePriceProduct = $elem['invoiceItemOrInvoiceRecItem']->getPrdServicePrice();
$indiceOver = (empty($elem['productFile']) or empty($elem['productFile']->getOver())) ? 0 : $elem['productFile']->getOver();
$indiceCommission = (empty($elem['productFile']) or empty($elem['productFile']->getCommission())) ? 0 : $elem['productFile']->getCommission();
}
// Se verifica el proveedor
if ($elem['supplier'] == 'AV EXPRESS S.L.') { $factorSupp = 0; } else { $factorSupp = 1; }
// Se verifica si es ganancia o perdida segun OVER (- o +)
if ($indiceOpOver == 0) { $factorOver = -1; } else { $factorOver = 1; }
// Se verifica si es ganancia o perdida segun COMISION (- o +)
if ($indiceOpComission == 0) { $factorCommission = -1; } else { $factorCommission = 1; }
// Pax
if ($indicePax == 0 or empty($indicePax)) { $pax = 1; } else { $pax = $indicePax; }
// Qty
if ($indiceQty == 0 or empty($indiceQty)) { $qty = 1; } else { $qty = $indiceQty; }
// Days
if ($indiceDays == 0 or empty($indiceDays)) { $days = 1; } else { $days = $indiceDays; }
// Precio base
$priceBase = $indicePriceProduct * $pax * $qty * $days;
// Agregamos el over (se consideran over + o -)
$price = $priceBase + ($factorOver * $indiceOver);
// Agregamos la comision (se consideran comision + o -)
$price = $price + ((($factorCommission * $indiceCommission) * $price) / 100);
// Agregamos el factor proveedor
$benefitEuroItem = $price - ($priceBase * $factorSupp);
// Agregamos al porcentaje el factor del tipo de documento (factura o fact rectificativa), NO HACE FALTA LOS PRECIOS VIENEN NEGATIVOS
// $benefitEuroItem = $benefitEuroItem * $factorTypeDoc;
// Agregamos al precio el factor del tipo de documento (factura o fact rectificativa), NO HACE FALTA LOS PRECIOS VIENEN NEGATIVOS
// $price = $price * $factorTypeDoc;
// Agregamos el precio a la venta neta
$netSale = $netSale + $price;
// Agregamos al precio el IVA para la venta total
$totalSale = $totalSale + ($price * $elem['iva']);
$benefitPercItem = (empty($invoice) or ($invoice->getTotalNet() == 0)) ? 0 : round((($benefitEuroItem * 100) / $invoice->getTotalNet()), 2, PHP_ROUND_HALF_UP);
$data[$invoice->getFileId()] = array(
'id' => $invoice->getFileId(),
'benefitEuro' => $benefitEuro + $benefitEuroItem,
'benefitPerc' => $benefitPerc + $benefitPercItem,
'netSale' => $netSale,
'totalSale' => $totalSale,
);
}
foreach ($data as $key => $elem) {
// Verificamos beneficios simplificados de proveedores
$simplyBen = $em->getRepository(AveBenefitsSupplier::class)->findByFileId($elem['id']);
$benefitEuro = $elem['benefitEuro'];
foreach ($simplyBen as $item) { $benefitEuro = $benefitEuro - $item->getBenefitSupplier(); }
$data[$key]['benefitEuro'] = $benefitEuro;
$newBenefitPerc = (($benefitEuro * 100) / $elem['netSale']);
$newBenefitPerc = round($newBenefitPerc, 2, PHP_ROUND_HALF_UP);
$data[$key]['benefitPerc'] = $newBenefitPerc;
}
// Los $benefitPercItem de 99.97 o 100.01 lo llevamos a 100
// if ($data[$invoice->getFileId()]['benefitEuro'] == $data[$invoice->getFileId()]['netSale']) { $data[$invoice->getFileId()]['benefitPerc'] = 100; }
$fileId = $invoice->getFileId();
if (isset($data[$fileId]) && $data[$fileId]['benefitEuro'] == $data[$fileId]['netSale']) {
$data[$fileId]['benefitPerc'] = 100;
}
// Buscamos los datos del cliente
if (!empty($invoice)) {
$file = $em->getRepository(AveFiles::class)->findOneById($invoice->getFileId());
$clientId = empty($file) ? null : $file->getClient();
$clientName = empty($clientId) ? null : $em->getRepository(Client::class)->findOneById($clientId);
$clientName = empty($clientName) ? null : $clientName->getName();
} else {
$clientId = null;
$clientName = null;
}
if (!empty($data)) {
$benefits = new AveBenefitsInvoiceInvoiceRec();
$benefits->setDocId($invoice->getId());
$benefits->setFileId($invoice->getFileId());
$benefits->setDocType($typeDoc);
$benefits->setDateAt($invoice->getDateAt());
$benefits->setFileName($file->getTitle());
$benefits->setClientId($clientId);
$benefits->setClientName($clientName);
$benefits->setBenefitEuro($data[$invoice->getFileId()]['benefitEuro']);
$benefits->setBenefitPerc($data[$invoice->getFileId()]['benefitPerc']);
$benefits->setNetSale($data[$invoice->getFileId()]['netSale']);
$benefits->setTotalSale($data[$invoice->getFileId()]['totalSale']);
$em->persist($benefits);
$em->flush();
}
//Llamamos al servicio del gestor de comisiones internas entre empresas
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$dataService = $this->commisionEnterpriseService->commissionAvExpressGreenPatio($invoice->getId(), $user_id);
return true;
}
};