Skip to content

Commit

Permalink
Renamed class
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Feb 21, 2025
1 parent 6c191f5 commit ece322a
Show file tree
Hide file tree
Showing 3 changed files with 164 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
* @author Vartika Rastogi
* @author Philip Helger
*/
public final class UBL21ToCII16BConverter extends AbstractToCII16BConverter
public final class UBL21InvoiceToCII16BConverter extends AbstractToCII16BConverter
{
private UBL21ToCII16BConverter ()
private UBL21InvoiceToCII16BConverter ()
{}

@Nonnull
private static List <SupplyChainTradeLineItemType> _convertInvoiceLines (final List <oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21.InvoiceLineType> aLstIL)
private static List <SupplyChainTradeLineItemType> _convertInvoiceLines (@Nonnull final List <InvoiceLineType> aLstIL)
{
final List <SupplyChainTradeLineItemType> ret = new ArrayList <> ();
for (final InvoiceLineType aILT : aLstIL)
Expand Down Expand Up @@ -183,8 +183,64 @@ private static List <SupplyChainTradeLineItemType> _convertInvoiceLines (final L
return ret;
}

@Nonnull
private static List <ReferencedDocumentType> _convertAdditionalReferencedDocument (@Nonnull final InvoiceType aUBLInvoice)
{
final List <ReferencedDocumentType> ret = new ArrayList <> ();
for (final DocumentReferenceType aDocDesc : aUBLInvoice.getAdditionalDocumentReference ())
{
final ReferencedDocumentType aURDT = new ReferencedDocumentType ();

if (aDocDesc.getID () != null)
aURDT.setIssuerAssignedID (aDocDesc.getIDValue ());

// Add DocumentTypeCode where possible
if (aDocDesc.getDocumentTypeCode () != null && isValidDocumentReferenceTypeCode (aDocDesc.getDocumentTypeCodeValue ()))
aURDT.setTypeCode (aDocDesc.getDocumentTypeCodeValue ());
else
aURDT.setTypeCode ("916");

if (aDocDesc.getIssueDate () != null)
{
final FormattedDateTimeType aFIDT = new FormattedDateTimeType ();
aFIDT.setDateTimeString (createFormattedDateValue (aDocDesc.getIssueDateValueLocal ()));
aURDT.setFormattedIssueDateTime (aFIDT);
}

for (final var aDesc : aDocDesc.getDocumentDescription ())
{
final TextType aText = new TextType ();
aText.setValue (aDesc.getValue ());
aText.setLanguageID (aDesc.getLanguageID ());
aText.setLanguageLocaleID (aDesc.getLanguageLocaleID ());
aURDT.addName (aText);
}

final AttachmentType aAttachment = aDocDesc.getAttachment ();
if (aAttachment != null)
{
// External Reference and Embedded Document Binary Object should be
// mutually exclusive
if (aAttachment.getExternalReference () != null && aAttachment.getExternalReference ().getURI () != null)
{
aURDT.setURIID (aAttachment.getExternalReference ().getURI ().getValue ());
}

if (aAttachment.getEmbeddedDocumentBinaryObject () != null)
{
final BinaryObjectType aBOT = new BinaryObjectType ();
aBOT.setMimeCode (aAttachment.getEmbeddedDocumentBinaryObject ().getMimeCode ());
aBOT.setValue (aAttachment.getEmbeddedDocumentBinaryObject ().getValue ());
aURDT.addAttachmentBinaryObject (aBOT);
}
}
ret.add (aURDT);
}
return ret;
}

@Nullable
private static HeaderTradeDeliveryType _convertApplicableHeaderTradeDelivery (@Nullable final DeliveryType aDelivery)
private static HeaderTradeDeliveryType _createApplicableHeaderTradeDelivery (@Nullable final DeliveryType aDelivery)
{
// Object is mandatory
final HeaderTradeDeliveryType ret = new HeaderTradeDeliveryType ();
Expand All @@ -211,94 +267,6 @@ private static HeaderTradeDeliveryType _convertApplicableHeaderTradeDelivery (@N
return ret;
}

@Nonnull
private static HeaderTradeSettlementType _convertApplicableHeaderTradeSettlement (@Nonnull final InvoiceType aUBLInvoice)
{
final HeaderTradeSettlementType ret = new HeaderTradeSettlementType ();

final PaymentMeansType aPM = aUBLInvoice.hasPaymentMeansEntries () ? aUBLInvoice.getPaymentMeansAtIndex (0) : null;

if (aPM != null && aPM.hasPaymentIDEntries ())
ret.addPaymentReference (convertText (aPM.getPaymentID ().get (0).getValue ()));

ret.setInvoiceCurrencyCode (aUBLInvoice.getDocumentCurrencyCode ().getValue ());

if (aUBLInvoice.getPayeeParty () != null)
ret.setPayeeTradeParty (convertParty (aUBLInvoice.getPayeeParty ()));

if (aPM != null)
{
final TradeSettlementPaymentMeansType aTSPMT = new TradeSettlementPaymentMeansType ();
aTSPMT.setTypeCode (aPM.getPaymentMeansCodeValue ());

final CreditorFinancialAccountType aCFAT = new CreditorFinancialAccountType ();
if (aPM.getPayeeFinancialAccount () != null)
aCFAT.setIBANID (aPM.getPayeeFinancialAccount ().getIDValue ());

aTSPMT.setPayeePartyCreditorFinancialAccount (aCFAT);
ret.addSpecifiedTradeSettlementPaymentMeans (aTSPMT);
}

ret.setApplicableTradeTax (_convertApplicableTradeTax (aUBLInvoice));

if (aUBLInvoice.hasInvoicePeriodEntries ())
{
final PeriodType aIP = aUBLInvoice.getInvoicePeriodAtIndex (0);

final SpecifiedPeriodType aSPT = new SpecifiedPeriodType ();
if (aIP.getStartDate () != null)
aSPT.setStartDateTime (convertDate (aIP.getStartDate ().getValueLocal ()));

if (aIP.getEndDate () != null)
aSPT.setEndDateTime (convertDate (aIP.getEndDate ().getValueLocal ()));

ret.setBillingSpecifiedPeriod (aSPT);
}

ret.setSpecifiedTradeAllowanceCharge (_convertSpecifiedTradeAllowanceCharge (aUBLInvoice));
ret.setSpecifiedTradePaymentTerms (_convertSpecifiedTradePaymentTerms (aUBLInvoice));
ret.setSpecifiedTradeSettlementHeaderMonetarySummation (_convertSpecifiedTradeSettlementHeaderMonetarySummation (aUBLInvoice));

if (aUBLInvoice.getAccountingCost () != null)
{
final TradeAccountingAccountType aTAAT = new TradeAccountingAccountType ();
aTAAT.setID (aUBLInvoice.getAccountingCost ().getValue ());
ret.addReceivableSpecifiedTradeAccountingAccount (aTAAT);
}

return ret;
}

@Nonnull
private static TradeSettlementHeaderMonetarySummationType _convertSpecifiedTradeSettlementHeaderMonetarySummation (@Nonnull final InvoiceType aUBLInvoice)
{
final TradeSettlementHeaderMonetarySummationType aTSHMST = new TradeSettlementHeaderMonetarySummationType ();
final MonetaryTotalType aUBLLMT = aUBLInvoice.getLegalMonetaryTotal ();
if (aUBLLMT != null)
{
ifNotNull (aTSHMST::addLineTotalAmount, convertAmount (aUBLLMT.getLineExtensionAmount ()));
ifNotNull (aTSHMST::addChargeTotalAmount, convertAmount (aUBLLMT.getChargeTotalAmount ()));
ifNotNull (aTSHMST::addAllowanceTotalAmount, convertAmount (aUBLLMT.getAllowanceTotalAmount ()));
ifNotNull (aTSHMST::addTaxBasisTotalAmount, convertAmount (aUBLLMT.getTaxExclusiveAmount ()));
}

if (aUBLInvoice.hasTaxTotalEntries ())
{
// Currency ID is required here
ifNotNull (aTSHMST::addTaxTotalAmount, convertAmount (aUBLInvoice.getTaxTotalAtIndex (0).getTaxAmount (), true));
}

if (aUBLLMT != null)
{
ifNotNull (aTSHMST::addRoundingAmount, convertAmount (aUBLLMT.getPayableRoundingAmount ()));
ifNotNull (aTSHMST::addGrandTotalAmount, convertAmount (aUBLLMT.getTaxInclusiveAmount ()));
ifNotNull (aTSHMST::addTotalPrepaidAmount, convertAmount (aUBLLMT.getPrepaidAmount ()));
ifNotNull (aTSHMST::addDuePayableAmount, convertAmount (aUBLLMT.getPayableAmount ()));
}

return aTSHMST;
}

@Nonnull
private static List <TradeTaxType> _convertApplicableTradeTax (@Nonnull final InvoiceType aUBLInvoice)
{
Expand Down Expand Up @@ -332,28 +300,6 @@ private static List <TradeTaxType> _convertApplicableTradeTax (@Nonnull final In
return ret;
}

@Nonnull
private static List <TradePaymentTermsType> _convertSpecifiedTradePaymentTerms (@Nonnull final InvoiceType aUBLInvoice)
{
final List <TradePaymentTermsType> ret = new ArrayList <> ();
for (final PaymentTermsType aPTT : aUBLInvoice.getPaymentTerms ())
{
final TradePaymentTermsType aTPTT = new TradePaymentTermsType ();

for (final var aNote : aPTT.getNote ())
aTPTT.addDescription (convertText (aNote.getValue ()));

if (aUBLInvoice.hasPaymentMeansEntries ())
{
final PaymentMeansType aPM = aUBLInvoice.getPaymentMeans ().get (0);
if (aPM.getPaymentDueDate () != null)
aTPTT.setDueDateDateTime (convertDate (aPM.getPaymentDueDate ().getValueLocal ()));
}
ret.add (aTPTT);
}
return ret;
}

@Nonnull
private static List <TradeAllowanceChargeType> _convertSpecifiedTradeAllowanceCharge (@Nonnull final InvoiceType aUBLInvoice)
{
Expand Down Expand Up @@ -400,58 +346,112 @@ private static List <TradeAllowanceChargeType> _convertSpecifiedTradeAllowanceCh
}

@Nonnull
private static List <ReferencedDocumentType> _convertAdditionalReferencedDocument (@Nonnull final InvoiceType aUBLInvoice)
private static List <TradePaymentTermsType> _convertSpecifiedTradePaymentTerms (@Nonnull final InvoiceType aUBLInvoice)
{
final List <ReferencedDocumentType> ret = new ArrayList <> ();
for (final DocumentReferenceType aDocDesc : aUBLInvoice.getAdditionalDocumentReference ())
final List <TradePaymentTermsType> ret = new ArrayList <> ();
for (final PaymentTermsType aPTT : aUBLInvoice.getPaymentTerms ())
{
final ReferencedDocumentType aURDT = new ReferencedDocumentType ();

if (aDocDesc.getID () != null)
aURDT.setIssuerAssignedID (aDocDesc.getIDValue ());
final TradePaymentTermsType aTPTT = new TradePaymentTermsType ();

// Add DocumentTypeCode where possible
if (aDocDesc.getDocumentTypeCode () != null && isValidDocumentReferenceTypeCode (aDocDesc.getDocumentTypeCodeValue ()))
aURDT.setTypeCode (aDocDesc.getDocumentTypeCodeValue ());
else
aURDT.setTypeCode ("916");
for (final var aNote : aPTT.getNote ())
aTPTT.addDescription (convertText (aNote.getValue ()));

if (aDocDesc.getIssueDate () != null)
if (aUBLInvoice.hasPaymentMeansEntries ())
{
final FormattedDateTimeType aFIDT = new FormattedDateTimeType ();
aFIDT.setDateTimeString (createFormattedDateValue (aDocDesc.getIssueDateValueLocal ()));
aURDT.setFormattedIssueDateTime (aFIDT);
final PaymentMeansType aPM = aUBLInvoice.getPaymentMeans ().get (0);
if (aPM.getPaymentDueDate () != null)
aTPTT.setDueDateDateTime (convertDate (aPM.getPaymentDueDate ().getValueLocal ()));
}
ret.add (aTPTT);
}
return ret;
}

for (final var aDesc : aDocDesc.getDocumentDescription ())
{
final TextType aText = new TextType ();
aText.setValue (aDesc.getValue ());
aText.setLanguageID (aDesc.getLanguageID ());
aText.setLanguageLocaleID (aDesc.getLanguageLocaleID ());
aURDT.addName (aText);
}
@Nonnull
private static TradeSettlementHeaderMonetarySummationType _createSpecifiedTradeSettlementHeaderMonetarySummation (@Nonnull final InvoiceType aUBLInvoice)
{
final TradeSettlementHeaderMonetarySummationType aTSHMST = new TradeSettlementHeaderMonetarySummationType ();
final MonetaryTotalType aUBLLMT = aUBLInvoice.getLegalMonetaryTotal ();
if (aUBLLMT != null)
{
ifNotNull (aTSHMST::addLineTotalAmount, convertAmount (aUBLLMT.getLineExtensionAmount ()));
ifNotNull (aTSHMST::addChargeTotalAmount, convertAmount (aUBLLMT.getChargeTotalAmount ()));
ifNotNull (aTSHMST::addAllowanceTotalAmount, convertAmount (aUBLLMT.getAllowanceTotalAmount ()));
ifNotNull (aTSHMST::addTaxBasisTotalAmount, convertAmount (aUBLLMT.getTaxExclusiveAmount ()));
}

final AttachmentType aAttachment = aDocDesc.getAttachment ();
if (aAttachment != null)
{
// External Reference and Embedded Document Binary Object should be
// mutually exclusive
if (aAttachment.getExternalReference () != null && aAttachment.getExternalReference ().getURI () != null)
{
aURDT.setURIID (aAttachment.getExternalReference ().getURI ().getValue ());
}
if (aUBLInvoice.hasTaxTotalEntries ())
{
// Currency ID is required here
ifNotNull (aTSHMST::addTaxTotalAmount, convertAmount (aUBLInvoice.getTaxTotalAtIndex (0).getTaxAmount (), true));
}

if (aAttachment.getEmbeddedDocumentBinaryObject () != null)
{
final BinaryObjectType aBOT = new BinaryObjectType ();
aBOT.setMimeCode (aAttachment.getEmbeddedDocumentBinaryObject ().getMimeCode ());
aBOT.setValue (aAttachment.getEmbeddedDocumentBinaryObject ().getValue ());
aURDT.addAttachmentBinaryObject (aBOT);
}
}
ret.add (aURDT);
if (aUBLLMT != null)
{
ifNotNull (aTSHMST::addRoundingAmount, convertAmount (aUBLLMT.getPayableRoundingAmount ()));
ifNotNull (aTSHMST::addGrandTotalAmount, convertAmount (aUBLLMT.getTaxInclusiveAmount ()));
ifNotNull (aTSHMST::addTotalPrepaidAmount, convertAmount (aUBLLMT.getPrepaidAmount ()));
ifNotNull (aTSHMST::addDuePayableAmount, convertAmount (aUBLLMT.getPayableAmount ()));
}

return aTSHMST;
}

@Nonnull
private static HeaderTradeSettlementType _createApplicableHeaderTradeSettlement (@Nonnull final InvoiceType aUBLInvoice)
{
final HeaderTradeSettlementType ret = new HeaderTradeSettlementType ();

final PaymentMeansType aPM = aUBLInvoice.hasPaymentMeansEntries () ? aUBLInvoice.getPaymentMeansAtIndex (0) : null;

if (aPM != null && aPM.hasPaymentIDEntries ())
ret.addPaymentReference (convertText (aPM.getPaymentIDAtIndex (0).getValue ()));

ret.setInvoiceCurrencyCode (aUBLInvoice.getDocumentCurrencyCode ().getValue ());

if (aUBLInvoice.getPayeeParty () != null)
ret.setPayeeTradeParty (convertParty (aUBLInvoice.getPayeeParty ()));

if (aPM != null)
{
final TradeSettlementPaymentMeansType aTSPMT = new TradeSettlementPaymentMeansType ();
aTSPMT.setTypeCode (aPM.getPaymentMeansCodeValue ());

final CreditorFinancialAccountType aCFAT = new CreditorFinancialAccountType ();
if (aPM.getPayeeFinancialAccount () != null)
aCFAT.setIBANID (aPM.getPayeeFinancialAccount ().getIDValue ());

aTSPMT.setPayeePartyCreditorFinancialAccount (aCFAT);
ret.addSpecifiedTradeSettlementPaymentMeans (aTSPMT);
}

ret.setApplicableTradeTax (_convertApplicableTradeTax (aUBLInvoice));

if (aUBLInvoice.hasInvoicePeriodEntries ())
{
final PeriodType aIP = aUBLInvoice.getInvoicePeriodAtIndex (0);

final SpecifiedPeriodType aSPT = new SpecifiedPeriodType ();
if (aIP.getStartDate () != null)
aSPT.setStartDateTime (convertDate (aIP.getStartDate ().getValueLocal ()));

if (aIP.getEndDate () != null)
aSPT.setEndDateTime (convertDate (aIP.getEndDate ().getValueLocal ()));

ret.setBillingSpecifiedPeriod (aSPT);
}

ret.setSpecifiedTradeAllowanceCharge (_convertSpecifiedTradeAllowanceCharge (aUBLInvoice));
ret.setSpecifiedTradePaymentTerms (_convertSpecifiedTradePaymentTerms (aUBLInvoice));
ret.setSpecifiedTradeSettlementHeaderMonetarySummation (_createSpecifiedTradeSettlementHeaderMonetarySummation (aUBLInvoice));

if (aUBLInvoice.getAccountingCost () != null)
{
final TradeAccountingAccountType aTAAT = new TradeAccountingAccountType ();
aTAAT.setID (aUBLInvoice.getAccountingCost ().getValue ());
ret.addReceivableSpecifiedTradeAccountingAccount (aTAAT);
}

return ret;
}

Expand Down Expand Up @@ -533,11 +533,11 @@ public static CrossIndustryInvoiceType convertToCrossIndustryInvoice (@Nonnull f
}

// ApplicableHeaderTradeDelivery
aSCTT.setApplicableHeaderTradeDelivery (_convertApplicableHeaderTradeDelivery (aUBLInvoice.hasDeliveryEntries () ? aUBLInvoice.getDeliveryAtIndex (0)
: null));
aSCTT.setApplicableHeaderTradeDelivery (_createApplicableHeaderTradeDelivery (aUBLInvoice.hasDeliveryEntries () ? aUBLInvoice.getDeliveryAtIndex (0)
: null));

// ApplicableHeaderTradeSettlement
aSCTT.setApplicableHeaderTradeSettlement (_convertApplicableHeaderTradeSettlement (aUBLInvoice));
aSCTT.setApplicableHeaderTradeSettlement (_createApplicableHeaderTradeSettlement (aUBLInvoice));

aCIIInvoice.setSupplyChainTradeTransaction (aSCTT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static ESuccess convertUBL21InvoicetoCIID16B (@Nonnull @WillNotClose fina
return ESuccess.FAILURE;

// Main conversion
final CrossIndustryInvoiceType aCrossIndustryInvoice = UBL21ToCII16BConverter.convertToCrossIndustryInvoice (aUBLInvoice, aErrorList);
final CrossIndustryInvoiceType aCrossIndustryInvoice = UBL21InvoiceToCII16BConverter.convertToCrossIndustryInvoice (aUBLInvoice, aErrorList);
if (aCrossIndustryInvoice == null)
return ESuccess.FAILURE;

Expand Down
Loading

0 comments on commit ece322a

Please sign in to comment.