0% found this document useful (0 votes)
150 views8 pages

Form Id

The document is a PHP code for generating payroll reports from an employee database. It contains code to: 1) Query an employee database to retrieve salary and other payroll data for employees. 2) Calculate values like gross salary, tax payable, net salary based on the retrieved data. 3) Generate an HTML table to display the payroll data for each employee, including calculated fields. 4) Summarize payroll amounts across columns for reporting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
150 views8 pages

Form Id

The document is a PHP code for generating payroll reports from an employee database. It contains code to: 1) Query an employee database to retrieve salary and other payroll data for employees. 2) Calculate values like gross salary, tax payable, net salary based on the retrieved data. 3) Generate an HTML table to display the payroll data for each employee, including calculated fields. 4) Summarize payroll amounts across columns for reporting.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

<form id="saveForm" action="process_payroll.

php">
<table class="table table-hover table-fixed-header"
id="allocation_table">
<thead>
<tr>
<th>#</th>
<th>ID</th>
<th>Name</th>
<th>Father Name</th>
<th>Position</th>
<th>Contract From</th>
<th>Contract To</th>
<th>Basic Salary</th>
<?php
// Fetch data from the SQL table using appropriate
query or method
$sql = "SELECT * FROM mo_budegt_allocation where
month='$month'";

// Execute the query and fetch the result


$result = mysqli_query($con, $sql);

// Get the column names


$columns = array();
$fields_info = mysqli_fetch_fields($result);
foreach ($fields_info as $val) {
$columns[] = $val->name;
}

// Columns to exclude
$exclude_columns = array('eid', 'FirstName',
'Designation', 'updated', 'gross_salary', 'month', 'id', 'AHF');

// Initialize an array to store the sums of the


columns
$column_sums = array();
$tax_sum_co = array();
foreach ($columns as $column) {
// Skip the excluded columns
if (!in_array($column, $exclude_columns)) {
$column_sums[$column] = 0;
$tax_sum_co[$column] = 0;
}
}
// Generate the table headers
foreach ($columns as $column) {
// Skip the column if it's in the excluded columns
if (!in_array($column, $exclude_columns)) {
echo '<th style="white-space: pre-wrap;">' .
$column . '</th>';
}
}

?>

<th>Days <br> of Month</th>


<th>Absent</th>
<th>Leave <br>Without<br>Pay</th>
<th>Paid<br>Days</th>

<th>Tax<br>Payable</th>
<th>Gross<br>Salary</t>
<th>Food Deduction</th>
<th>Net<br>Salary</th>

<th>Account Number</th>
<th>Email Address</th>
<th>Remarks</th>
<?php
// Additional headers for the tax columns
foreach ($columns as $column) {
// Skip the column if it's in the excluded columns
if (!in_array($column, $exclude_columns)) {
echo '<th style="white-space: pre-wrap;">Tax ' .
$column . '</th>';
}
}
?>
<th>Month</th>

<thead>
<tbody>
<?php

$year = date('Y', strtotime($month));


$monthNumber = date('m', strtotime($month));
$totalDays = cal_days_in_month(CAL_GREGORIAN,
$monthNumber, $year);
$totalbasic = 0;
$totalTaxPayable = 0;
$totalNetSalary = 0;
$totalOtherBenifts = 0;
$totalGrosssSalary = 0;
$totalTax = 0;
$totalnet = 0;
$totalnetcur = 0;
$totalfooddeduction = 0;
$selectedBudgets = $_POST['budgetLine']; //
Assuming you're retrieving the selected options from a form submission

$budgets = implode("', '", $selectedBudgets); //


Convert the selected options to a comma-separated string

// Fetch data from the SQL table using appropriate


query or method
$sql = "SELECT * FROM employeeinfo WHERE
duty_station='Kabul Main Office' AND DATE_FORMAT(contract_start_date, '%Y-%m') <=
'$month' AND budget_line IN ('$budgets')";

