if ($_POST['id']==0)
{
$sql = mysql_query("TRUNCATE temp_kilometry");
$pobierz_userow=mysql_query("select id,imie,nazwisko from uzytkownicy where usun='0' and id_sta='3' and usun='0' and blok='NIE' group by nazwisko");
while($u=mysql_fetch_array($pobierz_userow))
{
$id_user = $u[id];
$nazwisko = $u[nazwisko];
$imie = $u[imie];
$temp = mysql_query("INSERT INTO `temp_kilometry` ( `temp1` , `temp2` , `temp3` , `temp4` , `temp5` , `temp6` )
VALUES (
'$id_user', '$nazwisko', '$imie', '0', '0', '0'
)");
}
$pobierz_userow2=mysql_query("select b.temp1 as id,sum(a.przejechano) as kilometry from kilometry a,temp_kilometry b where a.id=b.temp1 and a.usun='0' and a.wyjazd='0' and a.data_kil >= '".$_POST['data1']."' and a.data_kil <= '".$_POST['data2']."' group by b.temp2");
while($z=mysql_fetch_array($pobierz_userow2))
{
$id1 = $z[id];
$sluzbowe = $z[kilometry];
$temp = mysql_query("update temp_kilometry SET temp4='".$sluzbowe."' where temp1='".$id1."'");
$sluzbowe = '0';
}
$pobierz_userow3=mysql_query("select b.temp1 as id,sum(a.przejechano) as kilometry from kilometry a,temp_kilometry b where a.id=b.temp1 and a.usun='0' and a.wyjazd='1' and a.data_kil >= '".$_POST['data1']."' and a.data_kil <= '".$_POST['data2']."' group by b.temp2");
while($y=mysql_fetch_array($pobierz_userow3))
{
$id2 = $y[id];
$sluzbowe2 = $y[kilometry];
$temp = mysql_query("update temp_kilometry SET temp5='".$sluzbowe2."' where temp1='".$id2."'");
$sluzbowe = '0';
}
$pobierz_userow4=mysql_query("select b.temp1 as id,sum(a.przejechano) as kilometry from kilometry a,temp_kilometry b where a.id=b.temp1 and a.usun='0' and a.data_kil >= '".$_POST['data1']."' and a.data_kil <= '".$_POST['data2']."' group by b.temp2");
while($x=mysql_fetch_array($pobierz_userow4))
{
$id3 = $x[id];
$sluzbowe3 = $x[kilometry];
$temp = mysql_query("update temp_kilometry SET temp6='".$sluzbowe3."' where temp1='".$id3."'");
$sluzbowe = '0';
}
$pobierz_userow5=mysql_query("select * from temp_kilometry group by temp2");
$data1 = $_POST['data1'];
$data2 = $_POST['data2'];
if(mysql_num_rows($pobierz_userow)==0)
{
uwaga('
Nie określono zakresu dat - spróbuj ponownie...
|
');
form_zestawienie_km();
}
else
{
$color=$color1;
echo ' Zestawienie kilometrow od '.$data1.' do '.$data2.'
|
';
echo '| Imie Nazwisko | Służobowe | Prywatne | Suma |
';
while($a=mysql_fetch_array($pobierz_userow5))
{
$roznica = ($z['kilometry'] - $u['kilometry']);
$color=zmien_color($color);
echo '| '.$a['temp2'].' '.$a['temp3'].' | '.$a['temp4'].' km | '.$a['temp5'].' km | '.$a['temp6'].' km |
' ;
$nazwisko = $a[temp2];
$imie = $a[temp3];
$sluzbowe = $a[temp4];
$prywatne = $a[temp5];
$suma = $a[temp6];
$sql2 = mysql_query("INSERT INTO `temp` ( `temp1` , `temp2` , `temp3` , `temp4` , `temp5` , `temp6` , `trmp7` , `tmp8` )
VALUES (
'$nazwisko', '$imie', '$sluzbowe', '$prywatne', '$suma', '', '', ''
)");
}
echo '
';
echo '
';
}
}
else
{
$pobierz_userow3=mysql_query("select b.id,b.imie,b.nazwisko,sum(a.przejechano) as kilometry from kilometry a,uzytkownicy b where a.id=b.id and a.usun='0' and a.wyjazd='0' and a.data_kil >= '".$_POST['data1']."' and a.data_kil <= '".$_POST['data2']."' and b.id='".$_POST['id']."'");
$pobierz_userow4=mysql_query("select b.id,b.imie,b.nazwisko,sum(a.przejechano) as kilometry from kilometry a,uzytkownicy b where a.id=b.id and a.usun='0' and a.data_kil >= '".$_POST['data1']."' and a.data_kil <= '".$_POST['data2']."' and b.id='".$_POST['id']."'");
$data1 = $_POST['data1'];
$data2 = $_POST['data2'];
if(mysql_num_rows($pobierz_userow3)==0)
{
uwaga(' Nie określono zakresu dat - spróbuj ponownie...
|
');
form_zestawienie_km();
}
else
{
$sql = mysql_query("TRUNCATE temp");
$color=$color1;
echo ' Zestawienie kilometrow od '.$data1.' do '.$data2.'
|
';
echo '| Imie Nazwisko | Służobowe | Prywatne | Suma |
';
while($x=mysql_fetch_array($pobierz_userow3) and $y=mysql_fetch_array($pobierz_userow4))
{
$roznica = ($y['kilometry'] - $x['kilometry']);
$s1 = $x['kilometry'];
if ($s1=='')
$s2 = "0";
else
$s2 = $s1;
$s3 = $y['kilometry'];
if ($s3=='')
$s4 = "0";
else
$s4 = $s3;
$color=zmien_color($color);
echo '| '.$x['nazwisko'].' '.$x['imie'].' | '.$s2.' km | '.$roznica.' km | '.$s4.' km |
' ;
$nazwisko = $x[nazwisko];
$imie = $x[imie];
if ($x['kilometry']=='')
$sluzbowe = '0';
else
$sluzbowe = $x['kilometry'];
$prywatne = $roznica;
$suma = $y['kilometry'];
$sql2 = mysql_query("INSERT INTO `temp` ( `temp1` , `temp2` , `temp3` , `temp4` , `temp5` , `temp6` , `trmp7` , `tmp8` )
VALUES (
'$nazwisko', '$imie', '$sluzbowe', '$prywatne', '$suma', '', '', ''
)");
}
echo '
';
echo '
';
}
}
?>