Ejemplo n.º 1
0
        public void SetReturnedReturnables(IEnumerable <KeyValuePair <Returnable, int> > returnables)
        {
            if (returnables == null || !returnables.Any())
            {
                ReturnedReturnables = new List <DeliveryReturnable>();
                return;
            }

            if (ReturnedReturnables == null)
            {
                ReturnedReturnables = new List <DeliveryReturnable>();
            }

            var newReturnableIds      = returnables.Select(r => r.Key.Id);
            var existingReturnableIds = ReturnedReturnables.Select(r => r.ReturnableId);

            var returnablesToRemove = newReturnableIds.Except(existingReturnableIds);

            foreach (var returnableToRemove in returnablesToRemove)
            {
                var returnable = ReturnedReturnables.SingleOrDefault(r => r.ReturnableId == returnableToRemove);
                ReturnedReturnables.Remove(returnable);
            }

            foreach (var returnable in returnables)
            {
                var existingReturnable = ReturnedReturnables.SingleOrDefault(r => r.ReturnableId == returnable.Key.Id);
                if (existingReturnable != null)
                {
                    existingReturnable.SetQuantity(returnable.Value);
                }
                else
                {
                    ReturnedReturnables.Add(new DeliveryReturnable(returnable.Key, returnable.Value));
                }
            }

            Refresh();
        }
Ejemplo n.º 2
0
        private void Refresh()
        {
            ReturnedReturnablesCount = ReturnedReturnables?.Sum(p => p.Quantity) ?? 0;
            BrokenProductsCount      = Products.Where(p => p.RowKind == ModificationKind.Broken).Sum(p => p.Quantity);
            ImproperProductsCount    = Products.Where(p => p.RowKind == ModificationKind.Improper).Sum(p => p.Quantity);
            ExcessProductsCount      = Products.Where(p => p.RowKind == ModificationKind.Excess).Sum(p => p.Quantity);
            MissingProductsCount     = Products.Where(p => p.RowKind == ModificationKind.Missing).Sum(p => p.Quantity);
            ReturnablesCount         = Products.Where(p => p.HasReturnable).Sum(p => p.Quantity);
            ProductsToDeliverCount   = Products.Where(p => p.RowKind == ModificationKind.ToDeliver).Sum(p => p.Quantity);
            PurchaseOrdersCount      = PurchaseOrders.Count;
            ProductsDeliveredCount   = ProductsToDeliverCount + BrokenProductsCount + MissingProductsCount +
                                       ImproperProductsCount + ExcessProductsCount;

            DeliveryFeesWholeSalePrice = PurchaseOrders.Max(po => po.ExpectedDelivery.DeliveryFeesWholeSalePrice);
            DeliveryFeesVatPrice       = PurchaseOrders.Max(po => po.ExpectedDelivery.DeliveryFeesVatPrice);
            DeliveryFeesOnSalePrice    = PurchaseOrders.Max(po => po.ExpectedDelivery.DeliveryFeesOnSalePrice);

            if (PurchaseOrdersCount < 1)
            {
                Status = DeliveryStatus.Cancelled;
            }

            DeliveryBatch?.Refresh();
        }