diff --git a/app/controllers/admin/venue_management_bills_controller.rb b/app/controllers/admin/venue_management_bills_controller.rb index f2788cb..c816eda 100644 --- a/app/controllers/admin/venue_management_bills_controller.rb +++ b/app/controllers/admin/venue_management_bills_controller.rb @@ -1,16 +1,12 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController include Admin::VenueManagementsHelper include ActionView::Helpers::FormOptionsHelper - include ActionView::Helpers::FormTagHelper - include ActionView::Helpers::FormHelper + #include ActionView::Helpers::FormTagHelper #don't include this helper,or you will got an error when using redirect_to and url_for + #include ActionView::Helpers::FormHelper #don't include this helper,or you will got an error when using redirect_to and url_for 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' @@ -20,9 +16,6 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController :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', @@ -44,17 +37,17 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController 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_type_select_str += render_html('<%= 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(\' \'))})()"} %>',{:value_bill_typeA=>value_bill_typeA}) 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 += render_html('<%= 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_typeB=>bill_typeB,:value_bill_typeB=>value_bill_typeB}) + bill_type_select_str += render_html('<%= 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)})) + + (render_html('<%= 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')) + + (render_html('<%= 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)}) %>' ) ) + + render_html("submit_tag(I18n.t('venue_management.search'))") + '
') filter_tags = params[:filters]["type"].to_a rescue [] @main_ids = nil @@ -72,7 +65,13 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController 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) + if accounting_month_start != 0 && accounting_month_end != 0 + @bills = VenueManagementBill.where(:accounting_month.gt=>accounting_month_start,:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10) + elsif accounting_month_start != 0 + @bills = VenueManagementBill.where(:accounting_month.gt=>accounting_month_start).page(params[:page]).per(10) + elsif accounting_month_end != 0 + @bills = VenueManagementBill.where(:accounting_month.lte=>accounting_month_end).page(params[:page]).per(10) + end 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) @@ -85,6 +84,9 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController if !@main_ids.nil? @bills = @bills.where(:venue_management_main_id.in=>@main_ids).page(params[:page]).per(10) end + if @bills.nil? + @bills = VenueManagementBill.all.page(params[:page]).per(10) + end @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" if request.xhr? render '_index' @@ -134,7 +136,9 @@ class Admin::VenueManagementBillsController < Admin::VenueAdminController redirect_to venue_management_bills_admin_venue_management_path(@venue_management_main_id) end - + def render_html(code,pass_variables={}) + render_to_string(:inline=>code,:locals=>pass_variables) + end private def set_venue_management_bill diff --git a/app/controllers/admin/venue_managements_controller.rb b/app/controllers/admin/venue_managements_controller.rb index afa5df9..ea2cc9c 100644 --- a/app/controllers/admin/venue_managements_controller.rb +++ b/app/controllers/admin/venue_managements_controller.rb @@ -1,21 +1,14 @@ # encoding: utf-8 class Admin::VenueManagementsController < Admin::VenueAdminController include ActionView::Helpers::FormOptionsHelper - include ActionView::Helpers::FormTagHelper - include ActionView::Helpers::FormHelper + #include ActionView::Helpers::FormTagHelper #don't include this helper,or you will got an error when using redirect_to and url_for + #include ActionView::Helpers::FormHelper #don't include this helper,or you will got an error when using redirect_to and url_for 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" @@ -358,20 +351,20 @@ class Admin::VenueManagementsController < Admin::VenueAdminController @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 = "
" - 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_type_select_str += render_html('<%= 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(\' \'))})()"} %>',{:value_bill_typeA=>value_bill_typeA}) 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 += render_html('<%= 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_typeB=>bill_typeB,:value_bill_typeB=>value_bill_typeB}) + bill_type_select_str += render_html('<%= 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)})) + + (render_html('<%= 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')) + + (render_html('<%= 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)}) %>' ) ) + + render_html("submit_tag(I18n.t('venue_management.search'))") + '
') filter_tags = params[:filters]["type"].to_a rescue [] @main_ids = nil @@ -417,7 +410,9 @@ class Admin::VenueManagementsController < Admin::VenueAdminController @contracts = @venue_management.venue_management_contracts.page(params[:page]).per(10) @venue_management_page_url = Page.where(:module =>"venue_management").last.url rescue "" end - + def render_html(code,pass_variables={}) + render_to_string(:inline=>code,:locals=>pass_variables) + end private def set_venue_management diff --git a/app/models/venue_management_bill.rb b/app/models/venue_management_bill.rb index 7c8711f..565410e 100644 --- a/app/models/venue_management_bill.rb +++ b/app/models/venue_management_bill.rb @@ -4,12 +4,14 @@ class VenueManagementBill include Mongoid::Timestamps 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']} + NOTFIELDKEY = ['float','fields','clear','no_margin','unit','display_title','display_unit','option_select'] 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']},'add_and_subtract'=>{'unit'=>'add_and_subtract_hint'}}, 'actual_bill'=>{'bill_amount'=>{}}, 'fixed'=>{'amount'=>{}}, 'taxable_present_value'=>{'present_value'=>{},'taxable_area'=>{'unit'=>'㎡'},'taxable_tax'=>{}}, 'announced_land_values'=>{'land_values'=>{},'taxable_area'=>{'unit'=>'㎡'},'taxable_tax'=>{}}, + 'interest'=>{'bills_payable'=>{},'delay_in_days'=>{},'delay_in_days_level_1'=>{'day'=>{},'_interest'=>{'display_title'=>'front','unit'=>'%'},'interest_type'=>{'display_title'=>'none','option_select'=>['annual_interest','double_dividend','daily_interest'],'type'=>'radio'}},'delay_in_days_level_2'=>{'day'=>{},'_interest'=>{'display_title'=>'front','unit'=>'%'},'interest_type'=>{'display_title'=>'none','option_select'=>['annual_interest','double_dividend','daily_interest'],'type'=>'radio'}},'delay_in_days_level_3'=>{'day'=>{},'_interest'=>{'display_title'=>'front','unit'=>'%'},'interest_type'=>{'display_title'=>'none','option_select'=>['annual_interest','double_dividend','daily_interest'],'type'=>'radio'}},'add_and_subtract'=>{'unit'=>'add_and_subtract_hint'}}, 'other'=>{'amount'=>{}}} CACILATYIONFORMULA = {'revenue'=>" i = find_insert_index(field_values,revenue) @@ -22,8 +24,9 @@ class VenueManagementBill field_values.push(f[0]) result += inner_product(field_values,percents) result = result / 100 - if(result < 0) - result = 0", + if(result < 0){ + result = 0 + }", "degree"=>" i = find_insert_index(field_values,consumption) field_values = field_values.slice(0,i) @@ -35,28 +38,76 @@ class VenueManagementBill field_values.push(f[0]) result += inner_product(field_values,dollardegrees) result += add_and_subtract - if(result < 0) - result = 0", + if(result < 0){ + result = 0 + } + ", "actual_bill"=>" result = bill_amount - if(result < 0) - result = 0", + if(result < 0){ + result = 0 + } + ", "fixed"=>" result = amount - if(result < 0) - result = 0", + if(result < 0){ + result = 0 + } + ", "taxable_present_value"=>" result = taxable_tax - if(result < 0) - result = 0", + if(result < 0){ + result = 0 + }", "announced_land_values"=>" result = taxable_tax - if(result < 0) - result = 0", + if(result < 0){ + result = 0 + }", "other"=>" result = amount - if(result < 0) - result = 0" + if(result < 0){ + result = 0 + }", + 'interest'=>" + i = find_insert_index(days,delay_in_days) + ref = JSON.parse(\"{\\\"annual_interest\\\": #{1/365.0},\\\"double_dividend\\\": #{1/2.0},\\\"daily_interest\\\": #{1/1.0}}\") + if(days[i-1] < delay_in_days && interest_types[i-1] != undefined ){ + result = _interests[i - 1] * (delay_in_days * ref[interest_types[i-1]]).ceil() + }else{ + if(i != 1 && days[i-2] < delay_in_days && interest_types[i-2] != undefined ){ + result = _interests[i - 2] * (delay_in_days * ref[interest_types[i-2]]).ceil() + }else{ + result = 0 + } + } + result = result / 100 + result = result * bills_payable + result += add_and_subtract + if(result < 0){ + result = 0 + } + ", + 'old_interest'=>" + i = find_insert_index(days,delay_in_days) + days = days.slice(0,i) + _interests = _interests.slice(0,i) + days.push(delay_in_days) + _interests.push(0) + result = inner_product_to_array(days,_interests) + result = array_multiply_scalar(result,-1) + f=days.shift(1) + days.push(f[0]) + result2 = inner_product_to_array(days,_interests) + result = array_add(result,result2) + result = inner_product_to_array(result,interest_types,JSON.parse(\"{\\\"annual_interest\\\": #{1/365.0},\\\"double_dividend\\\": #{1/2.0},\\\"daily_interest\\\": #{1/1.0}}\")) + result = sum(result) + result = result / 100 + result = result * bills_payable + result += add_and_subtract + if(result < 0) + result = 0 + " } CACULATIONBASIS = {'revenue'=>"revenue", "degree"=>"consumption", @@ -64,6 +115,7 @@ class VenueManagementBill "fixed"=>"amount", "taxable_present_value"=>"present_value", "announced_land_values"=>"land_values", + 'interest'=>'bills_payable', "other"=>"amount" } field :accounting_month, type: Date, default: Time.now @@ -86,6 +138,9 @@ class VenueManagementBill field :level_3 field :level_4 field :level_5 + field :delay_in_days_level_1 + field :delay_in_days_level_2 + field :delay_in_days_level_3 field :current_degree field :consumption field :tax_excluded, type: Boolean, default: false @@ -97,6 +152,8 @@ class VenueManagementBill field :land_values field :taxable_tax field :add_and_subtract + field :bills_payable + field :delay_in_days belongs_to :venue_management_main include VenueLinkFile # after_initialize do |record| @@ -132,9 +189,57 @@ class VenueManagementBill def pay_date return "#{self.deadline}/#{self.received_date}" end - def inner_product(a,b) + def inner_product(a,b,ref_val_for_b={}) result = 0 - a.each.with_index{|v,i| result += v*b[i] if b[i].present?} + a.each.with_index{|v,i| + if ref_val_for_b.blank? + p = v*b[i] rescue nil; + else + p = v*ref_val_for_b[b[i]] rescue nil; + end + if(!p.nil?) + result += p; + end + } return result end + def inner_product_to_array(a,b) + result = [] + a.each.with_index{|v,i| + p = v*b[i] rescue nil; + if(!p.nil?) + result.push(p); + end + } + return result + end + def array_multiply_scalar(arr,scalar) + result = []; + arr.each.with_index{|v,i| + p = v*scalar rescue nil; + if(!p.nil?) + result.push(p); + end + } + return result; + end + def array_add(arr1,arr2) + result = []; + arr1.each.with_index{|v,i| + p = v + arr2[i] rescue nil; + if(!p.nil?) + result.push(p); + end + } + return result; + end + def sum(arr) + result = 0; + arr.each.with_index{|v,i| + if(!v.nil?) + result += v; + end + } + return result; + end end diff --git a/app/views/admin/venue_management_bills/_form.html.erb b/app/views/admin/venue_management_bills/_form.html.erb index 52079d0..4c94094 100644 --- a/app/views/admin/venue_management_bills/_form.html.erb +++ b/app/views/admin/venue_management_bills/_form.html.erb @@ -83,8 +83,9 @@
>
+ <% other_keys = (v.keys - @venue_management_bill.class::NOTFIELDKEY) rescue [] %> <% if ( v['fields'].blank? rescue true) %> - <%= f.text_field k %> + <%= f.text_field k if other_keys.blank? %> <% else %> <% v['fields'].each do |field_key| %> <%= f.fields_for k do |f|%> @@ -93,6 +94,36 @@ <% end %> <% end %> <% end %> + <% if other_keys.present? %> + <% other_keys.each do |field_key| %> + <%= f.fields_for k do |f|%> + <%= t("vm_bill.#{field_key}") if v[field_key]['display_title'] == 'front' %> + <% if v[field_key]['option_select'].blank? %> + <%= f.text_field field_key,:value => (@venue_management_bill.send(k)[field_key] rescue "") %> + <% else %> + <% if v[field_key]['type'].nil? || v[field_key]['type'] == 'select' %> + <%= f.select field_key , options_for_select(v[field_key]['option_select'].map{|o| [t("vm_bill.#{o}"),o]} ,(@venue_management_bill.send(k)[field_key] rescue "")) %> + <% else %> + <% value = (@venue_management_bill.send(k)[field_key] rescue "") %> + <% v[field_key]['option_select'].each do |o| %> + + /> + <%= t("vm_bill.#{o}") %> + + <% end %> + <% end %> + <% end %> + <%= t("vm_bill.#{field_key}") if (field_key != 'field_value' && !v[field_key].has_key?('display_title') ) %> + + <% if ( t("vm_bill")[v[field_key]['unit'].to_sym].nil? rescue true) %> + <%= (v[field_key]['unit'].to_s rescue "") %> + <% else %> + <%= (t("vm_bill.#{v[field_key]['unit'].to_s}") rescue "") %> + <% end %> + + <% end %> + <% end %> + <% end %> <% if ( t("vm_bill")[v['unit'].to_sym].nil? rescue true) %> <%= (v['unit'].to_s rescue "") %> @@ -189,16 +220,49 @@ vv.each do |k,v| no_margin = (v['no_margin'] rescue false) ? 'no_margin' : '' html += "
" + + other_keys = (v.keys - @venue_management_bill.class::NOTFIELDKEY) rescue [] if ( v['fields'].blank? rescue true) - html += (f.text_field(k)) + html += f.text_field(k) if other_keys.blank? else v['fields'].each do |field_key| f.fields_for k do |f| - html += (f.text_field(field_key,:value => (@venue_management_bill.send(k)[field_key] rescue ""))) - html += (" "+t("vm_bill.#{field_key}")) if field_key != 'field_value' + html += f.text_field(field_key,:value => (@venue_management_bill.send(k)[field_key] rescue "")) + html += t("vm_bill.#{field_key}") if field_key != 'field_value' end end end + if other_keys.present? + other_keys.each do |field_key| + f.fields_for k do |f| + html += t("vm_bill.#{field_key}") if v[field_key]['display_title'] == 'front' + if v[field_key]['option_select'].blank? + html += f.text_field(field_key,:value => (@venue_management_bill.send(k)[field_key] rescue "")) + else + if v[field_key]['type'].nil? || v[field_key]['type'] == 'select' + html += f.select(field_key , options_for_select(v[field_key]['option_select'].map{|o| [t("vm_bill.#{o}"),o]} ,(@venue_management_bill.send(k)[field_key] rescue ""))) + else + value = (@venue_management_bill.send(k)[field_key] rescue "") + v[field_key]['option_select'].each do |o| + html += '' + html += "" + html += t("vm_bill.#{o}") + html += '' + end + end + end + html += t("vm_bill.#{field_key}") if (field_key != 'field_value' && !v[field_key].has_key?('display_title') ) + html += '' + if ( t("vm_bill")[v[field_key]['unit'].to_sym].nil? rescue true) + html += (v[field_key]['unit'].to_s rescue "") + else + html += (t("vm_bill.#{v[field_key]['unit'].to_s}") rescue "") + end + html += '' + end + end + end + html += " " if ( t("vm_bill")[v['unit'].to_sym].nil? rescue true) html += (v['unit'].to_s rescue "") @@ -216,7 +280,7 @@ %> var cbt_html = <%=cbt_html.to_s.gsub('=>',':').html_safe %>; //var cbt_init_func = <%#=cbt.map{|k,v| [k,v.map{|kk,vv| (vv["fields"].blank? rescue true) ? ("#{kk}=0") : (vv["fields"].map{|field| "#{field.gsub('/','')}s=[]"}.join(";")) }.join(";")]}.to_h.to_s.gsub('=>',':').html_safe %>; - <%=cbt.map{|k,v| v.map{|kk,vv| (vv["fields"].blank? rescue true) ? ("#{kk}=0") : (vv["fields"].map{|field| "#{field.gsub('/','')}s={}"}.join(";")) }.join(";")}.join(";").to_s.gsub('=>',':').html_safe %> + <%=cbt.map{|k,v| v.map{|kk,vv| fields=vv["fields"].to_a;other_keys = (vv.keys - @venue_management_bill.class::NOTFIELDKEY) rescue [];fields.concat(other_keys);(fields.blank? rescue true) ? ("#{kk}=0") : (fields.map{|field| "#{field.gsub('/','')}s={}"}.join(";")) }.join(";")}.join(";").to_s.gsub('=>',':').html_safe %> $("#caculation_basis_type").on('change',function(){ $("#caculation_basis_content").html(cbt_html[this.value]); update_result(); @@ -224,18 +288,64 @@ update_result(); }) }) - <% cbt_fields = cbt.map{|k,v| [k,v.flat_map{|kk,vv| vv['fields'].to_a.map{|f| f.gsub('/','')+"s"}}.select{|f| f != "s"}.uniq] }.to_h %> + <% cbt_fields = cbt.map{|k,v| [k,v.flat_map{|kk,vv| fields=vv["fields"].to_a;other_keys = (vv.keys - @venue_management_bill.class::NOTFIELDKEY) rescue [];fields.concat(other_keys);fields.map{|f| f.gsub('/','')+"s"}}.select{|f| f != "s"}.uniq] }.to_h %> var cbt = <%= cbt_fields.to_s.gsub('=>',':').html_safe%>; + Number.prototype.ceil = function(){ + return Math.ceil(this) + } function inner_product(a,b){ var result = 0; $.each(a,function(i,v){ - var p = v*b[i] + var p = v*b[i]; if(!isNaN(p)){ result += p; } }) return result; } + function inner_product_to_array(a,b,ref_val_for_b={}){ + var result = []; + $.each(a,function(i,v){ + var p; + if(Object.keys(ref_val_for_b).length == 0) + p = v*b[i]; + else + p = v*ref_val_for_b[b[i]]; + if(!isNaN(p)){ + result.push(p); + } + }) + return result; + } + function array_multiply_scalar(arr,scalar){ + var result = []; + $.each(arr,function(i,v){ + var p = v*scalar; + if(!isNaN(p)){ + result.push(p); + } + }) + return result; + } + function array_add(arr1,arr2){ + var result = []; + $.each(arr1,function(i,v){ + var p = v + arr2[i]; + if(!isNaN(p)){ + result.push(p); + } + }) + return result; + } + function sum(arr){ + var result = 0; + $.each(arr,function(i,v){ + if(!isNaN(v)){ + result += v; + } + }) + return result; + } function find_insert_index(arr,val){ var index = 0; arr.forEach(function(v){ @@ -250,7 +360,7 @@ function update_result(){ var formula = CACILATYIONFORMULA[calculate_type].replace('f[0]','f'); //(function(){eval.call(this,cbt_init_func[calculate_type])})(); - <%=cbt.map{|k,v| v.map{|kk,vv| (vv["fields"].blank? rescue true) ? ("#{kk}=0") : (vv["fields"].map{|field| "#{field.gsub('/','')}s={}"}.join(";")) }.join(";")}.join(";").to_s.gsub('=>',':').html_safe %> + <%=cbt.map{|k,v| v.map{|kk,vv| fields=vv["fields"].to_a;other_keys = (vv.keys - @venue_management_bill.class::NOTFIELDKEY) rescue [];fields.concat(other_keys);(fields.blank? rescue true) ? ("#{kk}=0") : (fields.map{|field| "#{field.gsub('/','')}s={}"}.join(";")) }.join(";")}.join(";").to_s.gsub('=>',':').html_safe %> $("#caculation_basis_content input").each(function(i,input){ var name = input.name; name = name.replace('venue_management_bill',''); @@ -258,13 +368,36 @@ name = name.replace('[','').replace(']',''); eval.call(this,''+name+"="+Number(input.value).toString()) }else{ - field_name = name.split("[").slice(1)[0].replace(']',''); - name = name.split("[").slice(1).last().replace(']','') + 's'; + var temp_arr = name.split("[").slice(1) + field_name = temp_arr[0].replace(']',''); + name = temp_arr.last().replace(']','') + 's'; + var arr_flag = false; + if(name == "s"){ + name = temp_arr[temp_arr.length - 2].replace(']','') + 's'; + arr_flag = true; + } name = name.replace("/","") - if(input.value != "") - eval.call(this,name)[field_name] = Number(input.value); + if(input.value != ""){ + var val = Number(input.value); + if( Number.isNaN(val) && input.value != "" ) + val = input.value; + if(arr_flag){ + if(window[name][field_name] == undefined) + window[name][field_name] = []; + if(input.checked && window[name][field_name].indexOf(val) == -1) + window[name][field_name].push(val); + } + else{ + if(input.type == 'radio' || input.type == 'checkbox' ){ + if( input.checked ) + window[name][field_name] = val; + } + else + window[name][field_name] = val; + } + } else - eval.call(this,name)[field_name] = null; + window[name][field_name] = null; } }) var ks = cbt[calculate_type]; diff --git a/app/views/admin/venue_managements/export.xlsx.axlsx b/app/views/admin/venue_managements/export.xlsx.axlsx index f08b012..37f26fe 100644 --- a/app/views/admin/venue_managements/export.xlsx.axlsx +++ b/app/views/admin/venue_managements/export.xlsx.axlsx @@ -42,7 +42,7 @@ wb.add_worksheet(name: t('restful_actions.venue_management_contracts')) do |shee sheet.add_row row @venue_management.venue_management_contracts.each do |contract| row2 = [] - row2 << contract.venue_management_inviting.case_no + row2 << contract.case_no row2 << contract.display_tags row2 << contract.display_contractors row2 << "#{contract.early_rent} / #{contract.operation_rent}" diff --git a/config/locales/en.yml b/config/locales/en.yml index 1aec8ac..c0ed524 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -191,6 +191,17 @@ en: event_date: Event Date details: Details vm_bill: + delay_in_days_level_1: Delay in days level 1 + delay_in_days_level_2: Delay in days level 2 + delay_in_days_level_3: Delay in days level 3 + bills_payable: bills_payable + delay_in_days: Delay in days + day: Day + _interest: ', Interest' + interest: Interest + annual_interest: Annual interest + double_dividend: Double Dividend + daily_interest: Daily interest add_and_subtract_hint: Please add a minus sign before the number if it's minus! add_and_subtract: Add and subtract contractor: Contractor diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 6234c83..11ed844 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -191,6 +191,17 @@ zh_tw: event_date: 事件日期 details: 事件內容 vm_bill: + delay_in_days_level_1: 延遲天數級距一 + delay_in_days_level_2: 延遲天數級距二 + delay_in_days_level_3: 延遲天數級距三 + bills_payable: 應繳費用 + delay_in_days: 延遲天數 + day: 天 + annual_interest: 年息 + double_dividend: 雙日息 + daily_interest: 日息 + _interest: ',利息' + interest: 利息 add_and_subtract_hint: 若為扣除金額請於數字前方填寫減號 ( - ) add_and_subtract: 加減金額 contractor: 廠商