use of org.kuali.kfs.module.ar.businessobject.NonAppliedHolding 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.module.ar.businessobject.NonAppliedHolding 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);
}
}
use of org.kuali.kfs.module.ar.businessobject.NonAppliedHolding in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationForm method getNonAppliedControlHoldings.
public List<NonAppliedHolding> getNonAppliedControlHoldings() {
EntryHolderComparator entryHolderComparator = new EntryHolderComparator();
List<EntryHolder> entryHoldings = new ArrayList<>();
for (NonAppliedHolding nonAppliedControlHolding : nonAppliedControlHoldings) {
entryHoldings.add(new EntryHolder(nonAppliedControlHolding.getDocumentHeader().getWorkflowDocument().getDateCreated().toDate(), nonAppliedControlHolding));
}
if (entryHoldings.size() > 0) {
entryHoldings.sort(entryHolderComparator);
}
List<NonAppliedHolding> results = new ArrayList<>();
for (EntryHolder entryHolder : entryHoldings) {
results.add((NonAppliedHolding) entryHolder.getHolder());
}
return results;
}
use of org.kuali.kfs.module.ar.businessobject.NonAppliedHolding in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method loadInvoices.
/**
* This method loads the invoices for currently selected customer
*
* @param payAppForm
* @param selectedInvoiceNumber
*/
protected void loadInvoices(PaymentApplicationForm payAppForm, String selectedInvoiceNumber) {
PaymentApplicationDocument payAppDoc = payAppForm.getPaymentApplicationDocument();
AccountsReceivableDocumentHeader arDocHeader = payAppDoc.getAccountsReceivableDocumentHeader();
String currentInvoiceNumber = selectedInvoiceNumber;
// entered against the db, and complain to the user if either is not right.
if (StringUtils.isNotBlank(payAppForm.getSelectedCustomerNumber())) {
Map<String, String> pkMap = new HashMap<>();
pkMap.put(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER, payAppForm.getSelectedCustomerNumber());
int found = getBusinessObjectService().countMatching(Customer.class, pkMap);
if (found == 0) {
addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.ENTERED_INVOICE_CUSTOMER_NUMBER, ArKeyConstants.PaymentApplicationDocumentErrors.ENTERED_INVOICE_CUSTOMER_NUMBER_INVALID);
}
}
boolean validInvoice = this.isValidInvoice(payAppForm);
if (!validInvoice) {
addFieldError(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB, ArPropertyConstants.PaymentApplicationDocumentFields.ENTERED_INVOICE_NUMBER, ArKeyConstants.ERROR_CUSTOMER_INVOICE_DOCUMENT_NOT_FINAL);
}
// form with an empty customer number wherever possible.
if (StringUtils.isBlank(payAppForm.getSelectedCustomerNumber())) {
if (StringUtils.isBlank(arDocHeader.getCustomerNumber())) {
if (payAppDoc.hasCashControlDetail()) {
payAppForm.setSelectedCustomerNumber(payAppDoc.getCashControlDetail().getCustomerNumber());
arDocHeader.setCustomerNumber(payAppDoc.getCashControlDetail().getCustomerNumber());
}
} else {
payAppForm.setSelectedCustomerNumber(arDocHeader.getCustomerNumber());
}
} else {
arDocHeader.setCustomerNumber(payAppForm.getSelectedCustomerNumber());
}
String customerNumber = payAppForm.getSelectedCustomerNumber();
// Invoice number entered, but no customer number entered
if (StringUtils.isBlank(customerNumber) && StringUtils.isNotBlank(currentInvoiceNumber) && validInvoice) {
Customer customer = getCustomerInvoiceDocumentService().getCustomerByInvoiceDocumentNumber(currentInvoiceNumber);
customerNumber = customer.getCustomerNumber();
payAppDoc.getAccountsReceivableDocumentHeader().setCustomerNumber(customerNumber);
}
// load up the control docs and non-applied holdings for non-cash-control payapps
if (StringUtils.isNotBlank(customerNumber)) {
if (!payAppDoc.hasCashControlDocument()) {
List<PaymentApplicationDocument> nonAppliedControlDocs = new ArrayList<>();
List<NonAppliedHolding> nonAppliedControlHoldings = new ArrayList<>();
// documents and nonapplied holdings that this doc paid against.
if (payAppDoc.isFinal()) {
nonAppliedControlDocs.addAll(payAppDoc.getPaymentApplicationDocumentsUsedAsControlDocuments());
nonAppliedControlHoldings.addAll(payAppDoc.getNonAppliedHoldingsUsedAsControls());
} else {
// otherwise, we pull all available non-zero non-applied holdings for
// this customer, and make the associated docs and non-applied holdings available
// retrieve the set of available non-applied holdings for this customer
nonAppliedControlHoldings.addAll(getNonAppliedHoldingService().getNonAppliedHoldingsForCustomer(customerNumber));
// get the parent list of payapp documents that they come from
List<String> controlDocNumbers = new ArrayList<>();
for (NonAppliedHolding nonAppliedHolding : nonAppliedControlHoldings) {
if (nonAppliedHolding.getAvailableUnappliedAmount().isPositive() && !controlDocNumbers.contains(nonAppliedHolding.getReferenceFinancialDocumentNumber())) {
controlDocNumbers.add(nonAppliedHolding.getReferenceFinancialDocumentNumber());
}
}
// only try to retrieve docs if we have any to retrieve
if (!controlDocNumbers.isEmpty()) {
try {
List<Document> docs = getDocumentService().getDocumentsByListOfDocumentHeaderIds(PaymentApplicationDocument.class, controlDocNumbers);
for (Document doc : docs) {
nonAppliedControlDocs.add((PaymentApplicationDocument) doc);
}
} catch (WorkflowException e) {
throw new RuntimeException("A runtimeException was thrown when trying to retrieve a list " + "of documents.", e);
}
}
}
// set the form vars from what we've loaded up here
payAppForm.setNonAppliedControlDocs(nonAppliedControlDocs);
payAppForm.setNonAppliedControlHoldings(nonAppliedControlHoldings);
payAppDoc.setNonAppliedHoldingsForCustomer(new ArrayList<>(nonAppliedControlHoldings));
payAppForm.setNonAppliedControlAllocations(null);
}
}
// reload invoices for the selected customer number
if (StringUtils.isNotBlank(customerNumber)) {
Collection<CustomerInvoiceDocument> openInvoicesForCustomer;
// at this point, we want to show the invoices it paid against, NOT the set of open invoices
if (payAppDoc.isFinal()) {
openInvoicesForCustomer = payAppDoc.getInvoicesPaidAgainst();
} else {
openInvoicesForCustomer = getCustomerInvoiceDocumentService().getOpenInvoiceDocumentsByCustomerNumber(customerNumber);
}
payAppForm.setInvoices(new ArrayList<>(openInvoicesForCustomer));
payAppForm.setupInvoiceWrappers(payAppDoc.getDocumentNumber());
}
// if no invoice number entered than get the first invoice
if (StringUtils.isNotBlank(customerNumber) && StringUtils.isBlank(currentInvoiceNumber)) {
if (payAppForm.getInvoices() == null || payAppForm.getInvoices().isEmpty()) {
currentInvoiceNumber = null;
} else {
currentInvoiceNumber = payAppForm.getInvoices().get(0).getDocumentNumber();
}
}
// load information for the current selected invoice
if (StringUtils.isNotBlank(currentInvoiceNumber)) {
payAppForm.setSelectedInvoiceDocumentNumber(currentInvoiceNumber);
payAppForm.setEnteredInvoiceDocumentNumber(currentInvoiceNumber);
}
// Make sure the invoice applies state are up to date
for (PaymentApplicationInvoiceApply invoiceApplication : payAppForm.getInvoiceApplications()) {
updateInvoiceApplication(payAppDoc, invoiceApplication);
}
// clear any NonInvoiced add line information from the form vars
payAppForm.setNonInvoicedAddLine(null);
// load any NonAppliedHolding information into the form vars
if (payAppDoc.getNonAppliedHolding() != null) {
payAppForm.setNonAppliedHoldingCustomerNumber(payAppDoc.getNonAppliedHolding().getCustomerNumber());
payAppForm.setNonAppliedHoldingAmount(payAppDoc.getNonAppliedHolding().getFinancialDocumentLineAmount());
} else {
// clear any NonAppliedHolding information from the form vars if it's empty
payAppForm.setNonAppliedHoldingCustomerNumber(null);
payAppForm.setNonAppliedHoldingAmount(null);
}
// Presort this list to not reload in the jsp - https://jira.kuali.org/browse/KFSCNTRB-1377
payAppForm.setInvoiceApplications(sortInvoiceApplications(payAppForm.getInvoiceApplications()));
}
Aggregations