// Execute the query and fetch the result


$result = mysqli_query($con, $sql);

$sequenceNumber = 1;
// generate the HTML for the table rows
while ($row = mysqli_fetch_array($result)) {
$exchangedSalary = $row['salary'];
$id = $row["eEmployeeCodeNumber"];
$nightDutyQuery = "SELECT * FROM night_duty WHERE
eid='$id' AND month='$month'";
$nightDutyResult = mysqli_query($con,
$nightDutyQuery);
$otherBenefits = 0;

while ($nightDutyRow =
mysqli_fetch_array($nightDutyResult)) {
if ($nightDutyRow["eid"] == $id) {
$otherBenefits +=
$nightDutyRow["total_amount"];

}
}
$id = $row["eEmployeeCodeNumber"];
$absentQuery = "SELECT SUM(absent_days) AS
total_absent_days, SUM(leave_without_pay) AS total_leave_without_pay,
GROUP_CONCAT(remarks SEPARATOR ', ') AS remarks FROM absent WHERE eid='$id' AND
effective_date='$month'";
$absentResult = mysqli_query($con, $absentQuery);
$absentDays = 0;
$leaveWithoutPay = 0;
$remarks = null;
while ($absentRow =
mysqli_fetch_array($absentResult)) {
$absentDays = $absentRow["total_absent_days"];
$leaveWithoutPay =
$absentRow["total_leave_without_pay"];
$remarks = $absentRow["remarks"];
}
$totalPaidDays = $totalDays - ($absentDays +
$leaveWithoutPay);
echo "<tr>";
echo "<td>" . htmlspecialchars($sequenceNumber) .
"</td>";
echo "<td>" .
htmlspecialchars($row["eEmployeeCodeNumber"]) . "</td>";
echo "<td>" . htmlspecialchars($row["FirstName"])
. "</td>";
echo "<td>" . htmlspecialchars($row["fname"]) .
"</td>";
echo "<td>" .
htmlspecialchars($row["eDesignationId"]) . "</td>";
echo "<td>" .
htmlspecialchars($row["contract_start_date"]) . "</td>";
echo "<td>" .
htmlspecialchars($row["contract_end_date"]) . "</td>";
echo "<td>" . number_format($row["salary"], 2) .
"</td>";
// Fetch data from the SQL table using
appropriate query or method
$sqlallocations = "SELECT * FROM
mo_budegt_allocation where month='$month' AND eid='$id'";

$resultallocations = mysqli_query($con,
$sqlallocations);

// Fetch the data


$data = mysqli_fetch_assoc($resultallocations);
$gross_salary = ((($exchangedSalary +
$otherBenefits) / $totalDays) * $totalPaidDays);
$grossSalary = $gross_salary;
if ($grossSalary > 100000) {
$taxPayable = 8900 + (($grossSalary - 100000) *
0.2);
} elseif ($grossSalary > 12500) {
$taxPayable = 150 + (($grossSalary - 12500) *
0.1);
} elseif ($grossSalary > 5000) {
$taxPayable = ($grossSalary - 5000) * 0.02;
} else {
$taxPayable = 0;
}

foreach ($columns as $column) {

if (!in_array($column, $exclude_columns)) {
// Check if the value is null and display 0
if it is
$value = isset($data[$column]) ?
$data[$column] : 0;
$value = (($value / $totalDays) *
$totalPaidDays);
echo '<td>' . number_format($value, 2) .
'</td>';
// Add the value to the sum of its column
$column_sums[$column] += $value;
if ($grossSalary != 0) {
$allocation_tax = ($taxPayable / 100) *
($value / $grossSalary * 100);

if (!isset($total_taxes[$column])) {
$total_taxes[$column] = 0;
}
$total_taxes[$column] += $allocation_tax;
} else {
$allocation_tax = 0;
}

$allocated_taxes[$column] = $allocation_tax;
$tax_sum_co[$column] += $allocation_tax;
}
}
//print_r($total_taxes);
echo "<td>" . htmlspecialchars($totalDays) .
"</td>";
echo "<td>" . htmlspecialchars($absentDays) .
"</td>";
echo "<td>" . htmlspecialchars($leaveWithoutPay)
. "</td>";
echo "<td>" . htmlspecialchars($totalPaidDays) .
"</td>";
echo "<td>" . number_format($taxPayable, 2) .
"</td>";
echo "<td>" . number_format($gross_salary, 2) .
"</td>";
if (isset($_POST['food_deduction_check_box'])) {

if ($row["eEmployeeCodeNumber"] === "AADA 0081"


or $row["budget_line"] === "Supportive") {
$food_deduction = 0;
} elseif ($row['salary'] >= 100000) {
$food_deduction = 2000;
} elseif ($row['salary'] >= 50000) {
$food_deduction = 1500;
} elseif ($row['salary'] >= 30000) {
$food_deduction = 1000;
} elseif ($row['salary'] >= 20000) {
$food_deduction = 500;
}
} else {
$food_deduction = 0;
}
echo "<td>" . number_format($food_deduction, 2) .
"</td>";
$net_salary = $grossSalary - $taxPayable -
$food_deduction;
echo "<td>" . number_format($net_salary, 2) .
"</td>";
echo "<td>" . htmlspecialchars($row["bank_acc"])
. "</td>";
echo "<td>" .
htmlspecialchars($row["eEmailAddress"]) . "</td>";
echo "<td>" . htmlspecialchars($remarks) .
"</td>";
foreach ($allocated_taxes as $column => $tax) {
echo '<td>' . number_format($tax, 2) . '</td>';
}
echo "<td>" . htmlspecialchars($month) . "</td>";
echo "</tr>";
$sequenceNumber++;
$totalbasic += $row["salary"];
$totalTaxPayable += $taxPayable;
$totalOtherBenifts += $otherBenefits;
$totalGrosssSalary += $gross_salary;
$totalTax += $taxPayable;
$totalnet += $net_salary;

$totalfooddeduction += $food_deduction;
}

