Esempio n. 1
0
        private void CreatePickList(IDerivation derivation)
        {
            if (this.ExistShipToParty)
            {
                var pendingPickList = this.PendingPickList;

                if (pendingPickList != null)
                {
                    foreach (PickListItem pickListItem in pendingPickList.PickListItems)
                    {
                        foreach (ItemIssuance itemIssuance in pickListItem.ItemIssuancesWherePickListItem)
                        {
                            itemIssuance.Delete();
                        }

                        pendingPickList.RemovePickListItem(pickListItem);
                        pickListItem.Delete();
                    }
                }

                foreach (ShipmentItem shipmentItem in this.ShipmentItems)
                {
                    var quantityIssued = 0M;
                    foreach (ItemIssuance itemIssuance in shipmentItem.ItemIssuancesWhereShipmentItem)
                    {
                        quantityIssued += itemIssuance.Quantity;
                    }

                    if (!shipmentItem.ExistItemIssuancesWhereShipmentItem || shipmentItem.Quantity > quantityIssued)
                    {
                        var salesOrderItem = shipmentItem.OrderShipmentsWhereShipmentItem[0].OrderItem as SalesOrderItem;

                        if (this.PendingPickList == null)
                        {
                            pendingPickList = new PickListBuilder(this.Strategy.Session).WithShipToParty(this.ShipToParty).Build();
                        }

                        PickListItem pickListItem = null;
                        foreach (PickListItem item in pendingPickList.PickListItems)
                        {
                            if (salesOrderItem != null && item.InventoryItem.Equals(salesOrderItem.ReservedFromNonSerialisedInventoryItem))
                            {
                                pickListItem = item;
                                break;
                            }
                        }

                        if (pickListItem != null)
                        {
                            pickListItem.RequestedQuantity += shipmentItem.Quantity;

                            var itemIssuances = pickListItem.ItemIssuancesWherePickListItem;
                            itemIssuances.Filter.AddEquals(M.ItemIssuance.ShipmentItem, shipmentItem);
                            itemIssuances.First.Quantity = shipmentItem.Quantity;
                        }
                        else
                        {
                            var quantity = shipmentItem.Quantity - quantityIssued;
                            pickListItem = new PickListItemBuilder(this.Strategy.Session)
                                           .WithInventoryItem(salesOrderItem.ReservedFromNonSerialisedInventoryItem)
                                           .WithRequestedQuantity(quantity)
                                           .WithActualQuantity(quantity)
                                           .Build();

                            if (salesOrderItem.ExistReservedFromNonSerialisedInventoryItem)
                            {
                                pickListItem.InventoryItem = salesOrderItem.ReservedFromNonSerialisedInventoryItem;
                            }

                            if (salesOrderItem.ExistReservedFromSerialisedInventoryItem)
                            {
                                pickListItem.InventoryItem = salesOrderItem.ReservedFromSerialisedInventoryItem;
                            }

                            if (salesOrderItem.ExistSerialisedItem)
                            {
                                salesOrderItem.ReservedFromSerialisedInventoryItem.SerialisedItem.AvailableForSale = false;

                                if (salesOrderItem.ExistNewSerialisedItemState)
                                {
                                    salesOrderItem.ReservedFromSerialisedInventoryItem.SerialisedItem.SerialisedItemState = salesOrderItem.NewSerialisedItemState;
                                }

                                if (salesOrderItem.NewSerialisedItemState.Equals(
                                        new SerialisedItemStates(this.strategy.Session).Sold))
                                {
                                    salesOrderItem.SerialisedItem.OwnedBy = this.ShipToParty;
                                }
                            }

                            new ItemIssuanceBuilder(this.Strategy.Session)
                            .WithInventoryItem(pickListItem.InventoryItem)
                            .WithShipmentItem(shipmentItem)
                            .WithQuantity(quantity)
                            .WithPickListItem(pickListItem)
                            .Build();
                        }

                        pendingPickList.AddPickListItem(pickListItem);
                    }
                }

                if (pendingPickList != null)
                {
                    pendingPickList.OnDerive(x => x.WithDerivation(derivation));
                }
            }
        }
