<?php include("config.php"); ?>
<?php include("lock.php"); ?>
<? include('style.php');?> 
<? include('welcome.php');?>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
function goBack()
  {
  window.history.back()
  }
</script>

<style type="text/css">
<!--
.style1 {
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-weight: bold; font-size: 18px; 
}

.style4 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 14px; }
.style10 {font-family: Geneva, Arial, Helvetica, sans-serif}
.style111 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px}
.style16 {font-family: Geneva, Arial, Helvetica, sans-serif; font-size: 12px; }
a {     text-decoration: none;
	font-family: Geneva, Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #333333;
	font-weight: bold;
}
}
a:link {
	text-decoration: none;
	font-size: 14px;
}
a:visited {
	text-decoration: none;
	color: #333333;
}
a:hover {
	text-decoration: none;
	color: #333333;
}
a:active {
	text-decoration: none;
	color: #333333;
}
-->
</style>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function Popup(url) {
    var width = 400;
    var height = 250;
    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;
    window.open(url, 'popupWindow', 'width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + ',scrollbars=no,resizable=no');
}
</script>



<p align="center"><input type="button" value="αναίρεση" onClick="goBack()"></p>
<p align="center" class="style4"><a href="home.php" >επιστροφή στην αρχική σελίδα</a></p>
<?

if ($bd->connect_error) {
    die("Σφάλμα σύνδεσης: " . $bd->connect_error);
}

if (session_status() == PHP_SESSION_NONE) {
    session_start();
}

if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    die("Μη έγκυρο ID.");
}

$kart = intval($_GET['id']);

$stmt = $bd->prepare("SELECT id, name, afm, amka, epitagi, room, date_in, date_out, dianiktere, ar_ofel, ar_symb, dik_ofel, katoikos, extra, plithos_dom, imeres, epidotisi, simetoxi, simf_simetox, hotel, periodos, sxolia, onoma_ex, im_ex, idiotita_ex, typos_domatio FROM oaed_thea WHERE id = ?");
$stmt->bind_param('i', $kart);
$stmt->execute();
$stmt->bind_result($id, $name, $afm, $amka, $epitagi, $room, $date_in, $date_out, $dianiktere, $ar_ofel, $ar_symb, $dik_ofel, $katoikos, $extra, $plithos_dom, $imeres, $epidotisi, $simetoxi, $simf_simetox, $hotel, $periodos, $sxolia, $onoma_ex, $im_ex, $idiotita_ex, $typos_domatio);


if (!$stmt->fetch()) {
    die("Δεν βρέθηκαν δεδομένα.");
}
$stmt->close();
$symb =  $ar_symb;

     $kart= $_GET['id'];
     
  // Υπολογισμοί
$date1 = new DateTime($date_in);
$date2 = new DateTime($date_out);
$diff = $date1->diff($date2)->days;

$atom = $ar_ofel + 1;

// Οι παρακάτω μεταβλητές πρέπει να οριστούν κατάλληλα ή να προστεθούν στο SELECT αν έρχονται από τη βάση
$epidotisi = 10;      // Παράδειγμα τιμή
$simetoxi = 5;        // Παράδειγμα τιμή
$simf_simetox = 15;   // Παράδειγμα τιμή
$apy_oaed = '';       // Αν δεν υπάρχει τιμή, να οριστεί κενή ή ανακτηθεί αλλού
$apy_pel = '';
$eggrafes = $atom;    // Ή ό,τι είναι σωστός αριθμός εγγραφών
$gr_ofel = $ar_ofel;  // Αντίγραφο για χρήση στον σύνδεσμο

$poso_apy_oaed = $epidotisi * $atom;
$poso_apy_pel = $simetoxi * $atom;
$simf = ($diff * $simf_simetox) * $atom;

$s_im = $simetoxi / $dianiktere;
$s_im_a = $simf_simetox - $s_im;
$simf_im = $s_im_a * $atom;

