Beispiel #1
0
    def put(self, request, pk, format=None):
        company_group_member = self._get_object(pk)
        original_group = company_group_member.company_group

        group_member_change_info = {
            'user': company_group_member.user,
            'company': company_group_member.company_group.company,
            'original_company_group': company_group_member.company_group
        }

        serializer = CompanyGroupMemberPostSerializer(company_group_member, data=request.DATA)
        if serializer.is_valid():
            serializer.save()

            # Collect updated group information and send notfiication email
            updated_company_group_member = self._get_object(pk)
            email_service = SendEmailService()
            email_service.send_employee_benefit_group_update_notification_email(
                company_group_member.user, 
                company_group_member.company_group.company,
                original_group,
                updated_company_group_member.company_group
            )

            return Response(serializer.data)

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Beispiel #2
0
    def execute(self, action_data):

        if (not action_data or not 'company_user_id_list' in action_data):
            raise ValueError(
                "action_data must contains valid 'company_user_id_list'!")

        send_email_service = SendEmailService()

        for company_id in action_data['company_user_id_list']:
            user_id_list = action_data['company_user_id_list'][company_id]
            for user_id in user_id_list:
                # build the list of target emails
                email = send_email_service.get_email_address_by_user(user_id)
                emails = [email]
                # Get action dependent data for outbound emails
                email_data = self._get_email_data(company_id, user_id)
                send_email_service.send_support_email(
                    emails, email_data.subject, email_data.context_data,
                    email_data.html_template_path,
                    email_data.txt_template_path)

                self.log.info("Action {} ran to completion for user {}".format(
                    self.__class__.__name__, user_id))

        self.log.info("Action {} ran to completion.".format(
            self.__class__.__name__))
    def _employee_mod_notify_broker(self, broker_user_id, in_last_num_minutes):
        company_ids = CompanyUser.objects.filter(
            company_user_type='broker',
            user=broker_user_id).values_list('company', flat=True).distinct()

        # The result collection of data to bind to the email content
        # Each entry will be for 1 client company
        company_users_collection = []
        for company_id in company_ids:
            # Get the list of employee users made modifications in the search range
            mod_summaries = self.employee_modifications_summary(
                company_id, in_last_num_minutes)
            if (len(mod_summaries) > 0):
                companies = Company.objects.filter(pk=company_id)
                if (len(companies) > 0):
                    company = companies[0]
                    company_users_collection.append({
                        'company':
                        company,
                        'mod_summary_list':
                        mod_summaries
                    })

        # If there is something needs to be notified about, send the email
        if (len(company_users_collection) > 0):
            email_service = SendEmailService()
            emails = [email_service.get_email_address_by_user(broker_user_id)]
            self._send_notification_email(emails, company_users_collection)
 def employee_modifications_notify_employer_for_all_companies(
         self, in_last_num_minutes):
     email_service = SendEmailService()
     company_list = Company.objects.all()
     for company in company_list:
         emails = email_service.get_employer_emails_by_company(company.id)
         self._employee_mod_notify_target_by_company(
             company, in_last_num_minutes, emails)
