use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CheckReconciliationMaintainableImpl method doRouteStatusChange.
/**
* @see org.kuali.kfs.kns.maintenance.MaintainableImpl#doRouteStatusChange(org.kuali.kfs.kns.bo.DocumentHeader)
*/
public void doRouteStatusChange(DocumentHeader documentHeader) {
WorkflowDocument workflowDocument = documentHeader.getWorkflowDocument();
if (workflowDocument.isProcessed() && !KFSConstants.MAINTENANCE_NEW_ACTION.equalsIgnoreCase(getMaintenanceAction())) {
DocumentService documentService = SpringContext.getBean(DocumentService.class);
MaintenanceDocument document;
try {
document = (MaintenanceDocument) documentService.getByDocumentHeaderId(documentHeader.getDocumentNumber());
CheckReconciliation oldCr = (CheckReconciliation) document.getOldMaintainableObject().getBusinessObject();
CheckReconciliation newCr = (CheckReconciliation) document.getNewMaintainableObject().getBusinessObject();
if (ObjectUtils.isNotNull(oldCr) && !oldCr.getStatus().equalsIgnoreCase(newCr.getStatus())) {
Date currentDate = SpringContext.getBean(DateTimeService.class).getCurrentSqlDate();
newCr.setStatusChangeDate(currentDate);
// KFSUPGRADE-377
if (CRConstants.CANCELLED.equalsIgnoreCase(newCr.getStatus())) {
newCr.setCancelDocHdrId(documentHeader.getDocumentNumber());
}
}
} catch (WorkflowException e) {
throw new RuntimeCacheException(e);
}
}
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CuPendingTransactionServiceImpl method reverseSourceDocumentsEntries.
/**
* Reverses the entries of the source documents
*
* @param paymentDetail
* @param sequenceHelper
*/
protected void reverseSourceDocumentsEntries(PaymentDetail paymentDetail, GeneralLedgerPendingEntrySequenceHelper sequenceHelper) {
// Need to reverse the payment document's GL entries if the check is stopped or cancelled
if (PurapConstants.PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT.equalsIgnoreCase(paymentDetail.getFinancialDocumentTypeCode()) || CUPdpConstants.PdpDocumentTypes.DISBURSEMENT_VOUCHER.equalsIgnoreCase(paymentDetail.getFinancialDocumentTypeCode()) || CUPdpConstants.PdpDocumentTypes.CREDIT_MEMO.equalsIgnoreCase(paymentDetail.getFinancialDocumentTypeCode())) {
try {
String sourceDocumentNumber = paymentDetail.getCustPaymentDocNbr();
try {
Long.valueOf(sourceDocumentNumber);
} catch (NumberFormatException nfe) {
sourceDocumentNumber = null;
}
if (sourceDocumentNumber != null && StringUtils.isNotBlank(sourceDocumentNumber)) {
Document doc = (AccountingDocumentBase) SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(paymentDetail.getCustPaymentDocNbr());
if (ObjectUtils.isNotNull(doc)) {
if (doc instanceof DisbursementVoucherDocument) {
// KFSUPGRADE-775
DisbursementVoucherDocument dv = (DisbursementVoucherDocument) doc;
generateDisbursementVoucherReversalEntries(dv, sequenceHelper);
// end KFSUPGRADE-775
} else if (doc instanceof VendorCreditMemoDocument) {
// KFSPTS-2719
String crCmCancelNote = parameterService.getParameterValueAsString(VendorCreditMemoDocument.class, CUPurapParameterConstants.PURAP_CR_CM_CANCEL_NOTE);
VendorCreditMemoDocument cmDocument = (VendorCreditMemoDocument) doc;
String crCancelMaintDocNbr = getCrCancelMaintenancedocumentNumber(paymentDetail);
crCmCancelNote = crCmCancelNote + crCancelMaintDocNbr;
try {
Note noteObj = documentService.createNoteFromDocument(cmDocument, crCmCancelNote);
cmDocument.addNote(noteObj);
noteService.save(noteObj);
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
// KFSUPGRADE-775
VendorCreditMemoDocument cm = (VendorCreditMemoDocument) doc;
AccountsPayableDocumentSpecificService accountsPayableDocumentSpecificService = cm.getDocumentSpecificService();
accountsPayableDocumentSpecificService.updateStatusByNode("", cm);
// end KFSUPGRADE-775
generateCreditMemoReversalEntries((VendorCreditMemoDocument) doc);
} else if (doc instanceof PaymentRequestDocument) {
// KFSPTS-2719
String crPreqCancelNote = parameterService.getParameterValueAsString(PaymentRequestDocument.class, CUPurapParameterConstants.PURAP_CR_PREQ_CANCEL_NOTE);
PaymentRequestDocument paymentRequest = (PaymentRequestDocument) doc;
String crCancelMaintDocNbr = getCrCancelMaintenancedocumentNumber(paymentDetail);
crPreqCancelNote = crPreqCancelNote + crCancelMaintDocNbr;
try {
Note cancelNote = documentService.createNoteFromDocument(paymentRequest, crPreqCancelNote);
paymentRequest.addNote(cancelNote);
noteService.save(cancelNote);
} catch (Exception e) {
throw new RuntimeException(PurapConstants.REQ_UNABLE_TO_CREATE_NOTE + " " + e);
}
// cancel extracted should not reopen PO
paymentRequest.setReopenPurchaseOrderIndicator(false);
// KFSUPGRADE-775
AccountsPayableDocumentSpecificService accountsPayableDocumentSpecificService = paymentRequest.getDocumentSpecificService();
accountsPayableDocumentSpecificService.updateStatusByNode("", paymentRequest);
// end KFSUPGRADE-775
generatePaymentRequestReversalEntries(paymentRequest);
}
}
}
} catch (WorkflowException we) {
System.out.println("Exception retrieving document " + paymentDetail.getCustPaymentDocNbr());
}
}
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class PaymentSourceExtractionServiceImpl method getListByDocumentStatusCodeCampus.
/**
* This method retrieves a list of disbursement voucher documents that are in the status provided for the campus
* code given.
*
* @param statusCode The status of the disbursement vouchers to be retrieved.
* @param campusCode The campus code that the disbursement vouchers will be associated with.
* @param immediatesOnly only retrieve Disbursement Vouchers marked for immediate payment
* @return A collection of disbursement voucher objects that meet the search criteria given.
*/
protected Collection<DisbursementVoucherDocument> getListByDocumentStatusCodeCampus(String statusCode, String campusCode, boolean immediatesOnly) {
LOG.info("getListByDocumentStatusCodeCampus(statusCode=" + statusCode + ", campusCode=" + campusCode + ", immediatesOnly=" + immediatesOnly + ") started");
Collection<DisbursementVoucherDocument> list = new ArrayList<>();
try {
Collection<DisbursementVoucherDocument> docs = financialSystemDocumentService.findByDocumentHeaderStatusCode(DisbursementVoucherDocument.class, statusCode);
for (DisbursementVoucherDocument element : docs) {
String dvdCampusCode = element.getCampusCode();
if (dvdCampusCode.equals(campusCode) && KFSConstants.PaymentSourceConstants.PAYMENT_METHOD_CHECK.equals(element.getDisbVchrPaymentMethodCode())) {
if (!immediatesOnly || element.isImmediatePaymentIndicator()) {
list.add(element);
}
}
}
} catch (WorkflowException we) {
LOG.error("Could not load Disbursement Voucher Documents with status code = " + statusCode + ": " + we);
throw new RuntimeException(we);
}
return list;
}
use of org.kuali.kfs.kew.api.exception.WorkflowException 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.kew.api.exception.WorkflowException 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);
}
}
}
}
}
Aggregations