Implementation of Paid Route for Event Invoice in Open Event Frontend
The implementation of event invoice tables is already explained in the blog post Implementation of Event Invoice view using Ember Tables. This blog post is an extension which will showcase the implementation of paid route for event invoice in Open Event Frontend. Event invoices can be explained as the monthly fee given by the organizer to the platform for hosting their event.
We begin by defining a route for displaying the paid event invoice. We chose event-invoice/paid route in router.js
this.route('event-invoice', function() { ... this.route('paid', { path: '/:invoice_identifier/paid' }); });
Now, we need to finalize the paid route. The route is divided in three sections –
- titleToken : To display title in the tab of the browser.
- model : To fetch event-invoice with the given identifier.
- afterModel : To check if the status of the fetched event -invoice is paid or due. If it is due, it is redirected to review page otherwise it is redirected to paid page.
import Route from '@ember/routing/route'; export default class extends Route { titleToken(model) { return this.l10n.tVar(`Paid Event Invoice - ${model.get('identifier')}`); } model(params) { return this.store.findRecord('event-invoice', params.invoice_identifier, { include : 'event,user', reload : true } ); } afterModel(model) { if (model.get('status') === 'due') { this.transitionTo('event-invoice.review', model.get('identifier')); } else if (model.get('status') === 'paid') { this.transitionTo('event-invoice.paid', model.get('identifier')); } } }
Now, we need to design the template for paid route. It includes various elements –
- Invoice Summary :
<div class="ten wide column print"> {{event-invoice/invoice-summary data=model event=model.event eventCurrency=model.event.paymentCurrency}} </div>
The invoice summary contains some of the details of the event invoice. It contains the event name, date of issue, date of completion and amount payable of the event invoice. The snippet for invoice summary can be viewed here
2. Event Info :
<div class="mobile hidden six wide column"> {{event-invoice/event-info event=model.event}} </div>
The event info section of the paid page contains the description of the event to which the invoice is associated. It contains event location, start date and end date of the event. The snippet for event info can be viewed here
3. Billing Info :
<div class="ten wide column"> {{event-invoice/billing-info user=model.user}} </div>
The billing info section of the event invoice paid page contains the billing info of the user to which the event is associated and that of the admin. The billing info includes name, email, phone, zip code and country of the user and the admin. The snippet for billing info can be viewed here
4. Payee Info :
<div class="mobile hidden row"> {{event-invoice/payee-info data=model payer=model.user}} </div>
The payee information displays the name and email of the user who pays for the invoice and also the method of the payment along with relevant information. The snippet for payee info can be viewed here
We can download the invoice of the payment made for the event invoice. This is triggered when the Print Invoice button is clicked.
Code snippet to trigger the download of the invoice –
<div class="row"> <div class="column right aligned"> <button {{action 'downloadEventInvoice' model.event.name model.identifier }} class="ui labeled icon blue {{if isLoadingInvoice 'loading'}} button"> <i class="print alternate icon"></i> {{t 'Print Invoice'}} </button> </div> </div>
The function downloadEventInvoice is called when the button Print Invoice is clicked. The event name and order ID is passed as parameters to the function. When the invoice pdf generation is successful, message Here is your Event Invoice is displayed on the screen whereas if there is an error, the message Unexpected error occurred is displayed.
@action async downloadEventInvoice(eventName, orderId) { this.set('isLoading', true); try { const result = this.loader.downloadFile(`/events/invoices/${this.orderId}`); const anchor = document.createElement('a'); anchor.style.display = 'none'; anchor.href = URL.createObjectURL(new Blob([result], { type: 'application/pdf' })); anchor.download = `${eventName} - EventInvoice-${orderId}.pdf`; document.body.appendChild(anchor); anchor.click(); this.notify.success(this.l10n.t('Here is your Event Invoice')); document.body.removeChild(anchor); } catch (e) { console.warn(e); this.notify.error(this.l10n.t('Unexpected error occurred.')); } this.set('isLoading', false); }
Resources:
Related work and code repo:
You must be logged in to post a comment.