use of org.kuali.kfs.sys.businessobject.SourceAccountingLine in project cu-kfs by CU-CommunityApps.
the class AmazonWebServicesBillingServiceImpl method buildFromAccountLine.
private SourceAccountingLine buildFromAccountLine(String diDocumentNumber, KualiDecimal amount) {
SourceAccountingLine line = new SourceAccountingLine();
Account fromAccount = findAccountFromAccountNumber(getTransactionFromAccountNumber());
line.setDocumentNumber(diDocumentNumber);
line.setAccountNumber(fromAccount.getAccountNumber());
line.setChartOfAccountsCode(fromAccount.getChartOfAccountsCode());
line.setFinancialObjectCode(getTransactionObjectCode());
line.setAmount(amount);
line.setFinancialDocumentLineDescription(buildAccountingLineDescription());
line.setSequenceNumber(new Integer(1));
return line;
}
use of org.kuali.kfs.sys.businessobject.SourceAccountingLine 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.sys.businessobject.SourceAccountingLine in project cu-kfs by CU-CommunityApps.
the class CuPendingTransactionServiceImpl method reencumberEncumbrance.
/**
* 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 preq PREQ for invoice
* @return List of accounting lines to use to create the pending general ledger entries
*/
protected List<SourceAccountingLine> reencumberEncumbrance(PaymentRequestDocument preq) {
LOG.debug("reencumberEncumbrance() started");
PurchaseOrderDocument po = SpringContext.getBean(PurchaseOrderService.class).getCurrentPurchaseOrder(preq.getPurchaseOrderIdentifier());
Map encumbranceAccountMap = new HashMap();
// Get each item one by one
for (Iterator items = preq.getItems().iterator(); items.hasNext(); ) {
PaymentRequestItem payRequestItem = (PaymentRequestItem) items.next();
PurchaseOrderItem poItem = getPoItem(po, payRequestItem.getItemLineNumber(), payRequestItem.getItemType());
// Amount to reencumber for this item
KualiDecimal itemReEncumber = null;
String logItmNbr = "Item # " + payRequestItem.getItemLineNumber();
LOG.debug("reencumberEncumbrance() " + logItmNbr);
// If there isn't a PO item or the total amount is 0, we don't need encumbrances
final KualiDecimal preqItemTotalAmount = (payRequestItem.getTotalAmount() == null) ? KualiDecimal.ZERO : payRequestItem.getTotalAmount();
if ((poItem == null) || (preqItemTotalAmount.doubleValue() == 0)) {
LOG.debug("reencumberEncumbrance() " + logItmNbr + " No encumbrances required");
} else {
LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance GL entries");
// Do we calculate the encumbrance amount based on quantity or amount?
if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) {
LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on quantity");
// Do disencumbrance calculations based on quantity
KualiDecimal preqQuantity = payRequestItem.getItemQuantity() == null ? ZERO : payRequestItem.getItemQuantity();
KualiDecimal outstandingEncumberedQuantity = poItem.getItemOutstandingEncumberedQuantity() == null ? ZERO : poItem.getItemOutstandingEncumberedQuantity();
KualiDecimal invoicedTotal = poItem.getItemInvoicedTotalQuantity() == null ? ZERO : poItem.getItemInvoicedTotalQuantity();
poItem.setItemInvoicedTotalQuantity(invoicedTotal.subtract(preqQuantity));
poItem.setItemOutstandingEncumberedQuantity(outstandingEncumberedQuantity.add(preqQuantity));
itemReEncumber = preqQuantity.multiply(new KualiDecimal(poItem.getItemUnitPrice()));
// add tax for encumbrance
KualiDecimal itemTaxAmount = poItem.getItemTaxAmount() == null ? ZERO : poItem.getItemTaxAmount();
KualiDecimal encumbranceTaxAmount = preqQuantity.divide(poItem.getItemQuantity()).multiply(itemTaxAmount);
itemReEncumber = itemReEncumber.add(encumbranceTaxAmount);
} else {
LOG.debug("reencumberEncumbrance() " + logItmNbr + " Calculate encumbrance based on amount");
itemReEncumber = preqItemTotalAmount;
// this prevents negative encumbrance
if ((poItem.getTotalAmount() != null) && (poItem.getTotalAmount().bigDecimalValue().signum() < 0)) {
// po item extended cost is negative
if ((poItem.getTotalAmount().compareTo(itemReEncumber)) > 0) {
itemReEncumber = poItem.getTotalAmount();
}
} else if ((poItem.getTotalAmount() != null) && (poItem.getTotalAmount().bigDecimalValue().signum() >= 0)) {
// po item extended cost is positive
if ((poItem.getTotalAmount().compareTo(itemReEncumber)) < 0) {
itemReEncumber = poItem.getTotalAmount();
}
}
}
LOG.debug("reencumberEncumbrance() " + logItmNbr + " Amount to reencumber: " + itemReEncumber);
KualiDecimal outstandingEncumberedAmount = poItem.getItemOutstandingEncumberedAmount() == null ? ZERO : poItem.getItemOutstandingEncumberedAmount();
LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Outstanding Encumbrance Amount set to: " + outstandingEncumberedAmount);
KualiDecimal newOutstandingEncumberedAmount = outstandingEncumberedAmount.add(itemReEncumber);
LOG.debug("reencumberEncumbrance() " + logItmNbr + " New PO Item Outstanding Encumbrance Amount to set: " + newOutstandingEncumberedAmount);
poItem.setItemOutstandingEncumberedAmount(newOutstandingEncumberedAmount);
KualiDecimal invoicedTotalAmount = poItem.getItemInvoicedTotalAmount() == null ? ZERO : poItem.getItemInvoicedTotalAmount();
LOG.debug("reencumberEncumbrance() " + logItmNbr + " PO Item Invoiced Total Amount set to: " + invoicedTotalAmount);
KualiDecimal newInvoicedTotalAmount = invoicedTotalAmount.subtract(preqItemTotalAmount);
LOG.debug("reencumberEncumbrance() " + logItmNbr + " New PO Item Invoiced Total Amount to set: " + newInvoicedTotalAmount);
poItem.setItemInvoicedTotalAmount(newInvoicedTotalAmount);
// make the list of accounts for the reencumbrance entry
PurchaseOrderAccount lastAccount = null;
KualiDecimal accountTotal = ZERO;
// Sort accounts
Collections.sort((List) poItem.getSourceAccountingLines());
for (Iterator accountIter = poItem.getSourceAccountingLines().iterator(); accountIter.hasNext(); ) {
PurchaseOrderAccount account = (PurchaseOrderAccount) accountIter.next();
if (!account.isEmpty()) {
SourceAccountingLine acctString = account.generateSourceAccountingLine();
// amount = item reencumber * account percent / 100
KualiDecimal reencumbranceAmount = itemReEncumber.multiply(new KualiDecimal(account.getAccountLinePercent().toString())).divide(HUNDRED);
account.setItemAccountOutstandingEncumbranceAmount(account.getItemAccountOutstandingEncumbranceAmount().add(reencumbranceAmount));
// For rounding check at the end
accountTotal = accountTotal.add(reencumbranceAmount);
lastAccount = account;
LOG.debug("reencumberEncumbrance() " + logItmNbr + " " + acctString + " = " + reencumbranceAmount);
if (encumbranceAccountMap.containsKey(acctString)) {
KualiDecimal currentAmount = (KualiDecimal) encumbranceAccountMap.get(acctString);
encumbranceAccountMap.put(acctString, reencumbranceAmount.add(currentAmount));
} else {
encumbranceAccountMap.put(acctString, reencumbranceAmount);
}
}
}
// account for rounding by adjusting last account as needed
if (lastAccount != null) {
KualiDecimal difference = itemReEncumber.subtract(accountTotal);
LOG.debug("reencumberEncumbrance() 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<SourceAccountingLine>();
for (Iterator<SourceAccountingLine> 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 CuAutoDisapproveDocumentsServiceImpl method buildSuccessMessage.
private String buildSuccessMessage(Document document) throws Exception {
StringBuilder headerBuilder = new StringBuilder();
headerBuilder.append(document.getDocumentNumber());
headerBuilder.append(TAB);
headerBuilder.append(document.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
headerBuilder.append(TAB);
headerBuilder.append(document.getDocumentHeader().getDocumentDescription());
headerBuilder.append(TAB);
headerBuilder.append(personService.getPerson(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId()).getPrincipalName());
headerBuilder.append(TAB);
headerBuilder.append(personService.getPerson(document.getDocumentHeader().getWorkflowDocument().getInitiatorPrincipalId()).getName());
headerBuilder.append(TAB);
headerBuilder.append(document.getDocumentHeader().getWorkflowDocument().getDateCreated());
headerBuilder.append(TAB);
ConfigurationService k = KRADServiceLocator.getKualiConfigurationService();
StringBuilder routeBuilder = new StringBuilder();
String url = k.getPropertyValueAsString("workflow.url");
routeBuilder.append(url);
routeBuilder.append("/RouteLog.do?routeHeaderId=");
routeBuilder.append(document.getDocumentNumber());
routeBuilder.append(TAB);
headerBuilder.append(routeBuilder);
List<ActionTaken> actions;
// try {
// actions = KEWServiceLocator.getActionTakenService().findByDocumentId(document.getDocumentHeader().getWorkflowDocument().getDocumentId());
actions = KewApiServiceLocator.getWorkflowDocumentService().getAllActionsTaken(document.getDocumentNumber());
ActionTaken max = null;
for (ActionTaken at : actions) {
if (ObjectUtils.isNull(max)) {
max = at;
} else if (at.getActionDate().compareTo(max.getActionDate()) > 0) {
max = at;
}
}
headerBuilder.append(personService.getPerson(max.getPrincipalId()).getPrincipalName());
headerBuilder.append(TAB);
headerBuilder.append(personService.getPerson(max.getPrincipalId()).getName());
headerBuilder.append(TAB);
headerBuilder.append(max.getActionDate());
headerBuilder.append(TAB);
headerBuilder.append(max.getActionTaken().getLabel());
headerBuilder.append(TAB);
// } catch (WorkflowException e) {
// e.printStackTrace();
// }
String headerString = headerBuilder.toString();
StringBuilder builder = new StringBuilder();
if (document instanceof AccountingDocumentBase) {
for (Object o : ((AccountingDocumentBase) document).getSourceAccountingLines()) {
SourceAccountingLine sal = (SourceAccountingLine) o;
builder.append(headerString);
builder.append(sal.getChartOfAccountsCode());
builder.append(TAB);
builder.append(sal.getAccountNumber());
builder.append(TAB);
builder.append(sal.getAmount());
builder.append(TAB);
builder.append(sal.getAccount().getOrganizationCode());
builder.append(TAB);
builder.append(KFSConstants.NEWLINE);
}
for (Object o : ((AccountingDocumentBase) document).getTargetAccountingLines()) {
TargetAccountingLine tal = (TargetAccountingLine) o;
builder.append(headerString);
builder.append(tal.getChartOfAccountsCode());
builder.append(TAB);
builder.append(tal.getAccountNumber());
builder.append(TAB);
builder.append(tal.getAmount());
builder.append(TAB);
builder.append(tal.getAccount().getOrganizationCode());
builder.append(TAB);
builder.append(KFSConstants.NEWLINE);
}
}
return builder.toString();
}
use of org.kuali.kfs.sys.businessobject.SourceAccountingLine in project cu-kfs by CU-CommunityApps.
the class DebitDeterminerServiceImplTest method test.
public void test() {
CuDisbursementVoucherDocument dv = null;
try {
dv = (CuDisbursementVoucherDocument) SpringContext.getBean(DocumentService.class).getNewDocument(DisbursementVoucherDocument.class);
} catch (WorkflowException e) {
throw new RuntimeException("Error creating new disbursement voucher document: " + e.getMessage(), e);
}
if (dv != null) {
dv.getDocumentHeader().setDocumentDescription("Test Document Description");
dv.getDocumentHeader().setExplanation("Stuff");
dv.initiateDocument();
VendorDetail vendor = SpringContext.getBean(VendorService.class).getVendorDetail("13366-0");
VendorAddress vendoraddress = SpringContext.getBean(VendorService.class).getVendorDefaultAddress(vendor.getVendorHeaderGeneratedIdentifier(), vendor.getVendorDetailAssignedIdentifier(), "RM", "");
System.out.println(vendoraddress.getVendorCityName() + "\n");
dv.templateVendor(vendor, vendoraddress);
dv.setPayeeAssigned(true);
dv.getDvPayeeDetail().setDisbVchrPaymentReasonCode("S");
dv.setDisbVchrCheckTotalAmount(new KualiDecimal(86.00));
dv.setDisbVchrPaymentMethodCode("P");
dv.setDisbVchrCheckStubText("check text");
SourceAccountingLine accountingLine = new SourceAccountingLine();
accountingLine.setChartOfAccountsCode("IT");
accountingLine.setAccountNumber("G081040");
accountingLine.setFinancialObjectCode("2045");
accountingLine.setAmount((new KualiDecimal(-14.00)));
accountingLine.setPostingYear(dv.getPostingYear());
accountingLine.setDocumentNumber(dv.getDocumentNumber());
dv.addSourceAccountingLine(accountingLine);
SourceAccountingLine accountingLine2 = new SourceAccountingLine();
accountingLine2.setChartOfAccountsCode("IT");
accountingLine2.setAccountNumber("1453611");
accountingLine2.setFinancialObjectCode("8462");
accountingLine2.setAmount((new KualiDecimal(100.00)));
accountingLine2.setPostingYear(dv.getPostingYear());
accountingLine2.setDocumentNumber(dv.getDocumentNumber());
dv.addSourceAccountingLine(accountingLine2);
try {
documentService.saveDocument(dv);
} catch (WorkflowException e) {
throw new RuntimeException("Error saving new disbursement voucher document: " + e.getMessage(), e);
}
}
List<GeneralLedgerPendingEntrySourceDetail> glpeS = dv.getGeneralLedgerPendingEntrySourceDetails();
GeneralLedgerPendingEntrySourceDetail postable = glpeS.get(0);
System.out.println("GL Detail" + postable.toString() + "\n");
assertFalse(debitDeterminerService.isDebitConsideringNothingPositiveOnly(dv, postable));
}
Aggregations