function createDataset(fields, constraints, sortFields) { log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#createDataset - RICARDO"); //######## references var SERVICE_PROVIDER = ""; var PACKAGE = "br.com.."; var SERVICE_LOCATOR = PACKAGE + "."; //######## fim references log.warn("######ENT_DOCS#DS_EntDoc_RetornoAprov#createDataset"); var dataset = DatasetBuilder.newDataset(); dataset.addColumn("CNOMAPRO"); dataset.addColumn("RETORNO"); if (constraints.length > 0) { var EMPRESA = ''; var FILIAL = ''; var CDOC = ''; var CSERIE = ''; var CFORNEC = ''; var CLOJA = ''; var CIDFLUI = ''; var CLOGIN = ''; var ARRAYITENS = ''; var COBS = ''; log.warn("######ENT_DOCS#DS_EntDoc_RetornoAprov#antes do for"); for (var i = 0; i < constraints.length; i++) { var coluna = constraints[i].fieldName; var valorInicial = constraints[i].initialValue; var valorFinal = constraints[i].finalValue; if (coluna == "CDOC") { CDOC = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov# CDOC: " + CDOC); } else if (coluna == "CIDFLUI") { CIDFLUI = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov# CIDFLUI: " + CIDFLUI); } else if (coluna == "CSERIE") { CSERIE = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov# CSERIE: " + CSERIE); } else if (coluna == "CFORNEC") { CFORNEC = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov# CFORNEC: " + CFORNEC); } else if (coluna == "CLOJA") { CLOJA = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov# CLOJA: " + CLOJA); } else if (coluna == "CLOGIN") { CLOGIN = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov# CLOGIN: " + CLOGIN); } else if (coluna == "EMPRESA") { EMPRESA = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov# EMPRESA: " + EMPRESA); } else if (coluna == "FILIAL") { FILIAL = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov# FILIAL: " + FILIAL); } else if (coluna == "ARRAYITENS") { ARRAYITENS = valorInicial; } else if (coluna == "COBS") { COBS = valorInicial; log.info("#### VALOR INICIAL: " + valorInicial); log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov# COBS: " + COBS); } else if (coluna == "CCUSTO") { CCUSTO = valorInicial; } else if (coluna == "CDESCITEM") { CDESCITEM = valorInicial; } else if (coluna == "CDESCMOEDA") { CDESCMOEDA = valorInicial; } else if (coluna == "CITEMPED") { CITEMPED = valorInicial; } else if (coluna == "CNUMPED") { CNUMPED = valorInicial; } else if (coluna == "CPROD") { CPROD = valorInicial; } else if (coluna == "NMOEDA") { NMOEDA = valorInicial; } else if (coluna == "NQTDEMP") { NQTDEMP = valorInicial; } else if (coluna == "NQTDITEM") { NQTDITEM = valorInicial; log.info("######ricardo ENT_DOCS#DS_EntDoc_RetornoAprov# NQTDITEM: " + NQTDITEM); } else if (coluna == "NQTDPC") { NQTDPC = valorInicial; } else if (coluna == "NQTDREG") { NQTDREG = valorInicial; } else if (coluna == "NVALITEM") { NVALITEM = valorInicial.replace('.', '').replace(',', '.'); } else if (coluna == "NVALMOED") { NVALMOED = valorInicial.replace('.', '').replace(',', '.'); } else if (coluna == "NVLUNIT") { //NVLUNIT = valorInicial.replace('.', '').replace(',', '.'); NVLUNIT = String(valorInicial); } else if (coluna == "NVLUNMOED") { NVLUNMOED = valorInicial.replace('.', '').replace(',', '.'); } else if (coluna == "CSIMB") { CSIMB = valorInicial; } else if (coluna == "CCCBLOQ") { CCCBLOQ = valorInicial; } else if (coluna == "SERVICE_PROVIDER") { SERVICE_PROVIDER = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#SERVICE_PROVIDER:" + SERVICE_PROVIDER); } else if (coluna == "PACKAGE") { PACKAGE = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#PACKAGE:" + PACKAGE); } else if (coluna == "SERVICE_LOCATOR") { SERVICE_LOCATOR = valorInicial; log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#SERVICE_LOCATOR:" + SERVICE_LOCATOR); } } var serviceProvider = ServiceManager.getServiceInstance(SERVICE_PROVIDER); var wsServiceLocator = serviceProvider.instantiate(SERVICE_LOCATOR); var retGRV = serviceProvider.instantiate(PACKAGE + ".RETGRV"); log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#RETGRV: " + retGRV); var ws = wsServiceLocator.getQGWSFLUISOAP(); log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#ARRAYITENS: " + ARRAYITENS); var ArrayItens = new Array(); var arrayOfGrv = serviceProvider.instantiate(PACKAGE + ".GRVITEM"); var arrItens = eval('(' + ARRAYITENS + ')'); var arrayOfItens = serviceProvider.instantiate(PACKAGE + ".ARRAYOFITEMPED"); log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#ARRITENS: " + arrItens); for(j in arrItens) { log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#ARRITENS CITEMPED: " + arrItens[j]["CITEMPED"]); for(z in arrItens[j]) { log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#arrItens[j][z]: " + arrItens[j][z]); if (arrItens[j][z] == "") { arrItens[j][z] = "0"; } } var arrayOfItens2 = serviceProvider.instantiate(PACKAGE + ".ITEMPED"); arrayOfItens2.setCCCUSTO(arrItens[j]["CCUSTO"]); // arrayOfItens2.setCDESCITEM(arrItens[j]["CDESCITEM"]); arrayOfItens2.setCDESCITEM(arrItens[j]["NQTDITEM"]); arrayOfItens2.setCDESCMOEDA(arrItens[j]["CDESCMOEDA"]); arrayOfItens2.setCITEMPED(arrItens[j]["CITEMPED"]); arrayOfItens2.setCNUMPED(arrItens[j]["CNUMPED"]); arrayOfItens2.setCPROD(arrItens[j]["CPROD"]); if (arrItens[j]["NMOEDA"] == null || arrItens[j]["NMOEDA"] == "") { arrayOfItens2.setNMOEDA(0); } else { arrayOfItens2.setNMOEDA(new java.math.BigInteger(arrItens[j]["NMOEDA"])); //1-EURO } arrayOfItens2.setNQTDEMP((arrItens[j]["NQTDEMP"])); arrayOfItens2.setNQTDITEM((arrItens[j]["NQTDITEM"])); arrayOfItens2.setNQTDPC((arrItens[j]["NQTDPC"])); arrayOfItens2.setNQTDREG((arrItens[j]["NQTDREG"])); arrayOfItens2.setNVALITEM(arrItens[j]["NVALITEM"]); arrayOfItens2.setNVALMOED(arrItens[j]["NVALMOED"]); arrayOfItens2.setNVLUNIT(arrItens[j]["NVLUNIT"]); log.info("###### RICARDO 2 - ENT_DOCS#DS_EntDoc_RetornoAprov#arrItens[j]['NQTDITEM']: " + arrItens[j]["NQTDITEM"]); log.info("###### RICARDO - ENT_DOCS#DS_EntDoc_RetornoAprov#arrayOfItens2.getCDESCITEM: " + arrayOfItens2.getCDESCITEM()); arrayOfItens2.setNVLUNMOED(arrItens[j]["NVLUNMOED"]); arrayOfItens2.setCSIMB((arrItens[j]["CSIMB"])); arrayOfItens2.setCCCBLOQ((arrItens[j]["CCCBLOQ"])); ArrayItens.push(arrayOfItens2); } arrayOfItens.setITEMPED(ArrayItens); arrayOfGrv.setAGRVITEM(arrayOfItens); log.info("###############arrayOfGrv" + arrayOfGrv); log.info("############### - RICARDO - arrayOfItens2 " + arrayOfItens2); log.info("###############ArrayItens " + ArrayItens); log.info("###############COBS: " + COBS); var result = ws.GRVSOLIC(EMPRESA, FILIAL, CDOC, CSERIE, CFORNEC, CLOJA, CIDFLUI, CLOGIN, COBS, arrayOfGrv); log.info("###############COBS: " + COBS); log.info("###############GRVSOLIC**result***: " + result); if (result.getCCODERRO() != "00") { dataset.addRow(new Array(result.getCMENERRO(), result.getCCODERRO())); } else { var aprovad = serviceProvider.instantiate(PACKAGE + ".APROVAD"); var arrayOfAprovad = serviceProvider.instantiate(PACKAGE + ".ARRAYOFAPROVAD"); arrayOfAprovad = result.getAAPROVAD(); aprovad = arrayOfAprovad.getAPROVAD(); log.info(aprovad); log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#for RETORNANDO DATASET***** " + dataset); log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#DATASET APROV LENGTH***** " + aprovad.length); for (var i = 0; i < aprovad.length; i++) { log.info("###############dataset getCNOMAPRO: " + aprovad[i].getCNOMAPRO()); dataset.addRow(new Array(aprovad[i].getCNOMAPRO(), "00")); log.info(aprovad[i]); } } log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#RETORNANDO DATASET ROWVL:***** " + dataset.values[0][0]); log.info("######ENT_DOCS#DS_EntDoc_RetornoAprov#RETORNANDO DATASET***** " + dataset); return dataset; } else { // dataset.addColumn("RETORNO"); dataset.addRow(new Array("VALORES OBRIGATORIOS", "01")); return dataset; } } function formataDecimal(strNumero) { var df = new java.text.DecimalFormat("0.0000"); df.setMaximumFractionDigits(4); // dataset.addRow(new Array()); var retorno = new java.lang.Float(df.format(new java.lang.Float(strNumero.replace('.', '').replace(',', '.')))); log.info("######RETORNO: " + retorno); return retorno; }