<!DOCTYPE html>
<html>
<head>
	<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
	<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>


</head>
<body>
    
     <header style=" text-align:center;">
        <br>        <br>
        <a href = "CLOSE" style="margin-top: -150px;"><img src="https://image.flaticon.com/icons/svg/93/93634.svg" class="img-responsive" style="height:50px"></a>
    </header>
    
<br>	<br>	
		<div class="container">
  <center>	<h3>Self-certified Income E-Form</h3></center><br>	<br>	
  <form id="ajax-contact" method="post" action="post.php">
     <?php
      include('connect.php');
      $driver_id = $_GET['driver_id'];
      $sql = mysqli_query($con,"SELECT * FROM assigned_drivers WHERE driver_id = '$driver_id'");
      
     ?>
   
<input type="hidden" name="driver_id" value="<?= $_GET['driver_id'] ?>">

<br>

<?php

  $str = date('Y-m-');


?>  


    <div class="form-group">
      <label>Week Number & Date:</label>
      <select class="form-control" name="week_date" required="">
        <option value="">Select a date</option>
        <?php
          for($i2=1; $i2<30; $i2++)
         {

    // echo '<br>',
      $ddd = $str.$i2;
    // echo '',
      $date = date('d M D Y', $time = strtotime($ddd) );

      if(strpos($date, 'Sun') )
      {
        echo '<option value ="'.$date.'">'.$date.'</option>';
      }
  }
        ?>
      </select>
    </div><br> 

    <div class="form-group">
      <label>Agency drop-down:</label>
     <select class="form-control" name="agency" required="">
  <option value="">Select an Agency</option>
  <?php 
   
   while ($data = mysqli_fetch_array($sql,MYSQLI_BOTH)) 
   { 
     $agency_id = $data['agency_id'];
     $sql2 = mysqli_query($con,"SELECT * FROM agencies WHERE id = '$agency_id'");
     $data2 = mysqli_fetch_array($sql2,MYSQLI_BOTH);
    ?>
     
     <option value="<?= $data2['id'] ?>"><?= $data2['company_re_name'] ?></option>


   <?php } 

  ?>


</select>
    </div><br>

    <div class="form-group">
      <label>Total Amount Recived:</label>
      <input type="number" onchange="calculations()" id="A" class="form-control" required="" name="total_amount">
      <h6> Amount recived in Ltd. Co Bank a/c </h6>
    </div><br> 

    <div class="row"> 
        <div class="col-md-6"> 
            <div class="form-group">
              <label>Night Out Expenses:</label>
              <input type="number" class="form-control" required="" name="night_expenses">
              <h6> Eg. Nights out </h6>
           </div>  
        </div>
        <div class="col-md-6">
            <div class="form-group">
              <label>Night Out Rate:</label>
              <input type="number" class="form-control" required="" name="night_rate">
           </div>
        </div>
     </div><br> 

     <div class="form-group">
      <label>Total Night Out Paid:</label>
      <input type="number" class="form-control" required="" name="night_paid">
      <h6> Night out x rate eg 4 x €25.00 </h6>
    </div><br> 

    <div class="form-group">
      <label>Parking Expenses:</label>
      <input type="number" class="form-control" required="" name="parking_expenses">
      <h6> Eg. Parking, tolls, Adblue </h6>
    </div><br> 


    <div class="form-group">
      <label>Less Deductible Expenses:</label>
      <input type="number" onchange="calculations()" id="B" class="form-control" required="" name="deductible_expenses">
    </div><br> 

    <div class="form-group">
      <label>Net Taxable Amount:</label>
      <input type="number" id="result1" readonly="" class="form-control" required="" name="taxable_amount">
    </div><br> 

    <div class="form-group">
      <label>Deductions Payable</label>
      <input type="number" readonly="" id="result2" class="form-control" required="" name="deduction_payable">
    </div><br> 

      <div class="form-group">
      <label>Please can you make your payment to:</label>
      <div class="container"> 
      <h6> AFFIRM ACCOUNTANCY SERVICES LIMITED </h6>
      <h6> NATWEST </h6>
      <h6> 60-21-59 </h6>
      <h6> 62077406 </h6>
      </div>
    </div><br> 

    <div class="form-group">
      <label>DATE PAID TO AFFIRM:</label>
      <input type="date" class="form-control" required="" name="date_paid">
    </div><br> 

    <div class="form-group">
        <label><p> I certify that my income for the week above is fully recorded and that i have complied with all Working-Time & EU Directives </p></label>
    </div><br> 
    
    <button type="submit" name="savecertified" class="btn btn-primary" onclick="save()">Submit</button>
  </form>
</div>

<br>  <br>  <br>  
</body>
</html>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<?php

if(isset($_GET['msg']))
{?>

 <script type="text/javascript">
   swal({
  title: "Data Saved!",
  text: "Your timesheet has been sent to selected agency.",
  icon: "success",
  button: "Close",
});
 </script>

<?php } 


if(isset($_GET['error']))
{?>

 <script type="text/javascript">
   swal({
  title: "Error!",
  text: "Timesheet Already submitted for this agency and week",
  icon: "error",
  button: "Close",
});
 </script>

<?php } ?>

  <script>
      $(function () {
        $('form').bind('save', function () {
          $.ajax({
            type: 'post',
            url: 'post.php',
            data: $('form').serialize(),
            success: function () {
              alert('form was submitted');
            }
          });
          return false;
        });
      });
    </script>





                <script type="text/javascript">
                  
                  function calculations()
                  {
                    var A = document.getElementById('A').value;
                    var B = document.getElementById('B').value;
                    result1 = document.getElementById('result1').value = A - B;
                    result2 = document.getElementById('result2').value = (A - B) * 0.10;
                  }

                </script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>