Search in sources :

Example 1 with RequisitionForm

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

the class CuRequisitionAction method addItem.

@SuppressWarnings("unchecked")
@Override
public ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
    PurApItem item = purchasingForm.getNewPurchasingItemLine();
    RequisitionItem requisitionItem = (RequisitionItem) item;
    PurchasingDocument purDocument = (PurchasingDocument) purchasingForm.getDocument();
    if (StringUtils.isBlank(requisitionItem.getPurchasingCommodityCode())) {
        boolean commCodeParam = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(CuRequisitionDocument.class, PurapParameterConstants.ENABLE_DEFAULT_VENDOR_COMMODITY_CODE_IND);
        if (commCodeParam) {
            if (purchasingForm instanceof RequisitionForm) {
                CuRequisitionDocument reqs = (CuRequisitionDocument) purchasingForm.getDocument();
                VendorDetail dtl = reqs.getVendorDetail();
                if (ObjectUtils.isNotNull(dtl)) {
                    List<VendorCommodityCode> vcc = dtl.getVendorCommodities();
                    String defaultCommodityCode = "";
                    Iterator<VendorCommodityCode> it = vcc.iterator();
                    while (it.hasNext()) {
                        VendorCommodityCode commodity = it.next();
                        if (commodity.isCommodityDefaultIndicator()) {
                            defaultCommodityCode = commodity.getPurchasingCommodityCode();
                            requisitionItem.setPurchasingCommodityCode(defaultCommodityCode);
                        }
                    }
                }
            }
        }
    }
    boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedAddPurchasingAccountsPayableItemEvent("", purDocument, item));
    if (rulePassed) {
        item = purchasingForm.getAndResetNewPurchasingItemLine();
        purDocument.addItem(item);
        // KFSPTS-985
        if (((PurchasingDocumentBase) (purDocument)).isIntegratedWithFavoriteAccount()) {
            populatePrimaryFavoriteAccount(item.getSourceAccountingLines(), getAccountClassFromNewPurApAccountingLine(purchasingForm));
        }
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : CuRequisitionDocument(edu.cornell.kfs.module.purap.document.CuRequisitionDocument) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) PurchasingDocumentBase(org.kuali.kfs.module.purap.document.PurchasingDocumentBase) VendorDetail(org.kuali.kfs.vnd.businessobject.VendorDetail) KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) RequisitionItem(org.kuali.kfs.module.purap.businessobject.RequisitionItem) PurchasingFormBase(org.kuali.kfs.module.purap.document.web.struts.PurchasingFormBase) AttributedAddPurchasingAccountsPayableItemEvent(org.kuali.kfs.module.purap.document.validation.event.AttributedAddPurchasingAccountsPayableItemEvent) RequisitionForm(org.kuali.kfs.module.purap.document.web.struts.RequisitionForm) VendorCommodityCode(org.kuali.kfs.vnd.businessobject.VendorCommodityCode)

Example 2 with RequisitionForm

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

the class IWantDocumentServiceImplTest method testSetUpRequisitionDetailsFromIWantDoc.

public void testSetUpRequisitionDetailsFromIWantDoc() throws Exception {
    IWantDocument iWantDocument = IWantDocumentFixture.I_WANT_DOC.createIWantDocument();
    RequisitionDocument requisitionDocumentBase = (RequisitionDocument) SpringContext.getBean(DocumentService.class).getNewDocument(RequisitionDocument.class);
    requisitionDocumentBase.initiateDocument();
    RequisitionForm requisitionForm = new RequisitionForm();
    iWantDocumentService.setUpRequisitionDetailsFromIWantDoc(iWantDocument, requisitionDocumentBase, requisitionForm);
    assertEquals(CUPurapConstants.RequisitionSources.IWNT, requisitionDocumentBase.getRequisitionSourceCode());
    assertEquals(iWantDocument.getVendorHeaderGeneratedIdentifier(), requisitionDocumentBase.getVendorHeaderGeneratedIdentifier());
}
Also used : RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) RequisitionForm(org.kuali.kfs.module.purap.document.web.struts.RequisitionForm) IWantDocument(edu.cornell.kfs.module.purap.document.IWantDocument)

Example 3 with RequisitionForm

use of org.kuali.kfs.module.purap.document.web.struts.RequisitionForm 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

RequisitionForm (org.kuali.kfs.module.purap.document.web.struts.RequisitionForm)3 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)2 IWantDocument (edu.cornell.kfs.module.purap.document.IWantDocument)2 RequisitionDocument (org.kuali.kfs.module.purap.document.RequisitionDocument)2 IWantDocumentService (edu.cornell.kfs.module.purap.document.service.IWantDocumentService)1 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)1 TransactionalDocumentAuthorizer (org.kuali.kfs.kns.document.authorization.TransactionalDocumentAuthorizer)1 TransactionalDocumentPresentationController (org.kuali.kfs.kns.document.authorization.TransactionalDocumentPresentationController)1 AuthorizationException (org.kuali.kfs.krad.exception.AuthorizationException)1 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)1 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)1 RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)1 PurchasingDocument (org.kuali.kfs.module.purap.document.PurchasingDocument)1 PurchasingDocumentBase (org.kuali.kfs.module.purap.document.PurchasingDocumentBase)1 PurapService (org.kuali.kfs.module.purap.document.service.PurapService)1 AttributedAddPurchasingAccountsPayableItemEvent (org.kuali.kfs.module.purap.document.validation.event.AttributedAddPurchasingAccountsPayableItemEvent)1 PurchasingFormBase (org.kuali.kfs.module.purap.document.web.struts.PurchasingFormBase)1 VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)1 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)1 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)1