diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index cefa64fb..b9b03c3e 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -102,7 +102,7 @@ $(function() { instances = menu_items[field].instances ; if (!instances.length > 0) { - swal("Hello Please Check!","doesn't not have instance item in this menu items ("+ menu_items[field].name+")","warning"); + swal("Hello Please Check!","Does not have instance item in this menu items ("+ menu_items[field].name+")","warning"); } if (instances.length > 0) { qty = 1; diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 4b58e52d..c12eb596 100755 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -6,7 +6,8 @@ class Api::BillController < Api::ApiController @status = false @error_message = "Order ID or Booking ID is require to request for a bill." - if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id) + # if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id) + if !ShiftSale.current_shift.nil? #create Bill by Booking ID table = 0 if (params[:booking_id]) @@ -41,8 +42,8 @@ class Api::BillController < Api::ApiController end # Bind shift sale id to sale - @sale_data.shift_sale_id = shift_by_terminal.id - @sale_data.save + # @sale_data.shift_sale_id = shift_by_terminal.id + # @sale_data.save Promotion.promo_activate(@sale) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 36d3ab43..9eb08f5f 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -93,6 +93,11 @@ class ApplicationController < ActionController::Base @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] end + # Get current Cashier + def get_cashier + @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + end + def current_company begin return Company.first diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 096af4d3..93a83be2 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -27,37 +27,40 @@ class Origami::HomeController < BaseOrigamiController @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all - @order_items_count = Hash.new - bookings = Booking.all - if !bookings.nil? - bookings.each do |booking| - if booking.sale_id.nil? && booking.booking_status != 'moved' - if !booking.booking_orders.empty? - booking.booking_orders.each do |booking_order| - order = Order.find(booking_order.order_id) - if !order.order_items.empty? - if !@order_items_count.key?(booking.dining_facility_id) - @order_items_count.store(booking.dining_facility_id, order.order_items.count) - else - @order_items_count[booking.dining_facility_id] += order.order_items.count - end - end - end - end - else - if !booking.sale_id.nil? - sale = Sale.find(booking.sale_id) - if sale.sale_status !='completed' - if !@order_items_count.key?(booking.dining_facility_id) - @order_items_count.store(booking.dining_facility_id, sale.sale_items.count) - else - @order_items_count[booking.dining_facility_id] += sale.sale_items.count - end - end - end - end - end - end + # bookings = Booking.all + # if !bookings.nil? + @order_items_count = Hash.new + # bookings.each do |booking| + # if booking.sale_id.nil? && booking.booking_status != 'moved' + # if !booking.booking_orders.empty? + # booking.booking_orders.each do |booking_order| + # order = Order.find(booking_order.order_id) + # if !order.order_items.empty? + # if !@order_items_count.key?(booking.dining_facility_id) + # @order_items_count.store(booking.dining_facility_id, order.order_items.count) + # else + # @order_items_count[booking.dining_facility_id] += order.order_items.count + # end + # end + # end + # end + # else + # if !booking.sale_id.nil? + # sale = Sale.find(booking.sale_id) + # if sale.sale_status !='completed' + # if !@order_items_count.key?(booking.dining_facility_id) + # @order_items_count.store(booking.dining_facility_id, sale.sale_items.count) + # else + # @order_items_count[booking.dining_facility_id] = sale.sale_items.count + # end + # end + # end + # end + # end + # end + + puts "@order_items_count" + puts @order_items_count.to_json @dining.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' diff --git a/app/controllers/origami/orders_controller.rb b/app/controllers/origami/orders_controller.rb index ec2f58ba..8e31c32b 100755 --- a/app/controllers/origami/orders_controller.rb +++ b/app/controllers/origami/orders_controller.rb @@ -13,36 +13,36 @@ class Origami::OrdersController < BaseOrigamiController end end - @order_items_count = Hash.new - bookings = Booking.all - if !bookings.nil? - bookings.each do |booking| - if booking.sale_id.nil? && booking.booking_status != 'moved' - if !booking.booking_orders.empty? - booking.booking_orders.each do |booking_order| - order = Order.find(booking_order.order_id) - if !order.order_items.empty? - if !@order_items_count.key?(booking.dining_facility_id) - @order_items_count.store(booking.dining_facility_id, order.order_items.count) - else - @order_items_count[booking.dining_facility_id] += order.order_items.count - end - end - end - end - else - if !booking.sale_id.nil? - sale = Sale.find(booking.sale_id) - if sale.sale_status !='completed' - if !@order_items_count.key?(booking.dining_facility_id) - @order_items_count.store(booking.dining_facility_id, sale.sale_items.count) - else - @order_items_count[booking.dining_facility_id] += sale.sale_items.count - end - end - end - end - end - end + # bookings = Booking.all + # if !bookings.nil? + # @order_items_count = Hash.new + # bookings.each do |booking| + # if booking.sale_id.nil? && booking.booking_status != 'moved' + # if !booking.booking_orders.empty? + # booking.booking_orders.each do |booking_order| + # order = Order.find(booking_order.order_id) + # if !order.order_items.empty? + # if !@order_items_count.key?(booking.dining_facility_id) + # @order_items_count.store(booking.dining_facility_id, order.order_items.count) + # else + # @order_items_count[booking.dining_facility_id] += order.order_items.count + # end + # end + # end + # end + # else + # if !booking.sale_id.nil? + # sale = Sale.find(booking.sale_id) + # if sale.sale_status !='completed' + # if !@order_items_count.key?(booking.dining_facility_id) + # @order_items_count.store(booking.dining_facility_id, sale.sale_items.count) + # else + # @order_items_count[booking.dining_facility_id] = sale.sale_items.count + # end + # end + # end + # end + # end + # end end end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index e0f1d06c..39ef789a 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -5,16 +5,15 @@ class Origami::RequestBillsController < ApplicationController @sale = Sale.new sale_order=SaleOrder.new - if shift = ShiftSale.current_open_shift(current_user.id) + # if shift = ShiftSale.current_open_shift(current_user.id)SSS + if !ShiftSale.current_shift.nil? order_id = params[:id] # order_id bk_order = BookingOrder.find_by_order_id(order_id) check_booking = Booking.find_by_booking_id(bk_order.booking_id) if check_booking.sale_id.nil? # Create Sale if it doesn't exist - # puts "current_login_employee" - # puts current_login_employee.name - @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, cashier = nil) + @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user) @sale_data = Sale.find_by_sale_id(@sale_id) @sale_items = SaleItem.where("sale_id=?",@sale_id) else @@ -23,8 +22,8 @@ class Origami::RequestBillsController < ApplicationController end # Bind shift sale id to sale - @sale_data.shift_sale_id = shift.id - @sale_data.save + # @sale_data.shift_sale_id = shift.id + # @sale_data.save # Promotion Activation Promotion.promo_activate(@sale) @@ -55,4 +54,10 @@ class Origami::RequestBillsController < ApplicationController # printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info,shop_details) end + + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index 68cb8798..124479aa 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -22,38 +22,38 @@ class Origami::RoomsController < BaseOrigamiController @shop = Shop::ShopDetail @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all - - @order_items_count = Hash.new - bookings = Booking.all - if !bookings.nil? - bookings.each do |booking| - if booking.sale_id.nil? && booking.booking_status != 'moved' - if !booking.booking_orders.empty? - booking.booking_orders.each do |booking_order| - order = Order.find(booking_order.order_id) - if !order.order_items.empty? - if !@order_items_count.key?(booking.dining_facility_id) - @order_items_count.store(booking.dining_facility_id, order.order_items.count) - else - @order_items_count[booking.dining_facility_id] += order.order_items.count - end - end - end - end - else - if !booking.sale_id.nil? - sale = Sale.find(booking.sale_id) - if sale.sale_status !='completed' - if !@order_items_count.key?(booking.dining_facility_id) - @order_items_count.store(booking.dining_facility_id, sale.sale_items.count) - else - @order_items_count[booking.dining_facility_id] += sale.sale_items.count - end - end - end - end - end - end + + # bookings = Booking.all + # if !bookings.nil? + @order_items_count = Hash.new + # bookings.each do |booking| + # if booking.sale_id.nil? && booking.booking_status != 'moved' + # if !booking.booking_orders.empty? + # booking.booking_orders.each do |booking_order| + # order = Order.find(booking_order.order_id) + # if !order.order_items.empty? + # if !@order_items_count.key?(booking.dining_facility_id) + # @order_items_count.store(booking.dining_facility_id, order.order_items.count) + # else + # @order_items_count[booking.dining_facility_id] += order.order_items.count + # end + # end + # end + # end + # else + # if !booking.sale_id.nil? + # sale = Sale.find(booking.sale_id) + # if sale.sale_status !='completed' + # if !@order_items_count.key?(booking.dining_facility_id) + # @order_items_count.store(booking.dining_facility_id, sale.sale_items.count) + # else + # @order_items_count[booking.dining_facility_id] = sale.sale_items.count + # end + # end + # end + # end + # end + # end @room.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 52b2068c..aa36067b 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -40,16 +40,25 @@ class Origami::VoidController < BaseOrigamiController # end table_avaliable = true + table_count = 0 table = sale.bookings[0].dining_facility table.bookings.each do |booking| - if !booking.sale.nil? - if booking.sale.sale_status == 'new' + if booking.booking_status != 'moved' + if booking.sale_id + if booking.sale.sale_status != 'completed' && booking.sale.sale_status != 'void' + table_avaliable = false + table_count += 1 + else + table_avaliable = true + end + else table_avaliable = false + table_count += 1 end end end - if table_avaliable + if table_avaliable && table_count == 0 table.status = 'available' table.save end diff --git a/app/models/sale.rb b/app/models/sale.rb index f42b62a0..f07a8a2f 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -78,12 +78,25 @@ class Sale < ApplicationRecord self.tax_type = "exclusive" # set cashier - if cashier != nil + open_cashier = Employee.where("role = 'cashier' AND token_session <> ''") + current_shift = ShiftSale.current_shift + shift = ShiftSale.current_open_shift(cashier.id) + + # set cashier + if shift != nil self.cashier_id = cashier.id self.cashier_name = cashier.name + self.shift_sale_id = shift.id else - self.cashier_id = requested_by.id - self.cashier_name = requested_by.name + if open_cashier.nil? + self.cashier_id = requested_by.id + self.cashier_name = requested_by.name + self.shift_sale_id = current_shift.id + else + self.cashier_id = current_shift.employee_id + self.cashier_name = Employee.find(current_shift.employee_id).name + self.shift_sale_id = current_shift.id + end end # set waiter @@ -743,7 +756,7 @@ def self.get_item_query() query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item,i.qty as qty," + "i.remark as status_type,"+ - " mii.price as unit_price,i.price as price,i.product_name as product_name, mc.name as" + + " i.unit_price,i.price as price,i.product_name as product_name, mc.name as" + " menu_category_name,mc.id as menu_category_id ") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + @@ -754,7 +767,7 @@ def self.get_item_query() # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id") # query = query.where("i.item_instance_code IS NOT NULL") - query = query.group("acc.title,mi.account_id,mi.menu_category_id,i.product_name") + query = query.group("acc.title,mi.account_id,mi.menu_category_id,i.product_name,i.unit_price") .order("acc.title desc, mi.account_id desc, mi.menu_category_id desc, i.unit_price asc") end diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 9e9873d2..5211061e 100755 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -1,7 +1,7 @@ class OrderSummaryPdf < Prawn::Document include ActionView::Helpers::NumberHelper 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 - def initialize(print_settings,order, print_status, order_items = nil,alt_name) + def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height self.margin = 0 diff --git a/app/pdf/order_summary_set_pdf.rb b/app/pdf/order_summary_set_pdf.rb index baab15b8..619b81ab 100644 --- a/app/pdf/order_summary_set_pdf.rb +++ b/app/pdf/order_summary_set_pdf.rb @@ -1,7 +1,7 @@ class OrderSummarySetPdf < Prawn::Document include ActionView::Helpers::NumberHelper 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 - def initialize(print_settings,order, print_status, order_items = nil,alt_name) + def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height self.margin = 0 diff --git a/app/pdf/order_summary_slim_pdf.rb b/app/pdf/order_summary_slim_pdf.rb index 87aba403..b4b850fa 100644 --- a/app/pdf/order_summary_slim_pdf.rb +++ b/app/pdf/order_summary_slim_pdf.rb @@ -1,7 +1,7 @@ class OrderSummarySlimPdf < Prawn::Document include ActionView::Helpers::NumberHelper 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 - def initialize(print_settings,order, print_status, order_items = nil,alt_name) + def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height self.margin = 0 diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 96f69da9..1dbe960f 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -396,7 +396,7 @@ var othertotal = parseFloat(credit1) + parseFloat(card1) + parseFloat(paypar1) + parseFloat(visa1) + parseFloat(jcb1) + parseFloat(master1) + parseFloat(unionpay1); var total = $('#amount_due').text(); var amt = parseFloat(total) - parseFloat(othertotal); - $('#cash').text(parseFloat(amt).toFixed(2)); + $('#cash').text(parseFloat(amt).toFixed(1)); update_balance(); break; } @@ -485,7 +485,7 @@ $( "#loading_wrapper" ).hide(); if($('#balance').text() < 0){ swal({ - title: "Information!", + title: "Payment Successful!", text: 'Changed amount ' + $('#balance').text() * (-1), html: true, closeOnConfirm: false, @@ -497,7 +497,7 @@ }else{ $('#pay').text("Pay"); swal({ - title: "Information!", + title: "Payment Successful!", text: 'Thank You !', html: true, closeOnConfirm: false,