ACTUALIZACIONES REALIZADAS: ✅ Eliminados hardcodeos en 13 archivos crons/ ✅ Actualizado ajax/facturas.php para uso dinámico ✅ Implementada lógica predeterminada para crons (empresaId=1) ✅ Sistema respeta sesión de usuario dinámica ✅ Compatible con funcionamiento independiente de crons VERIFICACIONES: ✅ No quedan hardcodeos 'empresaId = 15' ✅ Base de datos dinámica: 1→ventas_nm, >1→ventas_nm{id} ✅ Crons usan predeterminado si no hay sesión ✅ AJAX hereda empresaId del login ARCHIVOS MODIFICADOS: - crons/*.php (13 archivos actualizados) - ajax/facturas.php (eliminado hardcodeo) - test_fase3.php (verificación de funcionamiento) - md/plan-accion-multi-empresa.md (actualizado) PRÓXIMO: Fase 4 - Pruebas y validación final
231 lines
6.5 KiB
PHP
Executable File
231 lines
6.5 KiB
PHP
Executable File
<?php
|
|
|
|
session_start();
|
|
include_once('../init.php');
|
|
include_once('../config.php');
|
|
include_once('../libraries.php');
|
|
|
|
// CAMBIO CRÍTICO: Eliminar hardcodeo - usar valor dinámico
|
|
// El AJAX debe heredar el empresaId del login del usuario
|
|
if(!isset($_SESSION['empresaId']) || empty($_SESSION['empresaId'])) {
|
|
$_SESSION['empresaId'] = 1; // Valor predeterminado si no hay sesión
|
|
}
|
|
|
|
switch($_POST["type"]){
|
|
|
|
case 'doLogin':
|
|
|
|
$rfc = trim($_POST['rfc']);
|
|
$password = trim($_POST['password']);
|
|
|
|
$rfc->setRfc($rfc);
|
|
$facturacion->setPassword($password);
|
|
$facturacion->setRfcId($rfc->getRfcId());
|
|
|
|
if($facturacion->DoLogin())
|
|
{
|
|
$facturas = $facturacion->EnlistarFacturas(false);
|
|
|
|
$smarty->assign('facturas', $facturas);
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->display(DOC_ROOT.'/templates/facturas.tpl');
|
|
|
|
}else
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('error', $facturacion->GetError());
|
|
$smarty->display(DOC_ROOT.'/templates/facturas.tpl');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'addFactura':
|
|
|
|
$facturacion->setRfcId($_POST['rfcId']);
|
|
$facturacion->setFacturaId($_POST['facturaId']);
|
|
$facturacion->setSerie($_POST['serie']);
|
|
$facturacion->setFolio($_POST['folio']);
|
|
$facturacion->setTotal($_POST['total']);
|
|
$facturacion->setSubtotal($_POST['subtotal']);
|
|
$facturacion->setDescuento($_POST['descuento']);
|
|
$facturacion->setTraslado($_POST['traslado']);
|
|
$facturacion->setRetencion($_POST['retencion']);
|
|
$facturacion->setFecha($_POST['fecha']);
|
|
$facturacion->setFormaPago($_POST['formaPago']);
|
|
$facturacion->setMetodoPago($_POST['metodoPago']);
|
|
$facturacion->setMoneda($_POST['moneda']);
|
|
$facturacion->setTipoCambio($_POST['tipoCambio']);
|
|
$facturacion->setTipoComprobante($_POST['tipoComprobante']);
|
|
$facturacion->setLugarExpedicion($_POST['lugarExpedicion']);
|
|
$facturacion->setNumCtaPago($_POST['numCtaPago']);
|
|
$facturacion->setFolioFiscal($_POST['folioFiscal']);
|
|
$facturacion->setRfcReceptor($_POST['rfcReceptor']);
|
|
$facturacion->setNombreReceptor($_POST['nombreReceptor']);
|
|
$facturacion->setConceptos($_POST['conceptos']);
|
|
|
|
if($facturacion->AddFactura())
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('message', 'La factura ha sido agregada.');
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
|
|
}else
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('error', $facturacion->GetError());
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'deleteFactura':
|
|
|
|
$facturacion->setFacturaId($_POST['facturaId']);
|
|
|
|
if($facturacion->DeleteFactura())
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('message', 'La factura ha sido eliminada.');
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
|
|
}else
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('error', $facturacion->GetError());
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'enlazarFactura':
|
|
|
|
$facturaId = $_POST['facturaId'];
|
|
$facturacion->setFacturaId($facturaId);
|
|
|
|
if($facturacion->EnlazarFactura())
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('message', 'La factura ha sido enlazada correctamente.');
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
|
|
}else
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('error', $facturacion->GetError());
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'download':
|
|
|
|
$facturaId = $_GET['facturaId'];
|
|
$factura = $facturacion->DownloadFactura($facturaId);
|
|
$facturacion->setFacturaId($facturaId);
|
|
$facturas = $facturacion->EnlistarFacturas(false);
|
|
|
|
header("Content-Disposition: attachment; filename=\"".$factura['rfc']."-".$factura['serie'].$factura['folio'].".xml\"");
|
|
echo $factura['xml'];
|
|
break;
|
|
|
|
case 'cancelar':
|
|
|
|
$facturaId = $_GET['facturaId'];
|
|
$facturacion->setFacturaId($facturaId);
|
|
|
|
$facturas = $facturacion->EnlistarFacturas(false);
|
|
$facturaInfo = $facturacion->InfoFactura();
|
|
|
|
$usr = $_POST['usr'];
|
|
$pass = $_POST['pass'];
|
|
$uuid = $facturaInfo['uuid'];
|
|
$pac = new Pac;
|
|
|
|
//parametros para cancelar
|
|
$pac->SetParametros($usr,$pass,$facturaInfo['rfcEmisor']);
|
|
|
|
$res = $pac->CancelarFactura($uuid);
|
|
|
|
if($res['cancelada'])
|
|
{
|
|
$facturacion->setStatus('cancelada');
|
|
if($facturacion->UpdateFactura())
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('message', 'La factura ha sido cancelada.');
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
}else
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('error', $facturacion->GetError());
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
}
|
|
}else
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('error', $res['mensaje']);
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
}
|
|
|
|
break;
|
|
|
|
case 'updateAcuse':
|
|
|
|
$facturaId = $_POST['facturaId'];
|
|
$facturacion->setFacturaId($facturaId);
|
|
$acuse = $_POST['acuse'];
|
|
|
|
$facturacion->setAcuse($acuse);
|
|
if($facturacion->UpdateAcuse())
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('message', 'El acuse ha sido actualizado correctamente.');
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
|
|
}else
|
|
{
|
|
$smarty->assign('docRoot', DOC_ROOT);
|
|
$smarty->assign('error', $facturacion->GetError());
|
|
$smarty->display(DOC_ROOT.'/templates/messages.tpl');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'downloadPdf':
|
|
|
|
$facturaId = $_GET['facturaId'];
|
|
$factura = $facturacion->DownloadFactura($facturaId);
|
|
$facturacion->setFacturaId($facturaId);
|
|
|
|
$pdf = new PDF_MC_Table('L','mm','Letter');
|
|
$pdf->Open();
|
|
$pdf->AddPage();
|
|
|
|
$pdf->SetMargins(10,10,10);
|
|
$pdf->SetFont('Helvetica','',7);
|
|
|
|
$conceptos = $facturacion->GetConceptos();
|
|
|
|
$pdf->AddCol(20,'C','Clave');
|
|
$pdf->AddCol(70,'L','Descripcion');
|
|
$pdf->AddCol(15,'R','Cantidad');
|
|
$pdf->AddCol(15,'R','Valor Unitario');
|
|
$pdf->AddCol(15,'R','Importe');
|
|
$pdf->AddCol(15,'R','IVA');
|
|
$pdf->AddCol(15,'R','Importe Total');
|
|
|
|
$pdf->TableHeader($conceptos);
|
|
$pdf->TableContent($conceptos);
|
|
|
|
$pdf->Output();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
?>
|