Search in sources :

Example 1 with AccountingDocumentBase

use of org.kuali.kfs.sys.document.AccountingDocumentBase 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());
        }
    }
}
Also used : VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) AccountsPayableDocumentSpecificService(org.kuali.kfs.module.purap.document.service.AccountsPayableDocumentSpecificService) Note(org.kuali.kfs.krad.bo.Note) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) AccountingDocumentBase(org.kuali.kfs.sys.document.AccountingDocumentBase) VendorCreditMemoDocument(org.kuali.kfs.module.purap.document.VendorCreditMemoDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument) Document(org.kuali.kfs.krad.document.Document) PaymentRequestDocument(org.kuali.kfs.module.purap.document.PaymentRequestDocument) PurchaseOrderDocument(org.kuali.kfs.module.purap.document.PurchaseOrderDocument) DisbursementVoucherDocument(org.kuali.kfs.fp.document.DisbursementVoucherDocument) WorkflowException(org.kuali.kfs.kew.api.exception.WorkflowException)

Example 2 with AccountingDocumentBase

use of org.kuali.kfs.sys.document.AccountingDocumentBase in project cu-kfs by CU-CommunityApps.

the class CuAutoDisapproveDocumentsServiceImpl method buildSuccessMessage.

private String buildSuccessMessage(Document document) throws Exception {
    StringBuilder headerBuilder = new StringBuilder();
    headerBuilder.append(document.getDocumentNumber());
    headerBuilder.append(TAB);
    headerBuilder.append(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
    headerBuilder.append(TAB);
    headerBuilder.append(document.getDocumentHeader().getDocumentDescription());
    headerBuilder.append(TAB);
    headerBuilder.append(getPersonService().getPerson(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId()).getPrincipalName());
    headerBuilder.append(TAB);
    headerBuilder.append(getPersonService().getPerson(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId()).getName());
    headerBuilder.append(TAB);
    headerBuilder.append(document.getDocumentHeader().getWorkflowDocument().getDateCreated());
    headerBuilder.append(TAB);
    ConfigurationService k = KRADServiceLocator.getKualiConfigurationService();
    StringBuilder routeBuilder = new StringBuilder();
    String url = k.getPropertyValueAsString("workflow.url");
    routeBuilder.append(url);
    routeBuilder.append("/RouteLog.do?routeHeaderId=");
    routeBuilder.append(document.getDocumentNumber());
    routeBuilder.append(TAB);
    headerBuilder.append(routeBuilder);
    List<ActionTaken> actions;
    // try {
    // actions = KEWServiceLocator.getActionTakenService().findByDocumentId(document.getDocumentHeader().getWorkflowDocument().getDocumentId());
    actions = KEWServiceLocator.getActionTakenService().findByDocumentIdIgnoreCurrentInd(document.getDocumentNumber());
    ActionTaken max = null;
    for (ActionTaken at : actions) {
        if (ObjectUtils.isNull(max)) {
            max = at;
        } else if (at.getActionDate().compareTo(max.getActionDate()) > 0) {
            max = at;
        }
    }
    headerBuilder.append(getPersonService().getPerson(max.getPrincipalId()).getPrincipalName());
    headerBuilder.append(TAB);
    headerBuilder.append(getPersonService().getPerson(max.getPrincipalId()).getName());
    headerBuilder.append(TAB);
    headerBuilder.append(max.getActionDate());
    headerBuilder.append(TAB);
    headerBuilder.append(max.getActionTakenLabel());
    headerBuilder.append(TAB);
    // } catch (WorkflowException e) {
    // e.printStackTrace();
    // }
    String headerString = headerBuilder.toString();
    StringBuilder builder = new StringBuilder();
    if (document instanceof AccountingDocumentBase) {
        for (Object o : ((AccountingDocumentBase) document).getSourceAccountingLines()) {
            SourceAccountingLine sal = (SourceAccountingLine) o;
            builder.append(headerString);
            builder.append(sal.getChartOfAccountsCode());
            builder.append(TAB);
            builder.append(sal.getAccountNumber());
            builder.append(TAB);
            builder.append(sal.getAmount());
            builder.append(TAB);
            builder.append(sal.getAccount().getOrganizationCode());
            builder.append(TAB);
            builder.append(KFSConstants.NEWLINE);
        }
        for (Object o : ((AccountingDocumentBase) document).getTargetAccountingLines()) {
            TargetAccountingLine tal = (TargetAccountingLine) o;
            builder.append(headerString);
            builder.append(tal.getChartOfAccountsCode());
            builder.append(TAB);
            builder.append(tal.getAccountNumber());
            builder.append(TAB);
            builder.append(tal.getAmount());
            builder.append(TAB);
            builder.append(tal.getAccount().getOrganizationCode());
            builder.append(TAB);
            builder.append(KFSConstants.NEWLINE);
        }
    }
    return builder.toString();
}
Also used : TargetAccountingLine(org.kuali.kfs.sys.businessobject.TargetAccountingLine) ConfigurationService(org.kuali.kfs.core.api.config.property.ConfigurationService) AccountingDocumentBase(org.kuali.kfs.sys.document.AccountingDocumentBase) SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) ActionTaken(org.kuali.kfs.kew.actiontaken.ActionTaken)

Example 3 with AccountingDocumentBase

use of org.kuali.kfs.sys.document.AccountingDocumentBase in project cu-kfs by CU-CommunityApps.

the class BudgetAdjustmentDocumentPreRules method doPrompts.

/**
 * Execute pre-rules for BudgetAdjustmentDocument
 *
 * @param document document with pre-rules being applied
 * @return true if pre-rules fire without problem
 */
@Override
public boolean doPrompts(Document document) {
    BudgetAdjustmentDocument budgetDocument = (BudgetAdjustmentDocument) document;
    boolean preRulesOK = askLaborBenefitsGeneration(budgetDocument);
    preRulesOK &= SpringContext.getBean(AccountingDocumentPreRuleService.class).expiredAccountOverrideQuestion((AccountingDocumentBase) document, this);
    return preRulesOK;
}
Also used : AccountingDocumentBase(org.kuali.kfs.sys.document.AccountingDocumentBase) BudgetAdjustmentDocument(org.kuali.kfs.fp.document.BudgetAdjustmentDocument)

Aggregations

AccountingDocumentBase (org.kuali.kfs.sys.document.AccountingDocumentBase)3 ConfigurationService (org.kuali.kfs.core.api.config.property.ConfigurationService)1 BudgetAdjustmentDocument (org.kuali.kfs.fp.document.BudgetAdjustmentDocument)1 DisbursementVoucherDocument (org.kuali.kfs.fp.document.DisbursementVoucherDocument)1 ActionTaken (org.kuali.kfs.kew.actiontaken.ActionTaken)1 WorkflowException (org.kuali.kfs.kew.api.exception.WorkflowException)1 Note (org.kuali.kfs.krad.bo.Note)1 Document (org.kuali.kfs.krad.document.Document)1 PaymentRequestDocument (org.kuali.kfs.module.purap.document.PaymentRequestDocument)1 PurchaseOrderDocument (org.kuali.kfs.module.purap.document.PurchaseOrderDocument)1 VendorCreditMemoDocument (org.kuali.kfs.module.purap.document.VendorCreditMemoDocument)1 AccountsPayableDocumentSpecificService (org.kuali.kfs.module.purap.document.service.AccountsPayableDocumentSpecificService)1 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)1 TargetAccountingLine (org.kuali.kfs.sys.businessobject.TargetAccountingLine)1