<?php include('include/auth.php');
 $dateTimeZone = new DateTimeZone("Europe/Athens");
 $dateTime = new DateTime("now", $dateTimeZone);
 $timeOffset = $dateTimeZone->getOffset($dateTime);
 $today = time() + $timeOffset;
 $from1=strtotime('yesterday midnight');
 $from=strtotime('today midnight');
 $from2=strtotime('tomorrow midnight');
 $to1=strtotime('yesterday 23:59:59');
 $to=strtotime('today 23:59:59');
 $to2=strtotime('tomorrow  23:59:59');
?>
<!doctype html>
<html class="fixed dark">
	<?php 
	$pagerole="index";
	include('include/head.php'); ?><style>.noshow{display:none;}</style>
	<body>
		<section class="body">

			<!-- start: header -->
			<header class="header">
				<div class="logo-container">
					<a href="index.php" class="logo">
						<img src="img/logo-light.png" width="75" height="35" alt="Web Voyage" />
					</a>
					<div class="d-md-none toggle-sidebar-left" data-toggle-class="sidebar-left-opened" data-target="html" data-fire-event="sidebar-left-opened">
						<i class="fas fa-bars" aria-label="Toggle sidebar"></i>
					</div>
				</div>
			
				<!-- start: search & user box -->
				<div class="header-right">
			<?php include('include/search.php');?>
					
			
					<span class="separator"></span>
			<?php include('include/notifications.php');?>
				
			
					<span class="separator"></span>
					<?php include('include/userbox.php'); 
					
					?>
				
				</div>
				<!-- end: search & user box -->
			</header>
			<!-- end: header -->

			<div class="inner-wrapper">
				<!-- start: sidebar -->
				<?php include('include/nav.php');
				if ($stationid==0){$stationname="Central";} 
				else{
		$sqlstat = $db2->query("SELECT * FROM jostj_vikrentcar_stations WHERE jostj_vikrentcar_stations.station_id='$stationid' ") or die(mysql_error());
		$rowstat = mysqli_fetch_array( $sqlstat );
				$stationname=$rowstat['station_name'];}
				  $sqlstlo = "SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.station='$stationid' ";
		
				$result = mysqli_query($db2,$sqlstlo);
		
				?>
				<!-- end: sidebar -->

				<section role="main" class="content-body">
					<header class="page-header">
						<h2>Dashboard</h2>
					
						<div class="right-wrapper text-right">
							<ol class="breadcrumbs">
								<li>
									<a href="index.php">
										<i class="fas fa-home"></i>
									</a>
								</li>
								<li><span>WV Admin</span></li>
								<li><span>Dashboard</span></li>
							</ol>
					
							<a class="sidebar-right-toggle" data-open="sidebar-right"><i class="fas fa-chevron-left"></i></a>
						</div>
					</header>

					<!-- start: page -->
					<div class="row">
                    <div class="col">
                        <section class="card">
                            <header class="card-header">
                                <div class="card-actions">
                                    <a href="#" class="card-action card-action-toggle" data-card-toggle></a>
                                    <a href="#" class="card-action card-action-dismiss" data-card-dismiss></a>
                                </div>

                                <h2 class="card-title">Reservations for <?php echo $stationname;?></h2>
                            </header>

                            <div class="card-body">
					<div class="row">
						<div class="col-lg-12">
                          		<div class="tabs tabs-success">
								<ul class="nav nav-tabs nav-justified">
								<li class="nav-item">
										<a class="nav-link" href="#resyesterday" data-toggle="tab"><i class="fas fa-calendar-alt"></i>-1 Yesterday</a>
									</li>
									<li class="nav-item active">
										<a class="nav-link" href="#restoday" data-toggle="tab"><i class="fas fa-calendar-alt"></i> Today</a>
									</li>
									<li class="nav-item">
										<a class="nav-link" href="#restomorrow" data-toggle="tab"><i class="fas fa-calendar-alt"></i>+1 Tomorrow</a>
									</li>
								</ul>
								<div class="tab-content">
								<div id="resyesterday" class="tab-pane">
							

                                        <?php 
$sql = "SELECT jostj_vikrentcar_orders.id AS orderid, jostj_vikrentcar_orders.*, jostj_vikrentcar_places.*  FROM jostj_vikrentcar_orders
LEFT JOIN jostj_vikrentcar_places ON jostj_vikrentcar_orders.idplace=jostj_vikrentcar_places.id AND jostj_vikrentcar_orders.idreturnplace=jostj_vikrentcar_places.id
WHERE  jostj_vikrentcar_orders.custdata!='Car Closed' AND jostj_vikrentcar_orders.ritiro > '$from1'  AND jostj_vikrentcar_orders.ritiro < '$to1' ";
if ($stationid!='0'){
    $sql .="AND jostj_vikrentcar_places.station='$stationid' ";
    }
$result = mysqli_query($db2,$sql);

