<?php


include('../conn.php');
include('../common/head.php');




if(isset($_POST['submit'])){
 
    $name=addslashes($_POST['name']);
     $number=$_POST['contact'];
    $contact_person=$_POST['contact_person'];
     $adults=$_POST['adults'];
     $kids=$_POST['kids'];
     $men_swim_trk=$_POST['men_swim_trk'];
     $women_swim_trk=$_POST['women_swim_trk'];
     $jackets=$_POST['jacket'];
     $date=$_POST['date'];
     $time=$_POST['time'];
     $payment=$_POST['payment'];
     $orderid=$_POST['orderid'];
     $by=$_POST['by'];
     if ($payment=='nun') {
      echo"<script>alert('Please Select payment method'); window.location.href='../facility'</script>";
     }
     else {

     if ($kids==0) {
       $kdisplay='none';
     }
     if ($adults==0) {
        $adisplay='none';
      }
      if ($men_swim_trk==0) {
        $mdisplay='none';
      }
      if ($women_swim_trk==0) {
        $wdisplay='none';
      }
      if ($jackets==0) {
        $jdisplay='none';
      }

$per_adult=30;
$per_kid=20;
$men_swim=80;
$women_swim=100;
$jacket=10;

$real_id=substr($orderid,-2);
$ord = sprintf('%03d',$real_id);  

$sql="select * from tax where status='1'";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {
$data=$row['id'];
$tax=$row['tax'];
$percent=$row['percent']; 
}
$sql7="SELECT  sum(percent) FROM tax  WHERE status='1'";
  $result7 = mysqli_query($conn,$sql7)or die( mysqli_error($conn));
  $row7=mysqli_fetch_array($result7) ;
  
      $total_tax= $row7[0];




$amount_per_adult=$per_adult*$adults;
$amount_per_kid=$per_kid*$kids;
$amount_men_swim=$men_swim*$men_swim_trk;
$amount_women_swim=$women_swim*$women_swim_trk;
$amount_jacket=$jacket*$jackets;



$amount=$amount_per_adult+$amount_per_kid+$amount_men_swim+$amount_women_swim+$amount_jacket;
$total_tax_payable=$amount*$total_tax/100;
$amount_payable=$amount+$total_tax_payable;
}
$sql1="SELECT * FROM currency ";
$result1 = mysqli_query($conn,$sql1)or die( mysqli_error($conn));
$row1=mysqli_fetch_array($result1) ;
$currency=$row1['curency'];

$sql = "SELECT `number` FROM `customers` WHERE `number`='".$number."'";
$result = $conn->query($sql);

if($result->num_rows >= 1) {
 
} else {
   // Image db insert sql
   $sql = "INSERT INTO `customers`(`fname`, `number`, `date`,`by`) VALUES ('$name','$number','$date','$by')";
   if(mysqli_query($conn,$sql)){


   }
   else{
     echo 'Error: '.mysqli_error($conn);
   }

}
$per_adult=30;
$per_kid=20;
$men_swim=80;
$women_swim=100;
$jacket=10;

$sql="select * from tax where status='1'";
$result = mysqli_query($conn,$sql)or die( mysqli_error($conn));
while ($row=mysqli_fetch_array($result)) {
$data=$row['id'];
$tax=$row['tax'];
$percent=$row['percent']; 
}
$sql7="SELECT  sum(percent) FROM tax  WHERE status='1'";
$result7 = mysqli_query($conn,$sql7)or die( mysqli_error($conn));
$row7=mysqli_fetch_array($result7) ;

 $total_tax= $row7[0];




$amount_per_adult=$per_adult*$adults;
$amount_per_kid=$per_kid*$kids;
$amount_men_swim=$men_swim*$men_swim_trk;
$amount_women_swim=$women_swim*$women_swim_trk;
$amount_jacket=$jacket*$jackets;



$amount=$amount_per_adult+$amount_per_kid+$amount_men_swim+$amount_women_swim+$amount_jacket;
$total_tax_payable=$amount*$total_tax/100;
$amount_payable=$amount+$total_tax_payable;


$sql = "SELECT `orderid` FROM `pole` WHERE `orderid`='".$orderid."'";
$result = $conn->query($sql);

if($result->num_rows >= 1) {
    echo"<script>alert('You can not Submit one order times'); window.location.href='../pole'</script>";
 
} else {



$sql1 = "INSERT INTO `pole`(`orderid`, `name`, `number`, `contact_person`, `adults`, `kids`, `men_swim_trucks`, `women_swim_trucks`, `jackets`, `amount`, `payment_method`,`by`, `date`,`time` ) VALUES ('$orderid','$name','$number','$contact_person','$adults','$kids','$men_swim_trk','$women_swim_trk','$jackets','$amount_payable','$payment','$by','$date','$time')";
if(mysqli_query($conn,$sql1)){ 
    echo"<script>alert('Print reciept'); window.location.href='../print/pole_print.php?item=$orderid'</script>";
}
else{
echo 'Error: '.mysqli_error($conn);
}
}

}
?>