$poso_tamio = $simf - $poso_apy_pel;
$sin_xreosi = $poso_tamio + $poso_apy_oaed + $poso_apy_pel;
$datein = date('d/m/Y', strtotime($date_in));
    $dateout = date('d/m/Y', strtotime($date_out));







?> 
    <p>&nbsp;</p>
    
<table width="1000" border="0" align="center" bgcolor="#FFF">
  <tr>
    <td width="134"><div align="left" class="style111">Κωδ.</div></td>
    <td width="13"><span class="style111">:</span></td>
    <td width="350"><div align="left" class="style111"><? echo ($id)?></div></td>
    <td width="121"><div align="left" class="style111">Ονομ/νυμο</div></td>
    <td width="18"><span class="style111">:</span></td>
    <td width="317"><div align="left" class="style111"><? echo ($name)?></div></td>
  </tr>
  <tr>
    <td><div align="right"><span class="style111"></span></div></td>
    <td><span class="style111"></span></td>
    <td><div align="left"><span class="style111"></span></div></td>
    <td><div align="left" class="style111">ΔΙΚΑΙΟΥΧ /ΩΦΕΛΟΥΜ</div></td>
    <td><span class="style111">:</span></td>
    <td><span class="style111"><? if ($dik_ofel=="1") echo ' ΔΙΚΑΙΟΥΧΟΣ ';
                                  if ($dik_ofel=="2") echo ' ΩΦΕΛΟΥΜΕΝΟΣ ';  ?></span></td>
  </tr>
  <tr>
    <td><div align="left" class="style111">Α.Φ.Μ. </div></td>
    <td><span class="style111">:</span> </td>
    <td><div align="left" class="style111"><? echo ($afm)?></div></td>
    <td><div align="left" class="style111">Κατοικος</div></td>
    <td><span class="style111">:</span></td>
    <td><div align="left" class="style111"><? echo ($katoikos)?></div></td>
  </tr>
  <tr>
    <td><div align="left"><span class="style111">AMKA</span></div></td>
    <td><span class="style111">:</span></td>
    <td><div align="left"><span class="style111"><? echo ($amka)?></span></div></td>
    <td><div align="left" class="style111">Άφιξη</div></td>
    <td><span class="style111">:</span></td>
    <td><span class="style111"><? echo $datein; ?></span></td>
  </tr>
  
  <tr>
    <td><div align="left"><span class="style111">Aρ. επιταγής</span></div></td>
    <td><span class="style111">:</span></td>
    <td><div align="left"><span class="style111"><? echo ($epitagi)?></span></div></td>
    <td><div align="left" class="style111">Αναχώρηση</div></td>
    <td><span class="style111">:</span></td>
    <td><span class="style111"><? echo $dateout;?></span></td>
  </tr>
  
  
  <tr>
    <td><div align="left"></div></td>
    <td><span class="style111">:</span></td>
    <td><div align="left"></div></td>
    <td><div align="left" class="style111"> </div></td>
    <td><span class="style111"></span></td>
    <td><span class="style111"> </span></td>
  </tr>
  <tr>
    <td><div align="left"><span class="style111">Αρ. ωφελουμ.</span></div></td>
    <td><span class="style11">:</span></td>
    <td><div align="left"><span class="style111"><? echo ($ar_ofel)?></span></div></td>
    <td><div align="left"><span class="style11"></span><span class="style16">συνολο ΑΠΥ ΟΑΕΔ</span></div></td>
    <td><span class="style111">:</span></td>
    <td><span class="style111"><?  echo number_format((float)$poso_apy_oaed, 2, '.', '');?> €</span></td>
  </tr>
  <tr>
   <td><div align="left"><span class="style111">Σύν. Διανυκτ.</span></div></td>
    <td><span class="style111">:</span></td>
    <td><div align="left"><span class="style111"><? echo $diff;?></span></div></td>
    <td><div align="left" class="style111"><span class="style16">συνολο ΑΠΥ πελατη</span></div></td>
    <td><span class="style111">:</span></td>
    <td><span class="style111"><?  echo number_format((float)$poso_apy_pel, 2, '.', '');?> € </span></td>
  </tr>
  <tr>
    <td><div align="left"><span class="style111">Τύπος δωματίου </span></div></td>
    <td><span class="style111">:</span></td>
    <td><div align="left"><span class="style111"><? echo ($plithos_dom)?> / <? if ($infoil['typos_domatio']=="1") echo ' ΜΟΝΟΚΛΙΝΟ ';
                                                    if ($typos_domatio =="2") echo ' ΔΙΚΛΙΝΟ ';  
						    if ($typos_domatio =="3") echo ' ΤΡΙΚΛΙΝΟ ';  
						    if ($typos_domatio =="4") echo ' ΤΕΤΡΑΚΛΙΝΟ ';  												?></span></div></td>
    <td><div align="left" class="style111">συνολο Ταμειακης </div></td>
    <td><span class="style111">:</span></td>
    <td><span class="style111"><?  echo number_format((float)$poso_tamio, 2, '.', '');?> € ( <?  echo number_format((float)$simf_im, 2, '.', '');?> € X <? echo $diff;?> μερες)</span></td>
  </tr>
  
  
   
  <tr>
    <td><div align="left"><span class="style111">Room No</span></div></td>
    <td><span class="style111">:</span></td>
      
      <td><div align="left"><span class="style111"><? echo $room;?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      
     
      <? echo '<a href="edit_room.php?id=' . $id . ' "><img src="images/room.png" title="κλικ για αλλαγή δωματίου" style="width:25px;height:15px;" /></a></td>'?></span></div>
      
      
      
      
    <td><div align="left"><span class="style111">Συνολική χρέωση</span></div></td>
    <td><span class="style111">:</span></td>
    <td><span class="style111"><?  echo number_format((float)$sin_xreosi, 2, '.', '');?> € </span></td>
  </tr>
  
  <tr>
    <td><div align="left"><span class="style111">Αλλαγή δωμάτιο /σχόλια</span></div></td>
    <td><span class="style111">:</span></td>
   
      <td><div align="left"><span class="style111"><? echo ($sxolia)?></span></div></td>
   
    <td><span class="style111"></span></td>
    <td><span class="style111"></span></td>
  </tr>
  
 <tr><td>&nbsp;</td> </tr>
  
  <tr><td align="right"><span class="style111">συμβαση</span></td>
   <td><span class="style111"></span></td>
   <td><span class="style111">δελτιο αφιξης</span></td>
         <td><span class="style111">ΑΠΥ ΟΑΕΔ</span></td>
     <td></td>
      <td><span class="style111">ΑΠΥ πελατη</span></td>
       <td></td>
