def fees_by_events_view(self):
        from_date = request.args.get('from_date')
        to_date = request.args.get('to_date')

        if ('from_date' in request.args and not from_date) or ('to_date' in request.args and not to_date) or \
            ('from_date' in request.args and 'to_date' not in request.args) or \
                ('to_date' in request.args and 'from_date' not in request.args):

            return redirect(url_for('.fees_by_events_view'))

        marketer_role = CustomSysRole.query.filter_by(name='Marketer').first()
        marketer_id = login.current_user.id if login.current_user.is_sys_role(
            marketer_role.id) else None

        if from_date and to_date:
            orders = TicketingManager.get_orders(
                from_date=datetime.strptime(from_date, '%d/%m/%Y'),
                to_date=datetime.strptime(to_date, '%d/%m/%Y'),
                status='completed',
                marketer_id=marketer_id)
        else:
            orders = TicketingManager.get_orders(status='completed',
                                                 marketer_id=marketer_id)

        events = DataGetter.get_all_events()

        fee_summary = {}
        for event in events:
            fee_summary[str(event.id)] = {
                'name': event.name,
                'payment_currency': event.payment_currency,
                'fee_rate': get_fee(event.payment_currency),
                'fee_amount': 0,
                'tickets_count': 0
            }

        fee_total = 0
        tickets_total = 0

        for order in orders:
            for order_ticket in order.tickets:
                fee_summary[str(
                    order.event.id)]['tickets_count'] += order_ticket.quantity
                tickets_total += order_ticket.quantity
                ticket = CachedGetter.get_ticket(order_ticket.ticket_id)
                if order.paid_via != 'free' and order.amount > 0 and ticket.price > 0:
                    fee = ticket.price * (
                        get_fee(order.event.payment_currency) / 100)
                    fee = forex(order.event.payment_currency,
                                self.display_currency, fee)
                    fee_summary[str(order.event.id)]['fee_amount'] += fee
                    fee_total += fee

        return self.render('/gentelella/admin/super_admin/sales/fees.html',
                           fee_summary=fee_summary,
                           display_currency=self.display_currency,
                           from_date=from_date,
                           to_date=to_date,
                           tickets_total=tickets_total,
                           fee_total=fee_total)
