Search in sources :

Example 1 with AccountingDocument

use of org.kuali.kfs.sys.document.AccountingDocument in project cu-kfs by CU-CommunityApps.

the class CreateAccountingDocumentServiceImpl method processAccountingDocumentEntryFromXml.

protected void processAccountingDocumentEntryFromXml(AccountingXmlDocumentEntry accountingXmlDocument, CreateAccountingDocumentReportItem reportItem) {
    GlobalVariables.getMessageMap().clearErrorMessages();
    CreateAccountingDocumentReportItemDetail detail = new CreateAccountingDocumentReportItemDetail();
    detail.setIndexNumber(accountingXmlDocument.getIndex().intValue());
    detail.setDocumentType(accountingXmlDocument.getDocumentTypeCode());
    detail.setDocumentDescription(accountingXmlDocument.getDescription());
    detail.setDocumentExplanation(accountingXmlDocument.getExplanation());
    try {
        LOG.info("processAccountingDocumentEntryFromXml: Started processing accounting document of type: " + accountingXmlDocument.getDocumentTypeCode());
        String documentGeneratorBeanName = CuFPConstants.ACCOUNTING_DOCUMENT_GENERATOR_BEAN_PREFIX + accountingXmlDocument.getDocumentTypeCode();
        AccountingDocumentGenerator<? extends AccountingDocument> documentGenerator = findDocumentGenerator(documentGeneratorBeanName);
        AccountingDocument document = documentGenerator.createDocument(this::getNewDocument, accountingXmlDocument);
        document = (AccountingDocument) documentService.routeDocument(document, CuFPConstants.ACCOUNTING_DOCUMENT_XML_ROUTE_ANNOTATION, getAllAdHocRecipients(document));
        LOG.info("processAccountingDocumentEntryFromXml: Finished processing and routing accounting document " + document.getDocumentNumber() + " of type: " + accountingXmlDocument.getDocumentTypeCode());
        detail.setSuccessfullyRouted(true);
        detail.setDocumentNumber(document.getDocumentNumber());
        reportItem.getDocumentsSuccessfullyRouted().add(detail);
    } catch (Exception e) {
        detail.setSuccessfullyRouted(false);
        if (e instanceof ValidationException) {
            String errorMessage = buildValidationErrorMessage((ValidationException) e);
            LOG.error("processAccountingDocumentEntryFromXml: Could not route accounting document - " + errorMessage);
            detail.setErrorMessage(errorMessage);
        } else {
            LOG.error("processAccountingDocumentEntryFromXml: Error processing accounting XML document", e);
            detail.setErrorMessage("Non validation error: " + e.getMessage());
        }
        reportItem.getDocumentsInError().add(detail);
    } finally {
        GlobalVariables.getMessageMap().clearErrorMessages();
    }
}
Also used : ValidationException(org.kuali.kfs.krad.exception.ValidationException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) ValidationException(org.kuali.kfs.krad.exception.ValidationException) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) IOException(java.io.IOException) CreateAccountingDocumentReportItemDetail(edu.cornell.kfs.fp.batch.CreateAccountingDocumentReportItemDetail)

Example 2 with AccountingDocument

use of org.kuali.kfs.sys.document.AccountingDocument in project cu-kfs by CU-CommunityApps.

the class SalaryExpenseTransferAccountingLinesNotEmpty method validate.

/**
 * Validates that the accounting lines in the accounting document are not empty
 * <strong>Expects an accounting document as the first a parameter</strong>
 * @see org.kuali.kfs.validation.Validation#validate(java.lang.Object[])
 */
public boolean validate(AttributedDocumentEvent event) {
    boolean result = true;
    // ensure the employee ids in the source accounting lines are same
    AccountingDocument accountingDocument = (AccountingDocument) documentForValidation;
    if (!hasEmptyAccountingLines(accountingDocument)) {
        result = false;
    }
    return result;
}
Also used : AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument)

Example 3 with AccountingDocument

use of org.kuali.kfs.sys.document.AccountingDocument in project cu-kfs by CU-CommunityApps.

the class CuContractsAndGrantsResponsibilityPlusPayPeriodRoleTypeServiceImpl method documentIsWithinPayPeriodLimit.

/*
     * Helper method for determining if the difference between the document's create date period and
     * the earliest account pay period is within the given limit. Assumed to be within limit unless
     * proven otherwise.
     */
