function getAccrualBalance($accrual_policy_id, $user_id) { if ($accrual_policy_id == '') { return FALSE; } if ($user_id == '') { return FALSE; } $ablf = new AccrualBalanceListFactory(); $ablf->getByUserIdAndAccrualPolicyId($user_id, $accrual_policy_id); if ($ablf->getRecordCount() > 0) { $accrual_balance = $ablf->getCurrent()->getBalance(); } else { $accrual_balance = 0; } return TTDate::getTimeUnit($accrual_balance); }
function getCurrentAccrualBalance($user_id, $accrual_policy_id = NULL) { if ($user_id == '') { return FALSE; } if ($accrual_policy_id == '') { $accrual_policy_id = $this->getId(); } //Check min/max times of accrual policy. $ablf = new AccrualBalanceListFactory(); $ablf->getByUserIdAndAccrualPolicyId($user_id, $accrual_policy_id); if ($ablf->getRecordCount() > 0) { $accrual_balance = $ablf->getCurrent()->getBalance(); } else { $accrual_balance = 0; } Debug::Text(' Current Accrual Balance: ' . $accrual_balance, __FILE__, __LINE__, __METHOD__, 10); return $accrual_balance; }
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; }