Auto save data everytime click/choose the employee name

Hi,

Now, I save data to database using the save button with this code:


<?php
include 'config.php';

$currentEmpID = $_SESSION['empID'];
 
 
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";
$recPersonalNav = $conn->GetAll($sql);
$smarty->assign('personalAll', $recPersonalNav); 

$sql = "SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL p, EMPLOYMENT em  WHERE p.EMP_ID='$currentEmpID' AND em.EMP_ID = '$currentEmpID'";     
    
$recPersonalHead = $conn->Execute($sql);
$fullName = $recPersonalHead->fields["FULLNAME"];
$empno = $recPersonalHead->fields["EMP_NO"];

$smarty->assign('empid', $currentEmpID);
$smarty->assign('fullname', $fullName);
$smarty->assign('empno', $empno); 

 //==============Save Other Earnings============//
 $RegOTAmt = $_POST['RegOTAmt'];
 $SunSpecHolAmt = $_POST['SunSpecHolAmt'];
 $SunSpecHolOtAmt = $_POST['SunSpecHolOtAmt'];
 $RegHolAmt = $_POST['RegHolAmt'];
 $RegHolOtAmt = $_POST['RegHolOtAmt'];
 $HolLeaveAmt = $_POST['HolLeaveAmt'];
 $NightPremAmt = $_POST['NightPremAmt'];
 $MealAllowAmt = $_POST['MealAllowAmt'];
 $COLAAmt = $_POST['COLAAmt'];
 
 $sql = "SELECT EMP_NO, OTReg_Amt, SunReg_Amt, OTSun_Amt, HolReg_Amt, HolRegOT_Amt, HolLeave_Amt, NP_Amt, Meal_Amt, Cola_Amt FROM other_earnings WHERE EMP_NO = '$empno'";
 $RsOtherEarnings = $conn2->Execute($sql);
 
 $numrowsOtherEarnings = $RsOtherEarnings->RecordCount();
 
 if($numrowsOtherEarnings > 0){ 
 
 $saverec['EMP_NO'] = $empno;
 $saverec['OTReg_Amt'] = $RegOTAmt;
 $saverec['SunReg_Amt'] = $SunSpecHolAmt;
 $saverec['OTSun_Amt'] = $SunSpecHolOtAmt;
 $saverec['HolReg_Amt'] = $RegHolAmt;
 $saverec['HolRegOT_Amt'] = $RegHolOtAmt;
 $saverec['HolLeave_Amt'] = $HolLeaveAmt;
 $saverec['NP_Amt'] = $NightPremAmt;
 $saverec['Meal_Amt'] = $MealAllowAmt;
 $saverec['Cola_Amt'] = $COLAAmt;
 
  $updateOtherEarnings = $conn2->GetUpdateSQL($RsOtherEarnings, $saverec); 
  $conn2->Execute($updateOtherEarnings); 
 }
 else{
 $sql = "SELECT o.EMP_NO, o.OTReg_Amt, o.SunReg_Amt, o.OTSun_Amt, o.HolReg_Amt, o.HolRegOT_Amt, o.HolLeave_Amt, o.NP_Amt, o.Meal_Amt, o.Cola_Amt FROM $PAYROLL.other_earnings o, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
 $RsOtherEarnings = $conn2->Execute($sql);
 
 $saverec['EMP_NO'] = $empno;
 $saverec['OTReg_Amt'] = $RegOTAmt;
 $saverec['SunReg_Amt'] = $SunSpecHolAmt;
 $saverec['OTSun_Amt'] = $SunSpecHolOtAmt;
 $saverec['HolReg_Amt'] = $RegHolAmt;
 $saverec['HolRegOT_Amt'] = $RegHolOtAmt;
 $saverec['HolLeave_Amt'] = $HolLeaveAmt;
 $saverec['NP_Amt'] = $NightPremAmt;
 $saverec['Meal_Amt'] = $MealAllowAmt;
 $saverec['Cola_Amt'] = $COLAAmt;
 
  $insertOtherEarnings = $conn2->GetInsertSQL($RsOtherEarnings, $saverec); 
  $conn2->Execute($insertOtherEarnings); 
 }
 $smarty->display('header.tpl');
 $smarty->display('left.tpl');
 $smarty->display('empPayrollData.tpl');
 $smarty->display('footer.tpl');
  
?>

But i need to do is everytime the employee name was click and i click another employee name the data was in the first employee that I click will save.

here is my code for displaying employee name:
left.tpl


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<script>
function searchemppay(queryString) {
    var ajaxRequest = remoteRequestObject();
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
            var result = ajaxRequest.responseText;
            document.getElementById('searchpayroll').innerHTML = result;
        } 
    }
    var url = "search.php?query=" + queryString; 
    ajaxRequest.open("GET", url, true);
    ajaxRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    ajaxRequest.send(null);

}

function changeEmployeePay(queryID) {
 
window.location = "SearchData.php?queryEmpID=" + queryID;
}
</script>
<title>Untitled</title>
</head>
<body>
<div id="Search">
<form>
<p class="serif"><b>Search Lastname:</b></p>
<input type="text" name="search_" size="20" onkeyup="searchemppay(this.value);">  
<div id="searchpayroll" style="overflow:auto; height:390px; width:auto; margin-left:2px" >
<hr />
<ul>
{section name=co_emp loop=$personalAll}
<li onclick="changeEmployeePay('{$personalAll[co_emp].EMP_ID}')">{$personalAll[co_emp].FULLNAME}</li>
<hr />
{sectionelse}
<li>No records found</li>
{/section}
</ul>
</div>
</form>
</div>
</body>
</html>

search.php


<?php
session_start();
include 'config.php';

$queryString = $_GET["query"];

if ($queryString == "" || $queryString == null) {

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL 
        ORDER BY FULLNAME ASC";
}
else {
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL WHERE LNAME LIKE '" . $queryString . "%' ORDER BY FULLNAME ASC";
}

$recPersonalQuery = $conn->Execute($sql);
if (!$recPersonalQuery->BOF) {
    $recPersonalQuery->MoveFirst();
}

echo "<hr />";
echo "<ul>";
while (!$recPersonalQuery->EOF) {
    $empID   = $recPersonalQuery->fields["EMP_ID"]; 
    $empFullName = $recPersonalQuery->fields["FULLNAME"];

    echo "<li onclick=changeEmployeePay('$empID'); style= 'font-family:'Times New Roman',Times,serif; font-size:10%;'>$empFullName</li>";
    echo "<hr />";
    $recPersonalQuery->MoveNext();
} 
echo "</ul>";

$recPersonalQuery->Close();
exit();    
?>

SearchData.php


<?php
session_start();

$queryStr = trim($_GET["queryEmpID"]);

$_SESSION['empID'] = $queryStr; 

session_write_close();
header("Location:DisplayEmpPayroll.php");
exit();
?>

DisplayEmpPayroll.php


<?php
include 'config.php';
$currentEmpID = $_SESSION['empID']; 
 
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";
$recPersonalNav = $conn->GetAll($sql);
$smarty->assign('personalAll', $recPersonalNav);
// ========================================================================================================================
$EMP_NO = $_POST['EMP_NO'];

$sql = "SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL p, EMPLOYMENT em  WHERE p.EMP_ID='$currentEmpID' AND em.EMP_ID = '$currentEmpID'";      
  
$recPersonalHead = $conn->Execute($sql);
$fullName = $recPersonalHead->fields["FULLNAME"];
$empno = $recPersonalHead->fields["EMP_NO"];

$smarty->assign('empid', $currentEmpID);
$smarty->assign('fullname', $fullName);
$smarty->assign('empno', $empno);
 
 $sql = "SELECT EMP_ID, RATE FROM wage WHERE EMP_ID = '$currentEmpID'";
 $rsWage = $conn->Execute($sql);
 
 $Rate      = $rsWage->fields['RATE'];    
 

 $sql = "SELECT EMP_ID,EMP_NO, STATUS FROM employment WHERE EMP_ID = '$currentEmpID'";
 $rsStatus = $conn->Execute($sql);
 
 $STATUS = $rsStatus->fields['STATUS'];
 $EMP_ID = $rsStatus->fields['EMP_ID'];
 
 if ($STATUS == 'Regular'){
 
 $sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, r.Hours FROM $ADODB_DB.wage w, $ADODB_DB.employment em, $PAYROLL.regular_sum_hours r WHERE em.EMP_NO = r.EMP_NO AND w.EMP_ID = '$currentEmpID' AND em.EMP_ID = '$currentEmpID' GROUP BY r.EMP_NO"; 
  $RsEarnings = $conn2->Execute($sql); 
  
  $Rate      = $RsEarnings->fields['RATE'];
  $Hours      = $RsEarnings->fields['Hours'];

  $Hours = substr($Hours, 0, 5);
  $Hours = str_replace(':', '.', $Hours);
  
 $Amount = $_POST["Amount"];
 
 $Amount = round(($Hours/8)* $Rate, 2); 
 }
 elseif($STATUS == 'Casual'){
 
  $sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, c.Casual_Hours FROM $ADODB_DB.wage w, $ADODB_DB.employment em, $PAYROLL.casual_hours c WHERE em.EMP_NO = c.EMP_NO AND w.EMP_ID = '$currentEmpID' AND em.EMP_ID = '$currentEmpID' GROUP BY c.EMP_NO"; 
  $RsEarnings = $conn2->Execute($sql); 
  
  $Rate      = $RsEarnings->fields['RATE'];
  $Hours      = $RsEarnings->fields['Casual_Hours'];

  $Hours = substr($Hours, 0, 5);
  $Hours = str_replace(':', '.', $Hours);
  
 $Amount = $_POST["Amount"];
 
 $Amount = round(($Hours/8)* $Rate, 2);  
 }
 else{
     $Hours = ('00:00');
     $Amount = (0);
 }
  
  $smarty->assign('Rate', $Rate);
  $smarty->assign('Hours', $Hours);
  $smarty->assign('Amount', $Amount);
$smarty->display('header.tpl');
$smarty->display('left.tpl');
$smarty->display('empPayrollData.tpl');
$smarty->display('footer.tpl'); 

I don’t know how can i insert my code in saving in choosing the employee name and then it will save data when i choose another employee name.

Any help is highly appreciated…

I attach the sample image of my webpage for further understanding.

Thank you so much

What part don’t you know? The javascript part?

The javascript part and in the search.php

I don’t know where i can put the codes for payroll save. so that everytime i click the employee name it will save or update in database if it is already inserted.
I need to remove the save button

Thank you so much…

You’ll have to use AJAX for that.
So you’ll have to add something like a onClick on the link, and then do an AJAX call to a php script that’ll save the data.

did you see i already had onclick for employee…


<li onclick="changeEmployeePay('{$personalAll[co_emp].EMP_ID}')">{$personalAll[co_emp].FULLNAME}</li>

I’m not good and familiar with ajax…

I need to resolved it urgently…

Thank you for your help

as you noticed i have this code for changing employee everytime i click their name:


    
session_start();
include 'config.php';

$queryString = $_GET["query"];

if ($queryString == "" || $queryString == null) {

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL 
        ORDER BY FULLNAME ASC";
}
else {
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL WHERE LNAME LIKE '" . $queryString . "%' ORDER BY FULLNAME ASC";

//$sql = "SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL p, EMPLOYMENT em  WHERE p.LNAME LIKE '" . $queryString . "%' ORDER BY FULLNAME ASC";
}

$recPersonalQuery = $conn->Execute($sql);
if (!$recPersonalQuery->BOF) {
    $recPersonalQuery->MoveFirst();
}

echo "<hr />";
echo "<ul>";
while (!$recPersonalQuery->EOF) {
   // $empno = $recPersonalQuery->fields["EMP_NO"];
    $empID   = $recPersonalQuery->fields["EMP_ID"]; 
    $empFullName = $recPersonalQuery->fields["FULLNAME"];

    echo "<li onclick=changeEmployeePay('$empID'); style= 'font-family:'Times New Roman',Times,serif; font-size:10%;'>$empFullName</li>";
    echo "<hr />";
    $recPersonalQuery->MoveNext();
} 
echo "</ul>";

