예제 #1
0
switch ($action) {
    case 'recalculate_company':
    case 'recalculate_employee':
        Debug::text('Recalculating Employee Timesheet: User ID: ' . $filter_user_id . ' Pay Period ID: ' . $pay_period_ids, __FILE__, __LINE__, __METHOD__, 10);
        //Debug::setVerbosity(11);
        //Make sure pay period is not CLOSED.
        //We can re-calc on locked though.
        $pplf = new PayPeriodListFactory();
        $pplf->getById($pay_period_ids);
        if ($pplf->getRecordCount() > 0) {
            $pp_obj = $pplf->getCurrent();
            if ($pp_obj->getStatus() != 20) {
                $udlf = new UserDateListFactory();
                if ($action == 'recalculate_company') {
                    TTLog::addEntry($current_company->getId(), TTi18n::gettext('Notice'), TTi18n::gettext(' Recalculating Company TimeSheet'), $current_user->getId(), 'user_date_total');
                    $udlf->getByCompanyIdAndPayPeriodID($current_company->getId(), $pay_period_ids);
                } else {
                    TTLog::addEntry($filter_user_id, TTi18n::gettext('Notice'), TTi18n::gettext(' Recalculating Employee TimeSheet'), $current_user->getId(), 'user_date_total');
                    $udlf->getByUserIdAndPayPeriodID($filter_user_id, $pay_period_ids);
                }
                if ($udlf->getRecordCount() > 0) {
                    InitProgressBar();
                    $progress_bar->setValue(0);
                    $progress_bar->display();
                    Debug::text('Found days to re-calculate: ' . $udlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                    $udlf->StartTransaction();
                    $x = 1;
                    foreach ($udlf as $ud_obj) {
                        //Debug::text($x .' / '. $udlf->getRecordCount() .' - User Date Id: '. $ud_obj->getId() .' Date: '.$ud_obj->getDateStamp(TRUE) .' User ID: '. $ud_obj->getUser() , __FILE__, __LINE__, __METHOD__, 10);
                        UserDateTotalFactory::reCalculateDay($ud_obj->getId(), TRUE);
                        $progress_bar->setValue(Misc::calculatePercent($x, $udlf->getRecordCount()));