Beispiel #5
0
    def _examine_condition(self):
        super(TriggerEmployeeNoWorkTimeTracking, self)._examine_condition()

        # Only proceed if schedule met
        if (self._check_schedule()):

            send_email_service = SendEmailService()

            # Use the appropriate service to get the list of companies that
            # do not use this feature
            app_feature_service = ApplicationFeatureService()
            timesheet_disabled_company_list = app_feature_service.get_company_list_with_feature_disabled(APP_FEATURE_WORKTIMESHEET)
            ranged_timecard_enabled_company_list = app_feature_service.get_company_list_with_feature_enabled(APP_FEATURE_RANGEDTIMECARD)
            feature_disabled_company_list = [c for c in timesheet_disabled_company_list if c not in ranged_timecard_enabled_company_list]

            timesheet_notify_enabled_company_list = app_feature_service.get_company_list_with_feature_enabled(APP_FEATURE_WORKTIMESHEETNOTIFICATION)

            # Get the start date of the past week (starting Sunday)
            week_start_date = self._get_last_week_start_date()

            # Get the list of users that have submitted the timesheet
            # for the week
            time_tracking_service = TimeTrackingService()
            submitted_users = time_tracking_service.get_all_users_submitted_work_timesheet_by_week_start_date(week_start_date)

            # Get the list of users that have the notification of this feature blocked
            blocked_users = send_email_service.get_all_users_blocked_for_email_feature(
                    EMAIL_BLOCK_FEATURE_WORKTIMESHEETNOTIFICATION
                )

            # Only include the employee for reporting if all of the below hold
            #   - Company has the feature on
            #   - Company has the notification feature on
            #   - User is not blocked for this notification 
            #   - User has not submitted yet
            company_users = CompanyUser.objects.filter(
                    company_user_type=USER_TYPE_EMPLOYEE,
                    company__in=timesheet_notify_enabled_company_list,
                ).exclude(
                    company__in=feature_disabled_company_list
                ).exclude(
                    user__in=blocked_users
                ).exclude(
                    user__in=submitted_users
                )

            for company_user in company_users:
                user = company_user.user
                company = company_user.company

                self._cache_company_user(company.id, user.id)

        return (not self._is_cached_data_empty())
    def _send_email(self, person_company_extra_benefit_plan_model):
        # Construct a "view model" to pipe in the context information
        has_interests = False
        plan_items = []
        for item in person_company_extra_benefit_plan_model.plan_items.all():
            has_interests = has_interests or item.opt_in
            plan_items.append({
                'item_name': item.extra_benefit_item.name,
                'opt_in': 'Yes' if item.opt_in else 'No'
            })

        context_data = {
            'company':
            person_company_extra_benefit_plan_model.company_plan.company,
            'person':
            PersonInfo(person_company_extra_benefit_plan_model.person),
            'plan_items': plan_items
        }

        # Skip sending the email if employee did not show interest
        # on any of the items
        if (not has_interests):
            return

        send_email_service = SendEmailService()

        subject = 'Individual Benefits Interests Notification'
        html_template_path = 'email/extra_benefit_interest_notification.html'
        txt_template_path = 'email/extra_benefit_interest_notification.txt'

        # build the list of target emails
        company_id = person_company_extra_benefit_plan_model.company_plan.company.id
        broker_emails = send_email_service.get_broker_emails_by_company(
            company_id)

        # build the template context data
        context_data = {
            'context_data': context_data,
            'site_url': settings.SITE_URL
        }

        send_email_service.send_support_email(broker_emails, subject,
                                              context_data, html_template_path,
                                              txt_template_path)

        return
    def _send_notification_email(self, to_email_list,
                                 company_users_collection):
        email_service = SendEmailService()

        # Prepare and send the email with both HTML and plain text contents
        subject = 'Users Data Change Notification'
        from_email = '*****@*****.**'
        context_data = {
            'company_users_collection': company_users_collection,
            'site_url': settings.SITE_URL
        }
        html_template_path = 'email/user_data_change_notification.html'
        text_template_path = 'email/user_data_change_notification.txt'

        email_service.send_support_email(to_email_list, subject, context_data,
                                         html_template_path,
                                         text_template_path)
    def _get_action_data(self):
        hash_key_service = HashKeyService()
        send_email_service = SendEmailService()
        company_emails = send_email_service.get_employer_emails_for_all_companies(
        )

        result = []

        for companyId in company_emails.keys():
            result.append({
                'descriptor':
                hash_key_service.encode_key_with_environment(companyId),
                'emailList':
                company_emails[companyId]
            })

        return result
