def _list_formatted_get_buttons(self,
                                    row,
                                    permission_edit,
                                    permission_delete):
        """
        :param row:
        :param permission_edit:
        :return:
        """
        from .os_gui import OsGui

        T = current.T
        os_gui = OsGui()
        buttons = DIV(_class='pull-right')

        if permission_edit:
            edit = os_gui.get_button(
                'edit',
                URL('finance_expenses', 'edit', vars={'aeID': row.id})
            )
            buttons.append(edit)
        if permission_delete:
            onclick_delete = \
                "return confirm('" + \
                T('Are you sure you want to delete this expense?') + \
                "');"

            delete = os_gui.get_button(
                'delete_notext',
                URL('finance_expenses', 'delete', vars={'aeID': row.id}),
                onclick=onclick_delete
            )
            buttons.append(delete)

        return buttons
Beispiel #2
0
    def get_payment_fixed_rate_default_display(self):
        """
        :return: HTML display of default rate for teacher
        """
        from .os_gui import OsGui

        T = current.T
        os_gui = OsGui()

        display = DIV(H3(T("Default rate")), )

        edit_url = URL('payment_fixed_rate_default', vars={'teID': self.id})
        rows = self.get_payment_fixed_rate_default(render=True)
        if not rows:
            display.append(A(T('Set default rate'), _href=edit_url))
            return display

        row = list(rows)[0]

        display.append(
            DIV(
                os_gui.get_button('edit',
                                  edit_url,
                                  _class='pull-right',
                                  title=T('Edit'),
                                  tooltip=T('Edit the default rate')),
                H4(row.ClassRate),
                ' ',
                row.tax_rates_id,
                BR(),
            ))

        return display
Beispiel #3
0
def divisions():
    """
    List divisions
    """
    def get_button_set_default(division_id):
        if division_id == selected_division:
            return DIV(os_gui.get_label(
                'success',
                T('Selected'),
            ),
                       _class='pull-right')

        else:
            return os_gui.get_button('noicon',
                                     URL('division_set_default',
                                         vars={'division_id': division_id}),
                                     _class='pull-right',
                                     btn_class='btn-link',
                                     title=T("Select this division"))

    from ConfigParser import NoOptionError
    from openstudio.os_exact_online import OSExactOnline
    from openstudio.os_gui import OsGui

    response.title = T("Exact online")
    response.subtitle = T("Divisions")
    response.view = 'general/only_content.html'

    os_gui = OsGui()
    os_eo = OSExactOnline()
    api = os_eo.get_api()
    storage = os_eo.get_storage()
    try:
        selected_division = int(storage.get('transient', 'division'))
    except NoOptionError:
        selected_division = None

    division_choices, current_division = api.get_divisions()

    header = THEAD(TR(TH('Name'), TH('Exact ID'), TH()))

    table = TABLE(header, _class="table table-striped table-hover")

    for division_id in division_choices:
        tr = TR(
            TD(division_choices[division_id]),
            TD(division_id),
            TD(get_button_set_default(division_id))  # buttons
        )

        table.append(tr)

    content = table

    back = os_gui.get_button('back', URL('settings_integration',
                                         'exact_online'))

    return dict(content=content, back=back)
