Currently I’m trying to print two copies of the same receipt without using the browser-print dialogue. Now unfortunately there is no way to pass the number of copies to the print dialog so the only solution I came up with is doing it in a LOOP, but when looping the print command it does not work! while looping the whole POST method works just fine.
Here’s the code before I enter the loop
print function
function p_print(receipt) {
$('#receipt_section').html(receipt.html_content);
__currency_convert_recursively($('#receipt_section'));
__print_receipt('receipt_section');
}
Code without Loop
$.ajax({
method: 'POST',
url: url,
data: data,
dataType: 'json',
success: function(result) {
if (result.success == 1) {
if (result.mail_enabled) {
window.open(result.mail_enabled);
}
$('#modal_payment').modal('hide');
toastr.success(result.msg);
//Check if enabled or not
if (result.receipt.is_enabled) {
p_print(result.receipt);
}
} else {
toastr.error(result.msg);
}
},
});
Functioning loop that prints twice but also POSTS the data twice
var Count = 0;
var Copies = 2;
while ( Count < Copies ) {
$.ajax({
method: 'POST',
url: url,
data: data,
dataType: 'json',
success: function(result) {
if (result.success == 1) {
if (result.mail_enabled) {
window.open(result.mail_enabled);
}
$('#modal_pay').modal('hide');
toastr.success(result.msg);
if (result.receipt.is_enabled) {
p_print(result.receipt);
}
} else {
toastr.error(result.msg);
}
},
});
Count ++;
};
Now If I apply the loop only on p_print(result.receipt)
it wont print twice, only by applying it to the whole POST request it would then print twice but also stores the data twice which is not a proper solution at all.
Any help would be very appreciated.