<?php 
session_start();
 
if($_SESSION['CheckPWD']==false){ header("Location: login.php"); }
$myTopCaption_Text="ΔΙΑΧΕΙΡΙΣΗ ΑΠΟΘΕΜΑΤΙΚΟΥ © 2020";
$MyFormName=str_replace('.php', '', basename($_SERVER['PHP_SELF']));
$MyADDFormName="tameio_apothematiko_add";$w=850;$h=465;
$MyIDFieldName="IDApothematikou";
$tblName='tameio_apothematiko';
$FocusField='btnClose'; 
$ListExist=true;
$prefix=$MyFormName."@";
$frmOpenNew='"'.$MyIDFieldName.'","0","'.$MyADDFormName.'",'.$w.','.$h ;

include 'include/top_vars.php';  
include 'include/header.php';
#include 'myFunctions.php';
 
?>

<link href="logos/ApplicationLogo.png" rel="shortcut icon" type="image/x-icon"> 

<style>
 .r1 {text-align:right !important;padding-right:5px !important;}
</style>

<head>
	<title>vs Contracts</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="description" content="">
</head>

<form id="<?php echo $MyFormName;?>" name="<?php echo $MyFormName;?>">
<body OnLoad="document.<?php echo $MyFormName.'.'.$prefix ?>FindWhat.focus();">
 
 <div class="vsboxDetail" >
	<h1> ΚΑΤΑΣΤΑΣΗ ΑΠΟΘΕΜΑΤΙΚΟΥ </h1>
 </div>
 <?php include 'include/top_grid_list_buttons.php';  ?>
 
 <div class="scroll" style="height:62vh; margin-bottom:-50px;padding-bottom:-50px;" > 
<div class="sticky">
  <table id="CustomerList" class="gridList"  > 
   <tr >
	<td class="c w40">A/A</td>
	<td class="c w100">ΗΜΕΡ/ΝΙΑ</td>
    <td>ΑΙΤΙΟΛΟΓΙΑ</td>
    <td class="r w120"> ΕΣΟΔΑ </td>
	<td class="r w120"> ΕΞΟΔΑ </td>
	<td > ΘΕΣΗ </td>
	<td>ΠΑΡΑΤΗΡΗΣΕΙΣ </td>
  </tr> 
  </table>
</div>
 
 <table class="gridListNoCaption"  >   
<?php

$sumEsoda=0;$sumExoda=0;$sumYpoloipo=0;

 $start_date=formatMyDate($HmApo,"GrToMySql"); 
   $end_date=formatMyDate($HmEos,"GrToMySql"); 

 $query=" SELECT * FROM ". $tblName .
		" WHERE Concat(Aitiologia, ' ', Esoda, ' ' , Exoda, ' ',RecType, ' ', IFNULL(Sxolia,'')) LIKE '%" . $FindWhat ."%' "; 
	if($FindWhat=='') {
		 $query.=" AND Hmnia BETWEEN '" . $start_date . "' AND '" . $end_date . "' ";
	   }
 
 $query.=" ORDER BY Hmnia, IDApothematikou, Aitiologia ";
 

 // echo "===========================<br>" . $query . "<br>===========================" ;
  
  
  $num_rows=RecordsCount($conn,$query);
     $RecNo=$num_rows; 
   $FromRec=($pgNo-1)*$RecsPP ;
     $pgMax=intval($num_rows/$RecsPP)+1;
// ====================================  
//          Make Sums
// ====================================
$result = mysqli_query($conn, $query);
	while ($rs = mysqli_fetch_array($result)) {
		$RecType = $rs['RecType'];
		$Esoda = gconvertfield($rs['Esoda'],0);
		$Exoda = gconvertfield($rs['Exoda'],0);

		$sumEsoda = $sumEsoda +$Esoda;
		$sumExoda = $sumExoda +$Exoda;
	}
	
	$sumYpoloipo =$sumEsoda -$sumExoda ;
// ====================================
    $query = $query .  ' LIMIT ' .$FromRec . ', ' . $RecsPP ;
   $result = mysqli_query($conn, $query);
 
$iRow=$FromRec;

 while ($rs = mysqli_fetch_array($result)) {
$iRow +=1;
 
$IDApothematikou = $rs['IDApothematikou'];
$Hmnia = formatMyDate($rs['Hmnia'],"MySqlToGr");
$HmniaNum = $rs['HmniaNum'];
$Aitiologia = $rs['Aitiologia'];
$RecType = $rs['RecType'];
$IDRecType = gconvertfield($rs['IDRecType'],0);
$Esoda = gconvertfield($rs['Esoda'],0);
$Exoda = gconvertfield($rs['Exoda'],0);
$Sxolia = $rs['Sxolia']; 

$RecTypeStyle="";
if ($RecType=='Μετρητά'){$RecType='';}
if ($RecType=='Μισθοδοσία'){$RecTypeStyle="Style='background: #FFE6E6;'";}
 
$frmOpen='"'.$MyIDFieldName.'","'.$IDApothematikou.'","'.$MyADDFormName.'",'.$w.','.$h ;
// echo $RecType . ' - ' . $sumEsodaCredit . ' - ' . $sumEsodaCash . '<br>' ;
// ========================================
//  Pelates List
// ========================================
    echo "<tr $RecTypeStyle class='tablerowdata'  onclick='javascript:OpenFormADD_onWin($frmOpen);'> ";
    echo "<td class='r w40' >$iRow</td>";
	echo "<td class='c w100'>$Hmnia</td>";
    echo "<td>$Aitiologia</td>";
    echo "<td class='r w120'>$Esoda</td>";
	echo "<td class='r w120'>$Exoda</td>";
	echo "<td>$RecType</td>";
	echo "<td>$Sxolia</td>";
    echo "</tr>";
 }
 for ($x = $iRow+1; $x <= $pgNo*$RecsPP; $x++) {
    echo "<tr class='tablerowdata'  onclick='javascript:OpenFormADD_onWin($frmOpenNew);'> ";
    echo "<td class='w40'></td> <td class='w100'></td> <td></td>";
	echo "<td class='w120'></td> <td class='w120'></td>";
    echo " <td></td> <td></td>";
    echo "</tr>";
 }	
 ?> 

</table>
<table  class="gridList"  border="0" cellspacing="0" cellpadding="0" align="center" valign="bottom" > 
   <tr >
	<td class="r1" width="40"> </td>
	<td class="center w100"> </td>
    <td class="r1"> Σύνολα €</td>
    <td class="r1 w120"><?php echo number_format($sumEsoda, 2, '.', '') ?></td>
	<td class="r1 w120"><?php echo number_format($sumExoda, 2, '.', '') ?></td>
	<td class="r1  "> </td>
	<td class="hide1" style="text-align:right;padding-right:15px;color:green;">Υπόλοιπο Αποθεματικού: <?php echo number_format($sumYpoloipo, 2, '.', '')  ?> € </td>
  </tr> 
</table>  
 

	
 
<?php 
include ('include/recs_div_bottom.php');
include 'include/recs_no_max_div.php'; 
?>
<?php
  include 'HmApoEos.php';
?>
 </div>
</body>
</form> 
 
<?php 
  include 'include/footer2020.php';
?>
<script type="text/javascript" src="js/mycheck.js"></script>  
 
 

