示例#1
0
        public Agreement(Guid id, Store store, Producer producer, ProfileKind createdByKind, DeliveryMode delivery = null)
        {
            Id             = id;
            StoreId        = store.Id;
            Store          = store;
            CreatedByKind  = createdByKind;
            DeliveryModeId = delivery?.Id;
            DeliveryMode   = delivery;
            ProducerId     = producer.Id;
            Producer       = producer;

            if (CreatedByKind == ProfileKind.Store)
            {
                Status = AgreementStatus.WaitingForProducerApproval;
            }
            else
            {
                Status = AgreementStatus.WaitingForStoreApproval;
                if (delivery == null)
                {
                    throw SheaftException.Validation("Le mode de livraison est requis pour créer un partenariat avec un magasin.");
                }
            }

            DomainEvents = new List <DomainEvent> {
                new AgreementCreatedEvent(Id, createdByKind)
            };
        }
示例#2
0
文件: Product.cs 项目: sheaft-app/api
        public void SetVat(decimal?newVat)
        {
            if (Producer.NotSubjectToVat)
            {
                newVat = 0;
            }

            if (!newVat.HasValue)
            {
                throw SheaftException.Validation("La TVA est requise.");
            }

            if (newVat < 0)
            {
                throw SheaftException.Validation("La TVA ne peut être inférieure à 0%.");
            }

            if (newVat > 100)
            {
                throw SheaftException.Validation("La TVA ne peut être supérieure à 100%.");
            }

            Vat = newVat.Value;
            RefreshPrices();
        }
示例#3
0
文件: Product.cs 项目: sheaft-app/api
        public void SetConditioning(ConditioningKind conditioning, decimal quantity,
                                    UnitKind unit = UnitKind.NotSpecified)
        {
            if (conditioning == ConditioningKind.Not_Specified)
            {
                throw SheaftException.Validation("Le conditionnement est requis.");
            }

            if (conditioning != ConditioningKind.Bulk)
            {
                unit = UnitKind.NotSpecified;
            }

            if (conditioning == ConditioningKind.Bouquet || conditioning == ConditioningKind.Bunch)
            {
                quantity = 1;
            }

            if (quantity <= 0)
            {
                throw SheaftException.Validation("La quantité par conditionnement ne peut pas être inférieure à 0.");
            }

            if (conditioning == ConditioningKind.Bulk && unit == UnitKind.NotSpecified)
            {
                throw SheaftException.Validation("L'unité du type de conditionnement est requis.");
            }

            Conditioning    = conditioning;
            QuantityPerUnit = quantity;
            Unit            = unit;

            RefreshPrices();
        }
示例#4
0
        public void AcceptAgreement(DeliveryMode delivery, ProfileKind acceptedByKind)
        {
            if (Status != AgreementStatus.WaitingForProducerApproval &&
                Status != AgreementStatus.WaitingForStoreApproval)
            {
                throw SheaftException.Validation("Le partenariat ne peut pas être accepté, il n'est en attente d'acceptation.");
            }

            if (Status == AgreementStatus.WaitingForProducerApproval && acceptedByKind != ProfileKind.Producer)
            {
                throw SheaftException.Validation("Le partenariat doit être accepté par le producteur.");
            }

            if (Status == AgreementStatus.WaitingForStoreApproval && acceptedByKind != ProfileKind.Store)
            {
                throw SheaftException.Validation("Le partenariat doit être accepté par le magasin.");
            }

            if (delivery != null)
            {
                ChangeDelivery(delivery);
            }

            if (!DeliveryModeId.HasValue)
            {
                throw SheaftException.Validation("Le partenariat doit avoir un mode de livraison rattaché.");
            }

            Store.IncreaseProducersCount();

            Status = AgreementStatus.Accepted;
            DomainEvents.Add(new AgreementAcceptedEvent(Id, acceptedByKind));
        }
示例#5
0
        protected Address(string line1, string line2, string zipcode, string city, CountryIsoCode country)
        {
            if (string.IsNullOrWhiteSpace(line1))
            {
                throw SheaftException.Validation("La ligne d'adresse est requise.");
            }

            if (string.IsNullOrWhiteSpace(zipcode))
            {
                throw SheaftException.Validation("Le code postal est requis.");
            }

            if (string.IsNullOrWhiteSpace(city))
            {
                throw SheaftException.Validation("La ville est requise.");
            }

            Line1   = line1;
            Line2   = line2;
            City    = city;
            Country = country;

            if (zipcode.Length == 5)
            {
                Zipcode = zipcode;
            }
        }
示例#6
0
        public void SetDeliveryFees(DeliveryFeesApplication?feesApplication, decimal?fees, decimal?minAmount)
        {
            if (fees is <= 0)
            {
                throw SheaftException.Validation("Le forfait de livraison doit être supérieur à 0€");
            }

            if (minAmount is <= 0)
            {
                throw SheaftException.Validation("Le montant minimum de commande pour appliquer le forfait doit être supérieur à 0€");
            }

            if (feesApplication is DeliveryFeesApplication.TotalLowerThanPurchaseOrderAmount && !minAmount.HasValue)
            {
                throw SheaftException.Validation("Le montant minimum de commande pour appliquer le forfait est requis.");
            }

            if (feesApplication is DeliveryFeesApplication.TotalLowerThanPurchaseOrderAmount && minAmount < AcceptPurchaseOrdersWithAmountGreaterThan)
            {
                throw SheaftException.Validation("Le montant minimum de commande pour appliquer le forfait de livraison doit être supérieur au montant minimum d'acceptation de commande.");
            }

            ApplyDeliveryFeesWhen = feesApplication;
            DeliveryFeesMinPurchaseOrdersAmount = minAmount;

            DeliveryFeesWholeSalePrice = fees.HasValue ? Math.Round(fees.Value, 2, MidpointRounding.AwayFromZero) : null;
            DeliveryFeesVatPrice       = DeliveryFeesWholeSalePrice.HasValue ? Math.Round(DeliveryFeesWholeSalePrice.Value * 0.20m, 2, MidpointRounding.AwayFromZero) : null;
            DeliveryFeesOnSalePrice    = DeliveryFeesWholeSalePrice.HasValue && DeliveryFeesVatPrice.HasValue ? Math.Round(DeliveryFeesWholeSalePrice.Value * 1.20m, 2, MidpointRounding.AwayFromZero) : null;
        }
示例#7
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();
        }
示例#8
0
        public void SkipDelivery()
        {
            if (Status is DeliveryStatus.Delivered)
            {
                throw SheaftException.Validation("La livraison est déjà validée.");
            }

            Status = DeliveryStatus.Skipped;
        }
示例#9
0
文件: Job.cs 项目: sheaft-app/api
        public void SetCommand <T>(T command) where T : class
        {
            if (command == null)
            {
                throw SheaftException.Validation("La commande à executer par cette tâche est requise.");
            }

            Command = JsonConvert.SerializeObject(command);
        }
示例#10
0
文件: Product.cs 项目: sheaft-app/api
        public void SetReference(string reference)
        {
            if (string.IsNullOrWhiteSpace(reference))
            {
                throw SheaftException.Validation("La référence est requise.");
            }

            Reference = reference;
        }
示例#11
0
        public void SetEmail(string email)
        {
            if (string.IsNullOrWhiteSpace(email))
            {
                throw SheaftException.Validation("L'email de contact de l'entreprise est requis.");
            }

            Email = email;
        }
示例#12
0
        public void SetAsBilled()
        {
            if (Status != DeliveryStatus.Delivered)
            {
                throw SheaftException.Validation("La livraison n'a pas encore été validée.");
            }

            BilledOn = DateTimeOffset.UtcNow;
        }
示例#13
0
文件: Picking.cs 项目: sheaft-app/api
        public void Pause()
        {
            if (Status != PickingStatus.InProgress)
            {
                throw SheaftException.Validation("La préparation n'est pas en cours de traitement.");
            }

            Status = PickingStatus.Paused;
        }
示例#14
0
        public void SetEmail(string email)
        {
            if (email.IsNotNullAndIsEmptyOrWhiteSpace())
            {
                throw SheaftException.Validation("L'email est requis.");
            }

            Email = email;
        }
