					<!-- start: page -->
                    <div class="row mb-3">
                            <h3>Filters</h3>
                            <div class="col-md-auto"> <label>Reservation Status</label>
                        <select data-plugin-selectTwo class="form-control populate"
                            onChange="window.location.href=this.value">
                            <option value="?<?php echo http_build_query(array_merge($_GET, array("status"=>'0')))?>"
                                <?php if($status=='0') { echo "selected";} ?>>
                                All</option>
                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("status"=>"confirmed")))?>"
                                <?php if($status=="confirmed") { echo "selected";} ?>>
                                Confirmed</option>
                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("status"=>"standby")))?>"
                                <?php if($status=="standby") { echo "selected";} ?>>
                                StandBy</option>
                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("status"=>"cancelled")))?>"
                                <?php if($status=="cancelled") { echo "selected";} ?>>
                                Cancelled</option>
                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("status"=>"contract")))?>"
                                <?php if($status=="contract") { echo "selected";} ?>>
                                Contract</option>

                        </select>
                    </div>
                    <?php if ($stationid=='0'){?>
                    <div class="col-md-auto"> <label>Station (Res & Ret)</label>
                        <select data-plugin-selectTwo class="form-control populate"
                            onChange="window.location.href=this.value">
                            <option value="?<?php echo http_build_query(array_merge($_GET, array("stationid2"=>0)))?>"
                                <?php if($stationid2==0) { echo "selected";} ?>>
                                All</option>
                            <?php $sqlinst = $db2->query("SELECT * FROM jostj_vikrentcar_stations ") or die(mysql_error()); 
					 while($rowinst = mysqli_fetch_array($sqlinst)) {
                        
                         ?>
                            <option
                                value="?<?php echo http_build_query(array_merge($_GET, array("stationid2"=>$rowinst['station_id'])))?>"
                                <?php if($stationid2==$rowinst['station_id']) { echo "selected";} ?>>
                                <?php echo $rowinst['station_name'];?></option>
                            <?php } ?>

                        </select>
                    </div>
                    <?php }?>
                </div>
					<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 
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' ";
    }
else{
    if ($stationid2!='0'){
        $sql .="AND jostj_vikrentcar_places.station='$stationid2' ";
        }
}
    if ($status!='0'){
        $sql .=" AND jostj_vikrentcar_orders.status='$status'  ";
        }
    $sql .="ORDER BY jostj_vikrentcar_orders.ritiro ASC ";
$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 = ($row['source']==1006) ? date('d/m/Y H:i', strtotime('+2 hours', $row['ritiro'])) . '@' : date('d/m/Y H:i', $row['ritiro']);
    $droptime = ($row['source']==1006) ? date('d/m/Y H:i', strtotime('+2 hours', $row['consegna'])) . '@' : date('d/m/Y H:i', $row['consegna']);
}
     ?>

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

                                            <td class="text-center <?php if($row['status']=="cancelled"){echo "canc";}?>">
                                                <?php if ($row3["name"]!=NULL) {echo $row3["name"];} else {echo "not set";} ?>
                                            </td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $picktime;  ?></td>
                                            
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $row['order_total']; ?>€</td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $rowst['station_name']; ?></td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $row7['name']; ?></td>
                                            <td
                                                class="<?php if($row["status"]=="cancelled"){echo "canc";} elseif($row["status"]=="confirmed") {echo "green";} elseif($row["status"]=="standby"){echo "lightyellow";} elseif($row["status"]=="contract"){echo "lightblue";}?>">
                                                <?php echo $row['status']; ?></td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?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=(float)$rowopt2['cost']*(int)$optionalquant;
                       }
                       else{
                           $optionalvalue=(float)$rowopt['cost']*(int)$optionalquant;
                       }                    
                       ?>
                       <span class="<?php if($optionalquant==0){echo "noshow";}?> text-dark" ><?php echo $rowopt['name'];?> X<?php echo $optionalquant;?>, </span>
                   <?php }
                        }
                            ?></td>
                                            
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?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="contractselect.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 
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' ";
    }
    else{
        if ($stationid2!='0'){
            $sql .="AND jostj_vikrentcar_places.station='$stationid2' ";
            }
    }
    if ($status!='0'){
        $sql .=" AND jostj_vikrentcar_orders.status='$status'  ";
        }
    $sql .="ORDER BY jostj_vikrentcar_orders.ritiro ASC ";
