<!DOCTYPE html>
<html>
<head>
	<?php include('include/head.php'); ?>
</head>
<body>
	<?php include('include/header.php'); ?>
	<?php include('include/sidebar.php'); ?>
	<div class="main-container">
		<div class="pd-ltr-20 xs-pd-20-10">
			<div class="min-height-200px">
				<div class="page-header">
					<div class="row">
						<div class="col-md-6 col-sm-12">
							<div class="title">
								<h4>Voucher Details</h4>
							</div>
							<nav aria-label="breadcrumb" role="navigation">
								<ol class="breadcrumb">
									<li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
									<li class="breadcrumb-item active" aria-current="page">Add Voucher Details</li>
								</ol>
							</nav>
						</div>
						<div class="col-md-6 col-sm-12 text-right">
							<div class="dropdown">
								<a class="btn btn-primary" href="view_voucher_details.php" role="button">
									View Voucher Details
								</a>
							</div>
						</div>
					</div>
				</div>
				<!-- Default Basic Forms Start -->
				<div class="pd-20 bg-white border-radius-4 box-shadow mb-30">
					<form method="post">
			<?php 
              $select1=mysqli_query($connect,"select fld_voucher_details_id from tbl_voucher_details order by fld_voucher_details_id desc limit 1") or die(mysqli_error($connect));
              $fetch1=mysqli_fetch_array($select1);
              $voucher_id=$fetch1['fld_voucher_details_id'];
            ?>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Voucher Id<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" name="voucher_id"value="<?php echo "GBV" . ++$voucher_id;?>" readonly>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Name of Payee<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="payee" class="form-control" required="">
                    				<option value="">Select Name of Payee</option>
                                    <?php
                                        
                                        $query1=mysqli_query($connect,"select distinct fld_payee_name,fld_payee_id from tbl_payee where fld_payee_delete='0' order by fld_payee_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);

                                      ?>
                                    <option value="<?php echo $row['fld_payee_id'];?>"><?php echo $row['fld_payee_name'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Select Voucher Type<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="voucher_type" class="form-control" required="">
                    				<option value="">Select Voucher Type</option>
                                    <?php
                                        
                                        $query1=mysqli_query($connect,"select distinct fld_voucher_type,fld_voucher_type_id from tbl_voucher_type where fld_voucher_type_delete='0' order by fld_voucher_type_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);

                                      ?>
                                    <option value="<?php echo $row['fld_voucher_type_id'];?>"><?php echo $row['fld_voucher_type'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Select Voucher Category<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="voucher_category" class="form-control" required="">
                    				<option value="">Select Voucher Category</option>
                                    <?php
                                        
                                        $query1=mysqli_query($connect,"select distinct fld_voucher_category,fld_voucher_category_id from tbl_voucher_category where fld_voucher_category_delete='0' order by fld_voucher_category_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);

                                      ?>
                                    <option value="<?php echo $row['fld_voucher_category_id'];?>"><?php echo $row['fld_voucher_category'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Description<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<textarea class="form-control" name="description" placeholder="Description" oninput="this.value = this.value.replace(/[^a-zA-Z\s.]/g, '').replace(/(\..*)\./g, '$1');"></textarea>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Enter Amount<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control" type="text" placeholder="Amount" required="" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" name="amount" id="amount">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Select GST Percentage<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="gst" class="form-control" id="gst" required="" onchange="fn1()">
                    				<option value="">Select GST Percentage</option>
                                    <?php
                                        
                                        $query1=mysqli_query($connect,"select distinct fld_gst,fld_gst_id from tbl_gst where fld_gst_delete='0' order by fld_gst_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);

                                      ?>
                                    <option value="<?php echo $row['fld_gst'];?>"><?php echo $row['fld_gst'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Final Amount<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input type="text" name="final_amount" id="final_amount" class="form-control" readonly="">
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Select Payment Mode<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<select name="payment_mode" class="form-control" required="">
                    				<option value="">Select Payment Mode</option>
                                    <?php
                                        
                                        $query1=mysqli_query($connect,"select distinct fld_payment_mode,fld_payment_mode_id from tbl_payment_mode where fld_payment_mode_delete='0' order by fld_payment_mode_id desc");
                                        while($row=mysqli_fetch_assoc($query1)){
                                          extract($row);

                                      ?>
                                    <option value="<?php echo $row['fld_payment_mode_id'];?>"><?php echo $row['fld_payment_mode'];?></option>
                                    <?php  }?>
                				</select>
							</div>
						</div>
						<div class="form-group row">
							<label class="col-sm-12 col-md-2 col-form-label">Voucher Date<span class="text-danger">*</span> :</label>
							<div class="col-sm-12 col-md-10">
								<input class="form-control date-picker" placeholder="Select Date" type="text" name="voucher_date">
							</div>
						</div>
						<div class="form-group row">
							<div class="col-sm-12 col-md-10">
							<center><input class="btn btn-success" value="Submit" type="submit" name="submit">&nbsp;
								<input class="btn btn-danger" value="Reset" type="reset">&nbsp;
								<a href="view_voucher_details.php" class="btn btn-warning">Back</a></center>
							</div>
						</div>
					</form>
			</div>
			<?php include('include/footer.php'); ?>
		</div>
	</div>
	<?php include('include/script.php'); ?>
	<script type="text/javascript">
		function fn1()
{
	 var pri=parseInt(document.getElementById('amount').value);
	var qui=parseInt(document.getElementById('gst').value);

	var result=parseInt(pri) + (parseInt(pri) * parseInt(qui)/100);
	
	document.getElementById('final_amount').value=result;
}
</script>
<!-- <script>
        $(document).ready(function() {
        	var qui=parseInt(document.getElementById('gst').value);
            $('#amount').keyup(function(ev) {
                var total = $('#amount').val() * 1;
                var tot_price = total + (total * qui);
                var divobj = document.getElementById('final_amount');
                divobj.value = tot_price;
            });
        });
    </script> -->
	
</body>

<?php 
	if (isset($_POST['submit'])) 
	{

	extract($_POST);

	$voucher_date=$_POST['voucher_date'];
	$new_voucher_date= date("Y-m-d",strtotime($voucher_date));

	$abc=mysqli_query($connect,"select * from tbl_voucher_details where 
			fld_voucher_id='".$voucher_id."'");

	if(mysqli_num_rows($abc)==1)
	{
	    echo "<script>";
	    echo "alert('Voucher Id Alrady Exist');";
	    //echo "window.location.href='view_course_details.php';";
	    echo "</script>";
	}
	else
	{
	 $query="INSERT INTO tbl_voucher_details(fld_voucher_id,fld_payee_id,fld_voucher_type_id,fld_voucher_category_id,fld_description,fld_amount,fld_gst_id,fld_final_amount,fld_payment_mode_id,fld_voucher_date) VALUES ('$voucher_id','$payee','$voucher_type','$voucher_category','$description','$amount','$gst','$final_amount','$payment_mode','$new_voucher_date')";
	//echo $query."<br>";
	$row=mysqli_query($connect,$query) or die(mysqli_error($connect));
	if ($row) 
	{
	    echo "<script>";
	    echo "alert('Voucher Details Added Successfully');";
	    echo "window.location.href='view_voucher_details.php';";
	    echo "</script>";                 
	}
	else
	{
	    echo "<script>";
	    echo "alert('Error');";
	    echo "</script>";
	}
	}
	 }




 ?>
