Primer commit del sistema avantika sin cambios

This commit is contained in:
2026-01-06 19:42:24 -06:00
commit 3ae4be5957
7127 changed files with 440072 additions and 0 deletions

142
export/buenfin-proveedor.php Executable file
View File

@@ -0,0 +1,142 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
if($Usr['type'] != 'admin' && $Usr['type'] != 'gerente' && $Usr['type'] != 'centralizador'){
header('Location: '.WEB_ROOT);
exit;
}
$name = "R_Buen_Fin_Proveedor";
extract($_POST);
$idSucursal = $_POST['idSucursal'];
$idProveedor = $_POST['idProveedor'];
$fechaIni = date('Y-m-d',strtotime($_POST['fechaI']));
$fechaFin = date('Y-m-d',strtotime($_POST['fechaF']));
$promocionId = $promocion->GetBuenFinId();
if($idProveedor)
$sqlFilter = ' AND prov.proveedorId = '.$idProveedor;
$reportes->setIdSuc($idSucursal);
$resSuc = $reportes->EnumSucursales();
$totales['prods'] = 0;
$totales['costo'] = 0;
$sucursales = array();
foreach($resSuc as $res){
$sucursalId = $res['sucursalId'];
$sql = 'SELECT prov.proveedorId, prov.nombre, SUM(vp.cantidad) AS totalProds,
SUM(vp.cantidad * p.costo) AS totalCosto
FROM venta AS v, ventaProducto AS vp, producto AS p, proveedor AS prov
WHERE v.ventaId = vp.ventaId
AND vp.productoId = p.productoId
AND p.proveedorId = prov.proveedorId
AND ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
AND v.status <> "Descuento"
AND prov.baja = "0"
AND vp.promocionId = "'.$promocionId.'"
AND v.fecha >= "'.$fechaIni.' 00:00:00"
AND v.fecha <= "'.$fechaFin.' 23:59:59"
AND v.sucursalId = "'.$sucursalId.'"
'.$sqlFilter.'
GROUP BY prov.proveedorId';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$res['proveedores'] = $util->DBSelect($_SESSION['empresaId'])->GetResult();
$sql = 'SELECT SUM(vp.cantidad) AS totalProds,
SUM(vp.cantidad * p.costo) AS totalCosto
FROM venta AS v, ventaProducto AS vp, producto AS p, proveedor AS prov
WHERE v.ventaId = vp.ventaId
AND vp.productoId = p.productoId
AND p.proveedorId = prov.proveedorId
AND ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
AND v.status <> "Descuento"
AND prov.baja = "0"
AND vp.promocionId = "'.$promocionId.'"
AND v.fecha >= "'.$fechaIni.' 00:00:00"
AND v.fecha <= "'.$fechaFin.' 23:59:59"
'.$sqlFilter.'
AND v.sucursalId = "'.$sucursalId.'"';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$row = $util->DBSelect($_SESSION['empresaId'])->GetRow();
$res['totalProds'] = $row['totalProds'];
$res['totalCosto'] = $row['totalCosto'];
$totales['prods'] += $row['totalProds'];
$totales['costo'] += $row['totalCosto'];
$sucursales[] = $res;
}//foreach
$x .= "<table border=\"1\">";
foreach($sucursales as $res){
$x.="<thead>
<tr>
<th style=\"background:#E0E5E7;text-align:center\" colspan=\"4\"><b>".utf8_decode(urldecode($res['nombre']))."</b></th>
</tr>
</thead><tbody>";
$x .= "
<tr>
<td style=\"background:#E0E5E7;text-align:center\">No. Prov.</td>
<td style=\"background:#E0E5E7;text-align:center\">Proveedor</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Productos Vendidos</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Costo Total</td>
</tr>";
foreach($res['proveedores'] as $val){
$x .= "
<tr>
<td style='text-align:center;'>".$val['proveedorId']."</td>
<td>".$val['nombre']."</td>
<td style=\"text-align:center; padding-right:20px\">".$val['totalProds']."</td>
<td style=\"text-align:right; padding-right:20px\">$".number_format($val['totalCosto'],2)."</td>
</tr>";
}
$x .= "
<tr>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\"></td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Total</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">".$res['totalProds']."</td>
<td style=\"background:#E0E5E7;text-align:right\" padding-right:20px\">$".number_format($res['totalCosto'],2)."</td>
</tr>";
}
$x .= "
<tr>
<td style=\"text-align:center\" padding-right:20px\"></td>
<td style=\"text-align:center\" padding-right:20px\">TOTAL GENERAL</td>
<td style=\"text-align:center\" padding-right:20px\">".$totales['prods']."</td>
<td style=\"text-align:right\" padding-right:20px\">$".number_format($totales['costo'],2)."</td>
</tr>";
$x .= "</tbody>";
$x .= "</table>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

79
export/cuentas-pagar-saldos.php Executable file
View File

