Exemplo n.º 1
0
        public void SOSetup_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            SOSetup setup = e.Row as SOSetup;

            if (setup == null)
            {
                return;
            }

            PXUIFieldAttribute.SetEnabled <SOSetup.createZeroShipments>(sender, null, setup.AddAllToShipment == true);
        }
        /// <summary>
        /// Calculates Sales Price.
        /// </summary>
        /// <param name="sender">Cache</param>
        /// <param name="inventoryID">Inventory</param>
        /// <param name="curyID">Currency</param>
        /// <param name="UOM">Unit of measure</param>
        /// <param name="date">Date</param>
        /// <returns>Sales Price.</returns>
        /// <remarks>AlwaysFromBaseCury flag in the SOSetup is considered when performing the calculation.</remarks>
        public static decimal?CalculateSalesPrice(PXCache sender, int inventoryID, string curyID, string UOM, DateTime date)
        {
            bool alwaysFromBase = false;

            SOSetup sosetup = PXSelectReadonly <SOSetup> .Select(sender.Graph);

            if (sosetup != null)
            {
                alwaysFromBase = sosetup.AlwaysFromBaseCury == true;
            }

            return(SOSalesPriceEntry.CalculateSalesPrice(sender, inventoryID, curyID, UOM, date, alwaysFromBase));
        }
Exemplo n.º 3
0
        protected virtual void SOSetup_DefaultOrderType_FieldDefaulting(PXCache sender, PXFieldDefaultingEventArgs e)
        {
            SOSetup setup = e.Row as SOSetup;

            if (setup == null)
            {
                return;
            }

            if (!PXAccess.FeatureInstalled <FeaturesSet.inventory>())
            {
                e.NewValue = SOOrderTypeConstants.Invoice;
            }
        }
