public static void UpdatePOContempo(this POContempoOutput pocntmp, MMSPOEvent model) { pocntmp.CurrencyCode = model?.CurrencyCode; pocntmp.PONumber = model?.PONumber; pocntmp.SubVendor = model?.SubVendorNumber; pocntmp.StatusCode = model?.StatusCode; }
public static void UpdatePOContempoPoSkuData(this POContempoOutput pocntmp, List <POSkus> poskus) { //check if the POSku exists, update accordingly if (poskus != null && poskus.Count > 0) { List <POContempoSkuOutput> poskustobeaddedtoPO = new List <POContempoSkuOutput>(); poskus.ForEach(x => { var updatePoSKU = pocntmp.POSkus?.Find(p => p.SKU == x.SKU); if (updatePoSKU != null) { updatePoSKU.SKU = x.SKU; updatePoSKU.BuyQuanity = (x.BuyQuantity == null) ? 0 : x.BuyQuantity.Value; updatePoSKU.StatusCode = x.StatusCode; //CreateDate, ModifiedDate properties updatePoSKU.CreateDate = x.CreateDate != null ? x.CreateDate.Value : new DateTime?(); updatePoSKU.ModifiedDate = x.ModifiedDate != null ? x.ModifiedDate.Value : new DateTime?(); } }); //add the poskus if applicable var poskustobeadded = poskus.Where(x => !pocntmp.POSkus.Any(y => y.SKU == x.SKU)); poskustobeadded?.ToList().ForEach(y => { poskustobeaddedtoPO.Add(new POContempoSkuOutput { SKU = y.SKU, BuyQuanity = (y.BuyQuantity == null) ? 0 : y.BuyQuantity.Value, StatusCode = y.StatusCode, CreateDate = y.CreateDate != null ? y.CreateDate.Value : new DateTime?(), ModifiedDate = y.ModifiedDate != null ? y.ModifiedDate.Value : new DateTime?(), }); }); if (poskustobeadded?.ToList().Count > 0) { pocntmp.POSkus.AddRange(poskustobeaddedtoPO); } } }
public static POContempoOutput MapEventtoOutput(this MMSPOEvent entity, POContempoOutput poContempo) { poContempo.UpdatePOContempo(entity); return(poContempo); }
public async Task <POContempoOutput> UpdatePOObject(POContempoOutput poobject, MMSProductEvent product, POSkus posku) { try { var prodhierarchy = await _lookUpService.GetProductHierarchy(product.SubClass); var productlabelcode = await _lookUpService.GetProductLabelDescription(product.LabelType); //check if exists if (poobject.POSkus != null && poobject.POSkus.Count > 0 && poobject.POSkus.Exists(y => y.SKU == posku.SKU) && (product?.Department == "JEP" || product?.Department == "JSF") && product?.SubClass != "JOSAC") { var poskutobeupdated = poobject.POSkus.Find(y => y.SKU == posku.SKU); poskutobeupdated.POProduct.Class = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.Class; poskutobeupdated.POProduct.CountryOfOrigin = product?.ProductVendors?.Find(y => y.Sku == product.Sku && y.SubVendor == poobject.SubVendor)?.CountryOfOrigin; poskutobeupdated.POProduct.SubClass = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.SubClass; poskutobeupdated.POProduct.APVendor = posku.POProduct?.APVendor; poskutobeupdated.POProduct.VendorSKUCode = product?.ProductVendors?.Find(y => y.Sku == product.Sku && y.SubVendor == poobject.SubVendor)?.VendorSkuCode; poskutobeupdated.POProduct.ClassLevelDesc = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.Description; poskutobeupdated.POProduct.Size = posku.POProduct?.Size; poskutobeupdated.POProduct.LabelType = product?.LabelType; //TODO //This LabelDescription value should be populated from "MMSProductEvent" ProductVendors objects labeldescription //For now, it is coming from database so that we know the value is populating. poskutobeupdated.POProduct.LabelDescription = productlabelcode?.Description; poskutobeupdated.POProduct.SkuDesc = product?.SkuDescShrt; poskutobeupdated.POProduct.SubClassLevelDesc = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.SubclassDescription; poskutobeupdated.POProduct.RetailPrice = posku.GetRetailPrice(); //Update CreateDate value once it is available in POSkus object poskutobeupdated.CreateDate = posku.CreateDate != null ? posku.CreateDate.Value : new DateTime?(); poskutobeupdated.ModifiedDate = posku.ModifiedDate != null ? posku.ModifiedDate.Value : new DateTime?(); } else { if ((product?.Department == "JEP" || product?.Department == "JSF") && product?.SubClass != "JOSAC") { POContempoProductOutput poProductOutput = new POContempoProductOutput { LabelType = product?.LabelType, //TODO - need to figure out how we're getting these from MMS //This LabelDescription value should be populated from "MMSProductEvent" ProductVendors objects labeldescription //For now, it is coming from database so that we know the value is populating. LabelDescription = productlabelcode?.Description, Class = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.Class, CountryOfOrigin = posku.POProduct?.CountryOfOrigin, SubClass = prodhierarchy.Find(y => y.SubClass == product?.SubClass)?.SubClass, APVendor = posku.POProduct?.APVendor, VendorSKUCode = product?.ProductVendors?.Find(y => y.Sku == product?.Sku && y.SubVendor == poobject.SubVendor)?.VendorSkuCode, ClassLevelDesc = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.Description, Size = posku.POProduct?.Size, SkuDesc = product?.SkuDescShrt, SubClassLevelDesc = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.SubclassDescription, RetailPrice = posku.GetRetailPrice() }; POContempoSkuOutput POSkusOutput = new POContempoSkuOutput { SKU = posku.SKU, BuyQuanity = posku.BuyQuantity != null?Convert.ToInt32(posku.BuyQuantity) : 0, POProduct = poProductOutput, //Update CreateDate value once it is available in POSkus object CreateDate = posku.CreateDate != null ? posku.CreateDate.Value : new DateTime?(), ModifiedDate = posku.ModifiedDate != null ? posku.ModifiedDate.Value : new DateTime?(), StatusCode = posku.StatusCode, }; if (poobject.POSkus == null) { poobject.POSkus = new System.Collections.Generic.List <POContempoSkuOutput>(); } poobject.POSkus.Add(POSkusOutput); } } return(poobject); } catch (Exception ex) { _logger.LogError(ex, "UpdatePOObject - Failed Updating ContempoPO: {Reason}", ex.Message); return(null); } }
public static bool CheckPoStatus(this POContempoOutput POctmpOutput) { return(POctmpOutput.StatusCode == "OP"); }
/// <summary> /// For a given posku, this will determine if it should be sent through and, if so, sets the ActivityCode appropriately /// </summary> private void CompareContempoPOSkuData(POContempoSkuOutput currentSku, bool parentPOUpdated, POContempoOutput priorPO, CompareLogic comparisson) { //grab the previously sent version for this sku var poskutobecompared = priorPO.POSkus != null?priorPO.POSkus.Find(posku => posku.SKU == currentSku.SKU) : null; if (poskutobecompared == null) { //Never sent before. Only send if its status is open if (currentSku.StatusCode == "OP") { currentSku.ActivityCode = ""; } } else if (currentSku.StatusCode == "CN" || currentSku.StatusCode == "VD") { //Cancelled/voided. Send as "X", but only if it wasn't cancelled or voided when we last sent it if (poskutobecompared.StatusCode != "CN" && poskutobecompared.StatusCode != "VD") { currentSku.ActivityCode = "X"; } } else if (parentPOUpdated) { //Parent PO was modified, so all the child skus are considered modified currentSku.ActivityCode = ""; } else { //Parent PO hasn't changed. See if this sku line was itself modified var diffposkus = comparisson.Compare(currentSku, poskutobecompared).Differences; var diffpoproduct = comparisson.Compare(currentSku.POProduct, poskutobecompared.POProduct).Differences; if (diffposkus?.Count > 0 || diffpoproduct?.Count > 0) { currentSku.ActivityCode = ""; } } }
/// <summary> /// Method to compare 2 PO Contempo objects and return the POskulines that contains the data we want in our final output /// </summary> public POContempoOutput CompareContempoData(POContempoOutput poskusOutputcurrent, POContempoOutput poskusOutputprev, List <string> memberstoInclude) { try { //if the PO is closed, we won't be including it, even if it's changed if (poskusOutputcurrent.StatusCode == "CL") { return(new POContempoOutput()); } //Deliberately set the activty code for poskus to null. It will then //be set appropriately on each sku we decide we want to include if (poskusOutputcurrent.POSkus != null && poskusOutputcurrent.POSkus.Count > 0) { poskusOutputcurrent.POSkus.ForEach(y => { y.ActivityCode = null; }); } else { _logger.LogInformation($"CompareContempoData - Skipping output for PO - {poskusOutputcurrent.PONumber}; no SKUs were found."); return(new POContempoOutput()); } int propertyCount = typeof(POContempoOutput).GetProperties().Length; CompareLogic basicComparison = new CompareLogic() { Config = new ComparisonConfig() { MaxDifferences = propertyCount, MembersToInclude = memberstoInclude } }; List <Difference> diffs = basicComparison.Compare(poskusOutputcurrent, poskusOutputprev).Differences; //None of the values we care about have changed on this PO, so we won't send it. if (diffs == null || diffs.Count() == 0) { bool poUpdated = false; poskusOutputcurrent.POSkus.ForEach(y => CompareContempoPOSkuData(y, poUpdated, poskusOutputprev, basicComparison)); var finalupdatedprod = poskusOutputcurrent.POSkus.Where(posku => posku.ActivityCode != null); if (finalupdatedprod == null || (finalupdatedprod != null && finalupdatedprod.Count() == 0)) { return(new POContempoOutput()); } } ///See if it's been cancelled at the PO level if (poskusOutputcurrent.StatusCode == "CN" || poskusOutputcurrent.StatusCode == "VD") { //If it was previously cancelled, don't send if (poskusOutputprev.StatusCode == "CN" || poskusOutputprev.StatusCode == "VD") { return(new POContempoOutput()); } //Tag first sku with an activity code of "C" and leave the rest null //(we'll only need to send one line for all skus on the PO in this scenario) var first = poskusOutputcurrent.POSkus.FirstOrDefault(); if (first != null) { first.ActivityCode = "C"; } } else { //Determine if there were any differences on PO level, and then validate each sku line for inclusion bool poUpdated = (diffs?.Where(x => x.ParentPropertyName == string.Empty).Count() > 0); poskusOutputcurrent.POSkus.ForEach(y => CompareContempoPOSkuData(y, poUpdated, poskusOutputprev, basicComparison)); } //Now that we're done tagging, all the ones with a non-null ActivityCode are the ones we want in our output file var finalupdated = poskusOutputcurrent.POSkus.Where(posku => posku.ActivityCode != null); if (finalupdated == null || (finalupdated != null && finalupdated.Count() == 0)) { return(new POContempoOutput()); } var POContempoOutputtobesent = new POContempoOutput { //Company = poskusOutputcurrent.Company, PONumber = poskusOutputcurrent.PONumber, CurrencyCode = poskusOutputcurrent.CurrencyCode, StatusCode = poskusOutputcurrent.StatusCode, SubVendor = poskusOutputcurrent.SubVendor, POSkus = finalupdated.ToList() }; return(POContempoOutputtobesent); } catch (Exception ex) { _logger.LogError("Method Name -- CompareContempoData: PO-{PONumber}, {Reason}, {InnerEx}", poskusOutputcurrent.PONumber, ex?.Message, ex?.InnerException.ToString()); return(new POContempoOutput()); } }
public static POContempoOutput MapEventtoOutput(this MMSPOSkuEvent entity, POContempoOutput poCtmpo) { //POSkuevent will not come, so this will never be called //poCtmpo.UpdatePOContempoPoSkuData(entity); return(poCtmpo); }