diff --git a/README.md b/README.md index 85739c2a..ee9eb1e6 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,18 @@ # README -SXRestuarant is a new Dedicate project for SmartSales Restaurant. It is improvement from v1.2 with upgrade to latest Bootstrap and Rails 5. The API is better define and route are refactor. +SXRestuarant is a new Dedicate project for SmartSales Restaurant. It is improvement from v1.2 with upgrade to latest Bootstrap and Rails 5.2. The API is better define and route are refactor. Things you may want to cover: * Ruby version -ruby 2.3.2p217 +ruby 2.4.1p111 * ToDo list + +1. Cloud Sync +2. Action Cable +3. Shop Setup +4. Payment Integation * System dependencies @@ -23,4 +28,55 @@ ruby 2.3.2p217 * Deployment instructions -* ... + +* Features + +1. OQS + + 1. Filter + 2. Order Item to each Stations + 3. Edit Order Item + +2. Origami(Sale) + + 1. Sale + 2. Add Customer for membership + 3. Discount and Member Discount for Sale + 4. Assign Commissioner + 5. Add other charges to Sale + +3. CRM + + 1. Customer Management + + 2. Queue Management + +4. Backend + + 1. Dining Setup + + 2. Queue Station Setup + + 3. Menu Setup + + 4. Cashier Terminal Setup + + 5. Tax Profile Setup + + 6. Printer Setup + + 7. Payment Integration + + 8. Employee Management + + 9. Promotion Setup + + 10. Commissioner Setup + + 11. Membership Integration + + +5. Inventory + + +6. Report diff --git a/app/controllers/api/restaurant/menu_controller.rb b/app/controllers/api/restaurant/menu_controller.rb index b45e1189..ad8ad7f9 100644 --- a/app/controllers/api/restaurant/menu_controller.rb +++ b/app/controllers/api/restaurant/menu_controller.rb @@ -4,8 +4,25 @@ class Api::Restaurant::MenuController < Api::ApiController # Pull the default menu details and also other available (active) menus # Input Params - order_id def index - @menus = Menu.all - # @current_menu = Menu.current_menu + param_checksum = params[:checksum] + # checksum = File.readlines("public/checksums/menu_json.txt").pop.chomp + + all_menu = Menu.all + + # to hash + menu_array = [] + all_menu.each do |m| + menu_array.push(m.to_json(:include => {:menu_categories => { :include => { :menu_items => { :include => [:menu_item_sets, :menu_item_instances => {:include => :menu_instance_item_sets}]} } }})) + end + + #export Checksum file generate by md5 + menu_checksum = Digest::MD5.hexdigest(menu_array.to_json) + + if menu_checksum != param_checksum + response.headers['CHECKSUM'] = menu_checksum + @menus = all_menu + end + # @current_menu = Menu.current_menu end #Description diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index ffa714a2..2a0626dd 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -6,13 +6,33 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers.json def index filter = params[:filter] + type = params[:type] if filter.nil? @crm_customers = Customer.all else @crm_customers = Customer.search(filter) - + # search account no from paypar + if !@crm_customers.present? && type == "card" + response = Customer.search_paypar_account_no(filter) + if response["status"] == true + @crm_customers = Customer.new + @crm_customers.name = response["customer_data"]["name"] + @crm_customers.contact_no = response["customer_data"]["phone"] + @crm_customers.email = response["customer_data"]["email"] + @crm_customers.date_of_birth = response["customer_data"]["DOB"] + @crm_customers.nrc_no = response["customer_data"]["NRC"] + @crm_customers.address = response["customer_data"]["address"] + @crm_customers.card_no = response["customer_data"]["customer_card_no"] + @crm_customers.paypar_account_no = filter + @crm_customers.membership_id = response["customer_data"]["id"] + @crm_customers.membership_type = response["customer_data"]["member_group_id"] + @crm_customers.customer_type = "Dinein" + @crm_customers.tax_profiles = ["1", "2"] + @crm_customers.save + @crm_customers = Customer.search(filter) + end + end end - #@crm_customers = Customer.all @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) @crm_customer = Customer.new @count_customer = Customer.count_customer diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 8faaa221..72597613 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -9,13 +9,40 @@ class Origami::CustomersController < BaseOrigamiController end def get_customer + filter = params[:filter] + type = params[:type] + if filter.nil? @crm_customers = Customer.order("customer_id").page(params[:page]) #@products = Product.order("name").page(params[:page]).per(5) else - @crm_customers = Customer.search(filter) + @crm_customers = Customer.search(filter) + # search account no from paypar + if !@crm_customers.present? && type == "card" + response = Customer.search_paypar_account_no(filter) + if response["status"] == true + @crm_customers = Customer.new + @crm_customers.name = response["customer_data"]["name"] + @crm_customers.contact_no = response["customer_data"]["phone"] + @crm_customers.email = response["customer_data"]["email"] + @crm_customers.date_of_birth = response["customer_data"]["DOB"] + @crm_customers.nrc_no = response["customer_data"]["NRC"] + @crm_customers.address = response["customer_data"]["address"] + @crm_customers.card_no = response["customer_data"]["customer_card_no"] + @crm_customers.paypar_account_no = filter + @crm_customers.membership_id = response["customer_data"]["id"] + @crm_customers.membership_type = response["customer_data"]["member_group_id"] + @crm_customers.customer_type = "Dinein" + @crm_customers.tax_profiles = ["1", "2"] + @crm_customers.save + @crm_customers = Customer.search(filter) + else + @crm_customers = [{"customer_id": response["status"],"message": response["message"] }] + end + end end + render :json => @crm_customers.to_json end diff --git a/app/controllers/settings/simple_menu_items_controller.rb b/app/controllers/settings/simple_menu_items_controller.rb index 418cc2b8..e3010e30 100644 --- a/app/controllers/settings/simple_menu_items_controller.rb +++ b/app/controllers/settings/simple_menu_items_controller.rb @@ -79,7 +79,7 @@ class Settings::SimpleMenuItemsController < ApplicationController respond_to do |format| if @settings_menu_item.save menu_item = MenuItem.find(@settings_menu_item.id) - menu_item.update_attributes(item_options: params[:simple_menu_item][:item_options]) + menu_item.update_attributes(item_attributes: params[:simple_menu_item][:item_attributes], item_options: params[:simple_menu_item][:item_options]) format.html { redirect_to settings_menu_category_simple_menu_items_path, notice: 'Menu item was successfully created.' } format.json { render :show, status: :created, location: @settings_menu_item } diff --git a/app/models/customer.rb b/app/models/customer.rb index dff92ba2..9e629721 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -91,46 +91,54 @@ class Customer < ApplicationRecord auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - @customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL") + @customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL") @customers.each do |customer| - begin - response = HTTParty.post(url, - :body => - { name: customer.name,phone: customer.contact_no, - email: customer.email,dob: customer.date_of_birth, - address: customer.address,nrc:customer.nrc_no, - card_no:customer.card_no,member_group_id: customer.membership_type, - merchant_uid:merchant_uid,auth_token:auth_token - }.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - }) - rescue Net::OpenTimeout - response = { status: false, message: "Server Time out" } - - rescue OpenURI::HTTPError - response = { status: false, message: "Can't connect server"} + member_params = { name: customer.name,phone: customer.contact_no, + email: customer.email,dob: customer.date_of_birth, + address: customer.address,nrc:customer.nrc_no, + card_no:customer.card_no,member_group_id: customer.membership_type, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json - rescue SocketError - response = { status: false, message: "Can't connect server"} - end + # Check for paypar account exists + # if paypar_account_no != nil || paypar_account_no != '' + if paypar_account_no.present? + member_params = { name: customer.name,phone: customer.contact_no, + email: customer.email,dob: customer.date_of_birth, + address: customer.address,nrc:customer.nrc_no, + paypar_account_no: customer.paypar_account_no, + card_no:customer.card_no,member_group_id: customer.membership_type, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json + end - if response["status"] == true - status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - end + begin + response = HTTParty.post(url, + :body => member_params, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }) + rescue Net::OpenTimeout + response = { status: false, message: "Server Time out" } + + rescue OpenURI::HTTPError + response = { status: false, message: "Can't connect server"} + rescue SocketError + response = { status: false, message: "Can't connect server"} + end + + if response["status"] == true + status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) + end end end def self.update_rebate - sales = Sale.where("rebate_status = 'false'") sales.each do |sale| if sale.customer.membership_id - response = self.rebat(Sale.find(sale.sale_id)) - puts response.to_json + response = self.rebat(Sale.find(sale.sale_id)) if response["status"] == true status = sale.update_attributes(rebate_status: "true") end @@ -188,12 +196,44 @@ class Customer < ApplicationRecord response = { "status": false, "message": "Can't connect server"} end - return response - puts response.to_json + return response end end end + def self.search_paypar_account_no(account_no) + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("search_paypar_account_no") + merchant_uid = memberaction.merchant_account_id.to_s + auth_token = memberaction.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + begin + response = HTTParty.get(url, + :body => { paypar_account_no:account_no, + merchant_uid:merchant_uid, + auth_token:auth_token + }.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, + :timeout => 10 + ) + rescue HTTParty::Error + response = {status: false, message: "Server Error"} + + rescue Net::OpenTimeout + response = { status: false , message: "Server Time out"} + + rescue OpenURI::HTTPError + response = { status: false, message: "Can't connect server"} + + rescue SocketError + response = { status: false, message: "Can't connect server"} + end + return response + end + def self.search(search) if search # find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"]) diff --git a/app/models/menu_item_attribute.rb b/app/models/menu_item_attribute.rb index 54d2f34e..e57085cb 100644 --- a/app/models/menu_item_attribute.rb +++ b/app/models/menu_item_attribute.rb @@ -1,6 +1,6 @@ class MenuItemAttribute < ApplicationRecord validates_presence_of :attribute_type, :name, :value def self.collection - MenuItemAttribute.select("name, value").map { |e| [e.name, e.value] } + MenuItemAttribute.select("name").map { |e| [e.name, e.name] } end end diff --git a/app/models/order.rb b/app/models/order.rb index 0ef19729..e26d1ee2 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -90,7 +90,7 @@ class Order < ApplicationRecord # self.employee_name) # end - OrderItem.processs_item(menu_item[:item_code], menu_item[:name], menu_item[:alt_name], menu_item[:account_id], + OrderItem.processs_item(menu_item[:item_code], item[:item_instance_code], menu_item[:name], menu_item[:alt_name], menu_item[:account_id], item[:quantity],menu_item[:price], item[:options], set_order_items, self.id, self.employee_name) diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 897a4b1e..12c8c378 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -20,11 +20,12 @@ class OrderItem < ApplicationRecord # option_values : [], # sub_order_items : [], # } - def self.processs_item (item_code, menu_name, alt_name, account_id, qty,price, options, set_menu_items, order_id, item_order_by) + def self.processs_item (item_code, instance_code, menu_name, alt_name, account_id, qty,price, options, set_menu_items, order_id, item_order_by) orderitem = OrderItem.create do |oitem| oitem.order_id = order_id oitem.item_code = item_code + oitem.item_instance_code = instance_code oitem.item_name = menu_name oitem.alt_name = alt_name oitem.account_id = account_id diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 3435190d..4719e546 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -324,7 +324,6 @@ class SalePayment < ApplicationRecord update_shift end end - end # update for cashier shift diff --git a/app/views/api/restaurant/menu/_menu.json.jbuilder b/app/views/api/restaurant/menu/_menu.json.jbuilder index cfa950d7..29982631 100644 --- a/app/views/api/restaurant/menu/_menu.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu.json.jbuilder @@ -17,5 +17,4 @@ if (menu.menu_categories) end end end - end diff --git a/app/views/api/restaurant/menu/_menu_item.json.jbuilder b/app/views/api/restaurant/menu/_menu_item.json.jbuilder index 7a450850..3f8b5358 100644 --- a/app/views/api/restaurant/menu/_menu_item.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu_item.json.jbuilder @@ -1,44 +1,82 @@ # Format for attributes json attr_format = [] -param_count = item.item_attributes.count -# Format for attributes json -item.item_attributes.each do|attr_id| - menu_attr = MenuItemAttribute.find(attr_id) - if attr_format.count == 0 - attr_format.push({ type: menu_attr.attribute_type, value: [] }) - end - - attr_format.each do |af| - if menu_attr.attribute_type == af[:type] - af[:value].push(menu_attr.value) - else - new_attr = {type: menu_attr.attribute_type, value: [ menu_attr.value ] } - attr_format.push(new_attr) +# Format for attributes json +if item.item_attributes.count > 0 + item.item_attributes.each do|attr_id| + menu_attr = MenuItemAttribute.find(attr_id) + if attr_format.count == 0 + attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] }) + next end - - break if attr_format.count > param_count - end - param_count -= 1 + attr_format.each do |af| + if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]} + if menu_attr.attribute_type == af[:type] + af[:values].push(menu_attr.name) + end + else + new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] } + attr_format.push(new_attr) + break + end + end + end +end + +# Format for option json +opt_format = [] +# Format for attributes json +if item.item_options.count > 0 + item.item_options.each do|opt| + menu_opt = MenuItemOption.find(opt) + if opt_format.count == 0 + opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] }) + next + end + + opt_format.each do |of| + if menu_opt.option_type.in? opt_format.map {|k| k[:type]} + if menu_opt.option_type == of[:type] + of[:values].push(menu_opt.name) + end + else + new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } + opt_format.push(new_opt) + break + end + end + end end #Menu Item Information json.id item.id -json.item_code item.item_code +json.code item.item_code json.name item.name json.alt_name item.alt_name json.image item.image_path.url json.description item.description -json.Information item.information +json.information item.information json.type item.type json.account_id item.account_id json.min_qty item.min_qty json.is_available item.is_available json.is_sub_item item.is_sub_item json.unit item.unit -json.item_sets item.item_sets + +# Item Sets of Menu Item +json.item_sets item.item_sets do |its| + json.id its.id + json.name its.name + json.alt_name its.alt_name + json.min_selectable_qty its.min_selectable_qty + json.max_selectable_qty its.max_selectable_qty + json.instances its.menu_item_instances do |i| + json.id i.id + end +end + json.attributes attr_format -json.options item.item_options +json.options opt_format # json.min_selectable_item item.min_selectable_item # json.max_selectable_item item.max_selectable_item @@ -52,6 +90,7 @@ json.options item.item_options # json.item_attributes = item_instance.item_attributes json.instances item.menu_item_instances do |is| + json.id is.id json.code is.item_instance_code json.name is.item_instance_name json.price is.price @@ -59,8 +98,8 @@ json.options item.item_options json.is_default is.is_default json.is_on_promotion is.is_on_promotion json.promotion_price is.promotion_price - json.item_attributes is.item_attributes - json.item_sets is.item_sets + json.values is.item_attributes + # json.item_sets is.item_sets end #Child Menu items diff --git a/app/views/api/restaurant/menu/index.json.jbuilder b/app/views/api/restaurant/menu/index.json.jbuilder index 55e876f6..46f35e60 100644 --- a/app/views/api/restaurant/menu/index.json.jbuilder +++ b/app/views/api/restaurant/menu/index.json.jbuilder @@ -1,4 +1,4 @@ -json.array! @menus do |menu| +menu_json = json.array! @menus do |menu| json.id menu.id json.name menu.name json.valid_days menu.valid_days @@ -12,3 +12,4 @@ json.array! @menus do |menu| # end # end end + diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 35c3a46d..c39f065f 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -169,6 +169,7 @@ if(cardNo.length == 16){ $("#paypar_account_no").val(cardNo); $("#search").val(cardNo); + $("#type").val("card"); } } \ No newline at end of file diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 71772c92..9d2fa62b 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -25,6 +25,7 @@ <%= form_tag crm_customers_path, :id => "filter_form", :method => :get do %>
+ diff --git a/app/views/origami/addorders/show.html.erb b/app/views/origami/addorders/show.html.erb index 0e8a8163..8f9b1c08 100644 --- a/app/views/origami/addorders/show.html.erb +++ b/app/views/origami/addorders/show.html.erb @@ -49,48 +49,6 @@
- - - - - + + + +