From 0d8b4f55699b5c3f7f37bbc9092f36d8db4c82c0 Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Thu, 24 Oct 2019 18:16:43 +0630 Subject: [PATCH 01/49] print gap fixed --- Gemfile | 2 +- Gemfile.lock | 2 +- app/pdf/order_item_customise_pdf.rb | 2 +- app/pdf/order_item_pdf.rb | 2 +- app/pdf/order_item_slim_pdf.rb | 2 +- app/pdf/order_item_star_pdf.rb | 2 +- app/pdf/order_set_item_customise_pdf.rb | 2 +- app/pdf/order_set_item_pdf.rb | 2 +- config/initializers/action_controller.rb | 10 +++++----- config/puma.rb | 22 +++++++++++----------- 10 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index 1a15a61a..66c149ef 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.3.1' +ruby '2.4.1' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" diff --git a/Gemfile.lock b/Gemfile.lock index 393a2ac8..3f9a8a09 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -371,7 +371,7 @@ DEPENDENCIES whenever RUBY VERSION - ruby 2.3.1p112 + ruby 2.4.1p111 BUNDLED WITH 2.0.2 diff --git a/app/pdf/order_item_customise_pdf.rb b/app/pdf/order_item_customise_pdf.rb index 850a9574..b509a01a 100644 --- a/app/pdf/order_item_customise_pdf.rb +++ b/app/pdf/order_item_customise_pdf.rb @@ -129,7 +129,7 @@ class OrderItemCustomisePdf < Prawn::Document # add option y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left end end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 58937093..ed079aeb 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -130,7 +130,7 @@ class OrderItemPdf < Prawn::Document # add option y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left end end diff --git a/app/pdf/order_item_slim_pdf.rb b/app/pdf/order_item_slim_pdf.rb index 33e1e314..3e39644f 100755 --- a/app/pdf/order_item_slim_pdf.rb +++ b/app/pdf/order_item_slim_pdf.rb @@ -130,7 +130,7 @@ class OrderItemSlimPdf < Prawn::Document # add option y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left end end diff --git a/app/pdf/order_item_star_pdf.rb b/app/pdf/order_item_star_pdf.rb index 711fb81e..2686efd7 100644 --- a/app/pdf/order_item_star_pdf.rb +++ b/app/pdf/order_item_star_pdf.rb @@ -130,7 +130,7 @@ class OrderItemStarPdf < Prawn::Document # add option y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left end end diff --git a/app/pdf/order_set_item_customise_pdf.rb b/app/pdf/order_set_item_customise_pdf.rb index ce3e654f..2e1d0a2c 100644 --- a/app/pdf/order_set_item_customise_pdf.rb +++ b/app/pdf/order_set_item_customise_pdf.rb @@ -144,7 +144,7 @@ class OrderSetItemCustomisePdf < Prawn::Document # add option y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left end end diff --git a/app/pdf/order_set_item_pdf.rb b/app/pdf/order_set_item_pdf.rb index a02dc3e2..09cdc6db 100755 --- a/app/pdf/order_set_item_pdf.rb +++ b/app/pdf/order_set_item_pdf.rb @@ -143,7 +143,7 @@ class OrderSetItemPdf < Prawn::Document # add option y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do + bounding_box([0,y_position], :width => self.item_width) do text "#{options}", :size => self.item_font_size,:align => :left end end diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 85f38ec5..205c330a 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -21,11 +21,11 @@ class ActionController::Base end else # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end + if check_license + current_license(ENV["SX_PROVISION_URL"]) + else + redirect_to activate_path + end end end diff --git a/config/puma.rb b/config/puma.rb index f0013d25..d24425ae 100755 --- a/config/puma.rb +++ b/config/puma.rb @@ -1,11 +1,11 @@ -# application_path="#{File.expand_path("../..", __FILE__)}" -# directory application_path -# #environment ENV.fetch("RAILS_ENV") { "production" } -# environment "production" -# pidfile "#{application_path}/tmp/puma/pid" -# state_path "#{application_path}/tmp/puma/state" -# stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" -# port ENV.fetch("PORT") { 62158 } -# workers 2 -# preload_app! -# threads 1,1 +application_path="#{File.expand_path("../..", __FILE__)}" +directory application_path +#environment ENV.fetch("RAILS_ENV") { "production" } +environment "production" +pidfile "#{application_path}/tmp/puma/pid" +state_path "#{application_path}/tmp/puma/state" +stdout_redirect "#{application_path}/log/puma.stdout.log", "#{application_path}/log/puma.stderr.log" +port ENV.fetch("PORT") { 62158 } +workers 2 +preload_app! +threads 1,1 From cec212bb394dae01f0e7a21946188e27efe0ef8a Mon Sep 17 00:00:00 2001 From: Nweni Date: Tue, 29 Oct 2019 10:06:00 +0630 Subject: [PATCH 02/49] dump --- dump.rdb | Bin 1864 -> 1864 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/dump.rdb b/dump.rdb index e4cb2863ade5864c70f85f677175fe6da53f30c9..42a27347f402a7cb6e6710a1d8f90f36e350dfb7 100644 GIT binary patch delta 100 zcmX@XcY<$%0rNul4HJz$Cg-!UPX5AbG`W*adg3Y3$?j}wlU3McC%zQD@1@%}v)pp@=pL3YWBo8*DQqP#|C2N?dFKRMjN((!u- E0OzD65&!@I delta 116 zcmX@XcY<$%0khSYWfP4(Ca-3cU^CY>GCRO9`2d^bWOjCW9`53j#1gBt#LS%3l+6zr zAFxc`z$nUMYyegwK3SDfcH%Ud$y|)m6VI|we5^XTpHXV!2HD9@jOIXvQj-s|NldJk Uo_w86ob&(G?^>_Q<2Q8z02jk4^#A|> From 6b6c945af7fa25bda39cd53bc8e18830eecc08f2 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 10:23:28 +0630 Subject: [PATCH 03/49] gemfile --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 143907b6..5df23eb0 100644 --- a/Gemfile +++ b/Gemfile @@ -45,6 +45,7 @@ gem 'jquery-fileupload-rails', '~> 0.4.7' #Report and Printing gems #gem 'cups' #remove for cloud installation +# gem 'cups' gem 'prawn' gem 'prawn-table' gem 'prawn-qrcode' From d4e9f3217eb293a483d3977dab86474e24b0e909 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 10:33:54 +0630 Subject: [PATCH 04/49] gem --- Gemfile.lock | 2 -- 1 file changed, 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 393a2ac8..c0941977 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,7 +89,6 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) - cups (0.1.10) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -325,7 +324,6 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) - cups database_cleaner factory_girl_rails (~> 4.0) faker From 41178978d23b5959cb242590c6a3063327308e7a Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 10:38:49 +0630 Subject: [PATCH 05/49] gem lock --- Gemfile | 2 +- Gemfile.lock | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 5df23eb0..a49cf828 100644 --- a/Gemfile +++ b/Gemfile @@ -45,7 +45,7 @@ gem 'jquery-fileupload-rails', '~> 0.4.7' #Report and Printing gems #gem 'cups' #remove for cloud installation -# gem 'cups' +gem 'cups', '~>0.0.7' gem 'prawn' gem 'prawn-table' gem 'prawn-qrcode' diff --git a/Gemfile.lock b/Gemfile.lock index db4f94aa..3a70c5bd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,7 +80,7 @@ GEM activemodel (>= 4.0.0) activesupport (>= 4.0.0) mime-types (>= 1.16) - chartkick (3.2.1) + chartkick (3.2.2) chronic (0.10.2) chunky_png (1.3.11) coffee-rails (4.2.2) @@ -93,6 +93,7 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) + cups (0.0.7) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -270,7 +271,8 @@ GEM activemodel (>= 5.0) spreadsheet (1.2.5) ruby-ole (>= 1.0) - spring (2.1.0) + spring (2.0.2) + activesupport (>= 4.2) spring-watcher-listen (2.0.1) listen (>= 2.7, < 4.0) spring (>= 1.2, < 3.0) @@ -328,6 +330,7 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) + cups (~> 0.0.7) database_cleaner factory_girl_rails (~> 4.0) faker From fbaf63f07377fa80ad870b1efadcdae7d4fc33ef Mon Sep 17 00:00:00 2001 From: Myat Zin Wai Maw Date: Wed, 30 Oct 2019 16:28:28 +0630 Subject: [PATCH 06/49] printcopies --- app/models/printer/receipt_printer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index b45c722b..f7b35a5a 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -227,8 +227,8 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker count = printer_settings.print_copies # override print copies for print worker loop - print_settings.print_copies = 1 - print_settings.save! + # print_settings.print_copies = 1 + # print_settings.save! end directory_name = 'public/receipts' Dir.mkdir(directory_name) unless File.exists?(directory_name) From 359679d41906c7bbb4bfd25d38b37ac6d9e381f2 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 16:52:16 +0630 Subject: [PATCH 07/49] CBKI --- app/controllers/api/authenticate_controller.rb | 2 +- app/controllers/origami/addorders_controller.rb | 2 +- app/controllers/origami/payments_controller.rb | 2 +- app/controllers/origami/pending_order_controller.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/authenticate_controller.rb b/app/controllers/api/authenticate_controller.rb index 8fb10040..02043be9 100755 --- a/app/controllers/api/authenticate_controller.rb +++ b/app/controllers/api/authenticate_controller.rb @@ -1,5 +1,5 @@ class Api::AuthenticateController < Api::ApiController - skip_before_action :authenticate + # skip_before_action :authenticate def create emp_id = params[:emp_id] diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index ba302f88..597b5d28 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -305,7 +305,7 @@ class Origami::AddordersController < BaseOrigamiController def getCloudDomain from = "" if ENV["SERVER_MODE"] == 'cloud' - from = request.subdomain + "." + request.domain + from = request.subdomain.to_s + "." + request.domain.to_s end return from diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 5de37662..963d6ee3 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -839,7 +839,7 @@ class Origami::PaymentsController < BaseOrigamiController def getCloudDomain from = "" if ENV["SERVER_MODE"] == 'cloud' - from = request.subdomain + "." + request.domain + from = request.subdomain.to_s + "." + request.domain.to_s end return from diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb index 4b412c17..773a217e 100644 --- a/app/controllers/origami/pending_order_controller.rb +++ b/app/controllers/origami/pending_order_controller.rb @@ -22,7 +22,7 @@ class Origami::PendingOrderController < BaseOrigamiController else redirect_to "/origami/#{params[:type]}" and return end - elsif id.start_with?("BKI") + elsif (id.start_with?("BKI") || id.start_with?("CBKI")) @bookings = Booking.find(id) @order = @bookings.orders.where(status: "new").first @order_items = @bookings.order_items From d95499f24d9399f272813671e3782c79c252e272 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 30 Oct 2019 17:58:17 +0630 Subject: [PATCH 08/49] authenticate --- app/controllers/api/api_controller.rb | 2 +- app/controllers/api/authenticate_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index ad38376a..a5112ffe 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,5 +1,5 @@ class Api::ApiController < ActionController::API - # include TokenVerification + include TokenVerification # before_action :lookup_domain helper_method :current_token, :current_login_employee, :get_cashier diff --git a/app/controllers/api/authenticate_controller.rb b/app/controllers/api/authenticate_controller.rb index 02043be9..8fb10040 100755 --- a/app/controllers/api/authenticate_controller.rb +++ b/app/controllers/api/authenticate_controller.rb @@ -1,5 +1,5 @@ class Api::AuthenticateController < Api::ApiController - # skip_before_action :authenticate + skip_before_action :authenticate def create emp_id = params[:emp_id] From d2cf13cd3b8d48732f3e37c9086caddceef6fe77 Mon Sep 17 00:00:00 2001 From: Nweni Date: Fri, 1 Nov 2019 12:08:15 +0630 Subject: [PATCH 09/49] dump --- dump.rdb | Bin 1864 -> 1864 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/dump.rdb b/dump.rdb index 42a27347f402a7cb6e6710a1d8f90f36e350dfb7..2b0eb54ec77065e59631cfc96f9a0a9087d16625 100644 GIT binary patch delta 195 zcmX@XcY<$%f%xsbU9rD7N{drdbaPX44}Dn6$MBEgx9H?`jN&ZD1_u}>doUVK=3zGw z0f{GD Date: Fri, 1 Nov 2019 16:26:24 +0630 Subject: [PATCH 10/49] gemfile --- Gemfile.lock | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index c0941977..22c5244f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -89,6 +89,7 @@ GEM concurrent-ruby (1.1.5) connection_pool (2.2.2) crass (1.0.5) + cups (0.0.7) database_cleaner (1.7.0) diff-lcs (1.3) erubi (1.9.0) @@ -324,6 +325,7 @@ DEPENDENCIES carrierwave (~> 1.0) chartkick coffee-rails (~> 4.2) + cups database_cleaner factory_girl_rails (~> 4.0) faker From b73136dc79f1e815c712d159743bbd008afc3f31 Mon Sep 17 00:00:00 2001 From: Nweni Date: Fri, 1 Nov 2019 16:28:18 +0630 Subject: [PATCH 11/49] print copies --- app/models/printer/receipt_printer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index b45c722b..f7b35a5a 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -227,8 +227,8 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker count = printer_settings.print_copies # override print copies for print worker loop - print_settings.print_copies = 1 - print_settings.save! + # print_settings.print_copies = 1 + # print_settings.save! end directory_name = 'public/receipts' Dir.mkdir(directory_name) unless File.exists?(directory_name) From 155cb0a9eb9e8877c60680f1a62aabb655a89a42 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Wed, 6 Nov 2019 17:34:42 +0630 Subject: [PATCH 12/49] rounding decimal to print_settings precision --- .../origami/discounts_controller.rb | 139 +++--- .../origami/payments_controller.rb | 24 +- .../origami/sale_edit_controller.rb | 4 +- app/models/promotion.rb | 442 +++++------------- app/models/sale.rb | 304 ++++-------- app/models/sale_item.rb | 19 + app/models/sale_order.rb | 5 +- app/models/sale_tax.rb | 11 + app/views/origami/discounts/index.html.erb | 179 +++---- app/views/reports/receipt_no/index.html.erb | 70 ++- app/views/reports/receipt_no/index.xls.erb | 72 ++- 11 files changed, 467 insertions(+), 802 deletions(-) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index cd73d174..827d26c7 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -7,9 +7,9 @@ class Origami::DiscountsController < BaseOrigamiController @print_settings = PrintSetting.get_precision_delimiter() @webview = false if check_mobile - @webview = true + @webview = true end - + sale_id = params[:id] @cashier_type = params[:type] if Sale.exists?(sale_id) @@ -32,7 +32,7 @@ class Origami::DiscountsController < BaseOrigamiController discount_items = JSON.parse(params[:discount_items]) overall_discount = params[:overall_discount] sub_total = params[:sub_total] - + if Sale.exists?(sale_id) sale = Sale.find(sale_id) @@ -44,26 +44,29 @@ class Origami::DiscountsController < BaseOrigamiController table_id = nil end - - # sale.total_discount = overall_discount.to_f + + # sale.total_discount = overall_discount.to_f # sale.total_amount = sub_total.to_f - # sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; - # sale.save + # sale.grand_total = (sub_total.to_f - overall_discount.to_f) + sale.total_tax; + # sale.save if discount_items.length > 0 #save sale item for discount discount_items.each do |di| origin_sale_item = SaleItem.find(di["id"]) - + sale_item = SaleItem.new - if !origin_sale_item.nil? - menu_category = MenuCategory.get_menu_category(origin_sale_item.product_code) #get menu category for menu items - if !menu_category.nil? - sale_item.menu_category_code = menu_category.code - sale_item.menu_category_name = menu_category.name - end - end + # if !origin_sale_item.nil? + # menu_category = MenuCategory.get_menu_category(origin_sale_item.product_code) #get menu category for menu items + # if !menu_category.nil? + # sale_item.menu_category_code = menu_category.code + # sale_item.menu_category_name = menu_category.name + # end + # end + + sale_item.menu_category_code = origin_sale_item.menu_category_code + sale_item.menu_category_name = origin_sale_item.menu_category_name sale_item.sale_id = sale_id sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id @@ -73,7 +76,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.status = "Discount" sale_item.qty = -1 - sale_item.unit_price = di["price"].to_f * (-1) + sale_item.unit_price = di["price"].to_f * -1 sale_item.taxable_price = di["price"] sale_item.is_taxable = 1 sale_item.account_id = origin_sale_item.account_id @@ -83,11 +86,11 @@ class Origami::DiscountsController < BaseOrigamiController action_by = current_user.name remark = "Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} " - + sale_audit = SaleAudit.record_audit_discount(sale_item.sale_id,sale.cashier_name, action_by,remark,"ITEMDISCOUNT" ) - - end - end + + end + end # Re-calc All Amount in Sale if overall_discount.to_f > 0 @@ -97,24 +100,24 @@ class Origami::DiscountsController < BaseOrigamiController else remark = "Discount Overall Price [#{overall_discount}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " end - + sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"OVERALLDISCOUNT" ) - end - sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f, nil,order_source) + end + sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f, nil,order_source) if !table.nil? result = {:status=> "Success", :table_id => table_id, :table_type => table.type } else result = {:status=> "Success" } end - else + else if !table.nil? result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } else result = {:status=> "Please, Check Again!" } end - end + end + - render :json => result.to_json end @@ -131,45 +134,45 @@ class Origami::DiscountsController < BaseOrigamiController else table_id = nil table = nil - end - - - if discount_items.length > 0 + end + + + if discount_items.length > 0 #destroy sale item for discount - discount_items.each do |di| - sale_item = SaleItem.find(di["id"]) + discount_items.each do |di| + sale_item = SaleItem.find(di["id"]) sale.total_amount = (sale.total_amount + sale_item.price.abs) action_by = current_user.name if table.nil? remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- No Table " else - remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- #{table.name} " + remark = "Remove Item Discount Item Name ->#{sale_item.product_name}-Product Code ->#{sale_item.product_code} | Price [#{sale_item.price}] | Receipt No #{sale.receipt_no} | Table- #{table.name} " end sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEITEMDISCOUNT" ) - - sale_item.destroy - end - end - # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; + sale_item.destroy + end + end + + # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; # sale.save # Re-calc All Amount in Sale - sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount, nil, order_source) + sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount, nil, order_source) if table.nil? result = {:status=> "Success"} else result = {:status=> "Success", :table_id => table_id, :table_type => table.type } end - - else + + else if table.nil? result = {:status=> "Please, Check Again!"} else result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table.type } end - - end + + end render :json => result.to_json end @@ -180,29 +183,29 @@ class Origami::DiscountsController < BaseOrigamiController order_source = params[:type] if Sale.exists?(sale_id) - sale = Sale.find(sale_id) - + sale = Sale.find(sale_id) + if sale.bookings[0].dining_facility_id.to_i > 0 table_id = sale.bookings[0].dining_facility_id table = DiningFacility.find(table_id) - table_type = table.type + table_type = table.type else table_id = nil table = nil table_type = nil - end + end - discount_items = [] + discount_items = [] #destroy all discount sale item - sale.sale_items.each do |si| - if si.status == "Discount" && si.price < 0 - sale.total_amount = (sale.total_amount + si.price.abs) - discount_items.push(si) + sale.sale_items.each do |si| + if si.status == "Discount" && si.price < 0 + sale.total_amount = (sale.total_amount + si.price.abs) + discount_items.push(si) end - end + end # sale.total_discount = 0 - # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; + # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; # sale.save #destroy in sale.sale_items @@ -215,23 +218,23 @@ class Origami::DiscountsController < BaseOrigamiController remark = "Remove Discount Sale Id [#{sale.sale_id}]| Receipt No #{sale.receipt_no} | Table- #{table.name} " end sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_name, action_by,remark,"REMOVEALLDISCOUNT" ) - + # Re-calc All Amount in Sale sale.compute_by_sale_items(sale_id, sale.sale_items, 0, nil, order_source) if table.nil? result = {:status=> "Success"} else - result = {:status=> "Success", :table_id => table_id, :dining => table.name, :table_type => table_type } + result = {:status=> "Success", :table_id => table_id, :dining => table.name, :table_type => table_type } end - - else + + else if table.nil? result = {:status=> "Please, Check Again!"} else - result = {:status=> "Please, Check Again!", :table_id => table_id, :dining => table.name, :table_type => table_type } + result = {:status=> "Please, Check Again!", :table_id => table_id, :dining => table.name, :table_type => table_type } end - - end + + end render :json => result.to_json end @@ -251,7 +254,7 @@ class Origami::DiscountsController < BaseOrigamiController end # Check for Card Payment is_card_payment = SalePayment.get_sale_payments_by_card(sale.sale_payments) - + # if is_card != "true" account_types = Account.where("discount=?",true) table_id = sale.bookings[0].dining_facility_id @@ -267,9 +270,9 @@ class Origami::DiscountsController < BaseOrigamiController str={type:pc[:name],amount:pc[:price]} acc_prices.push(str) end - end + end end - generic_customer_id = sale.customer.membership_id + generic_customer_id = sale.customer.membership_id receipt_no = sale.receipt_no membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("member_discount") @@ -282,7 +285,7 @@ class Origami::DiscountsController < BaseOrigamiController # Check for items for Paypar Cloud if acc_prices.length > 0 begin - response = HTTParty.post(url, + response = HTTParty.post(url, :body => { account_no: account_no, generic_customer_id:generic_customer_id , campaign_type_id: campaign_type_id, @@ -307,7 +310,7 @@ class Origami::DiscountsController < BaseOrigamiController rescue SocketError response = {"status": false, "message": "Can't open membership server " } end - else + else response = {"status": false, "message": "You have no selected discount item" } end Rails.logger.debug "-------------- Member Discount Osaka ---------" @@ -325,7 +328,7 @@ class Origami::DiscountsController < BaseOrigamiController else result = {:status=> response["message"],:title=>"Alert", :table_id => table_id,:table_type => table_type } end - + render :json => result.to_json # end #end Is Card Payment @@ -376,5 +379,5 @@ class Origami::DiscountsController < BaseOrigamiController # redirect_to origami_path(sale_id) # end - + end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 5de37662..78de240d 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -64,15 +64,9 @@ class Origami::PaymentsController < BaseOrigamiController customer = Customer.find(sale_data.customer_id) # rounding adjustment if shop_detail.is_rounding_adj - a = sale_data.grand_total % 25 # Modulus - b = sale_data.grand_total / 25 # Division - #not calculate rounding if modulus is 0 and division is even - #calculate rounding if modulus is zero or not zero and division are not even - if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - rounding_adj = new_total-sale_data.grand_total - sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) - end + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + rounding_adj = new_total - sale_data.grand_total + sale_data.update_attributes(grand_total: new_total,old_grand_total: sale_data.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0 end #end rounding adjustment #record for sale audit @@ -151,15 +145,9 @@ class Origami::PaymentsController < BaseOrigamiController # rounding adjustment if !path.include? ("credit_payment") if shop_detail.is_rounding_adj - a = saleObj.grand_total % 25 # Modulus - b = saleObj.grand_total / 25 # Division - #not calculate rounding if modulus is 0 and division is even - #calculate rounding if modulus is zero or not zero and division are not even - if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) - new_total = Sale.get_rounding_adjustment(saleObj.grand_total) - rounding_adj = new_total-saleObj.grand_total - saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) - end + new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + rounding_adj = new_total - saleObj.grand_total + saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) if rounding_adj > 0 end end #end rounding adjustment diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 40f79afd..d537f8e9 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -72,7 +72,7 @@ class Origami::SaleEditController < BaseOrigamiController saleitemObj.status = 'foc' saleitemObj.remark = remark saleitemObj.save - @newsaleitem = SaleItem.new + @newsaleitem = saleitemObj.dup @newsaleitem.qty = saleitemObj.qty * -1 @newsaleitem.unit_price = saleitemObj.unit_price * 1 @@ -143,7 +143,7 @@ class Origami::SaleEditController < BaseOrigamiController sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"SALEITEMEDIT" ) # saleitemObj.remark = 'edit' - unless saleitemObj.product_name.include? 'updated' + unless saleitemObj.product_name.include? 'UPDATED' saleitemObj.product_name = saleitemObj.product_name + ' (UPDATED)' end diff --git a/app/models/promotion.rb b/app/models/promotion.rb index b636a097..0fa2b3e9 100755 --- a/app/models/promotion.rb +++ b/app/models/promotion.rb @@ -11,37 +11,23 @@ class Promotion < ApplicationRecord PROMO_TYPE3 = "Net_price" # 1800 => 1000 => 1000 PROMO_TYPE4 = "Percentage" + def is_promo_day + promo_day.include? Date.today.wday.to_s + end + def self.promo_activate(saleObj) - array_same =[] current_day = Time.now.strftime("%Y-%m-%d") current_time = Time.now.strftime('%H:%M:%S') day = Date.today.wday promoList = is_between_promo_datetime(current_day,current_time) - puts "promoList - " + promoList.size.to_s - if promoList.size > 0 - itemList = combine_item(saleObj) - itemList.each do|list| - list.each do |l| - array_same.push({ - item_instance_code: l.item_instance_code, - order_id:l.order_id, - qty:l.qty - }) + + promoList.each do |promo| + if promo.is_promo_day + if item = saleObj.qty_of(promo.original_product) + check_promo_type(promo, item, saleObj) end end end - item_list =[] - array_same.group_by do |same| - same.values_at :item_instance_code - end.map do |(item_instance_code), array_same| - quantities = array_same.map { |p| p[:qty] } - qty = quantities.all? ? quantities.reduce(:+) : nil - item_list.push({ item_instance_code: item_instance_code, qty: qty }) - end - Rails.logger.debug "-------promo_activate array_same-------" - puts item_list.to_json - is_promo_day(promoList,day, item_list, saleObj.sale_id) - end def self.is_between_promo_datetime(current_day,current_time) #database is not local time @@ -49,45 +35,7 @@ class Promotion < ApplicationRecord return promoList end - def self.combine_item(saleObj) - # order_id = saleObj.sale_orders[0][0].order_id - # itemList = OrderItem.where("order_id = ?", order_id).group(:item_instance_code).sum(:qty) - # array_same =[] - itemList = [] - saleObj.sale_orders.each do |so| - # itemList << OrderItem.where("order_id = ?",so.order_id).group(["item_instance_code", "order_id"]).sum(:qty) - itemList << OrderItem.where("order_id = ?",so.order_id).select(:item_instance_code,:order_id,:qty) - end - - return itemList - end - - def self.is_promo_day(promoList, day, orderitemList, sale_id) - puts "Today date - " + day.to_s - promoList.each do |promo| - dayresult = promo.promo_day.include?(day.to_s) - if dayresult - orderitemList.each do |item| - find_promo_item(promo, item, sale_id) - end - end - end - end - - def self.find_promo_item(promo, orderitem, sale_id) - item_code = OrderItem.find_by_item_instance_code(orderitem[:item_instance_code]).item_code - # orderitem.each do |odr_item| - if promo.original_product.downcase.to_s == orderitem[:item_instance_code] - if promo.min_qty.to_i > orderitem[:qty].to_i - return false - else - check_promo_type(promo,orderitem, sale_id) - end - end - # end - end - - def self.check_promo_type(promo, orderitem, sale_id) + def self.check_promo_type(promo, orderitem, saleObj) promo.promotion_products.each do |promo_product| if promo_product.item_code.downcase == orderitem[:item_instance_code] same = true @@ -97,20 +45,20 @@ class Promotion < ApplicationRecord end # same, promo_product = check_giveaway_product(promo, orderitem[0][0]) if promo.promo_type == Promotion::PROMO_TYPE1 - if same - give_promotion_same_product(orderitem[:qty], promo.min_qty, promo_product.min_qty, orderitem, sale_id,promo_product.item_code) - else - give_promotion_second_product(orderitem[:qty], promo.min_qty, promo_product.item_code, orderitem, sale_id) + if same + give_promotion_same_product(orderitem[:qty], promo.min_qty, promo_product.min_qty, orderitem, saleObj, promo_product.item_code) + else + give_promotion_second_product(orderitem[:qty], promo.min_qty, promo_product.item_code, orderitem, saleObj) end elsif promo.promo_type == Promotion::PROMO_TYPE2 - give_promotion_nett_off(same,promo_product,promo.min_qty, orderitem, sale_id) + give_promotion_nett_off(same,promo_product,promo.min_qty, orderitem, saleObj) elsif promo.promo_type == Promotion::PROMO_TYPE3 - give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, sale_id) + give_promotion_nett_price(same,promo_product,promo.min_qty, orderitem, saleObj) elsif promo.promo_type == Promotion::PROMO_TYPE4 - give_promotion_discount(same,promo_product,promo.min_qty, orderitem, sale_id) + give_promotion_discount(same,promo_product,promo.min_qty, orderitem, saleObj) end end end @@ -128,106 +76,66 @@ class Promotion < ApplicationRecord # end end - def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem, sale_id,promo_product) - item ='' - puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s - multiple = qty.to_i / promoqty.to_i # loop count - charge_qty = 0 - foc_qty = 0 - if multiple > 0 - multiple.times.each do |key| - if qty > promoqty - charge_qty += promoqty - different = qty - promoqty - qty = different - if different == 0 - foc_qty += foc_min_qty - else - foc_qty += foc_min_qty - qty = qty - foc_min_qty - end + def self.give_promotion_same_product(qty, promoqty, foc_min_qty, orderitem, saleObj,promo_product) + puts " Order qty: " + qty.to_s + " / promoqty: " + promoqty.to_s + " / giveaway: " + foc_min_qty.to_s + multiple = qty.to_i / promoqty.to_i # loop count + charge_qty = 0 + foc_qty = 0 + if multiple > 0 + multiple.times.each do |key| + if qty > promoqty + charge_qty += promoqty + different = qty - promoqty + qty = different + if different == 0 + foc_qty += foc_min_qty else - charge_qty += qty + foc_qty += foc_min_qty + qty = qty - foc_min_qty end + else + charge_qty += qty end - if multiple == foc_qty - charge_qty += qty - end - else + end + if multiple == foc_qty charge_qty += qty end - sale_order =SaleOrder.where("sale_id=?",sale_id) - price =0 - source ='' - sale_order.each do|order| - source = Order.find(order.order_id).source - end + else + charge_qty += qty + end - item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first - item ={ - item_code:item.item_code, - item_instance_code:item.item_instance_code, - item_name:item.item_name, - alt_name:item.alt_name, - account_id:item.account_id, - price:item.price - } - if promo_product.downcase != item[:item_instance_code] + price = 0 + source = saleObj.orders.first.source + item = saleObj.order_items.where(item_instance_code: promo_product).first - sale_order.each do|order| - source = Order.find(order.order_id).source - end - item = OrderItem.where("item_code = ?",promo_product).order("order_items_id DESC").first - item ={ - item_code:item.item_code, - item_instance_code:item.item_instance_code, - item_name:item.item_name, - alt_name:item.alt_name, - account_id:item.account_id, - price:item.price - } - end - if !item.nil? - update_existing_item(foc_qty, item, sale_id, "promotion", item[:price],source) - end + if !item.nil? + update_existing_item(foc_qty, item, sale_id, "promotion", item[:price], source) + end end # AA - 10 # 3 # BB # orderList, #S34345 - def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, sale_id) - source ='' - item ='' + def self.give_promotion_second_product(orderitem_count, foc_min_qty, promo_product, orderitem, saleObj) puts "..... orderitem_count: " + orderitem_count.to_s + " / foc_min_qty: " + foc_min_qty.to_s + " /promo_product: " + promo_product + " orderitem: " + orderitem.to_s + promotion_qty = orderitem_count.to_i / foc_min_qty.to_i # get foc item qty - foc_qty = find_second_item_qty(sale_id, promo_product) + foc_qty = saleObj.qty_of(promo_product).qty rescue 0 if (foc_qty < promotion_qty) promotion_qty = foc_qty end # item = OrderItem.find_by_item_instance_code(promo_product) - sale_order =SaleOrder.where("sale_id=?",sale_id) - price =0 - sale_order.each do|order| - source = Order.find(order.order_id).source - end - item = OrderItem.where("item_instance_code = ?",promo_product).order("order_items_id DESC").first - item ={ - item_code:item.item_code, - item_instance_code:item.item_instance_code, - item_name:item.item_name, - alt_name:item.alt_name, - account_id:item.account_id, - price:item.price - } - # item = OrderItem.where("item_instance_code = '#{promo_product}' and order_id = '#{orderitem[0][1]}'").first + + price = 0 + source = saleObj.orders.first.source + item = saleObj.order_items.where(item_instance_code: promo_product).first + if !item.nil? - # source = Order.find(item.order_id).source update_existing_item(promotion_qty, item, sale_id, "promotion", item[:price],source) end end - - def self.update_existing_item(qty, item, sale_id, type, item_price,source) - if qty >0 + def self.update_existing_item(qty, item, saleObj, type, item_price,source) + if qty > 0 menu_category = MenuCategory.get_menu_category(item[:item_code]) #get menu category for menu items - + sale_item = SaleItem.new if !menu_category.nil? sale_item.menu_category_code = menu_category.code @@ -247,216 +155,84 @@ class Promotion < ApplicationRecord sale_item.price = qty * item_price * (-1) sale_item.is_taxable = 1 - sale_item.sale_id = sale_id + sale_item.sale = saleObj sale_item.save - sale = Sale.find(sale_id) - sale.compute_by_sale_items(sale.id, sale.sale_items, sale.total_discount,nil,source) + + saleObj.compute_by_sale_items(saleObj.id, saleObj.sale_items, saleObj.total_discount,nil,source) end end - def self.give_promotion_nett_off(same, promo_product, foc_min_qty, orderitem, sale_id) - item ='' - source ='' + def self.give_promotion_nett_off(same, promo_product, foc_min_qty, orderitem, saleObj) puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s - sale_order =SaleOrder.where("sale_id=?",sale_id) - if same - foc_qty = orderitem[:qty].to_i / foc_min_qty - # item = OrderItem.find_by_item_instance_code(orderitem[0][0]) - - price =0 - sale_order.each do|order| - source = Order.find(order.order_id).source - end - item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first - item ={ - item_code:item.item_code, - item_instance_code:item.item_instance_code, - item_name:item.item_name, - alt_name:item.alt_name, - account_id:item.account_id, - price:item.price - } - # item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first - if !item.nil? - # source = Order.find(item.order_id).source - update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source) - end - - else - foc_qty = orderitem[:qty].to_i / foc_min_qty - # foc_qty = find_second_item_qty(sale_id, promo_product.item_code) - # item = OrderItem.find_by_item_instance_code(promo_product.item_code) - # item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first - sale_order.each do|order| - source = Order.find(order.order_id).source - end - item = OrderItem.where("item_instance_code = ?",promo_product.item_code).order("order_items_id DESC").first - item ={ - item_code:item.item_code, - item_instance_code:item.item_instance_code, - item_name:item.item_name, - alt_name:item.alt_name, - account_id:item.account_id, - price:item.price - } - if !item.nil? - # source = Order.find(item.order_id).source - update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source) - end - end - end - - def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, sale_id) - puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s - sale_order =SaleOrder.where("sale_id=?",sale_id) - source ='' - item ='' - if same - foc_qty = orderitem[:qty].to_i / foc_min_qty - # item = OrderItem.find_by_item_instance_code(orderitem[0][0]) # need to specify with menu item instance - # item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first - sale_order.each do|order| - source = Order.find(order.order_id).source - end - item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first - item ={ - item_code:item.item_code, - item_instance_code:item.item_instance_code, - item_name:item.item_name, - alt_name:item.alt_name, - account_id:item.account_id, - price:item.price - } - if !item.nil? - price = item[:price].to_i - promo_product.net_price.to_i - # source = Order.find(item.order_id).source - update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source) - end - - else - order_qty = find_second_item_qty(sale_id, promo_product.item_code)# need to check for qty + foc_qty = orderitem[:qty].to_i / foc_min_qty + if !same + order_qty = saleObj.qty_of(promo_product.item_code).qty rescue 0 foc_qty = orderitem[:qty].to_i / foc_min_qty if foc_qty > order_qty foc_qty = order_qty end - # item = OrderItem.find_by_item_instance_code(promo_product.item_code) - # item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first - sale_order.each do|order| - source = Order.find(order.order_id).source - end - item = OrderItem.where("item_instance_code",promo_product.item_code).order("order_items_id DESC").first - item ={ - item_code:item.item_code, - item_instance_code:item.item_instance_code, - item_name:item.item_name, - alt_name:item.alt_name, - account_id:item.account_id, - price:item.price - } + end - if !item.nil? - price = item[:price].to_i - promo_product.net_price.to_i - # source = Order.find(item.order_id).source - update_existing_item(foc_qty, item, sale_id, "promotion nett price", price,source) - end - + source = saleObj.orders.first.source + item = saleObj.order_items.where(item_instance_code: promo_product.item_code).first + + if !item.nil? + update_existing_item(foc_qty, item, sale_id, "promotion nett off", promo_product.net_off,source) end end - def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, sale_id) + def self.give_promotion_nett_price(same, promo_product, foc_min_qty, orderitem, saleObj) puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s - sale_order =SaleOrder.where("sale_id=?",sale_id) - source ='' - item ='' - if same + + foc_qty = orderitem[:qty].to_i / foc_min_qty + if !same + order_qty = saleObj.qty_of(promo_product.item_code).qty rescue 0 foc_qty = orderitem[:qty].to_i / foc_min_qty - # item = OrderItem.find_by_item_instance_code(orderitem[0][0]) - # item = OrderItem.where("item_instance_code = '#{orderitem[0][0]}' and order_id = '#{orderitem[0][1]}'").first - sale_order.each do|order| - source = Order.find(order.order_id).source - end - item = OrderItem.where("item_instance_code = ?",orderitem[:item_instance_code]).order("order_items_id DESC").first - item ={ - item_code:item.item_code, - item_instance_code:item.item_instance_code, - item_name:item.item_name, - alt_name:item.alt_name, - account_id:item.account_id, - price:item.price - } - # total = orderitem[1].to_i * item.price - if !item.nil? - total = item[:price] - price = calculate_discount(total, promo_product.percentage) - # source = Order.find(item.order_id).source - update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source) - end - - else - order_qty = find_second_item_qty(sale_id, promo_product.item_code) #need to check - foc_qty = orderitem[:qty].to_i / foc_min_qty - # give total qty is 1 - #foc_qty = (foc_qty - foc_qty) + 1 + if foc_qty > order_qty foc_qty = order_qty end - # item = OrderItem.find_by_item_instance_code(promo_product.item_code) - # item = OrderItem.where("item_instance_code = '#{promo_product.item_code}' and order_id = '#{orderitem[0][1]}'").first - sale_order.each do|order| - source = Order.find(order.order_id).source - end - item = OrderItem.where("item_instance_code = ?",promo_product.item_code).order("order_items_id DESC").first - item ={ - item_code:item.item_code, - item_instance_code:item.item_instance_code, - item_name:item.item_name, - alt_name:item.alt_name, - account_id:item.account_id, - price:item.price - } - # total = item.price * foc_qty - if !item.nil? - total = item[:price] - price = calculate_discount(total, promo_product.percentage) - # source = Order.find(item.order_id).source - update_existing_item(foc_qty, item, sale_id, "promotion discount", price,source) - end + end + + source = saleObj.orders.first.source + item = saleObj.order_items.where(item_instance_code: promo_product.item_code).first + + if !item.nil? + price = item[:price].to_i - promo_product.net_price.to_i + update_existing_item(foc_qty, item, saleObj, "promotion nett price", price,source) end end - def self.find_second_item_qty(sale_id, promo_item) - array_same =[] - saleObj = Sale.find_by_sale_id(sale_id) - itemList = combine_item(saleObj) - itemList.each do|list| - list.each do |l| - array_same.push({ - item_instance_code: l.item_instance_code, - order_id:l.order_id, - qty:l.qty - }) + def self.give_promotion_discount(same, promo_product, foc_min_qty, orderitem, saleObj) + puts " same: " + same.to_s + " promo_product: " + promo_product.item_code.to_s + " foc_min_qty: " + foc_min_qty.to_s + " orderitem: " + orderitem.to_s + + foc_qty = orderitem[:qty].to_i / foc_min_qty + if !same + order_qty = saleObj.qty_of(promo_product.item_code).qty rescue 0 + foc_qty = orderitem[:qty].to_i / foc_min_qty + + if foc_qty > order_qty + foc_qty = order_qty end end - item_list =[] - array_same.group_by do |same| - same.values_at :item_instance_code - end.map do |(item_instance_code), array_same| - quantities = array_same.map { |p| p[:qty] } - qty = quantities.all? ? quantities.reduce(:+) : nil - item_list.push({ item_instance_code: item_instance_code, qty: qty }) - end - item_list.each do |item| - if item[:item_instance_code] == promo_item.downcase - return item[:qty].to_i - end - end - return 0 - end - def self.calculate_discount(total, percentage) - return (total.to_i * percentage.to_i) / 100 - end + source = saleObj.orders.first.source + item = saleObj.order_items.where(item_instance_code: promo_product.item_code).first + puts saleObj + puts item + # total = orderitem[1].to_i * item.price + if item + total = item[:price] + price = calculate_discount(total, promo_product.percentage) + # source = Order.find(item.order_id).source + update_existing_item(foc_qty, item, saleObj, "promotion discount", price,source) + end + end + + def self.calculate_discount(total, percentage) + return (total * percentage) / 100 + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index a7208d50..cb4854b8 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -14,14 +14,20 @@ class Sale < ApplicationRecord has_many :sale_payments has_many :sale_orders has_many :orders, through: :sale_orders + has_many :order_items, through: :sale_orders has_many :bookings has_many :product_commissions + before_validation :round_to_precision after_update :update_stock_journal scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.beginning_of_day}' AND '#{DateTime.now.utc.end_of_day}'") } + def qty_of(item_instance_code) + order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first + end + REPORT_TYPE = { "daily" => 0, "monthly" => 1, @@ -418,11 +424,11 @@ class Sale < ApplicationRecord apply_tax(total_taxable, order_source, tax_type) self.total_amount = subtotal_price - self.total_discount = total_discount + # self.total_discount = total_discount self.grand_total = (self.total_amount - self.total_discount) + self.total_tax - self.grand_total_round + # self.grand_total_round #compute rounding adjustment - adjust_rounding + # adjust_rounding self.save! @@ -455,7 +461,7 @@ class Sale < ApplicationRecord sale.grand_total = 0 else sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax - sale.grand_total_round + # sale.grand_total_round end if discount_type == "member_discount" @@ -463,7 +469,6 @@ class Sale < ApplicationRecord end #compute rounding adjustment # adjust_rounding - sale.rounding_adjustment = compute_adjust_rounding(sale.grand_total) sale.save! end @@ -491,11 +496,11 @@ class Sale < ApplicationRecord apply_tax(total_taxable, order_source) self.total_amount = subtotal_price - self.total_discount = total_discount + # self.total_discount = total_discount self.grand_total = (self.total_amount - self.total_discount) + self.total_tax - self.grand_total_round + # self.grand_total_round #compute rounding adjustment - adjust_rounding + # adjust_rounding self.save! end @@ -509,89 +514,45 @@ class Sale < ApplicationRecord # #delete existing and create new # existing_tax.delete # end - taxes = SaleTax.where("sale_id='#{sale.sale_id}'").pluck(:sale_tax_id) - SaleTax.where("sale_tax_id IN (?)", taxes).destroy_all + taxes = SaleTax.where("sale_id='#{self.sale_id}'").destroy_all 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) - arr_tax = [] - arr_tax = unique_tax_profiles(order_source, self.customer_id) - if !arr_tax.empty? - if tax_type.nil? - tax_profiles = TaxProfile.where(:id => arr_tax) - else - tax_profiles = TaxProfile.where("group_type=?",order_source) - end - else - tax_profiles = TaxProfile.where("group_type=?",order_source) - end - - # #Creat new tax records if order_source.to_s == "emenu" order_source = "cashier" end + tax_profiles = unique_tax_profiles(order_source, self.customer_id) + + # #Creat new tax records if sale.payment_status != 'foc' tax_profiles.each do |tax| - if tax.group_type.to_s == order_source.to_s - 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 + 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 - 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 - else - # 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 - 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 + # 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 sale.tax_type = tax_incl_exec @@ -608,8 +569,7 @@ class Sale < ApplicationRecord # existing_tax.delete # end - taxes = SaleTax.where("sale_id='#{self.sale_id}'").pluck(:sale_tax_id) - SaleTax.where("sale_tax_id IN (?)", taxes).destroy_all + taxes = SaleTax.where("sale_id='#{self.sale_id}'").destroy_all total_tax_amount = 0 tax_incl_exec = "exclusive" @@ -622,77 +582,34 @@ class Sale < ApplicationRecord # tax_data = TaxProfile.unscoped.where("group_type=?",order_source).pluck(:id) # customer = Customer.find(self.customer_id).tax_profiles - arr_tax = [] - arr_tax = unique_tax_profiles(order_source, self.customer_id) + tax_profiles = unique_tax_profiles(order_source, self.customer_id) - if !arr_tax.empty? - if tax_type.nil? - tax_profiles = TaxProfile.where(:id => arr_tax) - else - tax_profiles = TaxProfile.where("group_type=?",order_source) - end - else - tax_profiles = TaxProfile.where("group_type=?",order_source) - end #Create new tax records tax_profiles.each do |tax| - if tax.group_type.to_s == order_source.to_s - if tax_type - if tax_type.to_s == tax.name.to_s || tax_type == 'all' - sale_tax = SaleTax.new(:sale => self) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate + 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 - 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 - else - # 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 - - # substract , to give after discount - 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 - 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 + # substract , to give after discount + 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 + 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 self.tax_type = tax_incl_exec self.total_tax = total_tax_amount @@ -727,42 +644,16 @@ class Sale < ApplicationRecord shop_details = Shop.first # rounding adjustment if shop_details.is_rounding_adj - a = self.grand_total % 25 # Modulus - b = self.grand_total / 25 # Division - #not calculate rounding if modulus is 0 and division is even - #calculate rounding if modulus is zero or not zero and division are not even - if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) - new_total = Sale.get_rounding_adjustment(self.grand_total) - self.rounding_adjustment = new_total - self.grand_total - else - self.rounding_adjustment = 0.00 - end + new_total = Sale.get_rounding_adjustment(self.grand_total) + self.rounding_adjustment = new_total - self.grand_total + self.old_grand_total = self.grand_total + self.grand_total = new_total else self.rounding_adjustment = 0.00 end end - def compute_adjust_rounding(grand_total) - shop_details = Shop.first - # rounding adjustment - if shop_details.is_rounding_adj - a = grand_total % 25 # Modulus - b = grand_total / 25 # Division - #not calculate rounding if modulus is 0 and division is even - #calculate rounding if modulus is zero or not zero and division are not even - if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) - new_total = Sale.get_rounding_adjustment(grand_total) - rounding_adjustment = new_total - grand_total - else - rounding_adjustment = 0.00 - end - else - rounding_adjustment = 0.00 - end - return rounding_adjustment - end - #Generate new Receipt No when it is not assigned def generate_receipt_no #shop_code and client_code @@ -857,36 +748,16 @@ class Sale < ApplicationRecord # if get_rounded_amt == true value = 0 - num = num.to_f.round - get_last_no = num.to_s.last(2).to_f - if get_last_no.between?(0,25) - ## down to 0 - num -= get_last_no - else - if get_last_no.between?(26,50) - ## up to 50 - value = 50 - get_last_no.to_f - num += value - puts 'up to 50' - else - if get_last_no.between?(51, 75) - ## down to 50 - value = get_last_no.to_f - 50 - num -= value - puts 'down to 50' - else - ## up to 100 - value = 100 - get_last_no.to_f - num += value - puts 'up to 100' - end - end + # num = num.to_f.round + mod = num % 50 + if mod > 0 && mod <= 25 + num -= mod + elsif mod > 25 + num += 50 - mod end - # end return num end - def self.daily_sales_list(from,to) sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN (SUM(sale_payments.payment_amount) + SUM(sale_payments.outstanding_amount)) ELSE 0 END) @@ -2646,20 +2517,15 @@ def self.get_sale_data_for_other_payment_credit(sale_id) end def unique_tax_profiles(order_source, customer_id) - tax_data = TaxProfile.where("group_type='#{order_source}'").pluck(:id) - customer_tax_profiles = Customer.find(customer_id).tax_profiles + tax_data = TaxProfile + .where(group_type: order_source) - arr_data = [] - if !customer_tax_profiles.empty? - customer_tax_profiles.each do |value1| - if tax_data.include? value1.to_i - arr_data.push(value1.to_i) - end - end - return arr_data - else - return tax_data + customer_tax_profiles = Customer.select(:tax_profiles).where(customer_id: customer_id).first + if customer_tax_profiles.present? + tax_data = tax_data.where(id: customer_tax_profiles.tax_profiles) end + + return tax_data end def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) @@ -2892,6 +2758,20 @@ private end end + def round_to_precision + if (self.total_amount != self.total_amount_was || self.total_discount != self.total_discount_was || self.total_tax != self.total_tax_was) + if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0) + precision = PrintSetting.get_precision_delimiter().precision.to_i + + self.total_amount = self.total_amount.round(precision) + self.total_discount = self.total_discount.round(precision) + self.total_tax = self.total_tax.round(precision) + self.grand_total = (self.total_amount - self.total_discount) + self.total_tax + end + adjust_rounding + end + end + def update_stock_journal if self.sale_status == "void" && self.sale_status_before_last_save != "void" self.sale_items.each do |item| diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index d17edc6e..0e073f13 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -11,6 +11,7 @@ class SaleItem < ApplicationRecord def compute_item end + before_validation :round_to_precision after_update :update_stock_journal # Add Sale Items @@ -231,6 +232,24 @@ class SaleItem < ApplicationRecord end end + def round_to_precision + unit_price_fraction = self.unit_price % 1 + price_fraction = self.unit_price % 1 + # is_dining_charge = self.menu_category_code == 'DingingCharge' + + if self.unit_price != self.unit_price_was || self.price != self.price_was + if unit_price_fraction > 0 || price_fraction > 0 + if ['Discount', 'promotion'].include?(self.status) + precision = PrintSetting.get_precision_delimiter().precision.to_i + + self.unit_price = self.unit_price.round(precision) + self.price = (self.unit_price * self.qty).round(precision) + self.taxable_price = self.price + end + end + end + end + def update_stock_journal is_void = self.status == "void" && self.status_before_last_save != "void" cancel_void = self.status_before_last_save == "void" && self.status.nil? diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index bbd68829..bb1375a8 100755 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -6,8 +6,9 @@ class SaleOrder < ApplicationRecord belongs_to :sale belongs_to :order + has_many :order_items, foreign_key: "order_id", primary_key: "order_id" - def create_sale_order(sale_id, order_id) + def create_sale_order(sale_id, order_id) # sale_order = SaleOrder.new self.sale_id = sale_id self.order_id = order_id @@ -37,6 +38,6 @@ class SaleOrder < ApplicationRecord if self.sale_order_id.nil? self.sale_order_id = SeedGenerator.generate_id(self.class.name, 'SOI') end - + end end diff --git a/app/models/sale_tax.rb b/app/models/sale_tax.rb index 06c73253..2e35d2b5 100755 --- a/app/models/sale_tax.rb +++ b/app/models/sale_tax.rb @@ -5,6 +5,8 @@ class SaleTax < ApplicationRecord before_create :generate_custom_id belongs_to :sale + before_validation :round_to_precision + def self.sync_sale_tax_records(sale_taxes) if !sale_taxes.nil? sale_taxes.each do |t| @@ -38,4 +40,13 @@ class SaleTax < ApplicationRecord self.sale_tax_id = SeedGenerator.generate_id(self.class.name, "STI") end end + + def round_to_precision + if self.tax_payable_amount != self.tax_payable_amount_was + if self.tax_payable_amount % 1 > 0 + precision = PrintSetting.get_precision_delimiter().precision.to_i + self.tax_payable_amount = self.tax_payable_amount.round(precision) + end + end + end end diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 3b14e05a..86cf26c7 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -34,7 +34,7 @@ <%end%> - +

Receipt No: <%=@sale_data.receipt_no rescue ' '%>

@@ -57,8 +57,8 @@ <% sub_total = 0 %> <% @sale_data.sale_items.each do |sale_item| %> - <% - sub_total += sale_item.qty*sale_item.unit_price + <% + sub_total += sale_item.qty*sale_item.unit_price if sale_item.price != 0 && sale_item.status != "void" && sale_item.status != "foc" %> > @@ -76,7 +76,7 @@ <% end - end + end %> @@ -130,18 +130,18 @@
-
-
+
+

-
+
<% @accounts.each do |acc| %> <% end %>
-
+
@@ -217,11 +217,11 @@
- +
-
+
@@ -235,7 +235,7 @@
-
+
@@ -243,11 +243,11 @@
-
+
-
+
- + --> @@ -259,7 +259,7 @@ <% if @member_discount%> - <%end %> @@ -300,10 +300,10 @@ var cashier_type = "<%= @cashier_type %>"; case 'num': var input_value = $(this).attr("data-value"); if (original_value == "0.0"){ - $('#discount-amount').val(input_value); + $('#discount-amount').val(input_value); } else{ - $('#discount-amount').val(original_value + '' + input_value); + $('#discount-amount').val(original_value + '' + input_value); } break; case 'add': @@ -313,10 +313,10 @@ var cashier_type = "<%= @cashier_type %>"; break; case 'del' : var discount_text=$('#discount-amount').val(); - $('#discount-amount').val(discount_text.substr(0,discount_text.length-1)); + $('#discount-amount').val(discount_text.substr(0,discount_text.length-1)); break; case 'clr': - $('#discount-amount').val("0.0"); + $('#discount-amount').val("0.0"); break; } event.handled = true; @@ -374,7 +374,7 @@ var cashier_type = "<%= @cashier_type %>"; } } }); - } + } }); // Calculate Net Discount for Payment @@ -384,7 +384,7 @@ var cashier_type = "<%= @cashier_type %>"; var discount_value = $('#discount-amount').val(); var sub_total = parseFloat($('#order-sub-total').text()); var ajax_url = "/origami/" + sale_id + "/discount"; - + if(discount_value!=""){ if(discount_value > 0){ if(parseFloat(discount_value) > sub_total){ @@ -393,7 +393,7 @@ var cashier_type = "<%= @cashier_type %>"; }else{ $("#discount-amountErr").html(""); // Selected Items - var sale_items = get_selected_sale_items(); + var sale_items = get_selected_sale_items(); // Selected Account var account_types = get_selected_account_types(); @@ -402,8 +402,8 @@ var cashier_type = "<%= @cashier_type %>"; calculate_overall_discount(0, discount_value); } else { - calculate_item_discount(0, discount_value, sale_items, account_types); - } + calculate_item_discount(0, discount_value, sale_items, account_types); + } // Remove Selection selection_remove(); @@ -414,7 +414,7 @@ var cashier_type = "<%= @cashier_type %>"; }else{ $("#discount-amountErr").html("can't be blank"); } - + }); // Calculate Percentage Discount for Payment @@ -425,19 +425,19 @@ var cashier_type = "<%= @cashier_type %>"; var ajax_url = "/origami/" + sale_id + "/discount"; // Selected Items - var sale_items = get_selected_sale_items(); + var sale_items = get_selected_sale_items(); // Selected Account var account_types = get_selected_account_types(); - + if(sale_items.length == 0 && account_types.length == 0){ calculate_overall_discount(1, discount_value); } else { - calculate_item_discount(1, discount_value, sale_items, account_types); + calculate_item_discount(1, discount_value, sale_items, account_types); } // Remove Selection - selection_remove(); + selection_remove(); }); // Remove selected discount items @@ -447,8 +447,8 @@ var cashier_type = "<%= @cashier_type %>"; var total = 0; $('.discount-item-row.selected-item').each(function(i){ - var amount = parseFloat($(this).find('#item-total-price').text()); - total = total + Math.abs(amount); + var amount = parseFloat($(this).find('#item-total-price').text()); + total = total + Math.abs(amount); $(this).remove(); }); $("#order-sub-total").text(origin_sub_total + total); @@ -464,8 +464,8 @@ var cashier_type = "<%= @cashier_type %>"; var sale_id = $('#sale-id').text(); var discount_items = JSON.stringify(get_discount_item_rows()); var overall_discount = $("#order-discount").text(); - var sub_total = $('#order-sub-total').text(); - var ajax_url = "/origami/" + sale_id + "/discount"; + var sub_total = $('#order-sub-total').text(); + var ajax_url = "/origami/" + sale_id + "/discount"; var params = { 'cashier_type' : cashier_type,'sale_id': sale_id, 'sub_total': sub_total, 'discount_items': discount_items, 'overall_discount': overall_discount }; @@ -473,8 +473,8 @@ var cashier_type = "<%= @cashier_type %>"; type: "POST", url: ajax_url, data: params, - success:function(result){ - $("#loading_wrapper").hide(); + success:function(result){ + $("#loading_wrapper").hide(); swal({ title: "Information!", text: result.status, @@ -489,7 +489,7 @@ var cashier_type = "<%= @cashier_type %>"; window.location.href = "/origami/room/" + result.table_id } } - }); + }); } }); }); @@ -500,12 +500,12 @@ var cashier_type = "<%= @cashier_type %>"; var sale_id = $('#sale-id').text(); var discount_items = []; - // Selected Items - var sale_items = get_selected_sale_items(); + // Selected Items + var sale_items = get_selected_sale_items(); if(sale_items.length == 0){ //swal("Information!", "You have no selected item!"); - swal ( "Oops" , "You have no selected item!" , "error" ); - return; + swal ( "Oops" , "You have no selected item!" , "error" ); + return; } for(var i=0;i < sale_items.length;i++){ @@ -514,7 +514,7 @@ var cashier_type = "<%= @cashier_type %>"; } else { swal ("Oops" , "You have no selected item!" , "error" ); - return; + return; } } @@ -539,7 +539,7 @@ var cashier_type = "<%= @cashier_type %>"; window.location.href = "/origami/room/" + result.table_id } } - }); + }); } }); }); @@ -566,7 +566,7 @@ var cashier_type = "<%= @cashier_type %>"; window.location.href = "/origami/room/" + result.table_id } } - }); + }); } }); }); @@ -575,8 +575,8 @@ var cashier_type = "<%= @cashier_type %>"; $("#member-discount").on('click', function(e){ e.preventDefault(); var sale_id = $('#sale-id').text(); - var sub_total = $('#order-sub-total').text(); - var ajax_url = "/origami/" + sale_id + "/member_discount"; + var sub_total = $('#order-sub-total').text(); + var ajax_url = "/origami/" + sale_id + "/member_discount"; // Selected Account //var account_types = JSON.stringify(get_selected_account_types()); @@ -618,7 +618,7 @@ var cashier_type = "<%= @cashier_type %>"; }); } }); - + });//end member discount }); @@ -631,7 +631,7 @@ var cashier_type = "<%= @cashier_type %>"; /* Get Item rows but not discount*/ function get_item_rows(){ - var sale_items = []; + var sale_items = []; $('.item-row').not('.discount-item-row').each(function(i){ var sale_item = {}; sale_item.id = $(this).attr('id').substr(0,16); @@ -639,13 +639,13 @@ var cashier_type = "<%= @cashier_type %>"; sale_item.account_id = $(this).find('#item-account-type').text(); sale_item.price = $(this).find('#item-total-price').text(); sale_items.push(sale_item); - }); + }); return sale_items; } /* Get discount Item rows */ function get_discount_item_rows(){ - var sale_items = []; + var sale_items = []; $('.discount-item-row').each(function(i){ var sale_item = {}; sale_item.id = $(this).attr('id'); @@ -653,13 +653,13 @@ var cashier_type = "<%= @cashier_type %>"; sale_item.account_id = $(this).find('#item_account_type').text(); sale_item.price = $(this).find('#item-total-price').text(); sale_items.push(sale_item); - }); + }); return sale_items; } /* Get discount Item rows */ // function get_selected_discount_items(){ -// var sale_items = []; +// var sale_items = []; // $('.discount-item-row').hasClass('.selected-item').each(function(i){ // var sale_item = {}; // sale_item.id = $(this).attr('id'); @@ -667,13 +667,13 @@ var cashier_type = "<%= @cashier_type %>"; // sale_item.account_id = $(this).find('#item_account_type').text(); // sale_item.price = $(this).find('#item-total-price').text(); // sale_items.push(sale_item); -// }); +// }); // return sale_items; // } /* Get Selected Sale Item's ID and Price */ function get_selected_sale_items(){ - var sale_items = []; + var sale_items = []; $('.item-row.selected-item').each(function(i){ var sale_item = {}; sale_item.id = $(this).attr('id').substr(0,16); @@ -681,33 +681,33 @@ function get_selected_sale_items(){ sale_item.account_id = $(this).find('#item-account-type').text(); sale_item.price = $(this).find('#item-total-price').text(); sale_items.push(sale_item); - }); + }); return sale_items; } /* Get Selected Accounts ID and Price */ -function get_selected_account_types(){ +function get_selected_account_types(){ var account_types = []; $('.selected-account').each(function(i){ var account= {}; account.id = $(this).attr('id').substr(8); - account.name = $(this).text(); + account.name = $(this).text(); account_types.push(account); - }); + }); return account_types; } /* Calculate Overall Discount*/ function calculate_overall_discount(type, amount){ - var origin_sub_total = parseFloat($("#order-sub-total").text()); + var origin_sub_total = parseFloat($("#order-sub-total").text()); var dis_amount = 0; var sub_total = 0; var total_discount = 0; // For Net Pay if(type == 0){ - total_discount = amount; + total_discount = Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision); } // For Percentage Pay @@ -719,10 +719,10 @@ function calculate_overall_discount(type, amount){ type: "error", confirmButtonText: 'OK', confirmButtonColor:"red" - }); + }); } else{ - total_discount = (origin_sub_total * amount)/100; + total_discount = Math.round(origin_sub_total * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision); } } @@ -731,22 +731,23 @@ function calculate_overall_discount(type, amount){ /* Calculate Items Discount*/ function calculate_item_discount(type, amount, sale_items, account_types){ - var origin_sub_total = parseFloat($("#order-sub-total").text()); + var origin_sub_total = parseFloat($("#order-sub-total").text()); var dis_amount = 0; var sub_total = 0; var total_discount = 0; var arrItemName = ""; + var precision = <%= precision %>; $("#discount_itemsErr").html(""); $("#discount-amountErr").html(""); // For Net Pay if(origin_sub_total > 0){ if(type == 0){ - dis_amount = (0 - amount); + dis_amount = -Math.round(amount * Math.pow(10, precision)) / Math.pow(10, precision); if(sale_items.length > 0){ for(var i=0;i < sale_items.length;i++){ // if(account_types.length > 0){ // for(var j=0; j < account_types.length; j++){ - // if(sale_items[i].account_id == account_types[j].id){ + // if(sale_items[i].account_id == account_types[j].id){ // // Discount Items // var discount_item_row = item_row_template(type, sale_items[i], dis_amount, amount); // $("#order-items-table tbody").append(discount_item_row); @@ -768,7 +769,7 @@ function calculate_item_discount(type, amount, sale_items, account_types){ $("#discount-amountErr").html("Discount is greater than sub total!"); } } - + // } } } @@ -782,11 +783,11 @@ function calculate_item_discount(type, amount, sale_items, account_types){ }else{ $("#discount_itemsErr").html("Discount is greater than "+arrItemName+" price"); } - + } - + // No Needs For Auto Selected - // if(account_types.length > 0){ + // if(account_types.length > 0){ // var item_rows=get_item_rows(); // if(item_rows.length > 0){ // for(var k=0; k < item_rows.length; k++){ @@ -802,7 +803,7 @@ function calculate_item_discount(type, amount, sale_items, account_types){ // } // else { // alert("No Items!"); - // } + // } // } sub_total = parseFloat(origin_sub_total) - parseFloat(total_discount); @@ -817,7 +818,7 @@ function calculate_item_discount(type, amount, sale_items, account_types){ type: "error", confirmButtonText: 'OK', confirmButtonColor:"red" - }); + }); } else{ // Check sale items exists @@ -825,7 +826,7 @@ function calculate_item_discount(type, amount, sale_items, account_types){ for(var i=0;i < sale_items.length;i++){ // if(account_types.length > 0){ // for(var j=0; j < account_types.length; j++){ - // if(sale_items[i].account_id == account_types[j].id){ + // if(sale_items[i].account_id == account_types[j].id){ // // Discount Items // dis_amount = 0 - ((sale_items[i].price * amount)/100); // var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); @@ -835,9 +836,9 @@ function calculate_item_discount(type, amount, sale_items, account_types){ // } // } // else { - dis_amount = 0 - ((sale_items[i].price * amount)/100); + dis_amount = -Math.round(sale_items[i].price * amount / 100 * Math.pow(10, precision)) / Math.pow(10, precision); var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount); - + total_discount = total_discount + dis_amount; if(parseFloat(origin_sub_total) >= parseFloat(total_discount)){ $("#order-items-table tbody").append(discount_item_row); @@ -852,14 +853,14 @@ function calculate_item_discount(type, amount, sale_items, account_types){ } // No Needs For Auto Selected // Check account types exists - // if(account_types.length > 0){ + // if(account_types.length > 0){ // var item_rows=get_item_rows(); // console.log(account_types); // if(item_rows.length > 0){ // for(var k=0; k < item_rows.length; k++){ // for(var j=0; j < account_types.length; j++){ // if(item_rows[k].account_id == account_types[j].id){ - // // Discount Items + // // Discount Items // dis_amount = 0 - ((item_rows[k].price * amount)/100); // var discount_item_row = item_row_template(type, item_rows[k], dis_amount, amount); // $("#order-items-table tbody").append(discount_item_row); @@ -870,15 +871,15 @@ function calculate_item_discount(type, amount, sale_items, account_types){ // } // else { // alert("No Items!"); - // } - // } + // } + // } } - + $("#order-sub-total").text(parseFloat(sub_total).toFixed(<%= precision.to_i %>)); }else{ $("#discount-amountErr").html("Discount is greater than sub total!"); } - + } function item_row_template(type, item, discount_amount, amount){ @@ -887,24 +888,24 @@ function item_row_template(type, item, discount_amount, amount){ dis_str = dis_str + "(" + amount + "%)" } var discount_item_row = "" + - "" + - "" + "" + - "" + + "" + "1" + "" + - "" + - "" + + "" + + "" + discount_amount + - "" + + "" + "" + ""; - return discount_item_row; + return discount_item_row; } diff --git a/app/views/reports/receipt_no/index.html.erb b/app/views/reports/receipt_no/index.html.erb index fbd49e3e..ab8edfd0 100755 --- a/app/views/reports/receipt_no/index.html.erb +++ b/app/views/reports/receipt_no/index.html.erb @@ -98,8 +98,8 @@ <%if !@sale_data.nil? %> <% @sale_data.each do |result| %> - <% grand_total +=result.grand_total.to_f %> - <% old_grand_total += result.grand_total_after_rounding() %> + <% grand_total += result.grand_total.to_f %> + <% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %> <% total_tax += result.total_tax.to_f %> <% total_sum += result.total_amount.to_f %> <% discount_amt += result.total_discount.to_f %> @@ -127,47 +127,35 @@ <%= number_with_precision(result.total_amount, precision: precision.to_i ,delimiter: delimiter) %> <%= number_with_precision(result.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue '0' %> - <% if !result.sale_taxes.empty? %> - <% num = 1 - if tax_flag && tax_count > 0 %> - <% while num <= tax_count %> - - <%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> - - <% num += 1 - end %> - <% end %> - <% result.sale_taxes.each do |tax| %> - - <%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - - <%end%> - <% num = 1 - if tax_flag==false && tax_count > 0 %> - <% while num <= tax_count %> - - <%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> - - <% num += 1 - end %> - <% end %> - <% else %> - <% @tax_profiles.each do |tax| %> - <%= number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <% end %> - <%end%> + <% num = 1 %> + <% if tax_flag && tax_count > 0 %> + <% while num <= tax_count %> + 0 + <% num += 1 %> + <% end %> + <% end %> + <% result.sale_taxes.each do |tax| %> + + <%= number_with_precision(tax.tax_payable_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + + <%end%> + <% num = 1 %> + <% if !tax_flag && tax_count > 0 %> + <% while num <= tax_count %> + 0 + <% num += 1 %> + <% end %> + <% end %> + <% else %> + <% @tax_profiles.each do |tax| %> + 0 + <% end %> + <%end%> - <% if result.old_grand_total.nil? %> - <%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%else%> - <%= number_with_precision(result.old_grand_total, precision: precision.to_i ,delimiter: delimiter) rescue '-' %> - <%end%> - - <%= result.rounding_adjustment.to_f rescue '-' %> - <%= number_with_precision(result.grand_total, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_with_precision(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_with_precision(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %> + <%= number_with_precision(result.grand_total, precision: precision.to_i, delimiter: delimiter) %> <% if @lookup.value.to_i == 1 %> diff --git a/app/views/reports/receipt_no/index.xls.erb b/app/views/reports/receipt_no/index.xls.erb index 66734e56..a221934f 100755 --- a/app/views/reports/receipt_no/index.xls.erb +++ b/app/views/reports/receipt_no/index.xls.erb @@ -16,21 +16,21 @@ <% if @shift_from %> - <% if @shift_data.employee %> + <% if @shift_data.employee %> <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> - <% end %> + <% end %> <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> ) - <% end %> + <% end %> <%= t("views.right_panel.detail.dining") %> <%= t("views.right_panel.detail.receipt_no") %> - <%= t :cashier %> <%= t("views.right_panel.detail.name") %> + <%= t :cashier %> <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %> <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> <% @tax_profiles.each do |tax| %> - <%= tax.name %> + <%= tax.name %> <% end %> <%= t("views.right_panel.detail.grand_total") %> @@ -45,36 +45,36 @@ <% old_grand_total = 0 %> <% total_tax = 0 %> <% guest_count = 0 %> - <% total_sum = 0 %> - <% discount_amt = 0 %> + <% total_sum = 0 %> + <% discount_amt = 0 %> <% other_amt = 0 %> - <% total_nett = 0 %> - <% rounding_adj = 0%> <% gov_tax = 0 %> <% service_charge = 0 %> + <% total_nett = 0 %> + <% rounding_adj = 0%> <% gov_tax = 0 %> <% service_charge = 0 %> <% tax_profile_count = @tax_profiles.length %> - <% + <% ttax_count = tax_profile_count - @sale_taxes.length ttax_flag = true - @sale_taxes.each do |tax| + @sale_taxes.each do |tax| if tax.tax_name.downcase.include?("service") ttax_flag = false end - end + end %> - <%if @sale_data %> + <%if @sale_data %> <% @sale_data.each do |result| %> - <% grand_total = grand_total.to_f + result.grand_total.to_f %> - <% old_grand_total = old_grand_total.to_f + result.old_grand_total.to_f %> + <% grand_total += result.grand_total.to_f %> + <% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %> <% total_tax += result.total_tax.to_f %> - <% total_sum += result.total_amount.to_f %> + <% total_sum += result.total_amount.to_f %> <% discount_amt += result.total_discount.to_f %> <% rounding_adj += result.rounding_adjustment.to_f %> <% sale_tax_count = result.sale_taxes.length %> <% tax_count = tax_profile_count - sale_tax_count %> <% tax_flag = true %> - <% result.sale_taxes.each do |tax| + <% result.sale_taxes.each do |tax| if tax.tax_name.downcase.include?("service") tax_flag = false end @@ -82,7 +82,7 @@ <%if result.type %> - <%= result.type %> - <%= result.name %> + <%= result.type %> - <%= result.name %> <% else %> - <% end %> @@ -91,15 +91,13 @@ <%= result.cashier_name rescue '-' %> <%= result.total_amount rescue '-' %> <%= result.total_discount rescue '-' %> - + <% if !result.sale_taxes.empty? %> - <% num = 1 + <% num = 1 if tax_flag && tax_count > 0 %> <% while num <= tax_count %> 0 - <% num += 1 + <% num += 1 end %> <% end %> <% result.sale_taxes.each do |tax| %> @@ -107,11 +105,11 @@ <%= tax.tax_payable_amount rescue '-' %> <%end%> - <% num = 1 + <% num = 1 if tax_flag==false && tax_count > 0 %> <% while num <= tax_count %> 0 - <% num += 1 + <% num += 1 end %> <% end %> <% else %> @@ -120,9 +118,9 @@ <% end %> <%end%> - <%= result.grand_total %> - <%= result.rounding_adjustment.to_f rescue '-' %> - <%= result.grand_total_after_rounding() rescue '-'%> + <%= result.grand_total - result.rounding_adjustment %> + <%= result.rounding_adjustment.to_f rescue '-' %> + <%= result.grand_total rescue '-'%> <% end %> @@ -134,11 +132,11 @@ <%= tax.st_amount.round(2) %> <% end %> --> <% if !@sale_taxes.empty? %> - <% num = 1 + <% num = 1 if ttax_flag && ttax_count > 0 %> <% while num <= ttax_count %> 0.00 - <% num += 1 + <% num += 1 end %> <% end %> <% @sale_taxes.each do |tax| %> @@ -146,11 +144,11 @@ <%= tax.st_amount.to_f.round(2) %> <%end%> - <% num = 1 + <% num = 1 if ttax_flag==false && ttax_count > 0 %> <% while num <= ttax_count %> 0.00 - <% num += 1 + <% num += 1 end %> <% end %> <% else %> @@ -158,15 +156,15 @@ 0.00 <% end %> <%end%> - <%= grand_total.to_f.round(2) rescue '-'%> - <%= rounding_adj rescue '-'%> - <%= grand_total.to_f.round + rounding_adj %> + <%= grand_total.to_f.round(2) rescue '-'%> + <%= rounding_adj rescue '-'%> + <%= grand_total.to_f.round + rounding_adj %>   <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %> <%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> - + <% @tax_profiles.each do |tax| %> <%= tax.name %> <% end %> @@ -184,4 +182,4 @@ - \ No newline at end of file + From 834df19e037ed0cfbc8c152fdd1d12082d083342 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Fri, 8 Nov 2019 09:58:52 +0630 Subject: [PATCH 13/49] use precision for rounding adj in receipt report. bug fixes for discount. --- app/views/origami/discounts/index.html.erb | 200 ++++++++++---------- app/views/reports/receipt_no/index.html.erb | 25 +-- 2 files changed, 116 insertions(+), 109 deletions(-) diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index 86cf26c7..abeeb442 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -44,24 +44,22 @@
-
- - - - - - +
+ +
ItemsQTY
+ + + + - - + + <% sub_total = 0 %> <% @sale_data.sale_items.each do |sale_item| %> - <% - sub_total += sale_item.qty*sale_item.unit_price - if sale_item.price != 0 && sale_item.status != "void" && sale_item.status != "foc" - %> - > + <% sub_total += sale_item.qty * sale_item.unit_price %> + <% if sale_item.price > 0 && sale_item.status.blank? %> + > - <% - end - end - %> - -
ItemsQTY Price
@@ -74,14 +72,26 @@ <%=(sale_item.qty*sale_item.unit_price)%>
-
-
+ <% elsif sale_item.price < 0 && sale_item.status == "Discount" %> + > + + + + <%=sale_item.product_name%>@<%=sale_item.unit_price%> + + + <%=sale_item.qty.abs%> + + + <%=(sale_item.qty*sale_item.unit_price)%> + + + <% end %> + <% end %> + + + + - - + + <% end %> + + + + + diff --git a/app/views/reports/staff_meal/_staff_meal_report_filter.html.erb b/app/views/reports/staff_meal/_staff_meal_report_filter.html.erb new file mode 100644 index 00000000..04108f48 --- /dev/null +++ b/app/views/reports/staff_meal/_staff_meal_report_filter.html.erb @@ -0,0 +1,146 @@ +
+ <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
+
+ + +
+ + +
+ + + +
+
+ + + +
+
+ + +
+
+ + +
+
+ + +
+
+ <% end %> + + <% end %> +
+ + diff --git a/app/views/reports/staff_meal/index.html.erb b/app/views/reports/staff_meal/index.html.erb new file mode 100644 index 00000000..ea92f55c --- /dev/null +++ b/app/views/reports/staff_meal/index.html.erb @@ -0,0 +1,390 @@ + +
+
+ <%= render :partial=>'staff_meal_report_filter', + :locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_staff_meal_index_path} %> + +
+ + + +
+
+
+ + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + <% p_qty = 0 %> + <% sub_qty = 0 %> + <% sub_total = 0 %> + <% other_sub_total = 0 %> + <% product_sub_total = 0 %> + <% count = 0 %> + <% row_count = 0 %> + <% total_price = 0 %> + <% cate_count = 0 %> + <% acc_count = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> + <% total_amount = 0 %> + <% discount = 0 %> + <% total_item_foc = 0 %> + <% total_item_dis = 0.0 %> + <% total_tax = 0 %> + <% unless @sale_data.blank? %> + <% @sale_data.each do |sale| %> + <% row_count += 1 %> + + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + total_item_foc += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "Discount" && sale.grand_total < 0 + total_item_dis += sale.grand_total*(-1) + end %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + <% if sale.status_type != "Discount" %> + + <%else%> + + <% end %> + + + + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.account_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% #sub_qty += sale.total_item %> + <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" + sub_qty += sale.total_item + end %> + <% if sale.status_type =="Discount" + sub_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "promotion" && @type == "promotion" + sub_qty += sale.total_item*(-1) + end %> + <% if count == value %> + + + + + + + + <% sub_total = 0.0%> + <% sub_qty = 0 %> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% end %> + + <% if @product.present?%> + + + + + + + <% @product.each do |product| %> + <% if product.total_item > 0 + total_qty += product.total_item + end %> + <% grand_total +=product.grand_total + p_qty += product.total_item%> + + + + + + + + + + + + <% product_sub_total += product.grand_total %> + + <% end %> + + + + + + + + + <%end%> + + + + + + + + + + + + + <% if @type =="" || @type =="all" || @type.nil? %> + + + <% end %> + <% end %> + <% if @type == "other"%> + + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%> + +
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
<%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
 <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