def fees_by_events_view():
    from_date = request.args.get('from_date')
    to_date = request.args.get('to_date')

    if ('from_date' in request.args and not from_date) or ('to_date' in request.args and not to_date) or \
        ('from_date' in request.args and 'to_date' not in request.args) or \
        ('to_date' in request.args and 'from_date' not in request.args):
        return redirect(url_for('.fees_by_events_view'))

    marketer_role = CustomSysRole.query.filter_by(name='Marketer').first()
    marketer_id = login.current_user.id if login.current_user.is_sys_role(marketer_role.id) else None

    if from_date and to_date:
        orders = TicketingManager.get_orders(
            from_date=datetime.strptime(from_date, '%d/%m/%Y'),
            to_date=datetime.strptime(to_date, '%d/%m/%Y'),
            status='completed',
            marketer_id=marketer_id
        )
    else:
        orders = TicketingManager.get_orders(status='completed', marketer_id=marketer_id)

    events = DataGetter.get_all_events()

    fee_summary = {}
    for event in events:
        fee_summary[str(event.id)] = {
            'name': event.name,
            'payment_currency': event.payment_currency,
            'fee_rate': get_fee(event.payment_currency),
            'fee_amount': 0,
            'tickets_count': 0
        }

    fee_total = 0
    tickets_total = 0

    for order in orders:
        if order.event:
            for order_ticket in order.tickets:
                fee_summary[str(order.event.id)]['tickets_count'] += order_ticket.quantity
                tickets_total += order_ticket.quantity
                ticket = CachedGetter.get_ticket(order_ticket.ticket_id)
                if order.paid_via != 'free' and order.amount > 0 and ticket.price > 0:
                    fee = ticket.price * (get_fee(order.event.payment_currency) / 100)
                    fee = forex(order.event.payment_currency, display_currency, fee)
                    fee_summary[str(order.event.id)]['fee_amount'] += fee
                    fee_total += fee

    return render_template('gentelella/super_admin/sales/fees.html',
                           fee_summary=fee_summary,
                           display_currency=display_currency,
                           from_date=from_date,
                           to_date=to_date,
                           tickets_total=tickets_total,
                           fee_total=fee_total,
                           navigation_bar=list_navbar())
    def fees_by_events_view(self):
        from_date = request.args.get('from_date')
        to_date = request.args.get('to_date')

        if ('from_date' in request.args and not from_date) or ('to_date' in request.args and not to_date) or \
            ('from_date' in request.args and 'to_date' not in request.args) or \
                ('to_date' in request.args and 'from_date' not in request.args):

            return redirect(url_for('.fees_by_events_view'))

        if from_date and to_date:
            orders = TicketingManager.get_orders(
                from_date=datetime.strptime(from_date, '%d/%m/%Y'),
                to_date=datetime.strptime(to_date, '%d/%m/%Y'),
                status='completed'
            )
        else:
            orders = TicketingManager.get_orders(status='completed')

        events = DataGetter.get_all_events()

        fee_summary = {}
        for event in events:
            fee_summary[str(event.id)] = {
                'name': event.name,
                'payment_currency': event.payment_currency,
                'fee_rate': get_fee(event.payment_currency),
                'fee_amount': 0,
                'tickets_count': 0
            }

        fee_total = 0
        tickets_total = 0

        for order in orders:
            for order_ticket in order.tickets:
                fee_summary[str(order.event.id)]['tickets_count'] += order_ticket.quantity
                tickets_total += order_ticket.quantity
                ticket = TicketingManager.get_ticket(order_ticket.ticket_id)
                if order.paid_via != 'free' and order.amount > 0 and ticket.price > 0:
                    fee = ticket.price * (get_fee(order.event.payment_currency)/100)
                    fee = forex(order.event.payment_currency, self.display_currency, fee)
                    fee_summary[str(order.event.id)]['fee_amount'] += fee
                    fee_total += fee

        return self.render('/gentelella/admin/super_admin/sales/fees.html',
                           fee_summary=fee_summary,
                           display_currency=self.display_currency,
                           from_date=from_date,
                           to_date=to_date,
                           tickets_total=tickets_total,
                           fee_total=fee_total)
