Class POFromXMLGen.XMLProductInfo

java.lang.Object
org.brerp.sped.nfe.grid.POFromXMLGen.XMLProductInfo
Record Components:
element - private MLBRDocLineIPI createIPI(Properties ctx, MLBRDocLineDetailsNfe details, Element element, String trxName) { NodeList nList = element.getElementsByTagName("IPI"); for (int temp = 0; temp < nList.getLength(); temp++) { MLBRDocLineIPI ipi; MLBRDocLineIPI[] ipiEntries = MLBRDocLineIPI.getOfDetails(details); if (ipiEntries != null && ipiEntries.length > 0) ipi = ipiEntries[0]; else ipi = new MLBRDocLineIPI(ctx, 0, trxName); ipi.setAD_Org_ID(details.getAD_Org_ID()); ipi.setLBR_DocLine_Details_ID(details.get_ID()); ipi.setIsTaxIncluded(false); Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElementIPI = (Element) nNode; String taxBaseAmt = null; if (eElementIPI.getElementsByTagName("CST").item(0) != null) ipi.setLBR_IPI_TaxStatus(eElementIPI.getElementsByTagName("CST").item(0).getTextContent()); if (eElementIPI.getElementsByTagName("vBC").item(0) != null) { taxBaseAmt = eElementIPI.getElementsByTagName("vBC").item(0).getTextContent(); if (taxBaseAmt != null) ipi.setLBR_TaxBaseAmt(new BigDecimal(taxBaseAmt)); } if (eElementIPI.getElementsByTagName("pIPI").item(0) != null) { ipi.setCalculationType("PER"); String taxRate = eElementIPI.getElementsByTagName("pIPI").item(0).getTextContent(); if (taxRate != null) ipi.setLBR_TaxRate(new BigDecimal(taxRate)); } if (eElementIPI.getElementsByTagName("qUnid").item(0) != null) { ipi.setCalculationType("AMT"); String qUnid = eElementIPI.getElementsByTagName("qUnid").item(0).getTextContent(); if (qUnid != null) ipi.setTotalQty(new BigDecimal(qUnid)); } if (eElementIPI.getElementsByTagName("vUnid").item(0) != null) { String vUnid = eElementIPI.getElementsByTagName("vUnid").item(0).getTextContent(); if (vUnid != null) ipi.setPriceActual(new BigDecimal(vUnid)); } if (eElementIPI.getElementsByTagName("vIPI").item(0) != null) { String taxAmt = eElementIPI.getElementsByTagName("vIPI").item(0).getTextContent(); if (taxAmt != null) ipi.setLBR_TaxAmt(new BigDecimal(taxAmt)); // force taxbaseamt if (taxBaseAmt == null) ipi.setLBR_TaxBaseAmt(Env.ZERO); } ipi.saveEx(); return ipi; } } return null; } /** Create II (child of Doc Line Details) private MLBRDocLineImportTax createII(Properties ctx, MLBRDocLineDetailsNfe details, Element element, String trxName) { NodeList nList = element.getElementsByTagName("II"); for (int temp = 0; temp < nList.getLength(); temp++) { MLBRDocLineImportTax ii; MLBRDocLineImportTax[] iiEntries = MLBRDocLineImportTax.getOfDetails(details); if (iiEntries != null && iiEntries.length > 0) ii = iiEntries[0]; else ii = new MLBRDocLineImportTax(ctx, 0, trxName); ii.setAD_Org_ID(details.getAD_Org_ID()); ii.setLBR_DocLine_Details_ID(details.get_ID()); ii.setIsTaxIncluded(true); Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; String taxBaseAmt = null; if (eElement.getElementsByTagName("vBC").item(0) != null) { taxBaseAmt = eElement.getElementsByTagName("vBC").item(0).getTextContent(); if (taxBaseAmt != null) ii.setLBR_TaxBaseAmt(new BigDecimal(taxBaseAmt)); } if (eElement.getElementsByTagName("vDespAdu").item(0) != null) { String customsValue = eElement.getElementsByTagName("vDespAdu").item(0).getTextContent(); if (customsValue != null) ii.setCustomsValue(new BigDecimal(customsValue)); } if (eElement.getElementsByTagName("vII").item(0) != null) { String taxAmt = eElement.getElementsByTagName("vII").item(0).getTextContent(); if (taxAmt != null) ii.setLBR_TaxAmt(new BigDecimal(taxAmt)); } if (eElement.getElementsByTagName("vIOF").item(0) != null) { String iofAmt = eElement.getElementsByTagName("vIOF").item(0).getTextContent(); if (iofAmt != null) ii.setLBR_IOFAmt(new BigDecimal(iofAmt)); if (taxBaseAmt == null) ii.setLBR_TaxBaseAmt(Env.ZERO); } ii.saveEx(); return ii; } } return null; } /** Create PIS (child of Doc Line Details) private MLBRDocLinePIS createPIS(Properties ctx, MLBRDocLineDetailsNfe details, Element element, String trxName) { NodeList nList = element.getElementsByTagName("PIS"); for (int temp = 0; temp < nList.getLength(); temp++) { MLBRDocLinePIS pis; MLBRDocLinePIS[] pisEntries = MLBRDocLinePIS.getOfDetails(details); if (pisEntries != null && pisEntries.length > 0) pis = pisEntries[0]; else pis = new MLBRDocLinePIS(ctx, 0, trxName); pis.setAD_Org_ID(details.getAD_Org_ID()); pis.setLBR_DocLine_Details_ID(details.get_ID()); pis.setIsTaxIncluded(true); Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElementPIS = (Element) nNode; if (eElementPIS.getElementsByTagName("CST").item(0) != null) { String taxStatus = eElementPIS.getElementsByTagName("CST").item(0).getTextContent(); if (taxStatus != null) pis.setLBR_PIS_TaxStatus(taxStatus); } String taxBaseAmt = null; if (eElementPIS.getElementsByTagName("vBC").item(0) != null) { taxBaseAmt = eElementPIS.getElementsByTagName("vBC").item(0).getTextContent(); if (taxBaseAmt != null) pis.setLBR_TaxBaseAmt(new BigDecimal(taxBaseAmt)); } if (eElementPIS.getElementsByTagName("pPIS").item(0) != null) { String taxRate = eElementPIS.getElementsByTagName("pPIS").item(0).getTextContent(); if (taxRate != null) pis.setLBR_TaxRate(new BigDecimal(taxRate)); } if (eElementPIS.getElementsByTagName("vPIS").item(0) != null) { String taxAmt = eElementPIS.getElementsByTagName("vPIS").item(0).getTextContent(); if (taxAmt != null) { pis.setLBR_TaxAmt(new BigDecimal(taxAmt)); // force taxbaseamt if (taxBaseAmt == null) pis.setLBR_TaxBaseAmt(Env.ZERO); } } pis.saveEx(); return pis; } } return null; } /** Create COFINS (child of Doc Line Details) private MLBRDocLineCOFINS createCOFINS(Properties ctx, MLBRDocLineDetailsNfe details, Element element, String trxName) { NodeList nList = element.getElementsByTagName("COFINS"); for (int temp = 0; temp < nList.getLength(); temp++) { MLBRDocLineCOFINS cofins; MLBRDocLineCOFINS[] cofinsEntries = MLBRDocLineCOFINS.getOfDetails(details); if (cofinsEntries != null && cofinsEntries.length > 0) cofins = cofinsEntries[0]; else cofins = new MLBRDocLineCOFINS(ctx, 0, trxName); cofins.setAD_Org_ID(details.getAD_Org_ID()); cofins.setLBR_DocLine_Details_ID(details.get_ID()); cofins.setIsTaxIncluded(true); Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElementCOFINS = (Element) nNode; if (eElementCOFINS.getElementsByTagName("CST").item(0) != null) { String taxStatus = eElementCOFINS.getElementsByTagName("CST").item(0).getTextContent(); if (taxStatus != null) cofins.setLBR_COF_TaxStatus(taxStatus); } String taxBaseAmt = null; if (eElementCOFINS.getElementsByTagName("vBC").item(0) != null) { taxBaseAmt = eElementCOFINS.getElementsByTagName("vBC").item(0).getTextContent(); if (taxBaseAmt != null) cofins.setLBR_TaxBaseAmt(new BigDecimal(taxBaseAmt)); } if (eElementCOFINS.getElementsByTagName("pCOFINS").item(0) != null) { String taxRate = eElementCOFINS.getElementsByTagName("pCOFINS").item(0).getTextContent(); if (taxRate != null) cofins.setLBR_TaxRate(new BigDecimal(taxRate)); } if (eElementCOFINS.getElementsByTagName("vCOFINS").item(0) != null) { String taxAmt = eElementCOFINS.getElementsByTagName("vCOFINS").item(0).getTextContent(); if (taxAmt != null) cofins.setLBR_TaxAmt(new BigDecimal(taxAmt)); // force taxbaseamt if (taxBaseAmt == null) cofins.setLBR_TaxBaseAmt(Env.ZERO); } cofins.saveEx(); return cofins; } } return null; } /** Create ISSQN (child of Doc Line Details) private MLBRDocLineISSQN createISSQN(Properties ctx, MLBRDocLineDetailsNfe details, Element element, String trxName) { NodeList nList = element.getElementsByTagName("ISSQN"); for (int temp = 0; temp < nList.getLength(); temp++) { MLBRDocLineISSQN issqn; MLBRDocLineISSQN[] issqnEntries = MLBRDocLineISSQN.getOfDetails(details); if (issqnEntries != null && issqnEntries.length > 0) issqn = issqnEntries[0]; else issqn = new MLBRDocLineISSQN(ctx, 0, trxName); issqn.setAD_Org_ID(details.getAD_Org_ID()); issqn.setLBR_DocLine_Details_ID(details.get_ID()); issqn.setIsTaxIncluded(true); Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; if (eElement.getElementsByTagName("vBC").item(0) != null) { String taxBaseAmt = eElement.getElementsByTagName("vBC").item(0).getTextContent(); if (taxBaseAmt != null) issqn.setLBR_TaxBaseAmt(new BigDecimal(taxBaseAmt)); } if (eElement.getElementsByTagName("vAliq").item(0) != null) { String taxRate = eElement.getElementsByTagName("vAliq").item(0).getTextContent(); if (taxRate != null) issqn.setLBR_TaxRate(new BigDecimal(taxRate)); } if (eElement.getElementsByTagName("vISSQN").item(0) != null) { String taxAmt = eElement.getElementsByTagName("vISSQN").item(0).getTextContent(); if (taxAmt != null) issqn.setLBR_TaxAmt(new BigDecimal(taxAmt)); } issqn.saveEx(); return issqn; } } return null; } private int getTax(MLBRNotaFiscal nf, Integer M_Product_ID, Integer C_Charge_ID) { int C_Tax_ID = 0; if (M_Product_ID != null) { C_Tax_ID = Tax.getProduct(nf.getCtx(), M_Product_ID, nf.getDateDoc(), nf.getDateDoc(), nf.getAD_Org_ID(), 0, nf.getC_BPartner_Location_ID(), nf.getC_BPartner_Location_ID(), nf.isSOTrx(), null); } else if (C_Charge_ID != null) { C_Tax_ID = Tax.getCharge(nf.getCtx(), C_Charge_ID, nf.getDateDoc(), nf.getDateDoc(), nf.getAD_Org_ID(), 0, nf.getC_BPartner_Location_ID(), nf.getC_BPartner_Location_ID(), nf.isSOTrx(), null); } return C_Tax_ID; } fim aqui
Enclosing class:
POFromXMLGen

public class POFromXMLGen.XMLProductInfo extends Object
teste aqui private String createNotaFiscal() { String errorMsg = null; // Create Trx String trxName = Trx.createTrxName("NFX"); Trx trx = Trx.get(trxName, true); // check if NFe already imported if (xmlNFeID != null) { MLBRDocFiscal oldNF = MLBRDocFiscal.getNFe(xmlNFeID, trxName); if (oldNF != null && (oldNF.getlbr_NFeStatus().equals("100") && (oldNF.getDocStatus().equals(MLBRDocFiscal.DOCSTATUS_Completed) || oldNF.getDocStatus().equals(MLBRDocFiscal.DOCSTATUS_Closed)))) return "Nota Fiscal já importada anteriormente. Número: " + xmlDocumentNo; } // Create Brazilian Fiscal Invoice MLBRDocFiscal nf = new MLBRDocFiscal(Env.getCtx(), 0, trx.getTrxName()); nf.setAD_Org_ID(AD_Org_ID); nf.setDescription(description); nf.setLBR_NFeStatus(xmlStatusCode); nf.setLBR_NFeID(xmlNFeID); nf.setDocumentNo(xmlDocumentNo); nf.setLBR_TransactionType(LBR_TransactionType); nf.setC_DocType_ID(C_DocType_ID); String versionNo = ""; NodeList nList = doc.getElementsByTagName("infNFe"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; versionNo = eElement.getAttribute("versao"); } } nList = doc.getElementsByTagName("ide"); for (int temp = 0; temp < nList.getLength(); temp++) { Node nNode = nList.item(temp); if (nNode.getNodeType() == Node.ELEMENT_NODE) { Element eElement = (Element) nNode; if (!versionNo.equals("3.10")) { nf.setLBR_NFE_DestinationType(getPresumedDestinationType()); nf.setLBR_NFeIndFinal("0"); // Não nf.setLBR_NFeIndPres("0"); // Não se Aplica } else { nf.setLBR_NFE_DestinationType(eElement.getElementsByTagName("idDest").item(0).getTextContent()); nf.setLBR_NFeIndFinal(eElement.getElementsByTagName("indFinal").item(0).getTextContent()); nf.setLBR_NFeIndPres(eElement.getElementsByTagName("indPres").item(0).getTextContent()); } nf.setLBR_NFeModel(eElement.getElementsByTagName("mod").item(0).getTextContent()); nf.setLBR_NFeSerie(eElement.getElementsByTagName("serie").item(0).getTextContent()); nf.setLBR_NFE_OperationType(eElement.getElementsByTagName("tpNF").item(0).getTextContent()); if (eElement.getElementsByTagName("dhEmi").item(0) != null) nf.setDateDoc(getTimestamp(eElement.getElementsByTagName("dhEmi").item(0).getTextContent())); else nf.setDateDoc(getTimestamp(eElement.getElementsByTagName("dEmi").item(0).getTextContent())); nf.setDateAcct(nf.getDateDoc()); if (LBR_OwnDateDelivered != null) nf.setLBR_OwnDateDelivered(LBR_OwnDateDelivered); else nf.setLBR_OwnDateDelivered(new Timestamp(new java.util.Date().getTime())); if (eElement.getElementsByTagName("dhSaiEnt").item(0) != null) nf.setDateDelivered(getTimestamp(eElement.getElementsByTagName("dhSaiEnt").item(0).getTextContent())); nf.setPaymentRule(eElement.getElementsByTagName("indPag").item(0).getTextContent()); nf.setLBR_NFeTpEmis(eElement.getElementsByTagName("tpEmis").item(0).getTextContent()); nf.setLBR_FinNFe(eElement.getElementsByTagName("finNFe").item(0).getTextContent()); nf.setLBR_NFeNatOp(eElement.getElementsByTagName("natOp").item(0).getTextContent()); MCity city = getCity(eElement.getElementsByTagName("cMunFG").item(0).getTextContent()); nf.setC_City_ID(city.get_ID()); nf.setC_Region_ID(city.getC_Region_ID()); } } nf.setVersionNo(versionNo); nf.setLBR_IsDocIssuedByOrg(false); nf.setC_BPartner_ID(C_BPartner_ID); nf.setC_BPartner_Location_ID(C_BPartner_Location_ID); nf.setIsTaxIncluded(true); nf.setTotalLines(new BigDecimal(xmlTotalLinesAmt)); nf.setGrandTotal(new BigDecimal(xmlGrandTotal)); try { nf.saveEx(); } catch (Exception e) { return "Não foi possível gerar a Nota Fiscal."; } // Attach XML File MAttachment attachNFe = nf.createAttachment(); attachNFe.setAD_Org_ID(nf.getAD_Org_ID()); attachNFe.addEntry(xmlFile); attachNFe.save(trx.getTrxName()); // Should update/create entries in M_ProductPO ? boolean createProductPO = MSysConfig.getBooleanValue("LBR_PRODUCTPO_WHEN_GEN_NF_FROM_XML", true, nf.getAD_Client_ID(), nf.getAD_Org_ID()); // Generate Lines for (int i = 1; i <= xmlProductMap.size(); i++) { String key = String.valueOf(i); XMLProductInfo group = xmlProductMap.get(key); MLBRNotaFiscalLine line = new MLBRNotaFiscalLine(nf); line.setAD_Org_ID(nf.getAD_Org_ID()); line.setLine(i*10); if (group.M_Product_ID != null){ line.setM_Product_ID(group.M_Product_ID); if (group.pPO == null) { // Try to get existing MProductPO for BPartner MProductPO existingPPO = getMProductPO(group.M_Product_ID, trx.getTrxName()); if (existingPPO == null) { group.pPO = new MProductPO(Env.getCtx(), 0, trx.getTrxName()); group.pPO.setAD_Org_ID(AD_Org_ID); } else { group.pPO = existingPPO; } } // Update MProductPO if (createProductPO) { group.pPO.setC_BPartner_ID(C_BPartner_ID); group.pPO.setM_Product_ID(group.M_Product_ID); group.pPO.setC_UOM_ID(group.C_UOM_ID); group.pPO.setVendorProductNo(group.xmlValue); group.pPO.set_TrxName(trx.getTrxName()); group.pPO.setIsCurrentVendor(false); group.pPO.saveEx(); } } if (group.C_Charge_ID != null) line.setC_Charge_ID(group.C_Charge_ID); line.setQty(group.qty); line.setC_UOM_ID(group.C_UOM_ID); line.setPriceActual(group.unitPrice); int stdPrecision = MPriceList.getStandardPrecision(Env.getCtx(), prodPrice.getM_PriceList_Version().getM_PriceList_ID()); if (group.qty != null && group.unitPrice != null) { BigDecimal LineNetAmt = group.qty.multiply(group.unitPrice); if (LineNetAmt.scale() > stdPrecision) LineNetAmt = LineNetAmt.setScale(stdPrecision, BigDecimal.ROUND_HALF_UP); line.setLineNetAmt(LineNetAmt); } line.setC_Tax_ID(getTax(nf, group.M_Product_ID, group.C_Charge_ID)); try { line.saveEx(); } catch (Exception e) { return "Não foi possível gerar a Linha da Nota Fiscal."; } // Generate details and taxes MLBRDocLineDetailsNfe details = MLBRDocLineDetailsNfe.createFromPO(line); Object[] ownInfo = getTaxes(Env.getCtx(), line, trxName); if (details != null) { // armazena CFOP do declarante if ((Integer) ownInfo[2] > 0) { details.set_ValueOfColumn("LBR_OwnCFOP_ID", ownInfo[2]); } details.setProductValue(group.xmlValue); details.setProductName(group.xmlName); // CFOP // puts a dot after the first CFOP digit if(group.xmlCFOP != null && !group.xmlCFOP.isEmpty()){ String cfopValue = group.xmlCFOP.substring(0,1)+"."+group.xmlCFOP.substring(1,4); MLBRCFOP cfop = MLBRCFOP.getCFOP(Env.getCtx(), cfopValue, trx.getTrxName()); if (cfop != null) details.setLBR_CFOP_ID(cfop.get_ID()); } // freight and other charges details.setFreightAmt(group.freightAmt); details.setSurcharges(group.surCharges); details.setInsuredAmount(group.InsuredAmount); details.setDiscountAmt(group.DiscountAmt); details.saveEx(); // ICMS MLBRDocLineICMS docLineICMS = createICMS(Env.getCtx(), details, group.eElement, trx.getTrxName()); // IPI MLBRDocLineIPI docLineIPI = createIPI(Env.getCtx(), details, group.eElement, trx.getTrxName()); // PIS MLBRDocLinePIS docLinePIS = createPIS(Env.getCtx(), details, group.eElement, trx.getTrxName()); // COFINS MLBRDocLineCOFINS docLineCOFINS = createCOFINS(Env.getCtx(), details, group.eElement, trx.getTrxName()); // II createII(Env.getCtx(), details, group.eElement, trx.getTrxName()); // ISSQN createISSQN(Env.getCtx(), details, group.eElement, trx.getTrxName());
  • Field Details

    • xmlLineNo

      public String xmlLineNo
    • xmlValue

      public String xmlValue
    • xmlName

      public String xmlName
    • xmlUOM

      public String xmlUOM
    • xmlQty

      public String xmlQty
    • xmlUnitPrice

      public String xmlUnitPrice
    • xmlLineAmt

      public String xmlLineAmt
    • xmlCFOP

      public String xmlCFOP
    • xmlcProdANP

      public String xmlcProdANP
    • xmlpMixGN

      public String xmlpMixGN
    • xmlCODIF

      public String xmlCODIF
    • xmlqTemp

      public String xmlqTemp
    • xmlUFCons

      public String xmlUFCons
    • pMixGN

      public BigDecimal pMixGN
    • qTemp

      public BigDecimal qTemp
    • M_Product_ID

      public Integer M_Product_ID
    • C_Charge_ID

      public Integer C_Charge_ID
    • C_UOM_ID

      public Integer C_UOM_ID
    • qty

      public BigDecimal qty
    • unitPrice

      public BigDecimal unitPrice
    • xmlFreightAmt

      public String xmlFreightAmt
    • freightAmt

      public BigDecimal freightAmt
    • xmlSurCharges

      public String xmlSurCharges
    • surCharges

      public BigDecimal surCharges
    • xmlInsuredAmount

      public String xmlInsuredAmount
    • InsuredAmount

      public BigDecimal InsuredAmount
    • xmlDiscountAmt

      public String xmlDiscountAmt
    • DiscountAmt

      public BigDecimal DiscountAmt
  • Constructor Details

    • XMLProductInfo

      public XMLProductInfo()