<commit_before>/*
 * Copyright 2007 The Kuali Foundation.
 * 
 * Licensed under the Educational Community License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.opensource.org/licenses/ecl1.php
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.module.ar.rules;

import org.kuali.core.document.Document;
import org.kuali.core.document.TransactionalDocument;
import org.kuali.core.rule.event.ApproveDocumentEvent;
import org.kuali.core.rules.TransactionalDocumentRuleBase;
import org.kuali.core.util.GlobalVariables;
import org.kuali.kfs.KFSKeyConstants;
import org.kuali.kfs.KFSPropertyConstants;
import org.kuali.module.ar.ArConstants;
import org.kuali.module.ar.bo.CashControlDetail;
import org.kuali.module.ar.document.CashControlDocument;
import org.kuali.module.ar.rule.AddCashControlDetailRule;
import org.kuali.module.ar.service.OrganizationOptionsService;
import org.kuali.module.ar.service.impl.OrganizationOptionsServiceImpl;
import org.kuali.module.chart.bo.ChartUser;
import org.kuali.module.chart.lookup.valuefinder.ValueFinderUtil;

public class CashControlDocumentRule extends TransactionalDocumentRuleBase implements AddCashControlDetailRule<CashControlDocument>{

    protected boolean processCustomSaveDocumentBusinessRules(Document document) {
        boolean isValid = super.processCustomSaveDocumentBusinessRules(document);
        
        CashControlDocument ccDocument = (CashControlDocument)document;
        isValid &= checkReferenceDocument(ccDocument);
        isValid &= checkUserOrgOptions(ccDocument);
        isValid &= checkPaymentMedium(ccDocument);
        isValid &= checkOrgDocNumber(ccDocument);       
        
        return true;
    }
    
    protected boolean processCustomRouteDocumentBusinessRules(Document document) {
        boolean isValid = super.processCustomRouteDocumentBusinessRules(document);
        CashControlDocument ccDocument = (CashControlDocument)document;
        
        isValid &= checkReferenceDocument(ccDocument);
        isValid &= checkUserOrgOptions(ccDocument);
        isValid &= checkPaymentMedium(ccDocument);
        isValid &= checkOrgDocNumber(ccDocument); 
        
        return isValid;
    }
    
    protected boolean processCustomApproveDocumentBusinessRules(ApproveDocumentEvent approveEvent) {
        boolean isValid = super.processCustomApproveDocumentBusinessRules(approveEvent);
        CashControlDocument ccDocument = (CashControlDocument)approveEvent.getDocument();
        
        isValid &= checkReferenceDocument(ccDocument);
        isValid &= checkUserOrgOptions(ccDocument);
        isValid &= checkPaymentMedium(ccDocument);
        isValid &= checkOrgDocNumber(ccDocument);   
        
        return isValid;
    }
    
  
    private boolean checkLineAmounts(CashControlDocument document, CashControlDetail detail) {
       
        boolean isValid = false;
        if (detail.getFinancialDocumentLineAmount().isZero()){
            GlobalVariables.getErrorMap().putError("financialDocumentLineAmount", KFSKeyConstants.ERROR_ZERO_AMOUNT);
            return false;
        }
        else if (detail.getFinancialDocumentLineAmount().isNegative() && document.isHasNegativeCashControlDetail()) {
            GlobalVariables.getErrorMap().putError("financialDocumentLineAmount", KFSKeyConstants.ERROR_INVALID_NEGATIVE_AMOUNT);
            return false;
        }
        
        if (detail.getFinancialDocumentLineAmount().isNegative()) {
            document.setHasNegativeCashControlDetail(true);
        }
        
        return isValid; 
    }
    
    private boolean checkPaymentMedium(CashControlDocument document) {
        boolean isValid = false;
        
        String paymentMedium = document.getCustomerPaymentMediumCode();
        
        return isValid;
    }
    <commit_msg>KULAR-129 In checkLineAmounts() initialize isValid to true<commit_after>/*
 * Copyright 2007 The Kuali Foundation.
 * 
 * Licensed under the Educational Community License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.opensource.org/licenses/ecl1.php
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.module.ar.rules;

import org.kuali.core.document.Document;
import org.kuali.core.document.TransactionalDocument;
import org.kuali.core.rule.event.ApproveDocumentEvent;
import org.kuali.core.rules.TransactionalDocumentRuleBase;
import org.kuali.core.util.GlobalVariables;
import org.kuali.kfs.KFSKeyConstants;
import org.kuali.kfs.KFSPropertyConstants;
import org.kuali.module.ar.ArConstants;
import org.kuali.module.ar.bo.CashControlDetail;
import org.kuali.module.ar.document.CashControlDocument;
import org.kuali.module.ar.rule.AddCashControlDetailRule;
import org.kuali.module.ar.service.OrganizationOptionsService;
import org.kuali.module.ar.service.impl.OrganizationOptionsServiceImpl;
import org.kuali.module.chart.bo.ChartUser;
import org.kuali.module.chart.lookup.valuefinder.ValueFinderUtil;

public class CashControlDocumentRule extends TransactionalDocumentRuleBase implements AddCashControlDetailRule<CashControlDocument>{

    protected boolean processCustomSaveDocumentBusinessRules(Document document) {
        boolean isValid = super.processCustomSaveDocumentBusinessRules(document);
        
        CashControlDocument ccDocument = (CashControlDocument)document;
        isValid &= checkReferenceDocument(ccDocument);
        isValid &= checkUserOrgOptions(ccDocument);
        isValid &= checkPaymentMedium(ccDocument);
        isValid &= checkOrgDocNumber(ccDocument);       
        
        return true;
    }
    
    protected boolean processCustomRouteDocumentBusinessRules(Document document) {
        boolean isValid = super.processCustomRouteDocumentBusinessRules(document);
        CashControlDocument ccDocument = (CashControlDocument)document;
        
        isValid &= checkReferenceDocument(ccDocument);
        isValid &= checkUserOrgOptions(ccDocument);
        isValid &= checkPaymentMedium(ccDocument);
        isValid &= checkOrgDocNumber(ccDocument); 
        
        return isValid;
    }
    
    protected boolean processCustomApproveDocumentBusinessRules(ApproveDocumentEvent approveEvent) {
        boolean isValid = super.processCustomApproveDocumentBusinessRules(approveEvent);
        CashControlDocument ccDocument = (CashControlDocument)approveEvent.getDocument();
        
        isValid &= checkReferenceDocument(ccDocument);
        isValid &= checkUserOrgOptions(ccDocument);
        isValid &= checkPaymentMedium(ccDocument);
        isValid &= checkOrgDocNumber(ccDocument);   
        
        return isValid;
    }
    
  
    private boolean checkLineAmounts(CashControlDocument document, CashControlDetail detail) {
       
        boolean isValid = true;
        if (detail.getFinancialDocumentLineAmount().isZero()){
            GlobalVariables.getErrorMap().putError("financialDocumentLineAmount", KFSKeyConstants.ERROR_ZERO_AMOUNT);
            return false;
        }
        else if (detail.getFinancialDocumentLineAmount().isNegative() && document.isHasNegativeCashControlDetail()) {
            GlobalVariables.getErrorMap().putError("financialDocumentLineAmount", KFSKeyConstants.ERROR_INVALID_NEGATIVE_AMOUNT);
            return false;
        }
        
        if (detail.getFinancialDocumentLineAmount().isNegative()) {
            document.setHasNegativeCashControlDetail(true);
        }
        
        return isValid; 
    }
    
    private boolean checkPaymentMedium(CashControlDocument document) {
        boolean isValid = false;
        
        String paymentMedium = document.getCustomerPaymentMediumCode();
        
        return isValid;
    }
    
{'fraction_non_alphanumeric': 0.07675023651844844, 'fraction_numerical': 0.002010406811731315, 'mean_word_length': 3.7140468227424748, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2148247', 'n_tokens_mistral': 2243, 'n_tokens_neox': 2166, 'n_words': 454}