Repository: fossasia/open-event-server

Issue:
Tab Sales in Admin section with relevant information
Add tab "Sales" in admin section at `https://open-event-dev.herokuapp.com/admin/`

We need to display ticket sales in a suitable way to understand the status of the system. How can this be best achieved. Useful information includes:
- [x] Sales by event
- [x] Sales by organizer, and email of organizer
- [x] Sales by location
- [x] Sale depending on date and period (maybe search option)
- [x] Fees by event
- [x] Status/list of (automatic) emails sent to organizer.
- [x] Status of fees paid (invoice to be sent, pending, late)
- [ ] What other information is useful?



Discussion:

Resolving patch:
diff --git a/app/models/event_invoice.py b/app/models/event_invoice.py
--- a/app/models/event_invoice.py
+++ b/app/models/event_invoice.py
@@ -69,6 +69,7 @@ def __init__(self,
         self.transaction_id = transaction_id
         self.paid_via = paid_via
         self.created_at = datetime.utcnow()
+        self.status = 'pending'
 
     def get_invoice_number(self):
         return 'I' + str(int(time.mktime(self.created_at.timetuple()))) + '-' + str(self.id)
diff --git a/app/views/admin/super_admin/sales.py b/app/views/admin/super_admin/sales.py
--- a/app/views/admin/super_admin/sales.py
+++ b/app/views/admin/super_admin/sales.py
@@ -1,5 +1,5 @@
 import copy
-from datetime import datetime
+from datetime import datetime, timedelta
 
 from flask import request
 from flask import url_for
@@ -12,6 +12,7 @@
 from app.helpers.payment import get_fee
 from app.views.admin.super_admin.super_admin_base import SuperAdminBaseView, SALES
 from app.helpers.ticketing import TicketingManager
+from app.helpers.invoicing import InvoicingManager
 
 class SuperAdminSalesView(SuperAdminBaseView):
     PANEL_NAME = SALES
@@ -75,6 +76,33 @@ def fees_by_events_view(self):
                            tickets_total=tickets_total,
                            fee_total=fee_total)
 
+    @expose('/fees/status/')
+    def fees_status_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_status_view'))
+
+        if from_date and to_date:
+            invoices = InvoicingManager.get_invoices(
+                from_date=datetime.strptime(from_date, '%d/%m/%Y'),
+                to_date=datetime.strptime(to_date, '%d/%m/%Y'),
+            )
+        else:
+            invoices = InvoicingManager.get_invoices()
+
+        return self.render('/gentelella/admin/super_admin/sales/fees_status.html',
+                           display_currency=self.display_currency,
+                           from_date=from_date,
+                           current_date=datetime.now(),
+                           overdue_date=datetime.now() + timedelta(days=15),
+                           invoices=invoices,
+                           to_date=to_date)
+
     @expose('/<path>/')
     def sales_by_events_view(self, path):
 


Test patch: