Files
ventas_php/modules/_facturacion-nueva.php

200 lines
5.7 KiB
PHP
Executable File

<?php
$empresa->AuthUser();
if(!$usuario->AllowPage($page, $_SESSION['loginKey'])){
header('Location: '.WEB_ROOT);
exit;
}
$sucursalId = $_SESSION['idSuc'];
$_SESSION['tipoComp'] = '';
$_SESSION['compFI'] = '';
$_SESSION['compFF'] = '';
$_SESSION['conceptos'] = array();
$_SESSION['impuestos'] = array();
$_SESSION["notasPorFacturar"] = array();
$totalDesglosado = array(
'subtotal' => '0.00',
'descuento' => '0.00',
'afterDescuento' => '0.00',
'iva' => '0.00',
'afterIva' => '0.00',
'ieps' => '0.00',
'afterImpuestos' => '0.00',
'retIva' => '0.00',
'retIsr' => '0.00',
'total' => '0.00'
);
if(is_numeric($_GET['ventaId'])){
$ventaId = $_GET['ventaId'];
$venta->setVentaId($ventaId);
$infV = $venta->Info();
$venta->LoadProductos();
if($infV['valDesc'] > 0){
$datos['porcentajeDescuento'] = $infV['valDesc'];
$post['porcentajeDescuento'] = $infV['valDesc'];
}
$totalDesglosado = $venta->GetTotalDesglosado($datos);
$difCents = $infV['total'] - $totalDesglosado['total'];
$difCents = number_format($difCents,2,'.','');
if($difCents == 0.01 || $difCents == -0.01){
$totalDesglosado['iva'] += $difCents;
$totalDesglosado['afterIva'] += $difCents;
$totalDesglosado['afterImpuestos'] += $difCents;
$totalDesglosado['total'] += $difCents;
}
$totalDesglosado['iva'] = number_format($totalDesglosado['iva'],2,'.','');
$totalDesglosado['afterIva'] = number_format($totalDesglosado['afterIva'],2,'.','');
$totalDesglosado['afterDescuento'] = number_format($totalDesglosado['afterDescuento'],2,'.','');
$totalDesglosado['afterImpuestos'] = number_format($totalDesglosado['afterImpuestos'],2,'.','');
$totalDesglosado['total'] = number_format($totalDesglosado['total'],2,'.','');
if($totalDesglosado){
foreach($totalDesglosado as $key => $total)
{
$totalDesglosado[$key] = number_format($totalDesglosado[$key], 2);
}
}
$concepts = $util->DecodeResult($_SESSION["conceptos"]);
$smarty->assign('ventaId', $ventaId);
$smarty->assign('conceptos', $concepts);
$smarty->assign("totalDesglosado", $totalDesglosado);
}elseif(isset($_GET['mensual'])){
/*
Factura Octubre = 2013-08-30 al 2013-09-28
Factura Noviembre = 2013-09-29 al 2013-10-29
Factura Diciembre = 2013-10-30 al 2013-11-28
*/
$venta->setSucursalId($sucursalId);
$vta = $venta->GetFirstTicket();
$fechaX = date('Y-m-01',strtotime($vta['fecha']));
while($fechaX < date('Y-m-01',strtotime('- 1 months'))){
$fechaI = date('Y-m-d', strtotime($fechaX.' - 2 days'));
$venta->setFecha($fechaI);
if(!$venta->MesFacturado()){
//START
$fechaT = $fechaX;
$fechaI = date('Y-m-d', strtotime($fechaT.' - 2 days'));
$fecha2 = date('Y-m-d', strtotime($fechaT.' + 1 months'));
$fechaF = date('Y-m-d', strtotime($fecha2.' - 3 days'));
$venta->setSucursalId($sucursalId);
$total = $venta->TotalTicketsNoFact($fechaI, $fechaF);
if($total == 0)
$fechaX = date('Y-m-d', strtotime($fechaX.' + 1 months'));
else
break;
//END
}else{
$fechaX = date('Y-m-d', strtotime($fechaX.' + 1 months'));
}
}
$fechaX = date('Y-m-d', strtotime($fechaX.' + 1 months'));
//$fechaT = date('Y-m-01');
$fechaT = $fechaX;
$fechaT = date('Y-m-d', strtotime($fechaT.' - 1 months'));
$fechaIni = date('Y-m-d', strtotime($fechaT.' - 2 days'));
$fecha2 = date('Y-m-d', strtotime($fechaT.' + 1 months'));
$fechaFin = date('Y-m-d', strtotime($fecha2.' - 3 days'));
//$fechaIni = '2013-09-10';
//$fechaFin = '2013-10-30';
$venta->setSucursalId($sucursalId);
$venta->TicketsNoFacturados($fechaIni, $fechaFin);
$_SESSION['tipoComp'] = 'Publico';
$_SESSION['compFI'] = $fechaIni;
$_SESSION['compFF'] = $fechaFin;
$facturacion->LoadConceptoPublico($_SESSION["notasPorFacturar"], $fechaIni, $fechaFin);
$notasPorFacturar = implode("-", $_SESSION["notasPorFacturar"]);
$totalDesglosado = $facturacion->GetTotalDesglosado();
if($totalDesglosado){
foreach($totalDesglosado as $key => $total)
{
$totalDesglosado[$key] = number_format($totalDesglosado[$key], 2);
}
}
//Obtenemos la informacion del RFC
$rfc->setRfcId(1);
$infR = $rfc->Info();
$post['rfc'] = $infR['rfc'];
$post['razonSocial'] = $infR['razonSocial'];
$post['calle'] = $infR['calle'];
$post['noExt'] = $infR['noExt'];
$post['noInt'] = $infR['noInt'];
$post['colonia'] = $infR['colonia'];
$post['municipio'] = $infR['ciudad'];
$post['estado'] = $infR['estado'];
$post['cp'] = $infR['cp'];
$post['pais'] = 'MEXICO';
$post['referencia'] = $infR['referencia'];
$post['metodoPago'] = 'Efectivo';
$smarty->assign('post', $_SESSION['conceptos']);
$smarty->assign('ventaId', 'publico');
$smarty->assign('conceptos', $_SESSION['conceptos']);
$smarty->assign('notasPorFacturar', $notasPorFacturar);
$smarty->assign('totalDesglosado', $totalDesglosado);
}//elseif
$ivas = $main->ListIvas();
$retIsrs = $main->ListRetIsr();
$retIvas = $main->ListRetIva();
$tiposDeMoneda = $main->ListTipoDeMoneda();
$comprobantes = $main->ListTiposDeComprobantesValidos();
$sucursal->setSucursalId($sucursalId);
$infSuc = $sucursal->Info();
$infSuc['nombre'] = urldecode($infSuc['nombre']);
$infSuc['nombre'] = utf8_decode($infSuc['nombre']);
$excentoIva = $main->ListExcentoIva();
$smarty->assign("ivas", $ivas);
$smarty->assign("retIsrs", $retIsrs);
$smarty->assign("retIvas", $retIvas);
$smarty->assign("excentoIva", $excentoIva);
$smarty->assign("infSuc", $infSuc);
$smarty->assign("post", $post);
$smarty->assign('totalDesglosado', $totalDesglosado);
$smarty->assign("tiposDeMoneda", $tiposDeMoneda);
$smarty->assign("comprobantes", $comprobantes);
?>