<?php 
session_start();
?>
<head>
	<title>Visualsoft Office Manager - Ταμείο</title>
	<link href="logos/ofm1.ico" rel="shortcut icon" type="image/x-icon"> 
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta name="description" content="">
	<meta http-equiv="content-type" content="text/html; charset=UTF-8">	
</head>
<?php  
error_reporting(E_ALL); ini_set('display_errors', 1);
  
if(!isset($_SESSION['CheckPWD']) || $_SESSION['CheckPWD'] == '' ){header("Location: login.php");die();}

$myTopCaption_Text="ΚΑΤΑΣΤΑΣΗ ΤΑΜΕΙΟΥ"; 
$MyFormName=str_replace('.php', '', basename($_SERVER['PHP_SELF']));
$MyADDFormName="tameio_add"; $w=890; $h=480;
$MyIDFieldName="IDTameiou";
$IDcField="IDTameiou";
$tblName='tameio';
$FocusField='btnClose'; 
$ListExist=true;
$prefix=$MyFormName."@";

$RequiredField="";

$frmOpenNew='"'.$MyIDFieldName.'","0","'.$MyADDFormName.'",'.$w.','.$h ;

include 'include/top_vars.php'; 
include 'include/header.php';
 
$start_date=formatMyDate($HmApo,"GrToMySql"); 
$end_date=formatMyDate($HmEos,"GrToMySql"); 

// echo "Periodos : $Periodos  ||  start_date: $start_date ====  end_date: $end_date";
// echo "user-ip: " . user_ip_address();
app_head();
?>


<style>
.prg_ypoloipo { background-color:#f2f2f2!important;
   text-shadow: 0px  !important;
 }	
.r1 {text-align:right;  }
.footer_sums {
	text-shadow: 1px 1px #F8F8F8;
    line-height:32px;
    border-top: 0px solid #F8F8F8;
	border-left: 0px solid #F8F8F8;
	border-right: 1px solid #D8D8D8 ;
	border-bottom: 1px solid #D8D8D8 ; 
	border-radius:3px;
}
</style>

<form id='<?php echo $MyFormName;?>' name="<?php echo $MyFormName;?>" autocomplete="off">
 <body OnLoad="document.<?php echo $MyFormName.'.'.$prefix ?>FindWhat.focus();">

 <div class="vsboxDetail hide1" >
 <h1 id="hmnia_caption"> ΚΑΤΑΣΤΑΣΗ ΤΑΜΕΙΟΥ</h1>
 </div>
 
 <?php include 'include/top_grid_list_buttons.php';  ?>
 
<div class="scroll" style="margin-bottom:0px;padding-bottom:0px;width:100%;" >
<div class="sticky">
  <table id="CustomerList" class="gridList"  > 
   <tr >
	<td class="r w50 hide1" >A/A</td>
	<td class="center w100">ΗΜΕΡ/ΝΙΑ<a onclick="grdsrt('Hmnia');" class="sortpic hide1"/></td>
    <td >ΑΙΤΙΟΛΟΓΙΑ <a onclick="grdsrt('Aitiologia');" class="sortpic"/></td>
    <td class="r w100 hide1"> ΕΣΟΔΑ </td>
	<td class="r w100 hide1"> ΕΞΟΔΑ </td>
	<td class="r w140 hide1" > ΠΛΗΡΩΜΗ<a onclick="grdsrt('RecType');" class="sortpic"/></td>
	<td class="hide1">ΠΑΡΑΤΗΡΗΣΕΙΣ </td>
	<td class="c w50 hide1">ΟΚ <a onclick="grdsrt('UpToDate');" class="sortpic"/></td>
  </tr> 
  </table >
</div  >  

  <table id="CustomerList" class="gridList"  > 
  <tr class="hide1">
	<td class="r w50 prg_ypoloipo hide1"> </td>
	<td class="c w100 prg_ypoloipo"> </td>
    <td class="prg_ypoloipo">Προηγούμενο Υπόλοιπο</td>
    <td class="r w100 prg_ypoloipo"> </td>
	<td class="r w100 prg_ypoloipo">  </td>
	<td class="r w140 prg_ypoloipo hide1"> </td>
	<td class="prg_ypoloipo hide1">  </td>
	<td class="c w50 prg_ypoloipo hide1"> </td>

  </tr> 
  
<?php

$sumEsodaCash=0;$sumExodaCash=0;
$sumEsodaCredit=0;$sumExodaCredit=0;
$sumYpoloipoCash=0;$sumYpoloipo=0;

     $flds="Aitiologia,Esoda,Exoda,RecType,Sxolia";
   $filter=filter_make($flds, $FindWhat);
 
 $query=" SELECT * FROM ".$tblName." ".$filter;  

if($filter=='') {
     	$query.=" WHERE Hmnia BETWEEN '" . $start_date . "' AND '" . $end_date . "' ";
   }
 
 if($SortValue==''){$query=$query ." ORDER BY Hmnia, IDTameiou, Aitiologia ";} else {$query=$query." ORDER BY " . $SortValue . " ";}
 
// select row_id from mytable where '%searched_text%' IN ('column1','column2','column3','column4','column5');

