85 lines
3.3 KiB
JavaScript
85 lines
3.3 KiB
JavaScript
import { PublicQrCodepost } from "../../Features/ConfigMasterPage/ConfigMasterPage";
|
|
import { blobToBase64, pdfDiv } from "../../Services/Others";
|
|
import { PrintStyleFunction } from "../paymentpdfPage/PrintStyleFunction";
|
|
const CommonApiurl = import.meta.env.ENV_API_URL_COMMON;
|
|
export const PurchaseQtMobilePrint = async ({
|
|
PrintTempData,
|
|
printerTemplateStyle = 'Style 13',
|
|
PrintOrderDetails = [],
|
|
setPrintOrderDetails = () => { },UserId, dispatch
|
|
}) => {
|
|
try {
|
|
// 1. Get style config for "Quotation"
|
|
const style = await PrintStyleFunction(PrintTempData?.StyleName == undefined ? 'Style 13' : PrintTempData?.StyleName,
|
|
'Quotation');
|
|
|
|
const stylesMap = {
|
|
'Style 1': 'SQPrintStyle1',
|
|
'Style 2': 'SQPrintStyle2',
|
|
'Style 3': 'SQPrintStyle3',
|
|
'Style 4': 'SQPrintStyle4',
|
|
'Style 5': 'SQPrintStyle5',
|
|
'Style 6': 'SQPrintStyle6',
|
|
'Style 7': 'SQPrintStyle7',
|
|
'Style 8': 'SQPrintStyle8',
|
|
'Style 9': 'SQPrintStyle9',
|
|
'Style 10': 'SQPrintStyle10',
|
|
'Style 11': 'SQPrintStyle11',
|
|
'Style 12': 'SQPrintStyle12',
|
|
'Style 13': 'Pur-Quot-Print',
|
|
A4: 'SQPrintStyleA4',
|
|
A5: 'SQPrintStyleA5',
|
|
A4Standard: 'SQA4Standard',
|
|
TaxInvoice: 'TaxInvoice',
|
|
};
|
|
const selectedStyle = stylesMap[PrintTempData?.StyleName] || 'Pur-Quot-Print';
|
|
const Printsize = PrintTempData?.PageSize || 'A4';
|
|
console.log("PurchaseQtMobilePrint:", printerTemplateStyle, PrintOrderDetails);
|
|
|
|
let container = document.getElementById('print-merged');
|
|
if (!container) {
|
|
container = document.createElement('div');
|
|
container.id = 'print-merged';
|
|
container.style.display = 'none';
|
|
document.body.appendChild(container);
|
|
} else {
|
|
container.innerHTML = '';
|
|
}
|
|
const element = document.getElementById(`${selectedStyle}`);
|
|
if (element) {
|
|
const cloned = element.cloneNode(true);
|
|
container.appendChild(cloned);
|
|
}
|
|
const pdfBlob = await pdfDiv('print-merged', style);
|
|
const base64Pdf = await blobToBase64(pdfBlob);
|
|
|
|
// const pdfUrl = URL.createObjectURL(pdfBlob);
|
|
// window.open(pdfUrl, "_blank");
|
|
const postData = { Url: base64Pdf, CreatedBy: UserId };
|
|
let printurl
|
|
const res = await dispatch(PublicQrCodepost(postData)).unwrap();
|
|
|
|
if (res?.data?.statusCode == 1) {
|
|
printurl = res?.data?.ReferenceNo
|
|
}
|
|
const intentUrl =
|
|
'intent://open?' +
|
|
'filename=' + encodeURIComponent('Receipt.pdf') +
|
|
'&size=' + pdfBlob.size +
|
|
'ApiClientS' +
|
|
CommonApiurl +
|
|
'ApiClientE' +
|
|
'&type=application/pdf' +
|
|
'&data=' + encodeURIComponent(printurl) +
|
|
'PrintSizeS' + encodeURIComponent(Printsize) +
|
|
'PrintSizeE' +
|
|
'#Intent;scheme=pozoprinter;package=com.example.pozoprinter;end';
|
|
|
|
window.location.href = intentUrl;
|
|
setPrintOrderDetails([]);
|
|
|
|
} catch (error) {
|
|
console.error('PurchaseQtMobilePrint error:', error);
|
|
}
|
|
};
|