getAll(); if ( $clf->getRecordCount() > 0 ) { foreach ( $clf as $c_obj ) { if ( isset( $company_id ) && $company_id != '' && $company_id != $c_obj->getId() ) { continue; } //if ( !in_array( $c_obj->getID(), array(1310,1347) ) ) { // continue; //} if ( $c_obj->getStatus() != 30 ) { $clf->StartTransaction(); Debug::text( 'Company: ' . $c_obj->getName() . ' ID: ' . $c_obj->getID(), __FILE__, __LINE__, __METHOD__, 10 ); echo "\n\n".'Company: ' . $c_obj->getName() . ' ID: ' . $c_obj->getID() . "\n"; //Get Pay Stub Entry Account ID for Net Pay. $pseallf = TTnew( 'PayStubEntryAccountLinkListFactory' ); /** @var PayStubEntryAccountLinkListFactory $pseallf */ $pseallf->getByCompanyId( $c_obj->getId() ); if ( $pseallf->getRecordCount() > 0 ) { $pay_stub_entry_account_link_obj = $pseallf->getCurrent(); $net_pay_ps_account_id = $pay_stub_entry_account_link_obj->getTotalNetPay(); Debug::text( ' Net Pay PS Account ID: '. $net_pay_ps_account_id, __FILE__, __LINE__, __METHOD__, 10 ); $ulf = TTnew('UserListFactory'); /** @var UserListFactory $ulf */ $ulf->getByCompanyId( $c_obj->getId() ); if ( $ulf->getRecordCount() > 0 ) { foreach( $ulf as $u_obj ) { //if ( $u_obj->getId() != '05a2b435-5a46-cb8f-1c14-6b2027c3ea62' ) { // continue; //} Debug::text( ' User: ' . $u_obj->getFullName() . ' ID: ' . $u_obj->getID(), __FILE__, __LINE__, __METHOD__, 10 ); //echo ' User: ' . $u_obj->getFullName() . ' ID: ' . $u_obj->getID() . "\n"; echo '.'; $pself = TTnew( 'PayStubEntryListFactory' ); /** @var PayStubEntryListFactory $pself */ $pay_stub_entry_arr = $pself->getYTDAmountSumByUserIdAndEntryNameIdAndDate( $u_obj->getID(), $net_pay_ps_account_id, $filter_end_date ); //Must use end-date, as it will automatically go to the start date of the year. if ( $pay_stub_entry_arr['amount'] == $pay_stub_entry_arr['ytd_amount'] ) { Debug::text( ' Net Pay YTD in-sync: YTD: ' . $pay_stub_entry_arr['ytd_amount'] . ' Actual (sum): ' . $pay_stub_entry_arr['amount'], __FILE__, __LINE__, __METHOD__, 10 ); //echo "\n".' Net Pay YTD in-sync: YTD: ' . $pay_stub_entry_arr['ytd_amount'] . ' Actual (sum): ' . $pay_stub_entry_arr['amount'] . "\n"; } else { Debug::text( ' Net Pay YTD out-of-sync: YTD: ' . $pay_stub_entry_arr['ytd_amount'] . ' Actual (sum): ' . $pay_stub_entry_arr['amount'], __FILE__, __LINE__, __METHOD__, 10 ); echo "\n"; echo ' User: ' . $u_obj->getFullName() . ' ID: ' . $u_obj->getID() . "\n"; echo ' **Recalculating Net Pay YTD out-of-sync: YTD: ' . $pay_stub_entry_arr['ytd_amount'] . ' Actual (sum): ' . $pay_stub_entry_arr['amount'] . "\n"; //Get first pay stub of the year, then trigger a recalculate on it. $psf = TTnew('PayStubFactory'); $psf->setUser( $u_obj->getID() ); $psf->setTransactionDate( $filter_start_date ); $psf->setRun( 1 ); $psf->recalculateYTD(); $pay_stub_entry_arr = $pself->getYTDAmountSumByUserIdAndEntryNameIdAndDate( $u_obj->getID(), $net_pay_ps_account_id, $filter_end_date ); //Must use end-date, as it will automatically go to the start date of the year. if ( $pay_stub_entry_arr['amount'] == $pay_stub_entry_arr['ytd_amount'] ) { Debug::text( ' Net Pay YTD in-sync: YTD: ' . $pay_stub_entry_arr['ytd_amount'] . ' Actual (sum): ' . $pay_stub_entry_arr['amount'], __FILE__, __LINE__, __METHOD__, 10 ); echo ' Net Pay YTD in-sync: YTD: ' . $pay_stub_entry_arr['ytd_amount'] . ' Actual (sum): ' . $pay_stub_entry_arr['amount'] . "\n"; } else { Debug::text( ' ERROR: Net Pay YTD still out-of-sync: YTD: ' . $pay_stub_entry_arr['ytd_amount'] . ' Actual (sum): ' . $pay_stub_entry_arr['amount'], __FILE__, __LINE__, __METHOD__, 10 ); echo ' ERROR: Net Pay YTD still out-of-sync: YTD: ' . $pay_stub_entry_arr['ytd_amount'] . ' Actual (sum): ' . $pay_stub_entry_arr['amount'] . "\n"; $total_recalculated_users_errors++; } $total_recalculated_users++; } $total_users++; } } } if ( $dry_run == true ) { $clf->FailTransaction(); } $clf->CommitTransaction(); } } } echo "\n"; echo "Users: Checked: ". $total_users ." Recalculated: ". $total_recalculated_users ." Errors: ". $total_recalculated_users_errors ."\n"; } echo "Done...\n"; Debug::WriteToLog(); Debug::Display(); ?>