From d87ffee65b491cc164fa8b6aba6a385da646f18f Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Fri, 20 Dec 2019 10:35:31 +0630 Subject: [PATCH] update seed generator and remove hard-coded customer id --- app/assets/javascripts/origami_bk.js | 16 ++-- app/controllers/api/api_controller.rb | 2 +- app/controllers/api/bill_controller.rb | 2 +- app/controllers/api/orders_controller.rb | 4 +- app/controllers/application_controller.rb | 1 + app/controllers/base_crm_controller.rb | 1 - app/controllers/base_inventory_controller.rb | 1 - app/controllers/base_oqs_controller.rb | 3 +- app/controllers/base_origami_controller.rb | 3 +- app/controllers/base_report_controller.rb | 1 - app/controllers/base_waiter_controller.rb | 1 - app/controllers/concerns/customers.rb | 18 +++++ app/controllers/crm/customers_controller.rb | 52 ++++++------- .../origami/addorders_controller.rb | 4 +- .../origami/customers_controller.rb | 8 +- .../origami/food_court_controller.rb | 4 +- app/controllers/origami/home_controller_bk.rb | 10 +-- .../origami/payments_controller.rb | 2 +- .../origami/pending_order_controller.rb | 4 +- .../origami/quick_service_controller.rb | 4 +- .../origami/room_invoices_controller.rb | 1 - app/controllers/origami/surveys_controller.rb | 16 ++-- .../origami/table_invoices_controller.rb | 1 - app/models/application_record.rb | 4 +- app/models/customer.rb | 50 +++++++----- app/models/order.rb | 2 +- app/models/sale.rb | 4 +- app/models/seed_generator.rb | 30 ++++++-- app/models/tax_profile.rb | 2 + app/views/origami/addorders/detail.html.erb | 4 +- app/views/origami/customers/index.html.erb | 77 +++++++++---------- app/views/origami/payments/show.html.erb | 5 +- 32 files changed, 184 insertions(+), 153 deletions(-) create mode 100644 app/controllers/concerns/customers.rb diff --git a/app/assets/javascripts/origami_bk.js b/app/assets/javascripts/origami_bk.js index d4071432..aaa05613 100755 --- a/app/assets/javascripts/origami_bk.js +++ b/app/assets/javascripts/origami_bk.js @@ -69,11 +69,11 @@ $(document).ready(function(){ type: "POST", url: "/origami/" + unique_id, data: { 'booking_id' : unique_id }, - success:function(result){ + success:function(result){ for (i = 0; i < result.length; i++) { var data = JSON.stringify(result[i]); var parse_data = JSON.parse(data); - var show_date = ""; + var show_date = ""; // Receipt Header receipt_no = result[i].receipt_no; @@ -81,14 +81,14 @@ $(document).ready(function(){ if(result[i].receipt_date != null){ receipt_date = new Date(result[i].receipt_date); show_date = receipt_date.getDate() + "-" + receipt_date.getMonth() + "-" + receipt_date.getFullYear() + ' ' + receipt_date.getHours()+ ':' + receipt_date.getMinutes() - } + } //Receipt Charges sub_total += parseFloat(parse_data.price); discount_amount = parse_data.discount_amount == null? '0.0' : parse_data.discount_amount; tax_amount = parse_data.tax_amount; - grand_total_amount = parse_data.grand_total_amount; + grand_total_amount = parse_data.grand_total_amount; // Ordered Items var order_items_rows = "" + @@ -135,7 +135,7 @@ $(document).ready(function(){ // Discount for Payment $('#discount').click(function() { var order_id=$(".selected-item").find(".orders-id").text().substr(0,16); - + if(order_id!=""){ window.location.href = '/origami/' + order_id + '/discount' } @@ -164,7 +164,7 @@ $(document).ready(function(){ } // For Percentage Discount - if(discount_type == 1){ + if(discount_type == 1){ discount_amount=(sub_total*discount_value)/100; } @@ -193,7 +193,7 @@ $(document).ready(function(){ $('#customer').click(function() { var sale = $(".selected-item").find(".orders-id").text().substr(0,16); - if (sale.substring(0, 3)=="SAL") { + if (sale.includes("SAL")) { var sale_id = sale }else{ var sale_id = $(".selected-item").find(".order-cid").text(); @@ -205,7 +205,7 @@ $(document).ready(function(){ $('#re-print').click(function() { var sale_id = $(".selected-item").find(".orders-id").text().substr(0,16); - + window.location.href = '/origami/'+ sale_id + "/reprint" return false; diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index c60b3f0f..8c6aaf65 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,9 +1,9 @@ class Api::ApiController < ActionController::API - include MultiTenancy include TokenVerification include ActionController::MimeResponds include ActionView::Rendering + include Customers # before_action :lookup_domain helper_method :current_token, :current_login_employee, :get_cashier diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 9ef0df15..64597f02 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -140,7 +140,7 @@ class Api::BillController < Api::ApiController @order = Order.new @order.source = "cashier" @order.order_type = "Takeaway" - @order.customer_id = "CUS-000000000002" # for no customer id from mobile + @order.customer_id = takeaway.customer_id # for no customer id from mobile @order.items = params[:order_items] @order.guest = params[:guest_info] @order.table_id = params[:table_id] # this is dining facilities's id diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 3002d996..0c79f303 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -93,7 +93,7 @@ class Api::OrdersController < Api::ApiController @order = Order.new @order.source = params[:order_source] @order.order_type = params[:order_type] - @order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + @order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile @order.items = params[:order_items] @order.guest = params[:guest_info] @order.table_id = params[:table_id] # this is dining facilities's id @@ -113,7 +113,7 @@ class Api::OrdersController < Api::ApiController end @status, @booking = @order.generate - + if @status && @booking Order.process_order_queue(@order.order_id,@order.table_id,@order.source) end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8f537383..6d5a413e 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,7 @@ class ApplicationController < ActionController::Base include MultiTenancy include LoginVerification + include Customers #before_action :check_installation protect_from_forgery with: :exception diff --git a/app/controllers/base_crm_controller.rb b/app/controllers/base_crm_controller.rb index 1f6ad484..273a3639 100755 --- a/app/controllers/base_crm_controller.rb +++ b/app/controllers/base_crm_controller.rb @@ -1,5 +1,4 @@ class BaseCrmController < ActionController::Base - include MultiTenancy include LoginVerification layout "CRM" diff --git a/app/controllers/base_inventory_controller.rb b/app/controllers/base_inventory_controller.rb index b591fe85..64cdd2cd 100755 --- a/app/controllers/base_inventory_controller.rb +++ b/app/controllers/base_inventory_controller.rb @@ -1,5 +1,4 @@ class BaseInventoryController < ActionController::Base - include MultiTenancy include LoginVerification layout "inventory" diff --git a/app/controllers/base_oqs_controller.rb b/app/controllers/base_oqs_controller.rb index 776f8749..6b01383d 100755 --- a/app/controllers/base_oqs_controller.rb +++ b/app/controllers/base_oqs_controller.rb @@ -1,8 +1,7 @@ class BaseOqsController < ActionController::Base - include MultiTenancy include LoginVerification - + layout "OQS" before_action :check_user diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index cd011ca4..468a2fab 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -1,7 +1,8 @@ class BaseOrigamiController < ActionController::Base - include MultiTenancy include LoginVerification + include Customers + layout "origami" before_action :check_user diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 021d29c6..9dfa7c18 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,5 +1,4 @@ class BaseReportController < ActionController::Base - include MultiTenancy include LoginVerification layout "application" diff --git a/app/controllers/base_waiter_controller.rb b/app/controllers/base_waiter_controller.rb index 598b93d6..f89a8f31 100755 --- a/app/controllers/base_waiter_controller.rb +++ b/app/controllers/base_waiter_controller.rb @@ -1,5 +1,4 @@ class BaseWaiterController < ActionController::Base - include MultiTenancy include LoginVerification layout "waiter" diff --git a/app/controllers/concerns/customers.rb b/app/controllers/concerns/customers.rb new file mode 100644 index 00000000..83df79c1 --- /dev/null +++ b/app/controllers/concerns/customers.rb @@ -0,0 +1,18 @@ +module Customers + extend ActiveSupport::Concern + + included do + helper_method :walkin, :takeaway if respond_to? :helper_method + end + + def walkin + return @walkin if defined? @walkin + @walkin = Customer.walkin + end + + def takeaway + return @takeaway if defined? @takeaway + @takeaway = Customer.takeaway + end + +end diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 023b453c..1a5ed025 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -21,7 +21,7 @@ class Crm::CustomersController < BaseCrmController # paymal_customer = Customer.search_paypar_account_no(filter) # search account no from paypar if type == "card" - + response = Customer.search_paypar_account_no(filter) if !@crm_customers.present? if response["status"] == true @@ -70,7 +70,7 @@ class Crm::CustomersController < BaseCrmController else flash[:member_error]="Need to press sync button " end - + end end end @@ -82,8 +82,9 @@ class Crm::CustomersController < BaseCrmController @membership_types = Lookup.collection_of("member_group_type") # @taxes = TaxProfile.where(:group_type => 'cashier') - @taxes = TaxProfile.unscope(:order).select("id, (CONCAT(name,'(',(SELECT name FROM lookups WHERE lookup_type='tax_profiles' AND value=group_type),')')) as name") - .order("group_type ASC,order_by ASC") + @taxes = TaxProfile.unscope(:order).select("tax_profiles.id, CONCAT(tax_profiles.name, '(', lookups.name, ')') as name") + .joins(:lookup) + .order("group_type ASC, order_by ASC") @filter = filter @@ -95,7 +96,7 @@ class Crm::CustomersController < BaseCrmController lookup_customer = Lookup.collection_of('customer_settings') if !lookup_customer.empty? lookup_customer.each do |create_setting| - if create_setting[0].downcase == "create" + if create_setting[0].downcase == "create" if create_setting[1] == '0' && current_login_employee.role == 'cashier' @create_flag = false end @@ -135,7 +136,7 @@ class Crm::CustomersController < BaseCrmController params[:type] = nil params[:customer_id] = params[:id] @credit_sales = SalePayment.get_credit_sales(params) - + #get customer amount @customer = Customer.find(params[:id]) @response = Customer.get_membership_transactions(@customer) @@ -159,7 +160,7 @@ class Crm::CustomersController < BaseCrmController @customer = Customer.find(params[:id]) end def sync - @customer = Customer.find(params[:id]) + @customer = Customer.find(params[:id]) respond_to do |format| name = @customer.name phone = @customer.contact_no @@ -170,8 +171,8 @@ class Crm::CustomersController < BaseCrmController card_no = @customer.card_no paypar_account_no = @customer.paypar_account_no id = @crm_customer.membership_id - member_group_id = @customer.membership_type - if !id.present? && !member_group_id.nil? + member_group_id = @customer.membership_type + if !id.present? && !member_group_id.nil? membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("create_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s @@ -179,7 +180,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -221,7 +222,7 @@ class Crm::CustomersController < BaseCrmController Rails.logger.debug "--------Sync Member response -------" Rails.logger.debug response.to_json if response["status"] == true - + status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) format.html { redirect_to crm_customers_path } @@ -252,9 +253,9 @@ class Crm::CustomersController < BaseCrmController end # POST /crm/customers # POST /crm/customers.json - def create - # Remove "" default first - params[:customer][:tax_profiles].delete_at(0) + def create + # Remove "" default first + params[:customer][:tax_profiles].delete_at(0) @checked_contact = Customer.find_by_contact_no(customer_params[:contact_no]) if @checked_contact.nil? respond_to do |format| @@ -272,7 +273,7 @@ class Crm::CustomersController < BaseCrmController nrc = customer_params[:nrc_no] card_no = customer_params[:card_no] paypar_account_no = customer_params[:paypar_account_no] - member_group_id = params[:member_group_id] + member_group_id = params[:member_group_id] if member_group_id.present? membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -282,7 +283,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -333,7 +334,7 @@ class Crm::CustomersController < BaseCrmController end # format.json { render :index, status: :created, location: @crm_customers } else - customer = Customer.find(@crm_customers.customer_id) + customer = Customer.find(@crm_customers.customer_id) # Check membership id and bind to user if response["membership_id"] != nil @@ -399,7 +400,7 @@ class Crm::CustomersController < BaseCrmController # PATCH/PUT /crm/customers/1 # PATCH/PUT /crm/customers/1.json def update - # Remove "" default first + # Remove "" default first params[:customer][:tax_profiles].delete_at(0) @checked_contact = nil @existed_contact = Customer.find_by_customer_id_and_contact_no(customer_params[:id], customer_params[:contact_no]) @@ -409,7 +410,7 @@ class Crm::CustomersController < BaseCrmController if !@existed_contact.nil? || @checked_contact.nil? respond_to do |format| if @crm_customer.update(customer_params) - # update tax profile + # update tax profile @crm_customer.update_attributes(tax_profiles: params[:customer][:tax_profiles]) name = customer_params[:name] phone = customer_params[:contact_no] @@ -420,7 +421,7 @@ class Crm::CustomersController < BaseCrmController card_no = customer_params[:card_no] paypar_account_no = customer_params[:paypar_account_no] id = @crm_customer.membership_id - member_group_id = params[:member_group_id] + member_group_id = params[:member_group_id] if !id.present? && !member_group_id.nil? membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -430,7 +431,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -471,7 +472,7 @@ class Crm::CustomersController < BaseCrmController Rails.logger.debug "--------Update Member response -------" Rails.logger.debug response.to_json if response["status"] == true - + status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) format.html { redirect_to crm_customers_path } @@ -496,7 +497,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, + dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json @@ -601,7 +602,7 @@ class Crm::CustomersController < BaseCrmController flash[:member_notice]='Membership was successfully updated' end end - + end @@ -617,6 +618,5 @@ class Crm::CustomersController < BaseCrmController params.require(:customer).permit(:id, :name, :company, :contact_no, :email, :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no, :paypar_account_no, :customer_type, :image_path) end - -end +end diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index afc8f07e..2e36aaa1 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -126,9 +126,9 @@ class Origami::AddordersController < BaseOrigamiController } # begin if params[:order_source] == "quick_service" && params[:table_id].to_i == 0 - customer_id = "CUS-000000000002" # for no customer id from mobile + customer_id = takeaway.customer_id # for no customer id from mobile else - customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile end Order.transaction do diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index b77137a9..746b8bdc 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -55,7 +55,7 @@ class Origami::CustomersController < BaseOrigamiController @cashier_type = params[:type] @page = params[:dir_page] - if(@sale_id[0,3] == "SAL") + if @sale_id.include? "SAL" @booking = Booking.find_by_sale_id(@sale_id) if @booking.dining_facility_id.to_i > 0 @dining_facility = DiningFacility.find(@booking.dining_facility_id) @@ -117,7 +117,7 @@ class Origami::CustomersController < BaseOrigamiController def update_sale_by_customer - id = params[:sale_id][0,3] + id = params[:sale_id] customer_id = params[:customer_id] customer = Customer.find(customer_id) order_source = params[:type] @@ -129,7 +129,7 @@ class Origami::CustomersController < BaseOrigamiController # end # end - if(id == "SAL") + if id.include? "SAL" sale = Sale.find(params[:sale_id]) status = sale.update_attributes(customer_id: customer_id) sale.sale_orders.each do |sale_order| @@ -153,7 +153,7 @@ class Origami::CustomersController < BaseOrigamiController if status == true render json: JSON.generate({:status => true}) - if(id == "SAL") + if id.include? "SAL" sale.compute_by_sale_items(sale.total_discount, nil, order_source) end else diff --git a/app/controllers/origami/food_court_controller.rb b/app/controllers/origami/food_court_controller.rb index 1157bb44..e201566d 100644 --- a/app/controllers/origami/food_court_controller.rb +++ b/app/controllers/origami/food_court_controller.rb @@ -49,7 +49,7 @@ class Origami::FoodCourtController < ApplicationController # @menus = Menu.all # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') # end - if(params[:id][0,3] == "BKI") + if params[:id].include? "BKI" @table_id = nil @table = nil @booking = Booking.find(params[:id]) @@ -106,7 +106,7 @@ class Origami::FoodCourtController < ApplicationController order = Order.new order.source = params[:order_source] order.order_type = params[:order_type] - order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile order.items = items_arr order.guest = params[:guest_info] order.table_id = params[:table_id] # this is dining facilities's id diff --git a/app/controllers/origami/home_controller_bk.rb b/app/controllers/origami/home_controller_bk.rb index 4839f15c..2220f463 100755 --- a/app/controllers/origami/home_controller_bk.rb +++ b/app/controllers/origami/home_controller_bk.rb @@ -1,9 +1,8 @@ class Origami::HomeController < ApplicationController def index if params[:booking_id] != nil - type=params[:booking_id].split('-')[0]; # Sale - if type == "SAL" + if params[:booking_id].include? "SAL" @selected_item = Sale.find(params[:booking_id]) @selected_item_type="Sale" # Booking @@ -25,9 +24,8 @@ class Origami::HomeController < ApplicationController def selection(selected_id, is_ajax) str = [] - type=selected_id.split('-')[0]; # Sale - if type == "SAL" + if selected_id.include? "SAL" @order_details = SaleItem.get_order_items_details(params[:booking_id]) @order_details.each do |ord_detail| str.push(ord_detail) @@ -48,9 +46,7 @@ class Origami::HomeController < ApplicationController end def update_sale_by_customer - - id = params[:sale_id][0,3] - if(id == "SAL") + if id.inlude? "SAL" sale = Sale.find(params[:sale_id]) else sale = Order.find(params[:sale_id]) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index ef30eb5d..3103ca38 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -295,7 +295,7 @@ class Origami::PaymentsController < BaseOrigamiController @shop = shop_detail #show shop info - @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") + @customer_lists = Customer.where(name: ["WALK-IN", "TAKEAWAY"]) saleObj = Sale.find(sale_id) diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb index 773a217e..aad9f792 100644 --- a/app/controllers/origami/pending_order_controller.rb +++ b/app/controllers/origami/pending_order_controller.rb @@ -14,7 +14,7 @@ class Origami::PendingOrderController < BaseOrigamiController def show id = params[:sale_id] - if id.start_with?("SAL") + if id.include? "SAL" @sale = Sale.find(id) if @sale.sale_status == "new" @bookings = @sale.bookings.first @@ -22,7 +22,7 @@ class Origami::PendingOrderController < BaseOrigamiController else redirect_to "/origami/#{params[:type]}" and return end - elsif (id.start_with?("BKI") || id.start_with?("CBKI")) + elsif id.include? "BKI" @bookings = Booking.find(id) @order = @bookings.orders.where(status: "new").first @order_items = @bookings.order_items diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index eb1508e4..5e8c3a98 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -42,7 +42,7 @@ class Origami::QuickServiceController < ApplicationController # @menus = Menu.all # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') # end - if(params[:id][0,3] == "BKI") + if params[:id].include? "BKI" @table_id = nil @table = nil @booking = Booking.find(params[:id]) @@ -99,7 +99,7 @@ class Origami::QuickServiceController < ApplicationController order = Order.new order.source = params[:order_source] order.order_type = params[:order_type] - order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + order.customer_id = params[:customer_id].present? ? params[:customer_id] : walkin.customer_id # for no customer id from mobile order.items = items_arr order.guest = params[:guest_info] order.table_id = params[:table_id] # this is dining facilities's id diff --git a/app/controllers/origami/room_invoices_controller.rb b/app/controllers/origami/room_invoices_controller.rb index 8d805771..095eaa93 100755 --- a/app/controllers/origami/room_invoices_controller.rb +++ b/app/controllers/origami/room_invoices_controller.rb @@ -1,7 +1,6 @@ class Origami::RoomInvoicesController < BaseOrigamiController def index @room = DiningFacility.find(params[:room_id]) - puts "room bookig lenght" @sale_array = Array.new @room.bookings.each do |booking| puts booking.sale_id diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index 700159bb..201313ff 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -2,14 +2,14 @@ class Origami::SurveysController < BaseOrigamiController def new @webview = false if check_mobile - @webview = true + @webview = true end - + @survey = Survey.new @id = params[:id] @cashier_type = params[:type] - if(@id[0,3] == "SAL") + if @id.include? "SAL" @sale = Sale.find(@id) @receipt_no = @sale.receipt_no @grand_total = @sale.grand_total @@ -27,14 +27,14 @@ class Origami::SurveysController < BaseOrigamiController @dining_facility = nil @table_type = nil end - + else @dining_facility = DiningFacility.find(@id) @table_type = @dining_facility.type @receipt_no = nil @grand_total = nil @survey_data = Survey.find_by_dining_name_and_receipt_no(@dining_facility.name,nil) - end + end end def create @@ -63,13 +63,13 @@ class Origami::SurveysController < BaseOrigamiController shift = ShiftSale.find(sale.shift_sale_id) shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(shift.cashier_terminal_id,nil) end - + if @type == "quick_service" || @type == "food_court" @url = "/origami/sale/"+@sale_id+"/"+@type+"/payment" else @url = "/origami/"+@dining_facility.type.downcase+"/"+params[:table_id] end - + if params[:survey_id].nil? || params[:survey_id] == "" @survey = Survey.new(survey_params) @@ -106,5 +106,5 @@ class Origami::SurveysController < BaseOrigamiController def survey_params params.require(:survey).permit(:child, :adult,:male,:female,:local,:foreigner, :dining_name,:receipt_no,:shift_id,:created_by,:total_customer,:total_amount,:survey_id) end - + end diff --git a/app/controllers/origami/table_invoices_controller.rb b/app/controllers/origami/table_invoices_controller.rb index 77a3fd57..3a526ed6 100755 --- a/app/controllers/origami/table_invoices_controller.rb +++ b/app/controllers/origami/table_invoices_controller.rb @@ -2,7 +2,6 @@ class Origami::TableInvoicesController < BaseOrigamiController def index @table = DiningFacility.find(params[:table_id]) shop = Shop.current_shop - puts "table bookig lenght" @sale_array = Array.new @table.bookings.each do |booking| puts booking.sale_id diff --git a/app/models/application_record.rb b/app/models/application_record.rb index 590cdf8d..c19491c8 100755 --- a/app/models/application_record.rb +++ b/app/models/application_record.rb @@ -5,10 +5,10 @@ class ApplicationRecord < ActiveRecord::Base super return unless subclass.superclass == self - return unless subclass.column_names.include? 'shop_id' + return unless subclass.column_names.include? 'shop_code' subclass.class_eval do - acts_as_tenant(:shop) + acts_as_tenant(:shop, foreign_key: 'shop_code', primary_key: 'shop_code') end end end diff --git a/app/models/customer.rb b/app/models/customer.rb index 04d4449c..0a17cf12 100755 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -11,12 +11,20 @@ class Customer < ApplicationRecord validates_presence_of :name, :contact_no, :email #,:card_no validates :contact_no, numericality: true #uniqueness: true, - validates :email, uniqueness: true,format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create } + # validates :email, uniqueness: true,format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, on: :create } # validates :card_no, uniqueness: true # validates :paypar_account_no, uniqueness: true paginates_per 50 + def self.walkin + self.find_by(name: "WALK-IN") + end + + def self.takeaway + self.find_by(name: "TAKEAWAY") + end + def self.get_member_account(customer) membership = MembershipSetting.active.find_by_membership_type("paypar_url") memberaction = MembershipAction.active.find_by_membership_type("get_all_member_account") @@ -26,7 +34,7 @@ class Customer < ApplicationRecord # urltest =self.url_exist?(url) if !membership.nil? && !memberaction.nil? begin - response = HTTParty.get(url, :body => { + response = HTTParty.get(url, :body => { membership_id: customer.membership_id, merchant_uid:merchant_uid, type: "summary", @@ -39,7 +47,7 @@ class Customer < ApplicationRecord :timeout => 10) rescue HTTParty::Error response = {status: false, message: "Server Error"} - + rescue Net::OpenTimeout response = { status: false , message: "Server Time out"} @@ -107,7 +115,7 @@ 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| member_params = { name: customer.name,phone: customer.contact_no, @@ -125,7 +133,7 @@ class Customer < ApplicationRecord 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 + end begin response = HTTParty.post(url, @@ -136,7 +144,7 @@ class Customer < ApplicationRecord }) rescue Net::OpenTimeout response = { status: false, message: "Server Time out" } - + rescue OpenURI::HTTPError response = { status: false, message: "Can't connect server"} @@ -154,12 +162,12 @@ class Customer < ApplicationRecord def self.update_rebate sales = Sale.where("rebate_status = 'false'") sales.each do |sale| - if sale.customer.membership_id + if sale.customer.membership_id response = self.rebat(Sale.find(sale.sale_id)) #record an payment in sale-audit if !response.nil? remark = "UPdate Rebate Response - #{response} for Customer #{sale.customer_id} Sale Id [#{sale.sale_id}]| pay amount -> #{sale.amount_received} " - sale_audit = SaleAudit.record_paymal(sale.sale_id, remark, 1) + sale_audit = SaleAudit.record_paymal(sale.sale_id, remark, 1) end if response["status"] == true status = sale.update_attributes(rebate_status: "true") @@ -172,7 +180,7 @@ class Customer < ApplicationRecord rebate_prices,campaign_method = SaleItem.calculate_rebate_by_account(sObj.sale_items) generic_customer_id = sObj.customer.membership_id - + if generic_customer_id.present? paypar = sObj.sale_payments payparcost = 0 @@ -189,7 +197,7 @@ class Customer < ApplicationRecord end # overall_dis = SaleItem.get_overall_discount(sObj.id) overall_dis = sObj.total_discount - + if credit != 1 membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("get_member_campaign") @@ -200,8 +208,8 @@ class Customer < ApplicationRecord # Control for Paypar Cloud begin - response = HTTParty.get(url, - :body => { + response = HTTParty.get(url, + :body => { member_group_id:sObj.customer.membership_type, merchant_uid:merchant_uid, campaign_type_id: campaign_type_id, @@ -215,7 +223,7 @@ class Customer < ApplicationRecord response = { "status": false , "message": "Connect To" } rescue OpenURI::HTTPError response = { "status": false, "message": "Can't connect server"} - + rescue SocketError response = { "status": false, "message": "Can't connect server"} end @@ -232,7 +240,7 @@ class Customer < ApplicationRecord response["membership_campaign_data"].each do |a| data = {:type => a["rules_type"], :percentage => a["change_unit"].to_i * a["base_unit"].to_i} total_percentage = total_percentage + a["change_unit"].to_i * a["base_unit"].to_i - + type_arr.push(data) end end @@ -249,7 +257,7 @@ class Customer < ApplicationRecord actual = a[:amount] - amount data[:amount] = actual end - + end end rebate_arr.push(data) @@ -272,8 +280,8 @@ class Customer < ApplicationRecord # Control for Paypar Cloud begin - response = HTTParty.post(url, - :body => { + response = HTTParty.post(url, + :body => { generic_customer_id:generic_customer_id , total_sale_transaction_amount: sObj.grand_total, merchant_uid:merchant_uid, @@ -291,7 +299,7 @@ class Customer < ApplicationRecord response = { "status": false , "message": "Connect To" } rescue OpenURI::HTTPError response = { "status": false, "message": "Can't connect server"} - + rescue SocketError response = { "status": false, "message": "Can't connect server"} end @@ -302,7 +310,7 @@ class Customer < ApplicationRecord end else puts "no Response" - response = { "status": "no_member", "message": "Not membership"} + response = { "status": "no_member", "message": "Not membership"} end end @@ -313,8 +321,8 @@ class Customer < ApplicationRecord 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, + response = HTTParty.get(url, + :body => { paypar_account_no:account_no, merchant_uid:merchant_uid, auth_token:auth_token }.to_json, diff --git a/app/models/order.rb b/app/models/order.rb index 0fa5ff78..0a6b8ddb 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -186,7 +186,7 @@ class Order < ApplicationRecord end def default_values - self.customer = Customer.find(1) if self.customer_id.nil? + self.customer = Customer.walkin if self.customer_id.nil? self.source = "emenu" if self.source.nil? self.order_type = "dine-in" if self.order_type.nil? end diff --git a/app/models/sale.rb b/app/models/sale.rb index 96e05a75..dd20fa2c 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1056,7 +1056,7 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,accou return query,other_charges, product, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount end -def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_type,customer_id) +def self.get_staff_meal_items(shift_sale_range, shift, from, to, status, account_type, customer_id) # date_type_selection = get_sql_function_for_report_type(report_type) if account_type.blank? account_type = '' @@ -1068,8 +1068,6 @@ def self.get_staff_meal_items(shift_sale_range, shift, from, to, status,account_ customer_id = customer_id.to_s customer_id[0] = "" customer_id = customer_id.chomp("]") - else - customer_id = '"CUS-000000000000"' end query = self.get_staff_meal_query() diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index b8224377..badde01f 100755 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -3,28 +3,44 @@ class SeedGenerator < ApplicationRecord def self.generate_id(model, prefix) model_name = self.get_model_name(model) + prefix ||= '' + prefix << '-' if prefix.present? + if ENV["SERVER_MODE"] == 'cloud' - prefix = "C#{prefix}" + prefix << 'C' + else + prefix << 'L' end - cur_val, next_val = self.update_seed(model_name) + if shop = Shop.current_shop + prefix << shop.shop_code + end - padding_len = 15 - prefix.length - saleOrderId = prefix +"-"+ cur_val.to_s.to_s.rjust(padding_len,'0') - return saleOrderId + seed = self.update_seed(model_name) + length = 15 - prefix.length + prefix + seed.to_s.rjust(padding_len, '0') end def self.generate_ids(model, prefix, count = 1) model_name = self.get_model_name(model) + prefix ||= '' + prefix << '-' if prefix.present? + if ENV["SERVER_MODE"] == 'cloud' - prefix = "C#{prefix}" + prefix << 'C' + else + prefix << 'L' + end + + if shop = Shop.current_shop + prefix << shop.shop_code end start = self.update_seed(model_name, count) stop = start + count - 1 length = 15 - prefix.length - (start..stop).map { |c| "#{prefix}-#{c.to_s.rjust(length, '0')}" } + (start..stop).map { |c| prefix + c.to_s.rjust(length, '0') } end def self.sync_seed_generator_records(seed_generators) diff --git a/app/models/tax_profile.rb b/app/models/tax_profile.rb index a9e56fac..5ae936ba 100755 --- a/app/models/tax_profile.rb +++ b/app/models/tax_profile.rb @@ -1,4 +1,6 @@ class TaxProfile < ApplicationRecord + has_one :lookup, -> { where(lookup_type: 'tax_profiles') }, foreign_key: "value", primary_key: "group_type" + default_scope { order('order_by asc') } # validations validates_presence_of :name, :rate, :group_type diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index daa12b33..07654ce6 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -267,11 +267,11 @@ <% if type && modify_order%> - + <%elsif !modify_order && type%> - + <% if current_user.role != "waiter"%> <% if @quick_service_only %> diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 72650ba3..e3ed07cb 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -22,7 +22,7 @@
- +
<% end %> --> @@ -72,7 +72,7 @@ - <% if @crm_customers.count > 0 %> + <% if @crm_customers.count > 0 %> <% @i = 0 %> <% @crm_customers.each do |crm_customer| %> @@ -80,7 +80,7 @@ - <% if crm_customer.customer_id != "CUS-000000000001" && crm_customer.customer_id != "CUS-000000000002" %> + <% if crm_customer.customer_id != "" && crm_customer.customer_id != "" %> <%= @i += 1 %> <%else%> - @@ -156,7 +156,7 @@ <%= simple_form_for @crm_customer,:url => crm_customers_path, :method => :post do |f| %> <%= f.error_notification %> - <%= f.hidden_field :id, :class => "form-control col-md-6 " %> + <%= f.hidden_field :id, :class => "form-control col-md-6 " %>
@@ -225,7 +225,7 @@
-
+
@@ -238,12 +238,12 @@ <% if f.object.image_path? %>

<%= f.object.name %>

<%= image_tag f.object.image_path.url, :class => "img-thumbnail" %> - <% else %> + <% else %> <%= image_tag "/image/menu_images/default.png", :class => "img-thumbnail" %> - <% end %> + <% end %>
<%= f.file_field :image_path, :class => "img-thumbnail" %> -
+
@@ -291,7 +291,7 @@ <%end %> - +
@@ -316,7 +316,7 @@
-
+
@@ -332,7 +332,7 @@ <%end %> - +
@@ -363,7 +363,7 @@
- diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index a7737724..ca2f6ada 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -1686,9 +1686,8 @@ $(document).ready(function(){ $("#customer_name").on("click",function(){ //start customer modal popup if((cashier_type=='quick_service' || cashier_type=='food_court') && (customer_id!=undefined) && (customer_id!=null) && (customer_id!="")){ - // if((customer_id == 'CUS-000000000001') && (customer_name == 'WALK-IN')){ - $("#is_memberModal").modal({show : true, backdrop: false, keyboard : false}); - // } + + $("#is_memberModal").modal({show : true, backdrop: false, keyboard : false}); } });