diff --git a/Gemfile b/Gemfile index 94ed4ef3..4ca47865 100755 --- a/Gemfile +++ b/Gemfile @@ -48,7 +48,6 @@ gem 'prawn' gem 'prawn-table' gem 'spreadsheet' gem 'to_xls-rails' - #Reporting gem #gem 'compendium' #gem "cancan" @@ -81,7 +80,6 @@ gem 'kaminari', '~> 1.0.1' gem 'filterrific' gem 'cancancan', '~> 1.10' - #pageless no need for current # gem 'will_paginate' # gem 'pageless-rails', github: 'rorlab/pageless-rails' @@ -129,4 +127,4 @@ gem 'momentjs-rails' # for date-range selector # gem 'bootstrap-datepicker-rails' # date picker # gem 'jquery-datetimepicker-rails' # gem 'select2-rails' # for multi-select and auto-complete select box -gem "chartkick" #chart lib +gem "chartkick" #chart lib \ No newline at end of file diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 401d894a..f6365db0 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -180,7 +180,6 @@ $(function() { image_path = "image/logo.png"; } } - console.log(menu_items[field].options) row = '
' +'
' @@ -190,6 +189,7 @@ $(function() { +JSON.stringify(menu_items[field].instances)+"' data-id = '" +JSON.stringify(menu_items[field].attributes)+"' data-item = '" +JSON.stringify(item_attributes)+"' data-option = '" + +JSON.stringify(menu_items[field].options)+"'data-opt = '" +JSON.stringify(menu_items[field].options)+"' data-item-sets = '" +JSON.stringify(menu_items[field].item_sets)+"' data-toggle='modal' data-target='."+data_target+"' >" +"" @@ -202,6 +202,7 @@ $(function() { + price +"' data-instance-code = '"+ code +"' data-instance = '" + name +"' data-promotion-price = '"+ promotion_price +"' data-attributes = '" + JSON.stringify(item_attributes) +"' data-options = '" + + JSON.stringify(menu_items[field].options) +"' data-opt = '" + 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 = '" @@ -296,7 +297,7 @@ $(function() { $('.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); @@ -351,6 +352,7 @@ $(function() { sub_total = $('#set_total_price').text(); name = $(this).data('name'); price = $(this).data('price'); + options = $(this).attr('data-options',''); // qty = $('#set_change_qty').val(); qty = document.getElementById("set_count").value; total = qty*price; @@ -379,14 +381,14 @@ $(function() { item = get_set_item(items); customer_display_view(item,"set_add"); - + var option = '' attribute_arr = [] var rowCount = $('.summary-items tbody tr').length+1; code = $('.set-item').attr('data-code'); name = $('.set-item').attr('data-name'); price = $('.set-item').attr('data-price'); - option = $('.set-item').attr('data-options'); + option = ($('.set-item').attr('data-options') === 'undefined') ? '' :$('.set-item').attr('data-options'); parent = $('.set-item').attr('data-parent'); total = qty * price ; row ="" +''+rowCount+'' - +'' + item_name+ ' ' + name +'-' + option +'' + +'' + item_name+ ' ' + name +' ' + option +'' +'' + qty + '' +'' + parseFloat(total).toFixed(2) @@ -404,22 +406,23 @@ $(function() { +''; $(".summary-items tbody").append(row); var rowCount = $('.summary-items tbody tr').length+1; + var set_option = '' $(items).each(function(i){ code = $(items[i]).attr('data-code'); name = $(items[i]).attr('data-name'); price = $(items[i]).attr('data-price'); - option = $(items[i]).attr('data-options'); + set_option = ($(items[i]).attr('data-options') === 'undefined') ? ' ' :$(items[i]).attr('data-options'); + sub_item = $(items[i]).attr('data-sub-item'); - option = $(items[i]).attr('data-options'); total = qty * price ; row ="" + +set_option+"' data-row ='"+rowCount+ "' data-sub-item ='"+sub_item+ "'>" +''+rowCount+'' - +'' + item_name+ ' ' + name +'-' + option +'' + +'' + item_name+ ' ' + name +' ' + set_option +'' +'' + qty + '' +'' + parseFloat(total).toFixed(2) @@ -659,7 +662,6 @@ $(function() { attribute_arr = get_selected_attributes('selected-attribute'); option_arr = get_selected_attributes('selected-option'); - if (item_row.length>0) { var instances = jQuery.parseJSON(item_row.attr('data-instances')); @@ -700,7 +702,7 @@ $(function() { var item_data = $(this); item = get_item(item_data); customer_display_view(item,"add"); - show_item_detail(item_data); + show_item_detail(item_data,"add_to_order"); calculate_sub_total(); }); //End add order Click @@ -710,11 +712,11 @@ $(function() { var item_data = $(this); item = get_item(item_data); customer_display_view(item,"add"); - show_item_detail(item_data); + show_item_detail(item_data,"add_icon"); calculate_sub_total(); }); //End Add Icon Click - function show_item_detail(data){ + function show_item_detail(data,click_type){ qty = parseInt(data.attr('data-qty')); append = 0; @@ -726,23 +728,26 @@ $(function() { }else{ instance = "("+data.attr('data-instance')+")"; } - - d_option = data.attr('data-options'); - if (d_option){ - option_name = "-"+data.attr('data-options'); + d_option = data.attr('data-opt'); + if (click_type != "add_icon"){ + option_name = "-"+data.attr('data-options'); + data_option = data.attr('data-options') ; }else{ - option_name = ''; + option_name = ' '; + data_option = '[]'; } + var rowCount = $('.summary-items tbody tr').length+1; var item_row = $('.summary-items tbody tr'); $(item_row).each(function(i){ item_code = $(item_row[i]).attr('data-code'); instance_code = $(item_row[i]).attr('data-instance-code'); - r_option = $(item_row[i]).attr('data-options'); - - if (item_code == data.attr('data-item-code') && instance_code == data.attr('data-instance-code')&&r_option==d_option) { + r_option = $(item_row[i]).attr('data-opt'); +console.log(r_option) +console.log(d_option) + if (item_code == data.attr('data-item-code') && instance_code == data.attr('data-instance-code')&&r_option == d_option) { if (qty > 1) { qty = parseInt($(item_row[i]).children('#item_qty').text()) + qty; }else{ @@ -766,9 +771,10 @@ $(function() { +instance+ "' data-code='"+data.attr('data-item-code')+"' data-instance-code='" +data.attr('data-instance-code')+"' data-attributes='" +data.attr('data-attributes')+"' data-options ='" + +data_option+"' data-opt ='" +data.attr('data-options')+"' data-row ='"+rowCount+ "'>" +''+rowCount+'' - +'' + data.attr('data-name')+ ' ' + instance +' ' + option_name +'' + +'' + data.attr('data-name')+ ' ' + instance +''+option_name+'' +'' + qty + '' +'' + parseFloat(price).toFixed(2) @@ -822,8 +828,6 @@ $(function() { data: params, dataType: "json", success:function(result){ - console.log(type) - console.log(table_type) if (type == "quick_service") { window.location.href = "/origami/quick_service" }else{ @@ -889,7 +893,7 @@ $(function() { dataType: "json", success:function(result){ if (result.status) { - console.log(result) + if (result.data == null){ swal({ title: "Please Open Shift !", diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 2e9602c8..43e1bd11 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -67,7 +67,8 @@ class Api::OrdersController < Api::ApiController end } #end extra time - + puts params[:order_items] + puts "ITEM aaaaaaaaaaaaaaaaaaa" # begin @order = Order.new @order.source = params[:order_source] diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 7dd2b3f0..3a8dea9b 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -94,10 +94,10 @@ class Origami::AddordersController < BaseOrigamiController extra_time = Time.at(time) end end - if i["parent_order_item_id"] - items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": i["options"]} + if i["parent_order_item_id"]; + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])} else - items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]} + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])} end items_arr.push(items) } diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index 4d7d6026..0a6d87c7 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -7,9 +7,12 @@ class Settings::MenusController < ApplicationController 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 + format.html + # format.csv { send_data MenuCsvExport.generate } + +format.csv { send_data Menu.to_csv } +# format.csv { send_data MenuCategory.to_csv } + end end # GET /settings/menus/1 @@ -71,6 +74,11 @@ class Settings::MenusController < ApplicationController # end end + def import + Menu.import(params[:file]) + redirect_to settings_menu_path, notice: "imported" + end + private # Use callbacks to share common setup or constraints between actions. def set_settings_menu diff --git a/app/controllers/transactions/orders_controller.rb b/app/controllers/transactions/orders_controller.rb index 17a117bb..52abf7fd 100755 --- a/app/controllers/transactions/orders_controller.rb +++ b/app/controllers/transactions/orders_controller.rb @@ -21,11 +21,12 @@ class Transactions::OrdersController < ApplicationController @receipt_no = filter @from = from @to = to - + respond_to do |format| - format.html # index.html.erb - format.json { render json: @orders } - end + format.html + format.json { render json: @orders } + # format.csv { send_data OrdersCsvExport.generate } + end end def show diff --git a/app/models/menu.rb b/app/models/menu.rb index 052a7042..12784eea 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -33,27 +33,20 @@ class Menu < ApplicationRecord 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} + m_attributes = %w{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 + 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 - + def self.import(file) + CSV.foreach(file.path, headers:true) do |row| + Menu.create! row.to_hash + end end end \ No newline at end of file diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index acb06c4f..65477a37 100755 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -1,7 +1,7 @@ class MenuCategory < ApplicationRecord # before_create :generate_menu_category_code - belongs_to :menu + belongs_to :menu , counter_cache: true has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id" belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true has_many :menu_items @@ -83,4 +83,19 @@ class MenuCategory < ApplicationRecord # def generate_menu_category_code # self.code = SeedGenerator.generate_code(self.class.name, "C") # end + + def self.to_csv + + 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 << mc_attributes + + csv << mc_attributes + MenuCategory.all.each do |user| + puts user + csv << mc_attributes.map{ |attr| user.send(attr)} + end + end + + end end diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 776bb94c..87d60e63 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -5,7 +5,8 @@ class OrderItem < ApplicationRecord before_create :generate_custom_id #Associations - belongs_to :order, autosave: true + belongs_to :order, autosave: true + # belongs_to :order, counter_cache: true #Validation validates_presence_of :item_code, :item_name, :qty diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 6c580f40..4e93e5a7 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -375,7 +375,7 @@