1190 lines
40 KiB
PHP
Executable File
1190 lines
40 KiB
PHP
Executable File
<?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'] != 'almacen' && $Usr['type'] != 'centralizador' && $Usr['type'] != 'facturacion' && $Usr['type'] != 'direccion' && $Usr['type'] != 'compras' && $Usr['type'] != 'supervisor')
|
|
{
|
|
header('Location: '.WEB_ROOT);
|
|
exit;
|
|
}
|
|
else
|
|
{
|
|
switch($_POST['type'])
|
|
{
|
|
case "tipoPago": $name="R_de_formas_de_Pago"; break;
|
|
case "tipoGral": $name="R_General"; break;
|
|
case "tipoVend": $name="R_por_vendedor"; break;
|
|
case "tipoTempo": $name="R_por_temporada"; break;
|
|
|
|
case "tipoProMasVend": $name="R_Productos_".$_POST['orden']."_vendidos"; break;
|
|
case "tipoComprado": $name="R_Prodcutos_".$_POST['orden']."_comprados"; break;
|
|
|
|
case "tipoCuentasPend": $name="R_cuentas_por_pagar"; break;
|
|
case "rInventario": $name="R_inventario_productos_disponibles"; break;
|
|
case "tipoVentasProv": $name="R_ventas_por_Proveedor"; break;
|
|
case "reporteEnvios": $name="R_envios"; break;
|
|
}
|
|
|
|
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");
|
|
|
|
extract($_POST);
|
|
|
|
switch($_POST['type'])
|
|
{
|
|
case "reporteEnvios":
|
|
|
|
$sucursalId = $_POST['sucursalId2'];
|
|
$fechaRec = $_POST['fechaEnvio2'];
|
|
|
|
if(!$sucursalId){
|
|
$util->setError(30015,'error','');
|
|
$util->PrintErrors();
|
|
echo 'fail[#]';
|
|
$smarty->display(DOC_ROOT.'/templates/boxes/status.tpl');
|
|
exit;
|
|
}
|
|
|
|
if($fechaRec == ''){
|
|
$util->setError(20099,'error','');
|
|
$util->PrintErrors();
|
|
echo 'fail[#]';
|
|
$smarty->display(DOC_ROOT.'/templates/boxes/status.tpl');
|
|
exit;
|
|
}
|
|
|
|
$fechaRec = date('Y-m-d',strtotime($fechaRec));
|
|
|
|
$sucursal->setSucursalId($sucursalId);
|
|
$nomSuc = urldecode($sucursal->GetNameById());
|
|
|
|
$inventario->setSucursalId($sucursalId);
|
|
$inventario->setFecha($fechaRec);
|
|
$resProds = $inventario->GetSingleProds();
|
|
|
|
$cantTotal = 0;
|
|
$impTotal = 0;
|
|
|
|
$productos = array();
|
|
foreach($resProds as $res){
|
|
$producto->setProductoId($res['productoId']);
|
|
$info = $producto->Info();
|
|
|
|
$res['codigoBarra'] = $info['codigoBarra'];
|
|
$res['modelo'] = utf8_encode($info['modelo']);
|
|
|
|
$inventario->setSucursalId($sucursalId);
|
|
$inventario->setProductoId($res['productoId']);
|
|
$inventario->setFecha($fechaRec);
|
|
$res['cantidad'] = $inventario->GetCantByProd();
|
|
|
|
$res['precio'] = $info['precioVentaIva'];
|
|
$res['importe'] = $res['cantidad'] * $res['precio'];
|
|
|
|
$cantTotal += $res['cantidad'];
|
|
$impTotal += $res['importe'];
|
|
|
|
$productos[] = $res;
|
|
}
|
|
$smarty->assign('fechaRec', $fechaRec);
|
|
$smarty->assign('impTotal', $impTotal);
|
|
$smarty->assign('cantTotal', $cantTotal);
|
|
$smarty->assign('nomSuc', $nomSuc);
|
|
$smarty->assign('productos', $productos);
|
|
$smarty->assign('DOC_ROOT', DOC_ROOT);
|
|
$smarty->display(DOC_ROOT.'/templates/lists/envios-reporte.tpl');
|
|
|
|
break;
|
|
|
|
//Formas de Pago
|
|
|
|
case "tipoPago":
|
|
|
|
$name = "Reporte_de_Formas_de_Pago";
|
|
|
|
$idSuc = $_POST['idSucursal'];
|
|
$idMetodoPago = $_POST['formaPago'];
|
|
$fechaIni = $_POST['fechaI'];
|
|
$fechaFin = $_POST['fechaF'];
|
|
|
|
$fechaIni2 = date('Y-m-d',strtotime($fechaIni));
|
|
$fechaFin2 = date('Y-m-d',strtotime($fechaFin));
|
|
|
|
$reportes->setIdSuc($idSuc);
|
|
$resSuc = $reportes->EnumSucursales($Usr['type'],$Usr['usuarioId']);
|
|
|
|
$totales = array();
|
|
$formasPago = array();
|
|
$sucursales = array();
|
|
foreach($resSuc as $suc){
|
|
|
|
$idSuc = $suc['sucursalId'];
|
|
|
|
$metodosPago = array();
|
|
|
|
$totalS = 0;
|
|
|
|
if($idMetodoPago){
|
|
$metodoPago->setMetodoPagoId($idMetodoPago);
|
|
$resMetodosPago = $metodoPago->EnumSingle();
|
|
}else{
|
|
$resMetodosPago = $reportes->EnumFpago2();
|
|
}
|
|
|
|
if($idMetodoPago == 1 || count($resMetodosPago) > 1){
|
|
|
|
$sql = 'SELECT IF(totalDesc > 0, totalDesc, total) totalVenta,
|
|
(
|
|
SELECT SUM(vp.cantidad)
|
|
FROM ventaPago vp
|
|
WHERE vp.ventaId = v.ventaId
|
|
) AS totalPago
|
|
FROM venta v
|
|
WHERE ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
|
|
AND v.ventaIdAnt = 0
|
|
AND v.status <> "Descuento"
|
|
AND v.fecha >= "'.$fechaIni2.' 00:00:00"
|
|
AND v.fecha <= "'.$fechaFin2.' 23:59:59"
|
|
AND v.sucursalId = "'.$idSuc.'"';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$vtas = $util->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
$cambio = 0;
|
|
foreach($vtas as $res)
|
|
$cambio += $res['totalPago'] - $res['totalVenta'];
|
|
|
|
}else{
|
|
$cambio = 0;
|
|
}
|
|
|
|
$totalCambio = $cambio;
|
|
|
|
//Metodos de Pago
|
|
|
|
foreach($resMetodosPago as $val){
|
|
|
|
$metodoPagoId = $val['metodoPagoId'];
|
|
|
|
$valT = $metodosPago[$metodoPagoId];
|
|
$valT2 = $formasPago[$metodoPagoId];
|
|
|
|
$sql = 'SELECT SUM(vp.cantidad) FROM venta AS v
|
|
LEFT JOIN ventaPago AS vp ON v.ventaId = vp.ventaId
|
|
WHERE ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
|
|
AND v.ventaIdAnt = 0
|
|
AND v.status <> "Descuento"
|
|
AND v.fecha >= "'.$fechaIni2.' 00:00:00"
|
|
AND v.fecha <= "'.$fechaFin2.' 23:59:59"
|
|
AND v.sucursalId = "'.$idSuc.'"
|
|
AND vp.metodoPagoId = '.$val['metodoPagoId'];
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$totalM = $util->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
$valT['total'] += $totalM;
|
|
$valT['nombre'] = $val['nombre'];
|
|
|
|
$valT2['total'] += $totalM;
|
|
$valT2['nombre'] = $val['nombre'];
|
|
|
|
$metodosPago[$metodoPagoId] = $valT;
|
|
$formasPago[$metodoPagoId] = $valT2;
|
|
|
|
$totales['ventas'] += $totalM;
|
|
|
|
$totalS += $totalM;
|
|
|
|
}//foreach
|
|
|
|
//Obtenemos losg pagos con Saldo a Favor
|
|
if(count($metodosPago) > 1 || isset($metodosPago[1]) == true){
|
|
|
|
$sql = 'SELECT SUM(vp.cantidad) FROM venta AS v
|
|
LEFT JOIN ventaPago AS vp ON v.ventaId = vp.ventaId
|
|
WHERE ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
|
|
AND v.ventaIdAnt = 0
|
|
AND v.status <> "Descuento"
|
|
AND v.fecha >= "'.$fechaIni2.' 00:00:00"
|
|
AND v.fecha <= "'.$fechaFin2.' 23:59:59"
|
|
AND v.sucursalId = "'.$idSuc.'"
|
|
AND vp.metodoPagoId = 6';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$totalSF = $util->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
}
|
|
|
|
//Eliminamos las Devoluciones
|
|
|
|
$sql = 'SELECT SUM(dev.total) FROM venta AS vta, devolucion AS dev
|
|
WHERE vta.ventaId = dev.ventaId
|
|
AND dev.fecha >= "'.$fechaIni2.' 00:00:00"
|
|
AND dev.fecha <= "'.$fechaFin2.' 23:59:59"
|
|
AND dev.sucursalId = "'.$idSuc.'"
|
|
ORDER BY vta.ventaId ASC';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$totalDev = $util->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
if(count($metodosPago) > 1 || isset($metodosPago[1]) == true){
|
|
$mEF = $metodosPago[1];
|
|
$mEF['total'] = $mEF['total'] - $totalCambio + $totalSF - $totalDev;
|
|
$metodosPago[1] = $mEF;
|
|
|
|
$mEF = $formasPago[1];
|
|
$mEF['total'] = $mEF['total'] - $totalCambio + $totalSF - $totalDev;
|
|
$formasPago[1] = $mEF;
|
|
}
|
|
|
|
$suc['metodosPago'] = $metodosPago;
|
|
$suc['total'] = $totalS - $totalCambio + $totalSF - $totalDev;
|
|
|
|
$totales['ventas'] += $totalSF;
|
|
$totales['total'] += $suc['total'];
|
|
|
|
if(count($metodosPago))
|
|
$sucursales[] = $suc;
|
|
|
|
}//foreach
|
|
|
|
$x.="<table border=\"1\">";
|
|
|
|
foreach($sucursales as $res){
|
|
|
|
$x.="<thead>
|
|
<tr>
|
|
<th style=\"background:#CCC;text-align:center\" colspan=\"3\"><b>".utf8_decode(urldecode($res['nombre']))."</b></th>
|
|
</tr>
|
|
<tr>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Tipo de Pago</b></th>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Número de Productos <br />Vendidos</b></th>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Total de venta</b></th>
|
|
</tr>
|
|
</thead><tbody>";
|
|
|
|
foreach($res['metodosPago'] as $val){
|
|
|
|
$x.="<tr><td>".$val['nombre']."</td>
|
|
<td style=\"text-align:center\">".number_format($val['prendas'],2)."</td>
|
|
<td style=\"text-align:right; padding-right:20px\">$".number_format($val['total'],2)."</td></tr>";
|
|
|
|
}
|
|
|
|
if($idMetodoPago > 0){
|
|
$x.="<tr>
|
|
<td><b>TOTAL</b></td>
|
|
<td></td>
|
|
<td style=\"text-align:right; padding-right:20px\">
|
|
<b>$".number_format($res['total'],2)."</b>
|
|
</td>
|
|
</tr>";
|
|
}else{
|
|
$x.="
|
|
<tr>
|
|
<td><b>TOTAL</b></td>
|
|
<td></td>
|
|
<td style=\"text-align:right; padding-right:20px\">
|
|
<b>$".number_format($res['total'],2)."</b>
|
|
</td>
|
|
</tr>";
|
|
}//else
|
|
|
|
$x.="</tbody>";
|
|
|
|
}//foreach
|
|
|
|
if($Usr['type'] == "admin" || $Usr['type'] == "centralizador" || $Usr['type'] == "almacen"){
|
|
|
|
$x.="
|
|
<tbody style=\"background:#E0E5E7;text-align:center\">
|
|
<tr>
|
|
<th style=\"background:#CCC;text-align:center\" colspan=\"3\"><b>TOTAL GENERAL</b></th>
|
|
</tr>
|
|
<tr>
|
|
<th style=\"background:#CCC;text-align:center\">Tipo de Pago</th>
|
|
<th style=\"background:#CCC;text-align:center\">Número de Productos <br />Vendidos</th>
|
|
<th style=\"background:#CCC;text-align:center\">Total de venta</th>
|
|
</tr>
|
|
</tbody>
|
|
<tbody>";
|
|
|
|
foreach($formasPago as $res){
|
|
|
|
$x.="<tr>
|
|
<td>".$res['nombre']."</td>
|
|
<td style=\"text-align:center\">".$res['prendas']."</td>
|
|
<td style=\"text-align:right;padding-right:20px;\">$".number_format($res['total'],2)."</td>
|
|
</tr>";
|
|
|
|
}
|
|
|
|
if($idMetodoPago > 0){
|
|
$x.="
|
|
<tr>
|
|
<td style=\"background:#F4F5F6\"><b>Total de Ventas</b></td>
|
|
<td style=\"text-align:center;background:#F4F5F6\"></td>
|
|
<td style=\"text-align:right;padding-right:20px;background:#F4F5F6\">
|
|
<b>$".$totales['total']."</b>
|
|
</td>
|
|
</tr>";
|
|
}else{
|
|
$x.="
|
|
<tr>
|
|
<td style=\"background:#F4F5F6\"><b>Total de Ventas</b></td>
|
|
<td style=\"text-align:center;background:#F4F5F6\"></td>
|
|
<td style=\"text-align:right;padding-right:20px;background:#F4F5F6\">
|
|
<b>$".$totales['total']."</b>
|
|
</td>
|
|
</tr>";
|
|
|
|
}
|
|
|
|
$x.="</tbody>";
|
|
|
|
}//if
|
|
|
|
$x.="</table>";
|
|
|
|
echo $x;
|
|
|
|
break;
|
|
|
|
//Reporte por Vendedor
|
|
|
|
case "tipoVend":
|
|
|
|
$fechaIni = $_POST['fechaI'];
|
|
$fechaFin = $_POST['fechaF'];
|
|
|
|
$fechaI = date('Y-m-d',strtotime($fechaIni));
|
|
$fechaF = date('Y-m-d',strtotime($fechaFin));
|
|
$sucursalId = $_POST['sucursalId2'];
|
|
$vendedorId = $_POST['vendedorId'];
|
|
|
|
$usrType = $Usr['type'];
|
|
|
|
if($sucursalId)
|
|
$sqlFilter = ' AND s.sucursalId = '.$sucursalId;
|
|
|
|
if($Usr['type'] == 'supervisor')
|
|
$sql = 'SELECT s.sucursalId, s.nombre
|
|
FROM sucursal s, usuarioSuc us
|
|
WHERE s.sucursalId = us.sucursalId
|
|
AND us.usuarioId = '.$Usr['usuarioId'].$sqlFilter.'
|
|
ORDER BY s.noSuc';
|
|
else
|
|
$sql = 'SELECT s.sucursalId, s.nombre, s.iva
|
|
FROM sucursal s WHERE 1 '.$sqlFilter.'
|
|
ORDER BY s.noSuc';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$sucursals = $util->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
//Obtenemos los Vendedores
|
|
|
|
if($vendedorId != 'todos')
|
|
$sqlFilter2 = ' AND usuarioId = '.$vendedorId;
|
|
|
|
$infoVendedor = $comision->getInfoVendedor();
|
|
|
|
$ventaTotal = 0;
|
|
$data = array();
|
|
$ventasVendedor = array();
|
|
foreach($sucursals as $suc){
|
|
|
|
$sucursalId = $suc['sucursalId'];
|
|
$data[$sucursalId] = $suc;
|
|
|
|
$sql = 'SELECT * FROM usuario
|
|
WHERE type = "vendedor"
|
|
AND sucursalId = '.$sucursalId.$sqlFilter2;
|
|
$util->DB()->setQuery($sql);
|
|
$vendedores = $util->DB()->GetResult();
|
|
|
|
foreach($vendedores as $vend){
|
|
|
|
$usuarioId = $vend['usuarioId'];
|
|
|
|
$sql = 'SELECT SUM(IF( venta.totalDesc <>0, venta.totalDesc, venta.total )) FROM venta
|
|
WHERE ((status = "Cancelado" AND cancelDev = "1") OR status <> "Cancelado")
|
|
AND ventaIdAnt = 0
|
|
AND status <> "Descuento"
|
|
AND venta.vendedorId = "'.$vend['usuarioId'].'"
|
|
AND venta.fecha >= "'.$fechaI.' 00:00:00"
|
|
AND venta.fecha <= "'.$fechaF.' 23:59:59"';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$vend['totalventas'] = $util->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
$data[$sucursalId]['ventasucursal'] += $vend['totalventas'];
|
|
$ventaTotal += $vend['totalventas'];
|
|
|
|
$sql = 'SELECT SUM(d.total)
|
|
FROM devolucion d, venta v
|
|
WHERE d.ventaId = v.ventaId
|
|
AND d.fecha >= "'.$fechaI.' 00:00:00"
|
|
AND d.fecha <= "'.$fechaF.' 23:59:59"
|
|
AND d.sucursalId = '.$sucursalId.'
|
|
AND v.vendedorId = '.$vend['usuarioId'];
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$devTotal = $util->DBSelect($_SESSION['empresaId'])->GetSingle();
|
|
|
|
$vend['totalventas'] -= $devTotal;
|
|
$ventaTotal -= $devTotal;
|
|
$data[$sucursalId]['ventasucursal'] -= $devTotal;
|
|
|
|
$comisionVendedor = 0;
|
|
if($vend['totalventas'] > 0 && $vend['totalventas'] <= $infoVendedor['rango']){
|
|
|
|
$totalVtas = $vend['totalventas'];
|
|
$totalVtas = $totalVtas / (1 + ($suc['iva']/100));
|
|
|
|
$comisionVendedor = ($totalVtas * $infoVendedor['comisionBajo'])/100;
|
|
|
|
}elseif($vend['totalventas'] > $infoVendedor['rango']){
|
|
|
|
$totalVtas = $vend['totalventas'];
|
|
$totalVtas = $totalVtas / (1 + ($suc['iva']/100));
|
|
|
|
$comisionVendedor = ($totalVtas * $infoVendedor['comisionAlto'])/100;
|
|
}
|
|
|
|
$vend['comisionVendedor'] = $comisionVendedor;
|
|
|
|
$data[$sucursalId]['vendedor'][$usuarioId] = $vend;
|
|
|
|
}//foreach vendedor
|
|
|
|
}//foreach
|
|
|
|
$x .= "<table>
|
|
<th><div style=\"text-align:center\">Periodo</div></th>
|
|
<th>".$_POST['fechaI']." <b>a</b> ".$_POST['fechaF']."</th>
|
|
<th></th>
|
|
</table>
|
|
<table border=\"1\">";
|
|
|
|
foreach($data as $suc){
|
|
|
|
$x .= "<thead>
|
|
<tr>
|
|
<th style=\"background:#CCC;text-align:center\" colspan=\"3\">
|
|
<b>".utf8_decode(urldecode($suc['nombre']))."</b>
|
|
</th>
|
|
</tr>
|
|
<tr>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Nombre de vendedor</b></th>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Total de venta</b></th>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Comision</b></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>";
|
|
|
|
if(count($suc['vendedor']) == 0)
|
|
$suc['vendedor'] = array();
|
|
|
|
foreach($suc['vendedor'] as $formaPago=>$kformaPago){
|
|
|
|
if($kformaPago['totalventas'] == NULL)
|
|
$ventas="0.00";
|
|
else
|
|
$ventas=$kformaPago['totalventas'];
|
|
|
|
$x .= "<tr>
|
|
<td>".$kformaPago['nombre']." ".$kformaPago['apellidos']."</td>
|
|
<td style=\"text-align:right; padding-right:20px\">$".$ventas."</td>
|
|
<td style=\"text-align:right; padding-right:20px\">$".$kformaPago['comisionVendedor']."</td>
|
|
</tr>";
|
|
}//foreach
|
|
|
|
$x .= "</tbody>
|
|
<tbody>
|
|
<td style=\"background:#F9F9F9\">Venta Total</td>
|
|
<td style=\"background:#F9F9F9;text-align:right;padding-right:20px\"><b>$".$suc['ventasucursal']."</b></td>
|
|
<td></td>
|
|
</tbody>";
|
|
|
|
}//foreach
|
|
|
|
if($Usr['type'] == "admin" || $Usr['type'] == "centralizador" || $Usr['type'] == "almacen"){
|
|
|
|
$x .= "<tr>
|
|
<tbody>
|
|
<tr>
|
|
<td style=\"background:#F9F9F9\">Venta General</td>
|
|
<td style=\"background:#F9F9F9;text-align:right;padding-right:20px\"><b>$".$ventaTotal."</b></td>
|
|
</tr>
|
|
</tbody>";
|
|
}
|
|
|
|
$x .= "</table>";
|
|
|
|
echo $x;
|
|
|
|
break;
|
|
|
|
//Reporte por Temporada
|
|
|
|
case "tipoTempo":
|
|
|
|
$anio = $_POST['anio'];
|
|
$sucursalId = $_POST['sucursal'];
|
|
$temporadaId = $_POST['temporada'];
|
|
|
|
$usrType = $Usr['type'];
|
|
|
|
$reportes->setTypeUser($usrType);
|
|
|
|
$reportes->setIdSuc($sucursalId);
|
|
$reportes->setIdTempo($_POST['idTemp']);
|
|
$reportes->setAnio($anio);
|
|
|
|
$temporadas = $reportes->enumTemporada();
|
|
$temporadas = $util->EncodeResult($temporadas);
|
|
|
|
$resSucursales = $reportes->EnumSucursales($Usr['type'],$Usr['usuarioId']);
|
|
|
|
$fechaI = $anio.'-01-01';
|
|
$fechaF = $anio.'-12-31';
|
|
|
|
$sucursales = array();
|
|
foreach($resSucursales as $suc){
|
|
|
|
$suc['temporadas'] = $temporadas;
|
|
|
|
$resTemp = array();
|
|
foreach($temporadas as $temp){
|
|
|
|
$sql = 'SELECT p.modelo, p.codigoBarra, SUM(vp.cantidad) AS vendidos
|
|
FROM venta v, ventaProducto vp, producto p
|
|
WHERE v.ventaId = vp.ventaId
|
|
AND p.productoId = vp.productoId
|
|
AND ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
|
|
AND v.fecha >= "'.$fechaI.' 00:00:00"
|
|
AND v.fecha <= "'.$fechaF.' 23:59:59"
|
|
AND v.sucursalId = "'.$suc['sucursalId'].'"
|
|
AND p.temporadaId = "'.$temp['temporadaId'].'"
|
|
GROUP BY vp.productoId';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$resProductos = $util->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
$totalVendidos = 0;
|
|
$productos = array();
|
|
foreach($resProductos as $res){
|
|
|
|
$reportes->setFechaI($fechaI);
|
|
$reportes->setFechaF($fechaF);
|
|
$reportes->setProductoId($res['productoId']);
|
|
$reportes->setIdSuc($suc['sucursalId']);
|
|
|
|
$devueltos = $reportes->GetTotalProdDevBySuc();
|
|
|
|
$totVend = $res['vendidos'] - $devueltos;
|
|
$totalVendidos += $totVend;
|
|
|
|
$res['vendidos'] = $totVend;
|
|
$res['modelo'] = utf8_encode($res['modelo']);
|
|
|
|
$productos[] = $res;
|
|
}
|
|
|
|
$products = $reportes->orderMultiDimensionalArray($productos,"vendidos",true);
|
|
|
|
$temp['productos'] = $products;
|
|
|
|
$temp['totalVendidos'] = $totalVendidos;
|
|
|
|
$resTemp[] = $temp;
|
|
}
|
|
$suc['temporadas'] = $resTemp;
|
|
|
|
$sucursales[] = $suc;
|
|
}
|
|
|
|
$x .= "<table><th colspan=\"2\">Año: ".$anio."</th></table>";
|
|
|
|
$x .= "<table border=\"1\">";
|
|
foreach($sucursales as $suc){
|
|
|
|
foreach($suc['temporadas'] as $temp){
|
|
|
|
if(count($temp['productos']) > 0){
|
|
|
|
$x .= "<thead>
|
|
<tr>
|
|
<th style=\"background:#E0E5E7;text-align:center\" colspan=\"3\">
|
|
<b>".utf8_decode(urldecode($suc['nombre']))."</b>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>";
|
|
|
|
$x .= "
|
|
<tr>
|
|
<td style=\"background:#E0E5E7;text-align:center\">Código de Barras</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\">".$temp['nombre']."</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">
|
|
Número de productos vendidos
|
|
</td>
|
|
</tr>";
|
|
|
|
foreach($temp['productos'] as $prod){
|
|
|
|
$x .= "
|
|
<tr>
|
|
<td>".$prod['codigoBarra']." </td>
|
|
<td>".$prod['modelo']."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".$prod['vendidos']."</td>
|
|
</tr>";
|
|
|
|
}//foreach
|
|
|
|
$x .= "
|
|
<tr>
|
|
<td></td>
|
|
<td><b>TOTAL</b></td>
|
|
<td style=\"text-align:center; padding-right:20px\"><b>".$temp['totalVendidos']."</b></td>
|
|
</tr>";
|
|
|
|
$x .= "</tbody>";
|
|
|
|
}//if
|
|
|
|
}//foreach
|
|
|
|
}//foreach
|
|
|
|
$x .= "</table>";
|
|
|
|
echo $x;
|
|
|
|
break;
|
|
|
|
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>PRODUCTOS>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
|
|
|
case "tipoProMasVend":
|
|
|
|
$reportes->setFechaI($_POST['fechaI']);
|
|
$reportes->setFechaF($_POST['fechaF']);
|
|
$orden = $_POST['orden'];
|
|
|
|
$fechaI = date('Y-m-d',strtotime($_POST['fechaI']));
|
|
$fechaF = date('Y-m-d',strtotime($_POST['fechaF']));
|
|
|
|
$smarty->assign("fi",$_POST['fechaI']);
|
|
$smarty->assign("ff",$_POST['fechaF']);
|
|
$smarty->assign("orden",$_POST['orden']);
|
|
$smarty->assign("type",$Usr);
|
|
|
|
if($orden == "mayor")
|
|
$mayormenor = true;
|
|
else
|
|
$mayormenor = false;
|
|
|
|
if($Usr['type']=="admin")
|
|
$smarty->assign("tipo","admin");
|
|
if($Usr['type']=="gerente")
|
|
$smarty->assign("tipo","gerente");
|
|
|
|
$reportes->setIdSuc($_POST['sucursal']);
|
|
$resSucursales = $reportes->EnumSucursales($Usr['type'],$Usr['usuarioId']);
|
|
|
|
$totDispGral = 0;
|
|
$totProdsGral = 0;
|
|
$totImpGral = 0;
|
|
$prodsGral = array();
|
|
foreach($resSucursales as $res){
|
|
$sucursalId = $res['sucursalId'];
|
|
|
|
$reportes->setIdSuc($sucursalId);
|
|
|
|
$sql = 'SELECT p.productoId, p.codigoBarra, p.modelo, p.costo, p.precioVentaIva AS precioVenta, SUM(vp.cantidad) AS vendidos
|
|
FROM ventaProducto AS vp, venta AS v, 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.fecha >= "'.$fechaI.' 00:00:00"
|
|
AND v.fecha <= "'.$fechaF.' 23:59:59"
|
|
AND v.sucursalId = "'.$sucursalId.'"
|
|
GROUP BY vp.productoId ORDER BY p.productoId';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$resProds = $util->DBSelect($_SESSION['empresaId'])->GetResult();
|
|
|
|
$sql = 'SELECT SUM(cantidad) AS disponible, productoId FROM inventario
|
|
WHERE sucursalId = '.$sucursalId.'
|
|
AND status = "Disponible" GROUP BY productoId ORDER BY productoId';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$disponibles = $util->DBSelect($_SESSION['empresaId'])->GetResultById("productoId");
|
|
|
|
$start = microtime(true);
|
|
|
|
$sql = 'SELECT SUM(cantidad) AS ventasDescontadas, inventario.productoId FROM inventario
|
|
JOIN pedido ON pedido.pedidoId = inventario.pedidoId
|
|
WHERE inventario.sucursalId = '.$sucursalId.'
|
|
AND pedido.ventaDesc = "Si"
|
|
GROUP BY inventario.productoId ORDER BY inventario.productoId';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$ventasDescontadas = $util->DBSelect($_SESSION['empresaId'])->GetResultById("productoId");
|
|
|
|
//Importe Venta
|
|
$sql = 'SELECT SUM(
|
|
IF(vp.tipoDesc = "Porcentaje", vp.total - (vp.total * (vp.valDesc / 100)),
|
|
IF(vp.tipoDesc = "Dinero", vp.total - vp.valDesc, vp.total)
|
|
)
|
|
) AS total, vp.productoId FROM ventaProducto AS vp, venta AS v
|
|
WHERE v.ventaId = vp.ventaId
|
|
AND ((v.status = "Cancelado" AND v.cancelDev = "1") OR v.status <> "Cancelado")
|
|
AND v.fecha >= "'.$fechaI.' 00:00:00"
|
|
AND v.fecha <= "'.$fechaF.' 23:59:59"
|
|
AND v.sucursalId = "'.$sucursalId.'"
|
|
GROUP BY vp.productoId';
|
|
$util->DBSelect($_SESSION['empresaId'])->setQuery($sql);
|
|
$impVendArray = $util->DBSelect($_SESSION['empresaId'])->GetResultById("productoId");
|
|
|
|
$totalDisp = 0;
|
|
$totalProds = 0;
|
|
$totalImporte = 0;
|
|
$productos = array();
|
|
foreach($resProds as $prod){
|
|
|
|
$prod["disponible"] = $disponibles[$prod["productoId"]]["disponible"];
|
|
$prod["ventasDescontadas"] = $ventasDescontadas[$prod["productoId"]]["ventasDescontadas"];
|
|
|
|
$productoId = $prod['productoId'];
|
|
|
|
$reportes->setProductoId($productoId);
|
|
$devueltos = $reportes->GetTotalProdDevBySuc();
|
|
$totalVendidos = $prod['vendidos'] - $devueltos;
|
|
$prod['vendidos'] = $totalVendidos;
|
|
if($prod['vendidos'] == 0)
|
|
continue;
|
|
|
|
$impVend = $impVendArray[$prod["productoId"]]["total"];;
|
|
|
|
//Este tambien se puede mejorar de la misma manera
|
|
$impDev = $reportes->GetImpTotalProdDevBySuc();
|
|
|
|
$importe = $impVend - $impDev;
|
|
$prod['total'] = $importe;
|
|
|
|
$prod['disponible'] -= $prod['ventasDescontadas'];
|
|
|
|
$totalDisp += $prod['disponible'];
|
|
$totalProds += $totalVendidos;
|
|
$totalImporte += $importe;
|
|
|
|
//Productos General MasMenos Vendidos
|
|
$cardP = array();
|
|
$cardP = $prodsGral[$productoId];
|
|
|
|
if(count($cardP) == 0){
|
|
$cardP['modelo'] = utf8_encode($prod['modelo']);
|
|
$cardP['codigoBarra'] = $prod['codigoBarra'];
|
|
$cardP['precioVenta'] = $prod['precioVenta'];
|
|
$cardP['costo'] = $prod['costo'];
|
|
}
|
|
$cardP['total'] = $importe;
|
|
|
|
$inventario->setProductoId($productoId);
|
|
$inventario->setSucursalId($sucursalId);
|
|
|
|
$cardP['disponible'] += $prod['disponible'];
|
|
$cardP['vendidos'] += $totalVendidos;
|
|
|
|
$totDispGral += $prod['disponible'];
|
|
$totProdsGral += $totalVendidos;
|
|
$totImpGral += $cardP['total'];
|
|
|
|
$prodsGral[$productoId] = $cardP;
|
|
|
|
$productos[] = $prod;
|
|
}
|
|
|
|
$res['productos'] = $reportes->orderMultiDimensionalArray($productos,'vendidos',$mayormenor);
|
|
|
|
$res['disponible'] = $totalDisp;
|
|
$res['vendidos'] = $totalProds;
|
|
$res['importe'] = $totalImporte;
|
|
|
|
$sucursales[] = $res;
|
|
|
|
}//foreach
|
|
|
|
$prodsGral2 = $reportes->orderMultiDimensionalArray($prodsGral,'vendidos',$mayormenor);
|
|
|
|
$x.="<table border=\"1\">";
|
|
|
|
foreach($sucursales as $suc){
|
|
|
|
$x .= "<thead>
|
|
<tr>
|
|
<th style=\"background:#E0E5E7;text-align:center\" colspan=\"7\">
|
|
<b>".utf8_decode(urldecode($suc['nombre']))."</b>
|
|
</th>
|
|
</tr>
|
|
</thead><tbody>";
|
|
$x .= "
|
|
<tr>
|
|
<td style=\"background:#E0E5E7;text-align:center\">Código de Barras</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\">Producto</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\">Inv. Actual</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Número de productos 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['codigoBarra']."
|
|
</td>
|
|
<td>".$temp['modelo']."</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\">".number_format($temp['costo'],2)."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".number_format($temp['precioVenta'],2)."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".number_format($temp['total'],2)."</td>
|
|
</tr>";
|
|
|
|
}//foreach
|
|
|
|
$x .= "
|
|
<tr>
|
|
<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\">".number_format($suc['disponible'],2)."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".number_format($suc['vendidos'],2)."</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\">".number_format($suc['importe'],2)."</td>
|
|
</tr>";
|
|
|
|
$x .= "</tbody>";
|
|
|
|
}//foreach
|
|
|
|
$x .= "</table>";
|
|
|
|
if($Usr['type'] == "admin" || $Usr['type'] == "centralizador" || $Usr['type'] == "almacen"){
|
|
|
|
if($orden=="mayor"){$texto="Productos Más Vendidos";}
|
|
if($orden=="menor"){$texto="Productos Menos Vendidos";}
|
|
$x.="<table border=\"1\">";
|
|
$x.="<thead><tr><th style=\"background:#E0E5E7;text-align:center\" colspan=\"7\"><b>".$texto."</b></th></tr>";
|
|
$x .= "
|
|
<tr>
|
|
<td style=\"background:#E0E5E7;text-align:center\">Código de Barras</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\">Producto</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\">Inv. Actual</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">
|
|
Número de productos 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($prodsGral2 as $vendidos)
|
|
{
|
|
$x .= "
|
|
<tr>
|
|
<td style=\"text-align:center; padding-right:20px\">
|
|
".$vendidos['codigoBarra']." </td><td>".$vendidos['modelo']."
|
|
</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".number_format($vendidos['disponible'],2)."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".number_format($vendidos['vendidos'],2)."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".number_format($vendidos['costo'],2)."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".number_format($vendidos['precioVenta'],2)."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".number_format($vendidos['total'],2)."</td>
|
|
</tr>";
|
|
}
|
|
|
|
$x .= "
|
|
<tr>
|
|
<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\">".number_format($totDispGral,2)."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".number_format($totProdsGral,2)."</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\">".number_format($totImpGral,2)."</td>
|
|
</tr>";
|
|
|
|
$x.="</tbody>";
|
|
$x.="</table>";
|
|
|
|
}//if
|
|
|
|
echo $x;
|
|
|
|
break;
|
|
|
|
case "tipoVentasProv":
|
|
$reportes->setFechaI($_POST['fechaI']);
|
|
$reportes->setFechaF($_POST['fechaF']);
|
|
if($reportes->validaF($_POST['fechaI'],$_POST['fechaF']))
|
|
{
|
|
$reportes->setIdSuc($_POST['sucursal']);
|
|
$sucursal=$reportes->enumsucursales();
|
|
$reportes->setProveedor($_POST['proveedor']);
|
|
$proveedores=$reportes->DatosProveedor();
|
|
$arregloVentas=$reportes->VentaVentaId();
|
|
if(sizeof($arregloVentas)>0)
|
|
{
|
|
$proVenta=$reportes->productosXventa();
|
|
$devVenta=$reportes->devolucionesXventa();
|
|
$n=0;
|
|
foreach($proVenta as $pv) //obtengo ventas
|
|
{ $dt[$n]=$pv;
|
|
foreach($devVenta as $dv)
|
|
{
|
|
if($pv['ventaId']==$dv['ventaId'] && $pv['productoId']==$dv['productoId'])
|
|
{
|
|
$dt[$n]['ventaProducto']=$pv['ventaProducto']-$dv['ncantidadDevolucion'];
|
|
}
|
|
}
|
|
$n=$n+1;
|
|
}
|
|
$n=0;
|
|
foreach($dt as $au) //le agrego la sucursal de la venta
|
|
{
|
|
foreach($arregloVentas as $vG)
|
|
{
|
|
if($vG['ventaId']==$au['ventaId'])
|
|
{
|
|
$ventasGR[$n]=$au;
|
|
$ventasGR[$n]['sucursal']=$vG['sucursalId'];
|
|
$ventasGR[$n]['contador']=$n;
|
|
}
|
|
}
|
|
$n=$n+1;
|
|
}
|
|
|
|
$n=0;
|
|
|
|
foreach($proveedores as $prov) //filtro los proveedores
|
|
{
|
|
foreach($ventasGR as $venta)
|
|
{
|
|
if($venta['proveedorId']==$prov['proveedorId'])
|
|
{
|
|
$provee[$n]['proveedorId']=$prov['proveedorId'];
|
|
$provee[$n]['nombre']=$prov['nombre'];
|
|
}
|
|
}$n=$n+1;
|
|
}
|
|
//------------
|
|
if(sizeof($provee)>0)
|
|
{
|
|
foreach($sucursal as $suc)
|
|
{
|
|
$data[$suc['sucursalId']]=$suc;
|
|
foreach($provee as $prov)
|
|
{
|
|
foreach($ventasGR as $ventas)
|
|
{
|
|
if($ventas['sucursal']==$suc['sucursalId'] && $ventas['proveedorId']==$prov['proveedorId'])
|
|
{
|
|
$data[$suc['sucursalId']]['proveedores'][$prov['proveedorId']]=$prov;
|
|
$data[$suc['sucursalId']]['proveedores'][$prov['proveedorId']]['ventas'][$ventas['contador']]=$ventas;
|
|
$data[$suc['sucursalId']]['proveedores'][$prov['proveedorId']]['totalProductos']+=$ventas['ventaProducto'];
|
|
$data[$suc['sucursalId']]['proveedores'][$prov['proveedorId']]['totalVenta']+=($ventas['ventaProducto']* $ventas['precioVenta']);
|
|
$data[$suc['sucursalId']]['totalProductos']+=$ventas['ventaProducto'];
|
|
$data[$suc['sucursalId']]['totalVenta']+=($ventas['ventaProducto']* $ventas['precioVenta']);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$x.="<table border=\"1\">";
|
|
foreach($data as $ventasProv=>$key)
|
|
{
|
|
if(sizeof($key['proveedores'])!=0)
|
|
{
|
|
$x.="<thead>
|
|
<tr>
|
|
<th style=\"background:#E0E5E7;text-align:center\" colspan=\"3\"><b>".utf8_decode(urldecode($key['nombre']))."</b></th>
|
|
</tr>
|
|
</thead><tbody>";
|
|
$x.="<tr><td style=\"background:#E0E5E7;text-align:center\">Sucursal</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Número de productos vendidos</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Total de Venta</td>
|
|
</tr>";
|
|
|
|
foreach($key['proveedores'] as $v=>$key2)
|
|
{
|
|
if (sizeof($key2['ventas'])!=0)
|
|
{
|
|
$x.="<tr><td>".$key2['nombre']."</td>
|
|
<td style=\"text-align:center; padding-right:20px\">".$key2['totalProductos']."</td>
|
|
<td style=\"text-align:right; padding-right:20px\">$".$key2['totalVenta']."</td></tr>";
|
|
}
|
|
}
|
|
$x.="
|
|
<tr>
|
|
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">Total</td>
|
|
<td style=\"background:#E0E5E7;text-align:center\" padding-right:20px\">".$key['totalProductos']."</td>
|
|
<td style=\"background:#E0E5E7;text-align:right\" padding-right:20px\">$".$key['totalVenta']."</td>
|
|
</tr>";
|
|
}
|
|
}
|
|
$x.="</tbody>";
|
|
$x.="</table>";
|
|
echo $x;
|
|
}//if
|
|
}//if
|
|
}//if
|
|
|
|
break;
|
|
|
|
//------------------------------------reportes de productos
|
|
case "tipoComprado":
|
|
$reportes->setFechaI($_POST['fechaI']);
|
|
$reportes->setFechaF($_POST['fechaF']);
|
|
$reportes->setUserUsuario($Usr['usuarioId']);
|
|
$reportes->setOrden($_POST['orden']);
|
|
if($reportes->validaF($_POST['fechaI'],$_POST['fechaF']))
|
|
{
|
|
$resProdCom=$reportes->ProductosComprados();
|
|
$x.="
|
|
<table> <thead>
|
|
<tr><th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Fecha</div></th>
|
|
<th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Producto</div></th>
|
|
<th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Número de productos comprados</div></th>
|
|
</tr></thead>";
|
|
foreach($resProdCom as $rProdCom)
|
|
{
|
|
$x.="
|
|
<tr>
|
|
<td style=\"mso-width-alt:6000;\"><div style=\"text-align:center\">".$rProdCom['fecha']."</div></td>
|
|
<td style=\"mso-width-alt:7000;\">".urldecode($rProdCom['modelo'])."</td>
|
|
<td style=\"mso-width-alt:7000;\">".$rProdCom['nProductos']."</td>
|
|
</tr>";
|
|
}
|
|
$x.="</table>";
|
|
echo $x;
|
|
}
|
|
break;//fin reporte producto mas comprado
|
|
|
|
case "tipoCuentasPend"://cuentas por pagar
|
|
$reportes->setFechaI(date('Y-m-d',strtotime($_POST['fechaI'])));
|
|
$reportes->setFechaF(date('Y-m-d',strtotime($_POST['fechaF'])));
|
|
$reportes->setIdSuc($_POST['sucursal']);
|
|
$reportes->setUserUsuario($Usr['usuarioId']);
|
|
if($Usr['type']=="admin")
|
|
{
|
|
$reportes->setTypeUser("admin");
|
|
$reportes->setIdSuc($Usr['sucursalId']);
|
|
}
|
|
if($reportes->validaF($_POST['fechaI'],$_POST['fechaF']))
|
|
{
|
|
$reportes->setProveedor($_POST['proveedor']);
|
|
$resCuentasPP=$reportes->cuentasPorpagar();
|
|
foreach($resCuentasPP as $rCuentasPP)
|
|
{
|
|
$reportes->setPedidoId($rCuentasPP['noPedido']);
|
|
$rCuentasPP['fecha']=date('d-m-Y H:i:s',strtotime($rCuentasPP['fecha']));
|
|
$rCuentasPP['bonificaciones']=$reportes->bonificaciones();
|
|
if($rCuentasPP['saldo']==NULL){$rCuentasPP['saldo']=$rCuentasPP['total'];}
|
|
if($rCuentasPP['totalparcial']==NULL){$rCuentasPP['totalparcial']="0.00";}
|
|
$rCuentasPP['saldoTotal'] =$rCuentasPP['saldo'] - $rCuentasPP['bonificaciones'];
|
|
$resultado[]=$rCuentasPP;
|
|
}
|
|
|
|
|
|
$x.="
|
|
<table> <thead>
|
|
<tr><th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Número de pedido</div></th>
|
|
<th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Fecha del pedido</div></th>
|
|
<th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Proveedor</div></th>
|
|
<th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Total</div></th>
|
|
<th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Abonos</div></th>
|
|
<th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Bonificaciones</div></th>
|
|
<th style=\"background:#EFEFEF\"><div style=\"text-align:center\">Saldo</div></th>
|
|
</tr></thead>";
|
|
foreach($resultado as $resPP)
|
|
{
|
|
$x.="
|
|
<tbody><tr>
|
|
<td style=\"mso-width-alt:6000;\"><div style=\"text-align:center\">".$resPP['noPedido']."</div></td>
|
|
<td>".$resPP['fecha']."</td>
|
|
<td style=\"mso-width-alt:7000;\">".urldecode($resPP['nombre'])."</td>
|
|
<td style=\"mso-width-alt:5000; mso-number-format:#,##0.00;\">$".$resPP['total']."</td>
|
|
<td style=\"mso-width-alt:5000; mso-number-format:#,##0.00;\">$".$resPP['totalparcial']."</td>
|
|
<td style=\"mso-width-alt:5000; mso-number-format:#,##0.00;\">$".$resPP['bonificaciones']."</td>
|
|
<td style=\"mso-width-alt:5000; mso-number-format:#,##0.00;\">$".$resPP['saldoTotal']."</td>
|
|
</tr></tbody>";
|
|
}
|
|
$x.="</table>";
|
|
echo $x;
|
|
|
|
}
|
|
break;
|
|
|
|
case "rInventario":
|
|
$reportes->setIdSuc($_POST['sucursal']);
|
|
$reportes->setProveedor($_POST['proveedorId']);
|
|
$resSuc=$reportes->enumsucursales();
|
|
$existentes=$reportes->disponibles();
|
|
if(sizeof($existentes)<1)
|
|
{
|
|
echo "<table width=\"100%\"><th style=\"text-align:center;\">No existen elementos para mostrar</th></table>";
|
|
}
|
|
else
|
|
{
|
|
$data=array();
|
|
foreach($resSuc as $sucursales)
|
|
{
|
|
$data[$sucursales['sucursalId']]=$sucursales;
|
|
foreach($existentes as $enumproductos)
|
|
{
|
|
if($sucursales['sucursalId']==$enumproductos['sucursalId'])
|
|
{
|
|
$data[$sucursales['sucursalId']]['producto'][$enumproductos['productoId']]=$enumproductos;
|
|
$data[$sucursales['sucursalId']]['producto'][$enumproductos['productoId']]['proveedor']=utf8_encode($reportes->GetProveedor($enumproductos['proveedorId']));
|
|
}
|
|
}
|
|
}
|
|
|
|
$x.="<table border=\"1\">";
|
|
foreach($data as $sucursales=>$sucursal)
|
|
{
|
|
$x.="<thead>
|
|
<tr>
|
|
<th style=\"background:#CCC;text-align:center\" colspan=\"4\"><b>".utf8_decode(urldecode($sucursal['nombre']))."</b></th>
|
|
</tr>
|
|
<tr>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Proveedor</b></th>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Modelo</b></th>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Precio de Venta</b></th>
|
|
<th style=\"background:#E0E5E7;text-align:center\"><b>Disponible</b></th>
|
|
</tr>
|
|
</thead><tbody>";
|
|
foreach($sucursal['producto'] as $productos=>$kproductos)
|
|
{
|
|
if($kproductos['ndisponibles']!=0)
|
|
{
|
|
$x.="<tr><td>".$kproductos['proveedor']."</td>
|
|
<td style=\"text-align:center;\">".urldecode($kproductos['modelo'])."</td>
|
|
<td style=\"text-align:right; padding-right:20px\">$".$kproductos['precioVenta']."</td>
|
|
<td style=\"text-align:center;\">".$kproductos['ndisponibles']."</td>
|
|
</tr>";
|
|
}
|
|
}
|
|
$x.="</tbody>";
|
|
}
|
|
$x.="</table>";
|
|
echo $x;
|
|
}
|
|
break;//FIN reporte de productos en inventario
|
|
}//switch
|
|
}//else
|
|
|
|
?>
|