private boolean documentIsWithinPayPeriodLimit(String documentNumber, int limit) {
    boolean withinLimit = true;
    AccountingDocument document;
    // Get the document, which is expected to be an accounting one.
    try {
        document = (AccountingDocument) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(documentNumber);
    } catch (WorkflowException e) {
        document = null;
    } catch (ClassCastException e) {
        document = null;
    }
    // Skip non-existent or non-retrievable documents, and have them default to within-limit routing.
    if (document == null) {
        return true;
    }
    // Make sure source/target lines containing the extra labor-ledger-related data actually exist on the document.
    boolean hasLLSourceLine = document.getSourceAccountingLineClass() != null && CollectionUtils.isNotEmpty(document.getSourceAccountingLines()) && LaborLedgerExpenseTransferAccountingLine.class.isAssignableFrom(document.getSourceAccountingLineClass());
    boolean hasLLTargetLine = document.getTargetAccountingLineClass() != null && CollectionUtils.isNotEmpty(document.getTargetAccountingLines()) && LaborLedgerExpenseTransferAccountingLine.class.isAssignableFrom(document.getTargetAccountingLineClass());
    if (hasLLSourceLine || hasLLTargetLine) {
        // Locate the earliest source/target line.
        LaborLedgerExpenseTransferAccountingLine earliestLine = null;
        if (hasLLSourceLine) {
            earliestLine = findEarliestPayPeriodAccountingLine(document.getSourceAccountingLines());
        }
        if (hasLLTargetLine) {
            if (earliestLine != null) {
                LaborLedgerExpenseTransferAccountingLine earliestTargetLine = findEarliestPayPeriodAccountingLine(document.getTargetAccountingLines());
                earliestLine = (earliestTargetLine == null) ? earliestLine : findEarliestPayPeriodAccountingLine(Arrays.asList(earliestLine, earliestTargetLine));
            } else {
                earliestLine = findEarliestPayPeriodAccountingLine(document.getTargetAccountingLines());
            }
        }
        // If an earliest line was found, then proceed with the within-limit determination.
        if (earliestLine != null) {
            // Prepare helper constants.
            final int NUM_MONTHS = 12;
            final int FY_OFFSET = 6;
            // Get the creation date, and calculate its corresponding fiscal year and pay period.
            DateTime dateCreated = document.getDocumentHeader().getWorkflowDocument().getDateCreated();
            int dateCreatedFiscalYear;
            int dateCreatedPayPeriod = dateCreated.getMonthOfYear() + FY_OFFSET;
            if (dateCreatedPayPeriod > NUM_MONTHS) {
                dateCreatedPayPeriod -= NUM_MONTHS;
            }
            dateCreatedFiscalYear = dateCreated.getYear() + ((dateCreatedPayPeriod <= FY_OFFSET) ? 1 : 0);
            // Determine difference between the pay period the doc was created in and the earliest impacted source/target account's pay period.
            int payPeriodDifference = ((dateCreatedFiscalYear - earliestLine.getPayrollEndDateFiscalYear().intValue()) * NUM_MONTHS) + dateCreatedPayPeriod - Integer.parseInt(earliestLine.getPayrollEndDateFiscalPeriodCode());
            // Set flag based on whether the difference is within the limit for standard Award node routing.
            withinLimit = payPeriodDifference <= limit;
        }
    }
    return withinLimit;
}
Also used : LaborLedgerExpenseTransferAccountingLine(org.kuali.kfs.integration.ld.LaborLedgerExpenseTransferAccountingLine) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService) DateTime(org.joda.time.DateTime)

Example 4 with AccountingDocument

use of org.kuali.kfs.sys.document.AccountingDocument in project cu-kfs by CU-CommunityApps.

the class CUFinancialSystemDocumentServiceImpl method checkAccountingLinesForChanges.

/**
 *  new == null, old == null : no change; line deleted previously.
 *  new == blah, old == blah : no change
 *  new == blah, old == meh : changed
 *  new == null, old == blah : deleted
 *  new == blah, old == null : added
 * @throws WorkflowException
 *
 * @see org.kuali.kfs.sys.document.service.FinancialSystemDocumentService#checkAccountingLinesForChanges(org.kuali.kfs.sys.document.AccountingDocument)
 */
