<?php 

include('include/auth.php');?>
<!doctype html>
<html class="fixed dark">
<?php 
if (isset($_GET['new'])  && $_GET['new']!=1) {
    $new=$_GET['new'];
}
else {
    $new=1;
}
if (isset($_GET['contnum']) ) {
    $contnum=$_GET['contnum'];
    $stprefix=$_GET['prefix'];
    $cnum=$_GET['cnum'];
}
else {
    $contnum='0';
} 
    $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'];
    
    }
    $idcar=$row["idcar"];
    $idplace=$row["idplace"];
    $idreturnplace =$row["idreturnplace"];
    $hour = abs($row['consegna'] - $row['ritiro'])/(60*60);
    $disfunct="";
    if($row['employee']==10){
        $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) . "*";
        $pickdet="*Time Auto Adjusted. Original time was: ".date('H:i', $row['ritiro']);
        $dropdet="*Time Auto Adjusted. Original time was: ".date('H:i', $row['consegna']);
  $conttime= $droptime2;
    }
    else{
        $picktime=date('d-m-Y H:i', $row['ritiro']);
        $droptime=date('d-m-Y H:i', $row['consegna']);
        $conttime=$row['consegna'];
    }
    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'];?> Add Contract </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="actions/newcontract.php"
                    method="post" name="form1">
                                                    
                    <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 </h2>
                               </div>
                               <div class="card-body">
                                   <div class="form-row">
                                        <?php if($contnum=='0'){?>
                                       <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 $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;?>>
                                               <option value="" disabled selected>Select Station</option>
                                               <?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 echo $rowcat['station_name'];?></option>


                                               <?php } ?>
                                           </select>
                                       </div>
                                     <?php } else { ?>
                                        <div class="form-group col-xl-3 mb-3" style="padding:1rem;" >
                                        <h3 class="p-2 red">Contract Number: <?php echo  $stprefix.$cnum;?></h3>
                                        <input type="hidden" class="form-control form-control-modern"
                                            name="contract_num" value="<?php echo $stprefix.$cnum;?>"/>
                                            <input type="hidden" name="stprefix" value="<?php echo $stprefix;?>">
                    <input type="hidden" name="cnum" value="<?php echo $cnum;?>">
                                            </div>
                                            <div class="form-group col-xl-3 mb-3" style="border-top:none;">
                                                <?php  $sqlpx = $db2->query("SELECT * FROM jostj_vikrentcar_stations WHERE jostj_vikrentcar_stations.station_contprefix='$stprefix' ") or die(mysql_error());
    $rowpfx = mysqli_fetch_array( $sqlpx ); ?>
                                        <h3 class="p-2 red">Station: <?php echo  $rowpfx['station_name']?></h3>

                                        <input type="hidden" class="form-control form-control-modern"
                                            name="station_id" value="<?php echo $rowpfx['station_id'];?>"/>
                                           
                                            </div>
                                    <?php }  ?>
                                   
                                       <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;?>>
                                               <option value="" disabled selected>Select Employee</option>
                                               <?php $sqlcat = "SELECT * FROM jostj_vikrentcar_employees  WHERE jostj_vikrentcar_employees.active=1 AND jostj_vikrentcar_employees.id!=10";
                                               $result = mysqli_query($db2,$sqlcat);
                                               while($rowcat = mysqli_fetch_array($result)) {?>

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


                                               <?php } ?>
                                           </select>
                                       </div>
                                       <div class="form-group col-xl-3 mb-3 pt-0" style="border-top:none;">
                                           <label>Assign Vehicle</label>
                                           <select class="form-control form-control-modern" name="vehfleet_id"
                                               data-plugin-selectTwo <?php echo $disfunct;?>>
                                               <option value="" disabled selected>Select Vehicle</option>
                                               <?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 echo $rowcat['name']." - ".$rowcat['lic_num'];?></option>


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


                                   </div>

                                   <div class="form-row">
                                       <div class="form-group col-xl-2 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-2 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-2 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-2 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 class="form-group col-xl-2 mb-3 pt-0" style="border-top:none;">
                                           <label>Payment Method</label>
                                               <select class="form-control form-control-modern" name="cidpayment"
                                                data-plugin-selectTwo <?php echo $disfunct;?>>
                                                
                                                <?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 class="form-group col-xl-2 mb-3 pt-0" style="border-top:none;">
                                           <label style="color:red;">Contract Return Date</label>
                                           <input style="color:red;" type="text" class="form-control form-control-modern" required
                                               name="cont_return" id="cont_return" value="<?php echo date('d-m-Y H:i', $conttime);  ?>"
                                               />
                                       </div>
                                   </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>
                           </div>
                          

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

                       
                    <div class="col-12 col-md-auto">
                            <button type="submit"
                                class="submit-button btn btn-primary btn-px-4 py-3 d-flex align-items-center font-weight-semibold line-height-1"
                                data-loading-text="Loading...">
                                <i class="bx bx-save text-4 mr-2"></i> Save Contract
                            </button>
                        </div>
                   
                        <div class="col-12 col-md-auto ">
                            <a href="reservation.php?id=<?php echo $row["id"];?>"
                                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>
                    <input type="hidden" name="fid" value="<?php echo $fid;?>">
                    <input type="hidden" name="dateadded" id="dateadded" value="<?php echo time(); ?>">
                    <input type="hidden" name="Res_ref" id="Res_ref" value="<?php echo $row["id"]; ?>">
                    <input type="hidden" name="Res_value" id="Res_value" value="<?php echo $row["order_total"]; ?>">
                    <input type="hidden" name="conttype" value="<?php echo $contnum;?>">
              
               
                </form>
                <!-- end: page -->
                <?php include('include/modals.php');?>
            </section>
        </div>

        <?php include('include/asideres.php');?>
        <div id="modalid" class="modal">
                    <section class="card">
                        <header class="card-header">
                            <h2 class="card-title">Select Reservation</h2>
                        </header>
                        <div class="card-body">
                            <form method="get" action="newcontract.php?">
                                <div class="modal-wrapper">
                                    <div class="modal-icon">
                                        <i class="fas fa-question-circle"></i>
                                    </div>

                                    <div class="modal-text">
                                        <div class="row">
                                            <div class="col-md-12">



                                                <div class="form-row">
                                                    <div class="form-group col mb-1">
                                                        <label>Reservation Id</label>
                                                        <input class="form-control" type="text" name="id" id="id"
                                                            value="" required>
                                                    </div>

                                                </div>

                                               



                                            </div>

                                        </div>
                                    </div>
                                </div>
                        </div>
                        <footer class="card-footer">
                            <div class="row">
                                <div class="col-md-12 text-right">
                                    <button class="btn btn-primary " type="submit">Select</button>
                                    <a class="btn btn-default" type="button" href="#" rel="modal:close">Cancel</a>
                                </div>
                               
                                </form>
                            </div>
                        </footer>
                    </section>
                </div>
    </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>
        <?php if($new==0){?>
    <script>
        $(window).on('load', function() {
        $('#modalid').modal('show');
    });
        </script>
    <?php }?>
    <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(cont_return, options);
    </script>
</body>

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