Beispiel #4
0
def financial_glaccounts():
    """
    List G/L accounts
    """
    from ConfigParser import NoOptionError
    from openstudio.os_exact_online import OSExactOnline

    from exactonline.exceptions import ObjectDoesNotExist
    from exactonline.resource import GET, POST, PUT, DELETE

    from openstudio.os_gui import OsGui

    response.title = T("Exact online")
    response.subtitle = T("G/L Accounts")
    response.view = 'general/only_content.html'

    os_gui = OsGui()
    os_eo = OSExactOnline()
    api = os_eo.get_api()
    storage = os_eo.get_storage()
    try:
        selected_division = int(storage.get('transient', 'division'))
    except NoOptionError:
        selected_division = None

    items = api.financialglaccounts.all()
    sorted_items = sorted(items, key=lambda k: k['Code'])

    header = THEAD(
        TR(
            TH('G/L Account code'),
            TH('G/L Account Description'),
            TH('G/L Account ID'),
        ))

    table = TABLE(header, _class="table table-striped table-hover")

    for item in sorted_items:
        tr = TR(TD(item['Code']), TD(item['Description']), TD(item['ID']))

        table.append(tr)

    content = table

    back = os_gui.get_button('back', URL('settings_integration',
                                         'exact_online'))

    return dict(content=content, back=back)
    def _list_sqlform_grid_link_edit(self, row):
        """
        :param row:
        :return:
        """
        from .os_gui import OsGui
        auth = current.auth
        os_gui = OsGui()
        edit = ''

        permission = auth.has_membership(group_id='Admins') or \
                     auth.has_permission('update', 'accounting_expenses')
        if permission:
            edit = os_gui.get_button(
                'edit',
                URL('finance_expenses', 'edit', vars={'aeID': row.id})
            )

        return edit
Beispiel #6
0
    def get_add(self,
                button_text=None,
                btn_size='btn-sm',
                redirect_vars={}):
        """
        :return: Returns an html add button for an account
        """
        from openstudio.os_gui import OsGui

        os_gui = OsGui()

        add = os_gui.get_button(
            'add',
            URL('customers', 'add', vars=redirect_vars),
            _class='pull-right',
            btn_size=btn_size,
            title=button_text
        )
        
        return add
Beispiel #7
0
    def _classes_reservation_add_get_button(self, clsID):
        """
            Returns add button for a customer to add a reservation
        """
        from .os_customer import Customer
        from .os_gui import OsGui
        os_gui = OsGui()

        session = current.session
        DATE_FORMAT = current.DATE_FORMAT

        date = session.customers_classes_reservation_add_vars['date']
        date_formatted = date.strftime(DATE_FORMAT)
        cuID = session.customers_classes_reservation_add_vars['cuID']
        customer = Customer(cuID)

        add = os_gui.get_button('add', URL('classes', 'reservation_add_choose',
                                           vars={'cuID': cuID,
                                                 'clsID': clsID,
                                                 'date': date_formatted}),
                                btn_size='btn-sm',
                                _class="pull-right")

        return add
Beispiel #8
0
    def get_payment_travel_display(self):
        """
        :return: gluon.dal.row object of db.teachers_payment_travel
        """
        from openstudio.os_gui import OsGui

        T = current.T
        auth = current.auth
        os_gui = OsGui()
        rows = self.get_payment_travel_allowances()

        display = DIV()

        if not rows:
            return display

        edit_permission = auth.has_membership(group_id='Admins') or \
                          auth.has_permission('update', 'teachers_payment_travel')
        delete_permission = auth.has_membership(group_id='Admins') or \
                          auth.has_permission('delete', 'teachers_payment_travel')
        delete_onclick = "return confirm('" + \
            T('Do you really want to delete the travel allowance for this location?') \
            + "');"

        table = TABLE(self._get_payment_travel_display_get_table_header(),
                      _class='table table-hover table-striped')

        for i, row in enumerate(rows):
            repr_row = list(rows[i:i + 1].render())[0]

            buttons = DIV(_class='pull-right')
            if edit_permission:
                edit_url = URL('payment_travel_edit',
                               vars={
                                   'teID': self.id,
                                   'tpfrtID': row.teachers_payment_travel.id
                               })
                buttons.append(os_gui.get_button('edit', edit_url))

            if delete_permission:
                delete_url = URL('payment_travel_delete',
                                 vars={
                                     'tpfrtID': row.teachers_payment_travel.id,
                                     'teID': self.id
                                 })
                buttons.append(
                    os_gui.get_button(
                        'delete_notext',
                        delete_url,
                        onclick=delete_onclick,
                    ))

            table.append(
                TR(TD(row.school_locations.Name),
                   TD(repr_row.teachers_payment_travel.TravelAllowance),
                   TD(repr_row.teachers_payment_travel.tax_rates_id),
                   TD(buttons)))

        display.append(table)

        return display
