<?php
 session_start();
 require_once('../connect.php');
 require_once('sql_required.php');

 $datetoday = date('Y-m-d'); 
$active_tab = "report"; 


$message = '';
if (isset($_POST['setnewreading'])) {
  $newreading = $_POST['newreading'];
  $newduedate = $_POST['newduedate'];

  $newdisconnection =  utf8_decode($_POST['newdisconnection']);
  $newduedate =  utf8_decode($_POST['newduedate']);
  $newreading =  utf8_decode($_POST['newreading']);
  

 
  
  $sqlRegistered = "INSERT INTO tbl_reading_sched(reading_date,due_date,disconnection_date,status) VALUES ('$newreading', '$newduedate', '$newdisconnection','0')";
  if (mysqli_query($conn, $sqlRegistered)) {

    $message = '<div class="pb-4">
    <span class="alert alert-success">Your schedule successfully saved!</span>
  </div>';

  }
  
}


?>  



<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>Reports</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <link rel="icon" href="images/logo.png" type="image/png" sizes="16x16">
  <link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css">
  <link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
  <link rel="stylesheet" href="dist/css/adminlte.min.css">
  <link rel="stylesheet" href="plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
  <link rel="stylesheet" href="plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
  <link rel="stylesheet" type="text/css" href="css/style1.css">
  <link rel="stylesheet" type="text/css" href="css/skeleton_loading.css">
<style type="text/css">
  .content-wrapper {
    background: #151e27!important;
  }
  @media(max-width:800px) {
    .modal-content {
      position: fixed; bottom: 40%; width: 96%; left: 7;
    }
    .modal-dialog {
      margin: 0!important; padding: 0!important;
    }
  }
  .page-item.active .page-link {
    background-color: #27313d!important;
    border-color: #27313d!important;
    color: #000;
  }
  .page-item .page-link {
    background-color: #151e27!important;
    border-color: grey!important;
    color: grey!important;
  }
  .txn-history {
    text-align: left;
  }
  .txn-list {
    background-color: #1d2532;
    padding: 12px 10px; 
    color: #777;
    font-size: 14px;
    margin: 7px 0;
    box-shadow: 0 2px 5px 0 rgba(0,0,0,.16), 0 2px 10px 0 rgba(0,0,0,.12)!important;
    cursor: pointer;
  }
  .transaction-amount {
    float: right;
    color: #fff;
    font-weight: 800;
  }
  .transaction-number {
   float: right;
  }
  .form-control {
    border-radius: 10px;
  }
  .form-control:focus {
    border: 1px solid #ffd700!important;
  }
  @media(max-width:991px) {
    #order_full_screen {
      display: none!important;
    }
    #order_small_screen {
      display: block!important;
    }
  }
</style>
</head>
<body class="hold-transition sidebar-mini layout-footer-fixed layout-fixed" style="background: #151e27;">
<div id="preloader" class="loading" style="display: none"></div>
<div class="wrapper">
  <nav class="main-header navbar navbar-expand navbar-white" style="background: #151e27; border-bottom: 0; box-shadow: none!important;">
    <ul class="navbar-nav">
      <li class="nav-item">
        <a href="index.php?<?php echo generate_string($permitted_chars, 100); ?>" class="withanimation back_arrow"><i class="fas fa-angle-left pr-2" style="font-size: 20px; color: #ffd700;"></i></a> 
      </li>
    </ul>
    <ul class="navbar-nav ml-auto">
      <a class="nav-link" data-widget="pushmenu" href="#" role="button"><i class="fas fa-bars"></i></a>
    </ul>
  </nav>

  <span id="message">
              <?php echo $message; ?>
            </span>