if ($result->num_rows > 0) {
    ?><table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
    <thead>
        <tr>
        <th>Res ID</th>
            <th>Ordered Date</th>
            <th>Client</th>
            <th>Vehicle</th>
            <th>Pick Up Location</th>
            <th>Pick Up Date/Time</th>
           
            <th>Rental Price</th>
            <th>Station</th>
            <th>Source</th>
            <th>Status</th>
            <th>Notes</th>
            <th>Extras</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody><?php
   while($row = mysqli_fetch_array($result)) {
	  	  if ($row["idplace"]!=NULL) {$idplace=$row["idplace"];} else {$idplace="1";}
	   if ($row["idreturnplace"]!=NULL) {$idreturnplace =$row["idreturnplace"];} else {$idreturnplace="1";}
	  $idsource=$row["source"];
	   $idcar=$row["idcar"];
	   
	  $sql4 = $db2->query("SELECT * FROM jostj_vikrentcar_cars WHERE jostj_vikrentcar_cars.id='$idcar' ") or die(mysql_error());
$row5 = mysqli_fetch_array( $sql4 ); 

	  $sql2 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id='$idplace' ");
$row3 = mysqli_fetch_array( $sql2 ); 
$idstatp=$row3['station'];
$sqlst = $db2->query("SELECT * FROM jostj_vikrentcar_stations WHERE jostj_vikrentcar_stations.station_id='$idstatp' ");
$rowst = mysqli_fetch_array( $sqlst ); 

	$sql3 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id='$idreturnplace' ") or die(mysql_error());
$row4 = mysqli_fetch_array( $sql3 );
	   $sql7 = $db2->query("SELECT * FROM jostj_vikrentcar_sources WHERE jostj_vikrentcar_sources.id='$idsource' ") or die(mysql_error());
$row7 = mysqli_fetch_array( $sql7 ); 
if($row['source']==1006){
    $picktime2=strtotime('+2 hours', $row['ritiro'])."@";
    $droptime2=strtotime('+2 hours', $row['consegna'])."@";
    $picktime=date('d/m/Y H:i', $picktime2)."@";
    $droptime=date('d/m/Y H:i', $droptime2)."@";
}
else{
    $picktime=date('d/m/Y H:i', $row['ritiro']);
    $droptime=date('d/m/Y H:i', $row['consegna']);
}
     ?>

<tr>
                                            <td><strong><?php echo $row["orderid"]; ?></strong></td>
                                            <td><?php echo date('d/m/Y H:i', $row['ts']);  ?></td>
                                            <td class="text-center">
                                                <?php if ($row["nominative"]!=NULL) {echo $row['nominative'];} else {echo $row['custdata'];} ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($row5['name']!=NULL) {echo $row5['name'];} else {echo "not set";} ?>
                                            </td>

                                            <td class="text-center">
                                                <?php if ($row3["name"]!=NULL) {echo $row3["name"];} else {echo "not set";} ?>
                                            </td>
                                            <td><?php echo $picktime;  ?></td>
                                            
                                            <td><?php echo $row['order_total']; ?>€</td>
                                            <td><?php echo $rowst['station_name']; ?></td>
                                            <td><?php echo $row7['name']; ?></td>
                                            <td
                                                class="<?php if($row["status"]=="cancelled"){echo "red";} elseif($row["status"]=="confirmed") {echo "green";} elseif($row["status"]=="standby"){echo "lightyellow";} elseif($row["status"]=="contract"){echo "lightblue";}?>">
                                                <?php echo $row['status']; ?></td>
                                            <td><?php if (is_null($row['optionals'])) {echo "None";}
                                    else {
                            $st2=explode(';', $row['optionals']);
                        
                        
                            foreach ($st2 as $index=>$value){
                                if ($value == NULL) {
                                    break;
                                }
                        $optionalname=trim(explode(':', $value)[0]);
                        $optionalquant=trim(explode(':', $value)[1]);
                        $sqlopt = $db2->query("SELECT * FROM jostj_vikrentcar_optionals  WHERE jostj_vikrentcar_optionals.id='$optionalname'  ") or die(mysql_error());
                                            $rowopt = mysqli_fetch_array( $sqlopt );
                       if ($row['source']==16){
                        $sqlopt2 = $db->query("SELECT * FROM jos8r_vikrentcar_optionals  WHERE jos8r_vikrentcar_optionals.id='$optionalname'  ") or die(mysql_error());
                        $rowopt2 = mysqli_fetch_array( $sqlopt2 );
                        $optionalvalue=$rowopt2['cost']*$optionalquant;
                       }
                       else{
                           $optionalvalue=$rowopt['cost']*$optionalquant;
                       }                    
                       ?>
                       <span class="<?php if($optionalquant==0){echo "noshow";}?> text-dark" ><?php echo $rowopt['name'];?> X<?php echo $optionalquant;?>, </span>
                   <?php }
                        }
                            ?></td>
                                            
                                            <td><?php echo $row['adminnotes']; ?></td>
                                            <td class="actions">
                                                <a href="reservation.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fa fa-eye"></i></a><?php if($row["status"]=="confirmed"){?>
                                                <a href="newcontract.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fas fa-file-signature"></i></a> <a
                                                    href="resprint.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i class="fas fa-print"></i></a>
                                                <?php } ?>

                                            </td>
                                        </tr>
                                        <?php } } else {echo "<h4 class='text-center'>Did Nothing Yesterday!</h4>";}?>
                                    </tbody>
                                </table>
									</div>
									<div id="restoday" class="tab-pane active">
                                 

                                        <?php 
$sql = "SELECT jostj_vikrentcar_orders.id AS orderid, jostj_vikrentcar_orders.*, jostj_vikrentcar_places.*  FROM jostj_vikrentcar_orders
LEFT JOIN jostj_vikrentcar_places ON jostj_vikrentcar_orders.idplace=jostj_vikrentcar_places.id AND jostj_vikrentcar_orders.idreturnplace=jostj_vikrentcar_places.id
WHERE  jostj_vikrentcar_orders.custdata!='Car Closed' AND jostj_vikrentcar_orders.ritiro > '$from'  AND jostj_vikrentcar_orders.ritiro < '$to' ";
if ($stationid!='0'){
    $sql .="AND jostj_vikrentcar_places.station='$stationid' ";
    }
