diff --git a/server/AyaNova/biz/BizObjectFactory.cs b/server/AyaNova/biz/BizObjectFactory.cs index 38208f28..01450694 100644 --- a/server/AyaNova/biz/BizObjectFactory.cs +++ b/server/AyaNova/biz/BizObjectFactory.cs @@ -34,6 +34,8 @@ namespace AyaNova.Biz return new AttachmentBiz(ct, userId, roles); case AyaType.Customer: return new CustomerBiz(ct, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles); + case AyaType.CustomerNote: + return new CustomerNoteBiz(ct, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles); case AyaType.User: return new UserBiz(ct, userId, ServerBootConfig.AYANOVA_DEFAULT_TRANSLATION_ID, roles); diff --git a/server/AyaNova/biz/CustomerBiz.cs b/server/AyaNova/biz/CustomerBiz.cs index 3511585d..a3e7993c 100644 --- a/server/AyaNova/biz/CustomerBiz.cs +++ b/server/AyaNova/biz/CustomerBiz.cs @@ -2,7 +2,6 @@ using System; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using System.Linq; -using EnumsNET; using AyaNova.Util; using AyaNova.Api.ControllerHelpers; using AyaNova.Models; diff --git a/server/AyaNova/biz/CustomerNoteBiz.cs b/server/AyaNova/biz/CustomerNoteBiz.cs index 2625bd7f..ce738101 100644 --- a/server/AyaNova/biz/CustomerNoteBiz.cs +++ b/server/AyaNova/biz/CustomerNoteBiz.cs @@ -1,12 +1,16 @@ +using System; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; +using System.Linq; using AyaNova.Util; using AyaNova.Api.ControllerHelpers; using AyaNova.Models; +using Newtonsoft.Json.Linq; +using System.Collections.Generic; namespace AyaNova.Biz { - internal class CustomerNoteBiz : BizObject, ISearchAbleObject + internal class CustomerNoteBiz : BizObject, ISearchAbleObject, IReportAbleObject, IExportAbleObject { internal CustomerNoteBiz(AyContext dbcontext, long currentUserId, long userTranslationId, AuthorizationRoles UserRoles) { @@ -160,6 +164,43 @@ namespace AyaNova.Biz } + //////////////////////////////////////////////////////////////////////////////////////////////// + //REPORTING + // + public async Task GetReportData(long[] idList) + { + JArray ReportData = new JArray(); + while (idList.Any()) + { + var batch = idList.Take(IReportAbleObject.REPORT_DATA_BATCH_SIZE); + idList = idList.Skip(IReportAbleObject.REPORT_DATA_BATCH_SIZE).ToArray(); + //query for this batch, comes back in db natural order unfortunately + var batchResults = await ct.CustomerNote.Where(z => batch.Contains(z.Id)).ToArrayAsync(); + //order the results back into original + var orderedList = from id in batch join z in batchResults on id equals z.Id select z; + foreach (CustomerNote w in orderedList) + { + var jo = JObject.FromObject(w); + // jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]); + ReportData.Add(jo); + } + } + return ReportData; + } + + + //////////////////////////////////////////////////////////////////////////////////////////////// + // IMPORT EXPORT + // + + + public async Task GetExportData(long[] idList) + { + //for now just re-use the report data code + //this may turn out to be the pattern for most biz object types but keeping it seperate allows for custom usage from time to time + return await GetReportData(idList); + } + //////////////////////////////////////////////////////////////////////////////////////////////// //VALIDATION // diff --git a/server/AyaNova/biz/ReportBiz.cs b/server/AyaNova/biz/ReportBiz.cs index 5bb27e6a..ad4d085e 100644 --- a/server/AyaNova/biz/ReportBiz.cs +++ b/server/AyaNova/biz/ReportBiz.cs @@ -282,7 +282,7 @@ namespace AyaNova.Biz if (string.IsNullOrWhiteSpace(proposedObj.Name)) AddError(ApiErrorCode.VALIDATION_REQUIRED, "Name"); - + //If name is otherwise OK, check that name is unique if (!PropertyHasErrors("Name")) @@ -318,7 +318,7 @@ namespace AyaNova.Biz { var log = AyaNova.Util.ApplicationLogging.CreateLogger("ReportBiz::GetReportData"); AuthorizationRoles effectiveRoles = CurrentUserRoles; - + if (!AyaNova.Api.ControllerHelpers.Authorized.HasReadFullRole(effectiveRoles, reportDataParam.ObjectType)) { @@ -355,7 +355,7 @@ namespace AyaNova.Biz } AuthorizationRoles effectiveRoles = CurrentUserRoles; - + if (!AyaNova.Api.ControllerHelpers.Authorized.HasReadFullRole(effectiveRoles, report.ObjectType)) { @@ -376,7 +376,15 @@ namespace AyaNova.Biz //Get data - var ReportData = await GetReportData(new DataListSelection() { ObjectType = report.ObjectType, SelectedRowIds = reportParam.SelectedRowIds, DataListKey = reportParam.DataListKey, ListView = reportParam.ListView }); + var ReportData = await GetReportData( + new DataListSelection() + { + ObjectType = report.ObjectType, + SelectedRowIds = reportParam.SelectedRowIds, + DataListKey = reportParam.DataListKey, + ListView = reportParam.ListView, + MetaView = reportParam.MetaView + }); //initialization log.LogDebug("Initializing report system"); @@ -426,7 +434,7 @@ namespace AyaNova.Biz using (var page = await browser.NewPageAsync()) { //see catch block - // var ChromiumProcessID = browser.Process.Id; + // var ChromiumProcessID = browser.Process.Id; try { diff --git a/server/AyaNova/models/dto/RenderReportParameter.cs b/server/AyaNova/models/dto/RenderReportParameter.cs index 26525c19..f7664bfd 100644 --- a/server/AyaNova/models/dto/RenderReportParameter.cs +++ b/server/AyaNova/models/dto/RenderReportParameter.cs @@ -8,7 +8,8 @@ namespace AyaNova.Models public long ReportId { get; set; } public long[] SelectedRowIds { get; set; } public string DataListKey { get; set; } - public string ListView { get; set; }//optional, if null or empty will use default list view built into DataList + public string ListView { get; set; }//optional, if null or empty will use default list view built into DataList + public string MetaView { get; set; }//optional meta list view to integrate into the standard list view. Used by client to add "meta" filter conditions above the user's choices e.g. customer notes customer id public JToken ClientMeta {get;set;}//meta JSON data passed from client, not part of biz object data }