<?php include("sass/icon_for_datepicker_and_datatable.php");?>
              
        <div class="wrapper row-offcanvas row-offcanvas-left">
            <!-- Left side column. contains the logo and sidebar -->
            <?php include("sass/sidebar.php");?>

            <!-- Right side column. Contains the navbar and content of the page -->
               <aside class="right-side">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1>
                       <?php echo $company_name ; ?>
                        <small>Control panel</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
                        <li class="active">Dashboard</li>
                    </ol>
                </section>
                 <section class="content">
                 	 <div class="row">
                        <div class="col-md-12" id="formdiv">
                 <!---Main Content--->

	<?php
$errMsg=""; 
if(isset($_POST['submit'])) // To check 'submmited or not' by if(isset($_POST['submit'])) 
{
	$bank_name = $_POST['bank_name'];
	$ac_no = $_POST['ac_no'];
	$balance = $_POST['balance'];
	
	
	
	if(empty($bank_name)) $errMsg="enter bank_name name";
	if(empty($errMsg))
	{
		
		$check=mysqli_query($connection,"select * from bank_name where bank_name='$bank_name'");
		$checkrows=mysqli_num_rows($check);
		if($checkrows>0){$errMsg="You have entered this bank_name Name before";}
		
		else{
		
		if(empty($bank_name)) $errMsg="write bank name";
	if(empty($errMsg))
	{
		
		
		mysqli_query($connection,"INSERT INTO bank_name (bank_name, ac_no, balance) VALUES ('$bank_name','$ac_no','$balance')")
		or die(mysqli_error()); 
		
		$result_bank_name = mysqli_query($connection,"SELECT bank_id FROM bank_name WHERE bank_name  = '$bank_name' and ac_no = '$ac_no'");
		$test_bank_name = mysqli_fetch_array($result_bank_name);
				
				$bank_id=$test_bank_name['bank_id'];
		
		mysqli_query($connection,"INSERT INTO transaction (date, ledger, debit, bank_id, payment_type) VALUES ('2014-01-02','14','$balance','$bank_id','bank')")
		or die(mysqli_error()); 
		
		$errMsg="Bank name inserted successfully";
	
}
	}
}
}



 if(isset($_POST['update']))
    {
	
$bank_id = $_POST['bank_id'];
$bank_name = $_POST['bank_name'];
	$ac_no = $_POST['ac_no'];
	$balance = $_POST['balance'];
	mysqli_query($connection,"UPDATE bank_name SET bank_name ='$bank_name', ac_no ='$ac_no', balance ='$balance' WHERE bank_id = '$bank_id'")
				or die(mysqli_error()); 
	$errMsg="Bank Successfully Updated";
	}