$result = mysqli_query($db2,$sql);

if ($result->num_rows > 0) {
    ?><table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
    <thead>
        <tr>
        <th>Res ID</th>
            <th>Ordered Date</th>
            <th>Client</th>
            <th>Vehicle</th>
            <th>Pick Up Location</th>
            <th>Pick Up Date/Time</th>
           
            <th>Rental Price</th>
            <th>Station</th>
            <th>Source</th>
            <th>Status</th>
            <th>Notes</th>
            <th>Extras</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody><?php
   while($row = mysqli_fetch_array($result)) {
	  	  if ($row["idplace"]!=NULL) {$idplace=$row["idplace"];} else {$idplace="1";}
	   if ($row["idreturnplace"]!=NULL) {$idreturnplace =$row["idreturnplace"];} else {$idreturnplace="1";}
	  $idsource=$row["source"];
	   $idcar=$row["idcar"];
	   
	  $sql4 = $db2->query("SELECT * FROM jostj_vikrentcar_cars WHERE jostj_vikrentcar_cars.id='$idcar' ") or die(mysql_error());
$row5 = mysqli_fetch_array( $sql4 ); 

	  $sql2 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id='$idplace' ");
$row3 = mysqli_fetch_array( $sql2 ); 
$idstatp=$row3['station'];
$sqlst = $db2->query("SELECT * FROM jostj_vikrentcar_stations WHERE jostj_vikrentcar_stations.station_id='$idstatp' ");
$rowst = mysqli_fetch_array( $sqlst ); 

	$sql3 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id='$idreturnplace' ") or die(mysql_error());
$row4 = mysqli_fetch_array( $sql3 );
	   $sql7 = $db2->query("SELECT * FROM jostj_vikrentcar_sources WHERE jostj_vikrentcar_sources.id='$idsource' ") or die(mysql_error());
$row7 = mysqli_fetch_array( $sql7 ); 
if($row['source']==1006){
    $picktime2=strtotime('+2 hours', $row['ritiro'])."@";
    $droptime2=strtotime('+2 hours', $row['consegna'])."@";
    $picktime=date('d/m/Y H:i', $picktime2)."@";
    $droptime=date('d/m/Y H:i', $droptime2)."@";
}
else{
    $picktime=date('d/m/Y H:i', $row['ritiro']);
    $droptime=date('d/m/Y H:i', $row['consegna']);
}
     ?>

<tr>
                                            <td><strong><?php echo $row["orderid"]; ?></strong></td>
                                            <td><?php echo date('d/m/Y H:i', $row['ts']);  ?></td>
                                            <td class="text-center">
                                                <?php if ($row["nominative"]!=NULL) {echo $row['nominative'];} else {echo $row['custdata'];} ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($row5['name']!=NULL) {echo $row5['name'];} else {echo "not set";} ?>
                                            </td>

                                            <td class="text-center">
                                                <?php if ($row3["name"]!=NULL) {echo $row3["name"];} else {echo "not set";} ?>
                                            </td>
                                            <td><?php echo $picktime;  ?></td>
                                            
                                            <td><?php echo $row['order_total']; ?>€</td>
                                            <td><?php echo $rowst['station_name']; ?></td>
                                            <td><?php echo $row7['name']; ?></td>
                                            <td
                                                class="<?php if($row["status"]=="cancelled"){echo "red";} elseif($row["status"]=="confirmed") {echo "green";} elseif($row["status"]=="standby"){echo "lightyellow";} elseif($row["status"]=="contract"){echo "lightblue";}?>">
                                                <?php echo $row['status']; ?></td>
                                            <td><?php if (is_null($row['optionals'])) {echo "None";}
                                    else {
                            $st2=explode(';', $row['optionals']);
                        
                        
                            foreach ($st2 as $index=>$value){
                                if ($value == NULL) {
                                    break;
                                }
                        $optionalname=trim(explode(':', $value)[0]);
                        $optionalquant=trim(explode(':', $value)[1]);
                        $sqlopt = $db2->query("SELECT * FROM jostj_vikrentcar_optionals  WHERE jostj_vikrentcar_optionals.id='$optionalname'  ") or die(mysql_error());
                                            $rowopt = mysqli_fetch_array( $sqlopt );
                       if ($row['source']==16){
                        $sqlopt2 = $db->query("SELECT * FROM jos8r_vikrentcar_optionals  WHERE jos8r_vikrentcar_optionals.id='$optionalname'  ") or die(mysql_error());
                        $rowopt2 = mysqli_fetch_array( $sqlopt2 );
                        $optionalvalue=$rowopt2['cost']*$optionalquant;
                       }
                       else{
                           $optionalvalue=$rowopt['cost']*$optionalquant;
                       }                    
                       ?>
                       <span class="<?php if($optionalquant==0){echo "noshow";}?> text-dark" ><?php echo $rowopt['name'];?> X<?php echo $optionalquant;?>, </span>
                   <?php }
                        }
                            ?></td>
                                            
                                            <td><?php echo $row['adminnotes']; ?></td>
                                            <td class="actions">
                                                <a href="reservation.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fa fa-eye"></i></a><?php if($row["status"]=="confirmed"){?>
                                                <a href="newcontract.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fas fa-file-signature"></i></a> <a
                                                    href="resprint.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i class="fas fa-print"></i></a>
                                                <?php } ?>

                                            </td>
                                        </tr>
                                        <?php } } else {echo "<h4 class='text-center'>Nothing to Do Today!</h4>";}?>
                                    </tbody>
                                </table>
									</div>
									
									<div id="restomorrow" class="tab-pane">
                                    

                                        <?php 