Beispiel #9
0
    def get_payment_fixed_rate_classes_display(self):
        """
        :return: gluon.dal.row object of db.teachers_payment_fixed_rate_class
        """
        from openstudio.os_gui import OsGui

        T = current.T
        auth = current.auth
        os_gui = OsGui()
        rows = self.get_payment_fixed_rate_classes_rows()

        display = DIV(
            os_gui.get_button('add',
                              URL('teachers',
                                  'payment_fixed_rate_class_add',
                                  vars={'teID': self.id}),
                              _class='pull-right'),
            H3(T("Class rates")),
        )

        if not rows:
            return display

        edit_permission = auth.has_membership(group_id='Admins') or \
                          auth.has_permission('update', 'teachers_payment_fixed_rate_class')
        delete_permission = auth.has_membership(group_id='Admins') or \
                          auth.has_permission('delete', 'teachers_payment_fixed_rate_class')
        delete_onclick = "return confirm('" + \
            T('Do you really want to delete this class rate?') \
            + "');"

        table = TABLE(
            self._get_payment_fixed_rate_classes_display_get_table_header(),
            _class='table table-hover table-striped')

        for i, row in enumerate(rows):
            repr_row = list(rows[i:i + 1].render())[0]

            buttons = DIV(_class='pull-right')
            if edit_permission:
                edit_url = URL(
                    'payment_fixed_rate_class',
                    vars={
                        'teID': self.id,
                        'clsID':
                        row.teachers_payment_fixed_rate_class.classes_id
                    })
                buttons.append(os_gui.get_button('edit', edit_url))

            if delete_permission:
                delete_url = URL('payment_fixed_rate_class_delete',
                                 vars={
                                     'tpfrcID':
                                     row.teachers_payment_fixed_rate_class.id,
                                     'teID':
                                     self.id
                                 })
                buttons.append(
                    os_gui.get_button(
                        'delete_notext',
                        delete_url,
                        onclick=delete_onclick,
                    ))

            time = SPAN(repr_row.classes.Starttime, ' - ',
                        repr_row.classes.Endtime)

            table.append(
                TR(TD(repr_row.classes.Week_day), TD(time),
                   TD(repr_row.classes.school_classtypes_id),
                   TD(repr_row.classes.school_locations_id),
                   TD(repr_row.teachers_payment_fixed_rate_class.ClassRate),
                   TD(repr_row.teachers_payment_fixed_rate_class.tax_rates_id),
                   TD(buttons)))

        display.append(table)

        return display