Beispiel #9
0
    def execute(self, action_data):
        if (not action_data or not 'company_user_id_list' in action_data):
            raise ValueError(
                "action_data must contains valid 'company_user_id_list'!")

        send_email_service = SendEmailService()

        subject = '[Action Required] Enrollment not Completed'
        html_template_path = 'email/system_notifications/employee_not_complete_enrollment.html'
        txt_template_path = 'email/system_notifications/employee_not_complete_enrollment.txt'

        for company_id in action_data['company_user_id_list']:

            self.log.debug("Company {0}".format(company_id))
            user_id_list = action_data['company_user_id_list'][company_id]

            for user_id in user_id_list:

                self.log.debug("User {0}".format(user_id))
                context_data = {'company': Company.objects.get(pk=company_id)}

                # build the list of target emails
                email = send_email_service.get_email_address_by_user(user_id)
                emails = [email]

                # build the template context data
                context_data = {
                    'context_data': context_data,
                    'site_url': self._get_site_URL(user_id)
                }

                send_email_service.send_support_email(emails, subject,
                                                      context_data,
                                                      html_template_path,
                                                      txt_template_path)

                self.log.info(
                    "Action {0} ran to completion for user {1}".format(
                        self.__class__.__name__, user_id))

        self.log.info("Action {0} ran to completion.".format(
            self.__class__.__name__))
    def execute(self, action_data):
        if (not action_data or not 'company_user_id_list' in action_data):
            raise ValueError(
                "action_data must contains valid 'company_user_id_list'!")

        send_email_service = SendEmailService()

        for company_id in action_data['company_user_id_list']:
            user_id_list = action_data['company_user_id_list'][company_id]

            email_data = self._get_email_data(company_id, user_id_list)

            # build the list of target emails
            emails = send_email_service.get_employer_emails_by_company(
                company_id)
            if email_data.include_broker:
                broker_emails = send_email_service.get_broker_emails_by_company(
                    company_id)
                emails.extend(broker_emails)

            send_email_service.send_support_email(
                emails, email_data.subject, email_data.context_data,
                email_data.html_template_path, email_data.txt_template_path)

            self.log.info("Action {} ran to completion for company {}".format(
                self.__class__.__name__, company_id))

        self.log.info("Action {} ran to completion".format(
            self.__class__.__name__))
    def _get_user_view_model_list(self, user_id_list):
        send_email_service = SendEmailService()
        model_list = []
        for user_id in user_id_list:
            user = User.objects.get(pk=user_id)
            email = send_email_service.get_email_address_by_user(user_id)
            person = None
            persons = Person.objects.filter(user=user.id, relationship=SELF)
            if (len(persons) > 0):
                person = persons[0]
            if (person):
                model_list.append({
                    'first_name': person.first_name,
                    'last_name': person.last_name,
                    'email': email
                })
            else:
                model_list.append({
                    'first_name': user.first_name,
                    'last_name': user.last_name,
                    'email': email
                })

        return model_list
    def _send_termination_email(self, employee_profile_model):
        send_email_service = SendEmailService()

        subject = 'Employment Termination Notification'
        html_template_path = 'email/employment_termination_notification.html'
        txt_template_path = 'email/employment_termination_notification.txt'

        # build the list of target emails
        to_emails = []
        employer_emails = send_email_service.get_employer_emails_by_company(
            employee_profile_model.company.id)
        to_emails.extend(employer_emails)
        broker_emails = send_email_service.get_broker_emails_by_company(
            employee_profile_model.company.id)
        to_emails.extend(broker_emails)

        # build the template context data
        context_data = {
            'employee_profile': employee_profile_model,
            'site_url': settings.SITE_URL
        }

        # get PDF
        pdf_service = CompanyEmployeeBenefitPdfReportService()
        pdf_buffer = StringIO()
        pdf_service.get_employee_report(employee_profile_model.person.user.id,
                                        employee_profile_model.company.id,
                                        pdf_buffer)
        pdf = pdf_buffer.getvalue()
        pdf_buffer.close()

        send_email_service.send_support_email(
            to_emails,
            subject,
            context_data,
            html_template_path,
            txt_template_path,
            attachment_name='employee_details.pdf',
            attachment=pdf,
            attachment_mime_type='application/pdf')

        return
Beispiel #13
0
 def __init__(self):
     super(CompanyDailyEmployeeDataChangeReportEventHandler,
           self).__init__(CompanyDailyEmployeeDataChangeReportEvent)
     self._send_email_service = SendEmailService()
     self._data_modification_service = DataModificationService()