$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 = ($row['source']==1006) ? date('d/m/Y H:i', strtotime('+2 hours', $row['ritiro'])) . '@' : date('d/m/Y H:i', $row['ritiro']);
    $droptime = ($row['source']==1006) ? date('d/m/Y H:i', strtotime('+2 hours', $row['consegna'])) . '@' : date('d/m/Y H:i', $row['consegna']);
}
     ?>

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

                                            <td class="text-center <?php if($row['status']=="cancelled"){echo "canc";}?>">
                                                <?php if ($row3["name"]!=NULL) {echo $row3["name"];} else {echo "not set";} ?>
                                            </td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $picktime;  ?></td>
                                            
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $row['order_total']; ?>€</td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $rowst['station_name']; ?></td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $row7['name']; ?></td>
                                            <td
                                                class="<?php if($row["status"]=="cancelled"){echo "canc";} elseif($row["status"]=="confirmed") {echo "green";} elseif($row["status"]=="standby"){echo "lightyellow";} elseif($row["status"]=="contract"){echo "lightblue";}?>">
                                                <?php echo $row['status']; ?></td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?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=(float)$rowopt2['cost']*(int)$optionalquant;
                       }
                       else{
                           $optionalvalue=(float)$rowopt['cost']*(int)$optionalquant;
                       }                    
                       ?>
                       <span class="<?php if($optionalquant==0){echo "noshow";}?> text-dark" ><?php echo $rowopt['name'];?> X<?php echo $optionalquant;?>, </span>
                   <?php }
                        }
                            ?></td>
                                            
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?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="contractselect.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 
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' ";
    }
    else{
        if ($stationid2!='0'){
            $sql .="AND jostj_vikrentcar_places.station='$stationid2' ";
            }
    }
    if ($status!='0'){
        $sql .=" AND jostj_vikrentcar_orders.status='$status'  ";
        }
    $sql .="ORDER BY jostj_vikrentcar_orders.ritiro ASC ";
$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 = ($row['source']==1006) ? date('d/m/Y H:i', strtotime('+2 hours', $row['ritiro'])) . '@' : date('d/m/Y H:i', $row['ritiro']);
    $droptime = ($row['source']==1006) ? date('d/m/Y H:i', strtotime('+2 hours', $row['consegna'])) . '@' : date('d/m/Y H:i', $row['consegna']);
}
     ?>

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

                                            <td class="text-center <?php if($row['status']=="cancelled"){echo "canc";}?>">
                                                <?php if ($row3["name"]!=NULL) {echo $row3["name"];} else {echo "not set";} ?>
                                            </td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $picktime;  ?></td>
                                            
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $row['order_total']; ?>€</td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $rowst['station_name']; ?></td>
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?php echo $row7['name']; ?></td>
                                            <td
                                                class="<?php if($row["status"]=="cancelled"){echo "canc";} elseif($row["status"]=="confirmed") {echo "green";} elseif($row["status"]=="standby"){echo "lightyellow";} elseif($row["status"]=="contract"){echo "lightblue";}?>">
                                                <?php echo $row['status']; ?></td>
                                            <td  class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?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= (float)$rowopt2['cost']*(int)$optionalquant;
                       }
                       else{
                          $optionalvalue = (float)$rowopt['cost'] * (int)$optionalquant;
                       }                    
                       ?>
                       <span class="<?php if($optionalquant==0){echo "noshow";}?> text-dark" ><?php echo $rowopt['name'];?> X<?php echo $optionalquant;?>, </span>
                   <?php }
                        }
                            ?></td>
                                            
                                            <td class="<?php if($row['status']=="cancelled"){echo "canc";}?>"><?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="contractselect.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' AND contracts.cont_cancelled=0 ";
