use of org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied 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.module.ar.businessobject.InvoicePaidApplied 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.InvoicePaidApplied in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method applyToIndividualCustomerInvoiceDetails.
protected List<InvoicePaidApplied> applyToIndividualCustomerInvoiceDetails(PaymentApplicationForm paymentApplicationForm) {
PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
// Handle amounts applied at the invoice detail level
int simpleInvoiceDetailApplicationCounter = 0;
// calculate paid applieds for all invoices
List<InvoicePaidApplied> invoicePaidApplieds = this.filterTempInvoicePaidApplieds(paymentApplicationForm);
for (PaymentApplicationInvoiceApply invoiceApplication : paymentApplicationForm.getInvoiceApplications()) {
for (PaymentApplicationInvoiceDetailApply detailApplication : invoiceApplication.getDetailApplications()) {
// selectedInvoiceDetailApplications[${ctr}].amountApplied
String fieldName = "selectedInvoiceDetailApplications[" + simpleInvoiceDetailApplicationCounter + "].amountApplied";
// needs to be incremented even if we skip this line
simpleInvoiceDetailApplicationCounter++;
// handle the user clicking full apply
if (detailApplication.isFullApply()) {
detailApplication.setAmountApplied(detailApplication.getAmountOpen());
} else {
// handle the user manually entering an amount
if (detailApplication.isFullApplyChanged()) {
// means it went from true to false
detailApplication.setAmountApplied(KualiDecimal.ZERO);
}
}
// Don't add lines where the amount to apply is zero. Wouldn't make any sense to do that.
if (KualiDecimal.ZERO.equals(detailApplication.getAmountApplied())) {
continue;
}
if (containsIdentical(detailApplication.getInvoiceDetail(), detailApplication.getAmountApplied(), invoicePaidApplieds)) {
continue;
}
// generate and validate the paidApplied, and always add it to the list, even if
// it fails validation. Validation failures will stop routing.
LOG.debug("Generating paid applied for detail application " + detailApplication.getInvoiceDocumentNumber());
InvoicePaidApplied invoicePaidApplied = generateAndValidateNewPaidApplied(detailApplication, fieldName, paymentApplicationDocument);
GlobalVariables.getMessageMap().addToErrorPath(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB);
GlobalVariables.getMessageMap().removeFromErrorPath(KFSConstants.PaymentApplicationTabErrorCodes.APPLY_TO_INVOICE_DETAIL_TAB);
invoicePaidApplieds.add(invoicePaidApplied);
}
}
return invoicePaidApplieds;
}
use of org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method adjustBothQuickApplyToInvoiceAndApplyToInvoiceDetailDueToDeleteInvoicePaidApplied.
protected void adjustBothQuickApplyToInvoiceAndApplyToInvoiceDetailDueToDeleteInvoicePaidApplied(PaymentApplicationForm paymentApplicationForm, int deletedAppliedFundsIndex) {
PaymentApplicationDocument paymentApplicationDocument = paymentApplicationForm.getPaymentApplicationDocument();
InvoicePaidApplied appliedFundBeingDeleted = paymentApplicationDocument.getInvoicePaidApplieds().get(deletedAppliedFundsIndex);
String summaryOfAppliedFundsDocumentNumberBeingDeleted = appliedFundBeingDeleted.getFinancialDocumentReferenceInvoiceNumber();
KualiDecimal summaryOfAppliedFundsAmountBeingDeleted = appliedFundBeingDeleted.getInvoiceItemAppliedAmount();
if (StringUtils.isNotBlank(summaryOfAppliedFundsDocumentNumberBeingDeleted)) {
for (PaymentApplicationInvoiceApply invoiceListItem : paymentApplicationForm.getInvoiceApplications()) {
for (PaymentApplicationInvoiceDetailApply invoiceListItemDetail : invoiceListItem.getDetailApplications()) {
deleteCleanupOfApplyToInvoiceDetailData(invoiceListItemDetail, summaryOfAppliedFundsDocumentNumberBeingDeleted, summaryOfAppliedFundsAmountBeingDeleted);
deleteCleanupOfQuickApplyToInvoiceData(invoiceListItem, invoiceListItemDetail, summaryOfAppliedFundsDocumentNumberBeingDeleted);
}
}
}
}
use of org.kuali.kfs.module.ar.businessobject.InvoicePaidApplied in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsPaymentHistoryReportLookupableHelperServiceImpl method performLookup.
/*
* back-port FINP-7396
*/
@Override
public Collection<ContractsGrantsPaymentHistoryReport> performLookup(LookupForm lookupForm, Collection<ResultRow> resultTable, boolean bounded) {
Map<String, String> lookupFormFields = lookupForm.getFieldsForLookup();
setBackLocation(lookupForm.getFieldsForLookup().get(KRADConstants.BACK_LOCATION));
setDocFormKey(lookupForm.getFieldsForLookup().get(KRADConstants.DOC_FORM_KEY));
Collection<ContractsGrantsPaymentHistoryReport> displayList = new ArrayList<>();
Map<String, String> invoiceAppliedLookupFields = new HashMap<>();
if (lookupFormFields.containsKey(ArPropertyConstants.INVOICE_TYPE)) {
invoiceAppliedLookupFields.put(ArPropertyConstants.CUSTOMER_INVOICE_DOCUMENT + "." + KFSPropertyConstants.DOCUMENT_HEADER + "." + KFSPropertyConstants.WORKFLOW_DOCUMENT_TYPE_NAME, lookupFormFields.get(ArPropertyConstants.INVOICE_TYPE));
}
if (lookupFormFields.containsKey(ArPropertyConstants.PAYMENT_NUMBER)) {
invoiceAppliedLookupFields.put(KFSPropertyConstants.DOCUMENT_NUMBER, lookupFormFields.get(ArPropertyConstants.PAYMENT_NUMBER));
}
if (lookupFormFields.containsKey(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER)) {
invoiceAppliedLookupFields.put(ArPropertyConstants.CUSTOMER_INVOICE_DOCUMENT + "." + ArPropertyConstants.CustomerInvoiceDocumentFields.CUSTOMER_NUMBER, lookupFormFields.get(ArPropertyConstants.CustomerFields.CUSTOMER_NUMBER));
}
if (lookupFormFields.containsKey(ArPropertyConstants.PAYMENT_AMOUNT)) {
invoiceAppliedLookupFields.put(ArPropertyConstants.CustomerInvoiceDetailFields.INVOICE_ITEM_APPLIED_AMOUNT, lookupFormFields.get(ArPropertyConstants.PAYMENT_AMOUNT));
}
if (lookupFormFields.containsKey(ArPropertyConstants.INVOICE_NUMBER)) {
invoiceAppliedLookupFields.put(ArPropertyConstants.CustomerInvoiceDocumentFields.FINANCIAL_DOCUMENT_REF_INVOICE_NUMBER, lookupFormFields.get(ArPropertyConstants.INVOICE_NUMBER));
}
Collection<InvoicePaidApplied> invoicePaidApplieds = getLookupService().findCollectionBySearchHelper(InvoicePaidApplied.class, invoiceAppliedLookupFields, true);
// For each Cash Control doc, get a list of payment app doc numbers
try {
for (InvoicePaidApplied invoicePaidApplied : invoicePaidApplieds) {
boolean useInvoicePaidApplied = true;
final Document doc = getDocumentService().getByDocumentHeaderId(invoicePaidApplied.getDocumentNumber());
if (doc instanceof PaymentApplicationAdjustableDocument) {
final PaymentApplicationAdjustableDocument paymentApp = (PaymentApplicationAdjustableDocument) doc;
if (getFinancialSystemDocumentService().getUnsuccessfulDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode())) {
useInvoicePaidApplied = false;
}
if (StringUtils.isNotBlank(lookupFormFields.get(ArPropertyConstants.APPLIED_INDICATOR))) {
final String appliedIndicator = lookupFormFields.get(ArPropertyConstants.APPLIED_INDICATOR);
if (KRADConstants.YES_INDICATOR_VALUE.equals(appliedIndicator) && !getFinancialSystemDocumentService().getSuccessfulDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode())) {
useInvoicePaidApplied = false;
} else if (KRADConstants.NO_INDICATOR_VALUE.equals(appliedIndicator) && !getFinancialSystemDocumentService().getPendingDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode())) {
useInvoicePaidApplied = false;
}
}
final DateTime dateFinalized = paymentApp.getDocumentHeader().getWorkflowDocument().getDateFinalized();
Date paymentAppFinalDate = null;
if (dateFinalized != null) {
paymentAppFinalDate = dateFinalized.toDate();
}
if (StringUtils.isNotBlank(lookupFormFields.get(ArPropertyConstants.PAYMENT_DATE))) {
final Date toPaymentDate = getDateTimeService().convertToDate(lookupFormFields.get(ArPropertyConstants.PAYMENT_DATE));
if (paymentAppFinalDate == null || !KfsDateUtils.isSameDay(paymentAppFinalDate, toPaymentDate) && toPaymentDate.before(paymentAppFinalDate)) {
useInvoicePaidApplied = false;
}
}
if (StringUtils.isNotBlank(lookupFormFields.get(KFSPropertyConstants.RANGE_LOWER_BOUND_KEY_PREFIX + ArPropertyConstants.PAYMENT_DATE))) {
final Date fromPaymentDate = getDateTimeService().convertToDate(lookupFormFields.get(KFSPropertyConstants.RANGE_LOWER_BOUND_KEY_PREFIX + ArPropertyConstants.PAYMENT_DATE));
if (paymentAppFinalDate == null || !KfsDateUtils.isSameDay(paymentAppFinalDate, fromPaymentDate) && fromPaymentDate.after(paymentAppFinalDate)) {
useInvoicePaidApplied = false;
}
}
final ContractsGrantsInvoiceDocument cgInvoiceDocument = getBusinessObjectService().findBySinglePrimaryKey(ContractsGrantsInvoiceDocument.class, invoicePaidApplied.getFinancialDocumentReferenceInvoiceNumber());
OperatorAndValue invoiceAmountOperator = buildOperatorAndValueFromField(lookupFormFields, ArPropertyConstants.INVOICE_AMOUNT);
if (invoiceAmountOperator != null && !invoiceAmountOperator.applyComparison(cgInvoiceDocument.getTotalDollarAmount())) {
useInvoicePaidApplied = false;
}
if (StringUtils.isNotBlank(lookupFormFields.get(KFSPropertyConstants.AWARD_NUMBER))) {
if (!StringUtils.equals(cgInvoiceDocument.getInvoiceGeneralDetail().getAward().getProposalNumber(), lookupFormFields.get(KFSPropertyConstants.AWARD_NUMBER))) {
useInvoicePaidApplied = false;
}
}
if (StringUtils.isNotBlank(lookupFormFields.get(ArPropertyConstants.REVERSED_INDICATOR))) {
final String reversedIndicator = lookupFormFields.get(ArPropertyConstants.REVERSED_INDICATOR);
if (KRADConstants.YES_INDICATOR_VALUE.equals(reversedIndicator) && !cgInvoiceDocument.isInvoiceReversal()) {
useInvoicePaidApplied = false;
} else if (KRADConstants.NO_INDICATOR_VALUE.equals(reversedIndicator) & cgInvoiceDocument.isInvoiceReversal()) {
useInvoicePaidApplied = false;
}
}
if (useInvoicePaidApplied) {
ContractsGrantsPaymentHistoryReport cgPaymentHistoryReport = new ContractsGrantsPaymentHistoryReport();
cgPaymentHistoryReport.setPaymentNumber(invoicePaidApplied.getDocumentNumber());
cgPaymentHistoryReport.setPaymentDocumentType(paymentApp.getDocumentHeader().getWorkflowDocument().getDocumentTypeName());
FinancialSystemDocumentHeader documentHeader = (FinancialSystemDocumentHeader) cgInvoiceDocument.getDocumentHeader();
cgPaymentHistoryReport.setInvoiceType(documentHeader.getWorkflowDocumentTypeName());
cgPaymentHistoryReport.setPaymentAmount(invoicePaidApplied.getInvoiceItemAppliedAmount());
cgPaymentHistoryReport.setInvoiceNumber(invoicePaidApplied.getFinancialDocumentReferenceInvoiceNumber());
if (dateFinalized != null) {
cgPaymentHistoryReport.setPaymentDate(new java.sql.Date(dateFinalized.getMillis()));
}
cgPaymentHistoryReport.setAppliedIndicator(getFinancialSystemDocumentService().getSuccessfulDocumentStatuses().contains(paymentApp.getFinancialSystemDocumentHeader().getWorkflowDocumentStatusCode()));
if (ObjectUtils.isNotNull(cgInvoiceDocument.getInvoiceGeneralDetail())) {
cgPaymentHistoryReport.setAwardNumber(cgInvoiceDocument.getInvoiceGeneralDetail().getProposalNumber());
}
cgPaymentHistoryReport.setReversedIndicator(cgInvoiceDocument.isInvoiceReversal());
cgPaymentHistoryReport.setCustomerNumber(cgInvoiceDocument.getCustomerNumber());
cgPaymentHistoryReport.setCustomerName(cgInvoiceDocument.getCustomer().getCustomerName());
cgPaymentHistoryReport.setInvoiceAmount(cgInvoiceDocument.getTotalDollarAmount());
displayList.add(cgPaymentHistoryReport);
}
}
}
buildResultTable(lookupForm, displayList, resultTable);
} catch (WorkflowException we) {
throw new RuntimeException("Could not open payment application document related to search", we);
} catch (ParseException pe) {
throw new RuntimeException("I tried to validate the date and amount fields related to search, I really " + "did. But...I guess I didn't try hard enough", pe);
}
return displayList;
}
Aggregations