cadd print pdf in payment page

This commit is contained in:
phyusin
2018-03-08 10:01:54 +06:30
parent 5d8ba3c416
commit d9a7e341fa
5 changed files with 125 additions and 44 deletions

View File

@@ -28,8 +28,21 @@ class Origami::PaymentsController < BaseOrigamiController
end
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf
# Print for First Bill to Customer
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
#shop detail
shop_details = Shop::ShopDetail
# customer= Customer.where('customer_id=' +.customer_id)
@@ -117,7 +130,20 @@ class Origami::PaymentsController < BaseOrigamiController
# For Print
if ENV["SERVER_MODE"] != "cloud" #no print in cloud server
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
customer= Customer.find(saleObj.customer_id)
# get member information
@@ -150,9 +176,9 @@ class Origami::PaymentsController < BaseOrigamiController
discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items)
printer = Printer::ReceiptPrinter.new(print_settings)
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)
filename, sale_receipt_no, 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})
render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name})
if params[:type] == "quick_service"
booking = Booking.find_by_sale_id(sale_id)
@@ -440,20 +466,30 @@ class Origami::PaymentsController < BaseOrigamiController
end
#print function for receipt
def print
# byebug
def print
filename = params[:filename]
receipt_no = parmas[:receipt_no]
print_copies = params[:print_copies]
receipt_no = params[:receipt_no]
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})
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
# get printer info
print_settings=PrintSetting.find_by_unique_code(unique_code)
printer = Printer::ReceiptPrinter.new(print_settings)
printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name)
render :json => {status: true}
end
#Shop Name in Navbor

View File

@@ -65,7 +65,8 @@ class Ability
can :create, :payment
can :reprint, :payment
can :rounding_adj, :payment
can :foc, :payment
can :foc, :payment
can :print, :payment
can :move_dining, :movetable
can :moving, :movetable
@@ -122,6 +123,7 @@ class Ability
can :create, :payment
can :reprint, :payment
can :rounding_adj, :payment
can :print, :payment
can :move_dining, :movetable
can :moving, :movetable
@@ -180,6 +182,7 @@ class Ability
can :show, :payment
can :reprint, :payment
can :rounding_adj, :payment
can :print, :payment
can :manage, Commission
can :manage, Commissioner

View File

@@ -218,7 +218,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
count -= 1
end until count == 0
return filename, sale_data.receipt_no, count, cashier_terminal.printer_name
return filename, sale_data.receipt_no, cashier_terminal.printer_name
end
# stock check
@@ -260,16 +260,21 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker
#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
count = print_copies.to_i
# if count == 0
# self.print("public"+filename, printer_name)
# else
begin
if count == 1
self.print("public"+filename, printer_name)
else
filename = "public/receipts/receipt_bill_#{receipt_no}_#{count}.pdf"
self.print(filename, printer_name)
end
print_copies -= 1
end until print_copies == 0
count -= 1
end until count == 0
# end
end
end

View File