$sql = "SELECT jostj_vikrentcar_orders.id AS orderid, jostj_vikrentcar_orders.*, jostj_vikrentcar_places.*  FROM jostj_vikrentcar_orders
LEFT JOIN jostj_vikrentcar_places ON jostj_vikrentcar_orders.idplace=jostj_vikrentcar_places.id AND jostj_vikrentcar_orders.idreturnplace=jostj_vikrentcar_places.id
WHERE  jostj_vikrentcar_orders.custdata!='Car Closed' AND jostj_vikrentcar_orders.ritiro > '$from2'  AND jostj_vikrentcar_orders.ritiro < '$to2' ";
if ($stationid!='0'){
    $sql .="AND jostj_vikrentcar_places.station='$stationid' ";
    }
$result = mysqli_query($db2,$sql);

if ($result->num_rows > 0) {
    // output data of each row
    ?><table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
    <thead>
        <tr>
            <th>Res ID</th>
            <th>Ordered Date</th>
            <th>Client</th>
            <th>Vehicle</th>
            <th>Pick Up Location</th>
            <th>Pick Up Date/Time</th>
           
            <th>Rental Price</th>
            <th>Station</th>
            <th>Source</th>
            <th>Status</th>
            <th>Notes</th>
            <th>Extras</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody><?php
   while($row = mysqli_fetch_array($result)) {
	  	  if ($row["idplace"]!=NULL) {$idplace=$row["idplace"];} else {$idplace="1";}
	   if ($row["idreturnplace"]!=NULL) {$idreturnplace =$row["idreturnplace"];} else {$idreturnplace="1";}
	  $idsource=$row["source"];
	   $idcar=$row["idcar"];
	   
	  $sql4 = $db2->query("SELECT * FROM jostj_vikrentcar_cars WHERE jostj_vikrentcar_cars.id='$idcar' ") or die(mysql_error());
$row5 = mysqli_fetch_array( $sql4 ); 

	  $sql2 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id='$idplace' ");
$row3 = mysqli_fetch_array( $sql2 ); 
$idstatp=$row3['station'];
$sqlst = $db2->query("SELECT * FROM jostj_vikrentcar_stations WHERE jostj_vikrentcar_stations.station_id='$idstatp' ");
$rowst = mysqli_fetch_array( $sqlst ); 

	$sql3 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id='$idreturnplace' ") or die(mysql_error());
$row4 = mysqli_fetch_array( $sql3 );
	   $sql7 = $db2->query("SELECT * FROM jostj_vikrentcar_sources WHERE jostj_vikrentcar_sources.id='$idsource' ") or die(mysql_error());
$row7 = mysqli_fetch_array( $sql7 ); 
if($row['source']==1006){
    $picktime2=strtotime('+2 hours', $row['ritiro'])."@";
    $droptime2=strtotime('+2 hours', $row['consegna'])."@";
    $picktime=date('d/m/Y H:i', $picktime2)."@";
    $droptime=date('d/m/Y H:i', $droptime2)."@";
}
else{
    $picktime=date('d/m/Y H:i', $row['ritiro']);
    $droptime=date('d/m/Y H:i', $row['consegna']);
}
     ?>

                                        <tr>
                                            <td><strong><?php echo $row["orderid"]; ?></strong></td>
                                            <td><?php echo date('d/m/Y H:i', $row['ts']);  ?></td>
                                            <td class="text-center">
                                                <?php if ($row["nominative"]!=NULL) {echo $row['nominative'];} else {echo $row['custdata'];} ?>
                                            </td>
                                            <td class="text-center">
                                                <?php if ($row5['name']!=NULL) {echo $row5['name'];} else {echo "not set";} ?>
                                            </td>

                                            <td class="text-center">
                                                <?php if ($row3["name"]!=NULL) {echo $row3["name"];} else {echo "not set";} ?>
                                            </td>
                                            <td><?php echo $picktime;  ?></td>
                                            
                                            <td><?php echo $row['order_total']; ?>€</td>
                                            <td><?php echo $rowst['station_name']; ?></td>
                                            <td><?php echo $row7['name']; ?></td>
                                            <td
                                                class="<?php if($row["status"]=="cancelled"){echo "red";} elseif($row["status"]=="confirmed") {echo "green";} elseif($row["status"]=="standby"){echo "lightyellow";} elseif($row["status"]=="contract"){echo "lightblue";}?>">
                                                <?php echo $row['status']; ?></td>
                                            <td><?php if (is_null($row['optionals'])) {echo "None";}
                                    else {
                            $st2=explode(';', $row['optionals']);
                        
                        
                            foreach ($st2 as $index=>$value){
                                if ($value == NULL) {
                                    break;
                                }
                        $optionalname=trim(explode(':', $value)[0]);
                        $optionalquant=trim(explode(':', $value)[1]);
                        $sqlopt = $db2->query("SELECT * FROM jostj_vikrentcar_optionals  WHERE jostj_vikrentcar_optionals.id='$optionalname'  ") or die(mysql_error());
                                            $rowopt = mysqli_fetch_array( $sqlopt );
                       if ($row['source']==16){
                        $sqlopt2 = $db->query("SELECT * FROM jos8r_vikrentcar_optionals  WHERE jos8r_vikrentcar_optionals.id='$optionalname'  ") or die(mysql_error());
                        $rowopt2 = mysqli_fetch_array( $sqlopt2 );
                        $optionalvalue=$rowopt2['cost']*$optionalquant;
                       }
                       else{
                           $optionalvalue=$rowopt['cost']*$optionalquant;
                       }                    
                       ?>
                       <span class="<?php if($optionalquant==0){echo "noshow";}?> text-dark" ><?php echo $rowopt['name'];?> X<?php echo $optionalquant;?>, </span>
                   <?php }
                        }
                            ?></td>
                                            
                                            <td><?php echo $row['adminnotes']; ?></td>
                                            <td class="actions">
                                                <a href="reservation.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fa fa-eye"></i></a><?php if($row["status"]=="confirmed"){?>
                                                <a href="newcontract.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fas fa-file-signature"></i></a> <a
                                                    href="resprint.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i class="fas fa-print"></i></a>
                                                <?php } ?>

                                            </td>
                                        </tr>
                                        <?php } } else {echo "<h4 class='text-center'>Nothing to Do Tomorrow!</h4>";}?>
                                    </tbody>
                                </table>
									</div>
								</div>
							</div>
						</div>

						
					</div>
					</div>

