Exemplo n.º 1
0
        protected override async Task <List <PrintingTemplateForSave> > SavePreprocessAsync(List <PrintingTemplateForSave> entities)
        {
            var settings = await _behavior.Settings();

            // Defaults
            entities.ForEach(entity =>
            {
                entity.Roles ??= new List <PrintingTemplateRoleForSave>();
                entity.Parameters ??= new List <PrintingTemplateParameterForSave>();
                entity.Parameters.ForEach(p =>
                {
                    p.IsRequired ??= false;
                    p.ControlOptions = ApplicationUtil.PreprocessControlOptions(p.Control, p.ControlOptions, settings);
                });

                // Set defaults
                entity.SupportsPrimaryLanguage ??= false;
                entity.SupportsSecondaryLanguage ??= false;
                entity.SupportsTernaryLanguage ??= false;

                // Make sure we adhere to company languages
                if (settings.SecondaryLanguageId == null)
                {
                    entity.SupportsSecondaryLanguage = false;
                }

                if (settings.TernaryLanguageId == null)
                {
                    entity.SupportsTernaryLanguage = false;
                }

                // Make sure at least primary language is true
                if (!entity.SupportsSecondaryLanguage.Value && !entity.SupportsTernaryLanguage.Value)
                {
                    entity.SupportsPrimaryLanguage = true;
                }

                // Collection and DefinitionId only make sense when the usage is specified
                if (entity.Usage == null)
                {
                    entity.Collection         = null;
                    entity.DefinitionId       = null;
                    entity.ReportDefinitionId = null;
                }

                if (entity.Usage == TemplateUsages.FromDetails || entity.Usage == TemplateUsages.FromSearchAndDetails)
                {
                }

                if (entity.Usage == TemplateUsages.FromReport)
                {
                    entity.Collection   = null;
                    entity.DefinitionId = null;
                }
                else
                {
                    entity.ReportDefinitionId = null;
                }

                if (entity.Usage == TemplateUsages.Standalone)
                {
                    entity.IsDeployed   = entity.Roles.Count > 0;
                    entity.Collection   = null;
                    entity.DefinitionId = null;
                }
                else
                {
                    entity.Roles = new List <PrintingTemplateRoleForSave>();
                }

                if (entity.Roles.Count == 0)
                {
                    entity.MainMenuIcon    = null;
                    entity.MainMenuSection = null;
                    entity.MainMenuSortKey = null;
                }
            });

            return(entities);
        }
        protected override async Task <List <NotificationTemplateForSave> > SavePreprocessAsync(List <NotificationTemplateForSave> entities)
        {
            var settings = await _behavior.Settings();

            // Defaults
            entities.ForEach(entity =>
            {
                entity.Parameters ??= new List <NotificationTemplateParameterForSave>();
                entity.Attachments ??= new List <NotificationTemplateAttachmentForSave>();
                entity.Subscribers ??= new List <NotificationTemplateSubscriberForSave>();

                if (!settings.SmsEnabled)
                {
                    entity.Channel = Channels.Email;
                }

                // Useless fields

                if (entity.Cardinality != Cardinalities.Bulk)
                {
                    entity.ListExpression    = null;
                    entity.AddressExpression = null;
                }

                if (entity.Cardinality != Cardinality.Single)
                {
                    entity.MaximumRenotify = null;
                    entity.Subscribers     = new List <NotificationTemplateSubscriberForSave>();
                }

                if (entity.Trigger != Triggers.Automatic)
                {
                    entity.Schedule            = null;
                    entity.ConditionExpression = null;
                    entity.MaximumRenotify     = null;
                }

                if (entity.Trigger != Triggers.Manual)
                {
                    entity.Usage      = null;
                    entity.Parameters = new List <NotificationTemplateParameterForSave>();

                    // Collection, DefinitionId etc... are cleaned down below when Usage is null
                }

                if (entity.Channel != Channels.Email)
                {
                    entity.Subject     = null;
                    entity.Attachments = new List <NotificationTemplateAttachmentForSave>();

                    entity.Subscribers.ForEach(e => e.Email = null);
                }

                if (entity.Channel != Channels.Sms)
                {
                    entity.Subscribers.ForEach(e => e.Phone = null);
                }

                if (entity.Usage == null)
                {
                    // Collection and DefinitionId only make sense when the usage is specified
                    entity.Collection         = null;
                    entity.DefinitionId       = null;
                    entity.ReportDefinitionId = null;
                }

                if (entity.Usage == TemplateUsages.FromDetails || entity.Usage == TemplateUsages.FromSearchAndDetails)
                {
                }

                if (entity.Usage == TemplateUsages.FromReport)
                {
                    entity.Collection   = null;
                    entity.DefinitionId = null;
                }
                else
                {
                    entity.ReportDefinitionId = null;
                }

                // Defaults

                entity.IsDeployed ??= false;
                entity.Parameters.ForEach(p =>
                {
                    p.IsRequired ??= false;
                    p.ControlOptions = ApplicationUtil.PreprocessControlOptions(p.Control, p.ControlOptions, settings);
                });
            });

            return(entities);
        }
