Search in sources :

Example 1 with CreditNoteType

use of oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType in project en16931-cii2ubl by phax.

the class CIIToUBL21ConverterTest method testConvertAndValidateAll.

@Test
public void testConvertAndValidateAll() {
    final String sBasePath = MockSettings.getBaseDir().getAbsolutePath();
    for (final File aFile : MockSettings.getAllTestFiles()) {
        LOGGER.info("Converting " + aFile.toString() + " to UBL 2.1");
        // Main conversion
        final ErrorList aErrorList = new ErrorList();
        final Serializable aInvoice = new CIIToUBL21Converter().convertCIItoUBL(aFile, aErrorList);
        assertTrue("Errors: " + aErrorList.toString(), aErrorList.isEmpty());
        assertNotNull(aInvoice);
        final File aDestFile = new File("toubl21/" + aFile.getParentFile().getAbsolutePath().substring(sBasePath.length()), FilenameHelper.getBaseName(aFile.getName()) + "-ubl.xml");
        final ValidationResultList aResultList;
        if (aInvoice instanceof InvoiceType) {
            final InvoiceType aUBLInvoice = (InvoiceType) aInvoice;
            // Check UBL XSD scheme
            final UBL21WriterBuilder<InvoiceType> aWriter = UBL21Writer.invoice().setFormattedOutput(true);
            aWriter.write(aUBLInvoice, aDestFile);
            // Validate against EN16931 validation rules
            aResultList = ValidationExecutionManager.executeValidation(MockSettings.VES_REGISTRY.getOfID(EN16931Validation.VID_UBL_INVOICE_137), ValidationSourceXML.create(new FileSystemResource(aDestFile)));
        } else {
            final CreditNoteType aUBLInvoice = (CreditNoteType) aInvoice;
            // Check UBL XSD scheme
            final UBL21WriterBuilder<CreditNoteType> aWriter = UBL21Writer.creditNote().setFormattedOutput(true);
            aWriter.write(aUBLInvoice, aDestFile);
            // Validate against EN16931 validation rules
            aResultList = ValidationExecutionManager.executeValidation(MockSettings.VES_REGISTRY.getOfID(EN16931Validation.VID_UBL_CREDIT_NOTE_137), ValidationSourceXML.create(new FileSystemResource(aDestFile)));
        }
        assertNotNull(aResultList);
        // Check that no errors (but maybe warnings) are contained
        for (final ValidationResult aResult : aResultList) {
            assertTrue("Errors: " + aResult.getErrorList().toString(), aResult.getErrorList().isEmpty());
        }
    }
}
Also used : Serializable(java.io.Serializable) ErrorList(com.helger.commons.error.list.ErrorList) ValidationResultList(com.helger.phive.api.result.ValidationResultList) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) ValidationResult(com.helger.phive.api.result.ValidationResult) File(java.io.File) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) Test(org.junit.Test)

Example 2 with CreditNoteType

use of oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType in project en16931-cii2ubl by phax.

the class CIIToUBL23ConverterTest method testConvertAndValidateAll.

@Test
public void testConvertAndValidateAll() {
    final String sBasePath = MockSettings.getBaseDir().getAbsolutePath();
    for (final File aFile : MockSettings.getAllTestFiles()) {
        LOGGER.info("Converting " + aFile.toString() + " to UBL 2.3");
        // Main conversion
        final ErrorList aErrorList = new ErrorList();
        final Serializable aInvoice = new CIIToUBL23Converter().convertCIItoUBL(aFile, aErrorList);
        assertTrue("Errors: " + aErrorList.toString(), aErrorList.isEmpty());
        assertNotNull(aInvoice);
        final File aDestFile = new File("toubl23/" + aFile.getParentFile().getAbsolutePath().substring(sBasePath.length()), FilenameHelper.getBaseName(aFile.getName()) + "-ubl.xml");
        final ValidationResultList aResultList;
        if (aInvoice instanceof InvoiceType) {
            final InvoiceType aUBLInvoice = (InvoiceType) aInvoice;
            // Check UBL XSD scheme
            final UBL23WriterBuilder<InvoiceType> aWriter = UBL23Writer.invoice().setFormattedOutput(true);
            aWriter.write(aUBLInvoice, aDestFile);
            // Validate against EN16931 validation rules
            aResultList = ValidationExecutionManager.executeValidation(MockSettings.VES_REGISTRY.getOfID(EN16931Validation.VID_UBL_INVOICE_137), ValidationSourceXML.create(new FileSystemResource(aDestFile)));
        } else {
            final CreditNoteType aUBLInvoice = (CreditNoteType) aInvoice;
            // Check UBL XSD scheme
            final UBL23WriterBuilder<CreditNoteType> aWriter = UBL23Writer.creditNote().setFormattedOutput(true);
            aWriter.write(aUBLInvoice, aDestFile);
            // Validate against EN16931 validation rules
            aResultList = ValidationExecutionManager.executeValidation(MockSettings.VES_REGISTRY.getOfID(EN16931Validation.VID_UBL_CREDIT_NOTE_137), ValidationSourceXML.create(new FileSystemResource(aDestFile)));
        }
        assertNotNull(aResultList);
        // Check that no errors (but maybe warnings) are contained
        for (final ValidationResult aResult : aResultList) {
            assertTrue("Errors: " + aResult.getErrorList().toString(), aResult.getErrorList().isEmpty());
        }
    }
}
Also used : Serializable(java.io.Serializable) ErrorList(com.helger.commons.error.list.ErrorList) ValidationResultList(com.helger.phive.api.result.ValidationResultList) FileSystemResource(com.helger.commons.io.resource.FileSystemResource) ValidationResult(com.helger.phive.api.result.ValidationResult) File(java.io.File) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType) Test(org.junit.Test)

Example 3 with CreditNoteType

use of oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType in project en16931-cii2ubl by phax.

the class CIIToUBL22Converter method convertToCreditNote.

@Nullable
public CreditNoteType convertToCreditNote(@Nonnull final CrossIndustryInvoiceType aCIICreditNote, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.notNull(aCIICreditNote, "CIICreditNote");
    ValueEnforcer.notNull(aErrorList, "ErrorList");
    final ExchangedDocumentType aED = aCIICreditNote.getExchangedDocument();
    final SupplyChainTradeTransactionType aSCTT = aCIICreditNote.getSupplyChainTradeTransaction();
    if (aSCTT == null) {
        // Mandatory element
        return null;
    }
    final HeaderTradeAgreementType aHeaderAgreement = aSCTT.getApplicableHeaderTradeAgreement();
    final HeaderTradeDeliveryType aHeaderDelivery = aSCTT.getApplicableHeaderTradeDelivery();
    final HeaderTradeSettlementType aHeaderSettlement = aSCTT.getApplicableHeaderTradeSettlement();
    if (aHeaderAgreement == null || aHeaderDelivery == null || aHeaderSettlement == null) {
        // All mandatory elements
        return null;
    }
    final CreditNoteType aUBLCreditNote = new CreditNoteType();
    if (false)
        aUBLCreditNote.setUBLVersionID(UBL_VERSION);
    if (StringHelper.hasText(getCustomizationID()))
        aUBLCreditNote.setCustomizationID(getCustomizationID());
    if (StringHelper.hasText(getProfileID()))
        aUBLCreditNote.setProfileID(getProfileID());
    if (aED != null)
        aUBLCreditNote.setID(aED.getIDValue());
    // Mandatory supplier
    final SupplierPartyType aUBLSupplier = new SupplierPartyType();
    aUBLCreditNote.setAccountingSupplierParty(aUBLSupplier);
    // Mandatory customer
    final CustomerPartyType aUBLCustomer = new CustomerPartyType();
    aUBLCreditNote.setAccountingCustomerParty(aUBLCustomer);
    // IssueDate
    {
        LocalDate aIssueDate = null;
        if (aED != null && aED.getIssueDateTime() != null)
            aIssueDate = _parseDate(aED.getIssueDateTime().getDateTimeString(), aErrorList);
        if (aIssueDate != null)
            aUBLCreditNote.setIssueDate(aIssueDate);
    }
    // DueDate
    {
        LocalDate aDueDate = null;
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) if (aPaymentTerms.getDueDateDateTime() != null) {
            aDueDate = _parseDate(aPaymentTerms.getDueDateDateTime().getDateTimeString(), aErrorList);
            if (aDueDate != null)
                break;
        }
        if (aDueDate != null)
            aUBLCreditNote.setDueDate(aDueDate);
    }
    // CreditNoteTypeCode
    if (aED != null)
        aUBLCreditNote.setCreditNoteTypeCode(aED.getTypeCodeValue());
    // Note
    if (aED != null)
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aEDNote : aED.getIncludedNote()) ifNotNull(aUBLCreditNote::addNote, _copyNote(aEDNote));
    // TaxPointDate
    for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
        if (aTradeTax.getTaxPointDate() != null) {
            final LocalDate aTaxPointDate = _parseDate(aTradeTax.getTaxPointDate().getDateString(), aErrorList);
            if (aTaxPointDate != null) {
                // Use the first tax point date only
                aUBLCreditNote.setTaxPointDate(aTaxPointDate);
                break;
            }
        }
    }
    // DocumentCurrencyCode
    final String sDefaultCurrencyCode = aHeaderSettlement.getInvoiceCurrencyCodeValue();
    aUBLCreditNote.setDocumentCurrencyCode(sDefaultCurrencyCode);
    // TaxCurrencyCode
    if (aHeaderSettlement.getTaxCurrencyCodeValue() != null) {
        aUBLCreditNote.setTaxCurrencyCode(aHeaderSettlement.getTaxCurrencyCodeValue());
    }
    // AccountingCost
    for (final TradeAccountingAccountType aAccount : aHeaderSettlement.getReceivableSpecifiedTradeAccountingAccount()) {
        final String sID = aAccount.getIDValue();
        if (StringHelper.hasText(sID)) {
            // Use the first ID
            aUBLCreditNote.setAccountingCost(sID);
            break;
        }
    }
    // BuyerReferences
    if (aHeaderAgreement.getBuyerReferenceValue() != null) {
        aUBLCreditNote.setBuyerReference(aHeaderAgreement.getBuyerReferenceValue());
    }
    // CreditNotePeriod
    {
        final SpecifiedPeriodType aSPT = aHeaderSettlement.getBillingSpecifiedPeriod();
        if (aSPT != null) {
            final DateTimeType aStartDT = aSPT.getStartDateTime();
            final DateTimeType aEndDT = aSPT.getEndDateTime();
            if (aStartDT != null && aEndDT != null) {
                final PeriodType aUBLPeriod = new PeriodType();
                aUBLPeriod.setStartDate(_parseDate(aStartDT.getDateTimeString(), aErrorList));
                aUBLPeriod.setEndDate(_parseDate(aEndDT.getDateTimeString(), aErrorList));
                aUBLCreditNote.addInvoicePeriod(aUBLPeriod);
            }
        }
    }
    // OrderReference
    {
        final OrderReferenceType aUBLOrderRef = _createUBLOrderRef(aHeaderAgreement.getBuyerOrderReferencedDocument(), aHeaderAgreement.getSellerOrderReferencedDocument());
        aUBLCreditNote.setOrderReference(aUBLOrderRef);
    }
    // BillingReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderSettlement.getInvoiceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null) {
            final BillingReferenceType aUBLBillingRef = new BillingReferenceType();
            aUBLBillingRef.setCreditNoteDocumentReference(aUBLDocRef);
            aUBLCreditNote.addBillingReference(aUBLBillingRef);
        }
    }
    // DespatchDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getDespatchAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLCreditNote.addDespatchDocumentReference(aUBLDocRef);
    }
    // ReceiptDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getReceivingAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLCreditNote.addReceiptDocumentReference(aUBLDocRef);
    }
    // OriginatorDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Use for "Tender or lot reference" with TypeCode "50"
            if (isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLCreditNote.addOriginatorDocumentReference(aUBLDocRef);
            }
        }
    }
    // ContractDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderAgreement.getContractReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLCreditNote.addContractDocumentReference(aUBLDocRef);
    }
    // AdditionalDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Except OriginatorDocumentReference
            if (!isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLCreditNote.addAdditionalDocumentReference(aUBLDocRef);
            }
        }
    }
    // ProjectReference
    {
        final ProcuringProjectType aSpecifiedProcuring = aHeaderAgreement.getSpecifiedProcuringProject();
        if (aSpecifiedProcuring != null) {
            final String sID = aSpecifiedProcuring.getIDValue();
            if (StringHelper.hasText(sID)) {
                final ProjectReferenceType aUBLProjectRef = new ProjectReferenceType();
                aUBLProjectRef.setID(sID);
                aUBLCreditNote.addProjectReference(aUBLProjectRef);
            }
        }
    }
    // Supplier Party
    {
        final TradePartyType aSellerParty = aHeaderAgreement.getSellerTradeParty();
        if (aSellerParty != null) {
            final PartyType aUBLParty = _convertParty(aSellerParty, true);
            for (final TaxRegistrationType aTaxRegistration : aSellerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aSellerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aSellerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLSupplier.setParty(aUBLParty);
        }
    }
    // Customer Party
    {
        final TradePartyType aBuyerParty = aHeaderAgreement.getBuyerTradeParty();
        if (aBuyerParty != null) {
            final PartyType aUBLParty = _convertParty(aBuyerParty, false);
            for (final TaxRegistrationType aTaxRegistration : aBuyerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aBuyerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aBuyerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCustomer.setParty(aUBLParty);
        }
    }
    // Payee Party
    {
        final TradePartyType aPayeeParty = aHeaderSettlement.getPayeeTradeParty();
        if (aPayeeParty != null) {
            final PartyType aUBLParty = _convertParty(aPayeeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aPayeeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aPayeeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aPayeeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCreditNote.setPayeeParty(aUBLParty);
        }
    }
    // Tax Representative Party
    {
        final TradePartyType aTaxRepresentativeParty = aHeaderAgreement.getSellerTaxRepresentativeTradeParty();
        if (aTaxRepresentativeParty != null) {
            final PartyType aUBLParty = _convertParty(aTaxRepresentativeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aTaxRepresentativeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aTaxRepresentativeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aTaxRepresentativeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCreditNote.setTaxRepresentativeParty(aUBLParty);
        }
    }
    // Delivery
    {
        final TradePartyType aShipToParty = aHeaderDelivery.getShipToTradeParty();
        if (aShipToParty != null) {
            final DeliveryType aUBLDelivery = new DeliveryType();
            final SupplyChainEventType aSCE = aHeaderDelivery.getActualDeliverySupplyChainEvent();
            if (aSCE != null) {
                final DateTimeType aODT = aSCE.getOccurrenceDateTime();
                if (aODT != null)
                    aUBLDelivery.setActualDeliveryDate(_parseDate(aODT.getDateTimeString(), aErrorList));
            }
            final oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22.LocationType aUBLDeliveryLocation = new oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22.LocationType();
            boolean bUseLocation = false;
            final oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_22.IDType aUBLID = _extractFirstPartyID(aShipToParty);
            if (aUBLID != null) {
                aUBLDeliveryLocation.setID(aUBLID);
                bUseLocation = true;
            }
            final TradeAddressType aPostalAddress = aShipToParty.getPostalTradeAddress();
            if (aPostalAddress != null) {
                aUBLDeliveryLocation.setAddress(_convertPostalAddress(aPostalAddress));
                bUseLocation = true;
            }
            if (bUseLocation)
                aUBLDelivery.setDeliveryLocation(aUBLDeliveryLocation);
            final TextType aName = aShipToParty.getName();
            if (aName != null) {
                final PartyType aUBLDeliveryParty = new PartyType();
                final PartyNameType aUBLPartyName = new PartyNameType();
                aUBLPartyName.setName(_copyName(aName, new NameType()));
                aUBLDeliveryParty.addPartyName(aUBLPartyName);
                aUBLDelivery.setDeliveryParty(aUBLDeliveryParty);
            }
            aUBLCreditNote.addDelivery(aUBLDelivery);
        }
    }
    // Payment means
    {
        for (final TradeSettlementPaymentMeansType aPaymentMeans : aHeaderSettlement.getSpecifiedTradeSettlementPaymentMeans()) {
            _convertPaymentMeans(aHeaderSettlement, aPaymentMeans, x -> _addPartyID(x, aUBLCreditNote.getAccountingSupplierParty().getParty()), aUBLCreditNote::addPaymentMeans, aErrorList);
            // Allowed again in 1.2.1: exactly 2
            if (false)
                // Since v1.2.0 only one is allowed
                if (true)
                    break;
        }
    }
    // Payment Terms
    {
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) {
            final PaymentTermsType aUBLPaymenTerms = new PaymentTermsType();
            for (final TextType aDesc : aPaymentTerms.getDescription()) ifNotNull(aUBLPaymenTerms::addNote, _copyNote(aDesc));
            if (aUBLPaymenTerms.hasNoteEntries())
                aUBLCreditNote.addPaymentTerms(aUBLPaymenTerms);
        }
    }
    // Allowance Charge
    {
        for (final TradeAllowanceChargeType aAllowanceCharge : aHeaderSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryCreditNote", "SupplyChainTradeTransaction", "ApplicableHeaderTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLAllowanceCharge = new AllowanceChargeType();
                aUBLAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aAllowanceCharge, aUBLAllowanceCharge, sDefaultCurrencyCode);
                aUBLCreditNote.addAllowanceCharge(aUBLAllowanceCharge);
            }
        }
    }
    final TradeSettlementHeaderMonetarySummationType aSTSHMS = aHeaderSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation();
    // TaxTotal
    {
        TaxTotalType aUBLTaxTotal = null;
        if (aSTSHMS != null && aSTSHMS.hasTaxTotalAmountEntries()) {
            // For all currencies
            for (final AmountType aTaxTotalAmount : aSTSHMS.getTaxTotalAmount()) {
                final TaxTotalType aUBLCurTaxTotal = new TaxTotalType();
                aUBLCurTaxTotal.setTaxAmount(_copyAmount(aTaxTotalAmount, new TaxAmountType(), sDefaultCurrencyCode));
                aUBLCreditNote.addTaxTotal(aUBLCurTaxTotal);
                if (aUBLTaxTotal == null) {
                    // Use the first one
                    aUBLTaxTotal = aUBLCurTaxTotal;
                }
            }
        } else {
            // Mandatory in UBL
            final TaxAmountType aUBLTaxAmount = new TaxAmountType();
            aUBLTaxAmount.setValue(BigDecimal.ZERO);
            aUBLTaxAmount.setCurrencyID(sDefaultCurrencyCode);
            aUBLTaxTotal = new TaxTotalType();
            aUBLTaxTotal.setTaxAmount(aUBLTaxAmount);
            aUBLCreditNote.addTaxTotal(aUBLTaxTotal);
        }
        for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
            final TaxSubtotalType aUBLTaxSubtotal = new TaxSubtotalType();
            if (aTradeTax.hasBasisAmountEntries()) {
                aUBLTaxSubtotal.setTaxableAmount(_copyAmount(aTradeTax.getBasisAmountAtIndex(0), new TaxableAmountType(), sDefaultCurrencyCode));
            }
            if (aTradeTax.hasCalculatedAmountEntries()) {
                aUBLTaxSubtotal.setTaxAmount(_copyAmount(aTradeTax.getCalculatedAmountAtIndex(0), new TaxAmountType(), sDefaultCurrencyCode));
            }
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            if (StringHelper.hasText(aTradeTax.getExemptionReasonCodeValue()))
                aUBLTaxCategory.setTaxExemptionReasonCode(aTradeTax.getExemptionReasonCodeValue());
            if (aTradeTax.getExemptionReason() != null) {
                final TaxExemptionReasonType aUBLTaxExemptionReason = new TaxExemptionReasonType();
                aUBLTaxExemptionReason.setValue(aTradeTax.getExemptionReason().getValue());
                aUBLTaxExemptionReason.setLanguageID(aTradeTax.getExemptionReason().getLanguageID());
                aUBLTaxExemptionReason.setLanguageLocaleID(aTradeTax.getExemptionReason().getLanguageLocaleID());
                aUBLTaxCategory.addTaxExemptionReason(aUBLTaxExemptionReason);
            }
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLTaxSubtotal.setTaxCategory(aUBLTaxCategory);
            aUBLTaxTotal.addTaxSubtotal(aUBLTaxSubtotal);
        }
    }
    // LegalMonetaryTotal
    {
        final MonetaryTotalType aUBLMonetaryTotal = new MonetaryTotalType();
        if (aSTSHMS != null) {
            if (aSTSHMS.hasLineTotalAmountEntries())
                aUBLMonetaryTotal.setLineExtensionAmount(_copyAmount(aSTSHMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTaxBasisTotalAmountEntries())
                aUBLMonetaryTotal.setTaxExclusiveAmount(_copyAmount(aSTSHMS.getTaxBasisTotalAmountAtIndex(0), new TaxExclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasGrandTotalAmountEntries())
                aUBLMonetaryTotal.setTaxInclusiveAmount(_copyAmount(aSTSHMS.getGrandTotalAmountAtIndex(0), new TaxInclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasAllowanceTotalAmountEntries())
                aUBLMonetaryTotal.setAllowanceTotalAmount(_copyAmount(aSTSHMS.getAllowanceTotalAmountAtIndex(0), new AllowanceTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasChargeTotalAmountEntries())
                aUBLMonetaryTotal.setChargeTotalAmount(_copyAmount(aSTSHMS.getChargeTotalAmountAtIndex(0), new ChargeTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTotalPrepaidAmountEntries())
                aUBLMonetaryTotal.setPrepaidAmount(_copyAmount(aSTSHMS.getTotalPrepaidAmountAtIndex(0), new PrepaidAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasRoundingAmountEntries()) {
                // compatibility
                if (MathHelper.isNE0(aSTSHMS.getRoundingAmountAtIndex(0).getValue()))
                    aUBLMonetaryTotal.setPayableRoundingAmount(_copyAmount(aSTSHMS.getRoundingAmountAtIndex(0), new PayableRoundingAmountType(), sDefaultCurrencyCode));
            }
            if (aSTSHMS.hasDuePayableAmountEntries())
                aUBLMonetaryTotal.setPayableAmount(_copyAmount(aSTSHMS.getDuePayableAmountAtIndex(0), new PayableAmountType(), sDefaultCurrencyCode));
        }
        aUBLCreditNote.setLegalMonetaryTotal(aUBLMonetaryTotal);
    }
    // All invoice lines
    for (final SupplyChainTradeLineItemType aLineItem : aSCTT.getIncludedSupplyChainTradeLineItem()) {
        final CreditNoteLineType aUBLCreditNoteLine = new CreditNoteLineType();
        final DocumentLineDocumentType aDLD = aLineItem.getAssociatedDocumentLineDocument();
        aUBLCreditNoteLine.setID(_copyID(aDLD.getLineID()));
        // Note
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aLineNote : aDLD.getIncludedNote()) ifNotNull(aUBLCreditNoteLine::addNote, _copyNote(aLineNote));
        // Line extension amount
        boolean bLineExtensionAmountIsNegative = false;
        final LineTradeSettlementType aLineSettlement = aLineItem.getSpecifiedLineTradeSettlement();
        final TradeSettlementLineMonetarySummationType aSTSLMS = aLineSettlement.getSpecifiedTradeSettlementLineMonetarySummation();
        if (aSTSLMS != null) {
            if (aSTSLMS.hasLineTotalAmountEntries()) {
                aUBLCreditNoteLine.setLineExtensionAmount(_copyAmount(aSTSLMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
                if (isLT0Strict(aUBLCreditNoteLine.getLineExtensionAmountValue()))
                    bLineExtensionAmountIsNegative = true;
            }
        }
        // CreditNoted quantity
        final LineTradeDeliveryType aLineDelivery = aLineItem.getSpecifiedLineTradeDelivery();
        if (aLineDelivery != null) {
            final QuantityType aBilledQuantity = aLineDelivery.getBilledQuantity();
            if (aBilledQuantity != null) {
                aUBLCreditNoteLine.setCreditedQuantity(_copyQuantity(aBilledQuantity, new CreditedQuantityType()));
            }
        }
        // Accounting cost
        if (aLineSettlement.hasReceivableSpecifiedTradeAccountingAccountEntries()) {
            final TradeAccountingAccountType aLineAA = aLineSettlement.getReceivableSpecifiedTradeAccountingAccountAtIndex(0);
            aUBLCreditNoteLine.setAccountingCost(aLineAA.getIDValue());
        }
        // CreditNote period
        final SpecifiedPeriodType aLineBillingPeriod = aLineSettlement.getBillingSpecifiedPeriod();
        if (aLineBillingPeriod != null) {
            final PeriodType aUBLLinePeriod = new PeriodType();
            if (aLineBillingPeriod.getStartDateTime() != null)
                aUBLLinePeriod.setStartDate(_parseDate(aLineBillingPeriod.getStartDateTime().getDateTimeString(), aErrorList));
            if (aLineBillingPeriod.getEndDateTime() != null)
                aUBLLinePeriod.setEndDate(_parseDate(aLineBillingPeriod.getEndDateTime().getDateTimeString(), aErrorList));
            aUBLCreditNoteLine.addInvoicePeriod(aUBLLinePeriod);
        }
        // Order line reference
        final LineTradeAgreementType aLineAgreement = aLineItem.getSpecifiedLineTradeAgreement();
        if (aLineAgreement != null) {
            final ReferencedDocumentType aBuyerOrderReference = aLineAgreement.getBuyerOrderReferencedDocument();
            if (aBuyerOrderReference != null && StringHelper.hasText(aBuyerOrderReference.getLineIDValue())) {
                final OrderLineReferenceType aUBLOrderLineReference = new OrderLineReferenceType();
                aUBLOrderLineReference.setLineID(_copyID(aBuyerOrderReference.getLineID(), new LineIDType()));
                aUBLCreditNoteLine.addOrderLineReference(aUBLOrderLineReference);
            }
        }
        // Document reference
        for (final ReferencedDocumentType aLineReferencedDocument : aLineSettlement.getAdditionalReferencedDocument()) {
            final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aLineReferencedDocument, aErrorList);
            if (aUBLDocRef != null)
                aUBLCreditNoteLine.addDocumentReference(aUBLDocRef);
        }
        // Allowance charge
        for (final TradeAllowanceChargeType aLineAllowanceCharge : aLineSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aLineAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aLineAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryCreditNote", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aLineAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                aUBLCreditNoteLine.addAllowanceCharge(aUBLLineAllowanceCharge);
            }
        }
        // Item
        final ItemType aUBLItem = new ItemType();
        final TradeProductType aLineProduct = aLineItem.getSpecifiedTradeProduct();
        if (aLineProduct != null) {
            final TextType aDescription = aLineProduct.getDescription();
            if (aDescription != null)
                ifNotNull(aUBLItem::addDescription, _copyName(aDescription, new DescriptionType()));
            if (aLineProduct.hasNameEntries())
                aUBLItem.setName(_copyName(aLineProduct.getNameAtIndex(0), new NameType()));
            final IDType aBuyerAssignedID = aLineProduct.getBuyerAssignedID();
            if (aBuyerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aBuyerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setBuyersItemIdentification(aUBLID);
            }
            final IDType aSellerAssignedID = aLineProduct.getSellerAssignedID();
            if (aSellerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aSellerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setSellersItemIdentification(aUBLID);
            }
            final IDType aGlobalID = aLineProduct.getGlobalID();
            if (aGlobalID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aGlobalID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setStandardItemIdentification(aUBLID);
            }
            final TradeCountryType aOriginCountry = aLineProduct.getOriginTradeCountry();
            if (aOriginCountry != null) {
                final CountryType aUBLCountry = new CountryType();
                aUBLCountry.setIdentificationCode(aOriginCountry.getIDValue());
                if (aOriginCountry.hasNameEntries())
                    aUBLCountry.setName(_copyName(aOriginCountry.getNameAtIndex(0), new NameType()));
                aUBLItem.setOriginCountry(aUBLCountry);
            }
            // Commodity Classification
            for (final ProductClassificationType aLineProductClassification : aLineProduct.getDesignatedProductClassification()) {
                final CodeType aClassCode = aLineProductClassification.getClassCode();
                if (aClassCode != null) {
                    final CommodityClassificationType aUBLCommodityClassification = new CommodityClassificationType();
                    aUBLCommodityClassification.setItemClassificationCode(_copyCode(aClassCode, new ItemClassificationCodeType()));
                    if (aUBLCommodityClassification.getItemClassificationCode() != null)
                        aUBLItem.addCommodityClassification(aUBLCommodityClassification);
                }
            }
        }
        for (final TradeTaxType aTradeTax : aLineSettlement.getApplicableTradeTax()) {
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLItem.addClassifiedTaxCategory(aUBLTaxCategory);
        }
        if (aLineProduct != null) {
            for (final ProductCharacteristicType aAPC : aLineProduct.getApplicableProductCharacteristic()) if (aAPC.hasDescriptionEntries()) {
                final ItemPropertyType aUBLAdditionalItem = new ItemPropertyType();
                aUBLAdditionalItem.setName(_copyName(aAPC.getDescriptionAtIndex(0), new NameType()));
                if (aAPC.hasValueEntries())
                    aUBLAdditionalItem.setValue(aAPC.getValueAtIndex(0).getValue());
                if (aUBLAdditionalItem.getName() != null)
                    aUBLItem.addAdditionalItemProperty(aUBLAdditionalItem);
            }
        }
        final PriceType aUBLPrice = new PriceType();
        boolean bUsePrice = false;
        if (aLineAgreement != null) {
            final TradePriceType aNPPTP = aLineAgreement.getNetPriceProductTradePrice();
            if (aNPPTP != null) {
                if (aNPPTP.hasChargeAmountEntries()) {
                    aUBLPrice.setPriceAmount(_copyAmount(aNPPTP.getChargeAmountAtIndex(0), new PriceAmountType(), sDefaultCurrencyCode));
                    bUsePrice = true;
                }
                if (aNPPTP.getBasisQuantity() != null) {
                    aUBLPrice.setBaseQuantity(_copyQuantity(aNPPTP.getBasisQuantity(), new BaseQuantityType()));
                    bUsePrice = true;
                }
            }
        }
        swapQuantityAndPriceIfNeeded(bLineExtensionAmountIsNegative, aUBLCreditNoteLine.getCreditedQuantityValue(), aUBLCreditNoteLine::setCreditedQuantity, bUsePrice ? aUBLPrice.getPriceAmountValue() : null, bUsePrice ? aUBLPrice::setPriceAmount : null);
        // Allowance charge
        final TradePriceType aTradePrice = aLineAgreement.getNetPriceProductTradePrice();
        if (aTradePrice != null)
            for (final TradeAllowanceChargeType aPriceAllowanceCharge : aTradePrice.getAppliedTradeAllowanceCharge()) {
                ETriState eIsCharge = ETriState.UNDEFINED;
                if (aPriceAllowanceCharge.getChargeIndicator() != null)
                    eIsCharge = _parseIndicator(aPriceAllowanceCharge.getChargeIndicator(), aErrorList);
                else
                    aErrorList.add(_buildError(new String[] { "CrossIndustryCreditNote", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeAgreement", "NetPriceProductTradePrice", "AppliedTradeAllowanceCharge" }, "Failed to determine if AppliedTradeAllowanceCharge is an Allowance or a Charge"));
                if (eIsCharge.isDefined()) {
                    final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                    aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                    _copyAllowanceCharge(aPriceAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                    aUBLPrice.addAllowanceCharge(aUBLLineAllowanceCharge);
                }
            }
        if (bUsePrice)
            aUBLCreditNoteLine.setPrice(aUBLPrice);
        aUBLCreditNoteLine.setItem(aUBLItem);
        aUBLCreditNote.addCreditNoteLine(aUBLCreditNoteLine);
    }
    return aUBLCreditNote;
}
Also used : DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) CollectionHelper(com.helger.commons.collection.CollectionHelper) BigDecimal(java.math.BigDecimal) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BinaryObjectType(un.unece.uncefact.data.standard.unqualifieddatatype._100.BinaryObjectType) MathHelper(com.helger.commons.math.MathHelper) oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_22(oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_22) CGlobal(com.helger.commons.CGlobal) StringHelper(com.helger.commons.string.StringHelper) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22) EqualsHelper(com.helger.commons.equals.EqualsHelper) Serializable(java.io.Serializable) ValueEnforcer(com.helger.commons.ValueEnforcer) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) Consumer(java.util.function.Consumer) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_22.InvoiceType) LocalDate(java.time.LocalDate) IErrorList(com.helger.commons.error.list.IErrorList) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) LocalDate(java.time.LocalDate) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_22) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_22.CreditNoteType) DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) ETriState(com.helger.commons.state.ETriState) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) Nullable(javax.annotation.Nullable)

