receipt no and print pdf

This commit is contained in:
phyusin
2018-03-07 15:36:05 +06:30
parent d8256a93f6
commit aedd79376f
41 changed files with 252 additions and 85 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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}"

View File

@@ -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

View File

@@ -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

View File

@@ -196,7 +196,7 @@
<div class="card-title">
<div class="row p-l-5 p-r-5">
<% if (!@sale_array.empty?) && (!@date.nil?) %>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="col-lg-8 col-md-8 col-sm-8">
&nbsp; Receipt No: <span id="receipt_no">
<% if @status_sale == 'sale' %>
<%= @sale_array[0].receipt_no rescue '' %>
@@ -204,7 +204,7 @@
</span>
<br>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 text-right">
<div class="col-lg-4 col-md-4 col-sm-4 text-right">
Date: <span id="receipt_date"><%= @date.utc.getlocal.strftime("%d/%m/%Y-%I:%M %p") rescue '-' %></span>
<br>
</div>

View File

@@ -1,4 +1,4 @@
<div class="container-fluid">
<div class="container-fluid" data-no-turbolink="true">
<div id="loading_wrapper" style="display:none;">
<div id="loading"></div>
</div>
@@ -384,7 +384,43 @@
</div>
</div>
</div>
</div>
</div>
<!-- pdf light box -->
<div class="modal fade" id="pdfModal" tabindex="-1" role="dialog" data-turbolinks-partial="pdfModal" >
<div class="modal-dialog modal-md" role="document">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title" id="pdfModalLabel"></h4>
</div>
<div class="modal-body">
<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">Print</button>
</div>
<% end %>
<div class="col-md-5">
<button type="button" class="btn btn-link bg-blue waves-effect btn_pdf_close" data-dismiss="modal">CLOSE</button>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var cashier_type = "<%= @cashier_type %>";
$(document).ready(function(){
@@ -402,7 +438,6 @@ var cashier_type = "<%= @cashier_type %>";
console.log("ssssssssssss")
payment_type = checkReceiptNoInFirstBillData(receipt_no,"payment")
if (member_id && member_discount) {
console.log("fffffffffffff")
if(parseInt(jQuery.inArray("Credit", payment_type)) == -1){
$("#credit_payment").hide();
} else{
@@ -529,6 +564,9 @@ console.log("fffffffffffff")
$('#cash').text(input_value);
update_balance();
}else{
if($('#cash').text() == '0'){
$('#cash').text("");
}
$('#cash').append(input_value);
update_balance();
}
@@ -638,7 +676,6 @@ console.log("fffffffffffff")
$.ajax({type: "POST",
url: "<%= origami_payment_cash_path %>",
data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type,
async: false,
success:function(result){
/* start delete receipt no in first bill*/
if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){
@@ -654,45 +691,65 @@ console.log("fffffffffffff")
else{
var msg = '';
}
$( "#loading_wrapper" ).hide();
$("#loading_wrapper" ).hide();
//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});
$("#pdfModalLabel").text("Payment Successful!");
$("#changed_amount").text("");
if($('#balance').text() < 0){
swal({
title: "Payment Successful!",
text: 'Changed amount ' + $('#balance').text() * (-1),
html: true,
closeOnConfirm: false,
closeOnCancel: false,
allowOutsideClick: false
}, function () {
if (cashier_type=="cashier") {
window.location.href = '/origami';
}else{
window.location.href = '/origami/quick_service';
}
});
}else{
$('#pay').text("Pay");
swal({
title: "Payment Successful!",
text: 'Thank You !',
html: true,
closeOnConfirm: false,
closeOnCancel: false,
allowOutsideClick: false
}, function () {
if (cashier_type=="cashier") {
window.location.href = '/origami';
}else{
window.location.href = '/origami/quick_service';
}
});
<% if precision.to_i > 0 %>
$("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)).toFixed(<%= precision %>));
<% else %>
$("#changed_amount").text('Changed amount ' + parseFloat($('#balance').text() * (-1)));
<% end %>
}
//PDF lightbox data
// if($('#balance').text() < 0){
// swal({
// title: "Payment Successful!",
// text: 'Changed amount ' + $('#balance').text() * (-1),
// html: true,
// closeOnConfirm: false,
// closeOnCancel: false,
// allowOutsideClick: false
// }, function () {
// // if (cashier_type=="cashier") {
// // window.location.href = '/origami';
// // }else{
// // window.location.href = '/origami/quick_service';
// // }
// });
// }else{
// $('#pay').text("Pay");
// swal({
// title: "Payment Successful!",
// text: 'Thank You !',
// html: true,
// closeOnConfirm: false,
// closeOnCancel: false,
// allowOutsideClick: false
// }, function () {
// // if (cashier_type=="cashier") {
// // window.location.href = '/origami';
// // }else{
// // window.location.href = '/origami/quick_service';
// // }
// });
// }
}
});
}
}
});
// $('#void').on('click',function () {
// if ($(this).attr('active') === "true") {
// var sale_id = $('#sale_id').text();
@@ -809,7 +866,7 @@ console.log("fffffffffffff")
}else{
swal("Oops","You are not authorized for foc","warning")
}
});
});
function calculate_member_discount(sale_id) {
var sub_total = $('#sub-total').text();
@@ -823,14 +880,61 @@ console.log("fffffffffffff")
}else{
is_card = true
}
$.ajax({
type: "POST",
url: "/origami/" + sale_id + "/member_discount",
data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card },
async: false,
success:function(result){
}
});
$.ajax({
type: "POST",
url: "/origami/" + sale_id + "/member_discount",
data: {'sale_id':sale_id, 'sub_total':sub_total,'is_card':is_card },
async: false,
success:function(result){
}
});
}
}
}
//print pdf function
$(document).on('ready page:load',function(){
$(document).on('click', "button#print_pdf",function(){
// $('#print_pdf').click(function(){
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 };
// swal({
// title: "Alert",
// text: "Are you sure want to print?",
// type: "warning",
// showCancelButton: true,
// confirmButtonColor: "#DD6B55",
// confirmButtonText: "Print",
// closeOnConfirm: false
// }, function (isConfirm) {
// if (isConfirm) {
$.ajax({
type: "POST",
url: "<%= origami_payment_print_path %>",
data: params,
success:function(result){
console.log(result);
// if (cashier_type=="cashier") {
// window.location.href = '/origami';
// }else{
// window.location.href = '/origami/quick_service';
// }
}
});
// }
// });
});
});
$(".btn_pdf_close").on('click',function(){
if (cashier_type=="cashier") {
window.location.href = '/origami';
}else{
window.location.href = '/origami/quick_service';
}
});
</script>

