Repository: fossasia/open-event-server

Issue:
Design Skeleton for Event Invoice Template
Parent Issue: #6123 


Discussion:
Issue-Label Bot is automatically applying the label `feature` to this issue, with a confidence of 0.92. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback! 

 Links: [app homepage](https://github.com/marketplace/issue-label-bot), [dashboard](https://mlbot.net/data/fossasia/open-event-server) and [code](https://github.com/hamelsmu/MLapp) for this bot.
@kushthedude This will be taken up by @shreyanshdwivedi as discussed in today's meeting. Would be great if you could help us in the other tasks related to event invoice :D
@uds5501 pinged me for claiming it , I have no objections.

On Sun, 28 Jul 2019 at 7:04 PM, Saicharan Reddy <notifications@github.com>
wrote:

> @kushthedude <https://github.com/kushthedude> This will be taken up by
> @shreyanshdwivedi <https://github.com/shreyanshdwivedi> as discussed in
> today's meeting.
>
> —
> You are receiving this because you were mentioned.
>
>
> Reply to this email directly, view it on GitHub
> <https://github.com/fossasia/open-event-server/issues/6197?email_source=notifications&email_token=AKQMTLXKAUKDG7WQL2R26UDQBWN73A5CNFSM4ID53LJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD266Z2Y#issuecomment-515763435>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AKQMTLVSBU3CRLLI2MOII73QBWN73ANCNFSM4ID53LJA>
> .
>


Resolving patch:
diff --git a/app/api/helpers/scheduled_jobs.py b/app/api/helpers/scheduled_jobs.py
--- a/app/api/helpers/scheduled_jobs.py
+++ b/app/api/helpers/scheduled_jobs.py
@@ -180,19 +180,28 @@ def send_monthly_event_invoice():
         events = Event.query.all()
         for event in events:
             # calculate net & gross revenues
+            user = event.owner
+            admin_info = get_settings()
             currency = event.payment_currency
             ticket_fee_object = db.session.query(TicketFees).filter_by(currency=currency).one()
             ticket_fee_percentage = ticket_fee_object.service_fee
             ticket_fee_maximum = ticket_fee_object.maximum_fee
             orders = Order.query.filter_by(event=event).all()
             gross_revenue = event.calc_monthly_revenue()
-            ticket_fees = event.tickets_sold * ticket_fee_percentage
+            ticket_fees = event.tickets_sold * (ticket_fee_percentage / 100)
             if ticket_fees > ticket_fee_maximum:
                 ticket_fees = ticket_fee_maximum
             net_revenue = gross_revenue - ticket_fees
+            payment_details = {
+                'tickets_sold': event.tickets_sold,
+                'gross_revenue': gross_revenue,
+                'net_revenue': net_revenue,
+                'amount_payable': ticket_fees
+            }
             # save invoice as pdf
-            pdf = create_save_pdf(render_template('pdf/event_invoice.html', orders=orders,
-                                  ticket_fee_object=ticket_fee_object, gross_revenue=gross_revenue,
+            pdf = create_save_pdf(render_template('pdf/event_invoice.html', orders=orders, user=user,
+                                  admin_info=admin_info, currency=currency, event=event,
+                                  ticket_fee_object=ticket_fee_object, payment_details=payment_details,
                                   net_revenue=net_revenue), UPLOAD_PATHS['pdf']['event_invoice'],
                                   dir_path='/static/uploads/pdf/event_invoices/', identifier=event.identifier)
             # save event_invoice info to DB
diff --git a/app/models/event.py b/app/models/event.py
--- a/app/models/event.py
+++ b/app/models/event.py
@@ -417,12 +417,9 @@ def calc_revenue(self):
 
     def calc_monthly_revenue(self):
         """Returns revenue of current month. Invoice sent every 1st of the month for the previous month"""
-        previous_month = datetime.datetime.now().month - 1
-        monthly_revenue = db.session.query(func.sum(Order.amount)).filter(Order.event_id == self.id,
-                                                                          Order.completed_at.month == previous_month,
-                                                                          Order.status == 'completed').scalar()
-        if monthly_revenue is None:
-            monthly_revenue = 0
+        previous_month = datetime.now().month - 1
+        orders = Order.query.filter_by(event_id=self.id, status='completed').all()
+        monthly_revenue = sum([o.amount for o in orders if o.completed_at and o.completed_at.month == previous_month])
         return monthly_revenue
 
     @property


Test patch: