From 70fa993e01e9edc1ecdd4c97ca02249336b1e846 Mon Sep 17 00:00:00 2001 From: bohung Date: Wed, 14 Oct 2020 09:48:38 +0800 Subject: [PATCH] Add filters to bill page Add add_and_subtract field to bill form --- .../venue_management_bills_controller.rb | 72 ++++++++++++++++++- .../admin/venue_managements_controller.rb | 64 ++++++++++++++++- app/models/venue_management_bill.rb | 5 +- .../venue_management_bills/_form.html.erb | 21 ++++-- .../venue_management_bills/_index.html.erb | 7 ++ .../venue_management_bills/index.html.erb | 1 + .../venue_management_bills.html.erb | 1 + config/locales/en.yml | 3 + config/locales/zh_tw.yml | 3 + 9 files changed, 164 insertions(+), 13 deletions(-) diff --git a/app/controllers/admin/venue_management_bills_controller.rb b/app/controllers/admin/venue_management_bills_controller.rb index a23e29d..f2788cb 100644 --- a/app/controllers/admin/venue_management_bills_controller.rb +++ b/app/controllers/admin/venue_management_bills_controller.rb @@ -1,13 +1,28 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController include Admin::VenueManagementsHelper + include ActionView::Helpers::FormOptionsHelper + include ActionView::Helpers::FormTagHelper + include ActionView::Helpers::FormHelper + include VenueAdminHelper + include ActionView::Context before_action ->(module_app = @app_title) { set_variables module_app } before_action :set_venue_management_bill, only: [:edit, :update, :destroy] - + def objectify_options(options) + @default_options = {} + @default_options.merge(options) + end def initialize super @app_title = 'venue_management' end - + def filter_fields(categories) + { + :category=>categories.map{|c| {:title=>(c.title.blank? ? " " : c.title), :id=>c.id}} + } + end + def text_field(object_name , options = {}) + text_field_tag(object_name, options[:value], options) + end def index @table_fields = [ 'venue_management.title', @@ -21,8 +36,59 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController "pay_method", "note" ] - @bills = VenueManagementBill.all.page(params[:page]).per(10) + @bills = nil + @categories = @module_app.categories.enabled + @filter_fields = filter_fields(@categories) + @tags = @module_app.tags + @filter_fields['vm_inviting.type'] = @tags.map{|t| {:title => t.name,:id => t.id} } + bill_type_select_str = "
" + value_bill_typeA = params[:filters]["bill_typeA"] rescue "0" + value_bill_typeB = params[:filters]["bill_typeB"] rescue "0" + bill_type_select_str += (select_tag "filters[bill_typeA]", options_for_select(VenueManagementBill::BILLTYPE.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] },value_bill_typeA) ,{:onchange=>"var $this=this;(function(){var obj=#{VenueManagementBill::BILLTYPE.map{|k,v| [k,v.map{|vv| [vv,I18n.t("vm_bill.#{vv}")]}.to_h]}.to_h.to_s.gsub('=>',':')};$($this).siblings('select').html($.map(obj[$this.value],function(v,k){return \'\'}).join(\' \'))})()"}) + bill_typeB = (params[:filters]["bill_typeA"].blank? rescue true) ? VenueManagementBill::BILLTYPE.values.first : VenueManagementBill::BILLTYPE[params[:filters]["bill_typeA"]] + bill_type_select_str += (select_tag "filters[bill_typeB]", options_for_select(bill_typeB.map { |v| [ I18n.t("vm_bill.#{v}"), v ] },value_bill_typeB) , {:onchange=> "var $this=this;(function(){if($this.value == 'other') $('#bill_other_field').removeClass('hidden');else $('#bill_other_field').addClass('hidden');})()"}) + bill_type_select_str += submit_tag(I18n.t('venue_management.search')) + bill_type_select_str += "
" + @filter_fields['vm_bill.bill_type'] = bill_type_select_str + @filter_fields['vm_bill.accounting_month'] = ('
'+ + (org_datetime_picker("filters[accounting_month_start]", {:no_label => true, :format=>"yyyy/MM", :new_record=>false, :value=>(DateTime.parse(params[:filters]["accounting_month_start"]) rescue nil)})) + + "
~
" + + (org_datetime_picker("filters[accounting_month_end]", {:no_label => true, :format=>"yyyy/MM", :new_record=>false, :value=>(DateTime.parse(params[:filters]["accounting_month_end"]) rescue nil)})) + + submit_tag(I18n.t('venue_management.search')) + + '
') + filter_tags = params[:filters]["type"].to_a rescue [] + @main_ids = nil + if !filter_tags.blank? + @main_ids = VenueManagementInviting.with_tags(filter_tags).pluck(:venue_management_main_id) + if !filters("category").blank? + @main_ids = VenueManagementMain.where(:id.in=>@main_ids).with_categories(filters("category")).pluck(:id) + end + elsif !filters("category").blank? + @main_ids = VenueManagementMain.all.with_categories(filters("category")).pluck(:id) + end + if ( !params[:filters]["bill_typeA"].blank? rescue false) + @bills = VenueManagementBill.where(:bill_typeA=>params[:filters]["bill_typeA"],:bill_typeB=>params[:filters]["bill_typeB"]).page(params[:page]).per(10) + end + accounting_month_start = DateTime.parse(params[:filters]["accounting_month_start"]) rescue 0 + accounting_month_end = DateTime.parse(params[:filters]["accounting_month_end"]) rescue 0 + if @bills.nil? + @bills = VenueManagementBill.where(:accounting_month.gt=>accounting_month_start,:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10) + else + if accounting_month_start != 0 && accounting_month_end != 0 + @bills = @bills.where(:accounting_month.gt=>accounting_month_start,:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10) + elsif accounting_month_start != 0 + @bills = @bills.where(:accounting_month.gt=>accounting_month_start).page(params[:page]).per(10) + elsif accounting_month_end != 0 + @bills = @bills.where(:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10) + end + end + if !@main_ids.nil? + @bills = @bills.where(:venue_management_main_id.in=>@main_ids).page(params[:page]).per(10) + end @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" + if request.xhr? + render '_index' + end end def new diff --git a/app/controllers/admin/venue_managements_controller.rb b/app/controllers/admin/venue_managements_controller.rb index 727a234..afa5df9 100644 --- a/app/controllers/admin/venue_managements_controller.rb +++ b/app/controllers/admin/venue_managements_controller.rb @@ -1,11 +1,21 @@ # encoding: utf-8 class Admin::VenueManagementsController < Admin::VenueAdminController - + include ActionView::Helpers::FormOptionsHelper + include ActionView::Helpers::FormTagHelper + include ActionView::Helpers::FormHelper + include VenueAdminHelper + include ActionView::Context require 'axlsx' helper Admin::VenueManagementsFieldHelper before_action ->(module_app = @app_title) { set_variables module_app } before_action :set_venue_management, only: [:edit, :set_write_off, :venue_management_signup, :destroy, :venue_management_invitings, :venue_management_memorabilias, :venue_management_bills, :venue_management_contracts] - + def objectify_options(options) + @default_options = {} + @default_options.merge(options) + end + def text_field(object_name , options = {}) + text_field_tag(object_name, options[:value], options) + end def initialize super @app_title = "venue_management" @@ -52,7 +62,7 @@ class Admin::VenueManagementsController < Admin::VenueAdminController @venue_managements = VenueManagementMain.all.order_by(sort).with_categories(filters("category")) @venue_managements = search_data(@venue_managements,[:title]) @venue_management_inviting_ids = @venue_managements.map{|v| v.venue_management_invitings.desc(:id).first.id rescue ""} - @venue_management_ids = VenueManagementInviting.where(:id.in=>@venue_management_inviting_ids).with_tags(filter_tags).map{|v| v.venue_management_main_id} + @venue_management_ids = VenueManagementInviting.where(:id.in=>@venue_management_inviting_ids).with_tags(filter_tags).pluck(:venue_management_main_id) @venue_managements = VenueManagementMain.where(:id.in=>@venue_management_ids).page(params[:page]).per(10) end @@ -344,6 +354,54 @@ class Admin::VenueManagementsController < Admin::VenueAdminController ] @bills = @venue_management.venue_management_bills.page(params[:page]).per(10) @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" + @categories = @module_app.categories.enabled + @filter_fields = filter_fields(@categories) + @tags = @module_app.tags + @filter_fields['vm_inviting.type'] = @tags.map{|t| {:title => t.name,:id => t.id} } + value_bill_typeA = params[:filters]["bill_typeA"] rescue "0" + value_bill_typeB = params[:filters]["bill_typeB"] rescue "0" + bill_type_select_str = "
" + bill_type_select_str += (select_tag "filters[bill_typeA]", options_for_select(VenueManagementBill::BILLTYPE.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] },value_bill_typeA) ,{:onchange=>"var $this=this;(function(){var obj=#{VenueManagementBill::BILLTYPE.map{|k,v| [k,v.map{|vv| [vv,I18n.t("vm_bill.#{vv}")]}.to_h]}.to_h.to_s.gsub('=>',':')};$($this).siblings('select').html($.map(obj[$this.value],function(v,k){return \'\'}).join(\' \'))})()"}) + bill_typeB = (params[:filters]["bill_typeA"].blank? rescue true) ? VenueManagementBill::BILLTYPE.values.first : VenueManagementBill::BILLTYPE[params[:filters]["bill_typeA"]] + bill_type_select_str += (select_tag "filters[bill_typeB]", options_for_select(bill_typeB.map { |v| [ I18n.t("vm_bill.#{v}"), v ] },value_bill_typeB) , {:onchange=> "var $this=this;(function(){if($this.value == 'other') $('#bill_other_field').removeClass('hidden');else $('#bill_other_field').addClass('hidden');})()"}) + bill_type_select_str += submit_tag(I18n.t('venue_management.search')) + bill_type_select_str += "
" + @filter_fields['vm_bill.bill_type'] = bill_type_select_str + @filter_fields['vm_bill.accounting_month'] = ('
'+ + (org_datetime_picker("filters[accounting_month_start]", {:no_label => true, :format=>"yyyy/MM", :new_record=>false, :value=>(DateTime.parse(params[:filters]["accounting_month_start"]) rescue nil)})) + + "
~
" + + (org_datetime_picker("filters[accounting_month_end]", {:no_label => true, :format=>"yyyy/MM", :new_record=>false, :value=>(DateTime.parse(params[:filters]["accounting_month_end"]) rescue nil)})) + + submit_tag(I18n.t('venue_management.search')) + + '
') + filter_tags = params[:filters]["type"].to_a rescue [] + @main_ids = nil + if !filter_tags.blank? + @main_ids = VenueManagementInviting.with_tags(filter_tags).pluck(:venue_management_main_id) + if !filters("category").blank? + @main_ids = VenueManagementMain.where(:id.in=>@main_ids).with_categories(filters("category")).pluck(:id) + end + elsif !filters("category").blank? + @main_ids = VenueManagementMain.all.with_categories(filters("category")).pluck(:id) + end + if ( !params[:filters]["bill_typeA"].blank? rescue false) + @bills = @bills.where(:bill_typeA=>params[:filters]["bill_typeA"],:bill_typeB=>params[:filters]["bill_typeB"]).page(params[:page]).per(10) + end + accounting_month_start = DateTime.parse(params[:filters]["accounting_month_start"]) rescue 0 + accounting_month_end = DateTime.parse(params[:filters]["accounting_month_end"]) rescue 0 + if accounting_month_start != 0 && accounting_month_end != 0 + @bills = @bills.where(:accounting_month.gt=>accounting_month_start,:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10) + elsif accounting_month_start != 0 + @bills = @bills.where(:accounting_month.gt=>accounting_month_start).page(params[:page]).per(10) + elsif accounting_month_end != 0 + @bills = @bills.where(:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10) + end + if !@main_ids.nil? + @bills = @bills.where(:venue_management_main_id.in=>@main_ids).page(params[:page]).per(10) + end + @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" + if request.xhr? + render 'admin/venue_management_bills/_index' + end end def venue_management_contracts @table_fields = [ diff --git a/app/models/venue_management_bill.rb b/app/models/venue_management_bill.rb index 6f2ffa8..7c8711f 100644 --- a/app/models/venue_management_bill.rb +++ b/app/models/venue_management_bill.rb @@ -5,7 +5,7 @@ class VenueManagementBill include Mongoid::Enum BILLTYPE = {'venue_fee'=>["usage_fee", "royalties", "admin_fee", "land_rent"],'utility_bill'=>['electricity','water'],'tax'=>['house_tax','land_tax'],'prejudgment_interest'=>["usage_fee", "royalties", "admin_fee", "land_rent",'electricity','water','house_tax','land_tax','other'],'other'=>['penalty','other']} CACULATIONBASISTYPE = {'revenue'=>{'revenue'=>{},'level_0'=>{'fields'=>['field_value','percent']},'level_1'=>{'fields'=>['field_value','percent']},'level_2'=>{'fields'=>['field_value','percent']},'level_3'=>{'fields'=>['field_value','percent']},'level_4'=>{'fields'=>['field_value','percent']},'level_5'=>{'fields'=>['field_value','percent']}}, - 'degree'=>{'current_degree'=>{'float'=>'left'},'consumption'=>{'float'=>'left','clear'=>true,'no_margin'=>true},'level_0'=>{'fields'=>['field_value','dollar/degree']},'level_1'=>{'fields'=>['field_value','dollar/degree']},'level_2'=>{'fields'=>['field_value','dollar/degree']},'level_3'=>{'fields'=>['field_value','dollar/degree']}}, + 'degree'=>{'current_degree'=>{'float'=>'left'},'consumption'=>{'float'=>'left','clear'=>true,'no_margin'=>true},'level_0'=>{'fields'=>['field_value','dollar/degree']},'level_1'=>{'fields'=>['field_value','dollar/degree']},'level_2'=>{'fields'=>['field_value','dollar/degree']},'level_3'=>{'fields'=>['field_value','dollar/degree']},'add_and_subtract'=>{'unit'=>'add_and_subtract_hint'}}, 'actual_bill'=>{'bill_amount'=>{}}, 'fixed'=>{'amount'=>{}}, 'taxable_present_value'=>{'present_value'=>{},'taxable_area'=>{'unit'=>'㎡'},'taxable_tax'=>{}}, @@ -34,6 +34,7 @@ class VenueManagementBill f=field_values.shift(1) field_values.push(f[0]) result += inner_product(field_values,dollardegrees) + result += add_and_subtract if(result < 0) result = 0", "actual_bill"=>" @@ -59,6 +60,7 @@ class VenueManagementBill } CACULATIONBASIS = {'revenue'=>"revenue", "degree"=>"consumption", + "actual_bill" => "bill_amount", "fixed"=>"amount", "taxable_present_value"=>"present_value", "announced_land_values"=>"land_values", @@ -94,6 +96,7 @@ class VenueManagementBill field :taxable_area field :land_values field :taxable_tax + field :add_and_subtract belongs_to :venue_management_main include VenueLinkFile # after_initialize do |record| diff --git a/app/views/admin/venue_management_bills/_form.html.erb b/app/views/admin/venue_management_bills/_form.html.erb index 5317342..52079d0 100644 --- a/app/views/admin/venue_management_bills/_form.html.erb +++ b/app/views/admin/venue_management_bills/_form.html.erb @@ -37,13 +37,13 @@
- <%= f.datetime_picker :accounting_month, :no_label => true, :format=>"yyyy/MM", :new_record => new_record %> + <%= f.org_datetime_picker :accounting_month, :no_label => true, :format=>"yyyy/MM", :new_record => new_record %>
- <%= f.select :bill_typeA, @venue_management_bill.class::BILLTYPE.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] },{},{:onchange=>"var $this=this;console.log($this.value);(function(){var obj=#{@venue_management_bill.class::BILLTYPE.map{|k,v| [k,v.map{|vv| [vv,I18n.t("vm_bill.#{vv}")]}.to_h]}.to_h.to_s.gsub('=>',':')};$($this).siblings('select').html($.map(obj[$this.value],function(v,k){return \'\'}).join(\' \'))})()"} %> + <%= f.select :bill_typeA, @venue_management_bill.class::BILLTYPE.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] },{},{:onchange=>"var $this=this;(function(){var obj=#{@venue_management_bill.class::BILLTYPE.map{|k,v| [k,v.map{|vv| [vv,I18n.t("vm_bill.#{vv}")]}.to_h]}.to_h.to_s.gsub('=>',':')};$($this).siblings('select').html($.map(obj[$this.value],function(v,k){return \'\'}).join(\' \'))})()"} %> <% bill_typeB = new_record ? @venue_management_bill.class::BILLTYPE.values.first : @venue_management_bill.class::BILLTYPE[@venue_management_bill.bill_typeA] %> <%= f.select :bill_typeB, bill_typeB.map { |v| [ I18n.t("vm_bill.#{v}"), v ] }, {}, {:onchange=> "var $this=this;(function(){if($this.value == 'other') $('#bill_other_field').removeClass('hidden');else $('#bill_other_field').addClass('hidden');})()"} %>
@@ -94,7 +94,11 @@ <% end %> <% end %> - <%= (v['unit'].to_s rescue "") %> + <% if ( t("vm_bill")[v['unit'].to_sym].nil? rescue true) %> + <%= (v['unit'].to_s rescue "") %> + <% else %> + <%= (t("vm_bill.#{v['unit'].to_s}") rescue "") %> + <% end %>
@@ -195,7 +199,13 @@ end end end - html += (" "+v['unit'].to_s+ "" rescue "") + html += " " + if ( t("vm_bill")[v['unit'].to_sym].nil? rescue true) + html += (v['unit'].to_s rescue "") + else + html += (t("vm_bill.#{v['unit'].to_s}") rescue "") + end + html += "" html += "
" if(v['clear'] rescue false) html += "
" @@ -235,7 +245,6 @@ return index; } }) - console.log(index); return index; } function update_result(){ @@ -289,7 +298,7 @@ ") }.select{|s| s.present?}.join(" ")+ 'default:'+ - 'console.log("error"); + ' break;}').html_safe %> eval.call(this,formula); diff --git a/app/views/admin/venue_management_bills/_index.html.erb b/app/views/admin/venue_management_bills/_index.html.erb index fa4aba1..07e2d8b 100644 --- a/app/views/admin/venue_management_bills/_index.html.erb +++ b/app/views/admin/venue_management_bills/_index.html.erb @@ -1,3 +1,10 @@ +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "lib/bootstrap-fileupload" %> + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + <%= javascript_include_tag "lib/file-type" %> + <%= javascript_include_tag "lib/module-area" %> +<% end %> diff --git a/app/views/admin/venue_management_bills/index.html.erb b/app/views/admin/venue_management_bills/index.html.erb index be82942..ce7e858 100644 --- a/app/views/admin/venue_management_bills/index.html.erb +++ b/app/views/admin/venue_management_bills/index.html.erb @@ -1,3 +1,4 @@ +<%= render_filter @filter_fields, "index_table" %> <%= render 'index' %> diff --git a/app/views/admin/venue_managements/venue_management_bills.html.erb b/app/views/admin/venue_managements/venue_management_bills.html.erb index ceec95f..92a7595 100644 --- a/app/views/admin/venue_managements/venue_management_bills.html.erb +++ b/app/views/admin/venue_managements/venue_management_bills.html.erb @@ -1,3 +1,4 @@ +<%= render_filter @filter_fields, "index_table" %> <%= render 'admin/venue_management_bills/index' %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 3d27273..1aec8ac 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -22,6 +22,7 @@ en: verification_failed: Verification Failed #驗證碼錯誤 venue_management: + search: Search reminder: Reminder print_pdf: Print send_email_reminder: Send email reminder @@ -190,6 +191,8 @@ en: event_date: Event Date details: Details vm_bill: + add_and_subtract_hint: Please add a minus sign before the number if it's minus! + add_and_subtract: Add and subtract contractor: Contractor accounting_month: Accounting month bill_type: Bill type diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 25c56f5..6234c83 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -22,6 +22,7 @@ zh_tw: verification_failed: 驗證碼錯誤 venue_management: + search: 查詢 reminder: 提醒 print_pdf: 列印 send_email_reminder: 寄送Email提醒 @@ -190,6 +191,8 @@ zh_tw: event_date: 事件日期 details: 事件內容 vm_bill: + add_and_subtract_hint: 若為扣除金額請於數字前方填寫減號 ( - ) + add_and_subtract: 加減金額 contractor: 廠商 accounting_month: 列帳年月 bill_type: 費用別