use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CuRequisitionDocument method isB2BTotalAmountForAutoPO.
protected boolean isB2BTotalAmountForAutoPO() {
boolean returnValue = false;
ParameterService parameterService = SpringContext.getBean(ParameterService.class);
String autoPOAmountString = new String(parameterService.getParameterValueAsString(RequisitionDocument.class, CUPurapParameterConstants.B2B_TOTAL_AMOUNT_FOR_AUTO_PO));
KualiDecimal autoPOAmount = new KualiDecimal(autoPOAmountString);
// KFSPTS-1625
String routedBy = getRoutedByPrincipalId();
if (StringUtils.isBlank(routedBy)) {
routedBy = this.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
}
if (KimApiServiceLocator.getPermissionService().hasPermission(routedBy, CUKFSConstants.ParameterNamespaces.PURCHASING, CUPurapConstants.B2B_HIGHER_LIMIT_PERMISSION)) {
String paramVal = parameterService.getParameterValueAsString(RequisitionDocument.class, CUPurapParameterConstants.B2B_TOTAL_AMOUNT_FOR_SUPER_USER_AUTO_PO);
if (StringUtils.isNotBlank(paramVal)) {
autoPOAmount = new KualiDecimal(paramVal);
}
}
RequisitionDocument document = null;
try {
document = (RequisitionDocument) (SpringContext.getBean(DocumentService.class).getByDocumentHeaderId(this.getDocumentNumber()));
} catch (WorkflowException we) {
}
KualiDecimal totalAmount = document.getFinancialSystemDocumentHeader().getFinancialDocumentTotalAmount();
if (ObjectUtils.isNotNull(autoPOAmount) && ObjectUtils.isNotNull(totalAmount) && (autoPOAmount.compareTo(totalAmount) >= 0)) {
returnValue = true;
} else {
returnValue = false;
}
return returnValue;
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CuRequisitionAction method createReqFromIWantDoc.
/**
* Creates a requisition document based on information from an I Want document.
*
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
@SuppressWarnings("deprecation")
public ActionForward createReqFromIWantDoc(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String iWantDocumentNumber = request.getParameter(KRADConstants.PARAMETER_DOC_ID);
RequisitionForm requisitionForm = (RequisitionForm) form;
IWantDocument iWantDocument = (IWantDocument) getDocumentService().getByDocumentHeaderId(iWantDocumentNumber);
if (iWantDocument == null) {
throw new WorkflowException("Could not find IWantDocument with ID '" + iWantDocumentNumber + "'");
}
// Make sure the user is authorized to create the req in this manner.
TransactionalDocumentPresentationController pControl = (TransactionalDocumentPresentationController) getDocumentHelperService().getDocumentPresentationController(iWantDocument);
TransactionalDocumentAuthorizer authorizer = (TransactionalDocumentAuthorizer) getDocumentHelperService().getDocumentAuthorizer(iWantDocument);
Set<String> iwntEditModes = authorizer.getEditModes(iWantDocument, GlobalVariables.getUserSession().getPerson(), pControl.getEditModes(iWantDocument));
if (!iwntEditModes.contains(CUPurapConstants.IWNT_DOC_CREATE_REQ)) {
throw new AuthorizationException(GlobalVariables.getUserSession().getPrincipalId(), CUPurapConstants.IWNT_DOC_CREATE_REQ, CuRequisitionDocument.class.getSimpleName(), "user is not authorized to create requisitions from IWantDocument '" + iWantDocumentNumber + "'", Collections.<String, Object>emptyMap());
}
// Do not allow the req to be created if the IWNT doc is already associated with another req.
if (iWantDocument != null && (StringUtils.isNotBlank(iWantDocument.getReqsDocId()) || StringUtils.isNotBlank(iWantDocument.getDvDocId()))) {
throw new WorkflowException("Cannot create requisition from IWantDocument '" + iWantDocumentNumber + "' because a DV or Requisition has already been created from that document");
}
IWantDocumentService iWantDocumentService = SpringContext.getBean(IWantDocumentService.class);
createDocument(requisitionForm);
RequisitionDocument requisitionDocument = requisitionForm.getRequisitionDocument();
iWantDocumentService.setUpRequisitionDetailsFromIWantDoc(iWantDocument, requisitionDocument, requisitionForm);
// Set the requisition doc ID reference on the IWantDocument.
iWantDocument.setReqsDocId(requisitionDocument.getDocumentNumber());
SpringContext.getBean(PurapService.class).saveDocumentNoValidation(iWantDocument);
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method createRejectDocument.
@Override
public ElectronicInvoiceRejectDocument createRejectDocument(ElectronicInvoice eInvoice, ElectronicInvoiceOrder electronicInvoiceOrder, ElectronicInvoiceLoad eInvoiceLoad) {
LOG.info("Creating reject document [DUNS=" + eInvoice.getDunsNumber() + ",POID=" + electronicInvoiceOrder.getInvoicePurchaseOrderID() + "]");
ElectronicInvoiceRejectDocument eInvoiceRejectDocument;
try {
eInvoiceRejectDocument = (ElectronicInvoiceRejectDocument) documentService.getNewDocument("EIRT");
eInvoiceRejectDocument.setInvoiceProcessTimestamp(dateTimeService.getCurrentTimestamp());
String rejectdocDesc = generateRejectDocumentDescription(eInvoice, electronicInvoiceOrder);
eInvoiceRejectDocument.getDocumentHeader().setDocumentDescription(rejectdocDesc);
eInvoiceRejectDocument.setDocumentCreationInProgress(true);
eInvoiceRejectDocument.setFileLevelData(eInvoice);
eInvoiceRejectDocument.setInvoiceOrderLevelData(eInvoice, electronicInvoiceOrder);
documentService.saveDocument(eInvoiceRejectDocument);
String noteText = "Invoice file";
attachInvoiceXMLWithRejectDoc(eInvoiceRejectDocument, getInvoiceFile(eInvoice.getFileName()), noteText);
eInvoiceLoad.addInvoiceReject(eInvoiceRejectDocument);
} catch (WorkflowException e) {
throw new RuntimeException(e);
}
LOG.info("Reject document has been created (DocNo=" + eInvoiceRejectDocument.getDocumentNumber() + ")");
emailTextErrorList.append("DUNS Number - " + eInvoice.getDunsNumber() + " " + eInvoice.getVendorName() + ":\n");
emailTextErrorList.append("An e-invoice from file '" + eInvoice.getFileName() + "' has been rejected due to the following error(s):\n");
// get note text max length from DD
int noteTextMaxLength = NOTE_TEXT_DEFAULT_MAX_LENGTH;
Integer noteTextLength = getDataDictionaryService().getAttributeMaxLength(Note.class, KRADConstants.NOTE_TEXT_PROPERTY_NAME);
if (noteTextLength != null) {
noteTextMaxLength = noteTextLength.intValue();
}
// KFSUPGRADE-489/KITI-2643 - Modified to fix bug reported in KFSPTS-292
// Ensure that we don't overflow the maximum size of the note by creating
// separate notes if necessary.
ArrayList<StringBuffer> rejectReasonNotes = new ArrayList<StringBuffer>();
StringBuffer rejectReasonNote = new StringBuffer();
String rejectReason = "";
rejectReasonNote.append("This reject document has been created because of the following reason(s):\n");
int index = 1;
for (ElectronicInvoiceRejectReason reason : eInvoiceRejectDocument.getInvoiceRejectReasons()) {
emailTextErrorList.append(" - " + reason.getInvoiceRejectReasonDescription() + "\n");
emailTextErrorList.append(" - PO " + eInvoiceRejectDocument.getPurchaseOrderIdentifier() + "\n");
emailTextErrorList.append(" - EIRT " + eInvoiceRejectDocument.getDocumentNumber() + "\n");
// addRejectReasonsToNote("Reject Reason " + index + ". " + reason.getInvoiceRejectReasonDescription(), eInvoiceRejectDocument);
rejectReason = " " + index + ". " + reason.getInvoiceRejectReasonDescription() + "\n";
if (rejectReasonNote.length() + rejectReason.length() > noteTextMaxLength) {
rejectReasonNotes.add(rejectReasonNote);
rejectReasonNote = new StringBuffer();
rejectReasonNote.append("Reject document creation reasons continued:\n");
}
rejectReasonNote.append(rejectReason);
index++;
}
rejectReasonNotes.add(rejectReasonNote);
emailTextErrorList.append("\n");
for (StringBuffer noteText : rejectReasonNotes) {
addRejectReasonsToNote(noteText.toString(), eInvoiceRejectDocument);
}
return eInvoiceRejectDocument;
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method createPaymentRequest.
@Override
protected PaymentRequestDocument createPaymentRequest(ElectronicInvoiceOrderHolder orderHolder) {
LOG.info("Creating Payment Request document");
KNSGlobalVariables.getMessageList().clear();
validateInvoiceOrderValidForPREQCreation(orderHolder);
if (LOG.isInfoEnabled()) {
if (orderHolder.isInvoiceRejected()) {
LOG.info("Not possible to convert einvoice details into payment request");
} else {
LOG.info("Payment request document creation validation succeeded");
}
}
if (orderHolder.isInvoiceRejected()) {
return null;
}
PaymentRequestDocument preqDoc = null;
try {
preqDoc = (PaymentRequestDocument) documentService.getNewDocument("PREQ");
} catch (WorkflowException e) {
String extraDescription = "Error=" + e.getMessage();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_WORKLOW_EXCEPTION, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
LOG.error("Error creating Payment request document - " + e.getMessage());
return null;
}
PurchaseOrderDocument poDoc = orderHolder.getPurchaseOrderDocument();
if (poDoc == null) {
throw new RuntimeException("Purchase Order document (POId=" + poDoc.getPurapDocumentIdentifier() + ") does not exist in the system");
}
preqDoc.getDocumentHeader().setDocumentDescription(generatePREQDocumentDescription(poDoc));
try {
preqDoc.updateAndSaveAppDocStatus(PaymentRequestStatuses.APPDOC_IN_PROCESS);
} catch (WorkflowException we) {
throw new RuntimeException("Unable to save route status data for document: " + preqDoc.getDocumentNumber(), we);
}
preqDoc.setInvoiceDate(orderHolder.getInvoiceDate());
preqDoc.setInvoiceNumber(orderHolder.getInvoiceNumber());
preqDoc.setVendorInvoiceAmount(new KualiDecimal(orderHolder.getInvoiceNetAmount()));
preqDoc.setAccountsPayableProcessorIdentifier("E-Invoice");
preqDoc.setVendorCustomerNumber(orderHolder.getCustomerNumber());
preqDoc.setPaymentRequestElectronicInvoiceIndicator(true);
if (orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier() != null) {
preqDoc.setAccountsPayablePurchasingDocumentLinkIdentifier(orderHolder.getAccountsPayablePurchasingDocumentLinkIdentifier());
}
// Copied from PaymentRequestServiceImpl.populatePaymentRequest()
// set bank code to default bank code in the system parameter
// KFSPTS-1891
boolean hasPaymentMethodCode = false;
if (preqDoc instanceof PaymentRequestDocument) {
String vendorPaymentMethodCode = ((VendorDetailExtension) poDoc.getVendorDetail().getExtension()).getDefaultB2BPaymentMethodCode();
if (StringUtils.isNotEmpty(vendorPaymentMethodCode)) {
((CuPaymentRequestDocument) preqDoc).setPaymentMethodCode(vendorPaymentMethodCode);
hasPaymentMethodCode = true;
} else {
((CuPaymentRequestDocument) preqDoc).setPaymentMethodCode(DEFAULT_EINVOICE_PAYMENT_METHOD_CODE);
}
}
Bank defaultBank = null;
if (hasPaymentMethodCode) {
defaultBank = cUPaymentMethodGeneralLedgerPendingEntryService.getBankForPaymentMethod(((CuPaymentRequestDocument) preqDoc).getPaymentMethodCode());
} else {
// default to baseline behavior - extended documents not in use
// Copied from PaymentRequestServiceImpl.populatePaymentRequest()
// set bank code to default bank code in the system parameter
defaultBank = bankService.getDefaultBankByDocType(preqDoc.getClass());
}
if (defaultBank != null) {
preqDoc.setBankCode(defaultBank.getBankCode());
preqDoc.setBank(defaultBank);
}
RequisitionDocument reqDoc = getRequisitionService().getRequisitionById(poDoc.getRequisitionIdentifier());
String reqDocInitiator = reqDoc.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
try {
Person user = KimApiServiceLocator.getPersonService().getPerson(reqDocInitiator);
setProcessingCampus(preqDoc, user.getCampusCode());
} catch (Exception e) {
String extraDescription = "Error setting processing campus code - " + e.getMessage();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
}
HashMap<String, ExpiredOrClosedAccountEntry> expiredOrClosedAccountList = getAccountsPayableService().expiredOrClosedAccountsList(poDoc);
if (expiredOrClosedAccountList == null) {
expiredOrClosedAccountList = new HashMap();
}
if (LOG.isInfoEnabled()) {
LOG.info(expiredOrClosedAccountList.size() + " accounts has been found as Expired or Closed");
}
preqDoc.populatePaymentRequestFromPurchaseOrder(orderHolder.getPurchaseOrderDocument(), expiredOrClosedAccountList);
// need to populate here for ext price. it become per item
// KFSPTS-1719. convert 1st matching inv item that is qty, but po is non-qty
checkQtyInvItemForNoQtyOrder(preqDoc, orderHolder);
populateItemDetails(preqDoc, orderHolder);
// KFSUPGRADE-485, KFSPTS-1719
if (CollectionUtils.isNotEmpty(((CuElectronicInvoiceOrderHolder) orderHolder).getNonMatchItems())) {
for (ElectronicInvoiceItemHolder invItem : ((CuElectronicInvoiceOrderHolder) orderHolder).getNonMatchItems()) {
PurchaseOrderItem item = (PurchaseOrderItem) ObjectUtils.deepCopy((Serializable) orderHolder.getPurchaseOrderDocument().getItems().get(invItem.getInvoiceItemLineNumber() - 1));
item.setItemLineNumber(invItem.getInvoiceItemLineNumber());
item.setItemDescription(((CuElectronicInvoiceItemHolder) invItem).getReferenceDescription());
// this will be populated to reqitem.poitemunitprice
item.setItemUnitPrice(invItem.getInvoiceItemUnitPrice());
PaymentRequestItem paymentRequestItem = new PaymentRequestItem(item, preqDoc, expiredOrClosedAccountList);
((CuPaymentRequestItemExtension) paymentRequestItem.getExtension()).setInvLineNumber(Integer.parseInt(((CuElectronicInvoiceItemHolder) invItem).getInvLineNumber()));
// need following in case inv item is qty item
paymentRequestItem.setItemQuantity(new KualiDecimal(invItem.getInvoiceItemQuantity()));
paymentRequestItem.setItemUnitOfMeasureCode(invItem.getInvoiceItemUnitOfMeasureCode());
paymentRequestItem.setPurchaseOrderItemUnitPrice(invItem.getInvoiceItemUnitPrice());
// if non qty don't need this unit price set, then this need to have a check
if (invItem.getInvoiceItemQuantity() != null && (new KualiDecimal(invItem.getInvoiceItemQuantity())).isPositive()) {
paymentRequestItem.setItemUnitPrice(invItem.getInvoiceItemUnitPrice());
}
paymentRequestItem.setItemCatalogNumber(invItem.getCatalogNumberStripped());
preqDoc.getItems().add(paymentRequestItem);
((CuElectronicInvoiceOrderHolder) orderHolder).setMisMatchItem((CuElectronicInvoiceItemHolder) invItem);
populateItemDetailsForNonMatching(preqDoc, orderHolder);
((CuElectronicInvoiceOrderHolder) orderHolder).setMisMatchItem(null);
}
}
/**
* Validate totals,paydate
*/
// PaymentRequestDocumentRule.processCalculateAccountsPayableBusinessRules
kualiRuleService.applyRules(new AttributedCalculateAccountsPayableEvent(preqDoc));
paymentRequestService.calculatePaymentRequest(preqDoc, true);
processItemsForDiscount(preqDoc, orderHolder);
if (orderHolder.isInvoiceRejected()) {
return null;
}
paymentRequestService.calculatePaymentRequest(preqDoc, false);
/**
* PaymentRequestReview
*/
// PaymentRequestDocumentRule.processRouteDocumentBusinessRules
kualiRuleService.applyRules(new AttributedPaymentRequestForEInvoiceEvent(preqDoc));
if (GlobalVariables.getMessageMap().hasErrors()) {
if (LOG.isInfoEnabled()) {
LOG.info("***************Error in rules processing - " + GlobalVariables.getMessageMap());
}
Map<String, AutoPopulatingList<ErrorMessage>> errorMessages = GlobalVariables.getMessageMap().getErrorMessages();
String errors = errorMessages.toString();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, errors, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
}
if (KNSGlobalVariables.getMessageList().size() > 0) {
if (LOG.isInfoEnabled()) {
LOG.info("Payment request contains " + KNSGlobalVariables.getMessageList().size() + " warning message(s)");
for (int i = 0; i < KNSGlobalVariables.getMessageList().size(); i++) {
LOG.info("Warning " + i + " - " + KNSGlobalVariables.getMessageList().get(i));
}
}
}
addShipToNotes(preqDoc, orderHolder);
try {
// KFSUPGRADE-490: Do save-only operations for just non-EIRT-generated PREQs.
if (orderHolder.isRejectDocumentHolder()) {
documentService.routeDocument(preqDoc, null, null);
} else {
documentService.saveDocument(preqDoc, DocumentSystemSaveEvent.class);
}
} catch (WorkflowException e) {
e.printStackTrace();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_FAILURE, e.getMessage(), orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
} catch (ValidationException e) {
String extraDescription = GlobalVariables.getMessageMap().toString();
ElectronicInvoiceRejectReason rejectReason = matchingService.createRejectReason(PurapConstants.ElectronicInvoice.PREQ_ROUTING_VALIDATION_ERROR, extraDescription, orderHolder.getFileName());
orderHolder.addInvoiceOrderRejectReason(rejectReason);
return null;
}
return preqDoc;
}
use of org.kuali.kfs.kew.api.exception.WorkflowException in project cu-kfs by CU-CommunityApps.
the class CuElectronicInvoiceHelperServiceImpl method routePREQDocuments.
/**
* @return
*/
protected boolean routePREQDocuments() {
Collection<String> documentIdList = null;
try {
documentIdList = retrieveDocumentsToRoute(KewApiConstants.ROUTE_HEADER_SAVED_CD, PaymentRequestDocument.class);
} catch (WorkflowException e1) {
LOG.error("Error retrieving preq documents for routing: " + e1.getMessage(), e1);
throw new RuntimeException(e1.getMessage(), e1);
} catch (RemoteException re) {
LOG.error("Error retrieving preq documents for routing: " + re.getMessage(), re);
throw new RuntimeException(re.getMessage(), re);
}
// Collections.reverse(documentIdList);
LOG.info("PREQs to Route: " + documentIdList);
for (String preqDocumentId : documentIdList) {
try {
LOG.info("Retrieving PREQ document # " + preqDocumentId + ".");
PaymentRequestDocument preqDocument = (PaymentRequestDocument) documentService.getByDocumentHeaderId(preqDocumentId);
LOG.info("Routing PREQ document # " + preqDocumentId + ".");
if (preqDocument.getPaymentRequestElectronicInvoiceIndicator()) {
documentService.prepareWorkflowDocument(preqDocument);
LOG.info("PREQ document # " + preqDocumentId + " prepared for workflow.");
// calling workflow service to bypass business rule checks
workflowDocumentService.route(preqDocument.getDocumentHeader().getWorkflowDocument(), "Routed by electronic invoice batch job", null);
LOG.info("PREQ document # " + preqDocumentId + " routed.");
}
} catch (WorkflowException e) {
LOG.error("Error routing document # " + preqDocumentId + " " + e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}
return true;
}
Aggregations