OrderDTO.java

package com.tradecloud.dto.api;

import com.fasterxml.jackson.annotation.*;
import com.tradecloud.domain.document.invoice.UnitPricePerItem;
import com.tradecloud.domain.event.ActivityLogType;
import com.tradecloud.domain.model.ordermanagement.VolumeOrWeightSource;
import com.tradecloud.domain.shipment.RouteType;
import com.tradecloud.dto.address.AddressDTO;
import com.tradecloud.dto.api.invoice.OrderPlannedSettlementDTO;
import com.tradecloud.dto.api.shipment.BasicShipmentInvoiceDTO;
import com.tradecloud.dto.order.ContainerQuantityDTO;
import com.tradecloud.dto.order.DatesDTO;
import com.tradecloud.schema.ISOCurrencyCodeType;
import com.tradecloud.schema.Incoterm;
import com.tradecloud.schema.dashboard.Order;
import com.tradecloud.schema.ordermanagement.CostedPurchaseOrder;
import com.tradecloud.schema.ordermanagement.Costline;
import com.tradecloud.schema.ordermanagement.FreightMode;

import javax.xml.datatype.XMLGregorianCalendar;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@JsonRootName(value = "order")
@JsonPropertyOrder(alphabetic = true)
@JsonIgnoreProperties(value = {"elcCosts"})
//@XmlTransient
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class OrderDTO extends CostedPurchaseOrder implements Serializable {
    @JsonProperty("containerQuantity")
    public List<ContainerQuantityDTO> containerQuantity2;
    private DatesDTO datesDTO;
    private String state;
    private int cargoWeight;
    private int cargoVolume;
    private RouteType routeType;
    private Order trackingDTO;
    @JsonPropertyDescription(value = "Will be   available when order is linked to shipment")
    @JsonProperty(access = JsonProperty.Access.AUTO)
    private String shipmentReference;
    @JsonPropertyDescription(value = "Will be available when order is linked to sub shipment")
    @JsonProperty(access = JsonProperty.Access.AUTO)
    private String subShipmentReference;
    @JsonProperty(access = JsonProperty.Access.AUTO)
    private List<BasicShipmentInvoiceDTO> commercialInvoices = new ArrayList<>();
    @JsonProperty(access = JsonProperty.Access.AUTO)
    private List<BasicShipmentInvoiceDTO> serviceProviderInvoices = new ArrayList<>();
    private String orderNumber;
    private String supplierName;
    private String organisationName;
    private String stateName;
    private List<OrderPlannedSettlementDTO> settlementDatePercentageDTOS = new ArrayList<>();
    private boolean elc;
    private Date lspPaymentDate;
    private Date serviceFeePaymentDate;
    private AddressDTO finalDestinationDeliveryAddress;
    private UnitPricePerItem unitPricePerItem;
    private AddressDTO collectionAddressDTO;
    private List<StaticDataDTO> costingLsp;
    private CurrencyExchangeRateDTO supplyROE = new CurrencyExchangeRateDTO();
    @JsonPropertyDescription(value = "Shows the last activity performed by buyer or supplier")
    private ActivityLogType lastActivity;
    private String rejectReason;
    private Long orderId;
    private Date estimatedArrivalDate;

    private VolumeOrWeightSource totalVolumeOrWeightSource = VolumeOrWeightSource.ITEM;

    protected List<Costline> costline;

    public OrderDTO() {
    }

    public OrderDTO(CostedPurchaseOrder costedPurchaseOrder) {
        super();
        super.setBuyer(costedPurchaseOrder.getBuyer());
        super.setSupplier(costedPurchaseOrder.getSupplier());
        super.setArrivalAtPlaceOfDischargeDate(costedPurchaseOrder.getArrivalAtPlaceOfDischargeDate());
        super.setAvailabilityDate(costedPurchaseOrder.getAvailabilityDate());
        super.setClearingDepot(costedPurchaseOrder.getClearingDepot());
        super.setComments(costedPurchaseOrder.getComments());
        super.setConfirmed(costedPurchaseOrder.isConfirmed());
        super.setCurrency(costedPurchaseOrder.getCurrency());
        super.setEarliestShipmentDate(costedPurchaseOrder.getEarliestShipmentDate());
        super.setFinalDestination(costedPurchaseOrder.getFinalDestination());
        super.setForeignAgent(costedPurchaseOrder.getForeignAgent());
        super.setFreightMode(costedPurchaseOrder.getFreightMode());
        super.setMultiModalFreightMode(costedPurchaseOrder.getMultiModalFreightMode());
        super.setIncoterm(costedPurchaseOrder.getIncoterm());
        super.setLatestShipmentDate(costedPurchaseOrder.getLatestShipmentDate());
        super.setMerchandisingAgent(costedPurchaseOrder.getMerchandisingAgent());
        super.setNamedPlace(costedPurchaseOrder.getNamedPlace());
        super.setOrderDate(costedPurchaseOrder.getOrderDate());
        super.setOrderReference(costedPurchaseOrder.getReference());
        super.setOrganisationalUnit(costedPurchaseOrder.getOrganisationalUnit());
        super.setPaymentMethod(costedPurchaseOrder.getPaymentMethod());
        super.setPaymentTerm(costedPurchaseOrder.getPaymentTerm());
        super.setPlaceOfDischarge(costedPurchaseOrder.getPlaceOfDischarge());
        super.setPlaceOfLoading(costedPurchaseOrder.getPlaceOfLoading());
        super.setProformaReference(costedPurchaseOrder.getProformaReference());
        super.setReference(costedPurchaseOrder.getReference());
        super.setRequiredOnSiteDate(costedPurchaseOrder.getRequiredOnSiteDate());
        super.setSourcingAgent(costedPurchaseOrder.getSourcingAgent());
        super.setTradingMargin(costedPurchaseOrder.getTradingMargin());
        super.setWarehousingAgent(costedPurchaseOrder.getWarehousingAgent());
        super.getItems().addAll(costedPurchaseOrder.getItems());
        super.getContainerQuantity().addAll(costedPurchaseOrder.getContainerQuantity());

        super.getContainers().addAll(costedPurchaseOrder.getContainers());
    }

    public UnitPricePerItem getUnitPricePerItem() {
        return unitPricePerItem;
    }

    public void setUnitPricePerItem(UnitPricePerItem unitPricePerItem) {
        this.unitPricePerItem = unitPricePerItem;
    }

    @Override
    @JsonIgnore //ignore base ,we want to use containerQuantity2 of ContainerQuantityDTO
    public List getContainerQuantity() {

        if (containerQuantity2 == null) {
            containerQuantity2 = new ArrayList<ContainerQuantityDTO>();
        }
        return containerQuantity2;
    }

    @JsonIgnore
    public void setContainerQuantity(List<ContainerQuantityDTO> containerQuantity) {
        this.containerQuantity2 = containerQuantity;
    }

    public List<ContainerQuantityDTO> getContainerQuantity2() {
        return containerQuantity2;
    }

    public void setContainerQuantity2(List<ContainerQuantityDTO> containerQuantity2) {
        this.containerQuantity2 = containerQuantity2;
    }

    @Override
    @JsonView(Views.Search.class)
    @JsonProperty(required = true)
    @JsonPropertyDescription(value = "Duplicate order references are not allowed.")
    public String getReference() {
        return super.getReference();
    }

    public DatesDTO getDatesDTO() {
        return datesDTO;
    }

    public void setDatesDTO(DatesDTO datesDTO) {
        this.datesDTO = datesDTO;
    }

    public int getCargoWeight() {
        return cargoWeight;
    }

    public void setCargoWeight(int cargoWeight) {
        this.cargoWeight = cargoWeight;
    }

    public int getCargoVolume() {
        return cargoVolume;
    }

    public void setCargoVolume(int cargoVolume) {
        this.cargoVolume = cargoVolume;
    }

    @Override
    @JsonIgnore
    public String getOrganisationalUnit() {
        return super.getOrganisationalUnit();
    }

    @Override
    @JsonIgnore
    public void setOrganisationalUnit(String value) {
        super.setOrganisationalUnit(value);
    }

    @JsonProperty(required = true)
    @JsonPropertyDescription(value = "Call the GET organisations per buyer API method")
    public String getOrganisation() {
        return getOrganisationalUnit();
    }

    public void setOrganisation(String value) {
        setOrganisationalUnit(value);
    }

    @Override
    @JsonIgnore
    public String getOrderReference() {
        return super.getOrderReference();
    }

    @Override
    @JsonIgnore
    public void setOrderReference(String value) {
        super.setOrderReference(value);
    }

    @Override
    @JsonProperty(required = true)
    @JsonPropertyDescription(value = "A default can be set based on the supplier selected on the order (call the GET supplier API\n" +
                                     "and get the payment method.")
    public ISOCurrencyCodeType getCurrency() {
        return super.getCurrency();
    }

    @Override
    public void setCurrency(ISOCurrencyCodeType value) {
        super.setCurrency(value);
    }

    @Override
    @JsonProperty(required = true)
    @JsonPropertyDescription(value = "")
    public XMLGregorianCalendar getOrderDate() {
        return super.getOrderDate();
    }

    @Override
    public void setOrderDate(XMLGregorianCalendar value) {
        super.setOrderDate(value);
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "A default can be set based on the supplier selected on the order or call" +
                                     "the GET supplier API and get the full list of payment terms).\n" +
                                     "\n" +
                                     "NB. Not available on OMP.")
    public String getPaymentTerm() {
        return super.getPaymentTerm();
    }

    @Override
    @JsonProperty(required = true)
    @JsonPropertyDescription(value = "TradeSuite will not provide this field. Tradecloud will use the latest shipment date\n" +
                                     "and the lead time tables to calculate this field.")
    public XMLGregorianCalendar getRequiredOnSiteDate() {
        return super.getRequiredOnSiteDate();
    }

    @Override
    @JsonProperty(required = true)
    @JsonPropertyDescription(value = "TradeSuite will not provide this field. Tradecloud will use the latest shipment date\n" +
                                     "and the lead time tables to calculate this field.")
    public void setRequiredOnSiteDate(XMLGregorianCalendar value) {
        super.setRequiredOnSiteDate(value);
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public RouteType getRouteType() {
        return routeType;
    }

    public void setRouteType(RouteType routeType) {
        this.routeType = routeType;
    }

    public Order getTrackingDTO() {
        return trackingDTO;
    }

    public void setTrackingDTO(Order trackingDTO) {
        this.trackingDTO = trackingDTO;
    }

    @Override
    @JsonProperty(required = true)
    @JsonPropertyDescription(value = "GET final destination API for full list of final destinations.")
    public String getFinalDestination() {
        return super.getFinalDestination();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "A default can be pulled from the supplier record selected on the order. If no shipping mode is specified,\n" +
                                     "the shipping mode will default to the shipping mode specified under the client configuration setup.")
    public FreightMode getFreightMode() {
        return super.getFreightMode();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "A default can be set based on the supplier selected on the order or call the GET supplier API and get the" +
                                     "full list of payment methods.\n" +
                                     "\n" +
                                     "NB. Not available on OMP.")
    public String getPaymentMethod() {
        return super.getPaymentMethod();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "Call the get Clearing Depot API.")
    public String getClearingDepot() {
        return super.getClearingDepot();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "The obtain the full list of places of loading, call the places of discharge(shipping mode).\n" +
                                     "\n" +
                                     "The places of discharge for air is missing.")
    public XMLGregorianCalendar getArrivalAtPlaceOfDischargeDate() {
        return super.getArrivalAtPlaceOfDischargeDate();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "he default will pull from the supplier record selected on the order. If no supplier is specified, the\n" +
                                     "place of discharge will default to the pol specified under the client configuration - order and items setup.\n" +
                                     "\n" +
                                     "The obtain the full list of places of loading, call the places of loading (shipping mode).")
    public String getPlaceOfLoading() {
        return super.getPlaceOfLoading();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "API to get Named Places.")
    public String getNamedPlace() {
        return super.getNamedPlace();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "")
    public String getWarehousingAgent() {
        return super.getWarehousingAgent();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "")
    public String getForeignAgent() {
        return super.getForeignAgent();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "")
    public String getSourcingAgent() {
        return super.getSourcingAgent();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "")
    public String getMerchandisingAgent() {
        return super.getMerchandisingAgent();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "A default can be set based on the supplier selected on the order (call the GET supplier API and get\n" +
                                     "the payment method.")
    public Incoterm getIncoterm() {
        return super.getIncoterm();
    }

    @Override
    @JsonProperty(required = true)
    @JsonPropertyDescription(value = "Call the GET supplier per org API method.")
    public String getSupplier() {
        return super.getSupplier();
    }

    @Override
    @JsonProperty(required = true)
    @JsonPropertyDescription(value = "Call the get Buyers default list.")
    public String getBuyer() {
        return super.getBuyer();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "Maps to Cargo Handover date on TradeSuite.")
    public XMLGregorianCalendar getAvailabilityDate() {
        return super.getAvailabilityDate();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "Maps to shipment date on TradeSuite. TradeSuite will send this field in the API and Tradecloud\n" +
                                     "will calculate the availability date (Cargo Handover Date) and the Required on site date (Cargo delivery date). A new API\n" +
                                     "will be available to return these dates without having to create the order based on the latest shipment date and the lead\n" +
                                     "time tables. (Refer to the Calculate shipping dates API).")
    public XMLGregorianCalendar getLatestShipmentDate() {
        return super.getLatestShipmentDate();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "This field is not used by TradeSuite. The field need to be populated to cost an consignment.\n" +
                                     "Tradecloud will default to the latest shipment date when the order is created.")
    public XMLGregorianCalendar getEarliestShipmentDate() {
        return super.getEarliestShipmentDate();
    }

    @Override
    @JsonProperty(required = false)
    @JsonPropertyDescription(value = "Note: Config exists to not allow duplicate proforma invoice references from the same supplier.\n" +
                                     "(Currently not enforced on Standard Bank config).")
    public String getProformaReference() {
        return super.getProformaReference();
    }

    public String getShipmentReference() {
        return shipmentReference;
    }

    public void setShipmentReference(String shipmentReference) {
        this.shipmentReference = shipmentReference;
    }

    public String getSubShipmentReference() {
        return subShipmentReference;
    }

    public void setSubShipmentReference(String subShipmentReference) {
        this.subShipmentReference = subShipmentReference;
    }

    public List<BasicShipmentInvoiceDTO> getCommercialInvoices() {
        return commercialInvoices;
    }

    public void setCommercialInvoices(List<BasicShipmentInvoiceDTO> commercialInvoices) {
        this.commercialInvoices = commercialInvoices;
    }

    public List<BasicShipmentInvoiceDTO> getServiceProviderInvoices() {
        return serviceProviderInvoices;
    }

    public void setServiceProviderInvoices(List<BasicShipmentInvoiceDTO> serviceProviderInvoices) {
        this.serviceProviderInvoices = serviceProviderInvoices;
    }

    public String getOrderNumber() {
        return orderNumber;
    }

    public void setOrderNumber(String orderNumber) {
        this.orderNumber = orderNumber;
    }

    public String getSupplierName() {
        return supplierName;
    }

    public void setSupplierName(String supplierName) {
        this.supplierName = supplierName;
    }

    public String getOrganisationName() {
        return organisationName;
    }

    public void setOrganisationName(String organisationName) {
        this.organisationName = organisationName;
    }

    public String getStateName() {
        return stateName;
    }

    public void setStateName(String stateName) {
        this.stateName = stateName;
    }

    public List<OrderPlannedSettlementDTO> getSettlementDatePercentageDTOS() {
        return settlementDatePercentageDTOS;
    }

    public void setSettlementDatePercentageDTOS(List<OrderPlannedSettlementDTO> settlementDatePercentageDTOS) {
        this.settlementDatePercentageDTOS = settlementDatePercentageDTOS;
    }

    public boolean isElc() {
        return elc;
    }

    public void setElc(boolean elc) {
        this.elc = elc;
    }

    public Date getLspPaymentDate() {
        return lspPaymentDate;
    }

    public void setLspPaymentDate(Date lspPaymentDate) {
        this.lspPaymentDate = lspPaymentDate;
    }

    public Date getServiceFeePaymentDate() {
        return serviceFeePaymentDate;
    }

    public void setServiceFeePaymentDate(Date serviceFeePaymentDate) {
        this.serviceFeePaymentDate = serviceFeePaymentDate;
    }

    @Override
    public String toString() {
        return reference;

       /* return "OrderDTO{" +
                "datesDTO=" + datesDTO +
                ", state='" + state + '\'' +
                ", cargoWeight=" + cargoWeight +
                ", cargoVolume=" + cargoVolume +
                ", routeType='" + routeType + '\'' +
                ", trackingDTO=" + trackingDTO +
                ", shipmentReference='" + shipmentReference + '\'' +
                ", subShipmentReference='" + subShipmentReference + '\'' +
                ", commercialInvoices=" + commercialInvoices +
                ", serviceProviderInvoices=" + serviceProviderInvoices +
                ", orderNumber='" + orderNumber + '\'' +
                ", supplierName='" + supplierName + '\'' +
                ", organisationName='" + organisationName + '\'' +
                ", stateName='" + stateName + '\'' +
                ", containerQuantity=" + containerQuantity +
                '}';*/
    }

    public AddressDTO getFinalDestinationDeliveryAddress() {
        return finalDestinationDeliveryAddress;
    }

    public void setFinalDestinationDeliveryAddress(AddressDTO finalDestinationDeliveryAddress) {
        this.finalDestinationDeliveryAddress = finalDestinationDeliveryAddress;
    }

    public AddressDTO getCollectionAddressDTO() {
        return collectionAddressDTO;
    }

    public void setCollectionAddressDTO(AddressDTO collectionAddressDTO) {
        this.collectionAddressDTO = collectionAddressDTO;
    }

    public List<StaticDataDTO> getCostingLsp() {
        return costingLsp;
    }

    public void setCostingLsp(List<StaticDataDTO> costingLsp) {
        this.costingLsp = costingLsp;
    }

    public CurrencyExchangeRateDTO getSupplyROE() {
        return supplyROE;
    }

    public void setSupplyROE(CurrencyExchangeRateDTO supplyROE) {
        this.supplyROE = supplyROE;
    }

    public ActivityLogType getLastActivity() {
        return lastActivity;
    }

    public void setLastActivity(ActivityLogType lastActivity) {
        this.lastActivity = lastActivity;
    }

    public VolumeOrWeightSource getTotalVolumeOrWeightSource() {
        return totalVolumeOrWeightSource;
    }

    public void setTotalVolumeOrWeightSource(VolumeOrWeightSource totalVolumeOrWeightSource) {
        this.totalVolumeOrWeightSource = totalVolumeOrWeightSource;
    }

    @Override
    @JsonIgnore
    public List<Costline> getCostline() {
        return costline;
    }

    public String getRejectReason() {
        return rejectReason;
    }

    public void setRejectReason(String rejectReason) {
        this.rejectReason = rejectReason;
    }

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public Date getEstimatedArrivalDate() {
        return estimatedArrivalDate;
    }

    public void setEstimatedArrivalDate(Date estimatedArrivalDate) {
        this.estimatedArrivalDate = estimatedArrivalDate;
    }
}