Exemplo n.º 3
0
        protected override async Task <List <EmailTemplateForSave> > SavePreprocessAsync(List <EmailTemplateForSave> entities)
        {
            var settings = await _behavior.Settings();

            // Defaults
            entities.ForEach(entity =>
            {
                entity.Parameters ??= new List <EmailTemplateParameterForSave>();
                entity.Attachments ??= new List <EmailTemplateAttachmentForSave>();
                entity.Subscribers ??= new List <EmailTemplateSubscriberForSave>();
                entity.IsDeployed ??= false;
                entity.Parameters.ForEach(p =>
                {
                    p.IsRequired ??= false;
                    p.ControlOptions = ApplicationUtil.PreprocessControlOptions(p.Control, p.ControlOptions, settings);
                });

                // Useless fields

                if (entity.Cardinality != Cardinalities.Multiple)
                {
                    entity.ListExpression = null;
                }

                if (entity.Cardinality != Cardinality.Single)
                {
                    entity.Subscribers = new List <EmailTemplateSubscriberForSave>();
                }

                if (entity.Trigger != Triggers.Automatic)
                {
                    entity.Schedule            = null;
                    entity.ConditionExpression = null;
                }

                if (entity.Trigger != Triggers.Manual)
                {
                    entity.Usage      = null;
                    entity.Parameters = new List <EmailTemplateParameterForSave>();

                    // Collection, DefinitionId etc... are cleaned down below when Usage is null
                }

                if (entity.Usage != TemplateUsages.FromSearchAndDetails && entity.Usage != TemplateUsages.FromDetails)
                {
                    // Collection and DefinitionId only make sense in certain usages
                    entity.Collection   = null;
                    entity.DefinitionId = null;
                }

                if (entity.Usage != TemplateUsages.Standalone)
                {
                    // Parameters are only supported in standalone
                    entity.Parameters = new List <EmailTemplateParameterForSave>();
                }

                if (entity.Usage != TemplateUsages.Standalone || !entity.IsDeployed.Value)
                {
                    entity.MainMenuIcon    = null;
                    entity.MainMenuSection = null;
                    entity.MainMenuSortKey = null;
                }
            });

            return(entities);
        }
