Exemple #1
0
        public void RemovePurchaseOrders(IEnumerable <PurchaseOrder> purchaseOrders)
        {
            if (Status == PickingStatus.Completed)
            {
                throw SheaftException.Validation(
                          "Impossible de modifier les commandes d'une préparation qui est terminée.");
            }

            if (PurchaseOrders == null)
            {
                throw SheaftException.NotFound("Cette préparation ne contient pas de commandes.");
            }

            if (purchaseOrders == null || !purchaseOrders.Any())
            {
                return;
            }

            foreach (var purchaseOrder in purchaseOrders)
            {
                foreach (var purchaseOrderProduct in purchaseOrder.Products)
                {
                    var product = ProductsToPrepare.FirstOrDefault(p =>
                                                                   p.ProductId == purchaseOrderProduct.ProductId && p.PurchaseOrderId == purchaseOrder.Id);

                    if (product == null)
                    {
                        continue;
                    }

                    ProductsToPrepare.Remove(product);

                    var preparedProduct = PreparedProducts.FirstOrDefault(p =>
                                                                          p.ProductId == purchaseOrderProduct.ProductId && p.PurchaseOrderId == purchaseOrder.Id);

                    if (preparedProduct == null)
                    {
                        continue;
                    }

                    PreparedProducts.Remove(preparedProduct);
                }

                PurchaseOrders.Remove(purchaseOrder);

                if (purchaseOrder.Status != PurchaseOrderStatus.Accepted)
                {
                    purchaseOrder.SetStatus(PurchaseOrderStatus.Accepted, true);
                }
            }

            Refresh();
        }
Exemple #2
0
        public void SetProductPreparedQuantity(Guid productId, Guid purchaseOrderId, int quantity, string preparedBy,
                                               bool completed, IEnumerable <Batch> batches)
        {
            var existingPreparedProduct =
                PreparedProducts.SingleOrDefault(p => p.ProductId == productId && p.PurchaseOrderId == purchaseOrderId);

            if (existingPreparedProduct != null)
            {
                existingPreparedProduct.SetBatches(batches);
                existingPreparedProduct.SetQuantity(quantity);
            }
            else
            {
                var productToPrepare = ProductsToPrepare.SingleOrDefault(p =>
                                                                         p.ProductId == productId && p.PurchaseOrderId == purchaseOrderId);
                if (productToPrepare == null)
                {
                    throw SheaftException.NotFound("Le produit est introuvable dans la préparation.");
                }

                existingPreparedProduct = new PreparedProduct(productToPrepare, purchaseOrderId, quantity);
                existingPreparedProduct.SetBatches(batches);
                PreparedProducts.Add(existingPreparedProduct);
            }

            if (completed)
            {
                existingPreparedProduct.CompleteProduct(preparedBy);
            }

            Refresh();

            if (PreparedProducts.Count == ProductsToPrepare.Count && PreparedProducts.All(p => p.PreparedOn.HasValue))
            {
                Complete();
            }
        }
Exemple #3
0
 private void Refresh()
 {
     ProductsToPrepareCount = ProductsToPrepare?.Sum(p => p.Quantity) ?? 0;
     PurchaseOrdersCount    = PurchaseOrders.Count;
     PreparedProductsCount  = PreparedProducts?.Sum(p => p.Quantity) ?? 0;
 }