forked from 3scale/porta
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 3scale#3840 from 3scale/THREESCALE-9824_invoices_t…
…oolbar 🦋Update provider invoices page
- Loading branch information
Showing
37 changed files
with
549 additions
and
454 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
app/presenters/finance/provider/invoices_index_presenter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# frozen_string_literal: true | ||
|
||
class Finance::Provider::InvoicesIndexPresenter | ||
include System::UrlHelpers.system_url_helpers | ||
|
||
delegate :can?, to: :ability | ||
|
||
def initialize(provider:, user:, params:) | ||
@provider = provider | ||
@search = ThreeScale::Search.new(params[:search] || params) | ||
@sort_params = [params[:sort], params[:direction]] | ||
@pagination_params = { page: params[:page] || 1, per_page: params[:per_page] || 20 } | ||
@ability = Ability.new(user) | ||
end | ||
|
||
attr_reader :provider, :search, :sort_params, :pagination_params, :ability | ||
|
||
def empty_state? | ||
raw_invoices.empty? | ||
end | ||
|
||
def empty_search? | ||
searched_invoices.empty? | ||
end | ||
|
||
def searched_invoices | ||
@searched_invoices ||= raw_invoices.scope_search(search) | ||
end | ||
|
||
def invoices | ||
@invoices ||= searched_invoices.order_by(*sort_params) | ||
.paginate(pagination_params) | ||
.decorate | ||
end | ||
|
||
def years | ||
@years ||= Invoice.years_by_provider(provider.id).presence || [(ActiveSupport::TimeZone.new(provider.timezone) || Time.zone).now.year] | ||
end | ||
|
||
def toolbar_props | ||
props = { | ||
totalEntries: invoices.total_entries, | ||
overflow: [], | ||
attributeFilters: [{ | ||
name: 'search[number]', | ||
title: 'Number', | ||
placeholder: '2017-06-* / 2018-*', | ||
chip: search.number | ||
}, { | ||
name: 'search[buyer_query]', | ||
title: 'Account', | ||
placeholder: '', | ||
chip: search.buyer_query | ||
}, { | ||
name: 'search[month_number]', | ||
title: 'Month', | ||
collection: months_for_filter, | ||
placeholder: 'Filter by month', | ||
chip: I18n.t('date.month_names')[search.month_number.to_i] | ||
}, { | ||
name: 'search[year]', | ||
title: 'Year', | ||
collection: years_for_filter, | ||
placeholder: 'Filter by year', | ||
chip: search.year | ||
}, { | ||
name: 'search[state]', | ||
title: 'State', | ||
collection: states_for_filter, | ||
placeholder: 'Filter by state', | ||
chip: search.state&.capitalize | ||
}] | ||
} | ||
|
||
if can?(:export, :data) | ||
props[:overflow].append({ href: new_provider_admin_account_data_exports_path, | ||
label: 'Export to CSV', | ||
isShared: false, | ||
variant: :secondary }) | ||
end | ||
|
||
props | ||
end | ||
|
||
private | ||
|
||
def raw_invoices | ||
@raw_invoices ||= provider.buyer_invoices.includes(:provider_account) | ||
end | ||
|
||
def states_for_filter | ||
Invoice.state_machine.states.keys.collect(&:to_s).sort.map do |state| | ||
{ id: state, title: state.capitalize } | ||
end | ||
end | ||
|
||
def months_for_filter | ||
I18n.t('date.month_names').drop(1).map.with_index(1) do |month, i| # First item in array is nil | ||
{ id: i, title: month } | ||
end | ||
end | ||
|
||
def years_for_filter | ||
years.map do |year| | ||
{ id: year, title: year.to_s } | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
- content_for :page_header_title, t('.page_header_title') | ||
|
||
- if presenter.empty_state? | ||
= render partial: 'shared/empty_state', locals: { title: t('.empty_state.title'), | ||
body: t('.empty_state.body') } | ||
- else | ||
- content_for :javascripts do | ||
= javascript_packs_with_chunks_tag 'table_toolbar' | ||
|
||
table class="pf-c-table pf-m-grid-lg" role="grid" aria-label="Invoices table" data-toolbar-props=presenter.toolbar_props.to_json | ||
thead | ||
tr role="row" | ||
= th_sortable('friendly_id', 'Number', :admin_finance_invoices_path) | ||
= th_sortable('accounts.org_name', 'Account', :admin_finance_invoices_path) | ||
= th_sortable('period', 'Month', :admin_finance_invoices_path) | ||
th role="columnheader" scope="col" Cost | ||
= th_sortable('state', 'State', :admin_finance_invoices_path) | ||
td | ||
|
||
tbody role="rowgroup" class="invoices" | ||
- if presenter.empty_search? | ||
= render partial: 'shared/empty_search_state', locals: { title: t('.empty_search.title'), | ||
body: t('.empty_search.body') } | ||
- else | ||
- presenter.invoices.each do |invoice| | ||
= content_tag_for(:tr, invoice, role: "row") do | ||
td role="cell" data-label="Number" | ||
= link_to(invoice.friendly_id, admin_finance_invoice_path(invoice)) | ||
td role="cell" data-label="Account" | ||
= link_to_buyer_or_deleted(invoice.buyer, :admin_buyers_account_invoices_path) | ||
td role="cell" data-label="Month" | ||
= invoice.name | ||
td role="cell" data-label="Cost" | ||
= price_tag(invoice.cost) | ||
td role="cell" data-label="State" | ||
= invoice.state.capitalize | ||
- if invoice.pdf.file? | ||
td role="cell" data-label="Download" | ||
= invoice_pdf_link(invoice) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
features/developer_portal/admin/account/invoices/pdf.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Feature: Dev Portal > Invoices > Download PDF | ||
|
||
As a buyer, I want to have the PDF versions of my invoices | ||
|
||
Background: | ||
Given a provider on 1st January 2011 | ||
And the provider is charging its buyers in prepaid mode | ||
And the provider has "finance" switch visible | ||
And a buyer "Jane" | ||
And the following invoices: | ||
| Buyer | Month | Friendly ID | State | | ||
| Jane | January, 2011 | 2011-01-00000001 | Paid | | ||
And the buyer logs in | ||
|
||
Scenario: Download PDF from the invoices table | ||
When they go to the dev portal invoices page | ||
Then there should be a secure link to download the PDF of invoice "2011-01-00000001" | ||
|
||
Scenario: Download PDF from the invoice detail | ||
When they go to the invoice "2011-01-00000001" dev portal page | ||
Then there should be a secure link to download the PDF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.