use of org.kuali.kfs.krad.bo.ModuleConfiguration 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);
}
}
Aggregations