</section>

</div>

</div>
<!--returns-->
<div class="row">
                    <div class="col">
                        <section class="card">
                            <header class="card-header">
                                <div class="card-actions">
                                    <a href="#" class="card-action card-action-toggle" data-card-toggle></a>
                                    <a href="#" class="card-action card-action-dismiss" data-card-dismiss></a>
                                </div>

                                <h2 class="card-title">Returns for <?php echo $stationname;?></h2>
                            </header>

                            <div class="card-body">
					<div class="row">
						<div class="col-lg-12">
                          		<div class="tabs tabs-success">
								<ul class="nav nav-tabs nav-justified">
								<li class="nav-item">
										<a class="nav-link" href="#retyesterday" data-toggle="tab"><i class="fas fa-calendar-alt"></i>-1 Yesterday</a>
									</li>
									<li class="nav-item active">
										<a class="nav-link" href="#rettoday" data-toggle="tab"><i class="fas fa-calendar-alt"></i> Today</a>
									</li>
									<li class="nav-item">
										<a class="nav-link" href="#rettomorrow" data-toggle="tab"><i class="fas fa-calendar-alt"></i>+1 Tomorrow</a>
									</li>
								</ul>
								<div class="tab-content">
								<div id="retyesterday" class="tab-pane">
							
                                <?php 
$sql = "SELECT *  FROM contracts
LEFT JOIN jostj_vikrentcar_orders ON jostj_vikrentcar_orders.id=contracts.Res_ref
LEFT JOIN jostj_vikrentcar_places ON jostj_vikrentcar_places.id=jostj_vikrentcar_orders.idreturnplace
LEFT JOIN fleet ON fleet.fleet_id=contracts.vehfleet_id
WHERE contracts.cont_return > '$from1' AND contracts.cont_return < '$to1' ";
if ($stationid!='0'){
    $sql .="AND jostj_vikrentcar_places.station='$stationid' ";
   }
$result = mysqli_query($db2,$sql);

