001 /* 002 * Copyright 2011 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 */ 016 package org.kuali.kfs.module.ar.document.service.impl; 017 018 import org.kuali.kfs.module.ar.businessobject.SalesTaxCustomerInvoiceDetail; 019 import org.kuali.kfs.module.ar.document.service.CustomerInvoiceGLPEService; 020 import org.kuali.kfs.sys.KFSConstants; 021 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntry; 022 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySequenceHelper; 023 import org.kuali.kfs.sys.businessobject.GeneralLedgerPendingEntrySourceDetail; 024 import org.kuali.kfs.sys.businessobject.TaxDetail; 025 import org.kuali.kfs.sys.document.GeneralLedgerPendingEntrySource; 026 import org.kuali.kfs.sys.service.GeneralLedgerPendingEntryService; 027 import org.kuali.rice.kns.util.KualiDecimal; 028 029 public class CustomerInvoiceGLPEServiceImpl implements CustomerInvoiceGLPEService { 030 031 private GeneralLedgerPendingEntryService generalLedgerPendingEntryService; 032 033 /** 034 * This method creates and adds generic invoice related GLPE's 035 * @param glpeSource 036 * @param glpeSourceDetail 037 * @param sequenceHelper 038 * @param isDebit 039 * @param hasClaimOnCashOffset 040 * @param amount 041 */ 042 public void createAndAddGenericInvoiceRelatedGLPEs(GeneralLedgerPendingEntrySource glpeSource, GeneralLedgerPendingEntrySourceDetail glpeSourceDetail, GeneralLedgerPendingEntrySequenceHelper sequenceHelper, boolean isDebit, boolean hasClaimOnCashOffset, KualiDecimal amount){ 043 044 GeneralLedgerPendingEntry explicitEntry = new GeneralLedgerPendingEntry(); 045 generalLedgerPendingEntryService.populateExplicitGeneralLedgerPendingEntry(glpeSource, glpeSourceDetail, sequenceHelper, explicitEntry); 046 explicitEntry.setTransactionLedgerEntryAmount(amount.abs()); 047 explicitEntry.setTransactionDebitCreditCode(isDebit? KFSConstants.GL_DEBIT_CODE : KFSConstants.GL_CREDIT_CODE); 048 049 //add explicit entry 050 glpeSource.addPendingEntry(explicitEntry); 051 052 //add claim on cash offset entry 053 if( hasClaimOnCashOffset ){ 054 sequenceHelper.increment(); 055 056 GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(explicitEntry); 057 generalLedgerPendingEntryService.populateOffsetGeneralLedgerPendingEntry(glpeSource.getPostingYear(), explicitEntry, sequenceHelper, offsetEntry); 058 glpeSource.addPendingEntry(offsetEntry); 059 } 060 } 061 062 /** 063 * This method creates and adds generic invoice related GLPE's 064 * @param glpeSource 065 * @param glpeSourceDetail 066 * @param sequenceHelper 067 * @param isDebit 068 * @param hasReceivableClaimOnCashOffset 069 * @param writeoffTaxGenerationMethodDisallowFlag 070 * @param amount 071 */ 072 public void createAndAddGenericInvoiceRelatedGLPEs(GeneralLedgerPendingEntrySource glpeSource, GeneralLedgerPendingEntrySourceDetail glpeSourceDetail, GeneralLedgerPendingEntrySequenceHelper sequenceHelper, boolean isDebit, boolean hasReceivableClaimOnCashOffset, boolean writeoffTaxGenerationMethodDisallowFlag, KualiDecimal amount){ 073 074 GeneralLedgerPendingEntry explicitEntry = new GeneralLedgerPendingEntry(); 075 generalLedgerPendingEntryService.populateExplicitGeneralLedgerPendingEntry(glpeSource, glpeSourceDetail, sequenceHelper, explicitEntry); 076 explicitEntry.setTransactionLedgerEntryAmount(amount.abs()); 077 explicitEntry.setTransactionDebitCreditCode(isDebit? KFSConstants.GL_DEBIT_CODE : KFSConstants.GL_CREDIT_CODE); 078 079 boolean overrideFinancialObjectCodeFlag = isDebit && writeoffTaxGenerationMethodDisallowFlag && !hasReceivableClaimOnCashOffset; 080 081 if (!overrideFinancialObjectCodeFlag) 082 //add explicit entry 083 glpeSource.addPendingEntry(explicitEntry); 084 085 // do not add claim on cash offset entry if GLPLE_RECEIVABLE_OFFSET_METHOD = 3 && GLPLE_WRITEOFF_TAX_GENERATION_METHOD = D 086 if (hasReceivableClaimOnCashOffset && writeoffTaxGenerationMethodDisallowFlag ) 087 return; 088 089 //add claim on cash offset entry 090 if( hasReceivableClaimOnCashOffset || writeoffTaxGenerationMethodDisallowFlag ){ 091 sequenceHelper.increment(); 092 093 GeneralLedgerPendingEntry offsetEntry = new GeneralLedgerPendingEntry(explicitEntry); 094 generalLedgerPendingEntryService.populateOffsetGeneralLedgerPendingEntry(glpeSource.getPostingYear(), explicitEntry, sequenceHelper, offsetEntry); 095 if (overrideFinancialObjectCodeFlag) { 096 explicitEntry.setFinancialObjectCode(offsetEntry.getFinancialObjectCode()); 097 glpeSource.addPendingEntry(explicitEntry); 098 } 099 // TODO 100 // override (here or above???) account and object when hasReceivableClaimOnCashOffset = true and writeoffTaxGenerationMethodDisallowFlag = true 101 glpeSource.addPendingEntry(offsetEntry); 102 } 103 } 104 105 public GeneralLedgerPendingEntryService getGeneralLedgerPendingEntryService() { 106 return generalLedgerPendingEntryService; 107 } 108 109 110 public void setGeneralLedgerPendingEntryService(GeneralLedgerPendingEntryService generalLedgerPendingEntryService) { 111 this.generalLedgerPendingEntryService = generalLedgerPendingEntryService; 112 } 113 114 115 116 }