diff --git a/Gemfile b/Gemfile index 8a32c7a60..a28b8fa31 100644 --- a/Gemfile +++ b/Gemfile @@ -35,7 +35,7 @@ gem 'jquery-validation-rails', '~> 1.13.1' # validate on client side # view helpers gem 'kaminari', '~> 0.16.3' # pagination gem 'nprogress-rails', '~> 0.1.6.5' # visual loader -gem 'html5_validators', '~> 1.1.3' # model requements now automatically on html form +gem 'html5_validators', '~> 1.1.3' # model requements now automatically on html form # rights gem 'devise', '~> 3.4.1' # authenitcation @@ -75,6 +75,9 @@ gem 'activerecord-import', '~> 0.7.0' # for inserting dummy data # for generating pdf gem 'pdfkit', '~> 0.6.2' +# for datepicker +gem 'jquery-ui-rails', '~> 5.0.3' + group :development do # dev tools gem 'spring', '~> 1.3.3' diff --git a/Gemfile.lock b/Gemfile.lock index 2cfdc269d..8fb034416 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -235,6 +235,8 @@ GEM rails-dom-testing (~> 1.0) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + jquery-ui-rails (5.0.3) + railties (>= 3.2.16) jquery-validation-rails (1.13.1) railties (>= 3.2, < 5.0) thor (~> 0.14) @@ -520,6 +522,7 @@ DEPENDENCIES iso8601 (~> 0.8.2) jbuilder (~> 2.2.6) jquery-rails (~> 4.0.3) + jquery-ui-rails (~> 5.0.3) jquery-validation-rails (~> 1.13.1) kaminari (~> 0.16.3) launchy (~> 2.4.3) diff --git a/app/assets/javascripts/admin-manifest.coffee b/app/assets/javascripts/admin-manifest.coffee index b1f8dddbe..883a2aadc 100644 --- a/app/assets/javascripts/admin-manifest.coffee +++ b/app/assets/javascripts/admin-manifest.coffee @@ -9,6 +9,7 @@ #= require jquery.nested_attributes #= require selectize #= require shared/jquery.validate.bootstrap +#= require jquery-ui/datepicker #= require shared/general #= require admin/application diff --git a/app/assets/javascripts/registrar-manifest.coffee b/app/assets/javascripts/registrar-manifest.coffee index 4d8d4ed63..c0596f09d 100644 --- a/app/assets/javascripts/registrar-manifest.coffee +++ b/app/assets/javascripts/registrar-manifest.coffee @@ -6,5 +6,6 @@ #= require bootstrap-sprockets #= require jquery.nested_attributes #= require shared/jquery.validate.bootstrap +#= require jquery-ui/datepicker #= require shared/general #= require registrar/application diff --git a/app/assets/javascripts/shared/general.coffee b/app/assets/javascripts/shared/general.coffee index f1069f029..9d4ae3390 100644 --- a/app/assets/javascripts/shared/general.coffee +++ b/app/assets/javascripts/shared/general.coffee @@ -9,3 +9,13 @@ $('#flash').find('div').addClass('bg-danger') $('#flash').find('div').html(msg) $('#flash').show() + +$(document).on 'ready page:load', -> + today = new Date() + tomorrow = new Date(today) + tomorrow.setDate(today.getDate() + 1) + + $('.datepicker').datepicker( + dateFormat: "yy-mm-dd", + maxDate: tomorrow + ); diff --git a/app/assets/stylesheets/registrar-manifest.sass b/app/assets/stylesheets/registrar-manifest.sass index 8c758228b..23c1641a0 100644 --- a/app/assets/stylesheets/registrar-manifest.sass +++ b/app/assets/stylesheets/registrar-manifest.sass @@ -1,5 +1,6 @@ //= require 'shared/general-manifest' //= require 'registrar/registrar-bootstrap' +//= require 'jquery-ui/datepicker' @import shared/fonts @import shared/general @import nprogress diff --git a/app/controllers/registrar/invoices_controller.rb b/app/controllers/registrar/invoices_controller.rb index 6c606a0bc..8d0a06831 100644 --- a/app/controllers/registrar/invoices_controller.rb +++ b/app/controllers/registrar/invoices_controller.rb @@ -4,6 +4,7 @@ class Registrar::InvoicesController < RegistrarController before_action :set_invoice, only: [:show, :forward, :download_pdf] def index + params[:q] ||= {} invoices = current_user.registrar.invoices.includes(:invoice_items, :account_activity) @q = invoices.search(params[:q]) @q.sorts = 'id desc' if @q.sorts.empty? diff --git a/app/models/invoice.rb b/app/models/invoice.rb index f8bc4ceaa..372d67a8c 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -32,6 +32,8 @@ class Invoice < ActiveRecord::Base false end + before_save -> { self.sum_cache = sum } + def binded? account_activity.present? end diff --git a/app/views/registrar/invoices/index.haml b/app/views/registrar/invoices/index.haml index a3a128526..1b49f7545 100644 --- a/app/views/registrar/invoices/index.haml +++ b/app/views/registrar/invoices/index.haml @@ -8,6 +8,43 @@ currency: current_user.registrar.cash_account.currency) %h1= t(:invoices) +.row + .col-md-12 + %hr + = search_form_for @q, url: [:registrar, :invoices], html: { style: 'margin-bottom: 0;' } do |f| + .row + .col-md-3 + .form-group + = f.label t(:minimum_invoice_no) + = f.search_field :number_gteq, class: 'form-control', placeholder: t(:minimum_invoice_no), autocomplete: 'off' + .col-md-3 + .form-group + = f.label t(:maximum_invoice_no) + = f.search_field :number_lteq, class: 'form-control', placeholder: t(:maximum_invoice_no), autocomplete: 'off' + .col-md-3 + .form-group + = f.label t(:due_date_after) + = f.search_field :due_date_gt, value: params[:q][:due_date_gt], class: 'form-control datepicker', placeholder: t(:due_date_after), autocomplete: 'off' + .col-md-3 + .form-group + = f.label t(:due_date_before) + = f.search_field :due_date_lt, value: params[:q][:due_date_lt], class: 'form-control datepicker', placeholder: t(:due_date_before), autocomplete: 'off' + .row + .col-md-3 + .form-group + = f.label t(:minimum_total) + = f.search_field :sum_cache_gteq, class: 'form-control', placeholder: t(:minimum_total), autocomplete: 'off' + .col-md-3 + .form-group + = f.label t(:maximum_total) + = f.search_field :sum_cache_lteq, class: 'form-control', placeholder: t(:maximum_total), autocomplete: 'off' + .col-md-3{style: 'padding-top: 25px;'} + %button.btn.btn-primary +   + %span.glyphicon.glyphicon-search +   + %button.btn.btn-default.js-reset-form + = t(:clear_fields) %hr .row .col-md-12 @@ -30,11 +67,14 @@ - else %td{class: 'text-danger'}= t(:unpaid) - - if x.cancelled? - %td.text-grey= t('cancelled') - - else - %td= l(x.due_date) + %td= l(x.due_date) %td= x.sum .row .col-md-12 = paginate @invoices + +:coffee + $(".js-reset-form").on "click", (e) -> + e.preventDefault(); + window.location = "#{registrar_invoices_path}" + diff --git a/config/locales/en.yml b/config/locales/en.yml index 1f2d1c5c6..a0e2f417e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -740,3 +740,9 @@ en: cannot_cancel_paid_invoice: 'Cannot cancel paid invoice' cannot_cancel_cancelled_invoice: 'Cannot cancel cancelled invoice' cannot_bind_cancelled_invoice: 'Cannot bind cancelled invoice' + minimum_invoice_no: 'Miminum invoice no' + maximum_invoice_no: 'Maximum invoice no' + due_date_after: 'Due date after' + due_date_before: 'Due date before' + minimum_total: 'Minimum total' + maximum_total: 'Maximum total' diff --git a/db/migrate/20150428075052_add_sum_cache_to_invoice.rb b/db/migrate/20150428075052_add_sum_cache_to_invoice.rb new file mode 100644 index 000000000..6706892ef --- /dev/null +++ b/db/migrate/20150428075052_add_sum_cache_to_invoice.rb @@ -0,0 +1,6 @@ +class AddSumCacheToInvoice < ActiveRecord::Migration + def change + add_column :invoices, :sum_cache, :decimal + Invoice.all.each(&:save) + end +end diff --git a/db/schema.rb b/db/schema.rb index 04d476149..aa45f6165 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150427073517) do +ActiveRecord::Schema.define(version: 20150428075052) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -368,6 +368,7 @@ ActiveRecord::Schema.define(version: 20150427073517) do t.string "updator_str" t.integer "number" t.datetime "cancelled_at" + t.decimal "sum_cache" end add_index "invoices", ["buyer_id"], name: "index_invoices_on_buyer_id", using: :btree diff --git a/spec/models/invoice_spec.rb b/spec/models/invoice_spec.rb index a0cee3db3..4ec594640 100644 --- a/spec/models/invoice_spec.rb +++ b/spec/models/invoice_spec.rb @@ -72,7 +72,8 @@ describe Invoice do it 'should cancel overdue invoices' do Fabricate(:invoice, created_at: Time.zone.now - 35.days, due_date: Time.zone.now - 1.days) - Invoice.cancel_overdue_invoices.should == 1 + Invoice.cancel_overdue_invoices + Invoice.where(cancelled_at: nil).count.should == 1 end # it 'should have one version' do