Search in sources :

Example 11 with Document

use of org.kuali.kfs.krad.document.Document in project cu-kfs by CU-CommunityApps.

the class AccountingDocumentGeneratorBase method createDocument.

@Override
public T createDocument(Function<Class<? extends Document>, Document> emptyDocumentGenerator, AccountingXmlDocumentEntry documentEntry) {
    Document emptyDocument = emptyDocumentGenerator.apply(getDocumentClass());
    T document = getDocumentClass().cast(emptyDocument);
    populateDocumentHeader(document, documentEntry);
    populateAccountingLines(document, documentEntry);
    populateDocumentNotes(document, documentEntry);
    populateDocumentAttachments(document, documentEntry);
    populateAdHocRecipients(document, documentEntry);
    populateCustomAccountingDocumentData(document, documentEntry);
    return document;
}
Also used : Document(org.kuali.kfs.krad.document.Document) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument)

Example 12 with Document

use of org.kuali.kfs.krad.document.Document in project cu-kfs by CU-CommunityApps.

the class CuBatchExtractServiceImpl method separatePOLines.

/**
 * @see org.kuali.kfs.module.cam.batch.service.BatchExtractService#separatePOLines(java.util.List, java.util.List,
 *      java.util.Collection)
 */
@Override
public void separatePOLines(List<Entry> fpLines, List<Entry> purapLines, Collection<Entry> elgibleGLEntries) {
    for (Entry entry : elgibleGLEntries) {
        if (CamsConstants.PREQ.equals(entry.getFinancialDocumentTypeCode())) {
            purapLines.add(entry);
        } else if (!CamsConstants.CM.equals(entry.getFinancialDocumentTypeCode())) {
            fpLines.add(entry);
        } else if (CamsConstants.CM.equals(entry.getFinancialDocumentTypeCode())) {
            Map<String, String> fieldValues = new HashMap<String, String>();
            fieldValues.put(CamsPropertyConstants.GeneralLedgerEntry.DOCUMENT_NUMBER, entry.getDocumentNumber());
            Class<? extends Document> docClass = dataDictionaryService.getDocumentClassByTypeName(PurapConstants.PurapDocTypeCodes.CREDIT_MEMO_DOCUMENT);
            // check if vendor credit memo, then include as FP line
            Collection<? extends Document> matchingCreditMemos = businessObjectService.findMatching(docClass, fieldValues);
            for (Document document : matchingCreditMemos) {
                VendorCreditMemoDocument creditMemoDocument = (VendorCreditMemoDocument) document;
                if (creditMemoDocument.getPurchaseOrderIdentifier() == null) {
                    fpLines.add(entry);
                } else {
                    purapLines.add(entry);
                }
            }
        }
    }
}
Also used : VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) Entry(org.kuali.kfs.gl.businessobject.Entry) GeneralLedgerEntry(org.kuali.kfs.module.cam.businessobject.GeneralLedgerEntry) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) Document(org.kuali.kfs.krad.document.Document) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) PurchasingAccountsPayableDocument(org.kuali.kfs.module.cam.businessobject.PurchasingAccountsPayableDocument)

Example 13 with Document

use of org.kuali.kfs.krad.document.Document in project cu-kfs by CU-CommunityApps.

the class WebUtils method isFormSessionDocument.

public static boolean isFormSessionDocument(PojoFormBase form) {
    Document document = null;
    if (KualiDocumentFormBase.class.isAssignableFrom(form.getClass())) {
        KualiDocumentFormBase docForm = (KualiDocumentFormBase) form;
        document = docForm.getDocument();
    }
    return isDocumentSession(document, form);
}
Also used : KualiDocumentFormBase(org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase) Document(org.kuali.kfs.krad.document.Document) SessionDocument(org.kuali.kfs.krad.document.SessionDocument)

Example 14 with Document

use of org.kuali.kfs.krad.document.Document in project cu-kfs by CU-CommunityApps.

the class PurchasingActionBase method doDistribution.

