use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAdjustmentDocument method generateDocumentGeneralLedgerPendingEntries.
@Override
public boolean generateDocumentGeneralLedgerPendingEntries(final GeneralLedgerPendingEntrySequenceHelper sequenceHelper) {
try {
final Document adjusteeDocument = getDocumentService().getByDocumentHeaderId(adjusteeDocumentNumber);
getPaymentApplicationAdjustmentDocumentService().createPendingEntries(adjusteeDocument, this, getPostingYear(), sequenceHelper).forEach(this::addPendingEntry);
return true;
} catch (final WorkflowException e) {
LOG.error("generateDocumentGeneralLedgerPendingEntries(...) - Failed to generate pending entries", e);
}
return false;
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CashControlDocument method getReferenceFinancialDocument.
public Document getReferenceFinancialDocument() {
DocumentService documentService = SpringContext.getBean(DocumentService.class);
Document document = null;
try {
document = documentService.getByDocumentHeaderId(getReferenceFinancialDocumentNumber());
} catch (WorkflowException we) {
LOG.warn("Unable to retrieve reference financial document: " + getReferenceFinancialDocumentNumber(), we);
}
return document;
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method loadInvoices.
/**
* This method loads the invoices for currently selected customer
*
* @param payAppForm
* @param selectedInvoiceNumber
*/
protected void loadInvoices(PaymentApplicationForm payAppForm, String selectedInvoiceNumber) {
PaymentApplicationDocument payAppDoc = payAppForm.getPaymentApplicationDocument();
AccountsReceivableDocumentHeader arDocHeader = payAppDoc.getAccountsReceivableDocumentHeader();
String currentInvoiceNumber = selectedInvoiceNumber;
// entered against the db, and complain to the user if either is not right.
if (StringUtils.isNotBlank(payAppForm.getSelectedCustomerNumber())) {
Map<String, String> pkMap = new HashMap<>();
pkMap.put(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER, payAppForm.getSelectedCustomerNumber());
int found = getBusinessObjectService().countMatching(Customer.class, pkMap);
if (found == 0) {
addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.ENTERED_INVOICE_CUSTOMER_NUMBER, ArKeyConstants.PaymentApplicationDocumentErrors.ENTERED_INVOICE_CUSTOMER_NUMBER_INVALID);
}
}
boolean validInvoice = this.isValidInvoice(payAppForm);
if (!validInvoice) {
addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.ENTERED_INVOICE_NUMBER, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DOCUMENT_NOT_FINAL);
}
// form with an empty customer number wherever possible.
if (StringUtils.isBlank(payAppForm.getSelectedCustomerNumber())) {
if (StringUtils.isBlank(arDocHeader.getCustomerNumber())) {
if (payAppDoc.hasCashControlDetail()) {
payAppForm.setSelectedCustomerNumber(payAppDoc.getCashControlDetail().getCustomerNumber());
arDocHeader.setCustomerNumber(payAppDoc.getCashControlDetail().getCustomerNumber());
}
} else {
payAppForm.setSelectedCustomerNumber(arDocHeader.getCustomerNumber());
}
} else {
arDocHeader.setCustomerNumber(payAppForm.getSelectedCustomerNumber());
}
String customerNumber = payAppForm.getSelectedCustomerNumber();
// Invoice number entered, but no customer number entered
if (StringUtils.isBlank(customerNumber) && StringUtils.isNotBlank(currentInvoiceNumber) && validInvoice) {
Customer customer = getCustomerInvoiceDocumentService().getCustomerByInvoiceDocumentNumber(currentInvoiceNumber);
customerNumber = customer.getCustomerNumber();
payAppDoc.getAccountsReceivableDocumentHeader().setCustomerNumber(customerNumber);
}
// load up the control docs and non-applied holdings for non-cash-control payapps
if (StringUtils.isNotBlank(customerNumber)) {
if (!payAppDoc.hasCashControlDocument()) {
List<PaymentApplicationDocument> nonAppliedControlDocs = new ArrayList<>();
List<NonAppliedHolding> nonAppliedControlHoldings = new ArrayList<>();
// documents and nonapplied holdings that this doc paid against.
if (payAppDoc.isFinal()) {
nonAppliedControlDocs.addAll(payAppDoc.getPaymentApplicationDocumentsUsedAsControlDocuments());
nonAppliedControlHoldings.addAll(payAppDoc.getNonAppliedHoldingsUsedAsControls());
} else {
// otherwise, we pull all available non-zero non-applied holdings for
// this customer, and make the associated docs and non-applied holdings available
// retrieve the set of available non-applied holdings for this customer
nonAppliedControlHoldings.addAll(getNonAppliedHoldingService().getNonAppliedHoldingsForCustomer(customerNumber));
// get the parent list of payapp documents that they come from
List<String> controlDocNumbers = new ArrayList<>();
for (NonAppliedHolding nonAppliedHolding : nonAppliedControlHoldings) {
if (nonAppliedHolding.getAvailableUnappliedAmount().isPositive() && !controlDocNumbers.contains(nonAppliedHolding.getReferenceFinancialDocumentNumber())) {
controlDocNumbers.add(nonAppliedHolding.getReferenceFinancialDocumentNumber());
}
}
// only try to retrieve docs if we have any to retrieve
if (!controlDocNumbers.isEmpty()) {
try {
List<Document> docs = getDocumentService().getDocumentsByListOfDocumentHeaderIds(PaymentApplicationDocument.class, controlDocNumbers);
for (Document doc : docs) {
nonAppliedControlDocs.add((PaymentApplicationDocument) doc);
}
} catch (WorkflowException e) {
throw new RuntimeException("A runtimeException was thrown when trying to retrieve a list " + "of documents.", e);
}
}
}
// set the form vars from what we've loaded up here
payAppForm.setNonAppliedControlDocs(nonAppliedControlDocs);
payAppForm.setNonAppliedControlHoldings(nonAppliedControlHoldings);
payAppDoc.setNonAppliedHoldingsForCustomer(new ArrayList<>(nonAppliedControlHoldings));
payAppForm.setNonAppliedControlAllocations(null);
}
}
// reload invoices for the selected customer number
if (StringUtils.isNotBlank(customerNumber)) {
Collection<CustomerInvoiceDocument> openInvoicesForCustomer;
// at this point, we want to show the invoices it paid against, NOT the set of open invoices
if (payAppDoc.isFinal()) {
openInvoicesForCustomer = payAppDoc.getInvoicesPaidAgainst();
} else {
openInvoicesForCustomer = getCustomerInvoiceDocumentService().getOpenInvoiceDocumentsByCustomerNumber(customerNumber);
}
payAppForm.setInvoices(new ArrayList<>(openInvoicesForCustomer));
payAppForm.setupInvoiceWrappers(payAppDoc.getDocumentNumber());
}
// if no invoice number entered than get the first invoice
if (StringUtils.isNotBlank(customerNumber) && StringUtils.isBlank(currentInvoiceNumber)) {
if (payAppForm.getInvoices() == null || payAppForm.getInvoices().isEmpty()) {
currentInvoiceNumber = null;
} else {
currentInvoiceNumber = payAppForm.getInvoices().get(0).getDocumentNumber();
}
}
// load information for the current selected invoice
if (StringUtils.isNotBlank(currentInvoiceNumber)) {
payAppForm.setSelectedInvoiceDocumentNumber(currentInvoiceNumber);
payAppForm.setEnteredInvoiceDocumentNumber(currentInvoiceNumber);
}
// Make sure the invoice applies state are up to date
for (PaymentApplicationInvoiceApply invoiceApplication : payAppForm.getInvoiceApplications()) {
updateInvoiceApplication(payAppDoc, invoiceApplication);
}
// clear any NonInvoiced add line information from the form vars
payAppForm.setNonInvoicedAddLine(null);
// load any NonAppliedHolding information into the form vars
if (payAppDoc.getNonAppliedHolding() != null) {
payAppForm.setNonAppliedHoldingCustomerNumber(payAppDoc.getNonAppliedHolding().getCustomerNumber());
payAppForm.setNonAppliedHoldingAmount(payAppDoc.getNonAppliedHolding().getFinancialDocumentLineAmount());
} else {
// clear any NonAppliedHolding information from the form vars if it's empty
payAppForm.setNonAppliedHoldingCustomerNumber(null);
payAppForm.setNonAppliedHoldingAmount(null);
}
// Presort this list to not reload in the jsp - https://jira.kuali.org/browse/KFSCNTRB-1377
payAppForm.setInvoiceApplications(sortInvoiceApplications(payAppForm.getInvoiceApplications()));
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method routeContractsGrantsInvoiceDocuments.
/**
* This method retrieves all the Contracts & Grants Invoice Documents with a status of Saved and routes them to
* the next step in the routing path.
*
* @return True if the routing was performed successfully. A runtime exception will be thrown if any errors occur
* while routing.
*/
@Override
public void routeContractsGrantsInvoiceDocuments() {
final String currentUserPrincipalId = GlobalVariables.getUserSession().getPerson().getPrincipalId();
List<String> documentIdList = retrieveContractsGrantsInvoiceDocumentsToRoute(DocumentStatus.SAVED, currentUserPrincipalId);
if (LOG.isInfoEnabled()) {
LOG.info("CGinvoice to Route: " + documentIdList);
}
for (String cgInvoiceDocId : documentIdList) {
try {
ContractsGrantsInvoiceDocument cgInvoiceDoc = (ContractsGrantsInvoiceDocument) documentService.getByDocumentHeaderId(cgInvoiceDocId);
// To route documents only if the user in the session is same as the initiator.
if (LOG.isInfoEnabled()) {
LOG.info("Routing Contracts & Grants Invoice document # " + cgInvoiceDocId + ".");
}
documentService.prepareWorkflowDocument(cgInvoiceDoc);
// calling workflow service to bypass business rule checks
workflowDocumentService.route(cgInvoiceDoc.getDocumentHeader().getWorkflowDocument(), "", null);
} catch (WorkflowException e) {
LOG.error("Error routing document # " + cgInvoiceDocId + " " + e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method createCGInvoiceDocumentByAwardInfo.
/*
* CU Customization (KFSPTS-23675):
* Added creationProcessType argument and its usage of it.
*/
@Override
public ContractsGrantsInvoiceDocument createCGInvoiceDocumentByAwardInfo(ContractsAndGrantsBillingAward awd, List<ContractsAndGrantsBillingAwardAccount> accounts, String chartOfAccountsCode, String organizationCode, List<ErrorMessage> errorMessages, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType) {
ContractsGrantsInvoiceDocument cgInvoiceDocument = null;
if (ObjectUtils.isNotNull(accounts) && !accounts.isEmpty()) {
if (chartOfAccountsCode != null && organizationCode != null) {
try {
cgInvoiceDocument = (ContractsGrantsInvoiceDocument) documentService.getNewDocument(ContractsGrantsInvoiceDocument.class);
// Set description to the document created.
cgInvoiceDocument.getDocumentHeader().setDocumentDescription(buildDocumentDescription(awd, accounts));
// setup several Default Values for CGInvoice document which extends from Customer Invoice Document
// a) set billing org and chart code
cgInvoiceDocument.setBillByChartOfAccountCode(chartOfAccountsCode);
cgInvoiceDocument.setBilledByOrganizationCode(organizationCode);
// b) set processing org and chart code
List<String> procCodes = getContractsGrantsInvoiceDocumentService().getProcessingFromBillingCodes(chartOfAccountsCode, organizationCode);
AccountsReceivableDocumentHeader accountsReceivableDocumentHeader = new AccountsReceivableDocumentHeader();
accountsReceivableDocumentHeader.setDocumentNumber(cgInvoiceDocument.getDocumentNumber());
// Set processing chart and org codes
if (procCodes != null) {
int procCodesSize = procCodes.size();
// Set processing chart
if (procCodesSize > 0) {
accountsReceivableDocumentHeader.setProcessingChartOfAccountCode(procCodes.get(0));
}
// Set processing org code
if (procCodesSize > 1) {
accountsReceivableDocumentHeader.setProcessingOrganizationCode(procCodes.get(1));
}
}
cgInvoiceDocument.setAccountsReceivableDocumentHeader(accountsReceivableDocumentHeader);
populateInvoiceFromAward(awd, accounts, cgInvoiceDocument, accountDetails, locCreationType, creationProcessType);
contractsGrantsInvoiceDocumentService.createSourceAccountingLines(cgInvoiceDocument, accounts);
if (ObjectUtils.isNotNull(cgInvoiceDocument.getInvoiceGeneralDetail().getAward())) {
contractsGrantsInvoiceDocumentService.updateSuspensionCategoriesOnDocument(cgInvoiceDocument);
}
LOG.info("Created Contracts & Grants Invoice Document " + cgInvoiceDocument.getDocumentNumber());
} catch (WorkflowException ex) {
LOG.error("Error creating cgin documents: " + ex.getMessage(), ex);
throw new RuntimeException("Error creating cgin documents: " + ex.getMessage(), ex);
}
} else {
// if chart of account code or organization code is not available, output the error
final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NO_CHART_OR_ORG, awd.getProposalNumber());
errorMessages.add(errorMessage);
}
}
return cgInvoiceDocument;
}
Aggregations