use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class CustomerInvoiceDetailServiceImpl method getCustomerInvoiceDetailFromCustomerInvoiceItemCode.
@Override
public CustomerInvoiceDetail getCustomerInvoiceDetailFromCustomerInvoiceItemCode(String invoiceItemCode, String chartOfAccountsCode, String organizationCode) {
Map<String, String> criteria = new HashMap<>();
criteria.put("invoiceItemCode", invoiceItemCode);
criteria.put("chartOfAccountsCode", chartOfAccountsCode);
criteria.put("organizationCode", organizationCode);
CustomerInvoiceItemCode customerInvoiceItemCode = businessObjectService.findByPrimaryKey(CustomerInvoiceItemCode.class, criteria);
CustomerInvoiceDetail customerInvoiceDetail = null;
if (ObjectUtils.isNotNull(customerInvoiceItemCode)) {
customerInvoiceDetail = new CustomerInvoiceDetail();
customerInvoiceDetail.setChartOfAccountsCode(customerInvoiceItemCode.getDefaultInvoiceChartOfAccountsCode());
customerInvoiceDetail.setAccountNumber(customerInvoiceItemCode.getDefaultInvoiceAccountNumber());
customerInvoiceDetail.setSubAccountNumber(customerInvoiceItemCode.getDefaultInvoiceSubAccountNumber());
customerInvoiceDetail.setFinancialObjectCode(customerInvoiceItemCode.getDefaultInvoiceFinancialObjectCode());
customerInvoiceDetail.setFinancialSubObjectCode(customerInvoiceItemCode.getDefaultInvoiceFinancialSubObjectCode());
customerInvoiceDetail.setProjectCode(customerInvoiceItemCode.getDefaultInvoiceProjectCode());
customerInvoiceDetail.setOrganizationReferenceId(customerInvoiceItemCode.getDefaultInvoiceOrganizationReferenceIdentifier());
customerInvoiceDetail.setInvoiceItemCode(customerInvoiceItemCode.getInvoiceItemCode());
customerInvoiceDetail.setInvoiceItemDescription(customerInvoiceItemCode.getInvoiceItemDescription());
customerInvoiceDetail.setInvoiceItemUnitPrice(customerInvoiceItemCode.getItemDefaultPrice());
customerInvoiceDetail.setInvoiceItemUnitOfMeasureCode(customerInvoiceItemCode.getDefaultUnitOfMeasureCode());
customerInvoiceDetail.setInvoiceItemQuantity(customerInvoiceItemCode.getItemDefaultQuantity());
customerInvoiceDetail.setTaxableIndicator(customerInvoiceItemCode.isTaxableIndicator());
// TODO set sales tax accordingly
customerInvoiceDetail.setInvoiceItemTaxAmount(new KualiDecimal(0.00));
// set amount = unit price * quantity
customerInvoiceDetail.updateAmountBasedOnQuantityAndUnitPrice();
}
return customerInvoiceDetail;
}
use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method containsIdentical.
protected boolean containsIdentical(CustomerInvoiceDetail customerInvoiceDetail, KualiDecimal amountApplied, List<InvoicePaidApplied> invoicePaidApplieds) {
boolean identicalFlag = false;
String custRefInvoiceDocNumber = customerInvoiceDetail.getDocumentNumber();
Integer custInvoiceSequenceNumber = customerInvoiceDetail.getInvoiceItemNumber();
for (InvoicePaidApplied invoicePaidApplied : invoicePaidApplieds) {
String refInvoiceDocNumber = invoicePaidApplied.getFinancialDocumentReferenceInvoiceNumber();
Integer invoiceSequenceNumber = invoicePaidApplied.getInvoiceItemNumber();
KualiDecimal appliedAmount = invoicePaidApplied.getInvoiceItemAppliedAmount();
if (custRefInvoiceDocNumber.equals(refInvoiceDocNumber) && custInvoiceSequenceNumber.equals(invoiceSequenceNumber) && amountApplied.equals(appliedAmount)) {
identicalFlag = true;
break;
}
}
return identicalFlag;
}
use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method applyUnapplied.
protected NonAppliedHolding applyUnapplied(PaymentApplicationForm payAppForm) throws WorkflowException {
PaymentApplicationDocument payAppDoc = payAppForm.getPaymentApplicationDocument();
KualiDecimal amount = payAppForm.getNonAppliedHoldingAmount();
// validate the customer number in the unapplied
if (StringUtils.isNotBlank(payAppForm.getNonAppliedHoldingCustomerNumber())) {
Map<String, String> pkMap = new HashMap<>();
pkMap.put(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER, payAppForm.getNonAppliedHoldingCustomerNumber().toUpperCase(Locale.US));
int found = getBusinessObjectService().countMatching(Customer.class, pkMap);
if (found == 0) {
addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.UNAPPLIED_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.UNAPPLIED_CUSTOMER_NUMBER, ArKeyConstants.PaymentApplicationDocumentErrors.ENTERED_INVOICE_CUSTOMER_NUMBER_INVALID);
return null;
}
// force customer number to upper
payAppForm.setNonAppliedHoldingCustomerNumber(payAppForm.getNonAppliedHoldingCustomerNumber().toUpperCase(Locale.US));
}
// validate the amount in the unapplied
if (payAppForm.getNonAppliedHoldingAmount() != null && payAppForm.getNonAppliedHoldingAmount().isNegative()) {
addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.UNAPPLIED_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.UNAPPLIED_AMOUNT, ArKeyConstants.PaymentApplicationDocumentErrors.UNAPPLIED_AMOUNT_CANNOT_BE_NEGATIVE);
return null;
}
// if we dont have enough information to make an UnApplied, then do nothing
if (StringUtils.isBlank(payAppForm.getNonAppliedHoldingCustomerNumber()) || amount == null || amount.isZero()) {
payAppDoc.setNonAppliedHolding(null);
return null;
}
// if we already have a NonAppliedHolding on the doc, we want to get that to avoid an OLE, otherwise, we'll
// create a new one
NonAppliedHolding nonAppliedHolding = payAppDoc.getNonAppliedHolding();
if (ObjectUtils.isNull(nonAppliedHolding)) {
nonAppliedHolding = new NonAppliedHolding();
nonAppliedHolding.setCustomerNumber(payAppForm.getNonAppliedHoldingCustomerNumber().toUpperCase(Locale.US));
nonAppliedHolding.setReferenceFinancialDocumentNumber(payAppDoc.getDocumentNumber());
payAppDoc.setNonAppliedHolding(nonAppliedHolding);
}
nonAppliedHolding.setFinancialDocumentLineAmount(amount);
boolean isValid = PaymentApplicationDocumentRuleUtil.validateNonAppliedHolding(payAppDoc, payAppForm.getTotalFromControl());
// check the validation results and return null if there were any errors
if (!isValid) {
return null;
}
return nonAppliedHolding;
}
use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method writeErrorEntryByAward.
protected void writeErrorEntryByAward(ContractsAndGrantsBillingAward award, List<String> validationCategory, PrintStream printStream) throws IOException {
// %15s %18s %20s %19s %15s %18s %23s %18s
if (ObjectUtils.isNotNull(award)) {
KualiDecimal cumulativeExpenses = KualiDecimal.ZERO;
String awardBeginningDate;
String awardEndingDate;
String awardTotalAmount;
String proposalNumber = award.getProposalNumber();
Date beginningDate = award.getAwardBeginningDate();
Date endingDate = award.getAwardEndingDate();
KualiDecimal totalAmount = award.getAwardTotalAmount();
if (ObjectUtils.isNotNull(beginningDate)) {
awardBeginningDate = beginningDate.toString();
} else {
awardBeginningDate = "null award beginning date";
}
if (ObjectUtils.isNotNull(endingDate)) {
awardEndingDate = endingDate.toString();
} else {
awardEndingDate = "null award ending date";
}
if (ObjectUtils.isNotNull(totalAmount) && ObjectUtils.isNotNull(totalAmount.bigDecimalValue())) {
awardTotalAmount = totalAmount.toString();
} else {
awardTotalAmount = "null award total amount";
}
if (CollectionUtils.isEmpty(award.getActiveAwardAccounts())) {
writeToReport(proposalNumber, "", awardBeginningDate, awardEndingDate, awardTotalAmount, cumulativeExpenses.toString(), printStream);
} else {
final SystemOptions systemOptions = optionsService.getCurrentYearOptions();
// calculate cumulativeExpenses
for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
cumulativeExpenses = cumulativeExpenses.add(contractsGrantsInvoiceDocumentService.getBudgetAndActualsForAwardAccount(awardAccount, systemOptions.getActualFinancialBalanceTypeCd()));
}
boolean firstLineFlag = true;
for (ContractsAndGrantsBillingAwardAccount awardAccount : award.getActiveAwardAccounts()) {
if (firstLineFlag) {
writeToReport(proposalNumber, awardAccount.getAccountNumber(), awardBeginningDate, awardEndingDate, awardTotalAmount, cumulativeExpenses.toString(), printStream);
firstLineFlag = false;
} else {
writeToReport("", awardAccount.getAccountNumber(), "", "", "", "", printStream);
}
}
}
}
// To print all the errors from the validation category.
for (String vCat : validationCategory) {
printStream.printf("%s", " " + vCat);
printStream.print("\r\n");
}
printStream.print(REPORT_LINE_DIVIDER);
printStream.print("\r\n");
}
use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method takeAPennyLeaveAPennyCGBStyle.
/**
* If the total of current expenditures within the list of InvoiceDetailAccountObjectCode business objects does
* not meet the amount to target, steal or give a penny from one of those business objects so that it does
*
* @param invoiceDetailAccountObjectCodes a List of InvoiceDetailAccountObjectCode business objects
* @param amountToTarget the amount which the sum of those objects should equal
*/
protected void takeAPennyLeaveAPennyCGBStyle(List<InvoiceDetailAccountObjectCode> invoiceDetailAccountObjectCodes, KualiDecimal amountToTarget) {
if (!CollectionUtils.isEmpty(invoiceDetailAccountObjectCodes)) {
final KualiDecimal currentExpenditureTotal = sumInvoiceDetailAccountObjectCodes(invoiceDetailAccountObjectCodes).getCurrentExpenditures();
if (!currentExpenditureTotal.equals(amountToTarget)) {
final KualiDecimal difference = currentExpenditureTotal.subtract(amountToTarget);
InvoiceDetailAccountObjectCode invoiceDetailAccountObjectCode = findFirstPositiveCurrentExpenditureInvoiceDetailAccountObjectCode(invoiceDetailAccountObjectCodes);
if (invoiceDetailAccountObjectCode != null) {
invoiceDetailAccountObjectCode.setCurrentExpenditures(invoiceDetailAccountObjectCode.getCurrentExpenditures().subtract(difference));
}
}
}
}
Aggregations