<?php

##################################################################################
#    PHP-RESIDENCE
#    Copyright (C) 2001-2009 by Marco Maria Francesco De Santis (marco@digitaldruid.net)
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    any later version accepted by Marco Maria Francesco De Santis, which
#    shall act as a proxy as defined in Section 14 of version 3 of the
#    license.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
##################################################################################




function dati_tariffe ($tablenometariffe,$tariffa_sel="") {

$righe_tariffe = esegui_query("select * from $tablenometariffe where idntariffe < '5' order by idntariffe");
$dati_tariffe['num'] = risul_query($righe_tariffe,0,'nomecostoagg');

for ($num1 = 1 ; $num1 <= $dati_tariffe['num'] ; $num1++) {
if (!$tariffa_sel or $tariffa_sel == $num1) {
$dati_tariffe['tariffa'.$num1]['nome'] = risul_query($righe_tariffe,0,'tariffa'.$num1);
$dati_tariffe['tariffa'.$num1]['caparra_percent'] = risul_query($righe_tariffe,1,'tariffa'.$num1);
$dati_tariffe['tariffa'.$num1]['caparra_arrotond'] = risul_query($righe_tariffe,2,'tariffa'.$num1);
$dati_tariffe['tariffa'.$num1]['moltiplica'] = risul_query($righe_tariffe,3,'tariffa'.$num1);
} # fine (!$tariffa_sel or $tariffa_sel == $num1)
} # fine for $num1

return $dati_tariffe;

} # fine function dati_tariffe



function trova_app_regola2 ($tipotariffa,&$regole2,&$num_regole2,&$app_regola2_predef,&$id_periodo_corrente,$idinizioperiodo,$idfineperiodo,$tipo_periodi,$anno,$tableregole) {

$app_regola2_predef = "";
if (!$regole2) {
$regole2 = esegui_query("select * from $tableregole where tariffa_per_app != ''");
$num_regole2 = numlin_query($regole2);
} # fine if (!$regole2)

for ($num1 = 0 ; $num1 < $num_regole2 ; $num1 = $num1 + 1) {
$tariffa_regola2 = risul_query($regole2,$num1,'tariffa_per_app');
if ($tipotariffa == $tariffa_regola2) {
$lista_app = risul_query($regole2,$num1,'motivazione');
$lista_appb = risul_query($regole2,$num1,'motivazione2');
if (strcmp($lista_appb,"")) {
if (!$id_periodo_corrente) $id_periodo_corrente = calcola_id_periodo_corrente($anno);
$ngiorni_reg2b = risul_query($regole2,$num1,'iddatainizio');
if ($ngiorni_reg2b) $diff_giorni = $idinizioperiodo - $id_periodo_corrente + 1;
else {
$ngiorni_reg2b = risul_query($regole2,$num1,'iddatafine');
$diff_giorni = $idfineperiodo - $id_periodo_corrente + 1;
} # fine else if ($ngiorni_reg2b)
if ($tipo_periodi == "s") $diff_giorni = $diff_giorni * 7;
if ($diff_giorni < $ngiorni_reg2b) {
$app_regola2_predef = $lista_app;
$lista_app = $lista_appb;
} # fine if ($diff_giorni < $ngiorni_reg2b)
} # fine if (strcmp($lista_appb,""))
break;
} # fine if ($tipotariffa == $tariffa_regola2)
} # fine for $num1

return $lista_app;

} # fine function trova_app_regola2




?>