@@ -0,0 +1,79 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
extract($_POST);
$proveedor->setProveedorId($_POST['proveedorId2']);
$proveedores = $proveedor->SearchSaldos($_POST['saldoIni2']);
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"5\">
<b>SALDOS INICIALES PROVEEDORES</b>
</th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>No. Prov.</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Proveedor</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Saldo Inicial</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Abonos</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Saldo Actual</b></th>
</tr>
</thead>
<tbody>";
$total = 0;
foreach($proveedores as $res){
//Obtenemos los abonos realizados
$cuentaPagar->setProveedorId($res['proveedorId']);
$res['abonos'] = $cuentaPagar->GetTotalPagosProv();
$res['saldoActual'] = $res['saldoCtaPagar'] - $res['abonos'];
$x .= "
<tr>
<td style=\"text-align:center;\">".$res['noProv']."</td>
<td style=\"text-align:left;\">".$res['nombre']."</td>
<td style=\"text-align:right;\">$".number_format($res['saldoCtaPagar'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['abonos'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['saldoActual'],2)."</td>
</tr>";
$total += $res['saldoCtaPagar'];
$totalAbonos += $res['abonos'];
$totalSaldoActual += $res['saldoActual'];
}//foreach
$x .= "
<tr>
<td style=\"text-align:center;\"></td>
<td style=\"text-align:center;\"><b>TOTAL</b></td>
<td style=\"text-align:right;\"><b>$".number_format($total,2)."</b></td>
<td style=\"text-align:right;\"><b>$".number_format($totalAbonos,2)."</b></td>
<td style=\"text-align:right;\"><b>$".number_format($totalSaldoActual,2)."</b></td>
</tr>";
$x .= "
</tbody>
</table>";
$name = 'Saldos_Iniciales_Prov';
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

255
export/cuentas-pagar.php Executable file
View File

@@ -0,0 +1,255 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
extract($_POST);
$global = $_POST['global'];
if($global == 1){
$cuentaPagar->setProveedorId($_POST['proveedorId2']);
$resProv = $cuentaPagar->EnumProveedores();
$info['total'] = 0;
$info['totalAbonos'] = 0;
$info['totalNotas'] = 0;
$info['totalDesc'] = 0;
$info['totalBonif'] = 0;
$info['totalDev'] = 0;
$info['totalSaldo'] = 0;
$info['totalSaldoInicial'] = 0;
$info['totalTotal'] = 0;
$proveedores = array();
foreach($resProv as $val){
$proveedor->setProveedorId($val['proveedorId']);
$val['proveedor'] = $proveedor->GetNameById();
$proveedor->setProveedorId($val['proveedorId']);
$infP = $proveedor->Info();
$cuentaPagar->setProveedorId($val['proveedorId']);
$resCuenta = $cuentaPagar->Search();
$totalG = 0;
$totAbonos = 0;
$totNotas = 0;
$totBonificaciones = 0;
$totDevoluciones = 0;
$totDescuentos = 0;
$totSaldo = 0;
foreach($resCuenta as $res){
if(preg_match('/FOLIO/i',$res['folioProv']))
continue;
//Obtenemos los abonos realizados
$cuentaPagar->setPedidoId($res['pedidoId']);
$res['abonos'] = $cuentaPagar->GetTotalPagos();
$res['totalNotas'] = $cuentaPagar->GetTotalNotas();
$bonificacion->setPedidoId($res['pedidoId']);
$res['bonificaciones'] = $bonificacion->getBonificaciones();
$res['devoluciones'] = $bonificacion->getDevoluciones();
$totalDesc = $res['totalPub'] + $res['totalDes'] + $res['totalFlete'] + $res['totalEsp'];
$res['totalDescuentos'] = number_format($totalDesc,2,'.','');
if($res['total2'] > 0)
$res['total'] = $res['total2'];
$res['saldo'] = $res['total'] - $res['abonos'] - $res['bonificaciones'] - $res['devoluciones'] - $res['totalDescuentos'] - $res['totalNotas'];
$totalG += $res['total'];
$totAbonos += $res['abonos'];
$totNotas += $res['totalNotas'];
$totBonificaciones += $res['bonificaciones'];
$totDevoluciones += $res['devoluciones'];
$totDescuentos += $res['totalDescuentos'];
$totSaldo += $res['saldo'];
$info['total'] += $res['total'];
$info['totalAbonos'] += $res['abonos'];
$info['totalNotas'] += $res['totalNotas'];
$info['totalDesc'] += $res['totalDescuentos'];
$info['totalBonif'] += $res['bonificaciones'];
$info['totalDev'] += $res['devoluciones'];
$info['totalSaldo'] += $res['saldo'];
}//foreach
if($totalG > 0){
$cuentaPagar->setProveedorId($val['proveedorId']);
$abonosSaldoIni = $cuentaPagar->GetTotalPagosProv();
$val['total'] = $totalG + $infP['saldoCtaPagar'];
$val['abonos'] += ($totAbonos + $abonosSaldoIni);
$val['totalNotas'] += $totNotas;
$val['bonificaciones'] += $totBonificaciones;
$val['devoluciones'] += $totDevoluciones;
$val['totalDescuentos'] += $totDescuentos;
$val['saldo'] += ($totSaldo + $infP['saldoCtaPagar'] - $abonosSaldoIni);
$val['saldoInicial'] = $infP['saldoCtaPagar'];
$val['totalTotal'] = $val['saldo'] + $infP['saldoCtaPagar'];
$info['totalSaldoInicial'] += $infP['saldoCtaPagar'];
$info['totalTotal'] += $val['totalTotal'];
$info['total'] += $infP['saldoCtaPagar'];
$info['totalSaldo'] += ($infP['saldoCtaPagar'] - $abonosSaldoIni);
$info['totalAbonos'] += $abonosSaldoIni;
$proveedores[] = $val;
}
}//foreach
$items = $util->orderMultiDimensionalArray($proveedores, 'proveedor');
}else{
$cuentaPagar->setProveedorId($_POST['proveedorId2']);
$resCuenta = $cuentaPagar->Search();
$items = array();
foreach($resCuenta as $res){
if(preg_match('/FOLIO/i',$res['folioProv']))
continue;
$proveedor->setProveedorId($res['proveedorId']);
$res['proveedor'] = $proveedor->GetNameById();
//Obtenemos los abonos realizados
$cuentaPagar->setPedidoId($res['pedidoId']);
$res['abonos'] = $cuentaPagar->GetTotalPagos();
$res['totalNotas'] = $cuentaPagar->GetTotalNotas();
$bonificacion->setPedidoId($res['pedidoId']);
$res['bonificaciones'] = $bonificacion->getBonificaciones();
$res['devoluciones'] = $bonificacion->getDevoluciones();
$totalDesc = $res['totalPub'] + $res['totalDes'] + $res['totalFlete'] + $res['totalEsp'];
$res['totalDescuentos'] = number_format($totalDesc,2,'.','');
if($res['total2'] > 0)
$res['total'] = $res['total2'];
$res['saldo'] = $res['total'] - $res['abonos'] - $res['bonificaciones'] - $res['devoluciones'] - $res['totalDescuentos'] - $res['totalNotas'];
$items[] = $res;
}//foreach
}
$colspan = 9;
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan='".$colspan."'>
<b>CUENTAS POR PAGAR</b>
</th>
</tr>
<tr>";
if($global)
$title = 'No. Prov.';
else
$title = 'No. Pedido';
$x .= " <th style=\"background:#E0E5E7;text-align:center\"><b>".$title."</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Proveedor</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Abonos</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Notas Credito</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Descuentos</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Bonificaciones</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Devoluciones</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Saldo</b></th>";
$x .= "</tr>
</thead>
<tbody>";
$total = 0;
$totalAbonos = 0;
$totalNotas = 0;
$totalDesc = 0;
$totalBonif = 0;
$totalDev = 0;
$totalSaldo = 0;
$saldoInicial = 0;
$totalTotal = 0;
foreach($items as $res){
if($global)
$valor = $res['proveedorId'];
else
$valor = $res['noPedido'];
$x .= "
<tr><td style=\"text-align:center;\">".$valor."</td>
<td style=\"text-align:left;\">".$res['proveedor']."</td>
<td style=\"text-align:right;\">$".number_format($res['total'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['abonos'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['totalNotas'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['totalDescuentos'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['bonificaciones'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['devoluciones'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['saldo'],2)."</td>";
$x .= "
</tr>";
$total += $res['total'];
$totalAbonos += $res['abonos'];
$totalNotas += $res['totalNotas'];
$totalDesc += $res['totalDescuentos'];
$totalBonif += $res['bonificaciones'];
$totalDev += $res['devoluciones'];
$totalSaldo += $res['saldo'];
$saldoInicial += $res['saldoInicial'];
$totalTotal += $res['totalTotal'];
}//foreach
$x .= "
<tr>
<td style=\"text-align:center;\"></td>
<td style=\"text-align:center;\"><b>TOTAL</b></td>
<td style=\"text-align:right;\"><b>$".number_format($total,2)."</b></td>
<td style=\"text-align:right;\"><b>$".number_format($totalAbonos,2)."</b></td>
<td style=\"text-align:right;\"><b>$".number_format($totalNotas,2)."</b></td>
<td style=\"text-align:right;\"><b>$".number_format($totalDesc,2)."</b></td>
<td style=\"text-align:right;\"><b>$".number_format($totalBonif,2)."</b></td>
<td style=\"text-align:right;\"><b>$".number_format($totalDev,2)."</b></td>
<td style=\"text-align:right;\"><b>$".number_format($totalSaldo,2)."</b></td>";
$x .= "
</tr>";
$x .= "
</tbody>
</table>";
$name = 'Cuentas_Pagar_Prov';
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
exit;
?>

142
export/envios-transito.php Executable file
View File

@@ -0,0 +1,142 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
$name = "R_Envios_Transito";
extract($_POST);
$sucursalId2 = $_POST['sucursalId2'];
$proveedorId2 = $_POST['proveedorId2'];
if($_POST['fechaIni2'])
$fechaIni = date('Y-m-d',strtotime($_POST['fechaIni2']));
if($_POST['fechaFin2'])
$fechaFin = date('Y-m-d',strtotime($_POST['fechaFin2']));
$envio->setFechaIni($fechaIni);
$envio->setFechaFin($fechaFin);
$envio->setSucursalId($sucursalId2);
$envios = $envio->GetEnviosTransito();
$cantTotal = 0;
$productos = array();
foreach($envios as $res){
$envioId = $res['envioId'];
$sucursalId = $res['sucursalId'];
$sucursal->setSucursalId($sucursalId);
$nomSuc = utf8_decode(urldecode($sucursal->GetNameById()));
$envio->setEnvioId($envioId);
$pedidos = $envio->GetPedidosByEnvio();
foreach($pedidos as $val){
$pedidoId = $val['pedidoId'];
$envio->setPedidoId($pedidoId);
$envio->setSucursalId($sucursalId);
$resProds = $envio->GetProductos2();
foreach($resProds as $prod){
$productoId = $prod['productoId'];
$producto->setProductoId($productoId);
$infP = $producto->Info();
if($proveedorId2){
if($proveedorId2 != $infP['proveedorId'])
continue;
}
$proveedor->setProveedorId($infP['proveedorId']);
$card['proveedor'] = $proveedor->GetNameById();
$card['cantidad'] = $prod['cantidad'];
$card['sucursal'] = $nomSuc;
$card['modelo'] = $infP['modelo'];
$card['codigoBarra'] = $infP['codigoBarra'];
$card['envioId'] = $envioId;
$card['fecha'] = $res['fecha'];
$cantTotal += $card['cantidad'];
$productos[] = $card;
}//foreach
}//foreach
}//foreach
$x = "
<table>
<th colspan=\"7\" style=\"text-align:center\">COMERCIALIZADORA NOVOMODA S.A. DE C.V.</th>
</table>
<br><br>
";
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>Sucursal</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Proveedor</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Codigo Barra</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Producto</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Cantidad</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>No. Envio</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Fecha</b></th>
</tr>
</thead>
<tbody>";
foreach($productos as $res){
$x .= "
<tr>
<td style=\"text-align:left;\">".$res['sucursal']."</td>
<td style=\"text-align:left;\">".$res['proveedor']."</td>
<td style=\"text-align:center;\">".$res['codigoBarra']."</td>
<td style=\"text-align:left;\">".$res['modelo']."</td>
<td style=\"text-align:center;\">".$res['cantidad']."</td>
<td style=\"text-align:center;\">".$res['envioId']."</td>
<td style=\"text-align:center;\">".$res['fecha']."</td>
</tr>";
}//foreach
if(count($productos) > 0){
$x .= "
<tr>
<td></td>
<td></td>
<td></td>
<td style=\"text-align:left;\">TOTAL</td>
<td style=\"text-align:center;\">".$cantTotal."</td>
<td></td>
<td></td>
</tr>";
}
$x .= "
</tbody>
</table>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

97
export/envios-traspasos.php Executable file
View File

@@ -0,0 +1,97 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
$name = "R_Envios_Traspasos";
extract($_POST);
$sucursalId = $_POST['sucursalId2'];
$status = $_POST['status2'];
$fechaEnvio = $_POST['fechaEnvio2'];
$ordenCompra = $_POST['ordenCompra2'];
$envio->setSucursalId($sucursalId);
$envio->setNoPedido($ordenCompra);
$envio->setStatus($status);
if($fechaEnvio)
$envio->setFecha(date('Y-m-d',strtotime($fechaEnvio)));
if($Usr['type'] == 'gerente')
$envio->setSucursalId($_SESSION['idSuc']);
$resEnvios = $envio->Search();
$envios = array();
foreach($resEnvios as $res){
$sucursal->setSucursalId($res['sucursalId']);
$res['sucursal'] = utf8_decode(urldecode($sucursal->GetNameById()));
$fecha = date('d-m-Y',strtotime($res['fecha']));
$res['fecha'] = $util->FormatDateDMMMY($fecha);
$envio->setEnvioId($res['envioId']);
$res['enviaron'] = $envio->GetTotalPrendas();
$res['recibieron'] = $envio->GetTotalRec();
$res['diferencia'] = $res['enviaron'] - $res['recibieron'];
$envios[] = $res;
}
$x = "
<table>
<th colspan=\"7\" style=\"text-align:center\">COMERCIALIZADORA NOVOMODA S.A. DE C.V.</th>
</table>
<br><br>
";
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>No.</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Fecha Env&iacute;o</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Sucursal</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Enviaron</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Recibieron</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Diferencia</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Status</b></th>
</tr>
</thead>
<tbody>";
foreach($envios as $res){
$x .= "
<tr>
<td style=\"text-align:center;\">".$res['envioId']."</td>
<td style=\"text-align:right;\">".$res['fecha']."</td>
<td style=\"text-align:right;\">".$res['sucursal']."</td>
<td style=\"text-align:right;\">".$res['enviaron']."</td>
<td style=\"text-align:center;\">".$res['recibieron']."</td>
<td style=\"text-align:center;\">".$res['diferencia']."</td>
<td style=\"text-align:center;\">".$res['status']."</td>
</tr>";
}//foreach
$x .= "
</tbody>
</table>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

1190
export/exportarexcel.php Executable file

File diff suppressed because it is too large Load Diff

188
export/general-dias.php Executable file
View File

@@ -0,0 +1,188 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$start = microtime(true);
$Usr = $user->Info();
if($Usr['type'] != 'admin' && $Usr['type'] != 'gerente' && $Usr['type'] != 'centralizador' && $Usr['type'] != 'almacen' && $Usr['type'] != 'facturacion' && $Usr['type'] != 'direccion' && $Usr['type'] != 'compras' && $Usr['type'] != 'supervisor'){
header('Location: '.WEB_ROOT);
exit;
}
$name = "R_General_Dias";
extract($_POST);
$sucursalId = $_POST['sucursalId'];
$fechaI = $_POST['fechaI'];
$fechaF = $_POST['fechaF'];
$fechaI2 = date('Y-m-d',strtotime($fechaI));
$fechaF2 = date('Y-m-d',strtotime($fechaF));
$reportes->setIdSuc($sucursalId);
$reportes->setFechaI($fechaI);
$reportes->setFechaF($fechaF);
if($sucursalId){
$sucursal->setSucursalId($sucursalId);
$sucursales[0] = $sucursal->Info();
}else{
$sucursales=$reportes->EnumSucursales($Usr['type'],$Usr['usuarioId']);
}
foreach($sucursales as $key => $suc){
$sucursalId = $suc['sucursalId'];
$reportes->setIdSuc($sucursalId);
// get total venta
$sucursales[$key]["ventas"] = $reportes->TotalVentasBySucReporteByDay();
// print_r($sucursales[$key]["ventas"]);
$sucursales[$key]["totalCostoVtas"] = $reportes->GetTotalSumProductosReporteByDay();
$sucursales[$key]["totalDev"] = $reportes->TotalDevolucionesBySucReporteByDay();
$sucursales[$key]["totalCostoDev"] = $reportes->GetTotalCostoProductosReporteByDay();
foreach($sucursales[$key]["ventas"] as $keyVenta => $value)
{
if($value["fecha"] == $sucursales[$key]["totalCostoVtas"][$keyVenta]["fecha"])
{
$sucursales[$key]["ventas"][$keyVenta]["importe"] = $sucursales[$key]["totalCostoVtas"][$keyVenta]["importe"];
}
foreach($sucursales[$key]["totalDev"] as $dev)
{
if($dev["fecha"] == $value["fecha"])
{
$sucursales[$key]["ventas"][$keyVenta]["totalDev"] = $dev["total"];
break;
}
}//froeach
foreach($sucursales[$key]["totalCostoDev"] as $costoDev)
{
if($costoDev["fecha"] == $value["fecha"])
{
$sucursales[$key]["ventas"][$keyVenta]["totalCostoDev"] = $costoDev["importe"];
break;
}
}//foreaach
$sucursales[$key]["ventas"][$keyVenta]["totalVenta"] -= $sucursales[$key]["ventas"][$keyVenta]["totalDev"];
$sucursales[$key]["ventas"][$keyVenta]["totalCosto"] = $sucursales[$key]["ventas"][$keyVenta]["importe"] - $sucursales[$key]["ventas"][$keyVenta]["totalCostoDev"];
$sucursales[$key]["ventas"][$keyVenta]["utilidad"] = $sucursales[$key]["ventas"][$keyVenta]["totalVenta"] - $sucursales[$key]["ventas"][$keyVenta]["totalCosto"];
$sucursales[$key]["totales"]["totalVenta"] += $sucursales[$key]["ventas"][$keyVenta]["totalVenta"];
$sucursales[$key]["totales"]["totalCosto"] += $sucursales[$key]["ventas"][$keyVenta]["totalCosto"];
$sucursales[$key]["totales"]["utilidad"] += $sucursales[$key]["ventas"][$keyVenta]["utilidad"];
$sucursales[$key]["totales"]["ventas"] += $sucursales[$key]["ventas"][$keyVenta]["ventas"];
}//foreach venta
$totalesGenerales["totalVenta"] += $sucursales[$key]["totales"]["totalVenta"];
$totalesGenerales["totalCosto"] += $sucursales[$key]["totales"]["totalCosto"];
$totalesGenerales["utilidad"] += $sucursales[$key]["totales"]["utilidad"];
$totalesGenerales["ventas"] += $sucursales[$key]["totales"]["ventas"];
}//foreach sucursal
$x = "
<table>
<th colspan=\"5\">Periodo del ".$fechaI." al ".$fechaF."</th>
</table>
<br><br>
";
foreach($sucursales as $suc){
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"5\">
<b>".utf8_decode(urldecode($suc['nombre']))."</b>
</th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>Fecha</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Venta Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Costo Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Utilidad</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>No. de Ventas<br />Realizadas </b></th>
</tr>
</thead>
<tbody>";
foreach($suc['ventas'] as $res){
$x .= "
<tr>
<td style=\"text-align:center;\">".$res['fecha']."</td>
<td style=\"text-align:right;\">$".$res['totalVenta']."</td>
<td style=\"text-align:right;\">$".$res['totalCosto']."</td>
<td style=\"text-align:right;\">$".$res['utilidad']."</td>
<td style=\"text-align:center;\">".$res['ventas']."</td>
</tr>";
}//foreach
$x .= "
<tr>
<td style=\"text-align:center;\">TOTALES</td>
<td style=\"text-align:right;\">$".$suc["totales"]['totalVenta']."</td>
<td style=\"text-align:right;\">$".$suc["totales"]['totalCosto']."</td>
<td style=\"text-align:right;\">$".$suc["totales"]['utilidad']."</td>
<td style=\"text-align:center;\">".$suc["totales"]['ventas']."</td>
</tr>";
$x .= "
</tbody>
</table>";
}//foreach
$x .= "
<br><br>";
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"5\">
<b>TOTALES GENERALES</b>
</th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>&nbsp;</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Venta Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Costo Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Utilidad</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>No. de Ventas<br />Realizadas </b></th>
</tr>
</thead>
<tbody>
<tr>
<td style=\"text-align:center;\">&nbsp;</td>
<td style=\"text-align:right;\">$".$totalesGenerales['totalVenta']."</td>
<td style=\"text-align:right;\">$".$totalesGenerales['totalCosto']."</td>
<td style=\"text-align:right;\">$".$totalesGenerales['utilidad']."</td>
<td style=\"text-align:center;\">".$totalesGenerales['ventas']."</td>
</tr>
</tbody>
</table>";
$x .= "Tiempo de Ejecucion: ";
$end = microtime(true);
$x .= $time = number_format(($end - $start), 2);
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

134
export/inventario-fisico.php Executable file
View File

@@ -0,0 +1,134 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
$invFisicoId = intval($_GET['id']);
$inventario->setInvFisicoId($invFisicoId);
$info = $inventario->InfoInvFisico();
if(!$info){
header('Location: '.WEB_ROOT.'/inventario-fisico');
exit;
}
if($Usr['type'] != 'admin'){
if($info['usuarioId'] != $Usr['usuarioId'] && $Usr['type'] == 'supervisor'){
header('Location: '.WEB_ROOT.'/inventario-fisico');
exit;
}
}
$name = "R_Inventario_Fisico_Teorico";
//Obtenemos los Productos
$inventario->setInvFisicoId($invFisicoId);
$resProds = $inventario->GetInvFisicoProds();
$productos = array();
foreach($resProds as $res){
$producto->setProductoId($res['productoId']);
$infP = $producto->Info();
$proveedor->setProveedorId($infP['proveedorId']);
$res['proveedor'] = $proveedor->GetNameById();
if($info['status'] == "Pendiente"){
$inventario->setProductoId($res['productoId']);
$inventario->setSucursalId($info['sucursalId']);
$res['disponible'] = $inventario->GetDispByProd();
}
$res['diferencia'] = $res['cantidad'] - $res['disponible'];
$res['codigoBarra'] = $infP['codigoBarra'];
$res['modelo'] = $infP['modelo'];
$productos[] = $res;
}
$sucursal->setSucursalId($info['sucursalId']);
$info['sucursal'] = utf8_decode(urldecode($sucursal->GetNameById()));
$x .= "<table border=\"1\">";
$x.="<thead>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>SUCURSAL</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>FECHA REPORTE</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>FECHA PROCESO</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>STATUS</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b></b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b></b></th>
</tr>
</thead><tbody>";
$x .= "
<tr>
<td style=\"text-align:center\">".$info['sucursal']."</td>
<td style=\"text-align:center\">".$info['fecha']."</td>
<td style=\"text-align:center\">".$info['fechaAjuste']."</td>
<td style=\"text-align:center\">".$info['status']."</td>
<td style=\"text-align:center\"></td>
<td style=\"text-align:center\"></td>
</tr>";
$x .= "
<tr>
<td style=\"background:#E0E5E7;text-align:center\"><b>Codigo Barra</b></td>
<td style=\"background:#E0E5E7;text-align:center\"><b>Proveedor</b></td>
<td style=\"background:#E0E5E7;text-align:center\"><b>Modelo</b></td>
<td style=\"background:#E0E5E7;text-align:center\"><b>Cant. Fisica</b></td>
<td style=\"background:#E0E5E7;text-align:center\"><b>Cant. Teorico</b></td>
<td style=\"background:#E0E5E7;text-align:center\"><b>Diferencia</b></td>
</tr>";
$totales['fisico'] = 0;
$totales['teorico'] = 0;
$totales['diferencia'] = 0;
foreach($productos as $val){
$x .= "
<tr>
<td style='text-align:center;'>".$val['codigoBarra']."</td>
<td style='text-align:center;'>".$val['proveedor']."</td>
<td style='text-align:center;'>".$val['modelo']."</td>
<td style='text-align:center;'>".$val['cantidad']."</td>
<td style='text-align:center;'>".$val['disponible']."</td>
<td style='text-align:center;'>".$val['diferencia']."</td>
</tr>";
$totales['fisico'] += $val['cantidad'];
$totales['teorico'] += $val['disponible'];
$totales['diferencia'] += $val['diferencia'];
}//foreach
$x .= "
<tr>
<td style=\"text-align:center\" padding-right:20px\"></td>
<td style=\"text-align:center\" padding-right:20px\"></td>
<td style=\"text-align:center\" padding-right:20px\"><b>TOTAL GENERAL</b></td>
<td style=\"text-align:center\">".number_format($totales['fisico'],2)."</td>
<td style=\"text-align:center\">".number_format($totales['teorico'],2)."</td>
<td style=\"text-align:center\">".number_format($totales['diferencia'],2)."</td>
</tr>";
$x .= "</tbody>";
$x .= "</table>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

834
export/prod-prov.php Executable file
View File

@@ -0,0 +1,834 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
if($Usr['type'] != 'admin' && $Usr['type'] != 'gerente' && $Usr['type'] != 'centralizador'){
header('Location: '.WEB_ROOT);
exit;
}
$name = "R_Productos_Proveedor";
extract($_POST);
if($_POST['type'] == 'tipoProdProv'){
$proveedorId = $_POST['idProveedor'];
$sucursalId = $_POST['idSucursal'];
$mesI = $_POST['mesI'];
$anioI = $_POST['anioI'];
$mesF = $_POST['mesF'];
$anioF = $_POST['anioF'];
$codigoBarra = trim($_POST['codigoBarra']);
if($codigoBarra != ''){
$producto->setCodigoBarra($codigoBarra);
$productoId = $producto->GetProductIdByCodigo();
$sql = "SELECT proveedorId FROM producto WHERE productoId = ".$productoId;
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$proveedorId = $util->DBSelect($_SESSION['empresaId'])->GetSingle();
}
//Obtener el Ultimo Reporte Generado
$sql = "SELECT reporte, fecha FROM `reporteProvBest` WHERE proveedorId = ".$proveedorId;
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$row = $util->DBSelect($_SESSION['empresaId'])->GetRow();
$reporte = $row['reporte'];
$fechaRep = date('d-m-Y',strtotime($row['fecha']));
$resSucursales = unserialize(urldecode($reporte));
//Obtenemos los Periodos
$strFechaI = strtotime('01-'.$mesI.'-'.$anioI);
$mI = intval($mesI);
$yI = $anioI;
$mF = intval($mesF);
$yF = $anioF;
$anios = $yF - $yI;
if($anios == 0){
$meses = $mF - $mI;
$meses += 1;
}else{
$meses = (12 - $mI) + 1 + $mF;
}
$fIni = $anioI.'-'.$mesI.'-01';
$fFin = $yF.'-'.$mesF.'-31';
//Meses Actuales
$aniosX = date('Y') - 2013;
$mesesX = (12 - 6) + 1 + $mF;
$mK = $mesesX - $meses;
$periodo = array();
for($m=0; $m<$meses; $m++){
$fecha = date('Y-m-d',strtotime('+'.$m.' month',$strFechaI));
$mm = date('m',strtotime($fecha));
$y = date('Y',strtotime($fecha));
$mes = $util->GetMMMName($mm);
$fPerI = $y.'-'.$mm.'-01';
$fPerF = $y.'-'.$mm.'-31';
if($fPerI >= $fIni && $fPerF <= $fFin)
$periodo[$mK] = $mes.' '.$y;
$mK++;
}//for
//Sucursales Calculos
$totIniciales = array();
$totEntradas = array();
$totSalidas = array();
$totEntradasA = array();
$totSalidasA = array();
$totBloqueados = array();
$totPzas = 0;
$totImporte = 0;
$totVtas = 0;
$totImporteVtas = 0;
$sucursales = array();
foreach($resSucursales as $res){
if($sucursalId > 0 && $sucursalId != $res['sucursalId'])
continue;
$productos = array();
foreach($res['productos'] as $k1 => $cat){
$cats = array();
foreach($cat as $k2 => $subcat){
$subcats = array();
foreach($subcat as $k3 => $prod){
//Totales Generales
$idProd = $prod['productoId'];
if($productoId > 0 && $prod['productoId'] != $productoId)
continue;
foreach($periodo as $kP => $per){
$totalPzas = $prod['iniciales'][$kP];
$totalPzas += $prod['entradas'][$kP];
$totalPzas -= $prod['salidas'][$kP];
$totalPzas += $prod['entradasA'][$kP];
$totalPzas -= $prod['salidasA'][$kP];
$totalPzas -= $prod['bloqueados'][$kP];
$totSubs[$k2][$kP]['inicial'] += $prod['iniciales'][$kP];
$totSubs[$k2][$kP]['entradas'] += $prod['entradas'][$kP];
$totSubs[$k2][$kP]['salidas'] += $prod['salidas'][$kP];
$totSubs[$k2][$kP]['entradasA'] += $prod['entradasA'][$kP];
$totSubs[$k2][$kP]['salidasA'] += $prod['salidasA'][$kP];
$totSubs[$k2][$kP]['bloqueados'] += $prod['bloqueados'][$kP];
$totCats[$k1][$kP]['inicial'] += $prod['iniciales'][$kP];
$totCats[$k1][$kP]['entradas'] += $prod['entradas'][$kP];
$totCats[$k1][$kP]['salidas'] += $prod['salidas'][$kP];
$totCats[$k1][$kP]['entradasA'] += $prod['entradasA'][$kP];
$totCats[$k1][$kP]['salidasA'] += $prod['salidasA'][$kP];
$totCats[$k1][$kP]['bloqueados'] += $prod['bloqueados'][$kP];
$totIniciales[$kP] += $prod['iniciales'][$kP];
$totEntradas[$kP] += $prod['entradas'][$kP];
$totSalidas[$kP] += $prod['salidas'][$kP];
$totEntradasA[$kP] += $prod['entradasA'][$kP];
$totSalidasA[$kP] += $prod['salidasA'][$kP];
$totBloqueados[$kP] += $prod['bloqueados'][$kP];
//Totales Generales
$products[$idProd]['iniciales'][$kP] += $prod['iniciales'][$kP];
$products[$idProd]['entradas'][$kP] += $prod['entradas'][$kP];
$products[$idProd]['salidas'][$kP] += $prod['salidas'][$kP];
$products[$idProd]['entradasA'][$kP] += $prod['entradasA'][$kP];
$products[$idProd]['salidasA'][$kP] += $prod['salidasA'][$kP];
$products[$idProd]['bloqueados'][$kP] += $prod['bloqueados'][$kP];
$prodTotales['iniciales'][$kP] += $prod['iniciales'][$kP];
$prodTotales['entradas'][$kP] += $prod['entradas'][$kP];
$prodTotales['salidas'][$kP] += $prod['salidas'][$kP];
$prodTotales['entradasA'][$kP] += $prod['entradasA'][$kP];
$prodTotales['salidasA'][$kP] += $prod['salidasA'][$kP];
$prodTotales['bloqueados'][$kP] += $prod['bloqueados'][$kP];
}//foreach
$totalVtas = 0;
foreach($periodo as $kP => $per)
$totalVtas += $prod['salidasVtas'][$kP];
$prod['totalPzas'] = $totalPzas;
$prod['importe'] = $prod['costo'] * $totalPzas;
$prod['totalVtas'] = $totalVtas;
$prod['precioVta'] = $prod['precioVentaIva'];
$prod['importeVtas'] = $totalVtas * $prod['precioVentaIva'];
$subcats[$k3] = $prod;
//Totales Generales
$products[$idProd]['codigoBarra'] = $prod['codigoBarra'];
$products[$idProd]['modelo'] = $prod['modelo'];
$products[$idProd]['fecha'] = $prod['fecha'];
$products[$idProd]['costo'] = $prod['costo'];
$products[$idProd]['precioVta'] = $prod['precioVta'];
$products[$idProd]['totalPzas'] += $prod['totalPzas'];
$products[$idProd]['importe'] += $prod['importe'];
$products[$idProd]['totalVtas'] += $prod['totalVtas'];
$products[$idProd]['importeVtas'] += $prod['importeVtas'];
$prodTotales['totalPzas'] += $prod['totalPzas'];
$prodTotales['importe'] += $prod['importe'];
$prodTotales['totalVtas'] += $prod['totalVtas'];
$prodTotales['importeVtas'] += $prod['importeVtas'];
//Otros Totales
$totPzas += $prod['totalPzas'];
$totImporte += $prod['importe'];
$totVtas += $prod['totalVtas'];
$totImporteVtas += $prod['importeVtas'];
//Totales
$totSubs[$k2]['totalPzas'] += $totalPzas;
$totSubs[$k2]['importe'] += $prod['importe'];
$totSubs[$k2]['totalVtas'] += $totalVtas;
$totSubs[$k2]['importeVtas'] += $prod['importeVtas'];
$totCats[$k1]['totalPzas'] += $totalPzas;
$totCats[$k1]['importe'] += $prod['importe'];
$totCats[$k1]['totalVtas'] += $totalVtas;
$totCats[$k1]['importeVtas'] += $prod['importeVtas'];
//Totales Generales
$totEntradas[$m] += $cantEntrada;
$totSalidas[$m] += $cantSalida;
$totEntradasA[$m] += $cantEntradaA;
$totSalidasA[$m] += $cantSalidaA;
$productos[] = $prod;
}//foreach
}//foreach
}//foreach
$res['productos'] = $productos;
$res['totSubs'] = $totSubs;
$res['totCats'] = $totCats;
$totalPzas = ($cantInicial + $cantEntrada - $cantSalida + $cantEntradaA - $cantSalidaA);
$res['totalPzas'] = $totalPzas;
$res['totIniciales'] = $totIniciales;
$res['totEntradas'] = $totEntradas;
$res['totSalidas'] = $totSalidas;
$res['totEntradasA'] = $totEntradasA;
$res['totSalidasA'] = $totSalidasA;
$res['totBloqueados'] = $totBloqueados;
$res['totPzas'] = $totPzas;
$res['totImporte'] = $totImporte;
$res['totVtas'] = $totVtas;
$res['totImporteVtas'] = $totImporteVtas;
$sucursales[] = $res;
}//foreach
//Other
$width = 800 + ($meses * 50);
$perIni = $util->GetMMMName($mesI).' '.$anioI;
$perFin = $util->GetMMMName($mesF).' '.$anioF;
$titulo = 'Periodo: <br>'.$perIni.' a '.$perFin;
$colspan = 11 + ($meses*2);
$x = "
<table>
<th colspan='".$colspan."'>Periodo: ".$perIni." a ".$perFin."
<br><br>
Los datos no son generados en tiempo real.
<br>
Ult. Act. del Reporte: ".$fechaRep."
</th>
</table>
<br><br>
";
foreach($sucursales as $suc){
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"".$colspan."\">
<b>Sucursal: ".utf8_decode(urldecode($suc['nombre']))."</b>
</th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>";
foreach($periodo as $mes)
$x .= "<th style=\"background:#E0E5E7;text-align:center\" colspan='6'><b>".$mes."</b></th>";
$x .= " <th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>Codigo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Producto</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>No. Prov.</b></th>";
foreach($periodo as $mes){
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Inicial</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Entrada</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Salida</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Ajuste Salida</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Ajuste Entrada</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Bloqueados</b></th>";
}
$x .= " <th style=\"background:#E0E5E7;text-align:center\"><b>Ultima Compra</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total Piezas</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Costo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Importe Total de Inv.</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total Ventas</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Precio Venta</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Importe Total Ventas</b></th>
</tr>
</thead>
<tbody>";
foreach($suc['productos'] as $res){
$x .= "
<tr>
<td style=\"text-align:center;\">".$res['codigoBarra']."</td>
<td style=\"text-align:left;\">".$res['modelo']."</td>
<td style=\"text-align:left;\">".$res['proveedorId']."</td>";
foreach($periodo as $m => $val){
$x .= "<td style=\"text-align:center;\">".number_format($res['iniciales'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['entradas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['salidas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['entradasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['salidasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['bloqueados'][$m],0)."</td>";
}
$x .= "<td style=\"text-align:right;\">".date('d-m-Y',strtotime($res['fecha']))."</td>
<td style=\"text-align:center;\">".number_format($res['totalPzas'],0)."</td>
<td style=\"text-align:center;\">$".number_format($res['costo'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['importe'],2)."</td>
<td style=\"text-align:center;\">".number_format($res['totalVtas'],0)."</td>
<td style=\"text-align:center;\">$".number_format($res['precioVta'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['importeVtas'],2)."</td>
</tr>";
}//foreach
if(count($suc['productos']) > 0){
$x .= "
<tr>
<td style=\"text-align:center;\"></td>
<td style=\"text-align:center;\">TOTALES</td>
<td style=\"text-align:center;\"></td>";
foreach($periodo as $m => $val){
$x .= "<td style=\"text-align:center;\">".number_format($suc['totIniciales'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($suc['totEntradas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($suc['totSalidas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($suc['totEntradasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($suc['totSalidasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($suc['bloqueados'][$m],0)."</td>";
}
$x .= "<td style=\"text-align:right;\"></td>
<td style=\"text-align:center;\">".number_format($suc['totPzas'],0)."</td>
<td></td>
<td style=\"text-align:right;\">$".number_format($suc['totImporte'],2)."</td>
<td style=\"text-align:center;\">".number_format($suc['totVtas'],0)."</td>
<td></td>
<td style=\"text-align:right;\">$".number_format($suc['totImporteVtas'],2)."</td>
</tr>";
}//if
$x .= "
</tbody>
</table>";
}//foreach
//Totales Generales
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"".$colspan."\">
<b>TOTALES GENERALES</b>
</th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>";
foreach($periodo as $mes)
$x .= "<th style=\"background:#E0E5E7;text-align:center\" colspan='6'><b>".$mes."</b></th>";
$x .= " <th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>Codigo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Producto</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>No. Prov.</b></th>";
foreach($periodo as $mes){
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Inicial</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Entrada</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Salida</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Ajuste Salida</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Ajuste Entrada</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Bloqueados</b></th>";
}
$x .= " <th style=\"background:#E0E5E7;text-align:center\"><b>Ultima Compra</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total Piezas</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Costo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Importe Total de Inv.</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total Ventas</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Precio Venta</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Importe Total Ventas</b></th>
</tr>
</thead>
<tbody>";
foreach($products as $res){
$x .= "
<tr>
<td style=\"text-align:center;\">".$res['codigoBarra']."</td>
<td style=\"text-align:left;\">".$res['modelo']."</td>
<td style=\"text-align:left;\">".$res['proveedorId']."</td>";
foreach($periodo as $m => $val){
$x .= "<td style=\"text-align:center;\">".number_format($res['iniciales'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['entradas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['salidas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['entradasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['salidasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['bloqueados'][$m],0)."</td>";
}
$x .= "<td style=\"text-align:right;\">".date('d-m-Y',strtotime($res['fecha']))."</td>
<td style=\"text-align:center;\">".number_format($res['totalPzas'],0)."</td>
<td style=\"text-align:center;\">$".number_format($res['costo'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['importe'],2)."</td>
<td style=\"text-align:center;\">".number_format($res['totalVtas'],0)."</td>
<td style=\"text-align:center;\">$".number_format($res['precioVta'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['importeVtas'],2)."</td>
</tr>";
}//foreach
if(count($suc['productos']) > 0){
$x .= "
<tr>
<td style=\"text-align:center;\"></td>
<td style=\"text-align:center;\">TOTALES</td>
<td style=\"text-align:center;\"></td>";
foreach($periodo as $m => $val){
$x .= "<td style=\"text-align:center;\">".number_format($prodTotales['iniciales'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($prodTotales['entradas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($prodTotales['salidas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($prodTotales['entradasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($prodTotales['salidasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($prodTotales['bloqueados'][$m],0)."</td>";
}
$x .= "<td style=\"text-align:right;\"></td>
<td style=\"text-align:center;\">".number_format($prodTotales['totalPzas'],0)."</td>
<td></td>
<td style=\"text-align:right;\">$".number_format($prodTotales['totImporte'],2)."</td>
<td style=\"text-align:center;\">".number_format($prodTotales['totalVtas'],0)."</td>
<td></td>
<td style=\"text-align:right;\">$".number_format($prodTotales['importeVtas'],2)."</td>
</tr>";
}//if
$x .= "
</tbody>
</table>";
}else{
$proveedorId = $_POST['idProveedor'];
$sucursalId = $_POST['idSucursal'];
$fechaI = $_POST['fechaI'];
$codigoBarra = trim($_POST['codigoBarra']);
$reportes->setIdSuc($sucursalId);
$resSuc = $reportes->EnumSucursales();
if($codigoBarra != ''){
$producto->setCodigoBarra($codigoBarra);
$productoId = $producto->GetProductIdByCodigo();
$producto->setProductoId($productoId);
$infP = $producto->Info();
$proveedorId = $infP['proveedorId'];
}
$sucursales = array();
foreach($resSuc as $suc){
$sucursalId = $suc['sucursalId'];
$producto->setProveedorId($proveedorId);
$resProds = $producto->EnumByProveedor();
$proveedor->setProveedorId($proveedorId);
$nomProv = $proveedor->GetNameById();
$strFechaI = $fechaI;
$totPzas = 0;
$totImporte = 0;
$totVtas = 0;
$totImporteVtas = 0;
$totales = array();
$totSaldos = array();
$productos = array();
foreach($resProds as $res){
if($productoId > 0 && $res['productoId'] != $productoId)
continue;
$producto->setProductoId($res['productoId']);
$infP = $producto->Info();
$producto->setProductoId($res['productoId']);
$res['fecha'] = $producto->GetFechaUltCompra();
if($res['fecha'] == 0)
continue;
$res['modelo'] = utf8_encode($res['modelo']);
//Obtenemos el Saldo Inicial
$fechaII = '2013-06-01';
$fechaFF = date('Y-m-d',strtotime($fechaI));
$producto->setProductoId($res['productoId']);
$producto->setFechaIni($fechaII);
$producto->setFechaFin($fechaFF);
$producto->setSucursalId($sucursalId);
$cantSalidaI = $producto->GetCantVendido();
$cantSalidaI += $producto->GetSalEnvTT();
$cantEntradaI = $producto->GetCantTotalCompBySuc();
$cantEntradaI += $producto->GetEntEnvTT();
$cantEntradaAI = $producto->GetEntAjusteEnv();
$cantSalidaAI = $producto->GetSalAjusteEnv();
$cantInicial = $cantEntradaI - $cantSalidaI + $cantEntradaAI - $cantSalidaAI;
$totalVtas = 0;
$mostrar = false;
$totalPzas = 0;
$iniciales = array();
$entradas = array();
$salidas = array();
$m = 0;
$fechaIni = $fechaFF;
$fechaFin = $fechaFF;
$producto->setProductoId($res['productoId']);
$producto->setFechaIni($fechaIni);
$producto->setFechaFin($fechaFin);
$producto->setSucursalId($sucursalId);
$cantSalida = $producto->GetCantVendido();
$cantSalida += $producto->GetSalEnvTT();
$cantEntrada = $producto->GetCantTotalCompBySuc();
$cantEntrada += $producto->GetEntEnvTT();
$cantEntradaA = $producto->GetEntAjusteEnv();
$cantSalidaA = $producto->GetSalAjusteEnv();
$totalVtas += $cantSalida;
$totalPzas = ($cantInicial + $cantEntrada - $cantSalida + $cantEntradaA - $cantSalidaA);
$totSubs[$prodSubcatId][$m]['inicial'] += $cantInicial;
$totSubs[$prodSubcatId][$m]['entradas'] += $cantEntrada;
$totSubs[$prodSubcatId][$m]['salidas'] += $cantSalida;
$totSubs[$prodSubcatId][$m]['entradasA'] += $cantEntradaA;
$totSubs[$prodSubcatId][$m]['salidasA'] += $cantSalidaA;
$totCats[$prodCatId][$m]['inicial'] += $cantInicial;
$totCats[$prodCatId][$m]['entradas'] += $cantEntrada;
$totCats[$prodCatId][$m]['salidas'] += $cantSalida;
$totCats[$prodCatId][$m]['entradasA'] += $cantEntradaA;
$totCats[$prodCatId][$m]['salidasA'] += $cantSalidaA;
if($cantEntrada > 0 || $cantEntradaA > 0 || $cantInicial > 0)
$mostrar = true;
if($cantSalida > 0 || $cantSalidaA > 0 || $cantInicial > 0)
$mostrar = true;
if($mostrar == true){
$iniciales[$m] = $cantInicial;
$entradas[$m] = $cantEntrada;
$salidas[$m] = $cantSalida;
$entradasA[$m] = $cantEntradaA;
$salidasA[$m] = $cantSalidaA;
$totIniciales[$m] += $cantInicial;
$totEntradas[$m] += $cantEntrada;
$totSalidas[$m] += $cantSalida;
$totEntradasA[$m] += $cantEntradaA;
$totSalidasA[$m] += $cantSalidaA;
}else{
$iniciales[$m] = 0;
$entradas[$m] = 0;
$salidas[$m] = 0;
$entradasA[$m] = 0;
$salidasA[$m] = 0;
}
$cantInicial = $cantInicial + $cantEntrada - $cantSalida + $cantEntradaA - $cantSalidaA;
$suc['productos'] = $productos;
$res['iniciales'] = $iniciales;
$res['entradas'] = $entradas;
$res['salidas'] = $salidas;
$res['entradasA'] = $entradasA;
$res['salidasA'] = $salidasA;
$res['totalPzas'] = $totalPzas;
$res['proveedor'] = $nomProv;
$res['importe'] = $res['costo'] * $totalPzas;
$res['totalVtas'] = $totalVtas;
$res['precioVta'] = $infP['precioVentaIva'];
$res['importeVtas'] = $totalVtas * $infP['precioVentaIva'];
if($mostrar == true){
$totPzas += $totalPzas;
$totImporte += $res['importe'];
$totVtas += $totalVtas;
$totImporteVtas += $res['importeVtas'];
$productos[] = $res;
}
}//foreach
$suc['productos'] = $productos;
$suc['totIniciales'] = $totIniciales;
$suc['totEntradas'] = $totEntradas;
$suc['totSalidas'] = $totSalidas;
$suc['totEntradasA'] = $totEntradasA;
$suc['totSalidasA'] = $totSalidasA;
$suc['totPzas'] = $totPzas;
$suc['totImporte'] = $totImporte;
$suc['totVtas'] = $totVtas;
$suc['totImporteVtas'] = $totImporteVtas;
$sucursales[] = $suc;
}//foreach
$meses = 1;
$periodo = array();
for($m=0; $m<$meses; $m++)
$periodo[$m] = $fechaI;
$colspan = 11 + ($meses*2);
$x = "
<table>
<th colspan='".$colspan."'>Periodo: ".$fechaI."</th>
</table>
<br><br>
";
foreach($sucursales as $suc){
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"".$colspan."\">
<b>Sucursal: ".utf8_decode(urldecode($suc['nombre']))."</b>
</th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>";
foreach($periodo as $mes)
$x .= "<th style=\"background:#E0E5E7;text-align:center\" colspan='5'><b>".$fechaI."</b></th>";
$x .= " <th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>Codigo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Producto</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>No. Prov.</b></th>";
foreach($periodo as $mes){
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Inicial</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Entrada</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Salida</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Ajuste Entrada</b></th>";
$x .= "<th style=\"background:#E0E5E7;text-align:center\"><b>Ajuste Salida</b></th>";
}
$x .= " <th style=\"background:#E0E5E7;text-align:center\"><b>Ultima Compra</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total Piezas</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Costo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Importe Total de Inv.</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total Ventas</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Precio Venta</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Importe Total Ventas</b></th>
</tr>
</thead>
<tbody>";
foreach($suc['productos'] as $res){
$x .= "
<tr>
<td style=\"text-align:center;\">".$res['codigoBarra']."</td>
<td style=\"text-align:left;\">".$res['modelo']."</td>
<td style=\"text-align:left;\">".$res['proveedorId']."</td>";
foreach($periodo as $m => $val){
$x .= "<td style=\"text-align:center;\">".number_format($res['iniciales'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['entradas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['salidas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['entradasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($res['salidasA'][$m],0)."</td>";
}
$x .= "<td style=\"text-align:right;\">".date('d-m-Y',strtotime($res['fecha']))."</td>
<td style=\"text-align:center;\">".number_format($res['totalPzas'],0)."</td>
<td style=\"text-align:center;\">$".number_format($res['costo'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['importe'],2)."</td>
<td style=\"text-align:center;\">".number_format($res['totalVtas'],0)."</td>
<td style=\"text-align:center;\">$".number_format($res['precioVta'],2)."</td>
<td style=\"text-align:right;\">$".number_format($res['importeVtas'],2)."</td>
</tr>";
}//foreach
if(count($suc['productos']) > 0){
$x .= "
<tr>
<td style=\"text-align:center;\"></td>
<td style=\"text-align:center;\">TOTALES</td>
<td style=\"text-align:center;\"></td>";
foreach($periodo as $m => $val){
$x .= "<td style=\"text-align:center;\">".number_format($suc['totIniciales'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($suc['totEntradas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($suc['totSalidas'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($suc['totEntradasA'][$m],0)."</td>";
$x .= "<td style=\"text-align:center;\">".number_format($suc['totSalidasA'][$m],0)."</td>";
}
$x .= "<td style=\"text-align:right;\"></td>
<td style=\"text-align:center;\">".number_format($suc['totPzas'],0)."</td>
<td></td>
<td style=\"text-align:right;\">$".number_format($suc['totImporte'],2)."</td>
<td style=\"text-align:center;\">".number_format($suc['totVtas'],0)."</td>
<td></td>
<td style=\"text-align:right;\">$".number_format($suc['totImporteVtas'],2)."</td>
</tr>";
}//if
$x .= "
</tbody>
</table>";
}//foreach
}//else if($_POST['type'] == 'tipoProdProv')
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

337
export/prod-prov2.php Executable file
View File

@@ -0,0 +1,337 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
if($Usr['type'] != 'admin' && $Usr['type'] != 'gerente' && $Usr['type'] != 'centralizador'){
header('Location: '.WEB_ROOT);
exit;
}
$name = "R_Productos_Proveedor_2";
extract($_POST);
$proveedorId = $_POST['idProveedor'];
$sucursalId = $_POST['idSucursal'];
$orden = $_POST['orden'];
$fechaI = $_POST['fechaI'];
$fechaF = $_POST['fechaF'];
$prodCatId = $_POST['prodCatId'];
$prodSubcatId = $_POST['prodSubcatId'];
$codigoBarra = $_POST['codigoBarra'];
$reportes->setFechaI($fechaI);
$reportes->setFechaF($fechaF);
if($orden=="mayor")
{
$orderBy = "DESC";
$mayormenor = true;
}
else
{
$mayormenor = false;
$orderBy = "ASC";
}
if($Usr['type']=="admin")
$smarty->assign("tipo","admin");
if($Usr['type']=="gerente")
$smarty->assign("tipo","gerente");
$reportes->setIdSuc($sucursalId);
$resSucursales = $reportes->EnumSucursales();
$global['disponible'] = 0;
$global['cedis'] = 0;
$global['porLlegar'] = 0;
$global['vendidos'] = 0;
$global['total'] = 0;
$totDispGral = 0;
$totProdsGral = 0;
$totImpGral = 0;
$prodGlobal = array();
foreach($resSucursales as $res){
$sucursalId = $res['sucursalId'];
$sqlFilter = '';
if($codigoBarra)
$sqlFilter .= ' AND p.codigoBarra = "'.$codigoBarra.'"';
if($proveedorId)
$sqlFilter .= ' AND p.proveedorId = '.$proveedorId;
if($proveedorId)
$sqlFilter .= ' AND p.proveedorId = '.$proveedorId;
if($prodCatId)
$sqlFilter .= ' AND p.prodCatId = '.$prodCatId;
if($prodSubcatId)
$sqlFilter .= ' AND p.prodSubcatId = '.$prodSubcatId;
/*
$sql = 'SELECT vp.productoId, p.imagen, p.modelo, p.codigoBarra, p.precioVentaIva AS precioVenta,
p.costo, p.proveedorId, p.prodCatId, p.prodSubcatId, SUM(vp.cantidad) AS vendidos
FROM ventaProducto AS vp, venta AS v, producto p
WHERE v.ventaId = vp.ventaId
AND vp.productoId = p.productoId
AND status <> "Cancelado"
AND v.fecha >= "'.date('Y-m-d',strtotime($fechaI)).' 00:00:00"
AND v.fecha <= "'.date('Y-m-d',strtotime($fechaF)).' 23:59:59"
AND v.sucursalId = "'.$sucursalId.'"
'.$sqlFilter.'
GROUP BY vp.productoId';
*/
$sql = 'SELECT p.productoId, p.imagen, p.modelo, p.codigoBarra, p.precioVentaIva AS precioVenta,
p.costo, p.proveedorId, p.prodCatId, p.prodSubcatId, SUM(IF( v.ventaId IS NULL , 0, vp.cantidad)) AS vendidos
FROM producto AS p
LEFT JOIN ventaProducto vp ON vp.productoId = p.productoId
LEFT JOIN venta v ON v.ventaId = vp.ventaId
AND v.status <> "Cancelado"
AND v.fecha >= "'.date('Y-m-d',strtotime($fechaI)).' 00:00:00"
AND v.fecha <= "'.date('Y-m-d',strtotime($fechaF)).' 23:59:59"
AND v.sucursalId = "'.$sucursalId.'"
WHERE 1
'.$sqlFilter.'
GROUP BY p.productoId ORDER BY vendidos '.$orderBy;
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$resProds = $util->DBSelect($_SESSION['empresaId'])->GetResult();
$reportes->setIdSuc($sucursalId);
$totalDisp = 0;
$totalProds = 0;
$totalImporte = 0;
$totalCedis = 0;
$totalPorLlegar = 0;
$productos = array();
foreach($resProds as $prod){
$productoId = $prod['productoId'];
$reportes->setProductoId($productoId);
$vendidos = $prod['vendidos'];
$devueltos = $reportes->GetTotalProdDevBySuc();
$totalVendidos = $vendidos - $devueltos;
$prod['vendidos'] = $totalVendidos;
$importe = $prod['vendidos'] * $prod['precioVenta'];
$prod['total'] = $importe;
//if($prod['vendidos'] == 0)
//continue;
$proveedor->setProveedorId($prod['proveedorId']);
$prod['proveedor'] = utf8_encode($proveedor->GetNameById());
$prodCat->setProdCatId($prod['prodCatId']);
$prod['depto'] = utf8_encode($prodCat->GetNameById());
$prodSubcat->setProdSubcatId($prod['prodSubcatId']);
$prod['linea'] = utf8_encode($prodSubcat->GetNameById());
$inventario->setProductoId($productoId);
$inventario->setSucursalId($sucursalId);
$disponible = $inventario->GetDispByProd();
$prod['disponible'] = $disponible;
$reportes->setProductoId($productoId);
$prod['cedis'] = $reportes->GetCantProdCedis();
$prod['porLlegar'] = $reportes->GetCantProdNoCedis();
$totalDisp += $disponible;
$totalProds += $totalVendidos;
$totalImporte += $importe;
$totalCedis += $prod['cedis'];
$totalPorLlegar += $prod['porLlegar'];
$productos[] = $prod;
//Guardamos los Datos Globales
if(array_key_exists($productoId, $prodGlobal)){
$prod2 = $prodGlobal[$productoId];
$prod2['disponible'] += $prod['disponible'];
$prod2['porLlegar'] += $prod['porLlegar'];
$prod2['cedis'] += $prod['cedis'];
$prod2['vendidos'] += $prod['vendidos'];
$prod2['total'] += $prod['total'];
}else
$prod2 = $prod;
$global['disponible'] += $prod['disponible'];
$global['porLlegar'] += $prod['porLlegar'];
$global['cedis'] += $prod['cedis'];
$global['vendidos'] += $prod['vendidos'];
$global['total'] += $prod['total'];
$prodGlobal[$productoId] = $prod2;
}//foreach
$res['productos'] = $reportes->orderMultiDimensionalArray($productos,'vendidos',$mayormenor);
$res['disponible'] = $totalDisp;
$res['vendidos'] = $totalProds;
$res['importe'] = $totalImporte;
$res['cedis'] = $totalCedis;
$res['porLlegar'] = $totalPorLlegar;
$sucursales[] = $res;
}//foreach
$global['productos'] = $reportes->orderMultiDimensionalArray($prodGlobal,'vendidos',$mayormenor);
foreach($sucursales as $suc){
$x.="<table border=\"1\">";
$x .= "<thead>
<tr>
<th style=\"background:#E0E5E7;text-align:center\" colspan=\"12\">
<b>".utf8_decode(urldecode($suc['nombre']))."</b>
</th>
</tr>
</thead><tbody>";
$x .= "
<tr>
<td style=\"background:#E0E5E7;text-align:center\">Proveedor</td>
<td style=\"background:#E0E5E7;text-align:center\">Departamento</td>
<td style=\"background:#E0E5E7;text-align:center\">Linea</td>
<td style=\"background:#E0E5E7;text-align:center\">C&oacute;digo de Barras</td>
<td style=\"background:#E0E5E7;text-align:center\">Producto</td>
<td style=\"background:#E0E5E7;text-align:center\">Cant. en Pedido</td>
<td style=\"background:#E0E5E7;text-align:center\">Cant. en CEDIS</td>
<td style=\"background:#E0E5E7;text-align:center\">Inv. Actual</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">No. Prods. Vendidos</td>
<td style=\"background:#E0E5E7;text-align:center\">Costo</td>
<td style=\"background:#E0E5E7;text-align:center\">Precio Venta</td>
<td style=\"background:#E0E5E7;text-align:center\">Importe Total</td>
</tr>";
foreach($suc['productos'] as $temp){
$x .= "
<tr>
<td style=\"text-align:center; padding-right:20px\">".$temp['proveedor']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['depto']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['linea']."</td>
<td style=\"text-align:center; padding-right:20px\">
".$temp['codigoBarra']."&nbsp;
</td>
<td>".$temp['modelo']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['porLlegar']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['cedis']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['disponible']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['vendidos']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['costo']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['precioVenta']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['total']."</td>
</tr>";
}//foreach
$x .= "
<tr>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center;\"><b>TOTAL</b></td>
<td style=\"text-align:center; padding-right:20px\">".$suc['porLlegar']."</td>
<td style=\"text-align:center; padding-right:20px\">".$suc['cedis']."</td>
<td style=\"text-align:center; padding-right:20px\">".$suc['disponible']."</td>
<td style=\"text-align:center; padding-right:20px\">".$suc['vendidos']."</td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\">".$suc['importe']."</td>
</tr>";
$x.="</tbody>
</table>";
}//foreach
if(count($sucursales) > 1){
$x.="<table border=\"1\">";
$x.="<thead><tr><th style=\"background:#E0E5E7;text-align:center\" colspan=\"12\"><b>TOTALES GLOBALES</b></th></tr>";
$x .= "
<tr>
<td style=\"background:#E0E5E7;text-align:center\">Proveedor</td>
<td style=\"background:#E0E5E7;text-align:center\">Departamento</td>
<td style=\"background:#E0E5E7;text-align:center\">Linea</td>
<td style=\"background:#E0E5E7;text-align:center\">C&oacute;digo de Barras</td>
<td style=\"background:#E0E5E7;text-align:center\">Producto</td>
<td style=\"background:#E0E5E7;text-align:center\">Cant. en Pedido</td>
<td style=\"background:#E0E5E7;text-align:center\">Cant. en CEDIS</td>
<td style=\"background:#E0E5E7;text-align:center\">Inv. Actual</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">No. Prods. Vendidos</td>
<td style=\"background:#E0E5E7;text-align:center\">Costo</td>
<td style=\"background:#E0E5E7;text-align:center\">Precio Venta</td>
<td style=\"background:#E0E5E7;text-align:center\">Importe Total</td>
</tr>
</thead>
<tbody>";
foreach($global['productos'] as $temp){
$x .= "
<tr>
<td style=\"text-align:center; padding-right:20px\">".$temp['proveedor']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['depto']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['linea']."</td>
<td style=\"text-align:center; padding-right:20px\">
".$temp['codigoBarra']."&nbsp;
</td>
<td>".$temp['modelo']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['porLlegar']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['cedis']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['disponible']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['vendidos']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['costo']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['precioVenta']."</td>
<td style=\"text-align:center; padding-right:20px\">".$temp['total']."</td>
</tr>";
}//foreach
$x .= "
<tr>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center;\"><b>TOTAL</b></td>
<td style=\"text-align:center; padding-right:20px\">".$global['porLlegar']."</td>
<td style=\"text-align:center; padding-right:20px\">".$global['cedis']."</td>
<td style=\"text-align:center; padding-right:20px\">".$global['disponible']."</td>
<td style=\"text-align:center; padding-right:20px\">".$global['vendidos']."</td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\"></td>
<td style=\"text-align:center; padding-right:20px\">".$global['total']."</td>
</tr>";
$x.="</tbody>";
$x.="</table>";
}//if
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

139
export/prods-transito.php Executable file
View File

@@ -0,0 +1,139 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
if($Usr['type'] != 'admin'){
header('Location: '.WEB_ROOT);
exit;
}
$name = "R_Prods_Transito";
extract($_POST);
$sucursalId = $_POST['idSucursal'];
$reportes->setIdSuc($sucursalId);
$resSucursales = $reportes->EnumSucursales();
$cantGral;
$totalGral;
foreach($resSucursales as $res){
$sucursalId = $res['sucursalId'];
$sql = 'SELECT p.codigoBarra, p.modelo, p.costo, p.precioVentaIva AS precioVenta,
SUM(pd.cantidad) AS cantidad, (SUM(pd.cantidad) * p.precioVentaIva) AS total
FROM envio e, envioPedido ep, pedidoDistribucion pd, producto AS p
WHERE e.envioId = ep.envioId
AND p.productoId = pd.productoId
AND ep.pedidoId = pd.pedidoId
AND e.status = "Pendiente"
AND e.sucursalId = "'.$sucursalId.'"
AND pd.sucursalId = "'.$sucursalId.'"
AND pd.cantidad > 0
GROUP BY pd.productoId';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$res['productos'] = $util->DBSelect($_SESSION['empresaId'])->GetResult();
$sql = 'SELECT SUM(pd.cantidad) AS cantidad, SUM(pd.cantidad * p.precioVentaIva) AS total
FROM envio e, envioPedido ep, pedidoDistribucion pd, producto AS p
WHERE e.envioId = ep.envioId
AND p.productoId = pd.productoId
AND ep.pedidoId = pd.pedidoId
AND e.status = "Pendiente"
AND e.sucursalId = "'.$sucursalId.'"
AND pd.sucursalId = "'.$sucursalId.'"
AND pd.cantidad > 0';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$row = $util->DBSelect($_SESSION['empresaId'])->GetRow();
$res['cantidad'] = $row['cantidad'];
$res['total'] = $row['total'];
$cantGral += $res['cantidad'];
$totalGral += $res['total'];
if(count($res['productos']) > 0)
$sucursales[] = $res;
}//foreach
$x = "";
foreach($sucursales as $suc){
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"6\">
<b>".utf8_decode(urldecode($suc['nombre']))."</b>
</th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>Codigo de Barras</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Producto</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Cantidad</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Costo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Precio Venta</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total Precio Venta</b></th>
</tr>
</thead>
<tbody>";
foreach($suc['productos'] as $res){
$x .= "
<tr>
<td style=\"text-align:center;\">".$res['codigoBarra']."</td>
<td style=\"text-align:left;\">".$res['modelo']."</td>
<td style=\"text-align:center;\">".number_format($res['cantidad'],2)."</td>
<td style=\"text-align:center;\">$".number_format($res['costo'],2)."</td>
<td style=\"text-align:center;\">$".number_format($res['precioVenta'],2)."</td>
<td style=\"text-align:center;\">$".number_format($res['total'],2)."</td>
</tr>";
}//foreach
$x .= "
<tr>
<td></td>
<td style=\"text-align:center;\"><b>TOTAL</b></td>
<td style=\"text-align:center;\">".number_format($suc['cantidad'],0)."</td>
<td style=\"text-align:center;\"></td>
<td style=\"text-align:center;\"></td>
<td style=\"text-align:center;\">".number_format($suc['total'],2)."</td>
</tr>";
$x .= "
</tbody>
</table>";
}//foreach
if(count($sucursales) > 1){
$x .= "<table border=\"1\">
<tr>
<td></td>
<td style=\"text-align:center;\"><b>TOTAL GENERAL</b></td>
<td style=\"text-align:center;\">".number_format($cantGral,0)."</td>
<td style=\"text-align:center;\"></td>
<td style=\"text-align:center;\"></td>
<td style=\"text-align:center;\">".number_format($totalGral,2)."</td>
</tr>
</table>";
}
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

165
export/reporte-devcedis.php Executable file
View File

@@ -0,0 +1,165 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$name = "Reporte_Devoluciones_CEDIS";
extract($_POST);
$fechaIni = trim($_POST['fechaI']);
$fechaFin = trim($_POST['fechaF']);
$sucursalId = $_POST['sucursalId2'];
if($fechaIni == ''){
$util->setError(20114,'error');
$util->PrintErrors();
echo 'fail[#]';
$smarty->display(DOC_ROOT.'/templates/boxes/status.tpl');
exit;
}
if($fechaFin == ''){
$util->setError(20115,'error');
$util->PrintErrors();
echo 'fail[#]';
$smarty->display(DOC_ROOT.'/templates/boxes/status.tpl');
exit;
}
$fechaIni = date('Y-m-d',strtotime($fechaIni));
$fechaFin = date('Y-m-d',strtotime($fechaFin));
if($sucursalId)
$sqlAdd = ' AND dp.sucursalId = "'.$sucursalId.'"';
$sql = 'SELECT SUM(dp.cantidad) AS totalCantidad, dp.*, d.fecha, s.nombre AS sucursal, prod.codigoBarra, prod.modelo AS producto,
prod.costo, prov.nombre AS proveedor, (prod.costo * dp.cantidad) AS total, d.usuarioId
FROM devolucionProdCedis dp, devolucionCedis d, sucursal s, producto prod, proveedor prov
WHERE dp.devCedisId = d.devCedisId
AND dp.sucursalId = s.sucursalId
AND dp.productoId = prod.productoId
AND prod.proveedorId = prov.proveedorId
AND DATE(d.fecha) >= "'.$fechaIni.'"
AND DATE(d.fecha) <= "'.$fechaFin.'"
'.$sqlAdd.' GROUP BY devCedisId';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$devoluciones = $util->DBSelect($_SESSION['empresaId'])->GetResult();
foreach($devoluciones as $key => $dev)
{
$sql = 'SELECT dp.*, d.fecha, s.nombre AS sucursal, prod.codigoBarra, prod.modelo AS producto,
prod.costo, prov.nombre AS proveedor
FROM devolucionProdCedis dp, devolucionCedis d, sucursal s, producto prod, proveedor prov
WHERE dp.devCedisId = d.devCedisId
AND dp.sucursalId = s.sucursalId
AND dp.productoId = prod.productoId
AND prod.proveedorId = prov.proveedorId
AND dp.devCedisId = "'.$dev["devCedisId"].'"';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$devoluciones[$key]["productos"] = $util->DBSelect($_SESSION['empresaId'])->GetResult();
$sql = 'SELECT SUM(prod.costo * dp.cantidad) AS total
FROM devolucionProdCedis dp, devolucionCedis d, sucursal s, producto prod, proveedor prov
WHERE dp.devCedisId = d.devCedisId
AND dp.sucursalId = s.sucursalId
AND dp.productoId = prod.productoId
AND prod.proveedorId = prov.proveedorId
AND dp.devCedisId = "'.$dev["devCedisId"].'"';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$devoluciones[$key]['total'] += $util->DBSelect($_SESSION['empresaId'])->GetSingle();
$usuario->setUsuarioId($dev['usuarioId']);
$devoluciones[$key]['usuario'] = $usuario->GetNameById();
}
$sql = 'SELECT SUM(dp.cantidad) AS totalCantidad, SUM(prod.costo * dp.cantidad) AS total
FROM devolucionProdCedis dp, devolucionCedis d, sucursal s, producto prod, proveedor prov
WHERE dp.devCedisId = d.devCedisId
AND dp.sucursalId = s.sucursalId
AND dp.productoId = prod.productoId
AND prod.proveedorId = prov.proveedorId
AND DATE(d.fecha) >= "'.$fechaIni.'"
AND DATE(d.fecha) <= "'.$fechaFin.'"
'.$sqlAdd;
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$row = $util->DBSelect($_SESSION['empresaId'])->GetRow();
$totalProds = $row[''];
$totalTotal = $row['total'];
$x.="<table border=\"1\">
<tbody>";
foreach($devoluciones as $res){
$x .= "<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>No. Dev</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Fecha</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Usuario</b></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Productos</b></th>
<th style=\"background:#E0E5E7;text-align:center\"></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total</b></th>
</tr>";
$x .= "<tr>
<td align='center'>".$res['devCedisId']."</td>
<td align='center'>".$res['fecha']."</td>
<td align='center'>".$res['usuario']."</td>
<td align='center'></td>
<td align='center'>".number_format($res['totalProds'],0)."</td>
<td align='center'></td>
<td align='center'>".number_format($res['total'],2)."</td>
</tr>";
$x .= "<tr>
<th style=\"background:#99CCFF;text-align:center\"><b>Sucursal</b></th>
<th style=\"background:#99CCFF;text-align:center\"><b>Proveedor</b></th>
<th style=\"background:#99CCFF;text-align:center\"><b>Codigo Barra</b></th>
<th style=\"background:#99CCFF;text-align:center\"><b>Producto</b></th>
<th style=\"background:#99CCFF;text-align:center\"><b>Cantidad</b></th>
<th style=\"background:#99CCFF;text-align:center\"><b>Costo</b></th>
<th style=\"background:#99CCFF;text-align:center\"><b>Total</b></th>
</tr>";
foreach($res['productos'] as $res2){
$x .= "<tr>
<td align='center'>".$res2['sucursal']."</td>
<td align='center'>".$res2['proveedor']."</td>
<td align='center'>".$res2['codigoBarra']."</td>
<td align='center'>".$res2['producto']."</td>
<td align='center'>".number_format($res2['cantidad'],0)."</td>
<td align='center'>$".number_format($res2['costo'],2)."</td>
<td align='center'>$".number_format($res2['total'],2)."</td>
</tr>";
}//foreach
}//foreach
$x .= '<tr>
<td></td>
<td></td>
<td></td>
<td align="center"><b>TOTAL</b></td>
<td align="center"><b>'.number_format($totalProds,2).'</b></td>
<td></td>
<td align="center"><b>'.number_format($totalTotal,2).'</b></td>
</tr>';
$x .= "</tbody>";
$x .= "</table>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

126
export/reporte-faltantes.php Executable file
View File

@@ -0,0 +1,126 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$name = "reporte_faltantes";
extract($_POST);
$proveedorId = $_POST['proveedorId'];
$reportes->setProveedorId($proveedorId);
$resProvs = $reportes->EnumAllProv();
if($proveedorId)
$sqlAdd = ' AND proveedorId = "'.$proveedorId.'"';
$sql = 'SELECT proveedorId, noProv, nombre FROM proveedor
WHERE baja = "0" '.$sqlAdd.'
ORDER BY nombre ASC';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$resProvs = $util->DBSelect($_SESSION['empresaId'])->GetResult();
$total = 0;
foreach($resProvs as $val){
$reportes->setProveedorId($val['proveedorId']);
$sql = "SELECT e.sucursalId, s.nombre AS sucursal
FROM envioRecibir er, envio e, producto p, sucursal s
WHERE e.envioId = er.envioId
AND e.sucursalId = s.sucursalId
AND er.productoId = p.productoId
AND p.proveedorId = '".$val['proveedorId']."'
AND er.faltantes > 0
GROUP BY e.sucursalId";
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$resSucursales = $util->DBSelect($_SESSION['empresaId'])->GetResult();
$sucursales = array();
foreach($resSucursales as $res){
$sql = "SELECT SUM(er.faltantes) AS faltantes, p.codigoBarra, p.modelo AS producto
FROM envioRecibir er, envio e, producto p
WHERE e.envioId = er.envioId
AND er.productoId = p.productoId
AND p.proveedorId = '".$val['proveedorId']."'
AND e.sucursalId = '".$res['sucursalId']."'
AND er.faltantes > 0
GROUP BY er.productoId";
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$res['productos'] = $util->DBSelect($_SESSION['empresaId'])->GetResult();
$sql = "SELECT SUM(er.faltantes)
FROM envioRecibir er, envio e, producto p
WHERE e.envioId = er.envioId
AND er.productoId = p.productoId
AND p.proveedorId = '".$val['proveedorId']."'
AND e.sucursalId = '".$res['sucursalId']."'
AND er.faltantes > 0";
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$total += $util->DBSelect($_SESSION['empresaId'])->GetSingle();
$sucursales[] = $res;
}
$val['sucursales'] = $sucursales;
$proveedores[] = $val;
}
$x.="<table border=\"1\">
<thead>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>No. Prov.</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Proveedor</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Codigo Barra</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Producto</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Sucursal</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Faltantes</b></th>
</tr>
</thead>
<tbody>";
foreach($proveedores as $prov){
foreach($prov['sucursales'] as $suc){
foreach($suc['productos'] as $prod){
$x .= "<tr>
<td>".$prov['noProv']."</td>
<td>".$prov['proveedor']."</td>
<td>".$prod['codigoBarra']."</td>
<td>".$prod['producto']."</td>
<td>".$suc['sucursal']."</td>
<td style=\"text-align:right;\">".$prod['faltantes']."</td>
</tr>";
}//foreach
}//foreach
}//foreach
$x .= '<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td><b>TOTAL</b></td>
<td align="right"><b>'.$total.'</b></td>
</tr>';
$x .= "</tbody>";
$x .= "</table>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

172
export/reporte-inventario.php Executable file
View File

@@ -0,0 +1,172 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$name = "R_inventario_productos_disponibles";
$Usr = $user->Info();
extract($_POST);
$proveedorId = $_POST['proveedorId'];
$sucursalId = $_POST['sucursal'];
$prodCatId = $_POST['prodCatId'];
$prodSubcatId = $_POST['prodSubcatId'];
$reportes->setIdSuc($sucursalId);
$resSuc = $reportes->EnumSucursales();
if($proveedorId)
$sqlFilter = ' AND proveedorId = '.$proveedorId;
$sql = 'SELECT proveedorId FROM proveedor WHERE 1 '.$sqlFilter;
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$proveedores = $util->DBSelect($_SESSION['empresaId'])->GetResult();
$dispGral = 0;
$totalGral = 0;
$totalGralPV = 0;
$sucursales = array();
foreach($resSuc as $res){
$sucursalId = $res['sucursalId'];
$dispSuc = 0;
$totalSuc = 0;
$totalSucPV = 0;
$productos = array();
foreach($proveedores as $prov){
$proveedorId = $prov['proveedorId'];
$sql = "SELECT reporte, fecha FROM `reporteInvBest` WHERE proveedorId = ".$proveedorId;
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$row = $util->DBSelect($_SESSION['empresaId'])->GetRow();
if(!$row)
continue;
$reporte = $row['reporte'];
$fechaRep = date('d-m-Y',strtotime($row['fecha']));
$resSucursales = unserialize(urldecode($reporte));
foreach($resSucursales as $res2){
if($sucursalId > 0 && $sucursalId != $res2['sucursalId'])
continue;
foreach($res2['productos'] as $prod){
if($prodCatId > 0 && $prodCatId != $prod['prodCatId'])
continue;
if($prodSubcatId > 0 && $prodSubcatId != $prod['prodSubcatId'])
continue;
$dispSuc += $prod['disponible'];
$totalSuc += $prod['total'];
$totalSucPV += $prod['totalPV'];
$dispGral += $prod['disponible'];
$totalGral += $prod['total'];
$totalGralPV += $prod['totalPV'];
$productos[] = $prod;
}//foreach
}//foreach
}//foreach
$res['disponible'] = $dispSuc;
$res['total'] = $totalSuc;
$res['totalPV'] = $totalSucPV;
$res['productos'] = $productos;
if(count($productos) > 0)
$sucursales[] = $res;
}//foreach
$totales['disponible'] = $dispGral;
$totales['total'] = $totalGral;
$totales['totalPV'] = $totalGralPV;
$x.="<table border=\"1\">";
foreach($sucursales as $res){
$x .= "<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"8\"><b>".utf8_decode(urldecode($res['nombre']))."</b></th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>Proveedor</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Codigo Barra</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Modelo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Costo Unitario</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Precio Venta</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Disponible</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total Costo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total P.V.</b></th>
</tr>
</thead><tbody>";
if(count($res['productos']) == 0)
$res['productos'] = array();
foreach($res['productos'] as $val){
$x .= "<tr><td>".$val['proveedor']."</td>
<td style=\"text-align:center;\">".$val['codigoBarra']."</td>
<td style=\"text-align:center;\">".$val['modelo']."</td>
<td style=\"text-align:right; padding-right:20px\">$".$val['costo']."</td>
<td style=\"text-align:right; padding-right:20px\">$".$val['precioVentaIva']."</td>
<td style=\"text-align:center;\">".$val['disponible']."</td>
<td style=\"text-align:right;\">$".number_format($val['total'],2)."</td>
<td style=\"text-align:right;\">$".number_format($val['totalPV'],2)."</td>
</tr>";
}//foreach
$x .= '<tr>
<td></td>
<td></td>
<td><b>TOTAL</b></td>
<td></td>
<td></td>
<td align="center"><b>'.number_format($res['disponible'],0,'.',',').'</b></td>
<td align="right"><b>$'.number_format($res['total'],2).'</b></td>
<td align="right"><b>$'.number_format($res['totalPV'],2).'</b></td>
</tr>';
}//foreach
$x .= '<tr>
<td></td>
<td></td>
<td><b>TOTAL GENERAL</b></td>
<td></td>
<td></td>
<td align="center"><b>'.number_format($totales['disponible'],0,'.',',').'</b></td>
<td align="right"><b>$'.number_format($totales['total'],2).'</b></td>
<td align="right"><b>$'.number_format($totales['totalPV'],2).'</b></td>
</tr>';
$x .= "</tbody>";
$x .= "</table>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

115
export/reporte-tickets.php Executable file
View File

@@ -0,0 +1,115 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$name = "reporte_tickets";
extract($_POST);
$codigoBarra = $_POST['codigoBarra2'];
$sql = 'SELECT prod.productoId, prod.codigoBarra, prod.modelo, prov.nombre AS proveedor
FROM producto prod, proveedor prov
WHERE prod.proveedorId = prov.proveedorId
AND prod.codigoBarra = "'.$codigoBarra.'"';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$info = $util->DBSelect($_SESSION['empresaId'])->GetRow();
$productoId = $info['productoId'];
//Total de Ventas
$sql = 'SELECT SUM(vp.cantidad)
FROM venta AS v, ventaProducto AS vp
WHERE v.ventaId = vp.ventaId
AND ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
AND v.status <> "Descuento"
AND vp.productoId = "'.$productoId.'"';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$info['totalVtas'] = $util->DBSelect($_SESSION['empresaId'])->GetSingle();
//Sucursal con mayor venta
$sql = 'SELECT SUM( vp.cantidad ) AS totalVentas, s.nombre AS sucursal
FROM venta AS v, ventaProducto AS vp, sucursal AS s
WHERE v.ventaId = vp.ventaId
AND v.sucursalId = s.sucursalId
AND ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
AND v.status <> "Descuento"
AND vp.productoId = "'.$productoId.'"
GROUP BY v.sucursalId
ORDER BY `totalVentas` DESC
LIMIT 1';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$row = $util->DBSelect($_SESSION['empresaId'])->GetRow();
$info['sucMasVtas'] = urldecode($row['sucursal']).'<br>'.$row['totalVentas'].' Vtas';
//Sucursal con menos venta
$sql = 'SELECT SUM( vp.cantidad ) AS totalVentas, s.nombre AS sucursal
FROM venta AS v, ventaProducto AS vp, sucursal AS s
WHERE v.ventaId = vp.ventaId
AND v.sucursalId = s.sucursalId
AND ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
AND v.status <> "Descuento"
AND vp.productoId = "'.$productoId.'"
GROUP BY v.sucursalId
ORDER BY `totalVentas` ASC
LIMIT 1';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$row = $util->DBSelect($_SESSION['empresaId'])->GetRow();
$info['sucMenosVtas'] = urldecode($row['sucursal']).'<br>'.$row['totalVentas'].' Vtas';
$reportes->setProductoId($productoId);
$fecha = $reportes->GetUltCompByProd();
if($fecha)
$info['fechaIngreso'] = date('d-m-Y H:i:s',strtotime($fecha));
else
$info['fechaIngreso'] = '---';
$reportes->setProductoId($productoId);
$info['disponibles'] = $reportes->GetTotalProdDispGral();
$x.="<table border=\"1\">";
$x .= "<thead>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>Proveedor</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Codigo Barra</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Modelo</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Total Ventas</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Suc. con Mas Ventas</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Suc. con Menos Ventas</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Fecha Ingreso</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>Disponibles</b></th>
</tr>
</thead>
<tbody>
<tr>
<td>".$info['proveedor']."</td>
<td style=\"text-align:center;\">".$info['codigoBarra']."</td>
<td style=\"text-align:center;\">".$info['modelo']."</td>
<td style=\"text-align:center;\">".$info['totalVtas']."</td>
<td style=\"text-align:center;\">".$info['sucMasVtas']."</td>
<td style=\"text-align:center;\">".$info['sucMenosVtas']."</td>
<td style=\"text-align:center;\">".$info['fechaIngreso']."</td>
<td style=\"text-align:center;\">".$info['disponibles']."</td>
</tr>";
$x .= "</tbody>";
$x .= "</table>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

147
export/ventas-general.php Executable file
View File

@@ -0,0 +1,147 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$name = "R_General";
$Usr = $user->Info();
extract($_POST);
$fechaIni = $_POST['fechaI'];
$fechaFin = $_POST['fechaF'];
$idSucursal = $_POST['idSucursal'];
$start = microtime(true);
$reportes->setIdSuc($idSucursal);
$resSuc = $reportes->EnumSucursales($Usr['type'],$Usr['usuarioId']);
$totales = array();
$sucursales = array();
foreach($resSuc as $res){
$sucursalId = $res['sucursalId'];
$reportes->setIdSuc($sucursalId);
$reportes->setFechaI($fechaIni);
$reportes->setFechaF($fechaFin);
$ventas = $reportes->TotalVentasBySucReporte();
$totalVenta = $ventas["totalVenta"];
$noVentas = $ventas["ventas"];
$totalCostoVtas = $reportes->GetTotalSumProductosReporte();
$totalDev = $reportes->TotalDevolucionesBySucReporte();
$totalCostoDev = $reportes->GetTotalCostoProductosReporte();
$totalVenta -= $totalDev;
$totalCosto = $totalCostoVtas - $totalCostoDev;
$utilidad = $totalVenta - $totalCosto;
$res['totalVenta'] = $totalVenta;
$res['totalDev'] = $totalDev;
$res['totalCosto'] = $totalCosto;
$res['totalUtilidad'] = $utilidad;
$res['totalNoVtas'] = $noVentas;
$totales['totalVenta'] += $totalVenta;
$totales['totalDev'] += $totalDev;
$totales['totalCosto'] += $totalCosto;
$totales['totalUtilidad'] += $utilidad;
$totales['totalNoVtas'] += $noVentas;
//Obtenemos las comiisiones
$infG = $comision->getInfoGerente();
$infSubG = $comision->getInfoSubgerente();
if($totalVenta <= $infG['rango'])
$res['comisionGte'] = ($totalVenta * $infG['comisionBajo']) / 100;
elseif($totalVenta > $infG['rango'])
$res['comisionGte'] = ($totalVenta * $infG['comisionAlto']) / 100;
if($totalVenta <= $infSubG['rango'])
$res['comisionSubGte'] = ($totalVenta * $infSubG['comisionBajo']) / 100;
elseif($totalVenta > $infSubG['rango'])
$res['comisionSubGte'] = ($totalVenta * $infSubG['comisionAlto']) / 100;
$sucursal->setSucursalId($sucursalId);
$gerente = $sucursal->getGerente();
$subGerente = $sucursal->getSubGerente();
$res['nomGte'] = $gerente['nombre']." ".$gerente['apellidos'];
$res['nomSubGte'] = $subGerente['nombre']." ".$subGerente['apellidos'];
$sucursales[] = $res;
}//foreach
$x .= "<table><th colspan=\"5\">Periodo del ".$fechaIni." Al ".$fechaFin."</th></table>
<br><br>";
foreach($sucursales as $res){
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"5\"><b>".utf8_decode(urldecode($res['nombre']))."</b></th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>$ Venta Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>$ Devolucion Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>$ Costo Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>$ Utilidad</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>N&uacute;mero de Ventas<br />Realizadas </b></th>
</tr>
</thead>
<tbody>
<td style=\"text-align:right; padding-right:20px\">$".number_format($res['totalVenta'],2)."</td>
<td style=\"text-align:right; padding-right:20px\">$".number_format($res['totalDev'],2)."</td>
<td style=\"text-align:right; padding-right:20px\">$".number_format($res['totalCosto'],2)."</td>
<td style=\"text-align:center; padding-right:20px\">".number_format($res['totalUtilidad'],2)."</td>
<td style=\"text-align:center; padding-right:20px\">".number_format($res['totalNoVtas'],2,'.','')."</td>
</tbody>
</table>
<br><br>";
}//foreach
$x .= "<br>";
if(($Usr['type'] == "admin" || $Usr['type'] == "centralizador" || $Usr['type'] == "almacen") && $idSucursal == ''){
$x .= "<table border=\"1\">
<thead>
<tr>
<th style=\"background:#CCC;text-align:center\" colspan=\"5\"><b>TOTALES GENERALES</b></th>
</tr>
<tr>
<th style=\"background:#E0E5E7;text-align:center\"><b>$ Venta Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>$ Devolucion Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>$ Costo Total</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>$ Utilidad</b></th>
<th style=\"background:#E0E5E7;text-align:center\"><b>N&uacute;mero de Productos<br />Vendidos </b></th>
</tr>
</thead>
<tbody>
<td style=\"text-align:right; padding-right:20px\">$".number_format($totales['totalVenta'],2)."</td>
<td style=\"text-align:right; padding-right:20px\">$".number_format($totales['totalDev'],2)."</td>
<td style=\"text-align:right; padding-right:20px\">$".number_format($totales['totalCosto'],2)."</td>
<td style=\"text-align:right; padding-right:20px\">$".number_format($totales['totalUtilidad'],2)."</td>
<td style=\"text-align:center; padding-right:20px\">".number_format($totales['totalNoVtas'],2,'.','')."</td>
</tbody>";
$x .= "</table>";
}
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>

200
export/ventas-proveedor.php Executable file
View File

@@ -0,0 +1,200 @@
<?php
include_once('../init.php');
include_once('../config.php');
include_once(DOC_ROOT.'/libraries.php');
$Usr = $user->Info();
if($Usr['type'] != 'admin' && $Usr['type'] != 'gerente' && $Usr['type'] != 'centralizador' && $Usr['type'] != 'almacen' && $Usr['type'] != 'facturacion' && $Usr['type'] != 'direccion' && $Usr['type'] != 'supervisor'){
header('Location: '.WEB_ROOT);
exit;
}
$name = "R_ventas_por_Proveedor";
extract($_POST);
$idSucursal = $_POST['idSucursal'];
$idProveedor = $_POST['idProveedor'];
$fechaIni = date('Y-m-d',strtotime($_POST['fechaI']));
$fechaFin = date('Y-m-d',strtotime($_POST['fechaF']));
$reportes->setIdSuc($idSucursal);
$resSuc=$reportes->EnumSucursales($Usr['type'],$Usr['usuarioId']);
if($idProveedor)
$sqlFilter = ' AND proveedorId = '.$idProveedor;
$sql = 'SELECT proveedorId, nombre FROM proveedor
WHERE baja = "0" '.$sqlFilter.'
ORDER BY proveedorId ASC';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$resProv = $util->DBSelect($_SESSION['empresaId'])->GetResult();
$totales['inv'] = 0;
$totales['prods'] = 0;
$totales['vtas'] = 0;
$sucursales = array();
foreach($resSuc as $res){
$sucursalId = $res['sucursalId'];
$totalInvG = 0;
$totalProdsG = 0;
$totalVtasG = 0;
$proveedores = array();
foreach($resProv as $val){
$sql = 'SELECT SUM(vp.cantidad) AS totalProds , SUM(vp.total) AS totalVtas
FROM venta AS v, ventaProducto AS vp, producto AS p
WHERE v.ventaId = vp.ventaId
AND vp.productoId = p.productoId
AND ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
AND v.status <> "Descuento"
AND v.fecha >= "'.$fechaIni.' 00:00:00"
AND v.fecha <= "'.$fechaFin.' 23:59:59"
AND v.sucursalId = "'.$sucursalId.'"
AND p.proveedorId = '.$val['proveedorId'];
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$row = $util->DBSelect($_SESSION['empresaId'])->GetRow();
$totalProds = $row['totalProds'];
$totalVtas = $row['totalVtas'];
$sql = 'SELECT SUM(dp.cantidad) AS totalProdsDev, SUM(dp.total) AS totalDevs
FROM venta AS v, devolucion AS d, devolucionProducto AS dp, producto AS p
WHERE v.ventaId = d.ventaId
AND d.devolucionId = dp.devolucionId
AND dp.productoId = p.productoId
AND ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
AND v.status <> "Descuento"
AND v.fecha >= "'.$fechaIni.' 00:00:00"
AND v.fecha <= "'.$fechaFin.' 23:59:59"
AND v.sucursalId = "'.$sucursalId.'"
AND p.proveedorId = '.$val['proveedorId'];
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$row = $util->DBSelect($_SESSION['empresaId'])->GetRow();
$totalProds -= $row['totalProdsDev'];
$totalVtas -= $row['totalDevs'];
if($totalProds){
$a = 1;
}else{
continue;
}
//Inventario Disponible
$sql = 'SELECT SUM(inv.cantidad)
FROM inventario AS inv, producto AS prod, proveedor AS prov
WHERE inv.productoId = prod.productoId
AND prod.proveedorId = prov.proveedorId
AND inv.status = "Disponible"
AND prod.proveedorId = "'.$val['proveedorId'].'"
AND inv.sucursalId = "'.$sucursalId.'"';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$totalInv = $util->DBSelect($_SESSION['empresaId'])->GetSingle();
//Eliminamos las ventas no descontadas
$sql = 'SELECT SUM(cantidad)
FROM inventario
LEFT JOIN pedido ON pedido.pedidoId = inventario.pedidoId
WHERE sucursalId = "'.$sucursalId.'"
AND pedido.proveedorId = "'.$val['proveedorId'].'"
AND pedido.ventaDesc = "Si"';
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
$totalInvDesc = $util->DBSelect($_SESSION['empresaId'])->GetSingle();
$val['nombre'] = utf8_encode($val['nombre']);
$val['totalInv'] = $totalInv - $totalInvDesc;
$val['totalProds'] = $totalProds;
$val['totalVtas'] = $totalVtas;
$totalInvG += $totalInv;
$totalProdsG += $totalProds;
$totalVtasG += $totalVtas;
$proveedores[] = $val;
}//foreach
$res['proveedores'] = $proveedores;
$res['totalInv'] = $totalInvG;
$res['totalProds'] = $totalProdsG;
$res['totalVtas'] = $totalVtasG;
$totales['inv'] += $totalInvG;
$totales['prods'] += $totalProdsG;
$totales['vtas'] += $totalVtasG;
$sucursales[] = $res;
}//foreach
$x .= "<table border=\"1\">";
foreach($sucursales as $res){
$x.="<thead>
<tr>
<th style=\"background:#E0E5E7;text-align:center\" colspan=\"5\"><b>".utf8_encode(urldecode($res['nombre']))."</b></th>
</tr>
</thead><tbody>";
$x .= "
<tr>
<td style=\"background:#E0E5E7;text-align:center\">No. Prov.</td>
<td style=\"background:#E0E5E7;text-align:center\">Proveedor</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Inventario Actual</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Productos Vendidos</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Total de Venta</td>
</tr>";
foreach($res['proveedores'] as $val){
$x .= "
<tr>
<td style='text-align:center;'>".$val['proveedorId']."</td>
<td>".$val['nombre']."</td>
<td style=\"text-align:center; padding-right:20px\">".$val['totalInv']."</td>
<td style=\"text-align:center; padding-right:20px\">".$val['totalProds']."</td>
<td style=\"text-align:right; padding-right:20px\">$".$val['totalVtas']."</td>
</tr>";
}
$x .= "
<tr>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\"></td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Total</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">".$res['totalInv']."</td>
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">".$res['totalProds']."</td>
<td style=\"background:#E0E5E7;text-align:right\" padding-right:20px\">$".$res['totalVtas']."</td>
</tr>";
}
$x .= "
<tr>
<td style=\"text-align:center\" padding-right:20px\"></td>
<td style=\"text-align:center\" padding-right:20px\">TOTAL GENERAL</td>
<td style=\"text-align:center\" padding-right:20px\">".$totales['inv']."</td>
<td style=\"text-align:center\" padding-right:20px\">".$totales['prods']."</td>
<td style=\"text-align:right\" padding-right:20px\">$".$totales['vtas']."</td>
</tr>";
$x .= "</tbody>";
$x .= "</table>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-type: application/x-msexcel; charset=utf-8");
header("Content-Disposition: attachment; filename=".$name.".xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $x;
?>