Example 4 with CreditNoteType

use of oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType in project en16931-cii2ubl by phax.

the class CIIToUBL21Converter method convertToCreditNote.

@Nullable
public CreditNoteType convertToCreditNote(@Nonnull final CrossIndustryInvoiceType aCIICreditNote, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.notNull(aCIICreditNote, "CIICreditNote");
    ValueEnforcer.notNull(aErrorList, "ErrorList");
    final ExchangedDocumentType aED = aCIICreditNote.getExchangedDocument();
    final SupplyChainTradeTransactionType aSCTT = aCIICreditNote.getSupplyChainTradeTransaction();
    if (aSCTT == null) {
        // Mandatory element
        return null;
    }
    final HeaderTradeAgreementType aHeaderAgreement = aSCTT.getApplicableHeaderTradeAgreement();
    final HeaderTradeDeliveryType aHeaderDelivery = aSCTT.getApplicableHeaderTradeDelivery();
    final HeaderTradeSettlementType aHeaderSettlement = aSCTT.getApplicableHeaderTradeSettlement();
    if (aHeaderAgreement == null || aHeaderDelivery == null || aHeaderSettlement == null) {
        // All mandatory elements
        return null;
    }
    final CreditNoteType aUBLCreditNote = new CreditNoteType();
    if (false)
        aUBLCreditNote.setUBLVersionID(UBL_VERSION);
    if (StringHelper.hasText(getCustomizationID()))
        aUBLCreditNote.setCustomizationID(getCustomizationID());
    if (StringHelper.hasText(getProfileID()))
        aUBLCreditNote.setProfileID(getProfileID());
    if (aED != null)
        aUBLCreditNote.setID(aED.getIDValue());
    // Mandatory supplier
    final SupplierPartyType aUBLSupplier = new SupplierPartyType();
    aUBLCreditNote.setAccountingSupplierParty(aUBLSupplier);
    // Mandatory customer
    final CustomerPartyType aUBLCustomer = new CustomerPartyType();
    aUBLCreditNote.setAccountingCustomerParty(aUBLCustomer);
    // IssueDate
    {
        LocalDate aIssueDate = null;
        if (aED != null && aED.getIssueDateTime() != null)
            aIssueDate = _parseDate(aED.getIssueDateTime().getDateTimeString(), aErrorList);
        if (aIssueDate != null)
            aUBLCreditNote.setIssueDate(aIssueDate);
    }
    // CreditNoteTypeCode
    if (aED != null)
        aUBLCreditNote.setCreditNoteTypeCode(aED.getTypeCodeValue());
    // Note
    if (aED != null)
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aEDNote : aED.getIncludedNote()) ifNotNull(aUBLCreditNote::addNote, _copyNote(aEDNote));
    // TaxPointDate
    for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
        if (aTradeTax.getTaxPointDate() != null) {
            final LocalDate aTaxPointDate = _parseDate(aTradeTax.getTaxPointDate().getDateString(), aErrorList);
            if (aTaxPointDate != null) {
                // Use the first tax point date only
                aUBLCreditNote.setTaxPointDate(aTaxPointDate);
                break;
            }
        }
    }
    // DocumentCurrencyCode
    final String sDefaultCurrencyCode = aHeaderSettlement.getInvoiceCurrencyCodeValue();
    aUBLCreditNote.setDocumentCurrencyCode(sDefaultCurrencyCode);
    // TaxCurrencyCode
    if (aHeaderSettlement.getTaxCurrencyCodeValue() != null) {
        aUBLCreditNote.setTaxCurrencyCode(aHeaderSettlement.getTaxCurrencyCodeValue());
    }
    // AccountingCost
    for (final TradeAccountingAccountType aAccount : aHeaderSettlement.getReceivableSpecifiedTradeAccountingAccount()) {
        final String sID = aAccount.getIDValue();
        if (StringHelper.hasText(sID)) {
            // Use the first ID
            aUBLCreditNote.setAccountingCost(sID);
            break;
        }
    }
    // BuyerReferences
    if (aHeaderAgreement.getBuyerReferenceValue() != null) {
        aUBLCreditNote.setBuyerReference(aHeaderAgreement.getBuyerReferenceValue());
    }
    // CreditNotePeriod
    {
        final SpecifiedPeriodType aSPT = aHeaderSettlement.getBillingSpecifiedPeriod();
        if (aSPT != null) {
            final DateTimeType aStartDT = aSPT.getStartDateTime();
            final DateTimeType aEndDT = aSPT.getEndDateTime();
            if (aStartDT != null && aEndDT != null) {
                final PeriodType aUBLPeriod = new PeriodType();
                aUBLPeriod.setStartDate(_parseDate(aStartDT.getDateTimeString(), aErrorList));
                aUBLPeriod.setEndDate(_parseDate(aEndDT.getDateTimeString(), aErrorList));
                aUBLCreditNote.addInvoicePeriod(aUBLPeriod);
            }
        }
    }
    // OrderReference
    {
        final OrderReferenceType aUBLOrderRef = _createUBLOrderRef(aHeaderAgreement.getBuyerOrderReferencedDocument(), aHeaderAgreement.getSellerOrderReferencedDocument());
        aUBLCreditNote.setOrderReference(aUBLOrderRef);
    }
    // BillingReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderSettlement.getInvoiceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null) {
            final BillingReferenceType aUBLBillingRef = new BillingReferenceType();
            aUBLBillingRef.setCreditNoteDocumentReference(aUBLDocRef);
            aUBLCreditNote.addBillingReference(aUBLBillingRef);
        }
    }
    // DespatchDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getDespatchAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLCreditNote.addDespatchDocumentReference(aUBLDocRef);
    }
    // ReceiptDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getReceivingAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLCreditNote.addReceiptDocumentReference(aUBLDocRef);
    }
    // OriginatorDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Use for "Tender or lot reference" with TypeCode "50"
            if (isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLCreditNote.addOriginatorDocumentReference(aUBLDocRef);
            }
        }
    }
    // ContractDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderAgreement.getContractReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLCreditNote.addContractDocumentReference(aUBLDocRef);
    }
    // AdditionalDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Except OriginatorDocumentReference
            if (!isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLCreditNote.addAdditionalDocumentReference(aUBLDocRef);
            }
        }
    }
    // ProjectReference (UBL 2.2 only)
    // {
    // final ProcuringProjectType aSpecifiedProcuring =
    // aHeaderAgreement.getSpecifiedProcuringProject ();
    // if (aSpecifiedProcuring != null)
    // {
    // final String sID = aSpecifiedProcuring.getIDValue ();
    // if (StringHelper.hasText (sID))
    // {
    // final ProjectReferenceType aUBLProjectRef = new ProjectReferenceType ();
    // aUBLProjectRef.setID (sID);
    // aUBLCreditNote.addProjectReference (aUBLProjectRef);
    // }
    // }
    // }
    // Supplier Party
    {
        final TradePartyType aSellerParty = aHeaderAgreement.getSellerTradeParty();
        if (aSellerParty != null) {
            final PartyType aUBLParty = _convertParty(aSellerParty, true);
            for (final TaxRegistrationType aTaxRegistration : aSellerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aSellerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aSellerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLSupplier.setParty(aUBLParty);
        }
    }
    // Customer Party
    {
        final TradePartyType aBuyerParty = aHeaderAgreement.getBuyerTradeParty();
        if (aBuyerParty != null) {
            final PartyType aUBLParty = _convertParty(aBuyerParty, false);
            for (final TaxRegistrationType aTaxRegistration : aBuyerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aBuyerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aBuyerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCustomer.setParty(aUBLParty);
        }
    }
    // Payee Party
    {
        final TradePartyType aPayeeParty = aHeaderSettlement.getPayeeTradeParty();
        if (aPayeeParty != null) {
            final PartyType aUBLParty = _convertParty(aPayeeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aPayeeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aPayeeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aPayeeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCreditNote.setPayeeParty(aUBLParty);
        }
    }
    // Tax Representative Party
    {
        final TradePartyType aTaxRepresentativeParty = aHeaderAgreement.getSellerTaxRepresentativeTradeParty();
        if (aTaxRepresentativeParty != null) {
            final PartyType aUBLParty = _convertParty(aTaxRepresentativeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aTaxRepresentativeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aTaxRepresentativeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aTaxRepresentativeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCreditNote.setTaxRepresentativeParty(aUBLParty);
        }
    }
    // Delivery
    {
        final TradePartyType aShipToParty = aHeaderDelivery.getShipToTradeParty();
        if (aShipToParty != null) {
            final DeliveryType aUBLDelivery = new DeliveryType();
            final SupplyChainEventType aSCE = aHeaderDelivery.getActualDeliverySupplyChainEvent();
            if (aSCE != null) {
                final DateTimeType aODT = aSCE.getOccurrenceDateTime();
                if (aODT != null)
                    aUBLDelivery.setActualDeliveryDate(_parseDate(aODT.getDateTimeString(), aErrorList));
            }
            final oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21.LocationType aUBLDeliveryLocation = new oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21.LocationType();
            boolean bUseLocation = false;
            final oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_21.IDType aUBLID = _extractFirstPartyID(aShipToParty);
            if (aUBLID != null) {
                aUBLDeliveryLocation.setID(aUBLID);
                bUseLocation = true;
            }
            final TradeAddressType aPostalAddress = aShipToParty.getPostalTradeAddress();
            if (aPostalAddress != null) {
                aUBLDeliveryLocation.setAddress(_convertPostalAddress(aPostalAddress));
                bUseLocation = true;
            }
            if (bUseLocation)
                aUBLDelivery.setDeliveryLocation(aUBLDeliveryLocation);
            final TextType aName = aShipToParty.getName();
            if (aName != null) {
                final PartyType aUBLDeliveryParty = new PartyType();
                final PartyNameType aUBLPartyName = new PartyNameType();
                aUBLPartyName.setName(_copyName(aName, new NameType()));
                aUBLDeliveryParty.addPartyName(aUBLPartyName);
                aUBLDelivery.setDeliveryParty(aUBLDeliveryParty);
            }
            aUBLCreditNote.addDelivery(aUBLDelivery);
        }
    }
    // Payment means
    {
        for (final TradeSettlementPaymentMeansType aPaymentMeans : aHeaderSettlement.getSpecifiedTradeSettlementPaymentMeans()) {
            _convertPaymentMeans(aHeaderSettlement, aPaymentMeans, x -> _addPartyID(x, aUBLCreditNote.getAccountingSupplierParty().getParty()), aUBLCreditNote::addPaymentMeans, aErrorList);
            // Allowed again in 1.2.1: exactly 2
            if (false)
                // Since v1.2.0 only one is allowed
                if (true)
                    break;
        }
    }
    // Payment Terms
    {
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) {
            final PaymentTermsType aUBLPaymenTerms = new PaymentTermsType();
            for (final TextType aDesc : aPaymentTerms.getDescription()) ifNotNull(aUBLPaymenTerms::addNote, _copyNote(aDesc));
            if (aUBLPaymenTerms.hasNoteEntries())
                aUBLCreditNote.addPaymentTerms(aUBLPaymenTerms);
        }
    }
    // Allowance Charge
    {
        for (final TradeAllowanceChargeType aAllowanceCharge : aHeaderSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryCreditNote", "SupplyChainTradeTransaction", "ApplicableHeaderTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLAllowanceCharge = new AllowanceChargeType();
                aUBLAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aAllowanceCharge, aUBLAllowanceCharge, sDefaultCurrencyCode);
                aUBLCreditNote.addAllowanceCharge(aUBLAllowanceCharge);
            }
        }
    }
    final TradeSettlementHeaderMonetarySummationType aSTSHMS = aHeaderSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation();
    // TaxTotal
    {
        TaxTotalType aUBLTaxTotal = null;
        if (aSTSHMS != null && aSTSHMS.hasTaxTotalAmountEntries()) {
            // For all currencies
            for (final AmountType aTaxTotalAmount : aSTSHMS.getTaxTotalAmount()) {
                final TaxTotalType aUBLCurTaxTotal = new TaxTotalType();
                aUBLCurTaxTotal.setTaxAmount(_copyAmount(aTaxTotalAmount, new TaxAmountType(), sDefaultCurrencyCode));
                aUBLCreditNote.addTaxTotal(aUBLCurTaxTotal);
                if (aUBLTaxTotal == null) {
                    // Use the first one
                    aUBLTaxTotal = aUBLCurTaxTotal;
                }
            }
        } else {
            // Mandatory in UBL
            final TaxAmountType aUBLTaxAmount = new TaxAmountType();
            aUBLTaxAmount.setValue(BigDecimal.ZERO);
            aUBLTaxAmount.setCurrencyID(sDefaultCurrencyCode);
            aUBLTaxTotal = new TaxTotalType();
            aUBLTaxTotal.setTaxAmount(aUBLTaxAmount);
            aUBLCreditNote.addTaxTotal(aUBLTaxTotal);
        }
        for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
            final TaxSubtotalType aUBLTaxSubtotal = new TaxSubtotalType();
            if (aTradeTax.hasBasisAmountEntries()) {
                aUBLTaxSubtotal.setTaxableAmount(_copyAmount(aTradeTax.getBasisAmountAtIndex(0), new TaxableAmountType(), sDefaultCurrencyCode));
            }
            if (aTradeTax.hasCalculatedAmountEntries()) {
                aUBLTaxSubtotal.setTaxAmount(_copyAmount(aTradeTax.getCalculatedAmountAtIndex(0), new TaxAmountType(), sDefaultCurrencyCode));
            }
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            if (StringHelper.hasText(aTradeTax.getExemptionReasonCodeValue()))
                aUBLTaxCategory.setTaxExemptionReasonCode(aTradeTax.getExemptionReasonCodeValue());
            if (aTradeTax.getExemptionReason() != null) {
                final TaxExemptionReasonType aUBLTaxExemptionReason = new TaxExemptionReasonType();
                aUBLTaxExemptionReason.setValue(aTradeTax.getExemptionReason().getValue());
                aUBLTaxExemptionReason.setLanguageID(aTradeTax.getExemptionReason().getLanguageID());
                aUBLTaxExemptionReason.setLanguageLocaleID(aTradeTax.getExemptionReason().getLanguageLocaleID());
                aUBLTaxCategory.addTaxExemptionReason(aUBLTaxExemptionReason);
            }
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLTaxSubtotal.setTaxCategory(aUBLTaxCategory);
            aUBLTaxTotal.addTaxSubtotal(aUBLTaxSubtotal);
        }
    }
    // LegalMonetaryTotal
    {
        final MonetaryTotalType aUBLMonetaryTotal = new MonetaryTotalType();
        if (aSTSHMS != null) {
            if (aSTSHMS.hasLineTotalAmountEntries())
                aUBLMonetaryTotal.setLineExtensionAmount(_copyAmount(aSTSHMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTaxBasisTotalAmountEntries())
                aUBLMonetaryTotal.setTaxExclusiveAmount(_copyAmount(aSTSHMS.getTaxBasisTotalAmountAtIndex(0), new TaxExclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasGrandTotalAmountEntries())
                aUBLMonetaryTotal.setTaxInclusiveAmount(_copyAmount(aSTSHMS.getGrandTotalAmountAtIndex(0), new TaxInclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasAllowanceTotalAmountEntries())
                aUBLMonetaryTotal.setAllowanceTotalAmount(_copyAmount(aSTSHMS.getAllowanceTotalAmountAtIndex(0), new AllowanceTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasChargeTotalAmountEntries())
                aUBLMonetaryTotal.setChargeTotalAmount(_copyAmount(aSTSHMS.getChargeTotalAmountAtIndex(0), new ChargeTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTotalPrepaidAmountEntries())
                aUBLMonetaryTotal.setPrepaidAmount(_copyAmount(aSTSHMS.getTotalPrepaidAmountAtIndex(0), new PrepaidAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasRoundingAmountEntries()) {
                // compatibility
                if (MathHelper.isNE0(aSTSHMS.getRoundingAmountAtIndex(0).getValue()))
                    aUBLMonetaryTotal.setPayableRoundingAmount(_copyAmount(aSTSHMS.getRoundingAmountAtIndex(0), new PayableRoundingAmountType(), sDefaultCurrencyCode));
            }
            if (aSTSHMS.hasDuePayableAmountEntries())
                aUBLMonetaryTotal.setPayableAmount(_copyAmount(aSTSHMS.getDuePayableAmountAtIndex(0), new PayableAmountType(), sDefaultCurrencyCode));
        }
        aUBLCreditNote.setLegalMonetaryTotal(aUBLMonetaryTotal);
    }
    // All invoice lines
    for (final SupplyChainTradeLineItemType aLineItem : aSCTT.getIncludedSupplyChainTradeLineItem()) {
        final CreditNoteLineType aUBLCreditNoteLine = new CreditNoteLineType();
        final DocumentLineDocumentType aDLD = aLineItem.getAssociatedDocumentLineDocument();
        aUBLCreditNoteLine.setID(_copyID(aDLD.getLineID()));
        // Note
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aLineNote : aDLD.getIncludedNote()) ifNotNull(aUBLCreditNoteLine::addNote, _copyNote(aLineNote));
        // Line extension amount
        boolean bLineExtensionAmountIsNegative = false;
        final LineTradeSettlementType aLineSettlement = aLineItem.getSpecifiedLineTradeSettlement();
        final TradeSettlementLineMonetarySummationType aSTSLMS = aLineSettlement.getSpecifiedTradeSettlementLineMonetarySummation();
        if (aSTSLMS != null) {
            if (aSTSLMS.hasLineTotalAmountEntries()) {
                aUBLCreditNoteLine.setLineExtensionAmount(_copyAmount(aSTSLMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
                if (isLT0Strict(aUBLCreditNoteLine.getLineExtensionAmountValue()))
                    bLineExtensionAmountIsNegative = true;
            }
        }
        // CreditNoted quantity
        final LineTradeDeliveryType aLineDelivery = aLineItem.getSpecifiedLineTradeDelivery();
        if (aLineDelivery != null) {
            final QuantityType aBilledQuantity = aLineDelivery.getBilledQuantity();
            if (aBilledQuantity != null) {
                aUBLCreditNoteLine.setCreditedQuantity(_copyQuantity(aBilledQuantity, new CreditedQuantityType()));
            }
        }
        // Accounting cost
        if (aLineSettlement.hasReceivableSpecifiedTradeAccountingAccountEntries()) {
            final TradeAccountingAccountType aLineAA = aLineSettlement.getReceivableSpecifiedTradeAccountingAccountAtIndex(0);
            aUBLCreditNoteLine.setAccountingCost(aLineAA.getIDValue());
        }
        // CreditNote period
        final SpecifiedPeriodType aLineBillingPeriod = aLineSettlement.getBillingSpecifiedPeriod();
        if (aLineBillingPeriod != null) {
            final PeriodType aUBLLinePeriod = new PeriodType();
            if (aLineBillingPeriod.getStartDateTime() != null)
                aUBLLinePeriod.setStartDate(_parseDate(aLineBillingPeriod.getStartDateTime().getDateTimeString(), aErrorList));
            if (aLineBillingPeriod.getEndDateTime() != null)
                aUBLLinePeriod.setEndDate(_parseDate(aLineBillingPeriod.getEndDateTime().getDateTimeString(), aErrorList));
            aUBLCreditNoteLine.addInvoicePeriod(aUBLLinePeriod);
        }
        // Order line reference
        final LineTradeAgreementType aLineAgreement = aLineItem.getSpecifiedLineTradeAgreement();
        if (aLineAgreement != null) {
            final ReferencedDocumentType aBuyerOrderReference = aLineAgreement.getBuyerOrderReferencedDocument();
            if (aBuyerOrderReference != null && StringHelper.hasText(aBuyerOrderReference.getLineIDValue())) {
                final OrderLineReferenceType aUBLOrderLineReference = new OrderLineReferenceType();
                aUBLOrderLineReference.setLineID(_copyID(aBuyerOrderReference.getLineID(), new LineIDType()));
                aUBLCreditNoteLine.addOrderLineReference(aUBLOrderLineReference);
            }
        }
        // Document reference
        for (final ReferencedDocumentType aLineReferencedDocument : aLineSettlement.getAdditionalReferencedDocument()) {
            final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aLineReferencedDocument, aErrorList);
            if (aUBLDocRef != null)
                aUBLCreditNoteLine.addDocumentReference(aUBLDocRef);
        }
        // Allowance charge
        for (final TradeAllowanceChargeType aLineAllowanceCharge : aLineSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aLineAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aLineAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryCreditNote", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aLineAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                aUBLCreditNoteLine.addAllowanceCharge(aUBLLineAllowanceCharge);
            }
        }
        // Item
        final ItemType aUBLItem = new ItemType();
        final TradeProductType aLineProduct = aLineItem.getSpecifiedTradeProduct();
        if (aLineProduct != null) {
            final TextType aDescription = aLineProduct.getDescription();
            if (aDescription != null)
                ifNotNull(aUBLItem::addDescription, _copyName(aDescription, new DescriptionType()));
            if (aLineProduct.hasNameEntries())
                aUBLItem.setName(_copyName(aLineProduct.getNameAtIndex(0), new NameType()));
            final IDType aBuyerAssignedID = aLineProduct.getBuyerAssignedID();
            if (aBuyerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aBuyerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setBuyersItemIdentification(aUBLID);
            }
            final IDType aSellerAssignedID = aLineProduct.getSellerAssignedID();
            if (aSellerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aSellerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setSellersItemIdentification(aUBLID);
            }
            final IDType aGlobalID = aLineProduct.getGlobalID();
            if (aGlobalID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aGlobalID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setStandardItemIdentification(aUBLID);
            }
            final TradeCountryType aOriginCountry = aLineProduct.getOriginTradeCountry();
            if (aOriginCountry != null) {
                final CountryType aUBLCountry = new CountryType();
                aUBLCountry.setIdentificationCode(aOriginCountry.getIDValue());
                if (aOriginCountry.hasNameEntries())
                    aUBLCountry.setName(_copyName(aOriginCountry.getNameAtIndex(0), new NameType()));
                aUBLItem.setOriginCountry(aUBLCountry);
            }
            // Commodity Classification
            for (final ProductClassificationType aLineProductClassification : aLineProduct.getDesignatedProductClassification()) {
                final CodeType aClassCode = aLineProductClassification.getClassCode();
                if (aClassCode != null) {
                    final CommodityClassificationType aUBLCommodityClassification = new CommodityClassificationType();
                    aUBLCommodityClassification.setItemClassificationCode(_copyCode(aClassCode, new ItemClassificationCodeType()));
                    if (aUBLCommodityClassification.getItemClassificationCode() != null)
                        aUBLItem.addCommodityClassification(aUBLCommodityClassification);
                }
            }
        }
        for (final TradeTaxType aTradeTax : aLineSettlement.getApplicableTradeTax()) {
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLItem.addClassifiedTaxCategory(aUBLTaxCategory);
        }
        if (aLineProduct != null) {
            for (final ProductCharacteristicType aAPC : aLineProduct.getApplicableProductCharacteristic()) if (aAPC.hasDescriptionEntries()) {
                final ItemPropertyType aUBLAdditionalItem = new ItemPropertyType();
                aUBLAdditionalItem.setName(_copyName(aAPC.getDescriptionAtIndex(0), new NameType()));
                if (aAPC.hasValueEntries())
                    aUBLAdditionalItem.setValue(aAPC.getValueAtIndex(0).getValue());
                if (aUBLAdditionalItem.getName() != null)
                    aUBLItem.addAdditionalItemProperty(aUBLAdditionalItem);
            }
        }
        final PriceType aUBLPrice = new PriceType();
        boolean bUsePrice = false;
        if (aLineAgreement != null) {
            final TradePriceType aNPPTP = aLineAgreement.getNetPriceProductTradePrice();
            if (aNPPTP != null) {
                if (aNPPTP.hasChargeAmountEntries()) {
                    aUBLPrice.setPriceAmount(_copyAmount(aNPPTP.getChargeAmountAtIndex(0), new PriceAmountType(), sDefaultCurrencyCode));
                    bUsePrice = true;
                }
                if (aNPPTP.getBasisQuantity() != null) {
                    aUBLPrice.setBaseQuantity(_copyQuantity(aNPPTP.getBasisQuantity(), new BaseQuantityType()));
                    bUsePrice = true;
                }
            }
        }
        swapQuantityAndPriceIfNeeded(bLineExtensionAmountIsNegative, aUBLCreditNoteLine.getCreditedQuantityValue(), aUBLCreditNoteLine::setCreditedQuantity, bUsePrice ? aUBLPrice.getPriceAmountValue() : null, bUsePrice ? aUBLPrice::setPriceAmount : null);
        // Allowance charge
        final TradePriceType aTradePrice = aLineAgreement.getNetPriceProductTradePrice();
        if (aTradePrice != null)
            for (final TradeAllowanceChargeType aPriceAllowanceCharge : aTradePrice.getAppliedTradeAllowanceCharge()) {
                ETriState eIsCharge = ETriState.UNDEFINED;
                if (aPriceAllowanceCharge.getChargeIndicator() != null)
                    eIsCharge = _parseIndicator(aPriceAllowanceCharge.getChargeIndicator(), aErrorList);
                else
                    aErrorList.add(_buildError(new String[] { "CrossIndustryCreditNote", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeAgreement", "NetPriceProductTradePrice", "AppliedTradeAllowanceCharge" }, "Failed to determine if AppliedTradeAllowanceCharge is an Allowance or a Charge"));
                if (eIsCharge.isDefined()) {
                    final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                    aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                    _copyAllowanceCharge(aPriceAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                    aUBLPrice.addAllowanceCharge(aUBLLineAllowanceCharge);
                }
            }
        if (bUsePrice)
            aUBLCreditNoteLine.setPrice(aUBLPrice);
        aUBLCreditNoteLine.setItem(aUBLItem);
        aUBLCreditNote.addCreditNoteLine(aUBLCreditNoteLine);
    }
    return aUBLCreditNote;
}
Also used : DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) CollectionHelper(com.helger.commons.collection.CollectionHelper) BigDecimal(java.math.BigDecimal) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BinaryObjectType(un.unece.uncefact.data.standard.unqualifieddatatype._100.BinaryObjectType) MathHelper(com.helger.commons.math.MathHelper) oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_21(oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_21) CGlobal(com.helger.commons.CGlobal) StringHelper(com.helger.commons.string.StringHelper) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) EqualsHelper(com.helger.commons.equals.EqualsHelper) Serializable(java.io.Serializable) ValueEnforcer(com.helger.commons.ValueEnforcer) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) Consumer(java.util.function.Consumer) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_21.InvoiceType) LocalDate(java.time.LocalDate) IErrorList(com.helger.commons.error.list.IErrorList) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) LocalDate(java.time.LocalDate) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_21) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType) DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) ETriState(com.helger.commons.state.ETriState) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) Nullable(javax.annotation.Nullable)