</tr>

<tr><span class="style111"><? echo '<td align="right" width="80" span class="style29"><a href="simb.php?id=' . $id . ' "><img src="images/simb.jpg" title="συμβαση" style="width:50px;height:40px;" /></td>'?></span></td>
   <td><span class="style111"></span></td>
   <? echo '<td align="left" width="80" span class="style29"><a href="deltio_af.php?id=' . $id . '"><img src="images/afixi.jpg"" title="δελτιο αφιξης" style="width:70px;height:40px;" /></td>'?>
 <? echo '<td align="left" width="80" span class="style29"><a href="add_apy.php?id=' . $id . ' "><img src="images/kartela.png" title="επιδοτηση ΟΑΕΔ" style="width:50px;height:40px;" /></td>'?></span>
 <td></td>
 <? echo '<td align="left" width="80" span class="style29"><a href="add_apy_p.php?id=' . $id . ' "><img src="images/kartela.png" title="συμμετοχη πελατη" style="width:50px;height:40px;" /></td>'?></span>
</tr>


  <tr> <td></td>
   <td><span class="style111"></span></td>
   <td><span class="style18"><? echo '<td align="right" width="300" span class="style18"><a href="add_ofe_edit.php?id=' . $id . '& ar_symb='.$ar_symb .'">καταχωρηση νέου ωφελούμενου</td>'?></span></td>
  
     <td><span class="style111"></span></td>
     <td><span class="style111">  <? echo '<td align="right" width="280" span class="style29"><a href="dik_cart.php?id=' . $id . '">απόκρυψη ωφελούμενων</td>'?></span></td>
  
  </tr>
  
  
  <tr> 
   <td colspan="8" align="center"><span class="style112"><?     if($atom == $eggrafes)
                                                                {
                                                                echo " ";
                                                                }else{   
                                                                echo "δεν συμφωνουν ο αριθμος των ωφελουμενων με τις εγγραφες";?> 
             <? echo '<a href="up_ofe.php?ar_symb=' . $ar_sim . ' & ar_ofel='.$gr_ofel.' & id='.$kart.'">(klik εδω για ενημερωση ατομων )'  ?> <? } ?></span></td>
   
  </tr>

