TimeTrex/unit_tests/testcases/payroll_deduction/USPayrollDeductionTest2011.php

427 lines
15 KiB
PHP

<?php /** @noinspection PhpMissingDocCommentInspection */
/*********************************************************************************
*
* TimeTrex is a Workforce Management program developed by
* TimeTrex Software Inc. Copyright (C) 2003 - 2021 TimeTrex Software Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY TIMETREX, TIMETREX DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
*
* You should have received a copy of the GNU Affero General Public License along
* with this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
*
* You can contact TimeTrex headquarters at Unit 22 - 2475 Dobbin Rd. Suite
* #292 West Kelowna, BC V4T 2E9, Canada or at email address info@timetrex.com.
*
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by TimeTrex" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by TimeTrex".
*
********************************************************************************/
/**
* @group USPayrollDeductionTest2011
*/
class USPayrollDeductionTest2011 extends PHPUnit\Framework\TestCase {
public $company_id = null;
public function setUp(): void {
Debug::text( 'Running setUp(): ', __FILE__, __LINE__, __METHOD__, 10 );
require_once( Environment::getBasePath() . '/classes/payroll_deduction/PayrollDeduction.class.php' );
$this->tax_table_file = dirname( __FILE__ ) . '/USPayrollDeductionTest2011.csv';
$this->company_id = PRIMARY_COMPANY_ID;
TTDate::setTimeZone( 'Etc/GMT+8' ); //Force to non-DST timezone. 'PST' isnt actually valid.
}
public function tearDown(): void {
Debug::text( 'Running tearDown(): ', __FILE__, __LINE__, __METHOD__, 10 );
}
public function mf( $amount ) {
return Misc::MoneyRound( $amount );
}
public function MatchWithinMarginOfError( $source, $destination, $error = 0 ) {
//Source: 125.01
//Destination: 125.00
//Source: 124.99
$high_water_mark = bcadd( $destination, $error );
$low_water_mark = bcsub( $destination, $error );
if ( $source <= $high_water_mark && $source >= $low_water_mark ) {
return $destination;
}
return $source;
}
//
// January 2011
//
function testCSVFile() {
$this->assertEquals( true, file_exists( $this->tax_table_file ) );
$test_rows = Misc::parseCSV( $this->tax_table_file, true );
$total_rows = ( count( $test_rows ) + 1 );
$i = 2;
foreach ( $test_rows as $row ) {
//Debug::text('Province: '. $row['province'] .' Income: '. $row['gross_income'], __FILE__, __LINE__, __METHOD__,10);
if ( $row['gross_income'] == '' && isset( $row['low_income'] ) && $row['low_income'] != '' && isset( $row['high_income'] ) && $row['high_income'] != '' ) {
$row['gross_income'] = ( $row['low_income'] + ( ( $row['high_income'] - $row['low_income'] ) / 2 ) );
}
if ( $row['country'] != '' && $row['gross_income'] != '' ) {
//echo $i.'/'.$total_rows.'. Testing Province: '. $row['province'] .' Income: '. $row['gross_income'] ."\n";
$pd_obj = new PayrollDeduction( $row['country'], $row['province'] );
$pd_obj->setDate( strtotime( $row['date'] ) );
$pd_obj->setAnnualPayPeriods( $row['pay_periods'] );
$pd_obj->setFederalFilingStatus( $row['filing_status'] );
$pd_obj->setFederalAllowance( $row['allowance'] );
$pd_obj->setStateFilingStatus( $row['filing_status'] );
$pd_obj->setStateAllowance( $row['allowance'] );
//Some states use other values for allowance/deductions.
switch ( $row['province'] ) {
case 'GA':
Debug::text( 'Setting UserValue3: ' . $row['allowance'], __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj->setUserValue3( $row['allowance'] );
break;
case 'IN':
case 'VA':
Debug::text( 'Setting UserValue1: ' . $row['allowance'], __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj->setUserValue1( $row['allowance'] );
break;
}
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( $this->mf( $row['gross_income'] ) );
//var_dump($pd_obj->getArray());
$this->assertEquals( $this->mf( $pd_obj->getGrossPayPeriodIncome() ), $this->mf( $row['gross_income'] ) );
if ( $row['federal_deduction'] != '' ) {
$this->assertEquals( $this->mf( $pd_obj->getFederalPayPeriodDeductions() ), $this->MatchWithinMarginOfError( $this->mf( $row['federal_deduction'] ), $this->mf( $pd_obj->getFederalPayPeriodDeductions() ), 0.01 ) );
}
if ( $row['provincial_deduction'] != '' ) {
$this->assertEquals( $this->mf( $pd_obj->getStatePayPeriodDeductions() ), $this->mf( $row['provincial_deduction'] ) );
}
}
$i++;
}
//Make sure all rows are tested.
$this->assertEquals( $total_rows, ( $i - 1 ) );
}
//
// US Social Security
//
function testUS_2011a_SocialSecurity() {
Debug::text( 'US - SemiMonthly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MO' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 24 ); //Semi-Monthly
$pd_obj->setFederalFilingStatus( 10 ); //Single
$pd_obj->setFederalAllowance( 0 );
$pd_obj->setYearToDateSocialSecurityContribution( 0 );
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 1000.00 );
$this->assertEquals( '1000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '42.00', $this->mf( $pd_obj->getEmployeeSocialSecurity() ) );
}
function testUS_2011a_SocialSecurity_Max() {
Debug::text( 'US - SemiMonthly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MO' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 24 ); //Semi-Monthly
$pd_obj->setFederalFilingStatus( 10 ); //Single
$pd_obj->setFederalAllowance( 0 );
$pd_obj->setYearToDateSocialSecurityContribution( 4484.60 ); //4485.60
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 1000.00 );
$this->assertEquals( '1000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '1.00', $this->mf( $pd_obj->getEmployeeSocialSecurity() ) );
}
function testUS_2011a_Medicare() {
Debug::text( 'US - SemiMonthly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MO' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 24 ); //Semi-Monthly
$pd_obj->setFederalFilingStatus( 10 ); //Single
$pd_obj->setFederalAllowance( 0 );
$pd_obj->setYearToDateSocialSecurityContribution( 0 );
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 1000.00 );
//var_dump($pd_obj->getArray());
$this->assertEquals( '1000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '14.50', $this->mf( $pd_obj->getEmployeeMedicare() ) );
$this->assertEquals( '14.50', $this->mf( $pd_obj->getEmployerMedicare() ) );
}
function testUS_2011a_FederalUI_NoState() {
Debug::text( 'US - SemiMonthly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MO' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 24 ); //Semi-Monthly
$pd_obj->setFederalFilingStatus( 10 ); //Single
$pd_obj->setFederalAllowance( 0 );
$pd_obj->setFederalUIRate( 6.2 );
$pd_obj->setYearToDateSocialSecurityContribution( 0 );
$pd_obj->setYearToDateFederalUIContribution( 0 );
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 1000.00 );
//var_dump($pd_obj->getArray());
$this->assertEquals( '1000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '62.00', $this->mf( $pd_obj->getFederalEmployerUI() ) );
}
function testUS_2011a_FederalUI_NoState_Max() {
Debug::text( 'US - SemiMonthly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MO' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 24 ); //Semi-Monthly
$pd_obj->setFederalFilingStatus( 10 ); //Single
$pd_obj->setFederalAllowance( 0 );
$pd_obj->setFederalUIRate( 6.2 );
$pd_obj->setStateUIRate( 0 );
$pd_obj->setStateUIWageBase( 0 );
$pd_obj->setYearToDateSocialSecurityContribution( 0 );
$pd_obj->setYearToDateFederalUIContribution( 433 ); //434
$pd_obj->setYearToDateStateUIContribution( 0 );
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 1000.00 );
//var_dump($pd_obj->getArray());
$this->assertEquals( '1000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '1.00', $this->mf( $pd_obj->getFederalEmployerUI() ) );
}
function testUS_2011a_FederalUI_State_Max() {
Debug::text( 'US - SemiMonthly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MO' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 24 ); //Semi-Monthly
$pd_obj->setFederalFilingStatus( 10 ); //Single
$pd_obj->setFederalAllowance( 0 );
$pd_obj->setFederalUIRate( 6.2 );
$pd_obj->setStateUIRate( 3.51 );
$pd_obj->setStateUIWageBase( 11000 );
$pd_obj->setYearToDateSocialSecurityContribution( 0 );
$pd_obj->setYearToDateFederalUIContribution( 433 ); //434
$pd_obj->setYearToDateStateUIContribution( 0 );
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 1000.00 );
//var_dump($pd_obj->getArray());
$this->assertEquals( '1000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '1.00', $this->mf( $pd_obj->getFederalEmployerUI() ) );
}
//
// MD
//
function testMD_2011a_BiWeekly_Single_LowIncome() {
Debug::text( 'US - BiWeekly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MD', 'ALL' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 26 ); //Bi-Weekly
$pd_obj->setFederalFilingStatus( 10 ); //Single
$pd_obj->setFederalAllowance( 0 );
$pd_obj->setStateFilingStatus( 10 ); //Single
$pd_obj->setStateAllowance( 0 );
$pd_obj->setUserValue3( 1.25 ); //County Rate
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 1000.00 );
$this->assertEquals( '1000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '121.54', $this->mf( $pd_obj->getFederalPayPeriodDeductions() ) );
$this->assertEquals( '55.38', $this->mf( $pd_obj->getStatePayPeriodDeductions() ) );
}
function testMD_2011a_BiWeekly_Married_LowIncome() {
Debug::text( 'US - BiWeekly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MD', 'ALL' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 26 ); //Bi-Weekly
$pd_obj->setFederalFilingStatus( 20 ); //Single
$pd_obj->setFederalAllowance( 1 );
$pd_obj->setStateFilingStatus( 20 ); //Single
$pd_obj->setStateAllowance( 1 );
$pd_obj->setUserValue3( 1.25 ); //County Rate
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 1000.00 );
$this->assertEquals( '1000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '55.38', $this->mf( $pd_obj->getFederalPayPeriodDeductions() ) );
$this->assertEquals( '48.00', $this->mf( $pd_obj->getStatePayPeriodDeductions() ) );
}
function testMD_2011a_BiWeekly_Married_HighIncome() {
Debug::text( 'US - BiWeekly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MD', 'ALL' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 26 ); //Bi-Weekly
$pd_obj->setFederalFilingStatus( 20 ); //Single
$pd_obj->setFederalAllowance( 2 );
$pd_obj->setStateFilingStatus( 20 ); //Single
$pd_obj->setStateAllowance( 2 );
$pd_obj->setUserValue3( 1.25 ); //County Rate
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 5000.00 );
$this->assertEquals( '5000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '804.81', $this->mf( $pd_obj->getFederalPayPeriodDeductions() ) );
$this->assertEquals( '280.62', $this->mf( $pd_obj->getStatePayPeriodDeductions() ) );
}
function testMD_2011b_BiWeekly_Married_HighIncome() {
Debug::text( 'US - BiWeekly - Beginning of 2011 01-Jan-2011: ', __FILE__, __LINE__, __METHOD__, 10 );
$pd_obj = new PayrollDeduction( 'US', 'MD', 'ALL' );
$pd_obj->setDate( strtotime( '01-Jan-2011' ) );
$pd_obj->setAnnualPayPeriods( 26 ); //Bi-Weekly
$pd_obj->setFederalFilingStatus( 20 ); //Single
$pd_obj->setFederalAllowance( 2 );
$pd_obj->setStateFilingStatus( 20 ); //Single
$pd_obj->setStateAllowance( 2 );
$pd_obj->setUserValue3( 3.20 ); //County Rate
$pd_obj->setFederalTaxExempt( false );
$pd_obj->setProvincialTaxExempt( false );
$pd_obj->setGrossPayPeriodIncome( 5000.00 );
$this->assertEquals( '5000.00', $this->mf( $pd_obj->getGrossPayPeriodIncome() ) );
$this->assertEquals( '804.81', $this->mf( $pd_obj->getFederalPayPeriodDeductions() ) );
$this->assertEquals( '371.82', $this->mf( $pd_obj->getStatePayPeriodDeductions() ) );
}
/*
function testNY_2011_BiWeekly_MedIncome() {
Debug::text('US - BiWeekly - Beginning of 2011 01-Jan-11: ', __FILE__, __LINE__, __METHOD__,10);
$pd_obj = new PayrollDeduction('US','NY');
$pd_obj->setDate(strtotime('01-Jan-11'));
$pd_obj->setAnnualPayPeriods( 26 ); //Bi-Weekly
$pd_obj->setFederalFilingStatus( 10 ); //Single
$pd_obj->setFederalAllowance( 0 );
$pd_obj->setStateAllowance( 0 );
$pd_obj->setFederalTaxExempt( FALSE );
$pd_obj->setProvincialTaxExempt( FALSE );
$pd_obj->setGrossPayPeriodIncome( 500.00 );
//var_dump($pd_obj->getArray());
$this->assertEquals( $this->mf( $pd_obj->getGrossPayPeriodIncome() ), '500.00' );
$this->assertEquals( $this->mf( $pd_obj->getStatePayPeriodDeductions() ), '8.65' );
}
*/
}
?>