/**
 * Distribute accounting line(s) to the item(s). Does not distribute the accounting line(s) to an item if there are already
 * accounting lines associated with that item, if the item is a below-the-line item and has no unit cost, or if the item is
 * inactive. Distribute commodity code to the item(s). Does not distribute the commodity code to an item if the item is not
 * above the line item, is inactive or if the commodity code fails the validation (i.e. inactive commodity code or non existence
 * commodity code).
 *
 * @param mapping An ActionMapping
 * @param form An ActionForm
 * @param request The HttpServletRequest
 * @param response The HttpServletResponse
 * @return An ActionForward
 * @throws Exception
 */
public ActionForward doDistribution(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    PurchasingFormBase purchasingForm = (PurchasingFormBase) form;
    boolean needToDistributeCommodityCode = false;
    if (StringUtils.isNotBlank(purchasingForm.getDistributePurchasingCommodityCode())) {
        // Do the logic for distributing purchasing commodity code to all the items.
        needToDistributeCommodityCode = true;
    }
    boolean needToDistributeAccount = false;
    List<PurApAccountingLine> distributionsourceAccountingLines = purchasingForm.getAccountDistributionsourceAccountingLines();
    if (distributionsourceAccountingLines.size() > 0) {
        needToDistributeAccount = true;
    }
    if (needToDistributeAccount || needToDistributeCommodityCode) {
        PurchasingAccountsPayableDocumentBase purApDocument = (PurchasingAccountsPayableDocumentBase) purchasingForm.getDocument();
        boolean institutionNeedsDistributeAccountValidation = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.VALIDATE_ACCOUNT_DISTRIBUTION_IND);
        boolean foundAccountDistributionError = false;
        boolean foundCommodityCodeDistributionError = false;
        boolean performedAccountDistribution = false;
        boolean performedCommodityCodeDistribution = false;
        // do check for account percents only if distribution method not equal to "P"
        if (!PurapConstants.AccountDistributionMethodCodes.PROPORTIONAL_CODE.equalsIgnoreCase(purApDocument.getAccountDistributionMethod())) {
            // the total percentage in the distribute account list does not equal 100 % then we should display error
            if (institutionNeedsDistributeAccountValidation && needToDistributeAccount && purchasingForm.getTotalPercentageOfAccountDistributionsourceAccountingLines().compareTo(new BigDecimal(100)) != 0) {
                GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.ERROR_DISTRIBUTE_ACCOUNTS_NOT_100_PERCENT);
                foundAccountDistributionError = true;
            }
        }
        // there is a validation error in the accounts to distribute then we should display an error
        if (institutionNeedsDistributeAccountValidation && needToDistributeAccount && (validateDistributeAccounts(purchasingForm.getDocument(), distributionsourceAccountingLines) == false)) {
            foundAccountDistributionError = true;
        }
        for (PurApItem item : ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItems()) {
            boolean itemIsActive = true;
            if (item instanceof PurchaseOrderItem) {
                // if item is PO item... only validate active items
                itemIsActive = ((PurchaseOrderItem) item).isItemActiveIndicator();
            }
            if (needToDistributeCommodityCode) {
                // only the above the line items need the commodity code.
                if (item.getItemType().isLineItemIndicator() && StringUtils.isBlank(((PurchasingItemBase) item).getPurchasingCommodityCode()) && itemIsActive) {
                    // Ideally we should invoke rules to check whether the commodity code is valid (active, not restricted,
                    // not missing, etc), probably somewhere here or invoke the rule class from here.
                    boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new AttributedCommodityCodesForDistributionEvent("", purchasingForm.getDocument(), purchasingForm.getDistributePurchasingCommodityCode()));
                    if (rulePassed) {
                        ((PurchasingItemBase) item).setPurchasingCommodityCode(purchasingForm.getDistributePurchasingCommodityCode());
                        performedCommodityCodeDistribution = true;
                    } else {
                        foundCommodityCodeDistributionError = true;
                    }
                } else if (item.getItemType().isLineItemIndicator() && !StringUtils.isBlank(((PurchasingItemBase) item).getPurchasingCommodityCode()) && itemIsActive) {
                    // could not apply to line, as it wasn't blank
                    foundCommodityCodeDistributionError = true;
                }
            }
            if (needToDistributeAccount && !foundAccountDistributionError) {
                BigDecimal zero = new BigDecimal(0);
                // We should be distributing accounting lines to above the line items all the time;
                // but only to the below the line items when there is a unit cost.
                boolean unitCostNotZeroForBelowLineItems = item.getItemType().isLineItemIndicator() ? true : item.getItemUnitPrice() != null && zero.compareTo(item.getItemUnitPrice()) < 0;
                Document document = ((PurchasingFormBase) form).getDocument();
                Class clazz = document instanceof PurchaseOrderAmendmentDocument ? PurchaseOrderDocument.class : document.getClass();
                List<String> typesNotAllowingEdit = new ArrayList<String>(SpringContext.getBean(ParameterService.class).getParameterValuesAsString(clazz, PurapParameterConstants.PURAP_ITEM_TYPES_RESTRICTING_ACCOUNT_EDIT));
                boolean itemOnExcludeList = (typesNotAllowingEdit == null) ? false : typesNotAllowingEdit.contains(item.getItemTypeCode());
                if (item.getSourceAccountingLines().size() == 0 && unitCostNotZeroForBelowLineItems && !itemOnExcludeList && itemIsActive) {
                    for (PurApAccountingLine purApAccountingLine : distributionsourceAccountingLines) {
                        item.getSourceAccountingLines().add((PurApAccountingLine) ObjectUtils.deepCopy(purApAccountingLine));
                    }
                    performedAccountDistribution = true;
                }
            }
        }
        if ((needToDistributeCommodityCode && performedCommodityCodeDistribution && !foundCommodityCodeDistributionError) || (needToDistributeAccount && performedAccountDistribution && !foundAccountDistributionError)) {
            if (needToDistributeCommodityCode && !foundCommodityCodeDistributionError && performedCommodityCodeDistribution) {
                KNSGlobalVariables.getMessageList().add(PurapKeyConstants.PUR_COMMODITY_CODE_DISTRIBUTED);
                purchasingForm.setDistributePurchasingCommodityCode(null);
            }
            if (needToDistributeAccount && !foundAccountDistributionError && performedAccountDistribution) {
                KNSGlobalVariables.getMessageList().add(PurapKeyConstants.PURAP_GENERAL_ACCOUNTS_DISTRIBUTED);
                distributionsourceAccountingLines.clear();
            }
            purchasingForm.setHideDistributeAccounts(true);
        }
        if ((needToDistributeAccount && !performedAccountDistribution && foundAccountDistributionError)) {
            GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.PURAP_GENERAL_NO_ITEMS_TO_DISTRIBUTE_TO, "account numbers");
        }
        if (needToDistributeCommodityCode && !performedCommodityCodeDistribution && foundCommodityCodeDistributionError) {
            GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_PURCHASING_COMMODITY_CODE, PurapKeyConstants.PURAP_GENERAL_NO_ITEMS_TO_DISTRIBUTE_TO, "commodity codes");
        }
    } else {
        GlobalVariables.getMessageMap().putError(PurapConstants.ACCOUNT_DISTRIBUTION_ERROR_KEY, PurapKeyConstants.PURAP_GENERAL_NO_ACCOUNTS_TO_DISTRIBUTE);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) ParameterService(org.kuali.kfs.coreservice.framework.parameter.ParameterService) PurApItem(org.kuali.kfs.module.purap.businessobject.PurApItem) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) PurchasingAccountsPayableDocumentBase(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocumentBase) KfsParameterConstants(org.kuali.kfs.sys.service.impl.KfsParameterConstants) ArrayList(java.util.ArrayList) PurApArrayList(org.kuali.kfs.module.purap.util.PurApArrayList) WorkflowDocument(org.kuali.rice.kew.api.WorkflowDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) RequisitionDocument(org.kuali.kfs.module.purap.document.RequisitionDocument) MaintenanceDocument(org.kuali.kfs.kns.document.MaintenanceDocument) PurchaseOrderAmendmentDocument(org.kuali.kfs.module.purap.document.PurchaseOrderAmendmentDocument) PurchasingDocument(org.kuali.kfs.module.purap.document.PurchasingDocument) Document(org.kuali.kfs.krad.document.Document) PurchasingAccountsPayableDocument(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument) BigDecimal(java.math.BigDecimal) PurchaseOrderItem(org.kuali.kfs.module.purap.businessobject.PurchaseOrderItem) KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) PurchasingItemBase(org.kuali.kfs.module.purap.businessobject.PurchasingItemBase) AttributedCommodityCodesForDistributionEvent(org.kuali.kfs.module.purap.document.validation.event.AttributedCommodityCodesForDistributionEvent) PurchasingAccountsPayableDocument(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)

