From 41657db355cb8303defbac43b7cb53daaf23b366 Mon Sep 17 00:00:00 2001 From: phyusin Date: Thu, 29 Nov 2018 18:08:11 +0630 Subject: [PATCH] order receipt bill pdf --- README.md | 1 + app/assets/javascripts/order_reservation.js | 33 ++++++++++++++++++- .../origami/payments_controller.rb | 23 ++++++++----- app/models/order_reservation.rb | 1 + app/models/printer/receipt_printer.rb | 21 +++++++----- .../origami/order_reservation/index.html.erb | 4 +-- 6 files changed, 63 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6eee9e4e..86040838 100755 --- a/README.md +++ b/README.md @@ -271,6 +271,7 @@ For Food Court Settings On/Off For Online Order Receip Setting 1) settings/lookups => { type:order_reservation, name:ReceiptBill, value: {0 or 1} } +2) settings/print_settings => {name: ReceiptBillOrder, unique_code: ReceiptBillOrderPdf, ....} * ToDo list diff --git a/app/assets/javascripts/order_reservation.js b/app/assets/javascripts/order_reservation.js index a5bdb968..07fdcc69 100644 --- a/app/assets/javascripts/order_reservation.js +++ b/app/assets/javascripts/order_reservation.js @@ -517,12 +517,17 @@ function callback_url(callback,ref_no,order_id,status,min_type,time,exptime,reas window.location.href = '/origami/order_reservation'; }); }else{ + //PDF lightbox data var pdfPath = "/en/pdfjs/minimal?file=" + result.filename.substring(6); + $("#sale_id").val(result.sale_id); $("#sale_receipt_no").val(result.receipt_no); $("#filename").val(result.filename); $("#printer_name").val(result.printer_name); $("#receipt_pdf").attr("src", pdfPath); + + $("#receciptpdfModal").modal({show : true, backdrop : false, keyboard : false}); + $("#receiptpdfModalLabel").text("Receipt: " + result.receipt_no); } }else{ swal({ @@ -683,8 +688,34 @@ function getOnlineOrderCount(){ } /* online order count*/ +//print pdf function +$("#print_receipt_pdf").on('click touchstart', function(event){ + $(this).off("click touchstart touchend"); + print_receipt(); +}); + /* pdf print out */ function print_receipt(){ - + var sale_id = $('#sale_id').text(); + var filename = $("#filename").val(); + var printer_name = $("#printer_name").val(); + var receipt_no = $("#sale_receipt_no").val(); + var params = { 'filename':filename, 'receipt_no':receipt_no, 'printer_name':printer_name }; + $.ajax({ + type: "POST", + url: "/origami/sale/"+sale_id+"/doemal_order/payment/print", + data: params, + success:function(result){ + // For Server Print - from jade + if ($("#server_mode").val() == "cloud") { + if(typeof code2lab != 'undefined'){ + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } + } + else{ + payment_success_alert(); + } + } + }); } /* pdf print out */ \ No newline at end of file diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index bade57a0..f76b9441 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -679,16 +679,21 @@ class Origami::PaymentsController < BaseOrigamiController filename = params[:filename] receipt_no = params[:receipt_no] printer_name = params[:printer_name] + cashier_type = params[:type] - receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf - unique_code = "ReceiptBillPdf" - if !receipt_bill_a5_pdf.empty? - receipt_bill_a5_pdf.each do |receipt_bilA5| - if receipt_bilA5[0] == 'ReceiptBillA5Pdf' - if receipt_bilA5[1] == '1' - unique_code = "ReceiptBillA5Pdf" - else - unique_code = "ReceiptBillPdf" + if cashier_type == "doemal_order" + unique_code = "ReceiptBillOrderPdf" + else + receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + unique_code = "ReceiptBillPdf" + if !receipt_bill_a5_pdf.empty? + receipt_bill_a5_pdf.each do |receipt_bilA5| + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[1] == '1' + unique_code = "ReceiptBillA5Pdf" + else + unique_code = "ReceiptBillPdf" + end end end end diff --git a/app/models/order_reservation.rb b/app/models/order_reservation.rb index e799547d..ef80ddbb 100644 --- a/app/models/order_reservation.rb +++ b/app/models/order_reservation.rb @@ -191,6 +191,7 @@ class OrderReservation < ApplicationRecord result = {:status=> true, :filepath => filename, + :sale_id => saleObj.sale_id, :receipt_no => sale_receipt_no, :printer_model => print_settings.brand_name, :printer_url => print_settings.api_settings , diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 8b7f5d56..35b1c9fb 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -193,17 +193,22 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Generate PDF #Print pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) - receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf - if !receipt_bill_a5_pdf.empty? - receipt_bill_a5_pdf.each do |receipt_bilA5| - if receipt_bilA5[0] == 'ReceiptBillA5Pdf' - if receipt_bilA5[1] == '1' - pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) - else - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + if printer_settings.name.strip.downcase != "receiptbillorder" + receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf + if !receipt_bill_a5_pdf.empty? + receipt_bill_a5_pdf.each do |receipt_bilA5| + if receipt_bilA5[0] == 'ReceiptBillA5Pdf' + if receipt_bilA5[1] == '1' + pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + else + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) + end end end end + else + #doemal online order pdf template + pdf = ReceiptBillOrderPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,other_amount,latest_order_no,card_balance_amount) end # print as print copies in printer setting count = printer_settings.print_copies diff --git a/app/views/origami/order_reservation/index.html.erb b/app/views/origami/order_reservation/index.html.erb index d6d50307..c736f7a9 100644 --- a/app/views/origami/order_reservation/index.html.erb +++ b/app/views/origami/order_reservation/index.html.erb @@ -659,10 +659,10 @@