<?php
/*******************************************************************************
* filename : agdet_u.php
* last change : 2006 - 11 - 20
*
* http://www.avesan.it/
* Copyright 2006 Alberto Santoro
*
* PMbyAS is free software; you can redistribute it and/or modify
* it under the terms of the GNU General public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
******************************************************************************/
$pgm="agdet_u.php";
// --------------- connessione
require_once "./_fcom/fconn.php";
// --------------- sessione
require_once "./_fcom/fsess.php";
// --------------- dati di sessione
require_once "./_fcom/fperiodo.php";
// inclusione edit ore/minuti
require_once "./_fcom/ed_hh_mm.php";
// -------------------------------- parametri di lavoro
$vs = substr($_REQUEST['opt'],0,1);
$tm = substr($_REQUEST['opt'],1,1);
$wka = explode("-",$_REQUEST['opt']);
$rsu = $wka[1];
$job = $wka[2];
$tlv = $wka[3];
$pgm="agdet_u.php?opt=".$vs.$tm."-".$rsu."-".$job."-".$tlv;
// --------------- Dati Risorsa
$query = "SELECT * FROM pge_ru WHERE RsuCod = \"$rsu\" ";
$rsok = mysqli_query($connessione,$query) or die("Query rsu fallita");
$rgu = mysqli_fetch_assoc($rsok);
// --------------- dati programma (se richiesto)
$pmdex = "";
if ($job > "") {
$query = "SELECT * FROM prog WHERE PgmCod = \"$job\" ";
$rsok = mysqli_query($connessione,$query) or die("Query programma fallita");
$rgp = mysqli_fetch_assoc($rsok);
$pmdex = "programma: {$rgp[PgmCod]} · {$rgp[PgmDex]}";}
// --------------- dati tipo lavoro (se richiesto)
if ($tlv > "") {
$query = "SELECT * FROM tb_lav WHERE LvCod = \"$tlv\" ";
$rsok = mysqli_query($connessione,$query) or die("Query tlv fallita");
$rgl = mysqli_fetch_assoc($rsok);
$pmdex = "tipo attv: {$rgl[LvCod]} · {$rgl[LvDex]}";}
// ====================================== versione video / stampa
if ($tm <> "P") $tsex = "del periodo"; else $tsex = "del mese";
// --- versione video
if ($tm <> "P") {
require_once "./_fcom/doctype.php"; // --- testata html video
require_once "./_fcom/nav.php"; // --- barra di navigazione
$tsfun="Dettaglio risorsa $tsex";
$tsdt2=" ";
$tsextra = "Risorsa: {$rgu[RsuCod]} · {$rgu[RsuDex]} $pmdex";
if ($vs == "P")
{$tsprint = "agdet_u.php?opt=PP"."-".$rsu."-".$job."-".$tlv;
require_once "./_fcom/tstper.php";
require_once "./_fcom/tstdxgen.php"; }
else {$tsprint = "agdet_u.php?opt=MP"."-".$rsu."-".$job."-".$tlv;
require_once "./_fcom/tstmese.php";
require_once "./_fcom/tstdxgen.php"; }
}
// --- versione stampa
else {require_once "./_fcom/doctype_p.php"; // --- testata html stampa
if ($vs == "P") {require_once "./_fcom/pr_perdx.php";}
else {require_once "./_fcom/pr_medx.php";}
$rptitle="Risorsa: {$rgu[RsuCod]} · {$rgu[RsuDex]} $pmdex";
$len = 939;
$rptdex= $pr_inizio." - ".$pr_fine;
if ($fal == "X") $rptdex = "fino al ".$pr_fine;
require_once "./_fcom/rptesta.php";
}
// ------------------------------------------------------------------
// ------------------------ testata finestra video
print "\n<div class=\"cpnn\">";
print "\n<table ><thead><tr>";
print "\n<th width=\"836\" > </th>";
print "\n<th width=\"70\" > </th>";
// --- corpo scrollabile
print "\n<th width=\"20\"> </th>";
print "\n</tr></thead>";
print "\n<tbody><tr><td colspan=\"3\"><div class=\"win478\"><table class=\"tbover\">";
// ============================================= estrazione da time report
if ($job > "") {
$query = "SELECT * FROM time_report
WHERE GtmRsu = \"$rsu\"
and GtmPgm = \"$job\"
and GtmDay >= \"$SEDTI\"
and GtmDay <= \"$SEDTF\"
and GtmStato <> \"A\"
ORDER by GtmDay ";}
else {
if ($tlv > "") {
$query = "SELECT * FROM time_report
WHERE GtmRsu = \"$rsu\"
and GtmTpo = \"$tlv\"
and GtmDay >= \"$SEDTI\"
and GtmDay <= \"$SEDTF\"
and GtmStato <> \"A\"
ORDER by GtmDay ";}
else {
$query = "SELECT * FROM time_report
WHERE GtmRsu = \"$rsu\"
and GtmDay >= \"$SEDTI\"
and GtmDay <= \"$SEDTF\"
and GtmStato <> \"A\"
ORDER by GtmDay ";}}
$rsns = mysqli_query($connessione,$query) or die("Query tm fallita");
print "\n<br class=\"br-mezzo\"><span class=\"bold7\">Dettaglio Costo Lavoro</span>";
$nrec = mysqli_num_rows($rsns);
if ($nrec == 0) {print "\n<br /><div class=\"pd8c\">Nessuna registrazione</div>";}
else $totval = write_lavoro($rsns,$tipo,$connessione);
//$totval = write_lavoro($rsns,$tipo,$connessione);
// =============================================== estrazione da nota spese
if ($job > "") {
$query = "SELECT * FROM nota_spese
WHERE GspRsu = \"$rsu\"
and GspPgm = \"$job\"
and GspDay >= \"$SEDTI\"
and GspDay <= \"$SEDTF\"
and GspStato <> \"A\"
ORDER by GspDay ";}
else {
if ($tlv > "") {
$query = "SELECT * FROM nota_spese
WHERE GspRsu = \"$rsu\"
and GspTpo = \"$tlv\"
and GspDay >= \"$SEDTI\"
and GspDay <= \"$SEDTF\"
and GspStato <> \"A\"
ORDER by GspDay ";}
else {
$query = "SELECT * FROM nota_spese
WHERE GspRsu = \"$rsu\"
and GspDay >= \"$SEDTI\"
and GspDay <= \"$SEDTF\"
and GspStato <> \"A\"
ORDER by GspDay ";}}
$rsns = mysqli_query($connessione,$query) or die("Query ns fallita");
print "\n<br class=\"br-mezzo\"><span class=\"bold7\">Dettaglio Spese</span>";
$nrec = mysqli_num_rows($rsns);
if ($nrec == 0) {print "\n<br /><div class=\"pd8c\">Nessuna registrazione</div>";}
else $totspe = write_spese($rsns,$tipo,$connessione);
//$totspe = write_spese($rsns,$tipo,$connessione);
// ----------------------- totale generale
$totgen = $totspe + $totval;
if ($totgen > 0 and $totgen > $totspe and $totgen > $totval) {
$ev = number_format($totgen, 2, ',', '.');
print "<br /><table width=\"900\" class=\"tbnb\">";
print "\n<tr>";
print "\n<td width=\"755\" class=\"c7dg\">Totale generale</td>";
print "\n<td class=\"c8dg\">$ev</td>";
print "</tr></table>";}
// --------------------------------------------- Fine tabella
print "\n</div></td></tr></tbody>"; // --- chiusura corpo tabella
// --------------------- piede tabella
print "\n<tfoot><tr>";
print "\n<td> </td>";
// ---------------------------------
print "\n</tr></tfoot></table</div>";
// -------------------------------- chiusura corpo pagina video
if ($tm <> "P") print "\n</div>";
// ===============================================================================
// ---------------- funzione di stampa righe tavola spese
function write_spese($rsns,$tipo,$connessione )
{
print "<br class=\"br-mezzo\"><table width=\"900\" class=\"tbover\">";
print "\n<tr>";
print "\n<th class=\"t8c\" width=\"50\">data</th>";
print "\n<th class=\"t8d\" width=\"30\">nreg</th>";
print "\n<th class=\"t8d\" width=\"20\">riga</th>";
print "\n<th class=\"t8s\" width=\"90\">programma</th>";
print "\n<th class=\"t8s\" width=\"40\">atv</th>";
print "\n<th class=\"t8s\" width=\"100\">voce spesa</th>";
print "\n<th class=\"t8s\" width=\"200\">descrizione </th>";
print "\n<th class=\"t8s\" width=\"104\">modo pag</th>";
print "\n<th class=\"t8d\" width=\"65\">spesa</th>";
print "\n</tr>";
$totspe = 0;
while ($rg = mysqli_fetch_assoc($rsns)) {
$query = "SELECT * FROM tb_mod_pag WHERE MpCod = \"{$rg["GspMPag"]}\" ";
$rsok = mysqli_query($connessione,$query) or die("Query fallita");
$rgm = mysqli_fetch_assoc($rsok);
$vsp = $rg["GspVsp"];
$query = "SELECT RsaCod as VspCod, RsaDex as VspDex, RsaPk, RsaTpo FROM pge_rsa
WHERE RsaPk = \"BS\" AND RsaTpo = \"S\" AND RsaCod = \"$vsp\" ";
$rsv = mysqli_query($connessione,$query) or die("Query vsp fallita");
$rv = mysqli_fetch_assoc($rsv);
$spdata = substr($rg["GspDay"],8,2).".".substr($rg["GspDay"],5,2).".".substr($rg["GspDay"],2,2);
print "\n<tr>";
print "\n<td class=\"c8c\">$spdata</td>";
print "\n<td class=\"c8d\">{$rg["GspNum"]}</td>";
print "\n<td class=\"c8n\">{$rg["GspRiga"]}</td>";
print "\n<td class=\"c8s\">{$rg["GspPgm"]}</td>";
print "\n<td class=\"c8s\">{$rg["GspAtv"]}</td>";
print "\n<td class=\"c8s\">{$rv["VspDex"]}</td>";
print "\n<td class=\"c8s\">{$rg["GspDex"]}</td>";
print "\n<td class=\"c8s\">{$rgm["MpDex"]}</td>";
print "\n<td class=\"c8d\">{$rg["GspVal"]}</td>";
print "\n</tr>";
$totspe = $totspe + $rg["GspVal"];
}
$ev = number_format($totspe, 2, ',', '.');
print "\n<tr><td colspan=\"8\" class=\"c7dg\">totale spese</td>";
print "\n<td class=\"c8dg\">$ev</td></tr></table>";
return $totspe;
}
// ========================================================
// ------------------- funzione di stampa righe lavoro
function write_lavoro($rsns,$tipo,$connessione)
{
print "<br class=\"br-mezzo\"><table width=\"900\" class=\"tbover\">";
print "\n<tr>";
print "\n<th class=\"t8c\" width=\"50\">data</th>";
print "\n<th class=\"t8d\" width=\"30\">nreg</th>";
print "\n<th class=\"t8d\" width=\"20\">riga</th>";
print "\n<th class=\"t8s\" width=\"270\">programma</th>";
print "\n<th class=\"t8s\" width=\"270\">attività </th>";
print "\n<th class=\"t8d\" width=\"50\">ore</th>";
print "\n<th class=\"t8d\" width=\"70\">costo</th>";
print "\n</tr>";
$totval = 0; $tore = 0;
while ($rg = mysqli_fetch_assoc($rsns)) {
$query = "SELECT * FROM prog WHERE PgmCod = \"{$rg["GtmPgm"]}\" ";
$rsok = mysqli_query($connessione,$query) or die("Query fallita");
$rgp = mysqli_fetch_assoc($rsok);
$query = "SELECT * FROM tb_attv WHERE AtCod = \"{$rg["GtmAtv"]}\" ";
$rsok = mysqli_query($connessione,$query) or die("Query fallita");
$rga = mysqli_fetch_assoc($rsok);
$tmdata = substr($rg["GtmDay"],8,2).".".
substr($rg["GtmDay"],5,2).".".
substr($rg["GtmDay"],2,2);
print "\n<tr>";
print "\n<td class=\"c8c\">$tmdata</td>";
print "\n<td class=\"c8d\">{$rg["GtmNum"]}</td>";
print "\n<td class=\"c8n\">{$rg["GtmRiga"]}</td>";
print "\n<td class=\"c8s\">{$rg["GtmPgm"]}·{$rgp["PgmDex"]}</td>";
print "\n<td class=\"c8s\">{$rg["GtmAtv"]}·{$rga["AtDex"]}</td>";
$whm = ed_ore_minuti($rg["GtmLav"]);
print "\n<td class=\"c8d\">{$whm[4]}</td>";
print "\n<td class=\"c8d\">{$rg["GtmVLav"]}</td>";
print "\n</tr>";
$totval = $totval + $rg["GtmVLav"];
$tmin = $tmin + $rg["GtmLav"];
}
$whm = ed_ore_minuti($tmin);
$ev = number_format($totval, 2, ',', '.');
print "\n<tr><td colspan=\"5\" class=\"c7dg\">totali lavoro</td>";
print "\n<td class=\"c8dg\">{$whm[4]}</td>";
print "\n<td class=\"c8dg\">$ev</td>";
print "</tr></table>";
return $totval;
}
?>
</body>
</html>