Dunque sono riuscito ad andare avanti in questo modo. Funziona tutto benissimo ora. Ho solo il problema dell'ordine delle funzioni, l'azione 3 (minuti di inattività) deve essere sempre compresa tra lo start (1) e lo stop (4). Come si riesce a fare questo tipo di controllo? Di seguito il codice, che nonostante tutto, sporco, brutto e incasinato, funziona!
$RsSql=$oConn->Query($strSql);
if ($oConn->RecordCount>0)
$nRec = $oConn->RecordCount;
else
$nRec = 0;
$operatore1 = "";
$ora1 = "";
$data1 = "";
$operatore0 = "";
$ora0 = "";
$data0 = "";
//echo $RsSql['datafunk'];
while(!$oConn->EOF) {
//echo $RsSql['idoperatore'];
//echo $RsSql['datafunk'];
//VERIFICO SE CI SONO OVERTIME
if (( $RsSql['idgruppolavorazione'] == 66) && isset($RsSql['azione'] == 1)){
$datafunk1 = $RsSql['datafunk'];
$overtime = "";
$dataOT = date('Y-m-d', strtotime($RsSql['datafunk']));
//$dataOT = substr($RsSql['datafunk'],0,11);
$dataOT = str_replace("-","",$dataOT);
$strSqlOT = " SELECT isnull (sum(overtime),0) as overtime
from lst_activitiLog l
inner join lst_activitiMachine m on l.IpPc=m.Ip
where m.Operatore = '".$RsSql['idoperatore']."' and overtime is not null
and convert(varchar,l.datalog, 112) = '".$dataOT."' ";
$RsSqlOT=$oConnOT->Query($strSqlOT);
if ($oConnOT->RecordCount>0){
while($oConnOT->EOF) {
$overtime = $RsSqlOT['overtime'];
$RsSqlOT=$oConnOT->MoveNext();
}
}
//echo $RsSqlOT['overtime'] ;
}
if (( $RsSql['idgruppolavorazione'] == 79) && ($RsSql['azione'] == 1)){
$datafunk1 = $RsSql['datafunk'];
$overtime = "";
$dataOT = date('Y-m-d', strtotime($RsSql['datafunk']));
//$dataOT = substr($RsSql['datafunk'],0,11);
$dataOT = str_replace("-","",$dataOT);
$strSqlOT = " SELECT isnull (sum(overtime),0) as overtime
from lst_activitiLog l
inner join lst_activitiMachine m on l.IpPc=m.Ip
where m.Operatore = '".$RsSql['idoperatore']."' and overtime is not null
and convert(varchar,l.datalog, 112) = '".$dataOT."' ";
$RsSqlOT=$oConnOT->Query($strSqlOT);
if ($oConnOT->RecordCount>0){
while($oConnOT->EOF) {
$overtime = $RsSqlOT['overtime'];
$RsSqlOT=$oConnOT->MoveNext();
}
}
//echo $RsSqlOT['overtime'] ;
}
$azione = $RsSql['azione'];
$datafunk = "";
$data = $RsSql['Data'];
$cellaora = "";
$operatore1 = $RsSql['nome'];
$descrizione = $RsSql['Descrizione'];
/*if($azione==1)
{
$datafunk1 = $RsSql['datafunk'];
$overtime = "";*/
//}
if ($azione == 4){
$descrizione = "Ore Lavorate";
$datafunk = $RsSql['datafunk'];
}
/*elseif($azione==3)
{
$overtime += $RsSql['overtime'];
//$RsSql['Overtime']
}*/
if (($operatore1 == $operatore0) && ($data1 == $data0) && ($azione == 4) ) {
//$stop = $datafunk;
$lavorato = abs(strtotime($datafunk) - strtotime($datafunk1));
$minutes = floor($lavorato / 60);
if ( $RsSql['idgruppolavorazione'] == 66) {
$cellaora = $minutes - $RsSqlOT['overtime'];
}
else
{
$cellaora = $minutes;
}
$cellaora = substr(($cellaora / 60),0,4);
$StrDati.=" <tr>";
$StrDati.=" <td>".$RsSql['nome']."</td>
<td>".$data."</td>
<td>".$descrizione."</td>
<td>".$cellaora."</td>
</tr>";
}
$i++;
$operatore0 = $RsSql['nome'];
//$data0 = substr($RsSql['Data'], 0 , 10);
//echo $cellaora;
$tot += $cellaora;
$RsSql=$oConn->MoveNext();
}