<?php include('include/auth.php');
//$fid=$_GET['id'];
$car=$_GET['car'];
$datechanged=$_GET['d'];
$vehchanged=$_GET['v'];
$printtype=$_GET['printtype'];
$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="disabled";
if($row['status']=="contract"){
    $sqlcont = $db2->query("SELECT * FROM contracts WHERE contracts.Res_ref='$fid' ") or die(mysql_error());
$rowcont = mysqli_fetch_array( $sqlcont );
$licnum=$rowcont['vehfleet_id'];
    $picktime=date('d-m-Y H:i', $row['ritiro']);
    if ($rowcont['cont_return']==0 ){
        $droptime=date('d-m-Y H:i', $row['consegna']);
    }
    else{
    $droptime=date('d-m-Y H:i', $rowcont['cont_return']);
    }
} 
else{
if($row['source']==1006){
    $picktime2=strtotime('+2 hours', $row['ritiro'])."*";
    $droptime2=strtotime('+2 hours', $row['consegna'])."*";
    $picktime=date('d/m/Y H:i', $picktime2)."*";
    $droptime=date('d/m/Y H:i', $droptime2)."*";
    $pickdet="*Time Auto Adjusted. Original time was: ".date('H:i', $row['ritiro']);
    $dropdet="*Time Auto Adjusted. Original time was: ".date('H:i', $row['consegna']);

}
else{
    $picktime=date('d-m-Y H:i', $row['ritiro']);
    $droptime=date('d-m-Y H:i', $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'];
   }
}
$subtotal= ($row['order_total']+$row['extracosts'])/1.24;
$vat= $row['order_total']-$subtotal;
$sql2 = $db2->query("SELECT * FROM jostj_vikrentcar_cars WHERE jostj_vikrentcar_cars.id=$idcar ") or die(mysql_error());
$row2 = mysqli_fetch_array( $sql2 ); 
$sqlcar2 = $db->query("SELECT * FROM jos8r_vikrentcar_cars WHERE jos8r_vikrentcar_cars.id='$idcar'  ") or die(mysql_error());
$rowcar2 = mysqli_fetch_array( $sqlcar2 );
$idcat2=explode(';', $rowcar2['idcat']);
$vehtype2=$idcat2[0];
$carcat2=$idcat2[1];
$sqlveh2 = $db->query("SELECT * FROM jos8r_vikrentcar_categories WHERE jos8r_vikrentcar_categories.id='$vehtype2'  ") or die(mysql_error());
$rowveh2 = mysqli_fetch_array( $sqlveh2 );
$sqlcar3 = $db->query("SELECT * FROM jos8r_vikrentcar_categories WHERE jos8r_vikrentcar_categories.id='$carcat2'  ") or die(mysql_error());
$rowcar3 = mysqli_fetch_array( $sqlcar3 );
$group2=$rowveh2['name']." / ".$rowcar3['name'];

$sql3 = $db2->query("SELECT * FROM jostj_vikrentcar_places LEFT JOIN jostj_vikrentcar_stations ON jostj_vikrentcar_places.station=jostj_vikrentcar_stations.station_id WHERE jostj_vikrentcar_places.id=$idplace ");
$row3 = mysqli_fetch_array( $sql3 ); 
       
$sql4 = $db2->query("SELECT * FROM jostj_vikrentcar_places LEFT JOIN jostj_vikrentcar_stations ON jostj_vikrentcar_places.station=jostj_vikrentcar_stations.station_id WHERE jostj_vikrentcar_places.id=$idreturnplace ") or die(mysql_error());
$row4 = mysqli_fetch_array( $sql4 );

$sql55 = $db2->query("SELECT * FROM fleet LEFT JOIN jostj_vikrentcar_cars ON jostj_vikrentcar_cars.id=fleet.veh_id  WHERE fleet.fleet_id=$licnum ") or die(mysql_error());
$row55 = mysqli_fetch_array( $sql55 ); 

$sourcename=$row['source'];
$sql56 = $db2->query("SELECT * FROM jostj_vikrentcar_sources  WHERE jostj_vikrentcar_sources.id=$sourcename ") or die(mysql_error());
$row56 = mysqli_fetch_array( $sql56 ); 

$custdata=$row['custdata'];
$cust2=explode(":",$custdata); 

if($row['cd_dob']==NULL){
    $custdob=substr($cust2[2], 0, strpos($cust2[2], "Address")); // imerominia genissis
}
else{$custdob=$row['cd_dob'];}
if($row['cd_address']==NULL){
    $custaddress=substr($cust2[3], 0, strpos($cust2[3], "Zip Code")); //address
    }
    else{$custaddress=$row['cd_address'];
    }
    if($row['cd_dlnumber']==NULL){
        $custdrlic=substr($cust2[6], 0, strpos($cust2[6], "Passport Number")); //license number
        }
        else{$custdrlic=$row['cd_dlnumber'];
        }

        if($row['cd_passnum']==NULL){
            $custpass=substr($cust2[7], 0, strpos($cust2[7], "Flight Number"));// passport
            }
            else{$custpass=$row['cd_passnum'];
            }
            if($row['cd_flight']==NULL){
                $custflight=substr($cust2[8], 0, strpos($cust2[8], "Hotel Name"));// flight
                }
                else{$custflight=$row['cd_flight'];
                }
                if($row['cd_hotel']==NULL){
                    $custhotel=substr($cust2[9], 0, strpos($cust2[9], "Room")); // hotel
                    }
                    else{$custhotel=$row['cd_hotel'];
                    }
                
                    if($row['cd_hotelroom']==NULL){
                        $custroom=$cust2[10]; //hotel room
                        }
                        else{$custroom=$row['cd_hotelroom'];
                        }

?>
<html>

<head>
    <title>WV Admin - Reservation Print</title>
    <!-- Web Fonts  -->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet" type="text/css">

    <!-- Vendor CSS -->
    <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.css" />

    <!-- Invoice Print Style -->
    <link rel="stylesheet" href="css/invoice-print.css" />
    <style>
        @media print {

            html,
            body {
                width: 100%;
                height: 100%;
                position: absolute;
                margin: 0mm;
                padding: 0mm;
            }

            .show {
                width: 100%;
            }

            p {
                color: #000;
                line-height: 2em;
                margin: 0 0 0;
            }
        }

        .noshow {
            display: none;
        }
    </style>
</head>

<body>
    <div class="container-fluid">
        <div class="row">
            <div class="col-12 text-center">
                <img style="width:90%" src="img/motorclub.bmp" alt="MotorClub.gr">
            </div>
        </div>



        <div class="row">
            <div class="col-12 text-center">
                <address style="font-size:2em;color: #000;">
                    <strong>SIGMA S.A. Tourism Trade &amp; Nautical Enterprices</strong>
                    <br>
                    Main office: 1, 18 Agglon Sq. 71202 Heraklion Crete
                    <br>
                    Tel.: (+30) 2810 222408, (+30) 2810 286012, (+30) 2810 286031
                    <br>
                    Fax: (+30) 2810 222862, e-mail: info@motorclub.gr
                    <br>
                    www.motorclub.gr
                </address>
            </div>
        </div>

        <div class="row">
            <div class="col-12 text-center">
                <p style="font-weight:bold;font-size:3em;">Contract Num: #1891 </p>
            </div>
        </div>

        <div class="row">
            <div class="col-12 text-center">
                <p style="font-weight:bold;font-size:3em;">ΕΝΟΙΚΙΑΣΕΙΣ ΑΥΤΟΚΙΝΗΤΩΝ</p>
                <p style="font-weight:bold;font-size:2em;">RENTAL AGREEMENT / Μισθωτήριο Συμβόλαιο</p>
                <p style="font-weight:bold;font-size:2em;">ΑΠΟΔΕΙΞΗ ΠΑΡΟΧΗΣ ΥΠΗΡΕΣΙΩΝ ΑΡΘΡΟ 13 &amp; 2Κ.Β.Σ </p>
            </div>
        </div>

        <hr>

        <div class="row">
            <div class="col-12 text-left">
            <p style="font-weight:bold;font-size:3em;">Rental Details</p>
              
                <p style="font-weight:bold;font-size:2em;">Agreed out Location :
                    <?php echo $row3['name'];  ?></p>
                <p style="font-weight:bold;font-size:2em;">Date & Time OUT :
                    <?php echo $picktime;  ?> </p>
                    <p style="font-weight:bold;font-size:2em;">Room Number :  <?php echo str_replace('\r\n',' ',$custroom); ?> </p>
                <p style="font-weight:bold;font-size:2em;">Agreed return Location :
                    <?php echo $row4['name'];  ?> </p>
                <p style="font-weight:bold;font-size:2em;">Date in & Time in :
                    <?php echo $droptime;  ?> </p>
            </div>
        </div>
        <hr>
        <div class="row">
            <div class="col-12 text-left">
            <p style="font-weight:bold;font-size:3em;">Vehicle Details</p>
                <p style="font-weight:bold;font-size:2em;">Model : <?php echo $row55['name'];?> </p>
                <p style="font-weight:bold;font-size:2em;">Number Plate :  <?php echo $row55['lic_num'];?> </p>
                <p style="font-weight:bold;font-size:2em;">FUEL OUT :
                    <?php echo $rowcont['cont_fuel_out'];  ?> </p>
                <p style="font-weight:bold;font-size:2em;">KILOMETERS :
                   FREE </p>
                <p style="font-weight:bold;font-size:2em;">EXTRAS : <?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;
                       }                    
                       ?>
                    <span class="<?php if($optionalquant==0){echo "noshow";}?> text-dark"><?php echo $rowopt['name'];?>
                        X<?php echo $optionalquant;?>, </span> </p>
                    <?php }
                        }
                            ?></span><br>
                             <p style="font-weight:bold;font-size:2em;">FULL INSURANCE</p>
                <p style="font-weight:bold;font-size:2em;">EXCESS : <?php if ($row['employee']==10) {
                                        $apsoure= $row['source'];
                                                    $sqlac = $db2->query("SELECT * FROM api_fleet WHERE api_fleet.api_fleet_partner='$apsoure' AND api_fleet.api_fleet_idcar='$idcar' ") or die(mysql_error());
                                                    $rowac = mysqli_fetch_array( $sqlac );
                                                    echo $rowac['api_fleet_acriss']." / ";  
                                                 } 
                                        if ($row['source']==16){ 
                                            $webid=$row['webid'];
                                            $sqtar = $db->query("SELECT * FROM jos8r_vikrentcar_orders LEFT JOIN jos8r_vikrentcar_dispcost ON jos8r_vikrentcar_dispcost.id=jos8r_vikrentcar_orders.idtar  WHERE jos8r_vikrentcar_orders.id='$webid'  ") or die(mysql_error());
                                            $rowtar = mysqli_fetch_array( $sqtar );
                                            $priceid=$rowtar['idprice'];
                                            $sqtar2 = $db->query("SELECT * FROM jos8r_vikrentcar_prices  WHERE jos8r_vikrentcar_prices.id='$priceid'  ") or die(mysql_error());
                                            $rowtar2 = mysqli_fetch_array( $sqtar2 );
                                            echo $rowtar2['name']." / ".$rowtar['attrdata'];
                                            
                                            } else{ 
                                                echo $row['idtar'];
                                                      }     ?> </p>
               
            </div>
        </div>
        <hr>
        <div class="row">
            <div class="col-12 text-left">
                <p style="font-weight:bold;font-size:3em;">Customer Details</p>
                <p style="font-weight:bold;font-size:2em;">Renter's Name :
                    <?php echo $row['nominative'];  ?></p>
                <!--<p style="font-weight:bold;font-size:2em;">Country : <?php echo $custcountry;?> </p>-->
                <p style="font-weight:bold;font-size:2em;">Address : <?php echo $custaddress; ?> </p>
                 <!--<p style="font-weight:bold;font-size:2em;">Zip code : <?php echo $custzip; ?> </p>
                <p style="font-weight:bold;font-size:2em;">City : <?php echo $custcity; ?> </p>-->
                <p style="font-weight:bold;font-size:2em;">Driving licence :
                <?php echo str_replace('\r\n',' ',$custdrlic); ?> </p>
                <p style="font-weight:bold;font-size:2em;">Passport number :
                <?php echo str_replace('\r\n',' ',$custpass); ?></p>
                <?php if($row['cont_codriver']==NULL){} else{?>
                    <p style="font-weight:bold;font-size:3em;">Co Driver</p>
                    <p style="font-weight:bold;font-size:2em;"> Name :
                    <?php echo $row['cont_codriver'];  ?></p>
                    <p style="font-weight:bold;font-size:2em;"> License / Passport :
                    <?php echo $row['cont_copport'];  ?> / <?php echo $row['cont_colicense'];  ?></p>
                    <?php }?>
            </div>
        </div>
        <hr>
        <?php $subcont=$rowcont['Contract_value']/1.24; 
        $vatcont=$rowcont['Contract_value']-$subcont;
        if($printtype!=2){
        ?>
        <div class="row">
            <div class="col-12 text-left">
                <p style="font-weight:bold;font-size:3em;">Finance Details</p>
                <p style="font-weight:bold;font-size:2em;">Pretax (Total) :
                    <?php echo number_format($subcont, 2, '.', '') ;  ?> € </p>
                <p style="font-weight:bold;font-size:2em;">Taxes - VAT :
                    <?php echo number_format($vatcont, 2, '.', '')  ?> €  </p>
                <p style="font-weight:bold;font-size:3em;">Total :
                    <?php echo number_format($rowcont['Contract_value'], 2, '.', '');  ?> € </p>
                <p style="font-weight:bold;font-size:2em;">Deposit : <?php echo $rowcont['deposit'];  ?>
                    € </p>
                <p style="font-weight:bold;font-size:2em;">Paid : <?php echo $rowcont['ctotal_paid'];  ?>
                    €</p>
                <p style="font-weight:bold;font-size:2em;">Balance :
                    <?php echo number_format($contrestpay, 2, '.', ''); ?> € </p>
               
            </div>
        </div>
        <?php }?>
    </div>

    <div class="row">
            <div class="col-12 text-left">
            <p style="font-weight:bold;font-size:3em;padding:5em;">CUSTOMER SIGNATURE:</p>

       </div>
    </div>
    <span style="
   color: #000;
    font-size: 1em;
    text-align: justify; 
"><strong>
        I have read and agree to the terms and conditions on motorclub.gr</span></strong>
    <script>
        window.print();
    </script>
</body>

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