use of org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader 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.AccountsReceivableDocumentHeader 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.businessobject.AccountsReceivableDocumentHeader 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);
}
use of org.kuali.kfs.module.ar.businessobject.AccountsReceivableDocumentHeader 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.AccountsReceivableDocumentHeader in project cu-kfs by CU-CommunityApps.
the class ContractsGrantsInvoiceCreateDocumentServiceImpl method createCGInvoiceDocumentByAwardInfo.
/*
* CU Customization (KFSPTS-23675):
* Added creationProcessType argument and its usage of it.
*/
@Override
public ContractsGrantsInvoiceDocument createCGInvoiceDocumentByAwardInfo(ContractsAndGrantsBillingAward awd, List<ContractsAndGrantsBillingAwardAccount> accounts, String chartOfAccountsCode, String organizationCode, List<ErrorMessage> errorMessages, List<ContractsGrantsLetterOfCreditReviewDetail> accountDetails, String locCreationType, ContractsAndGrantsInvoiceDocumentCreationProcessType creationProcessType) {
ContractsGrantsInvoiceDocument cgInvoiceDocument = null;
if (ObjectUtils.isNotNull(accounts) && !accounts.isEmpty()) {
if (chartOfAccountsCode != null && organizationCode != null) {
try {
cgInvoiceDocument = (ContractsGrantsInvoiceDocument) documentService.getNewDocument(ContractsGrantsInvoiceDocument.class);
// Set description to the document created.
cgInvoiceDocument.getDocumentHeader().setDocumentDescription(buildDocumentDescription(awd, accounts));
// setup several Default Values for CGInvoice document which extends from Customer Invoice Document
// a) set billing org and chart code
cgInvoiceDocument.setBillByChartOfAccountCode(chartOfAccountsCode);
cgInvoiceDocument.setBilledByOrganizationCode(organizationCode);
// b) set processing org and chart code
List<String> procCodes = getContractsGrantsInvoiceDocumentService().getProcessingFromBillingCodes(chartOfAccountsCode, organizationCode);
AccountsReceivableDocumentHeader accountsReceivableDocumentHeader = new AccountsReceivableDocumentHeader();
accountsReceivableDocumentHeader.setDocumentNumber(cgInvoiceDocument.getDocumentNumber());
// Set processing chart and org codes
if (procCodes != null) {
int procCodesSize = procCodes.size();
// Set processing chart
if (procCodesSize > 0) {
accountsReceivableDocumentHeader.setProcessingChartOfAccountCode(procCodes.get(0));
}
// Set processing org code
if (procCodesSize > 1) {
accountsReceivableDocumentHeader.setProcessingOrganizationCode(procCodes.get(1));
}
}
cgInvoiceDocument.setAccountsReceivableDocumentHeader(accountsReceivableDocumentHeader);
populateInvoiceFromAward(awd, accounts, cgInvoiceDocument, accountDetails, locCreationType, creationProcessType);
contractsGrantsInvoiceDocumentService.createSourceAccountingLines(cgInvoiceDocument, accounts);
if (ObjectUtils.isNotNull(cgInvoiceDocument.getInvoiceGeneralDetail().getAward())) {
contractsGrantsInvoiceDocumentService.updateSuspensionCategoriesOnDocument(cgInvoiceDocument);
}
LOG.info("Created Contracts & Grants Invoice Document " + cgInvoiceDocument.getDocumentNumber());
} catch (WorkflowException ex) {
LOG.error("Error creating cgin documents: " + ex.getMessage(), ex);
throw new RuntimeException("Error creating cgin documents: " + ex.getMessage(), ex);
}
} else {
// if chart of account code or organization code is not available, output the error
final ErrorMessage errorMessage = new ErrorMessage(ArKeyConstants.ContractsGrantsInvoiceCreateDocumentConstants.NO_CHART_OR_ORG, awd.getProposalNumber());
errorMessages.add(errorMessage);
}
}
return cgInvoiceDocument;
}
Aggregations