use of org.kuali.kfs.sys.businessobject.SourceAccountingLine in project cu-kfs by CU-CommunityApps.
the class PurchasingActionBase method customAccountRetrieval.
/**
* Sets the line for account distribution.
*
* @param accountIndex The index of the account into the request parameter
* @param purchasingAccountsPayableForm A form which inherits from PurchasingAccountsPayableFormBase
* @return A SourceAccountingLine
*/
@Override
protected SourceAccountingLine customAccountRetrieval(int accountIndex, PurchasingAccountsPayableFormBase purchasingAccountsPayableForm) {
PurchasingFormBase purchasingForm = (PurchasingFormBase) purchasingAccountsPayableForm;
SourceAccountingLine line;
line = (SourceAccountingLine) ObjectUtils.deepCopy(purchasingForm.getAccountDistributionsourceAccountingLines().get(accountIndex));
return line;
}
use of org.kuali.kfs.sys.businessobject.SourceAccountingLine in project cu-kfs by CU-CommunityApps.
the class AccountingLineAccessibleValidation method onlyObjectCodeChanged.
/**
* Checks to see if the object code is the only difference between the original accounting line and the updated accounting line.
*
* @param accountingLine
* @param updatedAccountingLine
* @return true if only the object code has changed on the accounting line, false otherwise
*/
protected boolean onlyObjectCodeChanged(AccountingLine accountingLine, AccountingLine updatedAccountingLine) {
// no changes, return false
if (accountingLine.isLike(updatedAccountingLine)) {
return false;
}
// copy the updatedAccountLine so we can set the object code on the copy of the updated accounting line
// to be the original value for comparison purposes
AccountingLine updatedLine = null;
if (updatedAccountingLine.isSourceAccountingLine()) {
updatedLine = new SourceAccountingLine();
} else {
updatedLine = new TargetAccountingLine();
}
updatedLine.copyFrom(updatedAccountingLine);
updatedLine.setFinancialObjectCode(accountingLine.getFinancialObjectCode());
// if they're the same, the only change was the object code
return (accountingLine.isLike(updatedLine));
}
use of org.kuali.kfs.sys.businessobject.SourceAccountingLine in project cu-kfs by CU-CommunityApps.
the class CuPendingTransactionServiceImpl method getCreditMemoEncumbrance.
/**
* Re-encumber the Encumbrance on a PO based on values in a PREQ. This is used when a PREQ is cancelled. Note: This modifies the
* encumbrance values on the PO and saves the PO
*
* @param cm Credit Memo document
* @param po Purchase Order document modify encumbrances
* @return List of accounting lines to use to create the pending general ledger entries
*/
protected List<SourceAccountingLine> getCreditMemoEncumbrance(VendorCreditMemoDocument cm, PurchaseOrderDocument po) {
LOG.debug("getCreditMemoEncumbrance() started");
if (ObjectUtils.isNull(po)) {
return null;
}
LOG.debug("getCreditMemoEncumbrance() Receiving items back from vendor (cancelled CM)");
Map encumbranceAccountMap = new HashMap();
// Get each item one by one
for (Iterator items = cm.getItems().iterator(); items.hasNext(); ) {
CreditMemoItem cmItem = (CreditMemoItem) items.next();
PurchaseOrderItem poItem = getPoItem(po, cmItem.getItemLineNumber(), cmItem.getItemType());
// Amount to disencumber for this item
KualiDecimal itemDisEncumber = null;
// Amount to alter the invoicedAmt on the PO item
KualiDecimal itemAlterInvoiceAmt = null;
String logItmNbr = "Item # " + cmItem.getItemLineNumber();
LOG.debug("getCreditMemoEncumbrance() " + logItmNbr);
final KualiDecimal cmItemTotalAmount = (cmItem.getTotalAmount() == null) ? KualiDecimal.ZERO : cmItem.getTotalAmount();
;
// If there isn't a PO item or the total amount is 0, we don't need encumbrances
if ((poItem == null) || (cmItemTotalAmount == null) || (cmItemTotalAmount.doubleValue() == 0)) {
LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " No encumbrances required");
} else {
LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " Calculate encumbrance GL entries");
// Do we calculate the encumbrance amount based on quantity or amount?
if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " Calculate encumbrance based on quantity");
// Do encumbrance calculations based on quantity
KualiDecimal cmQuantity = cmItem.getItemQuantity() == null ? ZERO : cmItem.getItemQuantity();
KualiDecimal encumbranceQuantityChange = calculateQuantityChange(poItem, cmQuantity);
LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " encumbranceQtyChange " + encumbranceQuantityChange + " outstandingEncumberedQty " + poItem.getItemOutstandingEncumberedQuantity() + " invoicedTotalQuantity " + poItem.getItemInvoicedTotalQuantity());
itemDisEncumber = encumbranceQuantityChange.multiply(new KualiDecimal(poItem.getItemUnitPrice()));
// add tax for encumbrance
KualiDecimal itemTaxAmount = poItem.getItemTaxAmount() == null ? ZERO : poItem.getItemTaxAmount();
KualiDecimal encumbranceTaxAmount = encumbranceQuantityChange.divide(poItem.getItemQuantity()).multiply(itemTaxAmount);
itemDisEncumber = itemDisEncumber.add(encumbranceTaxAmount);
itemAlterInvoiceAmt = cmItemTotalAmount;
itemAlterInvoiceAmt = itemAlterInvoiceAmt.multiply(new KualiDecimal("-1"));
} else {
LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " Calculate encumbrance based on amount");
// Do encumbrance calculations based on amount only
// Decrease encumbrance
itemDisEncumber = cmItemTotalAmount.multiply(new KualiDecimal("-1"));
if (poItem.getItemOutstandingEncumberedAmount().add(itemDisEncumber).doubleValue() < 0) {
LOG.debug("getCreditMemoEncumbrance() Cancel overflow");
itemDisEncumber = poItem.getItemOutstandingEncumberedAmount();
}
itemAlterInvoiceAmt = itemDisEncumber;
}
// alter the encumbrance based on what was originally encumbered
poItem.setItemOutstandingEncumberedAmount(poItem.getItemOutstandingEncumberedAmount().add(itemDisEncumber));
// alter the invoiced amt based on what was actually credited on the credit memo
poItem.setItemInvoicedTotalAmount(poItem.getItemInvoicedTotalAmount().subtract(itemAlterInvoiceAmt));
if (poItem.getItemInvoicedTotalAmount().compareTo(ZERO) < 0) {
poItem.setItemInvoicedTotalAmount(ZERO);
}
LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " Amount to disencumber: " + itemDisEncumber);
// Sort accounts
Collections.sort((List) poItem.getSourceAccountingLines());
// make the list of accounts for the disencumbrance entry
PurchaseOrderAccount lastAccount = null;
KualiDecimal accountTotal = ZERO;
// Collections.sort((List)poItem.getSourceAccountingLines());
for (Iterator accountIter = poItem.getSourceAccountingLines().iterator(); accountIter.hasNext(); ) {
PurchaseOrderAccount account = (PurchaseOrderAccount) accountIter.next();
if (!account.isEmpty()) {
KualiDecimal encumbranceAmount = null;
SourceAccountingLine acctString = account.generateSourceAccountingLine();
// amount = item disencumber * account percent / 100
encumbranceAmount = itemDisEncumber.multiply(new KualiDecimal(account.getAccountLinePercent().toString())).divide(new KualiDecimal(100));
account.setItemAccountOutstandingEncumbranceAmount(account.getItemAccountOutstandingEncumbranceAmount().add(encumbranceAmount));
// For rounding check at the end
accountTotal = accountTotal.add(encumbranceAmount);
lastAccount = account;
LOG.debug("getCreditMemoEncumbrance() " + logItmNbr + " " + acctString + " = " + encumbranceAmount);
if (encumbranceAccountMap.get(acctString) == null) {
encumbranceAccountMap.put(acctString, encumbranceAmount);
} else {
KualiDecimal amt = (KualiDecimal) encumbranceAccountMap.get(acctString);
encumbranceAccountMap.put(acctString, amt.add(encumbranceAmount));
}
}
}
// account for rounding by adjusting last account as needed
if (lastAccount != null) {
KualiDecimal difference = itemDisEncumber.subtract(accountTotal);
LOG.debug("getCreditMemoEncumbrance() difference: " + logItmNbr + " " + difference);
SourceAccountingLine acctString = lastAccount.generateSourceAccountingLine();
KualiDecimal amount = (KualiDecimal) encumbranceAccountMap.get(acctString);
if (amount == null) {
encumbranceAccountMap.put(acctString, difference);
} else {
encumbranceAccountMap.put(acctString, amount.add(difference));
}
lastAccount.setItemAccountOutstandingEncumbranceAmount(lastAccount.getItemAccountOutstandingEncumbranceAmount().add(difference));
}
}
}
List<SourceAccountingLine> encumbranceAccounts = new ArrayList();
for (Iterator iter = encumbranceAccountMap.keySet().iterator(); iter.hasNext(); ) {
SourceAccountingLine acctString = (SourceAccountingLine) iter.next();
KualiDecimal amount = (KualiDecimal) encumbranceAccountMap.get(acctString);
if (amount.doubleValue() != 0) {
acctString.setAmount(amount);
encumbranceAccounts.add(acctString);
}
}
return encumbranceAccounts;
}
use of org.kuali.kfs.sys.businessobject.SourceAccountingLine 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.sys.businessobject.SourceAccountingLine in project cu-kfs by CU-CommunityApps.
the class CuPurapAccountingServiceImpl method isFiscalOfficersForAllAcctLines.
public boolean isFiscalOfficersForAllAcctLines(PurchasingAccountsPayableDocument document) {
boolean isFoForAcctLines = true;
String personId = GlobalVariables.getUserSession().getPrincipalId();
for (SourceAccountingLine accountingLine : (List<SourceAccountingLine>) document.getSourceAccountingLines()) {
List<String> fiscalOfficers = new ArrayList<String>();
Map<String, String> roleQualifier = new HashMap<String, String>();
// KFSPTS-1273 : this method is final, so can't be overriden by REQ Auth. This is a fix for REQ existing issue. a broader solution need more work.
// the authorizer is called by validation rule and rendertag, so has to do it here. otherwise the invalid account will be saved.
boolean isExistingReqAcctline = false;
String updatedAccountNumber = KFSConstants.EMPTY_STRING;
if (accountingLine instanceof RequisitionAccount && ((RequisitionAccount) accountingLine).getAccountIdentifier() != null) {
RequisitionAccount dbAcctLine = (RequisitionAccount) getAccountFromDb((RequisitionAccount) accountingLine, RequisitionAccount.class);
if (dbAcctLine != null && !StringUtils.equals(accountingLine.getAccountNumber(), dbAcctLine.getAccountNumber())) {
updatedAccountNumber = accountingLine.getAccountNumber();
accountingLine.setAccountNumber(dbAcctLine.getAccountNumber());
isExistingReqAcctline = true;
}
}
if (accountingLine instanceof PurchaseOrderAccount && ((PurchaseOrderAccount) accountingLine).getAccountIdentifier() != null) {
PurchaseOrderAccount dbAcctLine = (PurchaseOrderAccount) getAccountFromDb((PurchaseOrderAccount) accountingLine, PurchaseOrderAccount.class);
if (dbAcctLine != null && !StringUtils.equals(accountingLine.getAccountNumber(), dbAcctLine.getAccountNumber())) {
updatedAccountNumber = accountingLine.getAccountNumber();
accountingLine.setAccountNumber(dbAcctLine.getAccountNumber());
isExistingReqAcctline = true;
}
}
if (accountingLine instanceof PaymentRequestAccount && ((PaymentRequestAccount) accountingLine).getAccountIdentifier() != null) {
PaymentRequestAccount dbAcctLine = (PaymentRequestAccount) getAccountFromDb((PaymentRequestAccount) accountingLine, PaymentRequestAccount.class);
if (dbAcctLine != null && !StringUtils.equals(accountingLine.getAccountNumber(), dbAcctLine.getAccountNumber())) {
updatedAccountNumber = accountingLine.getAccountNumber();
accountingLine.setAccountNumber(dbAcctLine.getAccountNumber());
isExistingReqAcctline = true;
}
}
roleQualifier.put(KimConstants.AttributeConstants.DOCUMENT_NUMBER, document.getDocumentNumber());
roleQualifier.put(KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
roleQualifier.put(KfsKimAttributes.FINANCIAL_DOCUMENT_TOTAL_AMOUNT, document.getFinancialSystemDocumentHeader().getFinancialDocumentTotalAmount().toString());
roleQualifier.put(KfsKimAttributes.CHART_OF_ACCOUNTS_CODE, accountingLine.getChartOfAccountsCode());
roleQualifier.put(KfsKimAttributes.ACCOUNT_NUMBER, accountingLine.getAccountNumber());
fiscalOfficers.addAll(SpringContext.getBean(RoleService.class).getRoleMemberPrincipalIds(KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimApiConstants.FISCAL_OFFICER_KIM_ROLE_NAME, roleQualifier));
if (!fiscalOfficers.contains(personId)) {
fiscalOfficers.addAll(SpringContext.getBean(RoleService.class).getRoleMemberPrincipalIds(KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimApiConstants.FISCAL_OFFICER_PRIMARY_DELEGATE_KIM_ROLE_NAME, roleQualifier));
}
if (!fiscalOfficers.contains(personId)) {
fiscalOfficers.addAll(SpringContext.getBean(RoleService.class).getRoleMemberPrincipalIds(KFSConstants.ParameterNamespaces.KFS, KFSConstants.SysKimApiConstants.FISCAL_OFFICER_SECONDARY_DELEGATE_KIM_ROLE_NAME, roleQualifier));
}
if (isExistingReqAcctline) {
accountingLine.setAccountNumber(updatedAccountNumber);
}
if (!fiscalOfficers.contains(personId)) {
isFoForAcctLines = false;
break;
}
}
return isFoForAcctLines;
}
Aggregations