示例#15
0
        public void SetLastname(string lastName)
        {
            if (string.IsNullOrWhiteSpace(lastName))
            {
                throw SheaftException.Validation("Le nom du représentant légal est requis.");
            }

            LastName = lastName;
        }
示例#16
0
        public void SetFirstname(string firstName)
        {
            if (string.IsNullOrWhiteSpace(firstName))
            {
                throw SheaftException.Validation("Le prénom du représentant légal est requis.");
            }

            FirstName = firstName;
        }
示例#17
0
        public void SetAsReady()
        {
            if (Status != RecallStatus.Waiting)
            {
                throw SheaftException.Validation("La campagne n'est pas en attente.");
            }

            Status = RecallStatus.Ready;
        }
示例#18
0
        public void SetName(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw SheaftException.Validation("Le nom du catalogue est requis.");
            }

            Name = name;
        }
示例#19
0
        public void SetWholeSalePrice(decimal newPrice)
        {
            if (newPrice <= 0)
            {
                throw SheaftException.Validation("Le prix doit être supérieur à 0€.");
            }

            WholeSalePrice = Math.Round(newPrice, DIGITS_COUNT, MidpointRounding.AwayFromZero);
        }
示例#20
0
        public void SetAcceptPurchaseOrdersWithAmountGreaterThan(decimal?amount)
        {
            if (amount is < 0)
            {
                throw SheaftException.Validation("Le montant minimum de commande doit être supérieur ou égal à 0€");
            }

            AcceptPurchaseOrdersWithAmountGreaterThan = amount;
        }
示例#21
0
        public void SetName(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw SheaftException.Validation("Le nom de l'entreprise est requis.");
            }

            Name = name;
        }
示例#22
0
        public void SetName(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw SheaftException.Validation("Le nom du mode de livraison est requis.");
            }

            Name = name;
        }
示例#23
0
        public void SetSiret(string siret)
        {
            if (siret.IsNotNullAndIsEmptyOrWhiteSpace())
            {
                throw SheaftException.Validation("Le numéro de SIRET est requis.");
            }

            Siret = siret.Trim();
        }
示例#24
0
        public void SetVatIdentifier(string vatNumber)
        {
            if (vatNumber.IsNotNullAndIsEmptyOrWhiteSpace())
            {
                throw SheaftException.Validation("Le numéro de TVA est requis.");
            }

            VatIdentifier = vatNumber;
        }
示例#25
0
        public override void SetKind(LegalKind kind)
        {
            if (kind == LegalKind.Natural)
            {
                throw SheaftException.Validation("Une statut légal d'une société ne peut pas être de type personnel.");
            }

            base.SetKind(kind);
        }
示例#26
0
        protected void SetUserName(string name)
        {
            if (name.IsNotNullAndIsEmptyOrWhiteSpace())
            {
                throw SheaftException.Validation("Le nom d'utilisateur est requis.");
            }

            Name = name;
        }
示例#27
0
        public override void SetKind(LegalKind kind)
        {
            if (kind != LegalKind.Natural)
            {
                throw SheaftException.Validation("Le statut légal de l'entité doit être de type personnel.");
            }

            base.SetKind(kind);
        }
示例#28
0
        public void RemovePurchaseOrders(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)
            {
                throw SheaftException.NotFound("Cette livraison ne contient pas de commandes.");
            }

            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)
                    {
                        continue;
                    }

                    existingProduct.RemoveQuantity(preparedQuantity);
                    if (existingProduct.Quantity <= 0)
                    {
                        foreach (var productToRemove in Products
                                 .Where(p => p.ProductId == purchaseOrderProduct.ProductId).ToList())
                        {
                            Products.Remove(productToRemove);
                        }
                    }
                }

                PurchaseOrders.Remove(purchaseOrder);
            }

            Refresh();
        }
示例#29
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;
        }
示例#30
0
        public StoreTag(Tag tag)
        {
            if (tag == null)
            {
                throw SheaftException.Validation("Le tag du magasin est introuvable.");
            }

            Tag   = tag;
            TagId = tag.Id;
        }