diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 970095e9..c446af72 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -95,7 +95,6 @@ class Origami::PaymentsController < BaseOrigamiController sale_payment = SalePayment.new sale_payment.process_payment(saleObj, current_user.name, cash, "cash") - render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error "}) rebate_amount = nil # For Cashier by Zone @@ -151,7 +150,9 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data) + filename, sale_receipt_no, print_copies, printer_name = printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data) + + render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :count => print_copies, :printer_name => printer_name}) if params[:type] == "quick_service" booking = Booking.find_by_sale_id(sale_id) @@ -438,6 +439,23 @@ class Origami::PaymentsController < BaseOrigamiController end end + #print function for receipt + def print + # byebug + filename = params[:filename] + receipt_no = parmas[:receipt_no] + print_copies = params[:print_copies] + printer_name = params[:printer_name] + + puts "print params" + puts params + + print_receipt_pdf(filename,receipt_no,print_copies,printer_name) + + redirect_to origami_path + # render json: JSON.generate({:status => true}) + end + #Shop Name in Navbor helper_method :shop_detail def shop_detail diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 0cf6526f..dac1778f 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -197,17 +197,28 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker print_settings.print_copies = 1 print_settings.save! + directory_name = 'public/receipts' + Dir.mkdir(directory_name) unless File.exists?(directory_name) + begin if count == 1 - pdf.render_file "tmp/receipt_bill_#{sale_data.receipt_no}.pdf" - self.print("tmp/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name) + filename = "/receipts/receipt_bill_#{sale_data.receipt_no}.pdf" + pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf" + if printed_status != 'Paid' + self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name) + end else - pdf.render_file "tmp/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" - self.print("tmp/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name) + filename = "/receipts/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" + pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" + if printed_status != 'Paid' + self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name) + end end count -= 1 end until count == 0 + + return filename, sale_data.receipt_no, count, cashier_terminal.printer_name end # stock check @@ -247,4 +258,18 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker self.print("tmp/print_call_waiter.pdf") end + #print receipt pdf from js + def print_receipt_pdf(filename,receipt_no,print_copies,printer_name) + begin + if print_copies == 1 + self.print("public"+filename, cashier_terminal.printer_name) + else + filename = "public/receipts/receipt_bill_#{receipt_no}_#{print_copies}.pdf" + self.print(filename, cashier_terminal.printer_name) + end + + print_copies -= 1 + end until print_copies == 0 + end + end diff --git a/app/models/sale.rb b/app/models/sale.rb index 54c60eb3..8252d343 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -548,11 +548,26 @@ class Sale < ApplicationRecord #Generate new Receipt No when it is not assigned def generate_receipt_no + #shop_code and client_code + shop_details = Shop::ShopDetail + #Date-Shift- if self.receipt_no.nil? prefix = DateTime.now().utc #self.receipt_no = prefix.to_s + "/" + self.shit_id.to_s + "/" + SeedGenerator.new_receipt_no().to_s - self.receipt_no = prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s + if !shop_details.nil? + if !shop_details.client_code.nil? && shop_details.shop_code.nil? + self.receipt_no = shop_details.client_code + "-" + prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s + elsif shop_details.client_code.nil? && !shop_details.shop_code.nil? + self.receipt_no = shop_details.shop_code + "-" + prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s + elsif !shop_details.client_code.nil? && !shop_details.shop_code.nil? + self.receipt_no = shop_details.client_code + "-" + shop_details.shop_code + "-" + prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s + else + self.receipt_no = prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s + end + else + self.receipt_no = prefix.strftime("%Y%m%d") + "-" + SeedGenerator.new_receipt_no().to_s + end self.receipt_date = prefix Rails.logger.debug "Receipt No #{self.receipt_no} | Date #{ self.receipt_date.to_s}" diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index b3302485..11ad8100 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -110,19 +110,20 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left end - if sale_data.bookings[0].dining_facility_id.to_i > 0 - bounding_box([self.item_description_width, y_position], :width => self.item_description_width, :height => self.item_height) do - text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right - end - end move_down 10 y_position = cursor - bounding_box([0, y_position], :width =>self.item_description_width, :height => self.item_height) do + if sale_data.bookings[0].dining_facility_id.to_i > 0 + bounding_box([0, y_position], :width => self.item_description_width, :height => self.item_height) do + text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_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 "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left end - bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do + 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 move_down 10 diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 0ae57fea..c34ce3e4 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -107,19 +107,20 @@ class ReceiptBillPdf < Prawn::Document move_down 7 # move_down 2 y_position = cursor - bounding_box([0,y_position], :width =>self.description_width, :height => self.item_height) do + bounding_box([0,y_position], :width =>self.description_width + self.price_num_width, :height => self.item_height) do text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left end - if sale_data.bookings[0].dining_facility_id.to_i > 0 - bounding_box([self.description_width - 2,y_position], :width => self.price_num_width, :height => self.item_height) do - text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right - end - end - + move_down 5 y_position = cursor - bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do + if sale_data.bookings[0].dining_facility_id.to_i > 0 + bounding_box([0,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :left + end + end + + bounding_box([self.label_width, y_position], :width =>self.label_width, :height => self.item_height) do text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index bd682b96..981ddb06 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -196,7 +196,7 @@
<% if (!@sale_array.empty?) && (!@date.nil?) %> -
+
  Receipt No: <% if @status_sale == 'sale' %> <%= @sale_array[0].receipt_no rescue '' %> @@ -204,7 +204,7 @@