def sales_by_events_view(path):
    from_date = request.args.get('from_date')
    to_date = request.args.get('to_date')

    if ('from_date' in request.args and not from_date) or ('to_date' in request.args and not to_date) or \
        ('from_date' in request.args and 'to_date' not in request.args) or \
        ('to_date' in request.args and 'from_date' not in request.args):
        return redirect(url_for('.sales_by_events_view', path=path))

    promoted_events = path == 'discounted-events'

    if from_date and to_date:
        orders = TicketingManager.get_orders(
            from_date=datetime.strptime(from_date, '%d/%m/%Y'),
            to_date=datetime.strptime(to_date, '%d/%m/%Y'),
            promoted_event=promoted_events
        )
    else:
        orders = TicketingManager.get_orders(promoted_event=promoted_events)

    if promoted_events:
        events = DataGetter.get_all_events_with_discounts()
    else:
        events = DataGetter.get_all_events()

    orders_summary = {
        'completed': {
            'class': 'success',
            'tickets_count': 0,
            'orders_count': 0,
            'total_sales': 0
        },
        'placed': {
            'class': 'info',
            'tickets_count': 0,
            'orders_count': 0,
            'total_sales': 0
        },
        'pending': {
            'class': 'warning',
            'tickets_count': 0,
            'orders_count': 0,
            'total_sales': 0
        },
        'expired': {
            'class': 'danger',
            'tickets_count': 0,
            'orders_count': 0,
            'total_sales': 0
        },
        'deleted': {
            'class': 'primary',
            'tickets_count': 0,
            'orders_count': 0,
            'total_sales': 0
        },
        'cancelled': {
            'class': 'default',
            'tickets_count': 0,
            'orders_count': 0,
            'total_sales': 0
        }
    }

    tickets_summary_event_wise = {}
    tickets_summary_organizer_wise = {}
    tickets_summary_location_wise = {}

    for event in events:
        tickets_summary_event_wise[str(event.id)] = {
            'name': event.name,
            'payment_currency': event.payment_currency,
            'marketer': '',
            'discount_code': '',
            'live_url': url_for('event_detail.display_event_detail_home', identifier=event.identifier).replace('events',
                                                                                                               'e'),
            'event_url': url_for('events.details_view', event_id=event.id),
            'start_time': event.start_time,
            'end_time': event.end_time,
            'completed': {
                'tickets_count': 0,
                'sales': 0
            },
            'placed': {
                'tickets_count': 0,
                'sales': 0
            },
            'pending': {
                'tickets_count': 0,
                'sales': 0
            },
            'expired': {
                'class': 'danger',
                'tickets_count': 0,
                'sales': 0
            },
            'cancelled': {
                'tickets_count': 0,
                'sales': 0
            },
            'deleted': {
                'tickets_count': 0,
                'sales': 0
            },
        }
        organizer = DataGetter.get_user_event_roles_by_role_name(event.id, 'organizer').first()

        if promoted_events:
            tickets_summary_event_wise[str(event.id)]['marketer'] = \
                event.discount_code.marketer.email
            tickets_summary_event_wise[str(event.id)]['discount_code'] = \
                str(event.discount_code.value) + '% off for ' + str(event.discount_code.max_quantity) + ' months'

        tickets_summary_organizer_wise[str(organizer.user.id)] = \
            copy.deepcopy(tickets_summary_event_wise[str(event.id)])
        if organizer:
            tickets_summary_organizer_wise[str(organizer.user.id)]['name'] = organizer.user.email

        tickets_summary_location_wise[unicode(event.searchable_location_name)] = \
            copy.deepcopy(tickets_summary_event_wise[str(event.id)])
        tickets_summary_location_wise[unicode(event.searchable_location_name)]['name'] = \
            event.searchable_location_name

    for order in orders:
        if order.event:
            if order.status == 'initialized':
                order.status = 'pending'
            orders_summary[str(order.status)]['orders_count'] += 1
            orders_summary[str(order.status)]['total_sales'] += forex(order.event.payment_currency,
                                                                      display_currency, order.amount)
            for order_ticket in order.tickets:
                discount = TicketingManager.get_discount_code(order.event_id, order.discount_code_id)
                orders_summary[str(order.status)]['tickets_count'] += order_ticket.quantity
                ticket = CachedGetter.get_ticket(order_ticket.ticket_id)
                tickets_summary_event_wise[str(order.event_id)][str(order.status)]['tickets_count'] \
                    += order_ticket.quantity
                tickets_summary_organizer_wise[str(organizer.user.id)][str(order.status)]['tickets_count'] \
                    += order_ticket.quantity
                tickets_summary_location_wise[unicode(order.event.searchable_location_name)][str(order.status)][
                    'tickets_count'] \
                    += order_ticket.quantity

                if order.paid_via != 'free' and order.amount > 0:
                    if discount and str(ticket.id) in discount.tickets.split(","):
                        if discount.type == "amount":
                            tickets_summary_event_wise[str(order.event_id)][str(order.status)][
                                'sales'] += forex(order.event.payment_currency, display_currency, \
                                            order_ticket.quantity * (ticket.price - discount.value))
                            tickets_summary_organizer_wise[str(organizer.user.id)][str(order.status)][
                                'sales'] += forex(order.event.payment_currency, display_currency, \
                                            order_ticket.quantity * (ticket.price - discount.value))
                            tickets_summary_location_wise[str(order.event.searchable_location_name)][str(order.status)][
                                'sales'] += forex(order.event.payment_currency, display_currency, \
                                            order_ticket.quantity * (ticket.price - discount.value))
                        else:
                            tickets_summary_event_wise[str(order.event_id)][str(order.status)]['sales'] += \
                                forex(order.event.payment_currency, display_currency, \
                                    order_ticket.quantity * (ticket.price - discount.value * ticket.price / 100.0))
                            tickets_summary_organizer_wise[str(organizer.user.id)][str(order.status)]['sales'] += \
                                forex(order.event.payment_currency, display_currency, \
                                    order_ticket.quantity * (ticket.price - discount.value * ticket.price / 100.0))
                            tickets_summary_location_wise[str(order.event.searchable_location_name)][str(order.status)]['sales'] += \
                                forex(order.event.payment_currency, display_currency, \
                                    order_ticket.quantity * (ticket.price - discount.value * ticket.price / 100.0))
                    else:
                        tickets_summary_event_wise[str(order.event_id)][str(order.status)][
                            'sales'] += forex(order.event.payment_currency, display_currency, order_ticket.quantity * ticket.price)
                        tickets_summary_organizer_wise[str(organizer.user.id)][str(order.status)][
                            'sales'] += forex(order.event.payment_currency, display_currency, order_ticket.quantity * ticket.price)
                        tickets_summary_location_wise[str(order.event.searchable_location_name)][str(order.status)][
                            'sales'] += forex(order.event.payment_currency, display_currency, order_ticket.quantity * ticket.price)
    if path == 'events' or path == 'discounted-events':
        return render_template(
            'gentelella/super_admin/sales/by_events.html',
            tickets_summary=tickets_summary_event_wise,
            display_currency=display_currency,
            from_date=from_date,
            to_date=to_date,
            path=path,
            orders_summary=orders_summary,
            navigation_bar=list_navbar())
    elif path == 'organizers':
        return render_template(
            'gentelella/super_admin/sales/by_organizer.html',
            tickets_summary=tickets_summary_organizer_wise,
            display_currency=display_currency,
            from_date=from_date,
            to_date=to_date,
            path=path,
            orders_summary=orders_summary,
            navigation_bar=list_navbar())
    elif path == 'locations':
        return render_template(
            'gentelella/super_admin/sales/by_location.html',
            tickets_summary=tickets_summary_location_wise,
            display_currency=display_currency,
            from_date=from_date,
            to_date=to_date,
            path=path,
            orders_summary=orders_summary,
            navigation_bar=list_navbar())

    else:
        abort(404)
    def sales_by_events_view(self, path):

        from_date = request.args.get('from_date')
        to_date = request.args.get('to_date')

        if ('from_date' in request.args and not from_date) or ('to_date' in request.args and not to_date) or \
            ('from_date' in request.args and 'to_date' not in request.args) or \
                ('to_date' in request.args and 'from_date' not in request.args):

            return redirect(url_for('.sales_by_events_view', path=path))

        promoted_events = path == 'promoted-events'

        if from_date and to_date:
            orders = TicketingManager.get_orders(
                from_date=datetime.strptime(from_date, '%d/%m/%Y'),
                to_date=datetime.strptime(to_date, '%d/%m/%Y'),
                promoted_event=promoted_events)
        else:
            orders = TicketingManager.get_orders(
                promoted_event=promoted_events)

        if promoted_events:
            events = DataGetter.get_all_events_with_discounts()
        else:
            events = DataGetter.get_all_events()

        completed_count = 0
        completed_amount = 0
        tickets_count = 0

        orders_summary = {
            'completed': {
                'class': 'success',
                'tickets_count': 0,
                'orders_count': 0,
                'total_sales': 0
            },
            'pending': {
                'class': 'warning',
                'tickets_count': 0,
                'orders_count': 0,
                'total_sales': 0
            },
            'expired': {
                'class': 'danger',
                'tickets_count': 0,
                'orders_count': 0,
                'total_sales': 0
            }
        }

        tickets_summary_event_wise = {}
        tickets_summary_organizer_wise = {}
        tickets_summary_location_wise = {}

        for event in events:
            tickets_summary_event_wise[str(event.id)] = {
                'name': event.name,
                'payment_currency': event.payment_currency,
                'marketer': '',
                'discount_code': '',
                'completed': {
                    'tickets_count': 0,
                    'sales': 0
                },
                'pending': {
                    'tickets_count': 0,
                    'sales': 0
                },
                'expired': {
                    'class': 'danger',
                    'tickets_count': 0,
                    'sales': 0
                }
            }

            if promoted_events:
                tickets_summary_event_wise[str(event.id)]['marketer'] = \
                    event.discount_code.marketer.email
                tickets_summary_event_wise[str(event.id)]['discount_code'] = \
                    str(event.discount_code.value) + '% off for ' + str(event.discount_code.max_quantity) + ' months'

            tickets_summary_organizer_wise[str(event.creator_id)] = \
                copy.deepcopy(tickets_summary_event_wise[str(event.id)])
            if event.creator:
                tickets_summary_organizer_wise[str(
                    event.creator_id)]['name'] = event.creator.email

            tickets_summary_location_wise[unicode(event.searchable_location_name)] = \
                copy.deepcopy(tickets_summary_event_wise[str(event.id)])
            tickets_summary_location_wise[unicode(event.searchable_location_name)]['name'] = \
                event.searchable_location_name

        for order in orders:
            if order.status == 'initialized':
                order.status = 'pending'
            orders_summary[str(order.status)]['orders_count'] += 1
            orders_summary[str(order.status)]['total_sales'] += forex(
                order.event.payment_currency, self.display_currency,
                order.amount)
            for order_ticket in order.tickets:
                orders_summary[str(
                    order.status)]['tickets_count'] += order_ticket.quantity
                ticket = CachedGetter.get_ticket(order_ticket.ticket_id)
                tickets_summary_event_wise[str(order.event_id)][str(order.status)]['tickets_count'] \
                    += order_ticket.quantity
                tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['tickets_count'] \
                    += order_ticket.quantity
                tickets_summary_location_wise[str(order
                                                  .event.searchable_location_name)][str(order
                                                                                        .status)]['tickets_count'] \
                    += order_ticket.quantity

                if order.paid_via != 'free' and order.amount > 0:
                    tickets_summary_event_wise[str(order.event_id)][str(order.status)]['sales'] += \
                        order_ticket.quantity * ticket.price
                    tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['sales'] += \
                        order_ticket.quantity * ticket.price
                    tickets_summary_location_wise[str(order.event.
                                                      searchable_location_name)][str(order.
                                                                                     status)]['sales'] += \
                        order_ticket.quantity * ticket.price

        if path == 'events' or path == 'promoted-events':
            return self.render(
                '/gentelella/admin/super_admin/sales/by_events.html',
                tickets_summary=tickets_summary_event_wise,
                display_currency=self.display_currency,
                from_date=from_date,
                to_date=to_date,
                path=path,
                orders_summary=orders_summary)
        elif path == 'organizers':
            return self.render(
                '/gentelella/admin/super_admin/sales/by_organizer.html',
                tickets_summary=tickets_summary_organizer_wise,
                display_currency=self.display_currency,
                from_date=from_date,
                to_date=to_date,
                path=path,
                orders_summary=orders_summary)
        elif path == 'locations':
            return self.render(
                '/gentelella/admin/super_admin/sales/by_location.html',
                tickets_summary=tickets_summary_location_wise,
                display_currency=self.display_currency,
                from_date=from_date,
                to_date=to_date,
                path=path,
                orders_summary=orders_summary)

        else:
            abort(404)
示例#6
0
def sales_by_events_view(path):
    from_date = request.args.get('from_date')
    to_date = request.args.get('to_date')

    if ('from_date' in request.args and not from_date) or ('to_date' in request.args and not to_date) or \
        ('from_date' in request.args and 'to_date' not in request.args) or \
        ('to_date' in request.args and 'from_date' not in request.args):
        return redirect(url_for('.sales_by_events_view', path=path))

    promoted_events = path == 'promoted-events'

    if from_date and to_date:
        orders = TicketingManager.get_orders(
            from_date=datetime.strptime(from_date, '%d/%m/%Y'),
            to_date=datetime.strptime(to_date, '%d/%m/%Y'),
            promoted_event=promoted_events
        )
    else:
        orders = TicketingManager.get_orders(promoted_event=promoted_events)

    if promoted_events:
        events = DataGetter.get_all_events_with_discounts()
    else:
        events = DataGetter.get_all_events()

    orders_summary = {
        'completed': {
            'class': 'success',
            'tickets_count': 0,
            'orders_count': 0,
            'total_sales': 0
        },
        'pending': {
            'class': 'warning',
            'tickets_count': 0,
            'orders_count': 0,
            'total_sales': 0
        },
        'expired': {
            'class': 'danger',
            'tickets_count': 0,
            'orders_count': 0,
            'total_sales': 0
        }
    }

    tickets_summary_event_wise = {}
    tickets_summary_organizer_wise = {}
    tickets_summary_location_wise = {}

    for event in events:
        tickets_summary_event_wise[str(event.id)] = {
            'name': event.name,
            'payment_currency': event.payment_currency,
            'marketer': '',
            'discount_code': '',
            'completed': {
                'tickets_count': 0,
                'sales': 0
            },
            'pending': {
                'tickets_count': 0,
                'sales': 0
            },
            'expired': {
                'class': 'danger',
                'tickets_count': 0,
                'sales': 0
            }
        }

        if promoted_events:
            tickets_summary_event_wise[str(event.id)]['marketer'] = \
                event.discount_code.marketer.email
            tickets_summary_event_wise[str(event.id)]['discount_code'] = \
                str(event.discount_code.value) + '% off for ' + str(event.discount_code.max_quantity) + ' months'

        tickets_summary_organizer_wise[str(event.creator_id)] = \
            copy.deepcopy(tickets_summary_event_wise[str(event.id)])
        if event.creator:
            tickets_summary_organizer_wise[str(event.creator_id)]['name'] = event.creator.email

        tickets_summary_location_wise[unicode(event.searchable_location_name)] = \
            copy.deepcopy(tickets_summary_event_wise[str(event.id)])
        tickets_summary_location_wise[unicode(event.searchable_location_name)]['name'] = \
            event.searchable_location_name

    for order in orders:
        if order.status == 'initialized':
            order.status = 'pending'
        orders_summary[str(order.status)]['orders_count'] += 1
        orders_summary[str(order.status)]['total_sales'] += forex(order.event.payment_currency,
                                                                  display_currency, order.amount)
        for order_ticket in order.tickets:
            orders_summary[str(order.status)]['tickets_count'] += order_ticket.quantity
            ticket = CachedGetter.get_ticket(order_ticket.ticket_id)
            tickets_summary_event_wise[str(order.event_id)][str(order.status)]['tickets_count'] \
                += order_ticket.quantity
            tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['tickets_count'] \
                += order_ticket.quantity
            tickets_summary_location_wise[str(order
                                              .event.searchable_location_name)][str(order
                                                                                    .status)]['tickets_count'] \
                += order_ticket.quantity

            if order.paid_via != 'free' and order.amount > 0:
                tickets_summary_event_wise[str(order.event_id)][str(order.status)]['sales'] += \
                    order_ticket.quantity * ticket.price
                tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['sales'] += \
                    order_ticket.quantity * ticket.price
                tickets_summary_location_wise[str(order.event.
                                                  searchable_location_name)][str(order.
                                                                                 status)]['sales'] += \
                    order_ticket.quantity * ticket.price

    if path == 'events' or path == 'promoted-events':
        return render_template('gentelella/admin/super_admin/sales/by_events.html',
                               tickets_summary=tickets_summary_event_wise,
                               display_currency=display_currency,
                               from_date=from_date,
                               to_date=to_date,
                               path=path,
                               orders_summary=orders_summary,
                               navigation_bar=list_navbar())
    elif path == 'organizers':
        return render_template('gentelella/admin/super_admin/sales/by_organizer.html',
                               tickets_summary=tickets_summary_organizer_wise,
                               display_currency=display_currency,
                               from_date=from_date,
                               to_date=to_date,
                               path=path,
                               orders_summary=orders_summary,
                               navigation_bar=list_navbar())
    elif path == 'locations':
        return render_template('gentelella/admin/super_admin/sales/by_location.html',
                               tickets_summary=tickets_summary_location_wise,
                               display_currency=display_currency,
                               from_date=from_date,
                               to_date=to_date,
                               path=path,
                               orders_summary=orders_summary,
                               navigation_bar=list_navbar())

    else:
        abort(404)
    def sales_by_events_view(self, path):

        from_date = request.args.get('from_date')
        to_date = request.args.get('to_date')

        if ('from_date' in request.args and not from_date) or ('to_date' in request.args and not to_date) or \
            ('from_date' in request.args and 'to_date' not in request.args) or \
                ('to_date' in request.args and 'from_date' not in request.args):

            return redirect(url_for('.sales_by_events_view', path=path))

        if from_date and to_date:
            orders = TicketingManager.get_orders(
                from_date=datetime.strptime(from_date, '%d/%m/%Y'),
                to_date=datetime.strptime(to_date, '%d/%m/%Y')
            )
        else:
            orders = TicketingManager.get_orders()

        events = DataGetter.get_all_events()

        completed_count = 0
        completed_amount = 0
        tickets_count = 0

        orders_summary = {
            'completed': {
                'class': 'success',
                'tickets_count': 0,
                'orders_count': 0,
                'total_sales': 0
            },
            'pending': {
                'class': 'warning',
                'tickets_count': 0,
                'orders_count': 0,
                'total_sales': 0
            },
            'expired': {
                'class': 'danger',
                'tickets_count': 0,
                'orders_count': 0,
                'total_sales': 0
            }
        }

        tickets_summary_event_wise = {}
        tickets_summary_organizer_wise = {}
        tickets_summary_location_wise = {}
        for event in events:
            tickets_summary_event_wise[str(event.id)] = {
                'name': event.name,
                'payment_currency': event.payment_currency,
                'completed': {
                    'tickets_count': 0,
                    'sales': 0
                },
                'pending': {
                    'tickets_count': 0,
                    'sales': 0
                },
                'expired': {
                    'class': 'danger',
                    'tickets_count': 0,
                    'sales': 0
                }
            }
            tickets_summary_organizer_wise[str(event.creator_id)] = \
                copy.deepcopy(tickets_summary_event_wise[str(event.id)])
            if event.creator:
                tickets_summary_organizer_wise[str(event.creator_id)]['name'] = event.creator.email

            tickets_summary_location_wise[unicode(event.searchable_location_name)] = \
                copy.deepcopy(tickets_summary_event_wise[str(event.id)])
            tickets_summary_location_wise[unicode(event.searchable_location_name)]['name'] = \
                event.searchable_location_name

        for order in orders:
            if order.status == 'initialized':
                order.status = 'pending'
            orders_summary[str(order.status)]['orders_count'] += 1
            orders_summary[str(order.status)]['total_sales'] += forex(order.event.payment_currency,
                                                                      self.display_currency, order.amount)
            for order_ticket in order.tickets:
                orders_summary[str(order.status)]['tickets_count'] += order_ticket.quantity
                ticket = TicketingManager.get_ticket(order_ticket.ticket_id)
                tickets_summary_event_wise[str(order.event_id)][str(order.status)]['tickets_count'] \
                    += order_ticket.quantity
                tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['tickets_count'] \
                    += order_ticket.quantity
                tickets_summary_location_wise[str(order
                                                  .event.searchable_location_name)][str(order
                                                                                        .status)]['tickets_count'] \
                    += order_ticket.quantity

                if order.paid_via != 'free' and order.amount > 0:
                    tickets_summary_event_wise[str(order.event_id)][str(order.status)]['sales'] += \
                        order_ticket.quantity * ticket.price
                    tickets_summary_organizer_wise[str(order.event.creator_id)][str(order.status)]['sales'] += \
                        order_ticket.quantity * ticket.price
                    tickets_summary_location_wise[str(order.event.
                                                      searchable_location_name)][str(order.
                                                                                     status)]['sales'] += \
                        order_ticket.quantity * ticket.price

        if path == 'events':
            return self.render('/gentelella/admin/super_admin/sales/by_events.html',
                               tickets_summary=tickets_summary_event_wise,
                               display_currency=self.display_currency,
                               from_date=from_date,
                               to_date=to_date,
                               orders_summary=orders_summary)
        elif path == 'organizers':
            return self.render('/gentelella/admin/super_admin/sales/by_organizer.html',
                               tickets_summary=tickets_summary_organizer_wise,
                               display_currency=self.display_currency,
                               from_date=from_date,
                               to_date=to_date,
                               orders_summary=orders_summary)
        elif path == 'locations':
            return self.render('/gentelella/admin/super_admin/sales/by_location.html',
                               tickets_summary=tickets_summary_location_wise,
                               display_currency=self.display_currency,
                               from_date=from_date,
                               to_date=to_date,
                               orders_summary=orders_summary)

        else:
            abort(404)