use of org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class FirstInvoiceForAwardSuspensionCategory method priorSuccessfulInvoicesExist.
protected boolean priorSuccessfulInvoicesExist(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
Map<String, String> criteria = new HashMap<>();
String proposalNumber = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getProposalNumber();
String documentNumber = contractsGrantsInvoiceDocument.getDocumentNumber();
ContractsAndGrantsBillingAward award = contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getAward();
criteria.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentFields.PROPOSAL_NUMBER, proposalNumber);
criteria.put(KFSPropertyConstants.DOCUMENT_HEADER + KFSConstants.DELIMITER + KFSPropertyConstants.WORKFLOW_DOCUMENT_STATUS_CODE, buildSuccessfulDocumentStatusesCriteria());
criteria.put(KFSPropertyConstants.DOCUMENT_NUMBER, SearchOperator.NOT.op() + documentNumber);
Map<String, String> extraCriteria = buildAdditionalCriteriaForInvoicingOption(contractsGrantsInvoiceDocument, award.getInvoicingOptionCode());
criteria.putAll(extraCriteria);
Collection<ContractsGrantsInvoiceDocument> priorInvoices = contractsGrantsInvoiceDocumentDao.getMatchingInvoicesByCollection(criteria);
return CollectionUtils.isNotEmpty(priorInvoices);
}
use of org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument 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;
}
use of org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method getOtherTotalBilledForAwardPeriod.
@Override
public KualiDecimal getOtherTotalBilledForAwardPeriod(ContractsGrantsInvoiceDocument contractsGrantsInvoiceDocument) {
KualiDecimal newTotalBilled = KualiDecimal.ZERO;
Map<String, String> fieldValuesForInvoice = new HashMap<>();
fieldValuesForInvoice.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentFields.PROPOSAL_NUMBER, contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getProposalNumber());
fieldValuesForInvoice.put(ArPropertyConstants.INVOICE_GENERAL_DETAIL + "." + ArPropertyConstants.BILLING_PERIOD, contractsGrantsInvoiceDocument.getInvoiceGeneralDetail().getBillingPeriod());
String docNumberCriteriaString = SearchOperator.NOT + contractsGrantsInvoiceDocument.getDocumentNumber();
if (ObjectUtils.isNotNull(contractsGrantsInvoiceDocument.getFinancialSystemDocumentHeader()) && StringUtils.isNotBlank(contractsGrantsInvoiceDocument.getFinancialSystemDocumentHeader().getFinancialDocumentInErrorNumber())) {
docNumberCriteriaString += SearchOperator.NOT + contractsGrantsInvoiceDocument.getFinancialSystemDocumentHeader().getFinancialDocumentInErrorNumber();
}
fieldValuesForInvoice.put(KFSPropertyConstants.DOCUMENT_NUMBER, docNumberCriteriaString);
fieldValuesForInvoice.put(ArPropertyConstants.DOCUMENT_STATUS_CODE, SearchOperator.NOT + KFSConstants.DocumentStatusCodes.PROCESSED + SearchOperator.NOT + KFSConstants.DocumentStatusCodes.APPROVED);
Collection<ContractsGrantsInvoiceDocument> cgInvoiceDocuments = retrieveAllCGInvoicesByCriteria(fieldValuesForInvoice);
for (ContractsGrantsInvoiceDocument cgInvoiceDocument : cgInvoiceDocuments) {
for (InvoiceAccountDetail invAcctD : cgInvoiceDocument.getAccountDetails()) {
newTotalBilled = newTotalBilled.add(invAcctD.getInvoiceAmount());
}
}
return newTotalBilled;
}
use of org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method getAwardBilledToDateAmount.
@Override
public KualiDecimal getAwardBilledToDateAmount(String proposalNumber) {
Map<String, String> fieldValues = new HashMap<>();
fieldValues.put(ArPropertyConstants.ContractsGrantsInvoiceDocumentFields.PROPOSAL_NUMBER, proposalNumber);
fieldValues.put(KFSPropertyConstants.DOCUMENT_HEADER + "." + KFSPropertyConstants.WORKFLOW_DOCUMENT_STATUS_CODE, StringUtils.join(financialSystemDocumentService.getSuccessfulDocumentStatuses(), "|"));
Collection<ContractsGrantsInvoiceDocument> invoiceDocuments = retrieveAllCGInvoicesByCriteria(fieldValues);
final KualiDecimal milestoneTotal = getMilestonesBilledToDateAmount(proposalNumber);
final KualiDecimal billTotal = getPredeterminedBillingBilledToDateAmount(proposalNumber);
final KualiDecimal nonScheduledTotal = calculateTotalInvoiceAmount(invoiceDocuments);
return milestoneTotal.add(billTotal).add(nonScheduledTotal);
}
use of org.kuali.kfs.module.ar.document.ContractsGrantsInvoiceDocument in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method routeContractsGrantsInvoiceDocuments.
/**
* This method retrieves all the Contracts & Grants Invoice Documents with a status of Saved and routes them to
* the next step in the routing path.
*
* @return True if the routing was performed successfully. A runtime exception will be thrown if any errors occur
* while routing.
*/
@Override
public void routeContractsGrantsInvoiceDocuments() {
final String currentUserPrincipalId = GlobalVariables.getUserSession().getPerson().getPrincipalId();
List<String> documentIdList = retrieveContractsGrantsInvoiceDocumentsToRoute(DocumentStatus.SAVED, currentUserPrincipalId);
if (LOG.isInfoEnabled()) {
LOG.info("CGinvoice to Route: " + documentIdList);
}
for (String cgInvoiceDocId : documentIdList) {
try {
ContractsGrantsInvoiceDocument cgInvoiceDoc = (ContractsGrantsInvoiceDocument) documentService.getByDocumentHeaderId(cgInvoiceDocId);
// To route documents only if the user in the session is same as the initiator.
if (LOG.isInfoEnabled()) {
LOG.info("Routing Contracts & Grants Invoice document # " + cgInvoiceDocId + ".");
}
documentService.prepareWorkflowDocument(cgInvoiceDoc);
// calling workflow service to bypass business rule checks
workflowDocumentService.route(cgInvoiceDoc.getDocumentHeader().getWorkflowDocument(), "", null);
} catch (WorkflowException e) {
LOG.error("Error routing document # " + cgInvoiceDocId + " " + e.getMessage());
throw new RuntimeException(e.getMessage(), e);
}
}
}
Aggregations