check foreigner lists
This commit is contained in:
@@ -32,17 +32,19 @@
|
|||||||
</div>
|
</div>
|
||||||
<%= f.input :total_customer, input_html: { value: @survey_data.total_customer, class: 'col-md-11'} %>
|
<%= f.input :total_customer, input_html: { value: @survey_data.total_customer, class: 'col-md-11'} %>
|
||||||
<%= f.input :local , input_html: { value: @survey_data.local, class: 'col-md-11' }%>
|
<%= f.input :local , input_html: { value: @survey_data.local, class: 'col-md-11' }%>
|
||||||
<fieldset style="border: 1px solid #BDBDBD;padding: 20px; width: 92%;margin: 20px 0 20px 0;">
|
<!--<fieldset style="border: 1px solid #BDBDBD;padding: 20px; width: 92%;margin: 20px 0 20px 0;"> -->
|
||||||
<legend style="font-size: 1.2em !important;font-weight: bold !important;text-align: left !important;border:none;width:100px;">Foreigner</legend>
|
<!-- <legend style="font-size: 1.2em !important;font-weight: bold !important;text-align: left !important;border:none;width:100px;">Foreigner</legend> -->
|
||||||
<div class="row clearfix">
|
<fieldset class="form-group">
|
||||||
|
<label class="bmd-label-static">Foreigner Lists</label>
|
||||||
|
<div class="row clearfix foreignerDiv">
|
||||||
<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5">
|
<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5">
|
||||||
<div class="form-group p-l-10 p-r-10">
|
<div class="form-group p-l-10 p-r-10">
|
||||||
<label class="p-l-10">Foreigner</label>
|
<label class="p-l-10">Foreigner</label>
|
||||||
<!-- <input type="text" class="form-control" name="survey[foreigner][]"> -->
|
<!-- <input type="text" class="form-control" name="survey[foreigner][]"> -->
|
||||||
<select class="form-control col-md-12 selectpicker show-tick" name="survey[foreigner][]" style="height: " >
|
<select class="form-control col-md-12 selectpicker show-tick" name="survey[foreigner][]" style="height: " >
|
||||||
<% Lookup.where("lookup_type = ?", "country" ).each do |ct| %>
|
<% Lookup.where("lookup_type = ?", "country" ).each do |ct| %>
|
||||||
<option value="<%= ct.value %>">
|
<option value="<%= ct.value %>">
|
||||||
<%= ct.name %></option>
|
<%= ct.name %></option>
|
||||||
<%end %>
|
<%end %>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@@ -243,7 +245,11 @@
|
|||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var cashier_type = "<%= @cashier_type %>";
|
var cashier_type = "<%= @cashier_type %>";
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
|
$('.foreignerDiv').removeClass("hidden");
|
||||||
setHeaderBreadCrumb(_SURVEY_);
|
setHeaderBreadCrumb(_SURVEY_);
|
||||||
|
<% if !@survey_data.nil? %>
|
||||||
|
addSurveyForeignerLists(<%= @survey_data.foreigner.to_json.html_safe %>);
|
||||||
|
<% end %>
|
||||||
//click add button for new row
|
//click add button for new row
|
||||||
$('#addForeigner').on('click',function(){
|
$('#addForeigner').on('click',function(){
|
||||||
$('#newTemplate').removeClass('hidden');
|
$('#newTemplate').removeClass('hidden');
|
||||||
@@ -272,6 +278,34 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
$('#newTemplate').append(text_box);
|
$('#newTemplate').append(text_box);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//click add button for new row
|
||||||
|
$('#newTemplate').on('click','#addForeigner',function(){
|
||||||
|
$('#newTemplate').removeClass('hidden');
|
||||||
|
|
||||||
|
var text_box = '<div id="newRow" class="row clearfix">'
|
||||||
|
+'<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 ">'
|
||||||
|
+'<div class="form-group p-l-10 p-r-10">'
|
||||||
|
+' <select class="form-control col-md-12 selectpicker show-tick" '
|
||||||
|
+' name="survey[foreigner][]" style="height: " >'
|
||||||
|
+'<% Lookup.where("lookup_type = ?", "country" ).each do |ct| %>'
|
||||||
|
+'<option value="<%= ct.value %>">'
|
||||||
|
+'<%= ct.name %></option>'
|
||||||
|
+'<%end %>'
|
||||||
|
+'</select>'
|
||||||
|
+'</div>'
|
||||||
|
+'</div>'
|
||||||
|
+'<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 ">'
|
||||||
|
+'<div class="form-group p-l-10 p-r-10">'
|
||||||
|
+'<input type="number" name="survey[foreigner][]" class="form-control">'
|
||||||
|
+'</div>'
|
||||||
|
+'</div>'
|
||||||
|
+'<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 ">'
|
||||||
|
+'<button type="button" class="btn btn-danger" id="removeRow">Remove</button>'
|
||||||
|
+'</div>'
|
||||||
|
+'</div>';
|
||||||
|
$('#newTemplate').append(text_box);
|
||||||
|
});
|
||||||
|
|
||||||
//click remove buttom
|
//click remove buttom
|
||||||
$('#newTemplate').on('click','#removeRow', function(){
|
$('#newTemplate').on('click','#removeRow', function(){
|
||||||
$(this).parent().parent().remove()
|
$(this).parent().parent().remove()
|
||||||
@@ -339,4 +373,84 @@ var cashier_type = "<%= @cashier_type %>";
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function addSurveyForeignerLists(foreigner_lists){
|
||||||
|
if((foreigner_lists != undefined) && (foreigner_lists != null) && (foreigner_lists != "")){
|
||||||
|
$('.foreignerDiv').remove();
|
||||||
|
$('#newTemplate').removeClass('hidden');
|
||||||
|
foreigner_lists = foreigner_lists.substring(1, (foreigner_lists.length - 1)).replace(new RegExp('"', "g"),'').split(",");
|
||||||
|
var arr_foreigner = {};
|
||||||
|
$.each(foreigner_lists,function(key,value){
|
||||||
|
if(!value.match(/^[0-9]+$/)){
|
||||||
|
arr_foreigner[value] = 0;
|
||||||
|
}else{
|
||||||
|
$.each(arr_foreigner,function(k,val){
|
||||||
|
if(arr_foreigner[k] == 0){
|
||||||
|
arr_foreigner[k] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// console.log(foreigner_lists);
|
||||||
|
// console.log(arr_foreigner);
|
||||||
|
$.each(arr_foreigner, function(key,value){
|
||||||
|
if(Object.keys(arr_foreigner)[0] == key){
|
||||||
|
var fgn_template = '<div id="newRow" class="row clearfix">'
|
||||||
|
+'<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 ">'
|
||||||
|
+'<div class="form-group p-l-10 p-r-10">'
|
||||||
|
+' <select class="form-control col-md-12 selectpicker show-tick" '
|
||||||
|
+' name="survey[foreigner][]" style="height: " >'
|
||||||
|
+'<% Lookup.where("lookup_type = ?", "country" ).each do |ct| %>'
|
||||||
|
// if (key.toString() == '<%= ct.value.to_s %>')
|
||||||
|
// var selected = "selected";
|
||||||
|
// else
|
||||||
|
// var selected = "";
|
||||||
|
+'<option value="<%= ct.value %>">'
|
||||||
|
+'<%= ct.name %></option>'
|
||||||
|
+'<%end %>'
|
||||||
|
+'</select>'
|
||||||
|
+'</div>'
|
||||||
|
+'</div>'
|
||||||
|
+'<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 ">'
|
||||||
|
+'<div class="form-group p-l-10 p-r-10">'
|
||||||
|
+'<input type="number" name="survey[foreigner][]" class="form-control" value="'+value+'">'
|
||||||
|
+'</div>'
|
||||||
|
+'</div>'
|
||||||
|
+'<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 ">'
|
||||||
|
+'<button type="button" class="btn btn-success" id="addForeigner">Add</button>'
|
||||||
|
+'</div>'
|
||||||
|
+'</div>';
|
||||||
|
}else{
|
||||||
|
var fgn_template = '<div id="newRow" class="row clearfix">'
|
||||||
|
+'<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 ">'
|
||||||
|
+'<div class="form-group p-l-10 p-r-10">'
|
||||||
|
+' <select class="form-control col-md-12 selectpicker show-tick" '
|
||||||
|
+' name="survey[foreigner][]" style="height: " >'
|
||||||
|
+'<% Lookup.where("lookup_type = ?", "country" ).each do |ct| %>'
|
||||||
|
// if (key.toString() == '<%= ct.value.to_s %>')
|
||||||
|
// var selected = "selected";
|
||||||
|
// else
|
||||||
|
// var selected = "";
|
||||||
|
+'<option value="<%= ct.value %>">'
|
||||||
|
+'<%= ct.name %></option>'
|
||||||
|
+'<%end %>'
|
||||||
|
+'</select>'
|
||||||
|
+'</div>'
|
||||||
|
+'</div>'
|
||||||
|
+'<div class="col-lg-5 col-md-5 col-sm-5 col-xs-5 ">'
|
||||||
|
+'<div class="form-group p-l-10 p-r-10">'
|
||||||
|
+'<input type="number" name="survey[foreigner][]" class="form-control" value="'+value+'">'
|
||||||
|
+'</div>'
|
||||||
|
+'</div>'
|
||||||
|
+'<div class="col-lg-1 col-md-1 col-sm-1 col-xs-1 ">'
|
||||||
|
+'<button type="button" class="btn btn-danger" id="removeRow">Remove</button>'
|
||||||
|
+'</div>'
|
||||||
|
+'</div>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#newTemplate').append(fgn_template);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -56,6 +56,7 @@
|
|||||||
<% total_female = 0 %>
|
<% total_female = 0 %>
|
||||||
<% total_local = 0 %>
|
<% total_local = 0 %>
|
||||||
<% total_customer = 0 %>
|
<% total_customer = 0 %>
|
||||||
|
<% total_foreigner = 0 %>
|
||||||
<% if !@surveys.nil? %>
|
<% if !@surveys.nil? %>
|
||||||
<% @surveys.each do |survey| %>
|
<% @surveys.each do |survey| %>
|
||||||
<% total_child = total_child.to_i + survey.child.to_i %>
|
<% total_child = total_child.to_i + survey.child.to_i %>
|
||||||
@@ -80,8 +81,11 @@
|
|||||||
<% foreigner_lists = foreign.split(",") %>
|
<% foreigner_lists = foreign.split(",") %>
|
||||||
<% if !foreigner_lists.empty? %>
|
<% if !foreigner_lists.empty? %>
|
||||||
<% foreigner_lists.each do |fgn| %>
|
<% foreigner_lists.each do |fgn| %>
|
||||||
|
<% unless fgn.match(/[^[:digit:]]+/)
|
||||||
|
total_foreigner = total_foreigner.to_i + fgn.to_i
|
||||||
|
end %>
|
||||||
<% if !fgn.scan(/\D/).empty? %>
|
<% if !fgn.scan(/\D/).empty? %>
|
||||||
<%= fgn %> :<% end %> <%= fgn.to_i unless fgn.match(/[^[:digit:]]+/) %><br>
|
<%= fgn %> :<% end %> <%= fgn.to_i unless fgn.match(/[^[:digit:]]+/) %><br>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -97,7 +101,8 @@
|
|||||||
<td><strong><%= total_male %></strong></td>
|
<td><strong><%= total_male %></strong></td>
|
||||||
<td><strong><%= total_female %></strong></td>
|
<td><strong><%= total_female %></strong></td>
|
||||||
<td><strong><%= total_customer %></strong></td>
|
<td><strong><%= total_customer %></strong></td>
|
||||||
<td colspan="2"><strong><%= total_local %></strong></td>
|
<td><strong><%= total_local %></strong></td>
|
||||||
|
<td><strong><%= total_foreigner %></strong></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
Reference in New Issue
Block a user