Repository: fossasia/open-event-server

Issue:
Add widget "tickets" to event dashboard
Show a widget with basic ticketing info in the dashboard of event at `/events/event-id` including:
* List of tickets with available and sold tickets
* Number of overall sold tickets
* Number of orders
* Sales


Discussion:
@mariobehling You mean to add the widget to the Overview tab under /events/event-id  which have the general info?
> add the widget to the Overview tab under /events/event-id which have the general info

@yasirunilan Yes, correct.
Thanks @mariobehling  I will start working on this
I created a UI prototype, is this the requirement ?
![screenshot from 2017-02-04 01 59 53](https://cloud.githubusercontent.com/assets/9814784/22617603/1d0c1084-ea7e-11e6-8af4-eac8c374fec7.png)

any feedback for this one?
@yasirunilan 

- Align the columns.
- Add the total sold to the first table as a footer below the sold column. 
- Add a total Available to the same footer. 
- And sales should be an amount. Show the amount in a formatted way(comma separated digit grouping)  with the proper currency symbol. 
@niranjan94 I would like to work on this and complete it. are these changes made by @yasirunilan in the development branch ? 

I'm still working on this @Himanshi-Khandelwal 
:+1: 
@niranjan94 @mariobehling 
Does it suffice ? 
Or something else should also be added to the info .

![ticket](https://cloud.githubusercontent.com/assets/17861054/26248625/b8f13b02-3cc0-11e7-9383-003d4a39c32a.png)

Resolving patch:
diff --git a/app/views/users/events.py b/app/views/users/events.py
--- a/app/views/users/events.py
+++ b/app/views/users/events.py
@@ -29,6 +29,7 @@
 from app.helpers.wizard.sponsors import get_sponsors_json, save_sponsors_from_json
 from app.models.call_for_papers import CallForPaper
 from app.settings import get_settings
+from app.views.users.ticket_sales import get_ticket
 
 
 def get_random_hash():
@@ -109,6 +110,7 @@ def create_image_upload():
 @can_access
 def details_view(event_id):
     event = DataGetter.get_event(event_id)
+    orders = TicketingManager.get_orders(event_id)
     checklist = {"": ""}
 
     if fields_not_empty(event,
@@ -188,11 +190,106 @@ def details_view(event_id):
                 'accepted': get_count(DataGetter.get_sessions_by_state_and_event_id('accepted', event_id)),
                 'rejected': get_count(DataGetter.get_sessions_by_state_and_event_id('rejected', event_id)),
                 'draft': get_count(DataGetter.get_sessions_by_state_and_event_id('draft', event_id))}
+    tickets_summary = {}
+
+    for ticket in event.tickets:
+        tickets_summary[str(ticket.id)] = {
+            'name': ticket.name,
+            'quantity': ticket.quantity,
+            '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
+            },
+            'deleted': {
+                'tickets_count': 0,
+                'sales': 0
+            },
+            'cancelled': {
+                'tickets_count': 0,
+                'sales': 0
+            },
+        }
+
+    orders_summary = {
+        'completed': {
+            'tickets_count': 0,
+            'orders_count': 0,
+            'total_sales': 0
+        },
+        'placed': {
+            'tickets_count': 0,
+            'orders_count': 0,
+            'total_sales': 0
+        },
+        'pending': {
+            'tickets_count': 0,
+            'orders_count': 0,
+            'total_sales': 0
+        },
+        'expired': {
+            'tickets_count': 0,
+            'orders_count': 0,
+            'total_sales': 0
+        },
+        'deleted': {
+            'tickets_count': 0,
+            'orders_count': 0,
+            'total_sales': 0
+        },
+        'cancelled': {
+            'tickets_count': 0,
+            'orders_count': 0,
+            'total_sales': 0
+        }
+    }
 
+    for order in orders:
+        fees = DataGetter.get_fee_settings_by_currency(DataGetter.get_event(order.event_id).payment_currency)
+        orders_summary[str(order.status)]['orders_count'] += 1
+        orders_summary[str(order.status)]['total_sales'] += order.amount
+
+        for order_ticket in order.tickets:
+            discount = TicketingManager.get_discount_code(event_id, order.discount_code_id)
+            orders_summary[str(order.status)]['tickets_count'] += order_ticket.quantity
+            ticket = get_ticket(order_ticket.ticket_id)
+            tickets_summary[str(ticket.id)][str(order.status)]['tickets_count'] += order_ticket.quantity
+            ticket_price = ticket.price
+            if fees and not ticket.absorb_fees:
+                order_fee = fees.service_fee * (ticket.price * order_ticket.quantity) / 100.0
+                if order_fee > fees.maximum_fee:
+                    ticket_price = ticket.price + fees.maximum_fee / order_ticket.quantity
+                else:
+                    ticket_price = ticket.price + fees.service_fee * ticket.price / 100.0
+
+            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[str(ticket.id)][str(order.status)]['sales'] += order_ticket.quantity * (
+                            ticket_price - discount.value)
+                    else:
+                        tickets_summary[str(ticket.id)][str(order.status)]['sales'] += order_ticket.quantity * (
+                            ticket_price - discount.value * ticket_price / 100.0)
+                else:
+                    tickets_summary[str(ticket.id)][str(order.status)]['sales'] += order_ticket.quantity * ticket_price
     return render_template('gentelella/users/events/details/details.html',
                            event=event,
                            checklist=checklist,
                            sessions=sessions,
+                           tickets_summary=tickets_summary,
+                           orders_summary=orders_summary,
                            settings=get_settings())
 
 


Test patch: