Search in sources :

Example 1 with AttributedAddPurchasingAccountsPayableItemEvent

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

the class PurchasingActionBase method addItem.

/**
 * Add a new item to the document.
 *
 * @param mapping An ActionMapping
 * @param form An ActionForm
 * @param request The HttpServletRequest
 * @param response The HttpServletResponse
 * @return An ActionForward
 * @throws Exception
 */
@SuppressWarnings("unchecked")
public ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
    PurApItem item = purchasingForm.getNewPurchasingItemLine();
    PurchasingDocument purDocument = (PurchasingDocument) purchasingForm.getDocument();
    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 : KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) AttributedAddPurchasingAccountsPayableItemEvent(org.kuali.kfs.module.purap.document.validation.event.AttributedAddPurchasingAccountsPayableItemEvent) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) PurchasingDocumentBase(org.kuali.kfs.module.purap.document.PurchasingDocumentBase)

Example 2 with AttributedAddPurchasingAccountsPayableItemEvent

use of org.kuali.kfs.module.purap.document.validation.event.AttributedAddPurchasingAccountsPayableItemEvent 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)

Aggregations

KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)2 PurApItem (org.kuali.kfs.module.purap.businessobject.PurApItem)2 PurchasingDocument (org.kuali.kfs.module.purap.document.PurchasingDocument)2 PurchasingDocumentBase (org.kuali.kfs.module.purap.document.PurchasingDocumentBase)2 AttributedAddPurchasingAccountsPayableItemEvent (org.kuali.kfs.module.purap.document.validation.event.AttributedAddPurchasingAccountsPayableItemEvent)2 CuRequisitionDocument (edu.cornell.kfs.module.purap.document.CuRequisitionDocument)1 ParameterService (org.kuali.kfs.coreservice.framework.parameter.ParameterService)1 RequisitionItem (org.kuali.kfs.module.purap.businessobject.RequisitionItem)1 PurchasingFormBase (org.kuali.kfs.module.purap.document.web.struts.PurchasingFormBase)1 RequisitionForm (org.kuali.kfs.module.purap.document.web.struts.RequisitionForm)1 VendorCommodityCode (org.kuali.kfs.vnd.businessobject.VendorCommodityCode)1 VendorDetail (org.kuali.kfs.vnd.businessobject.VendorDetail)1