Search in sources :

Example 1 with CustomerAddress

use of org.kuali.kfs.module.ar.businessobject.CustomerAddress in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method buildInvoiceAddressDetails.

/**
 * Builds a list of InvoiceAddressDetails based on the customer associated with the Award
 *
 * @param award    the award associated with the proposal we're building a CINV document for
 * @param document the CINV document we're creating
 * @return a List of the generated invoice address details
 */
protected List<InvoiceAddressDetail> buildInvoiceAddressDetails(ContractsAndGrantsBillingAward award, ContractsGrantsInvoiceDocument document) {
    CustomerAddress customerAddress = null;
    if (ObjectUtils.isNotNull(award.getCustomerAddressIdentifier())) {
        customerAddress = customerAddressService.getByPrimaryKey(award.getCustomerNumber(), award.getCustomerAddressIdentifier());
    }
    if (customerAddress == null) {
        customerAddress = customerAddressService.getPrimaryAddress(award.getCustomerNumber());
    }
    String documentNumber = document.getDocumentNumber();
    List<InvoiceAddressDetail> invoiceAddressDetails = new ArrayList<>();
    AtomicInteger detailNumber = new AtomicInteger(1);
    if (StringUtils.equalsIgnoreCase(ArKeyConstants.CustomerConstants.CUSTOMER_ADDRESS_TYPE_CODE_PRIMARY, customerAddress.getCustomerAddressTypeCode())) {
        document.setCustomerBillToAddressOnInvoice(customerAddress);
    }
    InvoiceAddressDetail invoiceAddressDetail = new InvoiceAddressDetail();
    invoiceAddressDetail.setCustomerNumber(customerAddress.getCustomerNumber());
    invoiceAddressDetail.setDocumentNumber(documentNumber);
    invoiceAddressDetail.setCustomerAddressIdentifier(customerAddress.getCustomerAddressIdentifier());
    invoiceAddressDetail.setDetailNumber(detailNumber.getAndIncrement());
    invoiceAddressDetail.setCustomerAddressTypeCode(customerAddress.getCustomerAddressTypeCode());
    invoiceAddressDetail.setCustomerAddressName(customerAddress.getCustomerAddressName());
    invoiceAddressDetail.setInvoiceTransmissionMethodCode(ArConstants.InvoiceTransmissionMethod.MAIL);
    invoiceAddressDetail.setCustomerLine1StreetAddress(customerAddress.getCustomerLine1StreetAddress());
    invoiceAddressDetail.setCustomerLine2StreetAddress(customerAddress.getCustomerLine2StreetAddress());
    invoiceAddressDetail.setCustomerCityName(customerAddress.getCustomerCityName());
    invoiceAddressDetail.setCustomerStateCode(customerAddress.getCustomerStateCode());
    invoiceAddressDetail.setCustomerZipCode(customerAddress.getCustomerZipCode());
    invoiceAddressDetail.setCustomerCountryCode(customerAddress.getCustomerCountryCode());
    invoiceAddressDetail.setCustomerInternationalMailCode(customerAddress.getCustomerInternationalMailCode());
    invoiceAddressDetail.setCustomerAddressInternationalProvinceName(customerAddress.getCustomerAddressInternationalProvinceName());
    if (StringUtils.isNotBlank(customerAddress.getCustomerInvoiceTemplateCode())) {
        invoiceAddressDetail.setCustomerInvoiceTemplateCode(customerAddress.getCustomerInvoiceTemplateCode());
    } else {
        AccountsReceivableCustomer customer = award.getAgency().getCustomer();
        if (ObjectUtils.isNotNull(customer) && StringUtils.isNotBlank(customer.getCustomerInvoiceTemplateCode())) {
            invoiceAddressDetail.setCustomerInvoiceTemplateCode(customer.getCustomerInvoiceTemplateCode());
        }
    }
    if (ArConstants.InvoiceTransmissionMethod.MAIL.equals(customerAddress.getInvoiceTransmissionMethodCode())) {
        invoiceAddressDetail.setSendIndicator(true);
    }
    invoiceAddressDetails.add(invoiceAddressDetail);
    CustomerAddress finalCustomerAddress = customerAddress;
    customerAddress.getCustomerAddressEmails().stream().filter(AccountsReceivableCustomerAddressEmail::isActive).forEach(email -> {
        InvoiceAddressDetail invoiceAddressDetailWithEmail = new InvoiceAddressDetail();
        invoiceAddressDetailWithEmail.setCustomerNumber(finalCustomerAddress.getCustomerNumber());
        invoiceAddressDetailWithEmail.setDocumentNumber(documentNumber);
        invoiceAddressDetailWithEmail.setCustomerAddressIdentifier(finalCustomerAddress.getCustomerAddressIdentifier());
        invoiceAddressDetailWithEmail.setDetailNumber(detailNumber.getAndIncrement());
        invoiceAddressDetailWithEmail.setCustomerEmailAddress(email.getCustomerEmailAddress());
        invoiceAddressDetailWithEmail.setInvoiceTransmissionMethodCode(ArConstants.InvoiceTransmissionMethod.EMAIL);
        if (ArConstants.InvoiceTransmissionMethod.EMAIL.equals(finalCustomerAddress.getInvoiceTransmissionMethodCode())) {
            invoiceAddressDetailWithEmail.setSendIndicator(true);
        }
        invoiceAddressDetails.add(invoiceAddressDetailWithEmail);
    });
    return invoiceAddressDetails;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AccountsReceivableCustomer(org.kuali.kfs.integration.ar.AccountsReceivableCustomer) ArrayList(java.util.ArrayList) InvoiceAddressDetail(org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail) CustomerAddress(org.kuali.kfs.module.ar.businessobject.CustomerAddress)

Example 2 with CustomerAddress

use of org.kuali.kfs.module.ar.businessobject.CustomerAddress in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceDocumentServiceImpl method generateInvoicesForInvoiceAddresses.

@Override
public void generateInvoicesForInvoiceAddresses(ContractsGrantsInvoiceDocument document) {
    InvoiceTemplate invoiceTemplate;
    byte[] reportStream;
    InvoiceGeneralDetail invoiceGeneralDetail = document.getInvoiceGeneralDetail();
    if (ObjectUtils.isNotNull(invoiceGeneralDetail.getCustomerInvoiceTemplateCode())) {
        CustomerAddress customerAddress = invoiceGeneralDetail.getCustomerAddress();
        String customerAddressName = customerAddress.getCustomerAddressName();
        invoiceTemplate = businessObjectService.findBySinglePrimaryKey(InvoiceTemplate.class, invoiceGeneralDetail.getCustomerInvoiceTemplateCode());
        if (ObjectUtils.isNotNull(invoiceTemplate) && invoiceTemplate.isActive() && StringUtils.isNotBlank(invoiceTemplate.getFilename())) {
            ModuleConfiguration systemConfiguration = kualiModuleService.getModuleServiceByNamespaceCode(KFSConstants.OptionalModuleNamespaces.ACCOUNTS_RECEIVABLE).getModuleConfiguration();
            String templateFolderPath = ((FinancialSystemModuleConfiguration) systemConfiguration).getTemplateFileDirectories().get(KFSConstants.TEMPLATES_DIRECTORY_KEY);
            String templateFilePath = templateFolderPath + File.separator + invoiceTemplate.getFilename();
            File templateFile = new File(templateFilePath);
            String outputFileName;
            try {
                Map<String, String> replacementList = getTemplateParameterList(document);
                reportStream = PdfFormFillerUtil.populateTemplate(templateFile, replacementList);
                outputFileName = buildFilenamePrefix(document, customerAddressName) + ArConstants.TemplateUploadSystem.EXTENSION;
                String watermarkText = null;
                if (ObjectUtils.isNotNull(document.getInvoiceGeneralDetail()) && document.getInvoiceGeneralDetail().isFinalBillIndicator()) {
                    watermarkText = getConfigurationService().getPropertyValueAsString(ArKeyConstants.INVOICE_ADDRESS_PDF_WATERMARK_FINAL);
                }
                Long noteId = buildAndAddInvoiceNote(document, reportStream, customerAddressName, outputFileName, ArKeyConstants.INVOICE_ADDRESS_PDF_FINAL_NOTE, watermarkText);
                document.getInvoiceGeneralDetail().setInvoiceNoteId(noteId);
                documentService.updateDocument(document);
            } catch (IOException ex) {
                addNoteForInvoiceReportFail(document);
            }
        } else {
            addNoteForInvoiceReportFail(document);
        }
    } else {
        addNoteForInvoiceReportFail(document);
    }
}
Also used : ModuleConfiguration(org.kuali.kfs.krad.bo.ModuleConfiguration) FinancialSystemModuleConfiguration(org.kuali.kfs.sys.FinancialSystemModuleConfiguration) InvoiceTemplate(org.kuali.kfs.module.ar.businessobject.InvoiceTemplate) InvoiceGeneralDetail(org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail) IOException(java.io.IOException) File(java.io.File) CustomerAddress(org.kuali.kfs.module.ar.businessobject.CustomerAddress)

Example 3 with CustomerAddress

use of org.kuali.kfs.module.ar.businessobject.CustomerAddress in project cu-kfs by CU-CommunityApps.

the class ContractsGrantsInvoiceCreateDocumentServiceImpl method populateInvoiceDetailFromAward.

/**
 * This method takes all the applicable attributes from the associated award object and sets those attributes
 * into their corresponding invoice attributes.
 *
 * @param invoiceGeneralDetail the invoice detail to populate
 * @param award                The associated award that the invoice will be linked to.
 */
protected void populateInvoiceDetailFromAward(InvoiceGeneralDetail invoiceGeneralDetail, ContractsAndGrantsBillingAward award) {
    invoiceGeneralDetail.setAwardTotal(award.getAwardTotalAmount());
    invoiceGeneralDetail.setAgencyNumber(award.getAgencyNumber());
    if (ObjectUtils.isNotNull(award.getBillingFrequencyCode())) {
        invoiceGeneralDetail.setBillingFrequencyCode(award.getBillingFrequencyCode());
    }
    if (ObjectUtils.isNotNull(award.getInstrumentTypeCode())) {
        invoiceGeneralDetail.setInstrumentTypeCode(award.getInstrumentTypeCode());
    }
    String awdDtRange = getDateTimeService().toDateString(award.getAwardBeginningDate()) + " to " + getDateTimeService().toDateString(award.getAwardEndingDate());
    invoiceGeneralDetail.setAwardDateRange(awdDtRange);
    invoiceGeneralDetail.setTotalPreviouslyBilled(contractsGrantsInvoiceDocumentService.getAwardBilledToDateAmount(award.getProposalNumber()));
    ContractsAndGrantsBillingAgency agency = award.getAgency();
    if (ObjectUtils.isNotNull(agency)) {
        String customerNumber = agency.getCustomerNumber();
        // default to primary of the customer
        CustomerAddress customerAddress = customerAddressService.getPrimaryAddress(customerNumber);
        // if award has customer address identifier - use it for population
        if (ObjectUtils.isNotNull(award.getCustomerAddressIdentifier())) {
            customerAddress = customerAddressService.getByPrimaryKey(customerNumber, award.getCustomerAddressIdentifier());
        }
        if (StringUtils.isNotBlank(customerAddress.getCustomerInvoiceTemplateCode())) {
            invoiceGeneralDetail.setCustomerInvoiceTemplateCode(customerAddress.getCustomerInvoiceTemplateCode());
        } else {
            AccountsReceivableCustomer customer = agency.getCustomer();
            if (ObjectUtils.isNotNull(customer) && StringUtils.isNotBlank(customer.getCustomerInvoiceTemplateCode())) {
                invoiceGeneralDetail.setCustomerInvoiceTemplateCode(customer.getCustomerInvoiceTemplateCode());
            }
        }
        invoiceGeneralDetail.setCustomerNumber(customerNumber);
        invoiceGeneralDetail.setCustomerAddressIdentifier(customerAddress.getCustomerAddressIdentifier());
    }
}
Also used : AccountsReceivableCustomer(org.kuali.kfs.integration.ar.AccountsReceivableCustomer) ContractsAndGrantsBillingAgency(org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAgency) CustomerAddress(org.kuali.kfs.module.ar.businessobject.CustomerAddress)

Aggregations

CustomerAddress (org.kuali.kfs.module.ar.businessobject.CustomerAddress)3 AccountsReceivableCustomer (org.kuali.kfs.integration.ar.AccountsReceivableCustomer)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ContractsAndGrantsBillingAgency (org.kuali.kfs.integration.cg.ContractsAndGrantsBillingAgency)1 ModuleConfiguration (org.kuali.kfs.krad.bo.ModuleConfiguration)1 InvoiceAddressDetail (org.kuali.kfs.module.ar.businessobject.InvoiceAddressDetail)1 InvoiceGeneralDetail (org.kuali.kfs.module.ar.businessobject.InvoiceGeneralDetail)1 InvoiceTemplate (org.kuali.kfs.module.ar.businessobject.InvoiceTemplate)1 FinancialSystemModuleConfiguration (org.kuali.kfs.sys.FinancialSystemModuleConfiguration)1