@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) {
       
       
        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());
                               
                                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) { 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()); paidcopies.add(paidcopy); } getbusinessobjectservice().save(paidcopies); singleitem.setpaidcopies(paidcopies); } } } } } catch (exception e) { log.error("exception during prepareforsave() in oleinvoicedocument", e); throw new runtimeexception(e); } }