public void checkAccountingLinesForChanges(AccountingDocument accountingDocument) {
    DocumentService docService = SpringContext.getBean(DocumentService.class);
    AccountingDocument savedDoc = null;
    try {
        savedDoc = (AccountingDocument) docService.getByDocumentHeaderId(accountingDocument.getDocumentNumber());
    } catch (WorkflowException we) {
        LOG.error("Unable to retrieve document number " + accountingDocument.getDocumentNumber() + " to evaluate accounting line changes");
    }
    if (savedDoc == null) {
        return;
    }
    if (!accountingDocument.getSourceAccountingLines().isEmpty()) {
        Map<Integer, AccountingLine> newSourceLines = buildAccountingLineMap(accountingDocument.getSourceAccountingLines());
        Map<Integer, AccountingLine> savedSourceLines = buildAccountingLineMap(savedDoc.getSourceAccountingLines());
        if (newSourceLines.isEmpty())
            return;
        int maxSourceKey = findMinOrMaxKeyValue(newSourceLines, savedSourceLines, false);
        int minSourceKey = findMinOrMaxKeyValue(newSourceLines, savedSourceLines, true);
        for (int i = minSourceKey; i < maxSourceKey + 1; i++) {
            AccountingLine newLine = newSourceLines.get(i);
            AccountingLine oldLine = savedSourceLines.get(i);
            if (!compareTo(newLine, oldLine)) {
                String diff = buildLineChangedNoteText(newLine, oldLine);
                if (StringUtils.isNotBlank(diff)) {
                    writeNote(accountingDocument, diff);
                }
            }
        }
    }
    if (!accountingDocument.getTargetAccountingLines().isEmpty()) {
        Map<Integer, AccountingLine> newTargetLines = buildAccountingLineMap(accountingDocument.getTargetAccountingLines());
        Map<Integer, AccountingLine> savedTargetLines = buildAccountingLineMap(savedDoc.getTargetAccountingLines());
        if (newTargetLines.isEmpty())
            return;
        int maxTargetKey = findMinOrMaxKeyValue(newTargetLines, savedTargetLines, false);
        int minTargetKey = findMinOrMaxKeyValue(newTargetLines, savedTargetLines, true);
        for (int i = minTargetKey; i < maxTargetKey + 1; i++) {
            AccountingLine newLine = newTargetLines.get(i);
            AccountingLine oldLine = savedTargetLines.get(i);
            if (!compareTo(newLine, oldLine)) {
                String diff = buildLineChangedNoteText(newLine, oldLine);
                if (StringUtils.isNotBlank(diff)) {
                    writeNote(accountingDocument, diff);
                }
            }
        }
    }
}
Also used : AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) DocumentService(org.kuali.kfs.krad.service.DocumentService) CUFinancialSystemDocumentService(edu.cornell.kfs.sys.document.service.CUFinancialSystemDocumentService)

Example 5 with AccountingDocument

use of org.kuali.kfs.sys.document.AccountingDocument in project cu-kfs by CU-CommunityApps.

the class FinancialSystemSearchableAttribute method extractDocumentAttributes.

