protected void ShipmentDetail_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity)
    {
        var shipmentEntry = (SOShipmentEntry)graph;

        var filterCache = shipmentEntry.addsofilter.Cache;
        var filter      = (AddSOFilter)filterCache.Current;

        var orderType = targetEntity.Fields.Single(f => f.Name == "OrderType") as EntityValueField;
        var orderNbr  = targetEntity.Fields.Single(f => f.Name == "OrderNbr") as EntityValueField;

        filter.OrderType = orderType.Value;
        filter.OrderNbr  = orderNbr.Value;
        filterCache.Update(filter);

        var orderLineNbr = targetEntity.Fields.SingleOrDefault(f => f.Name == "OrderLineNbr") as EntityValueField;
        Func <PXResult <SOShipmentPlan>, bool> lineCriteria;

        if (orderLineNbr != null && !string.IsNullOrEmpty(orderLineNbr.Value))
        {
            var nbr = int.Parse(orderLineNbr.Value);
            lineCriteria = r => r.GetItem <SOLineSplit>().LineNbr == nbr;
        }
        else
        {
            var inventoryId = targetEntity.Fields.SingleOrDefault(f => f.Name == "InventoryID") as EntityValueField;
            if (inventoryId == null || string.IsNullOrWhiteSpace(inventoryId.Value))
            {
                throw new InvalidOperationException("Neither OrderLineNbr nor InventoryID specified for ShipmentDetail");
            }
            var inventoryItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> > > > .Select(graph, inventoryId.Value).FirstOrDefault().GetItem <InventoryItem>();

            lineCriteria = r => r.GetItem <SOLineSplit>().InventoryID == inventoryItem.InventoryID;
        }

        SOShipmentPlan item = shipmentEntry.soshipmentplan.Select().Single(lineCriteria);

        item.Selected = true;
        shipmentEntry.soshipmentplan.Cache.Update(item);
        AssertNoErrors(shipmentEntry.soshipmentplan.Cache, item);
        shipmentEntry.Actions["AddSO"].Press();

        var shipLineCurrent = shipmentEntry.Caches[typeof(SOShipLine)].Current as SOShipLine;

        if (shipLineCurrent == null)
        {
            throw new InvalidOperationException("Can't add ShipmentDetail");
        }

        var allocations = targetEntity.Fields.SingleOrDefault(f => string.Equals(f.Name, "Allocations")) as EntityListField;

        if (allocations != null) // clear already allocated lines, to replace them with new
        {
            shipLineCurrent.ShippedQty     = 0;
            shipLineCurrent.BaseShippedQty = 0;
            shipmentEntry.Caches[typeof(SOShipLine)].Update(shipLineCurrent);

            var current = shipmentEntry.splits.Cache.Current as SOShipLineSplit;
            if (current != null)
            {
                shipmentEntry.splits.Cache.Clear();
            }

            var current2 = shipmentEntry.Caches[typeof(SOLineSplit2)].Current as SOLineSplit2;
            if (current2 != null)
            {
                current2.ShippedQty = 0;
                shipmentEntry.Caches[typeof(SOLineSplit2)].Update(current2);
            }
        }
    }
