UNPKG

cordova-plugin-netcontroll-integration

Version:
353 lines (320 loc) 14.6 kB
var exec = require('cordova/exec'); //Printer Functions exports.AbreConexaoImpressora = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.AbreConexaoImpressora', [params]); } exports.FechaConexaoImpressora = function (success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.FechaConexaoImpressora'); } exports.AvancaPapel = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.AvancaPapel', [params]); } exports.Corte = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.Corte', [params]); } exports.ImpressaoTexto = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.ImpressaoTexto', [params]); } exports.ImpressaoCodigoBarras = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.ImpressaoCodigoBarras', [params]); } exports.DefinePosicao = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.DefinePosicao', [params]); } exports.ImpressaoQRCode = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.ImpressaoQRCode', [params]); } exports.ImprimeXMLNFCe = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.ImprimeXMLNFCe', [params]); } exports.ImprimeXMLSAT = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.ImprimeXMLSAT', [params]); } exports.AbreGavetaElgin = function (success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.AbreGavetaElgin'); } exports.StatusImpressora = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.StatusImpressora', [params]); } exports.ImprimeImagemBase64 = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.ImprimeImagemBase64', [params]); } exports.IniciarPagamento = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.IniciarPagamento', [params]); } exports.IniciarCancelamentoVenda = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.IniciarCancelamentoVenda', [params]); } // //CUSTOM METHOD // exports.imprimeImagem = function (params, success, error) { // exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.ImprimeImagem', [params]); // } exports.ImpressaoTextoNetPrint = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.ImpressaoTextoNetPrint', [params]); } exports.ImpressaoBase64NetPrint = function (params, success, error) { exec(success, error, 'NetControllCordovaPluginsIntegration', 'Elgin.ElginSmartPay.ImpressaoBase64NetPrint', [params]); } exports.ImpressaoTextoNetPrintOld = function (params, success, error) { ImpressaoTextoNetPrintHelper(params.dados, success, error); } function ImpressaoTextoNetPrintHelper(textoImpresso, success, onError) { console.log('ImpressaoTextoNetPrintHelper'); try { var linhas = textoImpresso.split("\n"); linhas.forEach(function (linha) { linha = linha.replace('.nomeponto', ''); linha = linha.replace('.impressovia', ''); var tipoCaracter = "feed"; if (linha.includes("<n>") && linha.includes("</n>")) { tipoCaracter = "normal"; linha = linha.replace(/<n>/g, "").replace(/<\/n>/g, ""); if (linha.includes("<b>") && linha.includes("</b>")) { tipoCaracter += "-bold"; linha = linha.replace(/<b>/g, "").replace(/<\/b>/g, ""); } } else if (linha.includes("<g>") && linha.includes("</g>")) { tipoCaracter = "drawer"; } else if (linha.includes("<e>") && linha.includes("</e>")) { tipoCaracter = "expanded"; linha = linha.replace(/<e>/g, "").replace(/<\/e>/g, ""); if (linha.includes("<n>") && linha.includes("</n>")) { tipoCaracter += "-normal"; linha = linha.replace(/<n>/g, "").replace(/<\/n>/g, ""); if (linha.includes("<b>") && linha.includes("</b>")) { tipoCaracter = "bold"; linha = linha.replace(/<b>/g, "").replace(/<\/b>/g, ""); } } } else if (linha.includes("<b>") && linha.includes("</b>")) { tipoCaracter = "bold"; linha = linha.replace(/<b>/g, "").replace(/<\/b>/g, ""); if (linha.includes("<c>") && linha.includes("</c>")) { tipoCaracter += "-condensed"; linha = linha.replace(/<c>/g, "").replace(/<\/c>/g, ""); } else if (linha.includes("<n>") && linha.includes("</n>")) { tipoCaracter += "-normal"; linha = linha.replace(/<n>/g, "").replace(/<\/n>/g, ""); } } else if (linha.includes("<c>") && linha.includes("</c>")) { tipoCaracter = "condensed"; linha = linha.replace(/<c>/g, "").replace(/<\/c>/g, ""); } else if (linha.includes("<f>") && linha.includes("</f>")) { tipoCaracter = "reverse"; linha = linha.replace(/<f>/g, "").replace(/<\/f>/g, ""); } else if (linha.includes("<ce>") && linha.includes("</ce>")) { linha = linha.replace(/<ce>/g, "").replace(/<\/ce>/g, ""); if (linha.includes("<qrcode>") && linha.includes("</qrcode>")) { tipoCaracter = "qrcode"; linha = linha.replace(/<qrcode>/g, "").replace(/<\/qrcode>/g, ""); } else if (linha.includes("<code128>") && linha.includes("</code128>")) { tipoCaracter = "barcode128"; linha = linha.replace(/<code128>/g, "").replace(/<\/code128>/g, ""); } } if (linha.includes("<esc pos>")) { linha = linha.replace("<esc pos>", " "); } if (linha == "") { tipoCaracter = "feed"; } switch (tipoCaracter) { case "normal": ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 0, 1, 0); break; case "normal-bold": ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 0, 1 + 7, 0); break; case "bold-normal": ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 0, 1 + 7, 0); break; case "bold": ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 0, 0 + 8, 0); break; case "expanded": ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 0, 1, 17); break; case "condensed": ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 0, 1, 0); break; case "bold-condensed": ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 0, 1 + 7, 0); break; case "reverse": // ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 1, 8 + 4, 0); ImpressaoTextoNetPrintHelper_ImpressaoTexto(linha, 0, 1 + 4, 17); break; case "drawer": ImpressaoTextoNetPrintHelper_AbreGavetaElgin(); break; case "qrcode": ImpressaoTextoNetPrintHelper_DefinirImpressao(1); ImpressaoTextoNetPrintHelper_PrintQrCode(linha, 5, 1); ImpressaoTextoNetPrintHelper_AvancaPapel(1); break; case "barcode128": ImpressaoTextoNetPrintHelper_DefinirImpressao(1); ImpressaoTextoNetPrintHelper_PrintBarCode(8, "{C" + linha, 50, 2, 4); ImpressaoTextoNetPrintHelper_AvancaPapel(1); break; default: ImpressaoTextoNetPrintHelper_DefinirImpressao(0); ImpressaoTextoNetPrintHelper_AvancaPapel(1); break; } }); success("Ok"); } catch (error) { onError(error.toString()) } } function ImpressaoTextoNetPrintHelper_ImpressaoTexto(texto, posicao, stilo, tamanho) { console.log('cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.ImpressaoTexto'); try { var myResultSuccess; var myResultError; var result = cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.ImpressaoTexto( { dados: texto, posicao: posicao, stilo: stilo, tamanho: tamanho }, function (resultSuccess) { myResultSuccess = resultSuccess; console.log(resultSuccess); }, function (resultError) { myResultError = resultError; console.log(resultError); }); return result; } catch (error) { console.log(error.toString()); return false; } } function ImpressaoTextoNetPrintHelper_DefinirImpressao(position) { console.log('cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.DefinirImpressao'); try { var myResultSuccess; var myResultError; var result = cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.DefinePosicao( { posicao: position }, function (resultSuccess) { myResultSuccess = resultSuccess; console.log(resultSuccess); }, function (resultError) { myResultError = resultError; console.log(resultError); }); return result; } catch (error) { console.log(error.toString()); return false; } } function ImpressaoTextoNetPrintHelper_AvancaPapel(linhas) { console.log('cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.AvancaPapel'); try { var myResultSuccess; var myResultError; var result = cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.AvancaPapel( { linhas: linhas }, function (resultSuccess) { myResultSuccess = resultSuccess; console.log(resultSuccess); }, function (resultError) { myResultError = resultError; console.log(resultError); }); return result; } catch (error) { console.log(error.toString()); return false; } } function ImpressaoTextoNetPrintHelper_PrintQrCode(texto, tamanho, nivelCorrecao) { console.log('cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.ImpressaoQRCode'); try { var myResultSuccess; var myResultError; var result = cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.ImpressaoQRCode( { dados: texto, tamanho: tamanho, nivelCorrecao: nivelCorrecao }, function (resultSuccess) { myResultSuccess = resultSuccess; console.log(resultSuccess); }, function (resultError) { myResultError = resultError; console.log(resultError); }); return result; } catch (error) { console.log(error.toString()); return false; } } function ImpressaoTextoNetPrintHelper_PrintBarCode(tipo, texto, altura, largura, hri) { console.log('cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.ImpressaoCodigoBarras'); try { var myResultSuccess; var myResultError; var result = cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.ImpressaoCodigoBarras( { tipo: tipo, dados: texto, altura: altura, largura: largura, HRI: hri }, function (resultSuccess) { myResultSuccess = resultSuccess; console.log(resultSuccess); }, function (resultError) { myResultError = resultError; console.log(resultError); }); return result; } catch (error) { console.log(error.toString()); return false; } } function ImpressaoTextoNetPrintHelper_AbreGavetaElgin() { console.log('ImpressaoTextoNetPrintHelper_AbreGavetaElgin'); try { var myResultSuccess; var myResultError; var result = cordova.plugins.NetControllCordovaPluginsIntegration.ElginSmartPay.AbreGavetaElgin( function (resultSuccess) { myResultSuccess = resultSuccess; console.log(resultSuccess); }, function (resultError) { myResultError = resultError; console.log(resultError); }); return result; } catch (error) { console.log(error.toString()); return false; } }