diff --git a/app/models/venue_management_bill.rb b/app/models/venue_management_bill.rb
index dd46eea..fc56e1a 100644
--- a/app/models/venue_management_bill.rb
+++ b/app/models/venue_management_bill.rb
@@ -4,7 +4,47 @@ 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']}
- CACULATIONBASISTYPE = ['revenue','degree']
+ 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']}},
+ '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'=>{}},
+ 'other'=>{'amount'=>{}}}
+ CACILATYIONFORMULA = {'revenue'=>"
+ field_values.push(revenue)
+ percents.push(0)
+ result = -inner_product(field_values,percents)
+ f=field_values.shift(1)
+ field_values.push(f[0])
+ result += inner_product(field_values,percents)
+ result = result / 100",
+ "degree"=>"
+ field_values.push(consumption)
+ dollardegrees.push(0)
+ result = -inner_product(field_values,dollardegrees)
+ f=field_values.shift(1)
+ field_values.push(f[0])
+ result += inner_product(field_values,dollardegrees)
+ ",
+ "actual_bill"=>"
+ result = bill_amount",
+ "fixed"=>"
+ result = amount",
+ "taxable_present_value"=>"
+ result = taxable_tax",
+ "announced_land_values"=>"
+ result = taxable_tax",
+ "other"=>"
+ result = amount"
+ }
+ CACULATIONBASIS = {'revenue'=>"revenue",
+ "degree"=>"consumption",
+ "fixed"=>"amount",
+ "taxable_present_value"=>"present_value",
+ "announced_land_values"=>"land_values",
+ "other"=>"amount"
+ }
field :accounting_month, type: Date, default: Time.now
field :bill_typeA, type: String, default: ""
field :bill_typeB, type: String, default: ""
@@ -17,8 +57,41 @@ class VenueManagementBill
field :received_date, type: Date, default: Time.now
field :pay_method, type: String, default: "", localize: true
field :note, type: String, default: "", localize: true
+ field :revenue
+ field :bill_amount
+ field :level_0
+ field :level_1
+ field :level_2
+ field :level_3
+ field :level_4
+ field :level_5
+ field :current_degree
+ field :consumption
+ field :tax_excluded, type: Boolean, default: false
+ field :total_amount
+ field :actual_amount
+ field :tax
+ field :present_value
+ field :taxable_area
+ field :land_values
+ field :taxable_tax
belongs_to :venue_management_main
include VenueLinkFile
+ # after_initialize do |record|
+ # if record.caculation_basis_type == "degree"
+ # if record.caculation_basis != "" && record.consumption.blank?
+ # record.update(:consumption => record.caculation_basis)
+ # end
+ # elsif record.caculation_basis_type == "revenue"
+ # if record.caculation_basis != "" && record.revenue.blank?
+ # record.update(:revenue => record.caculation_basis)
+ # end
+ # end
+ # end
+ def display_caculation_basis
+ caculation_basis_val = eval("#{self.class::CACULATIONBASIS[self.caculation_basis_type]}")
+ return "#{I18n.t("vm_bill.#{self.caculation_basis_type}")}: #{caculation_basis_val}"
+ end
def display_accounting_month
return (self.accounting_month.strftime("%Y-%m") rescue "")
end
@@ -31,4 +104,9 @@ class VenueManagementBill
def pay_date
return "#{self.deadline}/#{self.received_date}"
end
+ def inner_product(a,b)
+ result = 0
+ a.each.with_index{|v,i| result += v*b[i] if b[i].present?}
+ 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 26ec334..e5a6ab5 100644
--- a/app/views/admin/venue_management_bills/_form.html.erb
+++ b/app/views/admin/venue_management_bills/_form.html.erb
@@ -10,6 +10,22 @@
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
+
@@ -53,19 +69,57 @@
+ <% cbt = @venue_management_bill.class::CACULATIONBASISTYPE %>
<%= t('vm_bill.caculation_basis') %>
- <%= f.select :caculation_basis_type, @venue_management_bill.class::CACULATIONBASISTYPE.map { |k| [ I18n.t("vm_bill.#{k}"), k ] } %>
- <%= f.number_field :caculation_basis %>
+ <%= f.select :caculation_basis_type, cbt.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] }, {}, :id=>'caculation_basis_type' %>
+ <% caculation_basis_type = (@venue_management_bill.new_record? ? cbt.keys.first : @venue_management_bill.caculation_basis_type) %>
+
+ <% cbt[caculation_basis_type].each do |k,v| %>
+ <% no_margin = (v['no_margin'] rescue false) ? 'no_margin' : '' %>
+
>
+
<%= t("vm_bill.#{k}") %>
+
+ <% if ( v['fields'].blank? rescue true) %>
+ <%= f.text_field k %>
+ <% else %>
+ <% v['fields'].each do |field_key| %>
+ <%= f.fields_for k do |f|%>
+ <%= f.text_field field_key,:value => (@venue_management_bill.send(k)[field_key] rescue "") %>
+ <%= t("vm_bill.#{field_key}") if field_key != 'field_value' %>
+ <% end %>
+ <% end %>
+ <% end %>
+
+ <%= (v['unit'].to_s rescue "") %>
+
+
+
+ <% if(v['clear'] rescue false) %>
+
+ <% end %>
+ <% end %>
+
+
-
<%= t('vm_bill.amount') %>
-
- <%= f.number_field :amount %>
+
<%=f.check_box :tax_excluded, :id=>"tax_excluded" %>
+
+ <%=t('vm_bill.tax_excluded')%>
+ <% fields = ['total_amount' ,'actual_amount','tax'] %>
+ <% fields.each_with_index do |field,i| %>
+
+
<%=t("vm_bill.#{field}") %>
+
+ <%= f.text_field field, :id=>field, :size=>'15', :style=>"width: auto;" %>
+
+
+ <% end %>
+
<%= t('vm_bill.deadline') %>
@@ -124,3 +178,92 @@
<%= link_to t('cancel'), venue_management_memorabilias_admin_venue_management_path(id: @venue_management.id), :class=>"btn" %>
+
\ No newline at end of file
diff --git a/app/views/admin/venue_management_bills/_index.html.erb b/app/views/admin/venue_management_bills/_index.html.erb
index ba3fa41..d5581e6 100644
--- a/app/views/admin/venue_management_bills/_index.html.erb
+++ b/app/views/admin/venue_management_bills/_index.html.erb
@@ -37,7 +37,7 @@
-<%=bill.bill_other%>
<% end %>
-
<%= "#{t("vm_bill.#{bill.caculation_basis_type}")}: #{bill.caculation_basis}" %>
+
<%= bill.display_caculation_basis %>
<%= bill.reason %>
<%= bill.amount %>
<%= bill.pay_date %>
diff --git a/app/views/venue_managements/show_bill.html.erb b/app/views/venue_managements/show_bill.html.erb
index bde759b..2bfb29f 100644
--- a/app/views/venue_managements/show_bill.html.erb
+++ b/app/views/venue_managements/show_bill.html.erb
@@ -34,7 +34,7 @@
<%= t('vm_bill.caculation_basis') %>
- <%= "#{t("vm_bill.#{@venue_management_bill.caculation_basis_type}")}: #{@venue_management_bill.caculation_basis}" %>
+ <%= @venue_management_bill.display_caculation_basis %>
<%= t('vm_bill.reason') %>
diff --git a/app/views/venue_managements/show_data.html.erb b/app/views/venue_managements/show_data.html.erb
index 15f83eb..892178f 100644
--- a/app/views/venue_managements/show_data.html.erb
+++ b/app/views/venue_managements/show_data.html.erb
@@ -383,7 +383,7 @@
-<%=bill.bill_other%>
<% end %>
- <%= bill.caculation_basis %>
+ <%= bill.display_caculation_basis %>
<%= bill.reason %>
<%= bill.amount %>
<%= bill.pay_date %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 9a7c56c..8a611d7 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -217,6 +217,31 @@ en:
penalty: Penalty
revenue: Revenue
degree: Degree
+ actual_bill: Actual bill
+ fixed: Fixed
+
+ bill_amount: Bill amount
+ level_0: Level 0
+ level_1: Level 1
+ level_2: Level 2
+ level_3: Level 3
+ level_4: Level 4
+ level_5: Level 5
+ current_degree: Current degree
+ consumption: Consumption
+ tax_excluded: Tax excluded
+ total_amount: Total amount
+ actual_amount: Actual amount
+ tax: Tax
+ taxable_tax: Tax
+ dollar/degree: $/degree
+ taxable_present_value: Taxable present value
+ announced_land_values: Announced land values
+ land_values: Land values
+ present_value: Present value
+ taxable_area: Taxable area
+ percent: %
+
prejudgment_interest: Prejudgment interest
vm_contract:
renewal_permission: Renewal permission
diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml
index 7eedb55..65a097b 100644
--- a/config/locales/zh_tw.yml
+++ b/config/locales/zh_tw.yml
@@ -217,6 +217,31 @@ zh_tw:
penalty: 罰款
revenue: 營業額
degree: 度數
+ actual_bill: 實際帳單
+ fixed: 定額
+
+ bill_amount: 帳單金額
+ level_0: 起始值
+ level_1: 級距一
+ level_2: 級距二
+ level_3: 級距三
+ level_4: 級距四
+ level_5: 級距五
+ current_degree: 本期錶數
+ consumption: 使用度數
+ tax_excluded: 應繳金額稅外加
+ total_amount: 應繳金額
+ actual_amount: 銷售額
+ tax: 稅額
+ taxable_tax: 稅額
+ dollar/degree: 元/度
+ taxable_present_value: 課稅現值
+ announced_land_values: 公告地價
+ land_values: 地價
+ present_value: 現值
+ taxable_area: 課稅⾯積
+ percent: %
+
prejudgment_interest: 遲延利息
vm_contract:
renewal_permission: 是否得續約