if ($stationid!='0'){
    $sql .="AND jostj_vikrentcar_places.station='$stationid' ";
   }
   else{
    if ($stationid2!='0'){
        $sql .="AND jostj_vikrentcar_places.station='$stationid2' ";
        }
}
   $sql .=" ORDER BY contracts.cont_return asc ";
$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>Fuel</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'];
    $sql3 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id='$idreturn' ") or die(mysql_error());
    $row4 = mysqli_fetch_array( $sql3 );
    $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 class="<?php if($row['returned']=="1"){echo "done";}?>">
                                            <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 if ($row['cont_veh_change']==0){echo $row['lic_num'];} else{
                                                                        $contid=$row['contract_id'];
 $sqlvx = $db2->query("SELECT * FROM veh_change  LEFT JOIN fleet ON fleet.fleet_id=veh_change.veh_id LEFT JOIN jostj_vikrentcar_cars ON jostj_vikrentcar_cars.id=fleet.veh_id WHERE veh_change.contract_id=$contid ") or die(mysql_error());
 $rowvx = mysqli_fetch_array( $sqlvx );
 echo $rowvx['lic_num']."*";
                                                                    } ?>
                                            </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 );
                                           
                                                 } 
                                        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 >
                                                
                                                <?php echo $row['cont_fuel_out']; ?>
                                                
                                            </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="contractselect.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 }  if($row['returned']=="0"){?>
                                                <a href="actions/contreturn.php?id=<?php echo $row["contract_id"];?>&resid=<?php echo $row["Res_ref"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fas fa-undo"></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' AND contracts.cont_cancelled=0 ";
if ($stationid!='0'){
    $sql .="AND jostj_vikrentcar_places.station='$stationid' ";
   }
   else{
    if ($stationid2!='0'){
        $sql .="AND jostj_vikrentcar_places.station='$stationid2' ";
        }
}
   $sql .=" ORDER BY contracts.cont_return asc ";
$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>Fuel</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'];
    $sql3 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id='$idreturn' ") or die(mysql_error());
    $row4 = mysqli_fetch_array( $sql3 );
    $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 class="<?php if($row['returned']=="1"){echo "done";}?>">
                                            <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 if ($row['cont_veh_change']==0){echo $row['lic_num'];} else{
                                                                        $contid=$row['contract_id'];
 $sqlvx = $db2->query("SELECT * FROM veh_change  LEFT JOIN fleet ON fleet.fleet_id=veh_change.veh_id LEFT JOIN jostj_vikrentcar_cars ON jostj_vikrentcar_cars.id=fleet.veh_id WHERE veh_change.contract_id=$contid ") or die(mysql_error());
 $rowvx = mysqli_fetch_array( $sqlvx );
 echo $rowvx['lic_num']."*";
                                                                    } ?>
                                            </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 );
                                                   
                                                 } 
                                        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 >
                                                
                                                <?php echo $row['cont_fuel_out']; ?>
                                                
                                            </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="contractselect.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 }  if($row['returned']=="0"){?>
                                                <a href="actions/contreturn.php?id=<?php echo $row["contract_id"];?>&resid=<?php echo $row["Res_ref"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fas fa-undo"></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' AND contracts.cont_cancelled=0 ";
if ($stationid!='0'){
    $sql .="AND jostj_vikrentcar_places.station='$stationid' ";
   }
   else{
    if ($stationid2!='0'){
        $sql .="AND jostj_vikrentcar_places.station='$stationid2' ";
        }
}
   $sql .=" ORDER BY contracts.cont_return asc ";