$recPersonalQuery->Close();
exit(); 

for getting employee names and empid then onchange for changing employee data everytime i click their employee name…

up to now, i don’t where i can put my code in payroll save so that everytime i click employee name it will insert data or update if it is existing already…

Thank you so much

Missed that. Very good.
So what does changeEmployeePay() do? Did you post that code too (if you did I missed it) ?

here is the function for changeEmployeePay()


<script>
function searchemppay(queryString) {
    var ajaxRequest = remoteRequestObject();
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
            var result = ajaxRequest.responseText;
            document.getElementById('searchpayroll').innerHTML = result;
        } 
    }
    var url = "search.php?query=" + queryString; 
    ajaxRequest.open("GET", url, true);
    ajaxRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    ajaxRequest.send(null);

}

function changeEmployeePay(queryID) {
window.location = "SearchData.php?queryEmpID=" + queryID;
}
</script>

search.php


<?php
session_start();
include 'config.php';

$queryString = $_GET["query"];

if ($queryString == "" || $queryString == null) {

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL 
        ORDER BY FULLNAME ASC";
}
else {
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL WHERE LNAME LIKE '" . $queryString . "%' ORDER BY FULLNAME ASC";
}

$recPersonalQuery = $conn->Execute($sql);
if (!$recPersonalQuery->BOF) {
    $recPersonalQuery->MoveFirst();
}

echo "<hr />";
echo "<ul>";
while (!$recPersonalQuery->EOF) {
    $empID   = $recPersonalQuery->fields["EMP_ID"]; 
    $empFullName = $recPersonalQuery->fields["FULLNAME"];

    echo "<li onclick=changeEmployeePay('$empID'); style= 'font-family:'Times New Roman',Times,serif; font-size:10%;'>$empFullName</li>";
    echo "<hr />";
    $recPersonalQuery->MoveNext();
} 
echo "</ul>";

$recPersonalQuery->Close();




exit();    
?>

search.php gets all the employeename and employee id and displayed it.

searchdata.php


<?php
session_start();

$queryStr = trim($_GET["queryEmpID"]);

$_SESSION['empID'] = $queryStr; 

session_write_close();
header("Location:DisplayEmpPayroll.php");
exit();
?>

searchdata display the DisplayEmpPayroll.php that has the data per employee.

the changeEmployeePay() it works when you click employee name the data for that employee will display at the right side. when I click another employee name the data for that employee will displayed.

Thank you…

If theres a question feel free to ask me for further understanding…

Thank you for your help…

So right now the result of clicking on a employee name is the displaying of that employee’s data.
And what you want to achieve is to save the current data before displaying the data of the new employee?

For example:

1) I'm looking at John's data
2) I click on Mary
    a) John's data is saved
    b) Mary's data is shown

Correct ?

Then I think you’ll have to
a) modify the javascript in the changeEmployeePay() function to send all the data you want to save to the script that will save the data (you could use SearchData.php for that)
b) add the php code that saves the data in the database to the script you’re calling from changeEmployeePay()

Hi…

For example I have 5 employees

1.Ann
2.John
3.Chris
4.Rey
5. Ben

For example I click Ann names automatically her data will save and if I edit his data then i click again her name or other employee name her data will update…

Yes, name that I click her data will shown and save.

But if I click her name then I edit her data then i click another name, the data that I edit automatically and also save the data of employee that i click…
is it possible?

here is my code for function and displaying data:


<script>
function searchemppay(queryString) {
  //alert(queryString);
    
    var ajaxRequest = remoteRequestObject();
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4 && ajaxRequest.status == 200) {
            var result = ajaxRequest.responseText;
            //alert(result);
            document.getElementById('searchpayroll').innerHTML = result;
        } 
    }
    //var url = "search.php?query=" + queryString; 
    var url = "search.php?query=" + queryString;
    ajaxRequest.open("GET", url, true);
    ajaxRequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT");
    ajaxRequest.send(null);

}

//function changeEmployeePay(queryID) {
function changeEmployeePay(queryID) {
   //var EMP_NO = document.getElementById('EMP_NO').value; 
   //var BurialSep = document.getElementById('BurialSep').value; 
   //var TaxAjt = document.getElementById('TaxAjt').value;
   //var CashAdvance = document.getElementById('CashAdvance').value;
   //var AdvancesShirt = document.getElementById('AdvancesShirt').innerText;
   //var AdvancesMed = document.getElementById('AdvancesMed').innerText;
   //var AdvancesOthers = document.getElementById('AdvancesOthers').innerText;
//alert(queryID);
//window.location = "DisplayEmpPayroll.php?empID=" + queryID+"&BurialSep="+BurialSep+"&TaxAjt="+TaxAjt+"&CashAdvance="+CashAdvance+"&AdvancesShirt="+AdvancesShirt+"&AdvancesMed="+AdvancesMed+"&AdvancesOthers="+AdvancesOthers;

window.location = "SearchData.php?queryEmpID=" + queryID;

//window.location = "DisplayEmpPayroll.php?queryEmpID=" + queryID;
//window.location = "SSSgetdata.php";
}
</script>


<div class="income">
<fieldset>
    <legend>EARNINGS</legend>
   <input type="hidden" name="EMP_NO" id="EMP_NO" value="{$empno}">{$empno}&nbsp;{$fullname}
        <p class="serif">
        <label for = "Rate" class = "LLabel">Rate:</label>
        <input name= "Rate" class = "LField" type="text" maxlength="12" tabindex="0" size="12" value="{$Rate}" readonly="readonly" style="background: #CCCCCC">
        
        <label for = "Hours" class = "LLabel">&nbsp;Hours:</label>
        <input name= "Hours" class = "LField" type="text" maxlength="12" tabindex="0" size="12"  value="{$Hours}" readonly="readonly" style="background: #CCCCCC">
        </p>
        <p class="serif">
        <label for = "Amount" id = "AmountLabel">&nbsp;&nbsp;<b>Basic Pay:</b></label>
        <input name= "Amount" id="Amount" type="text" maxlength="12" tabindex="0" size="12" value="{$Amount}" readonly="readonly" style="background: #CCCCCC">
        </p>
    <div class="OT">
    <fieldset>
        <legend>OTHERS</legend>
        <p class="serif">
        <label class="p">Hours</label><label>&nbsp;&nbsp;&nbsp;&nbsp;Amount</label>
        <label for = "RegOT" class = "LLabelOT">Regular Overtime:</label>
        <input name= "RegOTHrs" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$OTReg_Hours}" style="background: #e2e2e2" readonly="readonly"/>
        <input name= "RegOTAmt" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$OTReg_Amt}" style="background: #e2e2e2" readonly="readonly"/>
        <label for = "SunSpecHol" class = "LLabelOT">Sun/Spec Holiday:</label>
            <input name= "SunSpecHolHrs"  class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$SunReg_Hours}" style="background: #e2e2e2" readonly="readonly"/>
            <input name= "SunSpecHolAmt"  class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$SunReg_Amt}" style="background: #e2e2e2" readonly="readonly"/>
        <label for = "SunSpecHolOt" class = "LLabelOT">Sun/Spec Hol. OT:</label>
            <input name= "SunSpecHolOtHrs"  class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$OTSun_Hours}" style="background: #e2e2e2" readonly="readonly"/>
            <input name= "SunSpecHolOtAmt"  class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$OTSun_Amt}" style="background: #e2e2e2" readonly="readonly"/>
        <label for = "RegHol" class = "LLabelOT">Reg. Holiday:</label> 
            <input name= "RegHolHrs"  class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$HolReg_Hours}" style="background: #e2e2e2" readonly="readonly"/>
            <input name= "RegHolAmt"  class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$HolReg_Amt}" style="background: #e2e2e2" readonly="readonly"/>
        <label for = "RegHolOt" class = "LLabelOT">Reg. Holiday OT:</label> 
            <input name= "RegHolOtHrs" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$HolRegOT_Hours}" style="background: #e2e2e2" readonly="readonly"/>
            <input name= "RegHolOtAmt" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$HolRegOT_Amt}" style="background: #e2e2e2" readonly="readonly" />
        <label for = "HolLeave" class = "LLabelOT">Holiday/Leave:</label> 
            <input name= "HolLeaveHrs" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$HolLeave_Hours}" style="background: #e2e2e2" readonly="readonly" />
            <input name= "HolLeaveAmt" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$HolLeave_Amt}" style="background: #e2e2e2" readonly="readonly" />
        <label for = "NightPrem" class = "LLabelOT">Night Premium:</label> 
            <input name= "NightPremHrs" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$NP_Hours}" style="background: #e2e2e2" readonly="readonly"/>
            <input name= "NightPremAmt" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$NP_Amt}" style="background: #e2e2e2" readonly="readonly" />
        <label for = "MealAllow" class = "LLabelOT">Meal Allowance:</label> 
            <input name= "MealAllowHrs"  class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$Meal_Hours} days" style="background: #e2e2e2" readonly="readonly" />
            <input name= "MealAllowAmt"  class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$Meal_Amt}" style="background: #e2e2e2" readonly="readonly" />
        <label for = "COLA" class = "LLabelOT">COLA (P14 Allow):</label> 
            <input name= "COLAHrs" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$Cola_Hours} days" style="background: #e2e2e2" readonly="readonly"/>
            <input name= "COLAAmt" class = "LFieldOT" type="text" maxlength="10" tabindex="0" size="10" value="{$Cola_Amt}" style="background: #e2e2e2" readonly="readonly"/>
        <label name= "TotEarn" class="LLabelTotEarn"><b>Total Earnings:</b></label><br/>
            <input name="TotEarn" id="TotEarn" class="LFieldOT" type="text" maxlength="12" tabindex="0" size="10" readonly="readonly" value="{$TotEarn}" style="background: #CCCCCC">       
        </p>                                   
    </fieldset>
</fieldset>
</div> 
</div>

<div class="deductions">
<fieldset>
<legend>DEDUCTIONS</legend>
    <p class="serif">
    <label for = "SSS" class = "LLabelDed">SSS:</label>
        <input name= "SSS" id="SSS" class = "LFieldDed" type="text" maxlength="10" tabindex="0" size="10" value="{$SSS}" style="background: #e2e2e2" readonly="readonly" />
    <label for = "TAX" class = "LLabelDed">&nbsp;TAX:</label>
        <input name= "TAX" id="TAX" type="text" maxlength="10" tabindex="0" size="10" value="{$TAX}" readonly="readonly" style="background: #e2e2e2"/>
    <label for = "PCHL" class = "LLabelDed1">&nbsp;PCHL:</label>
        <input name= "PCHL" id="PCHL" type="text" maxlength="10" tabindex="0" size="10" value="{$PCHL}" style="background: #e2e2e2" readonly="readonly" />
    <label for = "HDMF" class = "LLabelDed2">HDMF:</label>
        <input name= "HDMF" id="HDMF"  type="text" maxlength="10" tabindex="0" size="10" value="{$HDMF}" style="background: #e2e2e2" readonly="readonly"/>
    </p>  
    
<div class="loan">
<fieldset>
<legend>LOANS</legend>
<p class="serif">
<label for="SSSLoan" class="LLabelLoan">SSS Loan:</label>
    <input name= "SSSAmor" id="SSSAmor" class = "LFieldLoan" type="text" maxlength="10" tabindex="0" size="10" value="{$SSSAmor}" style="background: #e2e2e2" readonly="readonly"/>
<label for="HDMFLoan" class="LLabelLoan1">&nbsp;HDMF Loan:</label>
    <input name= "HDMFAmor" id="HDMFAmor" class = "LFieldLoan1" type="text" maxlength="10" tabindex="0" size="10" value="{$HDMFAmor}" style="background: #e2e2e2" readonly="readonly"/>
<label for="Fund" class="LLabelLoan">Union/Trust Fund:</label>
    <input name= "UDTAmor" id="UDTAmor" class = "LFieldLoan" type="text" maxlength="10" tabindex="0" size="10" value="{$UDTAmor}" style="background: #e2e2e2" readonly="readonly"/>          
</p>
</fieldset>

<div>
<fieldset>
<legend>OTHERS</legend>
<p class="serif">
<label for="BurialSep" class="LLabelLoan">Burial/Separation Cont:</label>
    <input name= "BurialSep" id="BurialSep" type="text" maxlength="10" tabindex="0" size="10" onkeyup="return autocalded(this, SSS, TAX, PCHL, HDMF, SSSLoan, HDMFLoan, Fund, TaxAjt, CashAdvance, AdvancesShirt, AdvancesMed, AdvancesOthers)" value="{$BurialSep}" />
<label for="TaxAjt" class="LLabelLoan1">&nbsp;Tax Ajt:</label>
    <input name= "TaxAjt" id="TaxAjt" class = "LFieldLoan1" type="text" maxlength="10" tabindex="0" size="10" onkeyup="return autocalded(this, SSS, TAX, PCHL, HDMF, SSSLoan, HDMFLoan, Fund, BurialSep, CashAdvance, AdvancesShirt, AdvancesMed, AdvancesOthers)" value="{$TaxAjt}" />
<label for="CashAdvance" class="LLabelLoan">Cash Advance:</label>
    <input name= "CashAdvance" id="CashAdvance" class = "LFieldLoan" type="text" maxlength="10" tabindex="0" size="10" onkeyup="return autocalded(this, SSS, TAX, PCHL, HDMF, SSSLoan, HDMFLoan, Fund, BurialSep, TaxAjt, AdvancesShirt, AdvancesMed, AdvancesOthers)" value="{$CashAdvance}" />
<label for="AdvancesShirt" class="LLabelLoan1">&nbsp;Advances (Shirt):</label>
    <input name= "AdvancesShirt" id="AdvancesShirt" class = "LFieldLoan1" type="text" maxlength="10" tabindex="0" size="10" onkeyup="return autocalded(this, SSS, TAX, PCHL, HDMF, SSSLoan, HDMFLoan, Fund, BurialSep, TaxAjt, CashAdvance, AdvancesMed, AdvancesOthers)" value="{$AdvancesShirt}" />
<label for="AdvancesMed" class="LLabelLoan">Advances (Medical):</label>
    <input name= "AdvancesMed" id="AdvancesMed" class = "LFieldLoan" type="text" maxlength="10" tabindex="0" size="10" onkeyup="return autocalded(this, SSS, TAX, PCHL, HDMF, SSSLoan, HDMFLoan, Fund, BurialSep, TaxAjt, CashAdvance, AdvancesShirt, AdvancesOthers)" value="{$AdvancesMed}" />
<label for="AdvancesOthers" class="LLabelLoan1">&nbsp;Advances (Other):</label>
    <input name= "AdvancesOthers" id="AdvancesOthers" class = "LFieldLoan1" type="text" maxlength="10" tabindex="0" size="10" onkeyup="return autocalded(this, SSS, TAX, PCHL, HDMF, SSSLoan, HDMFLoan, Fund, BurialSep, TaxAjt, CashAdvance, AdvancesShirt, AdvancesMed)" value="{$AdvancesOthers}" />  
</p>
</fieldset>
<p class="serif">
<label for="TotalDeductions" class="LLabelDeduction">&nbsp;<b>Total Deductions:</b></label>
    <input name= "TotalDed" id="TotalDed" class = "LFieldLoan" type="text" maxlength="10" tabindex="0" size="10" value="{$TotalDed}" style="background: #CCCCCC"/>   
</p >
</fieldset>  
</div>
</div>
</div>
<div>
<p class="serif">
<label for="TakeHomePay" class="LLabelTakeHomePay"><b>Take Home Pay:</b></label>
    <input name= "TakeHomePay" id="TakeHomePay" class = "LFieldLoan" type="text" maxlength="20" tabindex="0" size="10" value="{$THP}" style="background: #CCCCCC" />
    &nbsp;<input type="button" name="save" value="SAVE" onclick="savePay()">
</p>
</div>
<div id="Generate">
<input type="button" name="generate" value="GENERATE PAYROLL" onclick="generatepayroll()">
</div>

this is the search.php


<?php
session_start();
include 'config.php';

$queryString = $_GET["query"];

if ($queryString == "" || $queryString == null) {

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL 
        ORDER BY FULLNAME ASC";
}
else {

$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL WHERE CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.')  LIKE '" . $queryString . "%' ORDER BY FULLNAME ASC";

}

$recPersonalQuery = $conn->Execute($sql);
if (!$recPersonalQuery->BOF) {
    $recPersonalQuery->MoveFirst();
}

echo "<hr />";
echo "<ul>";
while (!$recPersonalQuery->EOF) {
    $empID   = $recPersonalQuery->fields["EMP_ID"]; 
    $empFullName = $recPersonalQuery->fields["FULLNAME"];

  echo "<li onclick=changeEmployeePay('$empID'); style= 'font-family:'Times New Roman',Times,serif; font-size:10%;'>$empFullName</li>";
    echo "<hr />";
    $recPersonalQuery->MoveNext();
} 
echo "</ul>";

$recPersonalQuery->Close();
exit();   

You said i will put my payroll_save in search.php, i tried it but I got an error…
search.php is searching and displaying names of employee.

here is the SearchData.php


<?php
session_start();

$queryStr = trim($_GET["queryEmpID"]);

$_SESSION['empID'] = $queryStr; 

session_write_close();
header("Location:DisplayEmpPayroll.php");
exit();
?>

SearchData.php get the empid then display the payroll depend who is employee that i click…

I tried to add my payrollsave in DisplayEmpPayroll.php
but he only save data for SSS, HDMF, TAX, and PCHL because that data computed automatically in DisplayEmpPayroll.php

here is my code in DisplayEmpPayroll.php


<?php
include 'config.php';
$currentEmpID = $_SESSION['empID']; 
 
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";
$recPersonalNav = $conn->GetAll($sql);
$smarty->assign('personalAll', $recPersonalNav);
// ========================================================================================================================
$EMP_NO = $_POST['EMP_NO'];

$sql = "SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL p, EMPLOYMENT em  WHERE p.EMP_ID='$currentEmpID' AND em.EMP_ID = '$currentEmpID'";      
  
$recPersonalHead = $conn->Execute($sql);
$fullName = $recPersonalHead->fields["FULLNAME"];
$empno = $recPersonalHead->fields["EMP_NO"];

$smarty->assign('empid', $currentEmpID);
$smarty->assign('fullname', $fullName);
$smarty->assign('empno', $empno);

// ========================================================================================================================
 $sql = "SELECT EMP_ID, RATE FROM wage WHERE EMP_ID = '$currentEmpID'";
 $rsWage = $conn->Execute($sql);
 
 $Rate      = $rsWage->fields['RATE'];    
 

 $sql = "SELECT EMP_ID,EMP_NO, STATUS FROM employment WHERE EMP_ID = '$currentEmpID'";
 $rsStatus = $conn->Execute($sql);
 
 $STATUS = $rsStatus->fields['STATUS'];
 $EMP_ID = $rsStatus->fields['EMP_ID'];
 
 if ($STATUS == 'Regular'){
 
     $sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, r.Hours 
FROM $ADODB_DB.employment AS em 
INNER JOIN $ADODB_DB.wage AS w ON em.EMP_ID = w.EMP_ID
LEFT JOIN $PAYROLL.regular_sum_hours AS r ON em.EMP_NO = r.EMP_NO
WHERE  em.EMP_ID = '$currentEmpID'";
  
  $RsEarnings = $conn2->Execute($sql); 
  
  $Rate      = $RsEarnings->fields['RATE'];
  $Hours      = $RsEarnings->fields['Hours'];

  $Hours = substr($Hours, 0, 5);
  $Hours = str_replace(':', '.', $Hours);
  
 $Amount = $_POST["Amount"];
 
 $Amount = round(($Hours/8)* $Rate, 2); 
 }
 elseif($STATUS == 'Casual'){

  $sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, c.Casual_Hours 
FROM $ADODB_DB.employment AS em 
LEFT JOIN $ADODB_DB.wage AS w ON em.EMP_ID = w.EMP_ID
LEFT JOIN $PAYROLL.casual_hours AS c ON em.EMP_NO = c.EMP_NO
WHERE  em.EMP_ID = '$currentEmpID'";
  $RsEarnings = $conn2->Execute($sql); 
  
  $Rate      = $RsEarnings->fields['RATE'];
  $Hours      = $RsEarnings->fields['Casual_Hours'];

  $Hours = substr($Hours, 0, 5);
  $Hours = str_replace(':', '.', $Hours);
  
 $Amount = $_POST["Amount"];
 
 $Amount = round(($Hours/8)* $Rate, 2);  
 }
 else{
     $Hours = ('00:00');
     $Amount = (0);
 }
  
  $smarty->assign('Rate', $Rate);
  $smarty->assign('Hours', $Hours);
  $smarty->assign('Amount', $Amount);
//=================Display Regular Overtime ======================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'RegularOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$OTReg_Hours = $rsOTData->fields['OT_Hours'];
$OTReg_Hours = round($OTReg_Hours, 2);

$OTReg_Amt = round((($Rate / 8 * 1.3) * $OTReg_Hours), 2);
}
elseif($STATUS == 'Casual'){
 $sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'RegularOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$OTReg_Hours = $rsOTData->fields['OT_Hours'];
$OTReg_Hours = round($OTReg_Hours, 2);

$OTReg_Amt = round((($Rate / 8 * 1.25) * $OTReg_Hours), 2);
    
}
else{
$OTReg_Hours = 0;
$OTReg_Amt = 0;
}

$smarty->assign('OTReg_Hours', $OTReg_Hours);
$smarty->assign('OTReg_Amt', $OTReg_Amt);

//=====================Display Sunday Regular =================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em  WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'SundayRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$SunReg_Hours = $rsOTData->fields['OT_Hours'];
$SunReg_Hours = round($SunReg_Hours, 2);

$SunReg_Amt = round((($Rate / 8 * 1.35) * $SunReg_Hours), 2); 
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em  WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'SundayRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$SunReg_Hours = $rsOTData->fields['OT_Hours'];
$SunReg_Hours = round($SunReg_Hours, 2);

$SunReg_Amt = round((($Rate / 8 * 1.30) * $SunReg_Hours), 2); 
}
else{
    $SunReg_Hours = 0;
    $SunReg_Amt = 0;
}

$smarty->assign('SunReg_Hours', $SunReg_Hours);
$smarty->assign('SunReg_Amt', $SunReg_Amt); 

//====================Display Sunday Overtime===================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'SundayOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$OTSun_Hours = $rsOTData->fields['OT_Hours'];
$OTSun_Hours = round($OTSun_Hours, 2);

$OTSun_Amt = round((($Rate / 8 * 1.35 * 1.35) * $OTSun_Hours), 2);
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'SundayOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$OTSun_Hours = $rsOTData->fields['OT_Hours'];
$OTSun_Hours = round($OTSun_Hours, 2);

$OTSun_Amt = round((($Rate / 8 * 1.30 * 1.30) * $OTSun_Hours), 2);
}
else{
$OTSun_Hours = 0;
$OTSun_Amt = 0;
}

$smarty->assign('OTSun_Hours', $OTSun_Hours);
$smarty->assign('OTSun_Amt', $OTSun_Amt); 

//===================Display Holiday Regular======================
if($STATUS == 'Regular'){

$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolReg_Hours = $rsOTData->fields['OT_Hours'];
$HolReg_Hours = round($HolReg_Hours, 2);

$HolReg_Amt = round((($Rate / 8 * 1.5) * $HolReg_Hours), 2);
}
elseif($STATUS == 'Casual'){
 $sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolReg_Hours = $rsOTData->fields['OT_Hours'];
$HolReg_Hours = round($HolReg_Hours, 2);

$HolReg_Amt = round((($Rate / 8 * 1.25) * $HolReg_Hours), 2);
}
else{
$HolReg_Hours = 0;
$HolReg_Amt = 0;
}

