<?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("INSERT INTO other_accounts (date, show_date, php_date, title, description, receive, payment, type, bank) VALUES ('$date', '$show_date', '$php_date', 'null', '$description', '$receive', '$payment', 'null', '$bank')");
 			$sql = $db->query("INSERT INTO bank_accounts (date, show_date, php_date, title, description, receive, payment, type, bank) VALUES ('$date', '$show_date', '$php_date', 'null', '$description', '$receive', '$payment', '$type', '$bank')");

 		if ($sql) {
 			$success = "<strong>Success!</strong> Operation added successfully."; 
 		}else{
 			$danger = "<strong>Warning!</strong> This item name with same category already exist.";
 		} 
 } 
?>
	<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">

	<?php include 'accounttitleintoform.php'; ?>
	<?php include 'newbankname.php'; ?>
	
	<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> 
                    	Bank Sheet					<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 date("m/d/Y"); ?>" class="form-control datepicker" id="date">
					</div>
				</div>
				<!-- <div class="form-group">
					<label for="name" class="col-sm-3 col-md-3 col-lg-2 control-label required wide">Title :</label>					<div class="col-sm-9 col-md-9 col-lg-10">
						<input type="text" name="title" value="" id="title" list="listItems" class="form-control form-inps">
						<datalist id="listItems">
						<?php
							$listItems = $db->query("SELECT * FROM account_title");

							while($listrow = $listItems->fetchArray()){
						?>
							<option value="<?php echo $listrow['name']; ?>">
						<?php } ?>	
						</datalist>
						<a href="addtitle.php" target="_blank" id="addtitle"><input type="button"  value="Add Account Title" class=" submit_button btn btn-success"></a>
					</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>
						</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"  class="form-control" id="bank">
					<a href="addbank.php" target="_blank" id="addbank"><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="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">
						<input type = "text" name="description" class = "form-control">
					</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="" 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="" 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'; ?>
<script>
	$(document).ready(function(){
		$('#addtitle').on('click', function(e){
			e.preventDefault();
			$('#accounttitleform').show();
		});

		$('#closeaccounttitleform').on('click', function(){
			$('#accounttitleform').hide();
		});

		$('#submitaccounttitle').on('click', function(e){
			e.preventDefault();

			var uname = $('#acname').val();
			$.ajax({
			  method: "POST",
			  url: "addnewtitlefromaccounttitle.php",
			  async:false,
			  data: { uname: uname },
			  dataType: 'html',
			  success: function( data ) {
			  	$('#listItems').append(data);
			  	$('#title').focus();
			  }
		});
			$('#accounttitleform').hide();
		});
	});

	$(document).ready(function(){
		$('#addbank').on('click', function(e){
			e.preventDefault();
			$('#newbankform').show();
		});

		$('#closebankform').on('click', function(){
			$('#newbankform').hide();
		});

		$('#submitbank').on('click', function(e){
			e.preventDefault();

			var bname = $('#bname').val();
			var obname = $('#obname').val();
			$.ajax({
			  method: "POST",
			  url: "addnewbankname.php",
			  async:false,
			  data: { bname: bname, obname: obname },
			  dataType: 'html',
			  success: function( data ) {
			  	$('#bankNames').append(data);
			  	$('#bank').focus();
			  }
		});
			$('#newbankform').hide();
		});
	});
</script>	