Exemplo n.º 4
0
        public void SOSetup_RowPersisting(PXCache sender, PXRowPersistingEventArgs e)
        {
            SOSetup setup = e.Row as SOSetup;

            if (setup == null)
            {
                return;
            }

            if (setup.UseShippedNotInvoiced == true && setup.ShippedNotInvoicedAcctID == null)
            {
                throw new PXRowPersistingException(typeof(SOSetup.shippedNotInvoicedAcctID).Name, null, ErrorMessages.FieldIsEmpty, typeof(SOSetup.shippedNotInvoicedAcctID).Name);
            }
            if (setup.UseShippedNotInvoiced == true && setup.ShippedNotInvoicedSubID == null && PXAccess.FeatureInstalled <FeaturesSet.subAccount>())
            {
                throw new PXRowPersistingException(typeof(SOSetup.shippedNotInvoicedSubID).Name, null, ErrorMessages.FieldIsEmpty, typeof(SOSetup.shippedNotInvoicedSubID).Name);
            }
        }
        //TODO:refactor
        public static void SOCreateProc(List <SOFixedDemand> list, DateTime?PurchDate)
        {
            SOOrderEntry           docgraph = PXGraph.CreateInstance <SOOrderEntry>();
            SOSetup                sosetup  = docgraph.sosetup.Current;
            DocumentList <SOOrder> created  = new DocumentList <SOOrder>(docgraph);

            docgraph.ExceptionHandling.AddHandler <SOLineSplit.qty>((cache, e) => { e.Cancel = true; });
            docgraph.ExceptionHandling.AddHandler <SOLineSplit.isAllocated>((cache, e) => { ((SOLineSplit)e.Row).IsAllocated = true; e.Cancel = true; });

            foreach (SOFixedDemand demand in list)
            {
                string OrderType =
                    sosetup.TransferOrderType ?? SOOrderTypeConstants.TransferOrder;

                string demandPlanType = demand.PlanType;

                try
                {
                    if (demand.SourceSiteID == null)
                    {
                        PXProcessing <SOFixedDemand> .SetWarning(list.IndexOf(demand), Messages.MissingSourceSite);

                        continue;
                    }

                    SOOrder      order;
                    SOLineSplit2 sosplit = PXSelect <SOLineSplit2, Where <SOLineSplit2.planID, Equal <Required <SOLineSplit2.planID> > > > .Select(docgraph, demand.PlanID);

                    if (sosplit != null)
                    {
                        order = created.Find <SOOrder.orderType, SOOrder.destinationSiteID, SOOrder.defaultSiteID>(OrderType, sosplit.ToSiteID, sosplit.SiteID);
                    }
                    else
                    {
                        if (demand.SourceSiteID == demand.SiteID)
                        {
                            PXProcessing <SOFixedDemand> .SetWarning(list.IndexOf(demand), Messages.EqualSourceDestinationSite);

                            continue;
                        }

                        order = created.Find <SOOrder.orderType, SOOrder.destinationSiteID, SOOrder.defaultSiteID>(OrderType, demand.SiteID, demand.SourceSiteID);
                    }

                    if (order == null)
                    {
                        order = new SOOrder();
                    }

                    if (order.OrderNbr == null)
                    {
                        docgraph.Clear();

                        if (sosplit != null)
                        {
                            INSite sourceSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(docgraph, sosplit.SiteID);

                            order.BranchID  = sourceSite.BranchID;
                            order.OrderType = OrderType;
                            order           = PXCache <SOOrder> .CreateCopy(docgraph.Document.Insert(order));

                            order.DefaultSiteID     = sosplit.SiteID;
                            order.DestinationSiteID = sosplit.ToSiteID;
                            order.OrderDate         = PurchDate;

                            docgraph.Document.Update(order);
                        }
                        else
                        {
                            INSite sourceSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(docgraph, demand.SourceSiteID);

                            order.BranchID  = sourceSite.BranchID;
                            order.OrderType = OrderType;
                            order           = PXCache <SOOrder> .CreateCopy(docgraph.Document.Insert(order));

                            order.DefaultSiteID     = demand.SourceSiteID;
                            order.DestinationSiteID = demand.SiteID;
                            order.OrderDate         = PurchDate;

                            docgraph.Document.Update(order);
                        }
                    }
                    else if (docgraph.Document.Cache.ObjectsEqual(docgraph.Document.Current, order) == false)
                    {
                        docgraph.Document.Current = docgraph.Document.Search <SOOrder.orderNbr>(order.OrderNbr, order.OrderType);
                    }

                    SOLine      newline;
                    SOLineSplit newsplit;
                    PXCache     cache = docgraph.Caches[typeof(INItemPlan)];
                    INItemPlan  rp;

                    if (sosplit != null)
                    {
                        docgraph.Transactions.Current = newline = docgraph.Transactions.Search <SOLine.inventoryID, SOLine.subItemID, SOLine.siteID, SOLine.pOCreate>(demand.InventoryID, demand.SubItemID, demand.SiteID, false);
                        if (newline == null)
                        {
                            newline = PXCache <SOLine> .CreateCopy(docgraph.Transactions.Insert());

                            newline.InventoryID = demand.InventoryID;
                            newline.SubItemID   = demand.SubItemID;
                            newline.SiteID      = demand.SiteID;
                            newline.UOM         = demand.UOM;
                            newline.OrderQty    = 0m;

                            newline = docgraph.Transactions.Update(newline);
                        }

                        newsplit = new SOLineSplit();
                        newsplit.LotSerialNbr = sosplit.LotSerialNbr;
                        newsplit.IsAllocated  = true;
                        newsplit.IsMergeable  = false;
                        newsplit.SiteID       = demand.SiteID; //SiteID should be explicitly set because of PXFormula
                        newsplit.Qty          = demand.OrderQty;
                        newsplit.RefNoteID    = demand.RefNoteID;

                        //we have to delete previous allocation and reinsert it after the newsplit for transfer-order allocation to work properly
                        rp = PXCache <INItemPlan> .CreateCopy(demand);

                        cache.RaiseRowDeleted(demand);

                        newsplit = docgraph.splits.Insert(newsplit);

                        sosplit.SOOrderType    = newsplit.OrderType;
                        sosplit.SOOrderNbr     = newsplit.OrderNbr;
                        sosplit.SOLineNbr      = newsplit.LineNbr;
                        sosplit.SOSplitLineNbr = newsplit.SplitLineNbr;
                        docgraph.sodemand.Update(sosplit);

                        rp.SiteID       = sosplit.ToSiteID;
                        rp.PlanType     = INPlanConstants.Plan93;
                        rp.FixedSource  = null;
                        rp.SupplyPlanID = newsplit.PlanID;
                        cache.RaiseRowInserted(rp);
                        cache.SetStatus(rp, PXEntryStatus.Updated);
                    }
                    else
                    {
                        docgraph.Transactions.Current = newline = docgraph.Transactions.Search <SOLine.inventoryID, SOLine.subItemID, SOLine.siteID, SOLine.pOCreate>(demand.InventoryID, demand.SubItemID, demand.SourceSiteID, demand.VendorID != null);
                        if (newline == null)
                        {
                            newline = PXCache <SOLine> .CreateCopy(docgraph.Transactions.Insert());

                            newline.InventoryID = demand.InventoryID;
                            newline.SubItemID   = demand.SubItemID;
                            newline.SiteID      = demand.SourceSiteID;
                            newline.UOM         = demand.UOM;
                            newline.OrderQty    = 0m;
                            //newline.POCreate = (demand.VendorID != null);
                            newline.POCreate = (demand.FixedSource == INReplenishmentSource.TransferToPurchase);
                            newline.VendorID = demand.VendorID;
                            //newline.VendorLocationID = demand.VendorLocationID;

                            newline = docgraph.Transactions.Update(newline);
                        }

                        newsplit             = new SOLineSplit();
                        newsplit.IsAllocated = false;
                        newsplit.Qty         = demand.OrderQty;
                        //newsplit.POCreate = (demand.VendorID != null);
                        newsplit.POCreate = (demand.FixedSource == INReplenishmentSource.TransferToPurchase);
                        newsplit.VendorID = demand.VendorID;
                        //newsplit.VendorLocationID = demand.VendorLocationID;
                        newsplit = docgraph.splits.Insert(newsplit) ?? docgraph.splits.Current;

                        rp = PXCache <INItemPlan> .CreateCopy(demand);

                        cache.RaiseRowDeleted(demand);
                        rp.SiteID       = demand.SiteID;
                        rp.PlanType     = INPlanConstants.Plan94;
                        rp.FixedSource  = null;
                        rp.SupplyPlanID = newsplit.PlanID;
                        cache.RaiseRowInserted(rp);
                        cache.SetStatus(rp, PXEntryStatus.Updated);
                    }

                    if (newsplit.PlanID == null)
                    {
                        throw new PXRowPersistedException(typeof(SOLine).Name, newline, RQ.Messages.UnableToCreateSOOrders);
                    }

                    if (docgraph.Transactions.Cache.IsInsertedUpdatedDeleted)
                    {
                        using (PXTransactionScope scope = new PXTransactionScope())
                        {
                            docgraph.Save.Press();
                            if (demandPlanType == INPlanConstants.Plan90)
                            {
                                docgraph.Replenihment.Current = docgraph.Replenihment.Search <INReplenishmentOrder.noteID>(demand.RefNoteID);
                                if (docgraph.Replenihment.Current != null)
                                {
                                    INReplenishmentLine rLine =
                                        PXCache <INReplenishmentLine> .CreateCopy(docgraph.ReplenishmentLines.Insert(new INReplenishmentLine()));

                                    rLine.InventoryID       = newsplit.InventoryID;
                                    rLine.SubItemID         = newsplit.SubItemID;
                                    rLine.UOM               = newsplit.UOM;
                                    rLine.Qty               = newsplit.Qty;
                                    rLine.SOType            = newsplit.OrderType;
                                    rLine.SONbr             = docgraph.Document.Current.OrderNbr;
                                    rLine.SOLineNbr         = newsplit.LineNbr;
                                    rLine.SOSplitLineNbr    = newsplit.SplitLineNbr;
                                    rLine.SiteID            = demand.SourceSiteID;
                                    rLine.DestinationSiteID = demand.SiteID;
                                    rLine.PlanID            = demand.PlanID;
                                    docgraph.ReplenishmentLines.Update(rLine);
                                    INItemPlan plan = PXSelect <INItemPlan,
                                                                Where <INItemPlan.planID, Equal <Required <INItemPlan.planID> > > > .SelectWindowed(docgraph, 0, 1,
                                                                                                                                                    demand.SupplyPlanID);

                                    if (plan != null)
                                    {
                                        //plan.SupplyPlanID = rp.PlanID;
                                        rp.SupplyPlanID = plan.PlanID;
                                        cache.SetStatus(rp, PXEntryStatus.Updated);
                                    }

                                    docgraph.Save.Press();
                                }
                            }
                            scope.Complete();
                        }

                        PXProcessing <SOFixedDemand> .SetInfo(list.IndexOf(demand), PXMessages.LocalizeFormatNoPrefixNLA(Messages.TransferOrderCreated, docgraph.Document.Current.OrderNbr));

                        if (created.Find(docgraph.Document.Current) == null)
                        {
                            created.Add(docgraph.Document.Current);
                        }
                    }
                }
                catch (Exception e)
                {
                    PXProcessing <SOFixedDemand> .SetError(list.IndexOf(demand), e);
                }
            }
            if (created.Count == 1)
            {
                using (new PXTimeStampScope(null))
                {
                    docgraph.Clear();
                    docgraph.Document.Current = docgraph.Document.Search <POOrder.orderNbr>(created[0].OrderNbr, created[0].OrderType);
                    throw new PXRedirectRequiredException(docgraph, Messages.SOOrder);
                }
            }
        }
