001/*
002 * The Kuali Financial System, a comprehensive financial management system for higher education.
003 * 
004 * Copyright 2005-2014 The Kuali Foundation
005 * 
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as
008 * published by the Free Software Foundation, either version 3 of the
009 * License, or (at your option) any later version.
010 * 
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 * 
016 * You should have received a copy of the GNU Affero General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019package org.kuali.kfs.module.ar.businessobject;
020
021import java.sql.Date;
022import java.util.LinkedHashMap;
023
024import org.apache.commons.lang.StringUtils;
025import org.kuali.kfs.coa.businessobject.Chart;
026import org.kuali.kfs.coa.businessobject.Organization;
027import org.kuali.kfs.coa.service.ChartService;
028import org.kuali.kfs.coa.service.OrganizationService;
029import org.kuali.kfs.sys.context.SpringContext;
030import org.kuali.rice.core.api.datetime.DateTimeService;
031import org.kuali.rice.krad.bo.DocumentHeader;
032import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
033
034/**
035 * @author Kuali Nervous System Team (kualidev@oncourse.iu.edu)
036 */
037public class AccountsReceivableDocumentHeader extends PersistableBusinessObjectBase implements org.kuali.kfs.integration.ar.AccountsReceivableDocumentHeader{
038
039        private String documentNumber;
040        private String customerNumber;
041        private String processingChartOfAccountCode;
042        private String processingOrganizationCode;
043        private Date entryDate;
044        private String financialDocumentExplanationText;
045
046        private Customer customer;
047        private Chart processingChartOfAccount;
048        private Organization processingOrganization;
049    private DocumentHeader documentHeader;
050
051        /**
052         * Gets the documentNumber attribute.
053         *
054         * @return Returns the documentNumber
055         *
056         */
057        public String getDocumentNumber() {
058                return documentNumber;
059        }
060
061        /**
062         * Sets the documentNumber attribute.
063         *
064         * @param documentNumber The documentNumber to set.
065         *
066         */
067        @Override
068    public void setDocumentNumber(String documentNumber) {
069                this.documentNumber = documentNumber;
070        }
071
072        /**
073         * Gets the customerNumber attribute.
074         *
075         * @return Returns the customerNumber
076         *
077         */
078        @Override
079    public String getCustomerNumber() {
080                return StringUtils.upperCase(customerNumber);
081        }
082
083        /**
084         * Sets the customerNumber attribute.
085         *
086         * @param customerNumber The customerNumber to set.
087         *
088         */
089        @Override
090    public void setCustomerNumber(String customerNumber) {
091                this.customerNumber = customerNumber;
092        }
093
094        /**
095         * Gets the processingChartOfAccountCode attribute.
096         *
097         * @return Returns the processingChartOfAccountCode
098         *
099         */
100        @Override
101    public String getProcessingChartOfAccountCode() {
102                return processingChartOfAccountCode;
103        }
104
105        /**
106         * Sets the processingChartOfAccountCode attribute.
107         *
108         * @param processingChartOfAccountCode The processingChartOfAccountCode to set.
109         *
110         */
111        @Override
112    public void setProcessingChartOfAccountCode(String processingChartOfAccountCode) {
113                this.processingChartOfAccountCode = processingChartOfAccountCode;
114        }
115
116
117        /**
118         * Gets the processingOrganizationCode attribute.
119         *
120         * @return Returns the processingOrganizationCode
121         *
122         */
123        @Override
124    public String getProcessingOrganizationCode() {
125                return processingOrganizationCode;
126        }
127
128        /**
129         * Sets the processingOrganizationCode attribute.
130         *
131         * @param processingOrganizationCode The processingOrganizationCode to set.
132         *
133         */
134        @Override
135    public void setProcessingOrganizationCode(String processingOrganizationCode) {
136                this.processingOrganizationCode = processingOrganizationCode;
137        }
138
139
140        /**
141         * Gets the entryDate attribute.
142         *
143         * @return Returns the entryDate
144         *
145         */
146        public Date getEntryDate() {
147                return entryDate;
148        }
149
150        /**
151         * Sets the entryDate attribute.
152         *
153         * @param entryDate The entryDate to set.
154         *
155         */
156        public void setEntryDate(Date entryDate) {
157                this.entryDate = entryDate;
158        }
159
160
161        /**
162         * Gets the financialDocumentExplanationText attribute.
163         *
164         * @return Returns the financialDocumentExplanationText
165         *
166         */
167        public String getFinancialDocumentExplanationText() {
168                return financialDocumentExplanationText;
169        }
170
171        /**
172         * Sets the financialDocumentExplanationText attribute.
173         *
174         * @param financialDocumentExplanationText The financialDocumentExplanationText to set.
175         *
176         */
177        public void setFinancialDocumentExplanationText(String financialDocumentExplanationText) {
178                this.financialDocumentExplanationText = financialDocumentExplanationText;
179        }
180
181        /**
182         * Gets the customer attribute.
183         *
184         * @return Returns the customer
185         *
186         */
187        public Customer getCustomer() {
188                return customer;
189        }
190
191        /**
192         * Sets the customer attribute.
193         *
194         * @param customer The customer to set.
195         * @deprecated
196         */
197        @Deprecated
198    public void setCustomer(Customer customer) {
199                this.customer = customer;
200        }
201
202        /**
203         * Gets the processingChartOfAccount attribute.
204         *
205         * @return Returns the processingChartOfAccount
206         *
207         */
208        public Chart getProcessingChartOfAccount() {
209        if(processingChartOfAccount==null) {
210            if(StringUtils.isNotBlank(getProcessingChartOfAccountCode())) {
211                processingChartOfAccount = SpringContext.getBean(ChartService.class).getByPrimaryId(getProcessingChartOfAccountCode());
212            }
213        }
214
215                return processingChartOfAccount;
216        }
217
218        /**
219         * Sets the processingChartOfAccount attribute.
220         *
221         * @param processingChartOfAccount The processingChartOfAccount to set.
222         * @deprecated
223         */
224        @Deprecated
225    public void setProcessingChartOfAccount(Chart processingChartOfAccount) {
226                this.processingChartOfAccount = processingChartOfAccount;
227        }
228
229        /**
230         * Gets the processingOrganization attribute.
231         *
232         * @return Returns the processingOrganization
233         *
234         */
235        public Organization getProcessingOrganization() {
236        if(processingOrganization==null) {
237            if(StringUtils.isNotBlank(getProcessingOrganizationCode()) && StringUtils.isNotBlank(getProcessingChartOfAccountCode())) {
238                processingOrganization = SpringContext.getBean(OrganizationService.class).getByPrimaryId(getProcessingChartOfAccountCode(), getProcessingOrganizationCode());
239            }
240        }
241
242                return processingOrganization;
243        }
244
245        /**
246         * Sets the processingOrganization attribute.
247         *
248         * @param processingOrganization The processingOrganization to set.
249         * @deprecated
250         */
251        @Deprecated
252    public void setProcessingOrganization(Organization processingOrganization) {
253                this.processingOrganization = processingOrganization;
254        }
255
256    /**
257     * Gets the documentHeader attribute.
258     * @return Returns the documentHeader.
259     */
260    public DocumentHeader getDocumentHeader() {
261        return documentHeader;
262    }
263
264    /**
265     * Sets the documentHeader attribute value.
266     * @param documentHeader The documentHeader to set.
267     * @deprecated
268     */
269    @Deprecated
270    public void setDocumentHeader(DocumentHeader documentHeader) {
271        this.documentHeader = documentHeader;
272    }
273
274        /**
275         * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
276         */
277    @SuppressWarnings({ "unchecked", "rawtypes" })
278        protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
279            LinkedHashMap m = new LinkedHashMap();
280        m.put("documentNumber", this.documentNumber);
281            return m;
282    }
283
284    /**
285     * Get a string representation for processing organization
286     * @return
287     */
288    public String getProcessingChartOfAccCodeAndOrgCode() {
289        String returnVal = getProcessingChartOfAccountCode() + "/" +getProcessingOrganizationCode();
290
291        return returnVal;
292    }
293
294    /**
295     * Gets the documentStatus attribute.
296     * @return Returns the documentStatus.
297     */
298    public String getDocumentStatus() {
299        return getDocumentHeader().getWorkflowDocument().getApplicationDocumentStatus();
300    }
301
302    /**
303     *
304     * This method...
305     * @return
306     */
307    public String getCreateDate() {
308        return SpringContext.getBean(DateTimeService.class).toDateString(getDocumentHeader().getWorkflowDocument().getDateCreated().toDate());
309    }
310
311    /**
312     *
313     * This method...
314     * @return
315     */
316    public String getInitiatorId() {
317        return getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId();
318    }
319}