<?php 

include('include/auth.php');?>
<!doctype html>
<html class="fixed dark">
<?php 

   // $fid=$_GET['id'];
    $car=$_GET['car'];
    $datechanged=$_GET['d'];
    $vehchanged=$_GET['v'];
    $pagerole="user";
	include('include/head.php');
    if (isset($_GET['id'])  && $_GET['id']!='0') {
        $fid=$_GET['id'];
        $sql = $db2->query("SELECT * FROM jostj_vikrentcar_orders WHERE jostj_vikrentcar_orders.id='$fid' ") or die(mysql_error());
    $row = mysqli_fetch_array( $sql );
    }
    else {
        $fid2=$_GET['webid'];
        $sql = $db2->query("SELECT * FROM jostj_vikrentcar_orders WHERE jostj_vikrentcar_orders.webid='$fid2' ") or die(mysql_error());
    $row = mysqli_fetch_array( $sql );
    $fid=$row['id'];
    }
    $sql = $db2->query("SELECT * FROM jostj_vikrentcar_orders WHERE jostj_vikrentcar_orders.id='$fid' ") or die(mysql_error());
    $row = mysqli_fetch_array( $sql );

    $idcar=$row["idcar"];
    $idplace=$row["idplace"];
    $idreturnplace =$row["idreturnplace"];
$hour     = abs((int)$row['consegna'] - (int)$row['ritiro']) / 3600;
$disfunct = "disabled";
$custdata = $row['custdata'];

// 1) Start from base timestamps (int). If contract has a specific return date, use it.
$base_pick_ts = (int)$row['ritiro'];
$base_drop_ts = (int)$row['consegna'];
$rowccc = null;

if ($row['status'] === 'contract') {
    $sqlccc = $db2->query("SELECT * FROM contracts WHERE contracts.Res_ref='$fid' ") or die($db2->error);
    $rowccc = mysqli_fetch_array($sqlccc);
    if (!empty($rowccc) && (int)$rowccc['cont_return'] > 0) {
        $base_drop_ts = (int)$rowccc['cont_return'];
    }
}

// 2) Apply +2h if source is 1006 (whether it's contract or not)
$append_star = '';
$pickdet = '';
$dropdet = '';

if ((int)$row['source'] === 1006) {
    $adj_pick_ts = strtotime('+2 hours', $base_pick_ts);
    $adj_drop_ts = strtotime('+2 hours', $base_drop_ts);

    if ($adj_pick_ts !== false) $base_pick_ts = $adj_pick_ts;
    if ($adj_drop_ts !== false) $base_drop_ts = $adj_drop_ts;

    $append_star = '*';
    $pickdet = '*Time Auto Adjusted. Original time was: ' . date('H:i', (int)$row['ritiro']);

    $orig_drop_ts = (isset($rowccc['cont_return']) && (int)$rowccc['cont_return'] > 0)
        ? (int)$rowccc['cont_return']
        : (int)$row['consegna'];
    $dropdet = '*Time Auto Adjusted. Original time was: ' . date('H:i', $orig_drop_ts);
}

// 3) Final formatted strings
$picktime = date('d-m-Y H:i', $base_pick_ts) . $append_star;
$droptime = date('d-m-Y H:i', $base_drop_ts) . $append_star;
    if (is_null($row['totpaid']) || $row['totpaid']==0.00) {
$resttopay=$row['order_total'];
    }
    else{
       if(is_null($row['cust_cost']) || $row['cust_cost']==0.00){
           $resttopay=$row['order_total']-$row['totpaid'];
       } 
       else{
           $resttopay=$row['cust_cost'];
       }
    }
      
    $sql2 = $db2->query("SELECT * FROM jostj_vikrentcar_cars WHERE jostj_vikrentcar_cars.id=$idcar ") or die(mysql_error());
    $row2 = mysqli_fetch_array( $sql2 ); 
     
    $sql3 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id=$idplace ");
    $row3 = mysqli_fetch_array( $sql3 ); 
           
    $sql4 = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id=$idreturnplace ") or die(mysql_error());
    $row4 = mysqli_fetch_array( $sql4 );

    $emid=$row['employee'];
    $sqlem = $db2->query("SELECT * FROM jostj_vikrentcar_employees  WHERE jostj_vikrentcar_employees.id='$emid'  ") or die(mysql_error());
    $rowem = mysqli_fetch_array( $sqlem );
		?>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/rome/3.0.2/rome.css"
    integrity="sha512-TAAJeGIyqkrJ4o4ZkIPesmqNKH9zowoRBGHkHUf1s4vWeII8Dv3NayKIq8Hws02HWT3OpocxeSaOQEQo9SH7ZQ=="
    crossorigin="anonymous" />
<style>
    .ecommerce-timeline:before {

        box-shadow: none !important;
    }

    .ecommerce-timeline:after {

        box-shadow: none !important;
    }

    .editbutton {
        position: absolute;
        right: 15px;
        top: 10px;
    }

    .editnotes {
        position: absolute;
        right: 15px;
        bottom: 10px;
    }

    .rd-container-attachment {
        z-index: 10002;
        zoom: 80%
    }

    .modal {
        max-width: 90%;
    }
