mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 23:24:48 +02:00
added filtering
This commit is contained in:
parent
70ca01ba4b
commit
5cb4085660
5 changed files with 121 additions and 3 deletions
|
@ -33,10 +33,17 @@ module Admin
|
||||||
end
|
end
|
||||||
|
|
||||||
def index
|
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?
|
@q.sorts = 'number desc' if @q.sorts.empty?
|
||||||
@invoices = @q.result.page(params[:page])
|
@invoices = @q.result.page(params[:page])
|
||||||
@invoices = @invoices.per(params[:results_per_page]) if paginate?
|
@invoices = @invoices.per(params[:results_per_page]) if paginate?
|
||||||
|
|
||||||
|
render_by_format('admin/invoices/index', 'invoices')
|
||||||
end
|
end
|
||||||
|
|
||||||
def show; end
|
def show; end
|
||||||
|
@ -72,5 +79,29 @@ module Admin
|
||||||
payment_order = invoice.payment_orders.last
|
payment_order = invoice.payment_orders.last
|
||||||
payment_order.update(notes: 'Cancelled')
|
payment_order.update(notes: 'Cancelled')
|
||||||
end
|
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)
|
||||||
|
if params[:q][:receipt_date_gteq].present?
|
||||||
|
invoices = invoices.where(account_activity:
|
||||||
|
{ created_at: Time.parse(params[:q][:receipt_date_gteq])..Float::INFINITY })
|
||||||
|
end
|
||||||
|
|
||||||
|
return invoices unless params[:q][:receipt_date_lteq].present?
|
||||||
|
|
||||||
|
invoices.where(account_activity: { created_at: -Float::INFINITY..Time.parse(params[:q][:receipt_date_lteq]) })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,6 +3,7 @@ class Invoice < ApplicationRecord
|
||||||
include Invoice::Cancellable
|
include Invoice::Cancellable
|
||||||
include Invoice::Payable
|
include Invoice::Payable
|
||||||
include Invoice::BookKeeping
|
include Invoice::BookKeeping
|
||||||
|
extend ToCsv
|
||||||
|
|
||||||
belongs_to :buyer, class_name: 'Registrar'
|
belongs_to :buyer, class_name: 'Registrar'
|
||||||
has_one :account_activity
|
has_one :account_activity
|
||||||
|
|
81
app/views/admin/invoices/_search_form.html.erb
Normal file
81
app/views/admin/invoices/_search_form.html.erb
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
<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
|
- content_for :actions do
|
||||||
= link_to(t(:add), new_admin_invoice_path, class: 'btn btn-primary')
|
= link_to(t(:add), new_admin_invoice_path, class: 'btn btn-primary')
|
||||||
= render 'shared/title', name: t(:invoices)
|
= render 'shared/title', name: t(:invoices)
|
||||||
= render 'application/pagination'
|
= render 'search_form'
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-12
|
.col-md-12
|
||||||
|
@ -33,6 +33,7 @@
|
||||||
%td.text-grey= t(:cancelled)
|
%td.text-grey= t(:cancelled)
|
||||||
- else
|
- else
|
||||||
%td.text-danger= t(:unpaid)
|
%td.text-danger= t(:unpaid)
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
= paginate @invoices
|
= paginate @invoices
|
||||||
|
|
|
@ -9,4 +9,8 @@ en:
|
||||||
deliver_btn: Send
|
deliver_btn: Send
|
||||||
|
|
||||||
cancel:
|
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