use of org.kuali.kfs.core.api.util.type.KualiDecimal in project cu-kfs by CU-CommunityApps.
the class CustomerInvoiceDetailServiceImpl method getCustomerInvoiceDetailFromOrganizationAccountingDefault.
@Override
public CustomerInvoiceDetail getCustomerInvoiceDetailFromOrganizationAccountingDefault(Integer universityFiscalYear, String chartOfAccountsCode, String organizationCode) {
CustomerInvoiceDetail customerInvoiceDetail = new CustomerInvoiceDetail();
Map<String, Object> criteria = new HashMap<>();
criteria.put("universityFiscalYear", universityFiscalYear);
criteria.put("chartOfAccountsCode", chartOfAccountsCode);
criteria.put("organizationCode", organizationCode);
OrganizationAccountingDefault organizationAccountingDefault = businessObjectService.findByPrimaryKey(OrganizationAccountingDefault.class, criteria);
if (ObjectUtils.isNotNull(organizationAccountingDefault)) {
customerInvoiceDetail.setChartOfAccountsCode(organizationAccountingDefault.getDefaultInvoiceChartOfAccountsCode());
customerInvoiceDetail.setAccountNumber(organizationAccountingDefault.getDefaultInvoiceAccountNumber());
customerInvoiceDetail.setSubAccountNumber(organizationAccountingDefault.getDefaultInvoiceSubAccountNumber());
customerInvoiceDetail.setFinancialObjectCode(organizationAccountingDefault.getDefaultInvoiceFinancialObjectCode());
customerInvoiceDetail.setFinancialSubObjectCode(organizationAccountingDefault.getDefaultInvoiceFinancialSubObjectCode());
customerInvoiceDetail.setProjectCode(organizationAccountingDefault.getDefaultInvoiceProjectCode());
customerInvoiceDetail.setOrganizationReferenceId(organizationAccountingDefault.getDefaultInvoiceOrganizationReferenceIdentifier());
}
customerInvoiceDetail.setInvoiceItemTaxAmount(new KualiDecimal(0.00));
customerInvoiceDetail.setInvoiceItemQuantity(new BigDecimal(1));
customerInvoiceDetail.setInvoiceItemUnitOfMeasureCode(ArConstants.CUSTOMER_INVOICE_DETAIL_UOM_DEFAULT);
customerInvoiceDetail.setTaxableIndicator(false);
return customerInvoiceDetail;
}
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 PaymentApplicationAction method doApplicationOfFunds.
protected void doApplicationOfFunds(PaymentApplicationForm paymentApplicationForm) throws WorkflowException {
PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
List<InvoicePaidApplied> invoicePaidApplieds = new ArrayList<>();
// apply invoice detail entries
invoicePaidApplieds.addAll(applyToIndividualCustomerInvoiceDetails(paymentApplicationForm));
// quick-apply invoices
invoicePaidApplieds.addAll(quickApplyToInvoices(paymentApplicationForm, invoicePaidApplieds));
// re-number the paidApplieds internal sequence numbers
int paidAppliedItemNumber = 1;
for (InvoicePaidApplied i : invoicePaidApplieds) {
i.setPaidAppliedItemNumber(paidAppliedItemNumber++);
}
// apply non-Invoiced
NonInvoiced nonInvoiced = applyNonInvoiced(paymentApplicationForm);
// apply non-applied holdings
NonAppliedHolding nonAppliedHolding = applyUnapplied(paymentApplicationForm);
// sum up the paid applieds
KualiDecimal sumOfInvoicePaidApplieds = KualiDecimal.ZERO;
for (InvoicePaidApplied invoicePaidApplied : invoicePaidApplieds) {
KualiDecimal amount = invoicePaidApplied.getInvoiceItemAppliedAmount();
if (null == amount) {
amount = KualiDecimal.ZERO;
}
sumOfInvoicePaidApplieds = sumOfInvoicePaidApplieds.add(amount);
}
// sum up all applieds
KualiDecimal appliedAmount = KualiDecimal.ZERO;
appliedAmount = appliedAmount.add(sumOfInvoicePaidApplieds);
if (null != nonInvoiced && null != nonInvoiced.getFinancialDocumentLineAmount()) {
appliedAmount = appliedAmount.add(nonInvoiced.getFinancialDocumentLineAmount());
}
appliedAmount = appliedAmount.add(paymentApplicationDocument.getSumOfNonAppliedDistributions());
appliedAmount = appliedAmount.add(paymentApplicationDocument.getSumOfNonInvoicedDistributions());
appliedAmount = appliedAmount.add(paymentApplicationDocument.getSumOfNonInvoiceds());
if (null != paymentApplicationDocument.getNonAppliedHoldingAmount()) {
appliedAmount = appliedAmount.add(paymentApplicationDocument.getNonAppliedHoldingAmount());
}
// check that we haven't applied more than our control total
KualiDecimal controlTotalAmount = paymentApplicationForm.getTotalFromControl();
// if the person over-applies, we dont stop them, we just complain
if (appliedAmount.isGreaterThan(controlTotalAmount)) {
addGlobalError(ArKeyConstants.PaymentApplicationDocumentErrors.CANNOT_APPLY_MORE_THAN_CASH_CONTROL_TOTAL_AMOUNT);
}
// swap out the old paidApplieds with the newly generated
paymentApplicationDocument.getInvoicePaidApplieds().clear();
paymentApplicationDocument.getInvoicePaidApplieds().addAll(invoicePaidApplieds);
// NonInvoiced list management
if (null != nonInvoiced) {
paymentApplicationDocument.getNonInvoiceds().add(nonInvoiced);
// re-number the non-invoiced
int nonInvoicedItemNumber = 1;
for (NonInvoiced n : paymentApplicationDocument.getNonInvoiceds()) {
n.setFinancialDocumentLineNumber(nonInvoicedItemNumber++);
n.refreshReferenceObject("chartOfAccounts");
n.refreshReferenceObject("account");
n.refreshReferenceObject("subAccount");
n.refreshReferenceObject("financialObject");
n.refreshReferenceObject("financialSubObject");
n.refreshReferenceObject("project");
}
// make an empty new one
paymentApplicationForm.setNonInvoicedAddLine(new NonInvoiced());
}
// reset the allocations, so it gets re-calculated
paymentApplicationForm.setNonAppliedControlAllocations(null);
// Update the doc total if it is not a CashControl generated PayApp
if (!paymentApplicationDocument.hasCashControlDetail()) {
paymentApplicationDocument.getFinancialSystemDocumentHeader().setFinancialDocumentTotalAmount(appliedAmount);
}
}
Aggregations