ZUGFeRD / mustangproject

Open Source Java e-Invoicing library, validator and tool (Factur-X/ZUGFeRD, UNCEFACT/CII XRechnung)
http://www.mustangproject.org
Apache License 2.0
240 stars 136 forks source link

SpecifiedTradeSettlementPaymentMeans hardcoded #516

Open Paeprock opened 1 month ago

Paeprock commented 1 month ago

Why are these hardcoded in IZUGFeRDTradeSettlementPayment.java? (I know I can overwrite it if I want to)

` String xml = ""

fktrdui commented 1 month ago

@Paeprock could you please specify the steps you use to overwrite the ?

Paeprock commented 1 month ago

@Paeprock could you please specify the steps you use to overwrite the ram:Information?

Go ahead and create your own Class extending TradeParty and overwrite the following method getAsTradeSettlement and let it return an array of your own implementation of IZUGFeRDTradeSettlement in which you return the XML content in getSettlementXML

fktrdui commented 4 weeks ago

Thank you @Paeprock. I initially wondered if you’d found a dedicated field in a related class that could control this directly. It seems overriding getSettlementXML is currently the optimal solution for fine-tuning SpecifiedTradeSettlementPaymentMeans.

ThomasChr commented 5 days ago

Thats my workaround code if anyone needs it. Would be a simple issue to solve and add to the library but I‘m not a Java Guy so I better leave it to anyone else.

/* This was needed to set my own code in the xRechnung XML for '<ram:SpecifiedTradeSettlementPaymentMeans>'
See this issue: https://github.com/ZUGFeRD/mustangproject/issues/516
 */
package org.xxx;

import org.mustangproject.TradeParty;
import org.mustangproject.ZUGFeRD.IZUGFeRDTradeSettlement;

public class CustomTradeParty extends TradeParty {
    private Integer paymentMeansCode = 58;
    private String paymentMeansDescription= "SEPA credit transfer";

    @Override
    public IZUGFeRDTradeSettlement[] getAsTradeSettlement() {
        CustomTradeSettlement customSettlement = new CustomTradeSettlement(this);

        return new CustomTradeSettlement[]{customSettlement};
    }

    public Integer getPaymentMeansCode() {
        return paymentMeansCode;
    }

    public void setPaymentMeansCode(Integer paymentMeansCode) {
        this.paymentMeansCode = paymentMeansCode;
    }

    public String getPaymentMeansDescription() {
        return paymentMeansDescription;
    }

    public void setPaymentMeansDescription(String paymentMeansDescription) {
        this.paymentMeansDescription = paymentMeansDescription;
    }
}

class CustomTradeSettlement implements IZUGFeRDTradeSettlement {
    private final CustomTradeParty tradeParty;

    public CustomTradeSettlement(CustomTradeParty customTradeParty) {
        this.tradeParty = customTradeParty;
    }

    @Override
    public String getSettlementXML() {
        String xml = "<ram:SpecifiedTradeSettlementPaymentMeans>"
                + "<ram:TypeCode>" + tradeParty.getPaymentMeansCode().toString() + "</ram:TypeCode>"
                + "<ram:Information>" + tradeParty.getPaymentMeansDescription() + "</ram:Information>"
                + "<ram:PayeePartyCreditorFinancialAccount>"
                + "<ram:IBANID>" + tradeParty.getBankDetails().get(0).getIBAN() + "</ram:IBANID>"
                + "</ram:PayeePartyCreditorFinancialAccount>"
                + "<ram:PayeeSpecifiedCreditorFinancialInstitution>"
                + "<ram:BICID>" + tradeParty.getBankDetails().get(0).getBIC() + "</ram:BICID>"
                + "</ram:PayeeSpecifiedCreditorFinancialInstitution>"
                + "</ram:SpecifiedTradeSettlementPaymentMeans>";
        return xml;
    }
}
ThomasChr commented 2 days ago

It's so embarrassing that one can see all those force pushes to the branch. I struggled hard with some unrelated white space changes.