Beispiel #10
0
    def get_upcoming_classes_formatted(self, days=3):
        """
            Returns upcoming classes for teacher
        """
        from .os_gui import OsGui
        from .os_class_schedule import ClassSchedule

        T = current.T
        db = current.db
        auth = current.auth
        os_gui = OsGui()
        DATE_FORMAT = current.DATE_FORMAT
        TODAY_LOCAL = current.globalenv['TODAY_LOCAL']

        attendance_permission = (auth.has_membership(group_id='Admins')
                                 or auth.has_permission(
                                     'update', 'classes_attendance'))

        date = TODAY_LOCAL
        delta = datetime.timedelta(days=1)

        header = THEAD(
            TR(
                TH(T('Class date')),
                TH(T('Time')),
                TH(T('Location')),
                TH(T('Class type')),
                TH(T('Teacher')),
                TH(T('Teacher2')),
                TH(),
            ))

        table = TABLE(header, _class='table table-hover')

        for day in range(0, days):
            cs = ClassSchedule(date, filter_id_teacher=self.id)

            rows = cs.get_day_rows()
            for i, row in enumerate(rows):
                if row.classes_otc.Status == 'cancelled' or row.school_holidays.id:
                    continue

                repr_row = list(rows[i:i + 1].render())[0]

                result = cs._get_day_row_teacher_roles(row, repr_row)

                teacher = result['teacher_role']
                teacher2 = result['teacher_role2']

                attendance = ''
                if attendance_permission:
                    attendance = os_gui.get_button(
                        'noicon',
                        URL('classes',
                            'attendance',
                            vars={
                                'clsID': row.classes.id,
                                'date': date.strftime(DATE_FORMAT)
                            }),
                        title=T('Attendance'),
                        _class=T('pull-right'))

                tr = TR(
                    TD(date.strftime(DATE_FORMAT),
                       _class='bold green' if day == 0 else ''),
                    TD(repr_row.classes.Starttime, ' - ',
                       repr_row.classes.Endtime),
                    TD(repr_row.classes.school_locations_id),
                    TD(repr_row.classes.school_classtypes_id), TD(teacher),
                    TD(teacher2), TD(attendance))

                table.append(tr)

            date += delta

        upcoming_classes = DIV(
            DIV(H3(T('My upcoming classes'), _class="box-title"),
                DIV(A(I(_class='fa fa-minus'),
                      _href='#',
                      _class='btn btn-box-tool',
                      _title=T("Collapse"),
                      **{'_data-widget': 'collapse'}),
                    _class='box-tools pull-right'),
                _class='box-header with-border'),
            DIV(table, _class='box-body'),
            self._get_teacher_upcoming_classes_formatted_footer(),
            _class='box box-primary')

        return upcoming_classes
Beispiel #11
0
    def get_subrequests_formatted(self):
        """
        :return: HTML table holding subrequests this teacher can apply for
        """
        from .os_class import Class
        from .os_gui import OsGui

        os_gui = OsGui()

        T = current.T
        db = current.db
        auth = current.auth
        TODAY_LOCAL = current.TODAY_LOCAL

        header = THEAD(
            TR(TH(T('Class date')), TH(T('Time')), TH(T('Location')),
               TH(T('Class type')), TH()))

        table = TABLE(header, _class='table table-hover')

        # Get classtypes for currently logged on teacher
        query = (db.teachers_classtypes.auth_user_id == self.id)
        rows = db(query).select(db.teachers_classtypes.school_classtypes_id)
        ctIDs = [row.school_classtypes_id for row in rows]

        left = [
            db.classes.on(db.classes_otc.classes_id == db.classes.id, ),
            db.school_locations.on(
                db.classes.school_locations_id == db.school_locations.id)
        ]

        query = (db.classes_otc.Status == 'open') & \
                ((db.classes.school_classtypes_id.belongs(ctIDs)) |
                  (db.classes_otc.school_classtypes_id.belongs(ctIDs))) & \
                 (db.classes_otc.ClassDate >= TODAY_LOCAL)

        rows = db(query).select(db.classes_otc.ALL,
                                db.classes.ALL,
                                left=left,
                                orderby=db.classes_otc.ClassDate
                                | db.classes.Starttime
                                | db.school_locations.Name)

        for i, row in enumerate(rows):
            repr_row = list(rows[i:i + 1].render())[0]
            row_avail = db.classes_otc_sub_avail(
                classes_otc_id=row.classes_otc.id,
                auth_teacher_id=auth.user.id)

            date = row.classes_otc.ClassDate
            clsID = row.classes.id
            cls = Class(clsID, date)
            regular_teachers = cls.get_regular_teacher_ids()

            if regular_teachers['auth_teacher_id'] == self.id:
                continue

            if not row_avail:
                button = os_gui.get_button(
                    'noicon',
                    URL('ep',
                        'available_for_sub',
                        vars={'cotcID': row.classes_otc.id}),
                    title=T("I'm available"),
                    _class='pull-right',
                    btn_class='btn-success')
            else:
                button = os_gui.get_button('noicon',
                                           URL('ep',
                                               'cancel_available_for_sub',
                                               vars={'cotcsaID':
                                                     row_avail.id}),
                                           title=T("I'm no longer available"),
                                           _class='pull-right',
                                           btn_class='btn-warning')
            tr = TR(
                TD(repr_row.classes_otc.ClassDate),
                TD(repr_row.classes.Starttime, ' - ',
                   repr_row.classes.Endtime),
                TD(repr_row.classes.school_locations_id),
                TD(repr_row.classes.school_classtypes_id), TD(button))
            table.append(tr)

        if not len(rows):
            table = T("No one is looking for a sub at the moment...")

        sub_requests = DIV(DIV(H3(T('Can you sub a class?'),
                                  _class="box-title"),
                               DIV(A(I(_class='fa fa-minus'),
                                     _href='#',
                                     _class='btn btn-box-tool',
                                     _title=T("Collapse"),
                                     **{'_data-widget': 'collapse'}),
                                   _class='box-tools pull-right'),
                               _class='box-header with-border'),
                           DIV(table, _class='box-body'),
                           _class='box box-success')

        return sub_requests
