use of org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount in project cu-kfs by CU-CommunityApps.
the class CuPurapAccountingServiceImplTest method testUpdateAccountAmounts_AccountingLinePercentChanged.
public void testUpdateAccountAmounts_AccountingLinePercentChanged() throws Exception {
changeCurrentUser(UserNameFixture.ccs1);
// Save the requisition with items, but without accounting lines and then add the accounting lines and save again
// This odd methodology is to workaround an NPE that occurs when access security is enabled and refreshNonUpdatableReferences
// is called on the account. For some reason the RequisitionItem cannot be found in ojb's cache and so when
// it is attempted to be instantiated and constructor methods called, an NPE is thrown. This little dance works around the exception.
// More analysis could probably be done to determine the root cause and address it, but for now this is good enough.
RequisitionDocument requisitionDocument = RequisitionFixture.REQ_NON_B2B_WITH_ITEMS.createRequisition(documentService);
requisitionDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(new KualiDecimal(200));
RequisitionItem item = RequisitionItemFixture.REQ_ITEM3.createRequisitionItem(false);
requisitionDocument.addItem(item);
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
requisitionDocument.refreshNonUpdateableReferences();
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
PurchaseOrderDocument purchaseOrderDocument = (PurchaseOrderDocument) documentService.getNewDocument(PurchaseOrderDocument.class);
purchaseOrderDocument.populatePurchaseOrderFromRequisition(requisitionDocument);
purchaseOrderDocument.setContractManagerCode(10);
purchaseOrderDocument.setPurchaseOrderCurrentIndicator(true);
purchaseOrderDocument.getDocumentHeader().setDocumentDescription("Description");
purchaseOrderDocument.setApplicationDocumentStatus(PurchaseOrderStatuses.APPDOC_OPEN);
purchaseOrderDocument.refreshNonUpdateableReferences();
purchaseOrderDocument.setVendorShippingPaymentTermsCode("AL");
purchaseOrderDocument.setVendorPaymentTermsCode("00N30");
purchaseOrderDocument.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(purchaseOrderDocument, documentService);
changeCurrentUser(UserNameFixture.mo14);
PaymentRequestDocument paymentRequestDocument = PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(purchaseOrderDocument.getPurapDocumentIdentifier());
paymentRequestDocument.initiateDocument();
paymentRequestDocument.populatePaymentRequestFromPurchaseOrder(purchaseOrderDocument);
paymentRequestDocument.setApplicationDocumentStatus(PurapConstants.PaymentRequestStatuses.APPDOC_AWAITING_FISCAL_REVIEW);
paymentRequestDocument.getItem(0).setExtendedPrice(new KualiDecimal(1));
paymentRequestDocument.getItem(1).setExtendedPrice(new KualiDecimal(4));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).setAmount(new KualiDecimal(3));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(1))).setAmount(new KualiDecimal(1));
cuPurapAccountingServiceImpl.updateAccountAmounts(paymentRequestDocument);
assertEquals(new BigDecimal(75).setScale(2), ((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).getAccountLinePercent());
}
use of org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount in project cu-kfs by CU-CommunityApps.
the class CuPurapAccountingServiceImplTest method testUpdateAccountAmounts_AccountingLinePercentUnchanged.
public void testUpdateAccountAmounts_AccountingLinePercentUnchanged() throws Exception {
changeCurrentUser(UserNameFixture.ccs1);
// Save the requisition with items, but without accounting lines and then add the accounting lines and save again
// This odd methodology is to workaround an NPE that occurs when access security is enabled and refreshNonUpdatableReferences
// is called on the account. For some reason the RequisitionItem cannot be found in ojb's cache and so when
// it is attempted to be instantiated and constructor methods called, an NPE is thrown. This little dance works around the exception.
// More analysis could probably be done to determine the root cause and address it, but for now this is good enough.
RequisitionDocument requisitionDocument = RequisitionFixture.REQ_NON_B2B_WITH_ITEMS.createRequisition(documentService);
requisitionDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(new KualiDecimal(200));
RequisitionItem item = RequisitionItemFixture.REQ_ITEM3.createRequisitionItem(false);
requisitionDocument.addItem(item);
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
requisitionDocument.refreshNonUpdateableReferences();
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.getSourceAccountingLines().add(PurapAccountingLineFixture.REQ_ITEM_ACCT_LINE3.createRequisitionAccount(item.getItemIdentifier()));
item.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(requisitionDocument, documentService);
PurchaseOrderDocument purchaseOrderDocument = (PurchaseOrderDocument) documentService.getNewDocument(PurchaseOrderDocument.class);
purchaseOrderDocument.populatePurchaseOrderFromRequisition(requisitionDocument);
purchaseOrderDocument.setContractManagerCode(10);
purchaseOrderDocument.setPurchaseOrderCurrentIndicator(true);
purchaseOrderDocument.getDocumentHeader().setDocumentDescription("Description");
purchaseOrderDocument.setApplicationDocumentStatus(PurchaseOrderStatuses.APPDOC_OPEN);
purchaseOrderDocument.refreshNonUpdateableReferences();
purchaseOrderDocument.setVendorShippingPaymentTermsCode("AL");
purchaseOrderDocument.setVendorPaymentTermsCode("00N30");
purchaseOrderDocument.refreshNonUpdateableReferences();
AccountingDocumentTestUtils.saveDocument(purchaseOrderDocument, documentService);
changeCurrentUser(UserNameFixture.mo14);
PaymentRequestDocument paymentRequestDocument = PaymentRequestFixture.PAYMENT_REQ_DOC.createPaymentRequestDocument(purchaseOrderDocument.getPurapDocumentIdentifier());
paymentRequestDocument.initiateDocument();
paymentRequestDocument.populatePaymentRequestFromPurchaseOrder(purchaseOrderDocument);
paymentRequestDocument.setApplicationDocumentStatus(PurapConstants.PaymentRequestStatuses.APPDOC_IN_PROCESS);
paymentRequestDocument.getItem(0).setExtendedPrice(new KualiDecimal(1));
paymentRequestDocument.getItem(1).setExtendedPrice(new KualiDecimal(4));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).setAmount(new KualiDecimal(3));
((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(1))).setAmount(new KualiDecimal(1));
cuPurapAccountingServiceImpl.updateAccountAmounts(paymentRequestDocument);
assertEquals(new BigDecimal(50).setScale(2), ((PaymentRequestAccount) (((PaymentRequestItem) paymentRequestDocument.getItems().get(1)).getSourceAccountingLine(0))).getAccountLinePercent());
}
use of org.kuali.kfs.module.purap.businessobject.PaymentRequestAccount 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