468 lines
20 KiB
Plaintext
468 lines
20 KiB
Plaintext
<% content_for :page_specific_css do %>
|
|
<%= stylesheet_link_tag "lib/main-forms" %>
|
|
<%= stylesheet_link_tag "lib/fileupload" %>
|
|
<%= stylesheet_link_tag "lib/main-list" %>
|
|
<% end %>
|
|
<% 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 %>
|
|
<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">
|
|
<% new_record = @venue_management_bill.new_record? && params["action"] != "copy" %>
|
|
<!-- Module -->
|
|
<div class="tab-content module-area">
|
|
<!-- Basic Module -->
|
|
<div class="tab-pane fade in active" id="basic">
|
|
<%= f.hidden_field :venue_management_main_id %>
|
|
<div class="control-group">
|
|
<label class="control-label muted"><%= t('vm_bill.accounting_month') %></label>
|
|
<div class="controls">
|
|
<%= f.org_datetime_picker :accounting_month, :no_label => true, :format=>"yyyy/MM", :new_record => new_record %>
|
|
</div>
|
|
</div>
|
|
<div class="control-group">
|
|
<label class="control-label muted"><%= t('vm_bill.bill_type') %></label>
|
|
<div class="controls">
|
|
<%= 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 \'<option value=\"\'+k+\'\">\'+v+\'</option>\'}).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');})()"} %>
|
|
<div id="bill_other_field" class="tab-content language-area <%=@venue_management_bill.bill_typeB == 'other' ? '' : 'hidden'%>">
|
|
<div class="input-append">
|
|
<div class="tab-content">
|
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
|
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>" id="bill_other_<%=locale%>">
|
|
<!-- Bill other -->
|
|
<div class="add-input address-input">
|
|
<%= f.fields_for :bill_other_translations do |f| %>
|
|
<%= f.text_field locale , class: "input-block-level", :value => (@venue_management_bill.bill_other_translations[locale] rescue nil), :placeholder=> t('vm_bill.bill_other') %>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
<div class="btn-group" data-toggle="buttons-radio">
|
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
|
<a class="btn <%= (i == 0 ? 'active' : '') %> last" href="#bill_other_<%=locale%>" data-toggle="tab"><%=t(locale)%></a>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
</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, cbt.keys.map { |k| [ I18n.t("vm_bill.#{k}"), k ] }, {}, :id=>'caculation_basis_type' %>
|
|
</div>
|
|
</div>
|
|
<% caculation_basis_type = (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%>">
|
|
<% other_keys = (v.keys - @venue_management_bill.class::NOTFIELDKEY) rescue [] %>
|
|
<% if ( v['fields'].blank? rescue true) %>
|
|
<%= f.text_field k if other_keys.blank? %>
|
|
<% 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 %>
|
|
<% 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| %>
|
|
<span>
|
|
<input type="<%=v[field_key]['type']%>" name="<%= f.object_name %>[<%=field_key%>]<%= ((v[field_key]['type'] == 'checkbox') ? '[]' : '')%>" value="<%= o %>" <%= (value == o || (value.include?(o) rescue false)) ? 'checked' : '' %> />
|
|
<%= t("vm_bill.#{o}") %>
|
|
</span>
|
|
<% end %>
|
|
<% end %>
|
|
<% end %>
|
|
<%= t("vm_bill.#{field_key}") if (field_key != 'field_value' && !v[field_key].has_key?('display_title') ) %>
|
|
<span class="unit">
|
|
<% 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 %>
|
|
</span>
|
|
<% end %>
|
|
<% end %>
|
|
<% end %>
|
|
<span class="unit">
|
|
<% 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 %>
|
|
</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">
|
|
<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">
|
|
<%= f.datetime_picker :deadline, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
|
|
</div>
|
|
</div>
|
|
<div class="control-group">
|
|
<label class="control-label muted"><%= t('vm_bill.received_date') %></label>
|
|
<div class="controls">
|
|
<%= f.datetime_picker :received_date, :no_label => true, :format=>"yyyy/MM/dd", :new_record => new_record %>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Language Tabs -->
|
|
<div class="nav-name"><strong><%= t(:language) %></strong></div>
|
|
<ul class="nav nav-pills language-nav">
|
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
|
<li class="<%= 'active' if i == 0 %>">
|
|
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale) %></a>
|
|
</li>
|
|
<% end %>
|
|
</ul>
|
|
|
|
<!-- Language -->
|
|
<% translations_fields = {"reason"=>"text_field","pay_method"=>"text_field","note"=>"cktext_area"} %>
|
|
<div class="tab-content language-area">
|
|
|
|
<% @site_in_use_locales.each_with_index do |locale, i| %>
|
|
|
|
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
|
|
|
|
<!-- Content -->
|
|
<% translations_fields.each do |field,type| %>
|
|
<div class="control-group input-content">
|
|
<label class="control-label muted"><%= t("vm_bill.#{field}") %></label>
|
|
<div class="controls">
|
|
<div class="textarea">
|
|
<%= f.fields_for "#{field}_translations" do |f1| %>
|
|
<%= f1.send(type, locale, rows: 5, class: "input-block-level", :value => (@venue_management_bill.send("#{field}_translations")[locale] rescue nil)) %>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
<% end %>
|
|
<%= render partial: 'admin/venue_shared/venue_file_link',locals: {venue: @venue_management_bill,f: f} %>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Form Actions -->
|
|
<div class="form-actions">
|
|
<%= get_referer_url[:venue_managemention] rescue "" %>
|
|
<%= f.submit t('submit'), class: 'btn btn-primary' %>
|
|
<% if !params[:id].nil? %>
|
|
<input type="hidden" name="referer_url" value="<%= venue_management_bills_admin_venue_management_path(params[:id]) %>">
|
|
<% else %>
|
|
<input type="hidden" name="referer_url" value="<%= get_referer_url %>">
|
|
<% end %>
|
|
<%= 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}\">"
|
|
|
|
other_keys = (v.keys - @venue_management_bill.class::NOTFIELDKEY) rescue []
|
|
if ( v['fields'].blank? rescue true)
|
|
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'
|
|
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 += '<span>'
|
|
html += "<input type=\"#{v[field_key]['type']}\" name=\"#{f.object_name}[#{field_key}]#{((v[field_key]['type'] == 'checkbox') ? '[]' : '')}\" value=\"#{o}\" #{(value == o || (value.include?(o) rescue false)) ? 'checked' : ''} />"
|
|
html += t("vm_bill.#{o}")
|
|
html += '</span>'
|
|
end
|
|
end
|
|
end
|
|
html += t("vm_bill.#{field_key}") if (field_key != 'field_value' && !v[field_key].has_key?('display_title') )
|
|
html += '<span class="unit">'
|
|
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 += '</span>'
|
|
end
|
|
end
|
|
end
|
|
|
|
html += "<span class=\"unit\"> "
|
|
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 += "</span>"
|
|
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| 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();
|
|
$("#caculation_basis_content input").off("input").on("input",function(){
|
|
update_result();
|
|
})
|
|
})
|
|
<% 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];
|
|
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){
|
|
if(val >= v){
|
|
index++;
|
|
}else{
|
|
return index;
|
|
}
|
|
})
|
|
return index;
|
|
}
|
|
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| 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','');
|
|
if(name.split('[').length == 2){
|
|
name = name.replace('[','').replace(']','');
|
|
window[name] = Number(input.value);
|
|
}else{
|
|
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 != ""){
|
|
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
|
|
window[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:'+
|
|
'
|
|
break;}').html_safe
|
|
%>
|
|
eval.call(window,formula);
|
|
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();
|
|
})
|
|
$(document).ready(function(){
|
|
update_result();
|
|
})
|
|
</script> |