?? compute.inc
字號:
<?php
//==================================================================
// compute.inc
// include file for compute.php
//==================================================================
//------------------------------------------------------------------
// $para['GroupCode' ]
// $para['CPF']
// $para['A_or_D']
// $para['Amount']
// $para['AWages' ]
// $para['BasicPay']
// $para['PRIssue']
// $para['BirthDate']
// $para['CPFInd']
// $para['FWLAmount']
//------------------------------------------------------------------
function ComputeSalary( $para )
{
$totO = 0; // overtime
$totA = 0; // allowance
$totD = 0; // deduction
$totM = 0; // misc
$totB = 0; // bonus
if ( $para['GroupCode' ]== 2 ) { // overtime
if ( $para['CPF']=='Y' ) {
if ( $para['A_or_D']=='A' ) $totA += $para['Amount'];
else $totD += $para['Amount'];
}
else {
if ( $para['A_or_D']=='A' ) $totM += $para['Amount'];
else $totM -= $para['Amount'];
}
}
if ( $para['AWages' ]=='Y' ) $totB += $para['Amount'];
// compute gross, net salary and CPF contribution
$gross = $para['BasicPay'] + $totO + $totA - $totD;
$cpf = ComuteCPF( $gross, $totB, $para['PRIssue'], $para['BirthDate'],$para['CPFInd'] );
$netpay = $gross - $cpf['employee'] + $totM;
// compute SDF here
$sdf = 0;
if ( $gross < 1500 ) {
$sdf = $gross * 0.01;
if ( $sdf < 2 ) $sdf = 2;
}
// compute FWL here (if any)
if ( $para['CPFInd']!=2 ) $fwl = 0;
else $fwl = $para['FWLAmount'];
$salary['Basic']=$para['BasicPay'];
$salary['OverTime']=$totO;
$salary['Allowance']=$totA;
$salary['Deduction']=$totD;
$salary['Adjustment']=$totM;
$salary['Wages']=$totB;
$salary['SDF']= $sdf;
$salary['GrossPay']=$gross;
$salary['NettPay']=$netpay;
$salary['EmployeeCPF']=$cpf['employee'];
$salary['EmployerCPF']=$cpf['employer'];
$salary['FWL']=0;
return $salary;
}
//------------------------------------------------------------------
// $pr_issue_date, $birthdate :- yyyy-mm-dd format
// $cpf_ind :- 1=CPF, 2=FWL
//------------------------------------------------------------------
function ComputeCPF( $salary, $bonus, $pr_issue_date, $birthdate, $cpf_ind )
{
$cpf['employee'] = 0;
$cpf['employer'] = 0;
if ( $cpf_ind!=1 ) return $cpf; // do not require CPF calculation
$cmonth = date("Y") * 12 + date( "m" );
// (1) use $pr_issue_date to compute $select1
$select1 = 1; // singaporean
$pmonth = substr( $pr_issue_date, 0, 4 ) * 12 + substr( $pr_issue_date, 5, 2 );
$months = $cmonth - $pmonth;
if ( $months <= 12 ) $select1 = 2;
elseif ( $months <= 24 ) $select1 = 3;
// (2) use $birthdate to compute $select2
$bmonth = substr( $birthdate, 0, 4 ) * 12 + substr( $birthdate, 5, 2 );
$years = ($cmonth - $pmonth) / 12;
$select2 = 5;
if ($years <= 50 ) $select2 = 1;
elseif ($years <= 55 ) $select2 = 2;
elseif ($years <= 60 ) $select2 = 3;
elseif ($years <= 65 ) $select2 = 4;
// (3) open the CPF table
$strSQL = "Select * from cpf where select1='$select1' and select2='$select2';";
$cpftable = mysql_query( $strSQL );
if ( ($irow = mysql_fetch_assoc( $cpftable )) == NULL ) return NULL;
$psn = 5;
if ( $salary <= $irow['cpf1_1'] ) $psn = 1;
elseif ( $salary <= $irow['cpf2_1'] ) $psn = 2;
elseif ( $salary <= $irow['cpf3_1'] ) $psn = 3;
elseif ( $salary <= $irow['cpf4_1'] ) $psn = 4;
if ( $psn != 5 ) {
$p = "cpf".$psn;
//$w_con = ( $salary - $constant1 ) / $constant2;
$w_con = ( $salary - $irow["$p_4"] ) / $irow["$p_5"];
if ( $w_con==$salary ) $w_con = 0;
$cpf['employee'] = $salary * ($irow["$p_3"]/100) + $w_con;
$cpf['employer'] = $salary * ($irow["$p_2"]/100) + $w_con + 0.5 - $cpf['employee'];
}
else {
// $irow["cpf4-2"] = Total Rate ; $irow["cpf4-3"] = Employee Rate
$EmployeeBonus = $bonus * ($irow["cpf4_3"]/100);
$EmployerBonus = $bonus * ($irow["cpf4_2"]/100) + 0.5 - $EmployeeBonus;
// $irow["cpf5-2"] = Employer Amount ; $irow["cpf5-3"] = Employee Amount
$cpf['employee'] = $irow["cpf5_3"] + $EmployeeBonus;
$cpf['employer'] = $irow["cpf5_2"]-$irow["cpf5_3"] + $EmployerBonus;
}
return $cpf;
}
?>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -