<?php 
//session_start(); 
//$IDcField="IDPelati";
$prefix='pel_kiniseis@';
$FindWhatCookieName=$prefix.'FindWhat';
$pFind=$FindWhatCookieName;

$period_type_name=$prefix."period_type";
$period_type="week";
$RecsPP_fld=$prefix.'cboRecPP';
$HmApo_c_name=$prefix.'HmApo';
$HmEos_c_name=$prefix.'HmEos'; 

$SortFLD=$prefix.'srt';
$SortValue="Hmerominia";
$show_all_fld=$prefix.'ShowAll';
$show_all_value="checked";
 
if(!isset($_COOKIE[$SortFLD])) {$SortValue='';} else { $SortValue=$_COOKIE[$SortFLD];}
if(!isset($_COOKIE[$show_all_fld]) ) {$show_all_value="checked";} else { $show_all_value=$_COOKIE[$show_all_fld];} 
 
if(!isset($_COOKIE[$RecsPP_fld])) {$RecsPP=10;} else { $RecsPP=$_COOKIE[$RecsPP_fld];}
if(!isset($_COOKIE[$HmApo_c_name])) {$HmApo= date_create('now')->format('d/m/Y');} else { $HmApo=$_COOKIE[$HmApo_c_name];} 
if(!isset($_COOKIE[$HmEos_c_name])) {$HmEos=date_create('now')->format('d/m/Y'); } else { $HmEos=$_COOKIE[$HmEos_c_name];}
if(!isset($_COOKIE[$period_type_name])) {$period_type='week'; } else { $period_type=$_COOKIE[$period_type_name];}
if(!isset($_COOKIE[$FindWhatCookieName])) {$FindWhat1=''; } else { $FindWhat1=$_COOKIE[$FindWhatCookieName];}
 
#$FindWhat1 = trim(filter_input(INPUT_GET, $prefix.'FindWhat', FILTER_SANITIZE_SPECIAL_CHARS));
     $pgNo = trim(filter_input(INPUT_GET, $prefix.'pgNo', FILTER_SANITIZE_SPECIAL_CHARS));
 	  if(!is_numeric($pgNo)) { $pgNo=1;} 
 
?> 

	<table border="0" width="100%" class="hideOnPrint " style="padding: 0px 0px 5px 5px;margin-top:-15px;" > 
		<tr height="32px" style="valign:center;" >
			<td  style="width:300px;padding-right:4px;marging-right:5px; "  >	
			  <a href="javascript:OpenFormADD(0);;" class="button new">Νέα Εγγραφή</a>
			  <a href="javascript:refresh('<?php echo $prefix ?>');" class="button refresh">Ανανέωση</a>
			  <a href="javascript:window.print();" title=" Εκτύπωση Κατάστασης " class="button print">Εκτύπωση</a>
			</td>
			<td>
             		<?php HmGroupButtons($prefix, $period_type, $HmApo, $HmEos);?>
			</td>
			<td
				<div id="chk_container" style="margin-left:5px; ">
					<input type="checkbox" name="check" checked>
					<label for="check"><div></div></label>
				</div>
			</td>
 
 
			</td>
			<td width="25%">
	<?php 
		echo "<div class='search_container' style='float:left;width:96%;margin:-5px 15px -10px 16px;text-align:left;'>"."\n"; 
		echo "<form class='nosubmit' >"."\n"; 
		echo "<input class='nosubmit' type='search' name='$pFind' id='$pFind' placeholder='Αναζήτηση...' value='$FindWhat1' onfocus='gotoEndOfText(this);' onclick='submitForm(\"$prefix\");'>"."\n"; 
		echo "<button type='submit' hidden >Search</button>"."\n"; 
		echo "</form>"."\n";
		echo "</div>"."\n"; 
	?>
			</td>
		</tr>	  
	</table>

<div class="scroll" style="height:50vh;margin-bottom:0px;padding-bottom:0px;width:100%;shadow:none;" >
<div class="sticky">
  <table id="CustomerList" class="gridList"  > 
   <tr  >
	<td class='r w40  hide1'>A/A</td>
	<td class="c w100">ΗΜΕΡΟΜΗΝΙΑ</td>
	<td class="c w100  hide1" >ΑΡ.ΠΑΡΑΣΤ.</td> 
    <td>ΑΙΤΙΟΛΟΓΙΑ</td>
	<td class="c w100 hide1"> ΚΑΘ.ΑΞΙΑ </td>
	<td class="c w100 hide1"> ΦΠΑ </td>
	<td class="w100 hide1"> ΧΡΕΩΣΗ </a></td>
	<td class="w100 hide1"> ΠΙΣΤΩΣΗ </a></td>
	<td class="w100 hide1"> ΥΠΟΛΟΙΠΟ </a></td>
  </tr> 
</table>
</div  >  

 <table class="gridListNoCaption"  > 
  
