예제 #1
0
        public CRCaseReleaseProcess()
        {
            Items.SetSelected <CRCase.selected>();

            PXProcessingStep[] targets = PXAutomation.GetProcessingSteps(this);
            if (targets.Length > 0)
            {
                Items.SetProcessTarget(targets[0].GraphName,
                                       targets.Length > 1 ? null : targets[0].Name,
                                       targets[0].Actions[0].Name,
                                       targets[0].Actions[0].Menus[0],
                                       null, null);
            }
            else
            {
                throw new PXException(SO.Messages.MissingMassProcessWorkFlow);
            }

            PXUIFieldAttribute.SetVisible(Items.Cache, null, false);
            PXUIFieldAttribute.SetVisible <CRCase.caseCD>(Items.Cache, null);
            PXUIFieldAttribute.SetVisible <CRCase.subject>(Items.Cache, null);
            PXUIFieldAttribute.SetVisible <CRCase.contractID>(Items.Cache, null);
            PXUIFieldAttribute.SetVisible <CRCase.timeBillable>(Items.Cache, null);
            PXUIFieldAttribute.SetVisible <CRCase.overtimeBillable>(Items.Cache, null);

            var BAccountCache = Caches[typeof(Customer)];

            PXUIFieldAttribute.SetVisible(BAccountCache, null, false);
            PXUIFieldAttribute.SetDisplayName <Customer.acctName>(BAccountCache, Messages.BAccountName);
            PXUIFieldAttribute.SetDisplayName <Customer.classID>(BAccountCache, Messages.BAccountClass);

            Actions.Move("Process", "Cancel");
        }
예제 #2
0
        // TODO: rework on Workflow implementation
        internal static void RunActionWithAppliedAutomation(PXGraph graph, object entity, string menu)
        {
            graph.Views[graph.PrimaryView].Cache.Current = entity;

            List <object> searches = new List <object>();
            List <string> sorts    = new List <string>();

            foreach (string key in graph.Views[graph.PrimaryView].Cache.Keys)
            {
                searches.Add(graph.Views[graph.PrimaryView].Cache.GetValue(entity, key));
                sorts.Add(key);
            }

            PXAdapter a = new PXAdapter(graph.Views[graph.PrimaryView])
            {
                StartRow    = 0,
                MaximumRows = 1,
                Searches    = searches.ToArray(),
                Menu        = menu,
                SortColumns = sorts.ToArray()
            };

            if (graph.Actions.Contains("Action"))
            {
                // set automation step before running automation action. Workflow should work the same way
                PXAutomation.GetStep(graph, new List <object> {
                    entity
                }, a.View.BqlSelect);

                foreach (var c in graph.Actions["Action"].Press(a))
                {
                }
            }
        }
        public void SplitFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            SplitFilter filter = (SplitFilter)e.Row;

            if (filter == null)
            {
                return;
            }

            PXProcessingStep[] targets = PXAutomation.GetProcessingSteps(this);
            if (targets.Length > 0)
            {
                Splits.SetProcessTarget(targets[0].GraphName,
                                        targets.Length > 1 ? null : targets[0].Name,
                                        targets[0].Actions[0].Name,
                                        targets[0].Actions[0].Menus[0],
                                        filter.SplitDate,
                                        filter.SplitPeriodID,
                                        null, null, null, null, null,
                                        filter.DeprBeforeSplit,
                                        null,
                                        filter.AssetID);
            }
            else
            {
                throw new PXException(SO.Messages.MissingMassProcessWorkFlow);
            }

            Splits.SetProcessVisible(false);
            Splits.SetProcessAllEnabled(filter.AssetID != null && filter.SplitPeriodID != null);
            Splits.SetProcessAllCaption(Messages.Split);

            Splits.Cache.AllowInsert = filter.AssetID != null;
            Splits.Cache.AllowUpdate = filter.AssetID != null;
            Splits.Cache.AllowDelete = true;

            PXUIFieldAttribute.SetEnabled <SplitParams.cost>(Splits.Cache, null, true);
            PXUIFieldAttribute.SetEnabled <SplitParams.splittedQty>(Splits.Cache, null, true);
            PXUIFieldAttribute.SetEnabled <SplitParams.ratio>(Splits.Cache, null, true);
            Numbering nbr = assetNumbering.Select();

            PXUIFieldAttribute.SetEnabled <SplitParams.splittedAssetCD>(Splits.Cache, null, nbr == null || nbr.UserNumbering == true);

            PXUIFieldAttribute.SetEnabled <SplitFilter.deprBeforeSplit>(sender, filter, fasetup.Current.AutoReleaseDepr == true);

            FixedAsset asset = PXSelect <FixedAsset, Where <FixedAsset.assetID, Equal <Required <SplitFilter.assetID> > > > .Select(this, filter.AssetID);

            PXUIFieldAttribute.SetVisible <SplitFilter.deprBeforeSplit>(sender, filter, asset == null || asset.Depreciable == true);
        }
        private void InitializeProcessing()
        {
            FilteredItems.SetSelected <EMailAccount.selected>();

            PXProcessingStep[] targets = PXAutomation.GetProcessingSteps(this);
            if (targets.Length > 0)
            {
                FilteredItems.SetProcessTarget(targets[0].GraphName,
                                               targets.Length > 1 ? null : targets[0].Name,
                                               targets[0].Actions[0].Name,
                                               targets[0].Actions[0].Menus[0],
                                               null, null);
            }
            else
            {
                throw new PXException(PX.Objects.SO.Messages.MissingMassProcessWorkFlow);
            }
        }
