Files
ventas_php/export/ventas-general.php

147 lines
5.2 KiB
PHP
Executable File

<?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;
?>