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) }; }
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)); }
public ExpectedPurchaseOrderDelivery(DeliveryMode deliveryMode, DateTimeOffset expectedDeliveryDate, TimeSpan from, TimeSpan to, ExpectedAddress address) { DeliveryModeId = deliveryMode.Id; Address = address; Day = expectedDeliveryDate.DayOfWeek; From = from; Kind = deliveryMode.Kind; Name = deliveryMode.Name; To = to; ExpectedDeliveryDate = expectedDeliveryDate; }
public OrderDelivery(DeliveryMode delivery, DateTimeOffset expectedDeliveryDate, string comment = null) { Id = Guid.NewGuid(); DeliveryMode = delivery; DeliveryModeId = delivery.Id; Comment = comment; SetExpectedDate(expectedDeliveryDate); var oh = GetOpeningHour(delivery, expectedDeliveryDate); From = oh.From; To = oh.To; }
protected TimeSlotHour GetOpeningHour(DeliveryMode delivery, DateTimeOffset expectedDeliveryDate) { if (delivery.RemovedOn.HasValue) { throw SheaftException.Validation("Ce mode de livraison n'existe plus."); } var oh = delivery.DeliveryHours.FirstOrDefault(o => o.Day == expectedDeliveryDate.DayOfWeek && o.From <= expectedDeliveryDate.TimeOfDay && o.To >= expectedDeliveryDate.TimeOfDay); if (oh == null) { throw SheaftException.Validation("La date selectionnée ne correspond à aucune plage horaire du mode de livraison."); } if (delivery.LockOrderHoursBeforeDelivery.HasValue && expectedDeliveryDate.AddHours(-delivery.LockOrderHoursBeforeDelivery.Value) < DateTime.UtcNow) { throw SheaftException.Validation($"La date selectionnée se situe après la limite de {delivery.LockOrderHoursBeforeDelivery.Value}h avant le début de la livraison."); } return(oh); }
public void ApplyDeliveryModeFees(DeliveryMode deliveryMode) { DeliveryFeesWholeSalePrice = deliveryMode.DeliveryFeesWholeSalePrice ?? 0; DeliveryFeesVatPrice = deliveryMode.DeliveryFeesVatPrice ?? 0; DeliveryFeesOnSalePrice = deliveryMode.DeliveryFeesOnSalePrice ?? 0; }
public PurchaseOrder(Guid id, int reference, PurchaseOrderStatus status, DateTimeOffset expectedDeliveryDate, TimeSpan from, TimeSpan to, DeliveryMode deliveryMode, Producer producer, User client, IEnumerable <KeyValuePair <Domain.Product, int> > products, Catalog catalog, bool skipNotification, string comment = null) { if (producer == null) { throw SheaftException.Validation("Impossible de créer la commande, le producteur est requis."); } Id = id; Products = new List <PurchaseOrderProduct>(); DomainEvents = new List <DomainEvent> { new PurchaseOrderCreatedEvent(Id) }; Status = PurchaseOrderStatus.Waiting; CreatedOn = DateTimeOffset.UtcNow; SetSender(client); SetVendor(producer); var address = (int)deliveryMode.Kind <= 4 ? new ExpectedAddress(deliveryMode.Address.Line1, deliveryMode.Address.Line2, deliveryMode.Address.Zipcode, deliveryMode.Address.City, deliveryMode.Address.Country, deliveryMode.Address.Longitude, deliveryMode.Address.Latitude) : new ExpectedAddress(client.Address.Line1, client.Address.Line2, client.Address.Zipcode, client.Address.City, client.Address.Country, client.Address.Longitude, client.Address.Latitude); ExpectedDelivery = new ExpectedPurchaseOrderDelivery(deliveryMode, expectedDeliveryDate, from, to, address); SetComment(comment); SetReference(reference); foreach (var product in products) { AddProduct(new PurchaseOrderProduct(product.Key, catalog.Id, product.Value)); } var shouldAddDeliveryFees = deliveryMode.ApplyDeliveryFeesWhen is DeliveryFeesApplication.Always || (deliveryMode.ApplyDeliveryFeesWhen is DeliveryFeesApplication .TotalLowerThanPurchaseOrderAmount && deliveryMode.DeliveryFeesMinPurchaseOrdersAmount.HasValue && deliveryMode.DeliveryFeesMinPurchaseOrdersAmount.Value > TotalWholeSalePrice); if (shouldAddDeliveryFees) { ExpectedDelivery?.ApplyDeliveryModeFees(deliveryMode); RefreshOrder(); } SetStatus(status, skipNotification); }
public void ChangeDelivery(DeliveryMode deliveryMode) { DeliveryModeId = deliveryMode.Id; DeliveryMode = deliveryMode; Position = deliveryMode.Agreements.Count(a => a.Position.HasValue); }
public DeliveryClosing(DeliveryMode delivery, Guid id, DateTimeOffset from, DateTimeOffset to, string reason = null) : base(id, from, to) { Reason = reason; DeliveryModeId = delivery.Id; }