-
+
Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y-%I:%M %p") rescue '-' %>
diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index cb213a38..44b50bf6 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -1,4 +1,4 @@ -
+
@@ -384,7 +384,43 @@
-
+
+ + + + \ No newline at end of file diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 4cd6a846..7291581c 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -193,12 +193,15 @@
<% if @status_sale == 'sale' %> -
+
  Receipt No: <%= @obj_sale.receipt_no rescue '' %>
+
+ Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%> +
<% else %>
  Order No: @@ -206,17 +209,10 @@ <%= @obj_order.order_id rescue '' %>
- <% end %> - <% if @status_sale == 'sale' %> -
- Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%> -
- <% else %> -
+
Date: <%= @date.utc.getlocal.strftime("%d/%m/%Y") rescue '-'%>
<% end %> -
diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index 8f310dab..02e35bb8 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -20,11 +20,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/routes.rb b/config/routes.rb index 340dc914..2254bb2f 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -177,6 +177,8 @@ scope "(:locale)", locale: /en|mm/ do post 'payment/credit' => 'credit_payments#create' post 'payment/voucher' => 'voucher_payments#create' + post 'payment/print' => 'payments#print' + get 'sale/:sale_id/:type/payment/credit_payment' => "credit_payments#index" get 'sale/:sale_id/:type/payment/others_payment' => "others_payments#index" get 'sale/:sale_id/:type/payment/others_payment/MPU' => "mpu#index" diff --git a/db/migrate/20170530072247_create_shops.rb b/db/migrate/20170530072247_create_shops.rb index bd25c970..1c87b505 100755 --- a/db/migrate/20170530072247_create_shops.rb +++ b/db/migrate/20170530072247_create_shops.rb @@ -3,6 +3,9 @@ class CreateShops < ActiveRecord::Migration[5.1] create_table :shops do |t| t.string :logo t.string :name, :null => false + t.string :shop_code, :null => false + t.string :client_name, :null => false + t.string :client_code, :null => false t.string :address, :null => false t.string :township, :null => false t.string :city, :null => false diff --git a/db/migrate/20170628103624_create_print_settings.rb b/db/migrate/20170628103624_create_print_settings.rb index 329d3a7c..672953fc 100755 --- a/db/migrate/20170628103624_create_print_settings.rb +++ b/db/migrate/20170628103624_create_print_settings.rb @@ -6,7 +6,9 @@ class CreatePrintSettings < ActiveRecord::Migration[5.1] t.string :template t.string :font, :default => "" t.string :printer_name, :null => false - t.string :api_settings + t.string :api_settings, + t.string :brand_name + t.string :type t.decimal :page_width, :null => false, :default => 210 t.decimal :page_height, :null => false, :default => 1450 t.integer :print_copies, :null => false, :default => 1 diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-271.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-271.pdf new file mode 100644 index 00000000..e6522c39 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-271.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-272.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-272.pdf new file mode 100644 index 00000000..a28fd1c2 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-272.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-273.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-273.pdf new file mode 100644 index 00000000..8a399a2b Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-273.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-274.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-274.pdf new file mode 100644 index 00000000..acbd2b0e Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-274.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-275.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-275.pdf new file mode 100644 index 00000000..4cba74f8 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-275.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-276.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-276.pdf new file mode 100644 index 00000000..fe8237d8 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-276.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-277.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-277.pdf new file mode 100644 index 00000000..c8f52162 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-277.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-278.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-278.pdf new file mode 100644 index 00000000..9912eb67 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-278.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-279.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-279.pdf new file mode 100644 index 00000000..bb24abd2 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-279.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-280.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-280.pdf new file mode 100644 index 00000000..7f031a92 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-280.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-281.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-281.pdf new file mode 100644 index 00000000..6c563973 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-281.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-282.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-282.pdf new file mode 100644 index 00000000..c720a73c Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-282.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-283.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-283.pdf new file mode 100644 index 00000000..ec721a02 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-283.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-284.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-284.pdf new file mode 100644 index 00000000..641da314 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-284.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-285.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-285.pdf new file mode 100644 index 00000000..c62d3e90 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-285.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-286.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-286.pdf new file mode 100644 index 00000000..931d3c38 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-286.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-287.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-287.pdf new file mode 100644 index 00000000..fcd786fd Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-287.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-288.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-288.pdf new file mode 100644 index 00000000..d26390ac Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-288.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-289.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-289.pdf new file mode 100644 index 00000000..de3f773a Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-289.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-290.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-290.pdf new file mode 100644 index 00000000..4d436a85 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-290.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-291.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-291.pdf new file mode 100644 index 00000000..9395d104 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-291.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-292.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-292.pdf new file mode 100644 index 00000000..68200458 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-292.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-293.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-293.pdf new file mode 100644 index 00000000..adad2fa7 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-293.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-294.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-294.pdf new file mode 100644 index 00000000..f1ed65be Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-294.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-295.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-295.pdf new file mode 100644 index 00000000..a9c349a8 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-295.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-296.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-296.pdf new file mode 100644 index 00000000..3278789d Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-296.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-297.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-297.pdf new file mode 100644 index 00000000..1e30ab84 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-297.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-298.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-298.pdf new file mode 100644 index 00000000..df122cb2 Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-298.pdf differ diff --git a/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-299.pdf b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-299.pdf new file mode 100644 index 00000000..5af5c4bd Binary files /dev/null and b/public/receipts/receipt_bill_OSK-OSK(TMW)-20180307-299.pdf differ