<%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> + <% end %> + <% end %> +
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.total_item*(-1) rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
Product 
 Product<%= product.product_code rescue '-' %><%= product.product_name rescue '-' %><%= product.total_item rescue '-' %> <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 Total Product Qty <%= p_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
 <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
Other Charges 
 Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
+ +
+
+
+
+
+ + diff --git a/app/views/reports/staff_meal/index.xls.erb b/app/views/reports/staff_meal/index.xls.erb new file mode 100644 index 00000000..5bd390fd --- /dev/null +++ b/app/views/reports/staff_meal/index.xls.erb @@ -0,0 +1,277 @@ + + + + + + + +
+
+
+
+
+ + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% acc_arr = Array.new %> + <% cate_arr = Array.new %> + <% p_qty = 0 %> + <% sub_qty = 0 %> + <% sub_total = 0 %> + <% other_sub_total = 0 %> + <% product_sub_total = 0 %> + <% count = 0 %> + <% row_count = 0 %> + <% total_price = 0 %> + <% cate_count = 0 %> + <% acc_count = 0 %> + <% grand_total = 0 %> + <% total_qty = 0 %> + <% total_amount = 0 %> + <% discount = 0 %> + <% total_item_foc = 0 %> + <% total_item_dis = 0.0 %> + <% total_tax = 0 %> + <% unless @sale_data.blank? %> + <% @sale_data.each do |sale| %> + <% row_count += 1 %> + + + <% if sale.status_type != "Discount" && sale.status_type != "foc" && sale.status_type != "promotion" + total_qty += sale.total_item + end %> + <% if sale.status_type == "foc" && sale.price > 0 + total_qty += sale.total_item + end %> + <% if sale.status_type == "Discount" + total_qty += sale.total_item*(-1) + end %> + <% if sale.status_type =="promotion" && @type == "promotion" + total_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "foc" && sale.grand_total < 0 + total_item_foc += sale.grand_total*(-1) + end %> + + <% if sale.status_type == "Discount" && sale.grand_total < 0 + total_item_dis += sale.grand_total*(-1) + end %> + + <% if !acc_arr.include?(sale.account_id) %> + + + + + + + <% acc_arr.push(sale.account_id) %> + <% end %> + + + <% if !cate_arr.include?(sale.menu_category_id) %> + + <% cate_arr.push(sale.menu_category_id) %> + <% else %> + + <% end %> + + + <% if sale.status_type != "Discount" %> + + <%else%> + + <% end %> + + + + + + + <% @menu_cate_count.each do |key,value| %> + <% if sale.account_id == key %> + <% count = count + 1 %> + <% sub_total += sale.grand_total %> + <% #sub_qty += sale.total_item %> + <% if sale.status_type !="Discount" && (!sale.product_name.include? "FOC") && sale.status_type != "promotion" + sub_qty += sale.total_item + end %> + <% if sale.status_type =="Discount" + sub_qty += sale.total_item*(-1) + end %> + + <% if sale.status_type == "promotion" && @type == "promotion" + sub_qty += sale.total_item*(-1) + end %> + <% if count == value %> + + + + + + + + <% sub_total = 0.0%> + <% sub_qty = 0 %> + <% count = 0%> + <% end %> + <% end %> + <% end %> + + <% end %> + + <% if @product.present?%> + + + + + + + <% @product.each do |product| %> + <% if product.total_item > 0 + total_qty += product.total_item + end %> + <% grand_total +=product.grand_total + p_qty += product.total_item%> + + + + + + + + + + + + <% product_sub_total += product.grand_total %> + + <% end %> + + + + + + + + + <%end%> + + + + + + + + + + + + + <% if @type =="" || @type =="all" || @type.nil? %> + + + <% end %> + <% end %> + <% if @type == "other"%> + + + + + + <% @other_charges.each do |other| %> + <% if other.total_item > 0 + total_qty += other.total_item + end %> + <% grand_total +=other.grand_total%> + + + + + + + + + + + + <% other_sub_total += other.grand_total %> + + <% end %> + + + + + + <%end%> + +
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
<%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
 <%= t("views.right_panel.header.menu_category") %><%= t("views.right_panel.detail.code") %><%= t("views.right_panel.detail.product") %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= t("views.right_panel.detail.unit_price") %><%= t("views.right_panel.detail.revenue") %>
