Mini Shell

Direktori : /home/mhcadmin/public_html/Portal/
Upload File :
Current File : /home/mhcadmin/public_html/Portal/ManageFeesPayments.php

<?php
session_start();
$rootPath = realpath(dirname(__FILE__) . '/..');
require_once $rootPath . '/Portal/config/config.php';
require_once $rootPath . '/Portal/include/auth_validate.php';



    /////// Code for new access control on header menu /////////////////////////
    $User = $_SESSION['id'];
    $UserAccessName = $query3 = $result3 = $Status = "";

    $result = mysqli_query($conn, "SELECT * FROM admin_accounts WHERE id = '$User'");
    $num = mysqli_num_rows($result);

    if ($num > 0) {
        $rows = mysqli_fetch_array($result);
        $UserAccessName = $rows['Access_Level'];
    }

    $db = getDbInstance();

	
	$search_string = filter_input(INPUT_GET, 'search_string', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    $del_id = filter_input(INPUT_GET, 'del_id', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
	
    $filter_col = filter_input(INPUT_GET, 'filter_col', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
	
    $order_by = filter_input(INPUT_GET, 'order_by', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
	
    $page = filter_input(INPUT_GET, 'page', FILTER_SANITIZE_NUMBER_INT);
    
    $pagelimit = 5;
    if (!$page) {
        $page = 1;
    }
    
    // If filter types are not selected we show latest added data first
    if (!$filter_col) {
        $filter_col = "id";
    }
    if (!$order_by) {
        $order_by = "desc";
    }
    
    // Select the columns
    $select = array('id','Student_NO', 'Amount', 'Payment_Mode', 'Date_Paid', 'Reference', 'Class_Level', 'Term Year');
    
    // If user searches 
    if ($search_string) {
        $db->where('Student_NO', '%' . $search_string . '%', 'like');
    }

    if ($order_by) {
        $db->orderBy($filter_col, $order_by);
    }

    $db->pageLimit = $pagelimit;
    $result = $db->arraybuilder()->paginate("fees_payment", $page, $select);
    $total_pages = $db->totalPages;

    // Get columns for order filter
    $filter_options = array();
    if (!empty($result)) {
        foreach ($result as $value) {
            foreach ($value as $col_name => $col_value) {
                $filter_options[$col_name] = $col_name;
            }
            // Execute only once
            break;
        }
    }

// Code to delete a subject record

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['Delete_Record'])) {
 
 $RecordID = mysqli_real_escape_string($conn, $_POST['RecordID']);    
    $db->where('id', $RecordID);
    $stat = $db->delete('fees_payment');
    
	if($stat){
		
		//Event Trail
			   date_default_timezone_set('Africa/Blantyre');
				$EventTime = date('d-m-Y H:i', time());
						 
				$Action = $RecordType = $Details = $Date = $User = '';
				$Action = 'Delete Record'; 
				$RecordType = 'Delete Fees Payment';
				$Details = "with User ID Number $RecordID";
				$Date = "$EventTime";
				$User = $_SESSION['Full_Name'];
						 
				 $sql = mysqli_query($conn,"INSERT INTO eventtrail (Action,RecordType,Details,Date,User) 
							VALUES ('$Action','$RecordType','$Details','$Date','$User')");
		
        $_SESSION['info'] = "Subject deleted successfully!";
        
	}  
}




    $query3 = "SELECT * FROM `admin_accounts`";
    $result3 = mysqli_query($conn, $query3);

    include_once 'include/AdminHeader.php';
?>

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-6">
            <h4 class="page-header">Manage Fees Records</h4>
        </div>
        <div class="col-lg-6" style="">
            <div class="page-action-links text-right">
                
				<a href="#" data-toggle="modal" data-target="#Payments-Tamplate">
				<button class="btn btn-success"><span class="glyphicon glyphicon-download"></span> Download Template</button>
	            </a>
				<a href="#" data-toggle="modal" data-target="#Upload-Payments">
                    <button class="btn btn-success"><span class="glyphicon glyphicon-upload"></span> Upload Fees Records</button>
                </a>
				<a href="">
				<button class="btn btn-success"><span class="glyphicon glyphicon-refresh"></span> Refresh</button>
	            </a>
               
            </div>
        </div>
    </div>
    
    
    <?php include('include/flash_messages.php') ?>

    <?php
    if (isset($del_stat) && $del_stat == 1) {
        echo '<div class="alert alert-info">Successfully deleted</div>';
    }
    ?>
    
    <!-- Begin filter section -->
    <div class="well text-center filter-form">
        <form class="form form-inline" action="">
            <label for="input_search">Search</label>
            <input type="text" class="form-control" id="input_search" placeholder ="Student Number"  name="search_string" value="<?php echo htmlspecialchars($search_string ?? ''); ?>">
            <label for="input_order">Order By</label>
            <select name="filter_col" class="form-control">
                <?php
                foreach ($filter_options as $option) {
                    $selected = ($filter_col === $option) ? "selected" : "";
                    echo '<option value="' . htmlspecialchars($option) . '" ' . $selected . '>' . htmlspecialchars($option) . '</option>';
                }
                ?>
            </select>

            <select name="order_by" class="form-control" id="input_order">
                <option value="Asc" <?php echo ($order_by == 'Asc') ? "selected" : ""; ?>>Asc</option>
                <option value="Desc" <?php echo ($order_by == 'Desc') ? "selected" : ""; ?>>Desc</option>
            </select>
            <input type="submit" value="Go" class="btn btn-primary">
        </form>
    </div>
    <!-- Filter section end -->
    
    <hr>
    <table class="table table-striped table-bordered table-condensed">
        <thead>
            <tr style="background-color:#BAC4CC;">
                <th>Student_No</th>
                <th>Amount</th>
				<th>Payment_Mode</th>
				<th>Reference</th>
                <th>Date_Paid</th>
				<th>Class_Level</th>
                <th>Term</th>
				<th>Year</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php if (!empty($result)): ?>
                <?php foreach ($result as $row): ?>
                    <tr>
                        <td><h5><?php echo htmlspecialchars($row['Student_NO'] ?? '') ?></h5></td>
                        <td><h5><?php echo htmlspecialchars($row['Amount'] ?? '') ?></h5></td>
						<td><h5><?php echo htmlspecialchars($row['Payment_Mode'] ?? '') ?></h5></td>
                        <td><h5><?php echo htmlspecialchars($row['Date_Paid'] ?? '') ?></h5></td>
						<td><h5><?php echo htmlspecialchars($row['Reference'] ?? '') ?></h5></td>
                        <td><h5><?php echo htmlspecialchars($row['Class_Level'] ?? '') ?></h5></td>
						<td><h5><?php echo htmlspecialchars($row['Term'] ?? '') ?></h5></td>
                        <td><h5><?php echo htmlspecialchars($row['Year'] ?? '') ?></h5></td>
                        
                        
                        <td>
                            <ul class="nav navbar-top-links navbar-right">
                                <li class="dropdown">
                                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                                        <i class="fa fa-folder-open"></i> 
                                    </a>
                                    <ul class="dropdown-menu dropdown-user">
                                        <li class="divider"></li>
                                        <li><h6><a href="#" data-toggle="modal" data-target="#confirm-delete-<?php echo $row['id'] ?>"><span class="btn btn-danger delete_btn"> Delete Record</span></a></h6></li>
                                    </ul>
                                </li>
                            </ul>
                        </td>
                    </tr>

                    

                    <!-- Delete Confirmation Modal -->
                    <div class="modal fade" id="confirm-delete-<?php echo $row['id'] ?>" role="dialog">
                        <div class="modal-dialog">
                            <form action=" " method="POST">
                                <div class="modal-content">
                                    <div class="modal-header" style="text-align:center; background-color:#BAC4CC;">
                                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                                        <h4 class="modal-title">Confirm</h4>
                                    </div>
                                    <div class="modal-body">
                                        <input type="hidden" name="RecordID" id="del_id" value="<?php echo $row['id'] ?>">
                                        <p>Are you sure you want to delete this Record?</p>
                                    </div>
                                    <div class="modal-footer">
                                        <button type="submit" name="Delete_Record" id="submit" class="btn btn-danger delete_btn pull-left">Delete <span class="glyphicon glyphicon-trash"></span></button>
                                        <button type="button" class="btn btn-primary" data-dismiss="modal">Cancel <span class="glyphicon glyphicon-remove"></span></button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    
                    
					
					
                    
                <?php endforeach; ?>
            <?php else: ?>
                <tr>
                    <td colspan="8" class="text-center">No Fees Payment Record found</td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>

   
   
                 <!-- Fees Payment upload Modal -->
					<div class="modal fade" id="Upload-Payments" role="dialog">
							<div class="modal-dialog">
								<div class="modal-content">
									<form action="Fees_Upload.php" method="post" id="contact_form" enctype="multipart/form-data">
										<div class="modal-header" style="text-align:center; background-color:#BAC4CC;">
											<button type="button" class="close" data-dismiss="modal">&times;</button>
											<h5 class="modal-title" style="text-align:center;"><strong>UPLOAD SCHOOL FEES PAYMENT RECORD</strong></h5>
										</div>
										<div class="modal-body">
											<div class="form-group">
												<label class="control-label">Term</label>
												<select name="Term" class="form-control" required>
													<option value="">Select term</option>
													<option value="Term 1">Term 1</option>
													<option value="Term 2">Term 2</option>
													<option value="Term 3">Term 3</option>
												</select>
											</div>
											
											<div class="form-group">
												<label class="control-label">Year *</label>
												<select name="year" class="form-control selectpicker" required>
													<option value="">Select School Year</option>
													<?php
													$query3 = "SELECT * FROM `school_year`";
													$result3 = mysqli_query($conn, $query3);
													while ($row3 = mysqli_fetch_array($result3)):
														$Calendar_Name = $row3['Calendar_Name'];
													?>
														<option value="<?php echo htmlspecialchars($Calendar_Name); ?>"><?php echo htmlspecialchars($Calendar_Name); ?></option>
													<?php endwhile; ?>
												</select>
											</div>
											
											<div class="form-group">
												<label class="control-label">Attach Students List in CSV format *</label>
												<div class="form-control">
													<input type="file" name="file" id="file" required accept=".csv" />
												</div>
											</div>
											<div class="alert alert-info">
												<strong>Note:</strong> CSV file should have columns: Student_No, Full_Name, Level, Amount_Paid, Payment_Mode, Reference_No, Date_Paid

											</div>
										</div>
										<div class="modal-footer">
											<button type="submit" name="submit" id="submit" class="btn btn-warning pull-left">
												Save<span class="glyphicon glyphicon-send"></span>
											</button>
											<button type="button" class="btn btn-primary" data-dismiss="modal">
												Cancel <span class="glyphicon glyphicon-remove"></span>
											</button>
										</div>
									</form>
								</div>
							</div>
						</div>

	

                     <!-- Modal for downloading template for fees payment --!>
						<div class="modal fade" id="Payments-Tamplate" role="dialog">
							<div class="modal-dialog">
							<div class="modal-content">
								<form action="Fees_Payment_List.php" method="POST">
									<div class="modal-header" style="text-align:center; background-color:#BAC4CC;">
										<button type="button" class="close" data-dismiss="modal">&times;</button>
										<h5 class="modal-title" style="text-align:center;"><strong>DONLOAD TEMPLATE FOR FEES PAYMENT RECORD</strong></h5>
										</div>
										<div class="modal-body">
											<div class="form-group">
												<label class="control-label">Glade / Class</label>
												<select name="Grade" class="form-control" required id="Grade" 
													style="width: 100%; padding: 8px 12px; border-radius: 4px; border: 1px solid #ced4da;">
													<option value="">-- Select Grade/Class --</option>
													<option value="All">All Classes</option>
													<option value="Baby Class">Baby Class</option>
													<option value="Middle Class">Middle Class</option>
													<option value="Top Class">Top Class</option>
													<option value="Year 1">Year 1</option>
													<option value="Year 2">Year 2</option>
													<option value="Year 3">Year 3</option>
													<option value="Year 4">Year 4</option>
													<option value="Year 5">Year 5</option>
													<option value="Year 6">Year 6</option>
													<option value="Year 7">Year 7</option>
													<option value="Year 8">Year 8</option>
													<option value="Year 9">Year 9</option>
													<option value="Year 10">Year 10</option>
												</select>
																	</div>
											
											
										<div class="modal-footer">
											<button type="submit" name="submit" id="submit" class="btn btn-warning pull-left">
												Save & Send <span class="glyphicon glyphicon-send"></span>
											</button>
											<button type="button" class="btn btn-primary" data-dismiss="modal">
												Cancel <span class="glyphicon glyphicon-remove"></span>
											</button>
										</div>
									</form>
								</div>
							</div>
						</div>
	
					
					
   
   
   
   
   

    <!-- Pagination links -->
    <div class="text-center">
        <?php
        if ($total_pages > 1) {
            // Build query string
            $query_params = $_GET;
            unset($query_params['page']);
            $query_string = !empty($query_params) ? '?' . http_build_query($query_params) : '?';
            
            echo '<ul class="pagination text-center">';
            for ($i = 1; $i <= $total_pages; $i++) {
                $li_class = ($page == $i) ? ' class="active"' : '';
                echo '<li' . $li_class . '><a href="ManageFeesPayments.php' . $query_string . '&page=' . $i . '">' . $i . '</a></li>';
            }
            echo '</ul>';
        }
        ?>
    </div>
</div>

<?php 


include_once 'include/footer.php'; 
?>