<?php include ("navbar.php")?>
<div class="content-wrapper">
  <section class="content">
    <div class="container-fluid">
            <div class="card mt-3" style="border-radius: 10px; background-color: #1d2532; color: #fff;">
            
            <a data-toggle="modal" data-target="#readingsched" class="btn btn-sm btn-info">Set New Reading Schedule</a>
                <br>
                
                <table id="members_table" class="table table-striped">
                    <thead>
                    <tr>
                      <th width="5%">Account #</th>
                      <th>Account Name</th>
                      <th>Reading Date</th>
                      <th  width="10%">Due Date</th>
                      <th>Disconection Date</th>
                      <th>Payment Date</th>
                      <th>Previous Reading</th>
                      <th>Present Reading</th>
                      <th>Total Reading</th>
                      <th width="10%">Action</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php 
                      $sql_members = "SELECT * FROM tbl_members_report  ";
                      $result_members = $conn->query($sql_members);
                        while($row_members = mysqli_fetch_array($result_members)) {
                    ?>
                   <?php if( $row_members['line_status'] == 0 ) {?>
                    <tr style='background:#000'>

                    
                   <?php }else { ?>


<tr>
               <?php    }?> 
                      <td style="color: #ffd700;"><?php echo $row_members['account_no']  ?></td>
                      <td style="color: #ffd700;"><?php echo $row_members['account_name']; ?></td>
                      <td style="color: #ffd700;"><?php echo $row_members['reading_date']; ?></td>
                      <td style="color: #ffd700;"><?php echo $row_members['due_date']; ?></td>
                      <td style="color: #ffd700;"><?php echo $row_members['disconnection_date']; ?></td>

                      <td style="color: #ffd700;"><?php echo $row_members['payment_date']; ?></td>
                    
                      <td style="color: #ffd700;"><?php echo $row_members['prev_reading']; ?></td>
                      <td style="color: #ffd700;"><?php echo $row_members['pres_reading']; ?></td>
                      <td style="color: #ffd700;"><?php echo $row_members['total_reading']; ?></td>
                
                      <td>
                        <a data-toggle="modal" data-target="#members<?php echo $row_members['id']; ?>" class="btn btn-sm btn-info">View Details</a>
                     </td>
                    </tr>

          


   <form class="pl-3 pr-3 pt-4" method="POST" id="quickForm">
                      
                    <div class="modal" id="readingsched">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Set Reading Schedule</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0">
                            <div class="txn-history">
                              <p class="txn-list"> NEXT READING DATE: </P>
                              <div class="input-group date">
    <input type="date" name="newreading" class="form-control" value="12-02-2012">
  </div>
 
    <div class="txn-history">
                              <p class="txn-list"> SET DUE DATE: </P>
                              <div class="input-group date">
    <input type="date" name="newduedate"  class="form-control" value="12-02-2012"></div>

    <div class="txn-history">
                              <p class="txn-list"> SET DISCONNECTION DATE: </P>
                              <div class="input-group date">
    <input type="date" name="newdisconnection"  class="form-control" value="12-02-2012"></div>

 
                       
                        </div>
                        <div class="modal-footer" style="border: 0px">
                      

                   


                      <button type="button" data-toggle="modal" data-target="#addnewsched" class="btn btn-warning btn-block btn-lg" style="background: #FFD700; border-color: #ffd700;">Save Changes</button>

                  
                            <button type="button" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                          </div>
                      </div>
                    </div>


       <div class="modal" id="addnewsched">
          <div class="modal-dialog">
            <div class="modal-content" style="background-color: #151e27!important;">
              <div class="modal-header pb-0" style="border: 0px;">
                <h5 class="modal-title text-white" style="font-weight: bold;">New Schedule</h5>
              </div>
              <div class="modal-body pt-0 pb-0">
                <p class="text-muted">Are you sure you save to save new schedule?</p>
              </div>
              <div class="modal-footer pr-0 pl-0 pb-2 pt-0" style="display: block; border: 0px">
                <div class="row">
                  <div class="col-6">
                    <button type="button" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Cancel</button>
                  </div>
                  <div class="col-6">
                    <button type="submit" name="setnewreading" class="btn btn-warning btn-lg btn-block withanimation_submit" style="background: #FFD700; border-color: #ffd700;">Yes, Submit</button>
                  </div>
                </div>
                
              </div>
            </div>
          </div>
        </div>  

    </form>



                    <div class="modal" id="members<?php echo $row_members['id']; ?>">
                      <div class="modal-dialog">
                        <div class="modal-content" style="background-color: #151e27!important;">
                          <div class="modal-header pb-0" style="border: 0px;">
                            <h5 class="modal-title text-white" style="font-weight: bold;">Members Details</h5>
                          </div>
                          <div class="modal-body pt-2 pb-0">
                            <div class="txn-history">
                              <p class="txn-list">
                               <!-- <span class="text-white">Address: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['complete_address']; ?></span><br>
                                <span class="text-white">DR Count: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['dr_count']; ?></span><br>
                                <span class="text-white">IDRLVL1 Count: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['placement_count']; ?></span><br>
                                <span class="text-white">IDRLVL2 Count: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['placement_count_lvl2']; ?></span><br>
                                <span class="text-white">IDRLVL3 Count: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['placement_count_lvl3']; ?></span><br>
                                <span class="text-white">IDRLVL4 Count: </span><span class="transaction-amount" style="color: #ffd700;">0</span><br>
                                <span class="text-white">IDRLVL5 Count: </span><span class="transaction-amount" style="color: #ffd700;">0</span><br> -->


                                <span class="text-white">Account No: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['id']; ?></span><br>
                                <span class="text-white">Username </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['account_name']; ?></span><br>
                                <hr>
                                <span class="text-white">Billing Amount: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['billing_amount']; ?></span><br>
                                <span class="text-white">Amount Paid: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['amount_paid']; ?></span><br>
                                <span class="text-white">Balance: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['balance']; ?></span><br>
                              
                                <span class="text-white">Reading Date: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['reading_date']; ?></span><br>
                                <span class="text-white">Due Date: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['due_date']; ?></span><br>
                                <span class="text-white">Disconection: </span><span class="transaction-amount" style="color: #ffd700;"><?php echo $row_members['disconnection_date']; ?></span><br>
                              
                              </p>

                            </div>
 
                          </div>
                          <div class="modal-footer" style="border: 0px">
                          [ <a href="edit_profile.php?id=<?php echo $row_members['id'] ?> "> View Current Transaction </a>]
                            <button type="button" class="btn btn-default btn-lg btn-block" style="background: transparent; color: #fff;" data-dismiss="modal">Close</button>
                          </div>
                        </div>
                      </div>
                    </div>

                    <?php } ?>
                    </tbody>
                  </table>
                </div>
            </div>

    </div>
  </section>