@@ -1,4 +1,4 @@
<div class="container-fluid" data-no-turbolink="true">
<div class="container-fluid">
<div id="loading_wrapper" style="display:none;">
<div id="loading"></div>
</div>
@@ -387,7 +387,7 @@
</div>
<!-- pdf light box -->
<div class="modal fade" id="pdfModal" tabindex="-1" role="dialog" data-turbolinks-partial="pdfModal" >
<div class="modal fade" id="pdfModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
@@ -397,18 +397,16 @@
<input type="hidden" name="sale_receipt_no" id="sale_receipt_no">
<input type="hidden" name="filename" id="filename">
<input type="hidden" name="printer_name" id="printer_name">
<input type="hidden" name="print_copies" id="print_copies">
<p id="changed_amount"></p>
<div class="text-center">
<iframe id="receipt_pdf" src="" style="width: 400px; height: 600px;"></iframe>
<!-- <object id="receipt_pdf" data="" type="application/pdf" width="400" height="600"></object> -->
</div>
</div>
<div class="modal-footer ">
<div class="row p-r-20">
<% if ENV["SERVER_MODE"] != 'cloud' %>
<div class="col-md-5">
<button type="button" class="btn btn-link bg-red waves-effect" id="print_pdf" data-turbolinks="false" remote="true">Print</button>
<button type="button" class="btn btn-link bg-red waves-effect print_receipt">Print</button>
</div>
<% end %>
<div class="col-md-5">
@@ -419,11 +417,53 @@
</div>
</div>
</div>
</div>
</div>
<!-- customer light box -->
<div class="modal fade" id="is_memberModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="is_memberModalLabel">Is Member?</h4>
</div>
<div class="modal-body">
</div>
<div class="modal-footer ">
<div class="row p-r-20">
<div class="col-md-4">
<button type="button" class="btn btn-link bg-green waves-effect">Yes</button>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-link bg-red waves-effect" data-dismiss="modal">No</button>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-link bg-primary waves-effect">Member</button>
</div>
<div class="col-md-4">
<button type="button" class="btn btn-link bg-primary waves-effect">QR</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var cashier_type = "<%= @cashier_type %>";
var customer_id = "<%= @customer.id %>";
var customer_name = "<%= @customer.name %>";
$(document).ready(function(){
console.log(customer_name);
console.log(customer_id);
// if((customer_id == 'CUS-000000000001') && (customer_name == 'WALK-IN')){
// $("#is_memberModal").modal({show : true, backdrop: false, keyboard : false});
// }
/* start check first bill or not*/
var member_id = $('#membership_id').text();
var member_discount = $('#member_discount').text();
@@ -552,7 +592,6 @@ var cashier_type = "<%= @cashier_type %>";
//PDF lightbox data
$("#sale_receipt_no").val(result.receipt_no);
$("#filename").val(result.filename);
$("#print_copies").val(result.count);
$("#printer_name").val(result.printer_name);
$("#receipt_pdf").attr("src", result.filename);
$("#pdfModal").modal({show : true, backdrop : false, keyboard : false});
@@ -566,7 +605,6 @@ var cashier_type = "<%= @cashier_type %>";
<% end %>
}
//PDF lightbox data
// if($('#balance').text() < 0){
// swal({
// title: "Payment Successful!",
@@ -888,14 +926,14 @@ var cashier_type = "<%= @cashier_type %>";
}
}
$('#print_pdf').off('click');
//print pdf function
$("#print_pdf").on('click',function(){
$(".print_receipt").on('click',function(){
var sale_id = $('#sale_id').text();
var filename = $("#filename").val();
var printer_name = $("#printer_name").val();
var receipt_no = $("#sale_receipt_no").val();
var print_copies = $("#print_copies").val();
var params = { turbolinks: false, remote : true, 'filename':filename, 'receipt_no':receipt_no, 'print_copies':print_copies, 'printer_name':printer_name };
var params = { 'filename':filename, 'receipt_no':receipt_no, 'printer_name':printer_name };
// swal({
// title: "Alert",
// text: "Are you sure want to print?",
@@ -908,15 +946,15 @@ var cashier_type = "<%= @cashier_type %>";
// if (isConfirm) {
$.ajax({
type: "POST",
url: "<%= origami_payment_print_path %>",
url: "/origami/sale/"+sale_id+"/"+cashier_type+"/payment/print",
data: params,
success:function(result){
console.log(result);
// if (cashier_type=="cashier") {
// window.location.href = '/origami';
// }else{
// window.location.href = '/origami/quick_service';
// }
if (cashier_type=="cashier") {
window.location.href = '/origami';
}else{
window.location.href = '/origami/quick_service';
}
}
});
// }

View File

@@ -165,6 +165,7 @@ scope "(:locale)", locale: /en|mm/ do
post 'sale/:sale_id/rounding_adj' => 'payments#rounding_adj', :as => "calculate_rouding_adjs"
get 'sale/:sale_id/first_bill' => 'payments#first_bill', :defaults => {:format => 'json'}
get 'sale/:sale_id/:type/payment' => 'payments#show'
post 'sale/:sale_id/:type/payment/print' => 'payments#print' #route for print receipt
post 'payment/foc' => 'payments#foc', :defaults => {:format => 'json'}
post 'payment/cash' => 'payments#create'
@@ -177,8 +178,6 @@ 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"