Beispiel #14
0
class CompanyDailyEmployeeDataChangeReportEventHandler(EventHandlerBase):
    def __init__(self):
        super(CompanyDailyEmployeeDataChangeReportEventHandler,
              self).__init__(CompanyDailyEmployeeDataChangeReportEvent)
        self._send_email_service = SendEmailService()
        self._data_modification_service = DataModificationService()

    def _internal_handle(self, event):
        if (not event.company_id):
            raise ValueError(
                'The event is expected to provide company_id, which is missing!'
            )

        emails = self._send_email_service.get_employer_emails_by_company(
            event.company_id)

        # Get employee data modification summery records
        mod_summaries = self._data_modification_service.employee_modifications_summary(
            event.company_id, 24 * 60)
        if (len(mod_summaries) <= 0):
            # No modifications detected. Do not send anything
            return

        email_data = self._get_email_data(event.company_id, mod_summaries)

        self._send_email_service.send_support_email(
            emails, email_data.subject, email_data.context_data,
            email_data.html_template_path, email_data.txt_template_path)

    def _get_email_data(self, company_id, data_modification_summaries):
        # Get display date
        date_text = self._get_display_date()

        # Now prepare the email content data
        subject = '[System Notification - {0}] Employee Data Change Notification'.format(
            date_text)

        html_template_path = 'email/user_data_change_notification.html'
        txt_template_path = 'email/user_data_change_notification.txt'

        company_users_collection = [{
            'company':
            Company.objects.get(pk=company_id),
            'mod_summary_list':
            data_modification_summaries,
        }]

        context_data = {'date': date_text}
        context_data = {
            'context_data': context_data,
            'company_users_collection': company_users_collection,
            'site_url': settings.SITE_URL
        }

        return EmailData(subject, html_template_path, txt_template_path,
                         context_data, False)

    def _get_display_date(self):
        now = datetime.now()
        date = now - timedelta(hours=12)
        return date.strftime('%m/%d/%Y')
 def __init__(self):
     super(CompanyDailyTimeCardAuditEventHandler,
           self).__init__(CompanyDailyTimeCardAuditEvent)
     self._time_punch_card_service = TimePunchCardService()
     self._send_email_service = SendEmailService()
class CompanyDailyTimeCardAuditEventHandler(EventHandlerBase):
    def __init__(self):
        super(CompanyDailyTimeCardAuditEventHandler,
              self).__init__(CompanyDailyTimeCardAuditEvent)
        self._time_punch_card_service = TimePunchCardService()
        self._send_email_service = SendEmailService()

    def _internal_handle(self, event):
        if (not event.company_id):
            raise ValueError(
                'The event is expected to provide company_id, which is missing!'
            )

        emails = self._send_email_service.get_employer_emails_by_company(
            event.company_id)
        email_data = self._get_email_data(event.company_id)

        self._send_email_service.send_support_email(
            emails, email_data.subject, email_data.context_data,
            email_data.html_template_path, email_data.txt_template_path)

    def _get_email_data(self, company_id):
        # Get cards with validation issues
        card_aggrgates_with_issues = self._get_time_cards_aggrgates_with_issues(
            company_id)

        # Get display date
        date_text = self._get_display_date()

        # Now prepare the email content data
        subject = '[System Notification - {0}] Time & Attendance Data Validation Result'.format(
            date_text)

        html_template_path = 'email/system_notifications/time_card_audit_notification.html'
        txt_template_path = 'email/system_notifications/time_card_audit_notification.txt'

        context_data = {
            'company': Company.objects.get(pk=company_id),
            'card_aggrgates_with_issues': card_aggrgates_with_issues,
            'date': date_text
        }
        context_data = {
            'context_data': context_data,
            'site_url': settings.SITE_URL
        }

        return EmailData(subject, html_template_path, txt_template_path,
                         context_data, False)

    def _get_time_cards_aggrgates_with_issues(self, company_id):
        # Get all cards for the company for the day just passed
        # The assumption is that this report would be run sometime near
        # the end of the day. Just to play safe that this is not ran just
        # a few minutes passed the calendar day mark, take a time 12 hours
        # earlier to ensure we are looking at the right date.
        now = datetime.now()
        card_date = now - timedelta(hours=12)

        card_aggregates = self._time_punch_card_service.get_company_users_daily_time_punch_cards_aggregates(
            company_id, card_date, include_unclosed_cards=True)

        card_aggregates_with_issues = [
            _TimeCardAggregateViewModel(card_aggregate)
            for card_aggregate in card_aggregates
            if len(card_aggregate.validation_issues) > 0
        ]

        return card_aggregates_with_issues

    def _get_display_date(self):
        now = datetime.now()
        date = now - timedelta(hours=12)
        return date.strftime('%m/%d/%Y')