git-svn-id: https://192.168.0.254/svn/Proyectos.MatritumCantat_Web/trunk@2 8e3496fd-7892-4c45-be36-0ff06e9dacc6
452 lines
16 KiB
PHP
452 lines
16 KiB
PHP
<?php
|
|
###################################################################################
|
|
#INICIO
|
|
###################################################################################
|
|
# Inicializamos
|
|
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
|
|
require($mosConfig_absolute_path."/includes/perfiles.php");
|
|
require($mosConfig_absolute_path."/administrator/components/com_tesoreria/config.tesoreria.php");
|
|
require($mosConfig_absolute_path."/components/com_tesoreria/version.php");
|
|
|
|
# Establecemos idioma
|
|
if (file_exists('components/com_tesoreria/lang/'.$mosConfig_lang.'.php')) {
|
|
include('components/com_tesoreria/lang/'.$mosConfig_lang.'.php');
|
|
} else {
|
|
include('components/com_tesoreria/lang/spanish.php');
|
|
}
|
|
|
|
$trimestres = array (LIT_TRI1, LIT_TRI2, LIT_TRI3, LIT_TRI4);
|
|
$meses = array (LIT_ENE, LIT_FEB, LIT_MAR, LIT_ABR, LIT_MAY, LIT_JUN, LIT_JUL, LIT_AGO, LIT_SEP, LIT_OCT, LIT_NOV, LIT_DIC);
|
|
|
|
$cabecera ="<tr><th></th><th align='left'>Fecha</th><th align='left'>Descripción</th><th align='right'>Importe</th></tr>";
|
|
|
|
###################################################################################
|
|
#FUNCIONES
|
|
###################################################################################
|
|
# Dibujar Footer
|
|
function RefFooter($Tesoreria_version) {
|
|
echo "<center><font face=\"Arial\" size=\"1\"><b><font color=\"#0000FF\">Área</font><font color=\"#FF0000\"><img border=\"0\" src=\"components/com_tesoreria/images/tynimam.jpg\" width=\"12\" height=\"11\">Ensayo</font></b> $Tesoreria_version por <a href=\"http://www.rodax-software.com\" target=\"_blank\"><font face=\"Arial\" size=\"1\">Rodax Software S.L</font></a></center>";
|
|
return;
|
|
}
|
|
|
|
# Dibujar Cabecera
|
|
function RefHeader($Itemid) {
|
|
global $database;
|
|
echo "<span class='componentheading'>";
|
|
$database->setQuery("SELECT name from #__menu WHERE id='$Itemid'");
|
|
$menuname = $database->loadResult();
|
|
echo "$menuname";
|
|
echo "</span><p />";
|
|
return;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
// Función que nos escribe el script necesario para el listado de cuotas de los usuarios
|
|
//
|
|
function ScriptListaCuotas() {
|
|
echo "<SCRIPT language='JavaScript' type='text/javascript'>";
|
|
|
|
echo "function anadirAno() {"
|
|
."document.Form.op.value = 'opAnadirAno';"
|
|
."document.Form.submit();}";
|
|
|
|
echo "function eliminarEntrada(entrada) {"
|
|
."document.Form.op.value = 'opEliminar';"
|
|
."document.Form.numentrada.value = entrada;"
|
|
."document.Form.submit();}";
|
|
|
|
echo "function refrescar() {"
|
|
."document.Form.submit();}";
|
|
|
|
echo "function anadirEntrada(categoria,literal) {"
|
|
."document.Form.op.value = 'opAnadir';"
|
|
."document.Form.numentrada.value = categoria;"
|
|
."document.Form.literal.value = literal;"
|
|
."document.Form.submit();}";
|
|
|
|
echo "function grabar() {"
|
|
."if (document.Form.cuantia.value.lastIndexOf(',') != -1){"
|
|
."alert ('". LIT_ERR_CUANTIA ."');"
|
|
."document.Form.cuantia.focus();"
|
|
."document.Form.cuantia.select();"
|
|
."}else {"
|
|
."document.Form.op.value = 'opGrabar';"
|
|
."document.Form.submit();}}";
|
|
|
|
echo "function cancelar() {"
|
|
."document.Form.op.value = 'list';"
|
|
."document.Form.submit();}";
|
|
|
|
echo "</script>";
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////
|
|
// Función que nos muestra el listado de cuotas de los usuarios
|
|
//
|
|
function verListaTesoreria($idtrimestre, $idano) {
|
|
global $database, $my, $trimestres, $meses, $cabecera, $Perfiles;
|
|
|
|
$tabclass = array( 'sectiontableentry1', 'sectiontableentry2' );
|
|
ScriptListaCuotas();
|
|
|
|
//COMBO TRIMESTRE
|
|
$listatri = '<select name="idtrimestre" class="inputbox" size="1" onchange="javascript:refrescar();">';
|
|
$i=0;
|
|
foreach($trimestres as $trimestre){
|
|
$listatri .= "<option value=$i";
|
|
if ($idtrimestre == $i)
|
|
$listatri .= " selected";
|
|
$listatri .= ">$trimestre</option>";
|
|
$i++;
|
|
}
|
|
//Opcion todos
|
|
$listatri .= "<option value=$i";
|
|
if ($idtrimestre == $i)
|
|
$listatri .= " selected";
|
|
$listatri .= ">". LIT_TODOS ."</option>";
|
|
$listatri .= "</select>";
|
|
|
|
//COMBO ANO
|
|
$listano = '<select name="idano" class="inputbox" size="1" onchange="javascript:refrescar();">';
|
|
$cadena = "select distinct DATE_FORMAT(fecha, '%Y') as ano"
|
|
. "\nFROM #__tesoreria"
|
|
. "\nORDER BY ano";
|
|
$database->setQuery($cadena);
|
|
$rows = $database->loadObjectList();
|
|
foreach($rows as $row1){
|
|
$listano .= "<option value=$row1->ano";
|
|
if ($idano == $row1->ano)
|
|
$listano .= " selected";
|
|
$listano .= ">$row1->ano</option>";
|
|
}
|
|
$listano .= "</select>";
|
|
|
|
//FORMULARIO DE VISTA
|
|
//Campos Ocultos
|
|
echo "<form action='' method='post' name='Form'>";
|
|
echo '<input type="hidden" name="op" value=""/>';
|
|
echo '<input type="hidden" name="numentrada" value=""/>';
|
|
echo '<input type="hidden" name="literal" value=""/>';
|
|
|
|
echo '<table cellpadding="0" cellspacing="0" border="0" width="100%" class="contentpane">';
|
|
echo '<tr>';
|
|
echo '<td align="left">';
|
|
echo 'Ver ';
|
|
|
|
//Campos Visibles
|
|
echo $listatri;
|
|
echo ' de ';
|
|
echo $listano;
|
|
|
|
echo '</td><td class="buttonheading" width="150px">';
|
|
|
|
//Solo podra Tesorero, administrador y superadministrador
|
|
if (($Perfiles->esTesorero()) || strtolower($my->usertype) == 'administrator'
|
|
|| strtolower($my->usertype) == 'super administrator' )
|
|
echo '<a href="javascript:anadirAno();"><img src="components/com_tesoreria/images/add.gif">'. LIT_ANAANO .'</a>';
|
|
|
|
echo '</td>'
|
|
.'<td class="buttonheading">';
|
|
|
|
echo '</td></tr></table><br/>';
|
|
|
|
//DETALLES
|
|
//Dibujamos cabecera
|
|
switch ($idtrimestre) {
|
|
case 0: $cadenaAux = "('01','02','03')";
|
|
break;
|
|
case 1: $cadenaAux = "('04','05','06')";
|
|
break;
|
|
case 2: $cadenaAux = "('07','08','09')";
|
|
break;
|
|
case 3: $cadenaAux = "('10','11','12')";
|
|
break;
|
|
default: $cadenaAux = "";
|
|
break;
|
|
}
|
|
|
|
//Dibujamos detalle
|
|
$cadena = "SELECT t.*, DATE_FORMAT(t.fecha, '%Y'), DATE_FORMAT(t.fecha, '%m'), c.title"
|
|
. "\nFROM #__tesoreria as t"
|
|
. "\nLEFT JOIN #__categories AS c ON c.id = t.catid"
|
|
. "\nWHERE DATE_FORMAT(t.fecha, '%Y')='". $idano ."'";
|
|
if ($cadenaAux != "")
|
|
$cadena .= "\nAND DATE_FORMAT(t.fecha, '%m') in ". $cadenaAux;
|
|
$cadena .= "\nORDER BY t.catid, t.fecha";
|
|
|
|
$database->setQuery($cadena);
|
|
$rows = $database->loadObjectList();
|
|
|
|
//Dibujamos tablas de ingresos y gastos
|
|
$catidAnt = "";
|
|
$subTotal = 0;
|
|
$Total = 0;
|
|
$k = 0;
|
|
foreach ($rows as $row1){
|
|
|
|
//Cabeceras
|
|
if ($catidAnt == "" || $catidAnt != $row1->catid) {
|
|
if ($catidAnt != ""){
|
|
echo "<tr><td align='right' colspan=3><strong>". LIT_TOTAL ."</strong></td><td align='right'><strong>". number_format($subTotal, 2,',','.') ." €</strong></td></tr>";
|
|
echo "</table>";
|
|
$Total = $subTotal;
|
|
$subTotal = 0;
|
|
}
|
|
|
|
$catidAnt = $row1->catid;
|
|
|
|
echo "<table width='100%' border='0' cellspacing='0' cellpadding='2' class='contentpane'>";
|
|
echo '<tr><td class="contentheading">'. $row1->title .'</td></tr>';
|
|
echo '<tr><td class="buttonheading">';
|
|
//Solo podra Tesorero, administrador y superadministrador
|
|
if (($Perfiles->esTesorero()) || strtolower($my->usertype) == 'administrator'
|
|
|| strtolower($my->usertype) == 'super administrator' )
|
|
echo "<a href=javascript:anadirEntrada('". $row1->catid ."','" . $row1->title
|
|
."')><img src='components/com_tesoreria/images/add.gif'>". LIT_ANAAPU ."</a>";
|
|
echo '</td></tr>';
|
|
echo '</table>';
|
|
|
|
echo "<table width='100%' border='0' cellspacing='0' cellpadding='0' class='contentpaneopen'>";
|
|
echo $cabecera;
|
|
}
|
|
|
|
//Detalles
|
|
|
|
if ($row1->published == 1) {
|
|
echo '<tr class="' . $tabclass[$k]. '"?>';
|
|
$k = 1 - $k;
|
|
//CheckBox para eliminar entradas
|
|
if (($Perfiles->esTesorero()) || strtolower($my->usertype) == 'administrator'
|
|
|| strtolower($my->usertype) == 'super administrator' )
|
|
echo "<td align='center' class='buttonheading'><a href='javascript:eliminarEntrada(". $row1->id
|
|
.")'><img src='components/com_tesoreria/images/delete.png'/></a></td>";
|
|
else
|
|
echo "<td></td>";
|
|
|
|
echo "<td align='left'>".$row1->fecha ."</td>";
|
|
echo "<td align='left'>".$row1->descripcion ."</td>";
|
|
echo "<td align='right'>".number_format($row1->cuantia, 2,',','.')." €</td>";
|
|
echo "</tr>";
|
|
}
|
|
$subTotal = $subTotal + $row1->cuantia;
|
|
}
|
|
echo "<tr><td align='right' colspan=3><strong>". LIT_TOTAL ."</strong></td><td align='right'><strong>". number_format($subTotal, 2,',','.')." €</strong></td></tr>";
|
|
echo "</table>";
|
|
$Total = $Total - $subTotal;
|
|
echo '<table cellpadding="0" cellspacing="0" border="0" width="99%">';
|
|
echo '<tr><td>'. LIT_TES .' '. number_format($Total, 2,',','.') .' €</td></tr>';
|
|
echo '</table>';
|
|
echo '</form>';
|
|
return;
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Función que crea las entradas del nuevo año pasado por parametro en tabla cuotas
|
|
// de todos y cada uno de los usuarios de la página
|
|
//
|
|
function anadir ($numentrada, $literal, $idtrimestre, $idano){
|
|
|
|
echo '<script type="text/javascript" src="includes/js/mambojavascript.js"></script>';
|
|
echo '<script type="text/javascript" src="includes/js/calendar/calendar.js"></script>';
|
|
echo '<link rel="stylesheet" type="text/css" media="all" href="includes/js/calendar/calendar-mos.css" title="green" />';
|
|
echo '<script type="text/javascript" src="includes/js/calendar/lang/calendar-en.js"></script>';
|
|
|
|
ScriptListaCuotas();
|
|
|
|
echo "<form action='' method='post' name='Form'>";
|
|
echo '<input type="hidden" name="op" value=""/>';
|
|
|
|
echo '<input type="hidden" name="catid" value="'. $numentrada .'"/>';
|
|
echo '<input type="hidden" name="idtrimestre" value="'. $idtrimestre .'"/>';
|
|
echo '<input type="hidden" name="idano" value="'. $idano .'"/>';
|
|
|
|
|
|
echo '<table cellpadding="0" cellspacing="0" border="0" width="99%">';
|
|
echo '<tr>';
|
|
echo '<th align="center">'. LIT_ANADIR .' '. $literal .'</th>';
|
|
echo '<th align="right">';
|
|
echo '<a href="javascript:grabar();" onmouseout="MM_swapImgRestore();" '
|
|
.'onmouseover="MM_swapImage(\'save\',\'\',\''.$mosConfig_absolute_path.'/images/save_f2.png\',1);">'
|
|
.'<img src="'.$mosConfig_absolute_path.'/images/save.png" alt="Guardar" align="middle" name="save" border="0" /></a>';
|
|
|
|
echo '<a href="javascript:cancelar();" onmouseout="MM_swapImgRestore();"'
|
|
.'onmouseover="MM_swapImage(\'cancel\',\'\',\''.$mosConfig_absolute_path.'/images/cancel_f2.png\',1);">'
|
|
.'<img src="'.$mosConfig_absolute_path.'/images/cancel.png" alt="Cancelar" align="middle" name="cancel" border="0"/></a>';
|
|
echo '</th></tr>';
|
|
|
|
echo '<tr>';
|
|
echo '<td align="right">'. LIT_FECHA .'</td>'
|
|
.'<td><input class="inputbox" type="text" name="fechaent" id="fecha" size="12" maxlength="10" value="'. date("Y-m-d") .'"/>'
|
|
.'<input type="reset" class="button" value="..." onclick="return showCalendar(\'fecha\');"/>';
|
|
echo '</td>';
|
|
echo '</tr>';
|
|
|
|
echo '<tr>';
|
|
echo '<td align="right">'. LIT_DESCRIPCION .'</td>'
|
|
.'<td><input class="inputbox" type="text" name="descripcion" id="descripcion" size="60" maxlength="100" value=""/>';
|
|
echo '</td>';
|
|
echo '</tr>';
|
|
|
|
echo '<tr>';
|
|
echo '<td align="right">'. LIT_CUANTIA .'</td>'
|
|
.'<td><input class="inputbox" type="text" name="cuantia" id="cuantia" size="20" maxlength="20" value="0.0"/> €';
|
|
echo '</td>';
|
|
echo '</tr>';
|
|
|
|
|
|
echo '</table>';
|
|
echo '</form>';
|
|
|
|
return ("True");
|
|
}
|
|
|
|
function eliminar ($numentrada){
|
|
global $database;
|
|
|
|
$cadena = "delete from #__tesoreria"
|
|
. "\nWHERE id = " . $numentrada;
|
|
$database->setQuery($cadena);
|
|
if (!$database->query()) {
|
|
//echo $database->getErrorMsg();
|
|
return ("False");
|
|
exit;
|
|
}
|
|
return ("True");
|
|
}
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Función que añade los 4 trimestrs por defecto a un nuevo año
|
|
//
|
|
function anadirAno() {
|
|
global $database;
|
|
|
|
$resultado = 'True';
|
|
//Hallamos el año a añadir
|
|
$cadena = "SELECT MAX(DATE_FORMAT(fecha, '%Y')) as ano FROM #__tesoreria";
|
|
$database->setQuery($cadena);
|
|
$rows = $database->loadObjectList();
|
|
|
|
if (!$rows[0]->ano) {
|
|
$Aux = getDate();
|
|
$AnoAux = $Aux["year"];
|
|
}
|
|
else
|
|
$AnoAux = $rows[0]->ano+1;
|
|
|
|
//Hallamos las categorias a añadir (ingresos y gastos)
|
|
$cadena = "SELECT * FROM #__categories WHERE section = 'com_tesoreria' order by id";
|
|
$database->setQuery($cadena);
|
|
if ($database->query()) {
|
|
$rows = $database->loadObjectList();
|
|
$i=0;
|
|
foreach ($rows as $row1){
|
|
$cat[$i] = $row1->id;
|
|
$i++;
|
|
}
|
|
}
|
|
else $resultado = 'False';;
|
|
|
|
//Insertamos los 4 trimestres por defecto al nuevo año
|
|
for($i=0; $i < count($cat); $i++) {
|
|
$cadena = "INSERT INTO #__tesoreria (catid, fecha, descripcion, cuantia, published)"
|
|
."\nVALUES (". $cat[$i] . ", '". $AnoAux ."-01-01', '', '0','0'),"
|
|
."\n (". $cat[$i] . ", '". $AnoAux ."-04-01', '', '0','0'),"
|
|
."\n (". $cat[$i] . ", '". $AnoAux ."-07-01', '', '0','0'),"
|
|
."\n (". $cat[$i] . ", '". $AnoAux ."-10-01', '', '0','0')";
|
|
$database->setQuery($cadena);
|
|
if (!$database->query())
|
|
echo "Error de insercion";
|
|
$resultado = 'False';
|
|
}
|
|
|
|
return ($resultado);
|
|
}
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
|
|
// Función que graba la nueva entrada
|
|
//
|
|
function grabar ($catid, $fecha, $descripcion, $cuantia){
|
|
global $database;
|
|
|
|
$cadena = "INSERT INTO #__tesoreria (catid, fecha, descripcion, cuantia, published)"
|
|
."\nVALUES (". $catid . ", '". $fecha ."', '". $descripcion ."', ". $cuantia .",'1')";
|
|
$database->setQuery($cadena);
|
|
if (!$database->query()) {
|
|
echo $database->getErrorMsg();
|
|
return ("False");
|
|
}
|
|
else return ("True");
|
|
}
|
|
|
|
###################################################################################
|
|
#CUERPO
|
|
###################################################################################
|
|
|
|
//Chequeamos acceso
|
|
if ($my->usertype){
|
|
//Establecemos el perfil del usuario
|
|
$Perfiles = new Perfiles($my->id, $database) ;
|
|
|
|
# Estilo de vista
|
|
if ($obrens_verlista=="1" AND $op=="") $op = "list";
|
|
|
|
//Por defecto se posiciona en el trimestre y año actuales
|
|
$fecha = getdate();
|
|
if ($idtrimestre=="") {
|
|
switch($fecha["mon"]) {
|
|
case 1: case 2: case 3: $idtrimestre = 0;
|
|
break;
|
|
case 4: case 5: case 6: $idtrimestre = 1;
|
|
break;
|
|
case 7: case 8: case 9: $idtrimestre = 2;
|
|
break;
|
|
default: $idtrimestre = 3;
|
|
}
|
|
}
|
|
if ($idano=="") {
|
|
$idano = $fecha["year"];
|
|
}
|
|
|
|
|
|
# Cabecera
|
|
RefHeader($Itemid);
|
|
|
|
# Contenido
|
|
|
|
switch ($op) {
|
|
case 'list': verListaTesoreria($idtrimestre, $idano);
|
|
break;
|
|
case 'opAnadirAno': anadirAno();
|
|
$returnlink = "index.php?option=$option&Itemid=$Itemid&idtrimestre=$idtrimestre&idano=$idano";
|
|
mosRedirect("$returnlink", "");
|
|
break;
|
|
case 'opAnadir': anadir($numentrada, $literal, $idtrimestre, $idano);
|
|
break;
|
|
case 'opEliminar' : eliminar($numentrada);
|
|
$returnlink = "index.php?option=$option&Itemid=$Itemid&idtrimestre=$idtrimestre&idano=$idano";
|
|
mosRedirect("$returnlink", "");
|
|
break;
|
|
case 'opGrabar': grabar ($catid, $fechaent, $descripcion, $cuantia);
|
|
$returnlink = "index.php?option=$option&Itemid=$Itemid&idtrimestre=$idtrimestre&idano=$idano";
|
|
mosRedirect("$returnlink", "");
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
# Footer
|
|
if ($obrens_verfooter == "1")
|
|
RefFooter($Tesoreria_version);
|
|
|
|
}
|
|
//No esta autorizado la session se ha terminado
|
|
else {
|
|
echo _NOT_AUTH;
|
|
echo "<br>";
|
|
echo _DO_LOGIN;
|
|
}
|
|
|
|
|
|
?>
|