245 lines
6.2 KiB
PHP
Executable File
245 lines
6.2 KiB
PHP
Executable File
<?php
|
|
|
|
class VistaPrevia extends Comprobante
|
|
{
|
|
function VistaPreviaComprobante($data, $notaCredito = false)
|
|
{
|
|
global $empresa;
|
|
global $rfc;
|
|
global $cliente;
|
|
global $util;
|
|
global $venta;
|
|
|
|
$myData = urlencode(serialize($data));
|
|
$infEmp = $empresa->InfoAll();
|
|
$values = explode("&", $data["datosFacturacion"]);
|
|
unset($data["datosFacturacion"]);
|
|
foreach($values as $key => $val)
|
|
{
|
|
$array = explode("=", $values[$key]);
|
|
$data[$array[0]] = $array[1];
|
|
}
|
|
|
|
$tipoSerie = explode("-", $data["tiposComprobanteId"]);
|
|
$data["tiposComprobanteId"] = $tipoSerie[0];
|
|
$data["tiposSerieId"] = $tipoSerie[1];
|
|
|
|
$empresa->setRFC($data["rfc"]);
|
|
$empresa->setCalle($data["calle"]);
|
|
$empresa->setPais($data["pais"]);
|
|
|
|
if(strlen($data["formaDePago"]) <= 0)
|
|
{
|
|
$empresa->Util()->setError(10041, "error", "");
|
|
}
|
|
|
|
if(count($_SESSION["conceptos"]) < 1)
|
|
{
|
|
$empresa->Util()->setError(10040, "error", "");
|
|
}
|
|
|
|
$myConceptos = urlencode(serialize($_SESSION["conceptos"]));
|
|
|
|
$userId = $data["userId"];
|
|
|
|
$totales = $this->GetTotalDesglosado($data);
|
|
|
|
/*** AJUSTAMOS TOTALES ***/
|
|
|
|
$ventaId = $data['ventaId'];
|
|
|
|
if($ventaId){
|
|
|
|
$venta->setVentaId($ventaId);
|
|
$infV = $venta->Info();
|
|
|
|
$difCents = $infV['total'] - $totales['total'];
|
|
$difCents = number_format($difCents,2,'.','');
|
|
|
|
if($difCents == 0.01 || $difCents == -0.01){
|
|
$totales['iva'] += $difCents;
|
|
$totales['ivaThis'] += $difCents;
|
|
$totales['total'] += $difCents;
|
|
}
|
|
|
|
$totales['iva'] = number_format($totales['iva'],2,'.','');
|
|
$totales['ivaThis'] = number_format($totales['ivaThis'],2,'.','');
|
|
|
|
}
|
|
|
|
/*** FIN AJUSTAR TOTALES ***/
|
|
|
|
if($empresa->Util()->PrintErrors()){ return false; }
|
|
|
|
if(!$data["tipoDeCambio"])
|
|
{
|
|
$data["tipoDeCambio"] = "1.00";
|
|
}
|
|
|
|
if(!$data["porcentajeDescuento"])
|
|
{
|
|
$data["porcentajeDescuento"] = "0";
|
|
}
|
|
|
|
if(!$data["porcentajeIEPS"])
|
|
{
|
|
$data["porcentajeIEPS"] = "0";
|
|
}
|
|
|
|
//get active rfc
|
|
$activeRfc = $rfc->getRfcActive();
|
|
//get datos serie de acuerdo al tipo de comprobabte expedido.
|
|
|
|
if(!$data["tiposComprobanteId"])
|
|
{
|
|
$empresa->Util()->setError(10047, "error");
|
|
}
|
|
|
|
if($empresa->Util()->PrintErrors()){ return false; }
|
|
|
|
if($notaCredito)
|
|
{
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery("SELECT * FROM serie WHERE tiposComprobanteId = '2' AND empresaId = ".$_SESSION["empresaId"]." AND rfcId = '".$activeRfc."' AND consecutivo != folioFinal AND serieId = ".$data["tiposSerieId"]." ORDER BY serieId DESC LIMIT 1");
|
|
}
|
|
else
|
|
{
|
|
$sql = "SELECT
|
|
*
|
|
FROM
|
|
serie
|
|
WHERE
|
|
tiposComprobanteId = ".$data["tiposComprobanteId"]."
|
|
AND
|
|
empresaId = ".$_SESSION["empresaId"]."
|
|
AND
|
|
rfcId = '".$activeRfc."'
|
|
AND
|
|
consecutivo != folioFinal
|
|
AND
|
|
serieId = ".$data["tiposSerieId"]."
|
|
ORDER BY
|
|
serieId DESC
|
|
LIMIT
|
|
1";
|
|
$this->Util()->DBSelect($_SESSION["empresaId"])->setQuery($sql);
|
|
}
|
|
|
|
$serie = $this->Util()->DBSelect($_SESSION["empresaId"])->GetRow();
|
|
|
|
if(!$serie)
|
|
{
|
|
$empresa->Util()->setError(10047, "error");
|
|
}
|
|
|
|
if($empresa->Util()->PrintErrors()){ return false; }
|
|
|
|
$folio = $serie["consecutivo"];
|
|
$fecha = $this->Util()->FormatDateAndTime(time());
|
|
|
|
//el tipo de comprobante lo determina tiposComprobanteId
|
|
$tipoDeComprobante = $this->GetTipoComprobante($data["tiposComprobanteId"]);
|
|
$data["comprobante"] = $this->InfoComprobante($data["tiposComprobanteId"]);
|
|
|
|
$data["serie"] = $serie;
|
|
$data["folio"] = $folio;
|
|
$data["fecha"] = $fecha;
|
|
$data["tipoDeComprobante"] = $tipoDeComprobante;
|
|
$data["certificado"] = $serie["noCertificado"];
|
|
|
|
//build informacion nodo emisor
|
|
$sucursal = new Sucursal;
|
|
$sucursal->setSucursalId($data["sucursalId"]);
|
|
$nodoEmisor = $sucursal->Info();
|
|
$nodoEmisor['identificador'] = $nodoEmisor['nombre'];
|
|
|
|
$rfc->setRfcId($activeRfc);
|
|
$nodoEmisorRfc = $rfc->Info();
|
|
|
|
$data["nodoEmisor"]["sucursal"] = $nodoEmisor;
|
|
$data["nodoEmisor"]["rfc"] = $nodoEmisorRfc;
|
|
|
|
if($_SESSION["version"] == "auto")
|
|
{
|
|
$rootQr = DOC_ROOT."/empresas/".$_SESSION["empresaId"]."/qrs/";
|
|
$qrRfc = strtoupper($nodoEmisorRfc["rfc"]);
|
|
$nufa = $serie["serieId"]."_".$serie["noAprobacion"]."_".$qrRfc.".png";
|
|
//echo $rootQr.$nufa;
|
|
if(!file_exists($rootQr.$nufa))
|
|
{
|
|
$nufa = $serie["serieId"]."_".$serie["noAprobacion"]."_".$qrRfc."_.png";
|
|
if(!file_exists($rootQr.$nufa))
|
|
{
|
|
$empresa->Util()->setError(10048, "error");
|
|
}
|
|
}
|
|
|
|
if($empresa->Util()->PrintErrors()){ return false; }
|
|
|
|
}
|
|
|
|
//Build informacion Nodo Receptor
|
|
|
|
if($_SESSION['tipoComp'] == 'Publico'){
|
|
|
|
$rfc->setRfcId($activeRfc);
|
|
$nodoReceptor = $rfc->Info();
|
|
$nodoReceptor['nombre'] = $nodoReceptor['razonSocial'];
|
|
$data["nodoReceptor"] = $nodoReceptor;
|
|
|
|
}else{
|
|
|
|
$userId = $data["userId"];
|
|
$cliente->setClienteId($userId);
|
|
$nodoReceptor = $cliente->Info();
|
|
$nodoReceptor = $util->EncodeRow($nodoReceptor);
|
|
$data["nodoReceptor"] = $nodoReceptor;
|
|
|
|
}
|
|
|
|
//check tipo de cambio
|
|
|
|
switch($_SESSION["version"])
|
|
{
|
|
case "auto":
|
|
case "v3":
|
|
case "construc":
|
|
include_once(DOC_ROOT.'/classes/cadena_original_v3.class.php');break;
|
|
case "2":
|
|
include_once(DOC_ROOT.'/classes/cadena_original_v2.class.php');break;
|
|
}
|
|
$cadena = new Cadena;
|
|
$cadenaOriginal = $cadena->BuildCadenaOriginal($data, $serie, $totales, $nodoEmisor, $nodoReceptor, $_SESSION["conceptos"]);
|
|
|
|
$data["cadenaOriginal"] = utf8_encode($cadenaOriginal);
|
|
$data["cadenaOriginal"] = $cadenaOriginal;
|
|
|
|
$md5Cadena = utf8_decode($cadenaOriginal);
|
|
|
|
if(date("Y") > 2010)
|
|
{
|
|
$md5 = sha1($md5Cadena);
|
|
}
|
|
|
|
//Cambios 29 junio 2011
|
|
|
|
switch($_SESSION["version"])
|
|
{
|
|
case "v3":
|
|
case "construc": include_once(DOC_ROOT."/classes/override_generate_pdf_default.php"); break;
|
|
case "auto": include_once(DOC_ROOT."/classes/override_generate_pdf_default_auto.php");break;
|
|
case "2": include_once(DOC_ROOT."/classes/override_generate_pdf_default_2.php");break;
|
|
}
|
|
|
|
$override = new Override;
|
|
$pdf = $override->GeneratePDF($data, $serie, $totales, $nodoEmisor, $nodoReceptor, $_SESSION["conceptos"],$infEmp,0, "vistaPrevia");
|
|
|
|
|
|
return true;
|
|
|
|
}//VistaPreviaComprobante
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|