<?php
@session_start();
@ob_start();

include "header.php"; 
//$objIms->bankdet_alter();
?>
<script type="text/javascript">
	$(document).ready(function() {                
				$("#FORMNAME1").validate({
                    rules: {
					
                   branch_name:"required",
				  bank_name:"required",
				  accno:"required",
					},
		messages: {
			
					 branch_name: "",
					 bank_name: "",
						accno:"",		
				},
		  });                
            });
//---auto search-----
</script>
<!-- Page wrapper  -->
        <div class="page-wrapper">
            
            <!-- Container fluid  -->
             <div class="container-fluid">
                <!-- Start Page Content -->
                <div class="row justify-content-center">
                    <div class="col-lg-6">
                        <div class="card">
						<h4>Add Bank Detail <span style="float:right"><button onclick="goBack()" class="btn btn-info btn-sm">Go Back</button><script>
function goBack() {
    window.history.back();
}
</script></span></h4>
						<hr />    <form method="post" id="FORMNAME1">
	<?php // echo $objIms->error;?>
									<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Bank Name <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="bank_name" type="text" id="bank_name"  class="form-control" style="width:200px;" required />
                                            </div>
                                        </div>
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Branch Name <span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                               <input name="branch_name" type="text" style="width:200px;" class="form-control" id="branch_name" required/>
                                            </div>
                                        </div>
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Account No.<span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="accno" type="text" id="accno" onkeypress='validate(event)' maxlength="15" class="form-control" style="width:200px;"required />
                                            </div>
                                        </div>
                    <div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Opening Date<span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="date" type="date" id="date" class="form-control" style="width:200px;"required />
                                            </div>
                                        </div>
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Ifsc<span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="ifsc" type="text" id="ifsc" class="form-control" style="width:200px;" required/>
                                            </div>
                                        </div>
										
										<div class="form-group row">
                                            <label class="col-lg-4 col-form-label" for="val-username">Opening Balance<span class="text-danger">*</span></label>
                                            <div class="col-lg-6">
                                                <input name="bln" type="text" id="bln"  onkeypress="return isNumber(event,this);"  class="form-control" style="width:200px;" required/>
                                            </div>
                                        </div>
	 									<div class="form-group row">
                                            <div class="col-lg-8 ml-auto">
                                                <input type ="submit" name="Save"  class="btn btn-info"/>
                                            </div>
                                        </div>

	
		
		
</form>
<?php
if(isset($_POST['Save'])){
// $date= date('Y-m-d');
$or_date = date('d-m-Y', strtotime($_POST['date']));  
$order_date=$objIms->DateToInt($or_date);

 $sql_ins="INSERT INTO `tbl_bank_detail` (`acc_no`, `bank_name`, `branch_name`, `ifsc`, `opening_bln`, `create_date`,stampdate, session_login_id) VALUES ('".$_POST['accno']."', '".$_POST['bank_name']."', '".$_POST['branch_name']."', '".$_POST['ifsc']."', '".$_POST['bln']."', '$date', '$order_date', '".$_SESSION['login_id']."');";
				$res_ins=mysql_query($sql_ins);
$last_id=mysql_insert_id();
//here bank account start captial account as opening account
 $sql_cap="INSERT INTO captial_ac (type, credit_amount, stampdate, session_login_id) values('Captial','".$_POST['bln']."',  '$order_date', '".$_SESSION['login_id']."');";
 $res_cap=mysql_query($sql_cap);


 $sql_bank = "insert into tbl_bank (bankdet_id, head, debit, stampdate, session_login_id) values('$last_id', 'Bank_opening', '".$_POST['bln']."',  '$order_date', '".$_SESSION['login_id']."');";
$res_bank = mysql_query($sql_bank);
				?>
				<script>
				alert('Success');
				location='bank_detail.php';
				</script>
				<?php

}
?>
  </div>

                            </div>
						
                            
                        </div>
                    </div>
                </div>
                <!-- End PAge Content -->
            </div>
            <!-- End Container fluid  -->

<?php include 'footer.php' ?>
<script type="text/javascript">
    
    $(function() {

  $('#bank_name').keydown(function (e) {
  
    if (e.ctrlKey || e.altKey) {
    alert("only character allow");
      e.preventDefault();
      
    } else {
    
      var key = e.keyCode;
      
      if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key == 20) || (key == 9) || (key == 16) )) {
        alert("only character allow");
        e.preventDefault();
        
      }

    }
    
  });
  
});
</script>
<script type="text/javascript">
function isNumber(evt, element) {
  var charCode = (evt.which) ? evt.which : event.keyCode
  if (charCode > 31 && (charCode < 48 || charCode > 57) && !(charCode == 46 || charCode == 8))
    return false;
  else {
    var len = $(element).val().length;
    var index = $(element).val().indexOf('.');
    if (index > 0 && charCode == 46) {
      return false;
    }
    if (index > 0) {
      var CharAfterdot = (len + 1) - index;
      if (CharAfterdot > 3) {
        return false;
      }
    }

  }
  return true;
}


function validate(evt) {
  var theEvent = evt || window.event;
  var key = theEvent.keyCode || theEvent.which;
  key = String.fromCharCode( key );
  var regex = /[0-9]|\./;
  if( !regex.test(key) ) {
    theEvent.returnValue = false;
    if(theEvent.preventDefault) theEvent.preventDefault();
  }
}
</script>