Exemplo n.º 4
0
        protected override async Task <List <LineDefinitionForSave> > SavePreprocessAsync(List <LineDefinitionForSave> entities)
        {
            var settings = await _behavior.Settings();

            entities.ForEach(lineDefinition =>
            {
                lineDefinition.AllowSelectiveSigning ??= false;
                lineDefinition.ViewDefaultsToForm ??= false;
                lineDefinition.BarcodeBeepsEnabled ??= false;

                lineDefinition.Columns ??= new List <LineDefinitionColumnForSave>();
                lineDefinition.Entries ??= new List <LineDefinitionEntryForSave>();
                lineDefinition.GenerateParameters ??= new List <LineDefinitionGenerateParameterForSave>();
                lineDefinition.StateReasons ??= new List <LineDefinitionStateReasonForSave>();
                lineDefinition.Workflows ??= new List <WorkflowForSave>();

                lineDefinition?.Columns.ForEach(column =>
                {
                    // Those two are required in the sql table, so they cannot be null
                    if (column.ColumnName == nameof(Entry.CenterId))
                    {
                        column.VisibleState  = LineState.Draft;
                        column.RequiredState = LineState.Draft;
                    }

                    if (column.ColumnName == nameof(Entry.CurrencyId))
                    {
                        column.VisibleState  = LineState.Draft;
                        column.RequiredState = LineState.Draft;
                    }

                    // IMPORTANT: Keep in sync with line-definitions-details.component.ts
                    switch (column.ColumnName)
                    {
                    case nameof(Line.PostingDate):
                    case nameof(Line.Memo):
                    case nameof(Entry.CurrencyId):
                    case nameof(Entry.CenterId):
                    case nameof(Entry.AgentId):
                    case nameof(Entry.ResourceId):
                    case nameof(Entry.NotedAgentId):
                    case nameof(Entry.NotedResourceId):
                    case nameof(Entry.Quantity):
                    case nameof(Entry.UnitId):
                    case nameof(Entry.Time1):
                    case nameof(Entry.Duration):
                    case nameof(Entry.DurationUnitId):
                    case nameof(Entry.Time2):
                    case nameof(Entry.ExternalReference):
                    case nameof(Entry.ReferenceSourceId):
                    case nameof(Entry.InternalReference):
                        break;

                    default:
                        column.InheritsFromHeader = 0;     // Only listed columns can inherit
                        break;
                    }

                    if (column.ColumnName == null || !column.ColumnName.EndsWith("Id"))
                    {
                        column.Filter = null; // Only listed columns can inherit
                    }
                });

                // Generate Parameters
                lineDefinition.GenerateParameters.ForEach(parameter =>
                {
                    parameter.ControlOptions = ApplicationUtil.PreprocessControlOptions(parameter.Control, parameter.ControlOptions, settings);
                });

                // Workflows
                lineDefinition?.Workflows.ForEach(workflow =>
                {
                    workflow?.Signatures?.ForEach(signature =>
                    {
                        if (signature != null)
                        {
                            signature.RuleType ??= RuleTypes.ByRole; // Default

                            if (signature.RuleType != RuleTypes.ByUser)
                            {
                                signature.UserId = null;
                            }

                            if (signature.RuleType != RuleTypes.ByRole)
                            {
                                signature.RoleId = null;
                            }

                            if (signature.RuleType != RuleTypes.ByCustodian)
                            {
                                signature.RuleTypeEntryIndex = null;
                            }

                            if (signature.RuleType == RuleTypes.Public)
                            {
                                signature.ProxyRoleId = null;
                            }

                            if (signature.PredicateType == null)
                            {
                                signature.PredicateTypeEntryIndex = null;
                                signature.Value = null;
                            }
                        }
                    });
                });
            });

            return(entities);
        }