$smarty->assign('HolReg_Hours', $HolReg_Hours);
$smarty->assign('HolReg_Amt', $HolReg_Amt); 

//==========================Display Holiday Regular Overtime=====================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayRegularOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolRegOT_Hours = $rsOTData->fields['OT_Hours'];
$HolRegOT_Hours = round($HolRegOT_Hours, 2);

$HolRegOT_Amt = round((($Rate / 8 * 2.05 * 1.35) * $HolRegOT_Hours), 2);
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayRegularOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolRegOT_Hours = $rsOTData->fields['OT_Hours'];
$HolRegOT_Hours = round($HolRegOT_Hours, 2);

$HolRegOT_Amt = round((($Rate / 8 * 2 * 1.25) * $HolRegOT_Hours), 2);
}
else{
$HolRegOT_Hours = 0;
$HolRegOT_Amt = 0;
}

$smarty->assign('HolRegOT_Hours', $HolRegOT_Hours);
$smarty->assign('HolRegOT_Amt', $HolRegOT_Amt); 

//==========================Display Holiday Leave ==============================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayLeave' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolLeave_Hours = $rsOTData->fields['OT_Hours'];
$HolLeave_Hours = round($HolLeave_Hours, 2);

$HolLeave_Amt = round((($Rate / 8) * $HolLeave_Hours), 2);
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayLeave' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolLeave_Hours = $rsOTData->fields['OT_Hours'];
$HolLeave_Hours = round($HolLeave_Hours, 2);

$HolLeave_Amt = round((($Rate / 8) * $HolLeave_Hours), 2);
}
else{
$HolLeave_Hours = 0;
$HolLeave_Amt = 0;
}

$smarty->assign('HolLeave_Hours', $HolLeave_Hours);
$smarty->assign('HolLeave_Amt', $HolLeave_Amt); 


//===================Display Night Premium=========================
if($STATUS == 'Regular') {
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPReg_Hours = $rsOTData->fields['OT_Hours'];
$NPReg_Hours = round($NPReg_Hours, 2);

$NPReg_Amt = round((($Rate / 8 * 0.15) * $NPReg_Hours), 2);


$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumSunday' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPSun_Hours = $rsOTData->fields['OT_Hours'];
$NPSun_Hours = round($NPSun_Hours, 2);

$NPSun_Amt = round((($Rate / 8 * 1.35 * 0.15) * $NPSun_Hours), 2);


$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumHoliday' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPHol_Hours = $rsOTData->fields['OT_Hours'];
$NPHol_Hours = round($NPHol_Hours, 2);

$NPHol_Amt = round((($Rate / 8 * 2.05 * 0.15) * $NPHol_Hours), 2);


$NP_Hours = round(($NPReg_Hours + $NPSun_Hours + $NPHol_Hours), 2);
$NP_Hours = round($NP_Hours, 2);

$NP_Amt =  round(($NPReg_Amt + $NPSun_Amt + $NPHol_Amt), 2); 
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPReg_Hours = $rsOTData->fields['OT_Hours'];
$NPReg_Hours = round($NPReg_Hours, 2);

$NPReg_Amt = round((($Rate / 8 * 0.10) * $NPReg_Hours), 2);


$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumSunday' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPSun_Hours = $rsOTData->fields['OT_Hours'];
$NPSun_Hours = round($NPSun_Hours, 2);

$NPSun_Amt = round((($Rate / 8 * 1.25 * 0.10) * $NPSun_Hours), 2);


$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumHoliday' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPHol_Hours = $rsOTData->fields['OT_Hours'];
$NPHol_Hours = round($NPHol_Hours, 2);

$NPHol_Amt = round((($Rate / 8 * 2 * 0.10) * $NPHol_Hours), 2);


$NP_Hours = round(($NPReg_Hours + $NPSun_Hours + $NPHol_Hours), 2);
$NP_Hours = round($NP_Hours, 2);

$NP_Amt =  round(($NPReg_Amt + $NPSun_Amt + $NPHol_Amt), 2); 
}
else{
$NP_Hours = 0;
$NP_Amt = 0;
}

$smarty->assign('NP_Hours', $NP_Hours);
$smarty->assign('NP_Amt', $NP_Amt);

//=================================Meal Allowance Regular and Sunday===============================
if($STATUS == 'Regular'){
$sql = "SELECT COUNT(o.EMP_NO) AS EMP_NO, o.OT_Category, o.OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category IN ('RegularOvertime', 'HolidayRegular', 'HolidayRegularOvertime', 'HolidayLeave') AND o.OT_Hours > 2  AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);
$MealReg_Hours = $rsOTData->fields['EMP_NO'];
$MealReg_Hours = round($MealReg_Hours, 2);

$MealReg_Amt = round(($MealReg_Hours * 23), 2);

$sql = "SELECT COUNT(o.EMP_NO) AS EMP_NO, o.OT_Category, o.OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category IN ('SundayRegular', 'SundayOvertime') AND o.OT_Hours > 2 AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$MealSun_Hours = $rsOTData->fields['EMP_NO'];
$MealSun_Hours = round($MealSun_Hours, 2);


$MealSun_Amt = round(($MealSun_Hours * 30), 2);

$Meal_Hours = round(($MealReg_Hours + $MealSun_Hours), 2);

$Meal_Amt = round(($MealReg_Amt + $MealSun_Amt), 2);
}
elseif($STATUS == 'Casual'){
$sql = "SELECT COUNT(o.EMP_NO) AS EMP_NO, o.OT_Category, o.OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category IN ('RegularOvertime', 'HolidayRegular', 'HolidayRegularOvertime', 'HolidayLeave') AND o.OT_Hours > 2 AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);
$MealReg_Hours = $rsOTData->fields['EMP_NO'];
$MealReg_Hours = round($MealReg_Hours, 2);

$MealReg_Amt = round(($MealReg_Hours * 23), 2);

$sql = "SELECT COUNT(o.EMP_NO) AS EMP_NO, o.OT_Category, o.OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category IN ('SundayRegular', 'SundayOvertime') AND o.OT_Hours > 2 AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$MealSun_Hours = $rsOTData->fields['EMP_NO'];
$MealSun_Hours = round($MealSun_Hours, 2);


$MealSun_Amt = round(($MealSun_Hours * 30), 2);

$Meal_Hours = round(($MealReg_Hours + $MealSun_Hours), 2);

$Meal_Amt = round(($MealReg_Amt + $MealSun_Amt), 2);
}
else{
$Meal_Hours = 0;
$Meal_Amt = 0;
}

$smarty->assign('Meal_Hours', $Meal_Hours);
$smarty->assign('Meal_Amt', $Meal_Amt);

//=============================COLA================================

$sql = "SELECT COUNT(a.EMP_NO) AS EMP_NO, w.RATE FROM $ADODB_DB.wage w, $ADODB.employment em, $PAYROLL.attendance a WHERE em.EMP_NO = a.EMP_NO AND w.RATE = 302 AND em.EMP_ID = '$currentEmpID' GROUP BY w.RATE";
$rsOTData = $conn2->Execute($sql);

$Cola_Hours = $rsOTData->fields['EMP_NO'];
$Cola_Hours = round($Cola_Hours, 2);


$Cola_Amt = round(($Cola_Hours * 28), 2);
      
$smarty->assign('Cola_Hours', $Cola_Hours);
$smarty->assign('Cola_Amt', $Cola_Amt);

$TotEarn = $_POST['TotEarn'];

$TotEarn = round(($Amount + $OTReg_Amt + $SunReg_Amt + $OTSun_Amt + $HolReg_Amt + $HolRegOT_Amt + $HolLeave_Amt + $NP_Amt + $Meal_Amt + $Cola_Amt), 2);

$smarty->assign('TotEarn', $TotEarn);

//==========DISPLAY HDMF DEDUCTIONS============//
$HDMF = $_POST['HDMF'];

$sql = "SELECT Ref_No, Range FROM $PAYROLL.hdmf, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
$rs = $conn2->Execute($sql);

$Range = $rs->fields['Range'];
 
if ($TotEarn <= $Range) {
    $HDMF = round(($TotEarn * 0.01), 2);
} else {
    $HDMF = round(($TotEarn * 0.02), 2);
}  

$smarty->assign('HDMF', $HDMF);
//===========DISPLAY SSS Deductions=======//

$SSS = $_POST['SSS'];

$sql = "SELECT Ref_No, From_Range, To_Range, Employee_Share FROM $PAYROLL.sss, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID' AND $TotEarn BETWEEN From_Range AND To_Range";
$rs = $conn2->Execute($sql);

$SSS = $rs->fields['Employee_Share'];

$smarty->assign('SSS', $SSS);     

//======================PCHL Deduction=====================

$PCHL = $_POST['PCHL'];

$sql = "SELECT Ref_No, From_Range, To_Range, Employee_Share FROM $PAYROLL.pchl, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID' AND $TotEarn BETWEEN From_Range AND To_Range";
$rs = $conn2->Execute($sql);

$PCHL = $rs->fields['Employee_Share'];

$smarty->assign('PCHL', $PCHL);
//========================TAX Deduction==============
$TAX = $_POST['TAX'];

$sql = "SELECT EMP_ID, EMP_NO, W4_STATUS, DEPENDENTS FROM employment  WHERE EMP_ID = '$currentEmpID'";
$rsTax = $conn->Execute($sql);

$W4_STATUS = $rsTax->fields['W4_STATUS'];
$DEPENDENTS = $rsTax->fields['DEPENDENTS'];

