Search in sources :

Example 21 with RequisitionDocument

use of org.kuali.kfs.module.purap.document.RequisitionDocument in project cu-kfs by CU-CommunityApps.

the class CuRequisitionAction method createReqFromIWantDoc.

/**
 * Creates a requisition document based on information from an I Want document.
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@SuppressWarnings("deprecation")
public ActionForward createReqFromIWantDoc(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    String iWantDocumentNumber = request.getParameter(KRADConstants.PARAMETER_DOC_ID);
    RequisitionForm requisitionForm = (RequisitionForm) form;
    IWantDocument iWantDocument = (IWantDocument) getDocumentService().getByDocumentHeaderId(iWantDocumentNumber);
    if (iWantDocument == null) {
        throw new WorkflowException("Could not find IWantDocument with ID '" + iWantDocumentNumber + "'");
    }
    // Make sure the user is authorized to create the req in this manner.
    TransactionalDocumentPresentationController pControl = (TransactionalDocumentPresentationController) getDocumentHelperService().getDocumentPresentationController(iWantDocument);
    TransactionalDocumentAuthorizer authorizer = (TransactionalDocumentAuthorizer) getDocumentHelperService().getDocumentAuthorizer(iWantDocument);
    Set<String> iwntEditModes = authorizer.getEditModes(iWantDocument, GlobalVariables.getUserSession().getPerson(), pControl.getEditModes(iWantDocument));
    if (!iwntEditModes.contains(CUPurapConstants.IWNT_DOC_CREATE_REQ)) {
        throw new AuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), CUPurapConstants.IWNT_DOC_CREATE_REQ, CuRequisitionDocument.class.getSimpleName(), "user is not authorized to create requisitions from IWantDocument '" + iWantDocumentNumber + "'", Collections.<String, Object>emptyMap());
    }
    // Do not allow the req to be created if the IWNT doc is already associated with another req.
    if (iWantDocument != null && (StringUtils.isNotBlank(iWantDocument.getReqsDocId()) || StringUtils.isNotBlank(iWantDocument.getDvDocId()))) {
        throw new WorkflowException("Cannot create requisition from IWantDocument '" + iWantDocumentNumber + "' because a DV or Requisition has already been created from that document");
    }
    IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
    createDocument(requisitionForm);
    RequisitionDocument requisitionDocument = requisitionForm.getRequisitionDocument();
    iWantDocumentService.setUpRequisitionDetailsFromIWantDoc(iWantDocument, requisitionDocument, requisitionForm);
    // Set the requisition doc ID reference on the IWantDocument.
    iWantDocument.setReqsDocId(requisitionDocument.getDocumentNumber());
    SpringContext.getBean(PurapService.class).saveDocumentNoValidation(iWantDocument);
    return mapping.findForward(RiceConstants.MAPPING_BASIC);
}
Also used : CuRequisitionDocument(edu.cornell.kfs.module.purap.document.CuRequisitionDocument) RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) CuRequisitionDocument(edu.cornell.kfs.module.purap.document.CuRequisitionDocument) PurapService(org.kuali.kfs.module.purap.document.service.PurapService) AuthorizationException(org.kuali.kfs.krad.exception.AuthorizationException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) RequisitionForm(org.kuali.kfs.module.purap.document.web.struts.RequisitionForm) TransactionalDocumentPresentationController(org.kuali.kfs.kns.document.authorization.TransactionalDocumentPresentationController) TransactionalDocumentAuthorizer(org.kuali.kfs.kns.document.authorization.TransactionalDocumentAuthorizer) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument) IWantDocumentService(edu.cornell.kfs.module.purap.document.service.IWantDocumentService)

Aggregations

RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)21 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)6 KualiDecimal (org.kuali.rice.core.api.util.type.KualiDecimal)6 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)4 PaymentRequestItem (org.kuali.kfs.module.purap.businessobject.PaymentRequestItem)3 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)3 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)2 File (java.io.File)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 DocumentService (org.kuali.kfs.krad.service.DocumentService)2 ElectronicInvoiceLoad (org.kuali.kfs.module.purap.businessobject.ElectronicInvoiceLoad)2 PaymentRequestAccount (org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount)2 RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)2 WorkflowDocument (org.kuali.rice.kew.api.WorkflowDocument)2 CuPaymentRequestItemExtension (edu.cornell.kfs.module.purap.businessobject.CuPaymentRequestItemExtension)1 CuPaymentRequestDocument (edu.cornell.kfs.module.purap.document.CuPaymentRequestDocument)1 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)1