public void AppsDeriveVatRate(IDerivation derivation) { if (!this.ExistDerivedVatRate && this.ExistVatRegime && this.VatRegime.ExistVatRate) { this.DerivedVatRate = this.VatRegime.VatRate; } }
public void AppsOnDeriveCurrentShipmentStatus(IDerivation derivation) { var quantityReceived = 0M; foreach (ShipmentReceipt shipmentReceipt in this.ShipmentReceiptsWhereOrderItem) { quantityReceived += shipmentReceipt.QuantityAccepted; } this.QuantityReceived = quantityReceived; if (quantityReceived > 0) { if (quantityReceived < this.QuantityOrdered) { this.PurchaseOrderItemState = new PurchaseOrderItemStates(this.strategy.Session).PartiallyReceived; } else { this.PurchaseOrderItemState = new PurchaseOrderItemStates(this.strategy.Session).Completed; } } if (this.ExistPurchaseOrderWherePurchaseOrderItem) { var purchaseOrder = (PurchaseOrder)this.PurchaseOrderWherePurchaseOrderItem; purchaseOrder.AppsOnDerivePurchaseOrderState(derivation); } }
public void AppsOnDeriveRevenue(IDerivation derivation) { this.Revenue = 0; var toDate = DateTimeFactory.CreateDate(this.Year, this.Month, 01).AddMonths(1); var invoices = this.Store.SalesInvoicesWhereStore; invoices.Filter.AddNot().AddEquals(SalesInvoices.Meta.CurrentObjectState, new SalesInvoiceObjectStates(this.Strategy.Session).WrittenOff); invoices.Filter.AddBetween(SalesInvoices.Meta.InvoiceDate, DateTimeFactory.CreateDate(this.Year, this.Month, 01), toDate); foreach (SalesInvoice salesInvoice in invoices) { this.Revenue += salesInvoice.TotalExVat; } var months = ((DateTime.UtcNow.Year - this.Year) * 12) + DateTime.UtcNow.Month - this.Month; if (months <= 12) { var histories = this.Store.StoreRevenueHistoriesWhereStore; histories.Filter.AddEquals(StoreRevenueHistories.Meta.InternalOrganisation, this.InternalOrganisation); var history = histories.First ?? new StoreRevenueHistoryBuilder(this.Strategy.Session) .WithCurrency(this.Currency) .WithInternalOrganisation(this.InternalOrganisation) .WithStore(this.Store) .Build(); history.AppsOnDeriveRevenue(); } var internalOrganisationRevenue = InternalOrganisationRevenues.AppsFindOrCreateAsDependable(this.Strategy.Session, this); internalOrganisationRevenue.OnDerive(x => x.WithDerivation(derivation)); }
public void AppsDepleteSalesOrders(IDerivation derivation) { Extent<SalesOrderItem> salesOrderItems = this.Strategy.Session.Extent<SalesOrderItem>(); salesOrderItems.Filter.AddEquals(SalesOrderItems.Meta.CurrentObjectState, new SalesOrderItemObjectStates(this.Strategy.Session).InProcess); salesOrderItems.AddSort(SalesOrderItems.Meta.DeliveryDate, SortDirection.Descending); salesOrderItems = this.Strategy.Session.Instantiate(salesOrderItems); var subtract = this.PreviousQuantityOnHand - this.QuantityOnHand; foreach (SalesOrderItem salesOrderItem in salesOrderItems) { if (subtract > 0 && salesOrderItem.QuantityRequestsShipping > 0) { decimal diff; if (subtract >= salesOrderItem.QuantityRequestsShipping) { diff = salesOrderItem.QuantityRequestsShipping; } else { diff = subtract; } subtract -= diff; salesOrderItem.AppsOnDeriveSubtractFromShipping(derivation, diff); salesOrderItem.SalesOrderWhereSalesOrderItem.OnDerive(x => x.WithDerivation(derivation)); } } }
/// <summary> /// Removes an Observer <see cref="IDerivation"/> from the set of observers. /// </summary> /// <param name="observable">The observable to use.</param> /// <param name="derivation">The observer to add.</param> /// <exception cref="ArgumentNullException">When any of the arguments is null.</exception> /// <exception cref="InvalidOperationException">Thrown when shared state is not in batch mode.</exception> /// <exception cref="InvalidOperationException">Thrown when the derivation is not in the set of observers.</exception> public static void RemoveObserver(this IObservable observable, IDerivation derivation) { if (observable is null) { throw new ArgumentNullException(nameof(observable)); } if (derivation is null) { throw new ArgumentNullException(nameof(derivation)); } if (!observable.Observers.Contains(derivation)) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, Resources.ObserverNotInObservable, derivation.Name, observable.Name)); } observable.Observers.Remove(derivation); if (!observable.HasObservers()) { // deleted last observer. observable.QueueForUnobservation(); } }
public void AppsOnDeriveMarkupAndProfitMargin(IDerivation derivation) { //// Only take into account items for which there is data at the item level. //// Skip negative sales. decimal totalPurchasePrice = 0; decimal totalUnitBasePrice = 0; decimal totalListPrice = 0; foreach (SalesOrderItem item in this.ValidOrderItems) { if (item.TotalExVat > 0) { totalPurchasePrice += item.UnitPurchasePrice; totalUnitBasePrice += item.UnitBasePrice; totalListPrice += item.CalculatedUnitPrice; } } if (totalPurchasePrice != 0 && totalListPrice != 0 && totalUnitBasePrice != 0) { this.InitialMarkupPercentage = Math.Round(((totalUnitBasePrice / totalPurchasePrice) - 1) * 100, 2); this.MaintainedMarkupPercentage = Math.Round(((totalListPrice / totalPurchasePrice) - 1) * 100, 2); this.InitialProfitMargin = Math.Round(((totalUnitBasePrice - totalPurchasePrice) / totalUnitBasePrice) * 100, 2); this.MaintainedProfitMargin = Math.Round(((totalListPrice - totalPurchasePrice) / totalListPrice) * 100, 2); } }
public void AppsOnDeriveRevenue(IDerivation derivation) { this.Revenue = 0; var partyProductRevenues = this.Product.PartyProductRevenuesWhereProduct; partyProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.InternalOrganisation, this.InternalOrganisation); partyProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Year, this.Year); partyProductRevenues.Filter.AddEquals(PartyProductRevenues.Meta.Month, this.Month); foreach (PartyProductRevenue partyProductRevenue in partyProductRevenues) { this.Revenue += partyProductRevenue.Revenue; } var months = ((DateTime.UtcNow.Year - this.Year) * 12) + DateTime.UtcNow.Month - this.Month; if (months <= 12) { var histories = this.Product.ProductRevenueHistoriesWhereProduct; histories.Filter.AddEquals(ProductRevenueHistories.Meta.InternalOrganisation, this.InternalOrganisation); var history = histories.First ?? new ProductRevenueHistoryBuilder(this.Strategy.Session) .WithCurrency(this.Currency) .WithInternalOrganisation(this.InternalOrganisation) .WithProduct(this.Product) .Build(); } foreach (ProductCategory productCategory in this.Product.ProductCategories) { productCategory.OnDerive(x => x.WithDerivation(derivation)); } }
/// <summary> /// Adds an observer that implements <see cref="IDerivation"/> into the set of observers. /// for this <see cref="IObservable"/> instance. /// </summary> /// <param name="observable">The observable to use.</param> /// <param name="derivation">The observer to add.</param> /// <exception cref="ArgumentNullException">When any of the arguments is null.</exception> /// <exception cref="ArgumentOutOfRangeException">When the derivation is in the not tracking state.</exception> /// <exception cref="InvalidOperationException">When the derivation was already added.</exception> public static void AddObserver(this IObservable observable, IDerivation derivation) { if (observable is null) { throw new ArgumentNullException(nameof(observable)); } if (derivation is null) { throw new ArgumentNullException(nameof(derivation)); } if (derivation.DependenciesState == DerivationState.NotTracking) { throw new ArgumentOutOfRangeException( paramName: nameof(derivation), message: string.Format(CultureInfo.CurrentCulture, Resources.CanOnlyAddTrackedDependencies, DerivationState.NotTracking)); } if (observable.Observers.Contains(derivation)) { throw new InvalidOperationException( string.Format(CultureInfo.CurrentCulture, Resources.AlreadyAddedObserverToObservable, derivation.Name, observable.Name)); } observable.Observers.Add(derivation); if (observable.LowestObserverState > derivation.DependenciesState) { observable.LowestObserverState = derivation.DependenciesState; } }
public void AppsDeriveCanShip(IDerivation derivation) { if (this.SalesOrderState.Equals(new SalesOrderStates(this.Strategy.Session).InProcess)) { var somethingToShip = false; var allItemsAvailable = true; foreach (SalesOrderItem salesOrderItem in this.ValidOrderItems) { if (!this.PartiallyShip && salesOrderItem.QuantityRequestsShipping != salesOrderItem.QuantityOrdered) { allItemsAvailable = false; break; } if (this.PartiallyShip && salesOrderItem.QuantityRequestsShipping > 0) { somethingToShip = true; } } if ((!this.PartiallyShip && allItemsAvailable) || somethingToShip) { this.CanShip = true; return; } } this.CanShip = false; }
private void DeriveProductCharacteristics(IDerivation derivation) { var characteristicsToDelete = this.SerialisedItemCharacteristics.ToList(); if (this.ExistProductType) { foreach (SerialisedItemCharacteristicType characteristicType in this.ProductType.SerialisedItemCharacteristicTypes) { var characteristic = this.SerialisedItemCharacteristics.FirstOrDefault(v => Equals(v.SerialisedItemCharacteristicType, characteristicType)); if (characteristic == null) { this.AddSerialisedItemCharacteristic( new SerialisedItemCharacteristicBuilder(this.Strategy.Session) .WithSerialisedItemCharacteristicType(characteristicType) .Build()); } else { characteristicsToDelete.Remove(characteristic); } } } foreach (var characteristic in characteristicsToDelete) { this.RemoveSerialisedItemCharacteristic(characteristic); } }
/** * Executes the provided function `f` and tracks which observables are being accessed. * The tracking information is stored on the `derivation` object and the derivation is registered * as observer of any of the accessed observables. */ public static T TrackedDerivedFunction <T>(this IDerivation derivation, Func <T> func, object context) { // pre allocate array allocation + room for variation in deps // array will be trimmed by bindDependencies derivation.ChangeDependenciesStateTo0(); derivation.NewObservings = new List <IObservable>(derivation.Observings.Count + 100); derivation.UnboundDepsCount = 0; derivation.RunId = States.NextRunId; var previous = States.UntrackedStart(derivation); T result = default(T); if (States.State.DisableErrorBoundaries) { result = func(); } else { try { result = func(); } catch (Exception ex) { throw new CaughtException(ex); } } States.UntrackedEnd(previous); derivation.BindDependencies(); return(result); }
public void AppsOnDeriveQuantities(IDerivation derivation) { NonSerialisedInventoryItem inventoryItem = null; if (this.ExistPart) { var inventoryItems = this.Part.InventoryItemsWherePart; inventoryItems.Filter.AddEquals(M.InventoryItem.Facility, this.PurchaseOrderWherePurchaseOrderItem.Facility); inventoryItem = inventoryItems.First as NonSerialisedInventoryItem; } if (this.PurchaseOrderItemState.Equals(new PurchaseOrderItemStates(this.Strategy.Session).InProcess)) { if (!this.ExistPreviousQuantity || !this.QuantityOrdered.Equals(this.PreviousQuantity)) { if (inventoryItem != null) { inventoryItem.OnDerive(x => x.WithDerivation(derivation)); } } } if (this.PurchaseOrderItemState.Equals(new PurchaseOrderItemStates(this.Strategy.Session).Cancelled) || this.PurchaseOrderItemState.Equals(new PurchaseOrderItemStates(this.Strategy.Session).Rejected)) { if (inventoryItem != null) { inventoryItem.OnDerive(x => x.WithDerivation(derivation)); } } }
public void BaseOnDerivePurchaseShipmentItem(IDerivation derivation) { if (this.ExistShipmentWhereShipmentItem && this.ShipmentWhereShipmentItem is PurchaseShipment && this.ExistPart && this.Part.InventoryItemKind.IsNonSerialised && !this.ExistUnitPurchasePrice) { derivation.Validation.AssertExists(this, this.Meta.UnitPurchasePrice); } if (this.ExistShipmentWhereShipmentItem && this.ShipmentWhereShipmentItem is PurchaseShipment && !this.ExistStoredInFacility && this.ShipmentWhereShipmentItem.ExistShipToFacility) { this.StoredInFacility = this.ShipmentWhereShipmentItem.ShipToFacility; } if (this.ExistShipmentWhereShipmentItem && this.ShipmentWhereShipmentItem is PurchaseShipment && this.ExistShipmentReceiptWhereShipmentItem) { this.Quantity = 0; var shipmentReceipt = this.ShipmentReceiptWhereShipmentItem; this.Quantity += shipmentReceipt.QuantityAccepted + shipmentReceipt.QuantityRejected; } }
public void AppsOnDeriveOrderItems(IDerivation derivation) { var quantityOrderedByProduct = new Dictionary <Product, decimal>(); var totalBasePriceByProduct = new Dictionary <Product, decimal>(); var quantityOrderedByPart = new Dictionary <Part, decimal>(); var totalBasePriceByPart = new Dictionary <Part, decimal>(); foreach (PurchaseOrderItem purchaseOrderItem in this.ValidOrderItems) { purchaseOrderItem.OnDerive(x => x.WithDerivation(derivation)); purchaseOrderItem.AppsOnDeriveDeliveryDate(derivation); purchaseOrderItem.AppsOnDeriveCurrentShipmentStatus(derivation); purchaseOrderItem.AppsOnDerivePrices(); purchaseOrderItem.AppsDeriveVatRegime(derivation); if (purchaseOrderItem.ExistPart) { if (!quantityOrderedByPart.ContainsKey(purchaseOrderItem.Part)) { quantityOrderedByPart.Add(purchaseOrderItem.Part, purchaseOrderItem.QuantityOrdered); totalBasePriceByPart.Add(purchaseOrderItem.Part, purchaseOrderItem.TotalBasePrice); } else { quantityOrderedByPart[purchaseOrderItem.Part] += purchaseOrderItem.QuantityOrdered; totalBasePriceByPart[purchaseOrderItem.Part] += purchaseOrderItem.TotalBasePrice; } } } }
public void BaseOnDeriveUnitOfMeasure(IDerivation derivation) { if (this.ExistPart) { this.UnitOfMeasure = this.Part.UnitOfMeasure; } }
public ListDerivation ExpandStep() { //Идем вправо по списку, если: // SymbolDerivation, раскрываем и заменяем если результат ListDerivation, // возвращаем его иначе себя // ListDerivation - возврящаем его // дошли до конца списка - возвращаем верхний список (ParentDerivation) while (mCurrentItemIndex < mList.Count) { ListDerivation lAsListDer = CurrentItem as ListDerivation; if (null != lAsListDer) { mCurrentItemIndex++; return(lAsListDer); } SymbolDerivation lAsSymDer = CurrentItem as SymbolDerivation; if (null != lAsSymDer) { ExpandingSymbol = lAsSymDer.Symbol; //раскрываем и заменяем IDerivation lSymbolResult = Generator.ExpandNonTerminal(lAsSymDer.Symbol); CurrentItem = lSymbolResult; ListDerivation lSymbolResultAsList = lSymbolResult as ListDerivation; //если результат ListDerivation, возвращаем его иначе себя (старый верхний список) return(lSymbolResultAsList ?? this); } mCurrentItemIndex++; } //дошли до конца списка return(ParentDerivation as ListDerivation); //??? }
/// <summary> /// Do actual call of transductor method with parameter substitution /// </summary> /// <param name="aContext">Deriving context</param> /// <returns>List of symbols produced by transductor</returns> protected override IDerivation ExpandRnd(DerivationContext aContext) { //1. Substitute and prepare parameters form context by conf xml object[] parametrs = ParamsArray(aContext); if (mTargetAccess != null) { IDerivation lDeriv = mTargetAccess.Expand(aContext); mGrammar.ListTrans.TargetList = (ListDerivation)lDeriv; } mGrammar.SysTrans.Context = aContext; string lStrResult;// = "no trans result!!!"; //2. do actual call try { object lRetVal = mBindedMethod.Invoke(mTransductorClass, parametrs); if (lRetVal is int) { return(new ExprInt((int)lRetVal)); } lStrResult = Convert.ToString(lRetVal); } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } lStrResult = ex.Message; } TLog.Write("T", lStrResult); return(new TextDerivation(lStrResult)); }
public static void BaseOnDerivePartyFinancialRelationships(this Party @this, IDerivation derivation) { var internalOrganisations = new Organisations(@this.Strategy.Session).InternalOrganisations(); if (!internalOrganisations.Contains(@this)) { foreach (var internalOrganisation in internalOrganisations) { var partyFinancial = @this.PartyFinancialRelationshipsWhereParty.FirstOrDefault(v => Equals(v.InternalOrganisation, internalOrganisation)); if (partyFinancial == null) { partyFinancial = new PartyFinancialRelationshipBuilder(@this.Strategy.Session) .WithParty(@this) .WithInternalOrganisation(internalOrganisation) .Build(); } if (partyFinancial.SubAccountNumber == 0) { partyFinancial.SubAccountNumber = internalOrganisation.NextSubAccountNumber(); } } } }
/// <summary> /// Starts tracking the <see cref="IDerivation"/> instance given as paramteter. /// </summary> /// <param name="derivation">The derivation to track.</param> /// <returns>The prevous derivation.</returns> public IDerivation StartTracking(IDerivation derivation) { var result = this.TrackingDerivation; this.TrackingDerivation = derivation; return(result); }
public void AppsOnDeriveMembership(IDerivation derivation) { if (this.ExistSupplier) { if (this.Supplier.ContactsUserGroup != null) { foreach (OrganisationContactRelationship contactRelationship in this.Supplier.OrganisationContactRelationshipsWhereOrganisation) { if (this.FromDate <= DateTime.UtcNow && (!this.ExistThroughDate || this.ThroughDate >= DateTime.UtcNow)) { if (!this.Supplier.ContactsUserGroup.Members.Contains(contactRelationship.Contact)) { this.Supplier.ContactsUserGroup.AddMember(contactRelationship.Contact); } } else { if (this.Supplier.ContactsUserGroup.Members.Contains(contactRelationship.Contact)) { this.Supplier.ContactsUserGroup.RemoveMember(contactRelationship.Contact); } } } } } }
public void AppsOnDeriveName(IDerivation derivation) { if (this.ExistPart) { this.Name = this.Part.Name; } }
public void BaseOnDeriveMembership(IDerivation derivation) { if (this.ExistSupplier) { if (this.Supplier.ContactsUserGroup != null) { foreach (OrganisationContactRelationship contactRelationship in this.Supplier.OrganisationContactRelationshipsWhereOrganisation) { if (contactRelationship.FromDate <= this.Session().Now() && (!contactRelationship.ExistThroughDate || this.ThroughDate >= this.Session().Now())) { if (!this.Supplier.ContactsUserGroup.Members.Contains(contactRelationship.Contact)) { this.Supplier.ContactsUserGroup.AddMember(contactRelationship.Contact); } } else { if (this.Supplier.ContactsUserGroup.Members.Contains(contactRelationship.Contact)) { this.Supplier.ContactsUserGroup.RemoveMember(contactRelationship.Contact); } } } } } }
public void AppsOnDeriveRevenue(IDerivation derivation) { this.Revenue = 0; var toDate = DateTimeFactory.CreateDate(this.Year, this.Month, 01).AddMonths(1); var invoices = this.Party.SalesInvoicesWhereBillToCustomer; invoices.Filter.AddEquals(SalesInvoices.Meta.BilledFromInternalOrganisation, this.InternalOrganisation); invoices.Filter.AddNot().AddEquals(SalesInvoices.Meta.CurrentObjectState, new SalesInvoiceObjectStates(this.Strategy.Session).WrittenOff); invoices.Filter.AddBetween(SalesInvoices.Meta.InvoiceDate, DateTimeFactory.CreateDate(this.Year, this.Month, 01), toDate); foreach (SalesInvoice salesInvoice in invoices) { foreach (SalesInvoiceItem salesInvoiceItem in salesInvoice.SalesInvoiceItems) { if (salesInvoiceItem.ExistSalesRep && salesInvoiceItem.SalesRep.Equals(this.SalesRep)) { this.Revenue += salesInvoiceItem.TotalExVat; } } } if (this.ExistSalesRep) { var salesRepRevenue = SalesRepRevenues.AppsFindOrCreateAsDependable(this.Strategy.Session, this); salesRepRevenue.OnDerive(x => x.WithDerivation(derivation)); } }
public void AppsOnDeriveInvoiceItems(IDerivation derivation) { foreach (PurchaseInvoiceItem purchaseInvoiceItem in this.PurchaseInvoiceItems) { purchaseInvoiceItem.AppsOnDerivePrices(); } }
/// <summary> /// Accepts arguments /// </summary> private void AcceptArguments() { foreach (IMeasurements measurements in this.measurements) { IAssociatedObject cont = measurements as IAssociatedObject; INamedComponent c = cont.Object as INamedComponent; string name = c.Name; for (int i = 0; i < measurements.Count; i++) { IMeasurement measure = measurements[i]; string p = name + "." + measure.Name; for (int j = 0; j < 2; j++) { if (arguments[j].Equals(p)) { input[j] = measure; break; } } } } hasDerivation = true; for (int i = 0; i < input.Length; i++) { IDerivation der = input[i] as IDerivation; if (der == null) { hasDerivation = false; break; } } }
protected override IDerivation ExpandRnd(DerivationContext aContext) { DictionaryDerivation lList = new DictionaryDerivation(InsertSpace, aContext); int lExprCnt = 1; for (int i = 0; i < mPhrases.Count; i++) { IPhrase lPhr = mPhrases[i]; IDerivation lRes = lPhr.Expand(aContext); string lKeyName; Symbol lCurrentSymbol = lPhr as Symbol; if (lCurrentSymbol != null) { lCurrentSymbol.OccurenceInSeq = i; lKeyName = lCurrentSymbol.Text; //взять протокол вывода этого правила //TODO: aContext.RuleSeqProtocol.Add(lCurrentSymbol.Text, lRes); //добавить в его протокол вывода последовательности имя lCurrentSymbol.Text и результат lRes } else { lKeyName = string.Format("Expr{0}", lExprCnt++); } lList.Add(lKeyName, lRes, aContext); } return(lList); }
public void AppsOnDeriveInvoiceTotals(IDerivation derivation) { this.TotalBasePrice = 0; this.TotalDiscount = 0; this.TotalSurcharge = 0; this.TotalFee = 0; this.TotalShippingAndHandling = 0; this.TotalVat = 0; this.TotalExVat = 0; this.TotalIncVat = 0; this.TotalPurchasePrice = 0; this.TotalListPrice = 0; this.MaintainedMarkupPercentage = 0; this.InitialMarkupPercentage = 0; this.MaintainedProfitMargin = 0; this.InitialProfitMargin = 0; foreach (SalesInvoiceItem item in this.SalesInvoiceItems) { this.TotalBasePrice += item.TotalBasePrice; this.TotalDiscount += item.TotalDiscount; this.TotalSurcharge += item.TotalSurcharge; this.TotalVat += item.TotalVat; this.TotalExVat += item.TotalExVat; this.TotalIncVat += item.TotalIncVat; this.TotalPurchasePrice += item.UnitPurchasePrice; this.TotalListPrice += item.CalculatedUnitPrice; } this.DeriveDiscountAdjustments(derivation); this.DeriveSurchargeAdjustments(derivation); this.DeriveTotalFee(derivation); this.DeriveTotalShippingAndHandling(derivation); this.AppsOnDeriveMarkupAndProfitMargin(derivation); }
public void AppsOnDeriveSalesOrderPaymentStatus(IDerivation derivation) { foreach (SalesInvoiceItem invoiceItem in this.SalesInvoiceItems) { foreach (ShipmentItemBilling shipmentItemBilling in invoiceItem.ShipmentItemBillingsWhereInvoiceItem) { foreach (OrderShipment orderShipment in shipmentItemBilling.ShipmentItem.OrderShipmentsWhereShipmentItem) { if (orderShipment.OrderItem is SalesOrderItem salesOrderItem) { salesOrderItem.AppsOnDerivePaymentState(derivation); salesOrderItem.SalesOrderWhereSalesOrderItem.OnDerive(x => x.WithDerivation(derivation)); } } } foreach (OrderItemBilling orderItemBilling in invoiceItem.OrderItemBillingsWhereInvoiceItem) { foreach (OrderShipment orderShipment in orderItemBilling.OrderItem.OrderShipmentsWhereOrderItem) { if (orderShipment.OrderItem is SalesOrderItem salesOrderItem) { salesOrderItem.AppsOnDerivePaymentState(derivation); salesOrderItem.SalesOrderWhereSalesOrderItem.OnDerive(x => x.WithDerivation(derivation)); } } } } }
private void DeriveCurrentObjectState(IDerivation derivation) { if (this.SalesInvoiceState.Equals(new SalesInvoiceStates(this.Strategy.Session).Paid)) { this.AppsOnDeriveSalesOrderPaymentStatus(derivation); } }
private decimal AppsOnDeriveShippingAndHandlingCharges(IDerivation derivation) { var charges = 0M; if (!this.WithoutCharges) { foreach (ShippingAndHandlingComponent shippingAndHandlingComponent in new ShippingAndHandlingComponents(this.Strategy.Session).Extent()) { if (shippingAndHandlingComponent.FromDate <= DateTime.UtcNow && (!shippingAndHandlingComponent.ExistThroughDate || shippingAndHandlingComponent.ThroughDate >= DateTime.UtcNow)) { if (ShippingAndHandlingComponents.AppsIsEligible(shippingAndHandlingComponent, this)) { if (shippingAndHandlingComponent.Cost.HasValue) { if (charges == 0 || shippingAndHandlingComponent.Cost < charges) { charges = shippingAndHandlingComponent.Cost.Value; } } } } } } return(charges); }
private void Sync(IDerivation derivation, PurchaseOrderItem[] validOrderItems) { foreach (var orderItem in validOrderItems) { orderItem.Sync(this); } }
void IMeasurements.UpdateMeasurements() { if (input[0] == null) { return; } if (isUpdated) { return; } try { IDataConsumer c = this; c.UpdateChildrenData(); Calculate((double)input[0].Parameter(), (double)input[1].Parameter()); if (hasDerivation) { for (int i = 0; i < 2; i++) { IDerivation der = input[i] as IDerivation; result[1] += dx[i] * (double)der.Derivation.Parameter(); } } isUpdated = true; } catch (Exception e) { e.ShowError(10); this.Throw(e); } }
public void AppsOnDeriveCustomerContactMemberShip(IDerivation derivation) { if (this.ExistContact && this.ExistOrganisation && this.Organisation.ExistCustomerContactUserGroup) { if (this.FromDate <= DateTime.UtcNow && (!this.ExistThroughDate || this.ThroughDate >= DateTime.UtcNow)) { if (this.Organisation.AppsIsActiveCustomer(this.FromDate)) { if (!this.Organisation.CustomerContactUserGroup.ContainsMember(this.Contact)) { this.Organisation.CustomerContactUserGroup.AddMember(this.Contact); } } else { if (this.Organisation.CustomerContactUserGroup.ContainsMember(this.Contact)) { this.Organisation.CustomerContactUserGroup.RemoveMember(this.Contact); } } } else { if (this.Organisation.CustomerContactUserGroup.ContainsMember(this.Contact)) { this.Organisation.CustomerContactUserGroup.RemoveMember(this.Contact); } } } }
public void AppsDepleteSalesOrders(IDerivation derivation) { Extent <SalesOrderItem> salesOrderItems = this.Strategy.Session.Extent <SalesOrderItem>(); salesOrderItems.Filter.AddEquals(M.SalesOrderItem.SalesOrderItemState, new SalesOrderItemStates(this.Strategy.Session).InProcess); salesOrderItems.Filter.AddExists(M.OrderItem.DeliveryDate); salesOrderItems.AddSort(M.OrderItem.DeliveryDate, SortDirection.Descending); salesOrderItems = this.Strategy.Session.Instantiate(salesOrderItems); var subtract = this.PreviousQuantityOnHand - this.QuantityOnHand; foreach (SalesOrderItem salesOrderItem in salesOrderItems) { if (subtract > 0 && salesOrderItem.QuantityRequestsShipping > 0) { decimal diff; if (subtract >= salesOrderItem.QuantityRequestsShipping) { diff = salesOrderItem.QuantityRequestsShipping; } else { diff = subtract; } subtract -= diff; salesOrderItem.AppsOnDeriveSubtractFromShipping(derivation, diff); salesOrderItem.SalesOrderWhereSalesOrderItem.OnDerive(x => x.WithDerivation(derivation)); } } }
protected override IDerivation ExpandRnd(DerivationContext aContext) { if (IsTerminal) { TLog.Write("T", Text); return(new TextDerivation(Text)); } else { // искать правило if (mGrammar.mRules.ContainsKey(Text)) { Rule lRule = mGrammar.mRules[Text]; TreeNode lNewNode = new TreeNode(Text); aContext.RuleDerivNode.Nodes.Add(lNewNode); DerivationContext lNewContext = new DerivationContext(aContext); lNewContext.RuleDerivNode = lNewNode; lNewContext.ExpandingRuleSymbol = this; IDerivation lRuleResult = lRule.Expand(lNewContext); mGrammar.RuleProtocol.Add(Text, lRuleResult, aContext); return(lRuleResult); // Expand(lRuleResult, aContext); } else { // нашли нетерм. символ, который нельзя раскрыть throw new GrammarDeductException(string.Format("Не определен нетерминальный символ {0}", Text)); } } }
public void AppsOnDeriveCurrentObjectState(IDerivation derivation) { if (this.ExistCurrentObjectState && !this.CurrentObjectState.Equals(this.LastObjectState)) { var currentStatus = new PurchaseReturnStatusBuilder(this.Strategy.Session).WithPurchaseReturnObjectState(this.CurrentObjectState).Build(); this.AddShipmentStatus(currentStatus); this.CurrentShipmentStatus = currentStatus; } }
public void AppsOnDerivePurchaseShipmentItem(IDerivation derivation) { if (this.ShipmentWhereShipmentItem is PurchaseShipment) { this.Quantity = 0; var shipmentReceipt = this.ShipmentReceiptWhereShipmentItem; this.Quantity += shipmentReceipt.QuantityAccepted + shipmentReceipt.QuantityRejected; } }
public void AppsOnDeriveAmountPaid(IDerivation derivation) { this.AmountPaid = 0; foreach (PaymentApplication paymentApplication in this.PaymentApplicationsWhereInvoiceItem) { this.AmountPaid += paymentApplication.AmountApplied; this.AppsPaymentReceived(derivation); } }
public void AppsOnDeriveCurrentObjectState(IDerivation derivation) { if (this.ExistCurrentObjectState && !this.CurrentObjectState.Equals(this.LastObjectState)) { SerializedInventoryItemStatus currentStatus = new SerializedInventoryItemStatusBuilder(this.Strategy.Session).WithSerializedInventoryItemObjectState(this.CurrentObjectState).Build(); this.AddInventoryItemStatus(currentStatus); this.CurrentInventoryItemStatus = currentStatus; } this.AppsOnDeriveProductCategories(derivation); }
public void AppsOnDeriveCustomerShipmentItem(IDerivation derivation) { if (this.ShipmentWhereShipmentItem is CustomerShipment) { this.QuantityShipped = 0; foreach (PackagingContent packagingContent in PackagingContentsWhereShipmentItem) { this.QuantityShipped += packagingContent.Quantity; } } }
public void AppsOnDerivePartnerContacts(IDerivation derivation) { if (this.ExistPartner) { var partner = this.Partner; foreach (OrganisationContactRelationship contactRelationship in partner.OrganisationContactRelationshipsWhereOrganisation) { contactRelationship.Contact.OnDerive(x => x.WithDerivation(derivation)); } } }
public void AppsOnDeriveInventoryItem(IDerivation derivation) { Good good = null; if (this.ExistProduct) { good = this.Product as Good; } var supplier = this.Supplier as Organisation; if (supplier != null && good != null) { if (good.ExistInventoryItemKind && good.InventoryItemKind.Equals(new InventoryItemKinds(this.Strategy.Session).NonSerialized)) { foreach (SupplierRelationship supplierRelationship in supplier.SupplierRelationshipsWhereSupplier) { foreach (Facility facility in supplierRelationship.InternalOrganisation.FacilitiesWhereOwner) { var inventoryItems = good.InventoryItemsWhereGood; inventoryItems.Filter.AddEquals(InventoryItems.Meta.Facility, facility); var inventoryItem = inventoryItems.First; if (inventoryItem == null) { new NonSerializedInventoryItemBuilder(this.Strategy.Session).WithFacility(facility).WithGood(good).Build(); } } } } else { if (good.ExistFinishedGood && good.FinishedGood.ExistInventoryItemKind && good.FinishedGood.InventoryItemKind.Equals(new InventoryItemKinds(this.Strategy.Session).NonSerialized)) { foreach (SupplierRelationship supplierRelationship in supplier.SupplierRelationshipsWhereSupplier) { foreach (Facility facility in supplierRelationship.InternalOrganisation.FacilitiesWhereOwner) { var inventoryItems = good.FinishedGood.InventoryItemsWherePart; inventoryItems.Filter.AddEquals(InventoryItems.Meta.Facility, facility); var inventoryItem = inventoryItems.First; if (inventoryItem == null) { new NonSerializedInventoryItemBuilder(this.Strategy.Session).WithFacility(facility).WithPart(good.FinishedGood).Build(); } } } } } } }
public void AppsOnDeriveInvolvedParties(IDerivation derivation) { this.InvolvedParties = this.Participants; this.AddInvolvedParty(this.Owner); if (this.ExistPartyRelationshipWhereCommunicationEvent) { foreach (Party party in this.PartyRelationshipWhereCommunicationEvent.Parties) { this.AddInvolvedParty(party); } } }
public static void AppsOnDeriveProductCategories(this InventoryItem @this, IDerivation derivation) { @this.RemoveDerivedProductCategories(); if (@this.ExistGood) { foreach (ProductCategory productCategory in @this.Good.ProductCategories) { @this.AddDerivedProductCategory(productCategory); @this.AddParentCategories(productCategory); } } }
public static void AppsOnDeriveInventoryItem(this Part @this, IDerivation derivation) { if (@this.ExistInventoryItemKind && @this.InventoryItemKind.Equals(new InventoryItemKinds(@this.Strategy.Session).NonSerialized)) { if ([email protected]) { new NonSerializedInventoryItemBuilder(@this.Strategy.Session) .WithFacility(@this.OwnedByParty.DefaultFacility) .WithPart(@this) .Build(); } } }
public void AppsOnDeriveInvolvedParties(IDerivation derivation) { this.RemoveInvolvedParties(); this.AddInvolvedParty(this.Owner); this.AddInvolvedParty(this.Originator); this.AddInvolvedParty(this.Receiver); if (this.ExistPartyRelationshipWhereCommunicationEvent) { foreach (Party party in this.PartyRelationshipWhereCommunicationEvent.Parties) { this.AddInvolvedParty(party); } } }
public void AppsOnDeriveRevenue(IDerivation derivation) { this.Revenue = 0; var partyProductCategoryRevenues = this.ProductCategory.PartyProductCategoryRevenuesWhereProductCategory; partyProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.InternalOrganisation, this.InternalOrganisation); partyProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.Year, this.Year); partyProductCategoryRevenues.Filter.AddEquals(PartyProductCategoryRevenues.Meta.Month, this.Month); foreach (PartyProductCategoryRevenue productCategoryRevenue in partyProductCategoryRevenues) { this.Revenue += productCategoryRevenue.Revenue; } if (this.ProductCategory.ExistParents) { ProductCategoryRevenues.AppsFindOrCreateAsDependable(this.Strategy.Session, this); } var months = ((DateTime.UtcNow.Year - this.Year) * 12) + DateTime.UtcNow.Month - this.Month; if (months <= 12) { var histories = this.ProductCategory.ProductCategoryRevenueHistoriesWhereProductCategory; histories.Filter.AddEquals(ProductCategoryRevenueHistories.Meta.InternalOrganisation, this.InternalOrganisation); var history = histories.First ?? new ProductCategoryRevenueHistoryBuilder(this.Strategy.Session) .WithCurrency(this.Currency) .WithInternalOrganisation(this.InternalOrganisation) .WithProductCategory(this.ProductCategory) .Build(); } foreach (ProductCategory parentCategory in this.ProductCategory.Parents) { var productCategoryRevenues = parentCategory.ProductCategoryRevenuesWhereProductCategory; productCategoryRevenues.Filter.AddEquals(ProductCategoryRevenues.Meta.InternalOrganisation, this.InternalOrganisation); productCategoryRevenues.Filter.AddEquals(ProductCategoryRevenues.Meta.Year, this.Year); productCategoryRevenues.Filter.AddEquals(ProductCategoryRevenues.Meta.Month, this.Month); var productCategoryRevenue = productCategoryRevenues.First ?? new ProductCategoryRevenueBuilder(this.Strategy.Session) .WithInternalOrganisation(this.InternalOrganisation) .WithProductCategory(parentCategory) .WithYear(this.Year) .WithMonth(this.Month) .WithCurrency(this.Currency) .WithRevenue(0M) .Build(); productCategoryRevenue.OnDerive(x => x.WithDerivation(derivation)); } }
public void AppsOnDeriveInventoryItem(IDerivation derivation) { if (this.ExistShipmentItem && this.ShipmentItem.ExistOrderShipmentsWhereShipmentItem) { var purchaseOrderItem = this.ShipmentItem.OrderShipmentsWhereShipmentItem[0].PurchaseOrderItem; var order = purchaseOrderItem.PurchaseOrderWherePurchaseOrderItem; if (purchaseOrderItem.ExistProduct) { var good = purchaseOrderItem.Product as Allors.Domain.Good; if (good != null) { if (good.ExistFinishedGood) { if (!this.ExistInventoryItem || !this.InventoryItem.Part.Equals(good.FinishedGood)) { var inventoryItems = good.FinishedGood.InventoryItemsWherePart; inventoryItems.Filter.AddEquals(InventoryItems.Meta.Facility, order.ShipToBuyer.DefaultFacility); this.InventoryItem = inventoryItems.First as Allors.Domain.NonSerializedInventoryItem; } } else { if (!this.ExistInventoryItem || !this.InventoryItem.Good.Equals(good)) { var inventoryItems = good.InventoryItemsWhereGood; inventoryItems.Filter.AddEquals(InventoryItems.Meta.Facility, order.ShipToBuyer.DefaultFacility); this.InventoryItem = inventoryItems.First as Allors.Domain.NonSerializedInventoryItem ?? new NonSerializedInventoryItemBuilder(this.Strategy.Session).WithGood(good).Build(); } } } } if (purchaseOrderItem.ExistPart) { if (!this.ExistInventoryItem || !this.InventoryItem.Part.Equals(purchaseOrderItem.Part)) { var inventoryItems = purchaseOrderItem.Part.InventoryItemsWherePart; inventoryItems.Filter.AddEquals(InventoryItems.Meta.Facility, order.ShipToBuyer.DefaultFacility); this.InventoryItem = inventoryItems.First as Allors.Domain.NonSerializedInventoryItem; } } } }
public void AppsCalculatePurchasePrice(IDerivation derivation) { this.UnitPurchasePrice = 0; if (this.ExistProduct && this.Product.ExistSupplierOfferingsWhereProduct && this.Product.SupplierOfferingsWhereProduct.Count == 1 && this.Product.SupplierOfferingsWhereProduct.First.ExistProductPurchasePrices) { ProductPurchasePrice productPurchasePrice = null; var prices = this.Product.SupplierOfferingsWhereProduct.First.ProductPurchasePrices; foreach (ProductPurchasePrice purchasePrice in prices) { if (purchasePrice.FromDate <= this.SalesOrderWhereSalesOrderItem.OrderDate && (!purchasePrice.ExistThroughDate || purchasePrice.ThroughDate >= this.SalesOrderWhereSalesOrderItem.OrderDate)) { productPurchasePrice = purchasePrice; } } if (productPurchasePrice == null) { var index = this.Product.SupplierOfferingsWhereProduct.First.ProductPurchasePrices.Count; var lastKownPrice = this.Product.SupplierOfferingsWhereProduct.First.ProductPurchasePrices[index - 1]; productPurchasePrice = lastKownPrice; } if (productPurchasePrice != null) { this.UnitPurchasePrice = productPurchasePrice.Price; if (!productPurchasePrice.UnitOfMeasure.Equals(this.Product.UnitOfMeasure)) { foreach (UnitOfMeasureConversion unitOfMeasureConversion in productPurchasePrice.UnitOfMeasure.UnitOfMeasureConversions) { if (unitOfMeasureConversion.ToUnitOfMeasure.Equals(this.Product.UnitOfMeasure)) { this.UnitPurchasePrice = decimal.Round(this.UnitPurchasePrice * (1 / unitOfMeasureConversion.ConversionFactor), 2); } } } } } }
public void AppsOnDeriveSequenceNumber(IDerivation derivation) { var highestNumber = 0; if (this.ExistShipmentWhereShipmentPackage) { foreach (ShipmentPackage shipmentPackage in this.ShipmentWhereShipmentPackage.ShipmentPackages) { if (shipmentPackage.ExistSequenceNumber && shipmentPackage.SequenceNumber > highestNumber) { highestNumber = shipmentPackage.SequenceNumber; } } if (!this.ExistSequenceNumber || this.SequenceNumber == 0) { this.SequenceNumber = highestNumber + 1; } } }
public void AppsOnDeriveContraAccount(IDerivation derivation) { if (this.ExistPreviousContraAccount) { if (this.PreviousContraAccount.ExistJournalEntryDetailsWhereGeneralLedgerAccount) { derivation.Validation.AssertAreEqual(this, this.Meta.ContraAccount, this.Meta.PreviousContraAccount); } else { this.PreviousContraAccount = this.ContraAccount; } } else { if (this.ExistJournalType &&this.JournalType.Equals(new JournalTypes(this.Strategy.Session).Bank)) { // initial derivation of ContraAccount, PreviousContraAccount does not exist yet. if (this.ExistContraAccount) { var savedContraAccount = this.ContraAccount; this.RemoveContraAccount(); if (!savedContraAccount.IsNeutralAccount()) { derivation.Validation.AddError(this, this.Meta.ContraAccount, ErrorMessages.GeneralLedgerAccountNotNeutral); } if (!savedContraAccount.GeneralLedgerAccount.BalanceSheetAccount) { derivation.Validation.AddError(this, this.Meta.ContraAccount, ErrorMessages.GeneralLedgerAccountNotBalanceAccount); } this.ContraAccount = savedContraAccount; } } if (!derivation.Validation.HasErrors) { this.PreviousContraAccount = this.ContraAccount; } } }
public void AppsOnDeriveInternalOrganisationSupplier(IDerivation derivation) { if (this.ExistSupplier && this.ExistInternalOrganisation) { if (this.FromDate <= DateTime.UtcNow && (!this.ExistThroughDate || this.ThroughDate >= DateTime.UtcNow)) { if (!this.Supplier.ExistInternalOrganisationWhereSupplier) { this.InternalOrganisation.AddSupplier(this.Supplier); } } if (this.FromDate > DateTime.UtcNow || (this.ExistThroughDate && this.ThroughDate < DateTime.UtcNow)) { if (this.Supplier.ExistInternalOrganisationWhereSupplier) { this.InternalOrganisation.RemoveSupplier(this.Supplier); } } } }
public void AppsOnDeriveOrderItemAdjustment(IDerivation derivation) { if (this.ActualQuantity.HasValue && this.ExistPickListWherePickListItem && this.PickListWherePickListItem.CurrentObjectState.UniqueId.Equals(PickListObjectStates.PickedId)) { var diff = this.RequestedQuantity - this.ActualQuantity.Value; foreach (ItemIssuance itemIssuance in this.ItemIssuancesWherePickListItem) { itemIssuance.IssuanceDateTime = DateTime.UtcNow; foreach (OrderShipment orderShipment in itemIssuance.ShipmentItem.OrderShipmentsWhereShipmentItem) { if (!orderShipment.Picked) { if (diff > 0) { if (orderShipment.Quantity >= diff) { orderShipment.Quantity -= diff; orderShipment.ShipmentItem.Quantity -= diff; itemIssuance.Quantity -= diff; diff = 0; } else { orderShipment.ShipmentItem.Quantity -= orderShipment.Quantity; itemIssuance.Quantity -= orderShipment.Quantity; diff -= orderShipment.Quantity; orderShipment.Quantity = 0; } } orderShipment.SalesOrderItem.AppsOnDeriveOnPicked(derivation, orderShipment.Quantity); orderShipment.Picked = true; } } } } }
private void DeriveCurrentObjectState(IDerivation derivation) { if (this.ExistCurrentObjectState && !this.CurrentObjectState.Equals(this.LastObjectState)) { var currentStatus = new SalesOrderStatusBuilder(this.Strategy.Session).WithSalesOrderObjectState(this.CurrentObjectState).Build(); this.AddOrderStatus(currentStatus); this.CurrentOrderStatus = currentStatus; } }
public void AppsOnDeriveMembership(IDerivation derivation) { if (this.ExistSupplier && this.ExistInternalOrganisation) { if (this.Supplier.SupplierContactUserGroup != null) { foreach (OrganisationContactRelationship contactRelationship in this.Supplier.OrganisationContactRelationshipsWhereOrganisation) { if (this.FromDate <= DateTime.UtcNow && (!this.ExistThroughDate || this.ThroughDate >= DateTime.UtcNow)) { if (!this.Supplier.SupplierContactUserGroup.ContainsMember(contactRelationship.Contact)) { this.Supplier.SupplierContactUserGroup.AddMember(contactRelationship.Contact); } } else { if (this.Supplier.SupplierContactUserGroup.ContainsMember(contactRelationship.Contact)) { this.Supplier.SupplierContactUserGroup.RemoveMember(contactRelationship.Contact); } } } } } }
public void AppsOnDeriveOrderTotals(IDerivation derivation) { if (this.ExistValidOrderItems) { this.TotalBasePrice = 0; this.TotalDiscount = 0; this.TotalSurcharge = 0; this.TotalExVat = 0; this.TotalFee = 0; this.TotalShippingAndHandling = 0; this.TotalVat = 0; this.TotalIncVat = 0; this.TotalPurchasePrice = 0; this.TotalListPrice = 0; this.MaintainedMarkupPercentage = 0; this.InitialMarkupPercentage = 0; this.MaintainedProfitMargin = 0; this.InitialProfitMargin = 0; foreach (SalesOrderItem item in this.ValidOrderItems) { if (!item.ExistSalesOrderItemWhereOrderedWithFeature) { this.TotalBasePrice += item.TotalBasePrice; this.TotalDiscount += item.TotalDiscount; this.TotalSurcharge += item.TotalSurcharge; this.TotalExVat += item.TotalExVat; this.TotalVat += item.TotalVat; this.TotalIncVat += item.TotalIncVat; this.TotalPurchasePrice += item.UnitPurchasePrice; this.TotalListPrice += item.CalculatedUnitPrice; } } this.AppsOnDeriveOrderAdjustments(); this.AppsOnDeriveTotalFee(); this.AppsOnDeriveTotalShippingAndHandling(); this.AppsOnDeriveMarkupAndProfitMargin(derivation); } }
public void AppsOnDeriveSalesReps(IDerivation derivation) { this.RemoveSalesReps(); foreach (SalesOrderItem item in this.ValidOrderItems) { this.AddSalesRep(item.SalesRep); } }
public void AppsTryShip(IDerivation derivation) { if (this.CurrentObjectState.Equals(new SalesOrderObjectStates(this.Strategy.Session).InProcess)) { var somethingToShip = false; var allItemsAvailable = true; foreach (SalesOrderItem salesOrderItem in this.ValidOrderItems) { if (!this.PartiallyShip && salesOrderItem.QuantityRequestsShipping != salesOrderItem.QuantityOrdered) { allItemsAvailable = false; break; } if (this.PartiallyShip && salesOrderItem.QuantityRequestsShipping > 0) { somethingToShip = true; } } if (this.CurrentObjectState.Equals(new SalesOrderObjectStates(this.Strategy.Session).InProcess) && ((!this.PartiallyShip && allItemsAvailable) || somethingToShip)) { this.AppsShip(derivation); } } }
private CustomerShipment AppsShip(IDerivation derivation, KeyValuePair<PostalAddress, Party> address) { var pendingShipment = address.Value.AppsGetPendingCustomerShipmentForStore(address.Key, this.Store, this.ShipmentMethod); if (pendingShipment == null) { pendingShipment = new CustomerShipmentBuilder(this.Strategy.Session) .WithBillFromInternalOrganisation(this.TakenByInternalOrganisation) .WithShipFromParty(this.TakenByInternalOrganisation) .WithShipFromAddress(this.TakenByInternalOrganisation.ShippingAddress) .WithBillToParty(this.BillToCustomer) .WithBillToContactMechanism(this.BillToContactMechanism) .WithShipToAddress(address.Key) .WithShipToParty(address.Value) .WithShipmentPackage(new ShipmentPackageBuilder(this.Strategy.Session).Build()) .WithStore(this.Store) .WithShipmentMethod(this.ShipmentMethod) .WithPaymentMethod(this.PaymentMethod) .Build(); } foreach (SalesOrderItem orderItem in this.ValidOrderItems) { if (orderItem.ExistProduct && orderItem.ShipToAddress.Equals(address.Key) && orderItem.QuantityRequestsShipping > 0) { var good = orderItem.Product as Good; ShipmentItem shipmentItem = null; foreach (ShipmentItem item in pendingShipment.ShipmentItems) { if (item.Good.Equals(good)) { shipmentItem = item; break; } } if (shipmentItem != null) { shipmentItem.Quantity += orderItem.QuantityRequestsShipping; shipmentItem.ContentsDescription = $"{shipmentItem.Quantity} * {good}"; } else { shipmentItem = new ShipmentItemBuilder(this.Strategy.Session) .WithGood(good) .WithQuantity(orderItem.QuantityRequestsShipping) .WithContentsDescription($"{orderItem.QuantityRequestsShipping} * {good}") .Build(); pendingShipment.AddShipmentItem(shipmentItem); } foreach (SalesOrderItem featureItem in orderItem.OrderedWithFeatures) { shipmentItem.AddProductFeature(featureItem.ProductFeature); } var orderShipmentsWhereShipmentItem = shipmentItem.OrderShipmentsWhereShipmentItem; orderShipmentsWhereShipmentItem.Filter.AddEquals(OrderShipments.Meta.SalesOrderItem, orderItem); if (orderShipmentsWhereShipmentItem.First == null) { new OrderShipmentBuilder(this.Strategy.Session) .WithSalesOrderItem(orderItem) .WithShipmentItem(shipmentItem) .WithQuantity(orderItem.QuantityRequestsShipping) .Build(); } else { orderShipmentsWhereShipmentItem.First.Quantity += orderItem.QuantityRequestsShipping; } orderItem.AppsOnDeriveOnShip(derivation); } } // TODO: Check pendingShipment.OnDerive(x => x.WithDerivation(derivation)); return pendingShipment; }
private List<Shipment> AppsShip(IDerivation derivation) { var addresses = this.ShipToAddresses(); var shipments = new List<Shipment>(); if (addresses.Count > 0) { foreach (var address in addresses) { shipments.Add(this.AppsShip(derivation, address)); } } return shipments; }