</table>
<?
    
    ?>
  <table width="200" border="0" align="center" bgcolor="#FFFFFF">        
  </table>


<table width="900" cellpadding="2" cellspacing="2"  align="center">
  <p align="center"></p>
  
    <tr class="style4">
      <th width="15" align="left"> </th>
      <th width="250" align="left">Ονοματεπώνυμο</th>
      <th width="150" align="center">ΑΦΜ</th>
      <th width="150" align="center">ΑΜΚΑ</th>
      <th width="300" align="center">επιταγη</th>
      <th width="40" align="center">edit</th>     
      <th width="20" align="left">del</th>
    </tr>
  
  <tbody>
  
  <? 
  
  $kart = intval($_GET['id']);

  $datein=date('d/m/Y',  strtotime($rowtt['date_in'])); 
  $dateout=date('d/m/Y',  strtotime($rowtt['date_out'])); 
$stmt = $bd->prepare("SELECT id, name, afm, amka, epitagi, room, date_in, date_out, dianiktere, ar_ofel, ar_symb, dik_ofel, katoikos, extra, plithos_dom, imeres, epidotisi, simetoxi, simf_simetox, hotel, periodos, sxolia, onoma_ex, im_ex, idiotita_ex, typos_domatio FROM oaed_thea WHERE ar_symb='$symb' and `dik_ofel`!='1'");

$stmt->bind_param('i', $kart);
$stmt->execute();
$stmt->bind_result($id, $name, $afm, $amka, $epitagi, $room, $date_in, $date_out, $dianiktere, $ar_ofel, $ar_symb, $dik_ofel, $katoikos, $extra, $plithos_dom, $imeres, $epidotisi, $simetoxi, $simf_simetox, $hotel, $periodos, $sxolia, $onoma_ex, $im_ex, $idiotita_ex, $typos_domatio);

$counter = 1;
$c = false;

while ($stmt->fetch()) {
    echo '<tr class="style111" style="background:' . (($c = !$c) ? '#FFFFFF' : '#FFFF99') . '">';
    echo '<td bgcolor="#DDDDDD">' . $counter++ . '</td>';
    echo '<td width="250" align="left">' . htmlspecialchars($name) . '</td>';
    echo '<td align="center">' . htmlspecialchars($afm) . '</td>';
    echo '<td align="center">' . htmlspecialchars($amka) . '</td>';
    echo '<td align="center">' . htmlspecialchars($epitagi) . '</td>';
    echo '<td align="center" width="50"><a href="edit_dik.php?id=' . $id . '">edit</a></td>';
    echo '<td align="center" bgcolor="#FFFFFF"><a href="oaed_del.php?id=' . $id . '"><img src="images/delete12.png" alt="del" height="12" width="12"></a></td>';
    echo '</tr>';
}

$stmt->close();

  
 
 
 ?>
    
     