View File

@@ -193,12 +193,15 @@
<div class="card-title row p-l-5 p-r-5">
<% if @status_sale == 'sale' %>
<div class="col-lg-6 col-md-6 col-sm-6">
<div class="col-lg-8 col-md-8 col-sm-8">
&nbsp; Receipt No:
<span id="receipt_no">
<%= @obj_sale.receipt_no rescue '' %>
</span>
</div>
<div class="col-lg-4 col-md-4 col-sm-4 text-right">
Date: <span id="receipt_date"><%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span>
</div>
<% else %>
<div class="col-lg-7 col-md-7 col-sm-7">
&nbsp; Order No:
@@ -206,17 +209,10 @@
<%= @obj_order.order_id rescue '' %>
</span>
</div>
<% end %>
<% if @status_sale == 'sale' %>
<div class="col-lg-6 col-md-6 col-sm-6 text-right">
Date: <span id="receipt_date"><%= @date.utc.getlocal.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%></span>
</div>
<% else %>
<div class="col-lg-5 col-md-5 col-sm-5 text-right">
<div class="col-lg-5 col-md-5 col-sm-5 text-right">
Date: <span id="receipt_date"><%= @date.utc.getlocal.strftime("%d/%m/%Y") rescue '-'%></span>
</div>
<% end %>
</div>
<div class="card-title row customer_detail p-l-5 p-r-5" >
<div class="col-lg-6 col-md-6 col-sm-6">

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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