001/*
002 * Copyright 2006 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.opensource.org/licenses/ecl2.php
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.ole.gl.service.impl;
017
018import java.util.Iterator;
019import java.util.Map;
020
021import org.kuali.ole.gl.businessobject.Encumbrance;
022import org.kuali.ole.gl.dataaccess.EncumbranceDao;
023import org.kuali.ole.gl.service.EncumbranceService;
024import org.kuali.ole.sys.context.SpringContext;
025import org.kuali.rice.krad.service.BusinessObjectService;
026import org.springframework.transaction.annotation.Transactional;
027
028/**
029 * The base implementation of EncumbranaceService
030 */
031@Transactional
032public class EncumbranceServiceImpl implements EncumbranceService {
033    private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(EncumbranceServiceImpl.class);
034
035    private EncumbranceDao encumbranceDao;
036
037    /**
038     * Saves an encumbrance
039     * 
040     * @param enc an encumbrance to save
041     * @see org.kuali.ole.gl.service.EncumbranceService#save(org.kuali.ole.gl.businessobject.Encumbrance)
042     */
043    public void save(Encumbrance enc) {
044        LOG.debug("save() started");
045        SpringContext.getBean(BusinessObjectService.class).save(enc);
046    }
047
048    /**
049     * Removes all encumbrances from the database having a certain chart and fiscal year
050     * @param chartOfAccountsCode the chart of encumbrances to purge
051     * @param year the year of encumbrances to purge
052     * @see org.kuali.ole.gl.service.EncumbranceService#purgeYearByChart(java.lang.String, int)
053     */
054    public void purgeYearByChart(String chartOfAccountsCode, int year) {
055        LOG.debug("purgeYearByChart() started");
056
057        encumbranceDao.purgeYearByChart(chartOfAccountsCode, year);
058    }
059
060    /**
061     * Returns an iterator with all encumbrances from the database.
062     * @return an Iterator of all encumbrances
063     * @see org.kuali.ole.gl.service.EncumbranceService#getAllEncumbrances()
064     */
065    public Iterator getAllEncumbrances() {
066        return encumbranceDao.getAllEncumbrances();
067    }
068
069    /**
070     * Field accessor for EncumbranceDao
071     * 
072     * @param ed
073     */
074    public void setEncumbranceDao(EncumbranceDao ed) {
075        encumbranceDao = ed;
076    }
077
078    /**
079     * group all encumbrances with/without the given document type code by fiscal year, chart, account, sub-account, object code,
080     * sub object code, and balance type code, and summarize the encumbrance amount and the encumbrance close amount.
081     * 
082     * @param documentTypeCode the given document type code
083     * @param included indicate if all encumbrances with the given document type are included in the results or not
084     * @see org.kuali.ole.gl.service.EncumbranceService#getSummarizedEncumbrances(java.lang.String, boolean)
085     */
086    public Iterator getSummarizedEncumbrances(String documentTypeCode, boolean included) {
087        return encumbranceDao.getSummarizedEncumbrances(documentTypeCode, included);
088    }
089
090    /**
091     * Given the fieldValues, forms a query and finds the open encumbrances that match it
092     * @param fieldValues the values to form an encumbrance query out of
093     * @param includeZeroEncumbrances
094     * @return an Iterator full of qualifying encumbrances
095     * @see org.kuali.ole.gl.service.EncumbranceService#findOpenEncumbrance(java.util.Map)
096     */
097    public Iterator findOpenEncumbrance(Map fieldValues, boolean includeZeroEncumbrances) {
098        return encumbranceDao.findOpenEncumbrance(fieldValues, includeZeroEncumbrances);
099    }
100
101    /**
102     * Returns the count of all open encumbrances in the database, matching the given field values
103     * @param fieldValues the field values to build an encumbrance query out of
104     * @param includeZeroEncumbrances
105     * @return the number of qualifying open encumbrances
106     * @see org.kuali.ole.gl.service.EncumbranceService#getOpenEncumbranceCount(java.util.Map)
107     */
108    public Integer getOpenEncumbranceRecordCount(Map fieldValues, boolean includeZeroEncumbrances) {
109        return encumbranceDao.getOpenEncumbranceRecordCount(fieldValues, includeZeroEncumbrances);
110    }
111}