diff --git a/app/controllers/account/billing/invoices.js b/app/controllers/account/billing/invoices.js new file mode 100644 index 00000000000..4f97b110ff6 --- /dev/null +++ b/app/controllers/account/billing/invoices.js @@ -0,0 +1,4 @@ +import Controller from '@ember/controller'; + +export default class extends Controller { +} diff --git a/app/controllers/account/billing/invoices/list.js b/app/controllers/account/billing/invoices/list.js new file mode 100644 index 00000000000..8e248fde72d --- /dev/null +++ b/app/controllers/account/billing/invoices/list.js @@ -0,0 +1,112 @@ +import Controller from '@ember/controller'; +import EmberTableControllerMixin from 'open-event-frontend/mixins/ember-table-controller'; +import { computed } from '@ember/object'; + +export default class extends Controller.extend(EmberTableControllerMixin) { + @computed() + get columns() { + let columns = []; + if (this.model.params.invoice_status === 'upcoming') { + columns = [ + { + name : 'Invoice ID', + valuePath : 'id' + }, + { + name : 'Name', + valuePath : 'event', + cellComponent : 'ui-table/cell/events/cell-event-invoice' + }, + { + name : 'Date Issued', + valuePath : 'createdAt' + }, + { + name : 'Outstanding Amount', + valuePath : 'amount' + }, + { + name : 'View Invoice', + valuePath : 'invoicePdfUrl' + } + ]; + } else if (this.model.params.invoice_status === 'paid') { + columns = [ + { + name : 'Invoice ID', + valuePath : 'id' + }, + { + name : 'Name', + valuePath : 'event', + cellComponent : 'ui-table/cell/events/cell-event-invoice' + }, + { + name : 'Date Issued', + valuePath : 'createdAt' + }, + { + name : 'Amount', + valuePath : 'amount' + }, + { + name : 'Date Paid', + valuePath : 'completedAt' + }, + { + name : 'View Invoice', + valuePath : 'invoicePdfUrl' + } + + ]; + } else if (this.model.params.invoice_status === 'due') { + columns = [ + { + name : 'Invoice ID', + valuePath : 'id' + }, + { + name : 'Name', + valuePath : 'event', + cellComponent : 'ui-table/cell/events/cell-event-invoice' + + }, + { + name : 'Date Issued', + valuePath : 'createdAt' + }, + { + name : 'Amount Due', + valuePath : 'amount' + }, + { + name : 'View Invoice', + valuePath : 'invoicePdfUrl' + } + + ]; + } else if (this.model.params.invoice_status === 'due') { + columns = [ + { + name : 'Invoice ID', + valuePath : 'id' + }, + { + name : 'Name', + valuePath : 'event', + cellComponent : 'ui-table/cell/events/cell-event-invoice' + }, + { + name : 'Amount', + valuePath : 'amount' + }, + { + name : 'Status', + valuePath : 'status' + } + + ]; + } + return columns; + } +} \ No newline at end of file diff --git a/app/models/event-invoice.js b/app/models/event-invoice.js index d6543e1eab5..74cbfc34aa5 100644 --- a/app/models/event-invoice.js +++ b/app/models/event-invoice.js @@ -26,6 +26,7 @@ export default ModelBase.extend({ expYear : attr('number'), amount : attr('number'), completedAt : attr('moment'), + invoicePdfUrl : attr('string'), /** relationships * diff --git a/app/router.js b/app/router.js index 23d5b71502d..600ca73e374 100644 --- a/app/router.js +++ b/app/router.js @@ -115,7 +115,9 @@ router.map(function() { this.route('danger-zone'); this.route('billing', function() { this.route('payment-info'); - this.route('invoices'); + this.route('invoices', function() { + this.route('list', { path: '/:invoice_status' }); + }); }); }); this.route('explore'); diff --git a/app/routes/account/billing/invoices/list.js b/app/routes/account/billing/invoices/list.js new file mode 100644 index 00000000000..340ab7ed0a2 --- /dev/null +++ b/app/routes/account/billing/invoices/list.js @@ -0,0 +1,72 @@ +import Route from '@ember/routing/route'; +import moment from 'moment'; +import EmberTableRouteMixin from 'open-event-frontend/mixins/ember-table-route'; +import { action } from '@ember/object'; + +export default class extends Route.extend(EmberTableRouteMixin) { + titleToken() { + switch (this.params.invoice_status) { + case 'paid': + return this.l10n.t('Paid'); + case 'due': + return this.l10n.t('Due'); + case 'upcoming': + return this.l10n.t('Upcoming'); + case 'all': + return this.l10n.t('All'); + } + } + async model(params) { + this.set('params', params); + const searchField = 'name'; + let filterOptions = []; + if (params.invoice_status === 'paid' || params.invoice_status === 'due') { + filterOptions = [ + { + name : 'status', + op : 'eq', + val : params.invoice_status + } + ]; + } else if (params.invoice_status === 'upcoming') { + filterOptions = [ + { + and: [ + { + name : 'deleted-at', + op : 'eq', + val : null + }, + { + name : 'created-at', + op : 'ge', + val : moment().subtract(30, 'days').toISOString() + } + ] + } + ]; + } + + + filterOptions = this.applySearchFilters(filterOptions, params, searchField); + + let queryString = { + include : 'event', + filter : filterOptions, + 'page[size]' : params.per_page || 10, + 'page[number]' : params.page || 1 + }; + + queryString = this.applySortFilters(queryString, params); + return { + eventInvoices: (await this.store.query('event-invoice', queryString)).toArray(), + params + + }; + + } + @action + refreshRoute() { + this.refresh(); + } +} diff --git a/app/templates/account/billing/invoices.hbs b/app/templates/account/billing/invoices.hbs index 9505e1875dd..721da023ed5 100644 --- a/app/templates/account/billing/invoices.hbs +++ b/app/templates/account/billing/invoices.hbs @@ -1,14 +1,23 @@