View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.module.ar.businessobject;
20  
21  import org.kuali.kfs.coa.businessobject.Account;
22  import org.kuali.kfs.coa.businessobject.ObjectCode;
23  import org.kuali.kfs.module.ar.ArConstants;
24  import org.kuali.kfs.module.ar.document.CustomerInvoiceWriteoffDocument;
25  import org.kuali.kfs.sys.context.SpringContext;
26  import org.kuali.kfs.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE;
27  import org.kuali.rice.core.api.util.type.KualiDecimal;
28  import org.kuali.rice.coreservice.framework.parameter.ParameterService;
29  
30  
31  public class WriteoffTaxCustomerInvoiceDetail extends CustomerInvoiceDetail {
32      
33      private CustomerInvoiceDetail postable;
34      private CustomerInvoiceWriteoffDocument poster;
35      private boolean isUsingTaxLiabilityAdjustmentIndNo;
36      
37      public WriteoffTaxCustomerInvoiceDetail(CustomerInvoiceDetail postable, CustomerInvoiceWriteoffDocument poster){
38          this.postable = postable;
39          this.poster = poster;
40          
41          String writeoffTaxGenerationOption = SpringContext.getBean(ParameterService.class).getParameterValueAsString(CustomerInvoiceWriteoffDocument.class, ArConstants.ALLOW_SALES_TAX_LIABILITY_ADJUSTMENT_IND);
42          isUsingTaxLiabilityAdjustmentIndNo = ArConstants.ALLOW_SALES_TAX_LIABILITY_ADJUSTMENT_IND_NO.equals( writeoffTaxGenerationOption );
43  
44          if( isUsingTaxLiabilityAdjustmentIndNo ){
45              //if is using org account default, I already set the writeoff FAU on
46              //the document, so that is needed to do is refresh the FAU objects
47              this.poster.refreshReferenceObject("account");
48              this.poster.refreshReferenceObject("chartOfAccounts");
49              this.poster.refreshReferenceObject("subAccount");
50              this.poster.refreshReferenceObject("financialObject");
51              this.poster.refreshReferenceObject("financialSubObject");
52              this.poster.refreshReferenceObject("project");                      
53          } else {
54              this.postable.refreshNonUpdateableReferences();
55          }        
56      }
57      
58      @Override
59      public Account getAccount() {
60          if ( isUsingTaxLiabilityAdjustmentIndNo ){
61              return poster.getAccount();
62          } else {
63              return postable.getAccount();
64          }
65      }
66     
67     @Override
68      public String getAccountNumber() {
69          if ( isUsingTaxLiabilityAdjustmentIndNo ){
70              return poster.getAccountNumber();
71          } else {
72              return postable.getAccountNumber();
73          }
74      }
75  
76     @Override
77      public KualiDecimal getAmount() {
78          return postable.getAmountOpen();
79      }
80  
81     @Override
82      public String getChartOfAccountsCode() {
83          if ( isUsingTaxLiabilityAdjustmentIndNo ){
84              return poster.getChartOfAccountsCode();
85          } else {
86              return postable.getChartOfAccountsCode();
87          }        
88      }
89  
90     @Override
91      public String getDocumentNumber() {
92          return postable.getDocumentNumber();
93      }
94  
95     @Override
96      public String getFinancialDocumentLineDescription() {
97          return postable.getFinancialDocumentLineDescription();
98      }
99  
100    @Override
101    public String getFinancialObjectCode() {
102        if ( isUsingTaxLiabilityAdjustmentIndNo ){
103            return poster.getFinancialObjectCode();
104        } else {
105            return postable.getAccountsReceivableObjectCode();
106        }   
107    }
108 
109   @Override
110    public ObjectCode getObjectCode() {
111       if ( isUsingTaxLiabilityAdjustmentIndNo ){
112           return poster.getFinancialObject();
113       } else {
114           return postable.getAccountsReceivableObject();
115       }
116    }
117   
118   @Override
119   public String getFinancialSubObjectCode() {
120       return GENERAL_LEDGER_PENDING_ENTRY_CODE.getBlankFinancialSubObjectCode(); 
121   }
122 
123    @Override
124     public String getOrganizationReferenceId() {
125         if ( isUsingTaxLiabilityAdjustmentIndNo ){
126             return poster.getOrganizationReferenceIdentifier();
127         } else {
128             return postable.getOrganizationReferenceId();
129         }
130     }
131 
132    @Override
133     public String getProjectCode() {
134         if ( isUsingTaxLiabilityAdjustmentIndNo ){
135             return poster.getProjectCode();
136         } else {
137             return postable.getProjectCode();
138         }
139     }
140 
141    @Override
142     public String getSubAccountNumber() {
143         if ( isUsingTaxLiabilityAdjustmentIndNo ){
144             return poster.getSubAccountNumber();
145         } else {
146             return postable.getSubAccountNumber();
147         }
148     }
149 }