public static void UpdatePOFineLine(this POFineLineOutput pofineline, MMSPOEvent model)
 {
     pofineline.PurchaseOrder   = model.PONumber;
     pofineline.Currency        = model.CurrencyCode;
     pofineline.StatusCode      = model.StatusCode;
     pofineline.SubVendorNumber = model.SubVendorNumber;
 }
        public static void UpdatePOFineLinePoSkuData(this POFineLineOutput pofineline, List <POSkus> poskus)
        {
            if (poskus != null && poskus.Count > 0)
            {
                List <POFineLineSkuOutput> poskustobeaddedtoPO = new List <POFineLineSkuOutput>();
                pofineline.POSkus.ForEach(x =>
                {
                    var skutobeupdatefrom = poskus.Find(y => y.SKU == x.SKUNumber);
                    if (skutobeupdatefrom != null)
                    {
                        x.PurchaseOrderDate       = skutobeupdatefrom.CreateDate != null ? skutobeupdatefrom.CreateDate.Value : new DateTime?();
                        x.PurchaseOrderReviseDate = skutobeupdatefrom.ModifiedDate != null ? skutobeupdatefrom.ModifiedDate.Value : new DateTime?();

                        x.OrderQuantity = (skutobeupdatefrom.BuyQuantity == null) ? 0 : skutobeupdatefrom.BuyQuantity.Value;
                        x.StatusCode    = skutobeupdatefrom.StatusCode;
                    }
                });

                //add the poskus if applicable

                var poskustobeadded = poskus.Where(x => !pofineline.POSkus.Any(y => y.SKUNumber == x.SKU));
                poskustobeadded?.ToList().ForEach(y =>
                {
                    poskustobeaddedtoPO.Add(new POFineLineSkuOutput
                    {
                        SKUNumber               = y.SKU,
                        PurchaseOrderDate       = y.CreateDate != null ? y.CreateDate.Value : new DateTime?(),
                        PurchaseOrderReviseDate = y.ModifiedDate != null ? y.ModifiedDate.Value : new DateTime?(),
                        OrderQuantity           = (y.BuyQuantity == null) ? 0 : y.BuyQuantity.Value,
                        StatusCode              = y.StatusCode,
                    });
                });


                if (poskustobeadded?.ToList().Count > 0)
                {
                    pofineline.POSkus.AddRange(poskustobeaddedtoPO);
                }
            }
        }
        /// <summary>
        /// Mehod to compare 2 FineLine objects and return the POskulines that contains the data we want in our final output
        /// </summary>
        public POFineLineOutput CompareFineLineData(POFineLineOutput poskusOutputcurrent, POFineLineOutput 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 POFineLineOutput());
                }

                if (poskusOutputcurrent.POSkus != null && poskusOutputcurrent.POSkus.Count > 0)
                {
                    //Deliberately set the activty code for poskus to null. It will then
                    //be set appropriately on each sku we decide we want to include
                    poskusOutputcurrent.POSkus.ForEach(y =>
                    {
                        y.ActivityCode = null;
                    });
                }
                else
                {
                    _logger.LogInformation($"CompareFineLineData - Skipping output for PO - {poskusOutputcurrent.PurchaseOrder}; no SKUs were found.");
                    return(new POFineLineOutput());
                }
                int          propertyCount   = typeof(POFineLineOutput).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 = (diffs.Where(x => x.ParentPropertyName == string.Empty).Count() > 0);
                    poskusOutputcurrent.POSkus.ForEach(y => CompareFinelinePOSkuData(y, poUpdated, poskusOutputprev, basicComparison));
                    var finalupdatedprod = poskusOutputcurrent.POSkus.Where(posku => posku.ActivityCode != null);
                    if (finalupdatedprod == null || (finalupdatedprod != null && finalupdatedprod.Count() == 0))
                    {
                        return(new POFineLineOutput());
                    }
                }

                ///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 POFineLineOutput());
                    }

                    //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 => CompareFinelinePOSkuData(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 POFineLineOutput());
                }

                var POFineLineOutputtobesent = new POFineLineOutput
                {
                    PurchaseOrder   = poskusOutputcurrent.PurchaseOrder,
                    Currency        = poskusOutputcurrent.Currency,
                    StatusCode      = poskusOutputcurrent.StatusCode,
                    SubVendorNumber = poskusOutputcurrent.SubVendorNumber,
                    POSkus          = finalupdated.ToList()
                };
                return(POFineLineOutputtobesent);
            }
            catch (Exception ex)
            {
                _logger.LogError("Method Name -- CompareFineLineData : {Reason}", ex.Message);
                return(new POFineLineOutput());
            }
        }
        /// <summary>
        /// For a given posku, this will determine if it should be sent through and, if so, sets the ActivityCode appropriately
        /// </summary>
        private void CompareFinelinePOSkuData(POFineLineSkuOutput currentSku, bool parentPOUpdated, POFineLineOutput priorPO, CompareLogic comparisson)
        {
            POFineLineSkuOutput poskutobecompared = null;

            if (priorPO.POSkus != null && priorPO.POSkus.Count > 0)
            {
                //grab the previously sent version for this sku
                poskutobecompared = priorPO.POSkus.Find(posku => posku.SKUNumber == currentSku.SKUNumber);
            }
            else
            {
                _logger.LogInformation($"CompareFinelinePOSkuData - Skipping output for PO - {priorPO.PurchaseOrder}; no SKUs were found.");
                return;
            }

            ////grab the previously sent version for this sku
            //var poskutobecompared = priorPO.POSkus.Find(posku => posku.SKUNumber == currentSku.SKUNumber);
            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 = "";
                }
            }
        }
예제 #5
0
 public static bool CheckPoStatus(this POFineLineOutput POFineLineOutput)
 {
     return(POFineLineOutput.StatusCode == "OP");
 }
        public async Task <POFineLineOutput> UpdatePOObject(POFineLineOutput poobject, MMSProductEvent product, POSkus posku)
        {
            try
            {
                var prodhierarchy = await _lookUpService.GetProductHierarchy(product.SubClass);

                var productlabel = await _lookUpService.GetProductLabelDescription(product.LabelType);

                //check if exists
                if (poobject.POSkus != null && poobject.POSkus.Count > 0 && poobject.POSkus.Exists(y => y.SKUNumber == posku.SKU))
                {
                    var poskutobeupdated = poobject.POSkus.Find(y => y.SKUNumber == posku.SKU);
                    poskutobeupdated.POProduct.SKUDescription    = product?.SkuDescShrt;
                    poskutobeupdated.POProduct.SubClassID        = product?.SubClass;
                    poskutobeupdated.POProduct.TicketType        = productlabel?.Code;
                    poskutobeupdated.POProduct.TicketDescription = productlabel?.Description;
                    poskutobeupdated.POProduct.VendorNumber      = posku.POProduct?.APVendor;
                    poskutobeupdated.POProduct.Size                = product?.Size;
                    poskutobeupdated.POProduct.ISOCountryCode      = product.ProductVendors?.Find(y => y.Sku == posku.SKU)?.CountryOfOrigin;
                    poskutobeupdated.POProduct.ClassID             = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.Class;
                    poskutobeupdated.POProduct.ClassDescription    = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.Description;
                    poskutobeupdated.POProduct.VendorStyleNumber   = product.ProductVendors?.Find(y => y.Sku == posku.SKU)?.VendorSkuCode;
                    poskutobeupdated.POProduct.SubClassDescription = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.SubclassDescription;
                    poskutobeupdated.POProduct.SubVendorNumber     = product.ProductVendors?.Find(y => y.Sku == posku.SKU)?.SubVendor;
                    poskutobeupdated.POProduct.TicketRetail        = posku.GetRetailPrice();
                    return(poobject);
                }
                else
                {
                    POFineLineProductOutput poFLProductOutput = new POFineLineProductOutput
                    {
                        VendorNumber        = posku.POProduct?.APVendor,
                        SubVendorNumber     = product.ProductVendors?.Find(y => y.Sku == posku.SKU)?.SubVendor,
                        SKUDescription      = product?.SkuDescShrt,
                        VendorStyleNumber   = product.ProductVendors?.Find(y => y.Sku == posku.SKU)?.VendorSkuCode,
                        TicketType          = productlabel?.Code,
                        TicketDescription   = productlabel?.Description,
                        ClassID             = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.Class,
                        ClassDescription    = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.Description,
                        SubClassID          = product?.SubClass,
                        SubClassDescription = prodhierarchy?.Find(y => y.SubClass == product?.SubClass)?.SubclassDescription,
                        Size           = product?.Size,
                        ISOCountryCode = product.ProductVendors?.Find(y => y.Sku == posku.SKU)?.CountryOfOrigin,
                        TicketRetail   = posku.GetRetailPrice()
                    };
                    POFineLineSkuOutput POFLSkusOutput = new POFineLineSkuOutput
                    {
                        SKUNumber               = posku.SKU,
                        PurchaseOrderDate       = posku.CreateDate != null ? posku.CreateDate.Value : new DateTime?(),
                        PurchaseOrderReviseDate = posku.ModifiedDate != null ? posku.ModifiedDate.Value : new DateTime?(),
                        OrderQuantity           = posku.BuyQuantity != null?Convert.ToInt32(posku.BuyQuantity) : 0,
                        POProduct               = poFLProductOutput,
                        StatusCode              = posku.StatusCode,
                    };

                    if (poobject.POSkus == null)
                    {
                        poobject.POSkus = new System.Collections.Generic.List <POFineLineSkuOutput>();
                    }
                    poobject.POSkus.Add(POFLSkusOutput);
                    return(poobject);
                }
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "UpdatePOObject - Failed Updating FineLinePO: {Reason} -- {PONumber} -- {Sku }", ex.Message, poobject.PurchaseOrder, posku.SKU);
                return(null);
            }
        }
예제 #7
0
 public static POFineLineOutput MapEventtoOutput(this MMSPOSkuEvent entity, POFineLineOutput pofineline)
 {
     //POSkuevent will not come so this will never be called
     //pofineline.UpdatePOFineLinePoSkuData(entity);
     return(pofineline);
 }
 public static POFineLineOutput MapEventtoOutput(this MMSPOEvent entity, POFineLineOutput pofineline)
 {
     pofineline.UpdatePOFineLine(entity);
     return(pofineline);
 }