diff --git a/app/controllers/concerns/multi_tenancy.rb b/app/controllers/concerns/multi_tenancy.rb index d5efb2a2..8aac68aa 100644 --- a/app/controllers/concerns/multi_tenancy.rb +++ b/app/controllers/concerns/multi_tenancy.rb @@ -13,7 +13,8 @@ module MultiTenancy shop_code = request.subdomain.partition('-').last @shop = Shop.find_by(shop_code: shop_code) else - @shop = Shop.first + # @shop = Shop.first + @shop = Shop.find_by(shop_code: '262') end set_current_tenant(@shop) end diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 9cd67dde..56b941b4 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -130,7 +130,7 @@ class Crm::CustomersController < BaseCrmController params[:type] = nil params[:customer_id] = params[:id] - @credit_sales = SalePayment.get_credit_sales(params,@shop.shop_code) + @credit_sales = SalePayment.get_credit_sales(params) #get customer amount @customer = Customer.find(params[:id]) diff --git a/app/controllers/foodcourt/cash_ins_controller.rb b/app/controllers/foodcourt/cash_ins_controller.rb deleted file mode 100755 index 8700b01f..00000000 --- a/app/controllers/foodcourt/cash_ins_controller.rb +++ /dev/null @@ -1,43 +0,0 @@ -class Foodcourt::CashInsController < BaseFoodcourtController - def new - end - - def create - reference = params[:reference] - remark = params[:remark] - amount = params[:amount] - payment_method = params[:payment_method] - payment_method_reference = params[:payment_method_reference] - type = params[:type] - - p_jour = PaymentJournal.new - - p_jour.cash_in(reference, remark, amount, payment_method, payment_method_reference, current_user) - shift = ShiftSale.current_open_shift(current_user) - - current_shift = ShiftSale.current_shift(@shop.shop_code) - # set cashier - if shift != nil - shift = shift - else - - open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") - if open_cashier.count>0 - shift = ShiftSale.current_open_shift(open_cashier[0]) - - if shift - emp = Employee.find_by_id(shift.employee_id) - shift = ShiftSale.current_open_shift(emp) - else - shift = ShiftSale.current_open_shift(current_shift) - end - else - # shift = Employee.find(current_shift.employee_id).name - shift =current_shift - end - end - shift.cash_in = shift.cash_in + amount.to_f - shift.save - end - -end diff --git a/app/controllers/foodcourt/cash_outs_controller.rb b/app/controllers/foodcourt/cash_outs_controller.rb deleted file mode 100755 index 0ac91af5..00000000 --- a/app/controllers/foodcourt/cash_outs_controller.rb +++ /dev/null @@ -1,39 +0,0 @@ -class Foodcourt::CashOutsController < BaseFoodcourtController - def new - end - - def create - reference = params[:reference] - remark = params[:remark] - amount = params[:amount] - p_jour = PaymentJournal.new - p_jour.cash_out(reference, remark, amount, current_user) - shift = ShiftSale.current_open_shift(current_user) - - current_shift = ShiftSale.current_shift(@shop.shop_code) - - # set cashier - if shift != nil - shift = shift - else - open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") - if open_cashier.count>0 - - shift = ShiftSale.current_open_shift(open_cashier[0]) - - if shift - emp = Employee.find_by_id(shift.employee_id) - shift = ShiftSale.current_open_shift(emp) - else - shift = ShiftSale.current_open_shift(current_shift) - end - else - # shift = Employee.find(current_shift.employee_id).name - shift =current_shift - end - end - shift.cash_out = shift.cash_out + amount.to_i - shift.save - end - -end diff --git a/app/controllers/foodcourt/dashboard_controller.rb b/app/controllers/foodcourt/dashboard_controller.rb index 6857eab1..64168e5b 100644 --- a/app/controllers/foodcourt/dashboard_controller.rb +++ b/app/controllers/foodcourt/dashboard_controller.rb @@ -1,121 +1,18 @@ class Foodcourt::DashboardController < BaseFoodcourtController - - def index - today = DateTime.now.strftime('%Y-%m-%d') - - @display_type = Lookup.find_by_lookup_type("display_type") - - @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(@shop,today,current_user) - if !@total_payment_methods.nil? - @total_payment_methods.each do |payment| - if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" - pay = Sale.payment_sale(@shop,'card', today, current_user) - @sale_data.push({'card' => pay.payment_amount}) - else - pay = Sale.payment_sale(@shop,payment.payment_method, today, current_user) - @sale_data.push({payment.payment_method => pay.payment_amount}) - end - end - else - @sale_data = nil - end - @summ_sale = Sale.summary_sale_receipt(@shop,today,current_user) - @total_customer, @total_dinein, @total_takeaway, @total_membership = Sale.total_customer(@shop,today,current_user,@from,@to,@from_time,@to_time) - # @total_other_customer = Sale.total_other_customer(today,current_user) - - @total_order = Sale.total_order(@shop,today,current_user) - @total_accounts = Sale.total_account(@shop,today,current_user) - @account_data = Array.new - if !@total_accounts.nil? - @total_accounts.each do |account| - acc = Sale.account_data(@shop,account.account_id, today,current_user) - if !acc.nil? - @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) - end - end - else - @account_data = nil - end - - @top_items = Sale.top_items(@shop,today,current_user) - @total_foc_items = Sale.total_foc_items(@shop,today,current_user) - - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() - @current_user = current_user - #dine-in cashier - dinein_cashier = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dinein_cashier') - @dinein_cashier = 0 - if !dinein_cashier[0].nil? - @dinein_cashier = dinein_cashier[0][1] - end - - #quick service - quick_service = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('quick_service') - @quick_service = 0 - if !quick_service[0].nil? - @quick_service = quick_service[0][1] - end - - #fourt court - food_court = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('food_court') - @food_court = 0 - @food_court_name = nil - if !food_court[0].nil? - @food_court = food_court[0][1] - @food_court_name = food_court[0][0] - end - - #order reservation - order_reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('order_reservation') - @order_reservation = 0 - if !order_reservation.empty? - order_reservation.each do |order_reserve| - if order_reserve[0] == 'OrderReservation' - @order_reservation = order_reserve[1] - end - end - end - - #dashboard settings on/off for supervisor and cashier - dashboard_settings = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('dashboard_settings') - @setting_flag = true - if !dashboard_settings.empty? - dashboard_settings.each do |setting| - if setting[0].to_s.downcase == current_user.role.downcase && setting[1] == '0' - @setting_flag = false - end - end - end - - #reservation - reservation = Lookup.where("shop_code='#{@shop.shop_code}'").collection_of('reservation') - @reservation = 0 - if !reservation.empty? - reservation.each do |reserve| - if reserve[0] == 'Reservation' - @reservation = reserve[1] - end - end - end + def get_all_menu + @menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.shop + @item_attributes = MenuItemAttribute.all.load + @item_options = MenuItemOption.all.load end -def get_all_menu - @menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all - @item_attributes = MenuItemAttribute.all.load - @item_options = MenuItemOption.all.load -end + def get_credit_sales + credit_sales = SalePayment.get_credit_sales(params) + if !credit_sales.nil? + result = {:status=> true, :data=> credit_sales } + else + result = {:status=> false, :message=>"There is no record." } + end -def get_credit_sales - credit_sales = SalePayment.get_credit_sales(params,@shop.shop_code) - if !credit_sales.nil? - result = {:status=> true, :data=> credit_sales } - else - result = {:status=> false, :message=>"There is no record." } + render :json => result.to_json end - - render :json => result.to_json -end - end diff --git a/app/controllers/foodcourt/discounts_controller.rb b/app/controllers/foodcourt/discounts_controller.rb index 5ab25a7a..2d4c13d8 100755 --- a/app/controllers/foodcourt/discounts_controller.rb +++ b/app/controllers/foodcourt/discounts_controller.rb @@ -42,12 +42,6 @@ class Foodcourt::DiscountsController < BaseFoodcourtController table = nil table_id = nil end - - - # sale.total_discount = overall_discount.to_f - # sale.total_amount = sub_total.to_f - # sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; - # sale.save if discount_items.length > 0 #save sale item for discount @@ -56,14 +50,6 @@ class Foodcourt::DiscountsController < BaseFoodcourtController sale_item = SaleItem.new - # if !origin_sale_item.nil? - # menu_category = MenuCategory.get_menu_category(origin_sale_item.product_code) #get menu category for menu items - # if !menu_category.nil? - # sale_item.menu_category_code = menu_category.code - # sale_item.menu_category_name = menu_category.name - # end - # end - sale_item.menu_category_code = origin_sale_item.menu_category_code sale_item.menu_category_name = origin_sale_item.menu_category_name @@ -153,9 +139,6 @@ class Foodcourt::DiscountsController < BaseFoodcourtController sale_item.destroy end end - - # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; - # sale.save # Re-calc All Amount in Sale sale.compute_by_sale_items(sale.total_discount, nil, order_source) if table.nil? diff --git a/app/controllers/foodcourt/food_court_controller.rb b/app/controllers/foodcourt/food_court_controller.rb index f0a35a96..13f72dc3 100644 --- a/app/controllers/foodcourt/food_court_controller.rb +++ b/app/controllers/foodcourt/food_court_controller.rb @@ -10,17 +10,8 @@ class Foodcourt::FoodCourtController < ApplicationController def index today = DateTime.now day = Date.today.wday - # if params[:menu] == "true" @menus = [] @menu = [] - # else - # @menus = Menu.all - # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') - # end - @zone = Zone.all.where("is_active= true") - @customer = Customer.all - @tables = Table.all.active.order('status desc') - @rooms = Room.all.active.order('status desc') @cashier_type = "food_court" #checked quick_service only @quick_service_only = true @@ -40,104 +31,9 @@ class Foodcourt::FoodCourtController < ApplicationController .joins("JOIN order_items ON orders.order_id=order_items.order_id") .joins("JOIN customers ON orders.customer_id=customers.customer_id") .where("orders.source='app' and bookings.shop_code='#{@shop.shop_code}' and DATE(bookings.created_at) = '#{Date.today}' and bookings.booking_status='assign'").uniq.length - render "foodcourt/addorders/detail" end - def modify_order - @cashier_type = "food_court" - today = DateTime.now - day = Date.today.wday - # if params[:menu] == "true" - @menus = [] - @menu = [] - # else - # @menus = Menu.all - # @menu = MenuCategory.active.where("menu_id =#{@menus[0].id}").order('order_by asc') - # end - if(params[:id][0,3] == "BKI") - @table_id = nil - @table = nil - @booking = Booking.find(params[:id]) - else - @table_id = params[:id] - @table = DiningFacility.find(@table_id) - @booking = @table.get_booking - end - - @sale_id = @booking.sale_id - - if @booking - @booking_id = @booking.booking_id - @obj_order = @booking.orders.first - @customer = @obj_order.customer - @date = @obj_order.created_at - @order_items = @booking.order_items - end - - render "foodcourt/addorders/detail" - end - - def update_modify_order - booking = Booking.find(params[:booking_id]) - sale = booking.sale - if sale && sale.sale_status != 'new' - render :json => { :status => false } - end - - is_extra_time = false - extra_time = '' - cashier_type = "food_court" - - items_arr = [] - JSON.parse(params[:order_items]).each { |i| - i["item_instance_code"] = i["item_instance_code"].downcase.to_s - if i["item_instance_code"].include? "ext" - is_extra_time = true - arr_exts = i["item_instance_code"].split("_") - if arr_exts[1].match(/^(\d)+$/) - time = arr_exts[1].to_i*60*i["quantity"].to_i - extra_time = Time.at(time) - end - end - if i["parent_order_item_id"] - items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": i["options"]} - else - items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]} - end - items_arr.push(items) - } - - # begin - order = Order.new - order.source = params[:order_source] - order.order_type = params[:order_type] - order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile - order.items = items_arr - order.guest = params[:guest_info] - order.table_id = params[:table_id] # this is dining facilities's id - order.waiters = current_login_employee.name - order.employee_name = current_login_employee.name - - order.is_extra_time = is_extra_time - order.extra_time = extra_time - - order.new_booking = false - order.booking_id = booking.booking_id - - if order.generate - if sale - Sale.add_to_existing_pending_invoice(nil, sale.sale_id, booking) - render :json => { :status => true, :data => sale } - else - render :json => { :status => true, :data => 'OK' } - end - else - render :json => { :status => false } - end - - end - def get_menu_category () if (params[:id]) puts params[:id] @@ -150,7 +46,6 @@ class Foodcourt::FoodCourtController < ApplicationController end end - def get_menu_sub_category () id = params[:id] if (id) @@ -173,35 +68,4 @@ class Foodcourt::FoodCourtController < ApplicationController }.to_json end - def check_order_with_table(table_id) - table = DiningFacility.find(table_id) - if table - booking = table.get_current_booking - # puts booking - if booking - if !booking.sale_id.nil? - if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" - @order.new_booking = true - return false - end - else - @order.new_booking = false - @order.booking_id = booking.booking_id - return false - end - end - end - end - # this can always true - def check_order_with_booking(booking) - if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" - @order.new_booking = true - return false - else - @order.new_booking = false - @order.booking_id = params[:booking_id] - return false - end - end - end diff --git a/app/controllers/foodcourt/orders_controller.rb b/app/controllers/foodcourt/orders_controller.rb index 082e9ab4..38c6a2a5 100755 --- a/app/controllers/foodcourt/orders_controller.rb +++ b/app/controllers/foodcourt/orders_controller.rb @@ -66,11 +66,12 @@ class Foodcourt::OrdersController < BaseFoodcourtController @sale_data = Sale.find_by_sale_id(@booking.sale_id) end @bookings = Booking.select("bookings.*,customers.*") + .joins(" JOIN sales ON bookings.sale_id=sales.sale_id") .joins(" JOIN booking_orders ON booking_orders.booking_id=bookings.booking_id") .joins("JOIN orders ON orders.order_id=booking_orders.order_id") .joins("JOIN order_items ON orders.order_id=order_items.order_id") .joins("JOIN customers ON orders.customer_id=customers.customer_id") - .where("orders.source='app' and bookings.shop_code=? and DATE(bookings.created_at)=?",@shop.shop_code,Date.today).order("bookings.created_at desc").uniq + .where("sales.sale_status !=? and orders.source='app' and bookings.shop_code=? and DATE(bookings.created_at)=?",'void',@shop.shop_code,Date.today).order("bookings.created_at desc").uniq end def completed customer =Customer.find_by_customer_id(params[:customer_id]) diff --git a/app/controllers/foodcourt/shifts_controller.rb b/app/controllers/foodcourt/shifts_controller.rb index 599dad1e..4221206c 100755 --- a/app/controllers/foodcourt/shifts_controller.rb +++ b/app/controllers/foodcourt/shifts_controller.rb @@ -15,7 +15,7 @@ class Foodcourt::ShiftsController < BaseFoodcourtController end def new - @float = Lookup.where('lookup_type=?','float_value') + @float = Lookup.where('lookup_type=? and shop_code=?','float_value',@shop.shop_code) @terminal = CashierTerminal.available.where("shop_code='#{@shop.shop_code}'") end diff --git a/app/controllers/foodcourt/void_controller.rb b/app/controllers/foodcourt/void_controller.rb index 5cb18b4f..10171423 100755 --- a/app/controllers/foodcourt/void_controller.rb +++ b/app/controllers/foodcourt/void_controller.rb @@ -71,11 +71,12 @@ class Foodcourt::VoidController < BaseFoodcourtController sale_audit = SaleAudit.record_audit_for_edit(sale_id,current_user.name, action_by,remark,"SALEVOID" ) #call paymal to void - if sale.sale_payments.nil? + if !sale.sale_payments.nil? membership_response =sale.paymal_payment_void + Rails.logger.debug "---------Paymal Payment Void response in VoidController" + Rails.logger.debug membership_response.to_json end - Rails.logger.debug "---------Paymal Payment Void response in VoidController" - Rails.logger.debug membership_response.to_json + # For Print member_info = nil diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index 004cbf3b..b411f3d5 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -105,14 +105,14 @@ class Origami::DashboardController < BaseOrigamiController def get_all_menu - @menus = Menu.includes(:menu_categories => :children).includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.all + @menus = Menu.includes(:menu_categories => :children).includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).includes(:menu_categories => {:menu_items => {:item_sets => :menu_item_instances}}).active.shop @item_attributes = MenuItemAttribute.all.load @item_options = MenuItemOption.all.load end def get_credit_sales - credit_sales = SalePayment.get_credit_sales(params,@shop.shop_code) + credit_sales = SalePayment.get_credit_sales(params) if !credit_sales.nil? result = {:status=> true, :data=> credit_sales } else diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index b31e1a17..778b1458 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -6,14 +6,14 @@ class Origami::HomeController < BaseOrigamiController @webview = check_mobile - @tables = Table.unscope(:order).includes(:zone).all.active.order('status desc') - @rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc') + @tables = Table.unscope(:order).includes(:zone).shop.active.order('status desc') + @rooms = Room.unscope(:order).includes(:zone).shop.active.order('status desc') @complete = Sale.completed_sale("cashier") @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') @customers = Customer.pluck("customer_id, name") - @occupied_table = DiningFacility.where("shop_code='#{@shop.shop_code}' and status='occupied'").count + @occupied_table = DiningFacility.where("status='occupied'").shop.count @shift = ShiftSale.current_open_shift(current_user) end @@ -24,8 +24,8 @@ class Origami::HomeController < BaseOrigamiController @webview = check_mobile - @tables = Table.unscope(:order).includes(:zone).all.active.order('status desc') - @rooms = Room.unscope(:order).includes(:zone).all.active.order('status desc') + @tables = Table.unscope(:order).includes(:zone).shop.active.order('status desc') + @rooms = Room.unscope(:order).includes(:zone).shop.active.order('status desc') @complete = Sale.completed_sale("cashier") @orders = Order.includes("sale_orders").where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status != 'billed' and source != 'quick_service'",DateTime.now.strftime('%Y-%m-%d')).order('date desc') diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 3fcfe704..96ae85fe 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -15,7 +15,7 @@ class Origami::ShiftsController < BaseOrigamiController end def new - @float = Lookup.where('lookup_type=?','float_value') + @float = Lookup.where('lookup_type=? and shop_code=?','float_value',@shop.shop_code) @terminal = CashierTerminal.available end diff --git a/app/controllers/reports/dailysale_controller.rb b/app/controllers/reports/dailysale_controller.rb index a4fac509..74c73477 100755 --- a/app/controllers/reports/dailysale_controller.rb +++ b/app/controllers/reports/dailysale_controller.rb @@ -2,17 +2,15 @@ class Reports::DailysaleController < BaseReportController authorize_resource :class => false def index - from, to = get_date_range_from_params - @sale_data = Sale.daily_sales_list(from,to,@shop.shop_code) - @tax = SaleTax.get_tax(from,to,@shop.shop_code) - @from = from - @to = to - @payment_methods = PaymentMethodSetting.where("is_active='1' and shop_code='#{@shop.shop_code}'").pluck("payment_method") - - - # get printer info - @print_settings = PrintSetting.get_precision_delimiter() - respond_to do |format| + from, to = get_date_range_from_params + @sale_data = Sale.daily_sales_list(from,to) + @tax = SaleTax.get_tax(from,to) + @from = from + @to = to + @payment_methods = PaymentMethodSetting.where("is_active='1' and shop_code=?",@shop.shop_code).pluck("payment_method") + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + respond_to do |format| format.html format.xls end diff --git a/app/controllers/transactions/bookings_controller.rb b/app/controllers/transactions/bookings_controller.rb index 0a6f7cbb..75eac975 100644 --- a/app/controllers/transactions/bookings_controller.rb +++ b/app/controllers/transactions/bookings_controller.rb @@ -9,7 +9,7 @@ class Transactions::BookingsController < ApplicationController to = params[:to] if filter.nil? && from.nil? && to.nil? - @bookings = Booking.order("sale_id desc") + @bookings = Booking.where("shop_code=?",@shop.shop_code).order("sale_id desc") @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(20) else booking = Booking.search(filter,from,to) diff --git a/app/controllers/transactions/credit_notes_controller.rb b/app/controllers/transactions/credit_notes_controller.rb index dac22d3e..9622e5e4 100755 --- a/app/controllers/transactions/credit_notes_controller.rb +++ b/app/controllers/transactions/credit_notes_controller.rb @@ -6,7 +6,7 @@ class Transactions::CreditNotesController < ApplicationController # GET /transactions/sales # GET /transactions/sales.json def index - + @sources = [["All",''], ["Cashier","cashier"],["Quick Service","quick_service"],["Online Order","doemal_order"]] @customers = Customer.all @@ -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) and sales.shop_code='#{@shop.shop_code}'") + THEN NULL ELSE payment_method='creditnote' END)").shop @credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20) else - sale = Sale.search_credit_sales(customer,filter,from,to,order_source).where("sales.shop_code='#{@shop.shop_code}'") + sale = Sale.search_credit_sales(customer,filter,from,to,order_source).shop 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 13e617bb..761ec761 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'").order("sale_id desc") + @sales = Sale.where("NOT sale_status='new'").shop.order("sale_id desc") else - @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").order("sale_id desc") + @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").shop.order("sale_id desc") end @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) else - sale = Sale.search(receipt_no,from,to,@shift) + sale = Sale.search(receipt_no,from,to,@shift).shop if sale.count > 0 @sales = sale @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) @@ -271,6 +271,10 @@ class Transactions::SalesController < ApplicationController sale.sale_status = 'void' sale.save + #call paymal to void + if !sale.sale_payments.nil? + membership_response =sale.paymal_payment_void + end # No Need # bookings = sale.bookings # bookings.each do |booking| diff --git a/app/models/booking.rb b/app/models/booking.rb index 2f85d211..9b1cea1a 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -11,6 +11,8 @@ class Booking < ApplicationRecord has_many :order_items, :through => :orders scope :active, -> {where("booking_status != 'moved'")} scope :today, -> {where("created_at >= #{Time.now.utc}")} + scope :shop, -> { where("bookings.shop_code=?",Shop.current_shop.shop_code) } + def self.sync_booking_records(bookings) if !bookings.nil? @@ -84,7 +86,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 - .order("sale_id DESC") + .shop.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 999bcc0b..a9cff636 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -7,6 +7,7 @@ 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/menu.rb b/app/models/menu.rb index a1b6d735..d9c98e01 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -8,6 +8,7 @@ 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 diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 9b51e4f3..6e6aa159 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -192,6 +192,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Use CUPS service #Generate PDF #Print + puts printer_settings.to_json if !printer_settings.nil? if !printer_settings.unique_code.strip.downcase.include? ("receiptbillorder") pdf = ReceiptBillPdf.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) diff --git a/app/models/sale.rb b/app/models/sale.rb index 90ed9f73..5b0b08d4 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -32,6 +32,7 @@ class Sale < ApplicationRecord scope :receipt_date_between, -> (from, to) { where(receipt_date: from..to) } scope :along_with_sale_payments_except_void_between, -> (from, to) { joins(sanitize_sql_array(["LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND sale_payments.created_at BETWEEN ? and ?", from, to])) } + scope :shop, -> { where("sales.shop_code=?",Shop.current_shop.shop_code) } def qty_of(item_instance_code) @@ -832,7 +833,7 @@ class Sale < ApplicationRecord return num end -def self.daily_sales_list(from,to,shop_code) +def self.daily_sales_list(from,to) sales = select(" sales.*, SUM(case when (sale_payments.payment_method='KBZPay') then sale_payments.payment_amount else 0 end) as kbzpay_amount, @@ -853,7 +854,7 @@ def self.daily_sales_list(from,to,shop_code) 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) + .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to).shop .group("sale_id").to_sql daily_total = connection.select_all("SELECT @@ -2431,39 +2432,40 @@ def self.get_check_sale_data(transaction_date) .group("sales.receipt_no,sales.sale_status") end def paymal_payment_void - puts self.sale_payments.to_json membership_setting = MembershipSetting.find_by_membership_type_and_shop_code("paypar_url",self.shop_code) membership_actions_data = MembershipAction.find_by_membership_type_and_shop_code("void",self.shop_code) if !membership_actions_data.nil? sale_payments =self.sale_payments.where("payment_reference is not null") - account_no =sale_payments[0].payment_reference - url = membership_setting.gateway_url.to_s + membership_actions_data.gateway_url.to_s - merchant_uid = membership_actions_data.merchant_account_id - auth_token = membership_actions_data.auth_token - params = { receipt_no:self.receipt_no, - account_no:account_no, - merchant_uid:merchant_uid, - auth_token:auth_token}.to_json + if !sale_payments.empty? + account_no =sale_payments[0].payment_reference + url = membership_setting.gateway_url.to_s + membership_actions_data.gateway_url.to_s + merchant_uid = membership_actions_data.merchant_account_id + auth_token = membership_actions_data.auth_token + params = { receipt_no:self.receipt_no, + account_no:account_no, + merchant_uid:merchant_uid, + auth_token:auth_token}.to_json - # Control for Paypar Cloud - begin - response = HTTParty.post(url, - :body => params, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json; version=3' - }, - :timeout => 10 - ) - rescue Errno::ECONNREFUSED - response = { "status" => false, "message" => "Can't open membership server"} - rescue Net::OpenTimeout - response = { "status" => false, "message" => "No internet connection " } - rescue OpenURI::HTTPError - response = { "status" => false, "message" => "No internet connection "} - rescue SocketError - response = { "status" => false, "message" => "No internet connection "} - end + # Control for Paypar Cloud + begin + response = HTTParty.post(url, + :body => params, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=3' + }, + :timeout => 10 + ) + rescue Errno::ECONNREFUSED + response = { "status" => false, "message" => "Can't open membership server"} + rescue Net::OpenTimeout + response = { "status" => false, "message" => "No internet connection " } + rescue OpenURI::HTTPError + response = { "status" => false, "message" => "No internet connection "} + rescue SocketError + response = { "status" => false, "message" => "No internet connection "} + end + end else response = { "status" => false} end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 96be1d56..25c533cd 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -655,7 +655,7 @@ class SalePayment < ApplicationRecord if spay.payment_method == KbzPay::KBZ_PAY is_kbz_pay = 1 end - if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" || spay.payment_method == KbzPay::KBZ_PAY + if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" || spay.payment_method == KbzPay::KBZ_PAY || spay.payment_method =="paymal" method_status = true end end @@ -954,14 +954,14 @@ class SalePayment < ApplicationRecord #credit payment query - def self.get_credit_sales(params,shop_code) + def self.get_credit_sales(params) payments = SalePayment.select("sale_payments.sale_id, sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount") .select("SUM(sale_payments.payment_amount) OVER (PARTITION BY sale_payments.sale_id) total_payment_amount") credit_sales = Sale.select("sales.sale_id, sales.receipt_no, sales.receipt_date as sale_date, sales.cashier_name") .select("sale_payments.sale_payment_id, sale_payments.payment_amount").select("customers.name as customer_name") .joins("JOIN (#{payments.to_sql}) AS sale_payments ON sale_payments.sale_id = sales.sale_id").joins(:customer).joins(:orders) - .completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount and sales.shop_code=?",shop_code) + .completed.paid.where("sale_payments.payment_method = 'creditnote' AND sales.grand_total > sale_payments.total_payment_amount - sale_payments.payment_amount").shop .group(:receipt_no) .order(:receipt_date).order(:receipt_no) diff --git a/app/models/sale_tax.rb b/app/models/sale_tax.rb index e84aa434..ac981d1e 100755 --- a/app/models/sale_tax.rb +++ b/app/models/sale_tax.rb @@ -28,10 +28,10 @@ class SaleTax < ApplicationRecord end end - def self.get_tax(from,to,shop_code) + def self.get_tax(from,to) query = SaleTax.select("sale_taxes.tax_name,SUM(sale_taxes.tax_payable_amount) as tax_amount") .joins("join sales on sales.sale_id = sale_taxes.sale_id") - .where("sales.shop_code='#{shop_code}' and sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0 AND inclusive = 0", 'completed', from, to) + .where("sales.shop_code=? and sale_status = ? AND sales.receipt_date between ? and ? AND total_amount != 0 AND inclusive = 0",Shop.current_shop.shop_code, 'completed', from, to) .group("sale_taxes.tax_name") end diff --git a/app/models/zone.rb b/app/models/zone.rb index daef0c8b..5d1c9309 100755 --- a/app/models/zone.rb +++ b/app/models/zone.rb @@ -4,6 +4,8 @@ class Zone < ApplicationRecord has_many :rooms, dependent: :destroy 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 1bab0c30..60ec7114 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -46,7 +46,13 @@ class ReceiptBillPdf < Prawn::Document header(shop_details) if sale_data.orders[0].source =='app' - text "Mobile Order", :size => self.header_font_size,:align => :left + y_position = cursor + bounding_box([0,y_position], :width =>self.description_width + self.price_num_width) do + text "Mobile Order", :size => self.header_font_size,:align => :left + end + bounding_box([self.description_width - 2,y_position], :width => self.price_num_width) do + text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.header_font_size,:align => :right,:style=>:bold + end move_down 1 text "Customer Ph : #{sale_data.customer.contact_no}", :size => self.header_font_size,:align => :left move_down 1 @@ -136,11 +142,12 @@ class ReceiptBillPdf < Prawn::Document bounding_box([0,y_position], :width =>self.description_width + self.price_num_width, :height => self.item_height) do text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left end - - if sale_data.bookings[0].dining_facility_id.to_i > 0 - bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do - text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right - end + if sale_data.orders[0].source !='app' + if sale_data.bookings[0].dining_facility_id.to_i > 0 + bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do + text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + end + end end move_down line_move diff --git a/app/views/foodcourt/addorders/detail.html.erb b/app/views/foodcourt/addorders/detail.html.erb index adeec6b4..73ee792e 100644 --- a/app/views/foodcourt/addorders/detail.html.erb +++ b/app/views/foodcourt/addorders/detail.html.erb @@ -440,82 +440,8 @@ - <% if type && !modify_order%> -