834 lines
30 KiB
PHP
Executable File
834 lines
30 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'] != '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;
|
|
|
|
?>
|