diff --git a/README.md b/README.md index 97819e87..398634d2 100755 --- a/README.md +++ b/README.md @@ -318,9 +318,6 @@ settings/lookups => { type:customer_type, name: Staff, value:Staff } For FoodCourt Cashier role settings/lookups => { type:employee_roles, name: FoodCourt Cashier, value:foodcourt_cashier } -For Search Paypar security_code -settings/lookups => { type:employee_roles, name: FoodCourt Cashier, value:foodcourt_cashier } - * ToDo list diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index ee0e7567..ab5670ac 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1041,7 +1041,7 @@ $(function() { }else if(result.data == 'OK'){ window.location.href = '/origami/'+type+'/pending_order/' + $('#sale_id').text(); }else{ - if(result.current_user_role == 'foodcourt_cashier'){ + if(result.current_user_role == 'cashier'){ window.location.href = "/foodcourt/sale/"+result.data["sale_id"]+"/"+type+"/payment"; } else{ diff --git a/app/controllers/api/call_waiters_controller.rb b/app/controllers/api/call_waiters_controller.rb index dcb543b7..5861621a 100644 --- a/app/controllers/api/call_waiters_controller.rb +++ b/app/controllers/api/call_waiters_controller.rb @@ -26,7 +26,7 @@ class Api::CallWaitersController < ActionController::API unique_code = "CallWaiterPdf" print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_call_waiter(print_settings,@table,@time,@shop) + printer.print_call_waiter(print_settings,@table,@time,current_shop) end diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index f10a00c4..e8f2a6f6 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -70,7 +70,7 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation) if !order_reservation_id.nil? && flag - shop = @shop + shop = current_shop if !shop.nil? shop_code = shop.shop_code order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio") diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 45be2c70..edbb3f22 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -51,7 +51,7 @@ class Api::OrdersController < Api::ApiController # end # - return @shop.to_json + return current_shop.to_json end @@ -66,13 +66,13 @@ class Api::OrdersController < Api::ApiController def create Rails.logger.debug "Order Source - " + params[:order_source].to_s Rails.logger.debug "Table ID - " + params[:table_id].to_s - @shop = Shop.find_by_shop_code(params[:shop_code]) + current_shift = ShiftSale.current_shift if current_shift.nil? @status = false @message = "No Current Open Shift for This Employee" else - current_user =Employee.find(current_shift.employee_id) + current_user = Employee.find(current_shift.employee_id) if checkin_checkout_time(params[:booking_id]) table = DiningFacility.find(params[:table_id]) if params[:table_id].present? @@ -124,6 +124,9 @@ class Api::OrdersController < Api::ApiController if @status && @booking Order.process_order_queue(@order.order_id,@order.table_id,@order.source) + if @order.source == 'app' + @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) + end end if @order.table_id.to_i > 0 table = DiningFacility.find(@booking.dining_facility_id) diff --git a/app/controllers/api/payment/callback_controller.rb b/app/controllers/api/payment/callback_controller.rb index 89162fc4..14cd5beb 100644 --- a/app/controllers/api/payment/callback_controller.rb +++ b/app/controllers/api/payment/callback_controller.rb @@ -10,7 +10,7 @@ class Api::Payment::CallbackController < Api::ApiController if trade_status == "PAY_SUCCESS" merch_order_id = params[:Request][:merch_order_id] - status, filename, sale_receipt_no, printer_name = Payment.pay(getCloudDomain, cash, sale_id, member_info, type, tax_type, path, latest_order_no, shop_detail, current_user, 'kbzpay', merch_order_id) + status, filename, sale_receipt_no, printer_name = Payment.pay(getCloudDomain, cash, sale_id, member_info, type, tax_type, path, latest_order_no, current_shop, current_user, 'kbzpay', merch_order_id) render json: JSON.generate({:status => status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) end end diff --git a/app/controllers/api/payment/mobilepayment_controller.rb b/app/controllers/api/payment/mobilepayment_controller.rb index 0c0ca37a..41e6a706 100644 --- a/app/controllers/api/payment/mobilepayment_controller.rb +++ b/app/controllers/api/payment/mobilepayment_controller.rb @@ -15,7 +15,7 @@ class Api::Payment::MobilepaymentController < Api::ApiController saleObj = Sale.find(sale_id) sale_items = SaleItem.get_all_sale_items(sale_id) - shop_detail = @shop + shop_detail = current_shop # rounding adjustment if !path.include? ("credit_payment") diff --git a/app/controllers/api/payments_controller.rb b/app/controllers/api/payments_controller.rb index 16c6b0ed..4cb93784 100755 --- a/app/controllers/api/payments_controller.rb +++ b/app/controllers/api/payments_controller.rb @@ -171,9 +171,9 @@ class Api::PaymentsController < Api::ApiController action_by = current_login_employee.name @status = true @message = "" - membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",sale.shop_code) + membership_setting = MembershipSetting.find_by_membership_type("paypar_url") if membership_setting.gateway_url - member_actions =MembershipAction.find_by_membership_type_and_shop_code("get_account_balance",sale.shop_code) + member_actions =MembershipAction.find_by_membership_type("get_account_balance") if member_actions.gateway_url @campaign_type_id = nil url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s diff --git a/app/controllers/api/shops_controller.rb b/app/controllers/api/shops_controller.rb index 23d50ebc..486f86fa 100644 --- a/app/controllers/api/shops_controller.rb +++ b/app/controllers/api/shops_controller.rb @@ -2,11 +2,11 @@ class Api::ShopsController < Api::ApiController skip_before_action :authenticate - def index + def index @shops = Shop.select('id,logo,name,shop_code,address,phone_no').all - end + end - def show + def show @shop = Shop.find_by_shop_code(params[:id]) end -end \ No newline at end of file +end diff --git a/app/controllers/api/sound_effect_controller.rb b/app/controllers/api/sound_effect_controller.rb index fda3a71d..e6c11bed 100644 --- a/app/controllers/api/sound_effect_controller.rb +++ b/app/controllers/api/sound_effect_controller.rb @@ -2,7 +2,7 @@ class Api::SoundEffectController < Api::ApiController #sound effect / alarm api for doemal side calling def sound_effect - shop = @shop + shop = current_shop if !shop.nil? shop_code = shop.shop_code order_audio = DisplayImage.find_by_shop_id_and_name(shop.id, "order_audio") diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 001cf6d9..70d93bf6 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -6,7 +6,7 @@ class ApplicationController < ActionController::Base #before_action :check_installation protect_from_forgery with: :exception - helper_method :shop_detail,:order_reservation, :bank_integration + helper_method :current_shop,:order_reservation, :bank_integration # lookup domain for db from provision # before_action :set_locale # helper_method :current_company,:current_login_employee,:current_user diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index ff5e2da2..88b31f6d 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -2,7 +2,7 @@ module LoginVerification extend ActiveSupport::Concern included do before_action :authenticate_session_token - helper_method :current_company, :current_shop, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :shop_detail + helper_method :current_company, :current_login_employee, :current_user, :get_cashier, :order_reservation, :bank_integration, :current_shop end #this is base api base controller to need to inherit. @@ -16,32 +16,23 @@ module LoginVerification end end - def current_shop - begin - return Shop.current_shop - rescue - return nil - end - end - def current_login_employee - @employee = Employee.find_by_token_session(session[:session_token]) + @employee ||= current_user end def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] end # Get current Cashiers def get_cashier - @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + @cashier ||= Employee.where("role = 'cashier' AND token_session <> ''") end - #Shop Name in Navbor - def shop_detail - @shop ||= current_shop - end + # def shop_detail + # @shop ||= current_shop + # end #check order reservation used def order_reservation diff --git a/app/controllers/concerns/multi_tenancy.rb b/app/controllers/concerns/multi_tenancy.rb index cbea7e62..a88cc9e0 100644 --- a/app/controllers/concerns/multi_tenancy.rb +++ b/app/controllers/concerns/multi_tenancy.rb @@ -3,18 +3,19 @@ module MultiTenancy included do set_current_tenant_through_filter if respond_to? :set_current_tenant_through_filter - before_action :find_shop_by_subdomain_or_frist if respond_to? :before_action + before_action :set_current_tenant_by_subdomain_or_frist if respond_to? :before_action + helper_method :current_shop if respond_to? :helper_method end private - def find_shop_by_subdomain_or_frist - if request.subdomain.present? - shop_code = request.subdomain.partition('-').last - @shop = Shop.find_by(shop_code: shop_code) - else - # @shop = Shop.first - @shop = Shop.find_by(shop_code: '262') + def set_current_tenant_by_subdomain_or_frist + if request.subdomains.last && request.subdomains.last != 'www' + set_current_tenant(Shop.find_by(subdomain: request.subdomains.last)) end - set_current_tenant(@shop) + set_current_tenant(Shop.first) if current_tenant.nil? + end + + def current_shop + ActsAsTenant.current_tenant end end diff --git a/app/controllers/concerns/token_verification.rb b/app/controllers/concerns/token_verification.rb index ec55b8ec..9df9d8e2 100755 --- a/app/controllers/concerns/token_verification.rb +++ b/app/controllers/concerns/token_verification.rb @@ -6,14 +6,13 @@ module TokenVerification before_action :authenticate end - protected # Authenticate the user with token based authentication def authenticate authenticate_token || render_unauthorized end - def authenticate_token + def authenticate_token authenticate_with_http_token do |token, options| # Rails.logger.debug "token - " + token.to_s if(options.length !=0 && options["from"] == "DOEMAL") diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index f636072e..2dac2713 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -48,7 +48,6 @@ class Crm::CustomersController < BaseCrmController @crm_customers.membership_type = response["customer_data"]["member_group_id"] @crm_customers.customer_type = "Dinein" @crm_customers.tax_profiles = ["1", "2"] - @crm_customers.shop_code = @shop.shop_code @crm_customers.save @crm_customers = Customer.search(filter) flash[:member_notice]='Customer was successfully created.' @@ -263,7 +262,6 @@ class Crm::CustomersController < BaseCrmController if @checked_contact.nil? respond_to do |format| @crm_customers = Customer.new(customer_params) - @crm_customers.shop_code = @shop.shop_code if @crm_customers.save # update tax profile customer = Customer.find(@crm_customers.customer_id) diff --git a/app/controllers/crm/dining_queues_controller.rb b/app/controllers/crm/dining_queues_controller.rb index da0fe6fa..68f8e8d2 100755 --- a/app/controllers/crm/dining_queues_controller.rb +++ b/app/controllers/crm/dining_queues_controller.rb @@ -40,7 +40,6 @@ class Crm::DiningQueuesController < BaseCrmController # POST /crm/dining_queues.json def create @dining_queue = DiningQueue.new(dining_queue_params) - @dining_queue.shop_code = @shop.shop_code respond_to do |format| if @dining_queue.save diff --git a/app/controllers/foodcourt/addorders_controller.rb b/app/controllers/foodcourt/addorders_controller.rb index 79ffdb37..0141c9ae 100755 --- a/app/controllers/foodcourt/addorders_controller.rb +++ b/app/controllers/foodcourt/addorders_controller.rb @@ -135,7 +135,6 @@ class Foodcourt::AddordersController < BaseFoodcourtController @order.new_booking = true @order.waiters = current_login_employee.name @order.employee_name = current_login_employee.name - @order.shop_code = @shop.shop_code @order.is_extra_time = is_extra_time @order.extra_time = extra_time diff --git a/app/controllers/foodcourt/customers_controller.rb b/app/controllers/foodcourt/customers_controller.rb index 316b9837..930d2a83 100644 --- a/app/controllers/foodcourt/customers_controller.rb +++ b/app/controllers/foodcourt/customers_controller.rb @@ -87,8 +87,9 @@ class Foodcourt::CustomersController < BaseFoodcourtController @count_customer = Customer.count_customer # @taxes = TaxProfile.where(:group_type => 'cashier') - @taxes = TaxProfile.unscoped.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") # if flash["errors"] # @crm_customer.valid? # end diff --git a/app/controllers/foodcourt/orders_controller.rb b/app/controllers/foodcourt/orders_controller.rb index f7f30fdf..8d75e0ae 100755 --- a/app/controllers/foodcourt/orders_controller.rb +++ b/app/controllers/foodcourt/orders_controller.rb @@ -76,7 +76,7 @@ class Foodcourt::OrdersController < BaseFoodcourtController def completed customer =Customer.find_by_customer_id(params[:customer_id]) phone_number =customer.contact_no - if Order.send_message(phone_number,params[:order_id],@shop.name) + if Order.send_message(phone_number,params[:order_id],current_shop.name) booking =Booking.find(params[:booking_id]) booking.booking_status ='completed' booking.save! diff --git a/app/controllers/foodcourt/payments_controller.rb b/app/controllers/foodcourt/payments_controller.rb index 14a6dd02..6e7e2859 100755 --- a/app/controllers/foodcourt/payments_controller.rb +++ b/app/controllers/foodcourt/payments_controller.rb @@ -20,7 +20,7 @@ class Foodcourt::PaymentsController < BaseFoodcourtController #shop_detail = Shop.first # rounding adjustment if !path.include? ("credit_payment") - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total - saleObj.grand_total saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0 @@ -154,7 +154,7 @@ class Foodcourt::PaymentsController < BaseFoodcourtController other_amount = SaleItem.calculate_other_charges(sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,account_no, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, 'Foodcourt',current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,account_no, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, 'Foodcourt',current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) #end end @@ -223,7 +223,7 @@ class Foodcourt::PaymentsController < BaseFoodcourtController @pdf_view = @lookup_pdf.value end - amount = SalePayment.get_kbz_pay_amount(sale_id, current_user,@shop) + amount = SalePayment.get_kbz_pay_amount(sale_id, current_user) @kbz_pay_amount += amount.to_f #for changable on/off @@ -270,7 +270,7 @@ class Foodcourt::PaymentsController < BaseFoodcourtController #end rounding adjustment # rounding adjustment - if @shop.is_rounding_adj + if current_shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even @@ -472,7 +472,7 @@ class Foodcourt::PaymentsController < BaseFoodcourtController printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) result = { :status => true, @@ -571,7 +571,7 @@ class Foodcourt::PaymentsController < BaseFoodcourtController printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "FOC",nil,nil,other_amount,nil,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "FOC",nil,nil,other_amount,nil,nil,nil,nil) result = { :status => true, :filepath => filename, @@ -606,7 +606,7 @@ class Foodcourt::PaymentsController < BaseFoodcourtController saleObj = Sale.find(params[:sale_id]) - if @shop.is_rounding_adj + if current_shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even diff --git a/app/controllers/foodcourt/paypar_payments_controller.rb b/app/controllers/foodcourt/paypar_payments_controller.rb index 64fe7a6d..9317bf3d 100755 --- a/app/controllers/foodcourt/paypar_payments_controller.rb +++ b/app/controllers/foodcourt/paypar_payments_controller.rb @@ -9,7 +9,7 @@ class Foodcourt::PayparPaymentsController < BaseFoodcourtController saleObj = Sale.find(sale_id) # rounding adjustment - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total-saleObj.grand_total saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) diff --git a/app/controllers/foodcourt/sale_edit_controller.rb b/app/controllers/foodcourt/sale_edit_controller.rb index 9bebbe0e..de59ec10 100755 --- a/app/controllers/foodcourt/sale_edit_controller.rb +++ b/app/controllers/foodcourt/sale_edit_controller.rb @@ -118,7 +118,7 @@ class Foodcourt::SaleEditController < BaseFoodcourtController sale.compute_by_sale_items(sale.total_discount, nil, order_source) - ProductCommission.edit_product_commission(saleitemObj,sale.shop_code) + ProductCommission.edit_product_commission(saleitemObj) end # make cancel void item diff --git a/app/controllers/foodcourt/shifts_controller.rb b/app/controllers/foodcourt/shifts_controller.rb index d097282b..6866217b 100755 --- a/app/controllers/foodcourt/shifts_controller.rb +++ b/app/controllers/foodcourt/shifts_controller.rb @@ -88,11 +88,11 @@ class Foodcourt::ShiftsController < BaseFoodcourtController end end end - shop_details = shop_detail + shop_details = current_shop #get tax shift_obj = ShiftSale.where('id =?',@shift.id) sale_items = '' - @lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code) + @lookup = Lookup.shift_sale_items_lookup_value if @lookup.to_i == 1 @sale_items = Sale.get_shift_sale_items(@shift.id) other_charges = Sale.get_other_charges() diff --git a/app/controllers/foodcourt/surveys_controller.rb b/app/controllers/foodcourt/surveys_controller.rb index e664aca2..8d94a0e1 100644 --- a/app/controllers/foodcourt/surveys_controller.rb +++ b/app/controllers/foodcourt/surveys_controller.rb @@ -76,7 +76,6 @@ class Foodcourt::SurveysController < BaseFoodcourtController @survey = Survey.new(survey_params) @survey.shift_id = shift_by_terminal.id @survey.foreigner = params["survey"]["foreigner"].to_json - @survey.shop_code = @shop.shop_code # respond_to do |format| if @survey.save redirect_to @url diff --git a/app/controllers/foodcourt/void_controller.rb b/app/controllers/foodcourt/void_controller.rb index d86eb652..80154300 100755 --- a/app/controllers/foodcourt/void_controller.rb +++ b/app/controllers/foodcourt/void_controller.rb @@ -132,7 +132,7 @@ class Foodcourt::VoidController < BaseFoodcourtController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/foodcourt/waste_spoile_controller.rb b/app/controllers/foodcourt/waste_spoile_controller.rb index aea75d18..a4c76296 100755 --- a/app/controllers/foodcourt/waste_spoile_controller.rb +++ b/app/controllers/foodcourt/waste_spoile_controller.rb @@ -118,7 +118,7 @@ class Foodcourt::WasteSpoileController < BaseFoodcourtController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, remark,current_balance,nil,other_amount,nil,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, remark,current_balance,nil,other_amount,nil,nil,nil,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 9e9b4866..607f7e66 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -100,7 +100,7 @@ class HomeController < ApplicationController @sales = Sale.receipt_date_between(@from, @to).completed if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user.id) + if shift = ShiftSale.current_open_shift(current_user) @orders = @orders.where(shift_sale_id: shift.id) @sales = @sales.where(shift_sale_id: shift.id) end @@ -124,7 +124,7 @@ class HomeController < ApplicationController end end - @inventories = StockJournal.inventory_balances(@from,@to, current_shop).sum(:balance) + @inventories = StockJournal.inventory_balances(@from,@to).sum(:balance) @total_trans = Sale.total_trans(current_user,@from,@to) @total_card = Sale.total_card_sale(current_user,@from,@to) @@ -199,13 +199,22 @@ class HomeController < ApplicationController redirect_to dashboard_path end elsif employee.role == "cashier" + food_court = Lookup.find_by_lookup_type_and_value("food_court", "1") #check if cashier has existing open cashier shift = ShiftSale.current_open_shift(employee) - if !shift.nil? - redirect_to origami_dashboard_path - # redirect_to origami_root_path + if food_court + if !shift.nil? + redirect_to foodcourt_food_court_path + else + redirect_to new_foodcourt_shift_path + end else - redirect_to new_origami_shift_path + if !shift.nil? + redirect_to origami_dashboard_path + # redirect_to origami_root_path + else + redirect_to new_origami_shift_path + end end elsif employee.role == "manager" redirect_to dashboard_path diff --git a/app/controllers/inventory/inventory_definitions_controller.rb b/app/controllers/inventory/inventory_definitions_controller.rb index b3496c49..96243b8a 100755 --- a/app/controllers/inventory/inventory_definitions_controller.rb +++ b/app/controllers/inventory/inventory_definitions_controller.rb @@ -39,7 +39,6 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController @inventory_definition.min_order_level = params[:min_order_level] @inventory_definition.max_stock_level = inventory.max_stock_level.to_i + params[:max_stock_level].to_i end - @inventory_definition.shop_code = @shop.shop_code @inventory_definition.created_by = current_user.id if @inventory_definition.save result = {:status=> true, :message => "Inventory definition was created successfully",:data=> @inventory_definition} @@ -91,9 +90,8 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController format.json { head :no_content } end - # inventory = InventoryDefinition.find_by_id_and_shop_code(params[:id],@shop.shop_code) - StockJournal.delete_stock_journal(inventory.item_code,@shop) - StockCheckItem.delete_stock_check_item(inventory.item_code,@shop) + StockJournal.delete_stock_journal(inventory.item_code) + StockCheckItem.delete_stock_check_item(inventory.item_code) if !inventory.nil? inventory.destroy flash[:message] = 'Inventory was successfully destroyed.' diff --git a/app/controllers/inventory/stock_checks_controller.rb b/app/controllers/inventory/stock_checks_controller.rb index b71b7bec..6c501def 100755 --- a/app/controllers/inventory/stock_checks_controller.rb +++ b/app/controllers/inventory/stock_checks_controller.rb @@ -19,7 +19,7 @@ class Inventory::StockChecksController < BaseInventoryController item_list = JSON.parse(params[:stock_item]) reason = params[:reason] check = StockCheck.new - @check = check.create(current_user, reason, item_list,@shop) + @check = check.create(current_user, reason, item_list) end def show @@ -33,7 +33,7 @@ class Inventory::StockChecksController < BaseInventoryController check = params[:data] stockCheck = StockCheck.find_by_id(check) stockCheck.stock_check_items.each do |item| - StockJournal.from_stock_check(item,@shop) + StockJournal.from_stock_check(item) end end @@ -49,7 +49,7 @@ class Inventory::StockChecksController < BaseInventoryController print_settings = PrintSetting.find_by_unique_code(unique_code) if !print_settings.nil? printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker.name, @shop) + printer.print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker.name, current_shop) end end diff --git a/app/controllers/inventory/stock_journals_controller.rb b/app/controllers/inventory/stock_journals_controller.rb index cdba207e..49439456 100755 --- a/app/controllers/inventory/stock_journals_controller.rb +++ b/app/controllers/inventory/stock_journals_controller.rb @@ -25,7 +25,6 @@ class StockJournalsController < ApplicationController # POST /stock_journals.json def create @stock_journal = StockJournal.new(stock_journal_params) - @stock_journal.shop_code = @shop.shop_code respond_to do |format| if @stock_journal.save format.html { redirect_to @stock_journal, notice: 'Stock journal was successfully created.' } diff --git a/app/controllers/origami/alipay_controller.rb b/app/controllers/origami/alipay_controller.rb index 49a121ca..d6dae6df 100644 --- a/app/controllers/origami/alipay_controller.rb +++ b/app/controllers/origami/alipay_controller.rb @@ -23,7 +23,7 @@ class Origami::AlipayController < BaseOrigamiController others = 0 - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/credit_payments_controller.rb b/app/controllers/origami/credit_payments_controller.rb index 16981a5a..6c2e9e51 100755 --- a/app/controllers/origami/credit_payments_controller.rb +++ b/app/controllers/origami/credit_payments_controller.rb @@ -8,7 +8,7 @@ class Origami::CreditPaymentsController < BaseOrigamiController total = sale_data.grand_total @creditcount = 0 others = 0 - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 4f25cb7d..d3a74713 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -87,8 +87,9 @@ class Origami::CustomersController < BaseOrigamiController @count_customer = Customer.count_customer # @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") # if flash["errors"] # @crm_customer.valid? # end diff --git a/app/controllers/origami/dinga_controller.rb b/app/controllers/origami/dinga_controller.rb index 3098377a..524aa353 100644 --- a/app/controllers/origami/dinga_controller.rb +++ b/app/controllers/origami/dinga_controller.rb @@ -6,7 +6,7 @@ class Origami::DingaController < BaseOrigamiController @membership_rebate_balance=0 @sale_data = Sale.find_by_sale_id(@sale_id) @receipt_no = @sale_data.receipt_no - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(@sale_data.grand_total) else new_total = @sale_data.grand_total diff --git a/app/controllers/origami/gift_voucher_controller.rb b/app/controllers/origami/gift_voucher_controller.rb index dac27995..bc2ecdf0 100644 --- a/app/controllers/origami/gift_voucher_controller.rb +++ b/app/controllers/origami/gift_voucher_controller.rb @@ -17,7 +17,7 @@ class Origami::GiftVoucherController < BaseOrigamiController others = 0 - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 6ea59d86..f7416704 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -11,7 +11,7 @@ class Origami::HomeController < BaseOrigamiController @customers = Customer.pluck("customer_id, name") - @occupied_table = DiningFacility.where("status='occupied'").shop.count + @occupied_table = DiningFacility.where("status='occupied'").count @shift = ShiftSale.current_open_shift(current_user) end @@ -33,7 +33,7 @@ class Origami::HomeController < BaseOrigamiController @status_sale = "" @sale_array = Array.new - @shop = shop_detail + @shop = current_shop @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all @dining_booking = @dining.current_bookings diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb index 74bcdcd3..63a0a6eb 100644 --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -24,7 +24,7 @@ class Origami::JcbController < BaseOrigamiController others = 0 - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/junction_pay_controller.rb b/app/controllers/origami/junction_pay_controller.rb index f6a7fc78..d0819437 100644 --- a/app/controllers/origami/junction_pay_controller.rb +++ b/app/controllers/origami/junction_pay_controller.rb @@ -11,7 +11,7 @@ class Origami::JunctionPayController < BaseOrigamiController @cashier_id = current_user.emp_id @payment_method_setting_nav = PaymentMethodSetting.all - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb index 17fe4598..f92602f6 100644 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -23,7 +23,7 @@ class Origami::MasterController < BaseOrigamiController others = 0 - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb index 89d6fe7f..c9204f67 100644 --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -22,7 +22,7 @@ class Origami::MpuController < BaseOrigamiController others = 0 - if @shop.is_rounding_adj && (!path.include? ("credit_payment")) + if current_shop.is_rounding_adj && (!path.include? ("credit_payment")) new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/paymal_controller.rb b/app/controllers/origami/paymal_controller.rb index 419e914f..918e3945 100644 --- a/app/controllers/origami/paymal_controller.rb +++ b/app/controllers/origami/paymal_controller.rb @@ -6,7 +6,7 @@ class Origami::PaymalController < BaseOrigamiController @membership_rebate_balance=0 sale_data = Sale.find_by_sale_id(@sale_id) @receipt_no = sale_data.receipt_no - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 07c716e2..a5b38db2 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -65,7 +65,7 @@ class Origami::PaymentsController < BaseOrigamiController end end - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal, sale_items, sale_data, customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, @shop, "Frt", current_balance, nil, other_amount, nil, nil, nil) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, status, qr, cashier_terminal, sale_items, sale_data, customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, nil, current_shop, "Frt", current_balance, nil, other_amount, nil, nil, nil) result = { :filepath => filename, @@ -192,7 +192,7 @@ class Origami::PaymentsController < BaseOrigamiController end #card_balance amount for Paymal payment - card_balance_amount = SaleAudit.getCardBalanceAmount(sale_id) + card_balance_amount,transaction_ref = SaleAudit.getCardBalanceAmount(sale_id) # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) @@ -202,7 +202,7 @@ class Origami::PaymentsController < BaseOrigamiController other_amount = SaleItem.calculate_other_charges(sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Paid",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal, sale_items, saleObj, customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, current_shop, "Paid", current_balance, card_data, other_amount, latest_order_no, card_balance_amount, nil) #end end @@ -275,7 +275,7 @@ class Origami::PaymentsController < BaseOrigamiController @pdf_view = @lookup_pdf.value end - amount = SalePayment.get_kbz_pay_amount(sale_id, current_user,@shop) + amount = SalePayment.get_kbz_pay_amount(sale_id, current_user) @kbz_pay_amount += amount.to_f #for changable on/off @@ -322,7 +322,7 @@ class Origami::PaymentsController < BaseOrigamiController #end rounding adjustment # rounding adjustment - if @shop.is_rounding_adj + if current_shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even @@ -524,7 +524,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount, current_shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) result = { :status => true, @@ -622,7 +622,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "FOC",nil,nil,other_amount,nil,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "FOC",nil,nil,other_amount,nil,nil,nil,nil) result = { :status => true, :filepath => filename, @@ -657,7 +657,7 @@ class Origami::PaymentsController < BaseOrigamiController saleObj = Sale.find(params[:sale_id]) - if @shop.is_rounding_adj + if current_shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus b = saleObj.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even diff --git a/app/controllers/origami/paypar_payments_controller.rb b/app/controllers/origami/paypar_payments_controller.rb index 59ddb912..8acb5ca2 100755 --- a/app/controllers/origami/paypar_payments_controller.rb +++ b/app/controllers/origami/paypar_payments_controller.rb @@ -8,7 +8,7 @@ class Origami::PayparPaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) # rounding adjustment - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(saleObj.grand_total) rounding_adj = new_total-saleObj.grand_total saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb index 6b7802cf..2604e215 100755 --- a/app/controllers/origami/redeem_payments_controller.rb +++ b/app/controllers/origami/redeem_payments_controller.rb @@ -5,7 +5,7 @@ class Origami::RedeemPaymentsController < BaseOrigamiController @cashier_type = params[:type] @membership_rebate_balance=0 sale_data = Sale.find_by_sale_id(@sale_id) - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 57c1dc93..f575b0e5 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -163,7 +163,7 @@ class Origami::SaleEditController < BaseOrigamiController # end # end - ProductCommission.edit_product_commission(saleitemObj,sale.shop_code) + ProductCommission.edit_product_commission(saleitemObj) end # make cancel void item diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 91033f94..bbe2cf57 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -91,7 +91,7 @@ class Origami::ShiftsController < BaseOrigamiController #get tax shift_obj = ShiftSale.where('id =?',@shift.id) sale_items = '' - @lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code) + @lookup = Lookup.shift_sale_items_lookup_value if @lookup.to_i == 1 @sale_items = Sale.get_shift_sale_items(@shift.id) other_charges = Sale.get_other_charges() @@ -126,7 +126,7 @@ class Origami::ShiftsController < BaseOrigamiController if find_close_cashier_print[0][1].to_i > 0 - printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, @shop,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) + printer.print_close_cashier(print_settings,cashier_terminal, @shift, @sale_items, @total_other_charges_info, current_shop,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) end end end diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index 126f7d11..45af74fd 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -76,7 +76,6 @@ class Origami::SurveysController < BaseOrigamiController @survey = Survey.new(survey_params) @survey.shift_id = shift_by_terminal.id @survey.foreigner = params["survey"]["foreigner"].to_json - @survey.shop_code = @shop.shop_code # respond_to do |format| if @survey.save redirect_to @url diff --git a/app/controllers/origami/table_invoices_controller.rb b/app/controllers/origami/table_invoices_controller.rb index 0431ff87..7c9514c8 100755 --- a/app/controllers/origami/table_invoices_controller.rb +++ b/app/controllers/origami/table_invoices_controller.rb @@ -9,7 +9,7 @@ class Origami::TableInvoicesController < BaseOrigamiController else sale = Sale.find(booking.sale_id) # rounding adjustment - if @shop.is_rounding_adj + if current_shop.is_rounding_adj a = sale.grand_total % 25 # Modulus b = sale.grand_total / 25 # Division #not calculate rounding if modulus is 0 and division is even diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index 2f708af3..43a1f5bc 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -21,7 +21,7 @@ class Origami::UnionpayController < BaseOrigamiController total = sale_data.grand_total others = 0 - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb index a2e43d5a..e77363d9 100644 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -21,7 +21,7 @@ class Origami::VisaController < BaseOrigamiController total = sale_data.grand_total others = 0 - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index b4a3c1dc..55ef52f5 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -143,7 +143,7 @@ class Origami::VoidController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "VOID",current_balance,nil,other_amount,nil,nil,nil,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/origami/voucher_controller.rb b/app/controllers/origami/voucher_controller.rb index 196d93c4..d1aeb26b 100755 --- a/app/controllers/origami/voucher_controller.rb +++ b/app/controllers/origami/voucher_controller.rb @@ -7,7 +7,7 @@ class Origami::VoucherController < BaseOrigamiController total = sale_data.grand_total @vouchercount = 0 others = 0 - if @shop.is_rounding_adj + if current_shop.is_rounding_adj new_total = Sale.get_rounding_adjustment(sale_data.grand_total) else new_total = sale_data.grand_total diff --git a/app/controllers/origami/waste_spoile_controller.rb b/app/controllers/origami/waste_spoile_controller.rb index 4ab7b671..46b6f843 100755 --- a/app/controllers/origami/waste_spoile_controller.rb +++ b/app/controllers/origami/waste_spoile_controller.rb @@ -117,7 +117,7 @@ class Origami::WasteSpoileController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) other_amount = SaleItem.calculate_other_charges(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,@shop, remark,current_balance,nil,other_amount,nil,nil,nil,nil) + filename, sale_receipt_no, printer_name = printer.print_receipt_bill(print_settings, false, nil,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, remark,current_balance,nil,other_amount,nil,nil,nil,nil) result = { :filepath => filename, :printer_model => print_settings.brand_name, diff --git a/app/controllers/print_settings_controller.rb b/app/controllers/print_settings_controller.rb index 0d8c5280..8931bc07 100755 --- a/app/controllers/print_settings_controller.rb +++ b/app/controllers/print_settings_controller.rb @@ -11,7 +11,7 @@ class PrintSettingsController < ApplicationController # GET /print_settings/1 # GET /print_settings/1.json def show - @lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code) + @lookup = Lookup.shift_sale_items_lookup_value end # GET /print_settings/new @@ -22,7 +22,7 @@ class PrintSettingsController < ApplicationController # GET /print_settings/1/edit def edit - @lookup = Lookup.shift_sale_items_lookup_value(@shop.shop_code) + @lookup = Lookup.shift_sale_items_lookup_value @server_mode = ENV["SERVER_MODE"] end @@ -30,7 +30,6 @@ class PrintSettingsController < ApplicationController # POST /print_settings.json def create @print_setting = PrintSetting.new(print_setting_params) - @print_setting.shop_code = @shop.shop_code respond_to do |format| if @print_setting.save format.html { redirect_to @print_setting, notice: 'Print setting was successfully created.' } @@ -48,7 +47,7 @@ class PrintSettingsController < ApplicationController respond_to do |format| if @print_setting.update(print_setting_params) if @print_setting.unique_code == 'CloseCashierPdf' - Lookup.save_shift_sale_items_settings(params[:shift_sale_items],@shop.shop_code) + Lookup.save_shift_sale_items_settings(params[:shift_sale_items]) end format.html { redirect_to @print_setting, notice: 'Print setting was successfully updated.' } diff --git a/app/controllers/reports/credit_payment_controller.rb b/app/controllers/reports/credit_payment_controller.rb index 76465bd8..7b9fd55b 100755 --- a/app/controllers/reports/credit_payment_controller.rb +++ b/app/controllers/reports/credit_payment_controller.rb @@ -20,7 +20,7 @@ authorize_resource :class => false @filter = params[:filter_check] @order_source = params[:order_source] - @sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to,@filter,@order_source,@shop.shop_code) + @sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to,@filter,@order_source) @from = from @to = to diff --git a/app/controllers/reports/hourly_saleitem_controller.bk.rb b/app/controllers/reports/hourly_saleitem_controller.bk.rb index ab4f81ea..d2df64a0 100644 --- a/app/controllers/reports/hourly_saleitem_controller.bk.rb +++ b/app/controllers/reports/hourly_saleitem_controller.bk.rb @@ -118,7 +118,7 @@ class Reports::HourlySaleitemController < BaseReportController shift_name = employee.nil? ? sh_name : "#{sh_name} (#{employee.name})" end - shop_details = shop_detail + shop_details = current_shop account_type = params[:account_type] @type = params[:period_type] period_name = get_period_name(params[:period]) diff --git a/app/controllers/reports/hourly_saleitem_controller.rb b/app/controllers/reports/hourly_saleitem_controller.rb index 4092ee40..29bc9836 100644 --- a/app/controllers/reports/hourly_saleitem_controller.rb +++ b/app/controllers/reports/hourly_saleitem_controller.rb @@ -119,7 +119,7 @@ class Reports::HourlySaleitemController < BaseReportController shift_name = employee.nil? ? sh_name : "#{sh_name} (#{employee.name})" end - shop_details = shop_detail + shop_details = current_shop account_type = params[:account_type] @type = params[:period_type] period_name = get_period_name(params[:period]) diff --git a/app/controllers/reports/induty_controller.rb b/app/controllers/reports/induty_controller.rb index 2c435f25..ce215b1f 100644 --- a/app/controllers/reports/induty_controller.rb +++ b/app/controllers/reports/induty_controller.rb @@ -19,7 +19,7 @@ class Reports::IndutyController < BaseReportController end @commissioner = params[:commissioner] - @induty_data = InDuty.get_induty_by_shift(@shift_sale_range,@shift,from,to,@commissioner).where("sales.shop_code='#{@shop.shop_code}'") + @induty_data = InDuty.get_induty_by_shift(@shift_sale_range,@shift,from,to,@commissioner) @from = from @to = to diff --git a/app/controllers/reports/order_reservation_controller.rb b/app/controllers/reports/order_reservation_controller.rb index 257623dc..db9a2bb1 100644 --- a/app/controllers/reports/order_reservation_controller.rb +++ b/app/controllers/reports/order_reservation_controller.rb @@ -27,7 +27,7 @@ class Reports::OrderReservationController < BaseReportController provider = params[:provider] payment_type = params[:payment_type] - @order_reservation_data = OrderReservation.get_order_reservation_by_shift(@shift_sale_range,@shift,from,to,provider,payment_type).where("sales.shop_code='#{@shop.shop_code}'") + @order_reservation_data = OrderReservation.get_order_reservation_by_shift(@shift_sale_range,@shift,from,to,provider,payment_type) @from = from @to = to # get printer info @@ -49,7 +49,7 @@ class Reports::OrderReservationController < BaseReportController def show from, to = get_date_range_from_params - @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| diff --git a/app/controllers/reports/payment_method_controller.rb b/app/controllers/reports/payment_method_controller.rb index 3a82f01d..c9983b9f 100644 --- a/app/controllers/reports/payment_method_controller.rb +++ b/app/controllers/reports/payment_method_controller.rb @@ -9,7 +9,7 @@ class Reports::PaymentMethodController < BaseReportController from, to = get_date_range_from_params - @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift = '' if params[:shift_name].to_i != 0 @@ -21,7 +21,7 @@ class Reports::PaymentMethodController < BaseReportController end end @payment_type = params[:payment_type] - @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift_sale_range,@shift,from,to,@payment_type,@shop.shop_code) + @sale_data,@pyament_method = Sale.get_payment_method_by_shift(@shift_sale_range,@shift,from,to,@payment_type) @from = from @to = to # get printer info @@ -43,7 +43,7 @@ class Reports::PaymentMethodController < BaseReportController def show from, to = get_date_range_from_params - @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb index e06c1007..007ab864 100755 --- a/app/controllers/reports/receipt_no_controller.rb +++ b/app/controllers/reports/receipt_no_controller.rb @@ -10,7 +10,7 @@ authorize_resource :class => false @shift = '' if params[:shift_name].to_i != 0 - @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale = ShiftSale.find(params[:shift_name]) if to.blank? @@ -26,12 +26,12 @@ authorize_resource :class => false @lookup = Lookup.find_by_lookup_type('reprint_receipt') if @lookup.nil? - @lookup = Lookup.create_reprint_receipt_lookup(@shop.shop_code) + @lookup = Lookup.create_reprint_receipt_lookup end payment_type = params[:payment_type] - @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to,payment_type).where("sales.shop_code='#{@shop.shop_code}'") - @sale_taxes = Sale.get_separate_tax(@shift_sale_range,@shift,from,to,payment_type).where("sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to,payment_type) + @sale_taxes = Sale.get_separate_tax(@shift_sale_range,@shift,from,to,payment_type) @tax_profiles = TaxProfile.group('name').order('order_by asc') #.limit(2) @from = from @@ -55,7 +55,7 @@ authorize_resource :class => false def show from, to = get_date_range_from_params - @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| @@ -215,7 +215,7 @@ authorize_resource :class => false printer = Printer::ReceiptPrinter.new(print_settings) - filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_detail, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) + filename, receipt_no, cashier_printer = printer.print_receipt_bill(print_settings, false, nil, cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,current_shop, "Re-print",current_balance,card_data,other_amount,latest_order_no,card_balance_amount,nil,transaction_ref) result = { :status => true, diff --git a/app/controllers/reports/receipt_no_detail_controller.rb b/app/controllers/reports/receipt_no_detail_controller.rb index 0fe2458d..9102d6d5 100755 --- a/app/controllers/reports/receipt_no_detail_controller.rb +++ b/app/controllers/reports/receipt_no_detail_controller.rb @@ -26,7 +26,7 @@ authorize_resource :class => false payment_type = params[:payment_type] - @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type).where("sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) @from = from @@ -50,7 +50,7 @@ authorize_resource :class => false def show from, to = get_date_range_from_params - @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index b5a55f72..fe8a832a 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -9,7 +9,7 @@ class Reports::SaleitemController < BaseReportController shift = '' if params[:shift_name].to_i != 0 - shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) shift_sale = ShiftSale.find(params[:shift_name]) if to.blank? @@ -25,9 +25,9 @@ class Reports::SaleitemController < BaseReportController account_type = params[:account_type] @type = params[:sale_type] - @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type,@shop.shop_code) + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) - @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil).where("sales.shop_code='#{@shop.shop_code}'") + @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @account_cate_count = Hash.new {|hash, key| hash[key] = 0} @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} @@ -60,7 +60,7 @@ class Reports::SaleitemController < BaseReportController def show from, to, report_type = get_date_range_from_params - @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| @@ -114,7 +114,7 @@ class Reports::SaleitemController < BaseReportController @type = params[:period_type] period_name = get_period_name(params[:period]) - @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type,@shop.shop_code) + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type,account_type) other_charges = Sale.get_other_charges() if shift.present? @total_other_charges = other_charges.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a) @@ -129,11 +129,11 @@ class Reports::SaleitemController < BaseReportController if print_settings.nil? if !print_settings_star.nil? printer = Printer::CashierStationPrinter.new(print_settings_star) - printer.print_sale_items_report(print_settings_star, @shop, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) + printer.print_sale_items_report(print_settings_star, current_shop, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) end else printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_sale_items_report(print_settings, @shop, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) + printer.print_sale_items_report(print_settings, current_shop, period_name, @type, account_type, from, to, shift_name, @sale_data, @total_other_charges) end respond_to do |format| diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb index 5d02e9a1..be23d412 100755 --- a/app/controllers/reports/shiftsale_controller.rb +++ b/app/controllers/reports/shiftsale_controller.rb @@ -8,7 +8,7 @@ class Reports::ShiftsaleController < BaseReportController if params[:shift_name].to_i != 0 @shift = ShiftSale.find(params[:shift_name]) end - @sale_data = Sale.get_by_shiftsales(from,to,@shift,@shop.shop_code) + @sale_data = Sale.get_by_shiftsales(from,to,@shift) @from = from @to = to if @shift.present? @@ -29,7 +29,7 @@ class Reports::ShiftsaleController < BaseReportController from, to = get_date_range_from_params - @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| @@ -75,9 +75,9 @@ class Reports::ShiftsaleController < BaseReportController end - shop_details = shop_detail + shop_details = current_shop cashier_terminal = @shift.cashier_terminal - @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'") + @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') @total_waste = Sale.get_total_waste(shift_id).sum(:grand_total) @total_spoile = Sale.get_total_spoile(shift_id).sum(:grand_total) #other payment details for mpu or visa like card @@ -97,7 +97,7 @@ class Reports::ShiftsaleController < BaseReportController printer = Printer::CashierStationPrinter.new(print_settings) # printer.print_close_cashier(print_settings,cashier_terminal,@shift, nil, shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) - printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, @shop,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) + printer.print_close_cashier(print_settings,cashier_terminal,@shift, @sale_items, @total_other_charges_info, current_shops,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) respond_to do |format| format.html { redirect_to '/en/reports/shiftsale/', notice: 'Printing Completed.'} diff --git a/app/controllers/reports/staff_meal_controller.rb b/app/controllers/reports/staff_meal_controller.rb index 9b3c0236..71d363ba 100644 --- a/app/controllers/reports/staff_meal_controller.rb +++ b/app/controllers/reports/staff_meal_controller.rb @@ -32,9 +32,9 @@ class Reports::StaffMealController < BaseReportController account_type = params[:account_type] - @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_staff_meal_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,account_type,customer_id,@shop.shop_code) + @sale_data, @other_charges,@product, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_staff_meal_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,account_type,customer_id) - @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil).where("sales.shop_code='#{@shop.shop_code}'") + @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) @account_cate_count = Hash.new {|hash, key| hash[key] = 0} @sale_data.each {|acc_cate| @account_cate_count[acc_cate.account_id] += 1} diff --git a/app/controllers/reports/stock_check_controller.rb b/app/controllers/reports/stock_check_controller.rb index b9e54e8b..79862d12 100755 --- a/app/controllers/reports/stock_check_controller.rb +++ b/app/controllers/reports/stock_check_controller.rb @@ -29,7 +29,7 @@ class Reports::StockCheckController < BaseReportController from, to = get_date_range_from_params - @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| diff --git a/app/controllers/reports/void_sale_controller.rb b/app/controllers/reports/void_sale_controller.rb index 55560bd2..0dc6032a 100755 --- a/app/controllers/reports/void_sale_controller.rb +++ b/app/controllers/reports/void_sale_controller.rb @@ -16,7 +16,7 @@ authorize_resource :class => false end end - @sale_data = Sale.get_void_sale(@shift,from,to,@shop.shop_code) + @sale_data = Sale.get_void_sale(@shift,from,to) @from = from @to = to @@ -39,7 +39,7 @@ authorize_resource :class => false def show from, to = get_date_range_from_params - @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED).where("shift_sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED) date_arr = Array.new @sale_data.each do |sale| diff --git a/app/controllers/reports/waste_and_spoilage_controller.rb b/app/controllers/reports/waste_and_spoilage_controller.rb index 4b15cc01..1e938d91 100755 --- a/app/controllers/reports/waste_and_spoilage_controller.rb +++ b/app/controllers/reports/waste_and_spoilage_controller.rb @@ -4,7 +4,7 @@ authorize_resource :class => false from, to = get_date_range_from_params @sale_type = params[:sale_type] - @sale_data = Sale.get_wastes_and_spoilages(from,to,@sale_type).where("sales.shop_code='#{@shop.shop_code}'") + @sale_data = Sale.get_wastes_and_spoilages(from,to,@sale_type) @from = from @to = to # get printer info diff --git a/app/controllers/settings/accounts_controller.rb b/app/controllers/settings/accounts_controller.rb index 0f5b0ba7..fe45d957 100755 --- a/app/controllers/settings/accounts_controller.rb +++ b/app/controllers/settings/accounts_controller.rb @@ -28,7 +28,6 @@ class Settings::AccountsController < ApplicationController def create @settings_account = Account.new(account_params) - @settings_account.shop_code = @shop.shop_code respond_to do |format| if @settings_account.save format.html { redirect_to settings_accounts_url, notice: 'Account was successfully created.' } diff --git a/app/controllers/settings/cashier_terminals_controller.rb b/app/controllers/settings/cashier_terminals_controller.rb index 2e1d63c1..eeea0f9f 100755 --- a/app/controllers/settings/cashier_terminals_controller.rb +++ b/app/controllers/settings/cashier_terminals_controller.rb @@ -29,7 +29,6 @@ class Settings::CashierTerminalsController < ApplicationController def create @settings_cashier_terminal = CashierTerminal.new(settings_cashier_terminal_params) - @settings_cashier_terminal.shop_code = @shop.shop_code respond_to do |format| if @settings_cashier_terminal.save format.html { redirect_to settings_cashier_terminals_path, notice: 'Cashier terminal was successfully created.' } diff --git a/app/controllers/settings/commissioners_controller.rb b/app/controllers/settings/commissioners_controller.rb index 24cc484b..752b0397 100755 --- a/app/controllers/settings/commissioners_controller.rb +++ b/app/controllers/settings/commissioners_controller.rb @@ -31,7 +31,6 @@ class Settings::CommissionersController < ApplicationController @commissioner = Commissioner.new(commissioner_params) @commissioner.created_by = current_user.id - @commissioner.shop_code = @shop.shop_code unless @commissioner.joined_date.nil? @commissioner.joined_date = @commissioner.joined_date.utc.getlocal.strftime('%Y-%b-%d') end diff --git a/app/controllers/settings/commissions_controller.rb b/app/controllers/settings/commissions_controller.rb index 60778dab..20cc432c 100755 --- a/app/controllers/settings/commissions_controller.rb +++ b/app/controllers/settings/commissions_controller.rb @@ -32,7 +32,6 @@ class Settings::CommissionsController < ApplicationController @commission = Commission.new(commission_params) @commission.product_type = 'menu_item' @commission.product_code = "[]" - @commission.shop_code = @shop.shop_code respond_to do |format| if @commission.save diff --git a/app/controllers/settings/employees_controller.rb b/app/controllers/settings/employees_controller.rb index 74c8b410..bcbec6ff 100755 --- a/app/controllers/settings/employees_controller.rb +++ b/app/controllers/settings/employees_controller.rb @@ -1,6 +1,6 @@ class Settings::EmployeesController < ApplicationController load_and_authorize_resource - before_action :set_employee, only: [:show, :edit, :update, :destroy] + before_action :set_employee, only: [:show, :edit, :update, :destroy, :change_auth_token] # GET /employees @@ -31,7 +31,6 @@ class Settings::EmployeesController < ApplicationController # POST /employees.json def create @employee = Employee.new(employee_params) - @employee.shop_code =@shop.shop_code respond_to do |format| if @employee.save format.html { redirect_to settings_employees_path, notice: 'Employee was successfully created.' } @@ -39,6 +38,13 @@ class Settings::EmployeesController < ApplicationController format.html { render :new } end end + end + + def change_app_token + @employee.app_token = @employee.generate_app_token #SecureRandom.hex(10) + @employee.save + flash[:notice] = 'Auth Token was successfully updated.' + redirect_to settings_employee_url(@employee) end # PATCH/PUT /employees/1 @@ -72,6 +78,6 @@ class Settings::EmployeesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def employee_params - params.require(:employee).permit(:name, :role, :is_active, :emp_id, :password,:order_queue_station_id, :image_path) + params.require(:employee).permit(:name, :role, :is_active, :emp_id, :password,:order_queue_station_id, :image_path, :app_id, :app_token) end end diff --git a/app/controllers/settings/lookups_controller.rb b/app/controllers/settings/lookups_controller.rb index 87c81842..6f7a2bb0 100755 --- a/app/controllers/settings/lookups_controller.rb +++ b/app/controllers/settings/lookups_controller.rb @@ -25,7 +25,6 @@ class Settings::LookupsController < ApplicationController # POST /settings/lookups.json def create @settings_lookup = Lookup.new(settings_lookup_params) - @settings_lookup.shop_code = @shop.shop_code respond_to do |format| if @settings_lookup.save format.html { redirect_to settings_lookups_path, notice: 'Lookup was successfully created.' } diff --git a/app/controllers/settings/membership_actions_controller.rb b/app/controllers/settings/membership_actions_controller.rb index f6eb77bf..cca64594 100755 --- a/app/controllers/settings/membership_actions_controller.rb +++ b/app/controllers/settings/membership_actions_controller.rb @@ -27,7 +27,6 @@ class Settings::MembershipActionsController < ApplicationController def create @settings_membership_action = MembershipAction.new(settings_membership_action_params) - @settings_membership_action.shop_code = @shop.shop_code respond_to do |format| if @settings_membership_action.save format.html { redirect_to settings_membership_actions_path, notice: 'Membership action was successfully created.' } diff --git a/app/controllers/settings/membership_settings_controller.rb b/app/controllers/settings/membership_settings_controller.rb index 2e128ce0..3cf97628 100755 --- a/app/controllers/settings/membership_settings_controller.rb +++ b/app/controllers/settings/membership_settings_controller.rb @@ -27,7 +27,6 @@ class Settings::MembershipSettingsController < ApplicationController def create @settings_membership_setting = MembershipSetting.new(settings_membership_setting_params) - @settings_membership_setting.shop_code = @shop.shop_code respond_to do |format| if @settings_membership_setting.save format.html { redirect_to settings_membership_settings_path, notice: 'Membership setting was successfully created.' } diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index f448b959..5961a8f4 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -34,7 +34,6 @@ class Settings::MenusController < ApplicationController @settings_menu = Menu.new(settings_menu_params) @settings_menu.created_by = current_login_employee.name - @settings_menu.shop_code = @shop.shop_code respond_to do |format| if @settings_menu.save format.html { redirect_to settings_menus_path, notice: 'Menu was successfully created.' } @@ -158,7 +157,7 @@ class Settings::MenusController < ApplicationController def import if params[:file] - status = Menu.import(params[:file], current_user.name,@shop) + status = Menu.import(params[:file], current_user.name) redirect_to settings_menus_path, notice: status end end diff --git a/app/controllers/settings/order_queue_stations_controller.rb b/app/controllers/settings/order_queue_stations_controller.rb index e3a30d1f..762168e2 100755 --- a/app/controllers/settings/order_queue_stations_controller.rb +++ b/app/controllers/settings/order_queue_stations_controller.rb @@ -33,7 +33,6 @@ class Settings::OrderQueueStationsController < ApplicationController @settings_order_queue_station = OrderQueueStation.new(settings_order_queue_station_params) @settings_order_queue_station.created_by = current_login_employee.name @settings_order_queue_station.processing_items = "[]" - @settings_order_queue_station.shop_code = @shop.shop_code respond_to do |format| if @settings_order_queue_station.save format.html { redirect_to settings_order_queue_stations_path, notice: 'Order queue station was successfully created.' } diff --git a/app/controllers/settings/payment_method_settings_controller.rb b/app/controllers/settings/payment_method_settings_controller.rb index e85e7a99..8850c2c6 100755 --- a/app/controllers/settings/payment_method_settings_controller.rb +++ b/app/controllers/settings/payment_method_settings_controller.rb @@ -26,7 +26,6 @@ class Settings::PaymentMethodSettingsController < ApplicationController # POST /settings/payment_method_settings.json def create @settings_payment_method_setting = PaymentMethodSetting.new(settings_payment_method_setting_params) - @settings_payment_method_setting.shop_code = @shop.shop_code respond_to do |format| if @settings_payment_method_setting.save format.html { redirect_to settings_payment_method_settings_path, notice: 'Payment method setting was successfully created.' } diff --git a/app/controllers/settings/products_controller.rb b/app/controllers/settings/products_controller.rb index 4562d132..a8f64c25 100755 --- a/app/controllers/settings/products_controller.rb +++ b/app/controllers/settings/products_controller.rb @@ -29,7 +29,6 @@ load_and_authorize_resource except: [:create] @settings_product = Product.new(settings_product_params) @settings_product.created_by = current_user.name - @settings_product.shop_code = @shop.shop_code respond_to do |format| if @settings_product.save format.html { redirect_to settings_products_path, notice: 'Product was successfully created.' } diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index 442a2063..42ede2d4 100755 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -31,7 +31,6 @@ class Settings::PromotionsController < ApplicationController @promotion = Promotion.new(promotion_params) @promotion.created_by = current_login_employee.id - @promotion.shop_code = @shop.shop_code if !@promotion.promo_start_hour.nil? @promotion.promo_start_hour = @promotion.promo_start_hour.to_datetime.advance(hours: +6, minutes: +30) end diff --git a/app/controllers/settings/rooms_controller.rb b/app/controllers/settings/rooms_controller.rb index 6617720c..a9410248 100755 --- a/app/controllers/settings/rooms_controller.rb +++ b/app/controllers/settings/rooms_controller.rb @@ -30,7 +30,6 @@ class Settings::RoomsController < ApplicationController @settings_room.type = DiningFacility::ROOM_TYPE @settings_room.zone_id = params[:zone_id] @settings_room.created_by = current_login_employee.name - @settings_room.shop_code = @shop.shop_code respond_to do |format| if @settings_room.save format.html { redirect_to settings_zone_path(@zone), notice: 'Room was successfully created.' } diff --git a/app/controllers/settings/shops_controller.rb b/app/controllers/settings/shops_controller.rb index c15cf757..82fd7e06 100644 --- a/app/controllers/settings/shops_controller.rb +++ b/app/controllers/settings/shops_controller.rb @@ -32,7 +32,7 @@ class Settings::ShopsController < ApplicationController if @settings_shop.save if params[:display_images].present? params[:display_images]['image'].each do |a| - @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => a) + @display_image = @settings_shop.display_images.create!(:shop_id => current_shop.id, :image => a) end end format.html { redirect_to settings_shops_url, notice: 'Shop was successfully created.' } @@ -60,16 +60,16 @@ class Settings::ShopsController < ApplicationController File.delete(delete_path) end end - save_path = Rails.root.join("public/#{@shop.shop_code}_#{a.original_filename}") + save_path = Rails.root.join("public/#{current_shop.shop_code}_#{a.original_filename}") File.open(save_path, 'wb') do |f| f.write a.read end - audio_name = "#{@shop.shop_code}_#{a.original_filename}" + audio_name = "#{current_shop.shop_code}_#{a.original_filename}" @settings_shop.display_images.where(:name => "order_audio").destroy_all - @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :name => "order_audio", :image => audio_name) + @display_image = @settings_shop.display_images.create!(:shop_id => current_shop.id, :name => "order_audio", :image => audio_name) else @aa = Base64.encode64(a.read) - @display_image = @settings_shop.display_images.create!(:shop_id => @shop.id, :image => "data:image/jpeg;base64,"+@aa) + @display_image = @settings_shop.display_images.create!(:shop_id => current_shop.id, :image => "data:image/jpeg;base64,"+@aa) end end end diff --git a/app/controllers/settings/tables_controller.rb b/app/controllers/settings/tables_controller.rb index ed4afe37..b261a445 100755 --- a/app/controllers/settings/tables_controller.rb +++ b/app/controllers/settings/tables_controller.rb @@ -29,7 +29,6 @@ class Settings::TablesController < ApplicationController @settings_table = Table.new(settings_table_params) @settings_table.type = DiningFacility::TABLE_TYPE @settings_table.zone_id = params[:zone_id] - @settings_table.shop_code = @shop.shop_code @settings_table.created_by = current_login_employee.name respond_to do |format| if @settings_table.save diff --git a/app/controllers/settings/tax_profiles_controller.rb b/app/controllers/settings/tax_profiles_controller.rb index 51a8880f..ddf4781a 100755 --- a/app/controllers/settings/tax_profiles_controller.rb +++ b/app/controllers/settings/tax_profiles_controller.rb @@ -48,7 +48,6 @@ class Settings::TaxProfilesController < ApplicationController @settings_tax_profile = TaxProfile.new(settings_tax_profile_params) @settings_tax_profile.created_by = current_login_employee.name - @settings_tax_profile.shop_code = @shop.shop_code respond_to do |format| if @settings_tax_profile.save format.html { redirect_to settings_tax_profiles_path, notice: 'Tax profile was successfully created.' } diff --git a/app/controllers/settings/zones_controller.rb b/app/controllers/settings/zones_controller.rb index 1c1524ae..27193c2b 100755 --- a/app/controllers/settings/zones_controller.rb +++ b/app/controllers/settings/zones_controller.rb @@ -30,7 +30,6 @@ class Settings::ZonesController < ApplicationController def create @settings_zone = Zone.new(settings_zone_params) - @settings_zone.shop_code =@shop.shop_code @settings_zone.created_by = current_login_employee.name respond_to do |format| if @settings_zone.save diff --git a/app/controllers/transactions/credit_notes_controller.rb b/app/controllers/transactions/credit_notes_controller.rb index 9622e5e4..c20c8364 100755 --- a/app/controllers/transactions/credit_notes_controller.rb +++ b/app/controllers/transactions/credit_notes_controller.rb @@ -23,10 +23,10 @@ class Transactions::CreditNotesController < ApplicationController .joins("JOIN sale_payments sp on sp.sale_id = sales.sale_id") .where("(CASE WHEN (sales.grand_total + sales.amount_changed)=(select SUM(sale_payments.payment_amount) FROM sale_payments WHERE sale_payments.sale_id=sales.sale_id AND sale_payments.payment_method!='creditnote') - THEN NULL ELSE payment_method='creditnote' END)").shop + THEN NULL ELSE payment_method='creditnote' END)") @credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20) else - sale = Sale.search_credit_sales(customer,filter,from,to,order_source).shop + sale = Sale.search_credit_sales(customer,filter,from,to,order_source) if !sale.nil? @credit_notes = sale @credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20) diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb index b4072855..98b420ff 100755 --- a/app/controllers/transactions/sales_controller.rb +++ b/app/controllers/transactions/sales_controller.rb @@ -18,13 +18,13 @@ class Transactions::SalesController < ApplicationController if receipt_no.nil? && from.nil? && to.nil? if @shift.blank? - @sales = Sale.where("NOT sale_status='new'").shop.order("sale_id desc") + @sales = Sale.where("NOT sale_status='new'").order("sale_id desc") else - @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").shop.order("sale_id desc") + @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").order("sale_id desc") end @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) else - sale = Sale.search(receipt_no,from,to,@shift).shop + sale = Sale.search(receipt_no,from,to,@shift) if sale.count > 0 @sales = sale @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) @@ -350,7 +350,7 @@ class Transactions::SalesController < ApplicationController customer= Customer.find(sale.customer_id) #shop detail - shop_details = @shop + shop_details = current_shop # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate diff --git a/app/controllers/transactions/shift_sales_controller.rb b/app/controllers/transactions/shift_sales_controller.rb index db41b03a..dc06c9eb 100644 --- a/app/controllers/transactions/shift_sales_controller.rb +++ b/app/controllers/transactions/shift_sales_controller.rb @@ -38,7 +38,7 @@ class Transactions::ShiftSalesController < ApplicationController #get tax shift_obj = ShiftSale.where('id =?',@shift.id) - @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='').where("sales.shop_code='#{@shop.shop_code}'") + @sale_taxes = Sale.get_separate_tax(shift_obj,from=nil,to=nil,type='') #other payment details for mpu or visa like card @other_payment = ShiftSale.get_by_shift_other_payment(@shift) diff --git a/app/models/assigned_order_item.rb b/app/models/assigned_order_item.rb index bd20e447..d77248d8 100755 --- a/app/models/assigned_order_item.rb +++ b/app/models/assigned_order_item.rb @@ -36,7 +36,6 @@ class AssignedOrderItem < ApplicationRecord assigned_order_item.order_queue_station = order_queue_station assigned_order_item.print_status = false assigned_order_item.delivery_status = false - assigned_order_item.shop_code =order.shop_code assigned_order_item.save! end diff --git a/app/models/booking.rb b/app/models/booking.rb index 3cd13296..e3a8f6e3 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -135,7 +135,7 @@ class Booking < ApplicationRecord joins(" LEFT JOIN dining_facilities df ON df.id=bookings.dining_facility_id") .where("booking_id LIKE ? OR checkin_by LIKE ? OR booking_status LIKE? OR checkout_by LIKE? OR sale_id ='#{filter}' OR df.name LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%","%#{filter}%") end - .shop.order("sale_id DESC") + .order("sale_id DESC") end def self.get_sync_data(sale_id) diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 8717222e..a93f4742 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -20,7 +20,6 @@ class DiningFacility < ApplicationRecord ROOM_TYPE = "Room" default_scope { order('order_by asc') } - scope :shop, -> { where("shop_code=?",Shop.current_shop.shop_code) } scope :active, -> {where(is_active: true)} diff --git a/app/models/employee.rb b/app/models/employee.rb index a57b300f..9d18c6c6 100755 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -1,5 +1,6 @@ class Employee < ApplicationRecord has_secure_password + # has_secure_token :auth_token has_many :commissioners has_many :shit_sales has_one :current_shift, -> { where.not(shift_started_at: nil).where(shift_closed_at: nil) },class_name: "ShiftSale" @@ -11,6 +12,7 @@ class Employee < ApplicationRecord validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true validates :password, numericality: true, length: {in: 3..9}, allow_blank: true + before_create :generate_app_id, :generate_app_token , if: Proc.new { self.role == "application" } # Employee Image Uploader mount_uploader :image_path, EmployeeImageUploader @@ -43,7 +45,7 @@ class Employee < ApplicationRecord if (session_token) user = Employee.find_by_token_session(session_token) expiry_time = login_expiry_time - if !user.session_expiry.nil? + if user && !user.session_expiry.nil? if user && user.session_expiry.utc > DateTime.now.utc #Extend the login time each time authenticatation take place user.session_expiry = user.session_expiry.utc + expiry_time.minutes @@ -89,4 +91,18 @@ class Employee < ApplicationRecord return expiry_time end + + def generate_app_id + # return if self.role != 'application' + self.app_id = SecureRandom.urlsafe_base64(nil, false) + rescue ActiveRecord::RecordNotUnique + retry + end + + def generate_app_token + # return if self.role != 'application' + self.app_token = SecureRandom.hex(10) + rescue ActiveRecord::RecordNotUnique + retry + end end diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index 6be91da4..a1393556 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -8,7 +8,7 @@ class InventoryDefinition < ApplicationRecord logger.debug saleObj.sale_items.to_json if !saleObj.nil? saleObj.sale_items.each do |item| - found, inventory_definition = find_product_in_inventory(item,saleObj.shop_code) + found, inventory_definition = find_product_in_inventory(item) if found check_balance(item,inventory_definition) end diff --git a/app/models/lookup.rb b/app/models/lookup.rb index 323bf664..f6fbfd33 100755 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -1,7 +1,6 @@ class Lookup < ApplicationRecord has_many :accounts - belongs_to :shop scope :number_formats, -> { where(lookup_type: 'number_format')} @@ -26,12 +25,10 @@ class Lookup < ApplicationRecord # Lookup.select("value, name").where("lookup_type = ?", lookup_type ).order("name asc").map { |r| [r.name, r.value] } # end - def self.time_limit TIME_LIMIT end - def self.get_checkin_time_limit return RequestStore[:checkin_time_limit] if RequestStore[:checkin_time_limit] RequestStore[:checkin_time_limit] = Lookup.find_by_lookup_type('checkin_time_limit').value.to_i rescue time_limit @@ -63,41 +60,39 @@ class Lookup < ApplicationRecord Lookup.where("lookup_type" => type ).pluck("name, value") end - def self.create_shift_sale_lookup(shop_code) + def self.create_shift_sale_lookup @lookup = Lookup.new @lookup.lookup_type = 'shift_sale_items' @lookup.name = 'Shift Sale Items' @lookup.value = 0 - @lookup.shop_code = shop_code @lookup.save return @lookup end - def self.create_reprint_receipt_lookup(shop_code) + def self.create_reprint_receipt_lookup @lookup = Lookup.new @lookup.lookup_type = 'reprint_receipt' @lookup.name = 'Reprint Receipt in Report' @lookup.value = 0 - @lookup.shop_code = shop_code @lookup.save return @lookup end - def self.save_shift_sale_items_settings(val,shop_code) + def self.save_shift_sale_items_settings(val) @lookup = Lookup.where("lookup_type=?", 'shift_sale_items').last if @lookup.nil? - @lookup = Lookup.create_shift_sale_lookup(shop_code) + @lookup = Lookup.create_shift_sale_lookup end @lookup.value = val @lookup.save end - def self.shift_sale_items_lookup_value(shop_code) + def self.shift_sale_items_lookup_value @lookup = Lookup.where("lookup_type=?", 'shift_sale_items').last if @lookup.nil? - @lookup = Lookup.create_shift_sale_lookup(shop_code) + @lookup = Lookup.create_shift_sale_lookup end return @lookup.value end diff --git a/app/models/menu.rb b/app/models/menu.rb index d9c98e01..a59480a6 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -8,7 +8,6 @@ class Menu < ApplicationRecord #Default Scope to pull the active version only default_scope { order("created_at asc") } scope :active, -> {where("is_active = true")} - scope :shop, -> { where("menus.shop_code=?",Shop.current_shop.shop_code) } def self.current_menu today = DateTime.now @@ -47,7 +46,7 @@ class Menu < ApplicationRecord end end - def self.import(file, created_by,shop) + def self.import(file, created_by) status = "" spreadsheet = open_spreadsheet(file) if spreadsheet.sheets.count > 1 @@ -62,9 +61,9 @@ class Menu < ApplicationRecord # Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) account = Account.find_by_id(row["id"]) if account - Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"],shop_code: shop.shop_code) + Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) else - Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"],shop_code: shop.shop_code) + Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) end elsif sheet_name == "Item Set" # ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty]) @@ -93,9 +92,9 @@ class Menu < ApplicationRecord elsif sheet_name == "Menu" menu = Menu.find_by_id(row["id"]) if menu - Menu.create(name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"],shop_code: shop.shop_code) + Menu.create(name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) else - Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"],shop_code: shop.shop_code) + Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], is_ordering: row["is_ordering"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) end elsif sheet_name == "Menu Category" # MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) @@ -155,7 +154,7 @@ class Menu < ApplicationRecord menu = sheet.row(1)[1] is_ordering = sheet.row(1)[3]?sheet.row(1)[3]:0 - imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by,shop_code: shop.shop_code}) + imported_menu = Menu.create({name: menu, is_active: true, is_ordering: is_ordering, valid_days: "1,2,3,4,5,6,7",valid_time_from: "00:00:00", valid_time_to: "23:59:59", created_by: created_by}) (4..sheet.last_row).each do |ii| row = Hash[[sheet.row(3),sheet.row(ii)].transpose] @@ -194,7 +193,7 @@ class Menu < ApplicationRecord if !menu_itm account = Account.find_by_title(row["Account"]) if account.nil? - account = Account.create({title: row["Account"], account_type: "0",shop_code: shop.shop_code}) + account = Account.create({title: row["Account"], account_type: "0"}) end image_path = "" diff --git a/app/models/payment_journal.rb b/app/models/payment_journal.rb index 51b7fdf3..1b195329 100755 --- a/app/models/payment_journal.rb +++ b/app/models/payment_journal.rb @@ -8,7 +8,6 @@ class PaymentJournal < ApplicationRecord self.payment_status = 'paid' self.payment_method_references = payment_method_reference self.created_by = current_user.id - self.shop_code = current_user.shop_code self.save end @@ -18,7 +17,6 @@ class PaymentJournal < ApplicationRecord self.debit_amount = amount self.payment_status = 'paid' self.created_by = current_user.id - self.shop_code = current_user.shop_code self.save end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 48925f74..840631cf 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -90,20 +90,20 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Bill Receipt Print - def print_receipt_bill(printer_settings, kbz_pay_status, qr_code, cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation,transaction_ref) + def print_receipt_bill(printer_settings, kbz_pay_status, qr_code, cashier_terminal, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, shop_details, printed_status, balance, card_data, other_amount, latest_order_no, card_balance_amount, order_reservation = nil, transaction_ref = nil) #Use CUPS service #Generate PDF #Print if printer_settings if !printer_settings.unique_code.match?(/receiptbillorder/i) if Lookup.collection_of("print_settings").any? { |x| x == ["ReceiptBillA5Pdf", "1"] } #print_settings with name:ReceiptBillA5Pdf - pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, shop_details, printed_status, balance, card_data, other_amount, latest_order_no, card_balance_amount) else - pdf = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code.constantize.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + pdf = PrintSetting.where("unique_code REGEXP ?", "receipt.*bill.*pdf").first.unique_code.constantize.new(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, shop_details, printed_status, balance, card_data, other_amount, latest_order_no, card_balance_amount, transaction_ref) end else #doemal online order pdf template - pdf = ReceiptBillOrderPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation) + pdf = ReceiptBillOrderPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount,order_reservation) end # print as print copies in printer setting diff --git a/app/models/product_commission.rb b/app/models/product_commission.rb index b017df1e..00de8bed 100755 --- a/app/models/product_commission.rb +++ b/app/models/product_commission.rb @@ -33,7 +33,7 @@ class ProductCommission < ApplicationRecord product_commission.save end - def self.edit_product_commission(saleItemObj,shop_code) + def self.edit_product_commission(saleItemObj) menu_item = MenuItem.find_by_item_code(saleItemObj.product_code) commission = Commission.where("product_code = ? AND is_active = ?", menu_item.id, true).take product_commission = ProductCommission.where('sale_item_id = ?', saleItemObj.id).take diff --git a/app/models/sale.rb b/app/models/sale.rb index 01d537b4..bf9fa2bd 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -793,7 +793,7 @@ def self.daily_sales_list(from,to) SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") .along_with_sale_payments_except_void_between(from, to) - .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to).shop + .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) .group("sale_id").to_sql daily_total = connection.select_all("SELECT @@ -849,7 +849,7 @@ def self.get_by_range_by_saleitems(from,to,status,report_type) query = query.where("(receipt_date between ? and ? and sale_status=?) AND i.unit_price <> 0",from,to,status) end -def self.get_by_shiftsales(from,to,shift,shop_code) +def self.get_by_shiftsales(from,to,shift) if !shift.blank? query = ShiftSale.where("shift_sales.id =?",shift.id) else @@ -974,7 +974,7 @@ def self.get_other_charges() query = query.group("i.sale_item_id") end -def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,account_type,shop_code) +def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type,account_type) # date_type_selection = get_sql_function_for_report_type(report_type) if account_type.blank? account_type = '' @@ -1256,7 +1256,7 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay return query end -def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source,shop_code) +def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source) payments_for_credits = SalePayment.select(" sales.sale_id, DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') as credit_payment_receipt_date, @@ -1312,7 +1312,7 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter, credits = credits.group("sale_payments.sale_payment_id, sales_sale_payments.sale_id") end - def self.get_void_sale(shift,from,to,shop_code) + def self.get_void_sale(shift,from,to) sale_arr = Array.new query = Sale.select("sales.receipt_no,sales.receipt_date, sales.payment_status, sales.sale_status,sales.total_amount,sales.grand_total, sales.rounding_adjustment") @@ -1498,7 +1498,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user.id) + if shift = ShiftSale.current_open_shift(current_user) query = query.where("shift_sale_id='#{shift.id}'") end @@ -1525,7 +1525,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user.id) + if shift = ShiftSale.current_open_shift(current_user) query = query.where("shift_sale_id='#{shift.id}'") end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 7aa47a87..3c02111e 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -34,7 +34,7 @@ class SalePayment < ApplicationRecord end end - def self.get_kbz_pay_amount(sale_id, current_user,shop) + def self.get_kbz_pay_amount(sale_id, current_user) amount = 0 kbz_pay_method = PaymentMethodSetting.where(:payment_method => KbzPay::KBZ_PAY).last sale_payment = SalePayment.where('sale_id=? and payment_method=? and payment_status!=?', sale_id, KbzPay::KBZ_PAY, 'dead').last @@ -705,7 +705,7 @@ class SalePayment < ApplicationRecord self.sale.cashier_name = Employee.find(shift.employee_id).name self.sale.save else - shift = ShiftSale.current_shift(self.sale.shop_code) + shift = ShiftSale.current_shift shift.update(self.sale) self.sale.shift_sale_id = shift.id self.sale.cashier_id = shift.employee_id diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 9717f9e5..59432f0b 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -83,7 +83,6 @@ class ShiftSale < ApplicationRecord self.shift_started_at = DateTime.now self.employee_id = current_user.id self.opening_balance = opening_balance - self.shop_code = current_user.shop_code self.other_sales = 0 self.save end diff --git a/app/models/shop.rb b/app/models/shop.rb index a9b672b1..2a366927 100755 --- a/app/models/shop.rb +++ b/app/models/shop.rb @@ -2,9 +2,8 @@ class Shop < ApplicationRecord #ShopDetail = Shop.current_shop # Shop Image Uploader - - mount_uploader :logo, ShopImageUploader - has_many :display_images + mount_uploader :logo, ShopImageUploader + has_many :display_images accepts_nested_attributes_for :display_images diff --git a/app/models/stock_check.rb b/app/models/stock_check.rb index 541a7ea5..c2499c29 100755 --- a/app/models/stock_check.rb +++ b/app/models/stock_check.rb @@ -1,12 +1,11 @@ class StockCheck < ApplicationRecord has_many :stock_check_items - def create(user, reason, item_list,shop) + def create(user, reason, item_list) self.reason = reason self.check_by = user.id self.check_start = Time.now self.check_end = Time.now - self.shop_code = shop.shop_code save item_list.each do |item| stockItem = StockCheckItem.new diff --git a/app/models/stock_check_item.rb b/app/models/stock_check_item.rb index 9cab250e..16699803 100755 --- a/app/models/stock_check_item.rb +++ b/app/models/stock_check_item.rb @@ -67,7 +67,7 @@ class StockCheckItem < ApplicationRecord return query end - def self.delete_stock_check_item(item_code,shop) + def self.delete_stock_check_item(item_code) self.where("item_code=?", item_code).delete_all end end diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index f84c6204..3f952953 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -26,8 +26,7 @@ class StockJournal < ApplicationRecord inventory_definition_id: inventory_definition.id, remark: stock_message, trans_ref: trans_ref, - trans_type: trans_type, - shop_code: inventory_definition.shop_code + trans_type: trans_type ) end @@ -35,11 +34,11 @@ class StockJournal < ApplicationRecord return balance.to_i - qty.to_i end - def self.from_stock_check(item,shop) + def self.from_stock_check(item) stock_journal = StockJournal.where("item_code=?", item.item_code).order("id DESC").first if stock_journal.nil? old_blance = 0 - inventory_definition_id = InventoryDefinition.find_by_item_code_and_shop_code(item.item_code,shop.shop_code).id + inventory_definition_id = InventoryDefinition.find_by_item_code(item.item_code).id else old_blance = stock_journal.balance inventory_definition_id = stock_journal.inventory_definition_id @@ -54,12 +53,11 @@ class StockJournal < ApplicationRecord journal.remark = StockJournal::STOCK_CHECK_TRANS journal.trans_ref = item.id journal.trans_type = StockJournal::STOCK_CHECK_TRANS - journal.shop_code = shop.shop_code journal.save end - def self.inventory_balances(from,to, current_shop) + def self.inventory_balances(from,to) query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") .group("mii.item_instance_name") @@ -78,7 +76,7 @@ class StockJournal < ApplicationRecord end end - def self.delete_stock_journal(item_code,shop) + def self.delete_stock_journal(item_code) self.where("item_code=?", item_code).delete_all end diff --git a/app/models/zone.rb b/app/models/zone.rb index 5d1c9309..e9ca27cb 100755 --- a/app/models/zone.rb +++ b/app/models/zone.rb @@ -5,7 +5,6 @@ class Zone < ApplicationRecord has_many :order_queue_stations has_many :cashier_terminals - scope :shop, -> { where("shop_code=?",Shop.current_shop.shop_code) } # validations validates_presence_of :name, :created_by diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index aba19030..e8fd36b5 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -5,7 +5,7 @@ class ReceiptBillPdf < Prawn::Document attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move - def initialize(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_account, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil, shop_details, printed_status, current_balance, card_data, other_charges_amount, latest_order_no, card_balance_amount, transaction_ref) + def initialize(printer_settings, kbz_pay_status, qr_code, sale_items, sale_data, customer_account, item_price_by_accounts, discount_price_by_accounts, member_info, rebate_amount, shop_details, printed_status, current_balance, card_data, other_charges_amount, latest_order_no, card_balance_amount, transaction_ref = nil) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -72,8 +72,7 @@ class ReceiptBillPdf < Prawn::Document else customer(customer_account,nil) end - puts "Card data = >" +card_data - puts "Printed =>" + printed_status + #start card sale trans data if card_data != nil card_sale_data(card_data) @@ -693,7 +692,7 @@ class ReceiptBillPdf < Prawn::Document query = sale_data.sale_payments .merge(SalePayment.where.not(payment_method: 'creditnote') .or(SalePayment.where.not(SalePayment.arel_table[:payment_amount].lteq(sale_data.sale_payments.joins(:sale_audit).sum(:payment_amount))))) - + query.each do |payment| if payment.payment_method == "creditnote" diff --git a/app/uploaders/customer_image_uploader.rb b/app/uploaders/customer_image_uploader.rb index 77a133af..a66c5b86 100644 --- a/app/uploaders/customer_image_uploader.rb +++ b/app/uploaders/customer_image_uploader.rb @@ -20,7 +20,7 @@ class CustomerImageUploader < CarrierWave::Uploader::Base end def filename - if Shop.current_shop.shop_code.nil? + if Shop.current_shop.nil? "#{original_filename}" if original_filename.present? else "#{Shop.current_shop.shop_code}_#{original_filename}" if original_filename.present? diff --git a/app/views/api/restaurant/menu_items/show.json.jbuilder b/app/views/api/restaurant/menu_items/show.json.jbuilder index 193a0596..b15e664d 100644 --- a/app/views/api/restaurant/menu_items/show.json.jbuilder +++ b/app/views/api/restaurant/menu_items/show.json.jbuilder @@ -1,3 +1,3 @@ if (@menu_item) - json.partial! 'api/restaurant/menu/menu_item', item: @menu_item, request_url: @request_url + json.partial! 'api/restaurant/menu_items/menu_item', item: @menu_item, request_url: @request_url end diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 71f7398a..4cb3bde2 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -347,7 +347,7 @@ <% end %> <% end %> - <% if isMobile.include? "Mobile" %> + <% if isMobile.to_s.include? "Mobile" %>