echo '</tbody>';
/**
*
*
* @param $number
* @return
*/
function format_number($number)
{
return number_format($number, 2, '.', ',');
}

?>
<tfoot>
<tr>
<td colspan="7"><b>Totals</td>
<?php
echo "<td><b>" . number_format($totalbasic, 2) .
"</td>";
// Generate the table footer and display the sums in
it
foreach ($columns as $column) {
// Skip the column if it's in the excluded columns
if (!in_array($column, $exclude_columns)) {
echo '<td><b>' .
number_format($column_sums[$column], 2) . '</td>';
}
}
echo "<td>" . 0 . "</td>";
echo "<td>" . 0 . "</td>";
echo "<td>" . 0 . "</td>";
echo "<td>" . 0 . "</td>";
echo "<td><b>" . number_format($totalTax, 2) .
"</td>";
echo "<td><b>" . number_format($totalGrosssSalary, 2)
. "</td>";
echo "<td><b>" . number_format($totalfooddeduction,
2) . "</td>";
echo "<td><b>" . number_format($totalnet, 2) .
"</td>";
echo "<td></td>";
echo "<td colspan='1'></td>";
echo "<td colspan='1'></td>";
//print_r($column_sums);
foreach ($columns as $column) {
// Skip the column if it's in the excluded columns
if (!in_array($column, $exclude_columns)) {
echo '<td><b>' .
number_format($tax_sum_co[$column], 2) . '</td>';
}
}
echo "<td> </td>";

?>
</tr>
</tfoot>

<!-- Add the tfoot section to the table -->

</table>

</div>
<button type="button" class="btn btn-lg btn-outline-danger px-5
m-2"><i
class="bx bx-save mr-1" type="submit"
name="submit"></i>Save</button>
</form>

You might also like