This commit is contained in:
2021-07-22 22:35:10 +00:00
parent 4f81bff862
commit 90b90957d9
2 changed files with 152 additions and 14 deletions

View File

@@ -68,7 +68,7 @@ namespace AyaNova.Biz
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, newObject.Tags, null);
await HandlePotentialNotificationEvent(AyaEvent.Created, newObject);
if (populateDisplayFields)
await SetDisplayFields(newObject);
await SetDisplayFields(newObject, false);
return newObject;
}
}
@@ -121,7 +121,7 @@ namespace AyaNova.Biz
{
var ret = await ct.PurchaseOrder.Include(z => z.Items).AsNoTracking().SingleOrDefaultAsync(z => z.Id == id);
if (populateDisplayFields)
await SetDisplayFields(ret);
await SetDisplayFields(ret,false);
if (logTheGetEvent && ret != null)
await EventLogProcessor.LogEventToDatabaseAsync(new Event(UserId, id, BizType, AyaEvent.Retrieved), ct);
@@ -131,7 +131,7 @@ namespace AyaNova.Biz
////////////////////////////////////////////////////////////////////////////////////////////////
//DISPLAY FIELDS
//
private async Task SetDisplayFields(PurchaseOrder po)
private async Task SetDisplayFields(PurchaseOrder po, bool forReporting)
{
//NOTE: This expects to run AFTER bizActions have been performed
if (po == null) return;
@@ -148,8 +148,61 @@ namespace AyaNova.Biz
po.HasUnreceived = false;
if (po.DropShipToCustomerId != null)
po.DropShipToCustomerViz = await ct.Customer.AsNoTracking().Where(x => x.Id == po.DropShipToCustomerId).Select(x => x.Name).FirstOrDefaultAsync();
po.VendorViz = await ct.Vendor.AsNoTracking().Where(x => x.Id == po.VendorId).Select(x => x.Name).FirstOrDefaultAsync();
{
var ds = await ct.Customer.AsNoTracking().Where(x => x.Id == po.DropShipToCustomerId).FirstOrDefaultAsync();
po.DropShipToCustomerViz = ds.Name;
if (forReporting)
{
po.DropShipToCustomerAddressViz = ds.Address;
po.DropShipToCustomerCityViz = ds.City;
po.DropShipToCustomerRegionViz = ds.Region;
po.DropShipToCustomerCountryViz = ds.Country;
po.DropShipToCustomerLatitudeViz = ds.Latitude;
po.DropShipToCustomerLongitudeViz = ds.Longitude;
po.DropShipToCustomerPostAddressViz = ds.PostAddress;
po.DropShipToCustomerPostCityViz = ds.PostCity;
po.DropShipToCustomerPostRegionViz = ds.PostRegion;
po.DropShipToCustomerPostCountryViz = ds.PostCountry;
po.DropShipToCustomerPostCodeViz = ds.PostCode;
po.DropShipToCustomerPhone1Viz = ds.Phone1;
po.DropShipToCustomerPhone2Viz = ds.Phone2;
po.DropShipToCustomerPhone3Viz = ds.Phone3;
po.DropShipToCustomerPhone4Viz = ds.Phone4;
po.DropShipToCustomerPhone5Viz = ds.Phone5;
po.DropShipToCustomerEmailAddressViz = ds.EmailAddress;
}
}
var vnd = await ct.Vendor.AsNoTracking().Where(x => x.Id == po.VendorId).FirstOrDefaultAsync();
po.VendorViz = vnd.Name;
if (forReporting)
{
po.VendorAddressViz = vnd.Address;
po.VendorCityViz = vnd.City;
po.VendorRegionViz = vnd.Region;
po.VendorCountryViz = vnd.Country;
po.VendorLatitudeViz = vnd.Latitude;
po.VendorLongitudeViz = vnd.Longitude;
po.VendorPostAddressViz = vnd.PostAddress;
po.VendorPostCityViz = vnd.PostCity;
po.VendorPostRegionViz = vnd.PostRegion;
po.VendorPostCountryViz = vnd.PostCountry;
po.VendorPostCodeViz = vnd.PostCode;
po.VendorPhone1Viz = vnd.Phone1;
po.VendorPhone2Viz = vnd.Phone2;
po.VendorPhone3Viz = vnd.Phone3;
po.VendorPhone4Viz = vnd.Phone4;
po.VendorPhone5Viz = vnd.Phone5;
po.VendorEmailAddressViz = vnd.EmailAddress;
po.VendorContactViz = vnd.Contact;
po.VendorContactNotesViz = vnd.ContactNotes;
}
if (po.ProjectId != null)
po.ProjectViz = await ct.Project.AsNoTracking().Where(x => x.Id == po.ProjectId).Select(x => x.Name).FirstOrDefaultAsync();
@@ -258,7 +311,7 @@ namespace AyaNova.Biz
await SearchIndexAsync(putObject, false);
await TagBiz.ProcessUpdateTagsInRepositoryAsync(ct, putObject.Tags, dbObject.Tags);
await HandlePotentialNotificationEvent(AyaEvent.Modified, putObject, dbObject);
await SetDisplayFields(putObject);
await SetDisplayFields(putObject, false);
return putObject;
}
}
@@ -678,18 +731,13 @@ namespace AyaNova.Biz
{
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
//TODO: for reporting this would be more ideal if it populated the displayName fields
//I'm doing that in this object already by fluke, and don't really want to populate them always and in other objects but for reporting maybe
//have a report mode get or I guess just do it all here (but then need for export as well, but then again this is the way it gets for export via getreportdata)
//so perhaps we have a REPORT format of a biz object model and that format has display names mirroring all the fields
//it's fetching it here anyway, might as well do the whole shebang?
//query for this batch, comes back in db natural order unfortunately
var batchResults = await ct.PurchaseOrder.Include(x => x.Items).AsNoTracking().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 (PurchaseOrder w in orderedList)
{
await SetDisplayFields(w);
await SetDisplayFields(w, true);
var jo = JObject.FromObject(w);
if (!JsonUtil.JTokenIsNullOrEmpty(jo["CustomFields"]))
jo["CustomFields"] = JObject.Parse((string)jo["CustomFields"]);

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using AyaNova.Biz;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Newtonsoft.Json;
@@ -41,6 +40,97 @@ namespace AyaNova.Models
public List<PurchaseOrderItem> Items { get; set; } = new List<PurchaseOrderItem>();
//VIZ FIELDS
//POSTAL ADDRESS
[NotMapped]
public string DropShipToCustomerPostAddressViz { get; set; }
[NotMapped]
public string DropShipToCustomerPostCityViz { get; set; }
[NotMapped]
public string DropShipToCustomerPostRegionViz { get; set; }
[NotMapped]
public string DropShipToCustomerPostCountryViz { get; set; }
[NotMapped]
public string DropShipToCustomerPostCodeViz { get; set; }
//PHYSICAL ADDRESS
[NotMapped]
public string DropShipToCustomerAddressViz { get; set; }
[NotMapped]
public string DropShipToCustomerCityViz { get; set; }
[NotMapped]
public string DropShipToCustomerRegionViz { get; set; }
[NotMapped]
public string DropShipToCustomerCountryViz { get; set; }
[NotMapped]
public decimal? DropShipToCustomerLatitudeViz { get; set; }
[NotMapped]
public decimal? DropShipToCustomerLongitudeViz { get; set; }
[NotMapped]
public string DropShipToCustomerPhone1Viz { get; set; }
[NotMapped]
public string DropShipToCustomerPhone2Viz { get; set; }
[NotMapped]
public string DropShipToCustomerPhone3Viz { get; set; }
[NotMapped]
public string DropShipToCustomerPhone4Viz { get; set; }
[NotMapped]
public string DropShipToCustomerPhone5Viz { get; set; }
[NotMapped]
public string DropShipToCustomerEmailAddressViz { get; set; }
//POSTAL ADDRESS
[NotMapped]
public string VendorPostAddressViz { get; set; }
[NotMapped]
public string VendorPostCityViz { get; set; }
[NotMapped]
public string VendorPostRegionViz { get; set; }
[NotMapped]
public string VendorPostCountryViz { get; set; }
[NotMapped]
public string VendorPostCodeViz { get; set; }
//PHYSICAL ADDRESS
[NotMapped]
public string VendorAddressViz { get; set; }
[NotMapped]
public string VendorCityViz { get; set; }
[NotMapped]
public string VendorRegionViz { get; set; }
[NotMapped]
public string VendorCountryViz { get; set; }
[NotMapped]
public decimal? VendorLatitudeViz { get; set; }
[NotMapped]
public decimal? VendorLongitudeViz { get; set; }
[NotMapped]
public string VendorContactViz { get; set; }
[NotMapped]
public string VendorContactNotesViz { get; set; }
[NotMapped]
public string VendorPhone1Viz { get; set; }
[NotMapped]
public string VendorPhone2Viz { get; set; }
[NotMapped]
public string VendorPhone3Viz { get; set; }
[NotMapped]
public string VendorPhone4Viz { get; set; }
[NotMapped]
public string VendorPhone5Viz { get; set; }
[NotMapped]
public string VendorEmailAddressViz { get; set; }
//workaround for notification
[NotMapped, JsonIgnore]
public string Name { get; set; }