예제 #5
0
        public virtual void SOPostShipmentFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            SOPostShipmentFilter filter = e.Row as SOPostShipmentFilter;

            PXProcessingStep[] targets = PXAutomation.GetProcessingSteps(this);
            if (targets.Length > 0)
            {
                Dictionary <string, object> parameters = Filter.Cache.ToDictionary(filter);
                Orders.SetProcessTarget(targets[0].GraphName, targets[0].Name, targets[0].Actions[0].Name, targets[0].Actions[0].Menus[0], null, parameters);
            }
            else
            {
                Orders.SetProcessDelegate(delegate(List <SOOrder> list)
                {
                    PostOrder(filter, list);
                });
            }
        }
        public MergePrepareProcess()
        {
            Items.SetProcessCaption(Messages.Prepare);
            Items.SetProcessAllCaption(Messages.PrepareAll);
            Items.SetSelected <CRMerge.selected>();

            PXProcessingStep[] targets = PXAutomation.GetProcessingSteps(this);
            if (targets.Length > 0)
            {
                Items.SetProcessTarget(targets[0].GraphName,
                                       targets.Length > 1 ? null : targets[0].Name,
                                       targets[0].Actions[0].Name,
                                       targets[0].Actions[0].Menus[0],
                                       null, null);
            }
            else
            {
                throw new PXScreenMisconfigurationException(SO.Messages.MissingMassProcessWorkFlow);
            }

            Actions.Move("Process", "Cancel");
        }
