From d910c4078bc3bec66d464b302f32e77777981494 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Thu, 24 May 2018 17:02:54 +0630 Subject: [PATCH 1/3] Add Order item & summary customise font pdf --- README.md | 11 ++ app/controllers/api/orders_controller.rb | 6 + app/controllers/oqs/edit_controller.rb | 6 + app/controllers/oqs/print_controller.rb | 12 ++ app/models/order_queue_station.rb | 12 ++ app/models/printer/order_queue_printer.rb | 30 +++++ app/models/printer/receipt_printer.rb | 36 ++++++ app/pdf/order_item_customise_pdf.rb | 145 +++++++++++++++++++++ app/pdf/order_summary_customise_pdf.rb | 147 ++++++++++++++++++++++ 9 files changed, 405 insertions(+) create mode 100644 app/pdf/order_item_customise_pdf.rb create mode 100644 app/pdf/order_summary_customise_pdf.rb diff --git a/README.md b/README.md index 146f216e..4e817c7a 100755 --- a/README.md +++ b/README.md @@ -53,6 +53,17 @@ For Order Item & Order Summary Slim app/models/printer/receipt_printer.rb } +For Order Item & Order Summary Customise PDF + *** change OrderItemPdf to OrderItemCustomisePdf and OrderSummaryPdf to OrderSummaryCustomisePdf + 1) settings/lookups => { type:print_settings, name:OrderCustomisePdf, value:1 } + * no need to change these files + { app/controllers/oqs/edit_controller.rb + app/controllers/oqs/print_controller.rb + app/models/order_queue_station.rb + app/models/printer/order_queue_printer.rb + app/models/printer/receipt_printer.rb + * Can change Header font size and Item Font Size as you like + For ReceiptBillA5Pdf *** change ReceiptBillPdf to ReceiptBillA5Pdf 1) settings/print_settings , width:680, height:1450, Header font Size:16, Item font size:14 diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 49afe833..1e010007 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -244,6 +244,12 @@ class Api::OrdersController < Api::ApiController else unique_code="OrderItemPdf" end + elsif order_item_slim[0] == 'OrderCustomisePdf' + if order_item_slim[1] == '1' + unique_code="OrderItemCustomisePdf" + else + unique_code="OrderItemPdf" + end end end end diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index 73458b82..49addea1 100644 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -65,6 +65,12 @@ class Oqs::EditController < BaseOqsController else unique_code="OrderItemPdf" end + elsif order_item_slim[0] == 'OrderCustomisePdf' + if order_item_slim[1] == '1' + unique_code="OrderItemCustomisePdf" + else + unique_code="OrderItemPdf" + end end end end diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index bf5b803a..1fd3f7f1 100755 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -20,6 +20,12 @@ class Oqs::PrintController < ApplicationController else unique_code="OrderItemPdf" end + elsif order_item_slim[0] == 'OrderCustomisePdf' + if order_item_slim[1] == '1' + unique_code="OrderItemCustomisePdf" + else + unique_code="OrderItemPdf" + end end end end @@ -68,6 +74,12 @@ class Oqs::PrintController < ApplicationController else unique_code="OrderSummaryPdf" end + elsif order_summary_slim[0] == 'OrderCustomisePdf' + if order_summary_slim[1] == '1' + unique_code="OrderSummaryCustomisePdf" + else + unique_code="OrderSummaryPdf" + end end end end diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index d731c3d2..54435658 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -223,6 +223,12 @@ class OrderQueueStation < ApplicationRecord else unique_code="OrderSummaryPdf" end + elsif order_summary_slim[0] == 'OrderCustomisePdf' + if order_summary_slim[1] == '1' + unique_code="OrderSummaryCustomisePdf" + else + unique_code="OrderSummaryPdf" + end end end end @@ -257,6 +263,12 @@ class OrderQueueStation < ApplicationRecord else unique_code="OrderItemPdf" end + elsif order_item_slim[0] == 'OrderCustomisePdf' + if order_item_slim[1] == '1' + unique_code="OrderItemCustomisePdf" + else + unique_code="OrderItemPdf" + end end end end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 62e6f0a7..f00d898f 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -32,6 +32,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker else pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) end + elsif order_item_slim[0] == 'OrderCustomisePdf' + if order_item_slim[1] == '1' + pdf = OrderItemCustomisePdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) + else + pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) + end end end end @@ -97,6 +103,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker else pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) end + elsif order_item_slim[0] == 'OrderCustomisePdf' + if order_item_slim[1] == '1' + pdf = OrderItemCustomisePdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) + else + pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) + end end end end @@ -136,6 +148,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker else pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) end + elsif order_summary_slim[0] == 'OrderCustomisePdf' + if order_summary_slim[1] == '1' + pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) + else + pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) + end end end end @@ -195,6 +213,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker else pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) end + elsif order_item_slim[0] == 'OrderCustomisePdf' + if order_item_slim[1] == '1' + pdf = OrderItemCustomisePdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) + else + pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) + end end end end @@ -236,6 +260,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker else pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) end + elsif order_summary_slim[0] == 'OrderCustomisePdf' + if order_summary_slim[1] == '1' + pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) + else + pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) + end end end end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 8562fca6..b9a693aa 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -20,6 +20,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker else pdf = OrderItemPdf.new end + elsif order_item_slim[0] == 'OrderCustomisePdf' + if order_item_slim[1] == '1' + pdf = OrderItemCustomisePdf.new + else + pdf = OrderItemPdf.new + end end end end @@ -51,6 +57,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker else pdf = OrderSummaryPdf.new end + elsif order_summary_slim[0] == 'OrderCustomisePdf' + if order_summary_slim[1] == '1' + pdf = OrderSummaryCustomisePdf.new + else + pdf = OrderSummaryPdf.new + end end end end @@ -82,6 +94,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker else pdf = OrderSummaryPdf.new end + elsif order_summary_slim[0] == 'OrderCustomisePdf' + if order_summary_slim[1] == '1' + pdf = OrderSummaryCustomisePdf.new + else + pdf = OrderSummaryPdf.new + end end end end @@ -113,6 +131,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker else pdf = OrderSummaryPdf.new end + elsif order_summary_slim[0] == 'OrderCustomisePdf' + if order_summary_slim[1] == '1' + pdf = OrderSummaryCustomisePdf.new + else + pdf = OrderSummaryPdf.new + end end end end @@ -144,6 +168,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker else pdf = OrderSummaryPdf.new end + elsif order_summary_slim[0] == 'OrderCustomisePdf' + if order_summary_slim[1] == '1' + pdf = OrderSummaryCustomisePdf.new + else + pdf = OrderSummaryPdf.new + end end end end @@ -175,6 +205,12 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker else pdf = OrderSummaryPdf.new end + elsif order_summary_slim[0] == 'OrderCustomisePdf' + if order_summary_slim[1] == '1' + pdf = OrderSummaryCustomisePdf.new + else + pdf = OrderSummaryPdf.new + end end end end diff --git a/app/pdf/order_item_customise_pdf.rb b/app/pdf/order_item_customise_pdf.rb new file mode 100644 index 00000000..4124a075 --- /dev/null +++ b/app/pdf/order_item_customise_pdf.rb @@ -0,0 +1,145 @@ +class OrderItemCustomisePdf < 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,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width + def initialize(print_settings,order_item, print_status, options, alt_name, before_updated_qty) + self.page_width = print_settings.page_width + self.page_height = print_settings.page_height + self.header_font_size = print_settings.header_font_size.to_i + self.item_font_size = print_settings.item_font_size.to_i + self.order_no_font_size = 8 + self.margin = 0 + self.price_width = 40 # No Need for item + self.qty_width = 40 + self.total_width = 40 # No Need for item + self.item_width = self.page_width - (self.qty_width - self.margin) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) + self.label_width=90 + + super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + # super(:margin => [10, 5, 30, 5], :page_size => [200,400]) + + # db font setup + if print_settings.font != "" + font_families.update("#{print_settings.font}" => { + :normal => "public/fonts/#{print_settings.font}.ttf", + :italic => "public/fonts/#{print_settings.font}.ttf", + :bold => "public/fonts/#{print_settings.font}.ttf", + :bold_italic => "public/fonts/#{print_settings.font}.ttf" + }) + + font "#{print_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + end + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" + if !order_item.dining.nil? + text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + + stroke_horizontal_rule + move_down 3 + + #order_info + order_info(order_item.order_id, order_item.order_by,order_item.order_at) + + # order items + order_items(order_item, options, alt_name, print_settings.precision, before_updated_qty) + end + + # Write Order Information to PDF + def order_info(order_no, order_by, order_at) + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left + end + + stroke_horizontal_rule + + move_down 10 + end + + # Write Order items to PDF + def order_items(order_item, options, alt_name, precision, before_updated_qty) + y_position = cursor + + #Add Order Item + add_order_items(order_item, options, alt_name, precision) + + dash(1, :space => 1, :phase => 1) + stroke_horizontal_line 0, (self.page_width - self.margin) + add_updated_qty_text(before_updated_qty, order_item.qty, precision) + move_down 5 + end + + # Add order items under order info + def add_order_items(order_item, options, alt_name, precision) + y_position = cursor + + move_down 5 + + bounding_box([0,y_position], :width => self.item_width) do + text "#{order_item.item_code} - #{order_item.item_name}", :size => self.item_font_size,:align => :left + end + + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text "[#{number_with_precision(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + end + + bounding_box([0,y_position], :width => self.item_width) do + text "#{order_item.item_code} - #{order_item.item_name}", :size => self.item_font_size,:align => :left + + end + + if alt_name + if order_item.alt_name + move_down 4 + font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{order_item.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + end + end + end + + if !options.empty? + move_down 5 + + # add option + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "#{options}", :size => self.item_font_size,:align => :left + end + end + + move_down 5 + + end + + #add updated qty text + def add_updated_qty_text(before_updated_qty, updated_qty, precision) + if before_updated_qty.to_i > 0 && !before_updated_qty.nil? + move_down 5 + + # add option + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "* Change quantity [#{number_with_precision(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_with_precision(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + end + end + end + +end diff --git a/app/pdf/order_summary_customise_pdf.rb b/app/pdf/order_summary_customise_pdf.rb new file mode 100644 index 00000000..666d6755 --- /dev/null +++ b/app/pdf/order_summary_customise_pdf.rb @@ -0,0 +1,147 @@ +class OrderSummaryCustomisePdf < 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,:order_no_font_size,:item_height,:qty_width,:total_width,:item_description_width + 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.header_font_size = print_settings.header_font_size.to_i + self.item_font_size = print_settings.item_font_size.to_i + self.order_no_font_size = 8 + self.margin = 0 + self.price_width = 40 # No Need for item + self.qty_width = 40 + self.total_width = 40 # No Need for item + self.item_width = self.page_width - (self.qty_width - self.margin) + self.item_height = 15 + self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) + self.label_width=90 + + super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + # db font setup + if print_settings.font != "" + font_families.update("#{print_settings.font}" => { + :normal => "public/fonts/#{print_settings.font}.ttf", + :italic => "public/fonts/#{print_settings.font}.ttf", + :bold => "public/fonts/#{print_settings.font}.ttf", + :bold_italic => "public/fonts/#{print_settings.font}.ttf" + }) + + font "#{print_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + end + + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + + if !order[0].dining.nil? + text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + + stroke_horizontal_rule + move_down 5 + + #order_info + order_info(order[0].order_id, order[0].order_by,order[0].order_at) + + # order items + if order_items == nil + order_items(order, alt_name, print_settings.precision) + else + order_items(order_items, alt_name, print_settings.precision) + end + end + + # Write Order Information to PDF + def order_info(order_no, order_by, order_at) + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "OrderBy: #{order_by} ", :size => self.order_no_font_size,:align => :left + end + + move_down 1 + y_position = cursor + bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.order_no_font_size,:align => :left + end + + stroke_horizontal_rule + + move_down 10 + end + + # Write Order items to PDF + def order_items(order_item, alt_name, precision) + y_position = cursor + + #Add Order Item + add_order_items(order_item, alt_name, precision) + + end + + # Add order items under order info + def add_order_items(order_item, alt_name, precision) + y_position = cursor + + move_down 5 + + order_item.each do|odi| + # check for item not to show + # if odi.price != 0 + y_position = cursor + + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left + + end + + bounding_box([self.item_width,y_position], :width => self.qty_width) do + text " [#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + end + + bounding_box([0,y_position], :width => self.item_width) do + text "#{odi.item_code} - #{odi.item_name}", :size => self.item_font_size,:align => :left + + end + + if alt_name + if !(odi.alt_name).empty? + move_down 4 + font("public/fonts/NotoSansCJKtc-Regular.ttf") do + text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true + end + end + + end + + # add option + options = odi.options == "[]"? "" : odi.options + + if options != "" + move_down 5 + + y_position = cursor + bounding_box([0,y_position], :width => self.item_width) do + text "#{options}", :size => self.item_font_size,:align => :left + end + + move_down 5 + end + + move_down 5 + + dash(1, :space => 1, :phase => 1) + stroke_horizontal_line 0, (self.page_width - self.margin) + move_down 5 + # end + end + end +end From f906134fbfd75b5a76c2c5e854a3a8bdb25ee834 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Fri, 25 May 2018 16:06:10 +0630 Subject: [PATCH 2/3] Remove lookup settings in Order Pdf --- README.md | 51 ++--- app/controllers/api/orders_controller.rb | 26 +-- app/controllers/oqs/edit_controller.rb | 38 ++-- app/controllers/oqs/print_controller.rb | 49 ++--- app/models/order_queue_station.rb | 72 +++----- app/models/printer/order_queue_printer.rb | 207 ++++++++------------- app/models/printer/receipt_printer.rb | 216 ++++++++-------------- 7 files changed, 243 insertions(+), 416 deletions(-) diff --git a/README.md b/README.md index 4e817c7a..fd8ad10d 100755 --- a/README.md +++ b/README.md @@ -39,30 +39,26 @@ For Extra Time * must start with 'Ext'[a..z]'_'[1..100] * note : don't add character after '_' -For Order Item & Order Summary Slim - *** change OrderItemPdf to OrderItemSlimPdf and OrderSummaryPdf to OrderSummarySlimPdf - 1) settings/print_settings - (a) Font is present => {Header font size:11, Item Font Size:9} - (b) Font is blank => {Header font size:12, Item Font Size:10} - 2) settings/lookups => { type:print_settings, name:OrderSlimPdf, value:1 } - * no need to change these files - { app/controllers/oqs/edit_controller.rb - app/controllers/oqs/print_controller.rb - app/models/order_queue_station.rb - app/models/printer/order_queue_printer.rb - app/models/printer/receipt_printer.rb - } - -For Order Item & Order Summary Customise PDF - *** change OrderItemPdf to OrderItemCustomisePdf and OrderSummaryPdf to OrderSummaryCustomisePdf - 1) settings/lookups => { type:print_settings, name:OrderCustomisePdf, value:1 } - * no need to change these files - { app/controllers/oqs/edit_controller.rb - app/controllers/oqs/print_controller.rb - app/models/order_queue_station.rb - app/models/printer/order_queue_printer.rb - app/models/printer/receipt_printer.rb - * Can change Header font size and Item Font Size as you like +For Order Printing + 1)) ********* Order Pdf ********* + 1) settings/print_settings + (a) Unique Code => OrderItemPdf & OrderSummaryPdf + (b) Font is present => {Header font size:11, Item Font Size:9} + Font is blank => {Header font size:12, Item Font Size:10} + 2)) ********* Order Set Pdf ********* + 1) settings/print_settings + (a) Unique Code => OrderSetItemPdf & OrderSummarySetPdf + (b) Font is present => {Header font size:11, Item Font Size:9} + Font is blank => {Header font size:12, Item Font Size:10} + 3)) ********* Order Slim Pdf ********* + 1) settings/print_settings + (a) Unique Code => OrderItemSlimPdf & OrderSummarySlimPdf + (b) Font is present => {Header font size:11, Item Font Size:9} + Font is blank => {Header font size:12, Item Font Size:10} + 4)) ********* Order Customise PDF ********* + 1) settings/print_settings + (a) Unique Code => OrderItemCustomisePdf & OrderSummaryCustomisePdf + (b) Can change Header font size and Item Font Size as you like For ReceiptBillA5Pdf *** change ReceiptBillPdf to ReceiptBillA5Pdf @@ -72,13 +68,6 @@ For ReceiptBillA5Pdf For ReceiptBillAltName options 1) settings/lookups => { type:print_settings, name:ReceiptBillAltName, value:1 } -For OrderSetPdf options - *** change OrderItemPdf to OrderSetItemPdf and OrderSummaryPdf to OrderSummarySetPdf - 1) settings/lookups => { type:print_settings, name:OrderSetPdf, value:1 } - 2) settings/print_settings - (a) Font is present => {Header font size:11, Item Font Size:9} - (b) Font is blank => {Header font size:12, Item Font Size:10} - For Bank Integration setting 1) rake db:migrate for card_sale_trans, card_settle_trans 2) settings/lookups => { type:bank_integration, name: Bank Integration, value:1 } diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 1e010007..187d1139 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -227,32 +227,24 @@ class Api::OrdersController < Api::ApiController # order queue stations oqs = assign_item.order_queue_station - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all unique_code="OrderItemPdf" if !order_slim_pdf.empty? - order_slim_pdf.each do |order_item_slim| - if order_item_slim[0] == 'OrderSlimPdf' - if order_item_slim[1] == '1' + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderItemPdf' + unique_code="OrderItemPdf" + elsif printer_setting.unique_code == 'OrderItemSlimPdf' unique_code="OrderItemSlimPdf" - else - unique_code="OrderItemPdf" - end - elsif order_item_slim[0] == 'OrderSetPdf' - if order_item_slim[1] == '1' + elsif printer_setting.unique_code == 'OrderSetItemPdf' unique_code="OrderSetItemPdf" - else - unique_code="OrderItemPdf" - end - elsif order_item_slim[0] == 'OrderCustomisePdf' - if order_item_slim[1] == '1' + elsif printer_setting.unique_code == 'OrderItemCustomisePdf' unique_code="OrderItemCustomisePdf" - else - unique_code="OrderItemPdf" end end end - end + end print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index 49addea1..f86db74b 100644 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -48,32 +48,22 @@ class Oqs::EditController < BaseOqsController # order queue stations oqs = assign_item.order_queue_station - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf - + printer = PrintSetting.all + unique_code="OrderItemPdf" - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_item_slim| - if order_item_slim[0] == 'OrderSlimPdf' - if order_item_slim[1] == '1' - unique_code="OrderItemSlimPdf" - else - unique_code="OrderItemPdf" - end - elsif order_item_slim[0] == 'OrderSetPdf' - if order_item_slim[1] == '1' - unique_code="OrderSetItemPdf" - else - unique_code="OrderItemPdf" - end - elsif order_item_slim[0] == 'OrderCustomisePdf' - if order_item_slim[1] == '1' - unique_code="OrderItemCustomisePdf" - else - unique_code="OrderItemPdf" - end - end + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderItemPdf' + unique_code="OrderItemPdf" + elsif printer_setting.unique_code == 'OrderItemSlimPdf' + unique_code="OrderItemSlimPdf" + elsif printer_setting.unique_code == 'OrderSetItemPdf' + unique_code="OrderSetItemPdf" + elsif printer_setting.unique_code == 'OrderItemCustomisePdf' + unique_code="OrderItemCustomisePdf" + end end - end + end print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb index 1fd3f7f1..170add96 100755 --- a/app/controllers/oqs/print_controller.rb +++ b/app/controllers/oqs/print_controller.rb @@ -4,32 +4,24 @@ class Oqs::PrintController < ApplicationController def print if ENV["SERVER_MODE"] != "cloud" #no print in cloud server order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all unique_code="OrderItemPdf" - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_item_slim| - if order_item_slim[0] == 'OrderSlimPdf' - if order_item_slim[1] == '1' + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderItemPdf' + unique_code="OrderItemPdf" + elsif printer_setting.unique_code == 'OrderItemSlimPdf' unique_code="OrderItemSlimPdf" - else - unique_code="OrderItemPdf" - end - elsif order_item_slim[0] == 'OrderSetPdf' - if order_item_slim[1] == '1' + elsif printer_setting.unique_code == 'OrderSetItemPdf' unique_code="OrderSetItemPdf" - else - unique_code="OrderItemPdf" - end - elsif order_item_slim[0] == 'OrderCustomisePdf' - if order_item_slim[1] == '1' + elsif printer_setting.unique_code == 'OrderItemCustomisePdf' unique_code="OrderItemCustomisePdf" - else - unique_code="OrderItemPdf" end end end end - + assigned_item_id = params[:id] options = params[:options] assigned_item = AssignedOrderItem.find(assigned_item_id) @@ -59,26 +51,19 @@ class Oqs::PrintController < ApplicationController def print_order_summary if ENV["SERVER_MODE"] != "cloud" #no print in cloud server order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all unique_code="OrderSummaryPdf" if !order_slim_pdf.empty? - order_slim_pdf.each do |order_summary_slim| - if order_summary_slim[0] == 'OrderSlimPdf' - if order_summary_slim[1] == '1' + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderSummaryPdf' + unique_code="OrderSummaryPdf" + elsif printer_setting.unique_code == 'OrderSummarySlimPdf' unique_code="OrderSummarySlimPdf" - else - unique_code="OrderSummaryPdf" - end - elsif order_summary_slim[0] == 'OrderSetPdf' - if order_summary_slim[1] == '1' + elsif printer_setting.unique_code == 'OrderSummarySetPdf' unique_code="OrderSummarySetPdf" - else - unique_code="OrderSummaryPdf" - end - elsif order_summary_slim[0] == 'OrderCustomisePdf' - if order_summary_slim[1] == '1' + elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf' unique_code="OrderSummaryCustomisePdf" - else - unique_code="OrderSummaryPdf" end end end diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index 54435658..0f67349f 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -207,31 +207,21 @@ class OrderQueueStation < ApplicationRecord private #Print order_items in 1 slip def print_slip(oqs, order, order_items) - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all unique_code="OrderSummaryPdf" - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_summary_slim| - if order_summary_slim[0] == 'OrderSlimPdf' - if order_summary_slim[1] == '1' - unique_code="OrderSummarySlimPdf" - else - unique_code="OrderSummaryPdf" - end - elsif order_summary_slim[0] == 'OrderSetPdf' - if order_summary_slim[1] == '1' - unique_code="OrderSummarySetPdf" - else - unique_code="OrderSummaryPdf" - end - elsif order_summary_slim[0] == 'OrderCustomisePdf' - if order_summary_slim[1] == '1' - unique_code="OrderSummaryCustomisePdf" - else - unique_code="OrderSummaryPdf" - end - end + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderSummaryPdf' + unique_code="OrderSummaryPdf" + elsif printer_setting.unique_code == 'OrderSummarySlimPdf' + unique_code="OrderSummarySlimPdf" + elsif printer_setting.unique_code == 'OrderSummarySetPdf' + unique_code="OrderSummarySetPdf" + elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf' + unique_code="OrderSummaryCustomisePdf" + end end - end + end print_settings=PrintSetting.find_by_unique_code(unique_code) order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) @@ -247,31 +237,21 @@ class OrderQueueStation < ApplicationRecord #Print order_item in 1 slip per item def print_slip_item(oqs, order, assigned_items) - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all unique_code="OrderItemPdf" - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_item_slim| - if order_item_slim[0] == 'OrderSlimPdf' - if order_item_slim[1] == '1' - unique_code="OrderItemSlimPdf" - else - unique_code="OrderItemPdf" - end - elsif order_item_slim[0] == 'OrderSetPdf' - if order_item_slim[1] == '1' - unique_code="OrderSetItemPdf" - else - unique_code="OrderItemPdf" - end - elsif order_item_slim[0] == 'OrderCustomisePdf' - if order_item_slim[1] == '1' - unique_code="OrderItemCustomisePdf" - else - unique_code="OrderItemPdf" - end - end + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderItemPdf' + unique_code="OrderItemPdf" + elsif printer_setting.unique_code == 'OrderItemSlimPdf' + unique_code="OrderItemSlimPdf" + elsif printer_setting.unique_code == 'OrderSetItemPdf' + unique_code="OrderSetItemPdf" + elsif printer_setting.unique_code == 'OrderItemCustomisePdf' + unique_code="OrderItemCustomisePdf" + end end - end + end # order_item = OrderItem.where("order_id='#{assigned_item.order_id}' AND item_instance_code='#{assigned_item.instance_code}'").first() # print when complete click diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index f00d898f..e4e493b7 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -15,52 +15,43 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker filename = "tmp/order_item_#{order_id}_#{order_item_id}" + ".pdf" pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + print_setting = PrintSetting.all + # check for item not to show - # if order_item[0].price != 0 - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_item_slim| - if order_item_slim[0] == 'OrderSlimPdf' - if order_item_slim[1] == '1' - pdf = OrderItemSlimPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) - else - pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) - end - elsif order_item_slim[0] == 'OrderSetPdf' - if order_item_slim[1] == '1' - pdf = OrderSetItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) - else - pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) - end - elsif order_item_slim[0] == 'OrderCustomisePdf' - if order_item_slim[1] == '1' - pdf = OrderItemCustomisePdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) - else - pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) - end + if order_item[0].price != 0 + if !print_setting.empty? + print_setting.each do |print_settings| + if print_settings.unique_code == 'OrderItemPdf' + pdf = OrderItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) + elsif print_settings.unique_code == 'OrderItemSlimPdf' + pdf = OrderItemSlimPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) + elsif print_settings.unique_code == 'OrderSetItemPdf' + pdf = OrderSetItemPdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) + elsif print_settings.unique_code == 'OrderItemCustomisePdf' + pdf = OrderItemCustomisePdf.new(print_settings,order_item[0], print_status, options, oqs.use_alternate_name, before_updated_qty) end end end + end - pdf.render_file filename + pdf.render_file filename - if oqs.print_copy - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(filename, oqs.printer_name) - end - #For print copy - # pdf.render_file filename.gsub(".","-copy.") - # self.print(filename.gsub(".","-copy."), oqs.printer_name) - else - print_settings.print_copies = 1 - print_settings.save! - #no print in cloud server - if ENV["SERVER_MODE"] != "cloud" - self.print(filename, oqs.printer_name) - end - end - # end + if oqs.print_copy + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end + #For print copy + # pdf.render_file filename.gsub(".","-copy.") + # self.print(filename.gsub(".","-copy."), oqs.printer_name) + else + print_settings.print_copies = 1 + print_settings.save! + #no print in cloud server + if ENV["SERVER_MODE"] != "cloud" + self.print(filename, oqs.printer_name) + end + end end # Query for per order @@ -74,8 +65,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker print_settings.save! end - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf - + print_setting = PrintSetting.all order=print_query('order_summary', order_id) # For Print Per Item if oqs.cut_per_item @@ -88,30 +78,21 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # check for item not to show #if odi.price != 0 - pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_item_slim| - if order_item_slim[0] == 'OrderSlimPdf' - if order_item_slim[1] == '1' - pdf = OrderItemSlimPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) - end - elsif order_item_slim[0] == 'OrderSetPdf' - if order_item_slim[1] == '1' - pdf = OrderSetItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) - end - elsif order_item_slim[0] == 'OrderCustomisePdf' - if order_item_slim[1] == '1' - pdf = OrderItemCustomisePdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) - end + pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) + if !print_setting.empty? + print_setting.each do |print_settings| + if print_settings.unique_code == 'OrderItemPdf' + pdf = OrderItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderItemSlimPdf' + pdf = OrderItemSlimPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderSetItemPdf' + pdf = OrderSetItemPdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderItemCustomisePdf' + pdf = OrderItemCustomisePdf.new(print_settings,odi_item[0], print_status, options, oqs.use_alternate_name,before_updated_qty) end end - end + end + # pdf.render_file "tmp/order_item.pdf" pdf.render_file filename if oqs.print_copy @@ -134,29 +115,19 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker else filename = "tmp/order_summary_#{order_id}" + ".pdf" pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_summary_slim| - if order_summary_slim[0] == 'OrderSlimPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySlimPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) - end - elsif order_summary_slim[0] == 'OrderSetPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySetPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) - end - elsif order_summary_slim[0] == 'OrderCustomisePdf' - if order_summary_slim[1] == '1' - pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) - end + if !print_setting.empty? + print_setting.each do |print_settings| + if print_settings.unique_code == 'OrderSummaryPdf' + pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderSummarySlimPdf' + pdf = OrderSummarySlimPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderSummarySetPdf' + pdf = OrderSummarySetPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderSummaryCustomisePdf' + pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name,before_updated_qty) end end - end + end pdf.render_file filename if oqs.print_copy @@ -186,7 +157,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker print_settings.save! end - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + print_setting = PrintSetting.all order=print_query('booking_summary', booking_id) # For Print Per Item @@ -199,29 +170,19 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # check for item not to show #if odi.price != 0 pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_item_slim| - if order_item_slim[0] == 'OrderSlimPdf' - if order_item_slim[1] == '1' - pdf = OrderItemSlimPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) - end - elsif order_item_slim[0] == 'OrderSetPdf' - if order_item_slim[1] == '1' - pdf = OrderSetItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) - end - elsif order_item_slim[0] == 'OrderCustomisePdf' - if order_item_slim[1] == '1' - pdf = OrderItemCustomisePdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) - end + if !print_setting.empty? + print_setting.each do |print_settings| + if print_settings.unique_code == 'OrderItemPdf' + pdf = OrderItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderItemSlimPdf' + pdf = OrderItemSlimPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderSetItemPdf' + pdf = OrderSetItemPdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderItemCustomisePdf' + pdf = OrderItemCustomisePdf.new(print_settings,odi, print_status, options,oqs.use_alternate_name,before_updated_qty) end end - end + end pdf.render_file filename if oqs.print_copy @@ -246,29 +207,19 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker else filename = "tmp/booking_summary_#{booking_id}" + ".pdf" pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_summary_slim| - if order_summary_slim[0] == 'OrderSlimPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySlimPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) - end - elsif order_summary_slim[0] == 'OrderSetPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySetPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) - end - elsif order_summary_slim[0] == 'OrderCustomisePdf' - if order_summary_slim[1] == '1' - pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) - else - pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) - end + if !print_setting.empty? + print_setting.each do |print_settings| + if print_settings.unique_code == 'OrderSummaryPdf' + pdf = OrderSummaryPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderSummarySlimPdf' + pdf = OrderSummarySlimPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderSummarySetPdf' + pdf = OrderSummarySetPdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) + elsif print_settings.unique_code == 'OrderSummaryCustomisePdf' + pdf = OrderSummaryCustomisePdf.new(print_settings,order, print_status,oqs.use_alternate_name,before_updated_qty) end end - end + end pdf.render_file filename if oqs.print_copy diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index b9a693aa..24ac1259 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -4,31 +4,21 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Use CUPS service #Generate PDF #Print - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all pdf = OrderItemPdf.new - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_item_slim| - if order_item_slim[0] == 'OrderSlimPdf' - if order_item_slim[1] == '1' - pdf = OrderItemSlimPdf.new - else - pdf = OrderItemPdf.new - end - elsif order_item_slim[0] == 'OrderSetPdf' - if order_item_slim[1] == '1' - pdf = OrderSetItemPdf.new - else - pdf = OrderItemPdf.new - end - elsif order_item_slim[0] == 'OrderCustomisePdf' - if order_item_slim[1] == '1' - pdf = OrderItemCustomisePdf.new - else - pdf = OrderItemPdf.new - end - end + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderItemPdf' + pdf = OrderItemPdf.new + elsif printer_setting.unique_code == 'OrderItemSlimPdf' + pdf = OrderItemSlimPdf.new + elsif printer_setting.unique_code == 'OrderSetItemPdf' + pdf = OrderSetItemPdf.new + elsif printer_setting.unique_code == 'OrderItemCustomisePdf' + pdf = OrderItemCustomisePdf.new + end end - end + end pdf.render_file "tmp/order_item_queue_#{order_id}_#{order_item_id}" + ".pdf" #no print in cloud server if ENV["SERVER_MODE"] != "cloud" @@ -41,31 +31,21 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Generate PDF #Print filename = "tmp/order_summary_#{booking_id}" + ".pdf" - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all pdf = OrderSummaryPdf.new - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_summary_slim| - if order_summary_slim[0] == 'OrderSlimPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySlimPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderSetPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySetPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderCustomisePdf' - if order_summary_slim[1] == '1' - pdf = OrderSummaryCustomisePdf.new - else - pdf = OrderSummaryPdf.new - end - end + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderSummaryPdf' + pdf = OrderSummaryPdf.new + elsif printer_setting.unique_code == 'OrderSummarySlimPdf' + pdf = OrderSummarySlimPdf.new + elsif printer_setting.unique_code == 'OrderSummarySetPdf' + pdf = OrderSummarySetPdf.new + elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf' + pdf = OrderSummaryCustomisePdf.new + end end - end + end pdf.render_file filename #no print in cloud server if ENV["SERVER_MODE"] != "cloud" @@ -77,32 +57,22 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Use CUPS service #Generate PDF #Print - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all filename = "tmp/order_summary_#{booking_id}" + ".pdf" pdf = OrderSummaryPdf.new - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_summary_slim| - if order_summary_slim[0] == 'OrderSlimPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySlimPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderSetPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySetPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderCustomisePdf' - if order_summary_slim[1] == '1' - pdf = OrderSummaryCustomisePdf.new - else - pdf = OrderSummaryPdf.new - end - end + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderSummaryPdf' + pdf = OrderSummaryPdf.new + elsif printer_setting.unique_code == 'OrderSummarySlimPdf' + pdf = OrderSummarySlimPdf.new + elsif printer_setting.unique_code == 'OrderSummarySetPdf' + pdf = OrderSummarySetPdf.new + elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf' + pdf = OrderSummaryCustomisePdf.new + end end - end + end pdf.render_file filename #no print in cloud server if ENV["SERVER_MODE"] != "cloud" @@ -114,32 +84,22 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Use CUPS service #Generate PDF #Print - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all filename = "tmp/order_summary_#{booking_id}" + ".pdf" pdf = OrderSummaryPdf.new - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_summary_slim| - if order_summary_slim[0] == 'OrderSlimPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySlimPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderSetPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySetPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderCustomisePdf' - if order_summary_slim[1] == '1' - pdf = OrderSummaryCustomisePdf.new - else - pdf = OrderSummaryPdf.new - end - end + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderSummaryPdf' + pdf = OrderSummaryPdf.new + elsif printer_setting.unique_code == 'OrderSummarySlimPdf' + pdf = OrderSummarySlimPdf.new + elsif printer_setting.unique_code == 'OrderSummarySetPdf' + pdf = OrderSummarySetPdf.new + elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf' + pdf = OrderSummaryCustomisePdf.new + end end - end + end pdf.render_file filename #no print in cloud server if ENV["SERVER_MODE"] != "cloud" @@ -151,32 +111,22 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Use CUPS service #Generate PDF #Print - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all filename = "tmp/order_summary_#{booking_id}" + ".pdf" pdf = OrderSummaryPdf.new - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_summary_slim| - if order_summary_slim[0] == 'OrderSlimPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySlimPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderSetPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySetPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderCustomisePdf' - if order_summary_slim[1] == '1' - pdf = OrderSummaryCustomisePdf.new - else - pdf = OrderSummaryPdf.new - end - end + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderSummaryPdf' + pdf = OrderSummaryPdf.new + elsif printer_setting.unique_code == 'OrderSummarySlimPdf' + pdf = OrderSummarySlimPdf.new + elsif printer_setting.unique_code == 'OrderSummarySetPdf' + pdf = OrderSummarySetPdf.new + elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf' + pdf = OrderSummaryCustomisePdf.new + end end - end + end pdf.render_file filename #no print in cloud server if ENV["SERVER_MODE"] != "cloud" @@ -188,32 +138,22 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Use CUPS service #Generate PDF #Print - order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + printer = PrintSetting.all filename = "tmp/order_summary_#{booking_id}" + ".pdf" pdf = OrderSummaryPdf.new - if !order_slim_pdf.empty? - order_slim_pdf.each do |order_summary_slim| - if order_summary_slim[0] == 'OrderSlimPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySlimPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderSetPdf' - if order_summary_slim[1] == '1' - pdf = OrderSummarySetPdf.new - else - pdf = OrderSummaryPdf.new - end - elsif order_summary_slim[0] == 'OrderCustomisePdf' - if order_summary_slim[1] == '1' - pdf = OrderSummaryCustomisePdf.new - else - pdf = OrderSummaryPdf.new - end - end + if !printer.empty? + printer.each do |printer_setting| + if printer_setting.unique_code == 'OrderSummaryPdf' + pdf = OrderSummaryPdf.new + elsif printer_setting.unique_code == 'OrderSummarySlimPdf' + pdf = OrderSummarySlimPdf.new + elsif printer_setting.unique_code == 'OrderSummarySetPdf' + pdf = OrderSummarySetPdf.new + elsif printer_setting.unique_code == 'OrderSummaryCustomisePdf' + pdf = OrderSummaryCustomisePdf.new + end end - end + end pdf.render_file filename #no print in cloud server if ENV["SERVER_MODE"] != "cloud" From 578c14ccc33f1b81ed26786975a543a308256fd0 Mon Sep 17 00:00:00 2001 From: San Wai Lwin Date: Fri, 25 May 2018 16:22:30 +0630 Subject: [PATCH 3/3] Pull from master --- app/assets/javascripts/addorder.js | 11 +- .../javascripts/settings/processing_items.js | 4 - app/assets/stylesheets/addorder.scss | 19 +- app/assets/stylesheets/origami.scss | 5 + .../order_reservation_controller.rb | 2 +- app/controllers/api/orders_controller.rb | 3 + app/controllers/api/survey_controller.rb | 4 +- .../origami/order_reservation_controller.rb | 12 +- .../origami/payments_controller.rb | 24 +- .../origami/product_commissions_controller.rb | 82 ++--- app/models/ability.rb | 3 + app/models/commission.rb | 2 +- app/models/order.rb | 133 ++++---- app/models/product_commission.rb | 5 +- app/models/sale.rb | 106 +++---- app/pdf/receipt_bill_a5_pdf.rb | 6 +- app/pdf/receipt_bill_pdf.rb | 7 +- .../restaurant/menu/_menu_item.json.jbuilder | 2 +- app/views/origami/addorders/detail.html.erb | 8 +- .../origami/dashboard/_menu.json.jbuilder | 11 +- app/views/origami/payments/show.html.erb | 125 +++++++- .../load_commissioners.html.erb | 12 +- app/views/reports/commission/index.html.erb | 2 +- app/views/reports/dailysale/index.xls.erb | 297 +++++++++--------- config/routes.rb | 2 + lib/tasks/clear_data.rake | 7 +- 26 files changed, 536 insertions(+), 358 deletions(-) diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 3be2f34d..3fea4c6b 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1012,12 +1012,14 @@ $(function() { //calculate subtotal function calculate_sub_total(){ var total_price = 0; + var total_qty = 0; var taxable_amount = 0; var item_row = $('.summary-items tbody tr'); $(item_row).each(function(i){ var unit_price = parseFloat($(item_row[i]).attr('data-price')); var qty = parseFloat($(item_row[i]).children('#item_qty').text()); + total_qty += qty; total_price += qty*unit_price; }); var fixed_total_price = parseFloat(total_price).toFixed(2); @@ -1026,6 +1028,9 @@ $(function() { $('#sub_total').empty(); $('#sub_total').append(fixed_total_price); + $('#total_qty').empty(); + $('#total_qty').append(total_qty); + if (item_row.length > 0) { $('.create').removeAttr("disabled", false); }else{ @@ -1432,7 +1437,8 @@ $(function() { } } - row = '
' + row = '
' + +'
' +'
' +'
'+ menu_items[field].name +'
' +"
' +''+ price +'' +'
' - +'
'; + +'
' + +'
'; ; $('.menu_items_list').append(row); } //end instances in menu-items alest 1 instance diff --git a/app/assets/javascripts/settings/processing_items.js b/app/assets/javascripts/settings/processing_items.js index 1dc5e97f..e43aedde 100755 --- a/app/assets/javascripts/settings/processing_items.js +++ b/app/assets/javascripts/settings/processing_items.js @@ -1,7 +1,6 @@ $(document).ready(function() { $(".processitems").click(function(event){ event.preventDefault(); - console.log($(this).data("id")); var item = $(this).data("id"); $(this).toggleClass("opi_selected"); @@ -13,7 +12,6 @@ $(document).ready(function() { console.log($(this).data("id")); var group_id = $(this).data("id"); var selector = "#" + group_id + " li div"; - console.log ($(selector)); $(selector).removeClass("opi_selected"); $(selector).addClass("opi_selected"); @@ -25,7 +23,6 @@ $(document).ready(function() { console.log($(this).data("id")); var group_id = $(this).data("id"); var selector = "#" + group_id + " li div"; - console.log ($(selector)); $(selector).removeClass("opi_selected"); }); @@ -36,7 +33,6 @@ $(document).ready(function() { var items = new Array(); selected_div = $(".opi_selected"); $.each( selected_div, function( key, value ) { - console.log($(value).attr("data-id")); items.push($(value).attr("data-id")); }); diff --git a/app/assets/stylesheets/addorder.scss b/app/assets/stylesheets/addorder.scss index 929ffb13..36ea4e33 100755 --- a/app/assets/stylesheets/addorder.scss +++ b/app/assets/stylesheets/addorder.scss @@ -12,6 +12,7 @@ section .content{ } .custom-card { border: 2px solid rgba(0, 0, 0, 0.125) !important; + margin-bottom: 7px !important; } .custom-card-footer{ padding:0.35rem 1.25rem !important; @@ -72,16 +73,26 @@ section .content{ .nav-tabs { background-color: #ccc; } +.nav-tabs li a.active{ + border-bottom:1px solid #54A5AF !important; +} .nav-tabs .nav-link { padding: 0.7286rem 0.2575; border-top-left-radius: 0rem; border-top-right-radius: 0rem; } + +.nav-tabs .nav-link:focus, .nav-tabs .nav-link:hover { + color: #54A5AF #54A5AF #54A5AF; +} +.nav-tabs .nav-link.active:focus, .nav-tabs .nav-link.active:hover { + background-color: #009688; +} .nav-tabs .nav-link.active, .nav-tabs .nav-item.show .nav-link { - background-color: #a1aade; - border-left: 6px solid #111; - color:#54A5AF; - font-weight: bold; + background-color: #fff !important; + border-left: 6px solid #54A5AF !important; + color: #54A5AF !important; + font-weight: bold !important; border-color: #fff #fff #fff #54A5AF; } .sub_category_list{ diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 855ee984..7ce4e1ed 100755 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -462,4 +462,9 @@ iframe { /* section class for webview */ .section-margin { margin-top: -50px; +} + +.tax-btn-box { + width: 230px; + height: 80px; } \ No newline at end of file diff --git a/app/controllers/api/order_reserve/order_reservation_controller.rb b/app/controllers/api/order_reserve/order_reservation_controller.rb index 32e87a20..97c44df9 100644 --- a/app/controllers/api/order_reserve/order_reservation_controller.rb +++ b/app/controllers/api/order_reserve/order_reservation_controller.rb @@ -63,7 +63,7 @@ class Api::OrderReserve::OrderReservationController < Api::ApiController order_reservation = params order_reservation_id, flag = OrderReservation.addOrderReservationInfo(order_reservation) - if flag #&& ENV["SERVER_MODE"] != 'cloud' + if flag shop = Shop.find_by_id(1) if !shop.shop_code.nil? shop_code = shop.shop_code diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 187d1139..0c3703fe 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -117,6 +117,9 @@ class Api::OrdersController < Api::ApiController end @status, @booking = @order.generate + if @status && @booking + Order.process_order_queue(@order.order_id,@order.table_id,@order.source) + end # # for parallel order # remoteIP = "" # begin diff --git a/app/controllers/api/survey_controller.rb b/app/controllers/api/survey_controller.rb index 27fe327d..06c9f643 100644 --- a/app/controllers/api/survey_controller.rb +++ b/app/controllers/api/survey_controller.rb @@ -18,8 +18,8 @@ class Api::SurveyController < Api::ApiController cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id) shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) - if params[:id] - survey = Survey.find(params[:id]) + if params[:survey][:id] + survey = Survey.find(params[:survey][:id]) else survey = Survey.new end diff --git a/app/controllers/origami/order_reservation_controller.rb b/app/controllers/origami/order_reservation_controller.rb index a3421fbd..ea760e33 100644 --- a/app/controllers/origami/order_reservation_controller.rb +++ b/app/controllers/origami/order_reservation_controller.rb @@ -48,8 +48,16 @@ class Origami::OrderReservationController < BaseOrigamiController end def send_status - response = OrderReservation.send_status_to_ordering(params[:url],params[:ref_no],params[:status],params[:waiting_time],params[:min_type],params[:reason]) - + order_reservation = OrderReservation.find_by_transaction_ref(params[:ref_no]) + if !order_reservation.nil? + if !ShiftSale.current_shift.nil? || params[:status] == 'accepted' || (order_reservation.status == 'new' && params[:status] == 'rejected') + response = OrderReservation.send_status_to_ordering(params[:url],params[:ref_no],params[:status],params[:waiting_time],params[:min_type],params[:reason]) + else + response = { status: false, message: 'No current shift open for this employee!'} + end + else + response = { status: false, message: 'There is no order for '+params[:ref_no]+'!'} + end render :json => response end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 045afafb..313cc10c 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -96,6 +96,8 @@ class Origami::PaymentsController < BaseOrigamiController cash = params[:cash] sale_id = params[:sale_id] member_info = nil + type = params[:type] + tax_type = params[:tax_type] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) @@ -298,11 +300,18 @@ class Origami::PaymentsController < BaseOrigamiController # accounts = @customer.tax_profiles accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") @account_arr =[] + @tax_arr =[] accounts.each do |acc| account = TaxProfile.find(acc.id) - @account_arr.push(account) + # @account_arr.push(account) + @tax_arr.push(account.name) + end + sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id) + if !sale_taxes.empty? + sale_taxes.each do |sale_tax| + @account_arr.push(sale_tax) + end end - rebate = MembershipSetting.find_by_rebate(1) # get member information if @customer.membership_id != nil && rebate @@ -571,4 +580,15 @@ class Origami::PaymentsController < BaseOrigamiController render :json => result.to_json # render :json => {status: true} end + + #changable tax for sale + def change_tax + sale_id = params[:sale_id] + order_source = params[:cashier_type] + tax_type = params[:tax_type] + sale = Sale.find(sale_id) + sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount,nil,order_source,tax_type) + + render json: JSON.generate({:status => true}) + end end \ No newline at end of file diff --git a/app/controllers/origami/product_commissions_controller.rb b/app/controllers/origami/product_commissions_controller.rb index 1156827a..a9c74b70 100755 --- a/app/controllers/origami/product_commissions_controller.rb +++ b/app/controllers/origami/product_commissions_controller.rb @@ -83,54 +83,66 @@ class Origami::ProductCommissionsController < BaseOrigamiController def set_commissioner_to_sale_item # byebug - deselect = false - sale_item_id = params[:sale_item_id] + deselect = false + type = nil + sale_item_id = params[:sale_item_id] commissioner_id = params[:commissioner_id] - @sale_item = SaleItem.find(sale_item_id) - @menu_item = MenuItem.find_by_item_code(@sale_item.product_code) + @sale_item = SaleItem.find(sale_item_id) + @menu_item = MenuItem.find_by_item_code(@sale_item.product_code) # @commission = Commission.where('product_code = ? AND is_active = ?', @menu_item.item_code, true).take - Commission.all.each do |com| - if com.product_code.include? @menu_item.item_code && com.is_active == true - @commission = Commission.find(com.id) - break + Commission.all.active.each do |com| + if com.product_code != "[]" + if com.product_code.to_s.include? @menu_item.item_code + @commission = Commission.find(com.id) + break + end end end - @commissioner = Commissioner.where('id = ? AND is_active = ?', commissioner_id, true).take + @commissioner = Commissioner.where('id = ? AND is_active = ?', commissioner_id, true).take @product_commission = ProductCommission.where('sale_item_id = ?', @sale_item.id).take + if !@commission.nil? && @commissioner.commission_id == @commission.commission_id if !@product_commission.nil? - if @product_commission.commissioner_id == @commissioner.id - @product_commission.destroy - deselect = true - else - @product_commission.commissioner_id = @commissioner.id - deselect = false - end - else - @product_commission = ProductCommission.new - @product_commission.product_code = @menu_item.item_code - @product_commission.product_type = 'menu_item' # use for dummy data ToDo::need to change product type - unless @commission.nil? - @product_commission.commission_id = @commission.id - if @commission.commission_type == 'Percentage' - @product_commission.price = @sale_item.unit_price * (@commission.amount / 100.0) - @product_commission.amount = @product_commission.price * @sale_item.qty - elsif @commission.commission_type == 'Net Amount' - @product_commission.price = @commission.amount - @product_commission.amount = @product_commission.price * @sale_item.qty + if @product_commission.commissioner_id == @commissioner.id + @product_commission.destroy + deselect = true + type = "remove" + # render json: {status: true,deselect:deselect, message: "Remove Success !"} + else + @product_commission.commissioner_id = @commissioner.id + deselect = false end - end - @product_commission.commissioner_id = @commissioner.id - @product_commission.qty = @sale_item.qty - @product_commission.sale_id = @sale_item.sale_id - @product_commission.sale_item_id = @sale_item.sale_item_id + else + @product_commission = ProductCommission.new + @product_commission.product_code = @menu_item.item_code + @product_commission.product_type = 'menu_item' # use for dummy data ToDo::need to change product type + unless @commission.nil? + @product_commission.commission_id = @commission.id + if @commission.commission_type == 'Percentage' + @product_commission.price = @sale_item.unit_price * (@commission.amount / 100.0) + @product_commission.amount = @product_commission.price * @sale_item.qty + elsif @commission.commission_type == 'Net Amount' + @product_commission.price = @commission.amount + @product_commission.amount = @product_commission.price * @sale_item.qty + end + end + @product_commission.commissioner_id = @commissioner.id + @product_commission.qty = @sale_item.qty + @product_commission.sale_id = @sale_item.sale_id + @product_commission.sale_item_id = @sale_item.sale_item_id end if @product_commission.save - render json: {status: true, deselect: deselect} + message = "Success !" + if type == "remove" + message = "Remove Success !" + end + render json: {status: true, deselect:deselect,type:type,message: message} else - render json: {status: false, deselect: deselect} + render json: {status: false, deselect:deselect,type:type,message: "No Commission"} end + else + render json: {status: false, deselect:deselect,type:type,message: "No Commission"} end end diff --git a/app/models/ability.rb b/app/models/ability.rb index fbf66f57..9f1f105b 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -71,6 +71,7 @@ class Ability can :rounding_adj, :payment can :foc, :payment can :print, :payment + can :change_tax, :payment can :move_dining, :movetable can :moving, :movetable @@ -154,6 +155,7 @@ class Ability can :rounding_adj, :payment can :foc, :payment can :print, :payment + can :change_tax, :payment can :move_dining, :movetable can :moving, :movetable @@ -249,6 +251,7 @@ class Ability can :rounding_adj, :payment can :print, :payment can :foc, :payment + can :change_tax, :payment can :manage, Commission can :manage, Commissioner diff --git a/app/models/commission.rb b/app/models/commission.rb index e331eb59..32aa8a04 100755 --- a/app/models/commission.rb +++ b/app/models/commission.rb @@ -10,7 +10,7 @@ class Commission < ApplicationRecord # validations validates_presence_of :name, :commission_type, :amount - + scope :active, -> {where(is_active: true)} private def generate_custom_id self.commission_id = SeedGenerator.generate_id(self.class.name, 'COM') diff --git a/app/models/order.rb b/app/models/order.rb index 9a52942e..5edc778a 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -301,13 +301,6 @@ class Order < ApplicationRecord end # end end - - def check_cup_status(status) - if status.include? "Active: active (running)" || "Active: active (exited)" #"Cup Server is already running" - return true - end - return false - end #send order items and send to order queue def send_order_broadcast(booking) @@ -317,10 +310,10 @@ class Order < ApplicationRecord #Send to background job for processing # OrderBroadcastJob.perform_later(table,type) if ENV["SERVER_MODE"] == 'cloud' - from = request.subdomain + "." + request.domain - else - from = "" - end + from = request.subdomain + "." + request.domain + else + from = "" + end ActionCable.server.broadcast "order_channel",table: table,type:type,from:from end @@ -485,68 +478,74 @@ class Order < ApplicationRecord end #Process order items and send to order queue - # def process_order_queue - # print_status = nil - # cup_status = nil + def self.process_order_queue(order_id,table_id,source) + print_status = nil + cup_status = nil - # #Send to background job for processing - # order = Order.find(self.id) - # sidekiq = Lookup.find_by_lookup_type("sidekiq") + #Send to background job for processing + order = Order.find(order_id) + sidekiq = Lookup.find_by_lookup_type("sidekiq") - # if ENV["SERVER_MODE"] != 'cloud' - # cup_status = `#{"sudo service cups status"}` - # print_status = check_cup_status(cup_status) - # end + if ENV["SERVER_MODE"] != 'cloud' + cup_status = `#{"sudo service cups status"}` + print_status = check_cup_status(cup_status) + end - # if print_status - # if !sidekiq.nil? - # OrderQueueProcessorJob.perform_later(self.id, self.table_id) - # else - # if order - # oqs = OrderQueueStation.new - # oqs.process_order(order, self.table_id, self.source) - # end - # # assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) - # # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order - # end - # else - # if ENV["SERVER_MODE"] != 'cloud' - # cup_start = `#{"sudo service cups start"}` - # cup_status = `#{"sudo service cups status"}` - # print_status = check_cup_status(cup_status) - # end + if print_status + if !sidekiq.nil? + OrderQueueProcessorJob.perform_later(order_id, table_id) + else + if order + oqs = OrderQueueStation.new + oqs.process_order(order, table_id, source) + end + # assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) + # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + end + else + if ENV["SERVER_MODE"] != 'cloud' + cup_start = `#{"sudo service cups start"}` + cup_status = `#{"sudo service cups status"}` + print_status = check_cup_status(cup_status) + end - # if print_status - # if !sidekiq.nil? - # OrderQueueProcessorJob.perform_later(self.id, self.table_id) - # else - # if order - # oqs = OrderQueueStation.new - # oqs.process_order(order, self.table_id, self.source) - # end - # # assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) - # # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order - # end - # else - # if ENV["SERVER_MODE"] != 'cloud' + if print_status + if !sidekiq.nil? + OrderQueueProcessorJob.perform_later(order_id, table_id) + else + if order + oqs = OrderQueueStation.new + oqs.process_order(order, table_id, source) + end + # assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) + # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + end + else + if ENV["SERVER_MODE"] != 'cloud' - # msg = ' Print Error ! Please contact to service' - # ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' - # end - # if !sidekiq.nil? - # OrderQueueProcessorJob.perform_later(self.id, self.table_id) - # else - # if order - # oqs = OrderQueueStation.new - # oqs.process_order(order, self.table_id, self.source) - # end - # assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) - # ActionCable.server.broadcast "order_queue_station_channel",order: assign_order - # end - # end - # end - # end + msg = ' Print Error ! Please contact to service' + ActionCable.server.broadcast "call_waiter_channel",table: msg,time:'print_error' + end + if !sidekiq.nil? + OrderQueueProcessorJob.perform_later(order_id, table_id) + else + if order + oqs = OrderQueueStation.new + oqs.process_order(order, table_id, source) + end + assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) + ActionCable.server.broadcast "order_queue_station_channel",order: assign_order + end + end + end + end + def self.check_cup_status(status) + if status.include? "Active: active (running)" || "Active: active (exited)" #"Cup Server is already running" + return true + end + return false + end private diff --git a/app/models/product_commission.rb b/app/models/product_commission.rb index c865c674..9f91673a 100755 --- a/app/models/product_commission.rb +++ b/app/models/product_commission.rb @@ -61,9 +61,10 @@ class ProductCommission < ApplicationRecord end def self.get_transaction(from, to, commissioner) - transaction = all + transaction = ProductCommission.select("product_commissions.*,menu_items.name as porduct_name") + .joins("join menu_items on menu_items.item_code = product_commissions.product_code") if !from.nil? && !to.nil? - transaction = transaction.where('updated_at between ? and ?', from, to) + transaction = transaction.where('product_commissions.updated_at between ? and ?', from, to) end if commissioner != 0 transaction = transaction.where(commissioner_id: commissioner) diff --git a/app/models/sale.rb b/app/models/sale.rb index 24d3f81c..979d265c 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -131,7 +131,6 @@ class Sale < ApplicationRecord if order_source.nil? order_source = order.source end - puts "compute source" compute(order_source) #Update the order items that is billed @@ -346,7 +345,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil) + def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil) sale = Sale.find(sale_id) sales_items = sale_itemss @@ -365,7 +364,7 @@ class Sale < ApplicationRecord end end - compute_tax(sale, total_taxable, total_discount, order_source) + compute_tax(sale, total_taxable, total_discount, order_source, tax_type) sale.total_amount = subtotal_price sale.total_discount = total_discount @@ -412,7 +411,7 @@ class Sale < ApplicationRecord end # Tax Re-Calculte - def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil) + def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil, tax_type=nil) shop = Shop.first(); #if tax is not apply create new record @@ -422,6 +421,7 @@ class Sale < ApplicationRecord end total_tax_amount = 0 + tax_incl_exec = "exclusive" #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(sale.customer_id) @@ -429,11 +429,9 @@ class Sale < ApplicationRecord if sale.payment_status != 'foc' tax_profiles.each do |tax| - # customer.tax_profiles.each do |cus_tax| - # if cus_tax.to_i == tax.id if tax.group_type.to_s == order_source.to_s - if customer.customer_type.downcase == 'takeaway' - if tax.name.downcase == 'commercial tax' + if tax_type + if tax_type.to_s == tax.name.to_s || tax_type == 'all' sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -442,6 +440,7 @@ class Sale < ApplicationRecord total_tax = total_taxable - total_discount #include or execulive if tax.inclusive + tax_incl_exec = "inclusive" rate = tax.rate divided_value = (100 + rate)/rate sale_tax.tax_payable_amount = total_tax / divided_value @@ -453,39 +452,41 @@ class Sale < ApplicationRecord if shop.calc_tax_order total_taxable = total_taxable + sale_tax.tax_payable_amount end - sale_tax.inclusive = tax.inclusive sale_tax.save end else - sale_tax = SaleTax.new(:sale => sale) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id + sale_tax = SaleTax.new(:sale => sale) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate - # substract , to give after discount - total_tax = total_taxable - total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount - end - #new taxable amount is standard rule for step by step - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end - sale_tax.inclusive = tax.inclusive - sale_tax.save + # substract , to give after discount + total_tax = total_taxable - total_discount + #include or execulive + if tax.inclusive + tax_incl_exec = "inclusive" + rate = tax.rate + divided_value = (100 + rate)/rate + sale_tax.tax_payable_amount = total_tax / divided_value + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + end + #new taxable amount is standard rule for step by step + if shop.calc_tax_order + total_taxable = total_taxable + sale_tax.tax_payable_amount + end + sale_tax.inclusive = tax.inclusive + sale_tax.save + # end + # end end end - # end - # end end end - + sale.tax_type = tax_incl_exec sale.total_tax = total_tax_amount end @@ -500,6 +501,7 @@ class Sale < ApplicationRecord end total_tax_amount = 0 + tax_incl_exec = "exclusive" #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") @@ -510,11 +512,9 @@ class Sale < ApplicationRecord #Create new tax records tax_profiles.each do |tax| - # customer.tax_profiles.each do |cus_tax| - # if cus_tax.to_i == tax.id if tax.group_type.to_s == order_source.to_s - if customer.customer_type.downcase == 'takeaway' - if tax.name.downcase == 'commercial tax' + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -523,6 +523,7 @@ class Sale < ApplicationRecord total_tax = total_taxable - self.total_discount #include or execulive if tax.inclusive + tax_incl_exec = "inclusive" rate = tax.rate divided_value = (100 + rate)/rate sale_tax.tax_payable_amount = total_tax / divided_value @@ -538,37 +539,12 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save - end - else - sale_tax = SaleTax.new(:sale => self) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate - - # substract , to give after discount - total_tax = total_taxable - self.total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount - end - - #new taxable amount is standard rule for step by step - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end - - sale_tax.inclusive = tax.inclusive - sale_tax.save - end + # end + # end end - # end - # end end - self.total_tax = total_tax_amount + self.tax_type = tax_incl_exec + self.total_tax = total_tax_amount end def product_get_unit_price(item_code) diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 55b09668..707ecf00 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -303,12 +303,16 @@ class ReceiptBillA5Pdf < Prawn::Document end if sale_data.sale_taxes.length > 0 + incl_tax = "" + if sale_data.tax_type == "inclusive" + incl_tax = "Incl." + end sale_data.sale_taxes.each do |st| move_down line_move y_position = cursor bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do - text "#{ st.tax_name } ( #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 5f3cdc09..92ce858d 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -290,12 +290,17 @@ class ReceiptBillPdf < Prawn::Document end if sale_data.sale_taxes.length > 0 + incl_tax = "" + if sale_data.tax_type == "inclusive" + incl_tax = "Incl." + end + sale_data.sale_taxes.each do |st| move_down line_move y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "#{ st.tax_name } ( #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left + text "#{ st.tax_name } (#{incl_tax} #{ st.tax_rate.to_i }%)", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right diff --git a/app/views/api/restaurant/menu/_menu_item.json.jbuilder b/app/views/api/restaurant/menu/_menu_item.json.jbuilder index 56a8cb5f..d31389e1 100755 --- a/app/views/api/restaurant/menu/_menu_item.json.jbuilder +++ b/app/views/api/restaurant/menu/_menu_item.json.jbuilder @@ -53,7 +53,7 @@ json.id item.id json.code item.item_code json.name item.name json.alt_name item.alt_name -if !request_url.nil? && request_url != '' +if !request_url.nil? && request_url != '' && !item.image_path.url.nil? json.image request_url + item.image_path.url.to_s else json.image item.image_path.url diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 0ba7f60b..bbd9cb79 100644 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -101,7 +101,7 @@
-