Example 15 with Document

use of org.kuali.kfs.krad.document.Document in project cu-kfs by CU-CommunityApps.

the class CuAutoDisapproveDocumentsServiceImpl method processAutoDisapproveDocuments.

@Override
protected boolean processAutoDisapproveDocuments(String principalId, String annotation) {
    boolean success = true;
    Collection<FinancialSystemDocumentHeader> documentList = getDocumentsToDisapprove();
    LOG.info("Total documents to process " + documentList.size());
    String documentHeaderId = null;
    // CU Customization: Filter out documents whose workflow statuses are not actually ENROUTE (see referenced method for details).
    documentList = getDocumentsWithActualWorkflowStatus(documentList, DocumentStatus.ENROUTE);
    for (FinancialSystemDocumentHeader result : documentList) {
        documentHeaderId = result.getDocumentNumber();
        Document document = findDocumentForAutoDisapproval(documentHeaderId);
        if (document != null) {
            if (checkIfDocumentEligibleForAutoDispproval(document.getDocumentHeader())) {
                try {
                    String successMessage = buildSuccessMessage(document);
                    autoDisapprovalYearEndDocument(document, annotation);
                    sendAcknowledgement(document.getDocumentHeader(), annotation);
                    LOG.info("The document with header id: " + documentHeaderId + " is automatically disapproved by this job.");
                    getAutoDisapproveErrorReportWriterService().writeFormattedMessageLine(successMessage);
                } catch (Exception e) {
                    LOG.error("Exception encountered trying to auto disapprove the document " + e.getMessage());
                    String message = ("Exception encountered trying to auto disapprove the document: ").concat(documentHeaderId);
                    getAutoDisapproveErrorReportWriterService().writeFormattedMessageLine(message);
                }
            }
        } else {
            LOG.error("Document is NULL.  It should never have been null");
            String message = ("Error: Document with id: ").concat(documentHeaderId).concat(" - Document is NULL.  It should never have been null");
            getAutoDisapproveErrorReportWriterService().writeFormattedMessageLine(message);
        }
    }
    return success;
}
Also used : FinancialSystemDocumentHeader(org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader) Document(org.kuali.kfs.krad.document.Document) ParseException(java.text.ParseException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) UnknownDocumentTypeException(org.kuali.rice.krad.datadictionary.exception.UnknownDocumentTypeException)

