255 lines
7.9 KiB
PHP
Executable File
255 lines
7.9 KiB
PHP
Executable File
<?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;
|
|
|
|
?>
|