if ($result->num_rows > 0) {
    ?>
    <table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
    <thead>
        <tr>
        <th>Res ID</th>
            
            <th>Client</th>
            <th>Phone</th>
            <th>Vehicle</th>
            <th>Drop Off Location</th>
            <th>Drop Off Date/Time</th>
           
            <th>Balance</th>
            <th>Excess</th>
            <th>Station</th>
           
            
            <th>Res Notes</th>
            <th>Cont Notes</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody><?php
   while($row = mysqli_fetch_array($result)) {
    $droptime=date('d-m-Y H:i', $row['cont_return']);
    $idccar=$row['vehfleet_id'];
    $idstatp=$row['station'];
    $sqlst = $db2->query("SELECT * FROM jostj_vikrentcar_stations WHERE jostj_vikrentcar_stations.station_id='$idstatp' ");
    $rowst = mysqli_fetch_array( $sqlst ); 
    $idreturn=$row['idreturnplace'];
    $sql4r = $db2->query("SELECT * FROM jostj_vikrentcar_cars WHERE jostj_vikrentcar_cars.id='$idccar' ") or die(mysql_error());
$row5r = mysqli_fetch_array( $sql4r ); 
$balance=$row["Contract_value"]-($row["ctotal_paid"]+$row["deposit"]);
     ?>

<tr>
                                            <td><strong><?php echo $row["Res_ref"]." / ".$row["contract_num"]; ?></strong></td>
                                           
                                            <td >
                                                <?php if ($row["nominative"]!=NULL) {echo $row['nominative'];} else {echo $row['custdata'];} ?>
                                            </td>
                                            <td>
                                                <?php if ($row['phone']!=NULL) {echo $row['phone'];} else {echo "not set";} ?>
                                            </td>
                                            <td >
                                                <?php echo $row['lic_num']."<br>".$row5r['name']; ?>
                                            </td>

                                            <td class="text-center">
                                                <?php if ($row4["name"]!=NULL) {echo $row4["name"];} else {echo "not set";} ?>
                                            </td>
                                            <td><?php echo $droptime;  ?></td>
                                            
                                            <td><?php echo $balance;?>€</td>
                                           
                                            <td><?php if ($row['employee']==10) {
                                        $apsoure= $row['source'];
                                                    $sqlac = $db2->query("SELECT * FROM api_fleet WHERE api_fleet.api_fleet_partner='$apsoure' AND api_fleet.api_fleet_idcar='$idcar' ") or die(mysql_error());
                                                    $rowac = mysqli_fetch_array( $sqlac );
                                                    echo $rowac['api_fleet_acriss']." / ";  
                                                 } 
                                        if ($row['source']==16){ 
                                            $webid=$row['webid'];
                                            $sqtar = $db->query("SELECT * FROM jos8r_vikrentcar_orders LEFT JOIN jos8r_vikrentcar_dispcost ON jos8r_vikrentcar_dispcost.id=jos8r_vikrentcar_orders.idtar  WHERE jos8r_vikrentcar_orders.id='$webid'  ") or die(mysql_error());
                                            $rowtar = mysqli_fetch_array( $sqtar );
                                            $priceid=$rowtar['idprice'];
                                            $sqtar2 = $db->query("SELECT * FROM jos8r_vikrentcar_prices  WHERE jos8r_vikrentcar_prices.id='$priceid'  ") or die(mysql_error());
                                            $rowtar2 = mysqli_fetch_array( $sqtar2 );
                                            echo $rowtar2['name']." / ".$rowtar['attrdata'];
                                            
                                            } else{ 
                                                echo $row['idtar'];
                                                      }     ?></td>
                                                       <td><?php echo $rowst['station_name']; ?></td>
                                                                                     
                                            
                                            <td><?php echo $row['adminnotes']; ?></td>
                                            <td >
                                                <?php echo $row['cont_notes']; ?>
                                            </td>
                                            <td class="actions">
                                                <a href="reservation.php?id=<?php echo $row["Res_ref"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fa fa-eye"></i></a><?php if($row["status"]=="confirmed"){?>
                                                <a href="newcontract.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fas fa-file-signature"></i></a> <a
                                                    href="resprint.php?id=<?php echo $row["Res_ref"];?>"
                                                    class="on-default edit-row"><i class="fas fa-print"></i></a>
                                                <?php } ?>

                                            </td>
                                        </tr>
                                        <?php } } else {echo "<h4 class='text-center'>Did Nothing Yesterday!</h4>";}?>
                                    </tbody>
                                </table>
									</div>
									<div id="rettoday" class="tab-pane active">
                                 
                                    <?php 
$sql = "SELECT *  FROM contracts
LEFT JOIN jostj_vikrentcar_orders ON jostj_vikrentcar_orders.id=contracts.Res_ref
LEFT JOIN jostj_vikrentcar_places ON jostj_vikrentcar_places.id=jostj_vikrentcar_orders.idreturnplace
LEFT JOIN fleet ON fleet.fleet_id=contracts.vehfleet_id
WHERE contracts.cont_return > '$from' AND contracts.cont_return < '$to' ";
if ($stationid!='0'){
    $sql .="AND jostj_vikrentcar_places.station='$stationid' ";
   }
$result = mysqli_query($db2,$sql);

if ($result->num_rows > 0) {
    ?>
    <table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
    <thead>
        <tr>
        <th>Res ID</th>
            
            <th>Client</th>
            <th>Phone</th>
            <th>Vehicle</th>
            <th>Drop Off Location</th>
            <th>Drop Off Date/Time</th>
           
            <th>Balance</th>
            <th>Excess</th>
            <th>Station</th>
           
            
            <th>Res Notes</th>
            <th>Cont Notes</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody><?php
   while($row = mysqli_fetch_array($result)) {
    $droptime=date('d-m-Y H:i', $row['cont_return']);
    $idccar=$row['vehfleet_id'];
    $idstatp=$row['station'];
    $sqlst = $db2->query("SELECT * FROM jostj_vikrentcar_stations WHERE jostj_vikrentcar_stations.station_id='$idstatp' ");
    $rowst = mysqli_fetch_array( $sqlst ); 
    $idreturn=$row['idreturnplace'];
    $sql4r = $db2->query("SELECT * FROM jostj_vikrentcar_cars WHERE jostj_vikrentcar_cars.id='$idccar' ") or die(mysql_error());
$row5r = mysqli_fetch_array( $sql4r ); 
$balance=$row["Contract_value"]-($row["ctotal_paid"]+$row["deposit"]);
     ?>

<tr>
                                            <td><strong><?php echo $row["Res_ref"]." / ".$row["contract_num"]; ?></strong></td>
                                           
                                            <td >
                                                <?php if ($row["nominative"]!=NULL) {echo $row['nominative'];} else {echo $row['custdata'];} ?>
                                            </td>
                                            <td>
                                                <?php if ($row['phone']!=NULL) {echo $row['phone'];} else {echo "not set";} ?>
                                            </td>
                                            <td >
                                                <?php echo $row['lic_num']."<br>".$row5r['name']; ?>
                                            </td>

                                            <td class="text-center">
                                                <?php if ($row4["name"]!=NULL) {echo $row4["name"];} else {echo "not set";} ?>
                                            </td>
                                            <td><?php echo $droptime;  ?></td>
                                            
                                            <td><?php echo $balance;?>€</td>
                                           
                                            <td><?php if ($row['employee']==10) {
                                        $apsoure= $row['source'];
                                                    $sqlac = $db2->query("SELECT * FROM api_fleet WHERE api_fleet.api_fleet_partner='$apsoure' AND api_fleet.api_fleet_idcar='$idcar' ") or die(mysql_error());
                                                    $rowac = mysqli_fetch_array( $sqlac );
                                                    echo $rowac['api_fleet_acriss']." / ";  
                                                 } 
                                        if ($row['source']==16){ 
                                            $webid=$row['webid'];
                                            $sqtar = $db->query("SELECT * FROM jos8r_vikrentcar_orders LEFT JOIN jos8r_vikrentcar_dispcost ON jos8r_vikrentcar_dispcost.id=jos8r_vikrentcar_orders.idtar  WHERE jos8r_vikrentcar_orders.id='$webid'  ") or die(mysql_error());
                                            $rowtar = mysqli_fetch_array( $sqtar );
                                            $priceid=$rowtar['idprice'];
                                            $sqtar2 = $db->query("SELECT * FROM jos8r_vikrentcar_prices  WHERE jos8r_vikrentcar_prices.id='$priceid'  ") or die(mysql_error());
                                            $rowtar2 = mysqli_fetch_array( $sqtar2 );
                                            echo $rowtar2['name']." / ".$rowtar['attrdata'];
                                            
                                            } else{ 
                                                echo $row['idtar'];
                                                      }     ?></td>
                                                       <td><?php echo $rowst['station_name']; ?></td>
                                                                                     
                                            
                                            <td><?php echo $row['adminnotes']; ?></td>
                                            <td >
                                                <?php echo $row['cont_notes']; ?>
                                            </td>
                                            <td class="actions">
                                                <a href="reservation.php?id=<?php echo $row["Res_ref"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fa fa-eye"></i></a><?php if($row["status"]=="confirmed"){?>
                                                <a href="newcontract.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fas fa-file-signature"></i></a> <a
                                                    href="resprint.php?id=<?php echo $row["Res_ref"];?>"
                                                    class="on-default edit-row"><i class="fas fa-print"></i></a>
                                                <?php } ?>

                                            </td>
                                        </tr>
                                        <?php } } else {echo "<h4 class='text-center'>Nothing to Do Today!</h4>";}?>
                                    </tbody>
                                </table>
									</div>
									
									<div id="rettomorrow" class="tab-pane">
                                    
                                    <?php 