예제 #2
0
        public static void CreateShipment(System.Collections.Generic.List <SOShipmentPlan> list)
        {
            int num1 = 0;

            try
            {
                SOShipmentEntry instance = PXGraph.CreateInstance <SOShipmentEntry>();
                DocumentList <PX.Objects.SO.SOShipment> list1 = new DocumentList <PX.Objects.SO.SOShipment>((PXGraph)instance);
                Dictionary <long, PXResult <SOShipmentPlan, PX.Objects.SO.SOOrder> > dictionary = new Dictionary <long, PXResult <SOShipmentPlan, PX.Objects.SO.SOOrder> >();
                SOShipmentPlan        soShipmentPlan1 = new SOShipmentPlan();
                PX.Objects.SO.SOOrder soOrder         = new PX.Objects.SO.SOOrder();
                for (int index = 0; index < list.Count; ++index)
                {
                    SOShipmentPlan        i0 = list[index];
                    PX.Objects.SO.SOOrder i1 = SelectFrom <PX.Objects.SO.SOOrder> .Where <PX.Objects.SO.SOOrder.orderType.IsEqual <P.AsString>
                                                                                          .And <PX.Objects.SO.SOOrder.orderNbr.IsEqual <P.AsString> > > .View.Select((PXGraph)instance, (object)i0.OrderType, (object)i0.OrderNbr);

                    int?nullable1;
                    int?customerLocationId;
                    int?nullable2;
                    int num2;
                    if (num1 != 0)
                    {
                        int num3 = num1;
                        nullable1          = i1.CustomerID;
                        customerLocationId = i1.CustomerLocationID;
                        nullable2          = nullable1.HasValue & customerLocationId.HasValue ? new int?(nullable1.GetValueOrDefault() + customerLocationId.GetValueOrDefault()) : new int?();
                        int valueOrDefault = nullable2.GetValueOrDefault();
                        num2 = num3 == valueOrDefault & nullable2.HasValue ? 1 : 0;
                    }
                    else
                    {
                        num2 = 1;
                    }
                    if (num2 == 0)
                    {
                        throw new PXException("Please Only Select The Same Customer ID & Location For One Shipment");
                    }
                    nullable2          = i1.CustomerID;
                    customerLocationId = i1.CustomerLocationID;
                    int?nullable3;
                    if (!(nullable2.HasValue & customerLocationId.HasValue))
                    {
                        nullable1 = new int?();
                        nullable3 = nullable1;
                    }
                    else
                    {
                        nullable3 = new int?(nullable2.GetValueOrDefault() + customerLocationId.GetValueOrDefault());
                    }
                    nullable1 = nullable3;
                    num1      = nullable1.Value;
                    dictionary.Add(i0.PlanID.Value, new PXResult <SOShipmentPlan, PX.Objects.SO.SOOrder>(i0, i1));
                }
                PX.Objects.SO.SOOrder order = new PX.Objects.SO.SOOrder();
                foreach (PXResult <SOShipmentPlan, PX.Objects.SO.SOOrder> pxResult in dictionary.Values)
                {
                    SOShipmentPlan soShipmentPlan2 = (SOShipmentPlan)pxResult;
                    if (order.OrderNbr != pxResult.GetItem <PX.Objects.SO.SOOrder>().OrderNbr)
                    {
                        order = (PX.Objects.SO.SOOrder)pxResult;
                        instance.GetExtension <SOShipmentEntry_Extension>().CreateShipment2(order, soShipmentPlan2.SiteID, soShipmentPlan2.PlanDate, new bool?(false), "I", list1, list);
                    }
                }
                throw new PXPopupRedirectException((PXGraph)instance, "Shipment <*> is created", true);
            }
            catch (Exception ex)
            {
                if (ex.Message.Equals("Shipment <*> is created"))
                {
                    PXProcessing.SetProcessed();
                }
                else
                {
                    PXProcessing.SetError(ex);
                }
                throw;
            }
        }
예제 #3
0
 private void SelectLine(SOShipmentEntry shipmentEntry, SOShipmentPlan item)
 {
     item.Selected = true;
     shipmentEntry.soshipmentplan.Cache.Update(item);
     AssertNoErrors(shipmentEntry.soshipmentplan.Cache, item);
 }