$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>Fuel</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'];
    $sql3 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id='$idreturn' ") or die(mysql_error());
    $row4 = mysqli_fetch_array( $sql3 );
    $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 class="<?php if($row['returned']=="1"){echo "done";}?>">
                                            <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 if ($row['cont_veh_change']==0){echo $row['lic_num'];} else{
                                                                        $contid=$row['contract_id'];
 $sqlvx = $db2->query("SELECT * FROM veh_change  LEFT JOIN fleet ON fleet.fleet_id=veh_change.veh_id LEFT JOIN jostj_vikrentcar_cars ON jostj_vikrentcar_cars.id=fleet.veh_id WHERE veh_change.contract_id=$contid ") or die(mysql_error());
 $rowvx = mysqli_fetch_array( $sqlvx );
 echo $rowvx['lic_num']."*";
                                                                    } ?>
                                            </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 );
                                                   
                                                 } 
                                        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 >
                                                
                                                <?php echo $row['cont_fuel_out']; ?>
                                                
                                            </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 }  if($row['returned']=="0"){?>
                                                <a href="actions/contreturn.php?id=<?php echo $row["contract_id"];?>&resid=<?php echo $row["Res_ref"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fas fa-undo"></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">Last 10 API Cancellations</h2>
                            </header>

                            <div class="card-body">

                                <table class="table table-bordered table-striped mb-0" id="datatable-tabletools3">
                                    <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>Drop Off Location</th>

                                            <th>Drop Off Date/Time</th>
                                            <th>Rental Price</th>
                                            <th>Station</th>
                                            <th>Source</th>
                                            <th>Status</th>
                                            <th>Notes</th>
                                            <th>Timestamp</th>
                                            <th>Action</th>
                                        </tr>
                                    </thead>
                                    <tbody>

                                                                            <?php 
                                    $sql = "SELECT 
    jostj_vikrentcar_orders.id AS orderid, 
    jostj_vikrentcar_orders.*, 
    p1.name AS pickup_place_name, 
    p2.name AS return_place_name
FROM 
    jostj_vikrentcar_orders
LEFT JOIN jostj_vikrentcar_places AS p1 
    ON jostj_vikrentcar_orders.idplace = p1.id
LEFT JOIN jostj_vikrentcar_places AS p2 
    ON jostj_vikrentcar_orders.idreturnplace = p2.id
WHERE  
    jostj_vikrentcar_orders.cancelnotes IS NOT NULL
    AND jostj_vikrentcar_orders.seen = 0";
                                                    
                                    $result = mysqli_query($db2,$sql);

                                    if ($result->num_rows > 0) {
                                        // output data of each row
                                    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 = ($row['source']==1006) ? date('d/m/Y H:i', strtotime('+2 hours', $row['ritiro'])) . '@' : date('d/m/Y H:i', $row['ritiro']);
                                        $droptime = ($row['source']==1006) ? date('d/m/Y H:i', strtotime('+2 hours', $row['consegna'])) . '@' : date('d/m/Y H:i', $row['consegna']);
                                    }
                                   $st2= explode('-', $row['cancelnotes']);
                                    $tdate1=$st2[1];
                                   
                                    $tdate=substr($tdate1,19);
                                    $t_date= strtotime(str_replace('/', '-', $tdate));
                                        ?>

                                        <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 if ($row4['name']!=NULL) {echo $row4['name'];} else {echo "not set";} ?>
                                            </td>
                                            <td><?php echo $droptime;  ?></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 echo $row['cancelnotes']; ?></td>
                                            <td><?php echo $t_date; ?></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>

                                                <a href="actions/checkapicancellation.php?id=<?php echo $row["orderid"];?>"
                                                    class="on-default edit-row"><i
                                                        class="fa fa-check"></i></a> 
                                             

                                            </td>
                                        </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </div>

                        </section>

                    </div>
                </div>
                <?php } ?>
					<!-- end: page -->
				