use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.
the class PurchasingActionBase method processCustomInsertAccountingLine.
/**
* @see org.kuali.kfs.module.purap.document.web.struts.PurchasingAccountsPayableActionBase#processCustomInsertAccountingLine(PurchasingAccountsPayableFormBase, HttpServletRequest)
*/
@Override
public boolean processCustomInsertAccountingLine(PurchasingAccountsPayableFormBase purapForm, HttpServletRequest request) {
boolean success = false;
PurchasingFormBase purchasingForm = (PurchasingFormBase) purapForm;
// index of item selected
int itemIndex = getSelectedLine(request);
PurApItem item = null;
boolean institutionNeedsDistributeAccountValidation = SpringContext.getBean(ParameterService.class).getParameterValueAsBoolean(KfsParameterConstants.PURCHASING_DOCUMENT.class, PurapParameterConstants.VALIDATE_ACCOUNT_DISTRIBUTION_IND);
if (itemIndex == -2 && !institutionNeedsDistributeAccountValidation) {
PurApAccountingLine line = purchasingForm.getAccountDistributionnewSourceLine();
purchasingForm.addAccountDistributionsourceAccountingLine(line);
success = true;
}
return success;
}
use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.
the class PurchasingActionBase method addFavoriteAccount.
/*
* KFSPTS-985 : add favorite account.
* This is a copy from requisitionaction. to be shared by both req & po
*/
public ActionForward addFavoriteAccount(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
PurchasingFormBase poForm = (PurchasingFormBase) form;
PurchasingDocumentBase document = (PurchasingDocumentBase) poForm.getDocument();
int itemIdx = getSelectedLine(request);
final int DISTRIBUTION_INDEX = -2;
PurchasingFavoriteAccountLineBuilderBase<? extends PurApAccountingLine> favoriteAccountBuilder;
// Initialize the correct builder based on whether the Favorite Account is for an item in the list or for account distribution.
if (itemIdx >= 0) {
PurchasingItemBase item = (PurchasingItemBase) document.getItem(itemIdx);
favoriteAccountBuilder = new PurchasingFavoriteAccountLineBuilderForLineItem<PurApAccountingLine>(item, itemIdx, poForm.setupNewPurchasingAccountingLine());
} else if (itemIdx == DISTRIBUTION_INDEX) {
favoriteAccountBuilder = new PurchasingFavoriteAccountLineBuilderForDistribution<PurApAccountingLine>(document, poForm.getAccountDistributionsourceAccountingLines(), poForm.setupNewAccountDistributionAccountingLine());
} else {
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
// Add a new Favorite-Account-derived accounting line to the list, with errors inserted into the message map as appropriate.
favoriteAccountBuilder.addNewFavoriteAccountLineToListIfPossible();
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.
the class FavoriteAccountLineBuilderTest method assertAccountingLineHasCorrectConfiguration.
/*
* Convenience method for validating that the generated accounting line has the correct data and is of the correct type.
*/
private void assertAccountingLineHasCorrectConfiguration(FavoriteAccount expectedAccount, Class<? extends GeneralLedgerPendingEntrySourceDetail> expectedLineClass, GeneralLedgerPendingEntrySourceDetail acctLine) throws Exception {
if (!expectedLineClass.isAssignableFrom(acctLine.getClass())) {
fail("Expected line type is " + expectedLineClass.getName() + " but the generated line is of type " + acctLine.getClass().getName() + " which is not an instance of the expected one");
}
assertEquals("Generated line has wrong chart code", expectedAccount.getChartOfAccountsCode(), acctLine.getChartOfAccountsCode());
assertEquals("Generated line has wrong account number", expectedAccount.getAccountNumber(), acctLine.getAccountNumber());
assertEquals("Generated line has wrong sub-account number", expectedAccount.getSubAccountNumber(), acctLine.getSubAccountNumber());
assertEquals("Generated line has wrong object code", expectedAccount.getFinancialObjectCode(), acctLine.getFinancialObjectCode());
assertEquals("Generated line has wrong sub-object code", expectedAccount.getFinancialSubObjectCode(), acctLine.getFinancialSubObjectCode());
assertEquals("Generated line has wrong project code", expectedAccount.getProjectCode(), acctLine.getProjectCode());
assertEquals("Generated line has wrong org ref ID", expectedAccount.getOrganizationReferenceId(), acctLine.getOrganizationReferenceId());
// Validate pre-initialized percentage. The retrieval means will vary depending on line type and whether we need hacks to avoid Spring calls.
if (acctLine instanceof RequisitionAccount) {
assertEquals("Generated line has wrong percentage (comparison against 100% should have been zero)", 0, getRequisitionAccountLinePercent(((RequisitionAccount) acctLine)).compareTo(new BigDecimal(100)));
} else if (acctLine instanceof PurApAccountingLine) {
assertEquals("Generated line has wrong percentage (comparison against 100% should have been zero)", 0, ((PurApAccountingLine) acctLine).getAccountLinePercent().compareTo(new BigDecimal(100)));
} else if (acctLine instanceof IWantAccount) {
assertEquals("Generated line has wrong amount-or-percent indicator", CUPurapConstants.PERCENT, ((IWantAccount) acctLine).getUseAmountOrPercent());
assertEquals("Generated line has wrong percentage (comparison against 100% should have been zero)", 0, ((IWantAccount) acctLine).getAmountOrPercent().compareTo(new KualiDecimal(100)));
}
}
use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.
the class FavoriteAccountLineBuilderTest method setUp.
@BeforeClass
public static void setUp() throws Exception {
userProcurementProfileValidationService = new UserProcurementProfileValidationServiceImpl();
userFavoriteAccountService = new ExtendedTestUserFavoriteAccountService();
reqsAccounts = new ArrayList<PurApAccountingLine>();
poAccounts = new ArrayList<PurApAccountingLine>();
reqsItem = new RequisitionItem();
poItem = new PurchaseOrderItem();
reqsDoc = getMockedDocument(CuRequisitionDocument.class);
poDoc = getMockedDocument(PurchaseOrderDocument.class);
iwntDoc = getMockedDocument(IWantDocument.class);
iwntDoc.setAccounts(new ArrayList<IWantAccount>());
// Favorite Account with only some fields populated.
testFavoriteAccount = new FavoriteAccount();
testFavoriteAccount.setAccountLineIdentifier(TEST_FAVORITE_ACCOUNT_LINE_ID);
testFavoriteAccount.setUserProfileId(TEST_USER_PROFILE_ID);
testFavoriteAccount.setChartOfAccountsCode(TEST_CHART_CODE);
testFavoriteAccount.setAccountNumber(TEST_ACCOUNT_NUMBER);
testFavoriteAccount.setFinancialObjectCode(TEST_OBJECT_CODE);
// Favorite Account with all fields populated (except reference objects or object ID or version number).
testAltFavoriteAccount = new FavoriteAccount();
testAltFavoriteAccount.setAccountLineIdentifier(TEST_ALT_FAVORITE_ACCOUNT_LINE_ID);
testAltFavoriteAccount.setUserProfileId(TEST_ALT_USER_PROFILE_ID);
testAltFavoriteAccount.setChartOfAccountsCode(TEST_ALT_CHART_CODE);
testAltFavoriteAccount.setAccountNumber(TEST_ALT_ACCOUNT_NUMBER);
testAltFavoriteAccount.setSubAccountNumber(TEST_ALT_SUB_ACCOUNT_NUMBER);
testAltFavoriteAccount.setFinancialObjectCode(TEST_ALT_OBJECT_CODE);
testAltFavoriteAccount.setFinancialSubObjectCode(TEST_ALT_SUB_OBJECT_CODE);
testAltFavoriteAccount.setProjectCode(TEST_ALT_PROJECT_CODE);
testAltFavoriteAccount.setOrganizationReferenceId(TEST_ALT_ORG_REF_ID);
GlobalVariables.setMessageMap(new MessageMap());
}
use of org.kuali.kfs.module.purap.businessobject.PurApAccountingLine in project cu-kfs by CU-CommunityApps.
the class CuPurapAccountingServiceImpl method updateAccountAmounts.
/**
* @see org.kuali.kfs.module.purap.service.PurapAccountingService#updateAccountAmounts(org.kuali.kfs.module.purap.document.PurchasingAccountsPayableDocument)
*/
@Override
public void updateAccountAmounts(PurchasingAccountsPayableDocument document) {
PurchasingAccountsPayableDocumentBase purApDocument = (PurchasingAccountsPayableDocumentBase) document;
String accountDistributionMethod = purApDocument.getAccountDistributionMethod();
KualiRuleService kualiRuleService = SpringContext.getBean(KualiRuleService.class);
WorkflowDocument workflowDocument = purApDocument.getDocumentHeader().getWorkflowDocument();
Set<String> nodeNames = workflowDocument.getCurrentNodeNames();
// don't update if past the AP review level
if ((document instanceof PaymentRequestDocument) && purapService.isFullDocumentEntryCompleted(document)) {
if (nodeNames.contains(PaymentRequestStatuses.NODE_PAYMENT_METHOD_REVIEW)) {
// CU needs this update because the customization allows Treasury Manager to change unit/extended price and 'calculate'
for (PurApItem item : document.getItems()) {
updatePreqItemAccountAmountsOnly(item);
}
} else {
convertMoneyToPercent((PaymentRequestDocument) document);
}
return;
}
document.fixItemReferences();
// if distribution method is sequential and document is PREQ or VCM then...
if (((document instanceof PaymentRequestDocument) || (document instanceof VendorCreditMemoDocument)) && PurapConstants.AccountDistributionMethodCodes.SEQUENTIAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
if (document instanceof VendorCreditMemoDocument) {
VendorCreditMemoDocument cmDocument = (VendorCreditMemoDocument) document;
cmDocument.updateExtendedPriceOnItems();
for (PurApItem item : document.getItems()) {
for (PurApAccountingLine account : item.getSourceAccountingLines()) {
account.setAmount(KualiDecimal.ZERO);
}
}
}
// update the accounts amounts for PREQ and distribution method = sequential
for (PurApItem item : document.getItems()) {
updatePreqItemAccountAmounts(item);
}
return;
}
// if distribution method is proportional and document is PREQ or VCM then...
if (((document instanceof PaymentRequestDocument) || (document instanceof VendorCreditMemoDocument)) && PurapConstants.AccountDistributionMethodCodes.PROPORTIONAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
// update the accounts amounts for PREQ and distribution method = sequential
if (document instanceof VendorCreditMemoDocument) {
VendorCreditMemoDocument cmDocument = (VendorCreditMemoDocument) document;
cmDocument.updateExtendedPriceOnItems();
for (PurApItem item : document.getItems()) {
for (PurApAccountingLine account : item.getSourceAccountingLines()) {
account.setAmount(KualiDecimal.ZERO);
}
}
}
for (PurApItem item : document.getItems()) {
boolean rulePassed = true;
// check any business rules
rulePassed &= kualiRuleService.applyRules(new PurchasingAccountsPayableItemPreCalculateEvent(document, item));
if (rulePassed) {
updatePreqProportionalItemAccountAmounts(item);
}
}
return;
}
// No recalculate if the account distribution method code is equal to "S" sequential ON REQ or POs..
if (PurapConstants.AccountDistributionMethodCodes.SEQUENTIAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
for (PurApItem item : document.getItems()) {
boolean rulePassed = true;
// check any business rules
rulePassed &= kualiRuleService.applyRules(new PurchasingAccountsPayableItemPreCalculateEvent(document, item));
return;
}
}
// do recalculate only if the account distribution method code is not equal to "S" sequential method.
if (!PurapConstants.AccountDistributionMethodCodes.SEQUENTIAL_CODE.equalsIgnoreCase(accountDistributionMethod)) {
for (PurApItem item : document.getItems()) {
boolean rulePassed = true;
// check any business rules
rulePassed &= kualiRuleService.applyRules(new PurchasingAccountsPayableItemPreCalculateEvent(document, item));
if (rulePassed) {
updateItemAccountAmounts(item);
}
}
}
}
Aggregations