コード例 #1
0
        public async void LoadDirectory()
        {
            if (IsBusy)
            {
                return;
            }
            try
            {
                IsBusy = true;
                PurchaseOrders.Clear();
                await Task.Delay(100).ConfigureAwait(false);

                var directory = await PurchaseOrderDirectoryService.LoadPurchaseOrderDirectory();

                var index = 0;
                Device.BeginInvokeOnMainThread(() =>
                {
                    foreach (var purchaseOrder in directory.PurchaseOrders)
                    {
                        purchaseOrder.Index = index;
                        PurchaseOrders.Add(purchaseOrder);
                        index++;
                    }
                });
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            finally
            {
                IsBusy = false;
            }
        }
コード例 #2
0
ファイル: Picking.cs プロジェクト: sheaft-app/api
        public void AddPurchaseOrders(IEnumerable <PurchaseOrder> purchaseOrders)
        {
            if (purchaseOrders == null || !purchaseOrders.Any())
            {
                throw SheaftException.Validation("La préparation requiert une commande à minima.");
            }

            if (purchaseOrders.Any(po =>
                                   po.Status != PurchaseOrderStatus.Waiting && po.Status != PurchaseOrderStatus.Accepted &&
                                   po.Status != PurchaseOrderStatus.Processing))
            {
                throw SheaftException.Validation(
                          "Seule des commandes en attente ou acceptées peuvent être ajoutées à une préparation.");
            }

            if (Status == PickingStatus.Completed)
            {
                throw SheaftException.Validation(
                          "Impossible de modifier les commandes d'une préparation qui est terminée.");
            }

            PurchaseOrders ??= new List <PurchaseOrder>();
            foreach (var purchaseOrder in purchaseOrders)
            {
                if (purchaseOrder.PickingId.HasValue)
                {
                    purchaseOrder.Picking.RemovePurchaseOrders(new List <PurchaseOrder> {
                        purchaseOrder
                    });
                }

                if (purchaseOrder.Status == PurchaseOrderStatus.Waiting)
                {
                    purchaseOrder.Accept(true);
                }

                PurchaseOrders.Add(purchaseOrder);
            }

            ProductsToPrepare ??= new List <PickingProduct>();
            foreach (var purchaseOrder in purchaseOrders)
            {
                foreach (var purchaseOrderProduct in purchaseOrder.Products)
                {
                    ProductsToPrepare.Add(new PickingProduct(purchaseOrderProduct, purchaseOrder.Id,
                                                             purchaseOrderProduct.Quantity));
                }
            }

            if (Status == PickingStatus.InProgress)
            {
                foreach (var purchaseOrder in purchaseOrders)
                {
                    purchaseOrder.SetStatus(PurchaseOrderStatus.Processing, true);
                }
            }

            Refresh();
        }
コード例 #3
0
        public void AddPurchaseOrders(IEnumerable <PurchaseOrder> purchaseOrders)
        {
            if (Status != DeliveryStatus.Waiting)
            {
                throw SheaftException.Validation(
                          "Impossible de modifier les commandes d'une livraison qui n'est pas en attente");
            }

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

            PurchaseOrders ??= new List <PurchaseOrder>();
            foreach (var purchaseOrder in purchaseOrders)
            {
                if (purchaseOrder.DeliveryId.HasValue)
                {
                    purchaseOrder.Delivery.RemovePurchaseOrders(new List <PurchaseOrder> {
                        purchaseOrder
                    });
                }

                PurchaseOrders.Add(purchaseOrder);
            }

            Products ??= new List <DeliveryProduct>();
            foreach (var purchaseOrder in purchaseOrders)
            {
                foreach (var purchaseOrderProduct in purchaseOrder.Products)
                {
                    var preparedQuantity = 0;
                    if (purchaseOrder.PickingId.HasValue)
                    {
                        var preparedProduct = purchaseOrder.Picking.PreparedProducts.FirstOrDefault(p =>
                                                                                                    p.ProductId == purchaseOrderProduct.ProductId && p.PurchaseOrderId == purchaseOrder.Id);

                        if (preparedProduct != null)
                        {
                            preparedQuantity = preparedProduct.Quantity;
                        }
                    }
                    else
                    {
                        preparedQuantity = purchaseOrderProduct.Quantity;
                    }

                    var existingProduct = Products.FirstOrDefault(p =>
                                                                  p.ProductId == purchaseOrderProduct.ProductId && p.RowKind == ModificationKind.ToDeliver);

                    if (existingProduct != null)
                    {
                        existingProduct.AddQuantity(preparedQuantity);
                    }
                    else if (preparedQuantity > 0)
                    {
                        Products.Add(new DeliveryProduct(purchaseOrderProduct, preparedQuantity,
                                                         ModificationKind.ToDeliver));
                    }
                }
            }

            Refresh();
        }