?>
                 <?php
							if (!empty($errMsg)){echo "<div class='alert alert-warning alert-dismissible' role='alert'>$errMsg";
							echo "<button type='button' class='close' data-dismiss='alert'><span aria-hidden='false'>&times;</span><span class='sr-only'>		Close</span></button>
                        </div>";}
                        ?>
                 			<div class="box box-primary">
                                <div class="box-header">
                                    <h3 class="box-title">Bank Entry</h3>
                                </div><!-- /.box-header -->
                                <!-- form start -->
                                
                            
                                <form role="form"  action="<?php echo "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post" id="login_form">
                                    <div class="box-body">
                                    	<div class="col-md-12">
                                        <div class="col-md-6 col-md-offset-3">
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Bank Name</label>
                                            <input type="text" class="form-control" name="bank_name" >
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Account Number</label>
                                            <input type="text" class="form-control" name="ac_no" >
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Present Balance</label>
                                            <input type="text" class="form-control" name="balance" >
                                        </div>
                                        </div>
									</div>
												<!-- /.box-body -->

                                    <div class="box-footer">
                                        <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                </form>
                            </div>
                 
                 		</div>
                    </div>
                                          <img src="img/ajax-loader1.gif" style="display: none; margin-left:30%;" id="loading_image" width="50%">      
                 
                 
                 </section>
                 
                 
                 
                 <section class="content">
					<div class="box-body table-responsive" id="tbldiv">

                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            
                                            <tr>
                                                <th>Bank Name</th>
                                                <th>Account Number</th>
                                                <th>Current Balance</th>
                                                <th>Apply</th>
                                            </tr>
                                        </thead>
                                        <tbody>
										<?php
                                        
                                        $query = "SELECT * FROM bank_name";
                                        $result = mysqli_query($connection,$query);
                                        
										 $i=0;
                                        while($row=mysqli_fetch_array($result))
                                        {
                                        
                                         $i++;
										 $bank_id = $row['bank_id'];
											$bank_name = $row['bank_name'];
											$ac_no = $row['ac_no'];
											$balance = $row['balance'];
											
                                        
                                        
                                        echo "<tr>
                                        <td>$bank_name
										<input type='hidden' id='bank_name$i' value='$bank_name'/>
										</td>
                                        <td>$ac_no
										<input type='hidden' id='ac_no$i' value='$ac_no'/>
										</td>
                                        <td>$balance
										<input type='hidden' id='balance$i' value='$balance'/>
										</td>
                                        
                                        <td>
                                       <input type='hidden' id='zipsearch$i' value='$bank_id'/> <button type='button' class='btn btn-primary' data-toggle='modal' data-target='#myModal' onClick='sync$i()'><i class='fa fa-edit'></i> &nbsp;Edit</button>
									   
                                        </td> 
                                        </tr>";
										
										
										echo "<script>
function sync$i()
{
  var collect = document.getElementById('zipsearch$i');
  var entry = document.getElementById('xpaytype');
  
  
  var bank_namecollect = document.getElementById('bank_name$i');
  var bank_nameentry = document.getElementById('bank_name');
  
  
  var ac_nocollect = document.getElementById('ac_no$i');
  var ac_noentry = document.getElementById('ac_no');
 
  
  entry.value = collect.value;
  bank_nameentry.value = bank_namecollect.value;
  ac_noentry.value = ac_nocollect.value;
  
}
</script> ";

										
										}	
                                        ?>

                                        </tbody>
                                        <tfoot>
                                            
                                            <tr>
                                                <th>Bank Name</th>
                                                <th>Account Number</th>
                                                <th>Current Balance</th>
                                                <th>Apply</th>
                                            </tr>

                                        </tfoot>
                                    </table>
                                    
                                    
                                   <form method='post' action='<?php echo $_SERVER['SCRIPT_NAME']; ?>'>
										<div class='modal fade' id='myModal' tabindex='-1' role='dialog' aria-labelledby='myModalLabel' aria-hidden='true'>
  <div class='modal-dialog'>
    <div class='modal-content'>
      <div class='modal-header'>
        <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
        <h4 class='modal-title' id='myModalLabel'>Update Bank</h4>
      </div>
      <div class='modal-body'>
      <input type="hidden" id='xpaytype' name='bank_id' class='form-control'/>
        
                    <div class="form-group">
                        <input type="text" id='bank_name' name="bank_name" class="form-control"/>
                    </div>
                    <div class="form-group">
                        <input type="text" id='ac_no' name="ac_no" class="form-control" placeholder="ac_no"/>
                    </div>
                   
      </div>
      <div class='modal-footer'>
        <button type='button' class='btn btn-default' data-dismiss='modal'>Close</button>
        <button type='submit'  name="update" class='btn btn-primary'>Save</button>
      </div>
    </div>
  </div>
</div>
</form>








                                  
                                </div>
                </section>
                 
                </aside>
                <!-- /.right-side -->
        </div><!-- ./wrapper -->

        <!-- add new calendar event modal -->
<script type="text/javascript">
	 $('#login_form').submit(function() {
	$('#formdiv').hide();
	$('#tbldiv').hide();
    $('#loading_image').show(); // show animation
    return true; // allow regular form submission
});
 </script>

        <!-- jQuery 2.0.2 -->
         <?php include("sass/footer_for_datepicker_and_datatable.php");?>

    </body>
</html>