use of org.kuali.kfs.module.ar.businessobject.Customer in project cu-kfs by CU-CommunityApps.
the class CuContractsGrantsInvoiceDocumentServiceImpl method getCustomerNetTerms.
/*
* CUMod: KFSPTS-15342
*/
protected Optional<Integer> getCustomerNetTerms(ContractsGrantsInvoiceDocument document) {
Customer customer = null;
AccountsReceivableDocumentHeader documentHeader = document.getAccountsReceivableDocumentHeader();
if (ObjectUtils.isNotNull(documentHeader)) {
documentHeader.refreshReferenceObject(ArPropertyConstants.CustomerInvoiceDocumentFields.CUSTOMER);
customer = documentHeader.getCustomer();
}
if (ObjectUtils.isNotNull(customer)) {
CustomerExtendedAttribute customerExtension = (CustomerExtendedAttribute) customer.getExtension();
if (ObjectUtils.isNotNull(customerExtension)) {
return Optional.ofNullable(customerExtension.getNetTermsInDays());
}
}
return Optional.empty();
}
use of org.kuali.kfs.module.ar.businessobject.Customer in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceDocumentServiceImpl method buildCustomerFieldsMap.
private Map<String, Object> buildCustomerFieldsMap(ContractsGrantsInvoiceDocument document) {
Map<String, Object> customerFieldsMap = new HashMap<>();
Customer customer = document.getCustomer();
if (ObjectUtils.isNotNull(customer)) {
customerFieldsMap.put(ArPropertyConstants.CustomerInvoiceDocumentFields.CUSTOMER + "." + KFSPropertyConstants.CUSTOMER_NAME, customer.getCustomerName());
}
return customerFieldsMap;
}
use of org.kuali.kfs.module.ar.businessobject.Customer in project cu-kfs by CU-CommunityApps.
the class PaymentApplicationAction method findCustomerNumber.
/**
* figure out the current customer Number on the form
*
* @param paymentApplicationForm
* @return
*/
protected String findCustomerNumber(PaymentApplicationForm paymentApplicationForm) {
boolean validInvoice = this.isValidInvoice(paymentApplicationForm);
String customerNumber = paymentApplicationForm.getSelectedCustomerNumber();
String currentInvoiceNumber = paymentApplicationForm.getEnteredInvoiceDocumentNumber();
// Invoice number entered, but no customer number entered
if (StringUtils.isBlank(customerNumber) && StringUtils.isNotBlank(currentInvoiceNumber) && validInvoice) {
Customer customer = getCustomerInvoiceDocumentService().getCustomerByInvoiceDocumentNumber(currentInvoiceNumber);
customerNumber = customer.getCustomerNumber();
}
return customerNumber;
}
use of org.kuali.kfs.module.ar.businessobject.Customer 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()));
}
use of org.kuali.kfs.module.ar.businessobject.Customer in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method populateContractsGrantsInvoiceDocument.
/**
* FINP-5295 This method was modified for the backport.
*
* This method helps in setting up basic values for Contracts & Grants Invoice Document
*/
protected void populateContractsGrantsInvoiceDocument(ContractsAndGrantsBillingAward award, ContractsGrantsInvoiceDocument document, List<ContractsGrantsLetterOfCreditReviewDetail> locReviewDetails, String locCreationType) {
if (ObjectUtils.isNotNull(award.getAgency())) {
if (ObjectUtils.isNotNull(document.getAccountsReceivableDocumentHeader())) {
document.getAccountsReceivableDocumentHeader().setCustomerNumber(award.getAgency().getCustomerNumber());
}
Customer customer = getCustomerService().getByPrimaryKey(award.getAgency().getCustomerNumber());
if (ObjectUtils.isNotNull(customer)) {
document.setCustomerName(customer.getCustomerName());
}
}
// To set open invoice indicator to true to help doing cash control for the invoice
document.setOpenInvoiceIndicator(true);
// To set LOC creation type and appropriate values from award.
if (StringUtils.isNotBlank(locCreationType)) {
document.getInvoiceGeneralDetail().setLetterOfCreditCreationType(locCreationType);
}
// To set up values for Letter of Credit Fund and Fund Group irrespective of the LOC Creation type.
if (StringUtils.isNotEmpty(award.getLetterOfCreditFundCode())) {
document.getInvoiceGeneralDetail().setLetterOfCreditFundCode(award.getLetterOfCreditFundCode());
}
if (ObjectUtils.isNotNull(award.getLetterOfCreditFund())) {
if (StringUtils.isNotEmpty(award.getLetterOfCreditFund().getLetterOfCreditFundGroupCode())) {
document.getInvoiceGeneralDetail().setLetterOfCreditFundGroupCode(award.getLetterOfCreditFund().getLetterOfCreditFundGroupCode());
}
}
KualiDecimal totalAmountBilledToDate;
if (document.getInvoiceMilestones().size() > 0) {
totalAmountBilledToDate = getContractsGrantsInvoiceDocumentService().getInvoiceMilestoneTotal(document).add(document.getInvoiceGeneralDetail().getTotalPreviouslyBilled());
} else if (document.getInvoiceBills().size() > 0) {
totalAmountBilledToDate = getContractsGrantsInvoiceDocumentService().getBillAmountTotal(document).add(document.getInvoiceGeneralDetail().getTotalPreviouslyBilled());
} else {
totalAmountBilledToDate = calculateTotalExpenditureAmount(document, locReviewDetails).add(getContractsGrantsInvoiceDocumentService().getOtherTotalBilledForAwardPeriod(document));
}
document.getInvoiceGeneralDetail().setTotalAmountBilledToDate(totalAmountBilledToDate);
}
Aggregations