public override void Configure(PXScreenConfiguration configuration)
 {
     configuration
     .GetScreenConfigurationContext <OpportunityMaint, CROpportunity>()
     .UpdateScreenConfigurationFor(config => config
                                   .WithActions(a =>
     {
         a.Add <SM_OpportunityMaint>(e => e.CreateServiceOrder, c => c.InFolder(FolderType.ActionsFolder));
         a.Add <SM_OpportunityMaint>(e => e.OpenAppointmentBoard, c => c.InFolder(FolderType.ActionsFolder));
     })
                                   .UpdateDefaultFlow(flow =>
     {
         return(flow.WithFlowStates(states =>
         {
             states.Update(OpportunityWorkflow.States.New,
                           state => state.WithActions(actions =>
             {
                 actions.Add <SM_OpportunityMaint>(e => e.CreateServiceOrder);
             }));
             states.Update(OpportunityWorkflow.States.Open,
                           state => state.WithActions(actions =>
             {
                 actions.Add <SM_OpportunityMaint>(e => e.CreateServiceOrder);
             }));
             states.Update(OpportunityWorkflow.States.Won,
                           state => state.WithActions(actions =>
             {
                 actions.Add <SM_OpportunityMaint>(e => e.CreateServiceOrder);
             })
                           );
         }));
     })
                                   );
 }
        public override void Configure(PXScreenConfiguration configuration)
        {
            base.Configure(configuration);

            WorkflowContext <POOrderEntry, POOrder> context = configuration.GetScreenConfigurationContext <POOrderEntry, POOrder>();

            context.UpdateScreenConfigurationFor(screen =>
            {
                return(screen.WithFlows(flows =>
                {
                    flows.Update <POOrderType.regularOrder>(flow =>
                    {
                        return flow.WithFlowStates(states =>
                        {
                            states.Update <POOrderStatus.open>(state =>
                            {
                                return state.WithFieldStates(fields =>
                                {
                                    fields.AddField <POLineExt.usrVendConfDate>();
                                });
                            });
                            //states.Update<POOrderStatus.rejected>(state =>
                            //{
                            //    return state.WithActions(actions => { }).WithFieldStates(fields =>
                            //    {
                            //        fields.AddField<POOrder.orderDesc>();

                            //        fields.AddField(typeof(POLineExt), "usrVendConfDate");
                            //    });
                            //});
                        });
                    });
                }));
            });
        }
