Esempio n. 1
0
        public void CompleteBatch(bool partial = false)
        {
            if (Deliveries.Any(d => d.Status != DeliveryStatus.Delivered && d.Status != DeliveryStatus.Rejected))
            {
                throw SheaftException.Validation("La tournée contient des livraisons en cours.");
            }

            CompletedOn = DateTimeOffset.UtcNow;
            Status      = partial ? DeliveryBatchStatus.Partial : DeliveryBatchStatus.Completed;
        }
Esempio n. 2
0
        public void SetDeliveries(IEnumerable <Tuple <DeliveryMode, DateTimeOffset, string> > orderDeliveries)
        {
            if (Deliveries == null || Deliveries.Any())
            {
                Deliveries = new List <OrderDelivery>();
            }

            foreach (var orderDelivery in orderDeliveries)
            {
                Deliveries.Add(new OrderDelivery(orderDelivery.Item1, orderDelivery.Item2, orderDelivery.Item3));
            }

            DeliveryFeesWholeSalePrice = 0;
            DeliveryFeesVatPrice       = 0;
            DeliveryFeesOnSalePrice    = 0;

            foreach (var delivery in Deliveries)
            {
                var deliveryMode = delivery.DeliveryMode;

                if (deliveryMode.AcceptPurchaseOrdersWithAmountGreaterThan.HasValue &&
                    deliveryMode.AcceptPurchaseOrdersWithAmountGreaterThan.Value >
                    (TotalProductWholeSalePrice + TotalReturnableWholeSalePrice))
                {
                    throw SheaftException.Validation(
                              $"Le montant de la commande pour {deliveryMode.Producer.Name} est inférieur au palier de {deliveryMode.AcceptPurchaseOrdersWithAmountGreaterThan.Value}€ fixé par le producteur.");
                }

                if (deliveryMode.ApplyDeliveryFeesWhen is DeliveryFeesApplication.Always)
                {
                    DeliveryFeesWholeSalePrice += deliveryMode.DeliveryFeesWholeSalePrice ?? 0;
                    DeliveryFeesVatPrice       += deliveryMode.DeliveryFeesVatPrice ?? 0;
                    DeliveryFeesOnSalePrice    += deliveryMode.DeliveryFeesOnSalePrice ?? 0;
                }

                if (deliveryMode.ApplyDeliveryFeesWhen is DeliveryFeesApplication.TotalLowerThanPurchaseOrderAmount &&
                    deliveryMode.DeliveryFeesMinPurchaseOrdersAmount.HasValue &&
                    deliveryMode.DeliveryFeesMinPurchaseOrdersAmount.Value >
                    (TotalProductWholeSalePrice + TotalReturnableWholeSalePrice))
                {
                    DeliveryFeesWholeSalePrice += deliveryMode.DeliveryFeesWholeSalePrice ?? 0;
                    DeliveryFeesVatPrice       += deliveryMode.DeliveryFeesVatPrice ?? 0;
                    DeliveryFeesOnSalePrice    += deliveryMode.DeliveryFeesOnSalePrice ?? 0;
                }
            }

            DeliveriesCount = Deliveries?.Count ?? 0;
            RefreshOrder();
        }
Esempio n. 3
0
        private void SetDeliveries(IEnumerable <Delivery> deliveries)
        {
            if (Deliveries == null || Deliveries.Any())
            {
                Deliveries = new List <Delivery>();
            }

            var positionCounter = 0;

            foreach (var delivery in deliveries.OrderBy(d => d.Position))
            {
                if (delivery.DeliveryBatchId.HasValue && delivery.DeliveryBatchId != Id)
                {
                    delivery.DeliveryBatch.RemoveDelivery(delivery);
                }

                delivery.SetPosition(positionCounter);
                Deliveries.Add(delivery);
                positionCounter++;
            }

            Refresh();
        }
Esempio n. 4
0
        public void PostponeBatch(DateTimeOffset rescheduledOn, TimeSpan from, string reason)
        {
            if (Status != DeliveryBatchStatus.Waiting && Status != DeliveryBatchStatus.Ready && Status != DeliveryBatchStatus.InProgress)
            {
                throw SheaftException.Validation("La tournée doit être en attente, prête ou en cours pour la décaler.");
            }

            if (Deliveries.Any(d => d.Status == DeliveryStatus.Delivered || d.Status == DeliveryStatus.Rejected))
            {
                throw SheaftException.Validation("La tournée contient déjà des livraisons terminées ou refusées, veuillez compléter la tournée en précisant une nouvelle date.");
            }

            StartedOn   = null;
            ScheduledOn = rescheduledOn;
            From        = from;
            Reason      = reason;

            foreach (var delivery in Deliveries)
            {
                delivery.PostponeDelivery();
            }

            DomainEvents.Add(new DeliveryBatchPostponedEvent(Id));
        }