<?php

include 'load.php';


if(isset($_GET['expid'])){
	$expid=mysqli_real_escape_string($conn,$_GET['expid']);
	$view_qury=mysqli_query($conn,"SELECT * FROM mobileexpense WHERE expid='$expid'");
	$view_result=mysqli_fetch_array($view_qury);
}

else{
	echo "<script>window.location='expenselist.php';</script>";
}


	if(isset($_POST['update'])){

		$expid = $_GET['expid'];
		$expcategory = $_POST['expcategory'];
		$expdate = $_POST['expdate'];
		$amount = $_POST['amount'];
		$refno = $_POST['refno'];
		$expname = $_POST['expname'];
		$expdescription = $_POST['expdescription'];
		$status = $_POST['status'];
		
    if(!isset($errMSG)){
			
      $stmt = $DB_con->prepare('UPDATE mobileexpense
			SET expcategory=:expcategory,
			expdate=:expdate,
			amount=:amount,
			refno=:refno,
			expname=:expname,
			expdescription=:expdescription,
			status=:status
			WHERE expid=:expid');
			$stmt->bindParam(':expcategory',$expcategory);
			$stmt->bindParam(':expdate',$expdate);
			$stmt->bindParam(':amount',$amount);
			$stmt->bindParam(':refno',$refno);
			$stmt->bindParam(':expname',$expname);
			$stmt->bindParam(':expdescription',$expdescription);
			$stmt->bindParam(':status',$status);
			$stmt->bindParam(':expid',$expid);
			
      if($stmt->execute()){
		  
			$successMSG = "Expense Successfully Updated ...";
				
			header("refresh:2;expenselist.php"); // redirects image view page after 5 seconds.
				
			}else{
				
			$errMSG = "Sorry Data Could Not Updated !";
				
			}
		
    }

}
	
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
<meta name="description" content="POS - Payroll | Pos & Invetory System | Dashboard

">
<meta name="keywords" content="Payroll | Pos & Invetory System | Dashboard

">
<meta name="author" content="Payroll | Pos & Invetory System | Dashboard

">
<meta name="robots" content="noindex, nofollow">

<title>Home | Payroll | Pos & Invetory System | Dashboard

</title>


<?php
require_once 'headercss.php';
?>
</head>
<body>
<div id="global-loader">
<div class="whirly-loader"> </div>
</div>

<div class="main-wrapper">
<?php
require_once 'header.php';
?>

<?php
require_once 'navbar.php';
?>

<div class="page-wrapper">
<div class="content">
<div class="page-header">
<div class="page-title">
<h4>Expense EDIT</h4>
<h6>Add/Update Expenses</h6>
</div>
</div>
<div class="card">
<div class="card-body">
<div class="row">
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Expense Category</label>
<select name="expcategory" class="select" id="inputcategory">
										<option value="<?php

												$id = $view_result['expcategory']; 

												$query = $DB_con->prepare('SELECT epid FROM mobileexpensecategory WHERE epid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['epid'];

												?>"><?php

												$id = $view_result['expcategory'];  

												$query = $DB_con->prepare('SELECT epname FROM mobileexpensecategory WHERE epid='.$id);

												$query->execute();

												$result = $query->fetch();

												echo $result['epname'];

												?></option>
										<?php

										$stmt = $DB_con->prepare('SELECT * FROM mobileexpensecategory ORDER BY epid');

										$stmt->execute();

										if($stmt->rowCount() > 0)

										{

										while($row=$stmt->fetch(PDO::FETCH_ASSOC))

										{

										extract($row);

										?>
										<option value="<?php echo $row['epid']; ?>"><?php echo $row['epname']; ?></option>
										<?php 
										} 
										}
										?>
</select>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Expense Date </label>
<div class="input-groupicon">
<input type="text" name="expdate" placeholder="Choose Date" class="datetimepicker" value="<?php echo $view_result['expdate']; ?>">
<div class="addonset">
<img src="assets/img/icons/calendars.svg" alt="img">
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Amount</label>
<div class="input-groupicon">
<input type="text" name="amount" class="form-control" placeholder="Enter Amount" value="<?php echo $view_result['amount']; ?>">
<div class="addonset">
<img src="assets/img/icons/dollar.svg" alt="img">
</div>
</div>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Reference No.</label>
<input type="text">
<input type="text" name="refno" class="form-control" placeholder="Enter Reference No" value="<?php echo $view_result['refno']; ?>">
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<label>Expense for</label>
<input type="text">
<input type="text" name="expname" class="form-control" placeholder="Enter Expense" value="<?php echo $view_result['expname']; ?>">
</div>
</div>
<div class="col-lg-12">
<div class="form-group">
<label>Description</label>
<textarea class="form-control" name="expdescription" placeholder="Enter Credit"></textarea>
</div>
</div>
<div class="col-lg-3 col-sm-6 col-12">
<div class="form-group">
<label>Status</label>
<select class="form-control" name="status" required>
<option value="1"<?php if($view_result['status']=="1"){echo "selected";} ?>>Active</option>
<option value="0"<?php if($view_result['status']=="0"){echo "selected";} ?>>Deactive</option>
</select>
</div>
</div>
<div class="col-lg-12">
<a href="expenseexpense.php" class="btn btn-cancel">Cancel</a>
<button type="submit" name="update" class="btn btn-submit me-2">Update</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>


<script src="assets/js/jquery-3.6.0.min.js"></script>

<script src="assets/js/feather.min.js"></script>

<script src="assets/js/jquery.slimscroll.min.js"></script>

<script src="assets/js/jquery.dataTables.min.js"></script>
<script src="assets/js/dataTables.bootstrap4.min.js"></script>

<script src="assets/js/bootstrap.bundle.min.js"></script>

<script src="assets/plugins/select2/js/select2.min.js"></script>

<script src="assets/js/moment.min.js"></script>
<script src="assets/js/bootstrap-datetimepicker.min.js"></script>

<script src="assets/plugins/sweetalert/sweetalert2.all.min.js"></script>
<script src="assets/plugins/sweetalert/sweetalerts.min.js"></script>

<script src="assets/js/script.js"></script>
</body>
</html>