diff --git a/app/models/order.rb b/app/models/order.rb index c1b0583a..0bec3a1e 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -59,22 +59,26 @@ class Order < ApplicationRecord def adding_line_items if self.items + #re-order to + ordered_list = re_order_items(self.items) + #loop to add all items to order self.items.each do |item| menu_item = MenuItem.search_by_item_code(item[:item_instance_code]) - Rails.logger.debug menu_item - set_order_items = nil - ##If menu Item set item - must add child items to order as well, where price is only take from menu_item - if (menu_item[:type] == "SetMenuItem") - set_order_items - end - if (menu_item) + #if (!menu_item.nil?) + Rails.logger.debug menu_item + set_order_items = nil + ##If menu Item set item - must add child items to order as well, where price is only take from menu_item + if (menu_item[:type] == "SetMenuItem") + set_order_items + end OrderItem.processs_item(menu_item[:item_code], menu_item[:name], - item[:quantity],menu_item[:price], item[:options], set_order_items, self.id, - self.employee_name) - end + item[:quantity],menu_item[:price], item[:options], set_order_items, self.id, + self.employee_name) + + #end end self.item_count = self.order_items.count @@ -110,6 +114,69 @@ class Order < ApplicationRecord end + protected + def re_order_items(form_items) #reorder inputs items as parents and child + parent_id = Array.new + parents = Array.new + parents_and_children_items = Array.new + + new_items_list = Array.new + + form_items.each do |parent| + if !parent[:parent_order_item_id].nil? + if (!parent_id.include?(parent[:parent_order_item_id])) + parent_id.push(parent[:parent_order_item_id]) + + end + end + end + Rails.logger.debug "Parent Id count -> " + parent_id.count.to_s + + + parent_id.each do |pid| + form_items.each do |item| + Rails.logger.debug "Adding - Parents -> " + pid.to_s + " - " + item[:order_item_id].to_s + if (pid == item[:order_item_id]) + parents.push(item) + end + end + end + Rails.logger.debug "Parents count -> " + parents.count.to_s + + parents.each do |parent| + children = Array.new + form_items.each do |item| + if (parent[:order_item_id] == item[:parent_order_item_id] ) + children.push(item) + #Items to remove for new list + parents_and_children_items.push(item) + end + end + parent[:sub_items] = children + end + Rails.logger.debug "Parent/children Items to remove -> " + parents_and_children_items.count.to_s + + #Remove process items + #c = a.reject{ |e| b.include? e } + + new_items_list = form_items - parents_and_children_items + + + Rails.logger.debug "New list count -> " + new_items_list.count.to_s + + #Add parent to the list + #new_items_list = new_items_list + parents + + Rails.logger.debug "Re-Order List (Parent)-" + + Rails.logger.debug parents + + Rails.logger.debug "Re-Order List -" + Rails.logger.debug new_items_list + + return new_items_list + end + private def validate_api_inputs diff --git a/app/models/print_worker.rb b/app/models/print_worker.rb deleted file mode 100644 index 05084068..00000000 --- a/app/models/print_worker.rb +++ /dev/null @@ -1,20 +0,0 @@ -require 'cups' - -class PrintWorker - def self.printers() - Cups.show_destinations - end - - def self.default_printer() - Cups.default_printer - end - - def self.print_receipt_cashgo(sale,receipt_setting, printer_destination,order_id) - - pdf = CashPdf.new(sale,receipt_setting,order_id) - pdf.render_file "tmp/receipt_#{sale.receipt_no}" + ".pdf" - - page = Cups::PrintJob.new("tmp/receipt_#{sale.receipt_no}.pdf", printer_destination) - page.print - end -end diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 9ef0074e..5a41bade 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -217,6 +217,8 @@
This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.
+Last updated 3 mins ago
+