/*
 * Copyright 2007 The Kuali Foundation.
 * 
 * Licensed under the Educational Community License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.opensource.org/licenses/ecl1.php
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.kfs.module.purap.document.web.struts;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument;
import org.kuali.kfs.module.purap.document.service.PurapService;
import org.kuali.kfs.sys.KFSConstants;
import org.kuali.kfs.sys.context.SpringContext;
import org.kuali.kfs.sys.document.web.struts.FinancialSystemTransactionalDocumentActionBase;
import org.kuali.rice.kns.bo.Note;
import org.kuali.rice.kns.service.DocumentService;
import org.kuali.rice.kns.service.NoteService;
import org.kuali.rice.kns.util.GlobalVariables;

/**
 * Struts Action for Credit Memo document.
 */
public class ElectronicInvoiceRejectAction extends FinancialSystemTransactionalDocumentActionBase {
    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ElectronicInvoiceRejectAction.class);

    public ActionForward startResearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ElectronicInvoiceRejectForm electronicInvoiceRejectForm = (ElectronicInvoiceRejectForm) form;
        ElectronicInvoiceRejectDocument eirDocument = (ElectronicInvoiceRejectDocument) electronicInvoiceRejectForm.getDocument();
        eirDocument.setInvoiceResearchIndicator(true);

         Note noteObj = SpringContext.getBean(DocumentService.class).createNoteFromDocument(eirDocument, "Research started by: " + GlobalVariables.getUserSession().getFinancialSystemUser().getPersonName());
         if (SpringContext.getBean(DocumentService.class).addNoteToDocument(eirDocument, noteObj)) {
             SpringContext.getBean(NoteService.class).save(noteObj);
             SpringContext.getBean(PurapService.class).saveDocumentNoValidation(eirDocument);
         }

        return mapping.findForward(KFSConstants.MAPPING_BASIC);
    }

    public ActionForward completeResearch(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        ElectronicInvoiceRejectForm electronicInvoiceRejectForm = (ElectronicInvoiceRejectForm) form;
        ElectronicInvoiceRejectDocument eirDocument = (ElectronicInvoiceRejectDocument) electronicInvoiceRejectForm.getDocument();
        eirDocument.setInvoiceResearchIndicator(false);

        Note noteObj = SpringContext.getBean(DocumentService.class).createNoteFromDocument(eirDocument, "Research completed by: " + GlobalVariables.getUserSession().getFinancialSystemUser().getPersonName());
        if (SpringContext.getBean(DocumentService.class).addNoteToDocument(eirDocument, noteObj)) {
            SpringContext.getBean(NoteService.class).save(noteObj);
            SpringContext.getBean(PurapService.class).saveDocumentNoValidation(eirDocument);
        }
        return mapping.findForward(KFSConstants.MAPPING_BASIC);

    }
}

@@ -2322,32 +2322,94 @@
 tPersonName());%0A
+         eirDocument.getDocumentHeader().addNote(noteObj);%0A%0A//
          if (Spr
@@ -2485,32 +2485,34 @@
 nt, noteObj)) %7B%0A
+//
              Spr
@@ -2556,32 +2556,34 @@
 .save(noteObj);%0A
+//
              Spr
@@ -2652,32 +2652,34 @@
 n(eirDocument);%0A
+//
          %7D%0A%0A    
@@ -3394,32 +3394,92 @@
 tPersonName());%0A
+        eirDocument.getDocumentHeader().addNote(noteObj);%0A//
         if (Spri
@@ -3562,16 +3562,18 @@
 Obj)) %7B%0A
+//
         
@@ -3632,16 +3632,18 @@
 teObj);%0A
+//
         
@@ -3727,16 +3727,18 @@
 ument);%0A
+//
         

fix to notes for research process