Fix bugs.
This commit is contained in:
parent
24294862e4
commit
f4d4fdce94
|
@ -12,6 +12,9 @@ class VenueManagementBill
|
||||||
'announced_land_values'=>{'land_values'=>{},'taxable_area'=>{'unit'=>'㎡'},'taxable_tax'=>{}},
|
'announced_land_values'=>{'land_values'=>{},'taxable_area'=>{'unit'=>'㎡'},'taxable_tax'=>{}},
|
||||||
'other'=>{'amount'=>{}}}
|
'other'=>{'amount'=>{}}}
|
||||||
CACILATYIONFORMULA = {'revenue'=>"
|
CACILATYIONFORMULA = {'revenue'=>"
|
||||||
|
i = find_insert_index(field_values,revenue)
|
||||||
|
field_values = field_values.slice(0,i)
|
||||||
|
percents = percents.slice(0,i)
|
||||||
field_values.push(revenue)
|
field_values.push(revenue)
|
||||||
percents.push(0)
|
percents.push(0)
|
||||||
result = -inner_product(field_values,percents)
|
result = -inner_product(field_values,percents)
|
||||||
|
@ -22,6 +25,9 @@ class VenueManagementBill
|
||||||
if(result < 0)
|
if(result < 0)
|
||||||
result = 0",
|
result = 0",
|
||||||
"degree"=>"
|
"degree"=>"
|
||||||
|
i = find_insert_index(field_values,consumption)
|
||||||
|
field_values = field_values.slice(0,i)
|
||||||
|
dollardegrees = dollardegrees.slice(0,i)
|
||||||
field_values.push(consumption)
|
field_values.push(consumption)
|
||||||
dollardegrees.push(0)
|
dollardegrees.push(0)
|
||||||
result = -inner_product(field_values,dollardegrees)
|
result = -inner_product(field_values,dollardegrees)
|
||||||
|
|
|
@ -206,7 +206,7 @@
|
||||||
%>
|
%>
|
||||||
var cbt_html = <%=cbt_html.to_s.gsub('=>',':').html_safe %>;
|
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 %>;
|
//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| (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_type").on('change',function(){
|
||||||
$("#caculation_basis_content").html(cbt_html[this.value]);
|
$("#caculation_basis_content").html(cbt_html[this.value]);
|
||||||
update_result();
|
update_result();
|
||||||
|
@ -214,6 +214,8 @@
|
||||||
update_result();
|
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 %>
|
||||||
|
var cbt = <%= cbt_fields.to_s.gsub('=>',':').html_safe%>;
|
||||||
function inner_product(a,b){
|
function inner_product(a,b){
|
||||||
var result = 0;
|
var result = 0;
|
||||||
$.each(a,function(i,v){
|
$.each(a,function(i,v){
|
||||||
|
@ -224,11 +226,22 @@
|
||||||
})
|
})
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
function find_insert_index(arr,val){
|
||||||
|
var index = 0;
|
||||||
|
arr.forEach(function(v){
|
||||||
|
if(val >= v){
|
||||||
|
index++;
|
||||||
|
}else{
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
console.log(index);
|
||||||
|
return index;
|
||||||
|
}
|
||||||
function update_result(){
|
function update_result(){
|
||||||
var formula = CACILATYIONFORMULA[calculate_type].replace('f[0]','f');
|
var formula = CACILATYIONFORMULA[calculate_type].replace('f[0]','f');
|
||||||
console.log(calculate_type);
|
|
||||||
//(function(){eval.call(this,cbt_init_func[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 %>
|
<%=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){
|
$("#caculation_basis_content input").each(function(i,input){
|
||||||
var name = input.name;
|
var name = input.name;
|
||||||
name = name.replace('venue_management_bill','');
|
name = name.replace('venue_management_bill','');
|
||||||
|
@ -236,14 +249,50 @@
|
||||||
name = name.replace('[','').replace(']','');
|
name = name.replace('[','').replace(']','');
|
||||||
eval.call(this,''+name+"="+Number(input.value).toString())
|
eval.call(this,''+name+"="+Number(input.value).toString())
|
||||||
}else{
|
}else{
|
||||||
|
field_name = name.split("[").slice(1)[0].replace(']','');
|
||||||
name = name.split("[").slice(1).last().replace(']','') + 's';
|
name = name.split("[").slice(1).last().replace(']','') + 's';
|
||||||
name = name.replace("/","")
|
name = name.replace("/","")
|
||||||
if(input.value != "")
|
if(input.value != "")
|
||||||
eval.call(this,''+name+".push("+Number(input.value).toString()+")")
|
eval.call(this,name)[field_name] = Number(input.value);
|
||||||
|
else
|
||||||
|
eval.call(this,name)[field_name] = null;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
var ks = cbt[calculate_type];
|
||||||
|
var value_name = cbt[calculate_type][0];
|
||||||
|
<%= ('switch (calculate_type) {
|
||||||
|
'+
|
||||||
|
cbt_fields.map{|k,fields|
|
||||||
|
(fields[0].blank? ? "" : "case '#{k}':
|
||||||
|
if(#{fields[0].blank? ? "undefined" : fields[0]} != undefined){"+
|
||||||
|
fields[1..-1].to_a.map{|f|
|
||||||
|
"$.each(#{fields[0]},function(k,v){
|
||||||
|
if(v == null){
|
||||||
|
delete #{f}[k];
|
||||||
|
}
|
||||||
|
})
|
||||||
|
#{f} = Object.values(#{f});
|
||||||
|
"
|
||||||
|
}.join(";") +
|
||||||
|
"var fields_to_delete = [];
|
||||||
|
$.each(#{fields[0]},function(k,v){
|
||||||
|
if(v == null){
|
||||||
|
fields_to_delete.push(k);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
fields_to_delete.forEach(function(f){
|
||||||
|
delete #{fields[0]}[f];
|
||||||
|
})
|
||||||
|
#{fields[0]} = Object.values(#{fields[0]});"+
|
||||||
|
"}
|
||||||
|
break;
|
||||||
|
")
|
||||||
|
}.select{|s| s.present?}.join(" ")+
|
||||||
|
'default:'+
|
||||||
|
'console.log("error");
|
||||||
|
break;}').html_safe
|
||||||
|
%>
|
||||||
eval.call(this,formula);
|
eval.call(this,formula);
|
||||||
console.log(result);
|
|
||||||
if($("#tax_excluded").prop("checked")){
|
if($("#tax_excluded").prop("checked")){
|
||||||
$("#total_amount").val(Math.round(result*1.05));
|
$("#total_amount").val(Math.round(result*1.05));
|
||||||
$("#actual_amount").val(Math.round(result));
|
$("#actual_amount").val(Math.round(result));
|
||||||
|
@ -266,4 +315,7 @@
|
||||||
$("#caculation_basis_content input").off("input").on("input",function(){
|
$("#caculation_basis_content input").off("input").on("input",function(){
|
||||||
update_result();
|
update_result();
|
||||||
})
|
})
|
||||||
|
$(document).ready(function(){
|
||||||
|
update_result();
|
||||||
|
})
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue