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();
}
}
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;
}
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;
}
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);
}
}
}
}
}
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;
}
Aggregations