Deal.java
package com.tradecloud.domain.model.deal;
import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.base.utils.MathUtils;
import com.tradecloud.domain.exception.ZeroDealException;
import com.tradecloud.domain.model.*;
import com.tradecloud.domain.model.organisationalunit.OrganisationalUnit;
import com.tradecloud.domain.treasury.TreasuryBank;
import org.apache.commons.lang.Validate;
import org.hibernate.annotations.Type;
import org.joda.time.LocalDate;
import org.joda.time.LocalDateTime;
import org.joda.time.Period;
import javax.persistence.*;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Currency;
import java.util.List;
/**
* Deal is the root entity of the deal aggregate. Deals in a quoted state can be
* deleted while deals in a accepted state cannot be deleted or changed instead
* a contra deal must be created.
*/
@Entity
@Table(name = "deal")
public class Deal extends PersistenceBase implements ActualExposure {
private static final int THIRTY_ONE = 31;
private static final long serialVersionUID = 1L;
@Column(name = "maturity_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate maturityDate;
@Column(name = "estimated_settlement_date")
private EstimatedSettlementDate estimatedSettlementDate;
@Column(name = "settlement_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate settlementDate;
@Column(name = "deal_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
private LocalDateTime dealDate;
@Embedded
@AttributeOverrides({@AttributeOverride(name = "currency", column = @Column(name = "spot_rate_currency")),
@AttributeOverride(name = "value", column = @Column(name = "spot_rate_value", precision = 19, scale = 6))})
private Money spotRate;
@Embedded
@AttributeOverrides({@AttributeOverride(name = "currency", column = @Column(name = "forward_rate_currency")),
@AttributeOverride(name = "value", column = @Column(name = "forward_rate_value", precision = 19, scale = 6))})
private Money forwardRate;
@Embedded
@AttributeOverrides({@AttributeOverride(name = "currency", column = @Column(name = "amount_currency")),
@AttributeOverride(name = "value", column = @Column(name = "amount_value", precision = 19, scale = 6))})
private Money amount;
@Embedded
private DealStatus status = DealStatus.QUOTED;
// don't want to create new OrganisationalUnit objects for Deal only resuse existing ones
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "organisationalunit_id")
private OrganisationalUnit organisationalUnit;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "forexgroup_id")
private ForexGroup forexGroup;
// orderReference can beto shipment reference or , depending on how Redbox
// is configured
@Embedded
private OrderReference orderReference;
// dealLinkReference is actually the shipment reference
@Embedded
private DealLinkReference dealLinkReference;
@Embedded
private ShippingReference shippingReference;
@Embedded
private PaymentReference paymentReference;
@Embedded
private DebitCreditNoteReference debitCreditNoteReference;
@Embedded
@AttributeOverrides({@AttributeOverride(name = "currency", column = @Column(name = "debitCreditNoteAmount_currency")),
@AttributeOverride(name = "value", column = @Column(name = "debitCreditNoteAmount_value", precision = 19, scale = 6))})
private Money debitCreditNoteAmount;
@Embedded
private InvoiceReference invoiceReference;
@Column(name = "debitcreditnote_settlement_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate debitCreditNoteSettlementDate;
private String supplier;
@Enumerated(value = EnumType.STRING)
private TradePurpose tradePurpose;
@Column(name = "invoiced_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate invoicedDate;
@Transient
private Money groupAmount;
@Transient
private String autoLinkingMesg;
@Column(name = "expiry_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
LocalDateTime expiryDate;
@Column(name = "deal_leg_type")
@Enumerated(EnumType.STRING)
DealLegType dealLegType;
@ManyToOne(cascade = CascadeType.PERSIST)
Deal parent;
private String source;
@Column(name = "transaction_type")
//todo refactor into DealTransactionType enum
private String transactionType;
@Column(name = "buy_sell_deal_type")
@Enumerated(value = EnumType.STRING)
private BuySellDealType buySellDealType;
@ElementCollection
@CollectionTable(name = "deal_invoice_references", joinColumns = @JoinColumn(name = "deal_id"))
@Column(name = "invoice_reference")
private List<String> invoiceReferences;
@Column(name = "deal_rate_reset_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
private LocalDateTime dealRateResetDate;
private transient List<FECDealLink> fecDealLinks;
private transient List<FECRequestDealLink> fecRequestDealLinks;
//for now we keep party,buyer and paymentterm as string until, all clients have migrated to TC.
//otherwise we need to sync redbox and TC party(division), buyer and payment terms.
//There is no need to do sync for now, strings fulfills the current requirement, which is just to show names on the deal.
private String party;
private String buyer;
private String paymentTerm;
private String number;
//only applicable to direct cost(Merchandise forexgroup)
//only applicable to TC not redbox integration.
private String paymentType;
@Column(name = "shipment_date")
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
private LocalDate shipmentBillDate;
@ManyToOne
@JoinColumn(name = "nominatedBank_code")
private TreasuryBank nominatedBank;
private String orderNumber;
//settled amount for order
private BigDecimal orderSettledAmount;
@Column(name = "shipNumber")
private String shipmentNumber;
// @Column(name = "billdate")
// @Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalDateTime")
// private LocalDateTime shipmentBillDate;
private boolean earlyOrder = false;
private boolean fullLinked = false;
/**
* Creates a new {@code Deal} instance. This has private accessibility so
* cannot be used by outside clients. {@code Deal} instances should be
* created via a {@code DealBuilder} instance. A {@code DealBuilder} can be
* acquired by calling {@link #createBuilder()}.
*
* @param dealDate The date the deal was created
* @param amount The monetary value of the deal
* @param dealLinkReference The deal link reference
* @param estimatedSettlementDate The estimated date of settlement
* @param orderReference The order reference associated with the deal
* @param supplier The supplier associated with the deal
* @param tradePurpose The trade purpose associated with the deal
* @param dealLegType
* @param parent
* @param source
* @param transactionType
* @param nominatedBank
* @param shipmentNumber
* @param earlyOrder
* @see #createBuilder()
*/
private Deal(LocalDateTime dealDate, OrganisationalUnit organisationalUnit, Money amount, DealLinkReference dealLinkReference,
EstimatedSettlementDate estimatedSettlementDate, OrderReference orderReference, String supplier, TradePurpose tradePurpose,
ForexGroup forexGroup, LocalDate maturityDate, LocalDateTime expiryDate, DealLegType dealLegType, Deal parent, String source,
String transactionType, ShippingReference shippingReference, String party, String buyer, String paymentTerm, LocalDate shipmentDate,
String number, String paymentType, TreasuryBank nominatedBank, String orderNumber, BigDecimal orderSettledAmount,
InvoiceReference invoiceReference, String shipmentNumber, boolean earlyOrder) {
if (amount.getValue().compareTo(BigDecimal.ZERO) == 0) {
throw new ZeroDealException("Cannot create zero value deals");
}
Validate.notNull(number, "Deal number cannot be empty");
this.dealDate = dealDate;
this.amount = amount;
this.dealLinkReference = dealLinkReference;
this.estimatedSettlementDate = estimatedSettlementDate;
this.organisationalUnit = organisationalUnit;
this.orderReference = orderReference;
this.supplier = supplier;
this.maturityDate = maturityDate;
this.forexGroup = forexGroup;
this.tradePurpose = tradePurpose;
this.expiryDate = expiryDate;
this.dealLegType = dealLegType;
this.parent = parent;
this.source = source;
this.transactionType = transactionType;
setBuySellType(amount);
this.shippingReference = shippingReference;
this.dealRateResetDate = LocalDateTime.now();
this.party = party;
this.buyer = buyer;
this.paymentTerm = paymentTerm;
this.shipmentBillDate = shipmentDate;
this.number = number;
this.paymentType = paymentType;
this.nominatedBank = nominatedBank;
this.orderNumber = orderNumber;
this.invoiceReference = invoiceReference;
this.orderSettledAmount = orderSettledAmount;
// this.shipmentBillDate=shipmentBillDate;
this.shipmentNumber = shipmentNumber;
this.invoiceReference = invoiceReference;
this.orderSettledAmount = orderSettledAmount;
this.shipmentBillDate = shipmentBillDate;
this.shipmentNumber = shipmentNumber;
this.earlyOrder = earlyOrder;
}
private void setBuySellType(Money amount) {
if (amount.isPositive()) {
buySellDealType = BuySellDealType.BUY;
} else {
buySellDealType = BuySellDealType.SELL;
}
}
public List<String> getInvoiceReferences() {
return invoiceReferences;
}
public void setInvoiceReferences(List<String> invoiceReferences) {
this.invoiceReferences = invoiceReferences;
}
public void addInvoiceReference(String invoiceReference) {
if (this.invoiceReferences == null || this.invoiceReferences.isEmpty()) {
invoiceReferences = new ArrayList<String>();
}
if (!invoiceReferences.contains(invoiceReference)) {
invoiceReferences.add(invoiceReference);
}
}
/**
* Creates a {@code DealBuilder} instance. {@code Deal} instances should
* only be created using a {@code DealBuilder} instance.
*
* @return a new {@code DealBuilder} instance
*/
public static DealBuilder createBuilder() {
return new DealBuilder();
}
public Deal accept() {
if (DealStatus.QUOTED.equals(this.getStatus())) {
status = DealStatus.ACCEPTED;
}
return this;
}
public Deal acceptSettled() {
if (DealStatus.SETTLED.equals(this.getStatus())) {
status = DealStatus.ACCEPTED;
}
return this;
}
public Deal acceptWhenInvoiced() {
if (DealStatus.INVOICED.equals(this.getStatus())) {
status = DealStatus.ACCEPTED;
}
return this;
}
public Deal audit(List<FECDealLink> fecDealLinks, List<FECRequestDealLink> fecRequestDealLinks, boolean preventLinkedDealToBeAudited) {
if ((fecDealLinks.size() > 0 || fecRequestDealLinks.size() > 0) && preventLinkedDealToBeAudited) {
throw new IllegalStateException("Deal cannot be deleted as links exist");
}
status = DealStatus.AUDIT;
return this;
}
public Deal settle(LocalDate actualSettlementDate, PaymentReference paymentReference) {
settlementDate = actualSettlementDate;
this.paymentReference = paymentReference;
status = DealStatus.SETTLED;
return this;
}
public Deal invoice(InvoiceReference invoiceReference) {
updateInvoiceReference(invoiceReference);
status = DealStatus.INVOICED;
return this;
}
public InvoiceReference getInvoiceReference() {
return invoiceReference;
}
public OrderReference getOrderReference() {
return orderReference;
}
public void setOrderReference(OrderReference orderReference) {
this.orderReference = orderReference;
}
public LocalDate getMaturityDate() {
return maturityDate;
}
@Override
public TreasuryBank getBank() {
return nominatedBank;
}
public String getOrderNumber() {
return orderNumber;
}
public LocalDate getSettlementDate() {
return settlementDate;
}
public LocalDate getDebitCreditNoteSettlementDate() {
return debitCreditNoteSettlementDate;
}
public Money getForwardRate() {
return forwardRate;
}
public void setForwardRate(Money forwardRate) {
this.forwardRate = forwardRate;
}
public void setSpotRate(Money spotRate) {
this.spotRate = spotRate;
}
public Money getSpotRate() {
return spotRate;
}
public LocalDateTime getDealDate() {
return dealDate;
}
public DealLinkReference getDealLinkReference() {
return dealLinkReference;
}
public DebitCreditNoteReference getDebitCreditNoteReference() {
return debitCreditNoteReference;
}
public Money getDebitCreditNoteAmount() {
return debitCreditNoteAmount;
}
public void setDealLinkReference(DealLinkReference dealLinkReference) {
this.dealLinkReference = dealLinkReference;
}
public ShippingReference getShippingReference() {
return shippingReference;
}
public void setShippingReference(ShippingReference shippingReference) {
this.shippingReference = shippingReference;
}
public Money getAmount() {
return amount;
}
public DealStatus getStatus() {
return status;
}
public DealLegType getDealLegType() {
return dealLegType;
}
public void setDealLegType(DealLegType dealLegType) {
this.dealLegType = dealLegType;
}
public Deal getParent() {
return parent;
}
public String getShipmentNumber() {
return shipmentNumber;
}
// public LocalDateTime getShipmentBillDate() {
// return shipmentBillDate;
// }
public void setShipmentNumber(String shipmentNumber) {
this.shipmentNumber = shipmentNumber;
}
public void setShipmentBillDate(LocalDate shipmentBillDate) {
this.shipmentBillDate = shipmentBillDate;
}
public void setParent(Deal parent) {
this.parent = parent;
}
public BuySellDealType getBuySellDealType() {
if (buySellDealType == null) {
if (amount.isNegative()) {
return BuySellDealType.SELL;
} else {
return BuySellDealType.BUY;
}
}
return buySellDealType;
}
// @Deprecated //moved to DealService
// public Deal calculateRates(RatesResponse response) {
// if (organisationalUnit.getSpotRateMargin() == null) {
// spotRate = response.getSpotRate();
// } else {
// final BigDecimal adjustedSpotRateValue = response.getSpotRate().getValue()
// .multiply(organisationalUnit.getSpotRateMargin().getValue().add(BigDecimal.valueOf(1D)));
// spotRate = new Money(adjustedSpotRateValue, response.getSpotRate().getCurrency());
// }
//
// if (organisationalUnit.getForwardRateMargin() == null) {
// forwardRate = response.getForwardRate();
// } else {
// final BigDecimal adjustedForwardRateValue = response.getForwardRate().getValue()
// .multiply(organisationalUnit.getForwardRateMargin().getValue().add(BigDecimal.valueOf(1D)));
// forwardRate = new Money(adjustedForwardRateValue, response.getForwardRate().getCurrency());
// }
//
// return this;
// }
public Deal updateMaturityDate(LocalDate maturityDate) {
this.maturityDate = maturityDate;
return this;
}
public Deal updateEstimatedSettlementDate(EstimatedSettlementDate estimatedSettlementDate) {
this.estimatedSettlementDate = estimatedSettlementDate;
return this;
}
public Deal captureDebitCreditNote(DebitCreditNoteReference debitCreditNoteReference, Money debitCreditNoteAmount,
LocalDate debitCreditNoteSettlementDate) {
if (DealStatus.QUOTED.equals(this.status) || DealStatus.ACCEPTED.equals(this.status)) {
throw new IllegalStateException("Can only capture debit/credit note when deal is in either invoiced or settled state");
}
this.debitCreditNoteReference = debitCreditNoteReference;
this.debitCreditNoteAmount = debitCreditNoteAmount;
this.debitCreditNoteSettlementDate = debitCreditNoteSettlementDate;
return this;
}
public DealStatus status() {
return status;
}
public Money unlinkedAmount(List<FECDealLink> fecDealLinks, List<FECRequestDealLink> fecRequestDealLinks) {
Money totalLinked = linkedAmount(fecDealLinks, fecRequestDealLinks);
return amount.subtract(totalLinked);
}
private Money linkedAmount(List<FECDealLink> fecDealLinks, List<FECRequestDealLink> fecRequestDealLinks) {
Money totalLinked = Money.zeroValue(amount.getCurrency());
totalLinked = totalLinked.add(fecLinkedAmount(fecDealLinks));
totalLinked = totalLinked.add(requestedLinkedAmount(fecRequestDealLinks));
return totalLinked;
}
public Money fecLinkedAmount(List<FECDealLink> fecDealLinks) {
Money totalLinked = Money.zeroValue(amount.getCurrency());
for (FECDealLink link : fecDealLinks) {
if (this.getId() == link.getDeal().getId()) {
totalLinked = totalLinked.add(link.getAmount());
}
}
return totalLinked;
}
public Money requestedLinkedAmount(List<FECRequestDealLink> fecRequestDealLinks) {
Money totalLinked = Money.zeroValue(amount.getCurrency());
for (FECRequestDealLink link : fecRequestDealLinks) {
if (this.getId() == link.getDeal().getId()) {
totalLinked = totalLinked.add(link.getAmount());
}
}
return totalLinked;
}
public boolean hasExpired(Period period) {
return (new LocalDateTime()).isAfter(dealDate.plus(period));
}
public OrganisationalUnit getOrganisationalUnit() {
return organisationalUnit;
}
public EstimatedSettlementDate getEstimatedSettlementDate() {
return estimatedSettlementDate;
}
public Deal adjustRate(Money spotRate, Money forwardRate) {
Validate.isTrue(status == DealStatus.QUOTED, "Can not adjust rates for an accepted deal");
this.spotRate = spotRate;
this.forwardRate = forwardRate;
return this;
}
public void applyFinanceCharges(EstimatedSettlementDate estimatedSettlementDate, LocalDate maturityDate, Money forwardRate) {
this.forwardRate = forwardRate;
this.estimatedSettlementDate = estimatedSettlementDate;
this.maturityDate = maturityDate;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Deal deal = (Deal) o;
if (getId() != deal.getId()) {
return false;
}
if (amount != null ? !amount.equals(deal.amount) : deal.amount != null) {
return false;
}
if (dealDate != null ? !dealDate.equals(deal.dealDate) : deal.dealDate != null) {
return false;
}
if (dealLinkReference != null ? !dealLinkReference.equals(deal.dealLinkReference) : deal.dealLinkReference != null) {
return false;
}
if (debitCreditNoteAmount != null ? !debitCreditNoteAmount.equals(deal.debitCreditNoteAmount) : deal.debitCreditNoteAmount != null) {
return false;
}
if (debitCreditNoteReference != null ? !debitCreditNoteReference.equals(deal.debitCreditNoteReference)
: deal.debitCreditNoteReference != null) {
return false;
}
if (organisationalUnit != null ? !organisationalUnit.equals(deal.organisationalUnit) : deal.organisationalUnit != null) {
return false;
}
if (estimatedSettlementDate != null ? !estimatedSettlementDate.equals(deal.estimatedSettlementDate) : deal.estimatedSettlementDate != null) {
return false;
}
if (forwardRate != null ? !forwardRate.equals(deal.forwardRate) : deal.forwardRate != null) {
return false;
}
if (invoiceReference != null ? !invoiceReference.equals(deal.invoiceReference) : deal.invoiceReference != null) {
return false;
}
if (maturityDate != null ? !maturityDate.equals(deal.maturityDate) : deal.maturityDate != null) {
return false;
}
if (orderReference != null ? !orderReference.equals(deal.orderReference) : deal.orderReference != null) {
return false;
}
if (paymentReference != null ? !paymentReference.equals(deal.paymentReference) : deal.paymentReference != null) {
return false;
}
if (settlementDate != null ? !settlementDate.equals(deal.settlementDate) : deal.settlementDate != null) {
return false;
}
if (spotRate != null ? !spotRate.equals(deal.spotRate) : deal.spotRate != null) {
return false;
}
if (status != deal.status) {
return false;
}
if (invoicedDate != null ? !invoicedDate.equals(deal.invoicedDate) : deal.invoicedDate != null) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = maturityDate != null ? maturityDate.hashCode() : 0;
result = THIRTY_ONE * result + (estimatedSettlementDate != null ? estimatedSettlementDate.hashCode() : 0);
result = THIRTY_ONE * result + (settlementDate != null ? settlementDate.hashCode() : 0);
result = THIRTY_ONE * result + (invoicedDate != null ? invoicedDate.hashCode() : 0);
result = THIRTY_ONE * result + (dealDate != null ? dealDate.hashCode() : 0);
result = THIRTY_ONE * result + (spotRate != null ? spotRate.hashCode() : 0);
result = THIRTY_ONE * result + (forwardRate != null ? forwardRate.hashCode() : 0);
result = THIRTY_ONE * result + (amount != null ? amount.hashCode() : 0);
result = THIRTY_ONE * result + (status != null ? status.hashCode() : 0);
result = THIRTY_ONE * result + (organisationalUnit != null ? organisationalUnit.hashCode() : 0);
result = THIRTY_ONE * result + (orderReference != null ? orderReference.hashCode() : 0);
result = THIRTY_ONE * result + (dealLinkReference != null ? dealLinkReference.hashCode() : 0);
result = THIRTY_ONE * result + (paymentReference != null ? paymentReference.hashCode() : 0);
result = THIRTY_ONE * result + (debitCreditNoteReference != null ? debitCreditNoteReference.hashCode() : 0);
result = THIRTY_ONE * result + (debitCreditNoteAmount != null ? debitCreditNoteAmount.hashCode() : 0);
if (getId() != null) {
result = THIRTY_ONE * result + (int) (getId() ^ (getId() >>> 32));
}
result = THIRTY_ONE * result + (invoiceReference != null ? invoiceReference.hashCode() : 0);
return result;
}
/**
* for hibernate use.
*/
public Deal() {
}
public String getSupplier() {
return supplier;
}
public void setSupplier(String supplier) {
this.supplier = supplier;
}
public boolean canLinkToFEC(boolean allowQuotedDealsToLinkToFecConfig) {
return !DealStatus.isInvalidStateForLinking(status, allowQuotedDealsToLinkToFecConfig);
}
public TradePurpose getTradePurpose() {
return tradePurpose;
}
public void updateInvoiceReference(InvoiceReference invoiceReference) {
this.invoiceReference = invoiceReference;
this.invoicedDate = new LocalDate();
addInvoiceReference(invoiceReference.getReference());
}
public LocalDate getInvoicedDate() {
return invoicedDate;
}
public void setInvoicedDate(LocalDate invoicedDate) {
// TODO: Ask Stirling the Grey about this little DDD conundrum
this.invoicedDate = invoicedDate;
}
public String getNumber() {
return number;
}
public String getPaymentType() {
return paymentType;
}
public void setPaymentType(String paymentType) {
this.paymentType = paymentType;
}
public TreasuryBank getNominatedBank() {
return nominatedBank;
}
public void setNominatedBank(TreasuryBank nominatedBank) {
this.nominatedBank = nominatedBank;
}
public void setOrderNumber(String orderNumber) {
this.orderNumber = orderNumber;
}
@Override
public String toString() {
return String.valueOf(getId());
}
public Money getGroupAmount() {
return groupAmount;
}
public void setGroupAmount(Money groupAmount) {
this.groupAmount = groupAmount;
}
public String getAutoLinkingMesg() {
return autoLinkingMesg;
}
public void setAutoLinkingMesg(String autoLinkingMesg) {
this.autoLinkingMesg = autoLinkingMesg;
}
public OrganisationalUnit getDivision() {
return getOrganisationalUnit();
}
public PaymentReference getPaymentReference() {
return paymentReference;
}
public ForexGroup getForexGroup() {
return this.forexGroup;
}
@Override
public Currency getCurrency() {
return amount.getCurrency();
}
public void setDealLegDetails(Deal parentDeal, DealLegType dealLegType) {
if (dealLegType != DealLegType.ORIGINAL) {
Validate.isTrue(parentDeal != null, "Only original deals can have blank parent");
} else {
Validate.isTrue(parentDeal == null, "original deals must have blank parent");
}
this.setParent(parentDeal);
this.setDealLegType(dealLegType);
}
public void setAmount(Money money) {
amount = money;
setBuySellType(money);
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getTransactionType() {
return transactionType;
}
public void setTransactionType(String transactionType) {
this.transactionType = transactionType;
}
public LocalDateTime getDealRateResetDate() {
return dealRateResetDate;
}
public void setDealRateResetDate(LocalDateTime dealRateResetDate) {
this.dealRateResetDate = dealRateResetDate;
}
public void setFECDealLinks(List<FECDealLink> fecDealLinks) {
this.fecDealLinks = fecDealLinks;
}
public List<FECDealLink> getFecDealLinks() {
return fecDealLinks;
}
public void setFECRequestDealLinks(List<FECRequestDealLink> fecRequestDealLinks) {
this.fecRequestDealLinks = fecRequestDealLinks;
}
public List<FECRequestDealLink> getFecRequestDealLinks() {
return fecRequestDealLinks;
}
public String getParty() {
return party;
}
public String getBuyer() {
return buyer;
}
public String getPaymentTerm() {
return paymentTerm;
}
public LocalDate getShipmentBillDate() {
return shipmentBillDate;
}
public BigDecimal getOrderSettledAmount() {
return orderSettledAmount;
}
public void setOrderSettledAmount(BigDecimal orderSettledAmount) {
this.orderSettledAmount = orderSettledAmount;
}
// public String getRateConfig() {
// DealStatus status1 = this.getStatus();
// if (status1.equals(DealStatus.QUOTED) || status1.equals(DealStatus.ACCEPTED) ||
// status1.equals(DealStatus.AUDIT)) {
// return this.getDivision().getEstimatedCostingConfig(forexGroup.getName());
// } else if (status1.equals(DealStatus.INVOICED) || status1.equals(DealStatus.SETTLED)) {
// return this.getDivision().getActualCostingConfig(forexGroup.getName());
// }
// return null;
// }
/**
* Class that handles the building of a {@code Deal} instance. This pattern
* is used as the {@code Deal} constructor contains too many parameters
* which is unwieldy for clients to work with. It also forces clients of
* this class to create valid deals.
*/
public static class DealBuilder {
private LocalDateTime dealDate;
private OrganisationalUnit organisationalUnit;
private Money amount;
private DealLinkReference dealLinkReference;
private EstimatedSettlementDate estimatedSettlementDate;
private OrderReference orderReference;
private String supplier;
private TradePurpose tradePurpose;
private ForexGroup forexGroup;
private LocalDate maturityDate;
private LocalDateTime expiryDate;
private DealLegType dealLegType;
private Deal parent;
private String source;
private String transactionType;
private ShippingReference shippingReference;
private String party;
private String buyer;
private String paymentTerm;
private LocalDate shipmentBillDate;
private String number;
private String splitPaymentType;
private String orderNumber;
private TreasuryBank nominatedBank;
private BigDecimal orderSettledAmount;
private InvoiceReference invoiceReference;
private String shipmentNumber;
private boolean earlyOrder = false;
private DealBuilder() {
}
/**
* Creates a new {@code Deal} once the built parameters are deemed
* valid.
*
* @return a new {@code Deal} instance.
* @throws IllegalArgumentException if any required fields are missing
* @throws ZeroDealException if the amount field is zero
*/
public Deal build() {
validate();
return new Deal(dealDate, organisationalUnit, amount, dealLinkReference, estimatedSettlementDate, orderReference, supplier,
tradePurpose, forexGroup, maturityDate, expiryDate, dealLegType, parent, source, transactionType, shippingReference, party, buyer,
paymentTerm, shipmentBillDate, number, splitPaymentType, nominatedBank, orderNumber, orderSettledAmount,
invoiceReference, shipmentNumber, earlyOrder);
}
public DealBuilder setDealDate(LocalDateTime dealDate) {
this.dealDate = dealDate;
return this;
}
public DealBuilder setDivision(OrganisationalUnit organisationalUnit) {
this.organisationalUnit = organisationalUnit;
return this;
}
public DealBuilder setAmount(Money amount) {
this.amount = amount;
return this;
}
public DealBuilder setDealLinkReference(DealLinkReference dealLinkReference) {
this.dealLinkReference = dealLinkReference;
return this;
}
public DealBuilder setShippingReference(ShippingReference shippingReference) {
this.shippingReference = shippingReference;
return this;
}
public DealBuilder setEstimatedSettlementDate(EstimatedSettlementDate estimatedSettlementDate) {
this.estimatedSettlementDate = estimatedSettlementDate;
return this;
}
public DealBuilder setOrderReference(OrderReference orderReference) {
this.orderReference = orderReference;
return this;
}
public DealBuilder setSupplier(String supplier) {
this.supplier = supplier;
return this;
}
public DealBuilder setTradePurpose(TradePurpose tradePurpose) {
this.tradePurpose = tradePurpose;
return this;
}
public DealBuilder setExpiryDate(LocalDateTime expiryDate) {
this.expiryDate = expiryDate;
return this;
}
public DealBuilder setMaturityDate(LocalDate maturityDate) {
this.maturityDate = maturityDate;
return this;
}
public DealBuilder setForexGroup(ForexGroup forexGroup) {
this.forexGroup = forexGroup;
return this;
}
public DealBuilder setDealLegType(DealLegType dealLegType) {
this.dealLegType = dealLegType;
return this;
}
public DealBuilder setParent(Deal parent) {
this.parent = parent;
return this;
}
public DealBuilder setSource(String source) {
this.source = source;
return this;
}
public DealBuilder setTransactionType(String transactionType) {
this.transactionType = transactionType;
return this;
}
public DealBuilder setParty(String party) {
this.party = party;
return this;
}
public DealBuilder setBuyer(String buyer) {
this.buyer = buyer;
return this;
}
public DealBuilder setPaymentTerm(String paymentTerm) {
this.paymentTerm = paymentTerm;
return this;
}
public DealBuilder setShipmentBillDate(LocalDate shipmentBillDate) {
this.shipmentBillDate = shipmentBillDate;
return this;
}
public DealBuilder setNumber(String number) {
this.number = number;
return this;
}
public DealBuilder setSplitPaymentType(String splitPaymentType) {
this.splitPaymentType = splitPaymentType;
return this;
}
public DealBuilder setNominatedBank(TreasuryBank nominatedBank) {
this.nominatedBank = nominatedBank;
return this;
}
public DealBuilder setInvoiceReference(InvoiceReference invoiceReference) {
this.invoiceReference = invoiceReference;
return this;
}
public DealBuilder setOrderNumber(String orderNumber) {
this.orderNumber = orderNumber;
return this;
}
public DealBuilder setOrderSettledAmount(BigDecimal orderSettledAmount) {
this.orderSettledAmount = orderSettledAmount;
return this;
}
public DealBuilder setShipmentNumber(String shipmentNumber) {
this.shipmentNumber = shipmentNumber;
return this;
}
private void ensureNotNull(Object object, String name) {
if (object == null) {
throw new IllegalArgumentException("A valid Deal requires " + name + " to be set.");
}
}
private void validate() {
if (MathUtils.areNumbersCloselyEqual(amount.getValue().abs(), BigDecimal.ZERO, 2)) {
throw new ZeroDealException("Cannot create zero value deals");
}
ensureNotNull(dealDate, "deal date");
ensureNotNull(amount, "amount");
ensureNotNull(estimatedSettlementDate, "estimatedSettlementDate");
ensureNotNull(organisationalUnit, "organisationalUnit");
ensureNotNull(orderReference, "orderReference");
ensureNotNull(supplier, "supplier");
ensureNotNull(tradePurpose, "tradePurpose");
}
public DealBuilder setEarlyOrder(boolean earlyOrder) {
this.earlyOrder = earlyOrder;
return this;
}
}
public static DealDateComparator getDealDateComparator() {
return new DealDateComparator();
}
private static class DealDateComparator implements Comparator<Deal> {
@Override
public int compare(Deal o1, Deal o2) {
return o1.getDealDate().compareTo(o2.getDealDate());
}
}
public boolean isEarlyOrder() {
return earlyOrder;
}
public void setEarlyOrder(boolean earlyOrder) {
this.earlyOrder = earlyOrder;
}
public boolean isFullLinked() {
return fullLinked;
}
public void setFullLinked(boolean fullLinked) {
this.fullLinked = fullLinked;
}
}