Exemplo n.º 5
0
        protected override async Task <List <ReportDefinitionForSave> > SavePreprocessAsync(List <ReportDefinitionForSave> entities)
        {
            var settings = await _behavior.Settings();

            entities.ForEach(entity =>
            {
                // Makes subsequent code simpler
                entity.Rows ??= new List <ReportDefinitionRowForSave>();
                entity.Rows.ForEach(row => row.Attributes ??= new List <ReportDefinitionDimensionAttributeForSave>());
                entity.Columns ??= new List <ReportDefinitionColumnForSave>();
                entity.Columns.ForEach(col => col.Attributes ??= new List <ReportDefinitionDimensionAttributeForSave>());
                entity.Measures ??= new List <ReportDefinitionMeasureForSave>();
                entity.Select ??= new List <ReportDefinitionSelectForSave>();
                entity.Parameters ??= new List <ReportDefinitionParameterForSave>();
                entity.Roles ??= new List <ReportDefinitionRoleForSave>();

                // Default Values
                if (string.IsNullOrWhiteSpace(entity.Code))
                {
                    entity.Code = Guid.NewGuid().ToString("D");
                }

                // Summary reports
                if (entity.Type == "Summary")
                {
                    if (!(entity.IsCustomDrilldown ?? false))
                    {
                        // Those properties aren't needed
                        entity.Select  = new List <ReportDefinitionSelectForSave>();
                        entity.Top     = null;
                        entity.OrderBy = null;
                    }

                    // Defaults for Show Totals
                    entity.ShowColumnsTotal ??= false;
                    if (entity.Columns.Count == 0)
                    {
                        entity.ShowColumnsTotal = true;
                    }

                    if (!entity.ShowColumnsTotal.Value || entity.Columns.Count == 0)
                    {
                        entity.ColumnsTotalLabel  = null;
                        entity.ColumnsTotalLabel2 = null;
                        entity.ColumnsTotalLabel3 = null;
                    }

                    entity.ShowRowsTotal ??= false;
                    if (entity.Rows.Count == 0)
                    {
                        entity.ShowRowsTotal = true;
                    }

                    if (!entity.ShowRowsTotal.Value || entity.Rows.Count == 0)
                    {
                        entity.RowsTotalLabel  = null;
                        entity.RowsTotalLabel2 = null;
                        entity.RowsTotalLabel3 = null;
                    }
                }

                // Details Report
                if (entity.Type == "Details")
                {
                    // Those properties aren't needed
                    entity.Rows              = new List <ReportDefinitionRowForSave>();
                    entity.Columns           = new List <ReportDefinitionColumnForSave>();
                    entity.Measures          = new List <ReportDefinitionMeasureForSave>();
                    entity.ShowColumnsTotal  = false;
                    entity.ShowRowsTotal     = false;
                    entity.IsCustomDrilldown = false;
                    entity.Having            = null;
                }

                // Defaults to Chart
                if (string.IsNullOrWhiteSpace(entity.Chart))
                {
                    entity.DefaultsToChart = false;
                    entity.ChartOptions    = null;
                }
                else
                {
                    entity.DefaultsToChart ??= true;
                }

                // Main Menu
                if (entity.Roles.Count == 0)
                {
                    entity.MainMenuIcon    = null;
                    entity.MainMenuSection = null;
                    entity.MainMenuSortKey = null;
                }

                // Rows
                entity.Rows.ForEach(row =>
                {
                    if (row.Control != null)
                    {
                        row.ControlOptions = ApplicationUtil.PreprocessControlOptions(row.Control, row.ControlOptions, settings);
                    }
                    else
                    {
                        row.ControlOptions = null;
                    }
                });

                // Columns
                entity.Columns.ForEach(col =>
                {
                    if (col.Control != null)
                    {
                        col.ControlOptions = ApplicationUtil.PreprocessControlOptions(col.Control, col.ControlOptions, settings);
                    }
                    else
                    {
                        col.ControlOptions = null;
                    }
                });

                // Generate Parameters
                entity.Parameters.ForEach(parameter =>
                {
                    if (parameter.Control != null)
                    {
                        parameter.ControlOptions = ApplicationUtil.PreprocessControlOptions(parameter.Control, parameter.ControlOptions, settings);
                    }
                    else
                    {
                        parameter.ControlOptions = null;
                    }
                });

                // Generate Parameters
                entity.Measures.ForEach(measure =>
                {
                    if (measure.Control != null)
                    {
                        measure.ControlOptions = ApplicationUtil.PreprocessControlOptions(measure.Control, measure.ControlOptions, settings);
                    }
                    else
                    {
                        measure.ControlOptions = null;
                    }
                });
            });

            return(entities);
        }