//   echo $query;
// echo $conn;
// echo date("D d/m/Y")."<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);

	if($RecType=='Μετρητά') {
		  $sumEsodaCash = $sumEsodaCash + $Esoda;
		  $sumExodaCash = $sumExodaCash + $Exoda;
		  }  
	if($RecType=='Τραπεζική Κατάθεση' || $RecType=='Πιστωτική Κάρτα') {
		  $sumEsodaCredit=$sumEsodaCredit+$Esoda;
		  $sumExodaCredit=$sumExodaCredit+$Exoda;
		  }	 
	$sumYpoloipo= $sumYpoloipo +$Esoda-$Exoda;
	}
	
	$sumYpoloipoCash=$sumEsodaCash-$sumExodaCash;
// ====================================
    $query = $query .  ' LIMIT ' .$FromRec . ', ' . $RecsPP ;
   $result = mysqli_query($conn, $query);
 
$iRow=$FromRec;

if (!$result) {
    printf("Error: %s\n", mysqli_error($conn));
    exit();
}

while ($rs = mysqli_fetch_array($result)) {

$iRow +=1;
 
$IDTameiou = $rs['IDTameiou'];
$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']; 

$UpToDate = $rs['UpToDate'];
$UpToDateChk='unckecked';
if($UpToDate==-1){$UpToDateChk='checked';} 


$RecTypeStyle="";
if ($RecType=='Μετρητά'){$RecType='';}
if ($RecType=='Μισθοδοσία'){$RecTypeStyle="Style='background:#85e085;color:white;'";}

$frmOpen='"'.$MyIDFieldName.'","'.$IDTameiou.'","'.$MyADDFormName.'",'.$w.','.$h ;

// echo $RecType . ' - ' . $sumEsodaCredit . ' - ' . $sumEsodaCash . '<br>' ;
// ========================================
//  Pelates List
// ========================================
    echo "<tr $RecTypeStyle class='tablerowdata'  onclick='OpenFormADD_onWin($frmOpen);'> ";
    echo "<td class='r w50 hide1' >$iRow</td>";
	echo "<td class='c w100'>$Hmnia</td>";
    echo "<td>$Aitiologia</td>";
    echo "<td class='r w100 hide1'>$Esoda</td>";
	echo "<td class='r w100 hide1'>$Exoda</td>";
	echo "<td class='r w140 hide1'>$RecType</td>";
	echo "<td class='hide1'>$Sxolia</td>";
	echo "<td class='c w50 hide1'><input size ='1' type='checkbox' $UpToDateChk ></td>";
    echo "</tr>";
 }
for ($x = $iRow+1; $x <= $pgNo*$RecsPP; $x++) {
    echo "<tr class='tablerowdata' onclick='OpenFormADD_onWin($frmOpenNew);'> ";
    echo "<td class='r w50 hide1' ></td>";
	echo "<td class='c w100'></td>";
    echo "<td></td>";
    echo "<td class='r w100 hide1'></td>";
	echo "<td class='r w100 hide1'></td>";
	echo "<td class='r w140 hide1'></td>";
	echo "<td class='hide1'></td>";
	echo "<td class='c w50 hide1'></td>";
    echo "</tr>";
 }	
 ?> 
 
 </table>
 
 <div class="sticky_bottom"  >
 <table id="CustomerList" class="gridList" style="border:0px solid blue;padding-bottom:0;margin:0px;" >
   <tr class='gridListFooter'>
	<td class="w50 r hide1"> </td>
	<td class="c w100 hide1"> </td>
    <td class="hide1"> Μετρητα € </td>
    <td class="r1 w100 " ><?php echo number_format($sumEsodaCash, 2, '.', '') ?> €</td>
	<td class="r1 w100 "><?php echo number_format($sumExodaCash, 2, '.', '') ?> €</td>
	<td class="r1 w140 hide1"> </td>
	<td class="hide1" style="text-align:right;padding-right:5px;color:green;">Υπόλοιπο Ταμείου (Μετρητά) : <?php echo number_format($sumYpoloipoCash, 2, '.', '')  ?> €</td>
    <td class="c w50 hide1"> </td>
  </tr> 
 
   <tr class='gridListFooter hide1' >
	<td class="r w50 hide1"> </td>
	<td class="c w100"> </td>
    <td >Κάρτες - Καταθέσεις </td>
    <td class="r1 w100"><?php echo number_format($sumEsodaCredit, 2, '.', '') ?></td>
	<td class="r1 w100"><?php echo number_format($sumExodaCredit, 2, '.', '') ?></td>
	<td class="r1 w140 "> </td>
	<td class="r1 hide1" style="color:red;">Καθαρό Υπόλοιπο : <?php echo number_format($sumYpoloipo, 2, '.', '')  ?> €</td>
	<td class="w50 hide1"> </td> 
 </tr> 
</table>  

<?php 
$myTopBorder=0;
include ('include/recs_div_bottom.php');
?>
</div>
</div>
 
 
</body>
  
</form> 
 
<?php 
  include 'HmApoEos.php';
  include_once 'include/footer2020.php';
?>

<script type="text/javascript" src="js/mycheck.js"></script>  
<script type="text/javascript" src="js/datepicker.js"></script>   
 
 