<%= sale.account_name %> <%= t("views.right_panel.detail.total_price_by") %> <%= sale.account_name %> + <% @totalByAccount.each do |account, total| %> + <% if sale.account_id == account %> + <%= number_with_precision(total, precision:precision.to_i,delimiter:delimiter) %> + <% grand_total += total %> + <% end %> + <% end %> +
 <%= sale.menu_category_name %> <%= sale.item_code rescue '-' %><%= sale.product_name rescue '-' %><%= sale.total_item rescue '-' %><%= sale.total_item*(-1) rescue '-' %><%= number_with_precision(sale.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_with_precision(sale.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 Total <%= sale.account_name %> Qty <%= sub_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(sub_total , precision:precision.to_i,delimiter:delimiter)%>
Product 
 Product<%= product.product_code rescue '-' %><%= product.product_name rescue '-' %><%= product.total_item rescue '-' %> <%= number_with_precision(product.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(product.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 Total Product Qty <%= p_qty %><%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(product_sub_total , precision:precision.to_i,delimiter:delimiter)%>
 <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.item") %><%= total_qty%><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= number_with_precision(grand_total , precision:precision.to_i,delimiter:delimiter)%>
Other Charges 
 Other Charges<%= other.item_code rescue '-' %><%= other.product_name rescue '-' %><%= other.total_item rescue '-' %> <%= number_with_precision(other.unit_price , precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_with_precision(other.grand_total , precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 <%= t("views.right_panel.detail.sub_total") %><%= number_with_precision(other_sub_total , precision:precision.to_i,delimiter:delimiter)%>
+ +
+
+
+
+
+ + + diff --git a/config/routes.rb b/config/routes.rb index b3c5ff6e..933002d9 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -532,6 +532,7 @@ scope "(:locale)", locale: /en|mm/ do resources :dailysale, :only => [:index, :show] resources :saleitem, :only => [:index, :show] resources :hourly_saleitem, :only => [:index, :show] + resources :staff_meal, :only => [:index, :show] resources :shiftsale, :only => [:index, :show] resources :credit_payment, :only => [:index, :show] resources :void_sale, :only => [:index, :show] From a3e4cc899360f4b1699c713c7bac6273913571e2 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 18 Nov 2019 10:09:40 +0630 Subject: [PATCH 24/49] optimize for dashboards --- app/controllers/home_controller.rb | 2 +- .../origami/dashboard_controller.rb | 14 +- app/models/menu_category.rb | 24 +- app/models/menu_item.rb | 4 +- app/models/sale.rb | 877 ++++-------------- app/models/sale_audit.rb | 4 +- app/models/sale_payment.rb | 5 + app/models/shift_sale.rb | 41 +- .../addorders/_menu_item.json.jbuilder | 86 +- .../origami/dashboard/_menu.json.jbuilder | 71 +- 10 files changed, 321 insertions(+), 807 deletions(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 49b4ff5d..d9c67962 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -118,7 +118,7 @@ class HomeController < ApplicationController # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) logger.debug 'hourly_sales<>><><><<<<<<>><<<><><><><><><><><><<>><' - logger.debug @hourly_sales.to_json + logger.debug @hourly_sales.to_json employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time) # .sum("(CASE WHEN sp.payment_method='cash' THEN ((sp.payment_amount) - (sales.amount_changed)) ELSE (sp.payment_amount) END)") @employee_sales = [] diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index 25ea8390..1daa652b 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -4,7 +4,7 @@ class Origami::DashboardController < BaseOrigamiController @shop = Shop.first today = DateTime.now.strftime('%Y-%m-%d') - + @display_type = Lookup.find_by_lookup_type("display_type") @sale_data = Array.new @@ -14,7 +14,7 @@ class Origami::DashboardController < BaseOrigamiController if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" pay = Sale.payment_sale('card', today, current_user) @sale_data.push({'card' => pay.payment_amount}) - else + else pay = Sale.payment_sale(payment.payment_method, today, current_user) @sale_data.push({payment.payment_method => pay.payment_amount}) end @@ -38,10 +38,10 @@ class Origami::DashboardController < BaseOrigamiController end else @account_data = nil - end + end @top_items = Sale.top_items(today,current_user) - @total_foc_items = Sale.total_foc_items(today,current_user) + @total_foc_items = Sale.total_foc_items(today,current_user) # get printer info @print_settings = PrintSetting.get_precision_delimiter() @@ -104,12 +104,14 @@ class Origami::DashboardController < BaseOrigamiController end def get_all_menu - @menus = Menu.active.all + @menus = Menu.includes(:menu_categories => {:menu_items => :menu_item_instances}).includes(:menu_categories => {:menu_items => :item_sets }).active.all + @item_attributes = MenuItemAttribute.all.load + @item_options = MenuItemOption.all.load end def get_credit_sales credit_sales = SalePayment.get_credit_sales(params) - if !credit_sales.nil? + if !credit_sales.nil? result = {:status=> true, :data=> credit_sales } else result = {:status=> false, :message=>"There is no record." } diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index 746bcb79..d8597afa 100755 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -1,7 +1,7 @@ -class MenuCategory < ApplicationRecord +class MenuCategory < ApplicationRecord # before_create :generate_menu_category_code - belongs_to :menu + belongs_to :menu has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id" belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true has_many :menu_items @@ -38,9 +38,7 @@ class MenuCategory < ApplicationRecord end def valid_time - - menu_category = MenuCategory.find(self.id) - menu = Menu.find(menu_category.menu_id) + menu = self.menu from_t = Time.parse(menu.valid_time_from.strftime("%H:%M:%S")) to_t = Time.parse(menu.valid_time_to.strftime("%H:%M:%S")) @@ -64,7 +62,7 @@ class MenuCategory < ApplicationRecord c +=24 current = c*3600 + current_t.min* 60 + current_t.sec - + end end else # (after) noon @@ -77,8 +75,8 @@ class MenuCategory < ApplicationRecord day = Date.today.wday dayresult = menu.valid_days.include?(day.to_s) - - + + if current.between?(from, to) && menu.valid_days.include?(day.to_s) return true else @@ -104,12 +102,12 @@ class MenuCategory < ApplicationRecord private - # def generate_menu_category_code - # self.code = SeedGenerator.generate_code(self.class.name, "C") + # def generate_menu_category_code + # self.code = SeedGenerator.generate_code(self.class.name, "C") # end def self.to_csv - + mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at} CSV.generate(headers: true) do |csv| csv << mc_attributes @@ -123,7 +121,3 @@ class MenuCategory < ApplicationRecord end end - - - - diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 03e90011..59791cb2 100755 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -11,11 +11,11 @@ class MenuItem < ApplicationRecord belongs_to :account has_many :menu_item_sets - has_many :item_sets, through: :menu_item_sets + has_and_belongs_to_many :item_sets, join_table: "menu_item_sets" validates_presence_of :item_code, :name, :type, :min_qty,:account_id validates_uniqueness_of :item_code - + default_scope { order('item_code asc') } scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') } diff --git a/app/models/sale.rb b/app/models/sale.rb index 98457d0e..98252dbb 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -4,9 +4,9 @@ class Sale < ApplicationRecord #primary key - need to be unique generated for multiple shops before_create :generate_custom_id before_create :generate_receipt_no - belongs_to :cashier, :optional => true + belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee" belongs_to :customer, :optional => true - belongs_to :employees + belongs_to :shift_sale has_many :sale_items has_many :sale_discount_items has_many :sale_discounts @@ -23,6 +23,12 @@ class Sale < ApplicationRecord scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } scope :complete_sale, -> { where("sale_status = 'completed' and receipt_date BETWEEN '#{DateTime.now.utc.beginning_of_day}' AND '#{DateTime.now.utc.end_of_day}'") } + scope :paid, -> { where(payment_status: 'paid')} + scope :completed, -> { where(sale_status: 'completed') } + scope :date_on, -> (date) { where("DATE(CONVERT_TZ(receipt_date, '+00:00', ?)) = ?", Time.zone.formatted_offset, date) } + scope :date_between, -> (from, to) { where("DATE(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) } + scope :time_between, -> (from, to) { where("TIME(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) } + scope :along_with_sale_payments_except_void, -> { joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'))") } def qty_of(item_instance_code) order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first @@ -770,7 +776,7 @@ def self.daily_sales_list(from,to) ELSE 0 END as credit_amount, SUM(case when (sale_payments.payment_method='giftvoucher') then sale_payments.payment_amount else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='foc') then sale_payments.payment_amount else 0 end) as foc_amount") - .joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'))") + .along_with_sale_payments_except_void .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) .group("sale_id").to_sql @@ -1104,41 +1110,36 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay end def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter,order_source) - order_sources = Order.select("sale_orders.sale_id, orders.source") - .joins(:sale_orders).to_sql - - credit_payments = SalePayment.select(" + payments_for_credits = SalePayment.select(" sales.sale_id, DATE_FORMAT(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30'),'%d %b %y %h:%i%p') as credit_payment_receipt_date, sale_payments.payment_amount as credit_payment, employees.name as credit_payment_cashier_name, - CONCAT(DATE_FORMAT(CONVERT_TZ(shift_started_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'),' - ',DATE_FORMAT(CONVERT_TZ(shift_closed_at,'+00:00','+06:30'),'%d %b %y %h:%i%p')) as credit_payment_shift_name") - .joins("JOIN sales ON sales.sale_id = sale_payments.sale_id") - .joins("JOIN sale_audits ON sale_audits.sale_id = sales.sale_id AND SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id") - .joins("JOIN shift_sales ON shift_sales.id = sales.shift_sale_id") - .joins("JOIN employees ON employees.id = shift_sales.employee_id").to_sql + CONCAT(DATE_FORMAT(CONVERT_TZ(shift_sales.shift_started_at,'+00:00','+06:30'),'%d %b %y %h:%i%p'),' - ',DATE_FORMAT(CONVERT_TZ(shift_sales.shift_closed_at,'+00:00','+06:30'),'%d %b %y %h:%i%p')) as credit_payment_shift_name") + .joins(:sale_audit) + .joins(:sale => :shift_sale) + .joins(:sale => :cashier).to_sql credits = SalePayment.select(" sale_payments.sale_payment_id, sale_payments.payment_method, sale_payments.payment_amount, sale_payments.payment_status, - sales.sale_id, - sales.receipt_no, - sales.receipt_date as sale_date, - order_sources.source as order_source, - sales.cashier_name, + sales_sale_payments.sale_id, + sales_sale_payments.receipt_no, + sales_sale_payments.receipt_date as sale_date, + sales_sale_payments.cashier_name, + orders.source as order_source, customers.name as customer_name, - IFNULL(credit_payments.credit_payment_receipt_date, '-') as credit_payment_receipt_date, - IFNULL(credit_payments.credit_payment, 0) as credit_payment, - IFNULL(credit_payments.credit_payment_cashier_name, '-') as credit_payment_cashier_name, - IFNULL(credit_payments.credit_payment_shift_name, '-') as credit_payment_shift_name") - .joins("JOIN sales ON sales.sale_id = sale_payments.sale_id") - .joins("JOIN shift_sales ON shift_sales.id = sales.shift_sale_id") - .joins("JOIN customers ON customers.customer_id = sales.customer_id") - .joins("JOIN (#{order_sources}) order_sources ON order_sources.sale_id = sales.sale_id") - .joins("LEFT JOIN (#{credit_payments}) credit_payments ON credit_payments.sale_id = sales.sale_id") - .where("sale_payments.payment_method= ? AND sales.sale_status = ?", 'creditnote', 'completed') + IFNULL(payments_for_credits.credit_payment_receipt_date, '-') as credit_payment_receipt_date, + IFNULL(payments_for_credits.credit_payment, 0) as credit_payment, + IFNULL(payments_for_credits.credit_payment_cashier_name, '-') as credit_payment_cashier_name, + IFNULL(payments_for_credits.credit_payment_shift_name, '-') as credit_payment_shift_name") + .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales_sale_payments.sale_id") + .joins(:sale => :customer) + .joins(:sale => :orders) + .credits + .where("sales_sale_payments.sale_status = ?", 'completed') if order_source.present? if order_source == "cashier" @@ -1149,19 +1150,19 @@ def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to,filter, end if filter == 'paid' - credits = credits.where("credit_payment IS NOT NULL") + credits = credits.where("payments_for_credits IS NOT NULL") elsif filter == 'unpaid' - credits = credits.where("credit_payment IS NULL") + credits = credits.where("payments_for_credits IS NULL") end if shift.present? - credits = credits.where("sales.shift_sale_id in (?)",shift.to_a) + credits = credits.where("sales_sale_payments.shift_sale_id in (?)",shift.to_a) elsif shift_sale_range.present? - credits = credits.where("sales.shift_sale_id in (?)",shift_sale_range.to_a) + credits = credits.where("sales_sale_payments.shift_sale_id in (?)",shift_sale_range.to_a) else - credits = credits.where("sales.receipt_date between ? and ?",from,to) + credits = credits.where("sales_sale_payments.receipt_date between ? and ?",from,to) end - credits = credits.group("sales.sale_id") + credits = credits.group("sale_payments.sale_payment_id, sales_sale_payments.sale_id") end def self.get_void_sale(shift,from,to) @@ -1480,329 +1481,96 @@ end end def self.employee_sales(today,current_user,from,to,from_time,to_time) - #sub query for credit payment - outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END - FROM sale_payments - JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'" - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" - end - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" + shift = if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + ShiftSale.current_open_shift(current_user.id) end - sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) - FROM sale_payments - INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - INNER JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sales.sale_status='completed'" + payments_for_credits = SalePayment.joins(:sale_audit).to_sql - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" - end - else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - #sub query for credit payment - - changed_query = "SELECT SUM(s.amount_changed) - FROM `sales` s - WHERE s.sale_status='completed'" - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" - end - else - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - query = Sale.employee_sale(today,nil,from,to,from_time,to_time) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - changed_query += " AND s.shift_sale_id=sales.shift_sale_id" - query = Sale.employee_sale(today,nil,from,to,from_time,to_time) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - changed_query += " AND s.shift_sale_id=#{shift.id}" - query = Sale.employee_sale(today,shift,from,to,from_time,to_time) - end - end - end - else - if current_user.nil? - query = Sale.employee_sale(today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - changed_query += " AND s.shift_sale_id=sales.shift_sale_id" - query = Sale.employee_sale(today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - changed_query += " AND s.shift_sale_id=#{shift.id}" - query = Sale.employee_sale(today,shift) - end - end - end - end - query = query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - (#{changed_query})) WHEN sp.payment_method='creditnote' THEN (SUM(sp.payment_amount) - (#{sub_query})) ELSE SUM(sp.payment_amount) END) AS payment_amount, (CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END) AS payment_method, e.name AS e_name") + query = employee_sale(today, shift, from, to, from_time, to_time) + .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id") + .select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount, + CASE WHEN sale_payments.payment_method IN ('mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher') THEN 'card' + ELSE sale_payments.payment_method END AS payment_method, employees.name AS e_name") end def self.total_trans(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("SUM(grand_total) as total_sale, COUNT(sales.sale_id) as total_count") .where('sale_status = "completed"') if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - total = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - total = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - total = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',today,today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end + return query end def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") .where('sales.sale_status = "completed" and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method = "alipay" or sp.payment_method = "paymal" or sp.payment_method = "dinga" or sp.payment_method = "JunctionPay")') if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end query = query.sum("sp.payment_amount") end def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END - FROM sale_payments - JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'" + payments_for_credits = SalePayment.joins(:sale_audit).to_sql + + query = SalePayment.credits + .joins(:sale) + .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sale_payments.sale_id") + .where("sale_payments.payment_method= ? AND sales.sale_status = ?", 'creditnote', 'completed') if (!from.nil? && !to.nil?) && (from != "" && to!="") + query = query.merge(Sale.date_between(from, to)) if !from_time.nil? && !to_time.nil? - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" + query = query.merge(Sale.time_between(from_time, to_time)) end else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" + query = query.merge(Sale.date_on(today)) end - - sub_query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) as total_credit_payment") - .joins(" JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id") - .joins(" JOIN sales ON sale_payments.sale_id = sales.sale_id") - .where("sales.sale_status='completed'") - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") - else - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'") - end - else - sub_query = sub_query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'") - end - - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote"') - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',from,to,shift.id) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - end - end - end - end - else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',today,today) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and s.shift_sale_id=?',today,today,shift.id) - .sum("payment_amount") - if !sub_query.nil? - query = query.to_f - (sub_query[0].total_credit_payment.to_f > 0 ? sub_query[0].total_credit_payment.to_f : 0) - end - end - end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end - return query + + return query.sum("sale_payments.payment_amount - IFNULL(payments_for_credits.payment_amount, 0)") end def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') .where('sale_status = "completed"') if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.joins("sales.shift_sale_id = ?", shift.id) end end query = query.first() @@ -1813,147 +1581,50 @@ end .where('sales.sale_status = "completed"') .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.joins("sales.shift_sale_id = ?", shift.id) end end + return query end def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - time_query = '' - if !from_time.nil? && !to_time.nil? - time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - end + payments_for_credits = SalePayment.joins(:sale_audit).to_sql - outstanding_query = "SELECT CASE WHEN SUM(sale_payments.outstanding_amount) < 0 THEN SUM(sale_payments.outstanding_amount) ELSE 0 END - FROM sale_payments - JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sale_payments.outstanding_amount LIKE '%-%' AND sales.sale_status='completed'" + query = Sale.select("SUM(sale_payments.payment_amount) - CASE WHEN sale_payments.payment_method = 'creditnote' THEN IFNULL(SUM(payments_for_credits.payment_amount), 0) ELSE ABS(SUM(CASE WHEN sale_payments.outstanding_amount < 0 THEN sale_payments.outstanding_amount ELSE 0 END)) END AS payment_amount") + .joins(:sale_payments) + .joins("LEFT JOIN (#{payments_for_credits}) payments_for_credits ON payments_for_credits.sale_id = sales.sale_id") + .completed - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'" - end - else - outstanding_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - - sub_query = "SELECT (CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) + (#{outstanding_query}) ELSE 0 END) - FROM sale_payments - INNER JOIN sale_audits ON SUBSTRING_INDEX(sale_audits.remark,'||',1)=sale_payments.sale_payment_id - INNER JOIN sales ON sale_payments.sale_id = sales.sale_id - WHERE sales.sale_status='completed'" - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" - end - else - sub_query += " AND DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - - changed_query = "SELECT SUM(s.amount_changed) - FROM `sales` s - WHERE s.sale_status='completed'" - - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if !from_time.nil? && !to_time.nil? - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}' AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'" - else - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' AND '#{to}'" - end - else - changed_query += " AND DATE_FORMAT(CONVERT_TZ(s.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') = '#{today}'" - end - - query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") - where('sales.sale_status = "completed"') if payment_method == 'card' - query = query.where('(sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay" or sp.payment_method="alipay" or sp.payment_method="paymal" or sp.payment_method="dinga" or sp.payment_method="JunctionPay" or sp.payment_method = "giftvoucher")') + query = query.merge(SalePayment.cards) else - query = query.where("sp.payment_method = '#{payment_method}'") + query = query.where("sale_payments.payment_method = ?", payment_method) end + if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - changed_query += " AND s.shift_sale_id = #{shift.id}" - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time,to_time) end else - if current_user.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - changed_query += " AND s.shift_sale_id = #{shift.id}" - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) - end - end - end + query = query.date_on(today) end - query = query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - (#{changed_query})) WHEN sp.payment_method='creditnote' THEN SUM(sp.payment_amount) - (#{sub_query}) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) + end + end + query.first end def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) @@ -1984,45 +1655,18 @@ end .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('sales.sale_status = "completed" and c.membership_id is null') if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.joins("sales.shift_sale_id = ?", shift.id) end end - query = query.first() end @@ -2031,42 +1675,16 @@ end .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('sales.sale_status = "completed" and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))') if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?)',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id).first() - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id).first() - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.joins("sales.shift_sale_id = ?", shift.id) end end query = query.first() @@ -2119,50 +1737,25 @@ end # end def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.select("count(distinct a.order_id) as total_order") - .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") - .joins("JOIN orders as b ON b.order_id = a.order_id") - .where('b.status = "billed"') + query = Sale.select("count(distinct sale_orders.order_id) as total_order") + .joins(:sale_orders) + .completed if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end + query = query.date_on(today) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end - query = query.first() + + query = query.first end def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) @@ -2171,44 +1764,19 @@ end .joins("JOIN accounts as b ON b.id = a.account_id") .where('sales.sale_status = "completed"') if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ?',from,to,from_time,to_time) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%i") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) - else - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ?',today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where('DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.joins("sales.shift_sale_id = ?", shift.id) end end + return query end def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) @@ -2216,45 +1784,19 @@ end .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}'") if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.joins("sales.shift_sale_id = ?", shift.id) end end - query = query.first() + query = query.first end def self.top_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) @@ -2262,42 +1804,16 @@ end .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed'") if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.joins("sales.shift_sale_id = ?", shift.id) end end query = query.group("a.product_code") @@ -2309,42 +1825,16 @@ end query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") .where("sales.sale_status = 'completed' and a.status='foc' and a.product_name like '%FOC%'") if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ?",from,to,from_time,to_time) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) - end - end - end + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = query.where("DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.joins("sales.shift_sale_id = ?", shift.id) end end query = query.count() @@ -2540,27 +2030,24 @@ def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time= end def self.employee_sale(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") - .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") - .where("sales.payment_status='paid' and sales.sale_status = 'completed' ") + query = Sale.joins(:cashier) + .joins(:sale_payments) + .paid.completed if !from.nil? && !to.nil? + query = query.date_between(from, to) if !from_time.nil? && !to_time.nil? - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}'") - else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") + query = query.time_between(from_time, to_time) end else - query = query.where("DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') = '#{today}'") + query = query.date_on(today) end if !shift.nil? - query = query.where("sales.shift_sale_id ='#{shift.id}'") + query = query.where("sales.shift_sale_id = ?", shift.id) end - query = query.group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay' or sp.payment_method='alipay' or sp.payment_method='paymal' or sp.payment_method='dinga' or sp.payment_method='JunctionPay' or sp.payment_method='giftvoucher') THEN 'card' ELSE sp.payment_method END)","e.name") - .order("e.name") - - return query + query = query.group("payment_method","employees.name") + .order("employees.name") end # Start hourly sale item report diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index d96034ad..1488cad1 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -6,6 +6,8 @@ class SaleAudit < ApplicationRecord belongs_to :sale + belongs_to :credit_payment, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment" + def self.sync_sale_audit_records(sale_audits) if !sale_audits.nil? sale_audits.each do |sa| @@ -163,7 +165,7 @@ class SaleAudit < ApplicationRecord end end end - + return card_balance_amount end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 5a1fdb72..e0ad2383 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -6,8 +6,13 @@ class SalePayment < ApplicationRecord belongs_to :sale + has_one :sale_audit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id" + attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status,:action_by + scope :credits, -> { where(payment_method: 'creditnote') } + scope :cards, -> { where(payment_method: ['mpu', 'visa', 'master', 'jcb', 'unionpay', 'alipay', 'paymal', 'dinga', 'JunctionPay', 'giftvoucher']) } + def self.sync_sale_payment_records(sale_payments) if !sale_payments.nil? sale_payments.each do |sp| diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 2d263c21..07217103 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -15,6 +15,7 @@ class ShiftSale < ApplicationRecord belongs_to :cashier_terminal belongs_to :employee, :foreign_key => 'employee_id' + has_many :sales def self.current_shift # today_date = DateTime.now.strftime("%Y-%m-%d") @@ -25,7 +26,7 @@ class ShiftSale < ApplicationRecord def self.current_open_shift(current_user) #if current_user #find open shift where is open today and is not closed and login by current cashier - #DATE(shift_started_at)=? and + #DATE(shift_started_at)=? and today_date = DateTime.now.strftime("%Y-%m-%d") shift = ShiftSale.where("shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take return shift @@ -43,7 +44,7 @@ class ShiftSale < ApplicationRecord # status = 'updated' if shift_sale.nil? shift_sale = ShiftSale.new - # status = 'created' + # status = 'created' end shift_sale.id = ss['id'] @@ -118,7 +119,7 @@ class ShiftSale < ApplicationRecord credit = saleobj.get_credit_amount other_sales = saleobj.get_other_amount tax = saleobj.get_commerical_tax - + if type == "void" self.total_revenue = self.total_revenue.to_f - saleobj.total_amount.to_f self.total_discounts = self.total_discounts - saleobj.total_discount @@ -137,7 +138,7 @@ class ShiftSale < ApplicationRecord self.takeaway_count = self.takeaway_count - 1 end - + self.save end end @@ -149,11 +150,11 @@ class ShiftSale < ApplicationRecord end def self.get_by_shift_other_payment(shift) - + other_payment = Sale.select("sale_payments.payment_method as name, - SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount, - SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount, - SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount, + SUM(case when (sale_payments.payment_method='mpu') then (sale_payments.payment_amount) else 0 end) as mpu_amount, + SUM(case when (sale_payments.payment_method='visa') then (sale_payments.payment_amount) else 0 end) as visa_amount, + SUM(case when (sale_payments.payment_method='master') then (sale_payments.payment_amount) else 0 end) as master_amount, SUM(case when (sale_payments.payment_method='jcb') then (sale_payments.payment_amount) else 0 end) as jcb_amount, SUM(case when (sale_payments.payment_method='unionpay') then (sale_payments.payment_amount) else 0 end) as unionpay_amount, SUM(case when (sale_payments.payment_method='alipay') then (sale_payments.payment_amount) else 0 end) as alipay_amount, @@ -161,19 +162,19 @@ class ShiftSale < ApplicationRecord SUM(case when (sale_payments.payment_method='dinga') then (sale_payments.payment_amount) else 0 end) as dinga_amount, SUM(case when (sale_payments.payment_method='giftvoucher') then (sale_payments.payment_amount) else 0 end) as giftvoucher_amount, SUM(case when (sale_payments.payment_method='JunctionPay') then (sale_payments.payment_amount) else 0 end) as junctionpay_amount, - SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount, - SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount, + SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount, + SUM(case when (sale_payments.payment_method='paymal') then (sale_payments.payment_amount) else 0 end) as paymal_amount, SUM(case when (sale_payments.payment_method='paypar') then (sale_payments.payment_amount) else 0 end) as paypar_amount") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .where("sales.shift_sale_id =? and sale_status = 'completed' and sale_payments.payment_amount != 0 ", shift.id) end def self.calculate_total_price_by_accounts(shift,type) - query = Sale.select("acc.title as account_name," + + query = Sale.select("acc.title as account_name," + "SUM(case when (acc.id=i.account_id) then (i.price) else 0 end) as total_price") - + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id "+ - "JOIN accounts acc ON acc.id = i.account_id" + + "JOIN accounts acc ON acc.id = i.account_id" + " JOIN shift_sales sh ON sh.`id` = sales.shift_sale_id") if type == 'discount' query = query.where("sales.shift_sale_id =? and sale_status = 'completed' and i.remark = 'Discount'", shift.id) @@ -187,17 +188,17 @@ class ShiftSale < ApplicationRecord def self.get_total_member_discount(shift) query = Sale.select("SUM(sales.total_discount) as member_discount") .where("shift_sale_id =? and sale_status = 'completed' and discount_type = 'member_discount'", shift.id) - - end - def self.get_total_dinein(shift) + end + + def self.get_total_dinein(shift) query = Sale.select("sum(sales.grand_total) as total_dinein_amount") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Dinein" and c.membership_id is null',shift.id) .first() - end + end - def self.get_total_takeway(shift) + def self.get_total_takeway(shift) query = Sale.select("sum(sales.grand_total) as total_takeway_amount") .joins("JOIN customers as c ON c.customer_id = sales.customer_id") .where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Takeaway" and c.membership_id is null',shift.id) @@ -211,12 +212,12 @@ class ShiftSale < ApplicationRecord # .where('s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null and s.receipt_date between ? and ?',from, to) # end - def self.get_total_other_charges(shift) + def self.get_total_other_charges(shift) query = SaleItem.select("sum(sale_items.qty * sale_items.unit_price) as total_other_charges_amount") .joins("JOIN sales as s ON s.sale_id = sale_items.sale_id") .where('shift_sale_id =? and s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null',shift.id) .first() - end + end def self.search(filter,from,to) if filter.blank? diff --git a/app/views/origami/addorders/_menu_item.json.jbuilder b/app/views/origami/addorders/_menu_item.json.jbuilder index a18645c8..2768fa9c 100755 --- a/app/views/origami/addorders/_menu_item.json.jbuilder +++ b/app/views/origami/addorders/_menu_item.json.jbuilder @@ -1,53 +1,20 @@ # Format for attributes json attr_format = [] -# Format for attributes json -if item.item_attributes.count > 0 - item.item_attributes.each do|attr_id| - menu_attr = MenuItemAttribute.find(attr_id) - if attr_format.count == 0 - attr_format.push({ type: menu_attr.attribute_type, values: [menu_attr.name] }) - next - end - - attr_format.each do |af| - if menu_attr.attribute_type.in? attr_format.map {|k| k[:type]} - if menu_attr.attribute_type == af[:type] - af[:values].push(menu_attr.name) - end - else - new_attr = {type: menu_attr.attribute_type, values: [ menu_attr.name ] } - attr_format.push(new_attr) - break - end - end - end +# Format for attributes json +if item.item_attributes.count > 0 + item_attributes = MenuItemAttribute.where(id: item.item_attributes) + attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} } end # Format for option json opt_format = [] -# Format for attributes json -if item.item_options.count > 0 - item.item_options.each do|opt| - menu_opt = MenuItemOption.find(opt) - if opt_format.count == 0 - opt_format.push({ type: menu_opt.option_type, values: [menu_opt.name] }) - next - end - - opt_format.each do |of| - if menu_opt.option_type.in? opt_format.map {|k| k[:type]} - if menu_opt.option_type == of[:type] - of[:values].push(menu_opt.name) - end - else - new_opt = {type: menu_opt.option_type, values: [ menu_opt.name ] } - opt_format.push(new_opt) - break - end - end - end +# Format for attributes json +if item.item_options.count > 0 + item_options = MenuItemOption.where(id: item.item_options) + opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} } end + #Menu Item Information json.id item.id json.code item.item_code @@ -63,8 +30,8 @@ json.is_available item.is_available json.is_sub_item item.is_sub_item json.unit item.unit -# Item Sets of Menu Item -json.item_sets item.item_sets do |its| +# Item Sets of Menu Item +json.item_sets item.item_sets.includes(:menu_item_instances) do |its| json.id its.id json.name its.name json.alt_name its.alt_name @@ -73,7 +40,7 @@ json.item_sets item.item_sets do |its| json.instances its.menu_item_instances do |i| json.id i.id end -end +end json.attributes attr_format json.options opt_format @@ -92,22 +59,17 @@ json.options opt_format json.instances item.menu_item_instances do |is| if is.is_available # Convert id to name for attributes - instance_attr = [] - is.item_attributes.each do |ia| - mItemAttr = MenuItemAttribute.find(ia).name - instance_attr.push(mItemAttr) - end - - json.id is.id - json.code is.item_instance_code - json.name is.item_instance_name - json.price is.price - json.is_available is.is_available - json.is_default is.is_default - json.is_on_promotion is.is_on_promotion - json.promotion_price is.promotion_price - json.values instance_attr - # json.item_sets is.item_sets + instance_attr = MenuItemAttribute.where(id: item.item_attributes).pluck(:name) + + json.id is.id + json.code is.item_instance_code + json.name is.item_instance_name + json.price is.price + json.is_available is.is_available + json.is_default is.is_default + json.is_on_promotion is.is_on_promotion + json.promotion_price is.promotion_price + json.values instance_attr end end @@ -116,4 +78,4 @@ end # json.set_items item.children.each do |item| # json.partial! 'api/restaurant/menu/menu_item', item: item # end -# end \ No newline at end of file +# end diff --git a/app/views/origami/dashboard/_menu.json.jbuilder b/app/views/origami/dashboard/_menu.json.jbuilder index d558c4ea..9c9f1963 100644 --- a/app/views/origami/dashboard/_menu.json.jbuilder +++ b/app/views/origami/dashboard/_menu.json.jbuilder @@ -12,11 +12,11 @@ if (menu.menu_categories) # else # categories = menu.menu_categories # end - categories = menu.menu_categories + categories = menu.menu_categories json.categories categories do |category| if category.is_available - menu_category = MenuCategory.find_by_menu_category_id(category.id) - if !menu_category.nil? + parent_category = category.parent + if !parent_category.nil? json.sub_category "true" else json.sub_category "false" @@ -34,7 +34,7 @@ if (menu.menu_categories) json.is_available category.is_available if !order_by.nil? && order_by.value == "name" - menu_items = MenuItem.unscoped.where("menu_category_id = ?",category.id).order("name asc") + menu_items = category.menu_items.sort_by(&:name) else menu_items = category.menu_items end @@ -42,7 +42,68 @@ if (menu.menu_categories) if category.menu_items json.items menu_items do |item| if item.is_available - json.partial! 'origami/addorders/menu_item', item: item + # Format for attributes json + attr_format = [] + # Format for attributes json + if item.item_attributes.count > 0 + item_attributes = @item_attributes.select{ |x| item.item_attributes.include?(x.id.to_s) } + attr_format = item_attributes.group_by {|att| att.attribute_type }.map { |type, values| {type: type, values: values.map(&:name)} } + end + + # Format for option json + opt_format = [] + # Format for attributes json + if item.item_options.count > 0 + item_options = @item_options.select{ |x| item.item_options.include?(x.id.to_s) } + opt_format = item_options.group_by {|opt| opt.option_type }.map { |type, values| {type: type, values: values.map(&:name)} } + end + + #Menu Item Information + json.id item.id + json.code item.item_code + json.name item.name + json.alt_name item.alt_name + json.image item.image_path.url + json.description item.description + json.information item.information + json.type item.type + json.account_id item.account_id + json.min_qty item.min_qty + json.is_available item.is_available + json.is_sub_item item.is_sub_item + json.unit item.unit + + # Item Sets of Menu Item + json.item_sets item.item_sets.map { |its| + { id: its.id, + name: its.name, + alt_name: its.alt_name, + min_selectable_qty: its.min_selectable_qty, + max_selectable_qty: its.max_selectable_qty, + instances: its.menu_item_instances.pluck(:id).map { |id| {id: id}} + } + } + + json.attributes attr_format + json.options opt_format + + json.instances item.menu_item_instances do |is| + if is.is_available + # Convert id to name for attributes + instance_attr = @item_attributes.select{ |x| item.item_attributes.include?(x.id) }.pluck(:name) + + json.id is.id + json.code is.item_instance_code + json.name is.item_instance_name + json.price is.price + json.is_available is.is_available + json.is_default is.is_default + json.is_on_promotion is.is_on_promotion + json.promotion_price is.promotion_price + json.values instance_attr + end + end + end end end From 77d0e0a56c7f238fd16927959e12cf12ca54a52e Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Mon, 18 Nov 2019 10:22:54 +0630 Subject: [PATCH 25/49] add readme --- Gemfile | 2 +- README.md | 3 +++ app/models/inventory_definition.rb | 24 ++++++++++++------------ 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Gemfile b/Gemfile index ba95e3c9..c8139eb7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,5 +1,5 @@ source 'https://rubygems.org' -ruby '2.6.3' +ruby '2.4.1' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") "https://github.com/#{repo_name}.git" diff --git a/README.md b/README.md index 4d81b144..77a25926 100755 --- a/README.md +++ b/README.md @@ -299,6 +299,9 @@ settings/lookups => {type:display_type, name: Display Type, value: 2} For show total before tax in receipt bill settings/lookups => {type:show_total_before_tax, name:Show Total Before Tax, value: {0 or 1}} +For Using Staff Meal +settings/lookups => { type:customer_type, name: Staff, value:Staff } + * ToDo list 1. Migration diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index dd2f3c3c..f2ed207d 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -24,18 +24,18 @@ class InventoryDefinition < ApplicationRecord end def self.find_product_in_inventory(item,instance_code) - unless instance_code.empty? - instance_code = instance_code.to_s - instance_code[0] = "" - instance_code = instance_code.chomp("]") - else - instance_code = '"0"' - end - - if prod = InventoryDefinition.where("item_code IN(#{instance_code})") - puts "found prodcut+++++++++++++++++++++++++++++++++++===" - puts prod.to_json - end + # unless instance_code.empty? + # instance_code = instance_code.to_s + # instance_code[0] = "" + # instance_code = instance_code.chomp("]") + # else + # instance_code = '"0"' + # end + # + # if prod = InventoryDefinition.where("item_code IN(#{instance_code})") + # puts "found prodcut+++++++++++++++++++++++++++++++++++===" + # puts prod.to_json + # end if product = InventoryDefinition.find_by_item_code(item.item_instance_code) if stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code) From 5702819b8b5591435e23b13b3e0500364fd647ec Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 18 Nov 2019 11:16:14 +0630 Subject: [PATCH 26/49] fix dashboard error for cashier --- app/models/sale.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 8e7f0b92..fe43ea69 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1690,7 +1690,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user.id) - query = query.joins("sales.shift_sale_id = ?", shift.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end query = query.first() @@ -1710,7 +1710,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user.id) - query = query.joins("sales.shift_sale_id = ?", shift.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end return query @@ -1784,7 +1784,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user.id) - query = query.joins("sales.shift_sale_id = ?", shift.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end query = query.first() @@ -1804,7 +1804,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user.id) - query = query.joins("sales.shift_sale_id = ?", shift.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end query = query.first() @@ -1893,7 +1893,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user.id) - query = query.joins("sales.shift_sale_id = ?", shift.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end return query @@ -1913,7 +1913,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user.id) - query = query.joins("sales.shift_sale_id = ?", shift.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end query = query.first @@ -1933,7 +1933,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user.id) - query = query.joins("sales.shift_sale_id = ?", shift.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end query = query.group("a.product_code") @@ -1954,7 +1954,7 @@ end end if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') if shift = ShiftSale.current_open_shift(current_user.id) - query = query.joins("sales.shift_sale_id = ?", shift.id) + query = query.where("sales.shift_sale_id = ?", shift.id) end end query = query.count() From 55f489cabbce9b8deeabde21771b16e611adfaa0 Mon Sep 17 00:00:00 2001 From: Nweni Date: Mon, 18 Nov 2019 13:10:32 +0630 Subject: [PATCH 27/49] gem --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index cc6611ed..cb20745e 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' -#ruby '2.4.1' -ruby '2.5.7' +ruby '2.4.1' +# ruby '2.5.7' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") From 74e29f7c3959aa667d114ba35f30a0bf15514378 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 18 Nov 2019 14:00:52 +0630 Subject: [PATCH 28/49] remove def total_account from sale --- Gemfile.lock | 4 ++-- app/controllers/home_controller.rb | 7 ++++--- .../origami/dashboard_controller.rb | 3 ++- app/models/sale.rb | 21 ------------------- 4 files changed, 8 insertions(+), 27 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 49926b1c..a1fd1f6d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -375,8 +375,8 @@ DEPENDENCIES web-console (>= 3.3.0) whenever - RUBY VERSION - ruby 2.6.3p62 + ruby 2.4.1p111 + BUNDLED WITH 2.0.2 diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index d9c67962..4d8c715a 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -134,7 +134,7 @@ class HomeController < ApplicationController end @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance) - @total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time) + @total_trans = Sale.total_trans(today,current_user,@from,@to,@from_time,@to_time) @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time) @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time) @@ -157,15 +157,16 @@ class HomeController < ApplicationController # @total_other_customer = Sale.total_other_customer(today,current_user) @total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time) - @total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time) + @total_accounts = Account.select("accounts.id as account_id, accounts.title as title") @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| acc = Sale.account_data(account.account_id, today,current_user,@from,@to,@from_time,@to_time) - if !acc.nil? + if !acc.nil? && acc.cnt_acc > 0 @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end + @total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } end @top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time) diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index 1daa652b..a1aa2064 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -27,7 +27,7 @@ class Origami::DashboardController < BaseOrigamiController # @total_other_customer = Sale.total_other_customer(today,current_user) @total_order = Sale.total_order(today,current_user) - @total_accounts = Sale.total_account(today,current_user) + @total_accounts = Account.select("accounts.id as account_id, accounts.title as title") @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| @@ -36,6 +36,7 @@ class Origami::DashboardController < BaseOrigamiController @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end + @total_accounts = @total_accounts.reject.with_index { |x, i| @account_data[i].nil? } else @account_data = nil end diff --git a/app/models/sale.rb b/app/models/sale.rb index fe43ea69..999a18fd 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1878,27 +1878,6 @@ end query = query.first end - def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) - query = Sale.select("distinct b.id as account_id, b.title as title") - .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed"') - if (!from.nil? && !to.nil?) && (from != "" && to!="") - query = query.date_between(from, to) - if !from_time.nil? && !to_time.nil? - query = query.time_between(from_time, to_time) - end - else - query = query.date_on(today) - end - if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') - if shift = ShiftSale.current_open_shift(current_user.id) - query = query.where("sales.shift_sale_id = ?", shift.id) - end - end - return query - end - def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") From 8638a53f12e8a1376b84d6d52dc0518c07db4287 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Mon, 18 Nov 2019 15:48:35 +0630 Subject: [PATCH 29/49] fixed foc --- app/models/inventory_definition.rb | 9 +++++---- app/models/order_item.rb | 21 ++++++++++----------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index f2ed207d..82545456 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -23,8 +23,8 @@ class InventoryDefinition < ApplicationRecord end end - def self.find_product_in_inventory(item,instance_code) - # unless instance_code.empty? + def self.find_product_in_inventory(item) + # unless instance_code.nil? # instance_code = instance_code.to_s # instance_code[0] = "" # instance_code = instance_code.chomp("]") @@ -33,8 +33,9 @@ class InventoryDefinition < ApplicationRecord # end # # if prod = InventoryDefinition.where("item_code IN(#{instance_code})") - # puts "found prodcut+++++++++++++++++++++++++++++++++++===" - # puts prod.to_json + # if stock_check_item = StockCheckItem.where("item_code IN(#{instance_code})") + # return true, prod + # end # end if product = InventoryDefinition.find_by_item_code(item.item_instance_code) diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 005bfe67..0b1c77d2 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -125,18 +125,17 @@ class OrderItem < ApplicationRecord end def update_stock_journal - if self.set_menu_items.present? - puts "set menu itemsssssssss???????????????????????????????" - puts items = JSON.parse(self.set_menu_items) - instance_code = Array.new - count = 0 - items.each { |i| - instance_code.push(i["item_instance_code"]) - } - print instance_code - end + # if self.set_menu_items.present? + # items = JSON.parse(self.set_menu_items) + # instance_code = Array.new + # count = 0 + # items.each { |i| + # instance_code.push(i["item_instance_code"]) + # } + # end + if self.qty != self.qty_before_last_save - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self,instance_code) + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) if found InventoryDefinition.check_balance(self, inventory_definition) end From f2b4114ad5bfce9cd25e569188b9576d83ac5d25 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 19 Nov 2019 00:08:56 +0630 Subject: [PATCH 30/49] change config for local server --- .code2lab.env | 1 - .../origami/dashboard_controller.rb | 15 +- app/models/license.rb | 189 +++++++++--------- app/models/printer/printer_worker.rb | 4 +- config/cable.yml | 2 +- config/initializers/license.rb | 2 - config/redis.yml | 4 +- config/secrets.yml | 10 +- 8 files changed, 111 insertions(+), 116 deletions(-) diff --git a/.code2lab.env b/.code2lab.env index 3a697ccd..0a6c7f0b 100644 --- a/.code2lab.env +++ b/.code2lab.env @@ -1,2 +1 @@ RAILS_ENV=production -SERVER_MODE=cloud diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index 22aef2e1..7ccac407 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -2,10 +2,9 @@ class Origami::DashboardController < BaseOrigamiController def index @shop = Shop.first - Rails.logger.info ENV["SERVER_MODE"] - Rails.logger.info "<><><><><><><><>>" - today = DateTime.now.strftime('%Y-%m-%d') + today = DateTime.now.strftime('%Y-%m-%d') + @display_type = Lookup.find_by_lookup_type("display_type") @sale_data = Array.new @@ -15,7 +14,7 @@ class Origami::DashboardController < BaseOrigamiController if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" || payment.payment_method == "alipay" pay = Sale.payment_sale('card', today, current_user) @sale_data.push({'card' => pay.payment_amount}) - else + else pay = Sale.payment_sale(payment.payment_method, today, current_user) @sale_data.push({payment.payment_method => pay.payment_amount}) end @@ -39,10 +38,10 @@ class Origami::DashboardController < BaseOrigamiController end else @account_data = nil - end + end @top_items = Sale.top_items(today,current_user) - @total_foc_items = Sale.total_foc_items(today,current_user) + @total_foc_items = Sale.total_foc_items(today,current_user) # get printer info @print_settings = PrintSetting.get_precision_delimiter() @@ -105,12 +104,12 @@ class Origami::DashboardController < BaseOrigamiController end def get_all_menu - @menus = Menu.active.all + @menus = Menu.active.all end def get_credit_sales credit_sales = SalePayment.get_credit_sales(params) - if !credit_sales.nil? + if !credit_sales.nil? result = {:status=> true, :data=> credit_sales } else result = {:status=> false, :message=>"There is no record." } diff --git a/app/models/license.rb b/app/models/license.rb index befb4b36..2c550a1e 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -13,28 +13,27 @@ class License def initialize(server = "", lookup = "") #this code is hard-code to reflect server mode - Very important. - # self.server_mode = ENV["SERVER_MODE"] - self.server_mode = "cloud" + self.server_mode = ENV["SERVER_MODE"] if (server != "") self.class.base_uri server end - end + end # For Cloud - def detail_with_local_cache(lookup) + def detail_with_local_cache(lookup) aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_to_file(lookup) - + aes_key, aes_iv = aes.export_to_file(lookup) + ##Check from local redis - if available load local otherwise get from remote - cache_key = "#{lookup}:license:#{aes_key}:hostname" + cache_key = "#{lookup}:license:#{aes_key}:hostname" cache_license = nil ##Get redis connection from connection pool redis = Redis.new - cache_license = redis.get(cache_key) - + cache_license = redis.get(cache_key) + Rails.logger.info "Cache key - " + cache_key.to_s if cache_license.nil? ##change the d/e key @@ -48,7 +47,7 @@ class License assign(aes_key, aes_iv) #Rails.logger.info "License - " + response.parsed_response.to_s - + redis = Redis.new redis.set(cache_key, Marshal.dump(@license)) # redis.sadd("License:cache:keys", cache_key) @@ -61,36 +60,36 @@ class License return true end - else + else @license = Marshal.load(cache_license) assign(aes_key, aes_iv) - # Rails.logger.info 'API License' + # Rails.logger.info 'API License' return true end end # For Local System - def detail_with_local_file() + def detail_with_local_file() renewal_date_str = read_license("renewable_date") - if check_expiring(renewal_date_str) - # return for all ok + if check_expiring(renewal_date_str) + # return for all ok return 1 else has_license = verify_license() if has_license - # return for expiring + # return for expiring return 2 else return 0 end end - # end - end + # end + end # License Activation def license_activate (shop, license_key, db_host, db_schema, db_user, db_password) - aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_key(license_key) + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(license_key) @params = { query: { lookup_type: self.server_mode, iv_key: aes_iv, license_key: license_key } } response = self.class.get("/activate", @params) @@ -98,21 +97,21 @@ class License if (@activate["status"]) ##Check from local redis - if available load local otherwise get from remote - cache_key = "shop:#{@activate["shop_name"]}" + cache_key = "shop:#{@activate["shop_name"]}" - cache_license = nil + cache_license = nil ##Get redis connection from connection pool redis = Redis.new - cache_license = redis.get(cache_key) + cache_license = redis.get(cache_key) Rails.logger.info "Cache key - " + cache_key.to_s - if cache_license.nil? - cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } + if cache_license.nil? + cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] } redis = Redis.new redis.set(cache_key, Marshal.dump(cache)) - end + end Rails.logger.info "License - " + response.parsed_response.to_s @@ -122,21 +121,21 @@ class License sym_path = File.expand_path("~/symmetric/") response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password) - + if(response[:status]) response = run_symmetric(sym_path) end end else response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"} - end + end return response end - def verify_license - api_token = read_license_no_decrypt("api_token") + def verify_license + api_token = read_license_no_decrypt("api_token") @params = { query: {lookup_type: "application", api_token: api_token} } - + begin response = self.class.get("/verify", @params) @varified = response.parsed_response @@ -147,7 +146,7 @@ class License end else delete_license_file - end + end rescue SocketError => e Rails.logger.debug "In SocketError No Internet connection ! " @@ -161,21 +160,21 @@ class License rescue OpenURI::HTTPError Rails.logger.debug "Can't connect server" return true - end - return false + end + return false end # Check Expired before 30 days - def check_expiring(renewal_date_str) + def check_expiring(renewal_date_str) if !renewal_date_str.empty? - renewal_date = DateTime.parse(renewal_date_str) + renewal_date = DateTime.parse(renewal_date_str) renewal_date > Date.today.advance(:days => 30) end end # Check License expired date from PROVISION SERVER - def check_expired(renewal_date_str) + def check_expired(renewal_date_str) expired_date_str = read_license("renewable_date") renewal_date = DateTime.parse(renewal_date_str) if(renewal_date_str != expired_date_str) @@ -188,32 +187,32 @@ class License return false end end - + # Check License File exists def self.check_license_file - return File.exist?("config/license.yml") + return File.exist?("config/license.yml") end # read line by key for license file - def read_license(key_name) - decrypted_line = "" + def read_license(key_name) + decrypted_line = "" key, iv = get_redis_key() - if File.exist?("config/license.yml") + if File.exist?("config/license.yml") File.open("config/license.yml").each do |line| - if line.include? (key_name) - decrypted_line_array = line.split(": ") + if line.include? (key_name) + decrypted_line_array = line.split(": ") decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) end end - end + end return decrypted_line end # read line by key for license file without decrypt def read_license_no_decrypt(key) decrypted_line = "" - if File.exist?("config/license.yml") + if File.exist?("config/license.yml") File.open("config/license.yml").each do |line| if line.include? (key) decrypted_line_array = line.split(": ") @@ -228,18 +227,18 @@ class License def update_license(content, new_content) key, iv = get_redis_key() - if !new_content.include? "==" + if !new_content.include? "==" crypted_str = AESCrypt.encrypt_data(new_content, decode_str(key), decode_str(iv), ENV['CIPHER_TYPE']) end - + content_str = read_license_no_decrypt(content) - if File.exist?("config/license.yml") + if File.exist?("config/license.yml") file_str = File.read("config/license.yml") new_file_str = file_str.gsub(content_str, encode_str(crypted_str)) # To write changes to the file, use: File.open("config/license.yml", "w") {|file| file.puts new_file_str } - + # File.open("config/license.yml").each do |line| # new_file_str = line.gsub(content, crypted_str) # f.put @@ -249,33 +248,33 @@ class License # Re-get keys def get_key - api_token = read_license_no_decrypt("api_token") - shop_name = read_license_no_decrypt("shop_name") + api_token = read_license_no_decrypt("api_token") + shop_name = read_license_no_decrypt("shop_name") @params = { query: {lookup_type: "application", api_token: api_token } } response = self.class.get("/get_key", @params) @data = response.parsed_response - + if (@data["status"]) ##Check from local redis - if available load local otherwise get from remote - cache_key = "shop:#{shop_name.chomp}" + cache_key = "shop:#{shop_name.chomp}" - cache_license = nil + cache_license = nil ##Get redis connection from connection pool redis = Redis.new - cache_license = redis.get(cache_key) + cache_license = redis.get(cache_key) Rails.logger.info "Cache key - " + cache_key.to_s - if cache_license.nil? - cache = {"shop" => shop_name, "key" => @data["secret_key"], "iv" => @data["iv_key"], "renewable_date" => @data["renewable_date"] } + if cache_license.nil? + cache = {"shop" => shop_name, "key" => @data["secret_key"], "iv" => @data["iv_key"], "renewable_date" => @data["renewable_date"] } redis = Redis.new redis.set(cache_key, Marshal.dump(cache)) - end + end return true - end + end return false - end + end private def get_redis_key @@ -283,18 +282,18 @@ class License key = "" shop = read_license_no_decrypt("shop_name") ##Check from local redis - if available load local otherwise get from remote - cache_key = "shop:#{shop.chomp}" + cache_key = "shop:#{shop.chomp}" - cache_shop = nil + cache_shop = nil ##Get redis connection from connection pool redis = Redis.new - cache_shop = redis.get(cache_key) + cache_shop = redis.get(cache_key) - if !cache_shop.nil? - @shop = Marshal.load(cache_shop) - key = @shop["key"] - iv = @shop["iv"] + if !cache_shop.nil? + @shop = Marshal.load(cache_shop) + key = @shop["key"] + iv = @shop["iv"] end return key, iv end @@ -309,13 +308,13 @@ class License # License File Creation def create_license_file(response_data) - if File.exist?("config/license.yml") + if File.exist?("config/license.yml") delete_license_file end begin # Licese File Creation - File.open("config/license.yml", "w") do |f| + File.open("config/license.yml", "w") do |f| f.puts("iv_key: #{response_data['iv_key']}") f.puts("shop_name: #{response_data['shop_name']}") f.puts("email: #{response_data['email']}") @@ -327,11 +326,11 @@ class License f.puts("dbusername: #{response_data['dbusername']}") f.puts("dbpassword: #{response_data['dbpassword']}") f.puts("api_token: #{response_data['api_token']}") - f.puts("app_token: #{response_data['app_token']}") + f.puts("app_token: #{response_data['app_token']}") f.puts("plan_sku: #{response_data['plan_sku']}") f.puts("renewable_date: #{response_data['renewable_date']}") f.puts("plan_name: #{response_data['plan_name']}") - end + end rescue IOError response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} end @@ -354,15 +353,15 @@ class License f.write("group.id=sx\n") f.write("external.id=000\n") f.write("job.purge.period.time.ms=7200000\n") - f.write("job.routing.period.time.ms=5000\n") - f.write("job.push.period.time.ms=10000\n") - f.write("job.pull.period.time.ms=10000\n") - f.write("initial.load.create.first=true\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + f.write("initial.load.create.first=true\n") f.write("initial.load.use.extract.job.enabled=true\n") f.write("rest.api.enable=true\n") - f.close + f.close - # read from license file + # read from license file # shop_name = read_license_no_decrypt("shop_name") shop_name = "cloud" dbhost = read_license("dbhost") @@ -380,12 +379,12 @@ class License f.write("registration.url=http://#{db_host}:31415/sync/sx\n") f.write("group.id=cloud\n") f.write("external.id=001\n") - f.write("job.routing.period.time.ms=5000\n") - f.write("job.push.period.time.ms=10000\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") f.write("job.pull.period.time.ms=10000\n") f.write("rest.api.enable=true\n") - # f.write("initial.load.create.first=true\n") - # f.write("initial.load.use.extract.job.enabled=true\n") + # f.write("initial.load.create.first=true\n") + # f.write("initial.load.use.extract.job.enabled=true\n") f.close rescue IOError response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} @@ -394,12 +393,12 @@ class License end end - # Run Symmetric + # Run Symmetric def run_symmetric(sym_path) # check_sym_proc_str = `#{sym_path + "bin/sym_service status"}` # check_sym_proc_str = check_sym_proc_str.split("\n") # sym_install_status = check_sym_proc_str[0].split(": ") - + check_sym_proc_str = `#{"sudo service SymmetricDS status"}` # Check Sym Installed @@ -414,7 +413,7 @@ class License check_sym_table = system("sudo " + sym_path + "/bin/symadmin --engine sx create-sym-tables") if check_sym_table sym_sql = Rails.root + "db/sym_master.sql" - + if File.exist? (sym_sql) # Import Sym Sql to db and start sym run_sym_sql = system("sudo " + sym_path + "/bin/dbimport --engine sx " + sym_sql.to_s) @@ -429,7 +428,7 @@ class License else response = { "status": false, "message": "Activation is success but Cannot create Sym Tables. \n Please contact code2lab call center!"} end - else + else response = { "status": false, "message": "Activation is success but Symmetric not running. \n Please contact code2lab call center!"} end end @@ -437,7 +436,7 @@ class License # Check Symmetric Running def check_sym_running(status, sym_path) # Run Sym Service - # if status.include? "Server is already running" + # if status.include? "Server is already running" # return true # elsif status.include? "false" # sym_start_str = `#{sym_path + "bin/sym_service start"}` @@ -445,9 +444,9 @@ class License # return true # else # check_sym_running(sym_start_status[0]) - # end + # end # else - # return true + # return true # end if status.include? "Active: active (running)" || "Active: active (exited)" #"Server is already running" @@ -458,15 +457,15 @@ class License # Delete License File def delete_license_file - File.delete("config/license.yml") if File.exist?("config/license.yml") + File.delete("config/license.yml") if File.exist?("config/license.yml") end # Assign db info for Cloud - def assign(aes_key, aes_iv) + def assign(aes_key, aes_iv) key = Base64.decode64(aes_key) iv = Base64.decode64(aes_iv) - - if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] ) + + if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] ) host = Base64.decode64(@license["dbhost"]) dbschema = Base64.decode64(@license["dbschema"]) dbusername = Base64.decode64(@license["dbusername"]) @@ -475,8 +474,8 @@ class License self.dbhost = AESCrypt.decrypt_data(host, key, iv, ENV['CIPHER_TYPE']) self.dbschema = AESCrypt.decrypt_data(dbschema, key, iv, ENV['CIPHER_TYPE']) self.dbusername = AESCrypt.decrypt_data(dbusername, key, iv, ENV['CIPHER_TYPE']) - self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE']) + self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE']) end - + end end diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index 0a580e40..e0d4fc85 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -1,9 +1,9 @@ require 'net/http' -#require 'cups' +require 'cups' class Printer::PrinterWorker attr_accessor :print_settings - + def initialize(print_settings) self.print_settings = print_settings end diff --git a/config/cable.yml b/config/cable.yml index 36f0b961..e740f386 100755 --- a/config/cable.yml +++ b/config/cable.yml @@ -1,6 +1,6 @@ redis: &redis adapter: redis - url: redis://172.17.0.1:6380/1 + url: redis://localhost:6379/1 production: *redis development: *redis diff --git a/config/initializers/license.rb b/config/initializers/license.rb index 31510a0f..7eed14a6 100644 --- a/config/initializers/license.rb +++ b/config/initializers/license.rb @@ -3,6 +3,4 @@ if File.exist?("config/license.yml") config.fetch(Rails.env, {}).each do |key, value| ENV[key.upcase] = value.to_s end -else - ENV["SERVER_MODE"] = "cloud" end diff --git a/config/redis.yml b/config/redis.yml index 493a6027..b8c7b2eb 100644 --- a/config/redis.yml +++ b/config/redis.yml @@ -9,5 +9,5 @@ test: <<: *default production: - db: 0 - url: redis://172.17.0.1:6380 + <<: *default + url: redis://127.0.0.1:6379 diff --git a/config/secrets.yml b/config/secrets.yml index ff014434..069b1403 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -11,8 +11,8 @@ # if you're sharing your code publicly. development: - secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 - sx_provision_url: connect.smartsales.asia/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api + secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 + sx_provision_url: connect.smartsales.asia/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L @@ -23,8 +23,8 @@ test: # Do not keep production secrets in the repository, # instead read values from the environment. production: - secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 - sx_provision_url: 52.221.188.144:9292/api #connect.smartsales.asia/api #192.168.1.147:3002/api - server_mode: cloud + secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 + sx_provision_url: connect.smartsales.asia/api #52.221.188.144:9292/api #192.168.1.147:3002/api + server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L From 2b5105672a661df11f1263171a104770ff657fef Mon Sep 17 00:00:00 2001 From: Nweni Date: Tue, 19 Nov 2019 09:33:54 +0630 Subject: [PATCH 31/49] gem file --- Gemfile | 2 +- Gemfile.lock | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index cb20745e..f07c8f18 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' -ruby '2.4.1' +# ruby '2.4.1' # ruby '2.5.7' git_source(:github) do |repo_name| diff --git a/Gemfile.lock b/Gemfile.lock index 858ce67d..9c92b6e0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -374,9 +374,5 @@ DEPENDENCIES web-console (>= 3.3.0) whenever -RUBY VERSION - - ruby 2.4.1p111 - BUNDLED WITH 2.0.2 From 0ed10a0c6443c76698ee5a6ae434c67245357a34 Mon Sep 17 00:00:00 2001 From: Aung Ye Kyaw Date: Tue, 19 Nov 2019 11:53:02 +0000 Subject: [PATCH 32/49] Update Gemfile for Ruby version 2.4.1 --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index cc6611ed..e0d9e933 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ source 'https://rubygems.org' -#ruby '2.4.1' -ruby '2.5.7' +ruby '2.4.1' +#ruby '2.5.7' git_source(:github) do |repo_name| repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") From 336e32f1a67afe03b0a051e9dc73d2fb64163bf8 Mon Sep 17 00:00:00 2001 From: Nweni Date: Wed, 20 Nov 2019 09:44:49 +0630 Subject: [PATCH 33/49] fixed daliy sales report - payment method error --- app/views/reports/dailysale/index.html.erb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb index 592a8cca..54656079 100755 --- a/app/views/reports/dailysale/index.html.erb +++ b/app/views/reports/dailysale/index.html.erb @@ -26,12 +26,13 @@ <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%> + <% @count = 1 %> <% @payment_methods.each_slice(10) do |slice| %> <% alph = "A" %> - <% @count = 1 %> + <% slice.each do |payment_method| %> <%= alph %> From a36e170d94ec26ab20adb0a095cb0149729a4429 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Wed, 20 Nov 2019 15:14:09 +0630 Subject: [PATCH 34/49] inventory for set items --- .../origami/sale_edit_controller.rb | 4 +- app/models/inventory_definition.rb | 28 +--- app/models/order_item.rb | 40 +---- app/models/sale.rb | 6 +- app/models/sale_item.rb | 143 ++++++++++++++---- 5 files changed, 130 insertions(+), 91 deletions(-) diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 7f456f35..363791a8 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -163,7 +163,7 @@ class Origami::SaleEditController < BaseOrigamiController # end # end - sale.compute_by_sale_items(saleObj.total_discount, nil, order_source) + # sale.compute_by_sale_items(saleObj.total_discount, nil, order_source) FOR WHAT???? ProductCommission.edit_product_commission(saleitemObj) end @@ -195,7 +195,7 @@ class Origami::SaleEditController < BaseOrigamiController end remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}" sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,current_user.name, action_by,remark,"ITEMCANCELVOID" ) - + saleObj.compute_by_sale_items(saleObj.total_discount, nil, order_source) ProductCommission.remove_product_commission(saleitemObj) end diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index 82545456..fb247805 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -24,20 +24,6 @@ class InventoryDefinition < ApplicationRecord end def self.find_product_in_inventory(item) - # unless instance_code.nil? - # instance_code = instance_code.to_s - # instance_code[0] = "" - # instance_code = instance_code.chomp("]") - # else - # instance_code = '"0"' - # end - # - # if prod = InventoryDefinition.where("item_code IN(#{instance_code})") - # if stock_check_item = StockCheckItem.where("item_code IN(#{instance_code})") - # return true, prod - # end - # end - if product = InventoryDefinition.find_by_item_code(item.item_instance_code) if stock_check_item = StockCheckItem.find_by_item_code(item.item_instance_code) return true, product @@ -46,13 +32,12 @@ class InventoryDefinition < ApplicationRecord end def self.check_balance(item, inventory_definition) # item => saleItemOBj - stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first - unless stock.nil? - modify_balance(item, stock, inventory_definition) - else - puts "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< OUT OF STOCK >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" - StockJournal.add_to_journal(item.item_instance_code, item.qty, 0, "out of stock", inventory_definition, item.id, StockJournal::SALES_TRANS) - end + stock = StockJournal.where('item_code=?', item.item_instance_code).order("id DESC").first + unless stock.nil? + modify_balance(item, stock, inventory_definition) + else + StockJournal.add_to_journal(item.item_instance_code, item.qty, 0, "out of stock", inventory_definition, item.id, StockJournal::SALES_TRANS) + end end def self.modify_balance(item, stock, inventory_definition) #saleitemObj @@ -77,6 +62,7 @@ class InventoryDefinition < ApplicationRecord elsif item.is_a? SaleItem trans_type = StockJournal::SALES_TRANS end + # StockJournal.add_to_journal(instance_code, qty, stock.balance, remark, inventory_definition, item.id, trans_type) StockJournal.add_to_journal(item.item_instance_code, qty, stock.balance, remark, inventory_definition, item.id, trans_type) check_item.different = check_item.different - qty check_item.save diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 0b1c77d2..3e75ecba 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -125,41 +125,13 @@ class OrderItem < ApplicationRecord end def update_stock_journal - # if self.set_menu_items.present? - # items = JSON.parse(self.set_menu_items) - # instance_code = Array.new - # count = 0 - # items.each { |i| - # instance_code.push(i["item_instance_code"]) - # } - # end - - if self.qty != self.qty_before_last_save - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) - if found - InventoryDefinition.check_balance(self, inventory_definition) + unless MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code) + if self.qty != self.qty_before_last_save + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + InventoryDefinition.check_balance(self, inventory_definition) + end end end - # if self.qty > self.qty_was - # credit = 0 - # debit = self.qty.to_i - self.qty_was.to_i - # else - # credit = self.qty_was.to_i - self.qty.to_i - # debit = 0 - # end - # if credit != debit - # defination = InventoryDefinition.find_by_item_code(self.item_instance_code) - # stock = StockJournal.where('item_code = ?', self.item_instance_code).order("id DESC").first - # journal = StockJournal.create( - # item_code: self.item_instance_code, - # credit: credit, - # debit: debit, - # balance: stock.balance - debit + credit, - # inventory_definition_id: defination.id, - # remark: 'ok', - # trans_ref: self.order.id, - # trans_type: StockJournal::SALES_TRANS - # ) - # end end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 999a18fd..a0273619 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -2468,7 +2468,11 @@ private found, inventory_definition = InventoryDefinition.find_product_in_inventory(item) if found if stock_journal = StockJournal.find_by_trans_ref(item.order_items_id) - stock_journal.update(remark: self.sale_status) + if self.payment_status == "foc" && self.payment_status_was != "foc" + stock_journal.update(remark: self.payment_status) + else + stock_journal.update(remark: self.sale_status) + end end end end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 8473da78..65f3a4d5 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -13,6 +13,7 @@ class SaleItem < ApplicationRecord before_validation :round_to_precision after_update :update_stock_journal + after_save :update_stock_journal_set_item # Add Sale Items def self.add_sale_items(sale_items) @@ -304,40 +305,42 @@ class SaleItem < ApplicationRecord end def update_stock_journal - is_void = self.status == "void" && self.status_before_last_save != "void" - cancel_void = self.status_before_last_save == "void" && self.status.nil? - is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save - is_foc = self.status == "foc" && self.status_before_last_save != "foc" - cancel_foc = self.status_before_last_save == "foc" + unless MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code) + is_void = self.status == "void" && self.status_before_last_save != "void" + cancel_void = self.status_before_last_save == "void" && self.status.nil? + is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save + is_foc = self.status == "foc" && self.status_before_last_save != "foc" + cancel_foc = self.status_before_last_save == "foc" - if is_void or cancel_void or is_edit or is_foc or cancel_foc - found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) - if found - stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first - unless stock.nil? - check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first - if is_void or cancel_void or is_edit - if is_void - qty = -self.qty - remark = "void" - elsif cancel_void - qty = self.qty - remark = "cancel void" - elsif is_edit - qty = self.qty - self.qty_before_last_save - remark = "edit" - end - StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS) - check_item.different = check_item.different + qty - check_item.save - else is_foc or cancel_foc - qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit") - if order_item_id = self.sale.bookings.first.order_items.where(item_instance_code: self.item_instance_code, qty: self.qty + qty).select(:order_items_id).first.order_items_id - if stock_journal = StockJournal.find_by_trans_ref(order_item_id) - if is_foc - stock_journal.update(remark: "foc") - elsif cancel_foc - stock_journal.update(remark: "cancel_foc") + if is_void or cancel_void or is_edit or is_foc or cancel_foc + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + unless stock.nil? + check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + if is_void or cancel_void or is_edit + if is_void + qty = -self.qty + remark = "void" + elsif cancel_void + qty = self.qty + remark = "cancel void" + elsif is_edit + qty = self.qty - self.qty_before_last_save + remark = "edit" + end + StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS) + check_item.different = check_item.different + qty + check_item.save + else is_foc or cancel_foc + qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit") + if order_item_id = self.sale.bookings.first.order_items.where(item_instance_code: self.item_instance_code, qty: self.qty + qty).select(:order_items_id).first.order_items_id + if stock_journal = StockJournal.find_by_trans_ref(order_item_id) + if is_foc + stock_journal.update(remark: "foc") + elsif cancel_foc + stock_journal.update(remark: "cancel_foc") + end end end end @@ -346,4 +349,78 @@ class SaleItem < ApplicationRecord end end end + + def update_stock_journal_set_item + is_void = self.status == "void" && self.status_before_last_save != "void" && self.qty > 0 + cancel_void = self.status_before_last_save == "void" && self.status.nil? + is_edit = self.qty >= 0 && self.qty != self.qty_before_last_save + is_foc = self.status == "foc" && self.status_before_last_save != "foc" + cancel_foc = self.status_before_last_save == "foc" + is_waste = self.status == "waste" + is_spoile = self.status == "spoile" + + if MenuItemInstance.where("item_instance_name <> ''").pluck(:item_instance_code).include?(self.item_instance_code) + if self.qty == 1 && self.qty != self.qty_before_last_save + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + unless stock.nil? + check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + if self.qty.to_i >= 0 + qty = self.qty - self.qty_was + if stock.balance.to_i >= qty + puts ">> stock is greater than order qty" + remark = "ok" + else + puts " << stock is less than order qty" + remark = "out of stock" + end + end + StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS) + check_item.different = check_item.different - qty + check_item.save + else + StockJournal.add_to_journal(self.item_instance_code, self.qty, 0, "out of stock", inventory_definition, self.id, StockJournal::SALES_TRANS) + end + end + elsif is_void or cancel_void or is_edit + if is_void + qty = -self.qty + remark = "void" + elsif cancel_void + qty = self.qty + remark = "cancel void" + elsif is_edit + qty = self.qty - self.qty_before_last_save + remark = "edit" + end + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + stock = StockJournal.where('item_code=?', self.item_instance_code).order("id DESC").first + unless stock.nil? + check_item = StockCheckItem.where('item_code=?', self.item_instance_code).order("id DESC").first + end + end + StockJournal.add_to_journal(self.item_instance_code, qty, stock.balance, remark, inventory_definition, self.id, StockJournal::SALES_TRANS) + check_item.different = check_item.different + qty + check_item.save + elsif is_foc or cancel_foc + qty = StockJournal.where(trans_ref: self.sale_item_id).sum("credit-debit") + if stock_journal = StockJournal.where(trans_ref: self.sale_item_id, item_code: self.item_instance_code).order(id: :desc).first + if is_foc + stock_journal.update(remark: "foc") + elsif cancel_foc + stock_journal.update(remark: "cancel_foc") + end + end + elsif is_waste or is_spoile + found, inventory_definition = InventoryDefinition.find_product_in_inventory(self) + if found + if stock_journal = StockJournal.where(trans_ref: self.sale_item_id, item_code: self.item_instance_code) + stock_journal.update(remark: self.status) + end + end + end + end + end end From ba340292ab59bd2f30ea1c5152ca11cd939b08f2 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Mon, 25 Nov 2019 13:13:31 +0630 Subject: [PATCH 35/49] fixed no tax --- app/models/sale.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index a0273619..bbd76c25 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -527,7 +527,7 @@ class Sale < ApplicationRecord tax_profiles = unique_tax_profiles(order_source, self.customer_id) # #Creat new tax records - if self.payment_status != 'foc' + if self.payment_status != 'foc' && tax_type.to_s != "no_tax" tax_profiles.each do |tax| sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name @@ -552,6 +552,15 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save end + elsif tax_type.to_s == "no_tax" + tax_profiles.each do |tax| + sale_tax = SaleTax.new(:sale => self) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = 0 + sale_tax.tax_payable_amount = 0 + sale_tax.inclusive = tax.inclusive + sale_tax.save + end end self.tax_type = tax_incl_exec self.total_tax = total_tax_amount From ecd1bb79313c16868d90c4c19cafcfee19192725 Mon Sep 17 00:00:00 2001 From: NyanLinHtut Date: Mon, 25 Nov 2019 16:24:04 +0630 Subject: [PATCH 36/49] fixed service charges & commercial tax --- app/models/sale.rb | 54 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index bbd76c25..ad981c57 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -527,7 +527,7 @@ class Sale < ApplicationRecord tax_profiles = unique_tax_profiles(order_source, self.customer_id) # #Creat new tax records - if self.payment_status != 'foc' && tax_type.to_s != "no_tax" + if self.payment_status != 'foc' && tax_type.to_s == "all" tax_profiles.each do |tax| sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name @@ -561,6 +561,58 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save end + elsif tax_type.to_s == "Commercial Tax" + tax_profiles.each do |tax| + if tax.name == tax_type.to_s + 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 - 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 + elsif tax_type.to_s == "Service Charges" + tax_profiles.each do |tax| + if tax.name == tax_type.to_s + 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 - 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 self.tax_type = tax_incl_exec self.total_tax = total_tax_amount From 3c1cc737b59d183c78b65ec5c4055bdb08c6c5ef Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Mon, 25 Nov 2019 23:17:53 +0630 Subject: [PATCH 37/49] improve receipt/details reports and implement number formatting 1) eager load reports for receipt/details 2) introduce number_format lookups to replace print_settings for number formatting 3) implement NumberFormattable concern, reference number_format lookups or print_settings if not exist, to get number format settings and number formatting 4) replace rails NumberHelper.number_with_precision with NumberFormattable.number_format hopefully to reduce overhead, formatting numbers for huge lists of data --- README.md | 9 + app/controllers/application_controller.rb | 6 +- app/controllers/base_origami_controller.rb | 18 +- app/controllers/base_report_controller.rb | 20 +- .../concerns/number_formattable.rb | 57 +++++ app/controllers/home_controller.rb | 29 +-- .../reports/receipt_no_detail_controller.rb | 13 +- app/helpers/application_helper.rb | 5 +- app/models/lookup.rb | 2 + app/models/sale.rb | 226 ++++++------------ app/models/sale_audit.rb | 2 +- app/models/sale_item.rb | 3 +- app/models/sale_tax.rb | 2 +- app/pdf/check_in_out_pdf.rb | 2 +- app/pdf/close_cashier_customise_pdf.rb | 146 ++++++----- app/pdf/close_cashier_pdf.rb | 121 +++++----- app/pdf/close_cashier_pdf_v1.rb | 113 ++++----- app/pdf/move_table_pdf.rb | 6 +- app/pdf/move_table_star_pdf.rb | 6 +- app/pdf/order_item_customise_pdf.rb | 8 +- app/pdf/order_item_pdf.rb | 8 +- app/pdf/order_item_slim_customise_pdf.rb | 32 +-- app/pdf/order_item_slim_pdf.rb | 34 +-- app/pdf/order_item_star_pdf.rb | 8 +- app/pdf/order_set_item_customise_pdf.rb | 30 +-- app/pdf/order_set_item_pdf.rb | 30 +-- app/pdf/order_summary_customise_pdf.rb | 8 +- app/pdf/order_summary_pdf.rb | 52 ++-- app/pdf/order_summary_set_customise_pdf.rb | 38 +-- app/pdf/order_summary_set_pdf.rb | 48 ++-- app/pdf/order_summary_slim_customise_pdf.rb | 46 ++-- app/pdf/order_summary_slim_pdf.rb | 44 ++-- app/pdf/receipt_bill_a5_pdf.rb | 155 ++++++------ app/pdf/receipt_bill_order_pdf.rb | 83 +++---- app/pdf/receipt_bill_pdf.rb | 73 +++--- app/pdf/receipt_bill_star_pdf.rb | 65 +++-- app/pdf/sale_items_pdf.rb | 13 +- app/pdf/sale_items_star_pdf.rb | 13 +- app/views/home/dashboard.html.erb | 24 +- app/views/origami/dashboard/index.html.erb | 20 +- app/views/origami/discounts/index.html.erb | 124 ++-------- app/views/origami/home/show.html.erb | 154 ++++++------ app/views/origami/payments/show.html.erb | 96 ++++---- .../origami/table_invoices/show.html.erb | 72 +++--- app/views/reports/commission/index.html.erb | 26 +- .../reports/credit_payment/index.html.erb | 20 +- app/views/reports/dailysale/index.html.erb | 94 ++++---- app/views/reports/dailysale/index.xls.erb | 14 +- .../reports/hourly_saleitem/index.html.erb | 18 +- .../reports/hourly_saleitem/index.xls.erb | 18 +- .../reports/order_reservation/index.html.erb | 123 +++++----- .../reports/payment_method/index.html.erb | 50 ++-- .../reports/payment_method/index.xls.erb | 74 +++--- app/views/reports/product_sale/index.html.erb | 43 ++-- app/views/reports/receipt_no/index.html.erb | 40 ++-- app/views/reports/receipt_no/index.xls.erb | 39 ++- .../reports/receipt_no_detail/index.html.erb | 82 +++---- app/views/reports/saleitem/index.html.erb | 44 ++-- app/views/reports/saleitem/index.xls.erb | 88 +++---- .../reports/saleitem/indexbackup.html.erb | 106 ++++---- app/views/reports/shiftsale/index.html.erb | 32 +-- app/views/reports/staff_meal/index.html.erb | 38 +-- app/views/reports/staff_meal/index.xls.erb | 38 +-- app/views/reports/stock_check/index.html.erb | 20 +- app/views/reports/stock_check/index.xls.erb | 2 +- app/views/reports/void_sale/index.html.erb | 28 +-- .../reports/waste_and_spoilage/index.html.erb | 20 +- .../order_reservations/index.html.erb | 31 +-- .../order_reservations/show.html.erb | 59 ++--- app/views/transactions/sales/show.html.erb | 18 +- db/seeds.rb | 7 +- 71 files changed, 1338 insertions(+), 1898 deletions(-) create mode 100644 app/controllers/concerns/number_formattable.rb diff --git a/README.md b/README.md index 77a25926..54474f5e 100755 --- a/README.md +++ b/README.md @@ -279,6 +279,15 @@ For Food Court Settings On/Off ** '0' means can not use food court and '1' means can use food court ** => settings/lookups => { type:food_court, name: FoodCourt, value:'{0 or 1}' } +For Number Formats + Precision + => settings/lookups => { lookup_type: number_format, name: precision, value: {0..2} } + Delimiter + => settings/lookups => { lookup_type: number_format, name: delimiter, value: { ',', '\u0020', '', ... } + Strip insignificant zeros + => settings/lookups => { lookup_type: number_format, name: strip_insignificant_zeros, + value: {true: => ['1', 't', 'true', 'on', 'y', 'yes'], false: => ['0', 'f', 'false', 'off', 'n', 'no', ...] } + /* Customer Types in lookups */ 1) settings/lookups => { type:customer_type, name: Dinein, value:Dinein } 2) settings/lookups => { type:customer_type, name: Takeaway, value: Takeaway } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f1d5f79a..66f20c55 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,6 +1,6 @@ class ApplicationController < ActionController::Base include LoginVerification - + #before_action :check_installation protect_from_forgery with: :exception @@ -17,7 +17,5 @@ class ApplicationController < ActionController::Base flash[:warning] = exception.message redirect_to root_path end + end - - - diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index dc93b2de..6940a129 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -5,7 +5,7 @@ class BaseOrigamiController < ActionController::Base before_action :check_user #before_action :check_installation - protect_from_forgery with: :exception + protect_from_forgery with: :exception helper_method :current_token @@ -15,16 +15,16 @@ class BaseOrigamiController < ActionController::Base redirect_to origami_dashboard_path end - def check_user - if check_mobile + def check_user + if check_mobile if current_user.nil? return render status: 401, json: { - message: "User using other device!" + message: "User using other device!" }.to_json end - else + else if current_user.nil? - redirect_to root_path + redirect_to root_path end end end @@ -41,13 +41,13 @@ class BaseOrigamiController < ActionController::Base #check webview def check_mobile status = false - authenticate_with_http_token do |token, options| + authenticate_with_http_token do |token, options| if token session[:webview] = true session[:session_token] = token - end + end end - + if session[:webview] && request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i status = true end diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 0875fda5..8cb3d00d 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,11 +1,11 @@ class BaseReportController < ActionController::Base include LoginVerification - layout "application" + layout "application" - before_action :check_user + before_action :check_user - #before_action :check_installation - protect_from_forgery with: :exception + #before_action :check_installation + protect_from_forgery with: :exception rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message @@ -29,7 +29,7 @@ class BaseReportController < ActionController::Base period_type = params[:period_type] period = params[:period] from = params[:from] - to = params[:to] + to = params[:to] day_ref = Time.now.utc.getlocal if from.present? && to.present? @@ -39,10 +39,10 @@ class BaseReportController < ActionController::Base f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) from = f_time.beginning_of_day.utc.getlocal - to = t_time.end_of_day.utc.getlocal + to = t_time.end_of_day.utc.getlocal + + else - else - case period.to_i when PERIOD["today"] @@ -77,10 +77,10 @@ class BaseReportController < ActionController::Base when PERIOD["last_year"] from = (day_ref - 1.year).beginning_of_year.utc to = (day_ref - 1.year).end_of_year.utc - end + end end - return from, to + return from, to end def check_user diff --git a/app/controllers/concerns/number_formattable.rb b/app/controllers/concerns/number_formattable.rb new file mode 100644 index 00000000..a27c551c --- /dev/null +++ b/app/controllers/concerns/number_formattable.rb @@ -0,0 +1,57 @@ +module NumberFormattable + extend ActiveSupport::Concern + + def precision + @precision ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'precision'} + if @precision + @precision.value.to_i + else + @print_settings ||= PrintSetting.get_precision_delimiter + if @print_settings + @print_settings.precision.to_i + end + end || 2 + end + + def delimiter + @delimiter ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'delimiter'} + if @delimiter + @delimiter_value ||= @delimiter.value.to_s.gsub(/\\u(\h{4})/) { |m| [$1].pack("H*").unpack("n*").pack("U*") } + else + @print_settings ||= PrintSetting.get_precision_delimiter + if @print_settings + "," if @print_settings.delimiter + end + end || "" + end + + def strip_insignificant_zeros + @strip_insignificant_zeros ||= Lookup.number_formats.find { |f| f.name.parameterize.underscore == 'strip_insignificant_zeros'} + if @strip_insignificant_zeros + ['1', 't', 'true', 'on', 'y', 'yes'].include? @strip_insignificant_zeros.value.to_s + end || false + end + + def number_format(number, options = {}) + options[:precision] = options[:precision] || precision + # options[:delimiter] = options[:delimiter] || delimiter + options[:strip_insignificant_zeros] = options[:strip_insignificant_zeros] || strip_insignificant_zeros + + if options[:precision] > 0 + if options[:strip_insignificant_zeros] + formatted = "%.12g" % number.round(options[:precision]) + else + formatted = "%.#{options[:precision]}f" % number.round(options[:precision]) + end + else + formatted = number.to_i.to_s + end + + if options[:delimiter] && + formatted = formatted.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, "\\1#{options[:delimiter]}") + end + + return formatted + end + +end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 4d8c715a..3353a3a5 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -94,27 +94,24 @@ class HomeController < ApplicationController @shop = Shop.first today = DateTime.now.strftime('%Y-%m-%d') + @orders = Sale.where("payment_status = 'new' and sale_status = 'bill'") + @sales = Sale.completed + if !@from.nil? && !@to.nil? + @orders = @orders.date_between(@from, @to) + @sales = @sales.date_between(@from, @to) if !@from_time.nil? && @to_time.nil? - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() - else - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + @orders = @orders.time_between(@from_time, @to_time) + @sales = @sales.time_between(@from_time, @to_time) end else - @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() + @orders = @orders.date_on(today) + @sales = @sales.date_on(today) end - if !@from.nil? && !@to.nil? - if !@from_time.nil? && @to_time.nil? - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() - else - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() - end - else - @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - end - @top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top").sum('i.qty') - @bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom").sum('i.qty') - @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total) + + @top_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"top") + @bottom_products = Sale.top_bottom_products(today,current_user,@from,@to,@from_time,@to_time,"bottom") + @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) logger.debug 'hourly_sales<>><><><<<<<<>><<<><><><><><><><><><<>><' diff --git a/app/controllers/reports/receipt_no_detail_controller.rb b/app/controllers/reports/receipt_no_detail_controller.rb index d7b018d7..b6e8bb16 100755 --- a/app/controllers/reports/receipt_no_detail_controller.rb +++ b/app/controllers/reports/receipt_no_detail_controller.rb @@ -1,4 +1,4 @@ -class Reports::ReceiptNoDetailController < BaseReportController +class Reports::ReceiptNoDetailController < BaseReportController authorize_resource :class => false def index @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"]] @@ -9,11 +9,10 @@ authorize_resource :class => false @shift = '' if params[:shift_name].to_i != 0 - @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) @shift_sale = ShiftSale.find(params[:shift_name]) - if to.blank? + if to.blank? @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) else if @shift_sale.shift_closed_at.blank? @@ -25,7 +24,7 @@ authorize_resource :class => false end payment_type = params[:payment_type] - @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) + @sale_data = Sale.get_shift_sales_by_receipt_no_detail(@shift_sale_range,@shift,from,to,payment_type) @from = from @to = to @@ -62,10 +61,10 @@ authorize_resource :class => false end out = {:status => 'ok', :message => date_arr} - + respond_to do |format| format.json { render json: out } end end - -end \ No newline at end of file + +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 27024d75..16e44953 100755 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,4 +1,6 @@ module ApplicationHelper + include NumberFormattable + def flash_class(level) case level when :notice then "alert alert-info fade-in" @@ -6,5 +8,6 @@ module ApplicationHelper when :error then "alert alert-error fade-in" when :alert then "alert alert-error fade-in" end - end + end + end diff --git a/app/models/lookup.rb b/app/models/lookup.rb index b446d4e8..5b45822c 100755 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -2,6 +2,8 @@ class Lookup < ApplicationRecord has_many :accounts + scope :number_formats, -> { where(lookup_type: 'number_format')} + def available_types {'Employee Roles' => 'employee_roles', 'Dining Facilities Status' => 'dining_facilities_status', diff --git a/app/models/sale.rb b/app/models/sale.rb index a0273619..1074122b 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1,4 +1,5 @@ class Sale < ApplicationRecord + include NumberFormattable self.primary_key = "sale_id" #primary key - need to be unique generated for multiple shops @@ -7,12 +8,15 @@ class Sale < ApplicationRecord belongs_to :cashier, foreign_key: "cashier_id", class_name: "Employee" belongs_to :customer, :optional => true belongs_to :shift_sale + has_one :survey, foreign_key: "receipt_no" + has_many :sale_audits has_many :sale_items has_many :sale_discount_items has_many :sale_discounts has_many :sale_taxes has_many :sale_payments has_many :sale_orders + has_many :sale_payments_for_credits, through: :sale_audits has_many :orders, through: :sale_orders has_many :order_items, through: :sale_orders has_many :bookings @@ -28,7 +32,7 @@ class Sale < ApplicationRecord scope :date_on, -> (date) { where("DATE(CONVERT_TZ(receipt_date, '+00:00', ?)) = ?", Time.zone.formatted_offset, date) } scope :date_between, -> (from, to) { where("DATE(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) } scope :time_between, -> (from, to) { where("TIME(CONVERT_TZ(receipt_date, '+00:00', ?)) BETWEEN ? AND ?", Time.zone.formatted_offset, from, to) } - scope :along_with_sale_payments_except_void, -> { joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00','+06:30')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'))") } + scope :along_with_sale_payments_except_void, -> { joins("LEFT JOIN sale_payments on sales.sale_status != 'void' AND sale_payments.sale_id = sales.sale_id AND DATE(CONVERT_TZ(sale_payments.created_at,'+00:00', '#{Time.zone.formatted_offset}')) = DATE(CONVERT_TZ(sales.receipt_date,'+00:00', '#{Time.zone.formatted_offset}'))") } def qty_of(item_instance_code) order_items.select(:order_items_id, :item_instance_code, 'SUM(qty) as qty').where(item_instance_code: item_instance_code).group(:item_instance_code).first @@ -542,15 +546,20 @@ class Sale < ApplicationRecord 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 + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + end + + sale_tax.inclusive = tax.inclusive + sale_tax.save + + if !tax.inclusive 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 self.tax_type = tax_incl_exec @@ -598,6 +607,12 @@ class Sale < ApplicationRecord sale_tax.tax_payable_amount = total_tax / divided_value else sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + end + + sale_tax.inclusive = tax.inclusive + sale_tax.save + + if !tax.inclusive total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount end @@ -605,9 +620,6 @@ 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 self.tax_type = tax_incl_exec self.total_tax = total_tax_amount @@ -1197,7 +1209,7 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty payment_type = " and sale_payments.payment_method = '#{payment_type}'" end - query = Sale.all.select("sales.*,sale_payments.*,df.name,df.type") + query = Sale.includes(:sale_items).select("sales.*,sale_payments.*,df.name,df.type") .where("sale_status= 'completed' and sale_payments.payment_amount != 0 #{payment_type}") .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") .joins("join bookings on bookings.sale_id = sales.sale_id") @@ -1215,17 +1227,16 @@ end def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,payment_type) ## => left join -> show all sales although no orders - if payment_type.blank? - payment_type = '' - else - payment_type = " and sale_payments.payment_method = '#{payment_type}'" - end - query = Sale.select("sales.*,bookings.dining_facility_id as table_id") - .where("sale_status= 'completed' and sale_payments.payment_amount != 0 #{payment_type}") - .joins("join sale_payments on sale_payments.sale_id = sales.sale_id") - .joins("join bookings on bookings.sale_id = sales.sale_id") - .group("sales.sale_id") + query = Sale.includes([:customer, :survey, :sale_payments]) + .includes(:bookings => :dining_facility) + .select("sales.*, SUM(sale_payments.payment_amount) AS payments_for_credits_amount") + .joins(:bookings) + .left_joins(:sale_payments_for_credits) + .completed + .where.not(total_amount: 0) + .group(:sale_id) + .order(:receipt_date) if shift.present? query = query.where("sales.shift_sale_id in (?)", shift.to_a) elsif shift_sale_range.present? @@ -1233,6 +1244,9 @@ def self.get_shift_sales_by_receipt_no_detail(shift_sale_range,shift,from,to,pay else query = query.where("sales.receipt_date between ? and ?",from,to) end + + ActiveRecord::Associations::Preloader.new.preload(query, :sale_items, SaleItem.where.not(price: 0)) + return query end @@ -1503,101 +1517,53 @@ end end def self.top_bottom_products(today,current_user,from,to,from_time,to_time,type) - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - query = Sale.top_bottom(today,nil,from,to,from_time,to_time) + query = Sale.joins("JOIN sale_items ON sale_items.sale_id = sales.sale_id") + .completed + .where("qty > 0 AND price > 0") + .group("SUBSTRING_INDEX(product_name, ' - ', 1)") - if type == "top" - query = query.group('i.product_name') - .order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.group('i.product_name') - .order("SUM(i.qty) ASC").limit(20) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.top_bottom(today,nil,from,to,from_time,to_time) - if type == "top" - query = query.group('i.product_name') - .order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.group('i.product_name') - .order("SUM(i.qty) ASC").limit(20) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.top_bottom(today,shift,from,to,from_time,to_time) - if type == "top" - query = query.group('i.product_name') - .order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.group('i.product_name') - .order("SUM(i.qty) ASC").limit(20) - end - end - end + if !from.nil? && !to.nil? + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = Sale.top_bottom(today).group('i.product_name') - - if type == "top" - query = query.order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.order("SUM(i.qty) ASC").limit(20) - end - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.top_bottom(today).group('i.product_name') - if type == "top" - query = query.order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.order("SUM(i.qty) ASC").limit(20) - end - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.top_bottom(today,shift).group('i.product_name') - if type == "top" - query = query.order("SUM(i.qty) DESC").limit(20) - elsif type == "bottom" - query = query.order("SUM(i.qty) ASC").limit(20) - end - end - end + query = query.date_on(today) + end + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("shift_sale_id='#{shift.id}'") end end + + if type == "top" + query = query.order("SUM(qty) DESC") + else + query = query.order("SUM(qty) ASC") + end + + query.limit(20).sum('qty') end def self.hourly_sales(today,current_user,from,to,from_time,to_time) - if (!from.nil? && !to.nil?) && (from != "" && to!="") - if current_user.nil? - query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.hourly_sale_data(today,nil,from,to,from_time,to_time) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.hourly_sale_data(today,shift,from,to,from_time,to_time) - end - end + query = Sale.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") + .order('receipt_date').completed + + if !from.nil? && !to.nil? + query = query.date_between(from, to) + if !from_time.nil? && !to_time.nil? + query = query.time_between(from_time, to_time) end else - if current_user.nil? - query = Sale.hourly_sale_data(today) - else - if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor' - query = Sale.hourly_sale_data(today) - else - shift = ShiftSale.current_open_shift(current_user.id) - if !shift.nil? - query = Sale.hourly_sale_data(today,shift) - end - end + query = query.date_on(today) + end + + if current_user.present? && !(current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'account' || current_user.role == 'supervisor') + if shift = ShiftSale.current_open_shift(current_user.id) + query = query.where("shift_sale_id='#{shift.id}'") end end + query.sum(:grand_total) end def self.employee_sales(today,current_user,from,to,from_time,to_time) @@ -2074,60 +2040,6 @@ def unique_tax_profiles(order_source, customer_id) return tax_data end -def self.top_bottom(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) - if !from.nil? && !to.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,i.product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id") - if !from_time.nil? && !to_time.nil? - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%i') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") - else - query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ - " and sale_status= 'completed'") - end - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - else - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + - " i.price as unit_price,i.product_name") - .joins("JOIN sale_items i ON i.sale_id = sales.sale_id") - .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - " and sale_status= 'completed'") - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - end - return query -end - -def self.hourly_sale_data(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) - if !from.nil? && !to.nil? - query = Sale.select("grand_total") - if !from_time.nil? && !to_time.nil? - query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) - else - query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) - end - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") - .order('receipt_date') - else - query = Sale.select("grand_total") - .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) - if !shift.nil? - query = query.where("shift_sale_id='#{shift.id}'") - end - query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', '+06:30'), '%I %p')") - .order('receipt_date') - end - - return query -end - def self.employee_sale(today,shift=nil,from=nil,to=nil,from_time=nil,to_time=nil) query = Sale.joins(:cashier) .joins(:sale_payments) @@ -2291,7 +2203,7 @@ end def grand_total_round print_settings = PrintSetting.get_precision_delimiter() if !print_settings.nil? - self.grand_total =self.grand_total.round(print_settings.precision.to_i) + self.grand_total =self.grand_total.round(precision) end end @@ -2438,8 +2350,6 @@ private def round_to_precision if (self.total_amount != self.total_amount_was || self.total_discount != self.total_discount_was || self.total_tax != self.total_tax_was) if (self.total_amount % 1 > 0 || self.total_discount % 1 > 0 || self.total_tax % 1 > 0) - precision = PrintSetting.get_precision_delimiter().precision.to_i - self.total_amount = self.total_amount.round(precision) self.total_discount = self.total_discount.round(precision) self.total_tax = self.total_tax.round(precision) diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index 1488cad1..14b952af 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -6,7 +6,7 @@ class SaleAudit < ApplicationRecord belongs_to :sale - belongs_to :credit_payment, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment" + belongs_to :sale_payments_for_credit, -> { where "SUBSTRING_INDEX(sale_audits.remark,'||',1) = sale_payments.sale_payment_id" }, foreign_key: "sale_id", primary_key: "sale_id", class_name: "SalePayment" def self.sync_sale_audit_records(sale_audits) if !sale_audits.nil? diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 65f3a4d5..dc03935c 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -1,4 +1,5 @@ class SaleItem < ApplicationRecord + include NumberFormattable self.primary_key = "sale_item_id" #primary key - need to be unique generated for multiple shops @@ -294,8 +295,6 @@ class SaleItem < ApplicationRecord if self.unit_price != self.unit_price_was || self.price != self.price_was if unit_price_fraction > 0 || price_fraction > 0 if ['Discount', 'promotion'].include?(self.status) - precision = PrintSetting.get_precision_delimiter().precision.to_i - self.unit_price = self.unit_price.round(precision) self.price = (self.unit_price * self.qty).round(precision) self.taxable_price = self.price diff --git a/app/models/sale_tax.rb b/app/models/sale_tax.rb index 2e35d2b5..801c3bf7 100755 --- a/app/models/sale_tax.rb +++ b/app/models/sale_tax.rb @@ -1,4 +1,5 @@ class SaleTax < ApplicationRecord + include NumberFormattable self.primary_key = "sale_tax_id" #primary key - need to be unique generated for multiple shops @@ -44,7 +45,6 @@ class SaleTax < ApplicationRecord def round_to_precision if self.tax_payable_amount != self.tax_payable_amount_was if self.tax_payable_amount % 1 > 0 - precision = PrintSetting.get_precision_delimiter().precision.to_i self.tax_payable_amount = self.tax_payable_amount.round(precision) end end diff --git a/app/pdf/check_in_out_pdf.rb b/app/pdf/check_in_out_pdf.rb index 08b9eba8..dfc40c2c 100644 --- a/app/pdf/check_in_out_pdf.rb +++ b/app/pdf/check_in_out_pdf.rb @@ -1,5 +1,5 @@ class CheckInOutPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,booking, table) self.page_width = print_settings.page_width diff --git a/app/pdf/close_cashier_customise_pdf.rb b/app/pdf/close_cashier_customise_pdf.rb index 2b05394d..34c4288d 100644 --- a/app/pdf/close_cashier_customise_pdf.rb +++ b/app/pdf/close_cashier_customise_pdf.rb @@ -1,5 +1,5 @@ class CloseCashierCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) @@ -39,22 +39,11 @@ class CloseCashierCustomisePdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) end def header (shop_details) @@ -103,13 +92,13 @@ class CloseCashierCustomisePdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left end - + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Opening Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + text "#{ number_format(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left end y_position = cursor @@ -117,8 +106,8 @@ class CloseCashierCustomisePdf < Prawn::Document text "Closing Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left - # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + text "#{ number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}" end @@ -135,7 +124,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Received Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end @@ -144,7 +133,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Cash In :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -152,7 +141,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Cash Out :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end move_down -5 @@ -165,7 +154,7 @@ class CloseCashierCustomisePdf < Prawn::Document total_discount_account = total_discount_account.to_f + amount.total_price.to_f end - #end total amount by Account + #end total amount by Account #start total FOC amount @total_foc = 0 @@ -173,7 +162,7 @@ class CloseCashierCustomisePdf < Prawn::Document @total_foc = other.foc_amount.round(2) end - #end total FOC amount + #end total FOC amount total_grand_total = shift_sale.grand_total + @total_foc.to_f + shift_sale.total_void.to_f - total_discount_account.to_f # @total_grand_total = @shift_sale.grand_total + @overall + @total_foc + @shift_sale.total_void y_position = cursor @@ -181,21 +170,21 @@ class CloseCashierCustomisePdf < Prawn::Document text "Grand Total :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(total_grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(total_grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end #start total amount by Account Like Food / Beverage /.. total_discount_by_account.each do |amount| - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -205,8 +194,8 @@ class CloseCashierCustomisePdf < Prawn::Document @total_foc = 0 end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right - end + text "(#{ number_format(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -218,7 +207,7 @@ class CloseCashierCustomisePdf < Prawn::Document move_down -5 stroke_horizontal_rule - move_down 7 + move_down 7 @total_foc = 0 y_position = cursor @@ -226,7 +215,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Cash Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -234,9 +223,9 @@ class CloseCashierCustomisePdf < Prawn::Document text "Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right end - #start other payment details + #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) @@ -246,7 +235,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "MPU Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -256,7 +245,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "VISA Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -266,7 +255,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Master Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -276,7 +265,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "JCB Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -286,7 +275,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -296,7 +285,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Alipay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -306,7 +295,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "JunctionPay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -316,7 +305,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Dinga Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -326,7 +315,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -336,7 +325,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Paymal Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -346,7 +335,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end end @@ -356,7 +345,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Other Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -365,8 +354,8 @@ class CloseCashierCustomisePdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - + text "#{ number_format(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor @@ -374,14 +363,14 @@ class CloseCashierCustomisePdf < Prawn::Document text "Gross Sale :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "#{ number_format(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right end - # end other payment details + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 - + # start Dinein and Takeaway y_position = cursor @@ -392,7 +381,7 @@ class CloseCashierCustomisePdf < Prawn::Document total_dinein = 0 end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_dinein, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_dinein, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -401,11 +390,11 @@ class CloseCashierCustomisePdf < Prawn::Document end if total_takeway.nil? total_takeway = 0 - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_takeway, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_format(total_takeway, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + # stop Dinein and Takeaway move_down -5 @@ -419,7 +408,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -428,7 +417,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Taxes :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -436,7 +425,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + text "#{number_format(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end if total_credit_payments && total_credit_payments.to_f > 0 @@ -445,7 +434,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end #end for service charges and commercial tax @@ -463,16 +452,16 @@ class CloseCashierCustomisePdf < Prawn::Document move_down 7 #start total amount by Account Like Food / Beverage /.. # total_discount_by_account.each do |amount| - + # y_position = cursor # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do # text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right # end # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - # text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + # text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right # end # end - #end total amount by Account + #end total amount by Account # y_position = cursor # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -481,19 +470,19 @@ class CloseCashierCustomisePdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right # end - + #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account #start total other charges amount if total_other_charges.present? @@ -502,9 +491,9 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Other Charges :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_other_charges, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_other_charges, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - end + end #end total other charges amount move_down -5 @@ -513,32 +502,32 @@ class CloseCashierCustomisePdf < Prawn::Document #start total over all discount if total_member_discount[0].member_discount.present? - @member_discount = total_member_discount[0].member_discount rescue 0.0 + @member_discount = total_member_discount[0].member_discount rescue 0.0 @overall = shift_sale.total_discounts - @member_discount - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Member Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - else - @overall = shift_sale.total_discounts + else + @overall = shift_sale.total_discounts end - + if @overall > 0 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "-#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end + text "-#{ number_format(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end move_down -5 stroke_horizontal_rule move_down 7 - end + end #end total over all discount if total_waste.to_f > 0 @@ -547,7 +536,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Waste :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end end @@ -557,7 +546,7 @@ class CloseCashierCustomisePdf < Prawn::Document text "Total Spoile :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end end @@ -591,4 +580,3 @@ class CloseCashierCustomisePdf < Prawn::Document move_down 5 end end - diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index d4564291..976c3d93 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -1,5 +1,5 @@ class CloseCashierPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shift_sale, sale_items, total_other_charges_info, acc_cate_count, menu_cate_count, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) @@ -39,25 +39,14 @@ class CloseCashierPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) if !sale_items.nil? or !sale_items.blank? - sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges_info) + sale_items_detail(sale_items, acc_cate_count, menu_cate_count, total_by_acc, total_other_charges_info) end end @@ -107,13 +96,13 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left end - + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Opening Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + text "#{ number_format(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left end y_position = cursor @@ -121,8 +110,8 @@ class CloseCashierPdf < Prawn::Document text "Closing Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left - # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + text "#{ number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}" end @@ -139,7 +128,7 @@ class CloseCashierPdf < Prawn::Document text "Received Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end @@ -148,7 +137,7 @@ class CloseCashierPdf < Prawn::Document text "Cash In:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -156,7 +145,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Out:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end move_down -5 @@ -169,7 +158,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -177,10 +166,10 @@ class CloseCashierPdf < Prawn::Document text "Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right end - #start other payment details + #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) @@ -190,7 +179,7 @@ class CloseCashierPdf < Prawn::Document text "MPU Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -200,7 +189,7 @@ class CloseCashierPdf < Prawn::Document text "VISA Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -210,7 +199,7 @@ class CloseCashierPdf < Prawn::Document text "Master Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -220,7 +209,7 @@ class CloseCashierPdf < Prawn::Document text "JCB Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -230,7 +219,7 @@ class CloseCashierPdf < Prawn::Document text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -240,7 +229,7 @@ class CloseCashierPdf < Prawn::Document text "Alipay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -250,7 +239,7 @@ class CloseCashierPdf < Prawn::Document text "KBZ Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.kbzpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -260,7 +249,7 @@ class CloseCashierPdf < Prawn::Document text "JunctionPay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -270,7 +259,7 @@ class CloseCashierPdf < Prawn::Document text "Dinga Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -280,7 +269,7 @@ class CloseCashierPdf < Prawn::Document text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -290,7 +279,7 @@ class CloseCashierPdf < Prawn::Document text "Paymal Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -300,7 +289,7 @@ class CloseCashierPdf < Prawn::Document text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end end @@ -310,7 +299,7 @@ class CloseCashierPdf < Prawn::Document text "Other Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -319,7 +308,7 @@ class CloseCashierPdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -327,10 +316,10 @@ class CloseCashierPdf < Prawn::Document text "Total :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "#{ number_format(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right end - # end other payment details + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 @@ -342,7 +331,7 @@ class CloseCashierPdf < Prawn::Document text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -351,7 +340,7 @@ class CloseCashierPdf < Prawn::Document text "Total Taxes :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -359,7 +348,7 @@ class CloseCashierPdf < Prawn::Document text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + text "#{number_format(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end if total_credit_payments && total_credit_payments.to_f > 0 @@ -368,7 +357,7 @@ class CloseCashierPdf < Prawn::Document text "Total Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end #end for service charges and commercial tax @@ -386,30 +375,30 @@ class CloseCashierPdf < Prawn::Document move_down 7 #start total amount by Account Like Food / Beverage /.. total_discount_by_account.each do |amount| - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account if total_member_discount[0].member_discount.present? - @member_discount = total_member_discount[0].member_discount rescue 0.0 + @member_discount = total_member_discount[0].member_discount rescue 0.0 @overall = shift_sale.total_discounts - @member_discount - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Member Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - else - @overall = shift_sale.total_discounts + else + @overall = shift_sale.total_discounts end y_position = cursor @@ -417,18 +406,18 @@ class CloseCashierPdf < Prawn::Document text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end + text "#{ number_format(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total FOC :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right - end + text "(#{ number_format(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end - y_position = cursor + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Void :", :size => self.item_font_size, :align => :right end @@ -441,7 +430,7 @@ class CloseCashierPdf < Prawn::Document text "Total Waste :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end y_position = cursor @@ -449,7 +438,7 @@ class CloseCashierPdf < Prawn::Document text "Total Spoile :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end # y_position = cursor @@ -459,19 +448,19 @@ class CloseCashierPdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right # end - + move_down -5 stroke_horizontal_rule move_down 7 #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end @@ -482,7 +471,7 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{total_other_charges}", :size => self.item_font_size, :align => :right end - #end total amount by Account + #end total amount by Account y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -532,7 +521,7 @@ class CloseCashierPdf < Prawn::Document sale_items.each do |item| if !arr.include?(item['menu_category_id']) - + if flag == true move_down 5 stroke_horizontal_rule @@ -567,7 +556,7 @@ class CloseCashierPdf < Prawn::Document # text_box "#{item['grand_total'].to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix # } add_item_line(item['product_name'], item['unit_price'].to_i, item['total_item'].to_i, item['grand_total'].to_i) - + if item['total_item'].to_i > 0 or item['status_type'] == 'foc' or item['status_type'] == 'void' total_qty += item['total_item'].to_i total_items += item['total_item'].to_i @@ -657,4 +646,4 @@ class CloseCashierPdf < Prawn::Document text_box "#{sub_total.to_i}", :at =>[item_label_total_front_width,y_position], :width => item_label_total_end_width, :height =>self.item_height, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix } end -end \ No newline at end of file +end diff --git a/app/pdf/close_cashier_pdf_v1.rb b/app/pdf/close_cashier_pdf_v1.rb index 687f0aa8..c241c047 100644 --- a/app/pdf/close_cashier_pdf_v1.rb +++ b/app/pdf/close_cashier_pdf_v1.rb @@ -1,5 +1,5 @@ class CloseCashierPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shift_sale, total_by_acc, shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) @@ -39,22 +39,11 @@ class CloseCashierPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) end @@ -104,13 +93,13 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left end - + y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do text "Opening Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + text "#{ number_format(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left end y_position = cursor @@ -118,8 +107,8 @@ class CloseCashierPdf < Prawn::Document text "Closing Float : ", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do - text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left - # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + text "#{ number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}" end @@ -136,7 +125,7 @@ class CloseCashierPdf < Prawn::Document text "Received Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end @@ -145,7 +134,7 @@ class CloseCashierPdf < Prawn::Document text "Cash In:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -153,7 +142,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Out:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end move_down -5 @@ -166,7 +155,7 @@ class CloseCashierPdf < Prawn::Document text "Cash Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -174,10 +163,10 @@ class CloseCashierPdf < Prawn::Document text "Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + text "#{number_format(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right end - #start other payment details + #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| @total_foc = other.foc_amount.round(2) @@ -187,7 +176,7 @@ class CloseCashierPdf < Prawn::Document text "MPU Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -197,7 +186,7 @@ class CloseCashierPdf < Prawn::Document text "VISA Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{number_format(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -207,7 +196,7 @@ class CloseCashierPdf < Prawn::Document text "Master Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -217,7 +206,7 @@ class CloseCashierPdf < Prawn::Document text "JCB Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -227,7 +216,7 @@ class CloseCashierPdf < Prawn::Document text "UNIONPAY Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.unionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -237,7 +226,7 @@ class CloseCashierPdf < Prawn::Document text "Alipay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.alipay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -247,7 +236,7 @@ class CloseCashierPdf < Prawn::Document text "JunctionPay Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.junctionpay_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -257,7 +246,7 @@ class CloseCashierPdf < Prawn::Document text "Dinga Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.dinga_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -267,7 +256,7 @@ class CloseCashierPdf < Prawn::Document text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -277,7 +266,7 @@ class CloseCashierPdf < Prawn::Document text "Paymal Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.paymal_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -287,7 +276,7 @@ class CloseCashierPdf < Prawn::Document text "GiftVoucher Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(other.giftvoucher_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end end @@ -297,7 +286,7 @@ class CloseCashierPdf < Prawn::Document text "Other Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -306,7 +295,7 @@ class CloseCashierPdf < Prawn::Document text "Rounding Adjustments :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -314,10 +303,10 @@ class CloseCashierPdf < Prawn::Document text "Total :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + text "#{ number_format(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right end - # end other payment details + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 @@ -329,7 +318,7 @@ class CloseCashierPdf < Prawn::Document text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end @@ -338,7 +327,7 @@ class CloseCashierPdf < Prawn::Document text "Total Taxes :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -346,7 +335,7 @@ class CloseCashierPdf < Prawn::Document text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + text "#{number_format(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end if total_credit_payments && total_credit_payments.to_f > 0 @@ -355,7 +344,7 @@ class CloseCashierPdf < Prawn::Document text "Total Credit Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end end #end for service charges and commercial tax @@ -373,30 +362,30 @@ class CloseCashierPdf < Prawn::Document move_down 7 #start total amount by Account Like Food / Beverage /.. total_discount_by_account.each do |amount| - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{ number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end - #end total amount by Account + #end total amount by Account if total_member_discount[0].member_discount.present? - @member_discount = total_member_discount[0].member_discount rescue 0.0 + @member_discount = total_member_discount[0].member_discount rescue 0.0 @overall = shift_sale.total_discounts - @member_discount - + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Member Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + text "#{ number_format(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right end - else - @overall = shift_sale.total_discounts + else + @overall = shift_sale.total_discounts end y_position = cursor @@ -404,18 +393,18 @@ class CloseCashierPdf < Prawn::Document text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right - end + text "#{ number_format(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total FOC :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right - end + text "(#{ number_format(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end - y_position = cursor + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total Void :", :size => self.item_font_size, :align => :right end @@ -428,7 +417,7 @@ class CloseCashierPdf < Prawn::Document text "Total Waste :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end y_position = cursor @@ -436,7 +425,7 @@ class CloseCashierPdf < Prawn::Document text "Total Spoile :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + text "(#{ number_format(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right end # y_position = cursor @@ -446,19 +435,19 @@ class CloseCashierPdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right # end - + move_down -5 stroke_horizontal_rule move_down 7 #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + text "#{number_format(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right end end @@ -469,7 +458,7 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{total_other_charges}", :size => self.item_font_size, :align => :right end - #end total amount by Account + #end total amount by Account y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -502,4 +491,4 @@ class CloseCashierPdf < Prawn::Document end -end \ No newline at end of file +end diff --git a/app/pdf/move_table_pdf.rb b/app/pdf/move_table_pdf.rb index 5d44b393..dc55eedc 100644 --- a/app/pdf/move_table_pdf.rb +++ b/app/pdf/move_table_pdf.rb @@ -1,5 +1,5 @@ class MoveTablePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(printer_settings,to,from,shop_detail,date,type,moved_by,order_items) self.page_width = printer_settings.page_width @@ -39,7 +39,7 @@ class MoveTablePdf < Prawn::Document stroke_horizontal_rule move_down 5 - add_lining_item(order_items, printer_settings.precision) + add_lining_item(order_items, precision) move_down 5 stroke_horizontal_rule @@ -98,7 +98,7 @@ class MoveTablePdf < Prawn::Document 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 + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do diff --git a/app/pdf/move_table_star_pdf.rb b/app/pdf/move_table_star_pdf.rb index 0467cbab..88ea4ef1 100644 --- a/app/pdf/move_table_star_pdf.rb +++ b/app/pdf/move_table_star_pdf.rb @@ -1,5 +1,5 @@ class MoveTableStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,to,from,shop_detail,date,type,moved_by,order_items) self.page_width = printer_settings.page_width @@ -38,7 +38,7 @@ class MoveTableStarPdf < Prawn::Document stroke_horizontal_rule move_down 5 - add_lining_item(order_items, printer_settings.precision) + add_lining_item(order_items, precision) move_down 5 stroke_horizontal_rule @@ -97,7 +97,7 @@ class MoveTableStarPdf < Prawn::Document 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 + text "#{number_format(odi.qty, :precision => precision.to_i)}", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do diff --git a/app/pdf/order_item_customise_pdf.rb b/app/pdf/order_item_customise_pdf.rb index b509a01a..32be1928 100644 --- a/app/pdf/order_item_customise_pdf.rb +++ b/app/pdf/order_item_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderItemCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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 @@ -47,7 +47,7 @@ class OrderItemCustomisePdf < Prawn::Document 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) + order_items(order_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF @@ -107,7 +107,7 @@ class OrderItemCustomisePdf < Prawn::Document end bounding_box([self.item_width - 10,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 => :right + text "[#{number_format(order_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right end bounding_box([0,y_position], :width => self.item_width) do @@ -146,7 +146,7 @@ class OrderItemCustomisePdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.page_width) 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 + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index ed079aeb..d4a05aa2 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -1,5 +1,5 @@ class OrderItemPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_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) @@ -48,7 +48,7 @@ class OrderItemPdf < Prawn::Document 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) + order_items(order_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF @@ -108,7 +108,7 @@ class OrderItemPdf < Prawn::Document 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 + text "[#{number_format(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 @@ -147,7 +147,7 @@ class OrderItemPdf < Prawn::Document # 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 + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_slim_customise_pdf.rb b/app/pdf/order_item_slim_customise_pdf.rb index c4b1e5c5..f759cbec 100644 --- a/app/pdf/order_item_slim_customise_pdf.rb +++ b/app/pdf/order_item_slim_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderItemSlimCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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, :item_slim_font_size def initialize(print_settings,order_item_slim, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderItemSlimCustomisePdf < Prawn::Document 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_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 self.item_slim_font_size=8 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -29,17 +29,17 @@ class OrderItemSlimCustomisePdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" if !order_item_slim.dining.nil? text "#{ order_item_slim.type + '-' + order_item_slim.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 1 @@ -47,35 +47,35 @@ class OrderItemSlimCustomisePdf < Prawn::Document order_info(order_item_slim.order_id, order_item_slim.order_by,order_item_slim.order_at) # order items slim - order_items_slim(order_item_slim, options, alt_name, print_settings.precision, before_updated_qty) + order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_slim_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_slim_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 "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_slim_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.item_slim_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_slim_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.item_slim_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_slim_font_size,:align => :left end stroke_horizontal_rule @@ -88,7 +88,7 @@ class OrderItemSlimCustomisePdf < Prawn::Document def order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_items_slim(order_item_slim, options, alt_name, precision) dash(1, :space => 1, :phase => 1) @@ -108,7 +108,7 @@ class OrderItemSlimCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right + text "[#{number_format(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right end bounding_box([0,y_position], :width => self.item_width) do @@ -146,7 +146,7 @@ class OrderItemSlimCustomisePdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.page_width) 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 + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_slim_pdf.rb b/app/pdf/order_item_slim_pdf.rb index 3e39644f..a32c1a26 100755 --- a/app/pdf/order_item_slim_pdf.rb +++ b/app/pdf/order_item_slim_pdf.rb @@ -1,7 +1,7 @@ class OrderItemSlimPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width - + def initialize(print_settings,order_item_slim, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width self.page_height = print_settings.page_height @@ -12,9 +12,9 @@ class OrderItemSlimPdf < Prawn::Document 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_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + 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]) @@ -29,17 +29,17 @@ class OrderItemSlimPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" if !order_item_slim.dining.nil? text "#{ order_item_slim.type + '-' + order_item_slim.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 1 @@ -47,35 +47,35 @@ class OrderItemSlimPdf < Prawn::Document order_info(order_item_slim.order_id, order_item_slim.order_by,order_item_slim.order_at) # order items slim - order_items_slim(order_item_slim, options, alt_name, print_settings.precision, before_updated_qty) + order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_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 "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_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.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_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.item_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -87,7 +87,7 @@ class OrderItemSlimPdf < Prawn::Document def order_items_slim(order_item_slim, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_items_slim(order_item_slim, options, alt_name, precision) puts options puts '............PDF OPTIONS...............' @@ -108,7 +108,7 @@ class OrderItemSlimPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_item_slim.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_item_slim.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 @@ -146,7 +146,7 @@ class OrderItemSlimPdf < Prawn::Document # 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 + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_item_star_pdf.rb b/app/pdf/order_item_star_pdf.rb index 2686efd7..0703c8a2 100644 --- a/app/pdf/order_item_star_pdf.rb +++ b/app/pdf/order_item_star_pdf.rb @@ -1,5 +1,5 @@ class OrderItemStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_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) @@ -48,7 +48,7 @@ class OrderItemStarPdf < Prawn::Document 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) + order_items(order_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF @@ -108,7 +108,7 @@ class OrderItemStarPdf < Prawn::Document 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 + text "[#{number_format(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 @@ -147,7 +147,7 @@ class OrderItemStarPdf < Prawn::Document # 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 + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_set_item_customise_pdf.rb b/app/pdf/order_set_item_customise_pdf.rb index 2e1d0a2c..f684e275 100644 --- a/app/pdf/order_set_item_customise_pdf.rb +++ b/app/pdf/order_set_item_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSetItemCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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_set_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -12,9 +12,9 @@ class OrderSetItemCustomisePdf < Prawn::Document 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_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + 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]) @@ -29,11 +29,11 @@ class OrderSetItemCustomisePdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" if !order_set_item.dining.nil? text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else @@ -46,35 +46,35 @@ class OrderSetItemCustomisePdf < Prawn::Document order_info(order_set_item.order_id, order_set_item.order_by,order_set_item.order_at) # order items - order_set_items(order_set_item, options, alt_name, print_settings.precision, before_updated_qty) + order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left + text "Booking: #{booking_id}", :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 "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left + 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 + 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 + 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 @@ -86,7 +86,7 @@ class OrderSetItemCustomisePdf < Prawn::Document def order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_set_items(order_set_item, options, alt_name, precision) dash(1, :space => 1, :phase => 1) @@ -106,7 +106,7 @@ class OrderSetItemCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right + text "[#{number_format(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :right end bounding_box([0,y_position], :width => self.item_width) do @@ -161,7 +161,7 @@ class OrderSetItemCustomisePdf < Prawn::Document # add option y_position = cursor bounding_box([0,y_position], :width => self.page_width) 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 + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_set_item_pdf.rb b/app/pdf/order_set_item_pdf.rb index 09cdc6db..cb57c870 100755 --- a/app/pdf/order_set_item_pdf.rb +++ b/app/pdf/order_set_item_pdf.rb @@ -1,5 +1,5 @@ class OrderSetItemPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order_set_item, print_status, options, alt_name, before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSetItemPdf < Prawn::Document 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_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + 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]) @@ -28,11 +28,11 @@ class OrderSetItemPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] end # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - #font "public/fonts/Chinese.ttf" + # font "public/fonts/padauk.ttf" + #font "public/fonts/Chinese.ttf" if !order_set_item.dining.nil? text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 else @@ -45,35 +45,35 @@ class OrderSetItemPdf < Prawn::Document order_info(order_set_item.order_id, order_set_item.order_by,order_set_item.order_at) # order items - order_set_items(order_set_item, options, alt_name, print_settings.precision, before_updated_qty) + order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 2 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left end move_down 2 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.item_font_size,:align => :left + text "Date: #{order_at.utc.getlocal.strftime("%Y-%m-%d %I:%M %p")}", :size => self.item_font_size,:align => :left end stroke_horizontal_rule @@ -85,7 +85,7 @@ class OrderSetItemPdf < Prawn::Document def order_set_items(order_set_item, options, alt_name, precision, before_updated_qty) y_position = cursor - #Add Order Item + #Add Order Item add_order_set_items(order_set_item, options, alt_name, precision) dash(1, :space => 1, :phase => 1) @@ -105,7 +105,7 @@ class OrderSetItemPdf < Prawn::Document end bounding_box([self.item_width,y_position], :width => self.qty_width) do - text "[#{number_with_precision(order_set_item.qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(order_set_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 @@ -160,7 +160,7 @@ class OrderSetItemPdf < Prawn::Document # 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 + text "* Change quantity [#{number_format(before_updated_qty.to_i, :precision => precision.to_i)}] to [#{number_format(updated_qty.to_i, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end end end diff --git a/app/pdf/order_summary_customise_pdf.rb b/app/pdf/order_summary_customise_pdf.rb index 8ffedca0..bce29877 100644 --- a/app/pdf/order_summary_customise_pdf.rb +++ b/app/pdf/order_summary_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSummaryCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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 @@ -48,9 +48,9 @@ class OrderSummaryCustomisePdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end @@ -113,7 +113,7 @@ class OrderSummaryCustomisePdf < Prawn::Document end bounding_box([self.item_width - 10,y_position], :width => self.qty_width) do - text " [#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text " [#{number_format(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left end bounding_box([0,y_position], :width => self.item_width) do diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index fd446131..f3d25ff1 100755 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -1,5 +1,5 @@ class OrderSummaryPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSummaryPdf < Prawn::Document 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_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -27,18 +27,18 @@ class OrderSummaryPdf < Prawn::Document }) font "#{print_settings.font}" - fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + 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 @@ -47,38 +47,38 @@ class OrderSummaryPdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left - end - - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no}", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no}", :size => self.item_font_size,:align => :left end move_down 5 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.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 5 + 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.item_font_size,:align => :left end stroke_horizontal_rule @@ -103,7 +103,7 @@ class OrderSummaryPdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -113,7 +113,7 @@ class OrderSummaryPdf < Prawn::Document move_down 5 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -123,14 +123,14 @@ class OrderSummaryPdf < Prawn::Document 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 + text "#{number_format(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 @@ -138,15 +138,15 @@ class OrderSummaryPdf < Prawn::Document 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 @@ -161,7 +161,7 @@ class OrderSummaryPdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_set_customise_pdf.rb b/app/pdf/order_summary_set_customise_pdf.rb index 0e33d314..70c116fc 100644 --- a/app/pdf/order_summary_set_customise_pdf.rb +++ b/app/pdf/order_summary_set_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySetCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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 @@ -12,9 +12,9 @@ class OrderSummarySetCustomisePdf < Prawn::Document 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_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -38,7 +38,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 5 @@ -47,38 +47,38 @@ class OrderSummarySetCustomisePdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.order_no_font_size,:align => :left + text "Booking: #{booking_id}", :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 "OrderNo: #{order_no} ", :size => self.order_no_font_size,:align => :left + 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 + 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 + 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 @@ -92,7 +92,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -102,7 +102,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document move_down 5 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -112,14 +112,14 @@ class OrderSummarySetCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(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 @@ -127,7 +127,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true # end end - + end #add set menu items @@ -148,10 +148,10 @@ class OrderSummarySetCustomisePdf < Prawn::Document # 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 @@ -166,7 +166,7 @@ class OrderSummarySetCustomisePdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_set_pdf.rb b/app/pdf/order_summary_set_pdf.rb index 5e27f82b..dd65f0d2 100755 --- a/app/pdf/order_summary_set_pdf.rb +++ b/app/pdf/order_summary_set_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySetPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSummarySetPdf < Prawn::Document 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_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -37,7 +37,7 @@ class OrderSummarySetPdf < Prawn::Document else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 5 @@ -46,38 +46,38 @@ class OrderSummarySetPdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left - end - - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_font_size,:align => :left end move_down 5 y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left end move_down 5 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.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_font_size,:align => :left + end + + move_down 5 + 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.item_font_size,:align => :left end stroke_horizontal_rule @@ -102,7 +102,7 @@ class OrderSummarySetPdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -112,7 +112,7 @@ class OrderSummarySetPdf < Prawn::Document move_down 5 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -122,14 +122,14 @@ class OrderSummarySetPdf < Prawn::Document 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 + text "#{number_format(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 @@ -137,7 +137,7 @@ class OrderSummarySetPdf < Prawn::Document text "(#{odi.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true # end end - + end #add set menu items @@ -158,10 +158,10 @@ class OrderSummarySetPdf < Prawn::Document # 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 @@ -176,7 +176,7 @@ class OrderSummarySetPdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 5 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_slim_customise_pdf.rb b/app/pdf/order_summary_slim_customise_pdf.rb index c641b0c8..e8bd21f2 100644 --- a/app/pdf/order_summary_slim_customise_pdf.rb +++ b/app/pdf/order_summary_slim_customise_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySlimCustomisePdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:item_slim_font_size def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,10 +11,10 @@ class OrderSummarySlimCustomisePdf < Prawn::Document 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_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 - self.item_slim_font_size=8 + self.label_width=90 + self.item_slim_font_size=8 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -38,7 +38,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 1 @@ -47,38 +47,38 @@ class OrderSummarySlimCustomisePdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_slim_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 "OrderNo: #{order_no} ", :size => self.item_slim_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_slim_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.item_slim_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_slim_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.item_slim_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_slim_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.item_slim_font_size,:align => :left end stroke_horizontal_rule @@ -95,7 +95,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -105,7 +105,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document move_down 1 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -115,14 +115,14 @@ class OrderSummarySlimCustomisePdf < Prawn::Document end bounding_box([self.item_width - 5,y_position], :width => self.qty_width) do - text "[#{number_with_precision(odi.qty, :precision => precision.to_i)}]", :size => self.item_font_size,:align => :left + text "[#{number_format(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_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 1 @@ -134,7 +134,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 1 @@ -152,7 +152,7 @@ class OrderSummarySlimCustomisePdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 1 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/order_summary_slim_pdf.rb b/app/pdf/order_summary_slim_pdf.rb index 1b78cf23..2cbe14d8 100755 --- a/app/pdf/order_summary_slim_pdf.rb +++ b/app/pdf/order_summary_slim_pdf.rb @@ -1,5 +1,5 @@ class OrderSummarySlimPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width def initialize(print_settings,order, print_status, order_items = nil,alt_name,before_updated_qty) self.page_width = print_settings.page_width @@ -11,9 +11,9 @@ class OrderSummarySlimPdf < Prawn::Document 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_height = 15 self.item_description_width = self.page_width - (self.price_width + self.qty_width + self.total_width) - self.label_width=90 + self.label_width=90 super(:margin => [print_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) @@ -37,7 +37,7 @@ class OrderSummarySlimPdf < Prawn::Document else text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 end - + stroke_horizontal_rule move_down 1 @@ -46,38 +46,38 @@ class OrderSummarySlimPdf < Prawn::Document # order items if order_items == nil - order_items(order, alt_name, print_settings.precision) + order_items(order, alt_name, precision) else - order_items(order_items, alt_name, print_settings.precision) + order_items(order_items, alt_name, precision) end end # Write Order Information to PDF - def order_info(order_no, order_by, order_at) + def order_info(order_no, order_by, order_at) #booking ID booking_id = get_booking_id(order_no) y_position = cursor bounding_box([0,y_position], :width => self.item_width, :height => self.item_height) do - text "Booking: #{booking_id}", :size => self.item_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 "OrderNo: #{order_no} ", :size => self.item_font_size,:align => :left + text "Booking: #{booking_id}", :size => self.item_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.item_font_size,:align => :left + text "OrderNo: #{order_no} ", :size => self.item_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.item_font_size,:align => :left + text "OrderBy: #{order_by} ", :size => self.item_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.item_font_size,:align => :left end stroke_horizontal_rule @@ -102,7 +102,7 @@ class OrderSummarySlimPdf < Prawn::Document #Add Order Item add_order_items(order_item, alt_name, precision) - + end # Add order items under order info @@ -112,7 +112,7 @@ class OrderSummarySlimPdf < Prawn::Document move_down 1 order_item.each do|odi| - # check for item not to show + # check for item not to show # if odi.price != 0 y_position = cursor @@ -122,14 +122,14 @@ class OrderSummarySlimPdf < Prawn::Document 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 + text "#{number_format(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_name}", :size => self.item_font_size,:align => :left end - + if alt_name if !(odi.alt_name).empty? move_down 1 @@ -141,7 +141,7 @@ class OrderSummarySlimPdf < Prawn::Document # add option options = odi.options == "[]"? "" : odi.options - + if options != "" move_down 1 @@ -159,7 +159,7 @@ class OrderSummarySlimPdf < Prawn::Document stroke_horizontal_line 0, (self.page_width - self.margin) move_down 1 # end - end + end end def get_booking_id(order_no) diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 02443c0c..fbbf51e2 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -1,5 +1,5 @@ class ReceiptBillA5Pdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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, :description_width, :price_num_width, :line_move def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,other_charges_amount,latest_order_no,card_balance_amount) @@ -26,11 +26,6 @@ class ReceiptBillA5Pdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -46,23 +41,17 @@ class ReceiptBillA5Pdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) + line_items(sale_items,precision,delimiter) + all_total(sale_data,precision,delimiter) if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) end customer(customer_name) @@ -77,21 +66,21 @@ class ReceiptBillA5Pdf < Prawn::Document card_balance_data(card_balance_amount) end #end card blanace amount - + if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + discount_account(discount_price_by_accounts,precision,delimiter) end if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) + items_account(item_price_by_accounts,precision,delimiter) if other_charges_amount - show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + show_other_charges_amount(other_charges_amount,precision,delimiter) end end #start for individual payment if !sale_data.equal_persons.nil? - individual_payment(sale_data, printer_settings.precision, delimiter) + individual_payment(sale_data, precision, delimiter) end #end for individual payment @@ -100,7 +89,7 @@ class ReceiptBillA5Pdf < Prawn::Document if shop_details.note && !shop_details.note.nil? shop_note(printed_status) end - + footer(printed_status) end @@ -130,7 +119,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "OrderNo : #{ latest_order_no }", :size => self.header_font_size+2,:align => :left end move_down line_move - + # move_down 2 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do @@ -154,7 +143,7 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([self.item_description_width, y_position], :width =>self.item_description_width, :height => self.item_height) do text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left - end + end bounding_box([self.item_description_width - 2,y_position], :width =>self.item_description_width, :height => self.item_height) do text "C: #{sale_data.cashier_name}", :size => self.item_font_size,:align => :right end @@ -172,7 +161,7 @@ class ReceiptBillA5Pdf < Prawn::Document # bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do - # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } + # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } # - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" , # :size => self.item_font_size,:align => :right # end @@ -209,7 +198,7 @@ class ReceiptBillA5Pdf < Prawn::Document end def add_line_item_row(sale_items,precision,delimiter) - + if precision.to_i > 0 item_name_width = (self.item_width+self.price_width) item_qty_front_width = (self.item_width+self.price_width) + 5 @@ -229,17 +218,17 @@ class ReceiptBillA5Pdf < Prawn::Document sub_total = 0.0 total_qty = 0.0 sale_items.each do |item| - # check for item not to show + # check for item not to show show_price = Lookup.find_by_lookup_type("show_price") sub_total += item.price #(item.qty*item.unit_price) - comment for room charges if item.status != 'Discount' && item.qty > 0 if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 - total_qty += item.qty + total_qty += item.qty else if item.price != 0 - total_qty += item.qty + total_qty += item.qty end end end @@ -265,14 +254,14 @@ class ReceiptBillA5Pdf < Prawn::Document text "Sub Total", :size => self.item_font_size,:align => :left end # bounding_box([self.item_width + self.price_width + 11,y_position], :width =>self.qty_width, :height => self.item_height) do - # text "#{number_with_precision(total_qty, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :center + # text "#{number_format(total_qty, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :center # end # bounding_box([self.item_width + self.price_width + 8,y_position], :width =>self.total_width, :height => self.item_height) do - # text "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + # text "#{number_format(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right # end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -297,10 +286,10 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width) do text "#{product_name}", :size => self.item_font_size,:align => :left end - # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -328,7 +317,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ dis_type }", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "( #{number_with_precision(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end if sale_data.sale_taxes.length > 0 @@ -344,7 +333,7 @@ class ReceiptBillA5Pdf < Prawn::Document 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 + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end else @@ -370,7 +359,7 @@ class ReceiptBillA5Pdf < Prawn::Document end bounding_box([self.description_width,y_position], :width =>self.label_width) do text "#{sale_data.rounding_adjustment}", :size => self.item_font_size,:align => :right - end + end end move_down line_move @@ -380,15 +369,15 @@ class ReceiptBillA5Pdf < Prawn::Document text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move - + sale_payment(sale_data,precision,delimiter) - + end - def sale_payment(sale_data,precision,delimiter) + def sale_payment(sale_data,precision,delimiter) stroke_horizontal_rule # move_down 10 sql = "SELECT SUM(payment_amount) @@ -419,28 +408,28 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left end end - + bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end - if sale_data.amount_received > 0 + if sale_data.amount_received > 0 y_position = cursor move_down line_move bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do text "Change Amount", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end #move_down line_move - end + end end # show member information def member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) - if rebate_amount != nil + if rebate_amount != nil if rebate_amount["status"] == true stroke_horizontal_rule total = 0 @@ -467,10 +456,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "Rebate Earn", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - - end + + end # Total Rebate Amount if birthday if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebatebonusAccount" && res["status"]== "Rebate" rebate_balance = rebate_balance + res["deposit"] @@ -480,9 +469,9 @@ class ReceiptBillA5Pdf < Prawn::Document text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - end + end #end Total rebate if birthday end @@ -492,7 +481,7 @@ class ReceiptBillA5Pdf < Prawn::Document text "Redeem Amount", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if current_balance != nil @@ -502,10 +491,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "Old Balance", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end - + end end @@ -515,7 +504,7 @@ class ReceiptBillA5Pdf < Prawn::Document if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" total_balance = total_balance + res["balance"] - + end end move_down line_move @@ -524,10 +513,10 @@ class ReceiptBillA5Pdf < Prawn::Document text "Total Balance", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end - + end def customer(customer_name) @@ -554,8 +543,8 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :size => self.item_font_size,:align => :left end bounding_box([self.description_width,y_position], :width =>self.label_width) do - text "(" + "#{ number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right - end + text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + end move_down line_move end end @@ -570,8 +559,8 @@ class ReceiptBillA5Pdf < Prawn::Document text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.description_width) do - text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end + text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end move_down line_move end end @@ -582,9 +571,9 @@ class ReceiptBillA5Pdf < Prawn::Document text "Other Charges", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end - move_down line_move + move_down line_move end #individual payment per person @@ -604,7 +593,7 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -623,17 +612,17 @@ class ReceiptBillA5Pdf < Prawn::Document JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payment_id where sa.sale_id='#{sale_data.sale_id}')) = 0 - THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment| + THEN payment_method!='creditnote' ELSE 1 END) AND sale_id = ?", sale_data.sale_id).each do |payment| if payment.payment_method == "creditnote" y_position = cursor stroke_horizontal_rule - + bounding_box([self.label_width,y_position], :width =>self.description_width) do move_down 70 stroke_horizontal_rule end - + bounding_box([self.label_width,y_position], :width =>self.description_width) do move_down 73 text "Approved By" , :size => self.item_font_size,:align => :center @@ -650,8 +639,8 @@ class ReceiptBillA5Pdf < Prawn::Document move_down 70 stroke_horizontal_rule end - - if sale_data.payment_status == "foc" + + if sale_data.payment_status == "foc" bounding_box([self.label_width,y_position], :width =>self.description_width) do move_down 73 text "Acknowledged By" , :size => self.item_font_size,:align => :center @@ -661,10 +650,10 @@ class ReceiptBillA5Pdf < Prawn::Document move_down 73 text "Approved By" , :size => self.item_font_size,:align => :center end - end - - end - + end + + end + end def shop_note(shop) @@ -674,8 +663,8 @@ class ReceiptBillA5Pdf < Prawn::Document move_down line_move y_position = cursor - - text "#{shop.note}", :size => self.item_font_size,:align => :left + + text "#{shop.note}", :size => self.item_font_size,:align => :left move_down line_move end @@ -688,10 +677,10 @@ class ReceiptBillA5Pdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.item_description_width) do text "#{printed_status}",:style => :bold, :size => header_font_size,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size,:align => :right - end + end move_down line_move end @@ -729,7 +718,7 @@ class ReceiptBillA5Pdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width) do text "Card Balance: ",:style => :bold, :size => header_font_size,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{card_balance_amount}" , :size => self.item_font_size,:align => :right end @@ -753,4 +742,4 @@ class ReceiptBillA5Pdf < Prawn::Document end return status end -end \ No newline at end of file +end diff --git a/app/pdf/receipt_bill_order_pdf.rb b/app/pdf/receipt_bill_order_pdf.rb index e66cb37e..0f2e1fc6 100644 --- a/app/pdf/receipt_bill_order_pdf.rb +++ b/app/pdf/receipt_bill_order_pdf.rb @@ -1,5 +1,5 @@ class ReceiptBillOrderPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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, :description_width, :price_num_width, :line_move @@ -27,11 +27,6 @@ class ReceiptBillOrderPdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -47,19 +42,13 @@ class ReceiptBillOrderPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no,order_reservation) - line_items(sale_items,printer_settings.precision,delimiter,order_reservation) - all_total(sale_data,printer_settings.precision,delimiter,order_reservation) + line_items(sale_items,precision,delimiter,order_reservation) + all_total(sale_data,precision,delimiter,order_reservation) footer(printed_status) end @@ -78,13 +67,13 @@ class ReceiptBillOrderPdf < Prawn::Document def cashier_info(sale_data, customer_name, latest_order_no,order_reservation) move_down line_move - + # move_down 2 - + y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "Order Date " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "#{order_reservation.created_at.strftime('%d-%m-%Y %H:%M %p')}", :size => self.item_font_size,:align => :right end @@ -92,7 +81,7 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "Requested Date Time " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "#{order_reservation.requested_time.strftime('%d-%m-%Y %H:%M %p')}", :size => self.item_font_size,:align => :right end @@ -100,7 +89,7 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "Payment Type" , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "#{order_reservation.payment_type}", :size => self.item_font_size,:align => :right end @@ -108,7 +97,7 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width , :height => self.item_height) do text "#{customer_name} " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do text "Online Order", :size => self.item_font_size,:align => :right end @@ -167,14 +156,14 @@ class ReceiptBillOrderPdf < Prawn::Document total_qty = 0.0 show_price = Lookup.find_by_lookup_type("show_price") sale_items.each do |item| - # check for item not to show + # check for item not to show if item.status != 'Discount' && item.qty > 0 if !show_price.nil? && show_price.value.to_i > 0 && item.price == 0 - total_qty += item.qty + total_qty += item.qty else if item.price != 0 - total_qty += item.qty + total_qty += item.qty end end end @@ -191,7 +180,7 @@ class ReceiptBillOrderPdf < Prawn::Document qty = item.qty total_price = item.price #item.qty*item.unit_price - comment for room charges price = item.unit_price - + # end if !show_price.nil? && show_price.value.to_i>0 item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -209,8 +198,8 @@ class ReceiptBillOrderPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(order_reservation.total_amount, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(order_reservation.total_amount, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if !order_reservation.delivery_type.nil? && order_reservation.delivery_fee.to_f > 0 y_position = cursor @@ -219,27 +208,27 @@ class ReceiptBillOrderPdf < Prawn::Document end bounding_box([self.description_width - 48,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.delivery_fee, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end + text "#{number_format(order_reservation.delivery_fee, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end end if order_reservation.total_tax > 0 y_position = cursor bounding_box([0, y_position], :width =>self.item_description_width , :height => self.item_height) do text "Tax " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.total_tax, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end - end + text "#{number_format(order_reservation.total_tax, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end + end y_position = cursor bounding_box([0, y_position], :width =>self.item_description_width , :height => self.item_height) do text "Convenience Charges " , :size => self.item_font_size, :align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.convenience_charge, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(order_reservation.convenience_charge, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if order_reservation.discount_amount > 0 @@ -249,9 +238,9 @@ class ReceiptBillOrderPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "#{number_with_precision(order_reservation.discount_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end - end + text "#{number_format(order_reservation.discount_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end + end end #Change items rows @@ -277,10 +266,10 @@ class ReceiptBillOrderPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width) do text "#{product_name}", :size => self.item_font_size,:align => :left end - # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -309,11 +298,11 @@ class ReceiptBillOrderPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(order_reservation.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right - end + text "#{number_format(order_reservation.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + end move_down line_move - # sale_payment(sale_data,precision,delimiter) + # sale_payment(sale_data,precision,delimiter) end #Change Footer @@ -326,10 +315,10 @@ class ReceiptBillOrderPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width) do text "#{printed_status}",:style => :bold, :size => header_font_size - 1,:align => :left - end + end bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Thank You! See you Again", :left_margin => -5, :size => self.item_font_size - 1,:align => :left - end + end move_down line_move end @@ -351,4 +340,4 @@ class ReceiptBillOrderPdf < Prawn::Document end return status end -end \ No newline at end of file +end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 2a99e9f9..2d463b38 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,7 +1,7 @@ # require 'prawn/qrcode' require 'prawn/measurement_extensions' class ReceiptBillPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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, :description_width, :price_num_width, :line_move @@ -29,11 +29,6 @@ class ReceiptBillPdf < Prawn::Document #setting page margin and width super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -49,23 +44,17 @@ class ReceiptBillPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) + line_items(sale_items,precision,delimiter) + all_total(sale_data,precision,delimiter) if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) end customer(customer_name) @@ -82,19 +71,19 @@ class ReceiptBillPdf < Prawn::Document #end card blanace amount if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + discount_account(discount_price_by_accounts,precision,delimiter) end if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) + items_account(item_price_by_accounts,precision,delimiter) if other_charges_amount - show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + show_other_charges_amount(other_charges_amount,precision,delimiter) end end #start for individual payment if !sale_data.equal_persons.nil? - individual_payment(sale_data,sale_data.equal_persons, printer_settings.precision, delimiter) + individual_payment(sale_data,sale_data.equal_persons, precision, delimiter) end #end for individual payment @@ -273,8 +262,8 @@ class ReceiptBillPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(@sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(@sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -298,9 +287,9 @@ class ReceiptBillPdf < Prawn::Document text "#{product_name}", :size => self.item_font_size,:align => :left end # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -330,7 +319,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ dis_type }", :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(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end service_tax_desc = "" @@ -355,14 +344,14 @@ class ReceiptBillPdf < Prawn::Document sale_data.sale_taxes.each do |st| if (st.tax_name.include? "Service") service_tax_desc = st.tax_name - service_tax_amount = number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) + service_tax_amount = number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) if incl_tax service_tax_rate = st.tax_rate.to_i end end if (st.tax_name.include? "Commercial") com_tax_desc = st.tax_name - com_tax_amount = number_with_precision(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) + com_tax_amount = number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter) if incl_tax com_tax_rate = st.tax_rate.to_i end @@ -374,7 +363,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ service_tax_desc } (#{incl_tax} #{ service_tax_rate }%)", :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(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(service_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move y_position = cursor @@ -391,7 +380,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ com_tax_desc } (#{incl_tax} #{ com_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(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(com_tax_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end else sale_data.sale_taxes.each do |st| @@ -402,7 +391,7 @@ class ReceiptBillPdf < Prawn::Document 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 + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end end @@ -439,7 +428,7 @@ class ReceiptBillPdf < Prawn::Document text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move @@ -480,7 +469,7 @@ class ReceiptBillPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -491,7 +480,7 @@ class ReceiptBillPdf < Prawn::Document text "Change Amount", :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(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end # move_down line_move end @@ -526,7 +515,7 @@ class ReceiptBillPdf < Prawn::Document text "Rebate Earn", :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(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -539,7 +528,7 @@ class ReceiptBillPdf < Prawn::Document text "Rebate Earn Bonus", :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(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end #end Total rebate if birthday @@ -551,7 +540,7 @@ class ReceiptBillPdf < Prawn::Document text "Redeem Amount", :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(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if current_balance != nil @@ -561,7 +550,7 @@ class ReceiptBillPdf < Prawn::Document text "Old Balance", :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(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -583,7 +572,7 @@ class ReceiptBillPdf < Prawn::Document text "Total Balance", :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(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -615,7 +604,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :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(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -631,7 +620,7 @@ class ReceiptBillPdf < Prawn::Document text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -643,7 +632,7 @@ class ReceiptBillPdf < Prawn::Document text "Other Charges", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -666,7 +655,7 @@ class ReceiptBillPdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end diff --git a/app/pdf/receipt_bill_star_pdf.rb b/app/pdf/receipt_bill_star_pdf.rb index 0b1f8ce2..d9a14d4a 100644 --- a/app/pdf/receipt_bill_star_pdf.rb +++ b/app/pdf/receipt_bill_star_pdf.rb @@ -1,5 +1,5 @@ class ReceiptBillStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :margin_top, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move @@ -28,11 +28,6 @@ class ReceiptBillStarPdf < Prawn::Document #setting page margin and width super(:margin => [self.margin_top, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - # db font setup if printer_settings.font != "" font_families.update("#{printer_settings.font}" => { @@ -48,23 +43,17 @@ class ReceiptBillStarPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header(shop_details) stroke_horizontal_rule cashier_info(sale_data, customer_name, latest_order_no) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) + line_items(sale_items,precision,delimiter) + all_total(sale_data,precision,delimiter) if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + member_info(member_info,customer_name,rebate_amount,sale_data,precision,delimiter,current_balance) end customer(customer_name) @@ -81,19 +70,19 @@ class ReceiptBillStarPdf < Prawn::Document #end card blanace amount if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + discount_account(discount_price_by_accounts,precision,delimiter) end if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) + items_account(item_price_by_accounts,precision,delimiter) if other_charges_amount - show_other_charges_amount(other_charges_amount,printer_settings.precision,delimiter) + show_other_charges_amount(other_charges_amount,precision,delimiter) end end #start for individual payment if !sale_data.equal_persons.nil? - individual_payment(sale_data,sale_data.equal_persons, printer_settings.precision, delimiter) + individual_payment(sale_data,sale_data.equal_persons, precision, delimiter) end #end for individual payment @@ -268,8 +257,8 @@ class ReceiptBillStarPdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_width + self.price_width, :height => self.item_height) do text "Sub Total", :size => self.item_font_size,:align => :left end - text_box "#{number_with_precision(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(total_qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(sub_total, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix end def item_row(item,precision,delimiter,product_name,price,qty ,total_price) @@ -293,9 +282,9 @@ class ReceiptBillStarPdf < Prawn::Document text "#{product_name}", :size => self.item_font_size,:align => :left end # text_box "#{product_name}", :at =>[0,y_position], :width => self.item_width, :size => self.item_font_size - text_box "#{number_with_precision(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix - text_box "#{number_with_precision(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix - text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[self.item_width,y_position], :width => self.price_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix + text_box "#{number_format(qty, :precision => precision.to_i)}", :at =>[item_qty_front_width,y_position], :width => item_qty_end_width, :size => self.item_font_size, :align => :center, :overflow => :shrink_to_fix + text_box "#{number_format(total_price, :precision => precision.to_i, :delimiter => delimiter)}", :at =>[item_total_front_width,y_position], :width =>item_total_end_width, :size => self.item_font_size, :align => :right, :overflow => :shrink_to_fix if show_alt_name if !(item.product_alt_name).empty? @@ -325,7 +314,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ dis_type }", :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(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right + text "( #{number_format(sale_data.total_discount, :precision => precision.to_i, :delimiter => delimiter)} )" , :size => self.item_font_size,:align => :right end if sale_data.sale_taxes.length > 0 @@ -342,7 +331,7 @@ class ReceiptBillStarPdf < Prawn::Document 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 + text "#{number_format(st.tax_payable_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end else @@ -378,7 +367,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Grand Total",:style => :bold, :size => self.header_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right + text "#{number_format(sale_data.grand_total, :precision => precision.to_i, :delimiter => delimiter)}" , :style => :bold, :size => self.header_font_size,:align => :right end move_down line_move @@ -419,7 +408,7 @@ class ReceiptBillStarPdf < Prawn::Document end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -430,7 +419,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Change Amount", :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(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(sale_data.amount_changed, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end # move_down line_move end @@ -465,7 +454,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Rebate Earn", :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(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -478,7 +467,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Rebate Earn Bonus", :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(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end #end Total rebate if birthday @@ -490,7 +479,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Redeem Amount", :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(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end if current_balance != nil @@ -500,7 +489,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Old Balance", :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(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(current_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end @@ -522,7 +511,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Total Balance", :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(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(total_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end @@ -554,7 +543,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ 'Total ' + ipa[:name] + ' Discounts' }", :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(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right + text "(" + "#{ number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter) }" + ")" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -570,7 +559,7 @@ class ReceiptBillStarPdf < Prawn::Document text "#{ ipa[:name] }", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(ipa[:price], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -582,7 +571,7 @@ class ReceiptBillStarPdf < Prawn::Document text "Other Charges", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - text "#{number_with_precision(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_format(other_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end move_down line_move end @@ -605,7 +594,7 @@ class ReceiptBillStarPdf < Prawn::Document bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + text "#{number_format(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end diff --git a/app/pdf/sale_items_pdf.rb b/app/pdf/sale_items_pdf.rb index 657b7fe1..af76c427 100644 --- a/app/pdf/sale_items_pdf.rb +++ b/app/pdf/sale_items_pdf.rb @@ -1,5 +1,5 @@ class SaleItemsPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shop_details, period, type, account, from_date, to_date, shift, sale_items, total_other_charges) @@ -41,17 +41,6 @@ class SaleItemsPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule diff --git a/app/pdf/sale_items_star_pdf.rb b/app/pdf/sale_items_star_pdf.rb index 6860b341..a1181e13 100644 --- a/app/pdf/sale_items_star_pdf.rb +++ b/app/pdf/sale_items_star_pdf.rb @@ -1,5 +1,5 @@ class SaleItemsStarPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + include NumberFormattable 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,:text_width def initialize(printer_settings, shop_details, period, type, account, from_date, to_date, shift, sale_items, total_other_charges) @@ -41,17 +41,6 @@ class SaleItemsStarPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 - end - #check delimiter - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - header( shop_details) stroke_horizontal_rule diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 0f9890d7..5c2eeb8d 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -3,18 +3,6 @@

<%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %>

- <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %>
@@ -211,19 +199,19 @@ <% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> <%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : - <%= number_with_precision( revenue, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : - <%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_format( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : - <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_format( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total_sale") %> : - <%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%> + <%= number_format( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%> @@ -240,7 +228,7 @@ @@ -253,7 +241,7 @@ <% end %> diff --git a/app/views/origami/dashboard/index.html.erb b/app/views/origami/dashboard/index.html.erb index 204ac3d4..713ba6a5 100644 --- a/app/views/origami/dashboard/index.html.erb +++ b/app/views/origami/dashboard/index.html.erb @@ -6,18 +6,6 @@

<%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %>

- <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %>
@@ -91,19 +79,19 @@
<% revenue = @summ_sale.total_amount - @summ_sale.total_discount%> - + - + - + - +
<% @sale_data.each do |data| %> <% pay_mth = payment.payment_method %> - <%= number_with_precision(data[""+pay_mth+""], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_format(data[""+pay_mth+""], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %> <% end %>
<%= t("views.right_panel.detail.other_payment") %> : - <%= number_with_precision(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_format(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_format(0, precision: precision.to_i ,delimiter: delimiter) %>
<%= t("views.right_panel.detail.sale") %> <%= t :revenue %> : <%= number_with_precision( revenue, precision: precision.to_i ,delimiter: delimiter) %><%= number_format( revenue, precision: precision.to_i ,delimiter: delimiter) %>
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : <%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %><%= number_format( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %>
<%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%><%= number_format( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%>
<%= t("views.right_panel.detail.total") %> <%= t :sale %> : <%= number_with_precision( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%><%= number_format( @summ_sale.grand_total , precision: precision.to_i ,delimiter: delimiter)%>
diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index abeeb442..5d24c9d1 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -2,20 +2,6 @@ - <% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% end %>
@@ -96,7 +82,7 @@
- +
@@ -57,14 +43,14 @@
- <% @tables.each do |table| %> + <% @tables.each do |table| %> <% if table.status == 'occupied' %> <% if table.get_booking.nil? %> <% if table.get_checkout_booking.nil? %>
- <% else %> + <% else %>
- <% end %> + <% end %>
<%= table.name %>
<%= table.zone.name %> @@ -72,12 +58,12 @@
- <% else %> + <% else %> <% if table.get_checkout_booking.nil? %>
- <% else %> + <% else %>
- <% end %> + <% end %>
<%= table.name %>
<%= table.zone.name %> @@ -111,7 +97,7 @@ <% end %>
<%= room.name %>
- <%= room.zone.name %> + <%= room.zone.name %> billed
@@ -123,7 +109,7 @@ <% end %>
<%= room.name %>
- <%= room.zone.name %> + <%= room.zone.name %> new
@@ -132,8 +118,8 @@
<%= room.name %>
- <%= room.zone.name %> - + <%= room.zone.name %> +
<% end %> @@ -160,8 +146,8 @@ <% else %> <% order_status = order.status %> <% end %> - <%= order.order_id %> - <% if !order_status.empty? %>| <%= order_status %> + <%= order.order_id %> + <% if !order_status.empty? %>| <%= order_status %> <% end %>
@@ -193,7 +179,7 @@
- + @@ -245,7 +231,7 @@ <% else %> ORDER DETAILS | Table <%= @dining.name rescue "" %> <% end %> - +
@@ -335,8 +321,8 @@ <% end %> <% if !order_item.set_menu_items.nil? && order_item.set_menu_items != '[]' - JSON.parse(order_item.set_menu_items).each do |item_instance| - set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f %> + JSON.parse(order_item.set_menu_items).each do |item_instance| + set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f %>
<%= item_instance["item_instance_name"] %> @@ -345,17 +331,17 @@
<%= set_item_option %> <% end %> <% end %> -
- <% end + + <% end sub_total += set_item_prices end %>
- + <% end %> <% end %> - <% end %> + <% end %>
Sub Total:<%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %><%= number_format(sub_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<%= t :credit %> <%= t :sale %> <%= t("views.right_panel.detail.date") %> <%= t("views.right_panel.detail.receipt_no") %> <%= t :cashier %> <%= t("views.right_panel.detail.name") %> <%= t :customer %> <%= t("views.right_panel.detail.name") %> <%= t :customer %> <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.credit_amount") %>
<%= order_item.qty %> <%= (order_item.qty*order_item.price).to_f + set_item_prices %>
@@ -364,7 +350,7 @@ - + <%if @obj_sale != nil && @obj_sale.discount_type == 'member_discount'%> @@ -373,7 +359,7 @@ <%end%> - + <% if @status_sale == "sale" %> @@ -396,15 +382,15 @@ <% end %> - + - + - + <% end %> @@ -431,10 +417,10 @@ <% end %> <% end %> - <% if !order_item.set_menu_items.nil? - JSON.parse(order_item.set_menu_items).each do |item_instance| + <% if !order_item.set_menu_items.nil? + JSON.parse(order_item.set_menu_items).each do |item_instance| set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f - %> + %>
<%= item_instance["item_instance_name"] %> <% if !item_instance["options"].nil? && item_instance["options"] != "undefined" %> @@ -444,8 +430,8 @@ <% end %> <% end %> - - <% end + + <% end sub_total += set_item_prices end %> @@ -456,7 +442,7 @@ end %>
Sub Total:<%= number_with_precision(sub_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %><%= number_format(sub_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
Discount:(<%= number_with_precision(@obj_sale.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>)(<%= number_format(@obj_sale.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>)
<%= number_with_precision(@obj_sale.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%><%= number_format(@obj_sale.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
Rounding Adj:<%= number_with_precision(@obj_sale.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%><%= number_format(@obj_sale.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%>
Grand Total:<%= number_with_precision(@obj_sale.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %><%= number_format(@obj_sale.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
--> - + <% end %> <% if @sale_array.size > 1 %> @@ -496,7 +482,7 @@ - <% if @dining.status != "available" %> + <% if @dining.status != "available" %> <% if @status_order == 'order' && @status_sale != 'sale' %> <%if !@order_items.empty? %> @@ -526,7 +512,7 @@ <% if current_login_employee.role == "cashier" %> - Edit + Edit Void <% else %> @@ -545,19 +531,19 @@ <% end %> <% if current_login_employee.role != "waiter" %> - + <%if @membership.discount && @obj_sale.customer.membership_id %> <%else%> - <%end%> - + <%end%> + <% end %> <% end %> @@ -583,7 +569,7 @@
- + <% @payment_methods.each_with_index do |pay, pay_index| %> <%if (pay_index+1)%3 == 0 %>
@@ -625,7 +611,7 @@
- + @@ -638,7 +624,7 @@ - @@ -690,7 +676,7 @@ count += 1 %> - <%= count %> + <%= count %> <%= order_item.item_name %> <% if !order_item.options.nil? && !order_item.options.empty? && order_item.options != "undefined" %> @@ -701,10 +687,10 @@ <% end %> <% end %> - <% if !order_item.set_menu_items.nil? - JSON.parse(order_item.set_menu_items).each do |item_instance| + <% if !order_item.set_menu_items.nil? + JSON.parse(order_item.set_menu_items).each do |item_instance| set_item_prices += (item_instance["quantity"].to_f * item_instance["price"].to_f).to_f - %> + %>
<%= item_instance["item_instance_name"] %> <% if !item_instance["options"].nil? && item_instance["options"] != "undefined" %> @@ -714,8 +700,8 @@ <% end %> <% end %> - - <% end + + <% end sub_total += set_item_prices end %> @@ -823,7 +809,7 @@ if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ receipt_no = ($("#receipt_no").html()).trim(); } - + discount="<%= @membership.discount%>" if ($("#server_mode").val() != "cloud") { // first bill not used in cloud if (discount) { @@ -887,7 +873,7 @@ } else { var sale_id = "<%= @dining.id %>"; } - //var table_id = $('.tables').attr("data-id"); + //var table_id = $('.tables').attr("data-id"); window.location.href = '/origami/' + sale_id +"/"+cashier_type+ "/surveys" }); @@ -989,22 +975,22 @@ } location.reload(); } - }); + }); } - }); + }); }); - // click select option icon for add - $(document).on('click', '.payment_btn', function(event){ + // click select option icon for add + $(document).on('click', '.payment_btn', function(event){ active = $(this).hasClass('selected-payment'); value = $(this).data('value'); type = $(this).data('type'); group = $(this).data('group'); payments = $(".payment_btn"); - if (active) { + if (active) { $(this).removeClass('selected-payment'); - }else{ + }else{ $(this).addClass('selected-payment'); } }); //End selecct attribute buttom @@ -1026,7 +1012,7 @@ if(!location.pathname.includes("credit_payment")){ calculate_member_discount(sale_id,"Cash",tax_type); } - } + } } var ajax_url = "/origami/sale/" + sale_id + "/first_bill"; $.ajax({ @@ -1045,7 +1031,7 @@ } location.reload(); } - }); + }); }); function calculate_member_discount(sale_id,type,tax_type) { @@ -1060,10 +1046,10 @@ url: "/origami/" + sale_id + "/member_discount", data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card,'cashier_type':'cashier','tax_type':tax_type }, async: false, - success:function(result){ + success:function(result){ } }); - + } $('#pay').on('click', function () { @@ -1137,11 +1123,11 @@ } }); } - else { + else { location.reload(); } } - }); + }); }else{ swal("Opps","There is no orders!","warning"); } @@ -1151,7 +1137,7 @@ $('#split_bills').click(function(){ var dining_id = "<%= @dining.id %>"; window.location.href = '/origami/table/' + dining_id + "/" + cashier_type +"/split_bills"; - }); + }); $('#move').on('click', function () { if($('#move').is(":visible")) { @@ -1236,7 +1222,7 @@ }else{ swal("Opps","You are not authorized for void","warning") } - + }); $('#commissions').on('click', function () { @@ -1285,7 +1271,7 @@ } }); } - }); + }); }else{ swal("Opps","You are not authorized for void","warning") } @@ -1303,7 +1289,7 @@ window.location.href = '/origami/addorders/' + dining_id; }); - /* check in process */ + /* check in process */ $('#check_in').on('click',function(){ var dining_id = "<%= @dining.id %>"; @@ -1394,7 +1380,7 @@ } }); } - }); + }); } function check_emp_access_code(access_code,type) { @@ -1460,11 +1446,11 @@ type: "POST", url: "/origami/payment/"+cashier_type+"/change_tax", data: {sale_id: sale_id, cashier_type: cashier_type, tax_type: tax_type}, - success:function(data){ + success:function(data){ if(data.status){ localStorage.setItem("tax_type", tax_type); window.location.href = '/origami/table/'+dining_id; - } + } } }); }else{ diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index a40f7f58..a7737724 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -2,20 +2,6 @@ - <% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> - <% end %>
@@ -78,9 +64,9 @@ <% sub_total += sale_item.price%> <%= count %> - <%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%> + <%=sale_item.product_name%>@<%=number_format( sale_item.unit_price, precision: precision.to_i )%> <%=sale_item.qty%> - <%=(number_with_precision(sale_item.price, precision: precision.to_i ))%> + <%=(number_format(sale_item.price, precision: precision.to_i ))%> <%end %> @@ -93,7 +79,7 @@ Sub Total - <%=number_with_precision(sub_total, precision: precision.to_i)%> + <%=number_format(sub_total, precision: precision.to_i)%> <%if @sale_data.discount_type == 'member_discount'%> @@ -101,7 +87,7 @@ <%else%> (Discount) <%end%> - (<%= number_with_precision(@sale_data.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>) + (<%= number_format(@sale_data.total_discount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>) @@ -122,20 +108,20 @@ <% end %> - <%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> + <%= number_format(@sale_data.total_tax, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> Rounding Adj: - <%= number_with_precision(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> + <%= number_format(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> Grand Total - <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> + <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i )%> <%if @balance > 0%> <%= @accountable_type %> - <%=number_with_precision(@balance, precision: precision.to_i )%> + <%=number_format(@balance, precision: precision.to_i )%> <% end %> <% if !@individual_total[0].nil? %> @@ -149,7 +135,7 @@ Amount Due (per person) - <%= number_with_precision(@individual_total[0]['per_person_amount'], precision: precision.to_i )%> + <%= number_format(@individual_total[0]['per_person_amount'], precision: precision.to_i )%> <% end %> @@ -171,16 +157,16 @@ <% if @sale_payment.nil? %> - <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %> + <%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %> <% else %> - <%= number_with_precision(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i)%> + <%= number_format(@sale_payment[0].payment_amount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i)%> <% end %> @@ -190,13 +176,13 @@
Cash
- <%= number_with_precision(@cash, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %> + <%= number_format(@cash, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% if @sale_payment.nil? && @cashier_type != "food_court" %>
Credit
-
<%= number_with_precision(@credit, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@credit, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> @@ -205,21 +191,21 @@
Other Payments (KBZ Pay)
- <%= number_with_precision(@kbz_pay_amount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> + <%= number_format(@kbz_pay_amount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
<% elsif @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0 && @unionpaycount == 0.0 && @alipaycount == 0.0 && @paymalcount == 0.0 && @junctionpaycount == 0.0 && @dingacount == 0.0 && @giftvouchercount == 0.0 %>
Other Payments
- <%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> + <%= number_format(@other, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
<% else %>
Other Payments
- <%= number_with_precision(@other_payment, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %> + <%= number_format(@other_payment, precision: precision.to_i) rescue number_format(0, precision: precision.to_i) %>
<% end %> @@ -231,9 +217,9 @@
MPU
<% if @other != 0.0 %> -
<%= number_with_precision(@other, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@other, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %>
@@ -242,9 +228,9 @@
Redeem
<% if @ppamount != 0.0 %> -
<%= number_with_precision(@ppamount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@ppamount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %>
@@ -253,9 +239,9 @@
VISA
<% if @visacount != 0.0 %> -
<%= number_with_precision(@visacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@visacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -264,9 +250,9 @@
JCB
<% if @jcbcount != 0.0 %> -
<%= number_with_precision(@jcbcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@jcbcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -275,9 +261,9 @@
MASTER
<% if @mastercount != 0.0 %> -
<%= number_with_precision(@mastercount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@mastercount, precision: precision.to_i) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -287,9 +273,9 @@
UNIONPAY
<% if @unionpaycount != 0.0 %> -
<%= number_with_precision(@unionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@unionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -298,9 +284,9 @@
Alipay
<% if @alipaycount != 0.0 %> -
<%= number_with_precision(@alipaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@alipaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -309,9 +295,9 @@
PAYMAL
<% if @paymalcount != 0.0 %> -
<%= number_with_precision(@paymalcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@paymalcount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -319,9 +305,9 @@
DINGA
<% if @dingacount != 0.0 %> -
<%= number_with_precision(@dingacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@dingacount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -330,9 +316,9 @@
JUNCTION PAY
<% if @junctionpaycount != 0.0 %> -
<%= number_with_precision(@junctionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@junctionpaycount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %> @@ -341,15 +327,15 @@
GIFT VOUCHER
<% if @giftvouchercount != 0.0 %> -
<%= number_with_precision(@giftvouchercount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@giftvouchercount, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
<% else %> -
<%= number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(0, precision: precision.to_i ) %>
<% end %>
Balance
-
<%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
+
<%= number_format(@sale_data.grand_total, precision: precision.to_i ) rescue number_format(0, precision: precision.to_i ) %>
diff --git a/app/views/origami/table_invoices/show.html.erb b/app/views/origami/table_invoices/show.html.erb index 84efbc66..76c65057 100644 --- a/app/views/origami/table_invoices/show.html.erb +++ b/app/views/origami/table_invoices/show.html.erb @@ -1,19 +1,5 @@
-<% if !@print_settings.nil? %> - <% if @print_settings.precision.to_i > 0 - precision = @print_settings.precision - else - precision = 0 - end - #check delimiter - if @print_settings.delimiter - delimiter = "," - else - delimiter = "" - end - %> -<% end %>
@@ -89,7 +75,7 @@ <%= count %> <%= sale_item.product_name %> <%= sale_item.qty %> - <%= number_with_precision(sale_item.price, precision: precision.to_i ) %> + <%= number_format(sale_item.price, precision: precision.to_i ) %> <% # end @@ -108,7 +94,7 @@ <%= count %> <%= order_item.item_name %> <%= order_item.qty %> - <%= number_with_precision(order_item.qty*order_item.price, precision: precision.to_i ) %> + <%= number_format(order_item.qty*order_item.price, precision: precision.to_i ) %> <% end @@ -124,7 +110,7 @@ - + <%if @sale.discount_type == 'member_discount'%> @@ -132,19 +118,19 @@ <%else%> <%end%> - + - + - + - +
Sub Total:<%= number_with_precision(sub_total, precision: precision.to_i ) %><%= number_format(sub_total, precision: precision.to_i ) %>
Discount:(<%= number_with_precision(@sale.total_discount, precision: precision.to_i ) rescue 0%>)(<%= number_format(@sale.total_discount, precision: precision.to_i ) rescue 0%>)
Tax:<%= number_with_precision(@sale.total_tax, precision: precision.to_i ) rescue 0%><%= number_format(@sale.total_tax, precision: precision.to_i ) rescue 0%>
Rounding Adj:<%= number_with_precision(@sale.rounding_adjustment, precision: precision.to_i ) rescue 0%><%= number_format(@sale.rounding_adjustment, precision: precision.to_i ) rescue 0%>
Grand Total:<%= number_with_precision(@sale.grand_total, precision: precision.to_i ) rescue 0%><%= number_format(@sale.grand_total, precision: precision.to_i ) rescue 0%>
@@ -163,7 +149,7 @@ <%else%> - <%end%> + <%end%> <% end %> @@ -173,7 +159,7 @@ <% else %>