use of org.kuali.kfs.module.ar.document.PaymentApplicationDocument 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.PaymentApplicationDocument in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method quickApplyToInvoices.
protected List<InvoicePaidApplied> quickApplyToInvoices(PaymentApplicationForm paymentApplicationForm, List<InvoicePaidApplied> appliedToIndividualDetails) {
PaymentApplicationDocument applicationDocument = (PaymentApplicationDocument) paymentApplicationForm.getDocument();
List<InvoicePaidApplied> invoicePaidApplieds = new ArrayList<>();
// go over the selected invoices and apply full amount to each of their details
for (PaymentApplicationInvoiceApply invoiceApplication : paymentApplicationForm.getInvoiceApplications()) {
String invoiceDocNumber = invoiceApplication.getDocumentNumber();
// skip the line if its not set to quick apply
if (!invoiceApplication.isQuickApply()) {
// if it was just flipped from True to False
if (invoiceApplication.isQuickApplyChanged()) {
for (PaymentApplicationInvoiceDetailApply detailApplication : invoiceApplication.getDetailApplications()) {
// zero out all the details
detailApplication.setAmountApplied(KualiDecimal.ZERO);
detailApplication.setFullApply(false);
// remove any existing paidApplieds for this invoice
for (int i = appliedToIndividualDetails.size() - 1; i >= 0; i--) {
InvoicePaidApplied applied = appliedToIndividualDetails.get(i);
if (applied.getFinancialDocumentReferenceInvoiceNumber().equals(invoiceApplication.getDocumentNumber())) {
appliedToIndividualDetails.remove(i);
}
}
}
}
continue;
}
// make sure none of the invoices selected have zero open amounts, complain if so
if (invoiceApplication.getOpenAmount().isZero()) {
addGlobalError(ArKeyConstants.PaymentApplicationDocumentErrors.CANNOT_QUICK_APPLY_ON_INVOICE_WITH_ZERO_OPEN_AMOUNT);
return invoicePaidApplieds;
}
// remove any existing paidApplieds for this invoice
for (int i = appliedToIndividualDetails.size() - 1; i >= 0; i--) {
InvoicePaidApplied applied = appliedToIndividualDetails.get(i);
if (applied.getFinancialDocumentReferenceInvoiceNumber().equals(invoiceApplication.getDocumentNumber())) {
appliedToIndividualDetails.remove(i);
}
}
// create and validate the paid applieds for each invoice detail
String fieldName = "invoiceApplications[" + invoiceDocNumber + "].quickApply";
for (PaymentApplicationInvoiceDetailApply detailApplication : invoiceApplication.getDetailApplications()) {
detailApplication.setAmountApplied(detailApplication.getAmountOpen());
detailApplication.setFullApply(true);
InvoicePaidApplied paidApplied = generateAndValidateNewPaidApplied(detailApplication, fieldName, applicationDocument);
if (paidApplied != null) {
invoicePaidApplieds.add(paidApplied);
}
}
// maintain the selected doc number
if (invoiceDocNumber.equals(paymentApplicationForm.getEnteredInvoiceDocumentNumber())) {
paymentApplicationForm.setSelectedInvoiceDocumentNumber(invoiceDocNumber);
}
}
return invoicePaidApplieds;
}
use of org.kuali.kfs.module.ar.document.PaymentApplicationDocument in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method deleteInvoicePaidApplied.
// CU Customization: Added several helper methods for invoice-paid-applied deletion enhancement.
public ActionForward deleteInvoicePaidApplied(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
PaymentApplicationForm paymentApplicationForm = (PaymentApplicationForm) form;
paymentApplicationForm.setManualInvoicePaidAppliedDatabaseDeletionRequired(true);
PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
int deleteIndex = getLineToDelete(request);
adjustBothQuickApplyToInvoiceAndApplyToInvoiceDetailDueToDeleteInvoicePaidApplied(paymentApplicationForm, deleteIndex);
paymentApplicationDocument.getInvoicePaidApplieds().remove(deleteIndex);
GlobalVariables.getMessageMap().clearErrorMessages();
doApplicationOfFunds((PaymentApplicationForm) form);
return mapping.findForward(KFSConstants.MAPPING_BASIC);
}
use of org.kuali.kfs.module.ar.document.PaymentApplicationDocument in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method adjust.
public ActionForward adjust(final ActionMapping mapping, final ActionForm form, final HttpServletRequest request, final HttpServletResponse response) throws Exception {
// Document could be stale at this point (Submit followed immediately by Adjust); freshen it up
super.reload(mapping, form, request, response);
final KualiDocumentFormBase kualiDocumentFormBase = (KualiDocumentFormBase) form;
final PaymentApplicationDocument applicationDocument = (PaymentApplicationDocument) kualiDocumentFormBase.getDocument();
final PaymentApplicationAdjustmentDocument appAdjustDocument = getPaymentApplicationDocumentService().createPaymentApplicationAdjustment(applicationDocument);
kualiDocumentFormBase.setDocument(appAdjustDocument);
return createActionForward((KualiDocumentFormBase) form);
}
use of org.kuali.kfs.module.ar.document.PaymentApplicationDocument in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method createDocument.
@Override
protected void createDocument(KualiDocumentFormBase kualiDocumentFormBase) throws WorkflowException {
super.createDocument(kualiDocumentFormBase);
PaymentApplicationForm form = (PaymentApplicationForm) kualiDocumentFormBase;
PaymentApplicationDocument document = form.getPaymentApplicationDocument();
// create new accounts receivable header and set it to the payment application document
AccountsReceivableDocumentHeaderService accountsReceivableDocumentHeaderService = SpringContext.getBean(AccountsReceivableDocumentHeaderService.class);
AccountsReceivableDocumentHeader accountsReceivableDocumentHeader = accountsReceivableDocumentHeaderService.getNewAccountsReceivableDocumentHeaderForCurrentUser();
accountsReceivableDocumentHeader.setDocumentNumber(document.getDocumentNumber());
document.setAccountsReceivableDocumentHeader(accountsReceivableDocumentHeader);
}
Aggregations