diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 86d50556..09d75f70 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -34,12 +34,11 @@ class Api::BillController < Api::ApiController # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) - # Calculate Food and Beverage Total - - food_total, beverage_total = SaleItem.calculate_food_beverage(@sale_items) + # Calculate Price by accounts + item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total) + printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts) end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index 18971247..64fd840d 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -82,7 +82,33 @@ class Oqs::HomeController < BaseOqsController end # Query for OQS with delivery status - def queue_items_query(status) + def queue_items_query(status) + # queue_items = [] + # AssignedOrderItem.all.each do |aoi| + # oqs = OrderQueueStation.find(aoi.order_queue_station_id) + # order = Order.find(aoi.order_id) + # order_items = OrderItem.find_by_order_id(aoi.order_id) + # booking_orders = BookingOrder.find_by_order_id(aoi.order_id) + # booking = Booking.find(booking_orders.booking_id) + # dining = DiningFacility.find(booking.dining_facility_id) + # customer = Customer.find_by_customer_id(order.customer_id) + # queue_item = { + # :assigned_order_item_id => aoi.assigned_order_item_id, + # :station_name => oqs.station_name, + # :is_active => oqs.is_active, + # :zone => dining.name, + # :item_code => aoi.item_code, + # :item_name => order_items.item_name, + # :price => order_items.price, + # :qty => order_items.qty, + # :item_order_by => order_items.item_order_by, + # :options => order_items.options, + # :customer_name => customer.name, + # :created_at => order_items.created_at + # } + # queue_items.push(queue_item) + # end + # return queue_items AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join orders as od ON od.order_id = assigned_order_items.order_id diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 6c0a4c8d..73038556 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -19,6 +19,8 @@ class Origami::DiscountsController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find(sale_id) + table_id = sale.bookings[0].dining_facility_id + table_type = DiningFacility.find(table_id).type 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; @@ -44,7 +46,10 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.save end end - end + end + + dining = {:table_id => table_id, :table_type => table_type } + render :json => dining.to_json end #discount for selected order diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 38225fae..00abc9aa 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -23,10 +23,10 @@ class Origami::PaymentsController < BaseOrigamiController # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) # Calculate Food and Beverage Total - food_total, beverage_total = SaleItem.calculate_food_beverage(saleObj.sale_items) + item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, food_total, beverage_total, member_info,rebate_amount) + printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, member_info,rebate_amount) end end @@ -94,11 +94,11 @@ class Origami::PaymentsController < BaseOrigamiController # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) - # Calculate Food and Beverage Total - food_total, beverage_total = SaleItem.calculate_food_beverage(saleObj.sale_items) + # Calculate price_by_accounts + item_price_by_accounts = SaleItem.calculate_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, food_total, beverage_total, member_info,rebate_amount) + printer.print_receipt_bill(print_settings,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, member_info,rebate_amount) end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 93453ffc..95f63e58 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -24,19 +24,19 @@ class Origami::RequestBillsController < BaseOrigamiController customer= Customer.find(@sale_data.customer_id) # get member information - member_info = Customer.get_member_account(customer) + member_info = Customer.get_member_account(customer) # get printer info print_settings=PrintSetting.find_by_unique_code(unique_code) # find order id by sale id # sale_order = SaleOrder.find_by_sale_id(@sale_data.sale_id) - # Calculate Food and Beverage Total - food_total, beverage_total = SaleItem.calculate_food_beverage(@sale_items) + # Calculate price_by_accounts + item_price_by_accounts = SaleItem.calculate_price_by_accounts(@sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, food_total, beverage_total,member_info) + printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer.name, item_price_by_accounts,member_info) # redirect_to origami_path(@sale_data.sale_id) end diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 2e85ecde..04619379 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -18,14 +18,15 @@ class OrderQueueStation < ApplicationRecord order_items = order.order_items # get dining - booking = Booking.find_by_dining_facility_id(dining.id) + booking = Booking.find_by_dining_facility_id(dining.id) #Assign OQS id to order Items - oqs_stations.each do |oqs| + oqs_stations.each do |oqs| + is_auto_printed = false #Get List of items - pq_items = JSON.parse(oqs.processing_items) - #Loop through the processing items + #Loop through the processing items pq_items.each do |pq_item| #Processing through the looping items order_items.each do |order_item| @@ -36,11 +37,13 @@ class OrderQueueStation < ApplicationRecord # else AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) - # end - - if oqs.auto_print + # end + + # Auto Printing + if oqs.auto_print && is_auto_printed == false print_slip(oqs, order, order_items) - end + is_auto_printed = true + end end end end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 969b9d44..4b7287db 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -65,11 +65,11 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Bill Receipt Print - def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name, food_total, beverage_total, member_info = nil,rebate_amount=nil) + def print_receipt_bill(printer_settings,sale_items,sale_data, customer_name, item_price_by_accounts, member_info = nil,rebate_amount=nil) #Use CUPS service #Generate PDF #Print - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info,rebate_amount) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, member_info,rebate_amount) pdf.render_file "tmp/receipt_bill.pdf" self.print("tmp/receipt_bill.pdf") diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index bec8b5c5..8881efea 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -30,9 +30,24 @@ class SaleItem < ApplicationRecord # end end - # Calculate food total and beverage total - def self.calculate_food_beverage(sale_items) + def self.calculate_price_by_accounts(sale_items) + price_accounts = [] + Account.all.each do |a| + account_price = {:name => a.title, :price => 0} + sale_items.each do |si| + if si.account_id == a.id + account_price[:price] = account_price[:price] + si.price + end + end + price_accounts.push(account_price) + end + + return price_accounts + end + + # Calculate rebate_by_account + def self.calculate_rebate_by_account(sale_items) rebateacc = Account.where("rebate=?",true) puts "Account that can rebate" rebateacc.each do |i| @@ -40,7 +55,7 @@ class SaleItem < ApplicationRecord end prices=0 sale_items.each do |si| - price = self.get_price(si.sale_item_id,rebateacc) + price = self.get_rebate_price(si.sale_item_id,rebateacc) prices = prices + price end @@ -48,7 +63,7 @@ class SaleItem < ApplicationRecord end # get food price or beverage price for item - def self.get_price(sale_item_id,rebateacc) + def self.get_rebate_price(sale_item_id,rebateacc) price=0 item=SaleItem.select("sale_items.price , menu_items.account_id") diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index f988b4e3..950334cb 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -265,7 +265,7 @@ class SalePayment < ApplicationRecord end def rebat(sObj) - rebate_prices = SaleItem.calculate_food_beverage(sObj.sale_items) + rebate_prices = SaleItem.calculate_rebate_by_account(sObj.sale_items) puts "eeeeeeeeeeeeeeeeeeeeeeee" puts rebate_prices generic_customer_id = sObj.customer.membership_id diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 749a8a16..4b7559b1 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -2,7 +2,7 @@ class OrderItemPdf < 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 def initialize(order_item, print_status, options) self.page_width = 210 - self.page_height = 2500 + self.page_height = 1450 self.margin = 5 self.price_width = 40 # No Need for item self.qty_width = 30 diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index b9c1f6fe..176749b8 100644 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -2,7 +2,7 @@ class OrderSummaryPdf < 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 def initialize(order, print_status) self.page_width = 210 - self.page_height = 2500 + self.page_height = 1450 self.margin = 5 self.price_width = 40 # No Need for item self.qty_width = 30 diff --git a/app/pdf/queue_no_pdf.rb b/app/pdf/queue_no_pdf.rb index 704dbfdb..0963f55e 100644 --- a/app/pdf/queue_no_pdf.rb +++ b/app/pdf/queue_no_pdf.rb @@ -2,7 +2,7 @@ class QueueNoPdf < 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 def initialize(printer_settings, queue) self.page_width = 210 - self.page_height = 2500 + self.page_height = 1450 self.margin = 5 self.price_width = 35 self.qty_width = 20 diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index bdeb58a3..96e16cf4 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,6 +1,6 @@ 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 - def initialize(printer_settings, sale_items, sale_data, customer_name, food_total, beverage_total, member_info = nil,rebate_amount = nil) + def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, member_info = nil,rebate_amount = nil) self.page_width = 210 self.page_height = 2500 self.margin = 5 @@ -29,7 +29,8 @@ class ReceiptBillPdf < Prawn::Document stroke_horizontal_rule cashier_info(sale_data, customer_name) - line_items(sale_items, food_total, beverage_total) + line_items(sale_items) + items_account(item_price_by_accounts) all_total(sale_data) @@ -103,26 +104,24 @@ class ReceiptBillPdf < Prawn::Document move_down 5 end - def line_items(sale_items, food_total, beverage_total) + def line_items(sale_items) y_position = cursor pad_top(15) { - # @item_width.to_i + @half_qty.to_i - text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix - text_box "Price", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "Qty", :at =>[(self.item_width+self.price_width),y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "Total", :at =>[(self.item_width+self.price_width+4),y_position], :width => self.total_width+3, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - - } + # @item_width.to_i + @half_qty.to_i + text_box "Items", :at =>[0,y_position], :width => self.item_width, :height =>self.item_height, :size => self.item_font_size, :overflow => :shrink_to_fix + text_box "Price", :at =>[self.item_width,y_position], :width => self.price_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "Qty", :at =>[(self.item_width+self.price_width),y_position], :width => self.qty_width, :height =>self.item_height, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "Total", :at =>[(self.item_width+self.price_width+4),y_position], :width => self.total_width+3, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + } move_down 5 stroke_horizontal_rule - add_line_item_row(sale_items, food_total, beverage_total) - + add_line_item_row(sale_items) end - def add_line_item_row(sale_items, food_total, beverage_total) + def add_line_item_row(sale_items) item_name_width = (self.item_width+self.price_width) y_position = cursor move_down 5 @@ -155,25 +154,26 @@ class ReceiptBillPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{ sub_total }" , :size => self.item_font_size,:align => :right - end - - # Food and Beverage - food_beverage_total = food_total.to_s + "/" + beverage_total.to_s - - move_down 5 + end + move_down 5 + end + def items_account(item_price_by_accounts) y_position = cursor - bounding_box([0,y_position], :width => self.item_description_width, :height => self.item_height) do - text "Food/Beverage Total", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width => self.label_width) do - text "#{ food_beverage_total }" , :size => self.item_font_size,:align => :right + item_price_by_accounts.each do |ipa| + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{ ipa[:price] }" , :size => self.item_font_size,:align => :right + end + move_down 5 end end def all_total(sale_data) item_name_width = self.item_width - move_down 5 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 4e4d2b77..45ab4b2b 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -80,7 +80,7 @@ -