if($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 0 AND $TotEarn <= 2083){
  $TAX = round($TotEarn * .05);

}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 0 AND $TotEarn <= 2083){
  $TAX = round($TotEarn * .05);
 
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 2083 AND $TotEarn <= 2500) {
  $TAX = round($TotEarn - 2083);
  $TAX = round(20.83 + ($TAX * .10));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 2083 AND $TotEarn <= 2500) {
  $TAX = round($TotEarn - 2083);
  $TAX = round(20.83 + ($TAX * .10));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 2500 AND $TotEarn <= 3333) {
  $TAX = round($TotEarn - 2500);
  $TAX = round(104.17 + ($TAX * .15));
} 
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 2500 AND $TotEarn <= 3333) {
  $TAX = round($TotEarn - 2500);
  $TAX = round(104.17 + ($TAX * .15));
}  
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 3333 AND $TotEarn <= 5000) {
  $TAX = round($TotEarn - 3333);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 3333 AND $TotEarn <= 5000) {
  $TAX = round($TotEarn - 3333);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 5000 AND $TotEarn <= 7917) {
   $TAX = round($TotEarn - 5000);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 5000 AND $TotEarn <= 7917) {
   $TAX = round($TotEarn - 5000);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) {
   $TAX = round($TotEarn - 7917);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) {
   $TAX = round($TotEarn - 7917);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 12500 AND $TotEarn <= 22917) {
   $TAX = round($TotEarn - 12500);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 12500 AND $TotEarn <= 22917) {
   $TAX = round($TotEarn - 12500);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 0 AND $TotEarn <= 3125) {
   $TAX = round($TotEarn * .05);

}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 0 AND $TotEarn <= 3125) {
   $TAX = round($TotEarn * .05);
 
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 3125 AND $TotEarn <= 3542) {
   $TAX = round($TotEarn - 3125);
   $TAX = round(20.83 + ($TAX * .10));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 3125 AND $TotEarn <= 3542) {
   $TAX = round($TotEarn - 3125);
   $TAX = round(20.83 + ($TAX * .10));
}  
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 3542 AND $TotEarn <= 4375) {
  $TAX = round($TotEarn - 3542);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 3542 AND $TotEarn <= 4375) {
  $TAX = round($TotEarn - 3542);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 4375 AND $TotEarn <= 6042) {
   $TAX = round($TotEarn - 4375);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 4375 AND $TotEarn <= 6042) {
   $TAX = round($TotEarn - 4375);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 6042 AND $TotEarn <= 8958) {
   $TAX = round($TotEarn - 6042);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 6042 AND $TotEarn <= 8958) {
   $TAX = round($TotEarn - 6042);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 8958 AND $TotEarn <= 13542) {
   $TAX = round($TotEarn - 8958);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 8958 AND $TotEarn <= 13542) {
   $TAX = round($TotEarn - 8958);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 13542 AND $TotEarn <= 23958) {
   $TAX = round($TotEarn - 13542);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 13542 AND $TotEarn <= 23958) {
   $TAX = round($TotEarn - 13542);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 0 AND $TotEarn <= 4167) {
   $TAX = round($TotEarn * .05);
 
}   
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 0 AND $TotEarn <= 4167) {
   $TAX = round($TotEarn * .05);
 
}   
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 4167 AND $TotEarn <= 4583) {
   $TAX = round($TotEarn - 4167);
   $TAX = round(20.83 + ($TAX * .10));
} 
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 4167 AND $TotEarn <= 4583) {
   $TAX = round($TotEarn - 4167);
   $TAX = round(20.83 + ($TAX * .10));
}  
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 4583 AND $TotEarn <= 5417) {
  $TAX = round($TotEarn - 4583);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 4583 AND $TotEarn <= 5417) {
  $TAX = round($TotEarn - 4583);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 5417 AND $TotEarn <= 7083) {
   $TAX = round($TotEarn - 5417);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 5417 AND $TotEarn <= 7083) {
   $TAX = round($TotEarn - 5417);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 7083 AND $TotEarn <= 10000) {
   $TAX = round($TotEarn - 7083);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 7083 AND $TotEarn <= 10000) {
   $TAX = round($TotEarn - 7083);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 10000 AND $TotEarn <= 14583) {
   $TAX = round($TotEarn - 10000);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 10000 AND $TotEarn <= 14583) {
   $TAX = round($TotEarn - 10000);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 14583 AND $TotEarn <= 25000) {
   $TAX = round($TotEarn - 14583);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 14583 AND $TotEarn <= 25000) {
   $TAX = round($TotEarn - 14583);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 0 AND $TotEarn <= 5208) {
   $TAX = round($TotEarn * .05);

}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 0 AND $TotEarn <= 5208) {
   $TAX = round($TotEarn * .05);

}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 5208 AND $TotEarn <= 5625) {
   $TAX = round($TotEarn - 5208);
   $TAX = round(20.83 + ($TAX * .10));
}  
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 5208 AND $TotEarn <= 5625) {
   $TAX = round($TotEarn - 5208);
   $TAX = round(20.83 + ($TAX * .10));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 5625 AND $TotEarn <= 6458) {
  $TAX = round($TotEarn - 5625);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 5625 AND $TotEarn <= 6458) {
  $TAX = round($TotEarn - 5625);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 6458 AND $TotEarn <= 8125) {
   $TAX = round($TotEarn - 6458);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 6458 AND $TotEarn <= 8125) {
   $TAX = round($TotEarn - 6458);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 8125 AND $TotEarn <= 11042) {
   $TAX = round($TotEarn - 8125);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 8125 AND $TotEarn <= 11042) {
   $TAX = round($TotEarn - 8125);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 11042 AND $TotEarn <= 15625) {
   $TAX = round($TotEarn - 11042);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 11042 AND $TotEarn <= 15625) {
   $TAX = round($TotEarn - 11042);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 15625 AND $TotEarn <= 26042) {
   $TAX = round($TotEarn - 15625);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 15625 AND $TotEarn <= 26042) {
   $TAX = round($TotEarn - 15625);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 0 AND $TotEarn <= 6250) {
   $TAX = round($TotEarn * .05);
 
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 0 AND $TotEarn <= 6250) {
   $TAX = round($TotEarn * .05);

}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 6250 AND $TotEarn <= 6667) {
   $TAX = round($TotEarn - 6250);
   $TAX = round(20.83 + ($TAX * .10));
}  
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 6250 AND $TotEarn <= 6667) {
   $TAX = round($TotEarn - 6250);
   $TAX = round(20.83 + ($TAX * .10));
} 
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 6667 AND $TotEarn <= 7500) {
  $TAX = round($TotEarn - 6667);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 6667 AND $TotEarn <= 7500) {
  $TAX = round($TotEarn - 6667);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 7500 AND $TotEarn <= 9167) {
   $TAX = round($TotEarn - 7500);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 7500 AND $TotEarn <= 9167) {
   $TAX = round($TotEarn - 7500);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 9167 AND $TotEarn <= 12083) {
   $TAX = round($TotEarn - 9167);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 9167 AND $TotEarn <= 12083) {
   $TAX = round($TotEarn - 9167);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 12083 AND $TotEarn <= 16667) {
   $TAX = round($TotEarn - 12083);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 12083 AND $TotEarn <= 16667) {
   $TAX = round($TotEarn - 12083);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 16667 AND $TotEarn <= 27083) {
   $TAX = round($TotEarn - 16667);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 16667 AND $TotEarn <= 27083) {
   $TAX = round($TotEarn - 16667);
   $TAX = round(5208.83 + ($TAX * .32));
}

else{
    $TAX = round(0);
}

$smarty->assign('TAX', $TAX);

########DISPLAY SSS Loan Deduction##########

 $sql = "SELECT s.EMP_NO, s.SSSAmor FROM $PAYROLL.sssloan s, $ADODB_DB.employment em WHERE em.EMP_NO = s.EMP_NO AND em.EMP_ID = '$currentEmpID'";
 $RsDed = $conn2->Execute($sql);
 
 $SSSAmor = round($RsDed->fields['SSSAmor']);
 
//==========DISPLAY HDMF Loan Deduction===============

$sql = "SELECT h.EMP_NO, h.HDMFAmor FROM $PAYROLL.hdmfloan h, $ADODB_DB.employment em WHERE em.EMP_NO = h.EMP_NO AND em.EMP_ID = '$currentEmpID'"; 
 $RsHDMF = $conn2->Execute($sql);
 
 $HDMFAmor = round($RsHDMF->fields['HDMFAmor']);
 
 //============DISPLAY Trust Fund Loan Deduction=================
 
$sql = "SELECT u.EMP_NO, u.UDTAmor FROM $PAYROLL.udtloan u, $ADODB_DB.employment em WHERE em.EMP_NO = u.EMP_NO AND em.EMP_ID = '$currentEmpID'";
 $RsUDT = $conn2->Execute($sql);
 
 $UDTAmor = round($RsUDT->fields['UDTAmor']);

$TotalDed = $_POST['TotalDed'];

///===============other deductions========
 $BurialSep = $_POST["BurialSep"];
 $TaxAjt = $_POST["TaxAjt"];
 $CashAdvance = $_POST["CashAdvance"];
 $AdvancesShirt = $_POST["AdvancesShirt"];
 $AdvancesMed = $_POST["AdvancesMed"];
 $AdvancesOthers = $_POST["AdvancesOthers"];

 $sql = "SELECT o.EMP_NO, o.BurialSeparationCont, o.TaxAjt, o.CashAdvance, o.AdvanceShirt, o.AdvanceMed, o.AdvanceOther FROM $PAYROLL.other_deductions o, $ADODB_DB.personal p, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID' AND em.EMP_NO = o.EMP_NO";
 $rsOtherDed = $conn2->Execute($sql);
 
 $BurialSep = round($rsOtherDed->fields['BurialSeparationCont']);
 $TaxAjt = round($rsOtherDed->fields['TaxAjt']);
 $CashAdvance = round($rsOtherDed->fields['CashAdvance']);
 $AdvancesShirt = round($rsOtherDed->fields['AdvanceShirt']);
 $AdvancesMed = round($rsOtherDed->fields['AdvanceMed']);
 $AdvancesOthers = round($rsOtherDed->fields['AdvanceOther']);
 
 $smarty->assign('BurialSep', $BurialSep);
 $smarty->assign('TaxAjt', $TaxAjt);
 $smarty->assign('CashAdvance', $CashAdvance);
 $smarty->assign('AdvancesShirt', $AdvancesShirt);
 $smarty->assign('AdvancesMed', $AdvancesMed);
 $smarty->assign('AdvancesOthers', $AdvancesOthers);
 

$TotalDed = round(($SSS + $HDMF + $PCHL + $TAX + $SSSAmor + $HDMFAmor + $UDTAmor + $BurialSep + $TaxAjt + $CashAdvance + $AdvancesShirt + $AdvancesMed + $AdvancesOthers), 2); 

 $smarty->assign('SSSAmor', $SSSAmor);
 $smarty->assign('HDMFAmor', $HDMFAmor);
 $smarty->assign('UDTAmor', $UDTAmor);
 $smarty->assign('TotalDed', $TotalDed);
 
##############Total Earns##############
$THP = $_POST["TakeHomePay"];

$THP = round($TotEarn - $TotalDed, 2);

$smarty->assign('THP', $THP);

//=================Save Deductions=============
 
 $sql = "SELECT EMP_NO, SSS, TAX, PCHL, HDMF FROM deductions WHERE EMP_NO = '$empno'";
 $RsDeduction = $conn2->Execute($sql);
 
 $numrowsDeduction = $RsDeduction->RecordCount(); 
 
 if($numrowsDeduction > 0){
 $saverec['EMP_NO'] = $empno;
 $saverec['SSS'] = $SSS;
 $saverec['TAX'] = $TAX;
 $saverec['PCHL'] = $PCHL;
 $saverec['HDMF'] = $HDMF;
 
 
 $updateDeductionSQL = $conn2->GetUpdateSQL($RsDeduction, $saverec); 
 $conn2->Execute($updateDeductionSQL); 
 }
 else{
  $sql = "SELECT d.EMP_NO, d.SSS, d.TAX, d.PCHL, d.HDMF FROM $PAYROLL.deductions d, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
 $RsDeduction = $conn2->Execute($sql);
 
 $saverec['EMP_NO'] = $empno;
 $saverec['SSS'] = $SSS;
 $saverec['TAX'] = $TAX;  
 $saverec['PCHL'] = $PCHL;
 $saverec['HDMF'] = $HDMF;
 
 $insertSQL = $conn2->GetInsertSQL($RsDeduction, $saverec); 
 $conn2->Execute($insertSQL); 
 }
 
  //================SAVE LOAN============
 
 $SSSLoan = $_POST['SSSAmor'];
 $HDMFLoan = $_POST['HDMFAmor'];
 $Fund = $_POST['UDTAmor'];
 
 $sql = "SELECT EMP_NO, SSSLoan, HDMFLoan, UDTLoan FROM loan_deductions WHERE EMP_NO = '$empno'";
 $RsLoan = $conn2->Execute($sql);
 
 $numrowsRsLoan = $RsLoan->RecordCount();
 
 if($numrowsRsLoan > 0){
 $saverec['EMP_NO'] = $empno;
 $saverec['SSSLoan'] = $SSSLoan;
 $saverec['HDMFLoan'] = $HDMFLoan;
 $saverec['UDTLoan'] = $Fund;
 
 $updateLoanSQL = $conn2->GetUpdateSQL($RsLoan, $saverec); 
 $conn2->Execute($updateLoanSQL); 
 }
 else{
 
 $sql = "SELECT l.EMP_NO, l.SSSLoan, l.HDMFLoan, l.UDTLoan FROM $PAYROLL.loan_deductions l, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
 $RsLoan = $conn2->Execute($sql);
 
 $saverec['EMP_NO'] = $empno;
 $saverec['SSSLoan'] = $SSSLoan;
 $saverec['HDMFLoan'] = $HDMFLoan;
 $saverec['UDTLoan'] = $Fund;
 
 $insertSQL = $conn2->GetInsertSQL($RsLoan, $saverec); 
 $conn2->Execute($insertSQL); 
 }
     
$smarty->display('header.tpl');
$smarty->display('left.tpl');
$smarty->display('empPayrollData.tpl');
$smarty->display('footer.tpl'); 

?>

Thank you so much.

Hi…

I revised my EmpPayrollData.php


<?php
include 'config.php';

$currentEmpID = $_SESSION['empID']; 
 