Example 5 with CreditNoteType

use of oasis.names.specification.ubl.schema.xsd.creditnote_21.CreditNoteType in project en16931-cii2ubl by phax.

the class CIIToUBL23Converter method convertToCreditNote.

@Nullable
public CreditNoteType convertToCreditNote(@Nonnull final CrossIndustryInvoiceType aCIICreditNote, @Nonnull final ErrorList aErrorList) {
    ValueEnforcer.notNull(aCIICreditNote, "CIICreditNote");
    ValueEnforcer.notNull(aErrorList, "ErrorList");
    final ExchangedDocumentType aED = aCIICreditNote.getExchangedDocument();
    final SupplyChainTradeTransactionType aSCTT = aCIICreditNote.getSupplyChainTradeTransaction();
    if (aSCTT == null) {
        // Mandatory element
        return null;
    }
    final HeaderTradeAgreementType aHeaderAgreement = aSCTT.getApplicableHeaderTradeAgreement();
    final HeaderTradeDeliveryType aHeaderDelivery = aSCTT.getApplicableHeaderTradeDelivery();
    final HeaderTradeSettlementType aHeaderSettlement = aSCTT.getApplicableHeaderTradeSettlement();
    if (aHeaderAgreement == null || aHeaderDelivery == null || aHeaderSettlement == null) {
        // All mandatory elements
        return null;
    }
    final CreditNoteType aUBLCreditNote = new CreditNoteType();
    if (false)
        aUBLCreditNote.setUBLVersionID(UBL_VERSION);
    if (StringHelper.hasText(getCustomizationID()))
        aUBLCreditNote.setCustomizationID(getCustomizationID());
    if (StringHelper.hasText(getProfileID()))
        aUBLCreditNote.setProfileID(getProfileID());
    if (aED != null)
        aUBLCreditNote.setID(aED.getIDValue());
    // Mandatory supplier
    final SupplierPartyType aUBLSupplier = new SupplierPartyType();
    aUBLCreditNote.setAccountingSupplierParty(aUBLSupplier);
    // Mandatory customer
    final CustomerPartyType aUBLCustomer = new CustomerPartyType();
    aUBLCreditNote.setAccountingCustomerParty(aUBLCustomer);
    // IssueDate
    {
        LocalDate aIssueDate = null;
        if (aED != null && aED.getIssueDateTime() != null)
            aIssueDate = _parseDate(aED.getIssueDateTime().getDateTimeString(), aErrorList);
        if (aIssueDate != null)
            aUBLCreditNote.setIssueDate(aIssueDate);
    }
    // DueDate
    {
        LocalDate aDueDate = null;
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) if (aPaymentTerms.getDueDateDateTime() != null) {
            aDueDate = _parseDate(aPaymentTerms.getDueDateDateTime().getDateTimeString(), aErrorList);
            if (aDueDate != null)
                break;
        }
        if (aDueDate != null)
            aUBLCreditNote.setDueDate(aDueDate);
    }
    // CreditNoteTypeCode
    if (aED != null)
        aUBLCreditNote.setCreditNoteTypeCode(aED.getTypeCodeValue());
    // Note
    if (aED != null)
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aEDNote : aED.getIncludedNote()) ifNotNull(aUBLCreditNote::addNote, _copyNote(aEDNote));
    // TaxPointDate
    for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
        if (aTradeTax.getTaxPointDate() != null) {
            final LocalDate aTaxPointDate = _parseDate(aTradeTax.getTaxPointDate().getDateString(), aErrorList);
            if (aTaxPointDate != null) {
                // Use the first tax point date only
                aUBLCreditNote.setTaxPointDate(aTaxPointDate);
                break;
            }
        }
    }
    // DocumentCurrencyCode
    final String sDefaultCurrencyCode = aHeaderSettlement.getInvoiceCurrencyCodeValue();
    aUBLCreditNote.setDocumentCurrencyCode(sDefaultCurrencyCode);
    // TaxCurrencyCode
    if (aHeaderSettlement.getTaxCurrencyCodeValue() != null) {
        aUBLCreditNote.setTaxCurrencyCode(aHeaderSettlement.getTaxCurrencyCodeValue());
    }
    // AccountingCost
    for (final TradeAccountingAccountType aAccount : aHeaderSettlement.getReceivableSpecifiedTradeAccountingAccount()) {
        final String sID = aAccount.getIDValue();
        if (StringHelper.hasText(sID)) {
            // Use the first ID
            aUBLCreditNote.setAccountingCost(sID);
            break;
        }
    }
    // BuyerReferences
    if (aHeaderAgreement.getBuyerReferenceValue() != null) {
        aUBLCreditNote.setBuyerReference(aHeaderAgreement.getBuyerReferenceValue());
    }
    // CreditNotePeriod
    {
        final SpecifiedPeriodType aSPT = aHeaderSettlement.getBillingSpecifiedPeriod();
        if (aSPT != null) {
            final DateTimeType aStartDT = aSPT.getStartDateTime();
            final DateTimeType aEndDT = aSPT.getEndDateTime();
            if (aStartDT != null && aEndDT != null) {
                final PeriodType aUBLPeriod = new PeriodType();
                aUBLPeriod.setStartDate(_parseDate(aStartDT.getDateTimeString(), aErrorList));
                aUBLPeriod.setEndDate(_parseDate(aEndDT.getDateTimeString(), aErrorList));
                aUBLCreditNote.addInvoicePeriod(aUBLPeriod);
            }
        }
    }
    // OrderReference
    {
        final OrderReferenceType aUBLOrderRef = _createUBLOrderRef(aHeaderAgreement.getBuyerOrderReferencedDocument(), aHeaderAgreement.getSellerOrderReferencedDocument());
        aUBLCreditNote.setOrderReference(aUBLOrderRef);
    }
    // BillingReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderSettlement.getInvoiceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null) {
            final BillingReferenceType aUBLBillingRef = new BillingReferenceType();
            aUBLBillingRef.setCreditNoteDocumentReference(aUBLDocRef);
            aUBLCreditNote.addBillingReference(aUBLBillingRef);
        }
    }
    // DespatchDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getDespatchAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLCreditNote.addDespatchDocumentReference(aUBLDocRef);
    }
    // ReceiptDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderDelivery.getReceivingAdviceReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLCreditNote.addReceiptDocumentReference(aUBLDocRef);
    }
    // OriginatorDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Use for "Tender or lot reference" with TypeCode "50"
            if (isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLCreditNote.addOriginatorDocumentReference(aUBLDocRef);
            }
        }
    }
    // ContractDocumentReference
    {
        final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aHeaderAgreement.getContractReferencedDocument(), aErrorList);
        if (aUBLDocRef != null)
            aUBLCreditNote.addContractDocumentReference(aUBLDocRef);
    }
    // AdditionalDocumentReference
    {
        for (final ReferencedDocumentType aRD : aHeaderAgreement.getAdditionalReferencedDocument()) {
            // Except OriginatorDocumentReference
            if (!isOriginatorDocumentReferenceTypeCode(aRD.getTypeCodeValue())) {
                final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aRD, aErrorList);
                if (aUBLDocRef != null)
                    aUBLCreditNote.addAdditionalDocumentReference(aUBLDocRef);
            }
        }
    }
    // ProjectReference
    {
        final ProcuringProjectType aSpecifiedProcuring = aHeaderAgreement.getSpecifiedProcuringProject();
        if (aSpecifiedProcuring != null) {
            final String sID = aSpecifiedProcuring.getIDValue();
            if (StringHelper.hasText(sID)) {
                final ProjectReferenceType aUBLProjectRef = new ProjectReferenceType();
                aUBLProjectRef.setID(sID);
                aUBLCreditNote.addProjectReference(aUBLProjectRef);
            }
        }
    }
    // Supplier Party
    {
        final TradePartyType aSellerParty = aHeaderAgreement.getSellerTradeParty();
        if (aSellerParty != null) {
            final PartyType aUBLParty = _convertParty(aSellerParty, true);
            for (final TaxRegistrationType aTaxRegistration : aSellerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aSellerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aSellerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLSupplier.setParty(aUBLParty);
        }
    }
    // Customer Party
    {
        final TradePartyType aBuyerParty = aHeaderAgreement.getBuyerTradeParty();
        if (aBuyerParty != null) {
            final PartyType aUBLParty = _convertParty(aBuyerParty, false);
            for (final TaxRegistrationType aTaxRegistration : aBuyerParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aBuyerParty);
            if (aUBLPartyLegalEntity != null)
                aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            final ContactType aUBLContact = _convertContact(aBuyerParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCustomer.setParty(aUBLParty);
        }
    }
    // Payee Party
    {
        final TradePartyType aPayeeParty = aHeaderSettlement.getPayeeTradeParty();
        if (aPayeeParty != null) {
            final PartyType aUBLParty = _convertParty(aPayeeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aPayeeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aPayeeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aPayeeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCreditNote.setPayeeParty(aUBLParty);
        }
    }
    // Tax Representative Party
    {
        final TradePartyType aTaxRepresentativeParty = aHeaderAgreement.getSellerTaxRepresentativeTradeParty();
        if (aTaxRepresentativeParty != null) {
            final PartyType aUBLParty = _convertParty(aTaxRepresentativeParty, false);
            for (final TaxRegistrationType aTaxRegistration : aTaxRepresentativeParty.getSpecifiedTaxRegistration()) {
                final PartyTaxSchemeType aUBLPartyTaxScheme = _convertPartyTaxScheme(aTaxRegistration);
                if (aUBLPartyTaxScheme != null)
                    aUBLParty.addPartyTaxScheme(aUBLPartyTaxScheme);
            }
            // validation rules warning
            if (false) {
                final PartyLegalEntityType aUBLPartyLegalEntity = _convertPartyLegalEntity(aTaxRepresentativeParty);
                if (aUBLPartyLegalEntity != null)
                    aUBLParty.addPartyLegalEntity(aUBLPartyLegalEntity);
            }
            final ContactType aUBLContact = _convertContact(aTaxRepresentativeParty);
            if (aUBLContact != null)
                aUBLParty.setContact(aUBLContact);
            aUBLCreditNote.setTaxRepresentativeParty(aUBLParty);
        }
    }
    // Delivery
    {
        final TradePartyType aShipToParty = aHeaderDelivery.getShipToTradeParty();
        if (aShipToParty != null) {
            final DeliveryType aUBLDelivery = new DeliveryType();
            final SupplyChainEventType aSCE = aHeaderDelivery.getActualDeliverySupplyChainEvent();
            if (aSCE != null) {
                final DateTimeType aODT = aSCE.getOccurrenceDateTime();
                if (aODT != null)
                    aUBLDelivery.setActualDeliveryDate(_parseDate(aODT.getDateTimeString(), aErrorList));
            }
            final oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23.LocationType aUBLDeliveryLocation = new oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23.LocationType();
            boolean bUseLocation = false;
            final oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_23.IDType aUBLID = _extractFirstPartyID(aShipToParty);
            if (aUBLID != null) {
                aUBLDeliveryLocation.setID(aUBLID);
                bUseLocation = true;
            }
            final TradeAddressType aPostalAddress = aShipToParty.getPostalTradeAddress();
            if (aPostalAddress != null) {
                aUBLDeliveryLocation.setAddress(_convertPostalAddress(aPostalAddress));
                bUseLocation = true;
            }
            if (bUseLocation)
                aUBLDelivery.setDeliveryLocation(aUBLDeliveryLocation);
            final TextType aName = aShipToParty.getName();
            if (aName != null) {
                final PartyType aUBLDeliveryParty = new PartyType();
                final PartyNameType aUBLPartyName = new PartyNameType();
                aUBLPartyName.setName(_copyName(aName, new NameType()));
                aUBLDeliveryParty.addPartyName(aUBLPartyName);
                aUBLDelivery.setDeliveryParty(aUBLDeliveryParty);
            }
            aUBLCreditNote.addDelivery(aUBLDelivery);
        }
    }
    // Payment means
    {
        for (final TradeSettlementPaymentMeansType aPaymentMeans : aHeaderSettlement.getSpecifiedTradeSettlementPaymentMeans()) {
            _convertPaymentMeans(aHeaderSettlement, aPaymentMeans, x -> _addPartyID(x, aUBLCreditNote.getAccountingSupplierParty().getParty()), aUBLCreditNote::addPaymentMeans, aErrorList);
            // Allowed again in 1.2.1: exactly 2
            if (false)
                // Since v1.2.0 only one is allowed
                if (true)
                    break;
        }
    }
    // Payment Terms
    {
        for (final TradePaymentTermsType aPaymentTerms : aHeaderSettlement.getSpecifiedTradePaymentTerms()) {
            final PaymentTermsType aUBLPaymenTerms = new PaymentTermsType();
            for (final TextType aDesc : aPaymentTerms.getDescription()) ifNotNull(aUBLPaymenTerms::addNote, _copyNote(aDesc));
            if (aUBLPaymenTerms.hasNoteEntries())
                aUBLCreditNote.addPaymentTerms(aUBLPaymenTerms);
        }
    }
    // Allowance Charge
    {
        for (final TradeAllowanceChargeType aAllowanceCharge : aHeaderSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryCreditNote", "SupplyChainTradeTransaction", "ApplicableHeaderTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLAllowanceCharge = new AllowanceChargeType();
                aUBLAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aAllowanceCharge, aUBLAllowanceCharge, sDefaultCurrencyCode);
                aUBLCreditNote.addAllowanceCharge(aUBLAllowanceCharge);
            }
        }
    }
    final TradeSettlementHeaderMonetarySummationType aSTSHMS = aHeaderSettlement.getSpecifiedTradeSettlementHeaderMonetarySummation();
    // TaxTotal
    {
        TaxTotalType aUBLTaxTotal = null;
        if (aSTSHMS != null && aSTSHMS.hasTaxTotalAmountEntries()) {
            // For all currencies
            for (final AmountType aTaxTotalAmount : aSTSHMS.getTaxTotalAmount()) {
                final TaxTotalType aUBLCurTaxTotal = new TaxTotalType();
                aUBLCurTaxTotal.setTaxAmount(_copyAmount(aTaxTotalAmount, new TaxAmountType(), sDefaultCurrencyCode));
                aUBLCreditNote.addTaxTotal(aUBLCurTaxTotal);
                if (aUBLTaxTotal == null) {
                    // Use the first one
                    aUBLTaxTotal = aUBLCurTaxTotal;
                }
            }
        } else {
            // Mandatory in UBL
            final TaxAmountType aUBLTaxAmount = new TaxAmountType();
            aUBLTaxAmount.setValue(BigDecimal.ZERO);
            aUBLTaxAmount.setCurrencyID(sDefaultCurrencyCode);
            aUBLTaxTotal = new TaxTotalType();
            aUBLTaxTotal.setTaxAmount(aUBLTaxAmount);
            aUBLCreditNote.addTaxTotal(aUBLTaxTotal);
        }
        for (final TradeTaxType aTradeTax : aHeaderSettlement.getApplicableTradeTax()) {
            final TaxSubtotalType aUBLTaxSubtotal = new TaxSubtotalType();
            if (aTradeTax.hasBasisAmountEntries()) {
                aUBLTaxSubtotal.setTaxableAmount(_copyAmount(aTradeTax.getBasisAmountAtIndex(0), new TaxableAmountType(), sDefaultCurrencyCode));
            }
            if (aTradeTax.hasCalculatedAmountEntries()) {
                aUBLTaxSubtotal.setTaxAmount(_copyAmount(aTradeTax.getCalculatedAmountAtIndex(0), new TaxAmountType(), sDefaultCurrencyCode));
            }
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            if (StringHelper.hasText(aTradeTax.getExemptionReasonCodeValue()))
                aUBLTaxCategory.setTaxExemptionReasonCode(aTradeTax.getExemptionReasonCodeValue());
            if (aTradeTax.getExemptionReason() != null) {
                final TaxExemptionReasonType aUBLTaxExemptionReason = new TaxExemptionReasonType();
                aUBLTaxExemptionReason.setValue(aTradeTax.getExemptionReason().getValue());
                aUBLTaxExemptionReason.setLanguageID(aTradeTax.getExemptionReason().getLanguageID());
                aUBLTaxExemptionReason.setLanguageLocaleID(aTradeTax.getExemptionReason().getLanguageLocaleID());
                aUBLTaxCategory.addTaxExemptionReason(aUBLTaxExemptionReason);
            }
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLTaxSubtotal.setTaxCategory(aUBLTaxCategory);
            aUBLTaxTotal.addTaxSubtotal(aUBLTaxSubtotal);
        }
    }
    // LegalMonetaryTotal
    {
        final MonetaryTotalType aUBLMonetaryTotal = new MonetaryTotalType();
        if (aSTSHMS != null) {
            if (aSTSHMS.hasLineTotalAmountEntries())
                aUBLMonetaryTotal.setLineExtensionAmount(_copyAmount(aSTSHMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTaxBasisTotalAmountEntries())
                aUBLMonetaryTotal.setTaxExclusiveAmount(_copyAmount(aSTSHMS.getTaxBasisTotalAmountAtIndex(0), new TaxExclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasGrandTotalAmountEntries())
                aUBLMonetaryTotal.setTaxInclusiveAmount(_copyAmount(aSTSHMS.getGrandTotalAmountAtIndex(0), new TaxInclusiveAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasAllowanceTotalAmountEntries())
                aUBLMonetaryTotal.setAllowanceTotalAmount(_copyAmount(aSTSHMS.getAllowanceTotalAmountAtIndex(0), new AllowanceTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasChargeTotalAmountEntries())
                aUBLMonetaryTotal.setChargeTotalAmount(_copyAmount(aSTSHMS.getChargeTotalAmountAtIndex(0), new ChargeTotalAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasTotalPrepaidAmountEntries())
                aUBLMonetaryTotal.setPrepaidAmount(_copyAmount(aSTSHMS.getTotalPrepaidAmountAtIndex(0), new PrepaidAmountType(), sDefaultCurrencyCode));
            if (aSTSHMS.hasRoundingAmountEntries()) {
                // compatibility
                if (MathHelper.isNE0(aSTSHMS.getRoundingAmountAtIndex(0).getValue()))
                    aUBLMonetaryTotal.setPayableRoundingAmount(_copyAmount(aSTSHMS.getRoundingAmountAtIndex(0), new PayableRoundingAmountType(), sDefaultCurrencyCode));
            }
            if (aSTSHMS.hasDuePayableAmountEntries())
                aUBLMonetaryTotal.setPayableAmount(_copyAmount(aSTSHMS.getDuePayableAmountAtIndex(0), new PayableAmountType(), sDefaultCurrencyCode));
        }
        aUBLCreditNote.setLegalMonetaryTotal(aUBLMonetaryTotal);
    }
    // All invoice lines
    for (final SupplyChainTradeLineItemType aLineItem : aSCTT.getIncludedSupplyChainTradeLineItem()) {
        final CreditNoteLineType aUBLCreditNoteLine = new CreditNoteLineType();
        final DocumentLineDocumentType aDLD = aLineItem.getAssociatedDocumentLineDocument();
        aUBLCreditNoteLine.setID(_copyID(aDLD.getLineID()));
        // Note
        for (final un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100.NoteType aLineNote : aDLD.getIncludedNote()) ifNotNull(aUBLCreditNoteLine::addNote, _copyNote(aLineNote));
        // Line extension amount
        boolean bLineExtensionAmountIsNegative = false;
        final LineTradeSettlementType aLineSettlement = aLineItem.getSpecifiedLineTradeSettlement();
        final TradeSettlementLineMonetarySummationType aSTSLMS = aLineSettlement.getSpecifiedTradeSettlementLineMonetarySummation();
        if (aSTSLMS != null) {
            if (aSTSLMS.hasLineTotalAmountEntries()) {
                aUBLCreditNoteLine.setLineExtensionAmount(_copyAmount(aSTSLMS.getLineTotalAmountAtIndex(0), new LineExtensionAmountType(), sDefaultCurrencyCode));
                if (isLT0Strict(aUBLCreditNoteLine.getLineExtensionAmountValue()))
                    bLineExtensionAmountIsNegative = true;
            }
        }
        // CreditNoted quantity
        final LineTradeDeliveryType aLineDelivery = aLineItem.getSpecifiedLineTradeDelivery();
        if (aLineDelivery != null) {
            final QuantityType aBilledQuantity = aLineDelivery.getBilledQuantity();
            if (aBilledQuantity != null) {
                aUBLCreditNoteLine.setCreditedQuantity(_copyQuantity(aBilledQuantity, new CreditedQuantityType()));
            }
        }
        // Accounting cost
        if (aLineSettlement.hasReceivableSpecifiedTradeAccountingAccountEntries()) {
            final TradeAccountingAccountType aLineAA = aLineSettlement.getReceivableSpecifiedTradeAccountingAccountAtIndex(0);
            aUBLCreditNoteLine.setAccountingCost(aLineAA.getIDValue());
        }
        // CreditNote period
        final SpecifiedPeriodType aLineBillingPeriod = aLineSettlement.getBillingSpecifiedPeriod();
        if (aLineBillingPeriod != null) {
            final PeriodType aUBLLinePeriod = new PeriodType();
            if (aLineBillingPeriod.getStartDateTime() != null)
                aUBLLinePeriod.setStartDate(_parseDate(aLineBillingPeriod.getStartDateTime().getDateTimeString(), aErrorList));
            if (aLineBillingPeriod.getEndDateTime() != null)
                aUBLLinePeriod.setEndDate(_parseDate(aLineBillingPeriod.getEndDateTime().getDateTimeString(), aErrorList));
            aUBLCreditNoteLine.addInvoicePeriod(aUBLLinePeriod);
        }
        // Order line reference
        final LineTradeAgreementType aLineAgreement = aLineItem.getSpecifiedLineTradeAgreement();
        if (aLineAgreement != null) {
            final ReferencedDocumentType aBuyerOrderReference = aLineAgreement.getBuyerOrderReferencedDocument();
            if (aBuyerOrderReference != null && StringHelper.hasText(aBuyerOrderReference.getLineIDValue())) {
                final OrderLineReferenceType aUBLOrderLineReference = new OrderLineReferenceType();
                aUBLOrderLineReference.setLineID(_copyID(aBuyerOrderReference.getLineID(), new LineIDType()));
                aUBLCreditNoteLine.addOrderLineReference(aUBLOrderLineReference);
            }
        }
        // Document reference
        for (final ReferencedDocumentType aLineReferencedDocument : aLineSettlement.getAdditionalReferencedDocument()) {
            final DocumentReferenceType aUBLDocRef = _convertDocumentReference(aLineReferencedDocument, aErrorList);
            if (aUBLDocRef != null)
                aUBLCreditNoteLine.addDocumentReference(aUBLDocRef);
        }
        // Allowance charge
        for (final TradeAllowanceChargeType aLineAllowanceCharge : aLineSettlement.getSpecifiedTradeAllowanceCharge()) {
            ETriState eIsCharge = ETriState.UNDEFINED;
            if (aLineAllowanceCharge.getChargeIndicator() != null)
                eIsCharge = _parseIndicator(aLineAllowanceCharge.getChargeIndicator(), aErrorList);
            else
                aErrorList.add(_buildError(new String[] { "CrossIndustryCreditNote", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeSettlement", "SpecifiedTradeAllowanceCharge" }, "Failed to determine if SpecifiedTradeAllowanceCharge is an Allowance or a Charge"));
            if (eIsCharge.isDefined()) {
                final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                _copyAllowanceCharge(aLineAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                aUBLCreditNoteLine.addAllowanceCharge(aUBLLineAllowanceCharge);
            }
        }
        // Item
        final ItemType aUBLItem = new ItemType();
        final TradeProductType aLineProduct = aLineItem.getSpecifiedTradeProduct();
        if (aLineProduct != null) {
            final TextType aDescription = aLineProduct.getDescription();
            if (aDescription != null)
                ifNotNull(aUBLItem::addDescription, _copyName(aDescription, new DescriptionType()));
            if (aLineProduct.hasNameEntries())
                aUBLItem.setName(_copyName(aLineProduct.getNameAtIndex(0), new NameType()));
            final IDType aBuyerAssignedID = aLineProduct.getBuyerAssignedID();
            if (aBuyerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aBuyerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setBuyersItemIdentification(aUBLID);
            }
            final IDType aSellerAssignedID = aLineProduct.getSellerAssignedID();
            if (aSellerAssignedID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aSellerAssignedID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setSellersItemIdentification(aUBLID);
            }
            final IDType aGlobalID = aLineProduct.getGlobalID();
            if (aGlobalID != null) {
                final ItemIdentificationType aUBLID = new ItemIdentificationType();
                aUBLID.setID(_copyID(aGlobalID));
                if (StringHelper.hasText(aUBLID.getIDValue()))
                    aUBLItem.setStandardItemIdentification(aUBLID);
            }
            final TradeCountryType aOriginCountry = aLineProduct.getOriginTradeCountry();
            if (aOriginCountry != null) {
                final CountryType aUBLCountry = new CountryType();
                aUBLCountry.setIdentificationCode(aOriginCountry.getIDValue());
                if (aOriginCountry.hasNameEntries())
                    aUBLCountry.setName(_copyName(aOriginCountry.getNameAtIndex(0), new NameType()));
                aUBLItem.setOriginCountry(aUBLCountry);
            }
            // Commodity Classification
            for (final ProductClassificationType aLineProductClassification : aLineProduct.getDesignatedProductClassification()) {
                final CodeType aClassCode = aLineProductClassification.getClassCode();
                if (aClassCode != null) {
                    final CommodityClassificationType aUBLCommodityClassification = new CommodityClassificationType();
                    aUBLCommodityClassification.setItemClassificationCode(_copyCode(aClassCode, new ItemClassificationCodeType()));
                    if (aUBLCommodityClassification.getItemClassificationCode() != null)
                        aUBLItem.addCommodityClassification(aUBLCommodityClassification);
                }
            }
        }
        for (final TradeTaxType aTradeTax : aLineSettlement.getApplicableTradeTax()) {
            final TaxCategoryType aUBLTaxCategory = new TaxCategoryType();
            aUBLTaxCategory.setID(aTradeTax.getCategoryCodeValue());
            if (aTradeTax.getRateApplicablePercentValue() != null)
                aUBLTaxCategory.setPercent(MathHelper.getWithoutTrailingZeroes(aTradeTax.getRateApplicablePercentValue()));
            final TaxSchemeType aUBLTaxScheme = new TaxSchemeType();
            aUBLTaxScheme.setID(getVATScheme());
            aUBLTaxCategory.setTaxScheme(aUBLTaxScheme);
            aUBLItem.addClassifiedTaxCategory(aUBLTaxCategory);
        }
        if (aLineProduct != null) {
            for (final ProductCharacteristicType aAPC : aLineProduct.getApplicableProductCharacteristic()) if (aAPC.hasDescriptionEntries()) {
                final ItemPropertyType aUBLAdditionalItem = new ItemPropertyType();
                aUBLAdditionalItem.setName(_copyName(aAPC.getDescriptionAtIndex(0), new NameType()));
                if (aAPC.hasValueEntries())
                    aUBLAdditionalItem.setValue(aAPC.getValueAtIndex(0).getValue());
                if (aUBLAdditionalItem.getName() != null)
                    aUBLItem.addAdditionalItemProperty(aUBLAdditionalItem);
            }
        }
        final PriceType aUBLPrice = new PriceType();
        boolean bUsePrice = false;
        if (aLineAgreement != null) {
            final TradePriceType aNPPTP = aLineAgreement.getNetPriceProductTradePrice();
            if (aNPPTP != null) {
                if (aNPPTP.hasChargeAmountEntries()) {
                    aUBLPrice.setPriceAmount(_copyAmount(aNPPTP.getChargeAmountAtIndex(0), new PriceAmountType(), sDefaultCurrencyCode));
                    bUsePrice = true;
                }
                if (aNPPTP.getBasisQuantity() != null) {
                    aUBLPrice.setBaseQuantity(_copyQuantity(aNPPTP.getBasisQuantity(), new BaseQuantityType()));
                    bUsePrice = true;
                }
            }
        }
        swapQuantityAndPriceIfNeeded(bLineExtensionAmountIsNegative, aUBLCreditNoteLine.getCreditedQuantityValue(), aUBLCreditNoteLine::setCreditedQuantity, bUsePrice ? aUBLPrice.getPriceAmountValue() : null, bUsePrice ? aUBLPrice::setPriceAmount : null);
        // Allowance charge
        final TradePriceType aTradePrice = aLineAgreement.getNetPriceProductTradePrice();
        if (aTradePrice != null)
            for (final TradeAllowanceChargeType aPriceAllowanceCharge : aTradePrice.getAppliedTradeAllowanceCharge()) {
                ETriState eIsCharge = ETriState.UNDEFINED;
                if (aPriceAllowanceCharge.getChargeIndicator() != null)
                    eIsCharge = _parseIndicator(aPriceAllowanceCharge.getChargeIndicator(), aErrorList);
                else
                    aErrorList.add(_buildError(new String[] { "CrossIndustryCreditNote", "SupplyChainTradeTransaction", "IncludedSupplyChainTradeLineItem", "SpecifiedLineTradeAgreement", "NetPriceProductTradePrice", "AppliedTradeAllowanceCharge" }, "Failed to determine if AppliedTradeAllowanceCharge is an Allowance or a Charge"));
                if (eIsCharge.isDefined()) {
                    final AllowanceChargeType aUBLLineAllowanceCharge = new AllowanceChargeType();
                    aUBLLineAllowanceCharge.setChargeIndicator(eIsCharge.getAsBooleanValue());
                    _copyAllowanceCharge(aPriceAllowanceCharge, aUBLLineAllowanceCharge, sDefaultCurrencyCode);
                    aUBLPrice.addAllowanceCharge(aUBLLineAllowanceCharge);
                }
            }
        if (bUsePrice)
            aUBLCreditNoteLine.setPrice(aUBLPrice);
        aUBLCreditNoteLine.setItem(aUBLItem);
        aUBLCreditNote.addCreditNoteLine(aUBLCreditNoteLine);
    }
    return aUBLCreditNote;
}
Also used : DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) CollectionHelper(com.helger.commons.collection.CollectionHelper) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) BigDecimal(java.math.BigDecimal) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) CrossIndustryInvoiceType(un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) BinaryObjectType(un.unece.uncefact.data.standard.unqualifieddatatype._100.BinaryObjectType) MathHelper(com.helger.commons.math.MathHelper) CGlobal(com.helger.commons.CGlobal) oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_23(oasis.names.specification.ubl.schema.xsd.commonbasiccomponents_23) StringHelper(com.helger.commons.string.StringHelper) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23) InvoiceType(oasis.names.specification.ubl.schema.xsd.invoice_23.InvoiceType) EqualsHelper(com.helger.commons.equals.EqualsHelper) Serializable(java.io.Serializable) ValueEnforcer(com.helger.commons.ValueEnforcer) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) Consumer(java.util.function.Consumer) LocalDate(java.time.LocalDate) IErrorList(com.helger.commons.error.list.IErrorList) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) LocalDate(java.time.LocalDate) un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100(un.unece.uncefact.data.standard.reusableaggregatebusinessinformationentity._100) TextType(un.unece.uncefact.data.standard.unqualifieddatatype._100.TextType) AmountType(un.unece.uncefact.data.standard.unqualifieddatatype._100.AmountType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23(oasis.names.specification.ubl.schema.xsd.commonaggregatecomponents_23) IDType(un.unece.uncefact.data.standard.unqualifieddatatype._100.IDType) CreditNoteType(oasis.names.specification.ubl.schema.xsd.creditnote_23.CreditNoteType) DateTimeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.DateTimeType) FormattedDateTimeType(un.unece.uncefact.data.standard.qualifieddatatype._100.FormattedDateTimeType) QuantityType(un.unece.uncefact.data.standard.unqualifieddatatype._100.QuantityType) ETriState(com.helger.commons.state.ETriState) CodeType(un.unece.uncefact.data.standard.unqualifieddatatype._100.CodeType) Nullable(javax.annotation.Nullable)

Aggregations

ErrorList (com.helger.commons.error.list.ErrorList)6 Serializable (java.io.Serializable)6 CrossIndustryInvoiceType (un.unece.uncefact.data.standard.crossindustryinvoice._100.CrossIndustryInvoiceType)6 CGlobal (com.helger.commons.CGlobal)3 ValueEnforcer (com.helger.commons.ValueEnforcer)3 CollectionHelper (com.helger.commons.collection.CollectionHelper)3 EqualsHelper (com.helger.commons.equals.EqualsHelper)3 IErrorList (com.helger.commons.error.list.IErrorList)3 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)3 MathHelper (com.helger.commons.math.MathHelper)3 ETriState (com.helger.commons.state.ETriState)3 StringHelper (com.helger.commons.string.StringHelper)3 ValidationResult (com.helger.phive.api.result.ValidationResult)3 ValidationResultList (com.helger.phive.api.result.ValidationResultList)3 File (java.io.File)3 BigDecimal (java.math.BigDecimal)3 LocalDate (java.time.LocalDate)3 Consumer (java.util.function.Consumer)3 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3