Change a lot about venue bill.

This commit is contained in:
BoHung Chiu 2020-10-02 15:53:48 +08:00
parent 8e672b38e9
commit ff52810237
7 changed files with 280 additions and 9 deletions

View File

@ -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

View File

@ -10,6 +10,22 @@
<%= javascript_include_tag "lib/file-type" %>
<%= javascript_include_tag "lib/module-area" %>
<% end %>
<style type="text/css">
.unit{
font-size: initial;
font-weight: bold;
}
.normal{
font-size: initial;
}
.control-label.no_margin{
width: auto;
}
.controls.no_margin{
float: left;
margin: 0;
}
</style>
<!-- Input Area -->
<div class="input-area">
@ -53,19 +69,57 @@
</div>
</div>
</div>
<% cbt = @venue_management_bill.class::CACULATIONBASISTYPE %>
<div class="control-group">
<label class="control-label muted"><%= t('vm_bill.caculation_basis') %></label>
<div class="controls">
<%= 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' %>
</div>
</div>
<% caculation_basis_type = (@venue_management_bill.new_record? ? cbt.keys.first : @venue_management_bill.caculation_basis_type) %>
<div id="caculation_basis_content">
<% cbt[caculation_basis_type].each do |k,v| %>
<% no_margin = (v['no_margin'] rescue false) ? 'no_margin' : '' %>
<div class="control-group" <%= (v['float'].blank? rescue true) ? '' : "style=\"float: #{v['float']};\"".html_safe %>>
<label class="control-label <%=no_margin%>"><%= t("vm_bill.#{k}") %></label>
<div class="controls <%=no_margin%>">
<% 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 %>
<span class="unit">
<%= (v['unit'].to_s rescue "") %>
</span>
</div>
</div>
<% if(v['clear'] rescue false) %>
<div style="clear: both;"></div>
<% end %>
<% end %>
</div>
<div style="clear: both;"></div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_bill.amount') %></label>
<div class="controls">
<%= f.number_field :amount %>
<div class="control-label muted normal"><%=f.check_box :tax_excluded, :id=>"tax_excluded" %></div>
<div class="controls normal">
<%=t('vm_bill.tax_excluded')%>
</div>
</div>
<% fields = ['total_amount' ,'actual_amount','tax'] %>
<% fields.each_with_index do |field,i| %>
<div class="control-group" style="float: left;">
<div class="control-label normal <%= ( (i == 0) ? '' : 'no_margin')%>"><%=t("vm_bill.#{field}") %></div>
<div class="controls normal <%= ( (i == 0) ? '' : 'no_margin')%>">
<%= f.text_field field, :id=>field, :size=>'15', :style=>"width: auto;" %>
</div>
</div>
<% end %>
<div style="clear: both;"></div>
<div class="control-group">
<label class="control-label muted"><%= t('vm_bill.deadline') %></label>
<div class="controls">
@ -124,3 +178,92 @@
<input type="hidden" name="referer_url" value="<%= get_referer_url %>">
<%= link_to t('cancel'), venue_management_memorabilias_admin_venue_management_path(id: @venue_management.id), :class=>"btn" %>
</div>
<script type="text/javascript">
<% cbt_html = {}
cbt.each do |kk,vv|
html = ""
vv.each do |k,v|
no_margin = (v['no_margin'] rescue false) ? 'no_margin' : ''
html += "<div class=\"control-group\" #{(v['float'].blank? rescue true) ? '' : "style=\"float: #{v['float']};\""}><label class=\"control-label #{no_margin}\">#{t("vm_bill.#{k}")}</label><div class=\"controls #{no_margin}\">"
if ( v['fields'].blank? rescue true)
html += (f.text_field(k))
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'
end
end
end
html += ("<span class=\"unit\"> "+v['unit'].to_s+ "</span>" rescue "")
html += "</div></div>"
if(v['clear'] rescue false)
html += "<div style=\"clear: both;\"></div>"
end
end
cbt_html[kk] = html
end
%>
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 %>
$("#caculation_basis_type").on('change',function(){
$("#caculation_basis_content").html(cbt_html[this.value]);
update_result();
$("#caculation_basis_content input").off("input").on("input",function(){
update_result();
})
})
function inner_product(a,b){
var result = 0;
$.each(a,function(i,v){
var p = v*b[i]
if(!isNaN(p)){
result += p;
}
})
return result;
}
function update_result(){
var formula = CACILATYIONFORMULA[calculate_type].replace('f[0]','f');
console.log(calculate_type);
//(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 %>
$("#caculation_basis_content input").each(function(i,input){
var name = input.name;
name = name.replace('venue_management_bill','');
if(name.split('[').length == 2){
name = name.replace('[','').replace(']','');
eval.call(this,''+name+"="+Number(input.value).toString())
}else{
name = name.split("[").slice(1).last().replace(']','') + 's';
name = name.replace("/","")
if(input.value != "")
eval.call(this,''+name+".push("+Number(input.value).toString()+")")
}
})
eval.call(this,formula);
console.log(result);
if($("#tax_excluded").prop("checked")){
$("#total_amount").val(Math.round(result*1.05));
$("#actual_amount").val(Math.round(result));
$("#tax").val(Math.round(result*0.05));
}else{
$("#total_amount").val(Math.round(result));
$("#actual_amount").val(Math.round(result/1.05));
$("#tax").val(Math.round(result*0.05/1.05));
}
}
var CACILATYIONFORMULA = <%=@venue_management_bill.class::CACILATYIONFORMULA.to_s.gsub('=>',':').html_safe %>;
var calculate_type = $("#caculation_basis_type").val();
$("#caculation_basis_type").click(function(){
calculate_type = this.value;
update_result();
})
$("#tax_excluded").click(function(){
update_result();
})
$("#caculation_basis_content input").off("input").on("input",function(){
update_result();
})
</script>

View File

@ -37,7 +37,7 @@
-<%=bill.bill_other%>
<% end %>
</td>
<td><%= "#{t("vm_bill.#{bill.caculation_basis_type}")}: #{bill.caculation_basis}" %></td>
<td><%= bill.display_caculation_basis %></td>
<td><%= bill.reason %></td>
<td><%= bill.amount %></td>
<td><%= bill.pay_date %></td>

View File

@ -34,7 +34,7 @@
</tr>
<tr>
<th class="venue_managementive-title-field"><%= t('vm_bill.caculation_basis') %></th>
<td class="venue_managementive-title-value"><%= "#{t("vm_bill.#{@venue_management_bill.caculation_basis_type}")}: #{@venue_management_bill.caculation_basis}" %></td>
<td class="venue_managementive-title-value"><%= @venue_management_bill.display_caculation_basis %></td>
</tr>
<tr>
<th class="venue_managementive-title-field"><%= t('vm_bill.reason') %></th>

View File

@ -383,7 +383,7 @@
-<%=bill.bill_other%>
<% end %>
</td>
<td><%= bill.caculation_basis %></td>
<td><%= bill.display_caculation_basis %></td>
<td><%= bill.reason %></td>
<td><%= bill.amount %></td>
<td><%= bill.pay_date %></td>

View File

@ -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

View File

@ -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: 是否得續約