$sql = "SELECT EMP_ID, CONCAT(LNAME, ', ' , FNAME, ' ', MI) AS FULLNAME FROM PERSONAL ORDER BY LNAME ASC";
$recPersonalNav = $conn->GetAll($sql);
$smarty->assign('personalAll', $recPersonalNav);
// ========================================================================================================================
$EMP_NO = $_POST['EMP_NO'];

$sql = "SELECT em.EMP_NO, p.EMP_ID, CONCAT(LNAME, ', ',  FNAME, ' ', MI, '.') AS FULLNAME FROM PERSONAL p, EMPLOYMENT em  WHERE p.EMP_ID='$currentEmpID' AND em.EMP_ID = '$currentEmpID'";      
  
$recPersonalHead = $conn->Execute($sql);
$fullName = $recPersonalHead->fields["FULLNAME"];
$empno = $recPersonalHead->fields["EMP_NO"];

$smarty->assign('empid', $currentEmpID);
$smarty->assign('fullname', $fullName);
$smarty->assign('empno', $empno);

// ========================================================================================================================
 $sql = "SELECT EMP_ID, RATE FROM wage WHERE EMP_ID = '$currentEmpID'";
 $rsWage = $conn->Execute($sql);
 
 $Rate      = $rsWage->fields['RATE'];    
 

 $sql = "SELECT EMP_ID,EMP_NO, STATUS FROM employment WHERE EMP_ID = '$currentEmpID'";
 $rsStatus = $conn->Execute($sql);
 
 $STATUS = $rsStatus->fields['STATUS'];
 $EMP_ID = $rsStatus->fields['EMP_ID'];
 
 if ($STATUS == 'Regular'){
 
     $sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, r.Hours 
FROM $ADODB_DB.employment AS em 
INNER JOIN $ADODB_DB.wage AS w ON em.EMP_ID = w.EMP_ID
LEFT JOIN $PAYROLL.regular_sum_hours AS r ON em.EMP_NO = r.EMP_NO
WHERE  em.EMP_ID = '$currentEmpID'";
  
  $RsEarnings = $conn2->Execute($sql); 
  
  $Rate      = $RsEarnings->fields['RATE'];
  $Hours      = $RsEarnings->fields['Hours'];

  $Hours = substr($Hours, 0, 5);
  $Hours = str_replace(':', '.', $Hours);
  
 $Amount = $_POST["Amount"];
 
 $Amount = round(($Hours/8)* $Rate, 2); 
 }
 elseif($STATUS == 'Casual'){

  $sql = "SELECT em.EMP_NO, em.STATUS, w.RATE, c.Casual_Hours 
FROM $ADODB_DB.employment AS em 
LEFT JOIN $ADODB_DB.wage AS w ON em.EMP_ID = w.EMP_ID
LEFT JOIN $PAYROLL.casual_hours AS c ON em.EMP_NO = c.EMP_NO
WHERE  em.EMP_ID = '$currentEmpID'";
  $RsEarnings = $conn2->Execute($sql); 
  
  $Rate      = $RsEarnings->fields['RATE'];
  $Hours      = $RsEarnings->fields['Casual_Hours'];

  $Hours = substr($Hours, 0, 5);
  $Hours = str_replace(':', '.', $Hours);
  
 $Amount = $_POST["Amount"];
 
 $Amount = round(($Hours/8)* $Rate, 2);  
 }
 else{
     $Hours = ('00:00');
     $Amount = (0);
 }
  
  $smarty->assign('Rate', $Rate);
  $smarty->assign('Hours', $Hours);
  $smarty->assign('Amount', $Amount);
//=================Display Regular Overtime ======================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'RegularOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$OTReg_Hours = $rsOTData->fields['OT_Hours'];
$OTReg_Hours = round($OTReg_Hours, 2);

$OTReg_Amt = round((($Rate / 8 * 1.3) * $OTReg_Hours), 2);
}
elseif($STATUS == 'Casual'){
 $sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'RegularOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$OTReg_Hours = $rsOTData->fields['OT_Hours'];
$OTReg_Hours = round($OTReg_Hours, 2);

$OTReg_Amt = round((($Rate / 8 * 1.25) * $OTReg_Hours), 2);
    
}
else{
$OTReg_Hours = 0;
$OTReg_Amt = 0;
}

$smarty->assign('OTReg_Hours', $OTReg_Hours);
$smarty->assign('OTReg_Amt', $OTReg_Amt);

//=====================Display Sunday Regular =================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em  WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'SundayRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$SunReg_Hours = $rsOTData->fields['OT_Hours'];
$SunReg_Hours = round($SunReg_Hours, 2);

$SunReg_Amt = round((($Rate / 8 * 1.35) * $SunReg_Hours), 2); 
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em  WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'SundayRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$SunReg_Hours = $rsOTData->fields['OT_Hours'];
$SunReg_Hours = round($SunReg_Hours, 2);

$SunReg_Amt = round((($Rate / 8 * 1.30) * $SunReg_Hours), 2); 
}
else{
    $SunReg_Hours = 0;
    $SunReg_Amt = 0;
}

$smarty->assign('SunReg_Hours', $SunReg_Hours);
$smarty->assign('SunReg_Amt', $SunReg_Amt); 

//====================Display Sunday Overtime===================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'SundayOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$OTSun_Hours = $rsOTData->fields['OT_Hours'];
$OTSun_Hours = round($OTSun_Hours, 2);

$OTSun_Amt = round((($Rate / 8 * 1.35 * 1.35) * $OTSun_Hours), 2);
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'SundayOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$OTSun_Hours = $rsOTData->fields['OT_Hours'];
$OTSun_Hours = round($OTSun_Hours, 2);

$OTSun_Amt = round((($Rate / 8 * 1.30 * 1.30) * $OTSun_Hours), 2);
}
else{
$OTSun_Hours = 0;
$OTSun_Amt = 0;
}

$smarty->assign('OTSun_Hours', $OTSun_Hours);
$smarty->assign('OTSun_Amt', $OTSun_Amt); 

//===================Display Holiday Regular======================
if($STATUS == 'Regular'){

$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolReg_Hours = $rsOTData->fields['OT_Hours'];
$HolReg_Hours = round($HolReg_Hours, 2);

$HolReg_Amt = round((($Rate / 8 * 1.5) * $HolReg_Hours), 2);
}
elseif($STATUS == 'Casual'){
 $sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolReg_Hours = $rsOTData->fields['OT_Hours'];
$HolReg_Hours = round($HolReg_Hours, 2);

$HolReg_Amt = round((($Rate / 8 * 1.25) * $HolReg_Hours), 2);
}
else{
$HolReg_Hours = 0;
$HolReg_Amt = 0;
}

$smarty->assign('HolReg_Hours', $HolReg_Hours);
$smarty->assign('HolReg_Amt', $HolReg_Amt); 

//==========================Display Holiday Regular Overtime=====================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayRegularOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolRegOT_Hours = $rsOTData->fields['OT_Hours'];
$HolRegOT_Hours = round($HolRegOT_Hours, 2);

$HolRegOT_Amt = round((($Rate / 8 * 2.05 * 1.35) * $HolRegOT_Hours), 2);
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayRegularOvertime' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolRegOT_Hours = $rsOTData->fields['OT_Hours'];
$HolRegOT_Hours = round($HolRegOT_Hours, 2);

$HolRegOT_Amt = round((($Rate / 8 * 2 * 1.25) * $HolRegOT_Hours), 2);
}
else{
$HolRegOT_Hours = 0;
$HolRegOT_Amt = 0;
}

$smarty->assign('HolRegOT_Hours', $HolRegOT_Hours);
$smarty->assign('HolRegOT_Amt', $HolRegOT_Amt); 

//==========================Display Holiday Leave ==============================
if($STATUS == 'Regular'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayLeave' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolLeave_Hours = $rsOTData->fields['OT_Hours'];
$HolLeave_Hours = round($HolLeave_Hours, 2);

$HolLeave_Amt = round((($Rate / 8) * $HolLeave_Hours), 2);
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'HolidayLeave' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$HolLeave_Hours = $rsOTData->fields['OT_Hours'];
$HolLeave_Hours = round($HolLeave_Hours, 2);

$HolLeave_Amt = round((($Rate / 8) * $HolLeave_Hours), 2);
}
else{
$HolLeave_Hours = 0;
$HolLeave_Amt = 0;
}

$smarty->assign('HolLeave_Hours', $HolLeave_Hours);
$smarty->assign('HolLeave_Amt', $HolLeave_Amt); 


//===================Display Night Premium=========================
if($STATUS == 'Regular') {
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPReg_Hours = $rsOTData->fields['OT_Hours'];
$NPReg_Hours = round($NPReg_Hours, 2);

$NPReg_Amt = round((($Rate / 8 * 0.15) * $NPReg_Hours), 2);


$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumSunday' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPSun_Hours = $rsOTData->fields['OT_Hours'];
$NPSun_Hours = round($NPSun_Hours, 2);

$NPSun_Amt = round((($Rate / 8 * 1.35 * 0.15) * $NPSun_Hours), 2);


$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumHoliday' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPHol_Hours = $rsOTData->fields['OT_Hours'];
$NPHol_Hours = round($NPHol_Hours, 2);

$NPHol_Amt = round((($Rate / 8 * 2.05 * 0.15) * $NPHol_Hours), 2);


$NP_Hours = round(($NPReg_Hours + $NPSun_Hours + $NPHol_Hours), 2);
$NP_Hours = round($NP_Hours, 2);

$NP_Amt =  round(($NPReg_Amt + $NPSun_Amt + $NPHol_Amt), 2); 
}
elseif($STATUS == 'Casual'){
$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumRegular' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPReg_Hours = $rsOTData->fields['OT_Hours'];
$NPReg_Hours = round($NPReg_Hours, 2);

$NPReg_Amt = round((($Rate / 8 * 0.10) * $NPReg_Hours), 2);


$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumSunday' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPSun_Hours = $rsOTData->fields['OT_Hours'];
$NPSun_Hours = round($NPSun_Hours, 2);

$NPSun_Amt = round((($Rate / 8 * 1.25 * 0.10) * $NPSun_Hours), 2);


$sql = "SELECT em.EMP_NO, o.OT_Category, SUM(OT_Hours) AS OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category = 'NightPremiumHoliday' AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$NPHol_Hours = $rsOTData->fields['OT_Hours'];
$NPHol_Hours = round($NPHol_Hours, 2);

$NPHol_Amt = round((($Rate / 8 * 2 * 0.10) * $NPHol_Hours), 2);


$NP_Hours = round(($NPReg_Hours + $NPSun_Hours + $NPHol_Hours), 2);
$NP_Hours = round($NP_Hours, 2);

$NP_Amt =  round(($NPReg_Amt + $NPSun_Amt + $NPHol_Amt), 2); 
}
else{
$NP_Hours = 0;
$NP_Amt = 0;
}

$smarty->assign('NP_Hours', $NP_Hours);
$smarty->assign('NP_Amt', $NP_Amt);

