use of org.kuali.rice.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.rice.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class DebitDeterminerServiceImplTest method test.
public void test() {
CuDisbursementVoucherDocument dv = null;
try {
dv = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
} catch (WorkflowException e) {
throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
}
if (dv != null) {
dv.getDocumentHeader().setDocumentDescription("Test Document Description");
dv.getDocumentHeader().setExplanation("Stuff");
dv.initiateDocument();
VendorDetail vendor = SpringContext.getBean(VendorService.class).getVendorDetail("13366-0");
VendorAddress vendoraddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(vendor.getVendorHeaderGeneratedIdentifier(), vendor.getVendorDetailAssignedIdentifier(), "RM", "");
System.out.println(vendoraddress.getVendorCityName() + "\n");
dv.templateVendor(vendor, vendoraddress);
dv.setPayeeAssigned(true);
dv.getDvPayeeDetail().setDisbVchrPaymentReasonCode("S");
dv.setDisbVchrCheckTotalAmount(new KualiDecimal(86.00));
dv.setDisbVchrPaymentMethodCode("P");
dv.setDisbVchrCheckStubText("check text");
SourceAccountingLine accountingLine = new SourceAccountingLine();
accountingLine.setChartOfAccountsCode("IT");
accountingLine.setAccountNumber("G081040");
accountingLine.setFinancialObjectCode("2045");
accountingLine.setAmount((new KualiDecimal(-14.00)));
accountingLine.setPostingYear(dv.getPostingYear());
accountingLine.setDocumentNumber(dv.getDocumentNumber());
dv.addSourceAccountingLine(accountingLine);
SourceAccountingLine accountingLine2 = new SourceAccountingLine();
accountingLine2.setChartOfAccountsCode("IT");
accountingLine2.setAccountNumber("1453611");
accountingLine2.setFinancialObjectCode("8462");
accountingLine2.setAmount((new KualiDecimal(100.00)));
accountingLine2.setPostingYear(dv.getPostingYear());
accountingLine2.setDocumentNumber(dv.getDocumentNumber());
dv.addSourceAccountingLine(accountingLine2);
try {
documentService.saveDocument(dv);
} catch (WorkflowException e) {
throw new RuntimeException("Error saving new disbursement voucher document: " + e.getMessage(), e);
}
}
List<GeneralLedgerPendingEntrySourceDetail> glpeS = dv.getGeneralLedgerPendingEntrySourceDetails();
GeneralLedgerPendingEntrySourceDetail postable = glpeS.get(0);
System.out.println("GL Detail" + postable.toString() + "\n");
assertFalse(debitDeterminerService.isDebitConsideringNothingPositiveOnly(dv, postable));
}
use of org.kuali.rice.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class ProcurementCardCreateDocumentServiceImpl method createProcurementCardDocument.
/**
* Creates a ProcurementCardDocument from the List of transactions given.
*
* @param transactions List of ProcurementCardTransaction objects to be used for creating the document.
* @return A ProcurementCardDocument populated with the transactions provided.
*/
@SuppressWarnings({ "rawtypes", "deprecation" })
@Override
public ProcurementCardDocument createProcurementCardDocument(List transactions) {
ProcurementCardDocument pcardDocument = null;
dataDictionaryService = SpringContext.getBean(DataDictionaryService.class);
try {
// get new document from doc service
pcardDocument = buildNewProcurementCardDocument();
List<CapitalAssetInformation> capitalAssets = pcardDocument.getCapitalAssetInformation();
for (CapitalAssetInformation capitalAsset : capitalAssets) {
if (ObjectUtils.isNotNull(capitalAsset) && ObjectUtils.isNotNull(capitalAsset.getCapitalAssetInformationDetails())) {
capitalAsset.setDocumentNumber(pcardDocument.getDocumentNumber());
}
}
ProcurementCardTransaction trans = (ProcurementCardTransaction) transactions.get(0);
String errorText = validateTransaction(trans);
createCardHolderRecord(pcardDocument, trans);
// for each transaction, create transaction detail object and then acct lines for the detail
int transactionLineNumber = 1;
KualiDecimal documentTotalAmount = KualiDecimal.ZERO;
ProcurementCardTransaction transaction = null;
for (Iterator iter = transactions.iterator(); iter.hasNext(); ) {
/*ProcurementCardTransaction*/
transaction = (ProcurementCardTransaction) iter.next();
// create transaction detail record with accounting lines
errorText += createTransactionDetailRecord(pcardDocument, transaction, transactionLineNumber);
// update document total
documentTotalAmount = documentTotalAmount.add(transaction.getFinancialDocumentTotalAmount());
transactionLineNumber++;
}
pcardDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(documentTotalAmount);
// pcardDocument.getDocumentHeader().setDocumentDescription("SYSTEM Generated");
transaction = (ProcurementCardTransaction) transactions.get(0);
String cardHolderName = transaction.getCardHolderName();
String vendorName = transaction.getVendorName();
String transactionType = ((ProcurementCardTransactionExtendedAttribute) transaction.getExtension()).getTransactionType();
if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
VENDOR_NAME_MAX_LENGTH = 16;
} else {
VENDOR_NAME_MAX_LENGTH = 19;
}
if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() > VENDOR_NAME_MAX_LENGTH) {
cardHolderName = cardHolderName.substring(0, CARD_HOLDER_MAX_LENGTH);
vendorName = vendorName.substring(0, VENDOR_NAME_MAX_LENGTH);
}
if (cardHolderName.length() > CARD_HOLDER_MAX_LENGTH && vendorName.length() <= VENDOR_NAME_MAX_LENGTH) {
Integer endIndice = 0;
if ((CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length())) > cardHolderName.length()) {
endIndice = cardHolderName.length();
} else {
endIndice = CARD_HOLDER_MAX_LENGTH + (VENDOR_NAME_MAX_LENGTH - vendorName.length());
}
cardHolderName = cardHolderName.substring(0, endIndice);
}
if (vendorName.length() > VENDOR_NAME_MAX_LENGTH && cardHolderName.length() <= CARD_HOLDER_MAX_LENGTH) {
Integer endIndice = 0;
if ((VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length())) > vendorName.length()) {
endIndice = vendorName.length();
} else {
endIndice = VENDOR_NAME_MAX_LENGTH + (CARD_HOLDER_MAX_LENGTH - cardHolderName.length());
}
vendorName = vendorName.substring(0, endIndice);
}
String creditCardNumber = transaction.getTransactionCreditCardNumber();
String lastFour = "";
if (creditCardNumber.length() > CC_LAST_FOUR) {
lastFour = creditCardNumber.substring(creditCardNumber.length() - CC_LAST_FOUR);
}
String docDesc = cardHolderName + "/" + vendorName + "/" + lastFour;
if (transactionType != null && StringUtils.isNotBlank(transactionType)) {
docDesc = transactionType + "/" + cardHolderName + "/" + vendorName + "/" + lastFour;
}
if (docDesc.length() > MAX_DOC_DESC_LENGTH) {
docDesc = docDesc.substring(0, MAX_DOC_DESC_LENGTH);
}
pcardDocument.getDocumentHeader().setDocumentDescription(docDesc);
// Remove duplicate messages from errorText
String[] messages = StringUtils.split(errorText, ".");
for (int i = 0; i < messages.length; i++) {
int countMatches = StringUtils.countMatches(errorText, messages[i]) - 1;
errorText = StringUtils.replace(errorText, messages[i] + ".", "", countMatches);
}
// In case errorText is still too long, truncate it and indicate so.
Integer documentExplanationMaxLength = dataDictionaryService.getAttributeMaxLength(DocumentHeader.class.getName(), KFSPropertyConstants.EXPLANATION);
if (documentExplanationMaxLength != null && errorText.length() > documentExplanationMaxLength.intValue()) {
String truncatedMessage = " ... TRUNCATED.";
errorText = errorText.substring(0, documentExplanationMaxLength - truncatedMessage.length()) + truncatedMessage;
}
pcardDocument.getDocumentHeader().setExplanation(errorText);
} catch (WorkflowException e) {
LOG.error("Error creating pcdo documents: " + e.getMessage(), e);
throw new RuntimeException("Error creating pcdo documents: " + e.getMessage(), e);
}
return pcardDocument;
}
use of org.kuali.rice.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class DisbursementVoucherDocumentBatchServiceImpl method loadDisbursementVouchers.
/**
* @see com.rsmart.kuali.kfs.fp.batch.service.DisbursementVoucherDocumentBatchService#loadDisbursementVouchers(com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchFeed,
* com.rsmart.kuali.kfs.fp.businessobject.DisbursementVoucherBatchStatus, java.lang.String,
* org.kuali.kfs.kns.util.MessageMap)
*/
public void loadDisbursementVouchers(DisbursementVoucherBatchFeed batchFeed, DisbursementVoucherBatchStatus batchStatus, String incomingFileName, MessageMap MessageMap) {
// get new batch record for the load
DisbursementVoucherBatch disbursementVoucherBatch = getNewDisbursementVoucherBatch();
businessObjectService.save(disbursementVoucherBatch);
batchStatus.setUnitCode(batchFeed.getUnitCode());
boolean batchHasErrors = false;
for (BatchDisbursementVoucherDocument batchDisbursementVoucherDocument : batchFeed.getBatchDisbursementVoucherDocuments()) {
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_DV_RECORDS_READ, 1);
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_ACCOUNTING_RECORDS_READ, batchDisbursementVoucherDocument.getSourceAccountingLines().size());
// get defaults for DV chart/org
DisbursementVoucherBatchDefault batchDefault = null;
if (StringUtils.isNotBlank(batchFeed.getUnitCode())) {
batchDefault = getDisbursementVoucherBatchDefault(batchFeed.getUnitCode());
}
MessageMap documentMessageMap = new MessageMap();
batchFeedHelperService.performForceUppercase(DisbursementVoucherDocument.class.getName(), batchDisbursementVoucherDocument);
// create and route doc as system user
// create and route doc as system user
UserSession actualUserSession = GlobalVariables.getUserSession();
GlobalVariables.setUserSession(new UserSession(KFSConstants.SYSTEM_USER));
MessageMap globalMessageMap = GlobalVariables.getMessageMap();
GlobalVariables.setMessageMap(documentMessageMap);
DisbursementVoucherDocument disbursementVoucherDocument = null;
try {
disbursementVoucherDocument = populateDisbursementVoucherDocument(disbursementVoucherBatch, batchDisbursementVoucherDocument, batchDefault, documentMessageMap);
// if the document is valid create GLPEs, Save and Approve
if (documentMessageMap.hasNoErrors()) {
businessObjectService.save(disbursementVoucherDocument.getExtension());
documentService.routeDocument(disbursementVoucherDocument, "", null);
if (documentMessageMap.hasNoErrors()) {
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_DV_RECORDS_WRITTEN, 1);
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_ACCOUNTING_RECORDS_WRITTEN, disbursementVoucherDocument.getSourceAccountingLines().size());
batchStatus.updateStatistics(FPConstants.BatchReportStatisticKeys.NUM_GLPE_RECORDS_WRITTEN, disbursementVoucherDocument.getGeneralLedgerPendingEntries().size());
batchStatus.getBatchDisbursementVoucherDocuments().add(disbursementVoucherDocument);
}
}
} catch (WorkflowException e) {
LOG.error("Unable to route DV: " + e.getMessage());
throw new RuntimeException("Unable to route DV: " + e.getMessage(), e);
} catch (ValidationException e1) {
// will be reported in audit report
} finally {
GlobalVariables.setUserSession(actualUserSession);
GlobalVariables.setMessageMap(globalMessageMap);
}
if (documentMessageMap.hasErrors()) {
batchHasErrors = true;
}
// populate summary line and add to report
DisbursementVoucherBatchSummaryLine batchSummaryLine = populateBatchSummaryLine(disbursementVoucherDocument, documentMessageMap);
batchStatus.getBatchSummaryLines().add(batchSummaryLine);
}
// indicate in global map there were errors (for batch upload screen)
if (batchHasErrors) {
MessageMap.putError(KFSConstants.GLOBAL_ERRORS, FPKeyConstants.ERROR_BATCH_DISBURSEMENT_VOUCHER_ERRORS_NOTIFICATION);
}
batchFeedHelperService.removeDoneFile(incomingFileName);
}
use of org.kuali.rice.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class DisbursementVoucherDocumentBatchServiceImpl method populateDisbursementVoucherDocument.
/**
* Creates a new DV document and populates from the batch instance
*
* @param disbursementVoucherBatch
* @param batchDisbursementVoucherDocument batch dv document to pull values from
* @param batchDefault contains default values to use if value in feed is empty
* @param MessageMap MessageMap for adding encountered errors
* @return DisbursementVoucherDocument created and populated DV document
*/
protected DisbursementVoucherDocument populateDisbursementVoucherDocument(DisbursementVoucherBatch disbursementVoucherBatch, BatchDisbursementVoucherDocument batchDisbursementVoucherDocument, DisbursementVoucherBatchDefault batchDefault, MessageMap MessageMap) {
DisbursementVoucherDocument disbursementVoucherDocument = null;
try {
disbursementVoucherDocument = (DisbursementVoucherDocument) documentService.getNewDocument(DisbursementVoucherDocument.class);
} catch (WorkflowException e) {
LOG.error("Error creating new disbursement voucher document: " + e.getMessage());
throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
}
// populate extension with batch id
DisbursementVoucherDocumentExtension disbursementVoucherDocumentExtension = new DisbursementVoucherDocumentExtension();
disbursementVoucherDocumentExtension.setDocumentNumber(disbursementVoucherDocument.getDocumentNumber());
disbursementVoucherDocumentExtension.setBatchId(disbursementVoucherBatch.getBatchId());
disbursementVoucherDocument.setExtension(disbursementVoucherDocumentExtension);
populateDisbursementVoucherFields(disbursementVoucherDocument, batchDisbursementVoucherDocument, batchDefault, MessageMap);
batchFeedHelperService.loadDocumentAttachments(disbursementVoucherDocument, batchDisbursementVoucherDocument.getAttachments(), attachmentsPath, "", MessageMap);
return disbursementVoucherDocument;
}
Aggregations