From fc52804362b1c8f0b5dac439fae78e6a2d1f5047 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 30 Jan 2020 17:19:07 -0800 Subject: [PATCH] Added fetching for Shop Region + OPCODE decoding. --- BodyshopUploader/Models/Bodyshop.cs | 7 +++ BodyshopUploader/Utils/AppMetaData.cs | 3 + .../Utils/Decoder/EstimateDecoder.cs | 30 ++++++++-- BodyshopUploader/Utils/JobProcessingQueue.cs | 21 +++++++ BodyshopUploader/ViewModels/MainViewModel.cs | 58 +++++++++++++------ 5 files changed, 96 insertions(+), 23 deletions(-) diff --git a/BodyshopUploader/Models/Bodyshop.cs b/BodyshopUploader/Models/Bodyshop.cs index 38b5c68..441fe6f 100644 --- a/BodyshopUploader/Models/Bodyshop.cs +++ b/BodyshopUploader/Models/Bodyshop.cs @@ -48,5 +48,12 @@ namespace BodyshopUploader.Models get { return _associationActive; } set { SetProperty(ref _associationActive, value); } } + private string _regionConfig; + [JsonProperty("region_config")] + public string RegionConfig + { + get { return _regionConfig; } + set { SetProperty(ref _regionConfig, value); } + } } } diff --git a/BodyshopUploader/Utils/AppMetaData.cs b/BodyshopUploader/Utils/AppMetaData.cs index 9f8a355..953a3b0 100644 --- a/BodyshopUploader/Utils/AppMetaData.cs +++ b/BodyshopUploader/Utils/AppMetaData.cs @@ -8,7 +8,10 @@ namespace BodyshopUploader.Utils { public static class AppMetaData { + //TODO: Change firebase API Key to be dependent on what environment monitor has been set for. public static string FirebaseAPIKey_DEV = "AIzaSyDV9MsSHZmpLtjoaTK_ObvjFaJ-nMSd2KA"; public static string ActiveShopId = Properties.Settings.Default.LastSelectedShop; + public static string ShopRegion = ""; + public static dynamic CiecaOpCodes; } } diff --git a/BodyshopUploader/Utils/Decoder/EstimateDecoder.cs b/BodyshopUploader/Utils/Decoder/EstimateDecoder.cs index 5ce3693..3e81286 100644 --- a/BodyshopUploader/Utils/Decoder/EstimateDecoder.cs +++ b/BodyshopUploader/Utils/Decoder/EstimateDecoder.cs @@ -848,11 +848,7 @@ namespace BodyshopUploader.Utils.Decoder var allLines = new JArray(); - //Create new column to capture lbr op code description. in UI, show partno ? partno : op code desc. has to be stamped - //If the OEM_PARTNO is empty, use the operation code and look it up in opcode table. If found, take opcode.opcodedescription and populate oem_partno with it - //populate lbr_op with opcode.opcodetouse - //if part_type is blank, pull in the part type from parttypetousemitchell - //if not found, set description to not efined + #region Code //TODO: How to handle price markup and discounts. @@ -964,6 +960,26 @@ namespace BodyshopUploader.Utils.Decoder lin.bett_amt = readValues[43];//BETT_AMT lin.bett_tax = readValues[44];//BETT_TAX + //Create new column to capture lbr op code description. in UI, show partno ? partno : op code desc. has to be stamped + //If the OEM_PARTNO is empty, use the operation code and look it up in opcode table. If found, take opcode.opcodedescription and populate oem_partno with it + //populate lbr_op with opcode.opcodetouse + //if part_type is blank, pull in the part type from parttypetousemitchell + //if not found, set description to not efined + + if (string.IsNullOrEmpty(lin.oem_partno.Value)) + { + try + { + lin.op_code_desc = Utils.AppMetaData.CiecaOpCodes[lin.lbr_op.Value]["desc"].Value; + } + catch (Exception Ex) + { + logger.Warn(Ex, "Couldnt find OpCodeDesc from {0} ", lin.lbr_op.Value); + } + + } + + allLines.Add(lin); } @@ -984,6 +1000,10 @@ namespace BodyshopUploader.Utils.Decoder } } + public static object ReflectPropertyValue(object source, string property) + { + return source.GetType().GetProperty(property).GetValue(source, null); + } public static void ParseTtlFile(ref dynamic j, string RootFilePath) { diff --git a/BodyshopUploader/Utils/JobProcessingQueue.cs b/BodyshopUploader/Utils/JobProcessingQueue.cs index c7c6c5d..2d27ab0 100644 --- a/BodyshopUploader/Utils/JobProcessingQueue.cs +++ b/BodyshopUploader/Utils/JobProcessingQueue.cs @@ -66,6 +66,7 @@ namespace BodyshopUploader.Utils try { Thread.Sleep(1000);//Allow a small amount of time to pass before processing the queue item so that any writes can finish. + await GetOpCodes(); DecodeQueueItemJob(item); await UpsertQueueItem(item); } @@ -77,6 +78,26 @@ namespace BodyshopUploader.Utils } } } + + private static async Task GetOpCodes() + { + var r = new GraphQLRequest + { + Query = @"query MyQuery($key: String!) { + masterdata(where: {key: {_eq: $key}}) { + value + key + } + }", + Variables = new + { + key = "CA_BC_ciecaopcodes" + } + }; + var data = await Utils.GraphQL.ExecuteQuery(r); + + Utils.AppMetaData.CiecaOpCodes = JObject.Parse(data.masterdata[0].value.Value); + } private static void DecodeQueueItemJob(DTO_QueueItem item) { diff --git a/BodyshopUploader/ViewModels/MainViewModel.cs b/BodyshopUploader/ViewModels/MainViewModel.cs index e014862..bb11fcc 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.cs @@ -3,6 +3,7 @@ using BodyshopUploader.Utils.Growls; using GraphQL.Client; using GraphQL.Common.Request; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -138,6 +139,7 @@ namespace BodyshopUploader.ViewModels bodyshops { shopname id + region_config associations { id active @@ -194,31 +196,51 @@ namespace BodyshopUploader.ViewModels Properties.Settings.Default.LastSelectedShop = ActiveShop.Id; Properties.Settings.Default.Save(); Utils.AppMetaData.ActiveShopId = ActiveShop.Id; + Utils.AppMetaData.ShopRegion = ActiveShop.RegionConfig; IndeterminateLoading = false; } public async Task TestGql() { - Notification _n = new Notification() - { - Id = 123, - Title = "This is a title", - Subtitle = "Subtitle", - Message = "Somethin" - }; - Growler.AddNotification(_n); - - //var r = new GraphQLRequest + //Notification _n = new Notification() //{ - // Query = @" - // query QUERY_BODYSHOPS { - // bodyshops { - // shopname - // id - // } - // }" + // Id = 123, + // Title = "This is a title", + // Subtitle = "Subtitle", + // Message = "Somethin" //}; - //await Utils.GraphQL.ExecuteQuery(r); + //Growler.AddNotification(_n); + + var r = new GraphQLRequest + { + Query = @"query MyQuery($key: String!) { + masterdata(where: {key: {_eq: $key}}) { + value + key + } + }", + Variables = new + { + key = Utils.AppMetaData.ShopRegion + "_ciecaopcodes" + } + }; + var data = await Utils.GraphQL.ExecuteQuery(r); + + //var t = Newtonsoft.Json.JsonConvert.DeserializeObject>(data.masterdata[0].value.Value); + Utils.AppMetaData.CiecaOpCodes = JObject.Parse(data.masterdata[0].value.Value); + + try + { + var aa = Utils.AppMetaData.CiecaOpCodes.Property("OP1").Children(); + var cc = Utils.AppMetaData.CiecaOpCodes["OP1"]["desc"].Value; + var ab = Utils.AppMetaData.CiecaOpCodes.Property("OP1.desc"); + + } + catch (Exception EX) + { + logger.Warn("Err"); + } + } } }