Example #3
0
        public override void Configure(PXScreenConfiguration configuration)
        {
            var context = configuration.GetScreenConfigurationContext <LeadMaint, CRLead>();

            #region forms

            var reasons = new Dictionary <string, (string @default, string[] values)>(6)
            {
 public override void Configure(PXScreenConfiguration config) => Configure(config.GetScreenConfigurationContext <ProjectEntry, PMProject>());
Example #5
0
        public override void Configure(PXScreenConfiguration config)
        {
            var context = config.GetScreenConfigurationContext <CRCaseMaint, CRCase>();

            #region forms

            var reasons = new Dictionary <string, string[]>(5)
            {
                [States.New]             = new[] { _reasonUnassigned },
                [States.Open]            = new[] { _reasonInProcess, _reasonUpdated, _reasonInEscalation, _reasonPendingClosure },
                [States.PendingCustomer] = new[] { _reasonMoreInfoRequested, _reasonWaitingConfirmation, _reasonPendingClosure },
                [States.Closed]          = new[] { _reasonResolved, _reasonRejected, _reasonCanceled, _reasonAbandoned, _reasonDuplicate },
                [States.Released]        = new[] { _reasonResolved, _reasonCanceled },
            };

            var formOpen = context.Forms.Create(_formOpen, form => form
                                                .Prompt("Details")
                                                .WithFields(fields =>
            {
                AddResolutionFormField(fields, _reasonInProcess, reasons[States.Open]);
                AddOwnerFormField(fields);
            }));

            var formPending = context.Forms.Create(_formPending, form => form
                                                   .Prompt("Details")
                                                   .WithFields(fields =>
            {
                AddResolutionFormField(fields, _reasonWaitingConfirmation, reasons[States.PendingCustomer]);
            }));

            var formClose = context.Forms.Create(_formClose, form => form
                                                 .Prompt("Details")
                                                 .WithFields(fields =>
            {
                AddResolutionFormField(fields, _reasonResolved, reasons[States.Closed]);
            }));

            void AddResolutionFormField(FormField.IContainerFillerFields filler, string defaultValue, string[] values)
            {
                filler.Add(_fieldReason, field => field
                           .WithSchemaOf <CRCase.resolution>()
                           .IsRequired()
                           .Prompt("Reason")
                           .DefaultValue(defaultValue)
                           .OnlyComboBoxValues(values));
            }

            void AddOwnerFormField(FormField.IContainerFillerFields filler)
            {
                filler.Add(_fieldOwner, field => field
                           .WithSchemaOf <CRCase.ownerID>()
                           .Prompt("Owner")
                           .DefaultValueFromSchemaField());
            }

            #endregion

            var actionOpen = context.ActionDefinitions.CreateNew(_actionOpen, a => a
                                                                 .WithFieldAssignments(fields =>
            {
                fields.Add <CRCase.isActive>(f => f.SetFromValue(true));
                fields.Add <CRCase.resolution>(f => f.SetFromFormField(formOpen, _fieldReason));
                fields.Add <CRCase.ownerID>(f => f.SetFromFormField(formOpen, _fieldOwner));
                fields.Add <CRCase.resolutionDate>(f => f.SetFromValue(null));
            })
                                                                 .DisplayName("Open")
                                                                 .WithForm(formOpen)
                                                                 .MassProcessingScreen <UpdateCaseMassProcess>());

            var actionPending = context.ActionDefinitions.CreateNew(_actionPending, a => a
                                                                    .WithFieldAssignments(fields =>
            {
                fields.Add <CRCase.isActive>(f => f.SetFromValue(true));
                fields.Add <CRCase.resolution>(f => f.SetFromFormField(formPending, _fieldReason));
                fields.Add <CRCase.resolutionDate>(f => f.SetFromValue(null));
            })
                                                                    .DisplayName("Pending Customer")
                                                                    .WithForm(formPending)
                                                                    .MassProcessingScreen <UpdateCaseMassProcess>());

            var actionClose = context.ActionDefinitions.CreateNew(_actionClose, a => a
                                                                  .WithFieldAssignments(fields =>
            {
                fields.Add <CRCase.isActive>(f => f.SetFromValue(false));
                fields.Add <CRCase.resolution>(f => f.SetFromFormField(formClose, _fieldReason));
                fields.Add <CRCase.resolutionDate>(f => f.SetFromNow());
            })
                                                                  .DisplayName("Close")
                                                                  .WithForm(formClose)
                                                                  .MassProcessingScreen <UpdateCaseMassProcess>());

            var gactionRelease = context.ActionDefinitions.CreateExisting(g => g.release, a => a
                                                                          .InFolder(FolderType.ActionsFolder)
                                                                          .MassProcessingScreen <CRCaseReleaseProcess>());

            var gactionAssign      = context.ActionDefinitions.CreateExisting(g => g.assign, a => a.InFolder(FolderType.ActionsFolder));
            var gactionViewInvoice = context.ActionDefinitions.CreateExisting(g => g.viewInvoice, a => a.InFolder(FolderType.InquiriesFolder));

            context.AddScreenConfigurationFor(screen =>
            {
                return(screen
                       .StateIdentifierIs <CRCase.status>()
                       .AddDefaultFlow(DefaultCaseFlow)
                       .WithActions(actions =>
                {
                    actions.Add(actionOpen);
                    actions.Add(actionPending);
                    actions.Add(actionClose);
                    actions.Add(gactionRelease);
                    actions.Add(gactionAssign);
                    actions.Add(gactionViewInvoice);
                })
                       .WithForms(forms =>
                {
                    forms.Add(formOpen);
                    forms.Add(formPending);
                    forms.Add(formClose);
                })
                       .WithFieldStates(fields =>
                {
                    fields.Add <CRCase.resolution>(field => field
                                                   .SetComboValues(
                                                       (_reasonRejected, "Rejected"),
                                                       (_reasonResolved, "Resolved"),
                                                       (_reasonMoreInfoRequested, "More Info Requested"),
                                                       (_reasonInProcess, "In Process"),
                                                       (_reasonInternal, "Internal"),
                                                       (_reasonInEscalation, "In Escalation"),
                                                       (_reasonDuplicate, "Duplicate"),
                                                       (_reasonWaitingConfirmation, "Waiting Confirmation"),
                                                       (_reasonCustomerPostpone, "Customer Postpone"),
                                                       (_reasonCanceled, "Canceled"),
                                                       (_reasonPendingClosure, "Pending Closure"),
                                                       (_reasonAbandoned, "Abandoned"),
                                                       (_reasonUnassigned, "Unassigned"),
                                                       (_reasonUpdated, "Updated"),
                                                       (_reasonClosedOnPortal, "Closed on Portal"),
                                                       (_reasonOpenedOnPortal, "Opened on Portal")));
                }));
            });

            Workflow.IConfigured DefaultCaseFlow(Workflow.INeedStatesFlow flow)
            {
                #region states

                var newState = context.FlowStates.Create(States.New, state => state
                                                         .IsInitial()
                                                         .WithFieldStates(fields =>
                {
                    fields.AddField <CRCase.resolution>(field => field
                                                        .DefaultValue(_reasonUnassigned)
                                                        .ComboBoxValues(reasons[States.New].Union(new[] { _reasonOpenedOnPortal }).ToArray()));
                    fields.AddField <CRCase.isActive>(field => field.IsDisabled());
                })
                                                         .WithActions(actions =>
                {
                    actions.Add(g => g.takeCase);
                    actions.Add(g => g.assign);
                    AddOpenAction(actions, isDuplicationInToolbar: true);
                    AddPendingCustomerAction(actions);
                    AddCloseAction(actions);
                }));

                var openState = context.FlowStates.Create(States.Open, state => state
                                                          .WithFieldStates(fields =>
                {
                    fields.AddField <CRCase.resolution>(field =>
                                                        field.ComboBoxValues(reasons[States.Open]));
                    fields.AddField <CRCase.isActive>(field => field.IsDisabled());
                })
                                                          .WithActions(actions =>
                {
                    actions.Add(g => g.takeCase);
                    actions.Add(g => g.assign);
                    AddPendingCustomerAction(actions);
                    AddCloseAction(actions, isDuplicationInToolbar: true);
                }));

                var pendingState = context.FlowStates.Create(States.PendingCustomer, state => state
                                                             .WithFieldStates(fields =>
                {
                    fields.AddField <CRCase.resolution>(field => field
                                                        .ComboBoxValues(reasons[States.PendingCustomer])
                                                        .IsDisabled());
                    fields.AddField <CRCase.isActive>(field => field.IsDisabled());
                })
                                                             .WithActions(actions =>
                {
                    actions.Add(g => g.takeCase);
                    AddOpenAction(actions);
                    AddCloseAction(actions, isDuplicationInToolbar: true);
                }));

                var closedState = context.FlowStates.Create(States.Closed, state => state
                                                            .WithFieldStates(fields =>
                {
                    fields.AddField <CRCase.resolution>(field => field
                                                        .ComboBoxValues(reasons[States.Closed].Union(new[] { _reasonClosedOnPortal }).ToArray())
                                                        .IsDisabled());

                    DisableFieldsForFinalStates(fields);

                    fields.AddField <CRCase.isBillable>();
                    fields.AddField <CRCase.manualBillableTimes>();
                    fields.AddField <CRCase.timeBillable>();
                    fields.AddField <CRCase.overtimeBillable>();
                })
                                                            .WithActions(actions =>
                {
                    AddOpenAction(actions);
                    AddPendingCustomerAction(actions);
                    actions.Add(g => g.release, action => action.IsDuplicatedInToolbar());
                }));

                var releasedState = context.FlowStates.Create(States.Released, state => state
                                                              .WithFieldStates(fields =>
                {
                    fields.AddField <CRCase.resolution>(field => field
                                                        .ComboBoxValues(reasons[States.Released])
                                                        .IsDisabled());

                    DisableFieldsForFinalStates(fields);
                })
                                                              .WithActions(actions =>
                {
                    actions.Add(g => g.viewInvoice);
                }));


                #endregion

                return(flow
                       .WithFlowStates(states =>
                {
                    states.Add(newState);
                    states.Add(openState);
                    states.Add(pendingState);
                    states.Add(closedState);
                    states.Add(releasedState);
                })
                       .WithTransitions(transitions =>
                {
                    #region new

                    transitions.Add(transition => transition
                                    .From(newState)
                                    .To(openState)
                                    .IsTriggeredOn(actionOpen));

                    transitions.Add(transition => transition
                                    .From(newState)
                                    .To(pendingState)
                                    .IsTriggeredOn(actionPending));

                    transitions.Add(transition => transition
                                    .From(newState)
                                    .To(closedState)
                                    .IsTriggeredOn(actionClose));

                    transitions.Add(transition => transition
                                    .From(newState)
                                    .To(openState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.openCaseFromPortal)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(true));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonOpenedOnPortal));
                    }));

                    transitions.Add(transition => transition
                                    .From(newState)
                                    .To(closedState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.closeCaseFromPortal)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(false));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonClosedOnPortal));
                    }));

                    #endregion
                    #region open

                    transitions.Add(transition => transition
                                    .From(openState)
                                    .To(pendingState)
                                    .IsTriggeredOn(actionPending));

                    transitions.Add(transition => transition
                                    .From(openState)
                                    .To(closedState)
                                    .IsTriggeredOn(actionClose));

                    transitions.Add(transition => transition
                                    .From(openState)
                                    .To(openState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.openCaseFromProcessing)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(true));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonUpdated));
                    }));

                    transitions.Add(transition => transition
                                    .From(openState)
                                    .To(openState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.openCaseFromPortal)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(true));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonOpenedOnPortal));
                    }));

                    transitions.Add(transition => transition
                                    .From(openState)
                                    .To(closedState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.closeCaseFromPortal)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(false));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonClosedOnPortal));
                    }));

                    #endregion
                    #region pending

                    transitions.Add(transition => transition
                                    .From(pendingState)
                                    .To(openState)
                                    .IsTriggeredOn(actionOpen));

                    transitions.Add(transition => transition
                                    .From(pendingState)
                                    .To(closedState)
                                    .IsTriggeredOn(actionClose));

                    transitions.Add(transition => transition
                                    .From(pendingState)
                                    .To(openState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.openCaseFromProcessing)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(true));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonUpdated));
                    }));

                    transitions.Add(transition => transition
                                    .From(pendingState)
                                    .To(openState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.openCaseFromPortal)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(true));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonOpenedOnPortal));
                    }));

                    transitions.Add(transition => transition
                                    .From(pendingState)
                                    .To(closedState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.closeCaseFromPortal)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(false));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonClosedOnPortal));
                    }));

                    #endregion
                    #region closed

                    transitions.Add(transition => transition
                                    .From(closedState)
                                    .To(openState)
                                    .IsTriggeredOn(actionOpen));

                    transitions.Add(transition => transition
                                    .From(closedState)
                                    .To(pendingState)
                                    .IsTriggeredOn(actionPending));

                    transitions.Add(transition => transition
                                    .From(closedState)
                                    .To(releasedState)
                                    .IsTriggeredOn(g => g.release)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(false));
                    }));

                    transitions.Add(transition => transition
                                    .From(closedState)
                                    .To(openState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.openCaseFromProcessing)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(true));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonUpdated));
                    }));

                    transitions.Add(transition => transition
                                    .From(closedState)
                                    .To(openState)
                                    .IsTriggeredOn <CaseWorkflow>(e => e.openCaseFromPortal)
                                    .WithFieldAssignments(fields =>
                    {
                        fields.Add <CRCase.isActive>(f => f.SetFromValue(true));
                        fields.Add <CRCase.resolution>(f => f.SetFromValue(_reasonOpenedOnPortal));
                    }));

                    #endregion
                }));

                void AddOpenAction(ActionState.IContainerFillerActions filler, bool isDuplicationInToolbar = false)
                {
                    filler.Add(actionOpen, a => a.IsDuplicatedInToolbar(isDuplicationInToolbar));
                }

                void AddPendingCustomerAction(ActionState.IContainerFillerActions filler, bool isDuplicationInToolbar = false)
                {
                    filler.Add(actionPending, a => a.IsDuplicatedInToolbar(isDuplicationInToolbar));
                }

                void AddCloseAction(ActionState.IContainerFillerActions filler, bool isDuplicationInToolbar = false)
                {
                    filler.Add(actionClose, a => a.IsDuplicatedInToolbar(isDuplicationInToolbar));
                }

                void DisableFieldsForFinalStates(FieldState.IContainerFillerFields fields)
                {
                    fields.AddTable <CRCase>(field => field.IsDisabled());
                    fields.AddTable <CRPMTimeActivity>(field => field.IsDisabled());
                    fields.AddTable <CRCaseArticle>(field => field.IsDisabled());
                    fields.AddTable <CS.CSAnswers>(field => field.IsDisabled());
                    fields.AddField <CRCase.caseCD>();
                }
            }
        }
        public override void Configure(PXScreenConfiguration config)
        {
            var context = config.GetScreenConfigurationContext <OpportunityMaint, CROpportunity>();

            #region forms

            var formOpen = context.Forms.Create(_formOpen, form => form
                                                .Prompt("Details")
                                                .WithFields(fields =>
            {
                AddResolutionFormField(fields, _reasonInProcess, _reasonInProcess);
                AddStageIDFormField(fields);
            }));

            var formWon = context.Forms.Create(_formWon, form => form
                                               .Prompt("Details")
                                               .WithFields(fields =>
            {
                AddResolutionFormField(fields, _reasonOther,
                                       _reasonOther, _reasonPrice, _reasonRelationship, _reasonTechnology);
                AddStageIDFormField(fields);
            }));

            var formLost = context.Forms.Create(_formLost, form => form
                                                .Prompt("Details")
                                                .WithFields(fields =>
            {
                AddResolutionFormField(fields, _reasonCanceled,
                                       _reasonCanceled, _reasonOther, _reasonPrice, _reasonCompanyMaturity, _reasonFunctionality);
                AddStageIDFormField(fields);
            }));

            void AddResolutionFormField(FormField.IContainerFillerFields filler, string defaultValue, params string[] values)
            {
                filler.Add(_fieldReason, field => field
                           .WithSchemaOf <CROpportunity.resolution>()
                           .IsRequired()
                           .Prompt("Reason")
                           .DefaultValue(defaultValue)
                           .OnlyComboBoxValues(values));
            }

            void AddStageIDFormField(FormField.IContainerFillerFields filler)
            {
                filler.Add(_fieldStage, field => field
                           .WithSchemaOf <CROpportunity.stageID>()
                           .DefaultValueFromSchemaField()
                           .Prompt("Stage"));
            }

            #endregion

            var actionOpen = context.ActionDefinitions.CreateNew(_actionOpen, action => action
                                                                 .WithFieldAssignments(fields =>
            {
                fields.Add <CROpportunity.resolution>(f => f.SetFromFormField(formOpen, _fieldReason));
                fields.Add <CROpportunity.stageID>(f => f.SetFromFormField(formOpen, _fieldStage));
                fields.Add <CROpportunity.isActive>(f => f.SetFromValue(true));
                fields.Add <CROpportunity.closingDate>(f => f.SetFromValue(null));
            })
                                                                 .DisplayName("Open")
                                                                 .WithForm(formOpen)
                                                                 .MassProcessingScreen <UpdateOpportunityMassProcess>());

            var actionWon = context.ActionDefinitions.CreateNew(_actionWon, action => action
                                                                .WithFieldAssignments(fields =>
            {
                fields.Add <CROpportunity.resolution>(f => f.SetFromFormField(formWon, _fieldReason));
                fields.Add <CROpportunity.stageID>(f => f.SetFromFormField(formWon, _fieldStage));
                fields.Add <CROpportunity.isActive>(f => f.SetFromValue(false));
                fields.Add <CROpportunity.closingDate>(f => f.SetFromToday());
            })
                                                                .DisplayName("Close as Won")
                                                                .WithForm(formWon)
                                                                .MassProcessingScreen <UpdateOpportunityMassProcess>());

            var actionLost = context.ActionDefinitions.CreateNew(_actionLost, action => action
                                                                 .WithFieldAssignments(fields =>
            {
                fields.Add <CROpportunity.resolution>(f => f.SetFromFormField(formLost, _fieldReason));
                fields.Add <CROpportunity.stageID>(f => f.SetFromFormField(formLost, _fieldStage));
                fields.Add <CROpportunity.isActive>(f => f.SetFromValue(false));
                fields.Add <CROpportunity.closingDate>(f => f.SetFromToday());
            })
                                                                 .DisplayName("Close as Lost")
                                                                 .WithForm(formLost)
                                                                 .MassProcessingScreen <UpdateOpportunityMassProcess>());

            context.AddScreenConfigurationFor(screen =>
            {
                return(screen
                       .StateIdentifierIs <CROpportunity.status>()
                       .AddDefaultFlow(DefaultOpportunityFlow)
                       .WithActions(actions =>
                {
                    actions.Add(actionOpen);
                    actions.Add(actionWon);
                    actions.Add(actionLost);

                    actions.Add(g => g.submitQuote, c => c.InFolder(FolderType.ActionsFolder));
                    actions.Add(g => g.editQuote, c => c.InFolder(FolderType.ActionsFolder));
                    actions.Add(g => g.createSalesOrder, c => c.InFolder(FolderType.ActionsFolder));
                    actions.Add(g => g.createInvoice, c => c.InFolder(FolderType.ActionsFolder));
                    actions.Add(g => g.validateAddresses, c => c.InFolder(FolderType.ActionsFolder));
                    actions.Add <CreateContactExt>(e => e.CreateContact, c => c.InFolder(FolderType.ActionsFolder));
                    actions.Add <CreateAccountExt>(e => e.CreateBothContactAndAccount, c => c.InFolder(FolderType.ActionsFolder));
                    actions.Add <OpportunityMaint.Discount>(e => e.recalculatePrices, c => c.InFolder(FolderType.ActionsFolder));
                })
                       .WithForms(forms =>
                {
                    forms.Add(formOpen);
                    forms.Add(formWon);
                    forms.Add(formLost);
                })
                       .WithFieldStates(fields =>
                {
#pragma warning disable CS0618 // Type or member is obsolete
                    fields.Add <CROpportunity.source>(field => field
                                                      .SetComboValues(
                                                          (CRMSourcesAttribute._WEB, "Web"),
                                                          (CRMSourcesAttribute._PHONE_INQ, "Phone Inquiry"),
                                                          (CRMSourcesAttribute._PURCHASED_LIST, "Purchased List")));
#pragma warning restore CS0618 // Type or member is obsolete

                    fields.Add <CROpportunity.resolution>(field => field
                                                          .SetComboValues(
                                                              (_reasonTechnology, "Technology"),
                                                              (_reasonRelationship, "Relationship"),
                                                              (_reasonPrice, "Price"),
                                                              (_reasonOther, "Other"),
                                                              (_reasonAssign, "Assign"),
                                                              (_reasonInProcess, "In Process"),
                                                              (_reasonFunctionality, "Functionality"),
                                                              (_reasonCompanyMaturity, "Company Maturity"),
                                                              (_reasonCanceled, "Canceled")));
                }));
            });

            Workflow.IConfigured DefaultOpportunityFlow(Workflow.INeedStatesFlow flow)
            {
                #region states

                var newState = context.FlowStates.Create(States.New, state => state
                                                         .IsInitial()
                                                         .WithFieldStates(fields =>
                {
                    fields.AddField <CROpportunity.resolution>(field =>
                                                               field.DefaultValue(_reasonAssign).ComboBoxValues(_reasonAssign));

                    AddSourceFieldState(fields);
                })
                                                         .WithActions(actions =>
                {
                    actions.Add(g => g.createSalesOrder);
                    actions.Add(g => g.createInvoice);
                    actions.Add <CreateContactExt>(e => e.CreateContact);
                    actions.Add <CreateAccountExt>(e => e.CreateBothContactAndAccount);
                    actions.Add(g => g.validateAddresses);
                    actions.Add <OpportunityMaint.Discount>(e => e.recalculatePrices);
                    AddOpenAction(actions, isDuplicationInToolbar: true);
                    AddWonAction(actions);
                    AddLostAction(actions);
                }));

                var openState = context.FlowStates.Create(States.Open, state => state
                                                          .WithFieldStates(fields =>
                {
                    fields.AddField <CROpportunity.resolution>(field =>
                                                               field.ComboBoxValues(_reasonInProcess));

                    AddSourceFieldState(fields);
                })
                                                          .WithActions(actions =>
                {
                    actions.Add(g => g.createSalesOrder);
                    actions.Add(g => g.createInvoice);
                    actions.Add <CreateContactExt>(e => e.CreateContact);
                    actions.Add <CreateAccountExt>(e => e.CreateBothContactAndAccount);
                    actions.Add(g => g.validateAddresses);
                    actions.Add <OpportunityMaint.Discount>(e => e.recalculatePrices);
                    AddWonAction(actions, isDuplicationInToolbar: true);
                    AddLostAction(actions);
                }));

                var wonState = context.FlowStates.Create(States.Won, state => state
                                                         .WithFieldStates(fields =>
                {
                    fields.AddField <CROpportunity.resolution>(field => field
                                                               .ComboBoxValues(_reasonOther, _reasonPrice, _reasonRelationship, _reasonTechnology)
                                                               .IsDisabled());

                    DisableFieldsForFinalStates(fields);
                })
                                                         .WithActions(actions =>
                {
                    actions.Add(g => g.createSalesOrder);
                    actions.Add(g => g.createInvoice);
                    AddOpenAction(actions);
                }));

                var lostState = context.FlowStates.Create(States.Lost, state => state
                                                          .WithFieldStates(fields =>
                {
                    fields.AddField <CROpportunity.resolution>(field => field
                                                               .ComboBoxValues(_reasonCanceled, _reasonOther, _reasonPrice, _reasonCompanyMaturity, _reasonFunctionality)
                                                               .IsDisabled());

                    DisableFieldsForFinalStates(fields);
                })
                                                          .WithActions(actions =>
                {
                    AddOpenAction(actions);
                }));

                #endregion

                return(flow
                       .WithFlowStates(states =>
                {
                    states.Add(newState);
                    states.Add(openState);
                    states.Add(wonState);
                    states.Add(lostState);
                })
                       .WithTransitions(transitions =>
                {
                    transitions.Add(transition => transition
                                    .From(newState)
                                    .To(openState)
                                    .IsTriggeredOn(actionOpen));

                    transitions.Add(transition => transition
                                    .From(newState)
                                    .To(wonState)
                                    .IsTriggeredOn(actionWon));

                    transitions.Add(transition => transition
                                    .From(newState)
                                    .To(lostState)
                                    .IsTriggeredOn(actionLost));
                    transitions.Add(transition => transition
                                    .From(openState)
                                    .To(wonState)
                                    .IsTriggeredOn(actionWon));

                    transitions.Add(transition => transition
                                    .From(openState)
                                    .To(lostState)
                                    .IsTriggeredOn(actionLost));

                    transitions.Add(transition => transition
                                    .From(wonState)
                                    .To(openState)
                                    .IsTriggeredOn(actionOpen));

                    transitions.Add(transition => transition
                                    .From(lostState)
                                    .To(openState)
                                    .IsTriggeredOn(actionOpen));
                }));

                void AddOpenAction(ActionState.IContainerFillerActions filler, bool isDuplicationInToolbar = false)
                {
                    filler.Add(actionOpen, a => a

                               .IsDuplicatedInToolbar(isDuplicationInToolbar));
                }

                void AddWonAction(ActionState.IContainerFillerActions filler, bool isDuplicationInToolbar = false)
                {
                    filler.Add(actionWon, a => a

                               .IsDuplicatedInToolbar(isDuplicationInToolbar));
                }

                void AddLostAction(ActionState.IContainerFillerActions filler, bool isDuplicationInToolbar = false)
                {
                    filler.Add(actionLost, a => a

                               .IsDuplicatedInToolbar(isDuplicationInToolbar));
                }

                void AddSourceFieldState(FieldState.IContainerFillerFields filler)
                {
                    filler.AddField <CROpportunity.source>(field => field.ComboBoxValues(CRMSourcesAttribute.Values));
                }

                void DisableFieldsForFinalStates(FieldState.IContainerFillerFields fields)
                {
                    fields.AddTable <CROpportunity>(field => field.IsDisabled());
                    fields.AddTable <CROpportunityProducts>(field => field.IsDisabled());
                    fields.AddTable <CRTaxTran>(field => field.IsDisabled());
                    fields.AddTable <CROpportunityDiscountDetail>(field => field.IsDisabled());
                    fields.AddTable <CRContact>(field => field.IsDisabled());
                    fields.AddTable <CRAddress>(field => field.IsDisabled());
                    fields.AddTable <CS.CSAnswers>(field => field.IsDisabled());
                    fields.AddTable <CROpportunityTax>(field => field.IsDisabled());
                    fields.AddField <CROpportunity.opportunityID>();
                }
            }
        }