mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 18:26:06 +02:00
Merge pull request #2134 from internetee/2124-filtering-and-search-to-invoices-view
Admin: filtering and search to invoices view
This commit is contained in:
commit
c7d466e9fd
5 changed files with 119 additions and 5 deletions
|
@ -21,8 +21,7 @@ module Admin
|
|||
end
|
||||
|
||||
def cancel_paid
|
||||
invoice_id = params[:invoice_id]
|
||||
invoice = Invoice.find(invoice_id)
|
||||
invoice = Invoice.find(params[:invoice_id])
|
||||
|
||||
if account_activity_with_negative_sum(invoice)
|
||||
flash[:notice] = t(:payment_was_cancelled)
|
||||
|
@ -33,10 +32,16 @@ module Admin
|
|||
end
|
||||
|
||||
def index
|
||||
@q = Invoice.includes(:account_activity).search(params[:q])
|
||||
params[:q] ||= {}
|
||||
invoices = filter_by_status
|
||||
invoices = filter_by_receipt_date(invoices)
|
||||
|
||||
@q = invoices.search(params[:q])
|
||||
@q.sorts = 'number desc' if @q.sorts.empty?
|
||||
@invoices = @q.result.page(params[:page])
|
||||
@invoices = @invoices.per(params[:results_per_page]) if paginate?
|
||||
|
||||
render_by_format('admin/invoices/index', 'invoices')
|
||||
end
|
||||
|
||||
def show; end
|
||||
|
@ -72,5 +77,28 @@ module Admin
|
|||
payment_order = invoice.payment_orders.last
|
||||
payment_order.update(notes: 'Cancelled')
|
||||
end
|
||||
|
||||
def filter_by_status
|
||||
case params[:status]
|
||||
when 'Paid'
|
||||
Invoice.includes(:account_activity, :buyer).where.not(account_activity: { id: nil })
|
||||
when 'Unpaid'
|
||||
Invoice.includes(:account_activity, :buyer).where(account_activity: { id: nil })
|
||||
when 'Cancelled'
|
||||
Invoice.includes(:account_activity, :buyer).where.not(cancelled_at: nil)
|
||||
else
|
||||
Invoice.includes(:account_activity, :buyer)
|
||||
end
|
||||
end
|
||||
|
||||
def filter_by_receipt_date(invoices)
|
||||
date_from_param = params[:q][:receipt_date_gteq] if params[:q][:receipt_date_gteq].present?
|
||||
date_from = date_from_param ? Time.zone.parse(date_from_param) : -Float::INFINITY
|
||||
|
||||
date_until_param = params[:q][:receipt_date_lteq] if params[:q][:receipt_date_lteq].present?
|
||||
date_until = date_until_param ? Time.zone.parse(date_from_param) : Float::INFINITY
|
||||
|
||||
invoices.where(account_activity: { created_at: date_from..date_until })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@ class Invoice < ApplicationRecord
|
|||
include Invoice::Cancellable
|
||||
include Invoice::Payable
|
||||
include Invoice::BookKeeping
|
||||
extend ToCsv
|
||||
|
||||
belongs_to :buyer, class_name: 'Registrar'
|
||||
has_one :account_activity
|
||||
|
|
80
app/views/admin/invoices/_search_form.html.erb
Normal file
80
app/views/admin/invoices/_search_form.html.erb
Normal file
|
@ -0,0 +1,80 @@
|
|||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<%= search_form_for @q, url: [:admin, :invoices], html: { style: 'margin-bottom: 0;' } do |f| %>
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<%= f.label t(:invoice_number) %>
|
||||
<%= f.search_field :number_eq, class: 'form-control', placeholder: t(:invoice_number), autocomplete: 'off' %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<%= f.label t(:status) %>
|
||||
<%= select_tag :status, options_for_select(%w(Paid Unpaid Cancelled),params[:status]),
|
||||
{ multiple: false, include_blank: true, selected: params[:status], class: 'form-control selectize'} %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<%= f.label t(:due_date_from), for: nil %>
|
||||
<%= f.search_field :due_date_gteq, value: params[:q][:due_date_gteq], class: 'form-control js-datepicker', placeholder: t(:due_date_from) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<%= f.label t(:due_date_until), for: nil %>
|
||||
<%= f.search_field :due_date_lteq, value: params[:q][:due_date_lteq], class: 'form-control js-datepicker', placeholder: t(:due_date_until) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="form-group">
|
||||
<%= f.label "Registrar" %>
|
||||
<%= f.select :buyer_id_in, Registrar.all.map { |x| [x, x.id] }, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<%= f.label t(:receipt_date_from), for: nil %>
|
||||
<%= f.search_field :receipt_date_gteq, value: params[:q][:receipt_date_gteq], class: 'form-control js-datepicker', placeholder: t(:receipt_date_from) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<%= f.label t(:receipt_date_until), for: nil %>
|
||||
<%= f.search_field :receipt_date_lteq, value: params[:q][:receipt_date_lteq], class: 'form-control js-datepicker', placeholder: t(:receipt_date_until) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3"></div>
|
||||
<div class="col-md-3"></div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<%= label_tag t(:results_per_page) %>
|
||||
<%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-3" style="padding-top: 25px; float: right; padding-right: 10px;">
|
||||
<button class="btn btn-primary">
|
||||
|
||||
<span class="glyphicon glyphicon-search"></span>
|
||||
|
||||
</button>
|
||||
<%= link_to t('.download_btn'), admin_invoices_path(format: :csv, params: params.permit!),
|
||||
"data-toggle" => "tooltip", "data-placement" => "bottom", "title" => t('.download_btn'),
|
||||
class: 'btn btn-default' %>
|
||||
<%= link_to t('.reset_btn'), admin_invoices_path, class: 'btn btn-default' %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
|
@ -1,7 +1,7 @@
|
|||
- content_for :actions do
|
||||
= link_to(t(:add), new_admin_invoice_path, class: 'btn btn-primary')
|
||||
= render 'shared/title', name: t(:invoices)
|
||||
= render 'application/pagination'
|
||||
= render 'search_form'
|
||||
|
||||
.row
|
||||
.col-md-12
|
||||
|
@ -33,6 +33,7 @@
|
|||
%td.text-grey= t(:cancelled)
|
||||
- else
|
||||
%td.text-danger= t(:unpaid)
|
||||
|
||||
.row
|
||||
.col-md-6
|
||||
= paginate @invoices
|
||||
|
|
|
@ -9,4 +9,8 @@ en:
|
|||
deliver_btn: Send
|
||||
|
||||
cancel:
|
||||
cancelled: Invoice has been cancelled
|
||||
cancelled: Invoice has been cancelled
|
||||
|
||||
search_form:
|
||||
download_btn: CSV
|
||||
reset_btn: Reset
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue