<?php include("sass/icon_for_datepicker_and_datatable.php");?>
        
        <?php
$errMsg=""; 
if(isset($_POST['submit'])) // To check 'submmited or not' by if(isset($_POST['submit'])) 
{
	$loan_bank_name = $_POST['loan_bank_name'];
	$ac_no = $_POST['ac_no'];
	$total_loan = $_POST['total_loan'];
	$total_loan = ($total_loan) ;
	
	if(empty($loan_bank_name)) $errMsg="write bank name";
	if(empty($errMsg))
	{
		
		
		mysqli_query($connection,"INSERT INTO loan_bank_name (loan_bank_name, ac_no, total_loan) VALUES ('$loan_bank_name','$ac_no','$total_loan')")
		or die(mysqli_error()); 
		
		$result_bank_name = mysqli_query($connection,"SELECT loan_bank_name_id FROM loan_bank_name WHERE loan_bank_name  = '$loan_bank_name' and ac_no = '$ac_no'");
		$test_bank_name = mysqli_fetch_array($result_bank_name);
				
				$loan_bank_name_id=$test_bank_name['loan_bank_name_id'];
		
		
		mysqli_query($connection,"INSERT INTO transaction (date, ledger, debit, loan_bank_name_id, payment_type) VALUES ('2014-01-02','primary loan','$total_loan','$loan_bank_name_id','cash')")
		or die(mysqli_error()); 
		
		mysqli_query($connection,"UPDATE cash SET amount = amount + $total_loan WHERE cash_id = 1")
				or die(mysqli_error());
		
		
		$errMsg="Bank name inserted successfully";
	
}
}
?>

        
        
        <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">Bank Setup</li>
                    </ol>
                </section>
                 <section class="content">
                 <!---Main Content--->
                 
                     <div class="row">
                     
                         <div class="col-md-8 col-md-offset-2">
                         
                       
                        <?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">Loan Bank Setup</h3>
                                </div><!-- /.box-header -->
                                <!-- form start -->
                                <form role="form"  action="<?php echo "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>" method="post">
                                    <div class="box-body">
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Bank Name</label>
                                            <input type="text" class="form-control" name="loan_bank_name" id="" placeholder="write bank name">
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Account Number</label>
                                            <input type="text" class="form-control" name="ac_no" id="" placeholder="write account number">
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Present Loan</label>
                                            <input type="text" class="form-control" name="total_loan" id="" placeholder="write the quantity here">
                                        </div>
                                    </div><!-- /.box-body -->

                                    <div class="box-footer">
                                        <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                </form>
                            </div>
                         
                         </div>
                         
                         
                         <div class="col-md-12">
                         
                         
                         <div class="box">
                                <div class="box-header">
                                    <h3 class="box-title">Bank list with details</h3>
                                </div><!-- /.box-header -->
                                <div class="box-body table-responsive">
                                    <table id="example1" class="table table-bordered table-striped">
                                        <thead>
                                            <tr>
                                                <th>Bank Name</th>
                                                <th>Account Number</th>
                                                <th>Present Loan</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            
												<?php
                                                
                                                $query = "SELECT * FROM loan_bank_name";
                                                $result = mysqli_query($connection,$query);
                                                
                                                $i=0;
                                                while($row=mysqli_fetch_array($result))
                                                {
                                                $i++;
												$loan_bank_name_id = $row['loan_bank_name_id'];
                                                $loan_bank_name = $row['loan_bank_name'];
                                                $ac_no = $row['ac_no'];
                                                $total_loan = $row['total_loan'];
												 $total_loan= ($total_loan); 
												
											
				
				                            
                                                echo "<tr>";
                                                echo "<td>$loan_bank_name</td>";
                                                echo "<td>$ac_no</td>";
                                                echo "<td>$total_loan</td>";
                                                echo "</tr>";
                                                }
                                                
                                                ?>
                                         
                                        </tbody>
                                        <tfoot>
                                            <tr>
                                                <th>Bank Name</th>
                                                <th>Account Number</th>
                                                <th>Present Loan</th>
                                            </tr>
                                        </tfoot>
                                    </table>
                                </div><!-- /.box-body -->
                            </div>
                         
                         </div>
                     
                     </div>
                 
                 
                 
                 
                 </section>
                </aside>
                <!-- /.right-side -->
        </div><!-- ./wrapper -->

        <!-- add new calendar event modal -->
 <script>
function EditProduct(id) {
    window.open('edit_bank.php?id='+id,'logos','width=500,height=500');}
</script>
  <!-- jQuery 2.0.2 -->
         <?php include("sass/footer_for_datatable.php");?>
    </body>
</html>