</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');?>
            <!-- end: sidebar -->

            <section role="main" class="content-body">
                <header class="page-header">
                    <h2>#<?php echo $row['id'];?> Reservation
                        <?php if ($row['source']==16) {echo "/ Web ID: ".$row['webid'];}?></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>#<?php echo $row['id'];?> Reservation </span></li>
                        </ol>

                        <a class="sidebar-right-toggle" data-open="sidebar-right"><i
                                class="fas fa-chevron-left"></i></a>
                    </div>
                </header>

                <!-- start: page -->
                <form class="order-details action-buttons-fixed" action="reservation.php?id=<?php echo $fid;?>"
                    method="post" name="form1">

                    <div class="row">
                        <?php if ($datechanged=="yes"){?>
                        <div class="col-12 mb-3 ">
                            <div class="alert alert-danger">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <strong>Pick Up / Drop Off Details Changed!</strong> Do you want to ? <a
                                    href="#modalFinance" class="alert-link modal-basic">Change Reservation Cost</a>?
                            </div>
                        </div>
                        <?php }?>
                        <?php if ($vehchanged=="yes"){?>
                        <div class="col-12 mb-3 ">
                            <div class="alert alert-danger">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                                <strong>Vehicle Changed!</strong> Do you want to ? <a href="#modalFinance"
                                    class="alert-link modal-basic">Change Reservation Cost</a>?
                            </div>
                        </div>
                        <?php }?>

                        <div class="col-xl-4 mb-3 ">

                            <div class="card ">
                                <div class="card-header">
                                    <h2 class="card-title">General</h2>
                                </div>
                                <div class="card-body">
                                    <div class="form-row">
                                        <div class="form-group col-8 mb-3">
                                            <label>Status</label>
                                            <select class="form-control form-control-modern" name="orderStatus"
                                                <?php echo $disfunct;?>>

                                                <option value="on-hold"
                                                    <?php if($row['status']=="standby"){echo "selected";}?>>StandBy
                                                </option>

                                                <option value="completed"
                                                    <?php if($row['status']=="confirmed"){echo "selected";}?>>Confrimed
                                                </option>
                                                <option value="cancelled"
                                                    <?php if($row['status']=="cancelled"){echo "selected";}?>>Cancelled
                                                </option>
                                                <option value="refunded"
                                                    <?php if($row['status']=="contract"){echo "selected";}?>>Contract
                                                </option>

                                            </select>
                                        </div>
                                        <div class="form-group col-2 mb-3 mt-3" style="border-top:none;">

                                            <a class="modal-basic btn btn-warning <?php if($row['status']=="contract"){ echo"disabled";}?>"
                                                href="#modalStatus"><i class="fas fa-pencil-alt"></i></a>

                                        </div>
                                        <div class="form-group col-2 mb-3 mt-3" style="border-top:none;">
                                            <?php if($row['status']!="contract" && $row['status']=="confirmed"){?>
                                            <a class="btn btn-success"
                                                href="contractselect.php?id=<?php echo $row["id"];?>"><i
                                                    class="fas fa-file-signature"></i></a>
                                            <?php } else{
                                            if($row['status']=="contract"){?>
                                            <a class="btn btn-info" href="#contract"><i
                                                    class="fas fa-file-signature"></i></a>
                                            <?php } }?>

                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col-6 mb-3">
                                            <label>Rental Days</label>
                                            <input type="text" class="form-control form-control-modern" name="days"
                                                value="<?php echo $row['days'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                        <div class="form-group col-6 mb-3 pt-0" style="border-top:none;">
                                            <label>Rental Hours</label>
                                            <input type="text" class="form-control form-control-modern" name="hours"
                                                value="<?php echo $hour;  ?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Source</label>
                                            <select class="form-control form-control-modern" name="source"
                                                <?php echo $disfunct;?> data-plugin-selectTwo>
                                                <option value="" disabled selected hidden>
                                                    <?php if (is_null($row['source'])){echo "Not Set";} else{ echo $row['source'];} ?>
                                                </option>
                                                <?php $sqlcat2 = "SELECT * FROM jostj_vikrentcar_sources";
                                                        $result2 = mysqli_query($db2,$sqlcat2);
                                                        while($rowcat2 = mysqli_fetch_array($result2)) {?>


                                                <option value="<?php echo $rowcat2['id'];?>"
                                                    <?php if ($row['source']==$rowcat2['id']){ echo "selected";}?>>
                                                    <?php echo $rowcat2['name'];?></option>

                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Employee</label>
                                            <select class="form-control form-control-modern" name="source"
                                                <?php echo $disfunct;?> data-plugin-selectTwo>
                                                <option value="" disabled selected hidden>
                                                    <?php if (is_null($row['employee'])){echo "Not Set";} else{ echo $row['employee'];} ?>
                                                </option>
                                                <?php $sqlcat1 = "SELECT * FROM jostj_vikrentcar_employees WHERE jostj_vikrentcar_employees.active=1";
                                                        $result1 = mysqli_query($db2,$sqlcat1);
                                                        while($rowcat1 = mysqli_fetch_array($result1)) {?>


                                                <option value="<?php echo $rowcat1['id'];?>"
                                                    <?php if ($row['employee']==$rowcat1['id']){ echo "selected";}?>>
                                                    <?php echo $rowcat1['Name'];?></option>

                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Date Created</label>
                                            <div class="date-time-field">
                                                <div class="date">
                                                    <input type="text" class="form-control form-control-modern"
                                                        <?php echo $disfunct;?> name="orderDate"
                                                        value="<?php echo date('d/m/Y', $row['ts']);  ?>" />
                                                </div>
                                                <div class="time">
                                                    <span class="px-2">@</span>
                                                    <input type="text"
                                                        class="form-control form-control-modern text-center"
                                                        <?php echo $disfunct;?> name="orderTimeHour"
                                                        value="<?php echo date('H', $row['ts']);  ?>" />
                                                    <span class="px-2">:</span>
                                                    <input type="text"
                                                        class="form-control form-control-modern text-center"
                                                        <?php echo $disfunct;?> name="orderTimeMin"
                                                        value="<?php echo date('i', $row['ts']);  ?>" />
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="card card">
                                <div class="card-header">
                                    <h2 class="card-title">Customer <span class="editbutton"><a
                                                class="modal-basic btn btn-warning <?php if($row['status']=="contract"){ echo"disabled";}?>"
                                                href="#modalCustomer"><i class="fas fa-pencil-alt"></i></a></span></h2>
                                </div>
                                <div class="card-body">
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Drivers Name</label>
                                            <input type="text" class="form-control form-control-modern"
                                                name="nominative" value="<?php echo $row['nominative'];  ?>"
                                                <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                    <div class="form-group col-6 mb-3 pt-0" style="border-top:none;">
                                            <label>Date of Birth</label>
                                            <input type="text" class="form-control form-control-modern" name="cd_dob"
                                                value="<?php echo $row['cd_dob'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                        <div class="form-group col-6 mb-3 pt-0" style="border-top:none;">
                                            <label>Phone</label>
                                            <input type="text" class="form-control form-control-modern" name="phone"
                                                value="<?php echo $row['phone'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Email</label>
                                            <input type="text" class="form-control form-control-modern" name="custmail"
                                                value="<?php echo $row['custmail'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                 
                                    <div class="form-row">
                                        <div class="form-group col-4 mb-3 pt-0" style="border-top:none;">
                                            <label>Flight</label>
                                            <input type="text" class="form-control form-control-modern" name="flight"
                                                value="<?php echo $row['cd_flight'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                        <div class="form-group col-4 mb-3 pt-0" style="border-top:none;">
                                            <label>Hotel</label>
                                            <input type="text" class="form-control form-control-modern" name="hotel"
                                                value="<?php echo $row['cd_hotel'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                        <div class="form-group col-4 mb-3 pt-0" style="border-top:none;">
                                            <label>Room</label>
                                            <input type="text" class="form-control form-control-modern" name="room"
                                                value="<?php echo $row['cd_hotelroom'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col-6 mb-3 pt-0" style="border-top:none;">
                                            <label>Drivers Licence</label>
                                            <input type="text" class="form-control form-control-modern" name="cd_dlnumber"
                                                value="<?php echo $row['cd_dlnumber'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                        <div class="form-group col-6 mb-3 pt-0" style="border-top:none;">
                                            <label>Passport/ID Number</label>
                                            <input type="text" class="form-control form-control-modern" name="cd_passnum"
                                                value="<?php echo $row['cd_passnum'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Address</label>
                                            <textarea rows="1" class="form-control" name="cd_address" id="cd_address"
                                                <?php echo $disfunct;?>><?php echo $row['cd_address'];?> </textarea>
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Customer Data</label>
                                            <textarea rows="7" class="form-control" name="custdata" id="custdata"
                                                <?php echo $disfunct;?>><?php echo $row['custdata'];?> </textarea>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-xl-4">
                            <div class="card card">
                                <div class="card-header">
                                    <h2 class="card-title">Pick Up <span class="editbutton"><a
                                                class="btn btn-warning <?php if(($row['employee']==10 && $userrole!=1) || $row['status']=="contract"){echo "disabled";}?> "
                                                href="#modalpickup" rel="modal:open"><i
                                                    class="fas fa-pencil-alt"></i></a></span></h2>
                                </div>
                                <div class="card-body">
                                    <div class="form-row">
                                        <div class="form-group col mb-1">
                                            <label>Pick Up Date / Time</label>
                                            <input class="form-control" type="text" name="ritiro2" id="ritiro2"
                                                value="<?php echo $picktime;  ?>" <?php echo $disfunct;?>>
                                        </div>

                                    </div>
                                    <span style="color:red;font-size:x-small;"><?php echo $pickdet;?></span>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Pick Up Location</label>
                                            <select class="form-control form-control-modern" name="idplacer"
                                                data-plugin-selectTwo <?php echo $disfunct;?>>
                                                <?php $sqlcat = "SELECT * FROM jostj_vikrentcar_places";
                                                    $result = mysqli_query($db2,$sqlcat);
                                                    while($rowcat = mysqli_fetch_array($result)) {?>

                                                <option value="<?php echo $rowcat['id'];?>"
                                                    <?php if ($row['idplace']==$rowcat['id']){ echo "selected";} else {};?>>
                                                    <?php echo $rowcat['name'];?></option>


                                                <?php } ?>

                                            </select>
                                        </div>
                                    </div>


                                </div>
                            </div>
                            <div class="card card">
                                <div class="card-header">
                                    <h2 class="card-title">Vehicle Info <span class="editbutton"><a
                                                class="btn btn-warning <?php if($row['employee']==10 || $row['status']=="contract"){echo "disabled";}?> "
                                                href="#modalveh" rel="modal:open"><i
                                                    class="fas fa-pencil-alt"></i></a></span></h2>
                                </div>
                                <div class="card-body">

                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Selected Vehicle</label>
                                            <select class="form-control form-control-modern" name="idcar"
                                                data-plugin-selectTwo <?php echo $disfunct;?>>
                                                <?php $sqlcat = "SELECT * FROM jostj_vikrentcar_cars";
                                                    $result = mysqli_query($db2,$sqlcat);
                                                    while($rowcat = mysqli_fetch_array($result)) {?>

                                                <option value="<?php echo $rowcat['id'];?>"
                                                    <?php if ($row['idcar']==$rowcat['id']){ echo "selected";} else {};?>>
                                                    <?php echo $rowcat['name'];?></option>


                                                <?php } ?>

                                            </select>
                                        </div>
                                    </div>
                                    <?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 );
                                                    
                                                    ?>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Reserved ACRISS</label>
                                            <input type="text" class="form-control form-control-modern" name="accriss"
                                                value="<?php echo $rowac['api_fleet_acriss'];?>"
                                                <?php echo $disfunct;?> />
                                        </div>
                                    </div>

                                    <?php } 
                                        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 );
                                            $sqlcar = $db->query("SELECT * FROM jos8r_vikrentcar_cars WHERE jos8r_vikrentcar_cars.id='$idcar'  ") or die(mysql_error());
                                            $rowcar = mysqli_fetch_array( $sqlcar );
                                            $idcat=explode(';', $rowcar['idcat']);
                                            $vehtype=$idcat[0];
                                            $carcat=$idcat[1];
                                            $sqlveh = $db->query("SELECT * FROM jos8r_vikrentcar_categories WHERE jos8r_vikrentcar_categories.id='$vehtype'  ") or die(mysql_error());
                                            $rowveh = mysqli_fetch_array( $sqlveh );
                                            $sqlcar2 = $db->query("SELECT * FROM jos8r_vikrentcar_categories WHERE jos8r_vikrentcar_categories.id='$carcat'  ") or die(mysql_error());
                                            $rowcar2 = mysqli_fetch_array( $sqlcar2 );
                                            $group=$rowveh['name']." / ".$rowcar2['name'];
                                            ?>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Reserved Group</label>
                                            <input type="text" class="form-control form-control-modern" name="group"
                                                value="<?php echo $group;?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Tarrif</label>
                                            <input type="text" class="form-control form-control-modern" name="tarrif"
                                                value="<?php echo $rowtar2['name'];?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Excess</label>
                                            <input type="text" class="form-control form-control-modern" name="excess"
                                                value="<?php echo $rowtar['attrdata'];?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <?php } else{ ?>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Excess</label>
                                            <input type="text" class="form-control form-control-modern" name="excess"
                                                value="<?php echo $row['idtar'];?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <?php }
                                        ?>

                                </div>
                            </div>
                            <div class="card card">
                                <div class="card-header">
                                    <h2 class="card-title">Optional Extras <span class="editbutton"><a
                                                class="modal-basic btn btn-warning <?php if($row['status']=="contract"){ echo"disabled";}?>"
                                                href="#modaloptionals"><i class="fas fa-pencil-alt"></i></a></span></h2>
                                </div>
                                <div class="card-body">
                                    <?php
                                    if (is_null($row['optionals'])) {echo "None Selected";}
                                    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;
                       }                    
                       ?>
                                    <div class="form-row">
                                        <div class="form-group col-4 mb-3">

                                            <input type="text" class="form-control form-control-modern"
                                                name="op<?php echo $index+1;?>n" value="<?php echo $rowopt['name'];  ?>"
                                                <?php echo $disfunct;?> />
                                        </div>
                                        <div class="form-group col-1 mb-3 pt-0 text-center" style="border-top:none;"> X
                                        </div>
                                        <div class="form-group col-2  mb-3 pt-0" style="border-top:none;">

                                            <input type="text" class="form-control form-control-modern"
                                                name="op<?php echo $index+1;?>q" value="<?php echo $optionalquant;  ?>"
                                                <?php echo $disfunct;?> />
                                        </div>
                                        <div class="form-group col-1 mb-3 pt-0 text-center" style="border-top:none;"> =
                                        </div>
                                        <div class="form-group col-3  mb-3 pt-0" style="border-top:none;">

                                            <input type="text" class="form-control form-control-modern"
                                                name="op<?php echo $index+1;?>v" value="<?php echo $optionalvalue;  ?>"
                                                <?php echo $disfunct;?> />
                                        </div>
                                        <div class="form-group col-1 mb-3 pt-0 text-left" style="border-top:none;"> €
                                        </div>
                                    </div>
                                    <?php
                            
                            }
                        }
                            ?>
                                </div>
                            </div>
                        </div>
                        <div class="col-xl-4">


                            <div class="card card">
                                <div class="card-header">
                                    <h2 class="card-title">Drop Off <span class="editbutton"><a
                                                class="btn btn-warning <?php if(($row['employee']==10 && $userrole!=1) || $row['status']=="contract"){echo "disabled";}?>"
                                                href="#modaldropoff" rel="modal:open"><i
                                                    class="fas fa-pencil-alt"></i></a></span></h2>
                                </div>
                                <div class="card-body">
                                    <div class="form-row">
                                        <div class="form-group col mb-1">
                                            <label>Drop Off Date / Time</label>
                                            <input class="form-control" type="text" name="consegna2" id="consegna2"
                                                value="<?php echo $droptime;  ?>" <?php echo $disfunct;?>>
                                            <?php if($row['ext_old_date']!=NULL){echo "<p style='color:white;font-size:xx-small;'> extended on ".date('d/m/Y H:i', $row['ext_on'])." was until ".date('d/m/Y H:i', $row['ext_old_date'])."</p>";}?>

                                        </div>

                                    </div>
                                    <span style="color:red;font-size:x-small;"><?php echo $dropdet;?></span>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Drop Off Location</label>
                                            <select class="form-control form-control-modern" name="idreturnplacer"
                                                data-plugin-selectTwo <?php echo $disfunct;?>>
                                                <?php $sqlcat = "SELECT * FROM jostj_vikrentcar_places";
                                                        $result = mysqli_query($db2,$sqlcat);
                                                        while($rowcat = mysqli_fetch_array($result)) {?>

                                                <option value="<?php echo $rowcat['id'];?>"
                                                    <?php if ($row['idreturnplace']==$rowcat['id']){ echo "selected";} else {};?>>
                                                    <?php echo $rowcat['name'];?></option>


                                                <?php } ?>
                                            </select>
                                            <?php if($row['ext_old_return']!=NULL){ $oldreturnid=$row['ext_old_return'];
    $sqloldr = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id=$oldreturnid ") or die(mysql_error());
    $rowoldr = mysqli_fetch_array( $sqloldr );
    $oldreturn=$rowoldr['name']; echo "<p style='color:white;font-size:xx-small;'> extended on ".date('d/m/Y H:i', $row['ext_on'])." was previously set to return to ".$oldreturn."</p>";}?>
                                        </div>
                                    </div>


                                </div>
                            </div>
                            <div class="card card">
                                <div class="card-header">
                                    <h2 class="card-title">Finance Info <span class="editbutton"><a
                                                class="modal-basic btn btn-warning <?php if($row['status']=="contract"){ echo"disabled";}?>"
                                                href="#modalFinance"><i class="fas fa-pencil-alt"></i></a></span></h2>
                                </div>
                                <div class="card-body">
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Reservation Price</label>
                                            <input type="text" class="form-control form-control-modern"
                                                name="order_total" value="<?php echo $row['order_total'];  ?>"
                                                <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Total Paid</label>
                                            <input type="text" class="form-control form-control-modern" name="totpaid"
                                                value="<?php echo $row['totpaid'];  ?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Pay Locally</label>
                                            <input type="text" class="form-control form-control-modern" name="cust_cost"
                                                value="<?php echo $resttopay;  ?>" <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Extra Costs</label>
                                            <input type="text" class="form-control form-control-modern"
                                                name="extracosts" value="<?php echo $row['extracosts'];  ?>"
                                                <?php echo $disfunct;?> />
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col mb-3">
                                            <label>Payment Method</label>
                                            <select class="form-control form-control-modern" name="idpayment"
                                                data-plugin-selectTwo <?php echo $disfunct;?>>
                                                <option value="" disabled selected hidden>
                                                    <?php if (is_null($row['idpayment'])){echo "Not Set";} else{ echo trim(explode('=', $row['idpayment'])[1]);} ?>
                                                </option>
                                                <?php $sqlcat = "SELECT * FROM jostj_vikrentcar_gpayments";
                                                        $result = mysqli_query($db2,$sqlcat);
                                                        while($rowcat = mysqli_fetch_array($result)) {?>

                                                <option
                                                    value="<?php echo $rowcat['id'];?>=<?php echo $rowcat['name'];?>">
                                                    <?php echo $rowcat['name'];?></option>


                                                <?php } ?>
                                            </select>
                                        </div>
                                    </div>

                                </div>
                            </div>

                        </div>
                        <div class="col-xl-12 mb-3">
                            <div class="card card">
                                <div class="card-header">
                                    <h2 class="card-title">Notes
                                        <!--<span class="editbutton"><a
                                                class="modal-basic btn btn-success " href="#modaladdnote"><i
                                                    class="fas fa-plus"></i></a></span>-->
                                    </h2>
                                </div>
                                <div class="card-body">
                                    <div class="form-row">
                                        <div class="form-group col-xl-6 mb-3">
                                            <label>Admin Notes </label>
                                            <textarea rows="10" class="form-control" name="adminnotes" id="adminnotes"
                                                <?php echo $disfunct;?>><?php echo $row['adminnotes'];?> </textarea>

                                        </div>
                                        <div class="form-group col-xl-6 mb-3 pt-0" style="border-top:none;">
                                            <label>Email Text</label>
                                            <textarea rows="10" class="form-control" name="email_text" id="email_text"
                                                <?php echo $disfunct;?>><?php echo $row['email_text'];?> </textarea>
                                        </div>
                                    </div>
                                </div>
                                <div class="card-footer">
                                    <div class="row">
                                        <div class="col-6 text-left">
                                            <a class="modal-basic btn btn-warning " href="#modaladmin"><i
                                                    class="fas fa-pencil-alt"></i>Edit Admin Notes</a></div>
                                        <div class="col-6 text-right">
                                            <a class="modal-basic btn btn-warning " href="#modalemail"><i
                                                    class="fas fa-pencil-alt"></i>Edit Email Text</a>
                                        </div>

                                    </div>
                                </div>
                            </div>
                            <?php if ($row['status']=="contract"){
                                 $sqlcont = $db2->query("SELECT * FROM contracts  WHERE contracts.Res_ref='$fid'  ") or die(mysql_error());
                                 $rowcont = mysqli_fetch_array( $sqlcont );
                                 
                                ?>
                            <div class="col-xl-12 mb-3 mt-3" id="contract">

                                <div class="card card">
                                    <div class="card-header">
                                        <h2 class="card-title">Contract Info <?php if ($rowcont['cont_cancelled']==1){?><span style="color:red;">Cancelled!</span> <?php }?></h2>
                                    </div>
                                    <div class="card-body">
                                        <div class="form-row">
                                            <div class="form-group col-xl-3 mb-3">
                                                <label>Contract Number</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="contract_num" value="<?php echo $rowcont['contract_num'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>
                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Station</label>
                                                <select class="form-control form-control-modern" name="station_id"
                                                    data-plugin-selectTwo <?php echo $disfunct;?>>
                                                    <?php $sqlcat = "SELECT * FROM jostj_vikrentcar_stations";
                                                        $result = mysqli_query($db2,$sqlcat);
                                                        while($rowcat = mysqli_fetch_array($result)) {?>

                                                    <option value="<?php echo $rowcat['station_id'];?>"
                                                        <?php if ($rowcont['station_id']==$rowcat['id']){ echo "selected";} else {};?>>
                                                        <?php echo $rowcat['station_name'];?></option>


                                                    <?php } ?>
                                                </select>
                                            </div>
                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Vehicle</label>
                                                <select class="form-control form-control-modern" name="station_id"
                                                    data-plugin-selectTwo <?php echo $disfunct;?>>
                                                    <?php $sqlcat = "SELECT * FROM fleet LEFT JOIN jostj_vikrentcar_cars ON jostj_vikrentcar_cars.id=fleet.veh_id WHERE fleet.active=1";
                                                        $result = mysqli_query($db2,$sqlcat);
                                                        while($rowcat = mysqli_fetch_array($result)) {?>

                                                    <option value="<?php echo $rowcat['fleet_id'];?>"
                                                        <?php if ($rowcont['vehfleet_id']==$rowcat['fleet_id']){ echo "selected";} else {};?>>
                                                        <?php echo $rowcat['name']." - ".$rowcat['lic_num'];?></option>


                                                    <?php } ?>
                                                </select>
                                            </div>


                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Contract Date/Time</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="dateadded"
                                                    value="<?php echo date('d/m/Y H:i', $rowcont['dateadded']);  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>
                                        </div>

                                        <div class="form-row">
                                            <div class="form-group col-xl-3 mb-3 " style="border-top:none;">
                                                <label>Contract Value</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="Contract_value"
                                                    value="<?php echo $rowcont['Contract_value'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>

                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Res. Deposit</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="deposit" value="<?php echo $rowcont['deposit'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>

                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Extras Sold</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="extras_sold" value="<?php echo $rowcont['extras_sold'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>
                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Total Paid</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="ctotal_paid" value="<?php echo $rowcont['ctotal_paid'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>
                                        </div>
                                        <div class="form-row">


                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Employee</label>
                                                <select class="form-control form-control-modern" name="employee_id"
                                                    data-plugin-selectTwo <?php echo $disfunct;?>>
                                                    <?php $sqlcat = "SELECT * FROM jostj_vikrentcar_employees  WHERE jostj_vikrentcar_employees.active=1";
                                                $result = mysqli_query($db2,$sqlcat);
                                                while($rowcat = mysqli_fetch_array($result)) {?>

                                                    <option value="<?php echo $rowcat['station_id'];?>"
                                                        <?php if ($rowcont['employee_id']==$rowcat['id']){ echo "selected";} else {};?>>
                                                        <?php echo $rowcat['Name'];?></option>


                                                    <?php } ?>
                                                </select>
                                            </div>

                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Payment Method</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cidpayment"
                                                    value="<?php echo trim(explode('=', $rowcont["cidpayment"])[1]); ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>

                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Contract is Checked?</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="checked"
                                                    value="<?php if($rowcont['checked']==NULL || $rowcont['checked']==0){echo "Not Checked";} else {echo "Checked";}  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>
                                            <?php if($rowcont['checked']!=NULL){ 
                                            $chcid=$rowcont['checkedby'];
                                             $sqlchc = $db2->query("SELECT * FROM jostj_vikrentcar_employees  WHERE jostj_vikrentcar_employees.id='$chcid'  ") or die(mysql_error());
                                             $rowchc = mysqli_fetch_array( $sqlchc );
                                            ?>
                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Checked By</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="checkedby" value="<?php echo $rowchc['Name'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>
                                            <?php } ?>
                                        </div>
                                        <div class="form-row">
                                            <div class="form-group col-xl-3 mb-3 " style="border-top:none;">
                                                <label>Contract Fuel Out</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_fuel_out"
                                                    value="<?php echo $rowcont['cont_fuel_out'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>

                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Contract Fuel In</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_fuel_in" value="<?php echo $rowcont['cont_fuel_in'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>

                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Contract KM Out</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_km_out" value="<?php echo $rowcont['cont_km_out'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>
                                            <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                                <label>Contract KM In</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_km_in" value="<?php echo $rowcont['cont_km_in'];  ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>
                                        </div>
                                        <div class="form-row">
                                            <div class="form-group col-xl-6 mb-3 " style="border-top:none;">
                                                <label>Contract Damage Out</label>
                                                <textarea rows="5" class="form-control" name="cont_damage_out"
                                                    id="cont_damage_out"
                                                    <?php echo $disfunct;?>><?php echo $rowcont['cont_damage_out'];?> </textarea>

                                            </div>

                                            <div class="form-group col-xl-6 mb-3 pt-0" style="border-top:none;">
                                                <label>Contract Damage In</label>
                                                <textarea rows="5" class="form-control" name="cont_damage_in"
                                                    id="cont_damage_in"
                                                    <?php echo $disfunct;?>><?php echo $rowcont['cont_damage_in'];?> </textarea>

                                            </div>


                                        </div>
                                        <div class="form-row">
                                            <div class="form-group col-xl-4 mb-3 pt-3" style="border-top:none;">
                                                <label>Contract Additional Driver Name</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_codriver"
                                                    value="<?php echo $rowcont['cont_codriver'];  ?>"
                                                    <?php echo $disfunct;?> />

                                            </div>

                                            <div class="form-group col-xl-4 mb-3 " style="border-top:none;">
                                                <label>Contract Additional Driver Passport</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_copport" value="<?php echo $rowcont['cont_copport'];  ?>"
                                                    <?php echo $disfunct;?> />

                                            </div>
                                            <div class="form-group col-xl-4 mb-3 " style="border-top:none;">
                                                <label>Contract Additional Driver License</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_colicense"
                                                    value="<?php echo $rowcont['cont_colicense'];  ?>"
                                                    <?php echo $disfunct;?> />

                                            </div>

                                        </div>
                                        <div class="form-row">
                                            <div class="form-group col-xl-12 mb-3 " style="border-top:none;">
                                                <label>Contract Notes</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_notes" value="<?php echo $rowcont['cont_notes'];  ?>"
                                                    <?php echo $disfunct;?> />

                                            </div>

                                        </div>
                                        <div class="form-row">
                                       
                                            <div class="form-group col-xl-2 mb-3 pt-0" style="border-top:none;">
                                                <label>Contract Return Date</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_ret" value="<?php echo  $droptime; ?>"
                                                    <?php echo $disfunct;?> />
                                                   

                                            </div>
                                            <div class="form-group col-xl-1 mb-3 pt-0" style="border-top:none;">
                                        <span style="position: absolute;
    left: 0;
    top: 33px;"><a
                                                class="btn btn-warning <?php if($userrole!=1) {echo "disabled";}?>"
                                                href="#modalcontrdropoff" rel="modal:open"><i
                                                    class="fas fa-pencil-alt"></i></a></span>
                                            </div>
                                            <div class="form-group col-xl-2 mb-3 pt-0" style="border-top:none;">
                                                <label>Contract Extended?</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_extended"
                                                    value="<?php if($rowcont['cont_extended']==0) {echo "NO";} else { echo "YES";} ?>"
                                                    <?php echo $disfunct;?> />



                                            </div>

                                            <?php if($rowcont['cont_extended']==0) { }
                                        else {?>
                                            <div class="form-group col-xl-2 mb-3 pt-0" style="border-top:none;">
                                                <label>Contract New Price</label>
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_extended"
                                                    value="<?php echo  $rowcont['contract_ext_newprice']; ?>"
                                                    <?php echo $disfunct;?> />


                                            </div>
                                            <?php }?>
                                            <div class="form-group col-xl-2 mb-3 pt-0" style="border-top:none;">
                                                <label>Vehicle Changed?</label>
                                                <!--record old in table from to (changes)
                                                active in contract-->
                                                <input type="text" class="form-control form-control-modern"
                                                    name="cont_veh_change"
                                                    value="<?php if($rowcont['cont_veh_change']==0) {echo "NO";} else { echo "YES";}   ?>"
                                                    <?php echo $disfunct;?> />
                                            </div>
                                            <div class="form-group col-xl-2 mb-3 pt-0" style="border-top:none;">
                                            <?php if ($rowcont['cont_cancelled']==1){?><h1 style="color:red;">Cancelled!</h1> <?php }?>
                                        </div>
                                        </div>
                                    </div>
                                </div>


                            </div>
                            <?php } ?>
                        </div>

                        <?php if($rowcont['cont_extended']==1){?>
                        <div class="col-xl-12 mb-3 mt-3">

                            <div class="card">
                                <header class="card-header">


                                    <h2 class="card-title">Contract Extensions</h2>
                                </header>
                                <div class="card-body">
                                    <table class="table table-responsive-md table-sm mb-0">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>Old Ret. Date</th>
                                                <th>Old Ret. Place</th>
                                                <th>New Ret. Date</th>
                                                <th>New Ret. Place</th>
                                                <th>Extension Cost</th>
                                                <th>Extension Date</th>

                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php $sqlcext = "SELECT * FROM contract_extensions  WHERE contract_extensions.cont_ext_res=$fid";
                                                $result = mysqli_query($db2,$sqlcext);
                                                while($rowcext = mysqli_fetch_array($result)) {
                                                    $pla1=$rowcext['ext_old_return'];
                                                    $pla2=$rowcext['ext_new_rplace'];

                                                    $sql3ext = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id=$pla1 ");
                                                    $row3ext = mysqli_fetch_array( $sql3ext ); 
                                                           
                                                    $sql4ext = $db2->query("SELECT * FROM jostj_vikrentcar_places WHERE jostj_vikrentcar_places.id=$pla2 ") or die(mysql_error());
                                                    $row4ext = mysqli_fetch_array( $sql4ext );
                                                
                                                    
                                                    ?>
                                            <tr>
                                                <td><?php echo $rowcext['cont_ext_id'];?></td>
                                                <td><?php echo date('d-m-Y H:i', $rowcext['ext_old_date']);?></td>
                                                <td><?php echo $row3ext['name'];?></td>
                                                <td><?php echo date('d-m-Y H:i', $rowcext['ext_new_date']);?></td>
                                                <td><?php echo $row4ext['name'];?></td>
                                                <td><?php echo $rowcext['contract_ext_newprice'];?></td>
                                                <td><?php echo date('d-m-Y H:i', $rowcext['contract_ext_ts']);?></td>
                                            </tr>
                                            <?php }?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                        </div>
                        <?php }?>
                        <?php if($rowcont['cont_veh_change']==1){?>
                        <div class="col-xl-12 mb-3 mt-3">

                            <div class="card">
                                <header class="card-header">


                                    <h2 class="card-title">Vehicle Changes</h2>
                                </header>
                                <div class="card-body">
                                    <table class="table table-responsive-md table-sm mb-0">
                                        <thead>
                                            <tr>
                                                <th>ID</th>
                                                <th>Date of Change</th>
                                                <th>New Vehicle</th>
                                                <th>Reason</th>
                                                <th>Notes</th>
                                               
                                            </tr>
                                        </thead>
                                        <tbody>
                                          
                                            <?php
                                              $contid=$rowcont['contract_id'];
                                            $sqlcvehx= "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";
                                                $result = mysqli_query($db2,$sqlcvehx);
                                                while($rowvehx = mysqli_fetch_array($result)) {
                                                   
                                                    ?>
                                            <tr>
                                                <td><?php echo $rowvehx['change_id'];?></td>
                                                <td><?php echo date('d-m-Y H:i', $rowvehx['change_from']);?></td>
                                                <td><?php echo $rowvehx['name']."-".$rowvehx['lic_num'];?></td>
                                                <td><?php echo $rowvehx['reason'];?></td>
                                                <td><?php echo $rowvehx['notes'];?></td>
                                            </tr>
                                            <?php }?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                        </div>
                        <?php }?>
                        <div class="col-xl-12 mb-3 mt-3">

                            <div class="card card">
                                <div class="card-header">
                                    <h2 class="card-title">Reservation Log</h2>
                                </div>
                                <div class="card-body">
                                    <div class="ecommerce-timeline mb-3">
                                        <div class="ecommerce-timeline-items-wrapper">
                                            <?php if($row['employee']==10 && $row['status']=="cancelled"){?>

                                            <div class="ecommerce-timeline-item">
                                                <small>Cancelled by API with Notes:
                                                </small>
                                                <p><?php echo $row['cancelnotes'];?>*</p>
                                            </div>
                                            <?php }?>

                                            <?php $sqllog = "SELECT * FROM reservation_log WHERE reservation_log.reservation_log_res='$fid' order by reservation_log_id DESC ";
                                                        $result = mysqli_query($db2,$sqllog);
                                                        while($rowlog = mysqli_fetch_array($result)) {
                                                            $usid=$rowlog['reservation_log_user'];
                                                            $sqluser2 = $db->query("SELECT * FROM users WHERE users.id='$usid' ") or die(mysql_error());
                                                            $rowus2 = mysqli_fetch_array( $sqluser2 );
                                                            ?>
                                            <div class="ecommerce-timeline-item">
                                                <small>added on
                                                    <?php echo date('d/m/Y', $rowlog['reservation_log_date']);  ?> at
                                                    <?php echo date('H:i', $rowlog['reservation_log_date']);  ?> by
                                                    <?php echo $rowus2["username"];?> </small>
                                                <p><?php echo $rowlog['reservation_log_action']." ".$rowlog['reservation_log_item'];?>
                                                    With the following Details: </p>
                                                <p><?php echo $rowlog['reservation_log_details'];?></p>
                                            </div>
                                            <?php } 
                                            ?>
                                            <div class="ecommerce-timeline-item">
                                                <small>added on <?php echo date('d/m/Y', $row['ts']);  ?> at
                                                    <?php echo date('H:i', $row['ts']);  ?> by
                                                    <?php echo $rowem["Name"];?>*</small>
                                                <p>Reservation Creation</p>
                                            </div>
                                        </div>
                                    </div>
                                    *Auto Generated
                                </div>
                            </div>


                        </div>
                        <div class="row action-buttons">


                            <?php if($row['status']=="confirmed" ){?>
                            <div class="col-12 col-md-auto">
                                <a href="contractselect.php?id=<?php echo $row["id"];?>" target="_blank"
                                    class="btn btn-success btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Make
                                    Contract</a>

                            </div>
                            <?php } elseif($row['status']=="contract") {?>
                           
                            <div class="col-12 col-md-auto">
                                <a href="#modalextend" rel="modal:open"
                                    class="btn btn-danger btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Extension</a>

                            </div>

                            <div class="col-12 col-md-auto">
                                <a href="#modalvehcontractchange" rel="modal:open"
                                    class="btn btn-info btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Veh.
                                    Change</a>

                            </div>
                            <?php if($userrole==1 && $rowcont['cont_cancelled']==0){?>
                            <div class="col-12 col-md-auto">
                                <a href="#modalcontractcancel" rel="modal:open"
                                    class="btn btn-warning btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Cancel</a>

                            </div>
                            <?php } }?>
                            <div class="col-12 col-md-auto">
                                <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                </p>
                            </div>
                            <div class="col-12 col-md-auto ">
                                <a href="resprint.php?id=<?php echo $row["id"];?>" target="_blank"
                                    class="btn btn-primary btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Print
                                    Voucher</a>

                            </div>
                            <?php if($row['status']=="contract") {?>
                            <div class="col-12 col-md-auto">
                            <a href="contprint.php?id=<?php echo $row["id"];?>&sp=1" target="_blank"
                                    class="btn btn-dark btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Print
                                    A4</a>
                           
                        </div>
                        <div class="col-12 col-md-auto">
                            <a href="receiptprint.php?id=<?php echo $row["id"];?>" target="_blank"
                                    class="btn btn-warning btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Print
                                    80mm</a>
                           
                        </div>
                        <div class="col-12 col-md-auto">
                            <a href="receiptprint.php?id=<?php echo $row["id"];?>&printtype=2" target="_blank"
                                    class="btn btn-success btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Print
                                    receipt 80mm</a>
                           
                        </div>
                        <?php }?>
                            <!--<div class="col-12 col-md-auto ">
                            <a href="ressent.php?id=<?php echo $row["id"];?>"
                                class="btn btn-dark btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Sent to Customer</a>
                        </div>-->
                            <div class="col-12 col-md-auto ">
                                <a href="reservations-local.php"
                                    class="cancel-button btn btn-light btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1">Return</a>
                            </div>
                        </div>

                </form>
                <!-- end: page -->
                <?php include('include/modals.php');?>
            </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/select2/js/select2.js"></script>
    <script src="vendor/pnotify/pnotify.custom.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>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.css" />
    <!-- Examples -->
    <script src="js/examples/examples.header.menu.js"></script>
    <script src="js/examples/examples.ecommerce.orders.detail.js"></script>
    <script src="js/examples/examples.modals.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js"
        integrity="sha512-qTXRIMyZIFb8iQcfjXWCO8+M5Tbc38Qi5WzdPOYZHIlZpzBHG3L3by84BBBOiRGiEb7KKtAOAs5qYdUiZiQNNQ=="
        crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/rome/3.0.2/rome.standalone.min.js"
        integrity="sha512-cJ4aSZY0xBXrcH65MOwCloQAiTNCBm2F8/KlcBTlczgn4txZkT7h3YSXULN06pkUnsySMEg5BU4QCHAr97U7ng=="
        crossorigin="anonymous"></script>
    <script>
        const options = {
            "appendTo": document.body,
            "autoClose": true,
            "autoHideOnBlur": true,
            "autoHideOnClick": true,
            "date": true,
            "dateValidator": Function.prototype,
            "dayFormat": "DD",
            "initialValue": null,
            "inputFormat": "DD-MM-YYYY HH:mm",
            "invalidate": true,
            "max": null,
            "min": null,
            "monthFormat": "MMMM YYYY",
            "monthsInCalendar": 1,
            "required": false,
            "strictParse": false,
            "styles": {
                "back": "rd-back",
                "container": "rd-container",
                "date": "rd-date",
                "dayBody": "rd-days-body",
                "dayBodyElem": "rd-day-body",
                "dayConcealed": "rd-day-concealed",
                "dayDisabled": "rd-day-disabled",
                "dayHead": "rd-days-head",
                "dayHeadElem": "rd-day-head",
                "dayRow": "rd-days-row",
                "dayTable": "rd-days",
                "month": "rd-month",
                "next": "rd-next",
                "positioned": "rd-container-attachment",
                "selectedDay": "rd-day-selected",
                "selectedTime": "rd-time-selected",
                "time": "rd-time",
                "timeList": "rd-time-list",
                "timeOption": "rd-time-option"
            },
            "time": true,
            "timeFormat": "HH:mm",
            "timeInterval": 900,
            "timeValidator": Function.prototype,
            "weekdayFormat": "min",
            "weekStart": moment().weekday(0).day()
        }
        rome(newritiro, options);
        rome(newconsegna, options);
        rome(newconsegna3, options);
        rome(newpick, options);
        rome(cont_ret, options);
        
    </script>
</body>

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