$sql = "SELECT *  FROM contracts
LEFT JOIN jostj_vikrentcar_orders ON jostj_vikrentcar_orders.id=contracts.Res_ref
LEFT JOIN jostj_vikrentcar_places ON jostj_vikrentcar_places.id=jostj_vikrentcar_orders.idreturnplace
LEFT JOIN fleet ON fleet.fleet_id=contracts.vehfleet_id
WHERE contracts.cont_return > '$from2' AND contracts.cont_return < '$to2' ";
if ($stationid!='0'){
    $sql .="AND jostj_vikrentcar_places.station='$stationid' ";
   }
$result = mysqli_query($db2,$sql);

if ($result->num_rows > 0) {
    ?>
    <table class="table table-bordered table-striped mb-0" id="datatable-tabletools">
    <thead>
        <tr>
        <th>Res ID</th>
            
            <th>Client</th>
            <th>Phone</th>
            <th>Vehicle</th>
            <th>Drop Off Location</th>
            <th>Drop Off Date/Time</th>
           
            <th>Balance</th>
            <th>Excess</th>
            <th>Station</th>
           
            
            <th>Res Notes</th>
            <th>Cont Notes</th>
            <th>Action</th>
        </tr>
    </thead>
    <tbody><?php
   while($row = mysqli_fetch_array($result)) {
    $droptime=date('d-m-Y H:i', $row['cont_return']);
    $idccar=$row['vehfleet_id'];
    $idstatp=$row['station'];
    $sqlst = $db2->query("SELECT * FROM jostj_vikrentcar_stations WHERE jostj_vikrentcar_stations.station_id='$idstatp' ");
    $rowst = mysqli_fetch_array( $sqlst ); 
    $idreturn=$row['idreturnplace'];
    $sql4r = $db2->query("SELECT * FROM jostj_vikrentcar_cars WHERE jostj_vikrentcar_cars.id='$idccar' ") or die(mysql_error());
$row5r = mysqli_fetch_array( $sql4r ); 
$balance=$row["Contract_value"]-($row["ctotal_paid"]+$row["deposit"]);
     ?>

<tr>
                                            <td><strong><?php echo $row["Res_ref"]." / ".$row["contract_num"]; ?></strong></td>
                                           
                                            <td >
                                                <?php if ($row["nominative"]!=NULL) {echo $row['nominative'];} else {echo $row['custdata'];} ?>
                                            </td>
                                            <td>
                                                <?php if ($row['phone']!=NULL) {echo $row['phone'];} else {echo "not set";} ?>
                                            </td>
                                            <td >
                                                <?php echo $row['lic_num']."<br>".$row5r['name']; ?>
                                            </td>

                                            <td class="text-center">
                                                <?php if ($row4["name"]!=NULL) {echo $row4["name"];} else {echo "not set";} ?>
                                            </td>
                                            <td><?php echo $droptime;  ?></td>
                                            
                                            <td><?php echo $balance;?>€</td>
                                           
                                            <td><?php if ($row['employee']==10) {
                                        $apsoure= $row['source'];
                                                    $sqlac = $db2->query("SELECT * FROM api_fleet WHERE api_fleet.api_fleet_partner='$apsoure' AND api_fleet.api_fleet_idcar='$idcar' ") or die(mysql_error());
                                                    $rowac = mysqli_fetch_array( $sqlac );
                                                    echo $rowac['api_fleet_acriss']." / ";  
                                                 } 
                                        if ($row['source']==16){ 
                                            $webid=$row['webid'];
                                            $sqtar = $db->query("SELECT * FROM jos8r_vikrentcar_orders LEFT JOIN jos8r_vikrentcar_dispcost ON jos8r_vikrentcar_dispcost.id=jos8r_vikrentcar_orders.idtar  WHERE jos8r_vikrentcar_orders.id='$webid'  ") or die(mysql_error());
                                            $rowtar = mysqli_fetch_array( $sqtar );
                                            $priceid=$rowtar['idprice'];
                                            $sqtar2 = $db->query("SELECT * FROM jos8r_vikrentcar_prices  WHERE jos8r_vikrentcar_prices.id='$priceid'  ") or die(mysql_error());
                                            $rowtar2 = mysqli_fetch_array( $sqtar2 );
                                            echo $rowtar2['name']." / ".$rowtar['attrdata'];
                                            
                                            } else{ 
                                                echo $row['idtar'];
                                                      }     ?></td>
                                                       <td><?php echo $rowst['station_name']; ?></td>
                                                                                     
                                            
                                            <td><?php echo $row['adminnotes']; ?></td>
                                            <td >
                                                <?php echo $row['cont_notes']; ?>
                                            </td>
                                            <td class="actions">
                                                <a href="reservation.php?id=<?php echo $row["Res_ref"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fa fa-eye"></i></a><?php if($row["status"]=="confirmed"){?>
                                                <a href="retcontract.php?id=<?php echo $row["contract_id"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fas fa-file-signature"></i></a> <a
                                                    href="resprint.php?id=<?php echo $row["Res_ref"];?>"
                                                    class="on-default edit-row"><i class="fas fa-print"></i></a>
                                                <?php } ?>

                                            </td>
                                        </tr>
                                        <?php } } else {echo "<h4 class='text-center'>Nothing to Do Tomorrow!</h4>";}?>
                                    </tbody>
                                </table>
									</div>
								</div>
							</div>
						</div>

						
					</div>
					</div>

