Search in sources :

Example 1 with InvoiceTemplate

use of org.kuali.kfs.module.ar.businessobject.InvoiceTemplate 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)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 ModuleConfiguration (org.kuali.kfs.krad.bo.ModuleConfiguration)1 CustomerAddress (org.kuali.kfs.module.ar.businessobject.CustomerAddress)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