Aggregations

Document (org.kuali.kfs.krad.document.Document)17 MaintenanceDocument (org.kuali.kfs.kns.document.MaintenanceDocument)5 DocumentService (org.kuali.kfs.krad.service.DocumentService)5 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)5 Note (org.kuali.kfs.krad.bo.Note)4 KualiDocumentFormBase (org.kuali.kfs.kns.web.struts.form.KualiDocumentFormBase)3 VendorCreditMemoDocument (org.kuali.kfs.module.purap.document.VendorCreditMemoDocument)3 AccountingDocument (org.kuali.kfs.sys.document.AccountingDocument)3 HashMap (java.util.HashMap)2 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)2 Attachment (org.kuali.kfs.krad.bo.Attachment)2 DocumentHeader (org.kuali.kfs.krad.bo.DocumentHeader)2 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)2 Person (org.kuali.rice.kim.api.identity.Person)2 AccountExtendedAttribute (edu.cornell.kfs.coa.businessobject.AccountExtendedAttribute)1 AppropriationAccount (edu.cornell.kfs.coa.businessobject.AppropriationAccount)1 SubFundProgram (edu.cornell.kfs.coa.businessobject.SubFundProgram)1 AccountReversionTrickleDownInactivationService (edu.cornell.kfs.coa.service.AccountReversionTrickleDownInactivationService)1 CuDisbursementVoucherDocument (edu.cornell.kfs.fp.document.CuDisbursementVoucherDocument)1 CuDistributionOfIncomeAndExpenseDocument (edu.cornell.kfs.fp.document.CuDistributionOfIncomeAndExpenseDocument)1