</div>
</div>

<script src="dist/js/adminlte.min.js"></script>
<script src="plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="plugins/jquery-validation/jquery.validate.min.js"></script>
<script src="plugins/jquery-validation/additional-methods.min.js"></script>
<script src="dist/js/pages/dashboard.js"></script>
<script src="plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<script src="plugins/datatables/jquery.dataTables.min.js"></script>
<script src="plugins/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="plugins/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="plugins/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script type="text/javascript">

  
$(document).ready(function () {
  $('#search').keyup(function() {
    var members = $(this).val();
    var btn_action = "member_search";
     $.ajax({
      url:'fetch_data.php',
      method:"POST",
      dataType:"html",
      data:{members:members, btn_action:btn_action},
      success:function(data){
        $('#members_result').html(data);
      }
    });
  });
});
$(function () {
  $("#members_table").DataTable({
    "responsive": true,
    "autoWidth": false,
  });
  $('#example2').DataTable({
    "paging": true,
    "lengthChange": false,
    "searching": false,
    "ordering": true,
    "info": true,
    "autoWidth": false,
    "responsive": true,
  });
  $(".withanimation").click(function(e) {
      e.preventDefault();
      $(".loading").show();
      var url=$(this).attr("href");
      setTimeout(function() {
          window.location=url;
      }, 500);
  });
});
</script>
</body>
</html>