//=================================Meal Allowance Regular and Sunday===============================
if($STATUS == 'Regular'){
$sql = "SELECT COUNT(o.EMP_NO) AS EMP_NO, o.OT_Category, o.OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category IN ('RegularOvertime', 'HolidayRegular', 'HolidayRegularOvertime', 'HolidayLeave') AND o.OT_Hours > 2  AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);
$MealReg_Hours = $rsOTData->fields['EMP_NO'];
$MealReg_Hours = round($MealReg_Hours, 2);

$MealReg_Amt = round(($MealReg_Hours * 23), 2);

$sql = "SELECT COUNT(o.EMP_NO) AS EMP_NO, o.OT_Category, o.OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category IN ('SundayRegular', 'SundayOvertime') AND o.OT_Hours > 2 AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$MealSun_Hours = $rsOTData->fields['EMP_NO'];
$MealSun_Hours = round($MealSun_Hours, 2);


$MealSun_Amt = round(($MealSun_Hours * 30), 2);

$Meal_Hours = round(($MealReg_Hours + $MealSun_Hours), 2);

$Meal_Amt = round(($MealReg_Amt + $MealSun_Amt), 2);
}
elseif($STATUS == 'Casual'){
$sql = "SELECT COUNT(o.EMP_NO) AS EMP_NO, o.OT_Category, o.OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category IN ('RegularOvertime', 'HolidayRegular', 'HolidayRegularOvertime', 'HolidayLeave') AND o.OT_Hours > 2 AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);
$MealReg_Hours = $rsOTData->fields['EMP_NO'];
$MealReg_Hours = round($MealReg_Hours, 2);

$MealReg_Amt = round(($MealReg_Hours * 23), 2);

$sql = "SELECT COUNT(o.EMP_NO) AS EMP_NO, o.OT_Category, o.OT_Hours FROM $PAYROLL.ot_data o, $ADODB_DB.employment em WHERE em.EMP_NO = o.EMP_NO AND o.OT_Category IN ('SundayRegular', 'SundayOvertime') AND o.OT_Hours > 2 AND em.EMP_ID = '$currentEmpID' GROUP BY em.EMP_NO";
$rsOTData = $conn2->Execute($sql);

$MealSun_Hours = $rsOTData->fields['EMP_NO'];
$MealSun_Hours = round($MealSun_Hours, 2);


$MealSun_Amt = round(($MealSun_Hours * 30), 2);

$Meal_Hours = round(($MealReg_Hours + $MealSun_Hours), 2);

$Meal_Amt = round(($MealReg_Amt + $MealSun_Amt), 2);
}
else{
$Meal_Hours = 0;
$Meal_Amt = 0;
}

$smarty->assign('Meal_Hours', $Meal_Hours);
$smarty->assign('Meal_Amt', $Meal_Amt);

//=============================COLA================================

$sql = "SELECT COUNT(a.EMP_NO) AS EMP_NO, w.RATE FROM $ADODB_DB.wage w, $ADODB.employment em, $PAYROLL.attendance a WHERE em.EMP_NO = a.EMP_NO AND w.RATE = 302 AND em.EMP_ID = '$currentEmpID' GROUP BY w.RATE";
$rsOTData = $conn2->Execute($sql);

$Cola_Hours = $rsOTData->fields['EMP_NO'];
$Cola_Hours = round($Cola_Hours, 2);


$Cola_Amt = round(($Cola_Hours * 28), 2);
      
$smarty->assign('Cola_Hours', $Cola_Hours);
$smarty->assign('Cola_Amt', $Cola_Amt);

$TotEarn = $_POST['TotEarn'];

$TotEarn = round(($Amount + $OTReg_Amt + $SunReg_Amt + $OTSun_Amt + $HolReg_Amt + $HolRegOT_Amt + $HolLeave_Amt + $NP_Amt + $Meal_Amt + $Cola_Amt), 2);

$smarty->assign('TotEarn', $TotEarn);

//==========DISPLAY HDMF DEDUCTIONS============//
$HDMF = $_POST['HDMF'];

$sql = "SELECT Ref_No, Range FROM $PAYROLL.hdmf, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
$rs = $conn2->Execute($sql);

$Range = $rs->fields['Range'];
 
if ($TotEarn <= $Range) {
    $HDMF = round(($TotEarn * 0.01), 2);
} else {
    $HDMF = round(($TotEarn * 0.02), 2);
}  

$smarty->assign('HDMF', $HDMF);
//===========DISPLAY SSS Deductions=======//

$SSS = $_POST['SSS'];

$sql = "SELECT Ref_No, From_Range, To_Range, Employee_Share FROM $PAYROLL.sss, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID' AND $TotEarn BETWEEN From_Range AND To_Range";
$rs = $conn2->Execute($sql);

$SSS = $rs->fields['Employee_Share'];
$smarty->assign('SSS', $SSS);     

//======================PCHL Deduction=====================

$PCHL = $_POST['PCHL'];

$sql = "SELECT Ref_No, From_Range, To_Range, Employee_Share FROM $PAYROLL.pchl, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID' AND $TotEarn BETWEEN From_Range AND To_Range";
$rs = $conn2->Execute($sql);

$PCHL = $rs->fields['Employee_Share'];

$smarty->assign('PCHL', $PCHL);
//========================TAX Deduction==============
$TAX = $_POST['TAX'];

$sql = "SELECT EMP_ID, EMP_NO, W4_STATUS, DEPENDENTS FROM employment  WHERE EMP_ID = '$currentEmpID'";
$rsTax = $conn->Execute($sql);

$W4_STATUS = $rsTax->fields['W4_STATUS'];
$DEPENDENTS = $rsTax->fields['DEPENDENTS'];

if($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 0 AND $TotEarn <= 2083){
  $TAX = round($TotEarn * .05);
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 0 AND $TotEarn <= 2083){
  $TAX = round($TotEarn * .05);
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 2083 AND $TotEarn <= 2500) {
  $TAX = round($TotEarn - 2083);
  $TAX = round(20.83 + ($TAX * .10));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 2083 AND $TotEarn <= 2500) {
  $TAX = round($TotEarn - 2083);
  $TAX = round(20.83 + ($TAX * .10));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 2500 AND $TotEarn <= 3333) {
  $TAX = round($TotEarn - 2500);
  $TAX = round(104.17 + ($TAX * .15));
} 
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 2500 AND $TotEarn <= 3333) {
  $TAX = round($TotEarn - 2500);
  $TAX = round(104.17 + ($TAX * .15));
}  
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 3333 AND $TotEarn <= 5000) {
  $TAX = round($TotEarn - 3333);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 3333 AND $TotEarn <= 5000) {
  $TAX = round($TotEarn - 3333);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 5000 AND $TotEarn <= 7917) {
   $TAX = round($TotEarn - 5000);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 5000 AND $TotEarn <= 7917) {
   $TAX = round($TotEarn - 5000);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) {
   $TAX = round($TotEarn - 7917);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 7917 AND $TotEarn <= 12500) {
   $TAX = round($TotEarn - 7917);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 0 AND $TotEarn >= 12500 AND $TotEarn <= 22917) {
   $TAX = round($TotEarn - 12500);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 0 AND $TotEarn >= 12500 AND $TotEarn <= 22917) {
   $TAX = round($TotEarn - 12500);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 0 AND $TotEarn <= 3125) {
   $TAX = round($TotEarn * .05);
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 0 AND $TotEarn <= 3125) {
   $TAX = round($TotEarn * .05);
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 3125 AND $TotEarn <= 3542) {
   $TAX = round($TotEarn - 3125);
   $TAX = round(20.83 + ($TAX * .10));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 3125 AND $TotEarn <= 3542) {
   $TAX = round($TotEarn - 3125);
   $TAX = round(20.83 + ($TAX * .10));
}  
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 3542 AND $TotEarn <= 4375) {
  $TAX = round($TotEarn - 3542);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 3542 AND $TotEarn <= 4375) {
  $TAX = round($TotEarn - 3542);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 4375 AND $TotEarn <= 6042) {
   $TAX = round($TotEarn - 4375);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 4375 AND $TotEarn <= 6042) {
   $TAX = round($TotEarn - 4375);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 6042 AND $TotEarn <= 8958) {
   $TAX = round($TotEarn - 6042);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 6042 AND $TotEarn <= 8958) {
   $TAX = round($TotEarn - 6042);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 8958 AND $TotEarn <= 13542) {
   $TAX = round($TotEarn - 8958);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 8958 AND $TotEarn <= 13542) {
   $TAX = round($TotEarn - 8958);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 1 AND $TotEarn >= 13542 AND $TotEarn <= 23958) {
   $TAX = round($TotEarn - 13542);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 1 AND $TotEarn >= 13542 AND $TotEarn <= 23958) {
   $TAX = round($TotEarn - 13542);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 0 AND $TotEarn <= 4167) {
   $TAX = round($TotEarn * .05);
}   
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 0 AND $TotEarn <= 4167) {
   $TAX = round($TotEarn * .05);
}   
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 4167 AND $TotEarn <= 4583) {
   $TAX = round($TotEarn - 4167);
   $TAX = round(20.83 + ($TAX * .10));
} 
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 4167 AND $TotEarn <= 4583) {
   $TAX = round($TotEarn - 4167);
   $TAX = round(20.83 + ($TAX * .10));
}  
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 4583 AND $TotEarn <= 5417) {
  $TAX = round($TotEarn - 4583);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 4583 AND $TotEarn <= 5417) {
  $TAX = round($TotEarn - 4583);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 5417 AND $TotEarn <= 7083) {
   $TAX = round($TotEarn - 5417);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 5417 AND $TotEarn <= 7083) {
   $TAX = round($TotEarn - 5417);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 7083 AND $TotEarn <= 10000) {
   $TAX = round($TotEarn - 7083);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 7083 AND $TotEarn <= 10000) {
   $TAX = round($TotEarn - 7083);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 10000 AND $TotEarn <= 14583) {
   $TAX = round($TotEarn - 10000);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 10000 AND $TotEarn <= 14583) {
   $TAX = round($TotEarn - 10000);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 2 AND $TotEarn >= 14583 AND $TotEarn <= 25000) {
   $TAX = round($TotEarn - 14583);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 2 AND $TotEarn >= 14583 AND $TotEarn <= 25000) {
   $TAX = round($TotEarn - 14583);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 0 AND $TotEarn <= 5208) {
   $TAX = round($TotEarn * .05);
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 0 AND $TotEarn <= 5208) {
   $TAX = round($TotEarn * .05);
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 5208 AND $TotEarn <= 5625) {
   $TAX = round($TotEarn - 5208);
   $TAX = round(20.83 + ($TAX * .10));
}  
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 5208 AND $TotEarn <= 5625) {
   $TAX = round($TotEarn - 5208);
   $TAX = round(20.83 + ($TAX * .10));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 5625 AND $TotEarn <= 6458) {
  $TAX = round($TotEarn - 5625);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 5625 AND $TotEarn <= 6458) {
  $TAX = round($TotEarn - 5625);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 6458 AND $TotEarn <= 8125) {
   $TAX = round($TotEarn - 6458);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 6458 AND $TotEarn <= 8125) {
   $TAX = round($TotEarn - 6458);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 8125 AND $TotEarn <= 11042) {
   $TAX = round($TotEarn - 8125);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 8125 AND $TotEarn <= 11042) {
   $TAX = round($TotEarn - 8125);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 11042 AND $TotEarn <= 15625) {
   $TAX = round($TotEarn - 11042);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 11042 AND $TotEarn <= 15625) {
   $TAX = round($TotEarn - 11042);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 3 AND $TotEarn >= 15625 AND $TotEarn <= 26042) {
   $TAX = round($TotEarn - 15625);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 3 AND $TotEarn >= 15625 AND $TotEarn <= 26042) {
   $TAX = round($TotEarn - 15625);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 0 AND $TotEarn <= 6250) {
   $TAX = round($TotEarn * .05);
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 0 AND $TotEarn <= 6250) {
   $TAX = round($TotEarn * .05);
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 6250 AND $TotEarn <= 6667) {
   $TAX = round($TotEarn - 6250);
   $TAX = round(20.83 + ($TAX * .10));
}  
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 6250 AND $TotEarn <= 6667) {
   $TAX = round($TotEarn - 6250);
   $TAX = round(20.83 + ($TAX * .10));
} 
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 6667 AND $TotEarn <= 7500) {
  $TAX = round($TotEarn - 6667);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 6667 AND $TotEarn <= 7500) {
  $TAX = round($TotEarn - 6667);
  $TAX = round(104.17 + ($TAX * .15));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 7500 AND $TotEarn <= 9167) {
   $TAX = round($TotEarn - 7500);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 7500 AND $TotEarn <= 9167) {
   $TAX = round($TotEarn - 7500);
   $TAX = round(354.17 + ($TAX * .20));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 9167 AND $TotEarn <= 12083) {
   $TAX = round($TotEarn - 9167);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 9167 AND $TotEarn <= 12083) {
   $TAX = round($TotEarn - 9167);
   $TAX = round(937.50 + ($TAX * .25));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 12083 AND $TotEarn <= 16667) {
   $TAX = round($TotEarn - 12083);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 12083 AND $TotEarn <= 16667) {
   $TAX = round($TotEarn - 12083);
   $TAX = round(2083.33 + ($TAX * .30));
}
elseif($W4_STATUS == 1 AND $DEPENDENTS == 4 AND $TotEarn >= 16667 AND $TotEarn <= 27083) {
   $TAX = round($TotEarn - 16667);
   $TAX = round(5208.83 + ($TAX * .32));
}
elseif($W4_STATUS == 2 AND $DEPENDENTS == 4 AND $TotEarn >= 16667 AND $TotEarn <= 27083) {
   $TAX = round($TotEarn - 16667);
   $TAX = round(5208.83 + ($TAX * .32));
}

