Hi! Could we please enable some services and cookies to improve your experience and our website?

SQLize | PHPize | SQLtest

Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code

A A A
Login    Share code      Blog   FAQ
Copy Format Clear
<?php include "session.php"; include "header.php"; include "sidebar.php"; include "feesm-system.php"; include_once "config/class_staff.php"; // check if 'staff_id' is set //initially this is blank, but when the form below is submitted, that is when it stores the value of staff_id if (isset($_POST['staff_id'])) { $get_id = trim($_POST['staff_id']); } else { $get_id = ''; } // Check if 'staff_name' is set if (isset($_POST['staff_name'])) { $staff_name = trim($_POST['staff_name']); } else { $staff_name = ''; } // Fetch staff name if 'staff_id' is set but 'staff_name' is empty if (!empty($get_id) && empty($staff_name)) { $staff = new Staff(); $where_id = array("id" => $get_id); $staff_details = $staff->fetchRecord('staff_details', $where_id); $staff_name = isset($staff_details['name']) ? $staff_details['name'] : ''; } ?> <div class="back_area"> <div class="container-fluid"> <div class="row"> <div class="col-lg-12 text-end"> <ul> <li><a href="index.php">Home<i class="fa-solid fa-chevron-right"></i></a></li> <li><a href="salary.php">Salary<i class="fa-solid fa-chevron-right"></i></a></li> <li><a href="pf_statement.php">PF Statement<i class=""></i></a></li> </ul> </div> </div> </div> </div> <div class="container-fluid"> <div class="box-areag"> <form action="" method="POST" class="mt-3"> <div class="row"> <div class="col-sm-3 form-group"> <!-- Display Staff Name in Input --> <input type="text" id="staff_name" name="staff_name" class="form-control" value="<?php echo htmlspecialchars($staff_name); ?>"placeholder="Please Enter Staff ID/Name" required="required" style="width:200px;"> <!-- Hidden field to store Staff ID --> <input type="hidden" id="staff_id" name="staff_id" value="<?php echo $get_id; ?>"> <!-- Suggestion Box --> <div id="suggestion-box" class="form-group"></div> </div> <div class="col-sm-3 form-group"> <select id="financial_year" name="financial_year" class="form-control" style="width:200px;"> <option value="" selected disabled><--Select Financial Year--></option> <?php $start_year = date("Y") - 10; // Define the starting year $end_year = date("Y") + 5; // Define the ending year for($year = $start_year; $year < $end_year; $year++) { $next_year = $year+1; $financial_year = $year . "-" . $next_year; ?> <option value="<?php echo $financial_year; ?>"<?php if(isset($_POST['financial_year']) && $_POST['financial_year'] == $financial_year){ echo "selected";} ?>><?php echo $financial_year; ?></option> <?php } ?> </select> </div> <div class="col-sm-3 form-group"> <input type="submit" class="submit_btn" name="generate_pf_statement" value="GENERATE PF STATEMENT"> </div> <div class="col-sm-2"></div> </div> <!-- <div class="row"> --> </form> </div> </div> <!-- <div class="container box-areag"> closing --> <?php if(isset($_POST['generate_pf_statement'])) { if(isset($_POST['staff_id'], $_POST['financial_year']) && !empty($_POST['staff_id']) && !empty($_POST['financial_year'])) { $id = trim($_POST['staff_id']); $financial_year = $_POST['financial_year']; //---- $staff = new Staff(); $where_staff_id = array("id" => $id); $staff_details = $staff->fetchRecord('staff_details',$where_staff_id); $name = $staff_details['name']; $join_date = $staff_details['dob_day'] . '-' . str_pad($staff_details['dob_month'], 2, '0', STR_PAD_LEFT) . '-' . str_pad($staff_details['dob_year'], 2, '0', STR_PAD_LEFT); $retirement_date = $staff_details['retirement_date']; $formatted_retirement_date = (new DateTime($retirement_date))->format('d-m-Y'); // Format the date to d-m-Y //---- //---- Converts the input financial_year from form into array so it can store its values in two variables year1 and year2 $financial_year_array = explode("-",$_POST['financial_year']); $year1 = $financial_year_array[0]; // Ex: year1 stores 2015 of 2015-2016 // Check if the second part of the year is already in full format (e.g., 2016) if (strlen($financial_year_array[1]) == 2) { // If the year is short (e.g., 16), prepend "20" $year2 = "20" . $financial_year_array[1]; } else { // If it's already a full year (e.g., 2016), use it as-is $year2 = $financial_year_array[1]; } // Generating an Array of Financial Months of the fiscal year format $fiscal_year_month_format = array("4-" . $year1, "5-" . $year1, "6-" . $year1, "7-" . $year1, "8-" . $year1, "9-" . $year1, "10-" . $year1, "11-" . $year1, "12-" . $year1, "1-" . $year2, "2-" . $year2, "3-" . $year2); $months = array(1 => 'January', 2 => 'February', 3 => 'March', 4 => 'April', 5 => 'May', 6 => 'June', 7 => 'July', 8 => 'August', 9 => 'September', 10 => 'October', 11 => 'November', 12 => 'December'); //---- ?> <!-- DISPLAYING OPENING MESSAGE FOR SALARY STATEMENT --> <div class="container-fluid"> <div class="text-center p-5 bg-light text-dark rounded shadow-lg"> <!-- University Name --> <h3 class="fw-bold text-uppercase text-black mb-4 display-5"> Netaji Subhas Open University </h3> <!-- Financial Year --> <h4 class="text-dark mb-4 fs-4"> Financial Year: <span class="badge bg-secondary text-black fs-5 px-4 py-2"> <?php echo $financial_year; ?> </span> </h4> <!-- Statement Info --> <h4 class="text-dark mb-4 fs-4"> The Following PF Statement Has Been Generated For: </h4> <!-- Employee Details --> <h5 class="fw-semibold mt-4"> <!-- Employee Name --> <div class="mb-3"> <span class="badge bg-dark text-white fs-5 px-4 py-2"> <?php echo strtoupper($name); ?> </span> </div> <!-- Joining and Retirement Dates --> <div class="d-flex justify-content-center flex-wrap gap-3 mt-3"> <!-- Date of Joining --> <span class="badge bg-dark text-white fs-5 px-4 py-2"> Date of Joining: <span class="text-warning fw-bold ms-1"> <?php echo $join_date; ?> </span> </span> <!-- Date of Retirement --> <span class="badge bg-dark text-white fs-5 px-4 py-2"> Date of Retirement: <span class="text-warning fw-bold ms-1"> <?php echo $formatted_retirement_date; ?> </span> </span> </div> </h5> </div> </div> <!-- TABLE --> <div class="table-area"> <div class="container-fluid mt-3"> <div class="table-responsive"> <table class="table"> <thead> <tr> <th>Sl No.</th> <th>Year:</th> <th>Month:</th> <th>Opening Balance:</th> <th>Other Deposit:</th> <th>GPF:</th> <th>PF Loan:</th> <th>Other Loan:</th> <th>PF Total Balance:</th> </tr> </thead> <tbody> <?php $i = 1; $opening_balance = 0; $pf_total_balance = 0; foreach($fiscal_year_month_format as $value) { //splits the $value from above into month and year which can be then used to query the database table $split_month_year = explode("-", $value); $staff = new Staff(); $where_id_month_year = array("staff_id" => $id, "month" => $split_month_year[0], "year" => $split_month_year[1]); $salary_details = $staff->fetchRecord('salary', $where_id_month_year); $gpf = isset($salary_details['gpf']) ? $salary_details['gpf'] : 0; $pf_total_balance = $opening_balance + $gpf; ?> <tr> <td><?php echo $i++; ?></td> <td><?php echo $split_month_year[1]; ?></td> <td><?php echo $months[$split_month_year[0]]; ?></td> <td><?php echo $opening_balance; ?></td> <td>0</td> <td><?php echo isset($salary_details['gpf']) ? $salary_details['gpf'] : 0; ?></td> <td><?php echo isset($salary_details['pf_loan']) ? $salary_details['pf_loan'] : 0; ?></td> <td>0</td> <td><?php echo $pf_total_balance; ?></td> </tr> <?php $opening_balance = $pf_total_balance; $total_gpf = (isset($total_gpf) ? $total_gpf : 0) + $gpf; } //foreach closing ?> <tr> <td></td> <td></td> <td></td> <td><strong>TOTAL:</strong></td> <td></td> <td><?php echo $total_gpf; ?></td> <td></td> <td></td> <td></td> </tr> </tbody> </table> </div> </div> </div> <?php } //if(isset($_POST['staff_id'], $_POST['financial_year']) closing... // Displaying error message in else section else { echo '<div class="alert alert-danger text-center">PLEASE SELECT ALL REQUIRED FIELDS: STAFF-ID/NAME AND FINANCIAL YEAR.</div>'; } } //if(isset($_POST['generate_salary_statement'])) closing... ?> <script src='assets/jquery/jquery-3.7.1.min.js'></script> <script> $(document).ready(function() { $("#staff_name").keyup(function() { $.ajax({ type: "POST", url: "get-slip_id.php", data: { staff_id_name_keyword: $(this).val() }, success: function(data) { $("#suggestion-box").show(); $("#suggestion-box").html(data); } }); }); }); // Function to set staff name in the visible field and staff ID in the hidden field function selectStaffId(staff_id, staff_name) { $("#staff_name").val(staff_name); // Display name in text input $("#staff_id").val(staff_id); // Store ID in hidden input $("#suggestion-box").hide(); // Hide suggestions } </script> <?php include "footer.php"; ?>

Stuck with a problem? Got Error? Ask AI support!

Copy Clear