Search in sources :

Example 1 with DeleteAccountingLineEvent

use of org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent in project cu-kfs by CU-CommunityApps.

the class KualiAccountingDocumentActionBase method deleteSourceLine.

/**
 * This method will remove a SourceAccountingLine from a FinancialDocument. This assumes that the user presses the delete button
 * for a specific accounting line on the document and that the document is represented by a FinancialDocumentFormBase.
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
public ActionForward deleteSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    KualiAccountingDocumentFormBase financialDocumentForm = (KualiAccountingDocumentFormBase) form;
    int deleteIndex = getLineToDelete(request);
    String errorPath = KFSConstants.DOCUMENT_PROPERTY_NAME + "." + KFSConstants.EXISTING_SOURCE_ACCT_LINE_PROPERTY_NAME + "[" + deleteIndex + "]";
    boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new DeleteAccountingLineEvent(errorPath, financialDocumentForm.getDocument(), ((AccountingDocument) financialDocumentForm.getDocument()).getSourceAccountingLine(deleteIndex), false));
    // if the rule evaluation passed, let's delete it
    if (rulePassed) {
        deleteAccountingLine(true, financialDocumentForm, deleteIndex);
    } else {
        String[] errorParams = new String[] { "source", Integer.toString(deleteIndex + 1) };
        GlobalVariables.getMessageMap().putError(errorPath, KFSKeyConstants.ERROR_ACCOUNTINGLINE_DELETERULE_INVALIDACCOUNT, errorParams);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) DeleteAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument)

Example 2 with DeleteAccountingLineEvent

use of org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent in project cu-kfs by CU-CommunityApps.

the class KualiAccountingDocumentActionBase method deleteTargetLine.

/**
 * This method will remove a TargetAccountingLine from a FinancialDocument. This assumes that the user presses the delete button
 * for a specific accounting line on the document and that the document is represented by a FinancialDocumentFormBase.
 *
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
public ActionForward deleteTargetLine(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    KualiAccountingDocumentFormBase financialDocumentForm = (KualiAccountingDocumentFormBase) form;
    int deleteIndex = getLineToDelete(request);
    String errorPath = KFSConstants.DOCUMENT_PROPERTY_NAME + "." + KFSConstants.EXISTING_TARGET_ACCT_LINE_PROPERTY_NAME + "[" + deleteIndex + "]";
    boolean rulePassed = SpringContext.getBean(KualiRuleService.class).applyRules(new DeleteAccountingLineEvent(errorPath, financialDocumentForm.getDocument(), ((AccountingDocument) financialDocumentForm.getDocument()).getTargetAccountingLine(deleteIndex), false));
    // if the rule evaluation passed, let's delete it
    if (rulePassed) {
        deleteAccountingLine(false, financialDocumentForm, deleteIndex);
    } else {
        String[] errorParams = new String[] { "target", Integer.toString(deleteIndex + 1) };
        GlobalVariables.getMessageMap().putError(errorPath, KFSKeyConstants.ERROR_ACCOUNTINGLINE_DELETERULE_INVALIDACCOUNT, errorParams);
    }
    return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
Also used : KualiRuleService(org.kuali.kfs.krad.service.KualiRuleService) DeleteAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent) AccountingDocument(org.kuali.kfs.sys.document.AccountingDocument)

Example 3 with DeleteAccountingLineEvent

use of org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent in project cu-kfs by CU-CommunityApps.

the class PurchasingAccountsPayableDocumentBase method generateEvents.

// KFSUPGRADE-503 copied from AccountingDocumentBase and change
protected List generateEvents(List persistedLines, List currentLines, String errorPathPrefix, TransactionalDocument document) {
    List addEvents = new ArrayList();
    List updateEvents = new ArrayList();
    List reviewEvents = new ArrayList();
    List deleteEvents = new ArrayList();
    errorPathPrefix = KFSConstants.DOCUMENT_PROPERTY_NAME + ".item[";
    // 
    // generate events
    Map persistedLineMap = buildAccountingLineMap(persistedLines);
    // (iterate through current lines to detect additions and updates, removing affected lines from persistedLineMap as we go
    // so deletions can be detected by looking at whatever remains in persistedLineMap)
    int index = 0;
    for (Iterator i = currentLines.iterator(); i.hasNext(); index++) {
        // String indexedErrorPathPrefix = errorPathPrefix + "[" + index + "]";
        AccountingLine currentLine = (AccountingLine) i.next();
        Integer key = currentLine.getSequenceNumber();
        String indexedErrorPathPrefix = getIndexedErrorPathPrefix(errorPathPrefix, currentLine);
        AccountingLine persistedLine = (AccountingLine) persistedLineMap.get(key);
        // if line is both current and persisted...
        if (persistedLine != null) {
            // ...check for updates
            if (!currentLine.isLike(persistedLine)) {
                UpdateAccountingLineEvent updateEvent = new UpdateAccountingLineEvent(indexedErrorPathPrefix, document, persistedLine, currentLine);
                updateEvents.add(updateEvent);
            } else {
                ReviewAccountingLineEvent reviewEvent = new ReviewAccountingLineEvent(indexedErrorPathPrefix, document, currentLine);
                reviewEvents.add(reviewEvent);
            }
            persistedLineMap.remove(key);
        } else {
            // it must be a new addition
            AddAccountingLineEvent addEvent = new AddAccountingLineEvent(indexedErrorPathPrefix, document, currentLine);
            addEvents.add(addEvent);
        }
    }
    // detect deletions
    for (Iterator i = persistedLineMap.entrySet().iterator(); i.hasNext(); ) {
        // the deleted line is not displayed on the page, so associate the error with the whole group
        String groupErrorPathPrefix = errorPathPrefix + KFSConstants.ACCOUNTING_LINE_GROUP_SUFFIX;
        Map.Entry e = (Map.Entry) i.next();
        AccountingLine persistedLine = (AccountingLine) e.getValue();
        DeleteAccountingLineEvent deleteEvent = new DeleteAccountingLineEvent(groupErrorPathPrefix, document, persistedLine, true);
        deleteEvents.add(deleteEvent);
    }
    // 
    // merge the lists
    List lineEvents = new ArrayList();
    lineEvents.addAll(reviewEvents);
    lineEvents.addAll(updateEvents);
    lineEvents.addAll(addEvents);
    lineEvents.addAll(deleteEvents);
    return lineEvents;
}
Also used : SourceAccountingLine(org.kuali.kfs.sys.businessobject.SourceAccountingLine) AccountingLine(org.kuali.kfs.sys.businessobject.AccountingLine) PurApAccountingLine(org.kuali.kfs.module.purap.businessobject.PurApAccountingLine) ArrayList(java.util.ArrayList) UpdateAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.UpdateAccountingLineEvent) ReviewAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.ReviewAccountingLineEvent) AddAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent) GeneralLedgerPendingEntry(org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry) Iterator(java.util.Iterator) DeleteAccountingLineEvent(org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DeleteAccountingLineEvent (org.kuali.kfs.sys.document.validation.event.DeleteAccountingLineEvent)3 KualiRuleService (org.kuali.kfs.krad.service.KualiRuleService)2 AccountingDocument (org.kuali.kfs.sys.document.AccountingDocument)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 PurApAccountingLine (org.kuali.kfs.module.purap.businessobject.PurApAccountingLine)1 AccountingLine (org.kuali.kfs.sys.businessobject.AccountingLine)1 GeneralLedgerPendingEntry (org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry)1 SourceAccountingLine (org.kuali.kfs.sys.businessobject.SourceAccountingLine)1 AddAccountingLineEvent (org.kuali.kfs.sys.document.validation.event.AddAccountingLineEvent)1 ReviewAccountingLineEvent (org.kuali.kfs.sys.document.validation.event.ReviewAccountingLineEvent)1 UpdateAccountingLineEvent (org.kuali.kfs.sys.document.validation.event.UpdateAccountingLineEvent)1