예제 #7
0
        protected virtual void DisposalFilter_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
        {
            DisposalFilter filter = (DisposalFilter)e.Row;

            if (filter == null)
            {
                return;
            }

            Assets.SetProcessEnabled(filter.DisposalMethodID != null);
            Assets.SetProcessAllEnabled(filter.DisposalMethodID != null);
            PXProcessingStep[] targets = PXAutomation.GetProcessingSteps(this);
            if (targets.Length > 0)
            {
                Assets.SetProcessTarget(targets[0].GraphName,
                                        targets.Length > 1 ? null : targets[0].Name,
                                        targets[0].Actions[0].Name,
                                        targets[0].Actions[0].Menus[0],
                                        filter.DisposalDate,
                                        filter.DisposalPeriodID,
                                        filter.DisposalAmt,
                                        filter.DisposalMethodID,
                                        filter.DisposalAccountID,
                                        filter.DisposalSubID,
                                        filter.DisposalAmtMode,
                                        filter.DeprBeforeDisposal,
                                        filter.Reason);
            }
            else
            {
                throw new PXException(SO.Messages.MissingMassProcessWorkFlow);
            }

            PXUIFieldAttribute.SetEnabled <DisposalFilter.disposalAmt>(sender, e.Row, filter.DisposalAmtMode == DisposalFilter.disposalAmtMode.Automatic);
            PXUIFieldAttribute.SetEnabled <FixedAsset.disposalAmt>(Assets.Cache, null, Filter.Current.DisposalAmtMode == DisposalFilter.disposalAmtMode.Manual);
        }
        protected static void Approve(List <EPOwned> items, bool approve)
        {
            EntityHelper helper = new EntityHelper(new PXGraph());
            var          graphs = new Dictionary <Type, PXGraph>();

            bool errorOccured = false;

            foreach (EPOwned item in items)
            {
                try
                {
                    PXProcessing <EPApproval> .SetCurrentItem(item);

                    if (item.RefNoteID == null)
                    {
                        throw new PXException(Messages.ApprovalRefNoteIDNull);
                    }
                    object row = helper.GetEntityRow(item.RefNoteID.Value, true);

                    if (row == null)
                    {
                        throw new PXException(Messages.ApprovalRecordNotFound);
                    }

                    Type    cahceType = row.GetType();
                    Type    graphType = helper.GetPrimaryGraphType(row, false);
                    PXGraph graph;
                    if (!graphs.TryGetValue(graphType, out graph))
                    {
                        graphs.Add(graphType, graph = PXGraph.CreateInstance(graphType));
                    }

                    EPApproval approval = PXSelectReadonly <EPApproval,
                                                            Where <EPApproval.approvalID, Equal <Current <EPOwned.approvalID> > > >
                                          .SelectSingleBound(graph, new object[] { item });

                    if (approval.Status == EPApprovalStatus.Pending)
                    {
                        graph.Clear();
                        graph.Caches[cahceType].Current = row;
                        graph.Caches[cahceType].SetStatus(row, PXEntryStatus.Notchanged);
                        PXAutomation.GetView(graph);
                        string approved = typeof(EPExpenseClaim.approved).Name;
                        if (graph.AutomationView != null)
                        {
                            PXAutomation.GetStep(graph,
                                                 new object[] { graph.Views[graph.AutomationView].Cache.Current },
                                                 BqlCommand.CreateInstance(
                                                     typeof(Select <>),
                                                     graph.Views[graph.AutomationView].Cache.GetItemType())
                                                 );
                        }
                        string actionName = approve ? nameof(Approve) : nameof(Reject);
                        if (graph.Actions.Contains(actionName))
                        {
                            graph.Actions[actionName].Press();
                        }
                        else if (graph.AutomationView != null)
                        {
                            PXView     view    = graph.Views[graph.AutomationView];
                            BqlCommand select  = view.BqlSelect;
                            PXAdapter  adapter = new PXAdapter(new PXView.Dummy(graph, select, new List <object> {
                                row
                            }));
                            adapter.Menu = actionName;
                            if (graph.Actions.Contains("Action"))
                            {
                                if (!CheckRights(graphType, cahceType))
                                {
                                    throw new PXException(Messages.DontHaveAppoveRights);
                                }
                                foreach (var i in graph.Actions["Action"].Press(adapter))
                                {
                                    ;
                                }
                            }
                            else
                            {
                                throw new PXException(PXMessages.LocalizeFormatNoPrefixNLA(Messages.AutomationNotConfigured, graph));
                            }
                            //PXAutomation.ApplyAction(graph, graph.Actions["Action"], "Approve", row, out rollback);
                        }
                        else if (graph.Caches[cahceType].Fields.Contains(approved))
                        {
                            object upd = graph.Caches[cahceType].CreateCopy(row);
                            graph.Caches[cahceType].SetValue(upd, approved, true);
                            graph.Caches[cahceType].Update(upd);
                        }
                        graph.Persist();
                    }
                    PXProcessing <EPApproval> .SetInfo(ActionsMessages.RecordProcessed);
                }
                catch (Exception ex)
                {
                    errorOccured = true;
                    PXProcessing <EPApproval> .SetError(ex);
                }
            }
            if (errorOccured)
            {
                throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
            }
        }
