public async Task <DocumentTemplate> GetTemplateByPath(string reportPath, PhysicalDocumentType documentType, string company) { var templates = await GetTemplates(documentType, company, true); var template = templates.FirstOrDefault(t => t.Path == reportPath); return(template); }
public static string GetApplicationTableName(this PhysicalDocumentType physicalDocumentType) { switch (physicalDocumentType) { case PhysicalDocumentType.ContractAdvice: return("Section"); case PhysicalDocumentType.InvoiceGoodsInvoice: case PhysicalDocumentType.InvoiceCostsInvoice: case PhysicalDocumentType.InvoiceGoodsCostInvoice: case PhysicalDocumentType.InvoiceWashout: case PhysicalDocumentType.InvoiceString: case PhysicalDocumentType.InvoiceCircle: case PhysicalDocumentType.InvoiceProvisional: case PhysicalDocumentType.InvoiceFinal: case PhysicalDocumentType.InvoicePrepayment: case PhysicalDocumentType.InvoiceCancellation: return("Invoice"); case PhysicalDocumentType.CashSimpleCash: case PhysicalDocumentType.CashPickByTransaction: case PhysicalDocumentType.CashDifferentClient: case PhysicalDocumentType.CashDifferentCurrency: return("Cash"); case PhysicalDocumentType.ManualCreationJournalEntry: case PhysicalDocumentType.ManualCreationManualccrual: case PhysicalDocumentType.ManualCreationManualMTM: case PhysicalDocumentType.MonthEndAccruals: case PhysicalDocumentType.MonthEndMTMFX: case PhysicalDocumentType.MonthEndMTMFnO: case PhysicalDocumentType.MonthEndMTMPhysicals: case PhysicalDocumentType.MonthEndMTMInventory: case PhysicalDocumentType.MonthEndInventoryValidation: default: throw new System.Exception($"Unknown document type: {physicalDocumentType}"); } }
public static string GenerateErrorMessage(PhysicalDocumentType physicalDocumentType, PhysicalDocumentErrors errors) { switch (errors) { case PhysicalDocumentErrors.Format: return($"The selected document can only be a Word (.doc or .docx). " + $"The {EnumUtils.GetDisplayName(physicalDocumentType)} has not been created. " + $"Please repeat the operation with another document or choose another option."); case PhysicalDocumentErrors.Size: return($"The size of the selected document has to be inferior to 3MB. " + $"The {EnumUtils.GetDisplayName(physicalDocumentType)} has not been created. " + $"Please repeat the operation with another document or choose another option."); case PhysicalDocumentErrors.Unknown: case PhysicalDocumentErrors.Naming: case PhysicalDocumentErrors.General: default: return($"The selected document format does not allow to add the Document reference. " + $"The {EnumUtils.GetDisplayName(physicalDocumentType)} has not been created. " + "Please repeat the operation with another document or choose another option."); } }
public async Task <IEnumerable <DocumentTemplate> > GetTemplates(PhysicalDocumentType physicalDocumentType, string company, bool recursive, string module = "") { var documentTypes = await _documentTypeRepository.GetGeneratedDocumentTypesAsync(); var documentType = documentTypes.First(t => t.PhysicalDocumentTypeId == (int)physicalDocumentType); // Retrieve data from cache string cacheKey = $"SSRS_Templates_{company}_{documentType.PhysicalDocumentTypeId}_{recursive}_{module}"; var cachedJson = await _distributedCache.GetStringAsync(cacheKey); if (cachedJson != null) { var cachedDocumentTemplates = JsonConvert.DeserializeObject <List <DocumentTemplate> >(cachedJson); return(cachedDocumentTemplates); } try { var paths = documentType.TemplatesPaths.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries); List <ReportService2010.CatalogItem> catalogItems = new List <ReportService2010.CatalogItem>(); foreach (var path in paths) { var templatesPath = path.Replace("{company}", company); if (physicalDocumentType == PhysicalDocumentType.CustomReport && module != "module") { templatesPath = path + @"/" + company + @"/" + module; } var companyCatalogItems = await ListChildren(templatesPath, true); catalogItems.AddRange(companyCatalogItems); if (physicalDocumentType == PhysicalDocumentType.CustomReport) { catalogItems.RemoveAll(catalog => catalog.Path.ToLower().Contains(@"/archive/")); } } var documentTemplates = catalogItems .Where(i => i.TypeName == "Report" && !i.Hidden) //&& (i.Name.StartsWith(company, StringComparison.InvariantCultureIgnoreCase) || i.Name.StartsWith("cm", StringComparison.InvariantCultureIgnoreCase)) //&& i.Name.IndexOf(keyword, StringComparison.InvariantCultureIgnoreCase) >= 0) .Select(i => new DocumentTemplate { Id = i.ID, Name = i.Name, Path = i.Path, Description = i.Description, CreatedDateTime = i.CreationDate, CreatedBy = i.CreatedBy, ModifiedDateTime = i.ModifiedDate, ModifiedBy = i.ModifiedBy }).ToList(); // Save the data in cache var jsonToCache = JsonConvert.SerializeObject(documentTemplates); await _distributedCache.SetStringAsync(cacheKey, jsonToCache, new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10) // TODO: use settings ? }); return(documentTemplates.OrderBy(doc => doc.Name)); } catch (Exception e) { _logger.LogError(e, "Error retrieving templates from SSRS."); return(Enumerable.Empty <DocumentTemplate>()); } }