Esempio n. 2
0
        private void CreatePickList()
        {
            if (this.ExistShipmentItems && this.ExistShipToParty)
            {
                var pickList = new PickListBuilder(this.Strategy.Session).WithShipToParty(this.ShipToParty).WithStore(this.Store).Build();

                foreach (var shipmentItem in this.ShipmentItems
                         .Where(v => v.ShipmentItemState.Equals(new ShipmentItemStates(this.Session()).Created) ||
                                v.ShipmentItemState.Equals(new ShipmentItemStates(this.Session()).Picking)))
                {
                    var quantityIssued = 0M;
                    foreach (ItemIssuance itemIssuance in shipmentItem.ItemIssuancesWhereShipmentItem)
                    {
                        quantityIssued += itemIssuance.Quantity;
                    }

                    var quantityToIssue = shipmentItem.Quantity - quantityIssued;
                    if (quantityToIssue == 0)
                    {
                        return;
                    }

                    var unifiedGood    = shipmentItem.Good as UnifiedGood;
                    var nonUnifiedGood = shipmentItem.Good as NonUnifiedGood;
                    var serialized     = unifiedGood?.InventoryItemKind.Equals(new InventoryItemKinds(this.Session()).Serialised);
                    var part           = unifiedGood ?? nonUnifiedGood?.Part;

                    var facilities     = ((InternalOrganisation)this.ShipFromParty).FacilitiesWhereOwner;
                    var inventoryItems = part.InventoryItemsWherePart.Where(v => facilities.Contains(v.Facility));
                    SerialisedInventoryItem issuedFromSerializedInventoryItem = null;

                    foreach (InventoryItem inventoryItem in shipmentItem.ReservedFromInventoryItems)
                    {
                        // shipment item originates from sales order. Sales order item has only 1 ReservedFromInventoryItem.
                        // Foreach loop wil execute once.
                        var pickListItem = new PickListItemBuilder(this.Strategy.Session)
                                           .WithInventoryItem(inventoryItem)
                                           .WithQuantity(quantityToIssue)
                                           .Build();

                        new ItemIssuanceBuilder(this.Strategy.Session)
                        .WithInventoryItem(pickListItem.InventoryItem)
                        .WithShipmentItem(shipmentItem)
                        .WithQuantity(pickListItem.Quantity)
                        .WithPickListItem(pickListItem)
                        .Build();

                        pickList.AddPickListItem(pickListItem);

                        if (serialized.HasValue && serialized.Value)
                        {
                            issuedFromSerializedInventoryItem = (SerialisedInventoryItem)inventoryItem;
                        }
                    }

                    // shipment item is not linked to sales order item
                    if (!shipmentItem.ExistReservedFromInventoryItems)
                    {
                        var quantityLeftToIssue = quantityToIssue;
                        foreach (var inventoryItem in inventoryItems)
                        {
                            if (serialized.HasValue && serialized.Value && quantityLeftToIssue > 0)
                            {
                                var serializedInventoryItem = (SerialisedInventoryItem)inventoryItem;
                                if (serializedInventoryItem.AvailableToPromise == 1)
                                {
                                    var pickListItem = new PickListItemBuilder(this.Strategy.Session)
                                                       .WithInventoryItem(inventoryItem)
                                                       .WithQuantity(quantityLeftToIssue)
                                                       .Build();

                                    new ItemIssuanceBuilder(this.Strategy.Session)
                                    .WithInventoryItem(inventoryItem)
                                    .WithShipmentItem(shipmentItem)
                                    .WithQuantity(pickListItem.Quantity)
                                    .WithPickListItem(pickListItem)
                                    .Build();

                                    pickList.AddPickListItem(pickListItem);
                                    quantityLeftToIssue = 0;
                                    issuedFromSerializedInventoryItem = serializedInventoryItem;
                                }
                            }
                            else if (quantityLeftToIssue > 0)
                            {
                                var nonSerializedInventoryItem = (NonSerialisedInventoryItem)inventoryItem;
                                var quantity = quantityLeftToIssue > nonSerializedInventoryItem.AvailableToPromise
                                    ? nonSerializedInventoryItem.AvailableToPromise
                                    : quantityLeftToIssue;

                                if (quantity > 0)
                                {
                                    var pickListItem = new PickListItemBuilder(this.Strategy.Session)
                                                       .WithInventoryItem(inventoryItem)
                                                       .WithQuantity(quantity)
                                                       .Build();

                                    new ItemIssuanceBuilder(this.Strategy.Session)
                                    .WithInventoryItem(inventoryItem)
                                    .WithShipmentItem(shipmentItem)
                                    .WithQuantity(pickListItem.Quantity)
                                    .WithPickListItem(pickListItem)
                                    .Build();

                                    shipmentItem.AddReservedFromInventoryItem(inventoryItem);

                                    pickList.AddPickListItem(pickListItem);
                                    quantityLeftToIssue -= pickListItem.Quantity;
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void CreatePickList(IDerivation derivation)
        {
            if (this.ExistShipToParty)
            {
                var pendingPickList = this.PendingPickList;

                if (pendingPickList != null)
                {
                    foreach (PickListItem pickListItem in pendingPickList.PickListItems)
                    {
                        foreach (ItemIssuance itemIssuance in pickListItem.ItemIssuancesWherePickListItem)
                        {
                            itemIssuance.Delete();
                        }

                        pendingPickList.RemovePickListItem(pickListItem);
                        pickListItem.Delete();
                    }
                }

                foreach (ShipmentItem shipmentItem in this.ShipmentItems)
                {
                    var quantityIssued = 0M;
                    foreach (ItemIssuance itemIssuance in shipmentItem.ItemIssuancesWhereShipmentItem)
                    {
                        quantityIssued += itemIssuance.Quantity;
                    }

                    if (!shipmentItem.ExistItemIssuancesWhereShipmentItem || shipmentItem.Quantity > quantityIssued)
                    {
                        var orderItem = shipmentItem.OrderShipmentsWhereShipmentItem[0].SalesOrderItem;

                        if (pendingPickList == null)
                        {
                            pendingPickList = new PickListBuilder(this.Strategy.Session).WithShipToParty(this.ShipToParty).Build();
                        }

                        PickListItem pickListItem = null;
                        foreach (PickListItem item in pendingPickList.PickListItems)
                        {
                            if (item.InventoryItem.Equals(orderItem.ReservedFromInventoryItem))
                            {
                                pickListItem = item;
                                break;
                            }
                        }

                        if (pickListItem != null)
                        {
                            pickListItem.RequestedQuantity += shipmentItem.Quantity;

                            var itemIssuances = pickListItem.ItemIssuancesWherePickListItem;
                            itemIssuances.Filter.AddEquals(ItemIssuances.Meta.ShipmentItem, shipmentItem);
                            itemIssuances.First.Quantity = shipmentItem.Quantity;
                        }
                        else
                        {
                            var quantity = shipmentItem.Quantity - quantityIssued;
                            pickListItem = new PickListItemBuilder(this.Strategy.Session)
                                .WithInventoryItem(orderItem.ReservedFromInventoryItem)
                                .WithRequestedQuantity(quantity)
                                .WithActualQuantity(quantity)
                                .Build();

                            new ItemIssuanceBuilder(this.Strategy.Session)
                                .WithInventoryItem(orderItem.ReservedFromInventoryItem)
                                .WithShipmentItem(shipmentItem)
                                .WithQuantity(quantity)
                                .WithPickListItem(pickListItem)
                                .Build();
                        }

                        pendingPickList.AddPickListItem(pickListItem);
                    }
                }

                if (pendingPickList != null)
                {
                    pendingPickList.OnDerive(x=>x.WithDerivation(derivation));
                }
            }
        }