use of org.kuali.kfs.module.purap.util.SummaryAccount in project cu-kfs by CU-CommunityApps.
the class CuPurapGeneralLedgerServiceImpl method generateEntriesPaymentRequest.
protected boolean generateEntriesPaymentRequest(PaymentRequestDocument preq, List encumbrances, List summaryAccounts, String processType) {
LOG.debug("generateEntriesPaymentRequest() started");
boolean success = true;
preq.setGeneralLedgerPendingEntries(new ArrayList());
/*
* Can't let generalLedgerPendingEntryService just create all the entries because we need the sequenceHelper to carry over
* from the encumbrances to the actuals and also because we need to tell the PaymentRequestDocumentRule customize entry
* method how to customize differently based on if creating an encumbrance or actual.
*/
GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper(getNextAvailableSequence(preq.getDocumentNumber()));
// when cancelling a PREQ, do not book encumbrances if PO is CLOSED
if (encumbrances != null && !(CANCEL_PAYMENT_REQUEST.equals(processType) && PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals(preq.getPurchaseOrderDocument().getApplicationDocumentStatus()))) {
LOG.debug("generateEntriesPaymentRequest() generate encumbrance entries");
if (CREATE_PAYMENT_REQUEST.equals(processType)) {
// on create, use CREDIT code for encumbrances
preq.setDebitCreditCodeForGLEntries(GL_CREDIT_CODE);
} else if (CANCEL_PAYMENT_REQUEST.equals(processType)) {
// on cancel, use DEBIT code
preq.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
} else if (MODIFY_PAYMENT_REQUEST.equals(processType)) {
// no encumbrances for modify
}
preq.setGenerateEncumbranceEntries(true);
for (Iterator iter = encumbrances.iterator(); iter.hasNext(); ) {
AccountingLine accountingLine = (AccountingLine) iter.next();
preq.generateGeneralLedgerPendingEntries(accountingLine, sequenceHelper);
// increment for the next line
sequenceHelper.increment();
}
}
if (ObjectUtils.isNotNull(summaryAccounts) && !summaryAccounts.isEmpty()) {
LOG.debug("generateEntriesPaymentRequest() now book the actuals");
preq.setGenerateEncumbranceEntries(false);
if (CREATE_PAYMENT_REQUEST.equals(processType) || MODIFY_PAYMENT_REQUEST.equals(processType)) {
// on create and modify, use DEBIT code
preq.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
} else if (CANCEL_PAYMENT_REQUEST.equals(processType)) {
// on cancel, use CREDIT code
preq.setDebitCreditCodeForGLEntries(GL_CREDIT_CODE);
}
for (Iterator iter = summaryAccounts.iterator(); iter.hasNext(); ) {
SummaryAccount summaryAccount = (SummaryAccount) iter.next();
preq.generateGeneralLedgerPendingEntries(summaryAccount.getAccount(), sequenceHelper);
// increment for the next line
sequenceHelper.increment();
}
// generate offset accounts for use tax if it exists (useTaxContainers will be empty if not a use tax document)
List<UseTaxContainer> useTaxContainers = SpringContext.getBean(PurapAccountingService.class).generateUseTaxAccount(preq);
for (UseTaxContainer useTaxContainer : useTaxContainers) {
PurApItemUseTax offset = useTaxContainer.getUseTax();
List<SourceAccountingLine> accounts = useTaxContainer.getAccounts();
for (SourceAccountingLine sourceAccountingLine : accounts) {
preq.generateGeneralLedgerPendingEntries(sourceAccountingLine, sequenceHelper, useTaxContainer.getUseTax());
// increment for the next line
sequenceHelper.increment();
}
}
// Manually save preq summary accounts
if (MODIFY_PAYMENT_REQUEST.equals(processType)) {
// for modify, regenerate the summary from the doc
List<SummaryAccount> summaryAccountsForModify = SpringContext.getBean(PurapAccountingService.class).generateSummaryAccountsWithNoZeroTotalsNoUseTax(preq);
saveAccountsPayableSummaryAccounts(summaryAccountsForModify, preq.getPurapDocumentIdentifier(), PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT);
} else {
// for create and cancel, use the summary accounts
saveAccountsPayableSummaryAccounts(summaryAccounts, preq.getPurapDocumentIdentifier(), PurapDocTypeCodes.PAYMENT_REQUEST_DOCUMENT);
}
// manually save cm account change tables (CAMS needs this)
if (CREATE_PAYMENT_REQUEST.equals(processType) || MODIFY_PAYMENT_REQUEST.equals(processType)) {
SpringContext.getBean(PurapAccountRevisionService.class).savePaymentRequestAccountRevisions(preq.getItems(), preq.getPostingYearFromPendingGLEntries(), preq.getPostingPeriodCodeFromPendingGLEntries());
} else if (CANCEL_PAYMENT_REQUEST.equals(processType)) {
SpringContext.getBean(PurapAccountRevisionService.class).cancelPaymentRequestAccountRevisions(preq.getItems(), preq.getPostingYearFromPendingGLEntries(), preq.getPostingPeriodCodeFromPendingGLEntries());
}
// we would only want to do this when booking the actuals (not the encumbrances)
if (preq.getGeneralLedgerPendingEntries() == null || preq.getGeneralLedgerPendingEntries().size() < 2) {
LOG.warn("No gl entries for accounting lines.");
} else {
// upon create, build the entries normally
if (CREATE_PAYMENT_REQUEST.equals(processType)) {
getPaymentMethodGeneralLedgerPendingEntryService().generatePaymentMethodSpecificDocumentGeneralLedgerPendingEntries(preq, ((CuPaymentRequestDocument) preq).getPaymentMethodCode(), preq.getBankCode(), KRADConstants.DOCUMENT_PROPERTY_NAME + "." + "bankCode", preq.getGeneralLedgerPendingEntry(0), false, false, sequenceHelper);
} else if (MODIFY_PAYMENT_REQUEST.equals(processType)) {
// upon modify, we need to calculate the deltas here and pass them in so the appropriate adjustments are created
KualiDecimal bankOffsetAmount = KualiDecimal.ZERO;
Map<String, KualiDecimal> changesByChart = new HashMap<String, KualiDecimal>();
if (ObjectUtils.isNotNull(summaryAccounts) && !summaryAccounts.isEmpty()) {
for (SummaryAccount a : (List<SummaryAccount>) summaryAccounts) {
bankOffsetAmount = bankOffsetAmount.add(a.getAccount().getAmount());
if (changesByChart.get(a.getAccount().getChartOfAccountsCode()) == null) {
changesByChart.put(a.getAccount().getChartOfAccountsCode(), a.getAccount().getAmount());
} else {
changesByChart.put(a.getAccount().getChartOfAccountsCode(), changesByChart.get(a.getAccount().getChartOfAccountsCode()).add(a.getAccount().getAmount()));
}
}
}
getPaymentMethodGeneralLedgerPendingEntryService().generatePaymentMethodSpecificDocumentGeneralLedgerPendingEntries(preq, ((CuPaymentRequestDocument) preq).getPaymentMethodCode(), preq.getBankCode(), KRADConstants.DOCUMENT_PROPERTY_NAME + "." + "bankCode", preq.getGeneralLedgerPendingEntry(0), true, false, sequenceHelper, bankOffsetAmount, changesByChart);
}
}
preq.generateDocumentGeneralLedgerPendingEntries(sequenceHelper);
// END MOD
}
// Manually save GL entries for Payment Request and encumbrances
saveGLEntries(preq.getGeneralLedgerPendingEntries());
return success;
}
use of org.kuali.kfs.module.purap.util.SummaryAccount in project cu-kfs by CU-CommunityApps.
the class CuPendingTransactionServiceImpl method generateCreditMemoReversalEntries.
/**
* Generates the reversal entries for the given input VendorCreditMemoDocument.
*
* @param doc
* the VendorCreditMemoDocument for which we generate the reversal entries
* @param sequenceHelper
*/
protected void generateCreditMemoReversalEntries(VendorCreditMemoDocument cm) {
cm.setGeneralLedgerPendingEntries(new ArrayList());
boolean success = true;
GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper(getNextAvailableSequence(cm.getDocumentNumber()));
if (!cm.isSourceVendor()) {
LOG.debug("generateEntriesCreditMemo() create encumbrance entries for CM against a PO or PREQ (not vendor)");
PurchaseOrderDocument po = null;
if (cm.isSourceDocumentPurchaseOrder()) {
LOG.debug("generateEntriesCreditMemo() PO type");
po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(cm.getPurchaseOrderIdentifier());
} else if (cm.isSourceDocumentPaymentRequest()) {
LOG.debug("generateEntriesCreditMemo() PREQ type");
po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(cm.getPaymentRequestDocument().getPurchaseOrderIdentifier());
}
// for CM cancel or create, do not book encumbrances if PO is CLOSED, but do update the amounts on the PO
List encumbrances = getCreditMemoEncumbrance(cm, po);
if (!(PurapConstants.PurchaseOrderStatuses.APPDOC_CLOSED.equals(po.getApplicationDocumentStatus()))) {
if (encumbrances != null) {
cm.setGenerateEncumbranceEntries(true);
// even if generating encumbrance entries on cancel, call is the same because the method gets negative amounts
// from
// the map so Debits on negatives = a credit
cm.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
for (Iterator iter = encumbrances.iterator(); iter.hasNext(); ) {
AccountingLine accountingLine = (AccountingLine) iter.next();
if (accountingLine.getAmount().compareTo(ZERO) != 0) {
cm.generateGeneralLedgerPendingEntries(accountingLine, sequenceHelper);
// increment for the next line
sequenceHelper.increment();
}
}
}
}
}
List<SummaryAccount> summaryAccounts = SpringContext.getBean(PurapAccountingService.class).generateSummaryAccountsWithNoZeroTotalsNoUseTax(cm);
if (summaryAccounts != null) {
LOG.debug("generateEntriesCreditMemo() now book the actuals");
cm.setGenerateEncumbranceEntries(false);
for (Iterator iter = summaryAccounts.iterator(); iter.hasNext(); ) {
SummaryAccount summaryAccount = (SummaryAccount) iter.next();
cm.generateGeneralLedgerPendingEntries(summaryAccount.getAccount(), sequenceHelper);
// increment for the next line
sequenceHelper.increment();
}
// generate offset accounts for use tax if it exists (useTaxContainers will be empty if not a use tax document)
List<UseTaxContainer> useTaxContainers = SpringContext.getBean(PurapAccountingService.class).generateUseTaxAccount(cm);
for (UseTaxContainer useTaxContainer : useTaxContainers) {
PurApItemUseTax offset = useTaxContainer.getUseTax();
List<SourceAccountingLine> accounts = useTaxContainer.getAccounts();
for (SourceAccountingLine sourceAccountingLine : accounts) {
cm.generateGeneralLedgerPendingEntries(sourceAccountingLine, sequenceHelper, useTaxContainer.getUseTax());
// increment for the next line
sequenceHelper.increment();
}
}
// manually save cm account change tables (CAMS needs this)
SpringContext.getBean(PurapAccountRevisionService.class).cancelCreditMemoAccountRevisions(cm.getItems(), cm.getPostingYearFromPendingGLEntries(), cm.getPostingPeriodCodeFromPendingGLEntries());
}
businessObjectService.save(cm.getGeneralLedgerPendingEntries());
}
use of org.kuali.kfs.module.purap.util.SummaryAccount in project cu-kfs by CU-CommunityApps.
the class CuPendingTransactionServiceImpl method generateEntriesPaymentRequest.
/**
* Creates the general ledger entries for Payment Request actions.
*
* @param preq Payment Request document to create entries
* @param encumbrances List of encumbrance accounts if applies
* @param accountingLines List of preq accounts to create entries
* @param processType Type of process (create, modify, cancel)
* @return Boolean returned indicating whether entry creation succeeded
*/
protected boolean generateEntriesPaymentRequest(PaymentRequestDocument preq, List encumbrances, List summaryAccounts) {
LOG.debug("generateEntriesPaymentRequest() started");
boolean success = true;
preq.setGeneralLedgerPendingEntries(new ArrayList());
/*
* Can't let generalLedgerPendingEntryService just create all the entries because we need the sequenceHelper to carry over
* from the encumbrances to the actuals and also because we need to tell the PaymentRequestDocumentRule customize entry
* method how to customize differently based on if creating an encumbrance or actual.
*/
GeneralLedgerPendingEntrySequenceHelper sequenceHelper = new GeneralLedgerPendingEntrySequenceHelper(getNextAvailableSequence(preq.getDocumentNumber()));
// when cancelling a PREQ, do not book encumbrances if PO is CLOSED
if (encumbrances != null) {
// on cancel, use DEBIT code
preq.setDebitCreditCodeForGLEntries(GL_DEBIT_CODE);
preq.setGenerateEncumbranceEntries(true);
for (Iterator iter = encumbrances.iterator(); iter.hasNext(); ) {
AccountingLine accountingLine = (AccountingLine) iter.next();
preq.generateGeneralLedgerPendingEntries(accountingLine, sequenceHelper);
// increment for the next line
sequenceHelper.increment();
}
}
if (ObjectUtils.isNotNull(summaryAccounts) && !summaryAccounts.isEmpty()) {
LOG.debug("generateEntriesPaymentRequest() now book the actuals");
preq.setGenerateEncumbranceEntries(false);
// on cancel, use CREDIT code
preq.setDebitCreditCodeForGLEntries(GL_CREDIT_CODE);
for (Iterator iter = summaryAccounts.iterator(); iter.hasNext(); ) {
SummaryAccount summaryAccount = (SummaryAccount) iter.next();
preq.generateGeneralLedgerPendingEntries(summaryAccount.getAccount(), sequenceHelper);
// increment for the next line
sequenceHelper.increment();
}
// generate offset accounts for use tax if it exists (useTaxContainers will be empty if not a use tax document)
List<UseTaxContainer> useTaxContainers = SpringContext.getBean(PurapAccountingService.class).generateUseTaxAccount(preq);
for (UseTaxContainer useTaxContainer : useTaxContainers) {
PurApItemUseTax offset = useTaxContainer.getUseTax();
List<SourceAccountingLine> accounts = useTaxContainer.getAccounts();
for (SourceAccountingLine sourceAccountingLine : accounts) {
preq.generateGeneralLedgerPendingEntries(sourceAccountingLine, sequenceHelper, useTaxContainer.getUseTax());
// increment for the next line
sequenceHelper.increment();
}
}
}
// Manually save GL entries for Payment Request and encumbrances
LOG.debug("saveGLEntries() started");
businessObjectService.save(preq.getGeneralLedgerPendingEntries());
return success;
}
use of org.kuali.kfs.module.purap.util.SummaryAccount in project cu-kfs by CU-CommunityApps.
the class CuPurapGeneralLedgerServiceImplTest method testGenerateEntriesPaymentRequest.
public void testGenerateEntriesPaymentRequest() throws Exception {
changeCurrentUser(UserNameFixture.ccs1);
PurchaseOrderDocument po = PurchaseOrderFixture.PO_NON_B2B_OPEN_WITH_ITEMS.createPurchaseOrderdDocument(SpringContext.getBean(DocumentService.class));
po.setVendorShippingPaymentTermsCode("AL");
po.setVendorPaymentTermsCode("00N30");
po.refreshNonUpdateableReferences();
changeCurrentUser(UserNameFixture.mo14);
CuPaymentRequestDocument preq = (CuPaymentRequestDocument) PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(po.getPurapDocumentIdentifier());
preq.initiateDocument();
preq.populatePaymentRequestFromPurchaseOrder(po);
preq.setPaymentMethodCode("F");
preq.setApplicationDocumentStatus(PurapConstants.PaymentRequestStatuses.APPDOC_AWAITING_ACCOUNTS_PAYABLE_REVIEW);
((PaymentRequestItem) (preq.getItems().get(0))).setExtendedPrice(new KualiDecimal(1));
AccountingDocumentTestUtils.saveDocument(preq, SpringContext.getBean(DocumentService.class));
List<SummaryAccount> summaryAccounts = purapAccountingService.generateSummaryAccountsWithNoZeroTotalsNoUseTax(preq);
cuPurapGeneralLedgerServiceImpl.generateEntriesPaymentRequest(preq, null, summaryAccounts, "create");
boolean noBankOffsetGenerated = true;
for (GeneralLedgerPendingEntry pe : preq.getGeneralLedgerPendingEntries()) {
if (KFSKeyConstants.Bank.DESCRIPTION_GLPE_BANK_OFFSET.equalsIgnoreCase(pe.getTransactionLedgerEntryDescription())) {
noBankOffsetGenerated = false;
break;
}
}
assertEquals(2, preq.getGeneralLedgerPendingEntries().size());
assertTrue(noBankOffsetGenerated);
}
Aggregations