<?php
$sXreosiXorisFPA=0;
$sFPAXreosis=0;
$sXreosi=0;
$sPistosi=0;
$sYpoloipo=0;
 
 $start_date=formatMyDate($HmApo,"GrToMySql"); 
  $end_date=formatMyDate($HmEos,"GrToMySql"); 
  
     $flds="Aitiologia, Xreosi";
   $filter=filter_make($flds, $FindWhat1);
   $filter=str_replace("WHERE","AND", $filter);
    $query="SELECT * FROM pelates_kiniseis WHERE IDPelati=".$IDPelati." ".$filter." " ;
	
	if ($show_all_value!=="checked" ){
		if($filter==""||$filter==null) {
			$query=$query ." AND Hmerominia BETWEEN '" . $start_date . "' AND '" . $end_date . "' "; }
		}
  if($SortValue==''){$query=$query ." ORDER BY Hmerominia asc ";} else {$query=$query." ORDER BY " . $SortValue . " ";}
   
//  echo "<br>". $query."<br>";

  $num_rows=RecordsCount($conn,$query);
   $FromRec=($pgNo-1)*$RecsPP ;
     $pgMax=intval($num_rows/$RecsPP)+1;
   $query = $query .  ' LIMIT ' .$FromRec . ', ' . $RecsPP ;
   $result = mysqli_query($conn, $query);
 
$iRow=$FromRec;

 while ($rs = mysqli_fetch_array($result)) {
$iRow +=1;
 
//$IDPelati= $rs['IDPelati'];
$Hmerominia=formatMyDate($rs['Hmerominia'],"MySqlToGr");
$AATimologiou=$rs['AATimologiou'];
$Aitiologia= $rs['Aitiologia'];
$XreosiXorisFPA=$rs['XreosiXorisFPA'];
$FPAXreosis=$rs['FPAXreosis'];
$Xreosi=$rs['Xreosi'];
$Pistosi=$rs['Pistosi'];
$Ypoloipo=$rs['Ypoloipo'];

$sXreosiXorisFPA+=$XreosiXorisFPA;
$sFPAXreosis+=$FPAXreosis;
$sXreosi+=$Xreosi;
$sPistosi+=$Pistosi;
$sYpoloipo=$sXreosi-$sPistosi;

$XreosiXorisFPA=number_format($XreosiXorisFPA, 2, ',', '.');
$FPAXreosis=number_format($FPAXreosis, 2, ',', '.');
$Xreosi=number_format($Xreosi, 2, ',', '.');
$Pistosi=number_format($Pistosi, 2, ',', '.');
$Ypoloipo=number_format($Ypoloipo, 2, ',', '.'); 
// ========================================
//  Pelates List
// ========================================
    echo "<tr class='tablerowdata'  onclick='javascript:OpenFormADD($IDPelati);'> ";
    echo "<td class='r w40 hide1' >$iRow</td>";
	echo "<td class='c w100'>$Hmerominia</td>";
    echo "<td class='c w100 hide1'>$AATimologiou</td>";
	echo "<td class='l'>$Aitiologia</td>";
    echo "<td class='r w100 hide1'>$XreosiXorisFPA</td>";
    echo "<td class='r w100 hide1'>$FPAXreosis</td>";
	echo "<td class='r w100 hide1'>$Xreosi</td>";
	echo "<td class='r w100 hide1'>$Pistosi</td>";
	echo "<td class='r w100 hide1'>$Ypoloipo</td>";
    echo "</tr>";
 } 
for ($x = $iRow+1; $x <= $pgNo*$RecsPP; $x++) {
    echo "<tr class='tablerowdata'  onclick='javascript:OpenFormADD(0);'> ";
    echo "<td class='w40 hide1'> </td> <td class='w100'> </td> <td class='w100 hide1'> </td>"; 
 	 echo "<td> </td> ";
 	 echo "<td class='hide1 w100'> </td><td class='hide1 w100'> </td>";
    echo " <td class='w100 hide1'> </td> <td class='w100 hide1'> </td> <td class='w100 hide1'> </td>";
    echo "</tr>";
 }	
 
	$sXreosiXorisFPA=number_format($sXreosiXorisFPA, 2, ',', '.'); 
	$sFPAXreosis=number_format($sFPAXreosis, 2, ',', '.'); 
	$sXreosi=number_format($sXreosi, 2, ',', '.'); 
	$sPistosi=number_format($sPistosi, 2, ',', '.'); 
	$sYpoloipo=number_format($sYpoloipo, 2, ',', '.');  
 ?> 

</table>
 

<div class="sticky_bottom">

<?php 
	echo '<table class="gridListFooter" style="margin-left:-2px;" border="0"  cellspacing="0" cellpadding="0" align="center" valign="bottom">';
	echo '<tr>';
	echo "<td class='r1 w40' > </td>";
	echo "<td class='c1 w100'> </td>";
	echo "<td class='c1 w100'> </td>";
	echo "<td class='l1'> ΣΥΝΟΛΑ </td>";
	echo "<td class='r hide1 w100'>$sXreosiXorisFPA</td>";
	echo "<td class='r hide1 w100'>$sFPAXreosis</td>";
	echo "<td class='r w100'>$sXreosi</td>";
	echo "<td class='r w100'>$sPistosi</td>";
	echo "<td class='r w100'>$sYpoloipo</td>";
	echo '</tr>';
	echo '</table>';
?>	
 


<?php 
$myTopBorder=1;
include ('include/recs_div_bottom.php');
?>
</div>
</div>
 

 