Dépôt officiel du code source de l'ERP OpenConcerto
/trunk/OpenConcerto/src/org/openconcerto/erp/core/supplychain/purchase/importer/FacturXExporter.java |
---|
13,16 → 13,25 |
package org.openconcerto.erp.core.supplychain.purchase.importer; |
import org.openconcerto.erp.core.finance.payment.element.ModeDeReglementSQLElement; |
import org.openconcerto.sql.model.DBRoot; |
import org.openconcerto.sql.model.SQLRow; |
import org.openconcerto.sql.model.SQLRowAccessor; |
import org.openconcerto.sql.model.SQLRowValues; |
import org.openconcerto.sql.model.SQLRowValuesListFetcher; |
import org.openconcerto.sql.model.SQLTable; |
import org.openconcerto.sql.model.Where; |
import java.math.BigDecimal; |
import java.text.DecimalFormat; |
import java.text.DecimalFormatSymbols; |
import java.text.SimpleDateFormat; |
import java.util.ArrayList; |
import java.util.Collection; |
import java.util.Date; |
import java.util.HashMap; |
import java.util.List; |
import java.util.Locale; |
import java.util.Map; |
import org.jdom2.Document; |
import org.jdom2.Element; |
34,18 → 43,27 |
* FacturX export (EN 16931 format) |
*/ |
public class FacturXExporter { |
private class Tax { |
// Taux, ex pour 20% : 20.00 |
BigDecimal rate; |
final BigDecimal rate; |
// Montant de la TVA |
BigDecimal amount; |
BigDecimal amount = BigDecimal.ZERO; |
// montant HT sur lequel s'applique la TVA |
BigDecimal basisAmount; |
BigDecimal basisAmount = BigDecimal.ZERO; |
public Tax(BigDecimal rate) { |
this.rate = rate; |
} |
public void add(BigDecimal taxAmount, |
BigDecimal basisAmount) { |
this.amount = this.amount.add(taxAmount); |
this.basisAmount = this.basisAmount.add(basisAmount); |
} |
} |
public static Namespace QDT_NS = Namespace.getNamespace("qdt", "urn:un:unece:uncefact:data:standard:QualifiedDataType:100"); |
public static Namespace RAM_NS = Namespace.getNamespace("ram", "urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"); |
public static Namespace RSM_NS = Namespace.getNamespace("rsm", "urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"); |
56,26 → 74,55 |
FacturXExporter ex = new FacturXExporter(); |
System.err.println("FacturXExporter.main() " + ex.checkEAN13("5987854125989")); |
String xml = ex.createXMLFrom(null, 1); |
System.out.println(xml); |
// String xml = ex.createXMLFrom(null, 1); |
// System.out.println(xml); |
} |
public String createXMLFrom(DBRoot row, int invoiceId) { |
DecimalFormat formatAmount = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); |
List<Tax> taxes = new ArrayList<>(); |
Tax t1 = new Tax(); |
t1.rate = new BigDecimal("20.0"); |
t1.amount = new BigDecimal("40.0"); |
t1.basisAmount = new BigDecimal("200.0"); |
taxes.add(t1); |
private boolean useCommonClient = false; |
DecimalFormat format = new DecimalFormat("#0.00", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); |
public String createXMLFrom(DBRoot dbRoot, int invoiceId, SQLRow societeRow) { |
SQLTable factureTable = dbRoot.getTable("SAISIE_VENTE_FACTURE"); |
SQLRowValues rowValsToFetch = new SQLRowValues(factureTable); |
rowValsToFetch.putNulls("NUMERO", "DATE", "NOM", "T_TVA", "T_HT", "T_TTC", "NET_A_PAYER"); |
rowValsToFetch.putRowValues("ID_MODE_REGLEMENT").putNulls("COMPTANT", "AJOURS", "LENJOUR", "DATE_FACTURE", "FIN_MOIS").putRowValues("ID_TYPE_REGLEMENT").putNulls("NOM"); |
SQLRowValues putRowValuesClient = rowValsToFetch.putRowValues("ID_CLIENT"); |
putRowValuesClient.putNulls("NOM", "RESPONSABLE", "SIRET", "NUMERO_TVA", "MAIL", "TEL"); |
if (putRowValuesClient.getTable().contains("ID_CLIENT")) { |
this.useCommonClient = true; |
putRowValuesClient.putRowValues("ID_CLIENT").putNulls("NOM", "RESPONSABLE", "SIRET", "NUMERO_TVA", "MAIL", "TEL").putRowValues("ID_ADRESSE").putNulls("RUE", "VILLE", "CODE_POSTAL", |
"PAYS"); |
} |
putRowValuesClient.putRowValues("ID_ADRESSE").putNulls("RUE", "VILLE", "CODE_POSTAL", "PAYS"); |
putRowValuesClient.putRowValues("ID_ADRESSE_F").putNulls("RUE", "VILLE", "CODE_POSTAL", "PAYS"); |
rowValsToFetch.putRowValues("ID_ADRESSE").putNulls("RUE", "VILLE", "CODE_POSTAL", "PAYS"); |
SQLTable factureItemtable = dbRoot.getTable("SAISIE_VENTE_FACTURE_ELEMENT"); |
SQLRowValues rowValsItemsToFetch = new SQLRowValues(factureItemtable); |
rowValsItemsToFetch.putNulls("NIVEAU", "CODE", "NOM", "QTE", "QTE_UNITAIRE", "PV_HT", "T_PV_HT", "T_PV_TTC").putRowValues("ID_TAXE").put("TAUX", null); |
rowValsItemsToFetch.put("ID_SAISIE_VENTE_FACTURE", rowValsToFetch); |
List<SQLRowValues> factures = SQLRowValuesListFetcher.create(rowValsToFetch).fetch(new Where(factureTable.getKey(), "=", invoiceId)); |
SQLRowValues facture = factures.get(0); |
Collection<? extends SQLRowAccessor> factureItems = facture.getReferentRows(factureItemtable.getField("ID_SAISIE_VENTE_FACTURE")); |
Map<Integer, Tax> taxes = new HashMap<>(); |
// Tax t1 = new Tax(); |
// t1.rate = new BigDecimal("20.0"); |
// t1.amount = new BigDecimal("40.0"); |
// t1.basisAmount = new BigDecimal("200.0"); |
// taxes.add(t1); |
DecimalFormat fQty = new DecimalFormat("#0.########", DecimalFormatSymbols.getInstance(Locale.ENGLISH)); |
String invoiceNumber = "-"; |
Date invoiceDate = new Date(); |
String regNote = "SARL au capital de 50 000 EUR"; |
String legNote = "RCS MAVILLE 123 456 789"; |
int nbLines = 4; |
String invoiceNumber = facture.getString("NUMERO"); |
Date invoiceDate = facture.getDate("DATE").getTime(); |
String regNote = societeRow.getString("TYPE") + " au capital de " + societeRow.getObject("CAPITAL") + " €"; |
String legNote = societeRow.getString("RCS"); |
int nbLines = factureItems.size(); |
final Document doc = new Document(); |
Element root = new Element("CrossIndustryInvoice", RSM_NS); |
132,21 → 179,40 |
// SupplyChainTradeTransaction |
Element eSupplyChainTradeTransaction = new Element("SupplyChainTradeTransaction", RSM_NS); |
for (int i = 0; i < nbLines; i++) { |
String productCode = "a"; |
String productName = "b"; |
int lineID = 1; |
for (SQLRowAccessor rowItem : factureItems) { |
String productCode = rowItem.getString("CODE"); |
String productName = rowItem.getString("NOM").trim().length() == 0 ? "Ligne" : rowItem.getString("NOM"); |
BigDecimal pHT = new BigDecimal("12.46"); |
BigDecimal tax = new BigDecimal("0.20"); |
BigDecimal pTTC = new BigDecimal("14.95"); |
BigDecimal qte = new BigDecimal("10.0"); |
BigDecimal totalHTLigne = new BigDecimal("124.60"); |
final BigDecimal pHT, pTTC, totalHTLigne, totalTTCLigne; |
SQLRowAccessor taxeItem = rowItem.getForeign("ID_TAXE"); |
BigDecimal taxValue = new BigDecimal(taxeItem.getFloat("TAUX")).setScale(2); |
if (rowItem.getInt("NIVEAU") != 1) { |
pHT = BigDecimal.ZERO; |
pTTC = BigDecimal.ZERO; |
totalHTLigne = BigDecimal.ZERO; |
totalTTCLigne = BigDecimal.ZERO; |
} else { |
pHT = rowItem.getBigDecimal("PV_HT"); |
pTTC = pHT.multiply(taxValue.add(BigDecimal.ONE)); |
totalHTLigne = rowItem.getBigDecimal("T_PV_HT"); |
totalTTCLigne = rowItem.getBigDecimal("T_PV_TTC"); |
} |
int idTaxe = taxeItem.getID(); |
if (!taxes.containsKey(idTaxe)) { |
Tax t = new Tax(taxValue); |
taxes.put(idTaxe, t); |
} |
taxes.get(idTaxe).add(totalTTCLigne.subtract(totalHTLigne), totalHTLigne); |
BigDecimal qte = new BigDecimal(rowItem.getInt("QTE")).multiply(rowItem.getBigDecimal("QTE_UNITAIRE")); |
Element eLineItem = new Element("IncludedSupplyChainTradeLineItem", RAM_NS); |
// AssociatedDocumentLineDocument |
Element eAssociatedDocumentLineDocument = new Element("AssociatedDocumentLineDocument", RAM_NS); |
Element eLineID = new Element("LineID", RAM_NS); |
eLineID.setText(String.valueOf(i + 1)); |
eLineID.setText(String.valueOf(lineID++)); |
eAssociatedDocumentLineDocument.addContent(eLineID); |
eLineItem.addContent(eAssociatedDocumentLineDocument); |
// SpecifiedTradeProduct |
176,11 → 242,11 |
// Prix unitaire TTC |
Element eGrossPriceProductTradePrice = new Element("GrossPriceProductTradePrice", RAM_NS); |
Element eChargeAmount = new Element("ChargeAmount", RAM_NS); |
eChargeAmount.setText(format.format(pTTC)); |
eChargeAmount.setText(formatAmount.format(pTTC)); |
eGrossPriceProductTradePrice.addContent(eChargeAmount); |
Element eAppliedTradeAllowanceCharge = new Element("AppliedTradeAllowanceCharge", RAM_NS); |
Element eChargeIndicator = new Element("ChargeIndicator", RAM_NS); |
Element eIndicator = new Element("ChargeIndicator", UDT_NS); |
Element eIndicator = new Element("Indicator", UDT_NS); |
// pas de remise |
eIndicator.setText("false"); |
eChargeIndicator.addContent(eIndicator); |
188,17 → 254,17 |
Element eActualAmount = new Element("ActualAmount", RAM_NS); |
// Montant de TVA (unitaire) |
eActualAmount.setText(format.format(pTTC.subtract(pHT))); |
eActualAmount.setText(formatAmount.format(pTTC.subtract(pHT))); |
eAppliedTradeAllowanceCharge.addContent(eActualAmount); |
eGrossPriceProductTradePrice.addContent(eAppliedTradeAllowanceCharge); |
// eGrossPriceProductTradePrice.addContent(eAppliedTradeAllowanceCharge); |
eSpecifiedLineTradeAgreement.addContent(eGrossPriceProductTradePrice); |
// Prix unitaire HT |
Element eNetPriceProductTradePrice = new Element("NetPriceProductTradePrice", RAM_NS); |
Element eChargeAmountHT = new Element("ChargeAmount", RAM_NS); |
eChargeAmountHT.setText(format.format(pHT)); |
eChargeAmountHT.setText(formatAmount.format(pHT)); |
eNetPriceProductTradePrice.addContent(eChargeAmountHT); |
eSpecifiedLineTradeAgreement.addContent(eNetPriceProductTradePrice); |
240,7 → 306,7 |
Element eRateApplicablePercent = new Element("RateApplicablePercent", RAM_NS); |
// 20% -> 20.0 |
eRateApplicablePercent.setText(format.format(tax.multiply(new BigDecimal(100)))); |
eRateApplicablePercent.setText(formatAmount.format(taxValue)); |
eApplicableTradeTaxt.addContent(eRateApplicablePercent); |
eSpecifiedLineTradeSettlement.addContent(eApplicableTradeTaxt); |
248,7 → 314,7 |
Element eSpecifiedTradeSettlementLineMonetarySummation = new Element("SpecifiedTradeSettlementLineMonetarySummation", RAM_NS); |
// Total HT |
Element eLineTotalAmount = new Element("LineTotalAmount", RAM_NS); |
eLineTotalAmount.setText(format.format(totalHTLigne)); |
eLineTotalAmount.setText(formatAmount.format(totalHTLigne)); |
eSpecifiedTradeSettlementLineMonetarySummation.addContent(eLineTotalAmount); |
eSpecifiedLineTradeSettlement.addContent(eSpecifiedTradeSettlementLineMonetarySummation); |
257,12 → 323,11 |
eSupplyChainTradeTransaction.addContent(eLineItem); |
} |
addApplicableHeader(eSupplyChainTradeTransaction, taxes); |
root.addContent(ed); |
addApplicableHeader(societeRow, facture, eSupplyChainTradeTransaction, taxes.values()); |
ed.addContent(eSupplyChainTradeTransaction); |
root.addContent(eSupplyChainTradeTransaction); |
root.addContent(ed); |
final XMLOutputter xmlOutput = new XMLOutputter(); |
xmlOutput.setFormat(Format.getPrettyFormat()); |
return xmlOutput.outputString(doc); |
273,22 → 338,25 |
parent.addContent(element); |
} |
private void addApplicableHeader(Element eSupplyChainTradeTransaction, List<Tax> taxes) { |
private void addApplicableHeader(SQLRowAccessor rowSociete, SQLRowAccessor rowFacture, Element eSupplyChainTradeTransaction, Collection<Tax> taxes) { |
// |
// ApplicableHeaderTradeAgreement |
// |
final Element eApplicableHeaderTradeAgreement = new Element("ApplicableHeaderTradeAgreement", RAM_NS); |
addSupplierInfo(eApplicableHeaderTradeAgreement); |
addBuyerInfo(eApplicableHeaderTradeAgreement); |
addSupplierInfo(eApplicableHeaderTradeAgreement, rowSociete); |
addBuyerInfo(eApplicableHeaderTradeAgreement, rowFacture); |
String orderRef = ""; |
String contractRef = ""; |
// Date de livraison, facultative |
Date effectiveDeliveryDate = new Date(65454654); |
String invoiceNumber = "FA-2017-0010"; |
Date effectiveDeliveryDate = rowFacture.getDate("DATE").getTime(); |
String invoiceNumber = rowFacture.getString("NUMERO"); |
String currencyCode = "EUR"; |
String dueDescription = "30% d'acompte, solde à 30 j"; |
Date dueDate = new Date(65455654); |
SQLRowAccessor foreignMdr = rowFacture.getForeign("ID_MODE_REGLEMENT"); |
int ajours = foreignMdr.getInt("AJOURS"); |
int lenjour = foreignMdr.getInt("LENJOUR"); |
String dueDescription = (ajours > 0 ? "A " + ajours : "") + (lenjour > 0 ? " le " + lenjour : ""); |
Date dueDate = ModeDeReglementSQLElement.calculDate(foreignMdr, rowFacture.getDate("DATE").getTime()); |
final Element eBuyerOrderReferencedDocument = new Element("BuyerOrderReferencedDocument", RAM_NS); |
addValue(eBuyerOrderReferencedDocument, new Element("IssuerAssignedID", RAM_NS), orderRef); |
330,6 → 398,7 |
addValue(eApplicableHeaderTradeSettlement, new Element("PaymentReference", RAM_NS), invoiceNumber); |
addValue(eApplicableHeaderTradeSettlement, new Element("InvoiceCurrencyCode", RAM_NS), currencyCode); |
final Element aSpecifiedTradeSettlementPaymentMeans = new Element("SpecifiedTradeSettlementPaymentMeans", RAM_NS); |
addValue(aSpecifiedTradeSettlementPaymentMeans, new Element("TypeCode", RAM_NS), "57"); |
// <ram:TypeCode>30</ram:TypeCode> |
// <ram:Information>Virement sur compte Banque Fiducial</ram:Information> |
380,7 → 449,38 |
eApplicableHeaderTradeSettlement.addContent(eSpecifiedTradePaymentTerms); |
final Element eSpecifiedTradeSettlementHeaderMonetarySummation = new Element("SpecifiedTradeSettlementHeaderMonetarySummation", RAM_NS); |
final Element eTotalHT = new Element("LineTotalAmount", RAM_NS); |
eTotalHT.setText(this.formatAmount.format(new BigDecimal(rowFacture.getLong("T_HT")).movePointLeft(2))); |
eSpecifiedTradeSettlementHeaderMonetarySummation.addContent(eTotalHT); |
final Element eTotalBaseTVA = new Element("TaxBasisTotalAmount", RAM_NS); |
BigDecimal totalBaseTVA = BigDecimal.ZERO; |
for (Tax tax : taxes) { |
totalBaseTVA = totalBaseTVA.add(tax.basisAmount); |
} |
eTotalBaseTVA.setText(this.formatAmount.format(totalBaseTVA)); |
eSpecifiedTradeSettlementHeaderMonetarySummation.addContent(eTotalBaseTVA); |
final Element eTotalTVA = new Element("TaxTotalAmount", RAM_NS); |
eTotalTVA.setAttribute("currencyID", "EUR"); |
eTotalTVA.setText(this.formatAmount.format(new BigDecimal(rowFacture.getLong("T_TVA")).movePointLeft(2))); |
eSpecifiedTradeSettlementHeaderMonetarySummation.addContent(eTotalTVA); |
final Element eTotalTTC = new Element("GrandTotalAmount", RAM_NS); |
BigDecimal totalTTC = new BigDecimal(rowFacture.getLong("T_TTC")).movePointLeft(2); |
eTotalTTC.setText(this.formatAmount.format(totalTTC)); |
eSpecifiedTradeSettlementHeaderMonetarySummation.addContent(eTotalTTC); |
final Element eTotalPrepaid = new Element("TotalPrepaidAmount", RAM_NS); |
BigDecimal netApayer = new BigDecimal(rowFacture.getLong("NET_A_PAYER")).movePointLeft(2); |
eTotalPrepaid.setText(this.formatAmount.format(totalTTC.subtract(netApayer))); |
eSpecifiedTradeSettlementHeaderMonetarySummation.addContent(eTotalPrepaid); |
final Element eTotalDue = new Element("DuePayableAmount", RAM_NS); |
eTotalDue.setText(this.formatAmount.format(netApayer)); |
eSpecifiedTradeSettlementHeaderMonetarySummation.addContent(eTotalDue); |
// Total HT |
// <ram:LineTotalAmount>624.90</ram:LineTotalAmount> |
// Total HT sur leque est appliqué la TVA |
400,20 → 500,35 |
} |
private void addBuyerInfo(final Element eApplicableHeaderTradeAgreement) { |
private void addBuyerInfo(final Element eApplicableHeaderTradeAgreement, final SQLRowAccessor rowFacture) { |
SQLRowAccessor client = rowFacture.getForeign("ID_CLIENT"); |
SQLRowAccessor clientGestion = client; |
if (this.useCommonClient) { |
client = client.getForeign("ID_CLIENT"); |
} |
final SQLRowAccessor adr; |
if (!rowFacture.isForeignEmpty("ID_ADRESSE")) { |
adr = rowFacture.getForeign("ID_ADRESSE"); |
} else if (!clientGestion.isForeignEmpty("ID_ADRESSE_F")) { |
adr = clientGestion.getForeign("ID_ADRESSE_F"); |
} else { |
adr = client.getForeign("ID_ADRESSE"); |
} |
// Acheteur |
String buyerName = "Ma jolie boutique"; |
String buyerSIRET = "78787878400035"; |
String buyerVAT = "FR19787878784"; |
String buyerContactName = "Alexandre Payet"; |
String buyerPhone = "+33 4 72 07 08 67"; |
String buyerEmail = "alexandre.payet@majolieboutique.net"; |
String buyerAddrL1 = "35 rue de la République"; |
String buyerName = client.getString("NOM"); |
String buyerSIRET = client.getString("SIRET"); |
String buyerVAT = client.getString("NUMERO_TVA"); |
String buyerContactName = client.getString("RESPONSABLE"); |
String buyerPhone = client.getString("TEL"); |
String buyerEmail = client.getString("MAIL"); |
String buyerAddrL1 = adr.getString("RUE"); |
String buyerAddrL2 = ""; |
String buyerAddrL3 = ""; |
String buyerPostalCode = "69001"; |
String buyerCity = "Lyon"; |
String buyerCountryCode = "FR"; |
String buyerPostalCode = adr.getString("CODE_POSTAL"); |
String buyerCity = adr.getString("VILLE"); |
String buyerCountryCode = resolveCountryCode(adr.getString("PAYS")); |
final Element eBuyerTradeParty = new Element("BuyerTradeParty", RAM_NS); |
this.addValue(eBuyerTradeParty, new Element("Name", RAM_NS), buyerName); |
439,19 → 554,20 |
eBuyerTradeParty.addContent(eDefinedTradeContact); |
// Adresse postale |
final Element ePostalTradeAddress = new Element("PostalTradeAddress", RAM_NS); |
addValue(ePostalTradeAddress, new Element("LineOne>", RAM_NS), buyerAddrL1); |
addValue(ePostalTradeAddress, new Element("PostcodeCode", RAM_NS), buyerPostalCode); |
addValue(ePostalTradeAddress, new Element("LineOne", RAM_NS), buyerAddrL1); |
if (buyerAddrL2 != null && !buyerAddrL2.trim().isEmpty()) { |
addValue(ePostalTradeAddress, new Element("LineTwo>", RAM_NS), buyerAddrL2); |
addValue(ePostalTradeAddress, new Element("LineTwo", RAM_NS), buyerAddrL2); |
} |
if (buyerAddrL3 != null && !buyerAddrL3.trim().isEmpty()) { |
addValue(ePostalTradeAddress, new Element("LineThree>", RAM_NS), buyerAddrL3); |
addValue(ePostalTradeAddress, new Element("LineThree", RAM_NS), buyerAddrL3); |
} |
addValue(ePostalTradeAddress, new Element("PostcodeCode>", RAM_NS), buyerPostalCode); |
addValue(ePostalTradeAddress, new Element("CityName>", RAM_NS), buyerCity); |
addValue(ePostalTradeAddress, new Element("CountryID>", RAM_NS), buyerCountryCode); |
addValue(ePostalTradeAddress, new Element("CityName", RAM_NS), buyerCity); |
addValue(ePostalTradeAddress, new Element("CountryID", RAM_NS), buyerCountryCode); |
eBuyerTradeParty.addContent(ePostalTradeAddress); |
if (buyerVAT != null && buyerVAT.trim().length() > 0) { |
// TVA |
final Element eSpecifiedTaxRegistration = new Element("SpecifiedTaxRegistration", RAM_NS); |
final Element eSpecifiedTaxRegistrationId = new Element("ID", RAM_NS); |
459,23 → 575,24 |
eSpecifiedTaxRegistrationId.setText(buyerVAT); |
eSpecifiedTaxRegistration.addContent(eSpecifiedTaxRegistrationId); |
eBuyerTradeParty.addContent(eSpecifiedTaxRegistration); |
} |
eApplicableHeaderTradeAgreement.addContent(eBuyerTradeParty); |
} |
private void addSupplierInfo(final Element eApplicableHeaderTradeAgreement) { |
String supplierName = "Au bon moulin"; |
String supplierSIRET = "121321321321"; |
String supplierContactName = "Tony Dubois"; |
String supplierContactPhone = "+33 4 72 07 08 56"; |
String supplierContactEmail = "tony.dubois@aubonmoulin.fr"; |
String supplierAddrL1 = "3 rue du pont"; |
private void addSupplierInfo(final Element eApplicableHeaderTradeAgreement, SQLRowAccessor rowSociete) { |
String supplierName = rowSociete.getString("NOM"); |
String supplierSIRET = rowSociete.getString("NUM_SIRET"); |
String supplierContactName = ""; |
String supplierContactPhone = rowSociete.getString("NUM_TEL"); |
String supplierContactEmail = rowSociete.getString("MAIL"); |
SQLRowAccessor adr = rowSociete.getForeign("ID_ADRESSE_COMMON"); |
String supplierAddrL1 = adr.getString("RUE"); |
String supplierAddrL2 = ""; |
String supplierAddrL3 = ""; |
String supplierAddrPostalCode = "80100"; |
String supplierAddrCityName = "Abbeville"; |
String supplierAddrCountryID = "FR"; |
String supplierNumTVA = "FR121321321321"; |
String supplierAddrPostalCode = adr.getString("CODE_POSTAL"); |
String supplierAddrCityName = adr.getString("VILLE"); |
String supplierAddrCountryID = resolveCountryCode(adr.getString("PAYS")); |
String supplierNumTVA = rowSociete.getString("NUM_NII"); |
// Vendeur |
final Element eSellerTradeParty = new Element("SellerTradeParty", RAM_NS); |
addValue(eSellerTradeParty, new Element("Name", RAM_NS), supplierName); |
507,6 → 624,7 |
eSellerTradeParty.addContent(eDefinedTradeContact); |
final Element ePostalTradeAddress = new Element("PostalTradeAddress", RAM_NS); |
addValue(ePostalTradeAddress, new Element("PostcodeCode", RAM_NS), supplierAddrPostalCode); |
addValue(ePostalTradeAddress, new Element("LineOne", RAM_NS), supplierAddrL1); |
if (supplierAddrL2 != null && !supplierAddrL2.trim().isEmpty()) { |
addValue(ePostalTradeAddress, new Element("LineTwo", RAM_NS), supplierAddrL2); |
514,7 → 632,6 |
if (supplierAddrL3 != null && !supplierAddrL3.trim().isEmpty()) { |
addValue(ePostalTradeAddress, new Element("LineThree", RAM_NS), supplierAddrL3); |
} |
addValue(ePostalTradeAddress, new Element("PostcodeCode", RAM_NS), supplierAddrPostalCode); |
addValue(ePostalTradeAddress, new Element("CityName", RAM_NS), supplierAddrCityName); |
addValue(ePostalTradeAddress, new Element("CountryID", RAM_NS), supplierAddrCountryID); |
568,4 → 685,56 |
} |
return Integer.valueOf(code.substring(12, 13)).intValue() == checkdigit; |
} |
private String resolveCountryCode(String pays) { |
if (pays == null || pays.trim().length() == 0) { |
return "FR"; |
} else if (pays.toLowerCase().equals("france")) { |
return "FR"; |
} else if (pays.toLowerCase().equals("fr")) { |
return "FR"; |
} else if (pays.toLowerCase().equals("polska")) { |
return "PL"; |
} else if (pays.toLowerCase().equals("pologne")) { |
return "PL"; |
} else if (pays.toLowerCase().equals("pl")) { |
return "PL"; |
} else if (pays.toLowerCase().equals("allemagne")) { |
return "DE"; |
} else if (pays.toLowerCase().equals("de")) { |
return "DE"; |
} else if (pays.toLowerCase().equals("deutschland")) { |
return "DE"; |
} else if (pays.toLowerCase().equals("italie")) { |
return "IT"; |
} else if (pays.toLowerCase().equals("italy")) { |
return "IT"; |
} else if (pays.toLowerCase().equals("italia")) { |
return "IT"; |
} else if (pays.toLowerCase().equals("it")) { |
return "IT"; |
} else if (pays.toLowerCase().equals("espagne")) { |
return "SP"; |
} else if (pays.toLowerCase().equals("spain")) { |
return "SP"; |
} else if (pays.toLowerCase().equals("sp")) { |
return "SP"; |
} else if (pays.toLowerCase().equals("luxembourg")) { |
return "LU"; |
} else if (pays.toLowerCase().equals("lu")) { |
return "LU"; |
} else if (pays.toLowerCase().equals("portugal")) { |
return "PT"; |
} else if (pays.toLowerCase().equals("pt")) { |
return "PT"; |
} else if (pays.toLowerCase().equals("belgique")) { |
return "BE"; |
} else if (pays.toLowerCase().equals("belgium")) { |
return "BE"; |
} else if (pays.toLowerCase().equals("be")) { |
return "BE"; |
} else { |
return ""; |
} |
} |
} |