<?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");?>
 <?php
$errMsg=""; 
if(isset($_POST['submit'])) // To check 'submmited or not' by if(isset($_POST['submit'])) 
{
	$amount = $_POST['amount'];
	$amount_t = $amount;
	$bank_id_from = $_POST['bank_id_from'];
	$bank_id_to = $_POST['bank_id_to'];
	$cheque_no = $_POST['cheque_no'];
	$cheque_date = $_POST['cheque_date'];
	if(!empty($cheque_date)) {
$newDate = date("Y-m-d", strtotime($cheque_date));
}
else {
$newDate = "";
}
	$date = date("Y-m-d");
	
	if(empty($amount)) $errMsg="write the amount of taka";
	if(empty($errMsg))
	{
			

		$check=mysqli_query($connection,"select * from bank_name where bank_id = $bank_id_from and balance>='$amount_t'");
		$checkrows=mysqli_num_rows($check);
		if($checkrows<1){$errMsg="Sorry!! You Don't have Sufficient balance";}
		
		else{
		
		
		mysqli_query($connection,"UPDATE bank_name SET balance = balance-$amount_t WHERE bank_id = $bank_id_from")
				or die(mysqli_error()); 
				
		
		if(!empty($bank_id_to)) {


	mysqli_query($connection,"UPDATE bank_name SET balance = balance + $amount_t WHERE bank_id = $bank_id_to")
				or die(mysqli_error());
		
		//mysqli_query($connection,"INSERT INTO bank_statement (amount, payment_type, reason, bank_id, cheque_no, cheque_date, date) VALUES ('$amount_t','debit','Cash to Bank Transfer','$bank_id','$cheque_no','$newDate','$date')")
		//or die(mysqli_error());
		
		
		 mysqli_query($connection,"INSERT INTO transaction (date, ref_id, ledger, credit, cheque_no, cheque_date, bank_id, hint, payment_type, branch_id) VALUES ('$newDate','$cheque_no','15','$amount_t','$cheque_no','$newDate','$bank_id_from','Cash to Bank Transfer','bank','$branch_id_for_header_user')")
		or die(mysqli_error());
		
		 mysqli_query($connection,"INSERT INTO transaction (date, ref_id, ledger, debit, cheque_no, cheque_date, bank_id, hint, payment_type, branch_id) VALUES ('$newDate','$cheque_no','15','$amount_t','$cheque_no','$newDate','$bank_id_to','Cash to Bank Transfer','bank','$branch_id_for_header_user')")
		or die(mysqli_error());
		
		
		 
		}
		
		$errMsg="Money has been transfered from Bank to Bank";
		}
		
}
}
?>
            <!-- 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">
                        
                 <!---Main Content--->
                
                            
                           <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">Money transfer from Bank To Bank</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">Money Amount </label>
                                            <input type="text" class="form-control" name="amount" placeholder="write here">
                                        </div>
                                        
                                          <div class="form-group">
                                            <label for="exampleInputEmail1">Transfer From</label>
                                            <select name="bank_id_from" class="form-control">
												<?php  
                                                $query_bank = "select * from bank_name";
                                                $result_bank = mysqli_query($connection,$query_bank);
                                                
                                               
                                                while($row_bank=mysqli_fetch_array($result_bank))
                                                {
                                                
                                                echo "<option value='" . $row_bank['bank_id'] . "'>" . $row_bank['bank_name'] . "</option>";}?> 
                                            
                                            </select>
                                            
                                            
                                            
                                        </div>
                                        
                                        
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Transfer To</label>
                                            <select name="bank_id_to" class="form-control">
												<?php  
                                                $query_bank = "select * from bank_name";
                                                $result_bank = mysqli_query($connection,$query_bank);
                                                
                                               
                                                while($row_bank=mysqli_fetch_array($result_bank))
                                                {
                                                
                                                echo "<option value='" . $row_bank['bank_id'] . "'>" . $row_bank['bank_name'] . "</option>";}?> 
                                            
                                            </select>
                                            
                                            
                                            
                                        </div>
                                        
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Cheque Number</label>
                                            <input type="text" class="form-control" name="cheque_no" id="" placeholder="write cheque number">
                                        </div>
                                        <div class="form-group">
                                            <label for="exampleInputEmail1">Cheque Date</label>
                                            <input type="text" class="form-control datepicker" autocomplete="off" name="cheque_date" placeholder="write cheque date">
                                        </div>
                                    </div><!-- /.box-body -->

                                    <div class="box-footer">
                                        <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                                    </div>
                                </form>
                            </div>
                         
                         </div> 
                 
                 		
                    </div>
                 
                 
                 </section>
                </aside>
                <!-- /.right-side -->
        </div><!-- ./wrapper -->

        <!-- add new calendar event modal -->


         <?php include("sass/footer_for_datepicker_and_datatable.php");?>
    </body>
</html>