update addorder option for set

This commit is contained in:
Aung Myo
2018-03-15 14:35:25 +06:30
parent e2ad592007
commit f0e81caad0
5 changed files with 56 additions and 57 deletions

View File

@@ -180,7 +180,7 @@ $(function() {
image_path = "image/logo.png";
}
}
console.log(menu_items[field].options)
row = '<div class="card custom-card testimonial-card animated fadeInRight" style="height:100%;background-image:url(../../'+image_path+');background-repeat: no-repeat;">'
+'<div class="custom-card-head card-head row" style="line-height:14px;margin:0px;" style="">'
@@ -202,7 +202,7 @@ $(function() {
+ price +"' data-instance-code = '"+ code +"' data-instance = '"
+ name +"' data-promotion-price = '"+ promotion_price +"' data-attributes = '"
+ JSON.stringify(item_attributes) +"' data-options = '"
+ options +"' data-image='"+image_path+"' data-toggle='"
+ JSON.stringify(menu_items[field].options) +"' data-image='"+image_path+"' data-toggle='"
+data_modal+"' data-target='."+data_target+"' data-item-sets = '"
+JSON.stringify(menu_items[field].item_sets)+"'data-instances = '"
+JSON.stringify(menu_items[field].instances)+"'>"
@@ -237,10 +237,10 @@ $(function() {
//instances = $(this).data('instance');
item_sets = $(this).data('item-sets');
instances = $(this).data('instances');
// item_sets = $(data).attr('data-item-sets');
item_options = $(this).data('options');
for(var field in item_sets) {
$('.set_order').attr('data-min-qty',item_sets[field]["min_selectable_qty"]);
value = item_sets[field]["instances"];
@@ -283,10 +283,20 @@ $(function() {
});
}
for(var j in item_options) {
value = item_options[j]["values"];
type = item_options[j]["type"];
row = "<h4>"+type+"</h4>"
$(value).each(function(i){
row +="<button class='btn btn- waves-effect option_btn "+ type +"' data-type='"
+type+"' data-value='"+value[i]+"' data-group='set_menu_default'>"+value[i]+"</button>";
});
$(".options-list").append(row);
}
$('.set-item').attr('data-code',instances[0]['code']);
$('.set-item').attr('data-name',instances[0]['name']);
$('.set-item').attr('data-price',instances[0]['price']);
$('.set-item').attr('data-options','[]');
// $('.set-item').attr('data-options','[]');
$('.set-item').attr('data-parent',true);
$('#set_change_qty').val(1);
@@ -371,32 +381,28 @@ $(function() {
customer_display_view(item,"set_add");
attribute_arr = []
option_arr = []
var rowCount = $('.summary-items tbody tr').length+1;
option_arr = []
code = $('.set-item').attr('data-code');
name = $('.set-item').attr('data-name');
price = $('.set-item').attr('data-price');
option = $('.set-item').attr('data-options');
parent = $('.set-item').attr('data-parent');
total = qty * price ;
option_arr.push(option);
row ="<tr class='item_box' data-price ='"
+price+ "' data-toggle='modal' data-target='#sx_itemModal' 'data-instance ='"
+name+ "' data-code='"+item_code+"' data-instance-code='"
+code+"' data-attributes='"
+attribute_arr+"' data-options ='"
+option_arr+"' data-row ='"+rowCount+ "' data-parent ='"+parent+ "'>"
+option+"' data-row ='"+rowCount+ "' data-parent ='"+parent+ "'>"
+'<td class="item-cell-no">'+rowCount+'</td>'
+'<td class="item-cell-name" id="item_name" >' + item_name+ ' ' + name +'</td>'
+'<td class="item-cell-name" id="item_name" >' + item_name+ ' ' + name +'-' + option +'</td>'
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
+'<td class="item-cell-price" id="item_price">'
+ parseFloat(total).toFixed(2)
+'</td>'
+'</tr>';
$(".summary-items tbody").append(row);
var rowCount = $('.summary-items tbody tr').length+1;
$(items).each(function(i){
code = $(items[i]).attr('data-code');
@@ -406,15 +412,14 @@ $(function() {
sub_item = $(items[i]).attr('data-sub-item');
option = $(items[i]).attr('data-options');
total = qty * price ;
option_arr.push(option);
row ="<tr class='item_box' data-price ='"
+price+ "' data-toggle='modal' data-target='#sx_itemModal' 'data-instance ='"
+name+ "' data-code='"+item_code+"' data-instance-code='"
+code+"' data-attributes='"
+attribute_arr+"' data-options ='"
+option_arr+"' data-row ='"+rowCount+ "' data-sub-item ='"+sub_item+ "'>"
+option+"' data-row ='"+rowCount+ "' data-sub-item ='"+sub_item+ "'>"
+'<td class="item-cell-no">'+rowCount+'</td>'
+'<td class="item-cell-name" id="item_name" >' + item_name+ ' ' + name +'</td>'
+'<td class="item-cell-name" id="item_name" >' + item_name+ ' ' + name +'-' + option +'</td>'
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
+'<td class="item-cell-price" id="item_price">'
+ parseFloat(total).toFixed(2)
@@ -626,8 +631,6 @@ $(function() {
if(group == "set_menu"){
code = $(this).data('code');
value = $(this).data('value');
instance = $(".selected-instance");
$(instance).each(function(i){
@@ -638,6 +641,12 @@ $(function() {
}
});
}
if(group == "set_menu_default"){
option_arr = get_selected_attributes('selected-option');
$('.set-item').attr('data-options',JSON.stringify(option_arr));
$('.set_default_option').text(option_arr);
}
}); //End selecct attribute buttom

View File

@@ -6,6 +6,10 @@ class Settings::MenusController < ApplicationController
# GET /settings/menus.json
def index
@settings_menus = Menu.all.page(params[:page]).per(10)
respond_to do |format|
format.html
format.csv { send_data Menu.to_csv }
end
end
# GET /settings/menus/1

View File

@@ -31,4 +31,29 @@ class Menu < ApplicationRecord
menu.destroy
return false
end
end
def self.to_csv
m_attributes = %w{id name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at}
CSV.generate(headers: true) do |csv|
csv << m_attributes
menu = Menu.all
menu.each do |user|
puts user
csv << m_attributes.map{ |attr| user.send(attr)}
end
end
# mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at}
# CSV.generate(headers: true) do |csv|
# csv << m_attributes
# csv << mc_attributes
# MenuCategory.all.each do |user|
# puts user
# csv << mc_attributes.map{ |attr| user.send(attr)}
# end
# end
end
end

View File

@@ -1,5 +1,6 @@
require_relative 'boot'
require 'csv'
require 'rails/all'
# Require the gems listed in Gemfile, including any gems

View File

@@ -1,44 +1,4 @@
namespace :consolidate do
desc 'export sers who have logged in since 2017-06-30'
task :export => :environment do
puts "Export users who have logged in since 2017-06-30"
# get a file ready, the 'data' directory has already been added in Rails.root
filepath = File.join(Rails.root, 'data', 'recent_users.json')
puts "- exporting users into #{filepath}"
# the key here is to use 'as_json', otherwise you get an ActiveRecord_Relation object, which extends
# array, and works like in an array, but not for exporting
users = Employee.all.as_json
puts users
# The pretty is nice so I can diff exports easily, if that's not important, JSON(users) will do
File.open(filepath, 'w') do |f|
f.write(JSON.pretty_generate(users))
end
puts "- dumped #{users.size} users"
end
desc 'import users from recent users dump'
task :import => :environment do
puts "Importing current users"
filepath = File.join(Rails.root, 'data', 'recent_users.json')
abort "Input file not found: #{filepath}" unless File.exist?(filepath)
current_users = JSON.parse(File.read(filepath))
current_users.each do |cu|
puts cu.to_json
Employee.create(cu)
end
puts "- imported #{current_users.size} users"
end
desc "Receipt"
task :receipt => :environment do
Receipt.delete_all