use of com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument 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 com.rsmart.kuali.kfs.fp.document.BatchDisbursementVoucherDocument 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