package it.acxent.fattele; import it.acxent.anag.Iva; import it.acxent.common.StatusMsg; import it.acxent.db.DBAdapter; import it.acxent.db.ResParm; import it.acxent.util.DoubleOperator; import it.acxent.util.SimpleDateFormat; import it.acxent.util.Vectumerator; import java.io.File; import java.io.FileOutputStream; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Calendar; import java.util.Locale; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; import javax.xml.validation.Validator; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class FeXml extends _FeXmlAdapter { private boolean isBuildOk = false; private static final String TAG_BUILD_FE_XML = "Xml fatt. elett."; private FatturaElettronicaInterface fattura; private Vectumerator vecFatture; private Document dom; private Element rootElement; private SimpleDateFormat df; private DecimalFormat nf; public static final String REGIMI_FISCALI_VALIDI = ",RF01,RF02,RF04,RF05R,F06,RF07,RF08,RF09,RF10,RF11,RF12,RF13,RF14,RF15,RF16,RF17,RF18,RF19,"; public static final String TIPO_CASSA_VALIDI = ",TC01,TC02,TC04,TC05R,TC06,TC07,TC08,TC09,TC10,TC11,TC12,TC13,TC14,TC15,TC16,TC17,TC18,TC19,TC20,TC21,TC22,"; public static final String TIPO_SCONTO_MAGGIORAZIONE_VALIDI = ",SC,MG,"; public static final String TIPO_SCONTO_MAGGIORAZIONE_SCONTO = "SC"; public static final String TIPO_SCONTO_MAGGIORAZIONE_MAGGIORAZIONE = "MG"; public static final String TIPO_TRASMISSIONE_VERSO_PA = "FPA12"; public static final String TIPO_TRASMISSIONE_VERSO_PRIVATI = "FPR12"; public static final String TIPO_DOCUMENTO_01_FATTURA = "TD01"; public static final String TIPO_DOCUMENTO_02_ACCONTO_ANTICIPO_SU_FATTURA = "TD02"; public static final String TIPO_DOCUMENTO_03_ACCONTO_ANTICIPO_SU_PARCELLA = "TD03"; public static final String TIPO_DOCUMENTO_04_NOTA_DI_CREDITO = "TD04"; public static final String TIPO_DOCUMENTO_05_NOTA_DI_DEBITO = "TD05"; public static final String TIPO_DOCUMENTO_06_PARCELLA = "TD06"; public static final String TIPO_DOCUMENTO_16_INTEG_FT_REV_CHARGE_INT = "TD16"; public static final String TIPO_DOCUMENTO_17_INTEG_AUTOFAT_ACQ_SERV_ESTERO = "TD17"; public static final String TIPO_DOCUMENTO_18_INTEG_ACQ_BENI_INTRAC = "TD18"; public static final String TIPO_DOCUMENTO_19_INTEG_AUTOF_ACQ_ART17 = "TD19"; public static final String TIPO_DOCUMENTO_20_AUTOFATTURA = "TD20"; public static final String TIPO_DOCUMENTO_21_AUTOF_SPLAFONAMENTO = "TD21"; public static final String TIPO_DOCUMENTO_22_ESTRAZ_DA_DEPOSITO_IVA = "TD22"; public static final String TIPO_DOCUMENTO_23_ESTRAZ_DA_DEPOSITO_CON_VERSAMENTO = "TD23"; public static final String TIPO_DOCUMENTO_24_FATT_DIFF_ART_21_A_DPR_633_72 = "TD24"; public static final String TIPO_DOCUMENTO_25_FATT_DIFF_ART_21_B_DPR_633_72 = "TD25"; public static final String TIPO_DOCUMENTO_26_CESS_BENI_AMMORT = "TD26"; public static final String TIPO_DOCUMENTO_27_FATT_AUTOCONSUMO = "TD27"; public static final String IVA_TIPO_NATURA_VALIDI = ",N1,N2.1,N2.2,N3.1,N3.2,N3.3,N3.4,N3.5,N3.6,N4,N5,N6.1,N6.2,N6.3,N6.4,N6.5,N6.6,N6.7,N6.8,N6.9,N7,"; public static final String IVA_TIPO_NATURA_N1_ESCL_ART_15 = "N1"; public static final String IVA_TIPO_NATURA_N2_NON_SOGGETTO_NON_VALIDO_2021 = "N2"; public static final String IVA_TIPO_NATURA_N2_1_NON_SOGGETTO_ART_7 = "N2.1"; public static final String IVA_TIPO_NATURA_N2_2_NON_SOGGETTO_ALTRE = "N2.2"; public static final String IVA_TIPO_NATURA_N3_NON_IMPONIBILI_NON_VALIDO_2021 = "N3"; public static final String IVA_TIPO_NATURA_N3_1_NON_IMPONIBILI_ESPORTAZIONI = "N3.1"; public static final String IVA_TIPO_NATURA_N3_2_NON_IMPONIBILI_CESSIONI_INTRA = "N3.2"; public static final String IVA_TIPO_NATURA_N3_3_NON_IMPONIBILI_CESSIONI_S_MARINO = "N3.3"; public static final String IVA_TIPO_NATURA_N3_4_NON_IMPONIBILI_ASSIMILATE_CESS_ESP = "N3.4"; public static final String IVA_TIPO_NATURA_N3_5_NON_IMPONIBILI_DICHIARAZIONI_INTENTO = "N3.5"; public static final String IVA_TIPO_NATURA_N3_6_NON_IMPONIBILI_NON_CONCORRONO_PLAFOND = "N3.6"; public static final String IVA_TIPO_NATURA_N4_ESENTI = "N4"; public static final String IVA_TIPO_NATURA_N5_REGIME_DEL_MARGINE_IVA_NON_ESPOSTA = "N5"; public static final String IVA_TIPO_NATURA_N6_INVERSIONE_CONTABILE_NON_VALIDO_2021 = "N6"; public static final String IVA_TIPO_NATURA_N6_1_INVERSIONE_CONTABILE_ROTTAMI = "N6.1"; public static final String IVA_TIPO_NATURA_N6_2_INVERSIONE_CONTABILE_ORO_ARGENTO = "N6.2"; public static final String IVA_TIPO_NATURA_N6_3_INVERSIONE_CONTABILE_SUBAPPALTO_EDILE = "N6.3"; public static final String IVA_TIPO_NATURA_N6_4_INVERSIONE_CONTABILE_CESS_FABBRICATI = "N6.4"; public static final String IVA_TIPO_NATURA_N6_5_INVERSIONE_CONTABILE_CESS_CELLULARI = "N6.5"; public static final String IVA_TIPO_NATURA_N6_6_INVERSIONE_CONTABILE_PROD_ELETTRONCICI = "N6.6"; public static final String IVA_TIPO_NATURA_N6_7_INVERSIONE_CONTABILE_PREST_EDILE_E_CONNESSI = "N6.7"; public static final String IVA_TIPO_NATURA_N6_8_INVERSIONE_CONTABILE_SETT_ENERGETICO = "N6.8"; public static final String IVA_TIPO_NATURA_N6_9_INVERSIONE_CONTABILE_ALTRI_CASI = "N6.9"; public static final String IVA_TIPO_NATURA_N7_ALTRO_STATO_A_DISTANZA_SERV_TELE = "N7"; public static final String TIPO_CESSIONE_PRESTAZIONE_VALIDI = ",SC,PR,AB,AC,"; public static final String TIPO_CESSIONE_PRESTAZIONE_SCONTO = "SC"; public static final String TIPO_CESSIONE_PRESTAZIONE_PREMIO = "PR"; public static final String TIPO_CESSIONE_PRESTAZIONE_ABBUONO = "AB"; public static final String TIPO_CESSIONE_PRESTAZIONE_SPESA_ACCESSORIA = "AC"; public static final String TIPO_ESIGIBILITA_IVA_VALIDI = ",I,D,S,"; public static final String TIPO_ESIGIBILITA_IVA_IMMEDIATA = "I"; public static final String TIPO_ESIGIBILITA_IVA_DIFFERITA = "D"; public static final String TIPO_ESIGIBILITA_IVA_SCISSIONE = "S"; public static final String CONDIZIONI_PAGAMENTO_VALIDI = ",TP01,TP02,TP03,"; public static final String CONDIZIONI_PAGAMENTO_RATE_TP01 = "TP01"; public static final String CONDIZIONI_PAGAMENTO_COMPLETO_TP02 = "TP02"; public static final String CONDIZIONI_PAGAMENTO_ANTICIPO_TP03 = "TP03"; public static final String MODALITA_PAGAMENTO_VALIDI = ",MP01,MP02,MP03,MP04,MP05,MP06,MP07,MP08,MP00,MP10,MP11,MP12,MP13,MP14,MP15,MP16,MP17,MP18,MP19,MP20,MP21,MP22,"; public static final String FLAG_OPERAZIONE_INSERIMENTO = "I"; public static final String FLAG_OPERAZIONE_VARIAZIONE = "V"; public static final String FLAG_OPERAZIONE_RIMBORSO = "R"; public static final String FLAG_OPERAZIONE_CANCELLAZIONE = "C"; public static final String RIGA_ALTRI_DATI_GESTIONALI_VALUES = "INTENTO,NUMSCONTR"; public static final String RIGA_ALTRI_DATI_GESTIONALI_TIPO_DATO_INTENTO = "INTENTO"; public static final String RIGA_ALTRI_DATI_GESTIONALI_TIPO_DATO_SCONTRINO = "NUMSCONTR"; public static void main(String[] args) {} public FeXml(FatturaElettronicaInterface fattura) { this.fattura = fattura; this.vecFatture = null; } public FeXml(FatturaElettronicaInterface fattura, Vectumerator vecFatture) { this.vecFatture = vecFatture; this.fattura = fattura; } public static final String getFullFileXml(FatturaElettronicaInterface bean, String parmSfx) { return bean.getDocBase() + bean.getDocBase(); } public static final String getFileXmlToDocbase(FatturaElettronicaInterface bean, String parmSfx) { Calendar cal = Calendar.getInstance(); cal.setTime(bean.getFeDataDocumento()); String nomeFile = getNomeFileXml(bean, parmSfx); if (parmSfx != null && !parmSfx.equals("")) return bean.getApFull().getParm("FELETT_PATH_FATTURE_REL" + parmSfx).getTesto() + bean.getApFull().getParm("FELETT_PATH_FATTURE_REL" + parmSfx).getTesto() + "/" + cal.get(1) + "/" + cal.get(2) + 1; return bean.getApFull().getParm("FELETT_PATH_FATTURE_REL").getTesto() + bean.getApFull().getParm("FELETT_PATH_FATTURE_REL").getTesto() + "/" + cal.get(1) + "/" + cal.get(2) + 1; } private String getNomeFileXml(FatturaElettronicaInterface bean) { return getNomeFileXml(bean, ""); } private static String getNomeFileXml(FatturaElettronicaInterface bean, String parmSfx) { String nomeFile; if (parmSfx != null && !parmSfx.isEmpty()) { nomeFile = bean.getApFull().getParm("FELETT_TRASM_ID_PAESE" + parmSfx).getTesto() + bean.getApFull().getParm("FELETT_TRASM_ID_PAESE" + parmSfx).getTesto() + "_" + bean.getApFull().getParm("FELETT_TRASM_ID_CODICE" + parmSfx).getTesto() + ".xml"; } else { nomeFile = bean.getApFull().getParm("FELETT_TRASM_ID_PAESE").getTesto() + bean.getApFull().getParm("FELETT_TRASM_ID_PAESE").getTesto() + "_" + bean.getApFull().getParm("FELETT_TRASM_ID_CODICE").getTesto() + ".xml"; } return nomeFile; } private ResParm buildOneXml(FatturaElettronicaInterface bean, String parmSfx) { ResParm rp = new ResParm(); StringBuilder errMsg = new StringBuilder(); StringBuilder warnMsg = new StringBuilder(); rp = checkDatiObbligatori(bean, parmSfx); if (!rp.getStatus()) return rp; if (!bean.getFEDatiAnagraficiCessionario().getFEPaese().equals("IT") && !isFelettParm("FELETT_XML_ESTERO_SI" + parmSfx)) { rp.setStatus(true); rp.setInfoMsg(bean.getFENumeroDocumento() + ": Fattura vs. estero non obbiligatoria\n"); return rp; } Element e = null; SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat dTimef = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); NumberFormat nf = NumberFormat.getInstance(Locale.US); nf.setMaximumFractionDigits(2); nf.setMinimumFractionDigits(2); DecimalFormat nfe = (DecimalFormat)nf; nfe.applyPattern("##0.00"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); this.dom = db.newDocument(); this.rootElement = this.dom.createElement("p:FatturaElettronica"); this.rootElement.setAttribute("xmlns:ds", "http://www.w3.org/2000/09/xmldsig#"); this.rootElement.setAttribute("xmlns:p", "http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"); if (bean.isPubblicaAmministrazione()) { this.rootElement.setAttribute("versione", "FPA12"); } else { this.rootElement.setAttribute("versione", "FPR12"); } Element fatturaElettronicaHeader = this.dom.createElement("FatturaElettronicaHeader"); Element datiTrasmissione = this.dom.createElement("DatiTrasmissione"); Element idTrasmittente = this.dom.createElement("IdTrasmittente"); e = this.dom.createElement("IdPaese"); e.setTextContent(getFelettParm("FELETT_TRASM_ID_PAESE" + parmSfx)); idTrasmittente.appendChild(e); e = this.dom.createElement("IdCodice"); e.setTextContent(getFelettParm("FELETT_TRASM_ID_CODICE" + parmSfx)); idTrasmittente.appendChild(e); datiTrasmissione.appendChild(idTrasmittente); e = this.dom.createElement("ProgressivoInvio"); e.setTextContent(bean.getFEProgressivo()); datiTrasmissione.appendChild(e); e = this.dom.createElement("FormatoTrasmissione"); e.setTextContent(bean.isPubblicaAmministrazione() ? "FPA12" : "FPR12"); datiTrasmissione.appendChild(e); e = this.dom.createElement("CodiceDestinatario"); if (bean.getFECodiceDestinatario() == null || bean.getFECodiceDestinatario().isEmpty()) { if (bean.isPubblicaAmministrazione()) { e.setTextContent("000000"); } else if (bean.getFEDatiAnagraficiCessionario().getFEPaese().equals("IT")) { e.setTextContent("0000000"); } else { e.setTextContent("XXXXXXX"); } } else { e.setTextContent(bean.getFECodiceDestinatario().toUpperCase()); } datiTrasmissione.appendChild(e); if (!getFelettParm("FELETT_TRASM_CONTATTO_TELEFONO" + parmSfx).isEmpty() || !getFelettParm("FELETT_TRASM_CONTATTO_EMAIL" + parmSfx).isEmpty()) { Element contattiTrasmittente = this.dom.createElement("ContattiTrasmittente"); if (!getFelettParm("FELETT_TRASM_CONTATTO_TELEFONO" + parmSfx).isEmpty()) { e = this.dom.createElement("Telefono"); e.setTextContent(getFelettParm("FELETT_TRASM_CONTATTO_TELEFONO" + parmSfx)); contattiTrasmittente.appendChild(e); } if (!getFelettParm("FELETT_TRASM_CONTATTO_EMAIL" + parmSfx).isEmpty()) { e = this.dom.createElement("Email"); e.setTextContent(getFelettParm("FELETT_TRASM_CONTATTO_EMAIL" + parmSfx)); contattiTrasmittente.appendChild(e); } datiTrasmissione.appendChild(contattiTrasmittente); } if (bean.getFEPecDestinatario() != null && !bean.getFEPecDestinatario().isEmpty()) { e = this.dom.createElement("PECDestinatario"); e.setTextContent(bean.getFEPecDestinatario()); datiTrasmissione.appendChild(e); } else if (bean.getFECodiceDestinatario() == null || bean.getFECodiceDestinatario().isEmpty()) { warnMsg.append("DatiTrasmissione-> PECDestinatario o CodiceDestinatario non impostati\n"); } fatturaElettronicaHeader.appendChild(datiTrasmissione); Element cedentePrestatore = this.dom.createElement("CedentePrestatore"); Element datiAnagrafici = this.dom.createElement("DatiAnagrafici"); Element idFiscaleIVA = this.dom.createElement("IdFiscaleIVA"); e = this.dom.createElement("IdPaese"); e.setTextContent(getFelettParm("FELETT_CEDENTE_ID_PAESE" + parmSfx)); idFiscaleIVA.appendChild(e); e = this.dom.createElement("IdCodice"); e.setTextContent(getFelettParm("FELETT_CEDENTE_ID_CODICE" + parmSfx)); idFiscaleIVA.appendChild(e); datiAnagrafici.appendChild(idFiscaleIVA); e = this.dom.createElement("CodiceFiscale"); e.setTextContent(getFelettParm("FELETT_CEDENTE_COD_FISC" + parmSfx)); datiAnagrafici.appendChild(e); Element anagrafica = this.dom.createElement("Anagrafica"); if (!getFelettParm("FELETT_CEDENTE_DENOMINAZIONE" + parmSfx).isEmpty()) { e = this.dom.createElement("Denominazione"); e.setTextContent(convertStringToXmlString(getFelettParm("FELETT_CEDENTE_DENOMINAZIONE" + parmSfx), 80)); anagrafica.appendChild(e); } else { e = this.dom.createElement("Nome"); e.setTextContent(convertStringToXmlString(getFelettParm("FELETT_CEDENTE_NOME" + parmSfx), 60)); anagrafica.appendChild(e); e = this.dom.createElement("Cognome"); e.setTextContent(convertStringToXmlString(getFelettParm("FELETT_CEDENTE_COGNOME" + parmSfx), 60)); anagrafica.appendChild(e); if (!getFelettParm("FELETT_CEDENTE_TITOLO" + parmSfx).isEmpty()) { e = this.dom.createElement("Titolo"); e.setTextContent(getFelettParm("FELETT_CEDENTE_TITOLO" + parmSfx)); anagrafica.appendChild(e); } if (!getFelettParm("FELETT_CEDENTE_COD_EORI" + parmSfx).isEmpty()) { e = this.dom.createElement("CodEORI"); e.setTextContent(getFelettParm("FELETT_CEDENTE_COD_EORI" + parmSfx)); anagrafica.appendChild(e); } } datiAnagrafici.appendChild(anagrafica); e = this.dom.createElement("RegimeFiscale"); e.setTextContent(getFelettParm("FELETT_CEDENTE_REGIME_FISCALE" + parmSfx)); datiAnagrafici.appendChild(e); cedentePrestatore.appendChild(datiAnagrafici); Element sede = this.dom.createElement("Sede"); e = this.dom.createElement("Indirizzo"); e.setTextContent(convertStringToXmlString(getFelettParm("FELETT_CEDENTE_SEDE_INDIRIZZO" + parmSfx), 60)); sede.appendChild(e); e = this.dom.createElement("NumeroCivico"); e.setTextContent(getFelettParm("FELETT_CEDENTE_SEDE_NUM_CIV" + parmSfx)); sede.appendChild(e); e = this.dom.createElement("CAP"); e.setTextContent(getFelettParm("FELETT_CEDENTE_SEDE_CAP" + parmSfx)); sede.appendChild(e); e = this.dom.createElement("Comune"); e.setTextContent(convertStringToXmlString(getFelettParm("FELETT_CEDENTE_SEDE_COMUNE" + parmSfx), 60)); sede.appendChild(e); e = this.dom.createElement("Provincia"); e.setTextContent(getFelettParm("FELETT_CEDENTE_SEDE_PROV" + parmSfx).toUpperCase()); sede.appendChild(e); e = this.dom.createElement("Nazione"); e.setTextContent(getFelettParm("FELETT_CEDENTE_SEDE_NAZIONE" + parmSfx).toUpperCase()); sede.appendChild(e); cedentePrestatore.appendChild(sede); if (!getFelettParm("FELETT_CEDENTE_STAB_ORG_INDIRIZZO" + parmSfx).isEmpty()) { Element stabileOrganizzazione = this.dom.createElement("StabileOrganizzazione"); e = this.dom.createElement("Indirizzo"); e.setTextContent( convertStringToXmlString(getFelettParm("FELETT_CEDENTE_STAB_ORG_INDIRIZZO" + parmSfx), 60)); stabileOrganizzazione.appendChild(e); e = this.dom.createElement("NumeroCivico"); e.setTextContent(getFelettParm("FELETT_CEDENTE_STAB_ORG_NUMERO_CIVICO" + parmSfx)); stabileOrganizzazione.appendChild(e); e = this.dom.createElement("CAP"); e.setTextContent(getFelettParm("FELETT_CEDENTE_STAB_ORG_CAP" + parmSfx)); stabileOrganizzazione.appendChild(e); e = this.dom.createElement("Comune"); e.setTextContent(convertStringToXmlString(getFelettParm("FELETT_CEDENTE_STAB_ORG_COMUNE" + parmSfx), 60)); stabileOrganizzazione.appendChild(e); e = this.dom.createElement("Provincia"); e.setTextContent(getFelettParm("FELETT_CEDENTE_STAB_ORG_PROVINCIA" + parmSfx).toUpperCase()); stabileOrganizzazione.appendChild(e); e = this.dom.createElement("Nazione"); e.setTextContent(getFelettParm("FELETT_CEDENTE_STAB_ORG_NAZIONE" + parmSfx).toUpperCase()); stabileOrganizzazione.appendChild(e); cedentePrestatore.appendChild(stabileOrganizzazione); } if (!getFelettParm("FELETT_CEDENTE_RAPP_FISC_ID_CODICE" + parmSfx).isEmpty()) { Element rappresentanteFiscale = this.dom.createElement("RappresentanteFiscale"); Element element3 = this.dom.createElement("IdFiscaleIVA"); e = this.dom.createElement("IdPaese"); e.setTextContent(getFelettParm("FELETT_CEDENTE_RAPP_FISC_ID_PAESE" + parmSfx)); element3.appendChild(e); e = this.dom.createElement("IdCodice"); e.setTextContent(getFelettParm("FELETT_CEDENTE_RAPP_FISC_ID_CODICE" + parmSfx)); element3.appendChild(e); rappresentanteFiscale.appendChild(element3); if (!getFelettParm("FELETT_CEDENTE_RAPP_FISC_DENOMINAZIONE" + parmSfx).isEmpty()) { e = this.dom.createElement("Denominazione"); e.setTextContent(convertStringToXmlString( getFelettParm("FELETT_CEDENTE_RAPP_FISC_DENOMINAZIONE" + parmSfx), 80)); rappresentanteFiscale.appendChild(e); } else { e = this.dom.createElement("Nome"); e.setTextContent( convertStringToXmlString(getFelettParm("FELETT_CEDENTE_RAPP_FISC_NOME" + parmSfx), 60)); rappresentanteFiscale.appendChild(e); e = this.dom.createElement("Cognome"); e.setTextContent( convertStringToXmlString(getFelettParm("FELETT_CEDENTE_RAPP_FISC_COGNOME" + parmSfx), 60)); rappresentanteFiscale.appendChild(e); if (!getFelettParm("FELETT_CEDENTE_RAPP_FISC_TITOLO" + parmSfx).isEmpty()) { e = this.dom.createElement("Titolo"); e.setTextContent(getFelettParm("FELETT_CEDENTE_TITOLO" + parmSfx)); rappresentanteFiscale.appendChild(e); } if (!getFelettParm("FELETT_CEDENTE_RAPP_FISC_COD_EORI" + parmSfx).isEmpty()) { e = this.dom.createElement("CodEORI"); e.setTextContent(getFelettParm("FELETT_CEDENTE_COD_EORI" + parmSfx)); rappresentanteFiscale.appendChild(e); } } cedentePrestatore.appendChild(rappresentanteFiscale); } if (!getFelettParm("FELETT_CEDENTE_ISCR_REA_UFFICIO" + parmSfx).isEmpty()) { Element iscrizioneREA = this.dom.createElement("IscrizioneREA"); e = this.dom.createElement("Ufficio"); e.setTextContent(getFelettParm("FELETT_CEDENTE_ISCR_REA_UFFICIO" + parmSfx)); iscrizioneREA.appendChild(e); e = this.dom.createElement("NumeroREA"); e.setTextContent(getFelettParm("FELETT_CEDENTE_ISCR_REA_NUMERO_REA" + parmSfx)); iscrizioneREA.appendChild(e); e = this.dom.createElement("CapitaleSociale"); e.setTextContent(getFelettParm("FELETT_CEDENTE_ISCR_REA_CAPITALE_SOCIALE" + parmSfx)); iscrizioneREA.appendChild(e); e = this.dom.createElement("SocioUnico"); e.setTextContent(getFelettParm("FELETT_CEDENTE_ISCR_REA_SOCIO_UNICO" + parmSfx)); iscrizioneREA.appendChild(e); e = this.dom.createElement("StatoLiquidazione"); e.setTextContent(getFelettParm("FELETT_CEDENTE_ISCR_REA_STATO_LIQUIDAZIONE" + parmSfx)); iscrizioneREA.appendChild(e); cedentePrestatore.appendChild(iscrizioneREA); } if (!getFelettParm("FELETT_CEDENTE_CONTATTI_TELEFONO" + parmSfx).isEmpty() || !getFelettParm("FELETT_CEDENTE_CONTATTI_EMAIL" + parmSfx).isEmpty() || !getFelettParm("FELETT_CEDENTE_CONTATTI_FAX" + parmSfx).isEmpty()) { Element contatti = this.dom.createElement("Contatti"); if (!getFelettParm("FELETT_CEDENTE_CONTATTI_TELEFONO" + parmSfx).isEmpty()) { e = this.dom.createElement("Telefono"); e.setTextContent(getFelettParm("FELETT_CEDENTE_CONTATTI_TELEFONO" + parmSfx)); contatti.appendChild(e); } if (!getFelettParm("FELETT_CEDENTE_CONTATTI_EMAIL" + parmSfx).isEmpty()) { e = this.dom.createElement("Email"); e.setTextContent(getFelettParm("FELETT_CEDENTE_CONTATTI_EMAIL" + parmSfx)); contatti.appendChild(e); } if (!getFelettParm("FELETT_CEDENTE_CONTATTI_FAX" + parmSfx).isEmpty()) { e = this.dom.createElement("Fax"); e.setTextContent(getFelettParm("FELETT_CEDENTE_CONTATTI_FAX" + parmSfx)); contatti.appendChild(e); } cedentePrestatore.appendChild(contatti); } fatturaElettronicaHeader.appendChild(cedentePrestatore); if (bean.getFERappFiscalepartitaIva() != null && !bean.getFERappFiscalepartitaIva().isEmpty()) { Element rappresentanteFiscale = this.dom.createElement("RappresentanteFiscale"); Element element3 = this.dom.createElement("IdFiscaleIVA"); e = this.dom.createElement("IdPaese"); e.setTextContent(bean.getFERappFiscaleIdPaese()); element3.appendChild(e); e = this.dom.createElement("IdCodice"); e.setTextContent(bean.getFERappFiscalepartitaIva()); element3.appendChild(e); rappresentanteFiscale.appendChild(element3); if (bean.getFERappFiscaleDenominazione() != null && !bean.getFERappFiscaleDenominazione().isEmpty()) { e = this.dom.createElement("Denominazione"); e.setTextContent(convertStringToXmlString(bean.getFERappFiscaleDenominazione(), 80)); rappresentanteFiscale.appendChild(e); } else { e = this.dom.createElement("Nome"); e.setTextContent(convertStringToXmlString(bean.getFERappFiscaleNome(), 60)); rappresentanteFiscale.appendChild(e); e = this.dom.createElement("Cognome"); e.setTextContent(convertStringToXmlString(bean.getFERappFiscaleCognome(), 60)); rappresentanteFiscale.appendChild(e); if (bean.getFERappFiscaleTitolo() != null && !bean.getFERappFiscaleTitolo().isEmpty()) { e = this.dom.createElement("Titolo"); e.setTextContent(bean.getFERappFiscaleTitolo()); rappresentanteFiscale.appendChild(e); } if (bean.getFERappFiscaleCodEORI() != null && !bean.getFERappFiscaleCodEORI().isEmpty()) { e = this.dom.createElement("CodEORI"); e.setTextContent(bean.getFERappFiscaleCodEORI()); rappresentanteFiscale.appendChild(e); } } fatturaElettronicaHeader.appendChild(rappresentanteFiscale); } Element cessionarioCommittente = this.dom.createElement("CessionarioCommittente"); Element element1 = this.dom.createElement("DatiAnagrafici"); if (bean.getFEDatiAnagraficiCessionario().getFEPaese().equals("IT")) { if (bean.getFEDatiAnagraficiCessionario().getFEPartitaIva() != null && !bean.getFEDatiAnagraficiCessionario().getFEPartitaIva().isEmpty()) { Element element = this.dom.createElement("IdFiscaleIVA"); e = this.dom.createElement("IdPaese"); e.setTextContent(bean.getFEDatiAnagraficiCessionario().getFEPaese()); element.appendChild(e); e = this.dom.createElement("IdCodice"); e.setTextContent(bean.getFEDatiAnagraficiCessionario().getFEPartitaIva()); element.appendChild(e); element1.appendChild(element); } } else { Element element = this.dom.createElement("IdFiscaleIVA"); e = this.dom.createElement("IdPaese"); e.setTextContent(bean.getFEDatiAnagraficiCessionario().getFEPaese()); element.appendChild(e); e = this.dom.createElement("IdCodice"); if (bean.getFEDatiAnagraficiCessionario().getFEPartitaIva() != null && !bean.getFEDatiAnagraficiCessionario().getFEPartitaIva().isEmpty()) { e.setTextContent(bean.getFEDatiAnagraficiCessionario().getFEPartitaIva()); } else { e.setTextContent("00000000000"); } element.appendChild(e); element1.appendChild(element); } if (!bean.getFEDatiAnagraficiCessionario().getFECodiceFiscale().isEmpty() && bean.getFEDatiAnagraficiCessionario().getFEPaese().toUpperCase().equals("IT")) { e = this.dom.createElement("CodiceFiscale"); e.setTextContent(bean.getFEDatiAnagraficiCessionario().getFECodiceFiscale()); element1.appendChild(e); } anagrafica = this.dom.createElement("Anagrafica"); if (bean.getFEDatiAnagraficiCessionario().getFEDenominazione() != null && !bean.getFEDatiAnagraficiCessionario().getFEDenominazione().isEmpty()) { e = this.dom.createElement("Denominazione"); e.setTextContent( convertStringToXmlString(bean.getFEDatiAnagraficiCessionario().getFEDenominazione(), 80)); anagrafica.appendChild(e); } else { if (!bean.getFEDatiAnagraficiCessionario().getFENome().isEmpty()) { e = this.dom.createElement("Nome"); e.setTextContent(convertStringToXmlString(bean.getFEDatiAnagraficiCessionario().getFENome(), 60)); anagrafica.appendChild(e); } else { errMsg.append("Cessionario Nome non valido oppure impostare Cliente a Azienda\n"); } if (!bean.getFEDatiAnagraficiCessionario().getFECognome().isEmpty()) { e = this.dom.createElement("Cognome"); e.setTextContent( convertStringToXmlString(bean.getFEDatiAnagraficiCessionario().getFECognome(), 60)); anagrafica.appendChild(e); } else { errMsg.append("Cessionario Cognome non valido\n"); } if (bean.getFEDatiAnagraficiCessionario().getFETitolo() != null && !bean.getFEDatiAnagraficiCessionario().getFETitolo().isEmpty()) { e = this.dom.createElement("Titolo"); e.setTextContent(bean.getFEDatiAnagraficiCessionario().getFETitolo()); anagrafica.appendChild(e); } if (bean.getFEDatiAnagraficiCessionario().getFECodEORI() != null && !bean.getFEDatiAnagraficiCessionario().getFECodEORI().isEmpty()) { e = this.dom.createElement("CodEORI"); e.setTextContent(bean.getFEDatiAnagraficiCessionario().getFECodEORI()); anagrafica.appendChild(e); } } element1.appendChild(anagrafica); cessionarioCommittente.appendChild(element1); Element element2 = this.dom.createElement("Sede"); FESedeInterface feSede = bean.getFESedeCessonario(); e = this.dom.createElement("Indirizzo"); e.setTextContent(convertStringToXmlString(feSede.getFEIndirizzo(), 60)); element2.appendChild(e); if (!feSede.getFENumeroCivico().isEmpty()) { e = this.dom.createElement("NumeroCivico"); if (feSede.getFENumeroCivico().length() > 8) { e.setTextContent(feSede.getFENumeroCivico().substring(0, 8)); warnMsg.append("Cessionario Sede numero civico > 8 caratteri\n"); } else { e.setTextContent(feSede.getFENumeroCivico()); } element2.appendChild(e); } if (bean.getFEDatiAnagraficiCessionario().getFEPaese().toUpperCase().equals("IT")) { if (!feSede.getFECAP().isEmpty() && feSede.getFECAP().length() == 5) { e = this.dom.createElement("CAP"); e.setTextContent(feSede.getFECAP()); element2.appendChild(e); } else { errMsg.append("Cessionario CAP non valido\n"); } } else { e = this.dom.createElement("CAP"); e.setTextContent("00000"); element2.appendChild(e); } e = this.dom.createElement("Comune"); e.setTextContent(convertStringToXmlString(feSede.getFEComune(), 60)); element2.appendChild(e); if (bean.getFEDatiAnagraficiCessionario().getFEPaese().toUpperCase().equals("IT")) { e = this.dom.createElement("Provincia"); if (feSede.getFEProvincia().length() == 2) { e.setTextContent(feSede.getFEProvincia().toUpperCase()); } else { errMsg.append("Cessionario Sede Provincia IT errata\n"); } element2.appendChild(e); } else if (!feSede.getFEProvincia().isEmpty()) { e = this.dom.createElement("Provincia"); if (feSede.getFEProvincia().length() > 2) { e.setTextContent(feSede.getFEProvincia().substring(0, 2).toUpperCase()); warnMsg.append("Cessionario Sede Provincia > 2 caratteri\n"); } else { e.setTextContent(feSede.getFEProvincia().toUpperCase()); } element2.appendChild(e); } e = this.dom.createElement("Nazione"); e.setTextContent(feSede.getFENazione().toUpperCase()); element2.appendChild(e); cessionarioCommittente.appendChild(element2); if (bean.getFEStabileOrg() != null) { Element stabileOrganizzazione = this.dom.createElement("StabileOrganizzazione"); FESedeInterface fESedeInterface = bean.getFEStabileOrg(); e = this.dom.createElement("Indirizzo"); e.setTextContent(convertStringToXmlString(fESedeInterface.getFEIndirizzo(), 60)); element2.appendChild(e); e = this.dom.createElement("NumeroCivico"); e.setTextContent(fESedeInterface.getFENumeroCivico()); element2.appendChild(e); e = this.dom.createElement("CAP"); e.setTextContent(fESedeInterface.getFECAP()); element2.appendChild(e); e = this.dom.createElement("Comune"); e.setTextContent(convertStringToXmlString(fESedeInterface.getFEComune(), 60)); element2.appendChild(e); e = this.dom.createElement("Provincia"); e.setTextContent(fESedeInterface.getFEProvincia().toUpperCase()); element2.appendChild(e); e = this.dom.createElement("Nazione"); e.setTextContent(fESedeInterface.getFENazione().toUpperCase()); element2.appendChild(e); cessionarioCommittente.appendChild(stabileOrganizzazione); } fatturaElettronicaHeader.appendChild(cessionarioCommittente); if (!getFelettParm("FELETT_INTERMEDIARIO_ID_CODICE" + parmSfx).isEmpty()) { Element terzoIntermediario = this.dom.createElement("TerzoIntermediarioOSoggettoEmittente"); Element element3 = this.dom.createElement("DatiAnagrafici"); if (!getFelettParm("FELETT_INTERMEDIARIO_ID_PAESE" + parmSfx).isEmpty() && !getFelettParm("FELETT_INTERMEDIARIO_ID_CODICE" + parmSfx).isEmpty()) { Element element = this.dom.createElement("IdFiscaleIVA"); e = this.dom.createElement("IdPaese"); e.setTextContent(getFelettParm("FELETT_INTERMEDIARIO_ID_PAESE" + parmSfx)); element.appendChild(e); e = this.dom.createElement("IdCodice"); e.setTextContent(getFelettParm("FELETT_INTERMEDIARIO_ID_CODICE" + parmSfx)); element.appendChild(e); element3.appendChild(element); } else { errMsg.append("TerzoIntermediarioOSoggettoEmittente " + parmSfx + ": FELETT_INTERMEDIARIO_ID_PAESE o FELETT_INTERMEDIARIO_ID_CODICE nulli\n"); } if (!getFelettParm("FELETT_INTERMEDIARIO_CODICE_FISCALE" + parmSfx).isEmpty()) { e = this.dom.createElement("CodiceFiscale"); e.setTextContent(getFelettParm("FELETT_INTERMEDIARIO_CODICE_FISCALE" + parmSfx)); } else { errMsg.append("TerzoIntermediarioOSoggettoEmittente " + parmSfx + ": FELETT_INTERMEDIARIO_CODICE_FISCALE nulli\n"); } element3.appendChild(e); Element element4 = this.dom.createElement("Anagrafica"); if (!getFelettParm("FELETT_INTERMEDIARIO_DENOMINAZIONE" + parmSfx).isEmpty()) { e = this.dom.createElement("Denominazione"); e.setTextContent(convertStringToXmlString( getFelettParm("FELETT_INTERMEDIARIO_DENOMINAZIONE" + parmSfx), 80)); element4.appendChild(e); } else { e = this.dom.createElement("Nome"); e.setTextContent( convertStringToXmlString(getFelettParm("FELETT_INTERMEDIARIO_NOME" + parmSfx), 60)); element4.appendChild(e); e = this.dom.createElement("Cognome"); e.setTextContent( convertStringToXmlString(getFelettParm("FELETT_INTERMEDIARIO_COGNOME" + parmSfx), 60)); element4.appendChild(e); if (!getFelettParm("FELETT_INTERMEDIARIO_TITOLO" + parmSfx).isEmpty()) { e = this.dom.createElement("Titolo"); e.setTextContent(getFelettParm("FELETT_INTERMEDIARIO_TITOLO" + parmSfx)); element4.appendChild(e); } if (!getFelettParm("FELETT_INTERMEDIARIO_COD_EORI" + parmSfx).isEmpty()) { e = this.dom.createElement("CodEORI"); e.setTextContent(getFelettParm("FELETT_INTERMEDIARIO_COD_EORI" + parmSfx)); element4.appendChild(e); } } element3.appendChild(element4); terzoIntermediario.appendChild(element3); fatturaElettronicaHeader.appendChild(terzoIntermediario); } if (!getFelettParm("FELETT_INTERMEDIARIO_SOGGETTO_EMITTENTE" + parmSfx).isEmpty()) { Element soggettoEmittente = this.dom.createElement("SoggettoEmittente"); soggettoEmittente.setTextContent(getFelettParm("FELETT_INTERMEDIARIO_SOGGETTO_EMITTENTE" + parmSfx)); fatturaElettronicaHeader.appendChild(soggettoEmittente); } this.rootElement.appendChild(fatturaElettronicaHeader); Element FatturaElettronicaBody = this.dom.createElement("FatturaElettronicaBody"); Element datiGenerali = this.dom.createElement("DatiGenerali"); Element datiGeneraliDocumento = this.dom.createElement("DatiGeneraliDocumento"); e = this.dom.createElement("TipoDocumento"); e.setTextContent(bean.getFETipoDocumento()); datiGeneraliDocumento.appendChild(e); e = this.dom.createElement("Divisa"); e.setTextContent(bean.getFEDivisa()); datiGeneraliDocumento.appendChild(e); e = this.dom.createElement("Data"); e.setTextContent(df.format(bean.getFeDataDocumento())); datiGeneraliDocumento.appendChild(e); e = this.dom.createElement("Numero"); e.setTextContent(bean.getFENumeroDocumento()); datiGeneraliDocumento.appendChild(e); if (bean.getFeDatiRitenuta() != null) { Element datiRitenuta = this.dom.createElement("DatiRitenuta"); datiGeneraliDocumento.appendChild(datiRitenuta); } if (bean.getFeBolloVirtuale() != null && !bean.getFeBolloVirtuale().isEmpty()) { Element datiBollo = this.dom.createElement("DatiBollo"); e = this.dom.createElement("BolloVirtuale"); e.setTextContent(bean.getFeBolloVirtuale()); datiBollo.appendChild(e); e = this.dom.createElement("ImportoBollo"); e.setTextContent(nfe.format(bean.getFEImportoBollo())); datiBollo.appendChild(e); datiGeneraliDocumento.appendChild(datiBollo); } Vectumerator vecSM = bean.getFEScontoMaggiorazione(); if (vecSM != null) while (vecSM.hasMoreElements()) { FEScontoMaggiorazioneInterface rowSCMAG = (FEScontoMaggiorazioneInterface)vecSM.nextElement(); Element scontoMaggiorazione = this.dom.createElement("ScontoMaggiorazione"); if (",SC,MG,".indexOf("," + rowSCMAG.getFETipoScontoMagg() + ",") < 0) errMsg.append("Dati Generali Tipo sconto maggiorazione diverso da +,SC,MG,\n"); if ((rowSCMAG.getFEPercentualeScontoMagg() == 0.0D && rowSCMAG.getFEImportoScontoMagg() == 0.0D) || ( rowSCMAG.getFEPercentualeScontoMagg() > 0.0D && rowSCMAG.getFEImportoScontoMagg() > 0.0D)) errMsg.append("Dati Generali sconto maggiorazione percentuale e/o Importo non valido\n"); e = this.dom.createElement("Tipo"); e.setTextContent(rowSCMAG.getFETipoScontoMagg()); scontoMaggiorazione.appendChild(e); if (rowSCMAG.getFEPercentualeScontoMagg() > 0.0D) { e = this.dom.createElement("Percentuale"); e.setTextContent(nfe.format(rowSCMAG.getFEPercentualeScontoMagg())); scontoMaggiorazione.appendChild(e); } else { e = this.dom.createElement("Importo"); e.setTextContent(nfe.format(rowSCMAG.getFEImportoScontoMagg())); scontoMaggiorazione.appendChild(e); } datiGeneraliDocumento.appendChild(scontoMaggiorazione); } if (bean.getFEImportoTotaleDocumento() == 0.0D) warnMsg.append("Dati Generali Importo totale documento a zero\n"); e = this.dom.createElement("ImportoTotaleDocumento"); e.setTextContent(nfe.format(bean.getFEImportoTotaleDocumento())); datiGeneraliDocumento.appendChild(e); if (bean.getFEArrotondamento() > 0.0D) { e = this.dom.createElement("Arrotondamento"); e.setTextContent(nfe.format(bean.getFEArrotondamento())); datiGeneraliDocumento.appendChild(e); } if (bean.getFECausale() != null && !bean.getFECausale().isEmpty()) { e = this.dom.createElement("Causale"); e.setTextContent(convertStringToXmlString(bean.getFECausale(), 200)); datiGeneraliDocumento.appendChild(e); } if (bean.isFEArt73()) { e = this.dom.createElement("Art73"); e.setTextContent("SI"); datiGeneraliDocumento.appendChild(e); } datiGenerali.appendChild(datiGeneraliDocumento); if ((bean.getFEDatiOrdineAcquistoCodiceCIG() != null && !bean.getFEDatiOrdineAcquistoCodiceCIG().isEmpty()) || ( bean.getFEDatiOrdineAcquistoIdDocumento() != null && !bean.getFEDatiOrdineAcquistoIdDocumento().isEmpty())) { Element datiOrdineAcquisto = this.dom.createElement("DatiOrdineAcquisto"); if (bean.getFEDatiOrdineAcquistoIdDocumento() != null && !bean.getFEDatiOrdineAcquistoIdDocumento().isEmpty()) { e = this.dom.createElement("IdDocumento"); e.setTextContent(bean.getFEDatiOrdineAcquistoIdDocumento()); datiOrdineAcquisto.appendChild(e); } if (bean.getFEDatiOrdineAcquistoData() != null) { e = this.dom.createElement("Data"); e.setTextContent(df.format(bean.getFEDatiOrdineAcquistoData())); datiOrdineAcquisto.appendChild(e); } if (bean.getFEDatiOrdineAcquistoRifNumLinea() != null && !bean.getFEDatiOrdineAcquistoRifNumLinea().isEmpty()) { e = this.dom.createElement("RiferimentoNumeroLinea"); e.setTextContent(bean.getFEDatiOrdineAcquistoRifNumLinea()); datiOrdineAcquisto.appendChild(e); } if (bean.getFEDatiOrdineAcquistoNumItem() != null && !bean.getFEDatiOrdineAcquistoNumItem().isEmpty()) { e = this.dom.createElement("NumItem"); e.setTextContent(bean.getFEDatiOrdineAcquistoNumItem()); datiOrdineAcquisto.appendChild(e); } if (bean.getFEDatiOrdineAcquistoCodCommessaConv() != null && !bean.getFEDatiOrdineAcquistoCodCommessaConv().isEmpty()) { e = this.dom.createElement("CodiceCommessaConvenzione"); e.setTextContent(bean.getFEDatiOrdineAcquistoCodCommessaConv()); datiOrdineAcquisto.appendChild(e); } if (bean.getFEDatiOrdineAcquistoCodiceCUP() != null && !bean.getFEDatiOrdineAcquistoCodiceCUP().isEmpty()) { e = this.dom.createElement("CodiceCUP"); e.setTextContent(bean.getFEDatiOrdineAcquistoCodiceCUP()); datiOrdineAcquisto.appendChild(e); } if (bean.getFEDatiOrdineAcquistoCodiceCIG() != null && !bean.getFEDatiOrdineAcquistoCodiceCIG().isEmpty()) { e = this.dom.createElement("CodiceCIG"); e.setTextContent(bean.getFEDatiOrdineAcquistoCodiceCIG()); datiOrdineAcquisto.appendChild(e); } datiGenerali.appendChild(datiOrdineAcquisto); } if (bean.getFEDatiSALRiferimentoFase() != null && !bean.getFEDatiSALRiferimentoFase().isEmpty()) { Element datiSAL = this.dom.createElement("DatiSAL"); e = this.dom.createElement("RiferimentoFase"); e.setTextContent(bean.getFEDatiSALRiferimentoFase()); datiSAL.appendChild(e); datiGenerali.appendChild(datiSAL); } Vectumerator vecDDDT = bean.getFEDatiDDT(); if (vecDDDT != null) while (vecDDDT.hasMoreElements()) { FEDatiDDT rowDDT = (FEDatiDDT)vecDDDT.nextElement(); Element datiDDT = this.dom.createElement("DatiDDT"); e = this.dom.createElement("NumeroDDT"); e.setTextContent(rowDDT.getNumero()); datiDDT.appendChild(e); e = this.dom.createElement("DataDDT"); e.setTextContent(df.format(rowDDT.getData())); datiDDT.appendChild(e); if (rowDDT.getNumLinea() > 0L) { e = this.dom.createElement("RiferimentoNumeroLinea"); e.setTextContent(nfe.format(rowDDT.getNumLinea())); datiDDT.appendChild(e); } datiGenerali.appendChild(datiDDT); } if (bean.getFEDatiTrasporto() != null) { Element datiTrasporto = this.dom.createElement("DatiTrasporto"); FEDatiTrasportoInterface feDatiTrasporto = bean.getFEDatiTrasporto(); if (feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFEPartitaIva() != null && !feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFEPartitaIva().isEmpty() && (( feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFEDenominazione() != null && !feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFEDenominazione().isEmpty()) || ( feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFENome() != null && !feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFENome().isEmpty()))) { Element datiAnagraficiVettore = this.dom.createElement("DatiAnagraficiVettore"); Element element3 = this.dom.createElement("IdFiscaleIVA"); e = this.dom.createElement("IdPaese"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFEPaese()); element3.appendChild(e); e = this.dom.createElement("IdCodice"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFEPartitaIva()); element3.appendChild(e); datiAnagraficiVettore.appendChild(element3); e = this.dom.createElement("CodiceFiscale"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFECodiceFiscale()); datiAnagraficiVettore.appendChild(e); Element anagraficaVettore = this.dom.createElement("Anagrafica"); if (feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFEDenominazione() != null && !feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFEDenominazione().isEmpty()) { e = this.dom.createElement("Denominazione"); e.setTextContent(convertStringToXmlString( feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFEDenominazione(), 80)); anagraficaVettore.appendChild(e); } else { e = this.dom.createElement("Nome"); e.setTextContent(convertStringToXmlString( feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFENome(), 60)); anagraficaVettore.appendChild(e); e = this.dom.createElement("Cognome"); e.setTextContent(convertStringToXmlString( feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFECognome(), 60)); anagraficaVettore.appendChild(e); if (feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFETitolo() != null && !feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFETitolo().isEmpty()) { e = this.dom.createElement("Titolo"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFETitolo()); anagraficaVettore.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFECodEORI() != null && !feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFECodEORI().isEmpty()) { e = this.dom.createElement("CodEORI"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoAnagraficiVettore().getFECodEORI()); anagraficaVettore.appendChild(e); } } datiAnagraficiVettore.appendChild(anagraficaVettore); if (feDatiTrasporto.getFEDatiTrasportoInterfaceNumeroLicenzaGuida() != null && !feDatiTrasporto.getFEDatiTrasportoInterfaceNumeroLicenzaGuida().isEmpty()) { e = this.dom.createElement("NumeroLicenzaGuida"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoInterfaceNumeroLicenzaGuida()); anagraficaVettore.appendChild(e); } datiTrasporto.appendChild(datiAnagraficiVettore); } if (feDatiTrasporto.getFEDatiTrasportoMezzoTrasporto() != null && !feDatiTrasporto.getFEDatiTrasportoMezzoTrasporto().isEmpty()) { e = this.dom.createElement("MezzoTrasporto"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoMezzoTrasporto()); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoCausaleTrasporto() != null && !feDatiTrasporto.getFEDatiTrasportoCausaleTrasporto().isEmpty()) { e = this.dom.createElement("CausaleTrasporto"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoCausaleTrasporto()); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoNumeroColli() > 0L) { e = this.dom.createElement("NumeroColli"); e.setTextContent(String.valueOf(feDatiTrasporto.getFEDatiTrasportoNumeroColli())); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoDescrizione() != null && !feDatiTrasporto.getFEDatiTrasportoDescrizione().isEmpty()) { e = this.dom.createElement("Descrizione"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoDescrizione()); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoUnitaMisuraPeso() != null && !feDatiTrasporto.getFEDatiTrasportoUnitaMisuraPeso().isEmpty() && ( feDatiTrasporto.getFEDatiTrasportoPesoLordo() > 0.0D || feDatiTrasporto.getFEDatiTrasportoPesoLordo() > 0.0D)) { e = this.dom.createElement("UnitaMisuraPeso"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoUnitaMisuraPeso()); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoPesoLordo() > 0.0D) { e = this.dom.createElement("PesoLordo"); e.setTextContent(nfe.format(feDatiTrasporto.getFEDatiTrasportoPesoLordo())); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoPesoNetto() > 0.0D) { e = this.dom.createElement("PesoNetto"); e.setTextContent(nfe.format(feDatiTrasporto.getFEDatiTrasportoPesoNetto())); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoDataOraRitiro() != null) { e = this.dom.createElement("DataOraRitiro"); e.setTextContent(dTimef.format(feDatiTrasporto.getFEDatiTrasportoDataOraRitiro())); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoDataInizioTrasporto() != null) { e = this.dom.createElement("DataInizioTrasporto"); e.setTextContent(df.format(feDatiTrasporto.getFEDatiTrasportoDataInizioTrasporto())); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoTipoResa() != null && !feDatiTrasporto.getFEDatiTrasportoTipoResa().isEmpty()) { e = this.dom.createElement("TipoResa"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoTipoResa()); datiTrasporto.appendChild(e); } if (feDatiTrasporto.getFEDatiTrasportoIndirizzoResa() != null) { Element indirizzoResa = this.dom.createElement("IndirizzoResa"); if (feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFEIndirizzo() != null && !feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFEIndirizzo().isEmpty()) { e = this.dom.createElement("Indirizzo"); e.setTextContent(convertStringToXmlString( feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFEIndirizzo(), 60)); datiTrasporto.appendChild(e); } else { errMsg.append("Dati Trasporto Indirizzo Resa: indirizzo\n"); } if (feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFENumeroCivico() != null && !feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFENumeroCivico().isEmpty()) { e = this.dom.createElement("NumeroCivico"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFENumeroCivico()); datiTrasporto.appendChild(e); } else { errMsg.append("Dati Trasporto Indirizzo Resa: Numero Civico\n"); } if (feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFECAP() != null && !feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFECAP().isEmpty()) { e = this.dom.createElement("CAP"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFECAP()); datiTrasporto.appendChild(e); } else { errMsg.append("Dati Trasporto Indirizzo Resa: CAP\n"); } if (feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFEComune() != null && !feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFEComune().isEmpty()) { e = this.dom.createElement("Comune"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFEComune()); datiTrasporto.appendChild(e); } else { errMsg.append("Dati Trasporto Indirizzo Resa: Comune\n"); } if (feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFEProvincia() != null && !feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFEProvincia().isEmpty()) { e = this.dom.createElement("Provincia"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFEProvincia().toUpperCase()); datiTrasporto.appendChild(e); } else { errMsg.append("Dati Trasporto Indirizzo Resa: Provincia\n"); } if (feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFENazione() != null && !feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFENazione().isEmpty()) { e = this.dom.createElement("Nazione"); e.setTextContent(feDatiTrasporto.getFEDatiTrasportoIndirizzoResa().getFENazione().toUpperCase()); datiTrasporto.appendChild(e); } else { errMsg.append("Dati Trasporto Indirizzo Resa: Nazione\n"); } datiTrasporto.appendChild(indirizzoResa); } if (feDatiTrasporto.getFEDatiTrasportoDataOraConsegna() != null) { e = this.dom.createElement("DataOraConsegna"); e.setTextContent(dTimef.format(feDatiTrasporto.getFEDatiTrasportoDataOraConsegna())); datiTrasporto.appendChild(e); } datiGenerali.appendChild(datiTrasporto); } FatturaElettronicaBody.appendChild(datiGenerali); Element datiBeniServizi = this.dom.createElement("DatiBeniServizi"); Vectumerator vecDL = bean.getFEDettaglioLinee(); Vectumerator vecDLA = bean.getFEDettaglioLineeAltre(); if ((vecDL != null && vecDL.hasMoreElements()) || (vecDLA != null && vecDLA.hasMoreElements())) { Vectumerator> vectorDL = new Vectumerator(); if (vecDL != null) vectorDL.add(vecDL); if (vecDLA != null) vectorDL.add(vecDLA); int numLinea = 0; while (vectorDL.hasMoreElements()) { Vectumerator currentVecDL = (Vectumerator)vectorDL.nextElement(); while (currentVecDL.hasMoreElements()) { FEDettaglioLineeInterface rowDettLinee = (FEDettaglioLineeInterface)currentVecDL.nextElement(); Element dettaglioLinee = this.dom.createElement("DettaglioLinee"); numLinea++; e = this.dom.createElement("NumeroLinea"); e.setTextContent(String.valueOf(numLinea)); dettaglioLinee.appendChild(e); if (rowDettLinee.getFETipoCessionePrestazione() != null && !rowDettLinee.getFETipoCessionePrestazione().isEmpty()) if (",SC,PR,AB,AC," .indexOf("," + rowDettLinee.getFETipoCessionePrestazione() + ",") >= 0) { e = this.dom.createElement("TipoCessionePrestazione"); e.setTextContent(rowDettLinee.getFETipoCessionePrestazione()); dettaglioLinee.appendChild(e); } else { errMsg.append("Dati Beni Servizi->DettaglioLinee: TipoCessionePrestazione diverso da ,SC,PR,AB,AC,\n"); } if (rowDettLinee.getFECodiceArticoloValore() != null && !rowDettLinee.getFECodiceArticoloValore().isEmpty()) { Element codiceArticolo = this.dom.createElement("CodiceArticolo"); if (rowDettLinee.getFECodiceArticoloTipo() != null && !rowDettLinee.getFECodiceArticoloTipo().isEmpty()) { e = this.dom.createElement("CodiceTipo"); e.setTextContent(convertStringToXmlString(rowDettLinee.getFECodiceArticoloTipo(), 35)); codiceArticolo.appendChild(e); } e = this.dom.createElement("CodiceValore"); e.setTextContent(convertStringToXmlString(rowDettLinee.getFECodiceArticoloValore(), 35)); codiceArticolo.appendChild(e); dettaglioLinee.appendChild(codiceArticolo); } if (rowDettLinee.getFEDescrizione() != null && !rowDettLinee.getFEDescrizione().isEmpty()) { e = this.dom.createElement("Descrizione"); e.setTextContent(convertStringToXmlString(rowDettLinee.getFEDescrizione(), 1000)); dettaglioLinee.appendChild(e); } else { errMsg.append("Dati Beni Servizi->DettaglioLinee: Descrizione\n"); } if (rowDettLinee.getFEQuantita() > 0.0D) { e = this.dom.createElement("Quantita"); e.setTextContent(nfe.format(rowDettLinee.getFEQuantita())); dettaglioLinee.appendChild(e); } else { errMsg.append("Dati Beni Servizi->DettaglioLinee: Quantita<=0\n"); } if (rowDettLinee.getFEUnitaMisura() != null && !rowDettLinee.getFEUnitaMisura().isEmpty()) { e = this.dom.createElement("UnitaMisura"); e.setTextContent(rowDettLinee.getFEUnitaMisura()); dettaglioLinee.appendChild(e); } if (rowDettLinee.getFEDataInizioPeriodo() != null) { e = this.dom.createElement("dataInizioPeriodo"); e.setTextContent(df.format(rowDettLinee.getFEDataInizioPeriodo())); dettaglioLinee.appendChild(e); } if (rowDettLinee.getFEDataFinePeriodo() != null) { e = this.dom.createElement("DataFinePeriodo"); e.setTextContent(df.format(rowDettLinee.getFEDataFinePeriodo())); dettaglioLinee.appendChild(e); } if (rowDettLinee.getFEPrezzoUnitario() == 0.0D) warnMsg.append("Dati Beni Servizi->DettaglioLinee: Prezzo Unitario=0\n"); e = this.dom.createElement("PrezzoUnitario"); e.setTextContent(nfe.format(rowDettLinee.getFEPrezzoUnitario())); dettaglioLinee.appendChild(e); Vectumerator vectumerator = rowDettLinee.getFEScontoMaggiorazione(); if (vectumerator != null) while (vectumerator.hasMoreElements()) { FEScontoMaggiorazioneInterface rowScontoMaggiorazione = (FEScontoMaggiorazioneInterface)vectumerator.nextElement(); Element scontoMaggiorazione = this.dom.createElement("ScontoMaggiorazione"); if (",SC,MG," .indexOf("," + rowScontoMaggiorazione.getFETipoScontoMagg() + ",") >= 0) { e = this.dom.createElement("Tipo"); e.setTextContent(rowScontoMaggiorazione.getFETipoScontoMagg()); scontoMaggiorazione.appendChild(e); } else { errMsg.append("Dati Beni Servizi->DettaglioLinee>ScontoMaggiorazione: Tipo diverso da ,SC,MG,\n"); } if (rowScontoMaggiorazione.getFEPercentualeScontoMagg() <= 0.0D && rowScontoMaggiorazione.getFEImportoScontoMagg() <= 0.0D) { errMsg.append("Dati Beni Servizi->DettaglioLinee->ScontoMaggiorazione: percentuale o importo non impostato<=0\n"); } else if (rowScontoMaggiorazione.getFEPercentualeScontoMagg() > 0.0D) { e = this.dom.createElement("Percentuale"); e.setTextContent( nfe.format(rowScontoMaggiorazione.getFEPercentualeScontoMagg())); scontoMaggiorazione.appendChild(e); } else { e = this.dom.createElement("Importo"); e.setTextContent(nfe.format(rowScontoMaggiorazione.getFEImportoScontoMagg())); scontoMaggiorazione.appendChild(e); } dettaglioLinee.appendChild(scontoMaggiorazione); } if (rowDettLinee.getFEPrezzoTotale() == 0.0D) warnMsg.append("Dati Beni Servizi->DettaglioLinee: Prezzo Totale=0\n"); e = this.dom.createElement("PrezzoTotale"); e.setTextContent(nfe.format(rowDettLinee.getFEPrezzoTotale())); dettaglioLinee.appendChild(e); e = this.dom.createElement("AliquotaIVA"); e.setTextContent(nfe.format(rowDettLinee.getFEAliquotaIva())); dettaglioLinee.appendChild(e); if (rowDettLinee.getFERitenuta() > 0.0D) { e = this.dom.createElement("Ritenuta"); e.setTextContent(nfe.format(rowDettLinee.getFERitenuta())); dettaglioLinee.appendChild(e); } if (rowDettLinee.getFENatura() != null && !rowDettLinee.getFENatura().isEmpty()) { if (rowDettLinee.getFEAliquotaIva() == 0.0D && ",N1,N2.1,N2.2,N3.1,N3.2,N3.3,N3.4,N3.5,N3.6,N4,N5,N6.1,N6.2,N6.3,N6.4,N6.5,N6.6,N6.7,N6.8,N6.9,N7," .indexOf("," + rowDettLinee.getFENatura() + ",") >= 0) { e = this.dom.createElement("Natura"); e.setTextContent(rowDettLinee.getFENatura()); dettaglioLinee.appendChild(e); } else { errMsg.append("Dati Beni Servizi->DettaglioLinee linea " + numLinea + ": Natura errata(,N1,N2.1,N2.2,N3.1,N3.2,N3.3,N3.4,N3.5,N3.6,N4,N5,N6.1,N6.2,N6.3,N6.4,N6.5,N6.6,N6.7,N6.8,N6.9,N7,) o aliquota iva >0\n"); } } else if (rowDettLinee.getFEAliquotaIva() == 0.0D) { errMsg.append("Dati Beni Servizi->DettaglioLinee linea " + numLinea + ": Natura non impostata con aliquota iva = 0\n"); } if (rowDettLinee.getFERiferimentoAmministrazione() != null && !rowDettLinee.getFERiferimentoAmministrazione().isEmpty()) { e = this.dom.createElement("RiferimentoAmministrazione"); e.setTextContent(nfe.format(rowDettLinee.getFERiferimentoAmministrazione())); dettaglioLinee.appendChild(e); } if (bean.getFERiferimentoTipoDato() != null && !bean.getFERiferimentoTipoDato().isEmpty() && bean.getFERiferimentoTesto() != null && !bean.getFERiferimentoTesto().isEmpty() && bean.getFERiferimentoData() != null) if ("INTENTO,NUMSCONTR".indexOf(bean.getFERiferimentoTipoDato()) >= 0) { Element AltriDatiGestionali = this.dom.createElement("AltriDatiGestionali"); e = this.dom.createElement("TipoDato"); e.setTextContent(bean.getFERiferimentoTipoDato()); AltriDatiGestionali.appendChild(e); e = this.dom.createElement("RiferimentoTesto"); e.setTextContent(bean.getFERiferimentoTesto()); AltriDatiGestionali.appendChild(e); e = this.dom.createElement("RiferimentoNumero"); e.setTextContent(nfe.format(bean.getFERiferimentoNumero())); AltriDatiGestionali.appendChild(e); e = this.dom.createElement("RiferimentoData"); e.setTextContent(df.format(bean.getFERiferimentoData())); AltriDatiGestionali.appendChild(e); dettaglioLinee.appendChild(AltriDatiGestionali); } else { errMsg.append("Dati Beni Servizi->AltriDatiGestionali linea " + numLinea + ": tipo dato " + bean.getFERiferimentoTipoDato() + " non valido(INTENTO,NUMSCONTR) \n"); } datiBeniServizi.appendChild(dettaglioLinee); } } } else { errMsg.append("Dati Beni e servizi: Non ci sono Dettaglio Linee!\n"); } Vectumerator vecDR = bean.getFEDatiRiepilogo(); if (vecDR != null && vecDR.hasMoreElements()) { while (vecDR.hasMoreElements()) { FEDatiRiepilogoInterface rowDatiRiepilogo = (FEDatiRiepilogoInterface)vecDR.nextElement(); Element datiRiepilogo = this.dom.createElement("DatiRiepilogo"); e = this.dom.createElement("AliquotaIVA"); e.setTextContent(nfe.format(rowDatiRiepilogo.getFEAliquotaIva())); datiRiepilogo.appendChild(e); if (rowDatiRiepilogo.getFENatura() != null && !rowDatiRiepilogo.getFENatura().isEmpty()) if (rowDatiRiepilogo.getFEAliquotaIva() == 0.0D && ",N1,N2.1,N2.2,N3.1,N3.2,N3.3,N3.4,N3.5,N3.6,N4,N5,N6.1,N6.2,N6.3,N6.4,N6.5,N6.6,N6.7,N6.8,N6.9,N7," .indexOf("," + rowDatiRiepilogo.getFENatura() + ",") >= 0) { e = this.dom.createElement("Natura"); e.setTextContent(rowDatiRiepilogo.getFENatura()); datiRiepilogo.appendChild(e); } else { errMsg.append("Dati Beni Servizi->DatiRiepilogo: Natura errata(,N1,N2.1,N2.2,N3.1,N3.2,N3.3,N3.4,N3.5,N3.6,N4,N5,N6.1,N6.2,N6.3,N6.4,N6.5,N6.6,N6.7,N6.8,N6.9,N7,) o aliquota iva >0\n"); } if (rowDatiRiepilogo.getFESpeseAccessorie() > 0.0D) { e = this.dom.createElement("SpeseAccessorie"); e.setTextContent(nfe.format(rowDatiRiepilogo.getFESpeseAccessorie())); datiRiepilogo.appendChild(e); } if (rowDatiRiepilogo.getFEArrotondamento() > 0.0D) { e = this.dom.createElement("Arrotondamento"); e.setTextContent(nfe.format(rowDatiRiepilogo.getFEArrotondamento())); datiRiepilogo.appendChild(e); } e = this.dom.createElement("ImponibileImporto"); e.setTextContent(nfe.format(rowDatiRiepilogo.getFEImponibileImporto())); datiRiepilogo.appendChild(e); e = this.dom.createElement("Imposta"); e.setTextContent(nfe.format(rowDatiRiepilogo.getFEImposta())); datiRiepilogo.appendChild(e); if (rowDatiRiepilogo.getFEEsigibilitaIva() != null && !rowDatiRiepilogo.getFEEsigibilitaIva().isEmpty()) if (",I,D,S,".indexOf("," + rowDatiRiepilogo.getFEEsigibilitaIva() + ",") >= 0) { if (rowDatiRiepilogo.getFEEsigibilitaIva().equals("S") && rowDatiRiepilogo.equals("N6")) { errMsg.append("Dati Beni Servizi->Dati Riepilogo: Esigibilita IVA impostata a Scissione ma la natura non e' inversione contabile (N6)\n"); } else { e = this.dom.createElement("EsigibilitaIVA"); e.setTextContent(rowDatiRiepilogo.getFEEsigibilitaIva()); datiRiepilogo.appendChild(e); } } else { errMsg.append("Dati Beni Servizi->Dati Riepilogo: Esigibilita IVA errata(,I,D,S,)\n"); } if (rowDatiRiepilogo.getFERiferimentoNormativo() != null && !rowDatiRiepilogo.getFERiferimentoNormativo().isEmpty()) { e = this.dom.createElement("RiferimentoNormativo"); e.setTextContent(convertStringToXmlString(rowDatiRiepilogo.getFERiferimentoNormativo(), 100)); datiRiepilogo.appendChild(e); } datiBeniServizi.appendChild(datiRiepilogo); } } else { errMsg.append("Dati Beni e servizi: Non ci sono dettagli di riepilogo!\n"); } FatturaElettronicaBody.appendChild(datiBeniServizi); Vectumerator vecDP = bean.getFEDatiPagamento(); if (vecDP != null) while (vecDP.hasMoreElements()) { FEDatiPagamento rowDatiPagamento = (FEDatiPagamento)vecDP.nextElement(); Element datiPagamento = this.dom.createElement("DatiPagamento"); if (",TP01,TP02,TP03,".indexOf("," + rowDatiPagamento.getCondizioniPagamento() + ",") < 0) errMsg.append("Dati Pagamento: Condizioni pagamento diversi da +,TP01,TP02,TP03,\n"); e = this.dom.createElement("CondizioniPagamento"); e.setTextContent(rowDatiPagamento.getCondizioniPagamento()); datiPagamento.appendChild(e); Vectumerator vecDettaglioPagamento = rowDatiPagamento.getVecDettaglioPagamento(); if (vecDettaglioPagamento.getTotNumberOfRecords() == 0) errMsg.append("Dati Pagamento: Non ci sono dettagli Pagamenti\n"); while (vecDettaglioPagamento.hasMoreElements()) { FEDettaglioPagamento rowDettaglioPagamento = (FEDettaglioPagamento)vecDettaglioPagamento.nextElement(); Element dettaglioPagamento = this.dom.createElement("DettaglioPagamento"); if (!rowDettaglioPagamento.getBeneficiario().isEmpty()) { e = this.dom.createElement("Beneficiario"); e.setTextContent(convertStringToXmlString(rowDettaglioPagamento.getBeneficiario(), 200)); dettaglioPagamento.appendChild(e); } if (",MP01,MP02,MP03,MP04,MP05,MP06,MP07,MP08,MP00,MP10,MP11,MP12,MP13,MP14,MP15,MP16,MP17,MP18,MP19,MP20,MP21,MP22,".indexOf("," + rowDettaglioPagamento.getModalitaPagamento() + ",") < 0) errMsg.append("Dati Pagamento -> Dettaglio Pagamento: Modalita pagamento diversi da +,MP01,MP02,MP03,MP04,MP05,MP06,MP07,MP08,MP00,MP10,MP11,MP12,MP13,MP14,MP15,MP16,MP17,MP18,MP19,MP20,MP21,MP22,\n"); e = this.dom.createElement("ModalitaPagamento"); e.setTextContent(rowDettaglioPagamento.getModalitaPagamento()); dettaglioPagamento.appendChild(e); if (rowDettaglioPagamento.getDataScadenzaPagamento() != null) { e = this.dom.createElement("DataScadenzaPagamento"); e.setTextContent(df.format(rowDettaglioPagamento.getDataScadenzaPagamento())); dettaglioPagamento.appendChild(e); } if (rowDettaglioPagamento.getImportoPagamento() < 0.0D) errMsg.append("Dati Pagamento -> Dettaglio Pagamento: importo pagamento <=0: " + rowDettaglioPagamento.getImportoPagamento() + "\n"); e = this.dom.createElement("ImportoPagamento"); e.setTextContent(nfe.format(rowDettaglioPagamento.getImportoPagamento())); dettaglioPagamento.appendChild(e); if (!rowDettaglioPagamento.getIstitutoFinanziario().isEmpty()) { e = this.dom.createElement("IstitutoFinanziario"); e.setTextContent(rowDettaglioPagamento.getIstitutoFinanziario()); dettaglioPagamento.appendChild(e); } if (!rowDettaglioPagamento.getIBAN().isEmpty()) { e = this.dom.createElement("IBAN"); e.setTextContent(rowDettaglioPagamento.getIBAN()); dettaglioPagamento.appendChild(e); } if (!rowDettaglioPagamento.getABI().isEmpty()) { e = this.dom.createElement("ABI"); e.setTextContent(rowDettaglioPagamento.getABI()); dettaglioPagamento.appendChild(e); } if (!rowDettaglioPagamento.getCAB().isEmpty()) { e = this.dom.createElement("CAB"); e.setTextContent(rowDettaglioPagamento.getCAB()); dettaglioPagamento.appendChild(e); } if (!rowDettaglioPagamento.getBIC().isEmpty()) { e = this.dom.createElement("BIC"); e.setTextContent(rowDettaglioPagamento.getBIC()); dettaglioPagamento.appendChild(e); } datiPagamento.appendChild(dettaglioPagamento); } FatturaElettronicaBody.appendChild(datiPagamento); } if (bean.getFEAllegatiInterface() != null) { Element allegati = this.dom.createElement("Allegati"); if (bean.getFEAllegatiInterface().getFENomeAttachment() != null && !bean.getFEAllegatiInterface().getFENomeAttachment().isEmpty()) { e = this.dom.createElement("NomeAttachment"); e.setTextContent(bean.getFEAllegatiInterface().getFENomeAttachment()); allegati.appendChild(e); } else { errMsg.append("Allegati: Nome Attachment\n"); } if (bean.getFEAllegatiInterface().getFEAlgoritmoCompressione() != null && !bean.getFEAllegatiInterface().getFEAlgoritmoCompressione().isEmpty()) { e = this.dom.createElement("AlgoritmoCompressione"); e.setTextContent(bean.getFEAllegatiInterface().getFEAlgoritmoCompressione()); allegati.appendChild(e); } else { errMsg.append("Allegati: Algoritmo Compressione\n"); } if (bean.getFEAllegatiInterface().getFEFormatoAttachment() != null && !bean.getFEAllegatiInterface().getFEFormatoAttachment().isEmpty()) { e = this.dom.createElement("FormatoAttachment"); e.setTextContent(bean.getFEAllegatiInterface().getFEFormatoAttachment()); allegati.appendChild(e); } else { errMsg.append("Allegati: Formato Attachment\n"); } if (bean.getFEAllegatiInterface().getFEDescrizioneAttachment() != null && !bean.getFEAllegatiInterface().getFEDescrizioneAttachment().isEmpty()) { e = this.dom.createElement("DescrizioneAttachment"); e.setTextContent(bean.getFEAllegatiInterface().getFEDescrizioneAttachment()); allegati.appendChild(e); } else { errMsg.append("Allegati: Descrizione Attachment\n"); } if (bean.getFEAllegatiInterface().getFEFileAttachment() != null && !bean.getFEAllegatiInterface().getFEFileAttachment().isEmpty()) { if (new File(bean.getFEAllegatiInterface().getFEFileAttachment()).exists()) { e = this.dom.createElement("FileAttachment"); e.setTextContent( DBAdapter.getBase64StringFromFile(bean.getFEAllegatiInterface().getFEFileAttachment())); allegati.appendChild(e); } else { errMsg.append("Allegati: File Attachment non trovato!!\n"); } } else { errMsg.append("Allegati: File Attachment\n"); } FatturaElettronicaBody.appendChild(allegati); } this.rootElement.appendChild(FatturaElettronicaBody); this.dom.appendChild(this.rootElement); Node pi = this.dom.createProcessingInstruction("xml-stylesheet", " type=\"text/xsl\" href=\"fatturaordinaria_v1.2.1.xsl\""); this.dom.insertBefore(pi, this.rootElement); if (warnMsg.length() > 0) rp.setInfoMsg(bean.getFENumeroDocumento() + ": " + bean.getFENumeroDocumento()); if (errMsg.length() > 0) { rp.setStatus(false); rp.setMsg(bean.getFENumeroDocumento() + ": " + bean.getFENumeroDocumento()); return rp; } Transformer tr = TransformerFactory.newInstance().newTransformer(); tr.setOutputProperty("indent", "yes"); tr.setOutputProperty("method", "xml"); tr.setOutputProperty("encoding", "UTF-8"); tr.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); File xmlFile = new File(getFullFileXml(bean, parmSfx)); String theDir = xmlFile.getAbsolutePath().substring(0, xmlFile.getAbsolutePath().lastIndexOf(File.separator) + 1); DBAdapter.checkAndMakeDir(theDir); tr.transform(new DOMSource(this.dom), new StreamResult(new FileOutputStream(new File(getFullFileXml(bean, parmSfx))))); rp.setStatus(true); this.isBuildOk = true; bean.setFEAggiornaTmstFileXml(); } catch (ParserConfigurationException|javax.xml.transform.TransformerFactoryConfigurationError|java.io.FileNotFoundException|javax.xml.transform.TransformerException pce) { rp.setStatus(false); rp.setMsg("BuildXml: Error trying to instantiate DocumentBuilder " + String.valueOf(pce)); System.out.println(rp.getMsg()); } return rp; } public ResParm getXmlFile(boolean fullPath, String parmSfx) { ResParm rp = new ResParm(); StringBuilder warnMsg = new StringBuilder(); if (getVecFatture() == null) { StatusMsg.updateMsgByTag(this.fattura.getApFull(), "Xml fatt. elett.", "Documento " + getFattura().getFENumeroDocumento()); rp = buildOneXml(getFattura(), parmSfx); if (rp.getStatus()) if (fullPath) { rp.setMsg(getFullFileXml(getFattura(), parmSfx)); } else { rp.setMsg(getFileXmlToDocbase(getFattura(), parmSfx)); } } else { Calendar cal = Calendar.getInstance(); String timeInMils = String.valueOf(cal.getTimeInMillis()); String zipFIle = getFattura().getDocBase() + getFattura().getDocBase() + getFattura().getPathTmp() + ".zip"; String tempDir = getFattura().getDocBase() + getFattura().getDocBase() + getFattura().getPathTmp() + "/"; DBAdapter.checkAndMakeDir(tempDir); try { while (this.vecFatture.hasMoreElements()) { FatturaElettronicaInterface row = (FatturaElettronicaInterface)this.vecFatture.nextElement(); StatusMsg.updateMsgByTag(this.fattura.getApFull(), "Xml fatt. elett.", "File zip: Documento " + row.getFENumeroDocumento()); if (row.isFatturaElettronicaGenerabile()) { if (row.getTmstInvioXml() == null) { rp = buildOneXml(row, parmSfx); } else { rp.setStatus(true); warnMsg.append("Attenzione! Documento " + row.getFENumeroDocumento() + " impostato a File Xml Inviato! XML Non rigenerato"); } } else { rp.setStatus(true); warnMsg.append("Attenzione! Documento " + row.getFENumeroDocumento() + " Xml non generabile!"); } if (rp.getStatus()) { DBAdapter.copyFile(getFullFileXml(row, parmSfx), tempDir + tempDir); warnMsg.append(rp.getInfoMsg()); } } } catch (Exception e) { rp.setStatus(false); rp.setMsg(e); } if (rp.getStatus()) { File dirTmp = new File(tempDir); rp.setStatus(DBAdapter.zipDir(dirTmp, zipFIle, false)); if (rp.getStatus()) rp.setMsg(zipFIle.substring(getFattura().getDocBase().length())); } } StatusMsg.deleteMsgByTag(this.fattura.getApFull(), "Xml fatt. elett."); if (warnMsg.length() > 0) rp.setInfoMsg(warnMsg.toString()); return rp; } public ResParm getXmlFile(boolean fullPath) { return getXmlFile(fullPath, getFattura().getFEParmSfx()); } private String getZipFile() { boolean ok = true; return null; } private SimpleDateFormat getDataFormat() { if (this.df == null) this.df = new SimpleDateFormat("yyyy-MM-dd"); return this.df; } private DecimalFormat getDecimalFormat() { if (this.nf == null) { NumberFormat nf1 = NumberFormat.getNumberInstance(Locale.US); this.nf = (DecimalFormat)nf1; this.nf.applyPattern("###.00"); } return this.nf; } public static ResParm validate730PrecompilateSchema(String xmlPath, String xsdPath) { ResParm rp = new ResParm(true); try { SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); Schema schema = factory.newSchema(new File(xsdPath)); Validator validator = schema.newValidator(); validator.validate(new StreamSource(new File(xmlPath))); } catch (Exception e) { rp.setException(e); rp.setMsg(e.getMessage()); rp.setStatus(false); System.out.println("Exception: " + e.getMessage()); } return rp; } private FatturaElettronicaInterface getFattura() { return this.fattura; } private String getFelettParm(String theKey) { return this.fattura.getApFull().getParm(theKey).getTesto(); } private boolean isFelettParm(String theKey) { return this.fattura.getApFull().getParm(theKey).isTrue(); } private ResParm checkDatiObbligatori(FatturaElettronicaInterface bean, String parmSfx) { ResParm rp = new ResParm(); StringBuilder errMsg = new StringBuilder(); if (!bean.getFEDatiAnagraficiCessionario().getFEPaese().isEmpty() && !bean.getFEDatiAnagraficiCessionario().getFEPaese().equals("IT") && !isFelettParm("FELETT_XML_ESTERO_SI" + parmSfx)) { rp.setStatus(true); return rp; } if (getFelettParm("FELETT_TRASM_ID_PAESE" + parmSfx).isEmpty() || getFelettParm("FELETT_TRASM_ID_PAESE" + parmSfx).length() != 2) errMsg.append("FELETT_TRASM_ID_PAESE" + parmSfx + ": nullo o errato\n"); if (getFelettParm("FELETT_TRASM_ID_CODICE" + parmSfx).isEmpty() || (getFelettParm("FELETT_TRASM_ID_CODICE" + parmSfx).length() != 16 && getFelettParm("FELETT_TRASM_ID_CODICE" + parmSfx).length() != 11)) errMsg.append("FELETT_TRASM_ID_CODICE" + parmSfx + ": nullo o errato\n"); if (bean.getFEProgressivo().length() > 10) errMsg.append("Lunghezza Progressivo invio >10\n"); if (getFelettParm("FELETT_CEDENTE_ID_PAESE" + parmSfx).isEmpty() || getFelettParm("FELETT_CEDENTE_ID_PAESE" + parmSfx).length() != 2) errMsg.append("FELETT_CEDENTE_ID_PAESE" + parmSfx + ": nullo o errato\n"); if (getFelettParm("FELETT_CEDENTE_ID_CODICE" + parmSfx).isEmpty() || ( getFelettParm("FELETT_CEDENTE_ID_CODICE" + parmSfx).length() != 16 && getFelettParm("FELETT_CEDENTE_ID_CODICE" + parmSfx).length() != 11)) errMsg.append("FELETT_CEDENTE_ID_CODICE" + parmSfx + ": nullo o errato\n"); if (getFelettParm("FELETT_CEDENTE_COD_FISC" + parmSfx).isEmpty() || ( getFelettParm("FELETT_CEDENTE_COD_FISC" + parmSfx).length() != 16 && getFelettParm("FELETT_CEDENTE_COD_FISC" + parmSfx).length() != 11)) errMsg.append("FELETT_CEDENTE_COD_FISC" + parmSfx + ": nullo o errato\n"); if (getFelettParm("FELETT_CEDENTE_DENOMINAZIONE" + parmSfx).isEmpty() && getFelettParm("FELETT_CEDENTE_COGNOME" + parmSfx).isEmpty()) errMsg.append("FELETT_CEDENTE_DENOMINAZIONE" + parmSfx + " o FELETT_CEDENTE_COGNOME" + parmSfx + ": nullo o errato\n"); if (getFelettParm("FELETT_CEDENTE_DENOMINAZIONE" + parmSfx).length() > 80) errMsg.append("FELETT_CEDENTE_DENOMINAZIONE" + parmSfx + " > 80 caratteri\n"); if (getFelettParm("FELETT_CEDENTE_COGNOME" + parmSfx).length() > 60) errMsg.append("FELETT_CEDENTE_COGNOME" + parmSfx + " > 60 caratteri\n"); if (getFelettParm("FELETT_CEDENTE_NOME" + parmSfx).length() > 60) errMsg.append("FELETT_CEDENTE_NOME" + parmSfx + " > 60 caratteri\n"); if (!getFelettParm("FELETT_CEDENTE_COD_EORI" + parmSfx).isEmpty() && ( getFelettParm("FELETT_CEDENTE_COD_EORI" + parmSfx).length() < 13 || getFelettParm("FELETT_CEDENTE_COD_EORI" + parmSfx).length() > 17)) errMsg.append("FELETT_CEDENTE_COD_EORI" + parmSfx + ": lunghezza errata (13....17)\n"); if (getFelettParm("FELETT_CEDENTE_REGIME_FISCALE" + parmSfx).isEmpty() || ",RF01,RF02,RF04,RF05R,F06,RF07,RF08,RF09,RF10,RF11,RF12,RF13,RF14,RF15,RF16,RF17,RF18,RF19," .indexOf("," + getFelettParm("FELETT_CEDENTE_REGIME_FISCALE" + parmSfx) + ",") < 0) errMsg.append("FELETT_CEDENTE_REGIME_FISCALE" + parmSfx + ": nullo o errato (codice RF non riconosciuto. Vedi note\n"); if (getFelettParm("FELETT_CEDENTE_SEDE_INDIRIZZO" + parmSfx).isEmpty()) errMsg.append("FELETT_CEDENTE_SEDE_INDIRIZZO" + parmSfx + ": nullo o errato \n"); if (getFelettParm("FELETT_CEDENTE_SEDE_NUM_CIV" + parmSfx).isEmpty()) errMsg.append("FELETT_CEDENTE_SEDE_NUM_CIV" + parmSfx + ": nullo o errato \n"); if (getFelettParm("FELETT_CEDENTE_SEDE_NUM_CIV" + parmSfx).length() > 8) errMsg.append("FELETT_CEDENTE_SEDE_NUM_CIV" + parmSfx + ": > 8 caratteri \n"); if (getFelettParm("FELETT_CEDENTE_SEDE_CAP" + parmSfx).isEmpty()) errMsg.append("FELETT_CEDENTE_SEDE_CAP" + parmSfx + ": nullo o errato \n"); if (getFelettParm("FELETT_CEDENTE_SEDE_COMUNE" + parmSfx).isEmpty()) errMsg.append("FELETT_CEDENTE_SEDE_COMUNE" + parmSfx + ": nullo o errato \n"); if (getFelettParm("FELETT_CEDENTE_SEDE_PROV" + parmSfx).isEmpty() || getFelettParm("FELETT_CEDENTE_SEDE_PROV" + parmSfx).length() != 2) errMsg.append("FELETT_CEDENTE_SEDE_PROV" + parmSfx + ": nullo o errato (lunghezza !=2) \n"); if (getFelettParm("FELETT_CEDENTE_SEDE_NAZIONE" + parmSfx).isEmpty()) errMsg.append("FELETT_CEDENTE_SEDE_NAZIONE" + parmSfx + ": nullo o errato \n"); if (bean.getFEDatiAnagraficiCessionario().getFEPaese().isEmpty() || bean.getFEDatiAnagraficiCessionario().getFEPaese().length() != 2) errMsg.append("Cessionario Paese nulla o errata\n"); if (bean.getFEDatiAnagraficiCessionario().getFEPaese().equals("IT") && ( bean.getFEDatiAnagraficiCessionario().getFECodiceFiscale().isEmpty() || ( bean.getFEDatiAnagraficiCessionario().getFECodiceFiscale().length() != 16 && bean.getFEDatiAnagraficiCessionario().getFECodiceFiscale().length() != 11))) errMsg.append("Cessionario IT Codice fiscale errato\n"); if (bean.getFEDatiAnagraficiCessionario().getFEDenominazione().isEmpty() && bean.getFEDatiAnagraficiCessionario().getFECognome().isEmpty() && bean.getFEDatiAnagraficiCessionario().getFENome().isEmpty()) errMsg.append("Cessionario Denominazione e/o Cognome devono essere non nulli\n"); if (bean.getFEDatiAnagraficiCessionario().getFEDenominazione() != null && !bean.getFEDatiAnagraficiCessionario().getFEDenominazione().isEmpty()) { if (bean.getFEDatiAnagraficiCessionario().getFEDenominazione().length() > 80) errMsg.append("Cessionario Denominazione > 80 caratteri\n"); } else { if (bean.getFEDatiAnagraficiCessionario().getFECognome().length() > 60) errMsg.append("Cessionario Cognome > 60 caratteri\n"); if (bean.getFEDatiAnagraficiCessionario().getFENome().length() > 60) errMsg.append("Cessionario Nome > 60 caratteri\n"); } if (bean.getFESedeCessonario().getFEIndirizzo().isEmpty()) errMsg.append("Cessionario Sede Indirizzo\n"); if (bean.getFESedeCessonario().getFENumeroCivico().isEmpty()) errMsg.append("Cessionario Sede numero civico\n"); if (bean.getFESedeCessonario().getFENumeroCivico().length() > 8) errMsg.append("Cessionario Sede numero civico > 8 caratteri\n"); if (bean.getFEDatiAnagraficiCessionario().getFEPaese().equals("IT")) { if (bean.getFESedeCessonario().getFECAP().isEmpty()) errMsg.append("Cessionario Sede Cap\n"); if (bean.getFESedeCessonario().getFECAP().length() > 5) errMsg.append("Cessionario Sede CAP > 5 caratteri\n"); } if (bean.getFESedeCessonario().getFEComune().isEmpty()) errMsg.append("Cessionario Sede Comune\n"); if (bean.getFEDatiAnagraficiCessionario().getFEPaese().equals("IT") && ( bean.getFESedeCessonario().getFEProvincia().isEmpty() || bean.getFESedeCessonario().getFEProvincia().length() != 2)) errMsg.append("Cessionario Sede Provincia vuota o di lunghezza diversa da 2\n"); if (bean.getFESedeCessonario().getFENazione().isEmpty()) errMsg.append("Cessionario Sede Nazione\n"); if (bean.getFETipoDocumento().isEmpty()) errMsg.append("Dati Generali Tipo Documento\n"); if (bean.getFEDivisa().isEmpty()) errMsg.append("Dati Generali Divisa\n"); if (bean.getFeDataDocumento() == null) errMsg.append("Dati Generali Data Documento\n"); if (bean.getFENumeroDocumento().isEmpty()) errMsg.append("Dati Generali Numero Documento\n"); if (bean.getFeBolloVirtuale() != null && !bean.getFeBolloVirtuale().isEmpty() && ( !bean.getFeBolloVirtuale().equals("SI") || bean.getFEImportoBollo() <= 0.0D)) errMsg.append("Dati Generali Dati bollo errati\n"); if (errMsg.length() > 0) { rp.setStatus(false); rp.setMsg(bean.getFENumeroDocumento() + ": " + bean.getFENumeroDocumento()); } else { rp.setStatus(true); } return rp; } private Vectumerator getVecFatture() { return this.vecFatture; } private Vectumerator processaLineeRegimeMargine(Vectumerator vecDL) { Vectumerator vecDLRes = new Vectumerator(); while (vecDL.hasMoreElements()) { FEDettaglioLineeInterface row = (FEDettaglioLineeInterface)vecDL.nextElement(); if (row.getFENatura().equals("N5")) { FEDettaglioLinea rowN5 = clonaDettaglioLineaInterface(row); rowN5.setFEPrezzoUnitario(row.getFECostoArticolo()); if (row.getFEQuantita() == 1.0D) { rowN5.setFEPrezzoTotale(row.getFECostoArticolo()); } else { DoubleOperator dop = new DoubleOperator(row.getFECostoArticolo()); dop.setScale(2, 5); dop.multiply(row.getFEQuantita()); rowN5.setFEPrezzoTotale(dop.getResult()); } vecDLRes.add(rowN5); FEDettaglioLinea row22 = clonaDettaglioLineaInterface(row); DoubleOperator dopImpo = new DoubleOperator(row.getFEPrezzoUnitario()); dopImpo.setScale(2, 5); dopImpo.subtract(row.getFECostoArticolo()); double imponibile = Iva.scorporaIva(dopImpo.getResult(), 22.0D); row22.setFEPrezzoUnitario(imponibile); if (row.getFEQuantita() == 1.0D) { row22.setFEPrezzoTotale(imponibile); } else { DoubleOperator dop = new DoubleOperator(imponibile); dop.setScale(2, 5); dop.multiply(row.getFEQuantita()); row22.setFEPrezzoTotale(dop.getResult()); } row22.setFENatura(""); row22.setFEAliquotaIva(22.0D); vecDLRes.add(row22); continue; } vecDLRes.add(row); } return vecDLRes; } private FEDettaglioLinea clonaDettaglioLineaInterface(FEDettaglioLineeInterface row) { FEDettaglioLinea rowClonata = new FEDettaglioLinea(); rowClonata.setFEAliquotaIva(row.getFEAliquotaIva()); rowClonata.setFECodiceArticoloTipo(row.getFECodiceArticoloTipo()); rowClonata.setFECodiceArticoloValore(row.getFECodiceArticoloValore()); rowClonata.setFECostoArticolo(row.getFECostoArticolo()); rowClonata.setFEDataFinePeriodo(row.getFEDataFinePeriodo()); rowClonata.setFEDataInizioPeriodo(row.getFEDataInizioPeriodo()); rowClonata.setFEDescrizione(row.getFEDescrizione()); rowClonata.setFENatura(row.getFENatura()); rowClonata.setFEPrezzoTotale(row.getFEPrezzoTotale()); rowClonata.setFEPrezzoUnitario(row.getFEPrezzoUnitario()); rowClonata.setFEQuantita(row.getFEQuantita()); rowClonata.setFERiferimentoAmministrazione(row.getFERiferimentoAmministrazione()); rowClonata.setFERitenuta(row.getFERitenuta()); rowClonata.setFEScontoMaggiorazione(row.getFEScontoMaggiorazione()); rowClonata.setFETipoCessionePrestazione(row.getFETipoCessionePrestazione()); rowClonata.setFEUnitaMisura(row.getFEUnitaMisura()); return rowClonata; } }