</section>

</div>

</div>
<!--returns-->
					<!-- end: page -->
				</section>
			</div>

			<?php include('include/aside.php');?>

		</section>

		<!-- Vendor -->
		<script src="vendor/jquery/jquery.js"></script>
		<script src="vendor/jquery-browser-mobile/jquery.browser.mobile.js"></script>
		<script src="vendor/popper/umd/popper.min.js"></script>
		<script src="vendor/bootstrap/js/bootstrap.js"></script>
		<script src="vendor/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
		<script src="vendor/common/common.js"></script>
		<script src="vendor/nanoscroller/nanoscroller.js"></script>
		<script src="vendor/magnific-popup/jquery.magnific-popup.js"></script>
		<script src="vendor/jquery-placeholder/jquery.placeholder.js"></script>
		
		<!-- Specific Page Vendor -->
		<script src="vendor/jquery-ui/jquery-ui.js"></script>
		<script src="vendor/jqueryui-touch-punch/jquery.ui.touch-punch.js"></script>
		<script src="vendor/jquery-appear/jquery.appear.js"></script>
		<script src="vendor/bootstrap-multiselect/js/bootstrap-multiselect.js"></script>
		<script src="vendor/jquery.easy-pie-chart/jquery.easypiechart.js"></script>
		<script src="vendor/flot/jquery.flot.js"></script>
		<script src="vendor/flot.tooltip/jquery.flot.tooltip.js"></script>
		<script src="vendor/flot/jquery.flot.pie.js"></script>
		<script src="vendor/flot/jquery.flot.categories.js"></script>
		<script src="vendor/flot/jquery.flot.resize.js"></script>
		<script src="vendor/jquery-sparkline/jquery.sparkline.js"></script>
		<script src="vendor/raphael/raphael.js"></script>
		<script src="vendor/morris/morris.js"></script>
		<script src="vendor/gauge/gauge.js"></script>
		<script src="vendor/snap.svg/snap.svg.js"></script>
		<script src="vendor/liquid-meter/liquid.meter.js"></script>
		<script src="vendor/jqvmap/jquery.vmap.js"></script>
		<script src="vendor/jqvmap/data/jquery.vmap.sampledata.js"></script>
		<script src="vendor/jqvmap/maps/jquery.vmap.world.js"></script>
		<script src="vendor/jqvmap/maps/continents/jquery.vmap.africa.js"></script>
		<script src="vendor/jqvmap/maps/continents/jquery.vmap.asia.js"></script>
		<script src="vendor/jqvmap/maps/continents/jquery.vmap.australia.js"></script>
		<script src="vendor/jqvmap/maps/continents/jquery.vmap.europe.js"></script>
		<script src="vendor/jqvmap/maps/continents/jquery.vmap.north-america.js"></script>
		<script src="vendor/jqvmap/maps/continents/jquery.vmap.south-america.js"></script>


		<!--(remove-empty-lines-end)-->
		
		<!-- Theme Base, Components and Settings -->
		<script src="js/theme.js"></script>
		
		<!-- Theme Custom -->
		<script src="js/custom.js"></script>
		
		<!-- Theme Initialization Files -->
		<script src="js/theme.init.js"></script>

		<!-- Examples -->
		<script src="js/examples/examples.dashboard.js"></script>

	</body>
</html>
<?php include('include/footer.php');?>