// TODO Auto-generated method stub
// first populate, then call super
@Override
    public void prepareForSave(KualiDocumentEvent event) {
        // TODO Auto-generated method stub
        // first populate, then call super
        if (event instanceof AttributedContinuePurapEvent) {
            SpringContext.getBean(OleInvoiceService.class).populateInvoice(this);
        }
        if(this.getVendorPaymentTermsCode() != null && this.getVendorPaymentTermsCode().isEmpty()) {
            this.setVendorPaymentTermsCode(null);
        }
        super.prepareForSave(event);
        try {
            if (this.proformaIndicator && !this.immediatePaymentIndicator) {
                this.setImmediatePaymentIndicator(true);
            }
            LOG.debug("###########Inside OleInvoiceDocument " + "repareForSave###########");
            List<OleInvoiceItem> items = new ArrayList<OleInvoiceItem>();
            items = this.getItems();
            Iterator iterator = items.iterator();
            HashMap dataMap = new HashMap();
            String titleId;
            while (iterator.hasNext()) {
                LOG.debug("###########inside prepareForSave item loop###########");
                Object object = iterator.next();
                if (object instanceof OleInvoiceItem) {
                    LOG.debug("###########inside prepareForSave ole payment request item###########");
                    OleInvoiceItem singleItem = (OleInvoiceItem) object;
                    if (StringUtils.isNotBlank(this.invoiceCurrencyType)) {
                        this.setInvoiceCurrencyTypeId(new Long(this.getInvoiceCurrencyType()));
                        String currencyType = SpringContext.getBean(OleInvoiceService.class).getCurrencyType(this.getInvoiceCurrencyType());
                        if (StringUtils.isNotBlank(currencyType)) {
                            if(!currencyType.equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) {
                                if (StringUtils.isNotBlank(this.getInvoiceCurrencyExchangeRate())) {
                                    try {
                                        Double.parseDouble(this.getInvoiceCurrencyExchangeRate());
                                        singleItem.setItemExchangeRate(new KualiDecimal(this.getInvoiceCurrencyExchangeRate()));
                                        singleItem.setExchangeRate(this.getInvoiceCurrencyExchangeRate());
                                    }
                                    catch (NumberFormatException nfe) {
                                        throw new RuntimeException("Invalid Exchange Rate", nfe);
                                    }
                                }   else {
                                    BigDecimal exchangeRate = SpringContext.getBean(OleInvoiceService.class).getExchangeRate(this.getInvoiceCurrencyType()).getExchangeRate();
                                    this.setInvoiceCurrencyExchangeRate(exchangeRate.toString());
                                    singleItem.setItemExchangeRate(new KualiDecimal(exchangeRate));
                                    singleItem.setExchangeRate(exchangeRate.toString());
                                }
                                this.setVendorInvoiceAmount(this.getForeignVendorInvoiceAmount() != null ?
                                        new KualiDecimal(this.getForeignVendorInvoiceAmount().divide(new BigDecimal(singleItem.getExchangeRate()), 4, RoundingMode.HALF_UP)) : null);
                            }
                        }
                    }
                    setItemDescription(singleItem);
                    Map<String, String> copyCriteria = new HashMap<String, String>();
                    if (singleItem.getPaidCopies().size() <= 0 && singleItem.getPoItemIdentifier() != null && (this.getPurapDocumentIdentifier() != null && singleItem.getItemIdentifier() != null)) {
                        copyCriteria.put("poItemId", singleItem.getPoItemIdentifier().toString());
                        List<OleCopy> copies = (List<OleCopy>) getBusinessObjectService().findMatching(OleCopy.class, copyCriteria);
                        if (copies.size() > 0) {
                            List<OLEPaidCopy> paidCopies = new ArrayList<OLEPaidCopy>();
                            for (OleCopy copy : copies) {
                                OLEPaidCopy paidCopy = new OLEPaidCopy();
                                paidCopy.setCopyId(copy.getCopyId());
                                paidCopy.setInvoiceItemId(this.getPurapDocumentIdentifier());
                                paidCopy.setInvoiceIdentifier(singleItem.getItemIdentifier());
                                //copy.getOlePaidCopies().add(paidCopy);
                                paidCopies.add(paidCopy);
                            }
                            getBusinessObjectService().save(paidCopies);
                            singleItem.setPaidCopies(paidCopies);
                        }
                    }
                }
            }
        } catch (Exception e) {
            LOG.error("Exception during prepareForSave() in OleInvoiceDocument", e);
            throw new RuntimeException(e);
        }
    }
@Override
public void prepareForSave(KualiDocumentEvent event) {
// TODO Auto-generated method stub
// first populate, then call super
if (event instanceof AttributedContinuePurapEvent) {
SpringContext.getBean(OleInvoiceService.class).populateInvoice(this);
@Override
public void prepareForSave(KualiDocumentEvent event) {
// TODO Auto-generated method stub
// first populate, then call super
if (event instanceof AttributedContinuePurapEvent) {
SpringContext.getBean(OleInvoiceService.class).populateInvoice(this);
}
if(this.getVendorPaymentTermsCode() != null && this.getVendorPaymentTermsCode().isEmpty()) {
this.setVendorPaymentTermsCode(null);
}
super.prepareForSave(event);
try {
if (this.proformaIndicator && !this.immediatePaymentIndicator) {
this.setImmediatePaymentIndicator(true);
@Override
public void prepareForSave(KualiDocumentEvent event) {
// TODO Auto-generated method stub
// first populate, then call super
if (event instanceof AttributedContinuePurapEvent) {
SpringContext.getBean(OleInvoiceService.class).populateInvoice(this);
}
if(this.getVendorPaymentTermsCode() != null && this.getVendorPaymentTermsCode().isEmpty()) {
this.setVendorPaymentTermsCode(null);
}
super.prepareForSave(event);
try {
if (this.proformaIndicator && !this.immediatePaymentIndicator) {
this.setImmediatePaymentIndicator(true);
}
LOG.debug("###########Inside OleInvoiceDocument " + "repareForSave###########");
List<OleInvoiceItem> items = new ArrayList<OleInvoiceItem>();
items = this.getItems();
Iterator iterator = items.iterator();
HashMap dataMap = new HashMap();
String titleId;
while (iterator.hasNext()) {
LOG.debug("###########inside prepareForSave item loop###########");
Object object = iterator.next();