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

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