<?php
namespace App\MDS\DevelupBundle\Controller;
use App\Entity\Cities;
use App\Entity\Client;
use App\Entity\Configuration;
use App\Entity\Country;
use App\Entity\Regions;
use App\Entity\SettingsCompany;
use App\Entity\SupplierTechnology;
use App\Entity\User;
use App\MDS\DevelupBundle\Entity\MdvBriefings;
use App\MDS\DevelupBundle\Entity\MdvBudgetPending;
use App\MDS\DevelupBundle\Entity\MdvBudgetToProforma;
use App\MDS\DevelupBundle\Entity\MdvDocInvoiceItems;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use DateTime;
use App\MDS\DevelupBundle\Entity\MdvFiles;
use App\MDS\DevelupBundle\Entity\MdvProduct;
use App\MDS\DevelupBundle\Entity\MdvProductFile;
use App\MDS\DevelupBundle\Entity\MdvPaymentsClient;
use App\MDS\DevelupBundle\Entity\MdvDocProformaDeposit;
use App\MDS\DevelupBundle\Entity\MdvDocInvoice;
use App\MDS\DevelupBundle\Entity\MdvDocInvoiceRec;
use App\MDS\DevelupBundle\Entity\MdvDocProformaItems;
use App\MDS\DevelupBundle\Entity\MdvDocProforma;
use App\MDS\DevelupBundle\Entity\MdvDocInvoiceRecItems;
use App\MDS\DevelupBundle\Entity\MdvServices;
use App\MDS\DevelupBundle\Entity\MdvTelegramUser;
use App\MDS\EventsBundle\Entity\ProposalAgents;
use App\MDS\EventsBundle\Entity\ProposalSupplierServices;
use Swift_Mailer;
use Swift_Message;
use Swift_SmtpTransport;
use Symfony\Contracts\Translation\TranslatorInterface;
class InvoiceController extends AbstractController
{
private $translator;
public function __construct(TranslatorInterface $translator) {
$this->translator = $translator;
}
/**
* @Route("/listpaydep/{id}", name="mdv_list_payments_deposits")
* Listar pagos y depositos de un expediente
*/
public function listPaymentsDespositsAction( $id, Request $request){
$em = $this->getDoctrine()->getManager();
$paymentsInFile = $em->getRepository(MdvPaymentsClient::class)->findByFileId($id);
$proformaDepositsInFile = $em->getRepository(MdvDocProformaDeposit::class)->findByFileId($id);
$proformas = array();
$allProformas = $em->getRepository(MdvDocProforma::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/DevelupBundle/Develup/list-payments-deposits.html.twig',
array(
'id' => $id,
'proformas' => $proformas,
'payments' => $paymentsInFile,
'allInvoiceDeposit' => null,
'proformaDepositsInFile' => $proformaDepositsInFile,
)
);
}
/**
* @Route("/paymentadd/{id}", name="mdv_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 MdvPaymentsClient();
$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('mdv_list_payments_deposits',
array(
'id' => $id
)
);
}
/**
* @Route("/paymentdelete/{id}", name="mdv_delete_payment")
* Eliminar pago de un expediente
*/
public function deletePaymentsAction( $id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$payment = $em->getRepository(MdvPaymentsClient::class)->findOneById($id);
$fileId = $payment->getFileId();
$em->remove($payment);
$em->flush();
return $this->redirectToRoute('mdv_list_payments_deposits',
array(
'id' => $fileId
)
);
}
/**
* @Route("/newproformadeposit/{id}", name="mdv_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 MdvDocProformaDeposit();
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('mdv_list_payments_deposits', array( 'id' => $id));
}
return $this->redirectToRoute('mdv_view_proforma_deposit',
array(
'id' => $proforma->getId()
)
);
}
/**
* @Route("/viewproformadeposit/{id}", name="mdv_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(MdvDocProformaDeposit::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('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount()*0.21;
$allProformas = $em->getRepository(MdvDocProformaDeposit::class)->findByFileId($id);
// Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito //6*6*6
return $this->render('MDS/DevelupBundle/Develup/invoice-proforma-invdep.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => $proforma,
'company' => $company,
'clients' => $client,
'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,
'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("/dpexternal/printproformadeposit/{id}", name="mdv_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(MdvDocProformaDeposit::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('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $proforma->getAmount()*0.21;
$allProformas = $em->getRepository(MdvDocProformaDeposit::class)->findByFileId($id);
// Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito //6*6*6
return $this->render('MDS/DevelupBundle/Develup/invoice-proforma-invdep-print.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => $proforma,
'company' => $company,
'clients' => $client,
'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,
'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="mdv_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(MdvDocProformaDeposit::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('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
// Generamos la factura con la proforma especificada
$invoice = new MdvDocInvoice();
$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(MdvDocInvoice::class)->findByFileId($id);
$allProformas = null;
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(MdvDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
$boolToRec = empty($rectf);
return $this->redirectToRoute('mdv_view_invoice_deposit',
array(
'id' => $invoice->getId()
)
);
}
/**
* @Route("/viewinvoicedeposit/{id}", name="mdv_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(MdvDocInvoice::class)->findOneById($id);
$id = $invoice->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet()*0.21;
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($id);
$allInvoicesRec = $em->getRepository(MdvDocInvoiceRec::class)->findByFileId($id);
foreach ($allInvoicesRec as $item) {
array_push($allInvoices, $item);
}
$allProformas = null;
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(MdvDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
$boolToRec = empty($rectf);
return $this->render('MDS/DevelupBundle/Develup/invoice-proforma-invdep.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => null,
'company' => $company,
'clients' => $client,
'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,
// '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("/dpexternal/printinvoicedeposit/{id}", name="mdv_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(MdvDocInvoice::class)->findOneById($id);
$id = $invoice->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet()*0.21;
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($id);
$allProformas = null;
// Una factura solo se puede rectificar una vez
$rectf = $em->getRepository(MdvDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
$boolToRec = empty($rectf);
return $this->render('MDS/DevelupBundle/Develup/invoice-proforma-invdep-print.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => null,
'company' => $company,
'clients' => $client,
'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,
// '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("/newinvoicedepositrec/{id}", name="mdv_invoice_deposit_rec")
* Crear nueva factura rectificativa de deposito
*/
public function newInvoiceDepositRecAction( $id, Request $request)
{
$docType = 'Factura Rectificativa de Deposito';
$em = $this->getDoctrine()->getManager();
if (true){
// Verificamos que no exista una factura rectificativa previa sobre la misma factura
$previusInvoiceRec = $em->getRepository(MdvDocInvoiceRec::class)->findOneByInvoiceToRec($id);
if (!empty($previusInvoiceRec)){ return $this->redirectToRoute('mdv_view_invoice_deposit_rec', array('id' => $previusInvoiceRec->getId())); }
}
$invoice = $em->getRepository(MdvDocInvoice::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('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
// Generamos la factura con la proforma especificada
$invoiceRec = new MdvDocInvoiceRec();
$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->setBalance($totalInv);
$invoiceRec->setType('Factura 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('mdv_view_invoice_deposit_rec', array('id' => $invoiceRec->getId()));
}
/**
* @Route("/viewinvoicedepositrec/{id}", name="mdv_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(MdvDocInvoiceRec::class)->findOneById($id);
$id = $invoice->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet()*0.21;
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($id);
$allProformas = null;
// Una factura solo se puede rectificar una vez
// $rectf = $em->getRepository(MdvDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
$boolToRec = false;
return $this->render('MDS/DevelupBundle/Develup/invoice-proforma-invdep.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => null,
'company' => $company,
'clients' => $client,
'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,
// '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("/dpexternal/printinvoicedepositrec/{id}", name="mdv_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(MdvDocInvoiceRec::class)->findOneById($id);
$id = $invoice->getFileId();
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
$bases_imponibles['ivaMontoVeintiUno'] = $invoice->getTotalNet()*0.21;
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($id);
$allProformas = null;
// Una factura solo se puede rectificar una vez
// $rectf = $em->getRepository(MdvDocInvoiceRec::class)->findBy( array('invoiceToRec' => $invoice->getId()));
$boolToRec = false;
return $this->render('MDS/DevelupBundle/Develup/invoice-proforma-invdep-print.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => null,
'company' => $company,
'clients' => $client,
'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,
// '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("/selinvoice/{id}", name="mdv_select_invoice")
* Seleccionar los items que pasaran a la proforma o factura
*/
public function selectItemsInvoiceAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$paymentsClient = new MdvPaymentsClient();
$paymentsClient->setFileId($id);
$file = $em->getRepository(MdvFiles::class)->findOneById($id);
$payments = $em->getRepository(MdvPaymentsClient::class)->findByFileId($id);
$allProformas = $em->getRepository(MdvDocProforma::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 = "MDV-".$date->format('dmy')."-";
$fileInv = new MdvDocInvoice();
$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(MdvDocInvoiceItems::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(MdvDocInvoiceItems::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(MdvDocInvoiceItems::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/DevelupBundle/Develup/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="mdv_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(MdvDocProforma::class)->findOneById($id);
$id = $proforma->getFileId();
$proformaId = $proforma->getId();
$paymentsClient = new MdvPaymentsClient();
$paymentsClient->setFileId($id);
$file = $em->getRepository(MdvFiles::class)->findOneById($id);
$payments = $em->getRepository(MdvPaymentsClient::class)->findByFileId($id);
$allProformas = $em->getRepository(MdvDocProforma::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 = "MDV-".$date->format('dmy')."-";
$fileInv = new MdvDocInvoice();
$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(MdvDocInvoiceItems::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(MdvDocInvoiceItems::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(MdvDocInvoiceItems::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/DevelupBundle/Develup/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="mdv_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(MdvProductFile::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(MdvDocProformaItems::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 MdvProductFile();
//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 MdvDocProformaItems();
$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(MdvServices::class)->findOneById($key);
$itemProforma = new MdvDocProformaItems();
$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(MdvPaymentsClient::class)->findOneById($key);
$itemProforma = new MdvDocProformaItems();
$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 MdvDocProforma();
$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('mdv_edit_file', array('id' => $id));
}
//FIN: Creamos la proforma
return $this->redirectToRoute('mdv_select_invoice',array('id' => $id));
}
/**
* @Route("/newproforma/", name="mdv_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;
if (!empty($arrayBools['product'])) {
foreach ($arrayBools['product'] as $key => $item) {
if ($item == 'true') {
$boolMakeInvoice = true;
$product = $em->getRepository(MdvProductFile::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(MdvDocProformaItems::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 MdvProductFile();
//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 MdvDocProformaItems();
$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(MdvServices::class)->findOneById($key);
$itemProforma = new MdvDocProformaItems();
$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
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(MdvPaymentsClient::class)->findOneById($key);
$itemProforma = new MdvDocProformaItems();
$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 MdvDocProforma();
// $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('mdv_edit_file', array('id' => $id));
}
//FIN: Creamos la proforma
return $this->redirectToRoute('mdv_view_proforma', array( 'id' => $newProforma->getId()));
}
/**
* @Route("/discardproforma/{id}", name="mdv_discard_proforma")
* Descartar la proforma especificada en el ID
*/
public function discardProformaAction( $id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(MdvDocProforma::class)->findOneById($id);
$fileId = $proforma->getFileId();
//Eliminamos los productos dentro de la proforma
$proformaItems = $em->getRepository(MdvDocProformaItems::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('mdv_edit_file', array('id' => $fileId));
}
/**
* @Route("/viewproforma/{id}", name="mdv_view_proforma")
* Ver una proforma
*/
public function viewProformaAction( $id, Request $request)
{
$docType = 'Proforma';
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(MdvDocProforma::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('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
$data = $this->baseInvoiceDoneDocument($file->getId(), $proforma->getId(), 'P');
$allProformas = $em->getRepository(MdvDocProforma::class)->findByFileId($id);
// Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito //6*6*6
return $this->render('MDS/DevelupBundle/Develup/invoice-proforma-invdep.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => $proforma,
'company' => $company,
'clients' => $client,
'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'],
));
}
/**
* @Route("/dpexternal/printproforma/{id}", name="mdv_print_proforma")
* Imprimir una proforma
*/
public function printProformaAction( $id, Request $request)
{
$docType = 'Proforma';
$em = $this->getDoctrine()->getManager();
$proforma = $em->getRepository(MdvDocProforma::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('3');
// Buscamos el cliente
$file = $em->getRepository(MdvFiles::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());
}
}
// Buscamos el cliente
$data = $this->baseInvoiceDoneDocument($file->getId(), $proforma->getId(), 'P');
$allProformas = $em->getRepository(MdvDocProformaDeposit::class)->findByFileId($id);
// Falta agregar en $allProformas las proformas de facturas, hasta ahora solo estan las proformas de deposito //6*6*6
return $this->render('MDS/DevelupBundle/Develup/invoice-proforma-invdep-print.html.twig',
array(
'id' => $id,
'docType' => $docType,
'proforma' => $proforma,
'company' => $company,
'clients' => $client,
'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'],
));
}
/**
* @Route("/newinvoice/", name="mdv_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(MdvDocInvoice::class)->findAll();
if (!empty($allFacturas)){
$invoiceId = end($allFacturas)->getId() + 1;
} else {
$invoiceId = 1;
}
$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(MdvProductFile::class)->findOneById($key);
$itemInvoice = new MdvDocInvoiceItems();
$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->setPrdDateEnd($sala->getDateEnd());
$itemInvoice->setPrdServicePrice($sala->getServicePrice());
$itemInvoice->setPrdSubTotalPrice($sala->getSubTotalPrice());
$itemInvoice->setPrdQty($sala->getUnits());
$itemInvoice->setPrdPax($sala->getPax());
// $itemInvoice->setItemType($sala->getType());
$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());
$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(MdvServices::class)->findOneById($key);
$itemInvoice = new MdvDocInvoiceItems();
$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(MdvPaymentsClient::class)->findOneById($key);
$itemInvoice = new MdvDocInvoiceItems();
$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 MdvDocInvoice();
$newInvoice->setNumber("MDV-".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('mdv_view_invoices',array('id' => $id));
}
//FIN: Creamos la factura
$data = array();
$data = $this->baseInvoiceSelectedFile($id, $arrayBools,'I'.$newInvoice->getId());
$paymentsClient = new MdvPaymentsClient();
$paymentsClient->setFileId($id);
$file = $em->getRepository(MdvFiles::class)->findOneById($id);
$payments = $em->getRepository(MdvPaymentsClient::class)->findByFileId($id);
$services = $em->getRepository(MdvServices::class)->findByFileId($id);
$proforma = $em->getRepository(MdvDocProforma::class)->findOneByFileId($id);
$reservaInv = new MdvDocInvoice();
$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(MdvDocInvoiceRec::class)->findBy( array('number' => 'REC-'.$newInvoice->getNumber()));
$boolToRec = empty($rectf);
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($id);
$allInvoicesRec = $em->getRepository(MdvDocInvoiceRec::class)->findByFileId($id);
foreach ($allInvoicesRec as $item){
array_push($allInvoices, $item);
}
$allProformas = $em->getRepository(MdvDocProforma::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('mdv_view_invoice',
array(
'id' => $newInvoice->getId()
)
);
}
/**
* @Route("/newinvoicefromproforma/{id}", name="mdv_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(MdvDocProforma::class)->findOneById($id);
//INICIO: Buscamos los elementos de la proforma y verificamos disponibilidad
$proformaOrigenItems = $em->getRepository(MdvDocProformaItems::class)->findByProformaId($id);
$algunItemEstaFacturado = false;
foreach ($proformaOrigenItems as $item){
if ($item->getType() == 'PRODUCT'){
$estaFacturado = $em->getRepository(MdvDocInvoiceItems::class)->findByPrdControlId($item->getControlId());
if (!empty($estaFacturado)){$algunItemEstaFacturado = true;}
}
if ($item->getType() == 'PAYMENT'){
$estaFacturado = $em->getRepository(MdvDocInvoiceItems::class)->findByPayControlId($item->getControlId());
if (!empty($estaFacturado)){$algunItemEstaFacturado = true;}
}
if ($item->getType() == 'SERVICE'){
$estaFacturado = $em->getRepository(MdvDocInvoiceItems::class)->findByPayControlId($item->getControlId());
if (!empty($estaFacturado)){$algunItemEstaFacturado = true;}
}
}
//FIN: Buscamos los elementos de la proforma y verificamos disponibilidad
if ($algunItemEstaFacturado){
$id = $proformaOrigen->getFileId();
return $this->render('MDS/DevelupBundle/Develup/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' => '',
'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(MdvDocInvoice::class)->findAll();
if (!empty($allFacturas)) {
$invoiceId = end($allFacturas)->getId() + 1;
} else {
$invoiceId = 1;
}
$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(MdvProductFile::class)->findOneById($key);
$itemInvoice = new MdvDocInvoiceItems();
$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->setPrdDateEnd($sala->getDateEnd());
$itemInvoice->setPrdServicePrice($sala->getServicePrice());
$itemInvoice->setPrdSubTotalPrice($sala->getSubTotalPrice());
$itemInvoice->setPrdQty($sala->getUnits());
$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());
$itemInvoice->setPrdIva($sala->getIva());
$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(MdvServices::class)->findOneById($key);
$itemInvoice = new MdvDocInvoiceItems();
$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(MdvPaymentsClient::class)->findOneById($key);
$itemInvoice = new MdvDocInvoiceItems();
$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 MdvDocInvoice();
$newInvoice->setNumber('MDV-' . 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('mdv_view_invoices', array('id' => $id));
}
//FIN: Creamos la factura
$data = array();
$data = $this->baseInvoiceSelectedFile($id, $arrayBools, 'I' . $newInvoice->getId());
$paymentsClient = new MdvPaymentsClient();
$paymentsClient->setFileId($id);
$file = $em->getRepository(MdvFiles::class)->findOneById($id);
$payments = $em->getRepository(MdvPaymentsClient::class)->findByFileId($id);
$services = $em->getRepository(MdvServices::class)->findByFileId($id);
$proforma = $em->getRepository(MdvDocProforma::class)->findOneByFileId($id);
$reservaInv = new MdvDocInvoice();
$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(MdvDocInvoiceRec::class)->findBy(array('number' => 'REC-' . $newInvoice->getNumber()));
$boolToRec = empty($rectf);
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($id);
$allInvoicesRec = $em->getRepository(MdvDocInvoiceRec::class)->findByFileId($id);
foreach ($allInvoicesRec as $item) {
array_push($allInvoices, $item);
}
$allProformas = $em->getRepository(MdvDocProforma::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('mdv_view_invoice',
array(
'id' => $newInvoice->getId()
)
);
}
}
/**
* @Route("/viewinvoice/{id}", name="mdv_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(MdvDocInvoiceItems::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();
$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($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(MdvPaymentsClient::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(MdvDocInvoice::class)->findOneById($id);
//FIN: Buscamos la factura
$data = array();
$data = $this->baseInvoiceDoneFile($newInvoice->getFileId(), $id,'I');
$paymentsClient = new MdvPaymentsClient();
$paymentsClient->setFileId($id);
$fileInv = new MdvDocInvoice();
$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(MdvDocInvoiceRec::class)->findBy( array('number' => 'REC-'.$newInvoice->getNumber()));
$boolToRec = empty($rectf);
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($newInvoice->getFileId());
$allInvoicesRec = $em->getRepository(MdvDocInvoiceRec::class)->findByFileId($newInvoice->getFileId());
foreach ($allInvoicesRec as $item){
array_push($allInvoices, $item);
}
$allProformas = $em->getRepository(MdvDocProforma::class)->findByFileId($newInvoice->getFileId());
if(empty($data['type'])){$data['type'] = 'Invoice';}
return $this->render('MDS/DevelupBundle/Develup/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'],
)
);
}
/**
* @Route("/dpexternal/printinvoice/{id}", name="mdv_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');
/* 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(MdvDocInvoiceItems::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(MdvPaymentsClient::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(MdvDocInvoice::class)->findOneById($id);
//FIN: Buscamos la factura
$data = array();
$data = $this->baseInvoiceDoneFile($newInvoice->getFileId(), $id,'I');
$paymentsClient = new MdvPaymentsClient();
$paymentsClient->setFileId($id);
$fileInv = new MdvDocInvoice();
$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(MdvDocInvoiceRec::class)->findBy( array('number' => 'REC-'.$newInvoice->getNumber()));
$boolToRec = empty($rectf);
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($newInvoice->getFileId());
$allInvoicesRec = $em->getRepository(MdvDocInvoiceRec::class)->findByFileId($newInvoice->getFileId());
foreach ($allInvoicesRec as $item){
array_push($allInvoices, $item);
}
$allProformas = $em->getRepository(MdvDocProforma::class)->findByFileId($newInvoice->getFileId());
if(empty($data['type'])){$data['type'] = 'Invoice';}
return $this->render('MDS/DevelupBundle/Develup/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' => $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'],
)
);
}
/**
* @Route("/newinvoicerec/{id}", name="mdv_new_invoice_rec")
* Crear una factura rectificativa
*/
public function generateNewInvoiceRecAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoice = $em->getRepository(MdvDocInvoice::class)->findOneById($id);
if (true){
// Verificamos que no exista una factura rectificativa previa sobre la misma factura
$previusInvoiceRec = $em->getRepository(MdvDocInvoiceRec::class)->findOneByInvoiceToRec($id);
if (!empty($previusInvoiceRec)){ return $this->redirectToRoute('mdv_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 MdvDocInvoiceRec();
$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(MdvDocInvoiceItems::class)->findByInvoiceId($id);
// Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
foreach ($invoiceItems as $item){
$itemRec = new MdvDocInvoiceRecItems();
$itemRec->setFileId($item->getFileId());
$itemRec->setInvoiceId($item->getInvoiceId());
$itemRec->setItemType($item->getItemType());
$itemRec->setInvoiceRecId($invoiceRec->getId());
$itemRec->setPrdControlId($item->getPrdControlId());
$itemRec->setPrdName($item->getPrdName());
$itemRec->setPrdProductId($item->getPrdProductId());
// $itemRec->setPrdIdLounge($item->getPrdIdLounge());
$itemRec->setPrdDateStart($item->getPrdDateStart());
$itemRec->setPrdDateEnd($item->getPrdDateEnd());
$itemRec->setPrdServicePrice($item->getPrdServicePrice()*(-1));
$itemRec->setPrdSubTotalPrice($item->getPrdSubTotalPrice()*(-1));
$itemRec->setPrdQty($item->getPrdQty());
$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->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();
// Se libera asignando ID = 0
$item->setPrdControlId(0);
$item->setSrvControlId(0);
$item->setPayControlId(0);
$em->persist($item);
$em->flush();
}
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($invoice->getFileId());
$allInvoicesRec = $em->getRepository(MdvDocInvoiceRec::class)->findByFileId($invoice->getFileId());
foreach ($allInvoicesRec as $item){
array_push($allInvoices, $item);
}
$file = $em->getRepository(MdvFiles::class)->findOneById($invoice->getFileId());
$client = $em->getRepository(Client::class)->findById($file->getClient());
$data = array();
$data = $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $invoiceRec->getId(),'R');
$data['clients'][0] = $client;
$data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
// Una factura solo se puede rectificar una vez
// $rectf = $em->getRepository('DevelupBundle:MdvInvoiceRec')->findBy( array('number' => 'REC-'.$invoice->getNumber()));
$boolToRec = false;
return $this->redirectToRoute('mdv_view_invoice_rec',
array(
'id' => $invoiceRec->getId()
)
);
}
/**
* @Route("/viewinvoicerec/{id}", name="mdv_view_invoice_rec")
* Ver una factura rectificativa
*/
public function viewInvoiceRecAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoiceRec = $em->getRepository(MdvDocInvoiceRec::class)->findOneById($id);
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$invoiceItems = $em->getRepository(MdvDocInvoiceRecItems::class)->findByInvoiceId($id);
// Cada elemento se duplica en ItemsRec y se libera asignando ID = 0
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($invoiceRec->getFileId());
$allInvoicesRec = $em->getRepository(MdvDocInvoiceRec::class)->findByFileId($invoiceRec->getFileId());
foreach ($allInvoicesRec as $item){
array_push($allInvoices, $item);
}
$file = $em->getRepository(MdvFiles::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('');
} 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());
}
}
$data = array();
$data = $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $id,'R');
$data['clients'] = $client;
$data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
// Una factura solo se puede rectificar una vez
// $rectf = $em->getRepository('DevelupBundle:MdvInvoiceRec')->findBy( array('number' => 'REC-'.$invoice->getNumber()));
$boolToRec = false;
return $this->render('MDS/DevelupBundle/Develup/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' => $data['clients'],
'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'],
)
);
}
/**
* @Route("/dpexternal/printinvoicerec/{id}", name="mdv_print_invoice_rec")
* Imprimir una factura rectificativa
*/
public function printInvoiceRecAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoiceRec = $em->getRepository(MdvDocInvoiceRec::class)->findOneById($id);
$invoiceItems = $em->getRepository(MdvDocInvoiceRecItems::class)->findByInvoiceId($id);
$allInvoices = $em->getRepository(MdvDocInvoice::class)->findByFileId($invoiceRec->getFileId());
$allInvoicesRec = $em->getRepository(MdvDocInvoiceRec::class)->findByFileId($invoiceRec->getFileId());
foreach ($allInvoicesRec as $item){
array_push($allInvoices, $item);
}
$file = $em->getRepository(MdvFiles::class)->findOneById($invoiceRec->getFileId());
$client = $em->getRepository(Client::class)->findOneById($file->getClient());
$data = array();
$data = $this->baseInvoiceDoneFile($invoiceRec->getFileId(), $id,'R');
$data['clients'][0] = $client;
$data['company'] = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
// Una factura solo se puede rectificar una vez
// $rectf = $em->getRepository('DevelupBundle:MdvInvoiceRec')->findBy( array('number' => 'REC-'.$invoice->getNumber()));
$boolToRec = false;
$user_logueado = $this->getUser();
return $this->render('MDS/DevelupBundle/Develup/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' => $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'],
)
);
}
/**
* @Route("/listinvoice/", name="mdv_list_invoices")
* Listar facturas
*/
public function listInvoicesAction( Request $request){
$em = $this->getDoctrine()->getManager();
$invoiced = $em->getRepository(MdvDocInvoice::class)->findAll();
$invoicedRec = $em->getRepository(MdvDocInvoiceRec::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(MdvFiles::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(MdvPaymentsClient::class)->findOneByInvoiceId($item->getId());
if (!empty($payOfInvoiceDeposit)){
// Verificamos si el deposito esta dentro de una factura
$itemInvoiceOfInvoiceDeposit = $em->getRepository(MdvDocInvoiceItems::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(MdvDocInvoiceRecItems::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(MdvDocInvoiceRecItems::class)->findOneByPayControlId($payOfInvoiceDeposit->getId());
}
if (!empty($itemInvoiceOfInvoiceDepositRec)){
$estaEnFacturaRectificativa = true;
}
// FIN: Verificamos factura de deposito dentro de alguna factura
$invoicedDepositItems = $em->getRepository(MdvDocInvoiceItems::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/DevelupBundle/Develup/invoice-list.html.twig',
array(
'invocied' => $invoiced,
'sumatoriaTotalNet' => $sumatoriaTotalNet,
'sumatoriaTotalVat' => $sumatoriaTotalVat,
'sumatoriaTotal' => $sumatoriaTotal,
)
);
}
/**
* @Route("/invoiceispaid/{id}", name="mdv_invoices_is_paid")
* Confirmar y deshacer el pago de la factura
*/
public function invoiceIsPaidAction($id, Request $request)
{
$em = $this->getDoctrine()->getManager();
$invoice = $em->getRepository(MdvDocInvoice::class)->findOneById($id);
if(!empty($invoice)){
if($invoice->getIsPaid()){ $invoice->setIsPaid(false); } else { $invoice->setIsPaid(true); }
try {
$em->persist($invoice);
$em->flush();
$event = 'Se ha actualizado la factura';
$successMessage = $this->translator->trans($event);
$this->addFlash('mensajecontact', $successMessage);
} catch (\Exception $e) {
$event = 'An error occurred: ' . $e->getMessage() . ' | transport';
/* Para el usuario */
$errorMessage = $this->translator->trans($event);
$this->addFlash('mensajecontacterror', $errorMessage);
}
}
return $this->redirectToRoute('mdv_list_invoices');
}
/**
* @Route("/listpendingbud/", name="mdv_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(MdvBudgetPending::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(MdvBudgetToProforma::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(MdvFiles::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(MdvDocProformaItems::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(MdvProductFile::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(MdvBudgetToProforma::class)->findBy(
array(
'status' => 'Tosend', // Pending -> Tosend -> Confirmed -> Invoiced
)
);
$budInPro= array();
foreach ($budInProforma as $item){
$budInPro[$item->getFileId()]['file'] = $em->getRepository(MdvFiles::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(MdvDocProformaItems::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(MdvProductFile::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(MdvBudgetPending::class)->findBy(
array(
'serviceId' => null, // Pending -> Tosend -> Confirmed -> Invoiced
)
);
return $this->render('MDS/DevelupBundle/Develup/list-budgets-pending.html.twig',
array(
'pendingBudgets' => $pBuds,
'keysPendingBudgets' => $keysPbuds,
'budToInvoice' => $budToInvoice,
'budInProforma' => $budInPro,
'briefings' => $briefings,
)
);
}
/**
* @Route("/budgetadd/", name="mdv_list_budget_add")
* Crear los presupuestos (proformas) y los expedientes (si es necesario)
*/
public function budgetsAddAction( Request $request){
$services = $request->request->get('services_hidden');
$logTelegram = false;
//Modificar precios en Eventos (si es necesario)
foreach ($services as $item){
$em = $this->getDoctrine()->getManager();
$pendingBud = $em->getRepository(MdvBudgetPending::class)->findOneById($item['id']);
//INICIO: Creamos el expediente de Develup (en caso de ser necesario)
$file = $em->getRepository(MdvFiles::class)->findOneByIdProposal($pendingBud->getProposalId());
if (empty($file)){
$file = new MdvFiles();
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(5); // Usuario de Jorge de Freita
$file->setUpdatedAt(new DateTime('now'));
$file->setUpdatedId(5); // Usuario de Jorge de Freita
$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(MdvBriefings::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 Develup (en caso de ser necesario)
//INICIO: Creamos el producto dentro del expediente
$mdvProductSelected = $em->getRepository(MdvProduct::class)->findOneById($pendingBud->getServiceId());
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
$newProductFile = new MdvProductFile();
$newProductFile->setProductName($mdvProductSelected->getName());
$newProductFile->setProductId($mdvProductSelected->getId());
$newProductFile->setOriginId($pendingBud->getOriginId());
if (!empty($item['price'])){
$newProductFile->setServicePrice($item['price']);
if (!($item['price'] == $mdvProductSelected->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($mdvProductSelected->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']);
$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());
//Ajustamos el precio quitando el IVA
// $tempPrice = $newProductFile->getServicePrice()*100;
// $tempPrice = bcdiv($tempPrice,'121',2); // Divide entre 121 manteniendo 2 decimales sin redondeo
// $newProductFile->setServicePrice($tempPrice);
$newProductFile->setDescription($mdvProductSelected->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 MdvBudgetToProforma();
$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(MdvBudgetToProforma::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($budToPro)){
foreach ($proformas as $key => $elemento){
//INICIO: Creamos las proformas
//INICIO: Calculamos el ID de la proforma
$numberToPrefix = $em->getRepository(MdvDocProforma::class)->findAll();
if (empty($numberToPrefix)){
$numberToPrefix = 0;
} else {
$numberToPrefix = end($numberToPrefix)->getId();
}
$numberToPrefix++;
//FIN: Calculamos el ID de la proforma
$newProforma = new MdvDocProforma();
$newProforma->setPrefix('MDV-' . (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 MdvDocProformaItems();
$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 DEVELUP __ ID: '.$file->getIdProposal().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
//d('entro en 1',$proposalAgents->getAgOne(), $proposalDestino->getTitle());
}
if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))){
$this->sendTelegram($proposalAgents->getAgTwo(),'2. PRESUPUESTO APROBADO DESDE DEVELUP __ ID: '.$file->getIdProposal().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
//d('entro en 2',$proposalAgents->getAgTwo(), $proposalDestino->getTitle());
}
if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))){
$this->sendTelegram($proposalAgents->getAgThree(),'3. PRESUPUESTO APROBADO DESDE DEVELUP __ ID: '.$file->getIdProposal().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
//d('entro en 3', $proposalAgents->getAgThree(), $proposalDestino->getTitle());
}
if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))){
$this->sendTelegram($proposalAgents->getAgFour(),'4. PRESUPUESTO APROBADO DESDE DEVELUP __ ID: '.$file->getIdProposal().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
//d('entro en 4', $proposalAgents->getAgFour(), $proposalDestino->getTitle());
}
}
}
//FIN: Notificamos al agente por Telegram
//FIN: Creamos el presupuesto (proforma)
return $this->redirectToRoute('mdv_list_pending_bud');
}
/**
* @Route("/budgetsend/", name="mdv_budget_send")
* Envio automatico de los presupuestos forzado por usuario
*/
public function budgetSendAction( Request $request){
$em = $this->getDoctrine()->getManager();
$budToPro = $em->getRepository(MdvBudgetToProforma::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
//INICIO: Calculamos el ID de la proforma
// $numberToPrefix = $em->getRepository(MdvDocProforma::class)->findAll();
// if (empty($numberToPrefix)){
// $numberToPrefix = 0;
// } else {
// $numberToPrefix = end($numberToPrefix)->getId();
// }
// $numberToPrefix++;
// $numberToPrefix++;
//FIN: Calculamos el ID de la proforma
//d($proformas, $elemento);exit();
// $newProforma = new MdvDocProforma();
// $newProforma->setPrefix('MDV-' . (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
if (!empty($item->getProformaId())) {
$arrayIdPro[$item->getProformaId()] = $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 MdvDocProformaItems();
// $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('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 Develup #' . $key . ', ' . '<br><a href="http://' . $request->server->get('HTTP_HOST') . '/pdf/develupproforma/' . $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(MdvDocProforma::class)->findOneById($key);
$file = $em->getRepository(MdvFiles::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 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 DE DEVELUP ENVIADO POR CORREO __ ID: '.$file->getIdProposal().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
//d('entro en 1',$proposalAgents->getAgOne(), $proposalDestino->getTitle());
}
if ((!empty($proposalAgents->getAgTwo())) and (!($proposalAgents->getAgTwo() == 0))){
$this->sendTelegram($proposalAgents->getAgTwo(),'2. PRESUPUESTO DE DEVELUP ENVIADO POR CORREO __ ID: '.$file->getIdProposal().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
//d('entro en 2',$proposalAgents->getAgTwo(), $proposalDestino->getTitle());
}
if ((!empty($proposalAgents->getAgThree())) and (!($proposalAgents->getAgThree() == 0))){
$this->sendTelegram($proposalAgents->getAgThree(),'3. PRESUPUESTO DE DEVELUP ENVIADO POR CORREO __ ID: '.$file->getIdProposal().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
//d('entro en 3', $proposalAgents->getAgThree(), $proposalDestino->getTitle());
}
if ((!empty($proposalAgents->getAgFour())) and (!($proposalAgents->getAgFour() == 0))){
$this->sendTelegram($proposalAgents->getAgFour(),'4. PRESUPUESTO DE DEVELUP ENVIADO POR CORREO __ ID: '.$file->getIdProposal().' __ PROVEEDOR: Develup __ CONTACTO: '.$userData->getName().' '.$userData->getLastName());
//d('entro en 4', $proposalAgents->getAgFour(), $proposalDestino->getTitle());
}
}
}
//FIN: Notificamos al agente por Telegram
}
//FIN: Notificamos de todos los presupuestos (proformas) que se han creado
return $this->redirectToRoute('mdv_list_pending_bud');
// return new JsonResponse('Done');
}
/**
* @Route("/budgetdel/{id}", name="mdv_list_budget_del")
* Eliminar el producto de la solicitud de presupuesto
*/
public function budgetsDeleteAction($id, Request $request){
$em = $this->getDoctrine()->getManager();
$budget = $em->getRepository(MdvBudgetPending::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('mdv_list_pending_bud');
}
/**
* @Route("/cargaservicios/", name="mdv_carga_servicios")
* actualizar servicios develup desde inout events (Controlador inaccesible)
*/
public function cargaServiciosAddAction( Request $request){
$em = $this->getDoctrine()->getManager();
$services = $em->getRepository(SupplierTechnology::class)->findAll();
/* Obtengo usuario logueado */
$user_logueado = $this->get('security.token_storage')->getToken()->getUser();
$user_id = $user_logueado->getId();
foreach ($services as $item){
$temp = new MdvProduct();
$temp->setName($item->getTitle());
$temp->setPrice($item->getPrice());
$temp->setType($item->getType());
$temp->setCreatedId($user_id);
$temp->setUpdatedId($user_id);
$temp->setCreatedAt(new DateTime('now'));
$temp->setUpdatedAt(new DateTime('now'));
$em->persist($temp);
$em->flush();
}
d($services);exit();
}
/**
* @Route("/newinvoicefrombudget/{id}", name="mdv_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(MdvDocProformaItems::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(MdvBudgetToProforma::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('mdv_new_invoice_from_proforma',
array(
'id' => $id
)
);
}
/**
* @Route("/budgetdiscard/{id}", name="mdv_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(MdvBudgetToProforma::class)->findOneByProductFileId($item->getControlId());
$elemBudToProf->setStatus('Discarded');
$em->persist($item);
$em->flush();
}
return $this->redirectToRoute('mdv_list_pending_bud');
}
/**
* @Route("/updateinvoicedate/", name="mdv_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(MdvDocInvoice::class)->findOneById($invoiceId);
$newDate = new DateTime($invoiceNewDate);
$invoice->setDateAt($newDate);
// Modificamos el number para que se adapte a la nueva fecha
$invoice->setNumber('MDV-' . $newDate->format('dmy') . substr($invoice->getNumber(),10));
$invoice->setUpdatedId($user_id);
$invoice->setUpdatedAt(new DateTime('now'));
$em->persist($invoice);
$em->flush();
return $this->redirectToRoute('mdv_list_invoices');
}
/**
* @Route("/budgetbriefdiscard/{id}", name="mdv_budget_briefing_discard")
* Eliminar un budget que es de tipo Briefing
*/
public function budgetBriefDiscardAction($id, Request $request){
$em = $this->getDoctrine()->getManager();
$pendingBud = $em->getRepository(MdvBudgetPending::class)->findOneById($id);
// Se elimina el presupuesto pendiente
$em->remove($pendingBud);
$em->flush();
return $this->redirectToRoute('mdv_list_pending_bud');
}
// Replicar cambios entre FileController, InvoiceController y ProductsFilesController
private function calculosFile($id, $arrayBools, $number, $type)
{
// $id Id del Expediente (File)
// $arrayBool arreglo de logicos
// $number *********************
// $type tipo de calculos a realizar (edicion de expediente, factura, factura de deposito, proforma)
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(MdvFiles::class)->findOneById($id);
$items = $em->getRepository(MdvProductFile::class)->findByFileId($file->getId());
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
$client = $em->getRepository(Client::class)->findById($file->getClient());
if (!empty($client)){
$city = ($em->getRepository(Cities::class)->findOneById($client[0]->getPopulation()));
$client[0]->setPopulation($city);
$region = ($em->getRepository(Regions::class)->findOneById($client[0]->getRegion()));
$client[0]->setRegion($region);
$country = ($em->getRepository(Country::class)->findOneById($client[0]->getCountry()));
$client[0]->setCountry($country);
} else {
$client[0] = new Client();
$client[0]->setName('');
$client[0]->setTitle('');
$client[0]->setIdDocument('');
$client[0]->setPopulation('');
$client[0]->setRegion('');
$client[0]->setCountry('');
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => 0,
);
//INICIO: Determinamos el numero de factura o proforma
if (substr($number,0,1) == 'I'){
// Es una Factura
$numberInvoiceOrProforma = substr($number,1);
$number = $numberInvoiceOrProforma;
// $number = $em->getRepository('DevelupBundle:FileInvoice')->findOneById($number);
// $number = $number->getNumber();
$type = 'Invoice';
} else {
// Es una Proforma
$numberInvoiceOrProforma = substr($number,1);
$number = $numberInvoiceOrProforma;
// $number = $em->getRepository('DevelupBundle:FileProforma')->findOneById($number);
// $number = $number->getPrefix().$number->getReservationId();
$type = 'Proforma';
}
//FIN: Determinamos el numero de factura o proforma
// Buscamos las salas reservadas, pagos y servicios para el evento
$arrayItems = array();
$fileProducts = array();
if (!empty($arrayBools['product'])) {
foreach ($arrayBools['product'] as $key => $item) {
if ($item == 'true') {
// $fileProducts[] = $em->getRepository('DevelupBundle:ReservationLoungeSimple')->findOneById($key);
}
}
}
$payments = array();
if (!empty($arrayBools['payment'])) {
foreach ($arrayBools['payment'] as $key => $item) {
if ($item == 'true') {
// $payments[] = $em->getRepository('DevelupBundle:ReservationPaymentsClient')->findOneById($key);
}
}
}
$services = array();
if (!empty($arrayBools['service'])) {
foreach ($arrayBools['service'] as $key => $item) {
if ($item == 'true') {
// $services[] = $em->getRepository('DevelupBundle:ReservationService')->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
if (empty($items)){
$data_supplier['product'][0] = null;
}
foreach ($items as $item){
if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
} else {
$subtotalProduct = $item->getServicePrice() * 1.21;
$subneto = $item->getServicePrice();
$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;
$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(),
'description' => $item->getDescription(),
'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){
$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 (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 ($type == 'Invoice'){
$em->clear(); // sin este clear se producia error al guardar
$newInvoice = $em->getRepository(MdvDocInvoice::class)->findOneById($numberInvoiceOrProforma);
$newInvoice->setBalance($totales_all);
$em->persist($newInvoice);
$em->flush();
}
$data = array(
'id' => $id,
'type' => $type,
'number' => $number,
'prefix' => 'GPF-'.(new DateTime('now'))->format('dmy').'-',
'date' => new DateTime('now'),
'file' => $file,
// 'token' => $file->getAccessKey(),
'company' => $company,
'clients' => $client,
'arrayItems' => $arrayItems,
'datasupplier' => $data_supplier,
'currency' => $currency,
'totales_neto' => $totales_neto_all,
'bases_imponibles' => $data_iva,
'totales' => $totales_total,
'balance' => $totales_all,
'paymentInvoice' => $amount_pay,
);
return $data;
}
private function baseInvoiceFile($id, $type, $number, $prefix, $date)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(MdvFiles::class)->findOneById($id);
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
$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());
}
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => 0,
);
// Buscamos las salas reservadas, pagos y servicios para el evento
$productsInFile = $em->getRepository(MdvProductFile::class)->findByFileId($id);
$payments = $em->getRepository(MdvPaymentsClient::class)->findByFileId($id);
$services = $em->getRepository(MdvServices::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){
// Verificamos que el producto no se encuentre ya en una factura
$existe = $em->getRepository(MdvDocInvoiceItems::class)->findByPrdControlId($item->getId());
$days = 1;
$factorIva = (empty($item->getIva()) and !($item->getIva() == 0)) ? 21 : $item->getIva();
$factorIva = $factorIva / 100;
if (!((empty($item->getDateInAt()) or empty($item->getDateOutAt())))){
$days = ((($item->getDateOutAt())->diff($item->getDateInAt()))->days + 1);
}
$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->getSubTotalPrice() * (1 + $factorIva);
$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);
switch ($factorIva){
case 0.21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * $factorIva); break;
case 0: $data_iva['ivaMontoCero'] = 0; 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);
$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' => ($factorIva * 100),
'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(MdvDocInvoiceItems::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(MdvDocInvoiceItems::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' => $client,
'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(MdvFiles::class)->findOneById($id);
$items = $em->getRepository(MdvDocProformaItems::class)->findByFileId($file->getId());
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
$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());
}
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => 0,
);
//INICIO: Determinamos el numero de factura o proforma
if (substr($number,0,1) == 'I'){
// Es una Factura
$numberInvoiceOrProforma = substr($number,1);
$number = $numberInvoiceOrProforma;
$number = $em->getRepository(MdvDocInvoice::class)->findOneById($number);
$number = $number->getNumber();
$type = 'Invoice';
} else {
// Es una Proforma
$numberInvoiceOrProforma = substr($number,1);
$number = $numberInvoiceOrProforma;
$number = $em->getRepository(MdvDocProforma::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(MdvProductFile::class)->findOneById($key);
}
}
}
$payments = array();
if (!empty($arrayBools['payment'])) {
foreach ($arrayBools['payment'] as $key => $item) {
if ($item == 'true') {
$payments[] = $em->getRepository(MdvPaymentsClient::class)->findOneById($key);
}
}
}
$services = array();
if (!empty($arrayBools['service'])) {
foreach ($arrayBools['service'] as $key => $item) {
if ($item == 'true') {
$services[] = $em->getRepository(MdvServices::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){
$factorIva = empty($item->getIva()) ? 21 : $item->getIva();
$factorIva = $factorIva / 100;
if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
} else {
$subtotalProduct = $item->getSubTotalPrice() * (1 + $factorIva);
$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' => ($factorIva * 100),
'total' => $subtotal,
);
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
// $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * 0.21);
switch ($factorIva){
case 0.21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * $factorIva); break;
case 0: $data_iva['ivaMontoCero'] = 0; 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);
$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' => ($factorIva * 100),
'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(),
// 'iva' => '',
// 'total' => $item->getAmount(),
);
$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 = ((($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 ($type == 'Invoice'){
$em->clear(); // sin este clear se producia error al guardar
$newInvoice = $em->getRepository(MdvDocInvoice::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' => $client,
'arrayItems' => $arrayItems,
'datasupplier' => $data_supplier,
'currency' => $currency,
'totales_neto' => $totales_neto_all,
'bases_imponibles' => $data_iva,
'totales' => $totales_total,
'balance' => $totales_all,
'paymentInvoice' => $amount_pay,
);
return $data;
}
private function baseInvoiceDoneDocument($fileId, $invoiceId, $typeBase)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(MdvFiles::class)->findOneById($fileId);
$dateDocument = null; //Fecha final del documento
if (($typeBase == 'I') or ($typeBase == 'P')) {
if ($typeBase == 'I') {
// Es una factura
$items = $em->getRepository(MdvDocInvoiceItems::class)->findBy(array('fileId' => $fileId, 'invoiceId' => $invoiceId));
} else {
// Es una proforma
$items = $em->getRepository(MdvDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
}
} else {
// No es factura ni proforma, es una rectificativa
$items = $em->getRepository(MdvDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId, 'invoiceRecId' => $invoiceId));
}
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('2');
$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());
}
}
// 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
// $numberInvoiceOrProforma = $invoiceId;
// $number = $invoiceId;
$number = $em->getRepository(MdvDocInvoice::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$number = $number->getNumber();
$type = 'Invoice';
} else {
if ($typeBase == 'R'){
// Es una factura rectificativa
$number = $em->getRepository(MdvDocInvoiceRec::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$type = 'Invoice Rec';
} else {
// Es una Proforma
// $number = $em->getRepository(MdvDocProforma::class)->findOneById($invoiceId);
// $number = $number->getNumber();
$number = $invoiceId;
$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(MdvProductFile::class)->findOneById($item->getControlId());
if (!empty($productPro)) {
$fileProducts[] = $productPro;
}
break;
case 'PAYMENT': // Pago
$paymentPro = $em->getRepository(MdvPaymentsClient::class)->findOneById($item->getControlId());
if (!empty($paymentPro)) {
$payments[] = $paymentPro;
}
break;
case 'SERVICE': // Servicio
$servicePro = $em->getRepository(MdvServices::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 = ((($item->getDateEnd())->diff($item->getDateStart()))->days + 1);
$subtotalProduct = 0;
$subtotalLounge = 0;
$factorIva = empty($item->getIva()) ? 21 : $item->getIva();
$factorIva = $factorIva / 100;
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 {
$subtotalLounge = $item->getSubTotalPrice() * (1 + $factorIva);
$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(),
'amountSubTotal' => $neto,
'iva' => ($factorIva * 100),
'total' => $subtotal,
);
}
} else {
// Es proforma
if (is_null($item->getSubTotalPrice()) or empty($item->getSubTotalPrice())){
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
} else {
$subtotalProduct = $item->getSubTotalPrice() * (1 + $factorIva);
$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' => ($factorIva * 100),
'total' => $subtotal,
);
}
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
switch ($factorIva){
case 0.21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * $factorIva); break;
case 0: $data_iva['ivaMontoCero'] = 0; 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);
$pax = $item->getPax();
$qty = $item->getUnits();
if (!empty($item->getDays())){ $days = $item->getDays(); }
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->getServicePrice(),
'serviceSubTotalPrice' => $item->getSubTotalPrice(),
'subtotalLounge' => $subtotalLounge,
'iva' => ($factorIva * 100),
'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(),
'servicePrice' => $item->getServicePrice(),
'serviceSubTotalPrice' => $item->getSubTotalPrice(),
'subtotalProduct' => $subtotalProduct,
'iva' => ($factorIva * 100),
'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(),
// 'iva' => '',
// 'total' => $item->getPayAmount(),
);
} 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(),
// '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' => 'MDV-'.(new DateTime('now'))->format('dmy').'-'.$fileId,
'date' => $dateDocument,
'file' => $file,
'company' => $company,
'clients' => $client,
'arrayItems' => $arrayItems,
'datasupplier' => $data_supplier,
'currency' => $currency,
'totales_neto' => $totales_neto_all,
'bases_imponibles' => $data_iva,
'totales' => $totales_total,
'balance' => $totales_all,
'paymentInvoice' => $amount_pay,
);
return $data;
}
private function baseInvoiceDoneFile($fileId, $invoiceId, $typeBase)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(MdvFiles::class)->findOneById($fileId);
$dateDocument = null; //Fecha final del documento
$subneto = 0;
if (($typeBase == 'I') or ($typeBase == 'P')) {
if ($typeBase == 'I') {
$items = $em->getRepository(MdvDocInvoiceItems::class)->findBy(array('fileId' => $fileId, 'invoiceId' => $invoiceId));
} else {
// Es factura ni proforma
$items = $em->getRepository(MdvDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
}
} else {
// No es factura ni proforma, es una rectificativa
$items = $em->getRepository(MdvDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId, 'invoiceRecId' => $invoiceId));
}
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
$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());
}
}
// 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(MdvDocInvoice::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$number = $number->getNumber();
$type = 'Invoice';
} else {
if ($typeBase == 'R'){
// Es una factura rectificativa
$number = $em->getRepository(MdvDocInvoiceRec::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(MdvProductFile::class)->findOneById($item->getControlId());
if (!empty($productPro)) {
$fileProducts[] = $productPro;
}
break;
case 'PAYMENT': // Pago
$paymentPro = $em->getRepository(MdvPaymentsClient::class)->findOneById($item->getControlId());
if (!empty($paymentPro)) {
$payments[] = $paymentPro;
}
break;
case 'SERVICE': // Servicio
$servicePro = $em->getRepository(MdvServices::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 = ((($item->getPrdDateEnd())->diff($item->getPrdDateStart()))->days + 1);
$factorIva = $item->getPrdIva() === null ? 21 : $item->getPrdIva();
$factorIva = $factorIva / 100;
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 {
$subtotalProduct = $item->getPrdSubTotalPrice() * (1 + $factorIva);
$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' => ($factorIva * 100),
'total' => $subtotal,
);
}
} else {
// Es proforma
if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
$subtotal = 0; $neto = 0; $subtotalProduct = 0;
} else {
$subtotalProduct = $item->getServicePrice() * (1 + $factorIva);
$subneto = $item->getServicePrice();
$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' => ($factorIva * 100),
'total' => $subtotal,
);
}
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
switch ($factorIva){
case 0.21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * $factorIva); break;
case 0: $data_iva['ivaMontoCero'] = 0; 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' => ($factorIva * 100),
'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' => ($factorIva * 100),
'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
// $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' => 'MDV-'.(new DateTime('now'))->format('dmy').'-'.$invoiceId,
'date' => $dateDocument,
'file' => $file,
'token' => $file->getAccessKey(),
'company' => $company,
'clients' => $client,
'arrayItems' => $arrayItems,
'datasupplier' => $data_supplier,
'currency' => $currency,
'totales_neto' => $totales_neto_all,
'bases_imponibles' => $data_iva,
'totales' => $totales_total,
'balance' => $totales_all,
'paymentInvoice' => $amount_pay,
);
return $data;
}
private function baseInvoiceDoneFileTwo($fileId, $invoiceId, $typeBase)
{
$em = $this->getDoctrine()->getManager();
$file = $em->getRepository(MdvFiles::class)->findOneById($fileId);
$dateDocument = null; //Fecha final del documento
$subneto = 0;
if (($typeBase == 'I') or ($typeBase == 'P')) {
if ($typeBase == 'I') {
$items = $em->getRepository(MdvDocInvoiceItems::class)->findBy(array('fileId' => $fileId, 'invoiceId' => $invoiceId));
} else {
// Es factura ni proforma
$items = $em->getRepository(MdvDocProformaItems::class)->findBy(array('fileId' => $fileId, 'proformaId' => $invoiceId));
}
} else {
// No es factura ni proforma, es una rectificativa
$items = $em->getRepository(MdvDocInvoiceRecItems::class)->findBy(array('fileId' => $fileId, 'invoiceRecId' => $invoiceId));
}
$company = $em->getRepository(SettingsCompany::class)->findOneByPriority('3');
$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());
}
}
// 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(MdvDocInvoice::class)->findOneById($invoiceId);
$dateDocument = $number->getDateAt();
$number = $number->getNumber();
$type = 'Invoice';
} else {
if ($typeBase == 'R'){
// Es una factura rectificativa
$number = $em->getRepository(MdvDocInvoiceRec::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(MdvProductFile::class)->findOneById($item->getControlId());
if (!empty($productPro)) {
$fileProducts[] = $productPro;
}
break;
case 'PAYMENT': // Pago
$paymentPro = $em->getRepository(MdvPaymentsClient::class)->findOneById($item->getControlId());
if (!empty($paymentPro)) {
$payments[] = $paymentPro;
}
break;
case 'SERVICE': // Servicio
$servicePro = $em->getRepository(MdvServices::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){
$factorIva = empty($item->getIva()) ? 21 : $item->getIva();
$factorIva = $factorIva / 100;
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;
} else {
$subtotalProduct = $item->getPrdSubTotalPrice() * (1 + $factorIva);
$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' => ($factorIva * 100),
'total' => $subtotal,
);
}
} else {
// Es proforma
if (is_null($item->getServicePrice()) or empty($item->getServicePrice())){
$subtotal = 0;
$neto = 0;
$subtotalProduct = 0;
} else {
$subtotalProduct = $item->getServicePrice() * (1 + $factorIva);
$subneto = $item->getServicePrice();
$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' => ($factorIva * 100),
'total' => $subtotal,
);
}
}
// Acumula netos totales e IVA
$totales_neto_all = $totales_neto_all + $neto;
switch ($factorIva){
case 0.21: $data_iva['ivaMontoVeintiUno'] = $data_iva['ivaMontoVeintiUno'] + ($neto * $factorIva); break;
case 0: $data_iva['ivaMontoCero'] = 0; 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' => ($factorIva * 100),
'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' => ($factorIva * 100),
'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' => 'MDV-'.(new DateTime('now'))->format('dmy').'-'.$invoiceId,
'date' => $dateDocument,
'file' => $file,
'token' => $file->getAccessKey(),
'company' => $company,
'clients' => $client,
'arrayItems' => $arrayItems,
'datasupplier' => $data_supplier,
'currency' => $currency,
'totales_neto' => $totales_neto_all,
'bases_imponibles' => $data_iva,
'totales' => $totales_total,
'balance' => $totales_all,
'paymentInvoice' => $amount_pay,
);
return $data;
}
private function 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(MdvFiles::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());
}
}
// Acumuladores de los calculos
$totales_neto_all = 0;
$data_iva = array(
'iva' => 21,
'ivaMontoVeintiUno' => 0,
'ivaMontoDiez' => 0,
'ivaMontoCero' => 0,
);
// Buscamos las salas reservadas, pagos y servicios para el evento
// Buscamos los productos de la proforma
$productsInProforma = $em->getRepository(MdvDocProformaItems::class)->findByProformaId($proformaId);
$productsInFile = array();
foreach ($productsInProforma as $item){
$producto = $em->getRepository(MdvProductFile::class)->findOneById($item->getControlId());
if (!empty($producto)){ $productsInFile[] = $producto; }
}
// $productsInFile = $em->getRepository(MdvProductFile::class)->findByFileId($id);
$payments = $em->getRepository(MdvPaymentsClient::class)->findByFileId($id);
$services = $em->getRepository(MdvServices::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(MdvDocInvoiceItems::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(MdvDocInvoiceItems::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(MdvDocInvoiceItems::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' => $client,
'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;
}
};