<?php  include_once('db.php');  include_once('check.php'); include_once('math.php'); ?>

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title> GFSL | CALCULATOR  </title>
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
  <link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <link rel="stylesheet" href="dist/css/skins/skin-black.min.css">
  <link rel="stylesheet" href="bower_components/DataTables/datatables.min.css">
  <link rel="stylesheet" href="bower_components/select2/dist/css/select2.min.css">
  <link rel="stylesheet" href="bower_components/jquery-ui/themes/smoothness/jquery-ui.min.css">
  <link rel="stylesheet" href="bower_components/sweetalert/dist/sweetalert2.min.css">
  <link rel="stylesheet" href="../assets/fonts/font.css">
  <link rel="stylesheet" href="../assets/fonts/mycss.css">
      
  

</head>
<body class="hold-transition skin-black sidebar-mini">
<div class="wrapper">

  <!-- Main Header -->
    <header class="main-header">
    <!-- Logo -->
    <?php  include_once('inc/brand.php'); ?>   
 

    <!-- Header Navbar -->
    <nav class="navbar navbar-static-top" role="navigation">
      <!-- Sidebar toggle button-->
      <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
        <span class="sr-only">Toggle navigation</span>
      </a>
      <!-- Navbar Right Menu -->
      <div class="navbar-custom-menu">
        <ul class="nav navbar-nav">
          <li class="dropdown user user-menu">
                        
                                  <a href="#" class="dropdown-toggle" data-toggle="dropdown">
              <!-- The user image in the navbar-->
              <img src="images/adminlog.jpg" class="user-image" alt="User Image">
              <span class="hidden-xs"> 
                                      <?php echo $user_firstname .''.$user_lastname; ?>  
              </span>
            </a>
            <ul class="dropdown-menu">
              <!-- The user image in the menu -->
              <li class="user-header">
                <img src="images/adminlog.jpg" class="img-circle" alt="User Image">
                <p>
                                <?php echo $user_firstname.''.$user_job_details;?>  
                </p>
              </li>
              <!-- Menu Body -->
              <!-- Menu Footer-->
              <li class="user-footer">
                <div class="pull-left">
                  <a href="profile.php" class="btn btn-default btn-flat">Profile</a>
                </div>
                <div class="pull-right">
                  <a href=" signout.php" class="btn btn-default btn-flat">Sign out</a>
                </div>
              </li>
            </ul>
          </li>
          <!-- Control Sidebar Toggle Button -->
          <li>
            <a href="#" data-toggle="control-sidebar"><i class="fa fa-gears"></i></a>
          </li>
        </ul>
      </div>
    </nav>
  </header>
  
  <!-- Left side column. contains the logo and sidebar -->
      <aside class="main-sidebar">
        <?php  include_once('inc/menu.php'); ?>
      </aside>

<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <section class="content container-fluid">

      <div class="row">
        <div class="col-md-12">
         <div class="col-md-12">
          <div class="nav-tabs-custom">
            <ul class="nav nav-tabs">             
              <li class="active"><a href="#categories" data-toggle="tab" > <i class="fa fa-money fa-lg" style="font-size:25px; color:blue;"></i> Loan Amortisation Schedule  </a></li>     
            </ul>

              <div class="tab-content">      
                <div class="active   tab-pane" id="categories">
<!-- start calculation -->
                 <div class="row" >

                <?php
                if (count($_POST) == 0 or @$_POST['reset']) 
                { // POST array is empty - set initial values
                    $principal = 0;
                    $number    = 0;
                    $rate      = 1.5;
                    $payment   = 0;
                    } 
                    else {

                                $principal = $_POST['principal'];
                                $number    = $_POST['number'];
                                $rate      = $_POST['rate'];
                                $payment   = $_POST['payment'];
                        } 
                    

                 if (isset($_POST['button1']))  // principal
                    {
                        $principal = calc_principal($number, $rate, $payment);
                    } 
                        if (isset($_POST['button2'])) // number
                            {
                            $number = calc_number($principal , $rate, $payment);
                            } 
                                if (isset($_POST['button3']))  // rate
                                    {
                                    $rate = calc_rate($principal, $number, $payment);
                                    } 
                                        if (isset($_POST['button4']))  // paymnets 
                                        {
                                            $payment = calc_payment($principal, $number, $rate, 2);
                                        } 

                ?>
                    <div class="col-md-6">
                        <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="POST">
                            <table border="1" class="table-bordered">
                                
                                    <tr class="">
                                        <td>Principal</td><td><input type="text" name="principal" class="form-control" value="<?php echo $principal ?>" >    
                                        </td><td><input type="submit" name="button1"  class="btn btn-success" value="calculate Principal" ></td>
                                    </tr>
                                    <tr>
                                        <td>Number of Payments</td><td><input type="text" name="number" class="form-control"  value="<?php echo $number ?>" >
                                        </td><td><input type="submit" name="button2" class="btn btn-success" value="calculate Number " ></td>
                                    </tr>
                                    <tr>
                                        <td>Interest Rate (%) per Payment</td><td><input type="text" class="form-control" name="rate" value="<?php echo $rate ?>" >
                                        </td><td><input type="submit" name="button3"  class="btn btn-success" value="calculate Interest   " ></td>
                                    </tr>
                                    <tr>
                                        <td>Payment</td><td><input type="text" name="payment"  class="form-control" value="<?php echo $payment ?>" >
                                        </td><td><input type="submit" name="button4" class="btn btn-success" value="calculate Payment" ></td>
                                    </tr>
                            </table>
                                
                            <p style="padding-top:10px;"><input type="submit" name="reset" value="Reset Data" class="btn btn-warning" >&nbsp;&nbsp;&nbsp;
                            <input type="submit" name="button5" value =" view Payment Schedule" class="btn btn-danger pull-right" ></p>
                        </form>

                    </div>

                    <div class="col-md-6">
                        <?php
                            if (isset($_POST['button5']))
                                {
                                    $t = print_schedule($principal, $rate, $payment);
                                     echo  $t ;
                                  //print_schedule($principal, $rate, $payment);
                               } 
                        ?>
                    </div>

</div>
<!-- end calculation -->
                
                </div>
                 
            </div>
           </div>
          </div>
        </div>
      </div>
      
     </section>
 </div>
<!-- /.content-wrapper -->



        
  <!-- Main Footer -->
  <footer class="main-footer">
    <!-- To the right -->
    <?php  include_once('footer.php'); ?>

  </footer>


</div>


<!-- REQUIRED JS SCRIPTS -->
<script src="bower_components/jquery/dist/jquery.min.js"></script>
<script src="bower_components/jquery-ui/jquery-ui.min.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="dist/js/adminlte.min.js"></script>
<script src="bower_components/DataTables/datatables.min.js"></script>
<script src="bower_components/DataTables/Buttons-1.5.4/js/buttons.bootstrap.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script src="bower_components/select2/dist/js/select2.js"></script> 

</body>
</html>