<?php 
//session_start(); 
//$IDcField="IDPelati";
$prefix='pel_service@';
$MyADDFormName="service_add";;$w=1050;$h=580;
$MyIDFieldName="IDService";
$MyFormName=str_replace('.php', '', basename($_SERVER['PHP_SELF']));
$PeriodosGroupName=$prefix."cal_buttons";
$Periodos="week";

$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="";
 
if(!isset($_COOKIE[$SortFLD])) {$SortValue='';} else { $SortValue=$_COOKIE[$SortFLD];}

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];}
 
     $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>
		</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='r1 w40'>A/A</td>
	<td class="c1 w100">ΗΜΕΡΟΜΗΝΙΑ</td>
	<td class="l w120" >ΣΥΣΚΕΥΗ</td> 
    <td class="l w140" >MODEL</td> 
    <td>ΠΕΡΙΓΡΑΦΗ ΒΛΑΒΗΣ</td>
	<td class="c1 w100"> ΗΜ.ΕΠΙΣΚΕΥΗΣ </td>
	<td class="l"> ΠΕΡΙΓΡΑΦΗ ΕΡΓΑΣΙΩΝ </td>
	<td class=" w100"> ΧΡΕΩΣΗ </a></td>
  </tr> 
</table>
</div  >  

 <table class="gridListNoCaption"  > 
  
<?php
//$IDc = gConvertField($_COOKIE[$IDcField], '0');

     $flds="EidosSyskeyis,Model,PerigrafiVlavis,PerigrafiErgasion";
   $filter=filter_make($flds, $FindWhat1);
    $query=" SELECT * FROM service " . $filter ;
	if ($filter==""){$query.=" WHERE ";}else{$query.=" AND ";}
	 $query.=" IDPelati=". $IDPelati . " ORDER BY HmniaParalavis ";
 
//  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;
 
$IDService= gconvertfield($rs['IDService'],0);

$HmniaParalavis=formatMyDate($rs['HmniaParalavis'],"MySqlToGr");
$EidosSyskeyis=$rs['EidosSyskeyis'];
$Model=$rs['Model'];
$PerigrafiVlavis= $rs['PerigrafiVlavis'];
$HmniaEpiskeyis= formatMyDate($rs['HmniaEpiskeyis'],"MySqlToGr");  
$PerigrafiErgasion= $rs['PerigrafiErgasion'];

$Xreosi=$rs['Xreosi'];
$Xreosi=number_format($Xreosi, 2, ',', '.');
$frmOpen="'IDService','$IDService','$MyADDFormName'" ;
// ========================================
//  service List
// ========================================
 
//echo " =================" . $frmOpen;

//echo '<tr class="tablerowdata" onclick="javascript:OpenFormADD($frmOpen);"> '; 
  echo "<tr class='tablerowdata'  onclick='javascript:ServiceADD($IDService);'> ";
    echo "<td class='r1 w40' >$iRow</td>";
	echo "<td class='c1 w100'>$HmniaParalavis</td>";
    echo "<td class='w120'>$EidosSyskeyis</td>";
	echo "<td class='w140'>$Model</td>";
	echo "<td >$PerigrafiVlavis</td>";
    echo "<td class='c1 w100'>$HmniaEpiskeyis</td>";
    echo "<td >$PerigrafiErgasion</td>";
	echo "<td class='r1 w100'>$Xreosi</td>";
    echo "</tr>";
 } 
 for ($x = $iRow+1; $x <= $pgNo*$RecsPP; $x++) {
    echo "<tr class='tablerowdata'  onclick='javascript:ServiceADD(0);'> ";
    echo "<td class='w40'> </td> <td class='w100'> </td> <td class='w120'> </td>"; 
	echo " <td class='w140'> </td> <td> </td> ";
	echo "<td class='hide1 w100'> </td><td  > </td>";
    echo " <td class='w100'> </td> ";
    echo "</tr>";
 }	
 ?> 

</table>

<?php 

include ('include/recs_div_bottom.php');
?>
</div>

<script>
function ServiceADD(IDc){
 document.cookie = 'IDService=' + IDc;
 var w=850;var h=600; 
 var oPenFrm = "service_add.php" ; // ?IDc="+IDc;
 var NewWindow = window.open( oPenFrm, "_self"  ); 
    NewWindow.moveTo(0,0);
    NewWindow.resizeTo(screen.width,screen.height);   
   NewWindow.focus();
}
</script>