Exemplo n.º 6
0
        public static void SOCreateProc(List <SOFixedDemand> list, DateTime?PurchDate)
        {
            SOOrderEntry           docgraph = PXGraph.CreateInstance <SOOrderEntry>();
            SOSetup                sosetup  = docgraph.sosetup.Current;
            DocumentList <SOOrder> created  = new DocumentList <SOOrder>(docgraph);

            foreach (SOFixedDemand demand in list)
            {
                string OrderType =
                    sosetup.TransferOrderType ?? SOOrderTypeConstants.TransferOrder;

                string ErrorText = string.Empty;

                try
                {
                    if (demand.ReplenishmentSourceSiteID == null)
                    {
                        PXProcessing <SOFixedDemand> .SetWarning(list.IndexOf(demand), Messages.MissingSourceSite);

                        continue;
                    }

                    if (demand.ReplenishmentSourceSiteID == demand.SiteID)
                    {
                        PXProcessing <SOFixedDemand> .SetWarning(list.IndexOf(demand), Messages.EqualSourceDestinationSite);

                        continue;
                    }
                    SOOrder order;
                    POLine  poline = PXSelect <POLine, Where <POLine.planID, Equal <Required <POLine.planID> > > > .Select(docgraph, demand.PlanID);

                    if (poline != null)
                    {
                        order =
                            created.Find <SOOrder.orderType, SOOrder.destinationSiteID, SOOrder.defaultSiteID, SOOrder.origPOType, SOOrder.origPONbr>(
                                OrderType, demand.SiteID, demand.ReplenishmentSourceSiteID, poline.OrderType, poline.OrderNbr);
                    }
                    else
                    {
                        order = created.Find <SOOrder.orderType, SOOrder.destinationSiteID, SOOrder.defaultSiteID>(OrderType, demand.SiteID, demand.ReplenishmentSourceSiteID);
                    }

                    if (order == null)
                    {
                        order = new SOOrder();
                    }

                    if (order.OrderNbr == null)
                    {
                        docgraph.Clear();

                        INSite sourceSite = PXSelect <INSite, Where <INSite.siteID, Equal <Required <INSite.siteID> > > > .Select(docgraph, demand.ReplenishmentSourceSiteID);

                        order.BranchID  = sourceSite.BranchID;
                        order.OrderType = OrderType;
                        order           = PXCache <SOOrder> .CreateCopy(docgraph.Document.Insert(order));

                        order.DefaultSiteID     = demand.ReplenishmentSourceSiteID;
                        order.DestinationSiteID = demand.SiteID;
                        order.Status            = SOOrderStatus.Open;
                        order.OrderDate         = PurchDate;
                        if (poline != null)
                        {
                            order.OrigPOType = poline.OrderType;
                            order.OrigPONbr  = poline.OrderNbr;
                        }
                        docgraph.Document.Update(order);
                    }
                    else if (docgraph.Document.Cache.ObjectsEqual(docgraph.Document.Current, order) == false)
                    {
                        docgraph.Document.Current = docgraph.Document.Search <SOOrder.orderNbr>(order.OrderNbr, order.OrderType);
                    }
                    SOLine line = new SOLine();
                    line = PXCache <SOLine> .CreateCopy(docgraph.Transactions.Insert(line));

                    line.InventoryID = demand.InventoryID;
                    line.SubItemID   = demand.SubItemID;
                    line.SiteID      = demand.ReplenishmentSourceSiteID;
                    line.UOM         = demand.UOM;
                    line.OrderQty    = demand.OrderQty;
                    if (poline != null)
                    {
                        line.OrigPOType    = poline.OrderType;
                        line.OrigPONbr     = poline.OrderNbr;
                        line.OrigPOLineNbr = poline.LineNbr;
                    }

                    line = docgraph.Transactions.Update(line);

                    if (line.PlanID == null)
                    {
                        throw new PXRowPersistedException(typeof(SOLine).Name, line, RQ.Messages.UnableToCreateSOOrders);
                    }

                    PXCache cache          = docgraph.Caches[typeof(INItemPlan)];
                    string  demandPlanType = demand.PlanType;
                    //cache.SetStatus(demand, PXEntryStatus.Updated);
                    //demand.SupplyPlanID = line.PlanID;
                    INItemPlan rp = PXCache <INItemPlan> .CreateCopy(demand);

                    cache.RaiseRowDeleted(demand);
                    rp.PlanType     = INPlanConstants.Plan94;
                    rp.FixedSource  = null;
                    rp.SupplyPlanID = line.PlanID;
                    cache.RaiseRowInserted(rp);
                    cache.SetStatus(rp, PXEntryStatus.Updated);

                    if (docgraph.Transactions.Cache.IsInsertedUpdatedDeleted)
                    {
                        using (PXTransactionScope scope = new PXTransactionScope())
                        {
                            docgraph.Save.Press();
                            if (demandPlanType == INPlanConstants.Plan90)
                            {
                                docgraph.Replenihment.Current = docgraph.Replenihment.Search <INReplenishmentOrder.noteID>(demand.RefNoteID);
                                if (docgraph.Replenihment.Current != null)
                                {
                                    INReplenishmentLine rLine =
                                        PXCache <INReplenishmentLine> .CreateCopy(docgraph.ReplenishmentLines.Insert(new INReplenishmentLine()));

                                    rLine.InventoryID       = line.InventoryID;
                                    rLine.SubItemID         = line.SubItemID;
                                    rLine.UOM               = line.UOM;
                                    rLine.Qty               = line.OrderQty;
                                    rLine.SOType            = line.OrderType;
                                    rLine.SONbr             = docgraph.Document.Current.OrderNbr;
                                    rLine.SOLineNbr         = line.LineNbr;
                                    rLine.SiteID            = demand.ReplenishmentSourceSiteID;
                                    rLine.DestinationSiteID = demand.SiteID;
                                    rLine.PlanID            = demand.PlanID;
                                    docgraph.ReplenishmentLines.Update(rLine);
                                    INItemPlan plan = PXSelect <INItemPlan,
                                                                Where <INItemPlan.planID, Equal <Required <INItemPlan.planID> > > > .SelectWindowed(docgraph, 0, 1,
                                                                                                                                                    demand.SupplyPlanID);

                                    if (plan != null)
                                    {
                                        //plan.SupplyPlanID = rp.PlanID;
                                        rp.SupplyPlanID = plan.PlanID;
                                        cache.SetStatus(rp, PXEntryStatus.Updated);
                                    }

                                    docgraph.Save.Press();
                                }
                            }
                            scope.Complete();
                        }

                        PXProcessing <SOFixedDemand> .SetInfo(list.IndexOf(demand), string.Format(Messages.TransferOrderCreated, docgraph.Document.Current.OrderNbr) + "\r\n" + ErrorText);


                        if (created.Find(docgraph.Document.Current) == null)
                        {
                            created.Add(docgraph.Document.Current);
                        }
                    }
                }
                catch (Exception e)
                {
                    PXProcessing <SOFixedDemand> .SetError(list.IndexOf(demand), e);
                }
            }
        }