@Override
public List<DocumentAttribute> extractDocumentAttributes(ExtensionDefinition extensionDefinition, DocumentWithContent documentWithContent) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("extractDocumentAttributes( " + extensionDefinition + ", " + documentWithContent + " )");
    }
    List<DocumentAttribute> searchAttrValues = super.extractDocumentAttributes(extensionDefinition, documentWithContent);
    String docId = documentWithContent.getDocument().getDocumentId();
    DocumentService docService = SpringContext.getBean(DocumentService.class);
    Document doc = null;
    try {
        doc = docService.getByDocumentHeaderIdSessionless(docId);
    } catch (WorkflowException we) {
    }
    if (doc != null) {
        if (doc instanceof AmountTotaling && ((AmountTotaling) doc).getTotalDollarAmount() != null) {
            DocumentAttributeDecimal.Builder searchableAttributeValue = DocumentAttributeDecimal.Builder.create(KFSPropertyConstants.FINANCIAL_DOCUMENT_TOTAL_AMOUNT);
            searchableAttributeValue.setValue(((AmountTotaling) doc).getTotalDollarAmount().bigDecimalValue());
            searchAttrValues.add(searchableAttributeValue.build());
        }
        if (doc instanceof AccountingDocument) {
            AccountingDocument accountingDoc = (AccountingDocument) doc;
            searchAttrValues.addAll(harvestAccountingDocumentSearchableAttributes(accountingDoc));
        }
        boolean indexedLedgerDoc = false;
        if (doc instanceof LaborLedgerPostingDocumentForSearching) {
            LaborLedgerPostingDocumentForSearching LLPostingDoc = (LaborLedgerPostingDocumentForSearching) doc;
            searchAttrValues.addAll(harvestLLPDocumentSearchableAttributes(LLPostingDoc));
            indexedLedgerDoc = true;
        }
        if (doc instanceof GeneralLedgerPostingDocument && !indexedLedgerDoc) {
            GeneralLedgerPostingDocument GLPostingDoc = (GeneralLedgerPostingDocument) doc;
            searchAttrValues.addAll(harvestGLPDocumentSearchableAttributes(GLPostingDoc));
        }
        DocumentHeader docHeader = doc.getDocumentHeader();
        if (ObjectUtils.isNotNull(docHeader) && ObjectUtils.isNotNull(docHeader.getWorkflowDocument()) && CUKFSConstants.GACC_DOCUMENT_TYPE.equalsIgnoreCase(docHeader.getWorkflowDocument().getDocumentTypeName())) {
            for (AccountGlobalDetail detail : ((AccountGlobal) ((AccountGlobalMaintainableImpl) ((FinancialSystemMaintenanceDocument) doc).getNewMaintainableObject()).getBusinessObject()).getAccountGlobalDetails()) {
                if (!StringUtils.isBlank(detail.getAccountNumber())) {
                    DocumentAttributeString.Builder searchableAttributeValue = DocumentAttributeString.Builder.create(KFSPropertyConstants.ACCOUNT_NUMBER);
                    searchableAttributeValue.setValue(detail.getAccountNumber());
                    searchAttrValues.add(searchableAttributeValue.build());
                }
            }
        }
    }
    return searchAttrValues;
}
Also used : WorkflowException(org.kuali.rice.kew.api.exception.WorkflowException) DocumentAttributeDecimal(org.kuali.rice.kew.api.document.attribute.DocumentAttributeDecimal) DocumentAttributeString(org.kuali.rice.kew.api.document.attribute.DocumentAttributeString) Document(org.kuali.kfs.krad.document.Document) GeneralLedgerPostingDocument(org.kuali.kfs.sys.document.GeneralLedgerPostingDocument) FinancialSystemMaintenanceDocument(org.kuali.kfs.sys.document.FinancialSystemMaintenanceDocument) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) DocumentHeader(org.kuali.kfs.krad.bo.DocumentHeader) FinancialSystemDocumentHeader(org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader) DocumentService(org.kuali.kfs.krad.service.DocumentService) LaborLedgerPostingDocumentForSearching(org.kuali.kfs.integration.ld.LaborLedgerPostingDocumentForSearching) FinancialSystemMaintenanceDocument(org.kuali.kfs.sys.document.FinancialSystemMaintenanceDocument) GeneralLedgerPostingDocument(org.kuali.kfs.sys.document.GeneralLedgerPostingDocument) AccountGlobal(org.kuali.kfs.coa.businessobject.AccountGlobal) DocumentAttribute(org.kuali.rice.kew.api.document.attribute.DocumentAttribute) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument) AccountGlobalDetail(org.kuali.kfs.coa.businessobject.AccountGlobalDetail) DocumentAttributeString(org.kuali.rice.kew.api.document.attribute.DocumentAttributeString) AmountTotaling(org.kuali.kfs.sys.document.AmountTotaling)

Aggregations

AccountingDocument (org.kuali.kfs.sys.document.AccountingDocument)22 AccountingLine (org.kuali.kfs.sys.businessobject.AccountingLine)6 ArrayList (java.util.ArrayList)5 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)5 TargetAccountingLine (org.kuali.kfs.sys.businessobject.TargetAccountingLine)5 DocumentService (org.kuali.kfs.krad.service.DocumentService)4 WorkflowException (org.kuali.rice.kew.api.exception.WorkflowException)4 List (java.util.List)3 FinancialSystemDocumentHeader (org.kuali.kfs.sys.businessobject.FinancialSystemDocumentHeader)3 AccountingXmlDocumentEntryFixture (edu.cornell.kfs.fp.batch.xml.fixture.AccountingXmlDocumentEntryFixture)2 IOException (java.io.IOException)2 ActionForward (org.apache.struts.action.ActionForward)2 InternalBillingDocument (org.kuali.kfs.fp.document.InternalBillingDocument)2 Document (org.kuali.kfs.krad.document.Document)2 ValidationException (org.kuali.kfs.krad.exception.ValidationException)2 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)2 PersistenceService (org.kuali.kfs.krad.service.PersistenceService)2 AmountTotaling (org.kuali.kfs.sys.document.AmountTotaling)2 AddAccountingLineEvent (org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent)2 DeleteAccountingLineEvent (org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent)2