예제 #4
0
        protected void ShipmentDetail_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity)
        {
            var shipmentEntry = (SOShipmentEntry)graph;

            var filterCache = shipmentEntry.addsofilter.Cache;
            var filter      = (AddSOFilter)filterCache.Current;

            var orderLineNbrField = targetEntity.Fields.SingleOrDefault(f => f.Name == "OrderLineNbr") as EntityValueField;
            var shippedQtyField   = targetEntity.Fields.SingleOrDefault(f => f.Name == "ShippedQty") as EntityValueField;

            string  orderType    = (targetEntity.Fields.Single(f => f.Name == "OrderType") as EntityValueField).Value;
            string  orderNbr     = (targetEntity.Fields.Single(f => f.Name == "OrderNbr") as EntityValueField).Value;
            int?    orderLineNbr = !string.IsNullOrEmpty(orderLineNbrField?.Value) ? (int?)int.Parse(orderLineNbrField.Value) : null;
            string  inventoryId  = (targetEntity.Fields.SingleOrDefault(f => f.Name == "InventoryID") as EntityValueField)?.Value;
            string  lotSerialNbr = (targetEntity.Fields.SingleOrDefault(f => f.Name == "LotSerialNbr") as EntityValueField)?.Value;
            decimal?shippedQty   = !string.IsNullOrEmpty(shippedQtyField?.Value) ? (decimal?)decimal.Parse(shippedQtyField.Value) : null;

            //setting Add Sales Order filter parameters
            string oldOrderNbr = filter.OrderNbr;

            filter.OrderType = orderType;
            filter.OrderNbr  = orderNbr;
            filterCache.RaiseFieldUpdated <AddSOFilter.orderNbr>(filter, oldOrderNbr);
            filterCache.Update(filter);

            //forming selection criteria
            Func <PXResult <SOShipmentPlan>, bool> lineCriteria;
            SOShipmentPlan item = new SOShipmentPlan();

            if (orderLineNbr != null && orderLineNbr >= 0)
            {
                lineCriteria = r => r.GetItem <SOLineSplit>().LineNbr == orderLineNbr;

                item = FindSalesOrderLine(shipmentEntry, lineCriteria);
            }
            else if (!string.IsNullOrWhiteSpace(inventoryId))
            {
                var inventoryItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> > > > .Select(graph, inventoryId).FirstOrDefault().GetItem <InventoryItem>();

                lineCriteria = r => r.GetItem <SOLineSplit>().InventoryID == inventoryItem.InventoryID;

                if (!string.IsNullOrWhiteSpace(lotSerialNbr))
                {
                    lineCriteria = PX.Common.Func.Conjoin(lineCriteria, t => t.GetItem <SOLineSplit>().LotSerialNbr == lotSerialNbr);
                }
                if (shippedQty != null && shippedQty > 0)
                {
                    lineCriteria = PX.Common.Func.Conjoin(lineCriteria, t => t.GetItem <SOLineSplit>().OpenQty >= shippedQty);
                }

                item = FindSalesOrderLine(shipmentEntry, lineCriteria);
            }

            bool singleOrderLineAdded = false;

            if (item.InventoryID != null)
            {
                SelectLine(shipmentEntry, item);
                singleOrderLineAdded = true;
            }
            else
            {
                //It should be possible to modify this in next endpoint
                if (orderLineNbr != null && orderLineNbr < 0)
                {
                    filter.AddAllLines = true;
                }
                else
                {
                    foreach (SOShipmentPlan row in shipmentEntry.soshipmentplan.Select())
                    {
                        SelectLine(shipmentEntry, row);
                    }
                }
            }

            shipmentEntry.Actions["AddSO"].Press();

            var shipLineCurrent = shipmentEntry.Caches[typeof(SOShipLine)].Current as SOShipLine;

            if (shipLineCurrent == null)
            {
                throw new InvalidOperationException(SO.Messages.CantAddShipmentDetail);
            }

            var allocations = (targetEntity.Fields.SingleOrDefault(f => string.Equals(f.Name, "Allocations")) as EntityListField)?.Value ?? new EntityImpl[0];

            if (allocations.Any(a => a.Fields != null && a.Fields.Length > 0))
            {
                if (!singleOrderLineAdded)
                {
                    throw new InvalidOperationException("Allocations can be specified for unambiguously selected Sales Order line only.");
                }

                // Clear auto-allocated splits in the current line, to replace them with ones specified in allocations.
                PXCache splitsCache = shipmentEntry.splits.Cache;
                foreach (SOShipLineSplit split in splitsCache.Inserted)
                {
                    if (splitsCache.GetStatus(split) != PXEntryStatus.Inserted ||
                        shipLineCurrent.ShipmentNbr != split.ShipmentNbr ||
                        shipLineCurrent.LineNbr != split.LineNbr)
                    {
                        continue;
                    }

                    shipmentEntry.splits.Delete(split);
                }

                shipLineCurrent.ShippedQty = 0m;
                shipmentEntry.Caches[typeof(SOShipLine)].Update(shipLineCurrent);
            }
            else if (shippedQty != null)
            {
                shipLineCurrent.ShippedQty = shippedQty;
                shipmentEntry.Caches[typeof(SOShipLine)].Update(shipLineCurrent);
            }
        }
        protected void ShipmentDetail_Insert(PXGraph graph, EntityImpl entity, EntityImpl targetEntity)
        {
            var shipmentEntry = (SOShipmentEntry)graph;

            var filterCache = shipmentEntry.addsofilter.Cache;
            var filter      = (AddSOFilter)filterCache.Current;

            var orderType    = targetEntity.Fields.Single(f => f.Name == "OrderType") as EntityValueField;
            var orderNbr     = targetEntity.Fields.Single(f => f.Name == "OrderNbr") as EntityValueField;
            var orderLineNbr = targetEntity.Fields.SingleOrDefault(f => f.Name == "OrderLineNbr") as EntityValueField;
            var inventoryId  = targetEntity.Fields.SingleOrDefault(f => f.Name == "InventoryID") as EntityValueField;
            var lotSerialNbr = targetEntity.Fields.SingleOrDefault(f => f.Name == "LotSerialNbr") as EntityValueField;
            var shippedQty   = targetEntity.Fields.SingleOrDefault(f => f.Name == "ShippedQty") as EntityValueField;

            //setting Add Sales Order filter parameters
            string oldOrderNbr = filter.OrderNbr;

            filter.OrderType = orderType.Value;
            filter.OrderNbr  = orderNbr.Value;
            filterCache.RaiseFieldUpdated <AddSOFilter.orderNbr>(filter, oldOrderNbr);
            filterCache.Update(filter);

            //forming selection criteria
            Func <PXResult <SOShipmentPlan>, bool> lineCriteria;
            SOShipmentPlan item = new SOShipmentPlan();

            if (orderLineNbr != null && !string.IsNullOrEmpty(orderLineNbr.Value))
            {
                var nbr = int.Parse(orderLineNbr.Value);
                lineCriteria = r => r.GetItem <SOLineSplit>().LineNbr == nbr;

                item = FindSalesOrderLine(shipmentEntry, lineCriteria);
            }
            else if (inventoryId != null && !string.IsNullOrWhiteSpace(inventoryId.Value))
            {
                var inventoryItem = PXSelect <InventoryItem, Where <InventoryItem.inventoryCD, Equal <Required <InventoryItem.inventoryCD> > > > .Select(graph, inventoryId.Value).FirstOrDefault().GetItem <InventoryItem>();

                lineCriteria = r => r.GetItem <SOLineSplit>().InventoryID == inventoryItem.InventoryID;

                if (lotSerialNbr != null && !string.IsNullOrWhiteSpace(lotSerialNbr.Value))
                {
                    lineCriteria = PX.Common.Func.Conjoin <PXResult <SOShipmentPlan>, bool>(lineCriteria, t => t.GetItem <SOLineSplit>().LotSerialNbr == lotSerialNbr.Value);
                }
                if (shippedQty != null && shippedQty.Value != null && decimal.Parse(shippedQty.Value) > 0)
                {
                    lineCriteria = PX.Common.Func.Conjoin <PXResult <SOShipmentPlan>, bool>(lineCriteria, t => t.GetItem <SOLineSplit>().OpenQty >= decimal.Parse(shippedQty.Value));
                }

                item = FindSalesOrderLine(shipmentEntry, lineCriteria);
            }

            if (item.InventoryID != null)
            {
                SelectLine(shipmentEntry, item);
            }
            else
            {
                foreach (SOShipmentPlan row in shipmentEntry.soshipmentplan.Select())
                {
                    SelectLine(shipmentEntry, row);
                }
            }

            shipmentEntry.Actions["AddSO"].Press();

            var shipLineCurrent = shipmentEntry.Caches[typeof(SOShipLine)].Current as SOShipLine;

            if (shipLineCurrent == null)
            {
                throw new InvalidOperationException(SO.Messages.CantAddShipmentDetail);
            }

            var allocations = (targetEntity.Fields.SingleOrDefault(f => string.Equals(f.Name, "Allocations")) as EntityListField)?.Value ?? new EntityImpl[0];

            if (allocations.Any(a => a.Fields != null && a.Fields.Length > 0))
            {
                // clear already allocated lines, to replace them with new
                shipLineCurrent.ShippedQty     = 0;
                shipLineCurrent.BaseShippedQty = 0;
                shipmentEntry.Caches[typeof(SOShipLine)].Update(shipLineCurrent);

                var current = shipmentEntry.splits.Cache.Current as SOShipLineSplit;
                if (current != null)
                {
                    var inserted = shipmentEntry.splits.Cache.Inserted;
                    foreach (SOShipLineSplit split in inserted)
                    {
                        if (split.LineNbr == shipLineCurrent.LineNbr)
                        {
                            shipmentEntry.splits.Cache.SetStatus(split, PXEntryStatus.InsertedDeleted);
                        }
                    }
                }

                var current2 = shipmentEntry.Caches[typeof(SOLineSplit2)].Current as SOLineSplit2;
                if (current2 != null)
                {
                    current2.ShippedQty = 0;
                    shipmentEntry.Caches[typeof(SOLineSplit2)].Update(current2);
                }
            }
        }