Commit 9b86cc32 authored by gwendal's avatar gwendal
Browse files

add payment_method filter and sort on invoice#index

parent 19613934
......@@ -126,6 +126,13 @@ class InvoicesController < WebController
payed: "payed",
unpayed: "unpayed"
}
payment_method_dict = {
cash: 'cash',
money_transfert: 'money_transfert',
cheque: 'cheque',
direct_debit: 'direct_debit',
deposit: "deposit"
}
if not params[:update]
status_dict.keys.select do |e|
params[e] = true
......@@ -133,8 +140,12 @@ class InvoicesController < WebController
payed_dict.keys.select do |e|
params[e] = true
end
payment_method_dict.keys.select do |e|
params[e] = true
end
end
# Filter on status
status = status_dict.keys.select do |e|
params[e]
end.map do |e|
......@@ -142,6 +153,14 @@ class InvoicesController < WebController
end
@invoices = @invoices.match_status status
# Filter on payment_method
payment_methods = payment_method_dict.keys.select do |e|
params[e]
end.map do |e|
payment_method_dict[e]
end
@invoices = @invoices.match_payment_method payment_methods
# Filter on name
@invoices = @invoices.match_recipient_name params[:filter_name]
......@@ -190,7 +209,7 @@ class InvoicesController < WebController
# Sort
@invoices = order_columns(
@invoices, allowed_columns: [
'recipient.name', 'identifier', 'description', 'total_amount', 'period_start', 'period_end', 'issue_date', 'status',
'recipient.name', 'identifier', 'description', 'total_amount', 'period_start', 'period_end', 'issue_date', 'status', 'payment_method'
])
@actions = []
......
......@@ -29,6 +29,7 @@ class Invoice < InvoicingLedgerItem
where('period_start >= ? AND period_end <= ?', "#{start_date} 00h00".to_time.utc, "#{end_date} 24h00".to_time.utc)
}
scope :match_payed, ->(payed) { where(payed: payed) }
scope :match_payment_method, ->(payment_methods) { where(payment_method: payment_methods) unless payment_methods.empty? }
validates :currency, :presence => true
validates :recipient, :presence => true
......
......@@ -25,6 +25,11 @@
choices: ["payed", "unpayed"],
translation_prefix: 'invoices.index.'
) %>
<%= render(
'shared/index_check_boxes_filter',
choices: ["cash", "cheque", "money_transfert", "direct_debit", "deposit"],
translation_prefix: 'payment_method.'
) %>
<% end %>
<%= render(
'shared/index_block_container',
......@@ -52,6 +57,7 @@
<th class="recipient"><%= sortable "recipient_name", i18n.t('recipient') %></th>
<th class="description"><%= sortable "description", i18n.t('description') %></th>
<th class="total_amount"><%=sortable "total_amount", i18n.t('total_amount') %></th>
<th class="payment_method"><%=sortable "payment_method", i18n.t('payment_method') %></th>
<th class="issue_date"><%= sortable "issue_date", i18n.t('issue_date') %></th>
<th class="period_start"><%=sortable "period_start", i18n.t('period_start') %></th>
<th class="period_end"><%= sortable "period_end", i18n.t('period_end') %></th>
......@@ -67,6 +73,7 @@
<td class="t_invoice_recipient_name"><%= invoice.recipient %></td>
<td class="t_invoice_description"><%= invoice.description %></td>
<td class="t_invoice_total_amount"><%= number_to_currency(invoice.total_amount) %></td>
<td class="t_invoice_payment_method"><%= t(invoice.payment_method, scope: [:payment_method]) %></td>
<td class="t_invoice_issue_date"><%= invoice.issue_date.try(:strftime, '%Y-%m-%d') %></td>
<td class="t_invoice_period_start"><%= invoice.period_start.try(:strftime, '%Y-%m-%d') %></td>
<td class="t_invoice_period_end"><%= invoice.period_end.try(:strftime, '%Y-%m-%d') %></td>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment