use of org.kuali.kfs.module.ar.document.CustomerInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationForm method getNextInvoiceDocumentNumber.
public String getNextInvoiceDocumentNumber() {
CustomerInvoiceDocument nextInvoiceDocument = null;
PaymentApplicationInvoiceApply invoiceApplication = getSelectedInvoiceApplication();
CustomerInvoiceDocument selectedInvoiceDocument = invoiceApplication == null ? null : invoiceApplication.getInvoice();
if (null != selectedInvoiceDocument && 2 <= invoices.size()) {
Iterator<CustomerInvoiceDocument> iterator = invoices.iterator();
while (iterator.hasNext()) {
CustomerInvoiceDocument currentInvoiceDocument = iterator.next();
String currentInvoiceDocumentNumber = currentInvoiceDocument.getDocumentNumber();
if (currentInvoiceDocumentNumber.equals(selectedInvoiceDocument.getDocumentNumber())) {
if (iterator.hasNext()) {
nextInvoiceDocument = iterator.next();
} else {
nextInvoiceDocument = null;
}
}
}
}
return null == nextInvoiceDocument ? "" : nextInvoiceDocument.getDocumentNumber();
}
use of org.kuali.kfs.module.ar.document.CustomerInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationForm method getPreviousInvoiceDocumentNumber.
public String getPreviousInvoiceDocumentNumber() {
CustomerInvoiceDocument previousInvoiceDocument = null;
PaymentApplicationInvoiceApply invoiceApplication = getSelectedInvoiceApplication();
CustomerInvoiceDocument selectedInvoiceDocument = invoiceApplication == null ? null : invoiceApplication.getInvoice();
if (null != selectedInvoiceDocument && 2 <= invoices.size()) {
Iterator<CustomerInvoiceDocument> iterator = invoices.iterator();
CustomerInvoiceDocument customerInvoiceDocument = iterator.next();
String selectedInvoiceDocumentNumber = selectedInvoiceDocument.getDocumentNumber();
if (null != selectedInvoiceDocumentNumber && selectedInvoiceDocumentNumber.equals(customerInvoiceDocument.getDocumentNumber())) {
previousInvoiceDocument = null;
} else {
while (iterator.hasNext()) {
CustomerInvoiceDocument currentInvoiceDocument = iterator.next();
String currentInvoiceDocumentNumber = currentInvoiceDocument.getDocumentNumber();
if (null != currentInvoiceDocumentNumber && currentInvoiceDocumentNumber.equals(selectedInvoiceDocument.getDocumentNumber())) {
previousInvoiceDocument = customerInvoiceDocument;
} else {
customerInvoiceDocument = currentInvoiceDocument;
}
}
}
}
return null == previousInvoiceDocument ? "" : previousInvoiceDocument.getDocumentNumber();
}
use of org.kuali.kfs.module.ar.document.CustomerInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationForm method populate.
@Override
public void populate(HttpServletRequest request) {
super.populate(request);
// Set the next non-invoiced line number
PaymentApplicationDocument paymentApplicationDocument = getPaymentApplicationDocument();
if (ObjectUtils.isNotNull(paymentApplicationDocument.getNonInvoicedDistributions())) {
for (NonInvoicedDistribution u : paymentApplicationDocument.getNonInvoicedDistributions()) {
if (null == getNextNonInvoicedLineNumber()) {
setNextNonInvoicedLineNumber(u.getFinancialDocumentLineNumber());
} else if (u.getFinancialDocumentLineNumber() > getNextNonInvoicedLineNumber()) {
setNextNonInvoicedLineNumber(u.getFinancialDocumentLineNumber());
}
}
}
if (null == getNextNonInvoicedLineNumber()) {
setNextNonInvoicedLineNumber(1);
}
// This step doesn't affect anything persisted to the database. It allows proper calculation
// of amounts for the display.
String customerNumber = null;
String docId = getDocument().getDocumentNumber();
if (ObjectUtils.isNotNull(request.getParameter(KFSConstants.PARAMETER_DOC_ID)) && ObjectUtils.isNull(getDocument().getDocumentNumber())) {
// The document hasn't yet been set on the form. Let's look it up manually so that we can get the
// customer number.
docId = request.getParameter(KFSConstants.PARAMETER_DOC_ID).trim();
DocumentService documentService = SpringContext.getBean(DocumentService.class);
Document d;
try {
d = documentService.getByDocumentHeaderId(docId);
} catch (WorkflowException e) {
throw new RuntimeException("WorkflowException thrown when trying to load docId [" + docId + "]", e);
}
PaymentApplicationDocument pDocument = (PaymentApplicationDocument) d;
AccountsReceivableDocumentHeader arHeader = pDocument.getAccountsReceivableDocumentHeader();
if (ObjectUtils.isNotNull(arHeader)) {
customerNumber = arHeader.getCustomerNumber();
}
}
if (ObjectUtils.isNull(getSelectedInvoiceApplication())) {
if (ObjectUtils.isNull(invoices) || invoices.isEmpty()) {
if (ObjectUtils.isNotNull(customerNumber)) {
// get open invoices for the current customer
CustomerInvoiceDocumentService customerInvoiceDocumentService = SpringContext.getBean(CustomerInvoiceDocumentService.class);
Collection<CustomerInvoiceDocument> openInvoicesForCustomer = customerInvoiceDocumentService.getOpenInvoiceDocumentsByCustomerNumber(customerNumber);
setInvoices(new ArrayList<>(openInvoicesForCustomer));
if (invoices != null && !invoices.isEmpty()) {
setSelectedInvoiceDocumentNumber(invoices.get(0).getDocumentNumber());
}
setupInvoiceWrappers(docId);
}
}
}
}
use of org.kuali.kfs.module.ar.document.CustomerInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationForm method setupInvoiceWrappers.
/**
* @param payAppDocNumber
*/
protected void setupInvoiceWrappers(String payAppDocNumber) {
if (StringUtils.isBlank(payAppDocNumber)) {
throw new IllegalArgumentException("The payAppDocNumber parameter passed in was null or blank.");
}
// clear any existing
invoiceApplications.clear();
if (invoices == null || invoices.isEmpty()) {
return;
}
for (CustomerInvoiceDocument invoice : invoices) {
PaymentApplicationInvoiceApply invoiceApplication = new PaymentApplicationInvoiceApply(payAppDocNumber, invoice);
addInvoiceApplication(invoiceApplication);
}
}
use of org.kuali.kfs.module.ar.document.CustomerInvoiceDocument 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