Beispiel #12
0
    def classes_add_get_list(self, date, list_type, cuID=None, teID=None):
        """
            Get list of classes for a date
            list_type is expected to be in
            [ 'attendance', 'reservations', 'tp_fixed_rate' ]
        """
        from .os_attendance_helper import AttendanceHelper
        from .os_class_schedule import ClassSchedule
        from .os_gui import OsGui

        T = current.T
        db = current.db
        os_gui = OsGui()
        DATE_FORMAT = current.DATE_FORMAT
        session = current.session

        if list_type == 'attendance':
            session.classes_attendance_signin_back = 'cu_classes_attendance'
            ah = AttendanceHelper()
            # links = [ lambda row: ah.get_signin_buttons(row.classes.id, date, cuID) ]

        if session.classes_schedule_sort == 'location':
            orderby = db.school_locations.Name | db.classes.Starttime
        elif session.classes_schedule_sort == 'starttime':
            orderby = db.classes.Starttime | db.school_locations.Name
        else:
            orderby = db.school_locations.Name | db.classes.Starttime

        filter_id_teacher = None
        if list_type == 'tp_fixed_rate':
            filter_id_teacher = cuID
        cs = ClassSchedule(date,
                           sorting=orderby,
                           filter_id_teacher=filter_id_teacher)
        classes = cs.get_day_list()

        header = THEAD(TR(TH(T('Time')),
                          TH(T('Location')),
                          TH(T('Class')),
                          TH(),
                          TH()  # buttons
                          ))
        table = TABLE(header, _class='table table-striped table-hover')
        for c in classes:
            status = self._classes_add_get_list_get_cancelled_holiday(c)
            buttons = ''

            if list_type == 'reservations':
                buttons = self._classes_reservation_add_get_button(c['ClassesID'])
            elif list_type == 'attendance' and status == '':
                buttons = os_gui.get_button('noicon',
                                            URL('customers', 'classes_attendance_add_booking_options',
                                                vars={'cuID': cuID,
                                                      'clsID': c['ClassesID'],
                                                      'date': date.strftime(DATE_FORMAT)}),
                                            title='Check in',
                                            _class='pull-right')
            elif list_type == 'tp_fixed_rate':
                buttons = os_gui.get_button(
                    'noicon',
                    URL('teachers',
                        'payment_fixed_rate_class',
                        vars={'teID': teID,
                              'clsID': c['ClassesID']}),
                    title=T('Set rate'),
                    _class='pull-right'
                )

            tr = TR(
                TD(c['Starttime'], ' - ', c['Endtime']),
                TD(c['Location']),
                TD(c['ClassType']),
                TD(status),
                TD(buttons)
            )

            table.append(tr)

        return table