function postInstall()
 {
     global $cache;
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Get all pay period schedules.
     $ppslf = new PayPeriodScheduleListFactory();
     $ppslf->getAll();
     if ($ppslf->getRecordCount() > 0) {
         foreach ($ppslf as $pps_obj) {
             $user_ids = $pps_obj->getUser();
             if (is_array($user_ids)) {
                 $time_zone_arr = array();
                 foreach ($user_ids as $user_id) {
                     $uplf = new UserPreferenceListFactory();
                     $uplf->getByUserId($user_id);
                     if ($uplf->getRecordCount() > 0) {
                         if (isset($time_zone_arr[$uplf->getCurrent()->getTimeZone()])) {
                             $time_zone_arr[$uplf->getCurrent()->getTimeZone()]++;
                         } else {
                             $time_zone_arr[$uplf->getCurrent()->getTimeZone()] = 1;
                         }
                     }
                 }
                 arsort($time_zone_arr);
                 //Grab the first time zone, as it is most common
                 foreach ($time_zone_arr as $time_zone => $count) {
                     break;
                 }
                 if ($time_zone != '') {
                     //Set pay period timezone to the timezone of the majority of the users are in.
                     $pps_obj->setTimeZone($time_zone);
                     if ($pps_obj->isValid()) {
                         $pps_obj->Save();
                     }
                 }
             }
         }
     }
     Debug::text('l: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     return TRUE;
 }
Exemplo n.º 2
0
         unset($user_value_str, $user_values);
     }
 }
 //var_dump($user_deduction);
 foreach ($ulf as $u_obj) {
     //Wage data
     if (isset($user_wage[$u_obj->getId()])) {
         //Debug::Text('Wage Data found for User ID: '. $u_obj->getId(), __FILE__, __LINE__, __METHOD__,10);
         $user_wage_data = $user_wage[$u_obj->getId()];
     } else {
         Debug::Text('No Wage Data found for User ID: ' . $u_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
         //Dummy array
         $user_wage_data = array('type_id' => NULL, 'type' => NULL, 'wage' => NULL, 'effective_date_order' => NULL, 'effective_date' => NULL);
     }
     //Get user preference data.
     $uplf = new UserPreferenceListFactory();
     $uplf->getByUserId($u_obj->getId());
     if ($uplf->getRecordCount() > 0) {
         $up_obj = $uplf->getCurrent();
         $user_pref_data = array('language' => Option::getByKey($up_obj->getLanguage(), $language_options), 'date_format' => Option::getByKey($up_obj->getDateFormat(), $date_format_options), 'time_format' => Option::getByKey($up_obj->getTimeFormat(), $time_format_options), 'time_unit' => Option::getByKey($up_obj->getTimeUnitFormat(), $time_unit_format_options), 'time_zone' => Option::getByKey($up_obj->getTimeZone(), $time_zone_options), 'start_week_day' => Option::getByKey($up_obj->getStartWeekDay(), $start_week_day_options), 'items_per_page' => $up_obj->getItemsPerPage());
     }
     if (isset($permission_control_user_map[$u_obj->getId()])) {
         $permission_control_id = $permission_control_user_map[$u_obj->getId()];
     } else {
         $permission_control_id = 0;
     }
     if (isset($policy_group_user_map[$u_obj->getId()])) {
         $policy_group_id = $policy_group_user_map[$u_obj->getId()];
     } else {
         $policy_group_id = 0;
     }
 static function findOrInsertUserDate($user_id, $date, $timezone = NULL)
 {
     $date = TTDate::getMiddleDayEpoch($date);
     //Use mid day epoch so the timezone conversion across DST doesn't affect the date.
     if ($timezone == NULL) {
         //Find the employees preferred timezone, base the user date off that instead of the pay period timezone,
         //as it can be really confusing to the user if they punch in at 10AM on Sept 27th, but it records as Sept 26th because
         //the PP Schedule timezone is 12hrs different or something.
         $uplf = new UserPreferenceListFactory();
         $uplf->getByUserID($user_id);
         if ($uplf->getRecordCount() > 0) {
             $timezone = $uplf->getCurrent()->getTimeZone();
         }
     }
     $date = TTDate::convertTimeZone($date, $timezone);
     Debug::text(' Using TimeZone: ' . $timezone . ' Date: ' . TTDate::getDate('DATE+TIME', $date) . '(' . $date . ')', __FILE__, __LINE__, __METHOD__, 10);
     $udlf = new UserDateListFactory();
     $udlf->getByUserIdAndDate($user_id, $date);
     if ($udlf->getRecordCount() == 1) {
         $id = $udlf->getCurrent()->getId();
         Debug::text(' Found Already Existing User Date ID: ' . $id, __FILE__, __LINE__, __METHOD__, 10);
         return $id;
     } elseif ($udlf->getRecordCount() == 0) {
         Debug::text(' Inserting new UserDate row.', __FILE__, __LINE__, __METHOD__, 10);
         //Insert new row
         $udf = new UserDateFactory();
         $udf->setUser($user_id);
         $udf->setDateStamp($date);
         $udf->setPayPeriod();
         if ($udf->isValid()) {
             return $udf->Save();
         } else {
             Debug::text(' INVALID user date row. Pay Period Locked?', __FILE__, __LINE__, __METHOD__, 10);
         }
     } elseif ($udlf->getRecordCount() > 1) {
         Debug::text(' More then 1 user date row was detected!!: ' . $udlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
     }
     Debug::text(' Cant find or insert User Date ID. User ID: ' . $user_id . ' Date: ' . $date, __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }
 function getEmailMessageAddresses()
 {
     $olf = $this->getObjectHandler();
     if (is_object($olf)) {
         $olf->getById($this->getObject());
         if ($olf->getRecordCount() > 0) {
             $obj = $olf->getCurrent();
             switch ($this->getObjectType()) {
                 case 5:
                 case 100:
                     Debug::Text('Email Object Type... Parent ID: ' . $this->getParent(), __FILE__, __LINE__, __METHOD__, 10);
                     if ($this->getParent() == 0) {
                         $user_ids[] = $obj->getId();
                     } else {
                         $mlf = new MessageListFactory();
                         $mlf->getById($this->getParent());
                         if ($mlf->getRecordCount() > 0) {
                             $m_obj = $mlf->getCurrent();
                             $user_ids[] = $m_obj->getCreatedBy();
                         }
                         Debug::Text('cEmail Object Type... Parent ID: ' . $this->getParent(), __FILE__, __LINE__, __METHOD__, 10);
                     }
                     break;
                 case 40:
                     $user_ids[] = $obj->getId();
                     break;
                 case 50:
                     //Request
                     //Get all users who have contributed to the thread.
                     $mlf = new MessageListFactory();
                     $mlf->getMessagesInThreadById($this->getId());
                     Debug::Text(' Messages In Thread: ' . $mlf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                     if ($mlf->getRecordCount() > 0) {
                         foreach ($mlf as $m_obj) {
                             $user_ids[] = $m_obj->getCreatedBy();
                         }
                     }
                     unset($mlf, $m_obj);
                     //Debug::Arr($user_ids, 'User IDs in Thread: ', __FILE__, __LINE__, __METHOD__,10);
                     //Only alert direct supervisor to request at this point. Because we need to take into account
                     //if the request was authorized or not to determine if we should email the next higher level in the hierarchy.
                     if ($this->getParent() == 0) {
                         //Get direct parent in hierarchy.
                         $u_obj = $obj->getUserObject();
                         //Find proper hierarchy to use for this object
                         $hotlf = new HierarchyObjectTypeListFactory();
                         $control_id = $hotlf->getByCompanyIdAndObjectTypeId($u_obj->getCompany(), $this->getObjectType())->getCurrent()->getHierarchyControl();
                         Debug::Text(' Hierarchy Control ID: ' . $control_id, __FILE__, __LINE__, __METHOD__, 10);
                         $hlf = new HierarchyListFactory();
                         $node_data = $hlf->getByHierarchyControlIdAndUserId($control_id, $u_obj->getId());
                         if ($node_data['parent_id'] != 0) {
                             $user_ids[] = $node_data['parent_id'];
                         }
                         unset($hotlf, $control_id, $hlf, $node_data);
                     }
                     global $current_user;
                     if (isset($current_user) and is_object($current_user) and isset($user_ids) and is_array($user_ids)) {
                         $user_ids = array_unique($user_ids);
                         $current_user_key = array_search($current_user->getId(), $user_ids);
                         Debug::Text(' Current User Key: ' . $current_user_key, __FILE__, __LINE__, __METHOD__, 10);
                         if ($current_user_key !== FALSE) {
                             Debug::Text(' Removing Current User From Recipient List...' . $current_user->getId(), __FILE__, __LINE__, __METHOD__, 10);
                             unset($user_ids[$current_user_key]);
                         }
                     } else {
                         Debug::Text(' Current User Object not available...', __FILE__, __LINE__, __METHOD__, 10);
                     }
                     unset($current_user, $current_user_key);
                     break;
                 case 90:
                     $user_ids[] = $obj->getUser();
                     break;
             }
         }
         if (isset($user_ids) and is_array($user_ids)) {
             //Get user preferences and determine if they accept email notifications.
             Debug::Arr($user_ids, 'Recipient User Ids: ', __FILE__, __LINE__, __METHOD__, 10);
             $uplf = new UserPreferenceListFactory();
             $uplf->getByUserId($user_ids);
             if ($uplf->getRecordCount() > 0) {
                 foreach ($uplf as $up_obj) {
                     if ($up_obj->getEnableEmailNotificationMessage() == TRUE and $up_obj->getUserObject()->getStatus() == 10) {
                         if ($up_obj->getUserObject()->getWorkEmail() != '') {
                             $retarr[] = $up_obj->getUserObject()->getWorkEmail();
                         }
                         if ($up_obj->getEnableEmailNotificationHome() and $up_obj->getUserObject()->getHomeEmail() != '') {
                             $retarr[] = $up_obj->getUserObject()->getHomeEmail();
                         }
                     }
                 }
                 if (isset($retarr)) {
                     Debug::Arr($retarr, 'Recipient Email Addresses: ', __FILE__, __LINE__, __METHOD__, 10);
                     return $retarr;
                 }
             }
         }
     }
     return FALSE;
 }
Exemplo n.º 5
0
         }
         Redirect::Page(URLBuilder::getURL(array('user_id' => $pref_data['user_id'], 'data_saved' => 1), Environment::getBaseURL() . '/users/EditUserPreference.php'));
         unset($upf);
         break;
     }
 default:
     if (!isset($user_id) or isset($user_id) and $user_id == '') {
         $user_id = $current_user->getId();
     }
     $ulf->getByIdAndCompanyId($user_id, $current_company->getId());
     if ($ulf->getRecordCount() > 0) {
         $user_obj = $ulf->getCurrent();
     }
     if (!isset($action)) {
         BreadCrumb::setCrumb($title);
         $uplf = new UserPreferenceListFactory();
         $uplf->getByUserIDAndCompanyID($user_id, $current_company->getId());
         if (isset($user_obj) and is_object($user_obj)) {
             $is_owner = $permission->isOwner($user_obj->getCreatedBy(), $user_obj->getId());
             $is_child = $permission->isChild($user_obj->getId(), $permission_children_ids);
             if ($permission->Check('user_preference', 'edit') or $permission->Check('user_preference', 'edit_own') and $is_owner === TRUE or $permission->Check('user_preference', 'edit_child') and $is_child === TRUE) {
                 foreach ($uplf as $user_preference) {
                     $pref_data = array('id' => $user_preference->getId(), 'user_id' => $user_preference->getUser(), 'user_full_name' => $user_obj->getFullName(), 'language' => $user_preference->getLanguage(), 'date_format' => $user_preference->getDateFormat(), 'other_date_format' => $user_preference->getDateFormat(), 'time_format' => $user_preference->getTimeFormat(), 'time_zone' => $user_preference->getTimeZone(), 'time_unit_format' => $user_preference->getTimeUnitFormat(), 'timesheet_view' => $user_preference->getTimeSheetView(), 'start_week_day' => $user_preference->getStartWeekDay(), 'items_per_page' => $user_preference->getItemsPerPage(), 'enable_email_notification_exception' => $user_preference->getEnableEmailNotificationException(), 'enable_email_notification_message' => $user_preference->getEnableEmailNotificationMessage(), 'enable_email_notification_home' => $user_preference->getEnableEmailNotificationHome(), 'created_date' => $user_preference->getCreatedDate(), 'created_by' => $user_preference->getCreatedBy(), 'updated_date' => $user_preference->getUpdatedDate(), 'updated_by' => $user_preference->getUpdatedBy(), 'deleted_date' => $user_preference->getDeletedDate(), 'deleted_by' => $user_preference->getDeletedBy());
                 }
             }
         }
     }
     if (!isset($pref_data) and isset($user_obj)) {
         $udlf = new UserDefaultListFactory();
         $udlf->getByCompanyId($current_company->getId());
         if ($udlf->getRecordCount() > 0) {
 function postInstall()
 {
     global $cache;
     Debug::text('postInstall: ' . $this->getVersion(), __FILE__, __LINE__, __METHOD__, 9);
     //Configure currencies for Standard Edition.
     if ($this->getIsUpgrade() == TRUE) {
         $clf = new CompanyListFactory();
         $clf->StartTransaction();
         $clf->getAll();
         if ($clf->getRecordCount() > 0) {
             foreach ($clf as $c_obj) {
                 if ($c_obj->getStatus() == 10) {
                     //Converting to new Accrual Policy table.
                     Debug::text('Converting to new Accrual Policy Table: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9);
                     $pglf = new PolicyGroupListFactory();
                     $pglf->getByCompanyId($c_obj->getId());
                     if ($pglf->getRecordCount() > 0) {
                         foreach ($pglf as $pg_obj) {
                             Debug::text('Accrual Policy ID: ' . $pg_obj->getColumn('accrual_policy_id'), __FILE__, __LINE__, __METHOD__, 9);
                             if ($pg_obj->getColumn('accrual_policy_id') != '' and $pg_obj->getColumn('accrual_policy_id') != 0) {
                                 $pg_obj->setAccrualPolicy(array($pg_obj->getColumn('accrual_policy_id')));
                                 if ($pg_obj->isValid()) {
                                     $pg_obj->Save();
                                 }
                             }
                         }
                     }
                     Debug::text('Adding Currency Information to Company: ' . $c_obj->getName() . ' ID: ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 9);
                     $crlf = new CurrencyListFactory();
                     $crlf->getByCompanyId($c_obj->getId());
                     if ($crlf->getRecordCount() == 0) {
                         $cf = new CurrencyFactory();
                         $country_to_currency_map_arr = $cf->getOptions('country_currency');
                         if (isset($country_to_currency_map_arr[$c_obj->getCountry()])) {
                             $base_currency = $country_to_currency_map_arr[$c_obj->getCountry()];
                             Debug::text('Found Base Currency For Country: ' . $c_obj->getCountry() . ' Currency: ' . $base_currency, __FILE__, __LINE__, __METHOD__, 9);
                         } else {
                             Debug::text('DID NOT Find Base Currency For Country: ' . $c_obj->getCountry() . ' Using default USD.', __FILE__, __LINE__, __METHOD__, 9);
                             $base_currency = 'USD';
                         }
                         $cf->setCompany($c_obj->getId());
                         $cf->setStatus(10);
                         $cf->setName($base_currency);
                         $cf->setISOCode($base_currency);
                         $cf->setConversionRate('1.000000000');
                         $cf->setAutoUpdate(FALSE);
                         $cf->setBase(TRUE);
                         $cf->setDefault(TRUE);
                         if ($cf->isValid()) {
                             $base_currency_id = $cf->Save();
                             Debug::text('Base Currency ID: ' . $base_currency_id, __FILE__, __LINE__, __METHOD__, 10);
                             //Set Employee Hire Defaults.
                             $udlf = new UserDefaultListFactory();
                             $udlf->getByCompanyId($c_obj->getId());
                             if ($udlf->getRecordCount() > 0) {
                                 $ud_obj = $udlf->getCurrent();
                                 $ud_obj->setCurrency($base_currency_id);
                                 $ud_obj->setLanguage('en');
                                 if ($ud_obj->isValid()) {
                                     $ud_obj->Save();
                                 }
                             }
                             unset($udlf, $ud_obj);
                             if (is_numeric($base_currency_id)) {
                                 $ulf = new UserListFactory();
                                 $ulf->getByCompanyId($c_obj->getId());
                                 if ($ulf->getRecordCount() > 0) {
                                     foreach ($ulf as $u_obj) {
                                         $user_id = $u_obj->getID();
                                         Debug::text('Setting Base Currency For User: '******' ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                         $u_obj->setCurrency($base_currency_id);
                                         if ($u_obj->isValid()) {
                                             if ($u_obj->Save() == TRUE) {
                                                 //Set User Default Language
                                                 $uplf = new UserPreferenceListFactory();
                                                 $uplf->getByUserIDAndCompanyID($user_id, $c_obj->getId());
                                                 if ($uplf->getRecordCount() > 0) {
                                                     $up_obj = $uplf->getCurrent();
                                                     $up_obj->setLanguage('en');
                                                     //Englist
                                                     if ($up_obj->isValid()) {
                                                         $up_obj->Save();
                                                     }
                                                 }
                                                 unset($uplf, $up_obj);
                                                 Debug::text('  Setting Base Currency for Pay Stubs, User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                                 //Change all pay stubs for this user to the base currency.
                                                 //Do this in a single query for speed purposes.
                                                 $ph = array('currency_id' => $base_currency_id, 'currency_rate' => '1.000000000', 'user_id' => $user_id);
                                                 $query = 'update pay_stub set currency_id = ?, currency_rate = ? where user_id = ?';
                                                 Debug::text('  Pay Stub Currency Query: ' . $query, __FILE__, __LINE__, __METHOD__, 10);
                                                 $u_obj->db->Execute($query, $ph);
                                                 /*
                                                 $pslf = new PayStubListFactory();
                                                 $pslf->getByUserIdAndCompanyId( $user_id, $c_obj->getId() );
                                                 if ( $pslf->getRecordCount() > 0 ) {
                                                 	foreach( $pslf as $ps_obj ) {
                                                 		//Debug::text('    Setting Base Currency for Pay Stub ID: '. $ps_obj->getId(), __FILE__, __LINE__, __METHOD__,10);
                                                 		
                                                 		$ps_obj->setCurrency( $base_currency_id );
                                                 		if ( $ps_obj->isValid() ) {
                                                 			
                                                 			$ps_obj->setEnableLinkedAccruals( FALSE );												
                                                 			$ps_obj->setEnableCalcYTD( FALSE );
                                                 			$ps_obj->setEnableProcessEntries( FALSE );
                                                 			
                                                 			$ps_obj->Save();
                                                 		}
                                                 		
                                                 		unset($ps_obj);
                                                 	}
                                                 }
                                                 unset($pslf);
                                                 */
                                             } else {
                                                 Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                             }
                                         } else {
                                             Debug::text('Failed saving user ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                                         }
                                         unset($u_obj, $user_id);
                                     }
                                 }
                                 unset($ulf);
                             }
                         }
                         unset($cf);
                     }
                 } else {
                     Debug::text('Company is not active! ' . $c_obj->getId(), __FILE__, __LINE__, __METHOD__, 10);
                 }
                 unset($c_obj, $base_currency, $base_currency_id, $crlf);
             }
         }
         //$clf->FailTransaction();
         $clf->CommitTransaction();
     }
     //Add currency updating to cron.
     $maint_base_path = Environment::getBasePath() . DIRECTORY_SEPARATOR . 'maint' . DIRECTORY_SEPARATOR;
     if (PHP_OS == 'WINNT') {
         $cron_job_base_command = 'php-win.exe ' . $maint_base_path;
     } else {
         $cron_job_base_command = 'php ' . $maint_base_path;
     }
     Debug::text('Cron Job Base Command: ' . $cron_job_base_command, __FILE__, __LINE__, __METHOD__, 9);
     $cjf = new CronJobFactory();
     $cjf->setName('UpdateCurrencyRates');
     $cjf->setMinute(45);
     $cjf->setHour(1);
     $cjf->setDayOfMonth('*');
     $cjf->setMonth('*');
     $cjf->setDayOfWeek('*');
     $cjf->setCommand($cron_job_base_command . 'UpdateCurrencyRates.php');
     $cjf->Save();
     return TRUE;
 }
Exemplo n.º 7
0
 function getUserPreferenceObject()
 {
     if (is_object($this->user_preference_obj)) {
         return $this->user_preference_obj;
     } else {
         $uplf = new UserPreferenceListFactory();
         $this->user_preference_obj = $uplf->getByUserId($this->getId())->getCurrent();
         return $this->user_preference_obj;
     }
 }