$alf->StartTransaction(); if (is_array($ids)) { foreach ($ids as $id) { $alf->getById($id); foreach ($alf as $a_obj) { //Allow user to delete AccrualPolicy entries, but not Banked/Used entries. if ($a_obj->getUserDateTotalID() == FALSE) { $a_obj->setEnableCalcBalance(FALSE); $a_obj->setDeleted($delete); if ($a_obj->isValid()) { $a_obj->Save(); } } } } AccrualBalanceFactory::calcBalance($user_id, $accrual_policy_id); } $alf->CommitTransaction(); Redirect::Page(URLBuilder::getURL(NULL, 'ViewUserAccrualList.php')); break; default: $alf = TTnew('AccrualListFactory'); $alf->getByCompanyIdAndUserIdAndAccrualPolicyID($current_company->getId(), $user_id, $accrual_policy_id, $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array); $pager = new Pager($alf); foreach ($alf as $a_obj) { $date_stamp = $a_obj->getColumn('date_stamp'); if ($date_stamp != '') { $date_stamp = TTDate::strtotime($date_stamp); } $accruals[] = array('id' => $a_obj->getId(), 'user_id' => $a_obj->getUser(), 'accrual_policy_id' => $a_obj->getAccrualPolicyId(), 'type_id' => $a_obj->getType(), 'type' => Option::getByKey($a_obj->getType(), $a_obj->getOptions('type')), 'user_date_total_id' => $a_obj->getUserDateTotalId(), 'user_date_total_date_stamp' => $date_stamp, 'time_stamp' => $a_obj->getTimeStamp(), 'amount' => $a_obj->getAmount(), 'system_type' => $a_obj->isSystemType(), 'deleted' => $a_obj->getDeleted()); }
* $Id: fix_client_balance.php 1246 2007-09-14 23:47:42Z ipso $ * $Date: 2007-09-14 16:47:42 -0700 (Fri, 14 Sep 2007) $ */ require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'global.inc.php'; require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'CLI.inc.php'; if ($argc < 2 or in_array($argv[1], array('--help', '-help', '-h', '-?'))) { $help_output = "Usage: fix_accrual_balance.php [company_id]\n"; echo $help_output; } else { $company_id = $argv[1]; if ($company_id != '') { $ablf = new AccrualBalanceListFactory(); $ablf->getByCompanyId($company_id); $ablf->StartTransaction(); $alf = new AccrualListFactory(); foreach ($ablf as $ab_obj) { $alf->getOrphansByUserId($ab_obj->getUser()); if ($alf->getRecordCount() > 0) { foreach ($alf as $a_obj) { Debug::text('Orphan Record ID: ' . $a_obj->getID(), __FILE__, __LINE__, __METHOD__, 10); $a_obj->Delete(); } } AccrualBalanceFactory::calcBalance($ab_obj->getUser(), $ab_obj->getAccrualPolicyID()); //break; } //$ablf->FailTransaction(); $ablf->CommitTransaction(); } } Debug::Display();
static function deleteOrphans($user_id, $date_stamp) { Debug::text('Attempting to delete Orphaned Records for User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); //Remove orphaned entries $alf = TTnew('AccrualListFactory'); //$alf->getOrphansByUserId( $user_id ); $alf->getOrphansByUserIdAndDate($user_id, $date_stamp); Debug::text('Found Orphaned Records: ' . $alf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($alf->getRecordCount() > 0) { foreach ($alf as $a_obj) { Debug::text('Orphan Record ID: ' . $a_obj->getID(), __FILE__, __LINE__, __METHOD__, 10); $accrual_policy_ids[] = $a_obj->getAccrualPolicyId(); $a_obj->Delete(); } //ReCalc balances if (isset($accrual_policy_ids)) { foreach ($accrual_policy_ids as $accrual_policy_id) { AccrualBalanceFactory::calcBalance($user_id, $accrual_policy_id); } } } return TRUE; }
static function calcBalance($user_id, $accrual_policy_id = NULL) { global $profiler; $profiler->startTimer("AccrualBalanceFactory::calcBalance()"); $alf = new AccrualListFactory(); $balance = $alf->getSumByUserIdAndAccrualPolicyId($user_id, $accrual_policy_id); Debug::text('Balance for User ID: ' . $user_id . ' Accrual Policy ID: ' . $accrual_policy_id . ' Balance: ' . $balance, __FILE__, __LINE__, __METHOD__, 10); $ablf = new AccrualBalanceListFactory(); $ablf->getByUserIdAndAccrualPolicyId($user_id, $accrual_policy_id); Debug::text('Found balance records to delete: ' . $ablf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10); if ($ablf->getRecordCount() > 0) { foreach ($ablf as $ab_obj) { $ab_obj->Delete(); } } Debug::text('Setting new balance to: ' . $balance, __FILE__, __LINE__, __METHOD__, 10); $ab = new AccrualBalanceFactory(); $ab->setUser($user_id); $ab->setAccrualPolicyId($accrual_policy_id); $ab->setBalance($balance); $profiler->stopTimer("AccrualBalanceFactory::calcBalance()"); if ($ab->isValid()) { return $ab->Save(); } Debug::text('Setting new balance failed for User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10); return FALSE; }