예제 #9
0
        protected static void Approve(List <EPOwned> items)
        {
            EntityHelper helper = new EntityHelper(new PXGraph());
            var          graphs = new Dictionary <Type, PXGraph>();

            bool errorOccured = false;

            foreach (EPOwned item in items)
            {
                try
                {
                    PXProcessing <EPApproval> .SetCurrentItem(item);

                    if (item.RefNoteID == null)
                    {
                        throw new PXException(Messages.ApprovalRefNoteIDNull);
                    }
                    object row = helper.GetEntityRow(item.RefNoteID.Value, true);

                    if (row == null)
                    {
                        throw new PXException(Messages.ApprovalRecordNotFound);
                    }

                    Type    cahceType = row.GetType();
                    Type    graphType = helper.GetPrimaryGraphType(row, false);
                    PXGraph graph;
                    if (!graphs.TryGetValue(graphType, out graph))
                    {
                        graphs.Add(graphType, graph = PXGraph.CreateInstance(graphType));
                    }
                    graph.Clear();
                    graph.Caches[cahceType].Current = row;
                    graph.Caches[cahceType].SetStatus(row, PXEntryStatus.Notchanged);
                    PXAutomation.GetView(graph);
                    string approved = typeof(EPExpenseClaim.approved).Name;
                    if (graph.AutomationView != null)
                    {
                        PXAutomation.GetStep(graph,
                                             new object[] { graph.Views[graph.AutomationView].Cache.Current },
                                             BqlCommand.CreateInstance(
                                                 typeof(Select <>),
                                                 graph.Views[graph.AutomationView].Cache.GetItemType())
                                             );
                    }

                    if (graph.Actions.Contains("Approve"))
                    {
                        graph.Actions["Approve"].Press();
                    }
                    else if (graph.AutomationView != null)
                    {
                        PXView     view    = graph.Views[graph.AutomationView];
                        BqlCommand select  = view.BqlSelect;
                        PXAdapter  adapter = new PXAdapter(new DummyView(graph, select, new List <object> {
                            row
                        }));
                        adapter.Menu = "Approve";
                        if (graph.Actions.Contains("Action"))
                        {
                            if (!CheckRights(graphType, cahceType))
                            {
                                throw new PXException(Messages.DontHaveAppoveRights);
                            }
                            foreach (var i in graph.Actions["Action"].Press(adapter))
                            {
                                ;
                            }
                        }
                        else
                        {
                            throw new PXException("Automation for screen/graph {0} exists but is not configured properly. Failed to find action - 'Action'", graph);
                        }
                        //PXAutomation.ApplyAction(graph, graph.Actions["Action"], "Approve", row, out rollback);
                    }
                    else if (graph.Caches[cahceType].Fields.Contains(approved))
                    {
                        object upd = graph.Caches[cahceType].CreateCopy(row);
                        graph.Caches[cahceType].SetValue(upd, approved, true);
                        graph.Caches[cahceType].Update(upd);
                    }
                    graph.Persist();
                    PXProcessing <EPApproval> .SetInfo(ActionsMessages.RecordProcessed);
                }
                catch (Exception ex)
                {
                    errorOccured = true;
                    PXProcessing <EPApproval> .SetError(ex);
                }
            }
            if (errorOccured)
            {
                throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
            }
        }
        public virtual IEnumerable Action(
            PXAdapter adapter,
            [PXInt]
            [PXIntList(new int[] { 1, 2, 3, 4, 5 }, new string[] { "Create Shipment", "Apply Assignment Rules", "Create Invoice", "Post Invoice to IN", "Create Purchase Order" })]
            int?actionID,
            [PXDate]
            DateTime?shipDate,
            [PXSelector(typeof(INSite.siteCD))]
            string siteCD,
            [SOOperation.List]
            string operation,
            [PXString()]
            string ActionName,
            Func <PXAdapter, int?, DateTime?, string, string, string, IEnumerable> baseMtd)
        {
            switch (actionID)
            {
            case 1:
            {
                if (!string.IsNullOrEmpty(ActionName))
                {
                    PXAction action = Base.Actions[ActionName];

                    if (action != null)
                    {
                        Base.Save.Press();
                        List <object> result = new List <object>();
                        foreach (object data in action.Press(adapter))
                        {
                            result.Add(data);
                        }
                        return(result);
                    }
                }

                List <SOOrder> list = new List <SOOrder>();
                foreach (SOOrder order in adapter.Get <SOOrder>())
                {
                    list.Add(order);
                }

                if (shipDate != null)
                {
                    Base.soparamfilter.Current.ShipDate = shipDate;
                }

                if (Base.soparamfilter.Current.ShipDate == null)
                {
                    Base.soparamfilter.Current.ShipDate = Base.Accessinfo.BusinessDate;
                }

                if (siteCD != null)
                {
                    Base.soparamfilter.Cache.SetValueExt <SOParamFilter.siteID>(Base.soparamfilter.Current, siteCD);
                }

                if (!adapter.MassProcess)
                {
                    if (Base.soparamfilter.Current.SiteID == null)
                    {
                        Base.soparamfilter.Current.SiteID = GetPreferedSiteID();
                    }
                    if (adapter.ExternalCall)
                    {
                        Base.soparamfilter.AskExt(true);
                    }
                }
                if (Base.soparamfilter.Current.SiteID != null || adapter.MassProcess)
                {
                    try
                    {
                        Base.RecalculateExternalTaxesSync = true;
                        Base.Save.Press();
                    }
                    finally
                    {
                        Base.RecalculateExternalTaxesSync = false;
                    }
                    PXAutomation.RemovePersisted(Base, typeof(SOOrder), new List <object>(list));

                    SOParamFilter filter = Base.soparamfilter.Current;
                    PXLongOperation.StartOperation(Base, delegate()
                        {
                            bool anyfailed                    = false;
                            SOShipmentEntry docgraph          = PXGraph.CreateInstance <SOShipmentEntry>();
                            SOOrderEntry ordgraph             = PXGraph.CreateInstance <SOOrderEntry>();
                            DocumentList <SOShipment> created = new DocumentList <SOShipment>(docgraph);

                            //address AC-92776
                            for (int i = 0; i < list.Count; i++)
                            {
                                SOOrder order = list[i];
                                if (adapter.MassProcess)
                                {
                                    PXProcessing <SOOrder> .SetCurrentItem(order);
                                }

                                SOOrder ordercopy = (SOOrder)Base.Caches[typeof(SOOrder)].CreateCopy(order);
                                try
                                {
                                    if (operation == SOOperation.Issue)
                                    {
                                        ReviewWarehouseAvailability(ordgraph, order);
                                    }
                                }
                                catch (SOShipmentException ex)
                                {
                                    Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy);
                                    if (!adapter.MassProcess)
                                    {
                                        throw;
                                    }

                                    order.LastShipDate = filter.ShipDate;
                                    order.Status       = SOOrderStatus.Shipping; //Automation will set the order to back order since no shipments were created

                                    docgraph.Clear();

                                    var ordergraph = PXGraph.CreateInstance <SOOrderEntry>();
                                    ordergraph.Clear();

                                    ordergraph.Document.Cache.MarkUpdated(order);
                                    PXAutomation.CompleteSimple(ordergraph.Document.View);
                                    try
                                    {
                                        ordergraph.Save.Press();
                                        PXAutomation.RemovePersisted(ordergraph, order);

                                        PXTrace.WriteInformation(ex);
                                        PXProcessing <SOOrder> .SetWarning(ex);
                                    }
                                    catch (Exception inner)
                                    {
                                        Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy);
                                        PXProcessing <SOOrder> .SetError(inner);
                                        anyfailed = true;
                                    }
                                    continue;     //Stop there for this order
                                }
                                catch (Exception ex)
                                {
                                    if (!adapter.MassProcess)
                                    {
                                        throw;
                                    }
                                    PXProcessing <SOOrder> .SetError(ex);
                                    anyfailed = true;
                                    continue;
                                }

                                List <int?> sites = new List <int?>();

                                if (filter.SiteID != null)
                                {
                                    sites.Add(filter.SiteID);
                                }
                                else
                                {
                                    foreach (SOShipmentPlan plan in PXSelectGroupBy <SOShipmentPlan, Where <SOShipmentPlan.orderType, Equal <Current <SOOrder.orderType> >, And <SOShipmentPlan.orderNbr, Equal <Current <SOOrder.orderNbr> > > >, Aggregate <GroupBy <SOShipmentPlan.siteID> >, OrderBy <Asc <SOShipmentPlan.siteID> > > .SelectMultiBound(docgraph, new object[] { order }))
                                    {
                                        sites.Add(plan.SiteID);
                                    }
                                }

                                foreach (int?SiteID in sites)
                                {
                                    ordercopy = (SOOrder)Base.Caches[typeof(SOOrder)].CreateCopy(order);
                                    try
                                    {
                                        using (var ts = new PXTransactionScope())
                                        {
                                            PXTimeStampScope.SetRecordComesFirst(typeof(SOOrder), true);
                                            docgraph.CreateShipment(order, SiteID, filter.ShipDate, adapter.MassProcess, operation, created, adapter.QuickProcessFlow);
                                            ts.Complete();
                                        }

                                        if (adapter.MassProcess)
                                        {
                                            PXProcessing <SOOrder> .SetProcessed();
                                        }
                                    }
                                    catch (SOShipmentException ex)
                                    {
                                        Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy);
                                        if (!adapter.MassProcess)
                                        {
                                            throw;
                                        }
                                        order.LastSiteID   = SiteID;
                                        order.LastShipDate = filter.ShipDate;
                                        order.Status       = SOOrderStatus.Shipping;

                                        docgraph.Clear();

                                        var ordergraph = PXGraph.CreateInstance <SOOrderEntry>();
                                        ordergraph.Clear();

                                        ordergraph.Document.Cache.MarkUpdated(order);
                                        PXAutomation.CompleteSimple(ordergraph.Document.View);
                                        try
                                        {
                                            ordergraph.Save.Press();
                                            PXAutomation.RemovePersisted(ordergraph, order);

                                            PXTrace.WriteInformation(ex);
                                            PXProcessing <SOOrder> .SetWarning(ex);
                                        }
                                        catch (Exception inner)
                                        {
                                            Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy);
                                            PXProcessing <SOOrder> .SetError(inner);
                                            anyfailed = true;
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        Base.Caches[typeof(SOOrder)].RestoreCopy(order, ordercopy);
                                        docgraph.Clear();

                                        if (!adapter.MassProcess)
                                        {
                                            throw;
                                        }
                                        PXProcessing <SOOrder> .SetError(ex);
                                        anyfailed = true;
                                    }
                                }
                            }

                            if (adapter.AllowRedirect && !adapter.MassProcess && created.Count > 0)
                            {
                                using (new PXTimeStampScope(null))
                                {
                                    docgraph.Clear();
                                    docgraph.Document.Current = docgraph.Document.Search <SOShipment.shipmentNbr>(created[0].ShipmentNbr);
                                    throw new PXRedirectRequiredException(docgraph, "Shipment");
                                }
                            }

                            if (anyfailed)
                            {
                                throw new PXOperationCompletedWithErrorException(ErrorMessages.SeveralItemsFailed);
                            }
                        });
                }
                return(list);
            }

            default:
                return(baseMtd(adapter, actionID, shipDate, siteCD, operation, ActionName));
            }
        }
 private static void SetupAutomationStep(SubcontractEntry graph, POOrder subcontract)
 {
     PXAutomation.GetView(graph);
     PXAutomation.GetStep(graph, subcontract.CreateArray(),
                          BqlCommand.CreateInstance(typeof(Select <>), typeof(POOrder)));
 }