<!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">Update 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 
                $sel=mysqli_query($connect,"select * from tbl_voucher_details where fld_voucher_details_id='".$_GET['fld_voucher_details_id']."'") or die(mysqli_error($connect));
                $fetch=mysqli_fetch_array($sel);
            ?> 	
						<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" placeholder="Voucher Id" required="" name="voucher_id" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" value="<?php echo $fetch['fld_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 if ($fetch['fld_payee_id']==$row['fld_payee_id']){echo "selected";} ?>><?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 if ($fetch['fld_voucher_type_id']==$row['fld_voucher_type_id']){echo "selected";} ?>><?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 if ($fetch['fld_voucher_category_id']==$row['fld_voucher_category_id']){echo "selected";} ?>><?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');"><?php echo $fetch['fld_description']?></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="tel" placeholder="Amount" required="" oninput="this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1');" name="amount" id="amount" value="<?php echo $fetch['fld_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" id="gst" class="form-control" 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 if ($fetch['fld_gst']==$row['fld_gst']){echo "selected";} ?>><?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" value="<?php echo $fetch['fld_final_amount']; ?>" 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 if ($fetch['fld_payment_mode_id']==$row['fld_payment_mode_id']){echo "selected";} ?>><?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" value="<?php echo $fetch['fld_voucher_date'];?>">
							</div>
						</div>
						<div class="form-group row">
							<div class="col-sm-12 col-md-10">
							<center><input class="btn btn-success" value="Update" type="submit" name="update">&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>
	
</body>

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

	extract($_POST);
$abc=mysqli_query($connect,"select * from tbl_voucher_details where 
			fld_voucher_id='".$voucher_id."' and fld_voucher_details_id!='".$_GET['fld_voucher_details_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
	{
	$voucher_date=$_POST['voucher_date'];
	$new_voucher_date= date("Y-m-d",strtotime($voucher_date));

	$update=mysqli_query($connect,"update tbl_voucher_details set
                fld_voucher_id='".$_POST['voucher_id']."',
                fld_payee_id='".$_POST['payee']."',
                fld_voucher_type_id='".$_POST['voucher_type']."',
                fld_voucher_category_id='".$_POST['voucher_category']."',
                fld_description='".$_POST['description']."',
                fld_amount='".$_POST['amount']."',
                fld_gst_id='".$_POST['gst']."',
                 fld_final_amount='".$_POST['final_amount']."',
                fld_payment_mode_id='".$_POST['payment_mode']."',
                fld_voucher_date='".$new_voucher_date."'
                where fld_voucher_details_id='".$_GET['fld_voucher_details_id']."'") or die(mysqli_error($connect));
	if ($update) 
	{
	    echo "<script>";
	    echo "alert('Voucher Details Update Successfully');";
	    echo "window.location.href='view_voucher_details.php';";
	    echo "</script>";                 
	}
	else
	{
	    echo "<script>";
	    echo "alert('Error');";
	    echo "</script>";
	}
	}
	 }




 ?>