else{
    $TAX = round(0);
}

$smarty->assign('TAX', $TAX);

########DISPLAY SSS Loan Deduction##########

 $sql = "SELECT s.EMP_NO, s.SSSAmor FROM $PAYROLL.sssloan s, $ADODB_DB.employment em WHERE em.EMP_NO = s.EMP_NO AND em.EMP_ID = '$currentEmpID'";
 $RsDed = $conn2->Execute($sql);
 
 $SSSAmor = round($RsDed->fields['SSSAmor']);
 
//==========DISPLAY HDMF Loan Deduction===============

$sql = "SELECT h.EMP_NO, h.HDMFAmor FROM $PAYROLL.hdmfloan h, $ADODB_DB.employment em WHERE em.EMP_NO = h.EMP_NO AND em.EMP_ID = '$currentEmpID'"; 
 $RsHDMF = $conn2->Execute($sql);
 
 $HDMFAmor = round($RsHDMF->fields['HDMFAmor']);
 
 //============DISPLAY Trust Fund Loan Deduction=================
 
$sql = "SELECT u.EMP_NO, u.UDTAmor FROM $PAYROLL.udtloan u, $ADODB_DB.employment em WHERE em.EMP_NO = u.EMP_NO AND em.EMP_ID = '$currentEmpID'";
 $RsUDT = $conn2->Execute($sql);
 
 $UDTAmor = round($RsUDT->fields['UDTAmor']);

$TotalDed = $_POST['TotalDed'];

///===============other deductions========
 $BurialSep = $_POST["BurialSep"];
 $TaxAjt = $_POST["TaxAjt"];
 $CashAdvance = $_POST["CashAdvance"];
 $AdvancesShirt = $_POST["AdvancesShirt"];
 $AdvancesMed = $_POST["AdvancesMed"];
 $AdvancesOthers = $_POST["AdvancesOthers"];

 $sql = "SELECT o.EMP_NO, o.BurialSeparationCont, o.TaxAjt, o.CashAdvance, o.AdvanceShirt, o.AdvanceMed, o.AdvanceOther FROM $PAYROLL.other_deductions o, $ADODB_DB.personal p, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID' AND em.EMP_NO = o.EMP_NO";
 $rsOtherDed = $conn2->Execute($sql);
 
 $BurialSep = round($rsOtherDed->fields['BurialSeparationCont']);
 $TaxAjt = round($rsOtherDed->fields['TaxAjt']);
 $CashAdvance = round($rsOtherDed->fields['CashAdvance']);
 $AdvancesShirt = round($rsOtherDed->fields['AdvanceShirt']);
 $AdvancesMed = round($rsOtherDed->fields['AdvanceMed']);
 $AdvancesOthers = round($rsOtherDed->fields['AdvanceOther']);
 
 $smarty->assign('BurialSep', $BurialSep);
 $smarty->assign('TaxAjt', $TaxAjt);
 $smarty->assign('CashAdvance', $CashAdvance);
 $smarty->assign('AdvancesShirt', $AdvancesShirt);
 $smarty->assign('AdvancesMed', $AdvancesMed);
 $smarty->assign('AdvancesOthers', $AdvancesOthers);
 

$TotalDed = round(($SSS + $HDMF + $PCHL + $TAX + $SSSAmor + $HDMFAmor + $UDTAmor + $BurialSep + $TaxAjt + $CashAdvance + $AdvancesShirt + $AdvancesMed + $AdvancesOthers), 2); 

 $smarty->assign('SSSAmor', $SSSAmor);
 $smarty->assign('HDMFAmor', $HDMFAmor);
 $smarty->assign('UDTAmor', $UDTAmor);
 $smarty->assign('TotalDed', $TotalDed);
 
##############Total Earns##############
$THP = $_POST["TakeHomePay"];

$THP = round($TotEarn - $TotalDed, 2);

$smarty->assign('THP', $THP);


//==============Save Other Earnings============//
 
 $sql = "SELECT EMP_NO, OTReg_Amt, SunReg_Amt, OTSun_Amt, HolReg_Amt, HolRegOT_Amt, HolLeave_Amt, NP_Amt, Meal_Amt, Cola_Amt FROM other_earnings WHERE EMP_NO = '$empno'";
 $RsOtherEarnings = $conn2->Execute($sql);
 
 $numrowsOtherEarnings = $RsOtherEarnings->RecordCount();
 
 if($numrowsOtherEarnings > 0){ 
 
 $saverec['EMP_NO'] = $empno;
 $saverec['OTReg_Amt'] = $OTReg_Amt;
 $saverec['SunReg_Amt'] = $SunReg_Amt;
 $saverec['OTSun_Amt'] = $OTSun_Amt;
 $saverec['HolReg_Amt'] = $HolReg_Amt;
 $saverec['HolRegOT_Amt'] = $HolRegOT_Amt;
 $saverec['HolLeave_Amt'] = $HolLeaveAmt;
 $saverec['NP_Amt'] = $NP_Amt;
 $saverec['Meal_Amt'] = $Meal_Amt;
 $saverec['Cola_Amt'] = $Cola_Amt;
 
  $updateOtherEarnings = $conn2->GetUpdateSQL($RsOtherEarnings, $saverec); 
  $conn2->Execute($updateOtherEarnings); 
 }
 else{
 $sql = "SELECT o.EMP_NO, o.OTReg_Amt, o.SunReg_Amt, o.OTSun_Amt, o.HolReg_Amt, o.HolRegOT_Amt, o.HolLeave_Amt, o.NP_Amt, o.Meal_Amt, o.Cola_Amt FROM $PAYROLL.other_earnings o, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
 $RsOtherEarnings = $conn2->Execute($sql);
 
$saverec['EMP_NO'] = $empno;
 $saverec['OTReg_Amt'] = $OTReg_Amt;
 $saverec['SunReg_Amt'] = $SunReg_Amt;
 $saverec['OTSun_Amt'] = $OTSun_Amt;
 $saverec['HolReg_Amt'] = $HolReg_Amt;
 $saverec['HolRegOT_Amt'] = $HolRegOT_Amt;
 $saverec['HolLeave_Amt'] = $HolLeaveAmt;
 $saverec['NP_Amt'] = $NP_Amt;
 $saverec['Meal_Amt'] = $Meal_Amt;
 $saverec['Cola_Amt'] = $Cola_Amt;
 
  $insertOtherEarnings = $conn2->GetInsertSQL($RsOtherEarnings, $saverec); 
  $conn2->Execute($insertOtherEarnings); 
 }

//=================Save Deductions=============
 
 $sql = "SELECT EMP_NO, SSS, TAX, PCHL, HDMF FROM deductions WHERE EMP_NO = '$empno'";
 $RsDeduction = $conn2->Execute($sql);
 
 $numrowsDeduction = $RsDeduction->RecordCount(); 
 
 if($numrowsDeduction > 0){
 $saverec['EMP_NO'] = $empno;
 $saverec['SSS'] = $SSS;
 $saverec['TAX'] = $TAX;
 $saverec['PCHL'] = $PCHL;
 $saverec['HDMF'] = $HDMF;
 
 
 $updateDeductionSQL = $conn2->GetUpdateSQL($RsDeduction, $saverec); 
 $conn2->Execute($updateDeductionSQL); 
 }
 else{
  $sql = "SELECT d.EMP_NO, d.SSS, d.TAX, d.PCHL, d.HDMF FROM $PAYROLL.deductions d, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
 $RsDeduction = $conn2->Execute($sql);
 
 $saverec['EMP_NO'] = $empno;
 $saverec['SSS'] = $SSS;
 $saverec['TAX'] = $TAX;  
 $saverec['PCHL'] = $PCHL;
 $saverec['HDMF'] = $HDMF;
 
 $insertSQL = $conn2->GetInsertSQL($RsDeduction, $saverec); 
 $conn2->Execute($insertSQL); 
 }
 
  //================SAVE LOAN============
 
 $sql = "SELECT EMP_NO, SSSLoan, HDMFLoan, UDTLoan FROM loan_deductions WHERE EMP_NO = '$empno'";
 $RsLoan = $conn2->Execute($sql);
 
 $numrowsRsLoan = $RsLoan->RecordCount();
 
 if($numrowsRsLoan > 0){
 $saverec['EMP_NO'] = $empno;
 $saverec['SSSLoan'] = $SSSAmor;
 $saverec['HDMFLoan'] = $HDMFLoan;
 $saverec['UDTLoan'] = $UDTAmor;
 
 $updateLoanSQL = $conn2->GetUpdateSQL($RsLoan, $saverec); 
 $conn2->Execute($updateLoanSQL); 
 }
 else{
 
 $sql = "SELECT l.EMP_NO, l.SSSLoan, l.HDMFLoan, l.UDTLoan FROM $PAYROLL.loan_deductions l, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
 $RsLoan = $conn2->Execute($sql);
 
 $saverec['EMP_NO'] = $empno;
 $saverec['SSSLoan'] = $SSSAmor;
 $saverec['HDMFLoan'] = $HDMFLoan;
 $saverec['UDTLoan'] = $Fund;
 
 $insertSQL = $conn2->GetInsertSQL($RsLoan, $saverec); 
 $conn2->Execute($insertSQL); 
 }
     
$smarty->display('header.tpl');
$smarty->display('left.tpl');
$smarty->display('empPayrollData.tpl');
$smarty->display('footer.tpl'); 

?>


In my new code the data from Other Earnings, Deductions, Loans was now save in the database when I click their names.

Now I only have a problem in other deductions because it was a insertable fields and everytime I add other deductions the TotalDeductions will also change and the Take Home Pay…

I will try to find the solution also like what I did from other data that i need to save
Thank you so much…

I also add this code for saving Basic Pay, Total Earnings, Total Deductions, and Take Home Pay…


 //==================Save Total Pay=================
   $sql = "SELECT EMP_NO, Amount, TotalEarnings, TotalDeductions, TakeHomePay FROM totalpay WHERE EMP_NO = '$empno'";
  $rsTotal = $conn2->Execute($sql);
  
  $numrows = $rsTotal->RecordCount();
  
  if($numrows > 0){
  
  $saverec['EMP_NO'] = $empno;
  $saverec['Amount'] = $Amount; //Basic pay
  $saverec['TotalEarnings'] = $TotEarn; // Total Earnings
  $saverec['TotalDeductions'] = $TotalDed; //Total Deductions
  $saverec['TakeHomePay'] = $THP; //Take Home pay
  
  $updateSQL = $conn2->GetUpdateSQL($rsTotal, $saverec); 
  $conn2->Execute($updateSQL);  
  }
  else{ 
  $sql = "SELECT t.EMP_NO, t.Amount, t.TotalEarnings, t.TotalDeductions, t.TakeHomePay FROM $PAYROLL.totalpay t, $ADODB_DB.employment em WHERE em.EMP_ID = '$currentEmpID'";
  $rsTotal = $conn2->Execute($sql);
  
  $saverec['EMP_NO'] = $empno;
  $saverec['Amount'] = $Amount;  
  $saverec['TotalEarnings'] = $TotEarn;
  $saverec['TotalDeductions'] = $TotalDed;
  $saverec['TakeHomePay'] = $THP;
  
  $insertSQL = $conn2->GetInsertSQL($rsTotal, $saverec); 
  $conn2->Execute($insertSQL);  
  }

And as ive said in my previous post i have problem in updating totaldeductions and takehomepay because of other deductions…

Thank you so much…