Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 10 additions & 53 deletions urypos/src/stores/invoiceData.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,61 +387,18 @@ export const useInvoiceDataStore = defineStore("invoiceData", {
};
}
} else {
// Socket printing using iframe technique
// Socket printing using printview redirection
const url = `/printview?doctype=POS Invoice&name=${invoiceNo}&format=${this.print_format}&no_letterhead=1&settings={}&letterhead=No Letterhead&trigger_print=1&_lang=en`;
window.open(url, "_blank", "noopener,noreferrer");
try {
const printHTML = {
doc: "POS Invoice",
name: invoiceNo,
print_format: this.print_format,
_lang: "en",
};
const result = await this.call.get(
"frappe.www.printview.get_html_and_style",
printHTML
);

if (!result?.message?.html) {
this.isPrinting = false;
this.alert.createAlert(
"Message",
"Error while getting the HTML document to print",
"OK"
);
return;
}

// Create iframe for printing
const iframe = document.createElement('iframe');
iframe.id = 'print_content';
document.body.appendChild(iframe);

// Write HTML to iframe and print
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(result.message.html);
iframe.contentWindow.document.close();

// Trigger print dialog
iframe.contentWindow.print();

// Clean up: remove iframe after a short delay to allow print dialog to open
setTimeout(() => {
if (iframe.parentNode) {
iframe.parentNode.removeChild(iframe);
}
}, 100);

this.notification.createNotification("Print Successful");
this.isPrinting = false;
window.location.reload();
} catch (error) {
console.error(error);
this.isPrinting = false;
if (error._server_messages) {
const messages = JSON.parse(error._server_messages);
const message = JSON.parse(messages[0]);
this.alert.createAlert("Message", message.message, "OK");
}
await this.call.post("ury.ury.api.ury_print.qz_print_update", {
invoice: invoiceNo,
});
} catch (err) {
console.error("Failed to update print status for socket print", err);
}
this.notification.createNotification("Print triggered");
this.isPrinting = false;
}
} catch (e) {
if (e?.custom) {
Expand Down
Loading