getPermissionObject()->Check( 'pay_period_schedule', 'enabled' ) || !( $this->getPermissionObject()->Check( 'pay_period_schedule', 'edit' ) || $this->getPermissionObject()->Check( 'pay_period_schedule', 'edit_own' ) || $this->getPermissionObject()->Check( 'pay_period_schedule', 'edit_child' ) || $this->getPermissionObject()->Check( 'pay_period_schedule', 'add' ) ) ) { return $this->getPermissionObject()->PermissionDenied(); } if ( is_array( $location_data ) ) { $sp = $this->getMainClassObject(); $sp->setCompany( $this->getCurrentCompanyObject()->getId() ); $sp->setUser( $this->getCurrentUserObject()->getId() ); $this->getProgressBarObject()->start( $this->getAPIMessageID(), ( count( $location_data ) + 1 ), null, TTi18n::getText( 'Creating permissions...' ) ); $sp->Permissions(); //Must go before createPresets() as SetupPresets::UserDefault() requires it. $this->getProgressBarObject()->set( $this->getAPIMessageID(), 1, TTi18n::getText( 'Creating policies...' ) ); $sp->createPresets( null, null, null, null, null, $legal_entity_id ); $already_processed_country = []; $i = 1; if ( $legal_entity_id == TTUUID::getZeroID() ) { $legal_entity_id = null; } foreach ( $location_data as $location ) { if ( isset( $location['country'] ) && isset( $location['province'] ) ) { if ( $location['province'] == '00' ) { $location['province'] = null; } if ( !in_array( $location['country'], $already_processed_country ) ) { $sp->createPresets( $location['country'], null, null, null, null, $legal_entity_id ); } $sp->createPresets( $location['country'], $location['province'], null, null, null, $legal_entity_id ); Debug::text( 'Creating presets for Country: ' . $location['country'] . ' Province: ' . $location['province'], __FILE__, __LINE__, __METHOD__, 9 ); $already_processed_country[] = $location['country']; } $this->getProgressBarObject()->set( $this->getAPIMessageID(), $i ); $i++; } //Assign the current user to the only existing pay period schedule. $ppslf = TTnew( 'PayPeriodScheduleListFactory' ); /** @var PayPeriodScheduleListFactory $ppslf */ $ppslf->getByCompanyId( $this->getCurrentCompanyObject()->getId() ); if ( $ppslf->getRecordCount() == 1 ) { $pps_obj = $ppslf->getCurrent(); //In case the user runs the quick start wizard after they are already setup, assign all users to the only existing pay period schedule. $user_ids = []; $ulf = TTNew( 'UserListFactory' ); /** @var UserListFactory $ulf */ $ulf->getByCompanyId( $this->getCurrentCompanyObject()->getId() ); if ( $ulf->getRecordCount() > 0 ) { foreach ( $ulf as $u_obj ) { $user_ids[] = $u_obj->getId(); } } $pps_obj->setUser( $user_ids ); unset( $user_ids ); Debug::text( 'Assigning current user to pay period schedule: ' . $pps_obj->getID(), __FILE__, __LINE__, __METHOD__, 9 ); if ( $pps_obj->isValid() ) { $pps_obj->Save(); } } $this->getCurrentCompanyObject()->setSetupComplete( true ); if ( $this->getCurrentCompanyObject()->isValid() ) { $this->getCurrentCompanyObject()->Save(); } $this->getProgressBarObject()->stop( $this->getAPIMessageID() ); } return true; } } ?>