<?php 
include 'dheader.php';
$success = "";
$danger = "";
if (isset($_POST['submitf'])) {
 	# code...
 	extract($_POST, EXTR_OVERWRITE);
 	$date = $_POST['date'];
	$change_date = explode("/", $date);
	$show_date = $change_date[1]."/".$change_date[0]."/".$change_date[2];
	$php_date = $change_date[2]."/".$change_date[0]."/".$change_date[1];

 		$sql = $db->query("UPDATE bank_accounts SET date = '$date', show_date = '$show_date', php_date = '$php_date', description = '$description', receive = '$receive', payment = '$payment', type = $type, bank = '$bank' WHERE id = '".$_GET['edit']."' ");

 		if ($sql) {
 			$success = "<strong>Success!</strong> Operation updated successfully."; 
 		}else{
 			$danger = "<strong>Warning!</strong> This item name with same category already exist.";
 		} 
 } 
 $select = $db->query("SELECT * FROM bank_accounts WHERE id = '".$_GET['edit']."'");
 $fetch = $select->fetchArray();
?>
	<div class="modal fade hidden-print" id="myModal" tabindex="-1" role="dialog" aria-hidden="true"></div>
	<div class="wrapper ">
		<?php include 'leftbar.php'; ?>
		<!-- left-bar -->
		<?php include 'topbar.php'; ?>
			<!-- top-bar -->
			<div class="main-content">

<div class="row" id="form">
	<div class="spinner" id="grid-loader" style="display:none">
	  <div class="rect1"></div>
	  <div class="rect2"></div>
	  <div class="rect3"></div>
	</div>
	
	<div class="col-md-12">
		<form action="" id="customer_form" class="form-horizontal" enctype="multipart/form-data" method="post" accept-charset="utf-8" novalidate="novalidate" autocomplete="off">
			<div class="col-md-12">
	<div class="panel panel-piluku">
		<div class="panel-heading">
                <h3 class="panel-title">
                    <i class="ion-edit"></i> 
                    	Other Accounts						<small>(Fields in red are required)</small>
                </h3>
        </div>

			<div class="panel-body">
				<?php
                    if (isset($_POST['submitf'])) {
                    ?>
                    <div class="alert alert-<?php echo ($success) ? "success" : "danger"; ?>"> 
                            <?php echo ($success) ? $success : $danger; ?>                          
                    </div>
                 <?php } ?>
                <div class="form-group">
					<label for="date" class="col-sm-3 col-md-3 col-lg-2 control-label required">Date :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="date" autofocus="on"  value="<?php echo $fetch['date']; ?>" class="form-control datepicker" id="date">
					</div>
				</div>

				
				<div class="form-group">
					<label for="description" class="col-sm-3 col-md-3 col-lg-2 control-label required wide">Description :</label>						<div class="col-sm-9 col-md-9 col-lg-10">
						<textarea name="description" style="width: 100%; height: 100px;"><?php echo $fetch['description']; ?></textarea>
					</div>
				</div>

				<div class="form-group">
				<label for="type" class="col-sm-3 col-md-3 col-lg-2 control-label not_required">Payment Type :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
						<select name="type" class="form-control" id="type">

							<option value="2">Bank</option>
							<option value="1">Cash</option>
							<option value="3">Opening</option>
						</select>
					</div>
				</div>

				<div class="form-group">	
					<label for="bank" class="col-sm-3 col-md-3 col-lg-2 control-label ">Bank :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="bank" list="bankNames" value="<?php echo $fetch['bank']; ?>"  class="form-control" id="bank">
					<a href="addbank.php" target="_blank"><input type="button"  value="Add Bank" class=" submit_button btn btn-success"></a>
						<datalist id="bankNames">
						<?php
			                $sn4d  = "SELECT * FROM ";
			                $sn4d .= "bank";
			                $sn4d_run = $db->query($sn4d);
			                while($sn4d_row = $sn4d_run->fetchArray())
			                {
			            ?>
			                <option value="<?php echo $sn4d_row["name"]; ?>">
			            <?php
			                }
			            ?>    
			            </datalist>
					</div>
				</div>

				 <div class="form-group">
					<label for="receive" class="col-sm-3 col-md-3 col-lg-2 control-label required">Debit :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="receive" value="<?php echo $fetch['receive']; ?>" class="form-control" id="receive">
					</div>
				</div>

				<div class="form-group">
					<label for="payment" class="col-sm-3 col-md-3 col-lg-2 control-label required">Credit :</label>			<div class="col-sm-9 col-md-9 col-lg-10">
					<input type="text" name="payment" value="<?php echo $fetch['payment']; ?>" class="form-control" id="payment">
					</div>
				</div>

				<div class="form-actions pull-right">
										&nbsp;
					<input type="submit" name="submitf" value="Submit" id="submitf" class="submit_button btn btn-primary">
				</div>

			
							</div><!--/panel-body -->
		</div><!-- /panel-piluku -->


	</div>
			
		</form>
			</div>
		</div><!-- /row -->


	

			
<?php include 'dfooter.php'; ?>