USE [master] GO /****** Object: Database [site_fuchs] Script Date: 15.06.2021 12:30:13 ******/ CREATE DATABASE [site_fuchs] CONTAINMENT = NONE ON PRIMARY ( NAME = N'site_fuchs', FILENAME = N'C:\DATA\MSSQL14.SQL\MSSQL\DATA\site_fuchs.mdf' , SIZE = 4566016KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB ) LOG ON ( NAME = N'site_fuchs_log', FILENAME = N'C:\DATA\MSSQL14.SQL\MSSQL\DATA\site_fuchs_log.ldf' , SIZE = 28333632KB , MAXSIZE = 2048GB , FILEGROWTH = 10%) GO ALTER DATABASE [site_fuchs] SET COMPATIBILITY_LEVEL = 140 GO IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled')) begin EXEC [site_fuchs].[dbo].[sp_fulltext_database] @action = 'enable' end GO ALTER DATABASE [site_fuchs] SET ANSI_NULL_DEFAULT OFF GO ALTER DATABASE [site_fuchs] SET ANSI_NULLS OFF GO ALTER DATABASE [site_fuchs] SET ANSI_PADDING OFF GO ALTER DATABASE [site_fuchs] SET ANSI_WARNINGS OFF GO ALTER DATABASE [site_fuchs] SET ARITHABORT OFF GO ALTER DATABASE [site_fuchs] SET AUTO_CLOSE OFF GO ALTER DATABASE [site_fuchs] SET AUTO_SHRINK OFF GO ALTER DATABASE [site_fuchs] SET AUTO_UPDATE_STATISTICS ON GO ALTER DATABASE [site_fuchs] SET CURSOR_CLOSE_ON_COMMIT OFF GO ALTER DATABASE [site_fuchs] SET CURSOR_DEFAULT GLOBAL GO ALTER DATABASE [site_fuchs] SET CONCAT_NULL_YIELDS_NULL OFF GO ALTER DATABASE [site_fuchs] SET NUMERIC_ROUNDABORT OFF GO ALTER DATABASE [site_fuchs] SET QUOTED_IDENTIFIER OFF GO ALTER DATABASE [site_fuchs] SET RECURSIVE_TRIGGERS OFF GO ALTER DATABASE [site_fuchs] SET DISABLE_BROKER GO ALTER DATABASE [site_fuchs] SET AUTO_UPDATE_STATISTICS_ASYNC OFF GO ALTER DATABASE [site_fuchs] SET DATE_CORRELATION_OPTIMIZATION OFF GO ALTER DATABASE [site_fuchs] SET TRUSTWORTHY OFF GO ALTER DATABASE [site_fuchs] SET ALLOW_SNAPSHOT_ISOLATION OFF GO ALTER DATABASE [site_fuchs] SET PARAMETERIZATION SIMPLE GO ALTER DATABASE [site_fuchs] SET READ_COMMITTED_SNAPSHOT OFF GO ALTER DATABASE [site_fuchs] SET HONOR_BROKER_PRIORITY OFF GO ALTER DATABASE [site_fuchs] SET RECOVERY FULL GO ALTER DATABASE [site_fuchs] SET MULTI_USER GO ALTER DATABASE [site_fuchs] SET PAGE_VERIFY CHECKSUM GO ALTER DATABASE [site_fuchs] SET DB_CHAINING OFF GO ALTER DATABASE [site_fuchs] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF ) GO ALTER DATABASE [site_fuchs] SET TARGET_RECOVERY_TIME = 0 SECONDS GO ALTER DATABASE [site_fuchs] SET DELAYED_DURABILITY = DISABLED GO ALTER DATABASE [site_fuchs] SET QUERY_STORE = OFF GO USE [site_fuchs] GO /****** Object: User [fuchs_web] Script Date: 15.06.2021 12:30:14 ******/ CREATE USER [fuchs_web] FOR LOGIN [fuchs_web] WITH DEFAULT_SCHEMA=[dbo] GO /****** Object: User [fuchs_fds] Script Date: 15.06.2021 12:30:14 ******/ CREATE USER [fuchs_fds] FOR LOGIN [fuchs_fds] WITH DEFAULT_SCHEMA=[dbo] GO /****** Object: DatabaseRole [ocms_rwe] Script Date: 15.06.2021 12:30:14 ******/ CREATE ROLE [ocms_rwe] GO /****** Object: DatabaseRole [fuchs_rwe] Script Date: 15.06.2021 12:30:14 ******/ CREATE ROLE [fuchs_rwe] GO /****** Object: DatabaseRole [fds_rwe] Script Date: 15.06.2021 12:30:14 ******/ CREATE ROLE [fds_rwe] GO ALTER ROLE [ocms_rwe] ADD MEMBER [fuchs_web] GO ALTER ROLE [fuchs_rwe] ADD MEMBER [fuchs_web] GO ALTER ROLE [fds_rwe] ADD MEMBER [fuchs_fds] GO /****** Object: UserDefinedTableType [dbo].[fds__tt__admin_ReportAdminTable] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[fds__tt__admin_ReportAdminTable] AS TABLE( [class] [varchar](255) NULL, [title] [varchar](255) NULL, [label] [varchar](255) NULL, [sublabel] [varchar](255) NULL, [style] [varchar](2000) NULL, [typ] [varchar](10) NULL, [settings] [varchar](2000) NULL, [legend] [nvarchar](max) NULL, [order] [int] NOT NULL, PRIMARY KEY NONCLUSTERED ( [order] ASC )WITH (IGNORE_DUP_KEY = OFF) ) GO /****** Object: UserDefinedTableType [dbo].[fds__tt__idlist] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[fds__tt__idlist] AS TABLE( [Id] [bigint] NULL ) GO /****** Object: UserDefinedTableType [dbo].[fds__tt__invoice_base] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[fds__tt__invoice_base] AS TABLE( [Id] [varchar](10) NULL, [Version] [int] NULL, [InvoiceId] [nvarchar](25) NULL, [InvoiceType] [char](1) NULL, [InvoiceTitle] [varchar](100) NULL, [DocumentName] [nvarchar](255) NULL, [InvoiceBalance] [numeric](10, 3) NULL, [InvoiceBalance_net] [numeric](10, 3) NULL, [InvoiceVAT_net1] [numeric](10, 3) NULL, [InvoiceVAT_1] [numeric](5, 2) NULL, [InvoiceVAT_net2] [numeric](10, 3) NULL, [InvoiceVAT_2] [numeric](5, 2) NULL, [PaymentTerm] [varchar](5) NULL, [DueDate] [date] NULL, [CustomerId] [bigint] NULL, [SendToAddress] [nvarchar](1000) NULL, [SendToEmail] [nvarchar](255) NULL, [ProvisionPeriod] [varchar](50) NULL, [ProvisionLocation] [nvarchar](1000) NULL, [PaymentStatus] [char](1) NULL, [IsPayed] [bit] NULL, [IsSent] [bit] NULL, [IsFinal] [bit] NULL, [IsCanceled] [bit] NULL, [Replaces_InvId] [varchar](10) NULL, [CustomValues] [nvarchar](max) NULL, [DateSent] [datetime] NULL, [DateFinalized] [datetime] NULL, [UserFinalized] [varchar](25) NULL, [DateCancelled] [datetime] NULL, [UserCancelled] [varchar](25) NULL, [DateCreated] [datetime] NULL, [UserCreated] [varchar](25) NULL, [DateModified] [datetime] NULL, [UserModified] [varchar](25) NULL, [hasFile] [bit] NULL, [UserNameFinalized] [nvarchar](255) NULL, [UserEmailFinalized] [varchar](255) NULL, [PaymentTermPhrase] [nvarchar](255) NULL, [InvoiceService] [numeric](10, 3) NULL, [InvoiceService_net] [numeric](10, 3) NULL, [InvoiceService_VAT] [numeric](10, 3) NULL ) GO /****** Object: UserDefinedTableType [dbo].[fds__tt__invoice_items] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[fds__tt__invoice_items] AS TABLE( [Id] [bigint] NULL, [InvId] [varchar](10) NULL, [InvRqId] [bigint] NULL, [mfr__item] [bigint] NULL, [Type] [nvarchar](255) NULL, [Position] [varchar](5) NULL, [Quantity] [nvarchar](25) NULL, [Text] [nvarchar](max) NULL, [value] [numeric](10, 3) NULL, [value_total] [numeric](10, 3) NULL, [vat] [numeric](5, 2) NULL, [value_service] [numeric](10, 3) NULL, [det] [bit] NULL, [SortOrder] [tinyint] NULL ) GO /****** Object: UserDefinedTableType [dbo].[fds__tt__invoice_servicerequests] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[fds__tt__invoice_servicerequests] AS TABLE( [Id] [bigint] NULL, [InvId] [varchar](10) NULL, [mfr__servicerequest] [bigint] NULL, [title] [nvarchar](max) NULL, [value_net] [numeric](10, 3) NULL, [SortOrder] [tinyint] NULL ) GO /****** Object: UserDefinedTableType [dbo].[fds__tt__mfr_items] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[fds__tt__mfr_items] AS TABLE( [Id] [bigint] NULL, [Version] [int] NULL, [QuantityHours] [numeric](10, 3) NULL, [PlannedQuantityHours] [numeric](10, 3) NULL, [ItemTypeId] [bigint] NULL, [ItemNumber] [nvarchar](255) NULL, [TrackingId] [nvarchar](255) NULL, [Manufacture] [nvarchar](255) NULL, [Price] [numeric](10, 3) NULL, [Costs] [numeric](10, 3) NULL, [NameOrNumber] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NULL, [Note] [nvarchar](max) NULL, [ExternalId] [nvarchar](255) NULL, [Discount] [numeric](10, 3) NULL, [VAT] [numeric](10, 3) NULL, [IsManual] [bit] NULL, [SortOrder] [int] NULL, [Type] [nvarchar](255) NULL, [ServiceRequestId] [bigint] NULL, [ServiceObjectId] [bigint] NULL, [CreatorId] [bigint] NULL, [UnitId] [bigint] NULL, [UnitString] [nvarchar](255) NULL, [baseorder] [int] NULL, [order] [int] NULL ) GO /****** Object: UserDefinedTableType [dbo].[fds__tt__mfr_steps] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[fds__tt__mfr_steps] AS TABLE( [Id] [bigint] NOT NULL, [MobileId] [bigint] NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [IsDone] [bit] NOT NULL, [HasError] [bit] NOT NULL, [TrackingId] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [SortOrder] [int] NOT NULL, [Data] [nvarchar](max) NULL, [DateModifiedOffline] [datetime] NULL, [ServiceRequestId] [bigint] NULL, [Description] [nvarchar](max) NULL, [Comment] [nvarchar](max) NULL, [InternalComment] [nvarchar](max) NULL, [ServiceObjectId] [bigint] NULL, [StepListTemplateId] [bigint] NULL, [ParentId] [bigint] NULL, [baseorder] [int] NOT NULL, [order] [int] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__#customvalues] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__#customvalues] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [EntityId] [bigint] NOT NULL, [Property] [varchar](255) NOT NULL, [Meta] [varchar](255) NOT NULL, [Value] [varchar](1000) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__#locations] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__#locations] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [EntityId] [bigint] NULL, [Property] [varchar](255) NOT NULL, [Version] [int] NOT NULL, [AddressString] [nvarchar](255) NULL, [Postal] [nvarchar](255) NULL, [City] [nvarchar](255) NULL, [State] [nvarchar](255) NULL, [Country] [varchar](15) NULL, [Longitude] [numeric](8, 5) NULL, [Latitude] [numeric](8, 5) NULL, [IsValidLocation] [bit] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__*PartnerSet] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__*PartnerSet] AS TABLE( [setid] [varchar](5) NULL, [Property] [varchar](50) NOT NULL, [PartnerType] [varchar](25) NOT NULL, [PartnerId] [bigint] NOT NULL, [EntityId] [bigint] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__appointments] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__appointments] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [State] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [EndDateTime] [datetime] NULL, [StartDateTime] [datetime] NOT NULL, [DrivingDistanceFrom] [int] NULL, [DrivingDistanceTo] [int] NULL, [WasReadOnClientSide] [bit] NOT NULL, [ContactIds] [varchar](max) NULL, [ServiceRequestId] [bigint] NOT NULL, [ContactId] [bigint] NOT NULL, [Note] [nvarchar](max) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__attachments] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__attachments] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [URI] [nvarchar](255) NULL, [StepId] [bigint] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__comments] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__comments] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [DateOfCreation] [datetime] NOT NULL, [IsInternal] [bit] NOT NULL, [ServiceRequestId] [bigint] NOT NULL, [CompanyId] [bigint] NOT NULL, [Content] [nvarchar](max) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__companies] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__companies] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Location#ID] [bigint] NULL, [Version] [int] NOT NULL, [IsPhysicalPerson] [bit] NOT NULL, [IsOwner] [bit] NOT NULL, [IsEmailInvoicingActive] [bit] NOT NULL, [IsSupplier] [bit] NOT NULL, [MappingId] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [Name] [nvarchar](255) NULL, [Note] [nvarchar](255) NULL, [SupportTelephone] [nvarchar](255) NULL, [SupportFax] [nvarchar](255) NULL, [SupportMail] [nvarchar](255) NULL, [QuickSearch] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [MainContactId] [bigint] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__contacts] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__contacts] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [FirstName] [nvarchar](255) NULL, [LastName] [nvarchar](255) NULL, [Email] [nvarchar](255) NULL, [JobTitle] [nvarchar](255) NULL, [MobilePhone] [nvarchar](255) NULL, [Telephone] [nvarchar](255) NULL, [Fax] [nvarchar](255) NULL, [Note] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [Version] [int] NOT NULL, [CompanyId] [bigint] NOT NULL, [IsUser] [bit] NOT NULL, [ExternalId] [nvarchar](255) NULL, [Gender] [nvarchar](255) NULL, [UserId] [bigint] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__costcenters] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__costcenters] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__documents] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__documents] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [Version] [int] NOT NULL, [State] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [URI] [nvarchar](255) NULL, [IsGlobal] [bit] NOT NULL, [StartDateTime] [datetime] NULL, [EndDateTime] [datetime] NULL, [FileName] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [UploadDate] [datetime] NOT NULL, [IsLink] [bit] NOT NULL, [ContentType] [nvarchar](255) NULL, [HTMLCode] [nvarchar](255) NULL, [ServiceRequestId] [bigint] NOT NULL, [Note] [nvarchar](255) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__items] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__items] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [QuantityHours] [numeric](10, 3) NOT NULL, [PlannedQuantityHours] [numeric](10, 3) NOT NULL, [ItemTypeId] [bigint] NULL, [ItemNumber] [nvarchar](255) NULL, [TrackingId] [nvarchar](255) NULL, [Manufacture] [nvarchar](255) NULL, [Price] [numeric](10, 3) NOT NULL, [Costs] [numeric](10, 3) NULL, [NameOrNumber] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NULL, [Note] [nvarchar](max) NULL, [ExternalId] [nvarchar](255) NULL, [Discount] [numeric](10, 3) NOT NULL, [VAT] [numeric](10, 3) NOT NULL, [IsManual] [bit] NOT NULL, [SortOrder] [int] NOT NULL, [Type] [nvarchar](255) NULL, [ServiceRequestId] [bigint] NOT NULL, [ServiceObjectId] [bigint] NOT NULL, [CreatorId] [bigint] NOT NULL, [UnitId] [bigint] NULL, [UnitString] [nvarchar](255) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__itemtypes] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__itemtypes] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [Version] [int] NOT NULL, [Costs] [numeric](10, 3) NOT NULL, [Description] [nvarchar](max) NULL, [ListPrice] [numeric](10, 3) NOT NULL, [Manufacture] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [ItemNumber] [nvarchar](255) NULL, [NameOrNumber] [nvarchar](1000) NULL, [GlobalTradeItemNr] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [Price] [numeric](10, 3) NOT NULL, [VAT] [numeric](10, 3) NOT NULL, [IsPortalOnly] [bit] NOT NULL, [Discount] [numeric](10, 3) NOT NULL, [DateModified] [datetime] NOT NULL, [IsDiscontinued] [bit] NOT NULL, [IsWarehouse] [bit] NOT NULL, [UnitId] [bigint] NULL, [UnitString] [nvarchar](255) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__itemunits] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__itemunits] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__products] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__products] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [SubKey] [nvarchar](255) NULL, [Description] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [MappingId] [nvarchar](255) NULL, [CustomValueStepTemplateId] [bigint] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__qualifications] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__qualifications] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__reports] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__reports] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [DateOfCreation] [datetime] NOT NULL, [URI] [nvarchar](255) NULL, [DocumentName] [nvarchar](255) NULL, [FileTypeString] [nvarchar](255) NULL, [ReportDefinitionCode] [nvarchar](255) NULL, [ServiceObjectId] [bigint] NOT NULL, [CanBeDeleted] [bit] NOT NULL, [InvoiceBalance] [numeric](10, 3) NOT NULL, [InvoiceId] [nvarchar](255) NULL, [DueDate] [datetime] NOT NULL, [IsPayed] [bit] NOT NULL, [IsInvoice] [bit] NOT NULL, [IsCanceled] [bit] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__serviceobjects] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__serviceobjects] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Location#ID] [bigint] NULL, [Name] [nvarchar](255) NULL, [Note] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NOT NULL, [DateModified] [datetime] NOT NULL, [ExternalId] [nvarchar](255) NULL, [MappingId] [nvarchar](255) NULL, [QuickSearch] [nvarchar](255) NULL, [Version] [int] NOT NULL, [CreateGeoLocation] [bit] NOT NULL, [IsWarehouse] [bit] NOT NULL, [ParentServiceObjectId] [bigint] NOT NULL, [CompanyId] [bigint] NOT NULL, [ProductId] [bigint] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__servicerequests] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__servicerequests] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Name] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [InvoiceId] [nvarchar](255) NULL, [ClosedAt] [datetime] NULL, [ReleasedAt] [datetime] NULL, [WorkDoneAt] [datetime] NULL, [TargetTimeInMinutes] [bigint] NOT NULL, [DateModified] [datetime] NULL, [DateOfCreation] [datetime] NULL, [DueDateRangeStart] [datetime] NULL, [DueDateRangeEnd] [datetime] NULL, [PortalLink] [nvarchar](255) NULL, [CostCenterId] [bigint] NULL, [Description] [nvarchar](max) NULL, [State] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NOT NULL, [CurrentOwnerId] [bigint] NULL, [CustomerId] [bigint] NULL, [ParentServiceRequestId] [bigint] NULL, [Location#ID] [bigint] NULL, [Version] [int] NOT NULL, [IsTemplate] [bit] NOT NULL, [IsTemplateMobile] [bit] NOT NULL, [CreateFromServiceRequestTemplateId] [bigint] NOT NULL, [Type] [nvarchar](255) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__steplisttemplateinstances] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__steplisttemplateinstances] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [ServiceRequestId] [bigint] NULL, [TemplateId] [bigint] NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__steplisttemplates] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__steplisttemplates] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [MappingId] [nvarchar](255) NULL, [DateModified] [datetime] NULL, [IsReleased] [bit] NOT NULL, [IsDurable] [bit] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__steps] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__steps] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [MobileId] [bigint] NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [IsDone] [bit] NOT NULL, [HasError] [bit] NOT NULL, [TrackingId] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [SortOrder] [int] NOT NULL, [Data] [nvarchar](max) NULL, [DateModifiedOffline] [datetime] NULL, [ServiceRequestId] [bigint] NULL, [Description] [nvarchar](max) NULL, [Comment] [nvarchar](max) NULL, [InternalComment] [nvarchar](max) NULL, [ServiceObjectId] [bigint] NULL, [StepListTemplateId] [bigint] NULL, [ParentId] [bigint] NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__stockmovements] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__stockmovements] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Amount] [numeric](10, 3) NOT NULL, [AmountReceived] [numeric](10, 3) NOT NULL, [ExternalId] [varchar](255) NULL, [ItemId] [bigint] NULL, [ItemTypeId] [bigint] NULL, [StockMovementType] [varchar](255) NULL, [State] [varchar](255) NULL, [ServiceRequestId] [bigint] NOT NULL, [WarehouseId] [bigint] NOT NULL, [DateOfCreation] [datetime] NOT NULL, [DateModified] [datetime] NOT NULL, [TargetDate] [datetime] NOT NULL, [CreatedById] [bigint] NOT NULL, [ConfirmedById] [bigint] NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__tags] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__tags] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [ColorDefinition] [nvarchar](255) NULL, [Type] [nvarchar](255) NOT NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__timeevents] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__timeevents] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [State] [nvarchar](255) NULL, [IsApproved] [bit] NOT NULL, [TimeEventType] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [StartDateTime] [datetime] NOT NULL, [EndDateTime] [datetime] NOT NULL, [ProposedDrivingDistance] [int] NOT NULL, [ContactId] [bigint] NOT NULL, [ServiceRequestId] [bigint] NOT NULL, [Description] [nvarchar](max) NULL ) GO /****** Object: UserDefinedTableType [dbo].[mfr__tt__users] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[mfr__tt__users] AS TABLE( [setid] [varchar](5) NULL, [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [UserName] [nvarchar](255) NULL, [IsSystem] [bit] NOT NULL, [CreationDate] [datetime] NOT NULL, [IsApproved] [bit] NOT NULL, [ContactId] [bigint] NOT NULL, [PreferedLanguage] [nvarchar](255) NULL, [EmailChannelEnabled] [bit] NOT NULL, [HasFullScreenPreference] [bit] NOT NULL, [TimeZone] [int] NOT NULL, [PreferedCulture] [nvarchar](255) NULL, [IsActive] [bit] NOT NULL, [IsMobile] [bit] NOT NULL, [LastLoginDate] [datetime] NULL, [UserGuideProgress] [nvarchar](255) NULL, [DashboardSettings] [nvarchar](4000) NULL ) GO /****** Object: UserDefinedTableType [dbo].[ocms_type_itemtree] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[ocms_type_itemtree] AS TABLE( [ocms_iid] [bigint] NOT NULL, [parent_iid] [bigint] NULL, [ocms_pid] [bigint] NULL, [name] [nvarchar](255) NULL, [view] [bit] NOT NULL, [template_id] [bigint] NULL, [hide] [bit] NOT NULL, [order] [int] NOT NULL, [DateCreated] [datetime] NULL, [DateModified] [datetime] NULL, [level] [int] NULL, [sub] [bit] NULL, [sitepropsub] [bit] NULL, [focus] [bit] NULL, [new_order] [int] NULL ) GO /****** Object: UserDefinedTableType [dbo].[ocms_type_navigation_base] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[ocms_type_navigation_base] AS TABLE( [ocms_iid] [bigint] NOT NULL, [locale] [varchar](5) NOT NULL, [alias] [varchar](25) NULL ) GO /****** Object: UserDefinedTableType [dbo].[ocms_type_properties_base] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[ocms_type_properties_base] AS TABLE( [ocms_iid] [bigint] NOT NULL, [key] [varchar](50) NULL, [value] [nvarchar](max) NOT NULL, [locale] [varchar](5) NULL ) GO /****** Object: UserDefinedTableType [dbo].[ocms_type_viewtree_full] Script Date: 15.06.2021 12:30:14 ******/ CREATE TYPE [dbo].[ocms_type_viewtree_full] AS TABLE( [ocms_iid] [bigint] NOT NULL, [parent_iid] [bigint] NULL, [ocms_pid] [bigint] NULL, [name] [nvarchar](255) NULL, [view] [bit] NOT NULL, [template_id] [bigint] NULL, [hide] [bit] NOT NULL, [order] [int] NOT NULL, [DateCreated] [datetime] NULL, [DateModified] [datetime] NULL, [locale] [varchar](5) NOT NULL, [alias] [varchar](25) NULL, [path] [varchar](2000) NULL, [level] [int] NULL, [sub] [bit] NULL, [focus] [bit] NULL, [nav] [bit] NULL, [new_order] [int] NULL ) GO /****** Object: UserDefinedFunction [dbo].[AddBusinessDays] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION[dbo].[AddBusinessDays](@Date DATE,@n INT) RETURNS DATE AS BEGIN DECLARE @d INT,@f INT,@DW INT; SET @f=CAST(abs(1^SIGN(DATEPART(DW, @Date)-(7-@@DATEFIRST))) AS BIT) SET @DW=DATEPART(DW,@Date)-(7-@@DATEFIRST)*(@f^1)+@@DATEFIRST*(@f&1) SET @d=4-SIGN(@n)*(4-@DW); RETURN DATEADD(D,@n+((ABS(@n)+(@d%(8+SIGN(@n)))-2)/5)*2*SIGN(@n)-@d/7,@Date); END GO /****** Object: UserDefinedFunction [dbo].[date_addcustom] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[date_addcustom] ( @date date ,@phrase varchar(10) ) RETURNS date AS BEGIN DECLARE @returndate date, @numpart integer = TRY_PARSE(left(@phrase, patindex('%[^0-9]%', @phrase + '.') - 1) as integer), @defpart varchar(10) = LOWER(RIGHT(@phrase, LEN(@phrase) - patindex('%[^0-9]%', @phrase + '.') + 1)); SET @returndate = CASE WHEN @numpart is null then null WHEN @defpart = 'wd' THEN [dbo].[AddBusinessDays](@date, @numpart) WHEN @defpart = 'd' THEN DATEADD(DAY, @numpart, @date) WHEN @defpart = 'y' THEN DATEADD(YEAR, @numpart, @date) WHEN @defpart = 'm' THEN DATEADD(Month, @numpart, @date) WHEN @defpart = 'wk' THEN DATEADD(WEEK, @numpart, @date) ELSE @date END; RETURN @returndate; END GO /****** Object: UserDefinedFunction [dbo].[date_monthend] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[date_monthend] ( @date date ) RETURNS date AS BEGIN DECLARE @monthend date = CASE WHEN @date is null THEN NULL ELSE DATEADD(DAY, -1, DATEADD(MONTH, 1, DATEFROMPARTS(YEAR(@date), MONTH(@date),1))) END; return @monthend; END GO /****** Object: UserDefinedFunction [dbo].[date_monthfirst] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[date_monthfirst] ( @date date ) RETURNS date AS BEGIN DECLARE @monthfirst date = CASE WHEN @date is null THEN NULL ELSE DATEFROMPARTS(YEAR(@date), MONTH(@date), 1) END; return @monthfirst; END GO /****** Object: UserDefinedFunction [dbo].[date_weekend] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Dr. Stefan Ott -- Create date: 31.01.2013 -- Description: first day of week -- ============================================= CREATE FUNCTION [dbo].[date_weekend] ( @TargetDate date ) RETURNS date AS BEGIN DECLARE @Corretor smallint = -((@@DATEFIRST % 7) - 1); DECLARE @ret date = CASE WHEN @TargetDate is null THEN null ELSE dateadd(d ,-((datepart(weekday,@TargetDate) - 1 - @Corretor)%7), @TargetDate) END; return DATEADD(DAY, 6, @ret); END GO /****** Object: UserDefinedFunction [dbo].[date_weekfirst] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Dr. Stefan Ott -- Create date: 31.01.2013 -- Description: first day of week -- ============================================= CREATE FUNCTION [dbo].[date_weekfirst] ( @TargetDate date ) RETURNS date AS BEGIN DECLARE @Corretor smallint = -((@@DATEFIRST % 7) - 1); DECLARE @ret date = CASE WHEN @TargetDate is null THEN null ELSE dateadd(d ,-((datepart(weekday,@TargetDate) - 1 - @Corretor)%7), @TargetDate) END; return @ret; END GO /****** Object: UserDefinedFunction [dbo].[fds__fn_combineAddress] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fds__fn_combineAddress] ( @AddressString nvarchar(255) ,@AddressString2 nvarchar(255) ,@AddressString3 nvarchar(255) ,@Postal nvarchar(255) ,@City nvarchar(255) ,@State nvarchar(255) ,@Country nvarchar(255) ) RETURNS nvarchar(1000) AS BEGIN DECLARE @address nvarchar(1000) = STUFF( (SELECT (CHAR(10) + [t]) as [text()] FROM (SELECT * FROM (VALUES(@AddressString), (@AddressString2), (@AddressString3), (LTRIM(RTRIM(ISNULL(@postal, '') + ' ' + ISNULL(@city, '')))), (@state), (@country)) z ([t]) WHERE ISNULL([t], '') <> '')y FOR XML PATH , TYPE).value('.[1]','nvarchar(1000)') , 1, 1, ''); RETURN @address; END GO /****** Object: UserDefinedFunction [dbo].[fds__fn_DocumentName] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fds__fn_DocumentName] ( @InvoiceId varchar(10) , @InvoiceType char(1) , @InvoiceTitle varchar(100) , @DateFinalized datetime ) RETURNS varchar(50) AS BEGIN DECLARE @doc varchar(50); SET @doc = CASE WHEN @DateFinalized is null THEN '' WHEN ISNULL(@InvoiceTitle,'') <> '' THEN @InvoiceTitle + ' ' + @InvoiceId WHEN @InvoiceType = 'a' THEN 'Abschlagsrechnung ' + @InvoiceId WHEN @InvoiceType = 'c' THEN 'Stornorechnung ' + @InvoiceId WHEN @InvoiceType = 'f' THEN 'Schlussrechnung ' + @InvoiceId ELSE 'Rechnung ' + @InvoiceId END; RETURN @doc + '.pdf'; END GO /****** Object: UserDefinedFunction [dbo].[fds__fn_invoice_id] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[fds__fn_invoice_id] ( ) RETURNS varchar(8) AS BEGIN DECLARE @NewAccount varchar(5) = [dbo].[ocms_fn_generatePassword] (8,0,1,0); WHILE EXISTS( SELECT * FROM [dbo].[fds__invoices] WHERE [id] = @NewAccount) BEGIN SET @NewAccount = [dbo].[ocms_fn_generatePassword] (8,0,1,0); END RETURN @NewAccount; END; GO /****** Object: UserDefinedFunction [dbo].[fds__fn_InvoiceIDs_mfr] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fds__fn_InvoiceIDs_mfr] ( @invoiceid varchar(255), @other varchar(1000) ) RETURNS varchar(1000) AS BEGIN DECLARE @RET varchar(1000) = REPLACE(LTRIM(ISNULL(@invoiceid,'')),'Preview',''); IF @RET <> '' SET @RET = TRIM(REPLACE(@RET, ' ', ' ')); IF @RET <> '' SET @RET = REPLACE(@RET, ' ',' (mfr)' + CHAR(10)) + ' (mfr)'; IF @RET <> '' AND ISNULL(@other, '') <> '' SET @RET = @RET + CHAR(10); SET @RET = @RET + ISNULL(@other, ''); RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[fds__getCompanyAddress] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fds__getCompanyAddress] ( @companyid bigint ) RETURNS nvarchar(1000) AS BEGIN DECLARE @locationid bigint, @address nvarchar(1000); SELECT TOP(1) @locationid = cy.[Location#ID] from [dbo].[mfr__companies] as cy WHERE cy.id = @companyid; IF @locationid is null SELECT TOP(1) @locationid = l.[ID], @address = [dbo].[fds__fn_combineAddress] (l.[AddressString], null, null ,l.[Postal] ,l.[City] ,l.[State] ,l.[Country]) FROM [mfr__#locations] as l JOIN [dbo].[mfr__companies] as cy on l.[Property] = 'Company:Location' AND l.[EntityId] = cy.[Id] WHERE cy.[id] = @companyid; -- Return the result of the function IF @address is null SELECT TOP(1) @address = [dbo].[fds__fn_combineAddress] (loc.[AddressString], null, null ,loc.[Postal] ,loc.[City] ,loc.[State] ,loc.[Country]) FROM [dbo].[mfr__#locations] as loc WHERE [id] = @locationid; RETURN @address; END GO /****** Object: UserDefinedFunction [dbo].[fds__getUpdateableTables] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fds__getUpdateableTables] ( ) RETURNS @RET TABLE ( [entity_name] varchar(255) ,[table_name] varchar(255) ,[proc_name] varchar(255) ,[locked] bit ,[locked_reset] bit ,[updateneed] tinyint ,[datebased] bit ) AS BEGIN DECLARE @threshold_minutes_full int = 60, @threshold_minutes_short int = 8; DECLARE @utcnow datetime = GETUTCDATE(); DECLARE @UTCTimeInMinutes int = DATEDIFF(MINUTE, CAST(CAST(@utcnow as date) as datetime), @utcnow); DECLARe @AS XML = [dbo].[mfr__schema](); DECLARE @EntityTypes TABLE([#] int, [typ] varchar(50), [name] varchar(255), [set] varchar(255), [EntitySet] varchar(255), [tablename] varchar(255), [url] varchar(500), [DateColumn] varchar(25)); WITH XMLNAMESPACES ( 'http://schemas.microsoft.com/ado/2007/06/edmx' as edmx, 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' as m ), et as ( SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) as '#' , xD.value('local-name(.)', 'varchar(50)') as [type] , xD.value('@Name', 'varchar(255)') as [EntityType] --, xD.query('.') as 'q' , xS.value('@Name', 'varchar(255)') as [Set] , o.[name] as [tablename] from @as.nodes('/Schema[1]/EntityType') as xm(xD) JOIN @as.nodes('/Schema/EntityContainer/EntitySet') as xn(xS) ON (xS.value('@EntityType', 'varchar(255)')) like ('MFR.%[.]' + (xD.value('@Name', 'varchar(255)'))) JOIN sys.objects as o ON o.[name] like ('mfr__' + (LOWER(xS.value('@Name', 'varchar(255)')))) union SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) as '#' , xD.value('local-name(.)', 'varchar(50)') as [type] , xD.value('@Name', 'varchar(255)') as [EntityType] --, xD.query('.') as 'q' , '' as [Set] , o.[name] as [tablename] from @as.nodes('/Schema[1]/ComplexType') as xm(xD) JOIN sys.objects as o ON o.[name] like ('mfr__[#]' + (LOWER(xD.value('@Name', 'varchar(255)'))) + 's') ) INSERT INTO @EntityTypes SELECT [#],[type],[EntityType],[set] = LOWER([set]), [EntitySet] = [set], [tablename], null, null FROM et; WITH tbl as( SELECT --QUOTENAME(SCHEMA_NAME(sOBJ.schema_id)) + '.' + QUOTENAME(sOBJ.[name]) AS [TABLE_NAME] sOBJ.[name] AS [TABLE_NAME] , SUM(sPTN.Rows) AS [RowCount] ,sOBJ.[create_date] FROM sys.objects AS sOBJ INNER JOIN sys.partitions AS sPTN ON sOBJ.object_id = sPTN.object_id AND sOBJ.[name] like 'mfr__%' WHERE sOBJ.[type] = 'U' AND sOBJ.is_ms_shipped = 0x0 AND index_id < 2 -- 0:Heap, 1:Clustered GROUP BY sOBJ.schema_id , sOBJ.name , sObj.[create_date] ), pro as (SELECT * FROM sys.procedures WHERE LEFT([name], 11) = 'mfr__updt__') , lu as (SELECT [table], MAX([timestamp]) as 'lu' FROM [dbo].[fds__status] WHERE [action] like 'update%' group by [table]) , luf as (SELECT [table], MAX([timestamp]) as 'luf' FROM [dbo].[fds__status] WHERE [action] like 'update_full' group by [table]) , lur as (SELECT [table], MAX([timestamp]) as 'lur' FROM [dbo].[fds__status] WHERE [action] like 'update_reset' group by [table]) , luc as (SELECT lu.[table], [lu], [luf], [lur] , DATEDIFF(MINUTE, [lu], @utcnow) as [dlu] , DATEDIFF(MINUTE, [lur], @utcnow) as [dlr] , DATEDIFF(MINUTE, [luf], @utcnow) as [dluf] , CASE --WHEN [dbo].[ctm__getUpdateLockStatus] () = Cast(1 as bit) THEN 0 WHEN [lu] is null then 5 --WHEN DATEDIFF(MINUTE, [lu], @utcnow) > @threshold_minutes_full -- OR DATEDIFF(MINUTE, [luf], @utcnow) > @threshold_minutes_full -- THEN 2 WHEN DATEDIFF(MINUTE, [lu], @utcnow) > @threshold_minutes_short THEN 1 ELSE 0 END as 'need' from lu LEFT JOIN luf on lu.[table] = luf.[table] LEFT JOIN lur on lu.[table] = lur.[table] ), cols as (SELECT DISTINCT [TABLE_NAME] FROM INFORMATION_SCHEMA.COLUMNS WHERE LEFT(TABLE_NAME, 5) = N'mfr__' AND ([column_name] COLLATE Latin1_General_CI_AS in ('DateModified', 'DateCreated', 'DateOfCreation'))) INSERT INTO @RET SELECT DISTINCT [entity_name] = et.[name] , 'table_name' = tbl.[table_name] , 'temp_table' = pro.[name] , 'locked' = 0 --ISNULL([dbo].[ctm__getUpdateLockStatus_tbl](REPLACE(tbl.[TABLE_NAME], 'mfr__', '')), 0) , 'locked_reset' = 0 --ISNULL([dbo].[ctm__getUpdateLockStatus_reset_tbl](REPLACE(tbl.[TABLE_NAME], 'mfr__', '')), 0) , 'updateneed' = CASE --WHEN [dbo].[ctm__getUpdateLockStatus_tbl](REPLACE(tbl.[TABLE_NAME], 'mfr__', '')) = Cast(1 as bit) THEN 0 WHEN et.[name] COLLATE Latin1_General_CI_AS IN ('Attachment','Comment','Item','StepListTemplateInstance','Step') THEN 0 WHEN tbl.[RowCount] = 0 THEN 5 WHEN NOT EXISTS (SELECT * FROM cols WHERE tbl.[TABLE_NAME] = cols.[TABLE_NAME]) THEN 0 WHEN luc.need is null then 5 WHEN tbl.[TABLE_NAME] COLLATE Latin1_General_CI_AS in ('') AND ISNULL(luc.[dlr], 1440) >= 720 AND @UTCTimeInMinutes BETWEEN 45 AND 90 THEN 5 -- once every day, between 02:45 and 03:30 in the morning ELSE luc.[need]--ISNULL(luc.[need], 0) END , 'datebased' = CASE WHEN EXISTS (SELECT * FROM cols WHERE tbl.[TABLE_NAME] = cols.[TABLE_NAME]) THEN 1 ELSE 0 END FROM tbl JOIN @EntityTypes as et on tbl.[TABLE_NAME] = et.[tablename] JOIN pro on REPLACE(pro.[name], 'mfr__updt__', 'mfr__') = tbl.[TABLE_NAME] LEFT JOIN luc on tbl.[table_name] = luc.[table]; RETURN END GO /****** Object: UserDefinedFunction [dbo].[fds__newInvoiceId] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fds__newInvoiceId] ( @year int ) RETURNS varchar(25) AS BEGIN DECLARE @invoice_id varchar(25) = 'R' + CAST(@year as varchar(4)) + '-' + FORMAT(ISNULL( (SELECT MAX( TRY_PARSE(RIGHT([InvoiceId], 4) as integer) ) FROM [dbo].[fds__invoices] WHERE LEFT(ISNULL([InvoiceId],''),5) = ('R' + CAST(@year as varchar(4))) ) , 0) + 1, '0000'); RETURN @invoice_id; END GO /****** Object: UserDefinedFunction [dbo].[fds__updateNeed] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[fds__updateNeed] ( @threshold_minutes_full int ,@threshold_minutes_short int ) RETURNS tinyint AS BEGIN --[Reset] = 5 -- [Full] = 2 -- [Short] = 1 -- [None] = 0 SET @threshold_minutes_full = 60; SET @threshold_minutes_short = 8; DECLARE @RET tinyint = 1 DECLARE @UpDate datetime DECLARE @UpDateFull datetime RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_authenticate] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_authenticate] ( @email varchar(255), @password nvarchar(20) ) RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(100) null, [firstname] nvarchar(100) null, [email] varchar(255) NULL, [mobile] varchar(50) null, [functions] varchar(1000), [language] varchar(2), [fullname] nvarchar(255) null, [fullname_rev] nvarchar(255) null) AS BEGIN DECLARE @auth smallint = -1; DECLARE @useraccount_id varchar(10), @name nvarchar(255), @mobile varchar(50), @functions varchar(1000) = ''; SELECT TOP(1) @useraccount_id = [useraccount_id] FROM [dbo].[fis_useraccounts] as ua WHERE ua.[DateDeleted] is null AND ua.[DateDisabled] is null AND CAST(DECRYPTBYKEY(ua.[email_enc]) as varchar(255)) = @email AND @email <> '' AND CAST(DECRYPTBYKEY(ua.[password_enc]) as nvarchar(20)) = @password AND @password <> '' AND ua.[password_enc] is not null; INSERT INTO @RET SELECT * FROM [dbo].[fis_admin_getUserAccount](@useraccount_id); RETURN; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_checkUserExists] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_checkUserExists] ( @useraccount_id varchar(5) ) RETURNS bit AS BEGIN DECLARE @RET bit; SET @RET = IIF(EXISTS (SELECT * FROM [dbo].[fis_useraccounts] as ua WHERE [useraccount_id] = @useraccount_id AND ua.[DateDeleted] is null AND ua.[DateDisabled] is null), 1, 0); RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserAccount] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserAccount] ( @useraccount_id varchar(5) ) RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(100) null, [firstname] nvarchar(100) null, [email] varchar(255) NULL, [mobile] varchar(50) null, [functions] varchar(1000), [language] varchar(2), [fullname] nvarchar(255) null, [fullname_rev] nvarchar(255) null) AS BEGIN DECLARE @auth smallint = -1; DECLARE @email varchar(255), @name nvarchar(100), @firstname nvarchar(100), @mobile varchar(50), @functions varchar(1000) = '', @title varchar(50), @gender varchar(1), @password varchar(5), @language varchar(2), @fullname nvarchar(255), @fullname_rev nvarchar(255); SELECT TOP(1) @useraccount_id = [useraccount_id] ,@auth = CASE WHEN [useraccount_id] is null THEN -1 ELSE 1 END ,@name = CAST(DECRYPTBYKEY(ua.[name_enc]) as nvarchar(100)) ,@firstname = CAST(DECRYPTBYKEY(ua.[firstname_enc]) as nvarchar(100)) ,@title = CAST(DECRYPTBYKEY(ua.[title_enc]) as varchar(50)) ,@gender = CAST(DECRYPTBYKEY(ua.[gender_enc]) as varchar(1)) --,@password = DECRYPTBYKEY(ua.[password_enc]) ,@email = CAST(DECRYPTBYKEY(ua.[email_enc]) as varchar(255)) ,@mobile = CAST(DECRYPTBYKEY(ua.[mobile_enc]) as varchar(50)) ,@language = ua.[language] ,@fullname = [dbo].[fis_admin_getUserName](ua.[name_enc], ua.[firstname_enc], ua.[title_enc]) ,@fullname_rev = [dbo].[fis_admin_getUserName_rev](ua.[name_enc], ua.[firstname_enc], ua.[title_enc]) FROM [dbo].[fis_useraccounts] as ua WHERE ua.[DateDeleted] is null AND ua.[DateDisabled] is null AND ua.[useraccount_id] = @useraccount_id; SET @auth = ISNULL(TRY_CAST((SELECT TOP(1) [value] FROM [fis_useraccounts_settings] WHERE [useraccount_id] = @useraccount_id and [key] = 'intranet_admin') as smallint), @auth); SET @functions = STUFF( (SELECT ',' + [value] as [text()] FROM [fis_useraccounts_settings] WHERE [useraccount_id] = @useraccount_id and [key] = 'intranet_function' FOR XML PATH(''), TYPE).value('.','nvarchar(max)') , 1,1,''); INSERT INTO @RET VALUES( @useraccount_id ,IIF(@useraccount_id is null, -1, @auth) ,IIF(@useraccount_id is null, null, @name) ,IIF(@useraccount_id is null, null, @firstname) ,IIF(@useraccount_id is null, null, @email) ,IIF(@useraccount_id is null, null, @mobile) ,IIF(@useraccount_id is null, null, @functions) ,IIF(@useraccount_id is null, null, @language) ,IIF(@useraccount_id is null, null, @fullname) ,IIF(@useraccount_id is null, null, @fullname_rev) ); RETURN; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserAccount_byemail] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserAccount_byemail] ( @email varchar(255) ,@include_password bit = 0 ) RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(100) null, [firstname] nvarchar(100) null, [title] varchar(50) null, [gender] varchar(1) NULL, [email] varchar(255) NULL, [mobile] varchar(50) null, [password] nvarchar(25) null, [functions] varchar(1000), [language] varchar(2) , [fullname] nvarchar(255) null, [fullname_rev] nvarchar(255) null ) AS BEGIN DECLARE @auth smallint = -1; DECLARE @useraccount_id varchar(5), @name nvarchar(100), @firstname nvarchar(100), @mobile varchar(50), @functions varchar(1000) = '', @title varchar(50), @gender varchar(1), @password varchar(25), @language varchar(2), @fullname nvarchar(255), @fullname_rev nvarchar(255); SELECT TOP(1) @useraccount_id = [useraccount_id] ,@auth = CASE WHEN [useraccount_id] is null THEN -1 ELSE 1 END ,@name = CAST(DECRYPTBYKEY(ua.[name_enc]) as nvarchar(100)) ,@firstname = CAST(DECRYPTBYKEY(ua.[firstname_enc]) as nvarchar(100)) ,@title = CAST(DECRYPTBYKEY(ua.[title_enc]) as varchar(50)) ,@gender = CAST(DECRYPTBYKEY(ua.[gender_enc]) as varchar(1)) ,@password = IIF(ISNULL(@include_password,0) = 1, CAST(DECRYPTBYKEY(ua.[password_enc]) as nvarchar(25)) , null) ,@email = CAST(DECRYPTBYKEY(ua.[email_enc]) as varchar(255)) ,@mobile = CAST(DECRYPTBYKEY(ua.[mobile_enc]) as varchar(50)) ,@language = ua.[language] ,@fullname = [dbo].[fis_admin_getUserName](ua.[name_enc], ua.[firstname_enc], ua.[title_enc]) ,@fullname_rev = [dbo].[fis_admin_getUserName_rev](ua.[name_enc], ua.[firstname_enc], ua.[title_enc]) FROM [dbo].[fis_useraccounts] as ua WHERE ua.[DateDeleted] is null AND ua.[DateDisabled] is null AND LOWER(RTRIM(CAST(DECRYPTBYKEY(ua.[email_enc]) as varchar(255)))) = LOWER(RTRIM(@email)); SET @auth = ISNULL(TRY_CAST((SELECT TOP(1) [value] FROM [fis_useraccounts_settings] WHERE [useraccount_id] = @useraccount_id and [key] = 'intranet_admin') as smallint), @auth); SET @functions = STUFF( (SELECT ',' + [value] as [text()] FROM [fis_useraccounts_settings] WHERE [useraccount_id] = @useraccount_id and [key] = 'intranet_function' FOR XML PATH(''), TYPE).value('.','nvarchar(max)') , 1,1,''); INSERT INTO @RET VALUES( @useraccount_id ,IIF(@useraccount_id is null, -1, @auth) ,IIF(@useraccount_id is null, null, @name) ,IIF(@useraccount_id is null, null, @firstname) ,IIF(@useraccount_id is null, null, @title) ,IIF(@useraccount_id is null, null, @gender) ,IIF(@useraccount_id is null, null, @email) ,IIF(@useraccount_id is null, null, @mobile) ,IIF(@useraccount_id is null, null, @password) ,IIF(@useraccount_id is null, null, @functions) ,IIF(@useraccount_id is null, null, @language) ,IIF(@useraccount_id is null, null, @fullname) ,IIF(@useraccount_id is null, null, @fullname_rev) ); RETURN; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserAccount_Namelist] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserAccount_Namelist] ( @authaccount varchar(5) ) RETURNS @RET TABLE ( [useraccount_id] varchar(5), [name] nvarchar(100) null, [firstname] nvarchar(100) null, [order] int) AS BEGIN DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount); IF @auth > 1 BEGIN INSERT INTO @RET SELECT ua.[useraccount_id] ,CAST(DECRYPTBYKEY(ua.[name_enc]) as nvarchar(100)) ,CAST(DECRYPTBYKEY(ua.[firstname_enc]) as nvarchar(100)) ,'order' = ROW_NUMBER() OVER (ORDER BY CAST(DECRYPTBYKEY(ua.[name_enc]) as nvarchar(255))) FROM [dbo].[fis_useraccounts] as ua WHERE ua.[DateDeleted] is null; END RETURN; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserAccountList] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserAccountList] ( @authaccount varchar(5) , @useraccount_id varchar(5) , @usergroup_id varchar(5) , @include_nonmembers as bit ) RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(100) null, [firstname] nvarchar(100) null, [title] varchar(50) NULL, [gender] varchar(1), [email] varchar(255) NULL, [mobile] varchar(50) null, [functions] varchar(1000), [language] varchar(2), [disabled] bit, [nologin] bit, [member] bit, [order] int) AS BEGIN DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount); IF @auth > 1 OR (ISNULL(@useraccount_id, '') <>'' AND @useraccount_id = @authaccount) BEGIN DECLARE @ungrouped bit = CASE WHEN @usergroup_id is null THEN 1 ELSE 0 END; /* if no usergroup is selected => ungrouped */ IF @ungrouped = 1 OR EXISTS(SELECT * FROM [dbo].[fis_usergroups] as ug where ug.[usergroup_id] = @usergroup_id AND ug.[DateDeleted] is null) /* Validate selected group, alternatively do not even look for accounts */ BEGIN WITH SelectedGroupMembers as ( SELECT ug.[usergroup_id], ugm.[useraccount_id] FROM [dbo].[fis_usergroups_members] as ugm JOIN [dbo].[fis_usergroups] as ug ON ugm.[usergroup_id] = ug.[usergroup_id] WHERE ug.[DateDeleted] is null AND ugm.[DateDeleted] is null AND ug.[usergroup_id] = @usergroup_id ) INSERT INTO @RET SELECT ua.[useraccount_id] ,'auth' = ISNULL(TRY_CAST((SELECT TOP(1) [value] FROM [fis_useraccounts_settings] as s WHERE s.[useraccount_id] = ua.[useraccount_id] and s.[key] = 'intranet_admin') as smallint), CASE WHEN ua.[useraccount_id] is null THEN -1 WHEN [DateDisabled] is not null THEN 0 ELSE 1 END ) ,CAST(DECRYPTBYKEY(ua.[name_enc]) as nvarchar(100)) ,CAST(DECRYPTBYKEY(ua.[firstname_enc]) as nvarchar(100)) ,CAST(DECRYPTBYKEY(ua.[title_enc]) as varchar(50)) ,CAST(DECRYPTBYKEY(ua.[gender_enc]) as varchar(1)) ,CAST(DECRYPTBYKEY(ua.[email_enc]) as varchar(255)) ,CAST(DECRYPTBYKEY(ua.[mobile_enc]) as varchar(50)) ,'functions' = STUFF( (SELECT ',' + [value] as [text()] FROM [fis_useraccounts_settings] as s WHERE s.[useraccount_id] = ua.[useraccount_id] and s.[key] = 'intranet_function' FOR XML PATH(''), TYPE).value('.','nvarchar(max)') , 1,1,'') ,ua.[language] ,'disabled' = CASE WHEN ua.[DateDisabled] IS NULL THEN 0 ELSE 1 END ,'nologin' = CAST(CASE WHEN ua.[password_enc] is null THEN 1 WHEN ISNULL(CAST(DECRYPTBYKEY(ua.[password_enc]) as varchar(20)),'') = '' THEN 1 ELSE 0 END as bit) ,'member' = CASE WHEN @usergroup_id IS NULL THEN NULL WHEN sgm.[useraccount_id] is not null THEN 1 ELSE 0 END ,'order' = ROW_NUMBER() OVER (ORDER BY CAST(DECRYPTBYKEY(ua.[name_enc]) as nvarchar(255))) FROM [dbo].[fis_useraccounts] as ua LEFT JOIN SelectedGroupMembers as sgm on sgm.[useraccount_id] = ua.[useraccount_id] WHERE ua.[DateDeleted] is null /*never return deleted useraccounts */ AND (@useraccount_id is null OR (ua.[useraccount_id] = @useraccount_id)) /* if single useraccount is selected, return only this selected one */ AND (@ungrouped = 1 -- is no useraccount is selected OR ISNULL(@include_nonmembers,0) = 1 -- or if useraccount is selected, but non-members should be included also OR sgm.[useraccount_id] is not null) -- or if accounts are valid members END END RETURN; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserAddressForm] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserAddressForm] ( @name_enc varbinary(260) ,@title_enc varbinary(50) ,@gender_enc varbinary(100) ,@language varchar(2) ) RETURNS nvarchar(255) AS BEGIN DECLARE @Username nvarchar(255); DECLARE @l varchar(2) = LOWER(ISNULL(@language, 'de')); DECLARE @g varchar(1) = LOWER(ISNULL(CAST(DECRYPTBYKEY(@gender_enc) as varchar(1)), 'm')); SET @Username = CAST( CASE WHEN @l = 'de' THEN 'Sehr geehrte' + CASE WHEN @g = 'm' THEN 'r Herr ' ELSE ' Frau ' END ELSE 'Dear ' + CASE WHEN @g = 'm' THEN 'Mr ' ELSE ' Ms ' END END + ISNULL(CASE WHEN @title_enc is null THEN '' ELSE CAST(DECRYPTBYKEY(@title_enc) as varchar(50)) + ' ' END,'') + ISNULL(CASE WHEN @name_enc is null THEN '' ELSE CAST(DECRYPTBYKEY(@name_enc ) as nvarchar(100)) END, '') as nvarchar(255) ); RETURN @username; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserAuth] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserAuth] ( @useraccount_id varchar(5) ) RETURNS smallint AS BEGIN DECLARE @auth smallint = -1; SET @auth = ISNULL((SELECT TOP(1) ISNULL(TRY_CAST((SELECT TOP(1) [value] FROM [fis_useraccounts_settings] as s WHERE s.[useraccount_id] = ua.[useraccount_id] and s.[key] = 'intranet_admin') as smallint), CASE WHEN [useraccount_id] is null THEN -1 WHEN [DateDisabled] is not null THEN 0 ELSE 1 END ) FROM [dbo].[fis_useraccounts] as ua WHERE ua.[DateDeleted] is null AND ua.[useraccount_id] = @useraccount_id), -1); RETURN @auth; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserEmail_byID] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserEmail_byID] ( @useraccount_id varchar(5) ) RETURNS nvarchar(255) AS BEGIN DECLARE @UserEmail varchar(255); SELECT TOP(1) @UserEmail = ISNULL(CASE WHEN [email_enc] is null THEN '' ELSE CAST(DECRYPTBYKEY([email_enc] ) as varchar(255)) END, '') FROM [dbo].[fis_useraccounts] as ua WHERE [useraccount_id] = @useraccount_id AND [DateDeleted] is null; RETURN @userEmail; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserGroupList] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserGroupList] ( @authaccount varchar(5) , @usergroup_id varchar(5) ) RETURNS @RET TABLE ( [usergroup_id] varchar(5), [name] nvarchar(255) null, [order] int) AS BEGIN DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount); IF @auth > 1 BEGIN INSERT INTO @RET SELECT [usergroup_id] ,CAST(DECRYPTBYKEY(ug.[name_enc]) as nvarchar(255)) ,'order' = ROW_NUMBER() OVER (ORDER BY CAST(DECRYPTBYKEY(ug.[name_enc]) as nvarchar(255))) FROM [dbo].[fis_usergroups] as ug WHERE ug.[DateDeleted] is null AND (@usergroup_id is null OR ug.[usergroup_id] = @usergroup_id); END RETURN; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserName] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserName] ( @name_enc varbinary(260) ,@firstname_enc varbinary(260) ,@title_enc varbinary(50) ) RETURNS nvarchar(255) AS BEGIN DECLARE @Username nvarchar(255); SET @Username = CAST( ISNULL(CASE WHEN @title_enc is null THEN '' ELSE CAST(DECRYPTBYKEY(@title_enc) as varchar(50)) + ' ' END,'') + ISNULL(CASE WHEN @firstname_enc is null THEN '' ELSE CAST(DECRYPTBYKEY(@firstname_enc) as nvarchar(100)) + ' ' END,'') + ISNULL(CASE WHEN @name_enc is null THEN '' ELSE CAST(DECRYPTBYKEY(@name_enc ) as nvarchar(100)) END, '') as nvarchar(255)) RETURN @username; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserName_byID] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserName_byID] ( @useraccount_id varchar(5) ) RETURNS nvarchar(255) AS BEGIN DECLARE @Username nvarchar(255); SELECT TOP(1) @Username = [dbo].[fis_admin_getUserName]([name_enc],[firstname_enc],[title_enc]) FROM [dbo].[fis_useraccounts] as ua WHERE [useraccount_id] = @useraccount_id AND [DateDeleted] is null; RETURN @username; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserName_rev] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserName_rev] ( @name_enc varbinary(260) ,@firstname_enc varbinary(260) ,@title_enc varbinary(50) ) RETURNS nvarchar(255) AS BEGIN DECLARE @Username nvarchar(255); SET @Username = CAST( ISNULL(CASE WHEN @name_enc is null THEN '' ELSE CAST(DECRYPTBYKEY(@name_enc ) as nvarchar(100)) END, '') + N', ' + ISNULL(CASE WHEN @firstname_enc is null THEN '' ELSE CAST(DECRYPTBYKEY(@firstname_enc) as nvarchar(100)) + ' ' END,'') as nvarchar(255)) RETURN @username; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserName_rev_byID] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserName_rev_byID] ( @useraccount_id varchar(5) ) RETURNS nvarchar(255) AS BEGIN DECLARE @Username nvarchar(255); SELECT TOP(1) @Username = [dbo].[fis_admin_getUserName_rev]([name_enc],[firstname_enc],[title_enc]) FROM [dbo].[fis_useraccounts] as ua WHERE [useraccount_id] = @useraccount_id AND [DateDeleted] is null; RETURN @username; END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_getUserSetting] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_getUserSetting] ( @useraccount_id varchar(5) , @key varchar(25) ) RETURNS varchar(255) AS BEGIN DECLARE @ret varchar(25); SET @ret = ISNULL((SELECT TOP(1) ISNULL((SELECT TOP(1) [value] FROM [fis_useraccounts_settings] as s WHERE s.[useraccount_id] = ua.[useraccount_id] and s.[key] = @key), '') FROM [dbo].[fis_useraccounts] as ua WHERE ua.[DateDeleted] is null AND ua.[useraccount_id] = @useraccount_id), ''); RETURN ISNULL(@ret,''); END GO /****** Object: UserDefinedFunction [dbo].[fis_admin_testGroupMembership] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fis_admin_testGroupMembership] ( @useraccount_id varchar(5) ,@usergroup_id varchar(1000) ) RETURNS bit AS BEGIN DECLARE @groups TABLE([usergroup_id] varchar(5)); INSERT INTO @groups SELECT * from STRING_SPLIT(@usergroup_id,','); DECLARE @isMember bit = CASE WHEN EXISTS (SELECT * FROM [dbo].[fis_usergroups] as g JOIN @groups as groupstotest On groupstotest.[usergroup_id] = g.[usergroup_id] JOIN [dbo].[fis_usergroups_members] as gm on g.[usergroup_id] = gm.[usergroup_id] and gm.[DateDeleted] is null AND g.[DateDeleted] is null JOIN [dbo].[fis_useraccounts] as u on gm.[useraccount_id] = u.[useraccount_id] WHERE u.[DateDeleted] is null AND u.[DateDisabled] is null and u.[useraccount_id] = @useraccount_id and g.[DateDeleted] is null ) THEN 1 ELSE 0 END; RETURN @isMember; END GO /****** Object: UserDefinedFunction [dbo].[fis_fn_useraccount_id] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[fis_fn_useraccount_id] ( ) RETURNS varchar(5) AS BEGIN DECLARE @NewAccount varchar(5) = [dbo].[ocms_fn_generatePassword] (5,0,1,0); WHILE EXISTS( SELECT * FROM [dbo].[fis_useraccounts] WHERE [useraccount_id] = @NewAccount) BEGIN SET @NewAccount = [dbo].[ocms_fn_generatePassword] (5,0,1,0); END RETURN @NewAccount; END; GO /****** Object: UserDefinedFunction [dbo].[mfr__schema] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[mfr__schema] ( ) RETURNS XML AS BEGIN DECLARe @AS XML; SET @AS = N' '; RETURN @as; END GO /****** Object: UserDefinedFunction [dbo].[ocms_admin_authenticate] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ocms_admin_authenticate] ( @email varchar(255), @password nvarchar(20) ) RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(255) null, [email] varchar(255) NULL, [mobile] varchar(50) null) AS BEGIN DECLARE @auth smallint = -1; DECLARE @useraccount_id varchar(10), @name nvarchar(255), @mobile varchar(50); SELECT TOP(1) @useraccount_id = [useraccount_id] ,@name = DECRYPTBYKEY(ua.[name_enc]) ,@email = DECRYPTBYKEY(ua.[email_enc]) ,@mobile = DECRYPTBYKEY(ua.[mobile_enc]) FROM [dbo].[ocms_useraccounts] as ua WHERE ua.[DateDeleted] is null AND ua.[DateDisabled] is null AND DECRYPTBYKEY(ua.[email_enc]) = @email AND DECRYPTBYKEY(ua.[password_enc]) = @password AND ua.[password_enc] is not null; INSERT INTO @RET VALUES( @useraccount_id ,IIF(@useraccount_id is null, -1, 1) ,IIF(@useraccount_id is null, null, @name) ,IIF(@useraccount_id is null, null, @email) ,IIF(@useraccount_id is null, null, @mobile) ); RETURN; END GO /****** Object: UserDefinedFunction [dbo].[ocms_admin_checkUserExists] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ocms_admin_checkUserExists] ( @useraccount_id varchar(5) ) RETURNS bit AS BEGIN DECLARE @RET bit; SET @RET = IIF(EXISTS (SELECT * FROM [dbo].[ocms_useraccounts] as ua WHERE [useraccount_id] = @useraccount_id AND ua.[DateDeleted] is null AND ua.[DateDisabled] is null), 1, 0); RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[ocms_admin_getUserAccount] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ocms_admin_getUserAccount] ( @useraccount_id varchar(5) ) RETURNS @RET TABLE ( [useraccount_id] varchar(5), [auth] smallint, [name] nvarchar(255) null, [email] varchar(255) NULL, [mobile] varchar(50) null) AS BEGIN DECLARE @auth smallint = -1; DECLARE @name nvarchar(255), @email varchar(255), @mobile varchar(50); SELECT TOP(1) @useraccount_id = [useraccount_id] ,@name = DECRYPTBYKEY(ua.[name_enc]) ,@email = DECRYPTBYKEY(ua.[email_enc]) ,@mobile = DECRYPTBYKEY(ua.[mobile_enc]) FROM [dbo].[ocms_useraccounts] as ua WHERE ua.[DateDeleted] is null AND ua.[DateDisabled] is null AND ua.[useraccount_id] = @useraccount_id; INSERT INTO @RET VALUES( @useraccount_id ,IIF(@useraccount_id is null, -1, 1) ,IIF(@useraccount_id is null, null, @name) ,IIF(@useraccount_id is null, null, @email) ,IIF(@useraccount_id is null, null, @mobile) ); RETURN; END GO /****** Object: UserDefinedFunction [dbo].[ocms_fn_generatePassword] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[ocms_fn_generatePassword] ( @length int , @specialChars bit = 1 , @nums bit = 1 , @lowerCase bit = 1 ) RETURNS varchar(255) AS BEGIN DECLARE @randInt int; DECLARE @NewCharacter varchar(1); DECLARE @NewPassword TABLE([typ] char(1), [char] char(1), [order] int); SET @length = CASE WHEN @length > 255 THEN 255 ELSE @length END; DECLARE @cnt int = 0, @position as int; --random characters WHILE (@cnt < @length) BEGIN SELECT @randInt = [dbo].[ocms_fn_randbetween](33,122) IF (CASE WHEN (@randInt>=33 AND @randInt<=47) AND @specialChars = 1 THEN 1 WHEN (@randInt>=48 AND @randInt<=57) AND @nums = 1 THEN 1 WHEN (@randInt>=58 AND @randInt<=64) AND @specialChars = 1 THEN 1 WHEN (@randInt>=65 AND @randInt<=90) THEN 1 WHEN (@randInt>=91 AND @randInt<=93) AND @specialChars = 1 THEN 1 WHEN (@randInt>=97 AND @randInt<=122) AND @lowerCase = 1 THEN 1 ELSE 0 END) = 1 BEGIN SET @cnt = @cnt + 1; INSERT INTO @NewPassword VALUES (CASE WHEN (@randInt>=33 AND @randInt<=47) THEN 's' WHEN (@randInt>=48 AND @randInt<=57) THEN 'n' WHEN (@randInt>=58 AND @randInt<=64) THEN 's' WHEN (@randInt>=65 AND @randInt<=90) THEN 'u' WHEN (@randInt>=91 AND @randInt<=93) THEN 's' WHEN (@randInt>=97 AND @randInt<=122) THEN 'l' END, CHAR(@randInt), @cnt); END END DECLARE @min_n int = CASE WHEN @length > 4 AND @length < 11 THEN 1 ELSE FLOOR(@length * 0.1) END; DECLARE @min_s int = FLOOR(@length * 0.1); DECLARE @min_l int = FLOOR(@length * 0.4); DECLARE @min_u int = FLOOR(@length * 0.4); WHILE (SELECT COUNT(*) FROM @NewPassword WHERE [typ] = 'n') < @min_n AND @length > 0 AND @nums = 1 BEGIN SET @position = [dbo].[ocms_fn_randbetween](1,@length); UPDATE @NewPassword SET [char] = CHAR([dbo].[ocms_fn_randbetween](48,57)), [typ] = 'n' WHERE [order] = @position; END WHILE (SELECT COUNT(*) FROM @NewPassword WHERE [typ] = 'l') < @min_l AND @length > 0 AND @lowerCase = 1 BEGIN SET @position = [dbo].[ocms_fn_randbetween](1,@length); UPDATE @NewPassword SET [char] = CHAR([dbo].[ocms_fn_randbetween](97,122)), [typ] = 'l' WHERE [order] = @position; END WHILE (SELECT COUNT(*) FROM @NewPassword WHERE [typ] = 'u') < @min_n AND @length > 0 BEGIN SET @position = [dbo].[ocms_fn_randbetween](1,@length); UPDATE @NewPassword SET [char] = CHAR([dbo].[ocms_fn_randbetween](65,90)), [typ] = 'u' WHERE [order] = @position; END WHILE (SELECT COUNT(*) FROM @NewPassword WHERE [typ] = 's') < @min_s AND @length > 0 AND @specialChars = 1 BEGIN SET @position = [dbo].[ocms_fn_randbetween](1,@length); DECLARE @nc char(1), @nt char(1); select @randInt=[dbo].[ocms_fn_randbetween](33,122) UPDATE @NewPassword SET [char] = CHAR(@randint), [typ] = 's' WHERE [order] = @position AND (CASE WHEN (@randInt>=33 AND @randInt<=47) THEN 's' WHEN (@randInt>=48 AND @randInt<=57) THEN 'n' WHEN (@randInt>=58 AND @randInt<=64) THEN 's' WHEN (@randInt>=65 AND @randInt<=90) THEN 'u' WHEN (@randInt>=91 AND @randInt<=93) THEN 's' WHEN (@randInt>=97 AND @randInt<=122) THEN 'l' END) = 's'; END RETURN (Cast((SELECT [CHAR] as [text()] FROM @NewPassword FOR XML PATH(''),TYPE).value('.','NVARCHAR(MAX)') as varchar(255))); END; GO /****** Object: UserDefinedFunction [dbo].[ocms_fn_link_csv] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ocms_fn_link_csv] ( @inp1 varchar(4000) ,@inp2 varchar(4000) ) RETURNS varchar(4000) AS BEGIN DECLARE @RET varchar(4000) = ISNULL(@inp1, '') + CASE WHEN ISNULL(@inp1, '') <> '' AND ISNULL(@inp2, '') <> '' THEN ',' ELSE '' END + ISNULL(@inp2, ''); RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[ocms_fn_randbetween] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[ocms_fn_randbetween](@bottom integer, @top integer) RETURNS integer AS BEGIN RETURN (select cast(round((@top-@bottom) * [rn] +@bottom,0) as integer) from [dbo].[ocms_fn_rand]) END GO /****** Object: UserDefinedFunction [dbo].[ocms_fn_useraccount_id] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[ocms_fn_useraccount_id] ( ) RETURNS varchar(5) AS BEGIN DECLARE @NewAccount varchar(5) = [dbo].[ocms_fn_generatePassword] (5,0,1,0); WHILE EXISTS( SELECT * FROM [dbo].[ocms_useraccounts] WHERE [useraccount_id] = @NewAccount) BEGIN SET @NewAccount = [dbo].[ocms_fn_generatePassword] (5,0,1,0); END RETURN @NewAccount; END; GO /****** Object: UserDefinedFunction [dbo].[ocms_getFullItemTree] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ocms_getFullItemTree] ( @view_iid bigint ,@include_hidden bit ) RETURNS @itemtree TABLE ( [ocms_iid] [bigint] NOT NULL, [parent_iid] [bigint] NULL, [ocms_pid] [bigint] NULL, [name] [nvarchar](255) NULL, [view] [bit] NOT NULL, [template_id] [bigint] NULL, [hide] [bit] NOT NULL, [order] [int] NOT NULL, [DateCreated] [datetime] NULL, [DateModified] [datetime] NULL, [level] int, [sub] bit, [sitepropsub] bit, [focus] bit, [new_order] int ) AS BEGIN -- get basics DECLARE @site bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE i.[parent_iid] is null); IF @site is NOT null BEGIN WITH cteLevels as ( SELECT t.* , CAST(0 as int) as [level] , 0 as [sub] , 0 as [sitepropsub] FROM [dbo].[ocms_items] as t WHERE t.[ocms_iid] = @site UNION ALL SELECT t.* , CAST(c.[level] + 1 as int) as [level] , CASE WHEN c.[sub] = 1 THEN 1 WHEN t.[parent_iid] = @view_iid THEN 1 ELSE 0 END as [sub] , CASE WHEN c.[sitepropsub] = 1 THEN 1 WHEN t.[parent_iid] = @site and t.[view] = 0 THEN 1 ELSE 0 END as [sitepropsub] FROM [dbo].[ocms_items] as t inner JOIN cteLevels c on t.[parent_iid] = c.[ocms_iid] WHERE (t.[hide] = 0 Or @include_hidden = 1) ) INSERT INTO @itemtree SELECT t.* , IIF( t.[ocms_iid] = @view_iid , 1, 0) as [focus] , ROW_NUMBER() OVER (PARTITION BY [parent_iid] ORDER BY [order], [ocms_iid]) as [new_order] FROM cteLevels as t; --SELECT * FROM @itemtree END RETURN END GO /****** Object: UserDefinedFunction [dbo].[ocms_getFullViewTree] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ocms_getFullViewTree] ( @view_path varchar(255), @locale varchar(5) ) RETURNS @itemtree TABLE ( [ocms_iid] [bigint] NOT NULL, [parent_iid] [bigint] NULL, [ocms_pid] [bigint] NULL, [name] [nvarchar](255) NULL, [view] [bit] NOT NULL, [template_id] [bigint] NULL, [hide] [bit] NOT NULL, [order] [int] NOT NULL, [DateCreated] datetime null, [DateModified] datetime null, [locale] varchar(5) NOT NULL, [alias] varchar(25) NULL, [path] varchar(2000), [level] int, [sub] bit, [focus] bit, [nav] bit, [new_order] int ) AS BEGIN -- get basics DECLARE @site bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE i.[parent_iid] is null); SET @view_path = ISNULL(@view_path, ''); SET @locale = IIF(ISNULL(@locale, '')='', null, @locale); IF @site is NOT null BEGIN --get locales DECLARE @locales TABLE([locale] varchar(5), [order] int); INSERT INTO @locales SELECT * FROM [dbo].[ocms_locales](); -- tree in all locales WITH itm as( -- items are not localized SELECT i.*, l.[locale] FROM [dbo].[ocms_items] as i CROSS JOIN (SELECT * FROM @locales as l_ WHERE l_.[locale] <> '*') as l WHERE i.[view] = 1 OR ([ocms_iid] = @site) ), navitm as ( select itm.* ,IIF(itm.[name] COLLATE Latin1_General_CI_AS = 'index', 'index', n.[alias]) as 'alias' FROM itm LEFT JOIN [dbo].[ocms_navigation] as n ON itm.[ocms_iid] = n.[ocms_iid] and itm.[locale] = n.[locale] AND n.[locale] <> '*' ), cteLevels as ( SELECT t.* , Cast('//' as varchar(2000)) as [path] , CAST(0 as int) as [level] , 0 as [sub] FROM navitm as t WHERE t.[ocms_iid] = @site UNION ALL SELECT navitm.* , IIF( navitm.[view] = 0, '', CAST(IIF( c.[path] = '//' , '' , c.[path] + '/' ) + LOWER(navitm.[alias]) as varchar(2000)) ) as [path] , CAST(c.[level] + 1 as int) as [level] , CASE WHEN c.[sub] = 1 THEN 1 WHEN IIF( CAST(IIF( c.[path] = '//' , '' , c.[path] + '/' ) + ISNULL(LOWER(navitm.[name]), '') as varchar(2000)) = LOWER(@view_path), 1, 0) = 1 THEN 1 ELSE 0 END as [sub] FROM navitm inner JOIN cteLevels c on navitm.[parent_iid] = c.[ocms_iid] AND navitm.[locale] = c.[locale] ) INSERT INTO @itemtree SELECT t.* , IIF( [path] COLLATE Latin1_General_CI_AS = @view_path OR [path] COLLATE Latin1_General_CI_AS like (@view_path + '?%'), 1, 0) as [focus] , IIF( [view] = 1 AND [level] > 0 AND [path] <> '' AND [path] <> '//' AND ISNULL(t.[hide],0) = 0 , 1, 0 ) as [nav] , ROW_NUMBER() OVER (PARTITION BY [parent_iid] ORDER BY [order], [ocms_iid]) as [new_order] FROM cteLevels as t; UPDATE @itemtree SET [path] = null WHERE [nav] = 0; IF(ISNULL(@locale, '') <> '') BEGIN DECLARE @view_iid bigint = null, @view_level int; SELECT TOP(1) @view_iid = it.[ocms_iid] , @view_level = it.[level] , @locale = it.[locale] -- will override the selected language FROM @itemtree as it WHERE [focus] = 1 AND ([locale] = @locale OR [name] COLLATE Latin1_General_CI_AS <> 'index'); -- index is available in any language DELETE FROM @itemtree WHERE [locale] <> @locale; -- remove anything that is not in selected language END --SELECT * FROM @itemtree END RETURN END GO /****** Object: UserDefinedFunction [dbo].[ocms_locales] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ocms_locales] ( ) RETURNS @RET TABLE ([locale] varchar(5), [order] int) AS BEGIN DECLARE @set_value varchar(2000) = ISNULL((SELECT [value] FROM [ocms_settings] where [key] = 'locales'), '*,de'); DECLARE @c char = ','; INSERT INTO @RET SELECT [value], [order] = ROW_NUMBER() OVER (ORDER BY CHARINDEX(@c + value + @c, @c + @set_value + @c)) FROM STRING_SPLIT(@set_value, @c); RETURN; END GO /****** Object: UserDefinedFunction [dbo].[ott_20_randomStrings] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_20_randomStrings] ( @digits tinyint ) RETURNS @RET TABLE ( [s] varchar(5) ) AS BEGIN DECLARE @new_sessionid varchar(36), @trys int, @chars varchar(100), @UPPER int, @LOWER int; SELECT @chars = '012KLMN34STUVWEFGHIJXYZ567OPQR89ABCD'; SELECT @UPPER = LEN(@chars), @LOWER = 1; INSERT INTO @RET SELECT * FROM (SELECT TOP(20) SUBSTRING(SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1) + SUBSTRING(@chars, [dbo].[ott_random_int](@UPPER,@LOWER), 1), 1, @digits) as id FROM (VALUES(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16),(17),(18),(19),(20)) vl(id))z WHERE LEN(id) = @digits; RETURN END GO /****** Object: UserDefinedFunction [dbo].[ott_b10] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_b10] ( @string varchar(10) ) RETURNS int AS BEGIN DECLARE @RET int; DECLARE @str VARCHAR(10) = REVERSE(LOWER(@string)); WITH Split(stpos,endpos) AS( SELECT 1 AS stpos, 2 AS endpos UNION ALL SELECT endpos, endpos+1 FROM Split WHERE endpos <= LEN(@str) ) , c as ( SELECT 'character' = SUBSTRING(@str,stpos,COALESCE(NULLIF(endpos,0),LEN(@str)+1)-stpos) ,'charindex' = stpos FROM Split ) , s as ( SELECT * ,'num' = ASCII(character) - ASCII('a') + 1 ,'fac' = POWER(26,([charindex] -1)) ,'val' = POWER(26,([charindex] -1)) * (ASCII(character) - ASCII('a') + 1) FROM c ) select @RET = SUM([val]) FROM s; RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[ott_b26] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_b26] ( @number int ) RETURNS varchar(10) AS BEGIN DECLARE @RET varchar(10) /* SELECT *, LetterCode = Coalesce((SELECT Char(65 + (N.Num - 475255) / 456976 % 26) WHERE N.Num >= 475255), '') + Coalesce((SELECT Char(65 + (N.Num - 18279) / 17576 % 26) WHERE N.Num >= 18279), '') + Coalesce((SELECT Char(65 + (N.Num - 703) / 676 % 26) WHERE N.Num >= 703), '') + Coalesce((SELECT Char(65 + (N.Num - 27) / 26 % 26) WHERE N.Num >= 27), '') + (SELECT Char(65 + (N.Num - 1) % 26)) FROM (VALUES(18931)) as N(Num) ORDER BY N.Num */ SET @RET = LOWER( Coalesce((SELECT Char(65 + (@number - 475255) / 456976 % 26) WHERE @number >= 475255), '') + Coalesce((SELECT Char(65 + (@number - 18279) / 17576 % 26) WHERE @number >= 18279), '') + Coalesce((SELECT Char(65 + (@number - 703) / 676 % 26) WHERE @number >= 703), '') + Coalesce((SELECT Char(65 + (@number - 27) / 26 % 26) WHERE @number >= 27), '') + (SELECT Char(65 + (@number - 1) % 26)) ); RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[ott_csv_contains] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_csv_contains] ( @text varchar(500) ,@fragment varchar(500) ) RETURNS bit AS BEGIN DECLARE @RET bit; -- Will be true -- if any of the fragments exist in the list of text-items WITH texts as (SELECT * FROM string_split(ISNULL(@text,''), ',')) ,fragments as (SELECT * FROM string_split(ISNULL(@fragment,''), ',')) SELECT @RET = CASE WHEN EXISTS (SELECT * FROM texts JOIN fragments ON texts.[value] = fragments.[value]) THEN 1 ELSE 0 END; RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[ott_jcontent] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_jcontent] ( @groupcode varchar(10) ,@text varchar(4000) ) RETURNS varchar(4000) AS BEGIN DECLARE @RET varchar(4000); DECLARE @textinput varchar(4000) = REPLACE(ISNULL(@text, ''), ' ', ''); IF (@textinput = '' OR @textinput = '{}') BEGIN SET @RET = 0; END ELSE BEGIN DECLARE @Pattern varchar(20) = '%"' + @groupcode + '":"%'; DECLARE @P0 int = PATINDEX(@pattern, @textinput); DECLARE @P1 int = @P0 + LEN(@pattern) -2; DECLARE @P2 int = CHARINDEX('"',@textinput,@p1); SELECT @RET = CASE WHEN @P0 = 0 THEN '' ELSE SUBSTRING(@textinput, @P1, @P2 - @P1) END; END RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[ott_jcsv_contains] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_jcsv_contains] ( @groupcode varchar(10) ,@text varchar(4000) ,@fragment varchar(500) ) RETURNS bit AS BEGIN DECLARE @RET bit; DECLARE @textinput varchar(4000) = REPLACE(ISNULL(@text, ''), ' ', ''); IF (@textinput = '' OR @textinput = '{}' OR @fragment = '') BEGIN SET @RET = 0; END ELSE BEGIN -- Will be true -- if any of the fragments exist in the list of text-items DECLARE @Pattern varchar(20) = '%"' + @groupcode + '":"%'; DECLARE @P0 int = PATINDEX(@pattern, @textinput); DECLARE @P1 int = @P0 + LEN(@pattern) -2; DECLARE @P2 int = CHARINDEX('"',@textinput,@p1); IF @P0 = 0 BEGIN SET @RET = 0; END ELSE BEGIN DECLARE @text2 varchar(4000) = SUBSTRING(@textinput, @P1, @P2 - @P1); WITH texts as (SELECT * FROM string_split(ISNULL(@text2,''), ',')) ,fragments as (SELECT * FROM string_split(ISNULL(@fragment,''), ',')) SELECT @RET = CASE WHEN EXISTS (SELECT * FROM texts JOIN fragments ON texts.[value] = fragments.[value]) THEN 1 ELSE 0 END; END END RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[ott_jcsv_containskey] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_jcsv_containskey] ( @groupcode varchar(10) ,@text varchar(4000) ) RETURNS bit AS BEGIN DECLARE @RET bit; DECLARE @textinput varchar(4000) = REPLACE(ISNULL(@text, ''), ' ', ''); IF (@textinput = '' OR @textinput = '{}') BEGIN SET @RET = 0; END ELSE BEGIN -- Will be true -- if any of the fragments exist in the list of text-items DECLARE @Pattern varchar(20) = '%"' + @groupcode + '":"%'; DECLARE @P0 int = PATINDEX(@pattern, @textinput); SET @RET = Case WHEN @P0 = 0 THEN 0 ELSE 1 END; END RETURN @RET; END GO /****** Object: UserDefinedFunction [dbo].[ott_max] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Dr. Stefan Ott -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_max] ( @val1 int, @val2 int ) RETURNS int AS BEGIN DECLARE @RES int; IF @val1 is null and @val2 is not null SET @val1 = @val2 IF @val2 is null and @val1 is not null SET @val2 = @val1 IF @val1 is null and @val2 is null SELECT @val1 = 0, @val2 = 0; SELECT @RES = CASE WHEN @val1 > @val2 THEN @val1 ELSE @val2 END; RETURN @RES; END GO /****** Object: UserDefinedFunction [dbo].[ott_max_float] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Dr. Stefan Ott -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_max_float] ( @val1 float, @val2 float ) RETURNS float AS BEGIN DECLARE @RES float; IF @val1 is null and @val2 is not null SET @val1 = @val2 IF @val2 is null and @val1 is not null SET @val2 = @val1 IF @val1 is null and @val2 is null SELECT @val1 = 0, @val2 = 0; SELECT @RES = CASE WHEN @val1 > @val2 THEN @val1 ELSE @val2 END; RETURN @RES; END GO /****** Object: UserDefinedFunction [dbo].[ott_min] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Dr. Stefan Ott -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_min] ( @val1 int, @val2 int ) RETURNS int AS BEGIN DECLARE @RES int; IF @val1 is null and @val2 is not null SET @val1 = @val2 IF @val2 is null and @val1 is not null SET @val2 = @val1 IF @val1 is null and @val2 is null SELECT @val1 = 0, @val2 = 0; SELECT @RES = CASE WHEN @val1 < @val2 THEN @val1 ELSE @val2 END; RETURN @RES; END GO /****** Object: UserDefinedFunction [dbo].[ott_min_float] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Dr. Stefan Ott -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_min_float] ( @val1 float, @val2 float ) RETURNS float AS BEGIN DECLARE @RES float; IF @val1 is null and @val2 is not null SET @val1 = @val2 IF @val2 is null and @val1 is not null SET @val2 = @val1 IF @val1 is null and @val2 is null SELECT @val1 = 0, @val2 = 0; SELECT @RES = CASE WHEN @val1 < @val2 THEN @val1 ELSE @val2 END; RETURN @RES; END GO /****** Object: UserDefinedFunction [dbo].[ott_random_int] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[ott_random_int] (@UPPER int, @LOWER int) RETURNS int AS BEGIN DECLARE @RET INT = CAST(ROUND(((@UPPER - @LOWER - 1) * (SELECT TOP(1) [rn] FROM [dbo].[ocms_fn_rand]) + @LOWER), 0) as int); RETURN @RET; END GO /****** Object: Table [dbo].[fds__admin_settings] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__admin_settings]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [type] [varchar](50) NOT NULL, [key] [varchar](50) NULL, [value] [nvarchar](max) NULL, [value2] [nvarchar](1000) NULL, CONSTRAINT [PK_fds__admin_settings] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: UserDefinedFunction [dbo].[fds__admin_reminderSettings] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fds__admin_reminderSettings] ( ) RETURNS TABLE AS RETURN ( WITH rs as ( SELECT * FROM [dbo].[fds__admin_settings] WHERE [type] = 'reminder' ) SELECT [stage1] = (SELECT TOP(1) [value] FROM rs WHERE [key] = 1) , [stage2] = (SELECT TOP(1) [value] FROM rs WHERE [key] = 2) , [stage3] = (SELECT TOP(1) [value] FROM rs WHERE [key] = 3) ) GO /****** Object: Table [dbo].[mfr__*PartnerSet] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__*PartnerSet]( [Property] [varchar](50) NOT NULL, [PartnerType] [varchar](25) NOT NULL, [PartnerId] [bigint] NOT NULL, [EntityId] [bigint] NOT NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__contacts] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__contacts]( [Id] [bigint] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [FirstName] [nvarchar](255) NULL, [LastName] [nvarchar](255) NULL, [Email] [nvarchar](255) NULL, [JobTitle] [nvarchar](255) NULL, [MobilePhone] [nvarchar](255) NULL, [Telephone] [nvarchar](255) NULL, [Fax] [nvarchar](255) NULL, [Note] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [Version] [int] NOT NULL, [CompanyId] [bigint] NOT NULL, [IsUser] [bit] NOT NULL, [ExternalId] [nvarchar](255) NULL, [Gender] [nvarchar](255) NULL, [UserId] [bigint] NOT NULL, CONSTRAINT [PK_mfr__contact] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__companies] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__companies]( [Id] [bigint] NOT NULL, [Location#ID] [bigint] NULL, [Version] [int] NOT NULL, [IsPhysicalPerson] [bit] NOT NULL, [IsOwner] [bit] NOT NULL, [IsEmailInvoicingActive] [bit] NOT NULL, [IsSupplier] [bit] NOT NULL, [MappingId] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [Name] [nvarchar](255) NULL, [Note] [nvarchar](255) NULL, [SupportTelephone] [nvarchar](255) NULL, [SupportFax] [nvarchar](255) NULL, [SupportMail] [nvarchar](255) NULL, [QuickSearch] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [MainContactId] [bigint] NOT NULL, CONSTRAINT [PK_mfr__company] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: UserDefinedFunction [dbo].[fds__getCompanyContacts] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fds__getCompanyContacts] ( @companyid bigint ) RETURNS TABLE AS RETURN ( WITH ps as ( SELECT [contactid] = p.[EntityId] from [mfr__*PartnerSet] as p WHERE p.property = 'Contact:Company' and p.[partnerId] = @companyid UNION SELECT [contactid] = p.[PartnerId] from [mfr__*PartnerSet] as p WHERE p.property = 'Company:Contacts' and p.[EntityId] = @companyid ) SELECT ct.* ,[isMainContact] = CAST( CASE WHEN cy.[MainContactId] is null then 0 WHEN cy.[MainContactId] = ct.[id] THEN 1 ELSE 0 END as bit) FROM [dbo].[mfr__contacts] as ct JOIN [dbo].[mfr__companies] as cy ON ct.[CompanyId] = cy.[id] WHERE ct.CompanyId = @companyid UNION SELECT ct.* ,[isMainContact] = CAST( CASE WHEN cy.[MainContactId] is null then 0 WHEN cy.[MainContactId] = ct.[id] THEN 1 ELSE 0 END as bit) FROM [dbo].[mfr__contacts] as ct JOIN ps ON ct.[id] = ps.[contactid] JOIN [dbo].[mfr__companies] as cy ON cy.[id] = @companyid ) GO /****** Object: UserDefinedFunction [dbo].[fds__getCompanysContacts] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE FUNCTION [dbo].[fds__getCompanysContacts] ( @companyids [dbo].[fds__tt__idlist] READONLY ) RETURNS TABLE AS RETURN ( WITH ps as ( SELECT [companyid] = p.[partnerId], [contactid] = p.[EntityId] from [mfr__*PartnerSet] as p WHERE p.property = 'Contact:Company' and p.[partnerId] IN (SELECT [Id] FROM @companyids) UNION SELECT [companyid] = p.[PartnerId], [contactid] = p.[PartnerId] from [mfr__*PartnerSet] as p WHERE p.property = 'Company:Contacts' and p.[EntityId] = (SELECT [Id] FROM @companyids) ) SELECT [CyId] = cyid.[Id] ,ct.* ,[isMainContact] = CAST( CASE WHEN cy.[MainContactId] is null then 0 WHEN cy.[MainContactId] = ct.[id] THEN 1 ELSE 0 END as bit) FROM [dbo].[mfr__contacts] as ct JOIN @companyids as cyid ON ct.[CompanyId] = cyid.[id] JOIN [dbo].[mfr__companies] as cy ON cyid.[id] = cy.[id] UNION SELECT [CyId] = cyid.[Id] ,ct.* ,[isMainContact] = CAST( CASE WHEN cy.[MainContactId] is null then 0 WHEN cy.[MainContactId] = ct.[id] THEN 1 ELSE 0 END as bit) FROM [dbo].[mfr__contacts] as ct JOIN ps ON ct.[id] = ps.[contactid] JOIN @companyids as cyid ON ps.[CompanyId] = cyid.[id] JOIN [dbo].[mfr__companies] as cy ON cyid.[id] = cy.[id] ) GO /****** Object: View [dbo].[ocms_fn_rand] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE VIEW [dbo].[ocms_fn_rand] AS select rand(Cast(newid() as varbinary)) as rn GO /****** Object: Table [dbo].[email_list] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[email_list]( [uid] [int] IDENTITY(1,1) NOT NULL, [email] [varchar](255) NULL, [sent] [datetime] NULL, [result] [bit] NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[fds__admin_reportcatalog] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__admin_reportcatalog]( [type] [varchar](50) NOT NULL, [key] [varchar](100) NOT NULL, [label] [varchar](255) NOT NULL, [description] [nvarchar](4000) NULL, [tags_csv] [varchar](255) NULL, [category] [varchar](255) NULL, [image_dataurl] [varchar](max) NULL, [link] [varchar](255) NULL, [functions] [varchar](10) NULL, [hidden] [bit] NOT NULL, [refresh] [smallint] NULL, [auth] [varchar](1000) NULL, [help_url] [varchar](255) NULL, [display_order] [smallint] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fds__custom_invoiceinfo] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__custom_invoiceinfo]( [InvID] [bigint] NOT NULL, [PaymentStatus] [char](1) NULL, [isPayed] [bit] NOT NULL, [file] [varbinary](max) NULL, CONSTRAINT [PK_fds__custom_i] PRIMARY KEY CLUSTERED ( [InvID] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fds__custom_servicerequest] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__custom_servicerequest]( [EntityId] [bigint] NOT NULL, [hidden] [bit] NOT NULL, CONSTRAINT [PK_fds__custom_servicerequest] PRIMARY KEY CLUSTERED ( [EntityId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[fds__custom_vat] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__custom_vat]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [EntityType] [varchar](50) NOT NULL, [EntityID] [bigint] NOT NULL, [VAT] [numeric](5, 2) NOT NULL, CONSTRAINT [PK_fds__custom_vat] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[fds__debuglog] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__debuglog]( [uid] [bigint] IDENTITY(1,1) NOT NULL, [CodeReference] [varchar](255) NULL, [ExceptionMessage] [varchar](max) NULL, [StackTrace] [varchar](max) NULL, [Data] [varchar](max) NULL, [timestamp] [datetime] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fds__emaillog] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__emaillog]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [Ref] [varchar](25) NOT NULL, [guid] [varchar](50) NULL, [DateSent] [datetime] NOT NULL, [config] [nvarchar](max) NOT NULL, [success] [bit] NOT NULL, [log] [nvarchar](max) NOT NULL, CONSTRAINT [PK_fds__emaillog] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fds__invoice_details] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__invoice_details]( [InvId] [varchar](10) NOT NULL, [InvoiceService_net] [numeric](10, 3) NULL, [InvoiceService_VAT] [numeric](10, 3) NULL, CONSTRAINT [PK_fds__invoice_details] PRIMARY KEY CLUSTERED ( [InvId] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[fds__invoice_items] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__invoice_items]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [InvId] [varchar](10) NOT NULL, [InvRqId] [bigint] NOT NULL, [mfr__item] [bigint] NULL, [Type] [nvarchar](255) NULL, [Position] [varchar](5) NULL, [Quantity] [nvarchar](25) NULL, [Text] [nvarchar](max) NULL, [value] [numeric](10, 3) NULL, [value_total] [numeric](10, 3) NULL, [vat] [numeric](5, 2) NULL, [value_service] [numeric](10, 3) NULL, [det] [bit] NULL, [SortOrder] [tinyint] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fds__invoice_servicerequests] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__invoice_servicerequests]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [InvId] [varchar](10) NOT NULL, [mfr__servicerequest] [bigint] NULL, [title] [nvarchar](max) NULL, [value_net] [numeric](10, 3) NULL, [SortOrder] [tinyint] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fds__invoices] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__invoices]( [Id] [varchar](10) NOT NULL, [Version] [int] NOT NULL, [InvoiceId] [nvarchar](25) NULL, [InvoiceType] [char](1) NOT NULL, [InvoiceTitle] [varchar](100) NULL, [DocumentName] [varchar](50) NULL, [InvoiceBalance] [numeric](10, 3) NOT NULL, [InvoiceBalance_net] [numeric](10, 3) NOT NULL, [InvoiceVAT_net1] [numeric](10, 3) NOT NULL, [InvoiceVAT_1] [numeric](5, 2) NOT NULL, [InvoiceVAT_net2] [numeric](10, 3) NULL, [InvoiceVAT_2] [numeric](5, 2) NULL, [PaymentTerm] [varchar](5) NOT NULL, [DueDate] [date] NOT NULL, [CustomerId] [bigint] NULL, [SendToAddress] [nvarchar](1000) NULL, [SendToEmail] [nvarchar](255) NULL, [ProvisionPeriod] [varchar](50) NULL, [ProvisionLocation] [nvarchar](1000) NULL, [PaymentStatus] [char](1) NULL, [IsPayed] [bit] NOT NULL, [IsSent] [bit] NOT NULL, [IsFinal] AS (CONVERT([bit],case when [DateFinalized] IS NULL then (0) else (1) end)), [IsCanceled] AS (CONVERT([bit],case when [DateCancelled] IS NULL then (0) else (1) end)), [Replaces_InvId] [varchar](10) NULL, [CustomValues] [nvarchar](max) NULL, [DateSent] [datetime] NULL, [DateFinalized] [datetime] NULL, [UserFinalized] [varchar](25) NULL, [DateCancelled] [datetime] NULL, [UserCancelled] [varchar](25) NULL, [DateCreated] [datetime] NOT NULL, [UserCreated] [varchar](25) NOT NULL, [DateModified] [datetime] NOT NULL, [UserModified] [varchar](25) NOT NULL, [file] [varbinary](max) NULL, CONSTRAINT [PK_fds__invoices] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fds__log] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__log]( [table] [varchar](50) NOT NULL, [action] [varchar](50) NOT NULL, [timestamp] [datetime] NOT NULL, [setid] [varchar](10) NULL, [info] [varchar](250) NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[fds__payments] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__payments]( [Id] [bigint] IDENTITY(1,1) NOT NULL, [ExternalID] [varchar](50) NULL, [InvId] [varchar](10) NOT NULL, [CustomerId] [bigint] NULL, [DateReceived] [datetime] NOT NULL, [AllocationStatus] [char](1) NULL, [IBAN] [varchar](25) NULL, [sender] [varchar](255) NULL, [reference] [varchar](35) NULL, [purpose] [varchar](140) NULL, [amount] [numeric](10, 3) NOT NULL, [rec_account] [varchar](25) NULL, CONSTRAINT [PK_fds__payments] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[fds__reminder] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__reminder]( [Id] [varchar](10) NOT NULL, [InvId] [varchar](10) NOT NULL, [type] [varchar](3) NULL, [amount] [numeric](10, 3) NULL, [text] [nvarchar](2000) NULL, [IsSent] [bit] NOT NULL, [CustomValues] [nvarchar](max) NULL, [DateSent] [datetime] NULL, [DateFinalized] [datetime] NULL, [UserFinalized] [varchar](25) NULL, [DateCreated] [datetime] NOT NULL, [UserCreated] [varchar](25) NOT NULL, [DateModified] [datetime] NOT NULL, [UserModified] [varchar](25) NOT NULL, [file] [varbinary](max) NULL, CONSTRAINT [PK_fds__reminder] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fds__status] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fds__status]( [table] [varchar](50) NOT NULL, [action] [varchar](50) NOT NULL, [timestamp] [datetime] NOT NULL, [setid] [varchar](10) NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[fis_admin_debuglog] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fis_admin_debuglog]( [uid] [int] IDENTITY(1,1) NOT NULL, [machine] [varchar](50) NULL, [type] [varchar](10) NULL, [url] [varchar](255) NULL, [uniquekey] [varchar](5) NULL, [authuser] [varchar](5) NULL, [query] [varchar](max) NULL, [form / content] [nvarchar](max) NULL, [server_variables] [varchar](max) NULL, [cookies] [varchar](max) NULL, [authcookie] [varchar](max) NULL, [files] [varchar](max) NULL, [isdebug] [bit] NULL, [timestamp] [datetime] NULL, CONSTRAINT [PK_fis_admin_debuglog] PRIMARY KEY CLUSTERED ( [uid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fis_useraccounts] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fis_useraccounts]( [useraccount_id] [varchar](5) NOT NULL, [name_enc] [varbinary](260) NOT NULL, [firstname_enc] [varbinary](260) NULL, [title_enc] [varbinary](120) NULL, [gender_enc] [varbinary](100) NULL, [email_enc] [varbinary](350) NOT NULL, [mobile_enc] [varbinary](120) NULL, [password_enc] [varbinary](100) NOT NULL, [language] [varchar](2) NULL, [UserDisabled] [varchar](36) NULL, [DateDisabled] [datetime] NULL, [UserCreated] [varchar](36) NOT NULL, [DateCreated] [datetime] NOT NULL, [UserModified] [varchar](36) NULL, [DateModified] [datetime] NOT NULL, [UserDeleted] [varchar](36) NULL, [DateDeleted] [datetime] NULL, CONSTRAINT [PK_fis_useraccounts] PRIMARY KEY CLUSTERED ( [useraccount_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[fis_useraccounts_settings] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fis_useraccounts_settings]( [useraccount_set_uid] [int] IDENTITY(1,1) NOT NULL, [useraccount_id] [varchar](5) NOT NULL, [key] [varchar](25) NOT NULL, [value] [varchar](255) NULL, [UserModified] [varchar](36) NOT NULL, [DateModified] [datetime] NOT NULL, CONSTRAINT [PK_fis_useraccounts_settings] PRIMARY KEY CLUSTERED ( [useraccount_set_uid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[fis_usergroups] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fis_usergroups]( [usergroup_id] [varchar](5) NOT NULL, [name_enc] [varbinary](600) NOT NULL, [UserCreated] [varchar](36) NOT NULL, [DateCreated] [datetime] NOT NULL, [UserModified] [varchar](36) NOT NULL, [DateModified] [datetime] NOT NULL, [UserDeleted] [varchar](36) NULL, [DateDeleted] [datetime] NULL, CONSTRAINT [PK_fis_usergroups] PRIMARY KEY CLUSTERED ( [usergroup_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[fis_usergroups_members] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fis_usergroups_members]( [uid] [int] IDENTITY(1,1) NOT NULL, [usergroup_id] [varchar](5) NULL, [useraccount_id] [varchar](5) NULL, [UserCreated] [varchar](36) NOT NULL, [DateCreated] [datetime] NOT NULL, [UserDeleted] [varchar](36) NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[fuchs_debug] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fuchs_debug]( [rn] [bigint] IDENTITY(1,1) NOT NULL, [interface] [varchar](50) NOT NULL, [url] [varchar](500) NULL, [data] [nvarchar](max) NULL, [date] [datetime] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fuchs_planner] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fuchs_planner]( [planner_id] [tinyint] IDENTITY(1,1) NOT NULL, [shortname] [varchar](10) NOT NULL, [name] [varchar](100) NULL, [description] [varchar](2000) NULL, [active] [bit] NOT NULL, CONSTRAINT [PK_fuchs_planner] PRIMARY KEY CLUSTERED ( [planner_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[fuchs_planner_groups] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fuchs_planner_groups]( [group_id] [int] NOT NULL, [code] AS ([dbo].[ott_b26]([group_id])), [planner_id] [tinyint] NOT NULL, [sequence_order] [tinyint] NOT NULL, [parent_codes] [varchar](50) NULL, [condition] [varchar](50) NULL, [shortname] [varchar](15) NULL, [name] [varchar](100) NULL, [description] [varchar](max) NULL, [selection_type] [varchar](10) NULL, [final] [bit] NOT NULL, [hide] [bit] NOT NULL, CONSTRAINT [PK_fuchs_planner_groups] PRIMARY KEY CLUSTERED ( [group_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fuchs_planner_options] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fuchs_planner_options]( [option_id] [int] IDENTITY(1,1) NOT NULL, [planner_id] [tinyint] NOT NULL, [group_id] [int] NOT NULL, [code] AS (([dbo].[ott_b26]([group_id])+'.')+[dbo].[ott_b26]([option_id])), [subgroup] [varchar](10) NULL, [option_order] [tinyint] NOT NULL, [option_type] [char](1) NULL, [condition] [varchar](100) NULL, [name] [varchar](100) NULL, [description] [varchar](2000) NULL, [tooltip] [varchar](500) NULL, [icon_url] [varchar](max) NULL, [hide] [bit] NOT NULL, CONSTRAINT [PK_fuchs_planner_options] PRIMARY KEY CLUSTERED ( [option_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[fuchs_planner_traffic] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[fuchs_planner_traffic]( [uid] [bigint] IDENTITY(1,1) NOT NULL, [planner_id] [tinyint] NOT NULL, [sessionid] [varchar](10) NOT NULL, [group_code] [varchar](10) NULL, [values] [nvarchar](4000) NULL, [DateSubmitted] [datetime] NOT NULL, CONSTRAINT [PK_fuchs_planner_traffic] PRIMARY KEY CLUSTERED ( [uid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__#customvalues] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__#customvalues]( [Id] [bigint] NOT NULL, [EntityID] [bigint] NOT NULL, [Property] [varchar](255) NOT NULL, [Meta] [varchar](255) NOT NULL, [Value] [varchar](1000) NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__#locations] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__#locations]( [Id] [bigint] NOT NULL, [EntityId] [bigint] NOT NULL, [Property] [varchar](255) NOT NULL, [Version] [int] NOT NULL, [AddressString] [nvarchar](255) NULL, [Postal] [nvarchar](255) NULL, [City] [nvarchar](255) NULL, [State] [nvarchar](255) NULL, [Country] [varchar](15) NULL, [Longitude] [numeric](8, 5) NULL, [Latitude] [numeric](8, 5) NULL, [IsValidLocation] [bit] NOT NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__appointments] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__appointments]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [State] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [EndDateTime] [datetime] NULL, [StartDateTime] [datetime] NOT NULL, [DrivingDistanceFrom] [int] NULL, [DrivingDistanceTo] [int] NULL, [WasReadOnClientSide] [bit] NOT NULL, [ContactIds] [varchar](max) NULL, [ServiceRequestId] [bigint] NOT NULL, [ContactId] [bigint] NOT NULL, [Note] [nvarchar](max) NULL, CONSTRAINT [PK_mfr__appointment] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__attachments] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__attachments]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [URI] [nvarchar](255) NULL, [StepId] [bigint] NOT NULL, CONSTRAINT [PK_mfr__attachment] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__comments] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__comments]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [DateOfCreation] [datetime] NOT NULL, [IsInternal] [bit] NOT NULL, [ServiceRequestId] [bigint] NOT NULL, [CompanyId] [bigint] NOT NULL, [Content] [nvarchar](max) NULL, CONSTRAINT [PK_mfr__comment] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__costcenters] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__costcenters]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, CONSTRAINT [PK_mfr__costcenter] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__d_#customvalues] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__d_#customvalues]( [Id] [bigint] NULL, [EntityID] [bigint] NULL, [Property] [varchar](255) NULL, [Meta] [varchar](255) NULL, [Value] [varchar](1000) NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__d_#locations] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__d_#locations]( [Id] [bigint] NULL, [EntityId] [bigint] NULL, [Property] [varchar](255) NULL, [Version] [int] NULL, [AddressString] [nvarchar](255) NULL, [Postal] [nvarchar](255) NULL, [City] [nvarchar](255) NULL, [State] [nvarchar](255) NULL, [Country] [varchar](15) NULL, [Longitude] [numeric](8, 5) NULL, [Latitude] [numeric](8, 5) NULL, [IsValidLocation] [bit] NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__d_*PartnerSet] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__d_*PartnerSet]( [Property] [varchar](50) NULL, [PartnerType] [varchar](25) NULL, [PartnerId] [bigint] NULL, [EntityId] [bigint] NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__d_appointments] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__d_appointments]( [Id] [bigint] NULL, [Version] [int] NULL, [State] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [EndDateTime] [datetime] NULL, [StartDateTime] [datetime] NULL, [DrivingDistanceFrom] [int] NULL, [DrivingDistanceTo] [int] NULL, [WasReadOnClientSide] [bit] NULL, [ContactIds] [varchar](max) NULL, [ServiceRequestId] [bigint] NULL, [ContactId] [bigint] NULL, [Note] [nvarchar](max) NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__d_comments] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__d_comments]( [Id] [bigint] NULL, [Version] [int] NULL, [DateOfCreation] [datetime] NULL, [IsInternal] [bit] NULL, [ServiceRequestId] [bigint] NULL, [CompanyId] [bigint] NULL, [Content] [nvarchar](max) NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__d_items] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__d_items]( [Id] [bigint] NULL, [Version] [int] NULL, [QuantityHours] [numeric](10, 3) NULL, [PlannedQuantityHours] [numeric](10, 3) NULL, [ItemTypeId] [bigint] NULL, [ItemNumber] [nvarchar](255) NULL, [TrackingId] [nvarchar](255) NULL, [Manufacture] [nvarchar](255) NULL, [Price] [numeric](10, 3) NULL, [Costs] [numeric](10, 3) NULL, [NameOrNumber] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NULL, [Note] [nvarchar](max) NULL, [ExternalId] [nvarchar](255) NULL, [Discount] [numeric](10, 3) NULL, [VAT] [numeric](10, 3) NULL, [IsManual] [bit] NULL, [SortOrder] [int] NULL, [Type] [nvarchar](255) NULL, [ServiceRequestId] [bigint] NULL, [ServiceObjectId] [bigint] NULL, [CreatorId] [bigint] NULL, [UnitId] [bigint] NULL, [UnitString] [nvarchar](255) NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__d_steps] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__d_steps]( [Id] [bigint] NULL, [MobileId] [bigint] NULL, [Version] [int] NULL, [Name] [nvarchar](255) NULL, [IsDone] [bit] NULL, [HasError] [bit] NULL, [TrackingId] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [SortOrder] [int] NULL, [Data] [nvarchar](max) NULL, [DateModifiedOffline] [datetime] NULL, [ServiceRequestId] [bigint] NULL, [Description] [nvarchar](max) NULL, [Comment] [nvarchar](max) NULL, [InternalComment] [nvarchar](max) NULL, [ServiceObjectId] [bigint] NULL, [StepListTemplateId] [bigint] NULL, [ParentId] [bigint] NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__d_stockmovements] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__d_stockmovements]( [Id] [bigint] NULL, [Version] [int] NULL, [Amount] [numeric](10, 3) NULL, [AmountReceived] [numeric](10, 3) NULL, [ExternalId] [varchar](255) NULL, [ItemId] [bigint] NULL, [ItemTypeId] [bigint] NULL, [StockMovementType] [varchar](255) NULL, [State] [varchar](255) NULL, [ServiceRequestId] [bigint] NULL, [WarehouseId] [bigint] NULL, [DateOfCreation] [datetime] NULL, [DateModified] [datetime] NULL, [TargetDate] [datetime] NULL, [CreatedById] [bigint] NULL, [ConfirmedById] [bigint] NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__d_timeevents] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__d_timeevents]( [Id] [bigint] NULL, [Version] [int] NULL, [State] [nvarchar](255) NULL, [IsApproved] [bit] NULL, [TimeEventType] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [DateModified] [datetime] NULL, [StartDateTime] [datetime] NULL, [EndDateTime] [datetime] NULL, [ProposedDrivingDistance] [int] NULL, [ContactId] [bigint] NULL, [ServiceRequestId] [bigint] NULL, [Description] [nvarchar](max) NULL, [DateDeleted] [datetime] NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__documents] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__documents]( [Id] [bigint] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [Version] [int] NOT NULL, [State] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [URI] [nvarchar](255) NULL, [IsGlobal] [bit] NOT NULL, [StartDateTime] [datetime] NULL, [EndDateTime] [datetime] NULL, [FileName] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [UploadDate] [datetime] NOT NULL, [IsLink] [bit] NOT NULL, [ContentType] [nvarchar](255) NULL, [HTMLCode] [nvarchar](255) NULL, [ServiceRequestId] [bigint] NOT NULL, [Note] [nvarchar](255) NULL, CONSTRAINT [PK_mfr__document] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__items] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__items]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [QuantityHours] [numeric](10, 3) NOT NULL, [PlannedQuantityHours] [numeric](10, 3) NOT NULL, [ItemTypeId] [bigint] NULL, [ItemNumber] [nvarchar](255) NULL, [TrackingId] [nvarchar](255) NULL, [Manufacture] [nvarchar](255) NULL, [Price] [numeric](10, 3) NOT NULL, [Costs] [numeric](10, 3) NULL, [NameOrNumber] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NULL, [Note] [nvarchar](max) NULL, [ExternalId] [nvarchar](255) NULL, [Discount] [numeric](10, 3) NOT NULL, [VAT] [numeric](10, 3) NOT NULL, [IsManual] [bit] NOT NULL, [SortOrder] [int] NOT NULL, [Type] [nvarchar](255) NULL, [ServiceRequestId] [bigint] NOT NULL, [ServiceObjectId] [bigint] NOT NULL, [CreatorId] [bigint] NOT NULL, [UnitId] [bigint] NULL, [UnitString] [nvarchar](255) NULL, CONSTRAINT [PK_mfr__item] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__itemtypes] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__itemtypes]( [Id] [bigint] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [Version] [int] NOT NULL, [Costs] [numeric](10, 3) NOT NULL, [Description] [nvarchar](max) NULL, [ListPrice] [numeric](10, 3) NOT NULL, [Manufacture] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [ItemNumber] [nvarchar](255) NULL, [NameOrNumber] [nvarchar](1000) NULL, [GlobalTradeItemNr] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [Price] [numeric](10, 3) NOT NULL, [VAT] [numeric](10, 3) NOT NULL, [IsPortalOnly] [bit] NOT NULL, [Discount] [numeric](10, 3) NOT NULL, [DateModified] [datetime] NOT NULL, [IsDiscontinued] [bit] NOT NULL, [IsWarehouse] [bit] NOT NULL, [UnitId] [bigint] NULL, [UnitString] [nvarchar](255) NULL, CONSTRAINT [PK_mfr__itemtype] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__itemunits] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__itemunits]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, CONSTRAINT [PK_mfr__itemunit] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__products] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__products]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [SubKey] [nvarchar](255) NULL, [Description] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [MappingId] [nvarchar](255) NULL, [CustomValueStepTemplateId] [bigint] NOT NULL, CONSTRAINT [PK_mfr__product] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__qualifications] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__qualifications]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, CONSTRAINT [PK_mfr__qualification] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__reports] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__reports]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [DateOfCreation] [datetime] NOT NULL, [URI] [nvarchar](255) NULL, [DocumentName] [nvarchar](255) NULL, [FileTypeString] [nvarchar](255) NULL, [ReportDefinitionCode] [nvarchar](255) NULL, [ServiceObjectId] [bigint] NOT NULL, [CanBeDeleted] [bit] NOT NULL, [InvoiceBalance] [numeric](10, 3) NOT NULL, [InvoiceId] [nvarchar](255) NULL, [DueDate] [datetime] NOT NULL, [IsPayed] [bit] NOT NULL, [IsInvoice] [bit] NOT NULL, [IsCanceled] [bit] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, CONSTRAINT [PK_mfr__report] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__serviceobjects] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__serviceobjects]( [Id] [bigint] NOT NULL, [Location#ID] [bigint] NULL, [Name] [nvarchar](255) NULL, [Note] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NOT NULL, [DateModified] [datetime] NOT NULL, [ExternalId] [nvarchar](255) NULL, [MappingId] [nvarchar](255) NULL, [QuickSearch] [nvarchar](255) NULL, [Version] [int] NOT NULL, [CreateGeoLocation] [bit] NOT NULL, [IsWarehouse] [bit] NOT NULL, [ParentServiceObjectId] [bigint] NOT NULL, [CompanyId] [bigint] NOT NULL, [ProductId] [bigint] NOT NULL, CONSTRAINT [PK_mfr__serviceobject] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__servicerequests] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__servicerequests]( [Id] [bigint] NOT NULL, [Name] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [InvoiceId] [nvarchar](255) NULL, [ClosedAt] [datetime] NULL, [ReleasedAt] [datetime] NULL, [WorkDoneAt] [datetime] NULL, [TargetTimeInMinutes] [bigint] NOT NULL, [DateModified] [datetime] NULL, [DateOfCreation] [datetime] NULL, [DueDateRangeStart] [datetime] NULL, [DueDateRangeEnd] [datetime] NULL, [PortalLink] [nvarchar](255) NULL, [CostCenterId] [bigint] NULL, [Description] [nvarchar](max) NULL, [State] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NOT NULL, [CurrentOwnerId] [bigint] NULL, [CustomerId] [bigint] NULL, [ParentServiceRequestId] [bigint] NULL, [Location#ID] [bigint] NULL, [Version] [int] NOT NULL, [IsTemplate] [bit] NOT NULL, [IsTemplateMobile] [bit] NOT NULL, [CreateFromServiceRequestTemplateId] [bigint] NOT NULL, [Type] [nvarchar](255) NULL, CONSTRAINT [PK_mfr__servicerequest] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__steplisttemplateinstances] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__steplisttemplateinstances]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [ServiceRequestId] [bigint] NULL, [TemplateId] [bigint] NULL, CONSTRAINT [PK_mfr__steplisttemplateinstance] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__steplisttemplates] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__steplisttemplates]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [MappingId] [nvarchar](255) NULL, [DateModified] [datetime] NULL, [IsReleased] [bit] NOT NULL, [IsDurable] [bit] NOT NULL, CONSTRAINT [PK_mfr__steplisttemplate] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__steps] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__steps]( [Id] [bigint] NOT NULL, [MobileId] [bigint] NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [IsDone] [bit] NOT NULL, [HasError] [bit] NOT NULL, [TrackingId] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [SortOrder] [int] NOT NULL, [Data] [nvarchar](max) NULL, [DateModifiedOffline] [datetime] NULL, [ServiceRequestId] [bigint] NULL, [Description] [nvarchar](max) NULL, [Comment] [nvarchar](max) NULL, [InternalComment] [nvarchar](max) NULL, [ServiceObjectId] [bigint] NULL, [StepListTemplateId] [bigint] NULL, [ParentId] [bigint] NULL, CONSTRAINT [PK_mfr__step] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__stockmovements] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__stockmovements]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Amount] [numeric](10, 3) NOT NULL, [AmountReceived] [numeric](10, 3) NOT NULL, [ExternalId] [varchar](255) NULL, [ItemId] [bigint] NULL, [ItemTypeId] [bigint] NULL, [StockMovementType] [varchar](255) NULL, [State] [varchar](255) NULL, [ServiceRequestId] [bigint] NOT NULL, [WarehouseId] [bigint] NOT NULL, [DateOfCreation] [datetime] NOT NULL, [DateModified] [datetime] NOT NULL, [TargetDate] [datetime] NOT NULL, [CreatedById] [bigint] NOT NULL, [ConfirmedById] [bigint] NOT NULL, CONSTRAINT [PK_mfr__stockmovement] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__tags] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__tags]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [ColorDefinition] [nvarchar](255) NULL, [Type] [nvarchar](255) NOT NULL, CONSTRAINT [PK_mfr__tag] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__timeevents] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__timeevents]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [State] [nvarchar](255) NULL, [IsApproved] [bit] NOT NULL, [TimeEventType] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [StartDateTime] [datetime] NOT NULL, [EndDateTime] [datetime] NOT NULL, [ProposedDrivingDistance] [int] NOT NULL, [ContactId] [bigint] NOT NULL, [ServiceRequestId] [bigint] NOT NULL, [Description] [nvarchar](max) NULL, CONSTRAINT [PK_mfr__timeevent] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[mfr__users] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[mfr__users]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [UserName] [nvarchar](255) NULL, [IsSystem] [bit] NOT NULL, [CreationDate] [datetime] NOT NULL, [IsApproved] [bit] NOT NULL, [ContactId] [bigint] NOT NULL, [PreferedLanguage] [nvarchar](255) NULL, [EmailChannelEnabled] [bit] NOT NULL, [HasFullScreenPreference] [bit] NOT NULL, [TimeZone] [int] NOT NULL, [PreferedCulture] [nvarchar](255) NULL, [IsActive] [bit] NOT NULL, [IsMobile] [bit] NOT NULL, [LastLoginDate] [datetime] NULL, [UserGuideProgress] [nvarchar](255) NULL, [DashboardSettings] [nvarchar](4000) NULL, CONSTRAINT [PK_mfr__user] PRIMARY KEY CLUSTERED ( [Id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_archive__items] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_archive__items]( [ocms_iid] [bigint] NOT NULL, [parent_iid] [bigint] NULL, [ocms_pid] [bigint] NULL, [name] [nvarchar](255) NULL, [view] [bit] NOT NULL, [template_id] [bigint] NULL, [hide] [bit] NOT NULL, [order] [int] NOT NULL, [DateCreated] [datetime] NULL, [DateModified] [datetime] NULL, [DateDeleted] [datetime] NULL, [UserDeleted] [varchar](36) NULL ) ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_archive__properties] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_archive__properties]( [ocms_pid] [bigint] NULL, [ocms_iid] [bigint] NULL, [key] [varchar](50) NULL, [value] [nvarchar](max) NULL, [locale] [varchar](5) NULL, [DateCreated] [datetime] NULL, [DateModified] [datetime] NULL, [DateDeleted] [datetime] NULL, [UserDeleted] [varchar](36) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_debug] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_debug]( [uid] [bigint] IDENTITY(1,1) NOT NULL, [machine] [varchar](50) NULL, [error] [varchar](2000) NULL, [exception] [varchar](max) NULL, [procedure] [varchar](255) NULL, [authuser] [varchar](25) NULL, [data] [nvarchar](max) NULL, [isdebug] [bit] NULL, [timestamp] [datetime] NOT NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_items] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_items]( [ocms_iid] [bigint] NOT NULL, [parent_iid] [bigint] NULL, [ocms_pid] [bigint] NULL, [name] [nvarchar](255) NULL, [view] [bit] NOT NULL, [template_id] [bigint] NULL, [hide] [bit] NOT NULL, [order] [int] NOT NULL, [DateCreated] [datetime] NULL, [DateModified] [datetime] NULL, CONSTRAINT [PK_ocms_items] PRIMARY KEY CLUSTERED ( [ocms_iid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_log__properties] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_log__properties]( [ocms_pid] [bigint] NULL, [action] [varchar](50) NULL, [n_ocms_iid] [bigint] NULL, [n_key] [varchar](50) NULL, [n_value] [nvarchar](max) NULL, [n_locale] [varchar](5) NULL, [n_DateCreated] [datetime] NULL, [n_DateModified] [datetime] NULL, [n_DateDeleted] [datetime] NULL, [n_UserDeleted] [varchar](36) NULL, [o_ocms_iid] [bigint] NULL, [o_key] [varchar](50) NULL, [o_value] [nvarchar](max) NULL, [o_locale] [varchar](5) NULL, [o_DateCreated] [datetime] NULL, [o_DateModified] [datetime] NULL, [o_DateDeleted] [datetime] NULL, [o_UserDeleted] [varchar](36) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_navigation] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_navigation]( [ocms_nid] [bigint] IDENTITY(1,1) NOT NULL, [ocms_iid] [bigint] NOT NULL, [parent_iid] [bigint] NULL, [locale] [varchar](5) NOT NULL, [alias] [varchar](25) NOT NULL, CONSTRAINT [PK_ocms_navigation] PRIMARY KEY CLUSTERED ( [ocms_nid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_properties] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_properties]( [ocms_pid] [bigint] NOT NULL, [ocms_iid] [bigint] NOT NULL, [key] [varchar](50) NULL, [value] [nvarchar](max) NOT NULL, [locale] [varchar](5) NULL, [DateCreated] [datetime] NULL, [DateModified] [datetime] NULL, CONSTRAINT [PK_ocms_properties] PRIMARY KEY CLUSTERED ( [ocms_pid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_settings] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_settings]( [ocms_set] [bigint] IDENTITY(1,1) NOT NULL, [key] [varchar](25) NOT NULL, [value] [varchar](2000) NULL, CONSTRAINT [PK_ocms_settings] PRIMARY KEY CLUSTERED ( [ocms_set] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_template_properties] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_template_properties]( [ocms_tpid] [bigint] NOT NULL, [ocms_tid] [bigint] NOT NULL, [key] [varchar](50) NOT NULL, [mandatory] [bit] NOT NULL, [type] [varchar](50) NOT NULL, [default] [nvarchar](max) NULL, [condition] [varchar](max) NULL, [order] [int] NOT NULL, CONSTRAINT [PK_ocms_template_properties] PRIMARY KEY CLUSTERED ( [ocms_tpid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_templates] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_templates]( [ocms_tid] [bigint] IDENTITY(1,1) NOT NULL, [name] [varchar](255) NULL, [partial_view] [varchar](255) NULL, CONSTRAINT [PK_ocms_templates] PRIMARY KEY CLUSTERED ( [ocms_tid] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_translations] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_translations]( [ocms_tln] [bigint] IDENTITY(1,1) NOT NULL, [context_typ] [nvarchar](15) NOT NULL, [context] [bigint] NULL, [value] [nvarchar](255) NOT NULL, [translation] [nvarchar](255) NOT NULL, [locale] [varchar](5) NOT NULL, CONSTRAINT [PK_ocms_translations] PRIMARY KEY CLUSTERED ( [ocms_tln] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[ocms_useraccounts] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[ocms_useraccounts]( [useraccount_id] [varchar](5) NOT NULL, [name_enc] [varbinary](600) NOT NULL, [email_enc] [varbinary](350) NOT NULL, [mobile_enc] [varbinary](120) NULL, [password_enc] [varbinary](100) NOT NULL, [UserDisabled] [varchar](36) NULL, [DateDisabled] [datetime] NULL, [UserCreated] [varchar](36) NOT NULL, [DateCreated] [datetime] NOT NULL, [UserModified] [varchar](36) NULL, [DateModified] [datetime] NOT NULL, [UserDeleted] [varchar](36) NULL, [DateDeleted] [datetime] NULL, CONSTRAINT [PK_ocms_useraccounts] PRIMARY KEY CLUSTERED ( [useraccount_id] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] ) ON [PRIMARY] GO /****** Object: Table [dbo].[t_9xnak_mfr__users] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[t_9xnak_mfr__users]( [setid] [nvarchar](max) NULL, [Id] [bigint] NULL, [Version] [int] NULL, [UserName] [nvarchar](max) NULL, [IsSystem] [bit] NULL, [CreationDate] [datetime] NULL, [IsApproved] [bit] NULL, [ContactId] [bigint] NULL, [PreferedLanguage] [nvarchar](max) NULL, [EmailChannelEnabled] [bit] NULL, [HasFullScreenPreference] [bit] NULL, [TimeZone] [int] NULL, [PreferedCulture] [nvarchar](max) NULL, [IsActive] [bit] NULL, [IsMobile] [bit] NULL, [LastLoginDate] [datetime] NULL, [UserGuideProgress] [nvarchar](max) NULL, [DashboardSettings] [nvarchar](max) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[t_w7fmz_mfr__users] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[t_w7fmz_mfr__users]( [setid] [nvarchar](max) NULL, [Id] [bigint] NULL, [Version] [int] NULL, [UserName] [nvarchar](max) NULL, [IsSystem] [bit] NULL, [CreationDate] [datetime] NULL, [IsApproved] [bit] NULL, [ContactId] [bigint] NULL, [PreferedLanguage] [nvarchar](max) NULL, [EmailChannelEnabled] [bit] NULL, [HasFullScreenPreference] [bit] NULL, [TimeZone] [int] NULL, [PreferedCulture] [nvarchar](max) NULL, [IsActive] [bit] NULL, [IsMobile] [bit] NULL, [LastLoginDate] [datetime] NULL, [UserGuideProgress] [nvarchar](max) NULL, [DashboardSettings] [nvarchar](max) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Table [dbo].[tt_backup] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[tt_backup]( [Id] [bigint] NOT NULL, [Version] [int] NOT NULL, [State] [nvarchar](255) NULL, [IsApproved] [bit] NOT NULL, [TimeEventType] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [StartDateTime] [datetime] NOT NULL, [EndDateTime] [datetime] NOT NULL, [ProposedDrivingDistance] [int] NOT NULL, [ContactId] [bigint] NOT NULL, [ServiceRequestId] [bigint] NOT NULL, [Description] [nvarchar](max) NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO /****** Object: Index [IX_fuchs_planner_groups] Script Date: 15.06.2021 12:30:14 ******/ CREATE UNIQUE NONCLUSTERED INDEX [IX_fuchs_planner_groups] ON [dbo].[fuchs_planner_groups] ( [planner_id] ASC, [sequence_order] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO /****** Object: Index [IX_fuchs_planner_options] Script Date: 15.06.2021 12:30:14 ******/ CREATE UNIQUE NONCLUSTERED INDEX [IX_fuchs_planner_options] ON [dbo].[fuchs_planner_options] ( [planner_id] ASC, [group_id] ASC, [option_order] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [mfr__#locations__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__#locations__ix1] ON [dbo].[mfr__#locations] ( [EntityId] ASC, [Property] ASC ) INCLUDE([AddressString],[Postal],[City],[Country]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO /****** Object: Index [mfr__#locations__ix2] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__#locations__ix2] ON [dbo].[mfr__#locations] ( [Id] ASC ) INCLUDE([AddressString],[Postal],[City],[State],[Country],[Longitude],[Latitude]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [mfr__*PartnerSet__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__*PartnerSet__ix1] ON [dbo].[mfr__*PartnerSet] ( [Property] ASC ) INCLUDE([PartnerId],[EntityId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [mfr__*PartnerSet__ix2] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__*PartnerSet__ix2] ON [dbo].[mfr__*PartnerSet] ( [EntityId] ASC, [Property] ASC ) INCLUDE([PartnerId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [mfr__appointments__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__appointments__ix1] ON [dbo].[mfr__appointments] ( [State] ASC ) INCLUDE([EndDateTime],[StartDateTime],[ServiceRequestId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [mfr__appointments__ix2] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__appointments__ix2] ON [dbo].[mfr__appointments] ( [State] ASC, [ServiceRequestId] ASC ) INCLUDE([EndDateTime],[StartDateTime]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO /****** Object: Index [mfr__contacts__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__contacts__ix1] ON [dbo].[mfr__contacts] ( [CompanyId] ASC ) INCLUDE([CustomValues],[FirstName],[LastName],[Email],[JobTitle],[MobilePhone],[Telephone],[Fax],[Note],[DateModified],[Version],[IsUser],[ExternalId],[Gender],[UserId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO /****** Object: Index [mfr__items__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__items__ix1] ON [dbo].[mfr__items] ( [ServiceRequestId] ASC ) INCLUDE([QuantityHours],[Price]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [mfr__servicerequests__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__servicerequests__ix1] ON [dbo].[mfr__servicerequests] ( [InvoiceId] ASC ) INCLUDE([Name],[DateOfCreation],[CustomerId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO /****** Object: Index [mfr__steps__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE NONCLUSTERED INDEX [mfr__steps__ix1] ON [dbo].[mfr__steps] ( [ServiceRequestId] ASC ) INCLUDE([MobileId],[Version],[Name],[IsDone],[HasError],[TrackingId],[Type],[SortOrder],[Data],[DateModifiedOffline],[Description],[Comment],[InternalComment],[ServiceObjectId],[StepListTemplateId],[ParentId]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [ocms_items__ix0] Script Date: 15.06.2021 12:30:14 ******/ CREATE UNIQUE NONCLUSTERED INDEX [ocms_items__ix0] ON [dbo].[ocms_items] ( [parent_iid] ASC, [name] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [ocms_items__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE UNIQUE NONCLUSTERED INDEX [ocms_items__ix1] ON [dbo].[ocms_items] ( [name] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [ocms_navigation__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE UNIQUE NONCLUSTERED INDEX [ocms_navigation__ix1] ON [dbo].[ocms_navigation] ( [ocms_iid] ASC, [locale] ASC, [alias] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [ocms_template_properties__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE UNIQUE NONCLUSTERED INDEX [ocms_template_properties__ix1] ON [dbo].[ocms_template_properties] ( [ocms_tid] ASC, [key] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [ocms_templates__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE UNIQUE NONCLUSTERED INDEX [ocms_templates__ix1] ON [dbo].[ocms_templates] ( [name] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO SET ANSI_PADDING ON GO /****** Object: Index [ocms_useraccounts__ix1] Script Date: 15.06.2021 12:30:14 ******/ CREATE UNIQUE NONCLUSTERED INDEX [ocms_useraccounts__ix1] ON [dbo].[ocms_useraccounts] ( [email_enc] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] GO ALTER TABLE [dbo].[fds__invoices] ADD CONSTRAINT [DF_fds__invoices_Version] DEFAULT ((0)) FOR [Version] GO ALTER TABLE [dbo].[fds__invoices] ADD CONSTRAINT [DF_fds__invoices_InvoiceTitle] DEFAULT ('Rechnung') FOR [InvoiceTitle] GO ALTER TABLE [dbo].[fds__invoices] ADD CONSTRAINT [DF_fds__invoices_IsPayed] DEFAULT ((0)) FOR [IsPayed] GO ALTER TABLE [dbo].[fds__invoices] ADD CONSTRAINT [DF_fds__invoices_IsSent] DEFAULT ((0)) FOR [IsSent] GO ALTER TABLE [dbo].[fds__payments] ADD CONSTRAINT [DF_fds__payments_IsAllocated] DEFAULT ((0)) FOR [AllocationStatus] GO ALTER TABLE [dbo].[fds__reminder] ADD CONSTRAINT [DF_fds__reminder_IsSent] DEFAULT ((0)) FOR [IsSent] GO ALTER TABLE [dbo].[fis_useraccounts] ADD CONSTRAINT [DF_fis_useraccounts_language] DEFAULT ('de') FOR [language] GO ALTER TABLE [dbo].[fis_useraccounts] ADD CONSTRAINT [DF_fis_useraccounts_DateCreated] DEFAULT (getutcdate()) FOR [DateCreated] GO ALTER TABLE [dbo].[fis_useraccounts] ADD CONSTRAINT [DF_fis_useraccounts_DateModified] DEFAULT (getutcdate()) FOR [DateModified] GO ALTER TABLE [dbo].[fuchs_debug] ADD CONSTRAINT [DF_fuchs_debug_date] DEFAULT (getutcdate()) FOR [date] GO ALTER TABLE [dbo].[fuchs_planner] ADD CONSTRAINT [DF_fuchs_planner_active] DEFAULT ((1)) FOR [active] GO ALTER TABLE [dbo].[fuchs_planner_groups] ADD CONSTRAINT [DF_fuchs_planner_groups_order] DEFAULT ((0)) FOR [sequence_order] GO ALTER TABLE [dbo].[fuchs_planner_groups] ADD CONSTRAINT [DF_fuchs_planner_groups_final] DEFAULT ((0)) FOR [final] GO ALTER TABLE [dbo].[fuchs_planner_groups] ADD CONSTRAINT [DF_fuchs_planner_groups_hide] DEFAULT ((0)) FOR [hide] GO ALTER TABLE [dbo].[fuchs_planner_options] ADD CONSTRAINT [DF_Table_1_item_oder] DEFAULT ((0)) FOR [option_order] GO ALTER TABLE [dbo].[fuchs_planner_options] ADD CONSTRAINT [DF_fuchs_planner_options_hide] DEFAULT ((0)) FOR [hide] GO ALTER TABLE [dbo].[fuchs_planner_traffic] ADD CONSTRAINT [DF_fuchs_planner_traffic_DateSubmitted] DEFAULT (getutcdate()) FOR [DateSubmitted] GO ALTER TABLE [dbo].[ocms_debug] ADD CONSTRAINT [DF_ocms_debug_timestamp] DEFAULT (getutcdate()) FOR [timestamp] GO ALTER TABLE [dbo].[ocms_items] ADD CONSTRAINT [DF_ocms_items_view] DEFAULT ((0)) FOR [view] GO ALTER TABLE [dbo].[ocms_items] ADD CONSTRAINT [DF_ocms_items_hide] DEFAULT ((0)) FOR [hide] GO ALTER TABLE [dbo].[ocms_items] ADD CONSTRAINT [DF_ocms_items_order] DEFAULT ((0)) FOR [order] GO ALTER TABLE [dbo].[ocms_items] ADD CONSTRAINT [DF_ocms_items_DateCreated] DEFAULT (getutcdate()) FOR [DateCreated] GO ALTER TABLE [dbo].[ocms_items] ADD CONSTRAINT [DF_ocms_items_DateModified] DEFAULT (getutcdate()) FOR [DateModified] GO ALTER TABLE [dbo].[ocms_properties] ADD CONSTRAINT [DF_ocms_properties_DateCreated] DEFAULT (getutcdate()) FOR [DateCreated] GO ALTER TABLE [dbo].[ocms_properties] ADD CONSTRAINT [DF_ocms_properties_DateModified] DEFAULT (getutcdate()) FOR [DateModified] GO ALTER TABLE [dbo].[ocms_template_properties] ADD CONSTRAINT [DF_ocms_template_properties_mandatory] DEFAULT ((0)) FOR [mandatory] GO ALTER TABLE [dbo].[ocms_template_properties] ADD CONSTRAINT [DF_ocms_template_properties_order] DEFAULT ((0)) FOR [order] GO ALTER TABLE [dbo].[ocms_useraccounts] ADD CONSTRAINT [DF_ocms_useraccounts_DateCreated] DEFAULT (getutcdate()) FOR [DateCreated] GO ALTER TABLE [dbo].[ocms_useraccounts] ADD CONSTRAINT [DF_ocms_useraccounts_DateModified] DEFAULT (getutcdate()) FOR [DateModified] GO ALTER TABLE [dbo].[fuchs_planner_groups] WITH CHECK ADD CONSTRAINT [FK_fuchs_planner_groups_fuchs_planner] FOREIGN KEY([planner_id]) REFERENCES [dbo].[fuchs_planner] ([planner_id]) GO ALTER TABLE [dbo].[fuchs_planner_groups] CHECK CONSTRAINT [FK_fuchs_planner_groups_fuchs_planner] GO ALTER TABLE [dbo].[fuchs_planner_groups] WITH CHECK ADD CONSTRAINT [FK_fuchs_planner_groups_fuchs_planner_groups] FOREIGN KEY([group_id]) REFERENCES [dbo].[fuchs_planner_groups] ([group_id]) GO ALTER TABLE [dbo].[fuchs_planner_groups] CHECK CONSTRAINT [FK_fuchs_planner_groups_fuchs_planner_groups] GO ALTER TABLE [dbo].[fuchs_planner_options] WITH CHECK ADD CONSTRAINT [FK_fuchs_planner_options_fuchs_planner] FOREIGN KEY([planner_id]) REFERENCES [dbo].[fuchs_planner] ([planner_id]) GO ALTER TABLE [dbo].[fuchs_planner_options] CHECK CONSTRAINT [FK_fuchs_planner_options_fuchs_planner] GO ALTER TABLE [dbo].[fuchs_planner_options] WITH CHECK ADD CONSTRAINT [FK_fuchs_planner_options_fuchs_planner_groups] FOREIGN KEY([group_id]) REFERENCES [dbo].[fuchs_planner_groups] ([group_id]) GO ALTER TABLE [dbo].[fuchs_planner_options] CHECK CONSTRAINT [FK_fuchs_planner_options_fuchs_planner_groups] GO ALTER TABLE [dbo].[ocms_items] WITH CHECK ADD CONSTRAINT [FK_ocms_items_ocms_items] FOREIGN KEY([ocms_iid]) REFERENCES [dbo].[ocms_items] ([ocms_iid]) GO ALTER TABLE [dbo].[ocms_items] CHECK CONSTRAINT [FK_ocms_items_ocms_items] GO ALTER TABLE [dbo].[ocms_items] WITH CHECK ADD CONSTRAINT [FK_ocms_items_ocms_properties] FOREIGN KEY([ocms_pid]) REFERENCES [dbo].[ocms_properties] ([ocms_pid]) GO ALTER TABLE [dbo].[ocms_items] CHECK CONSTRAINT [FK_ocms_items_ocms_properties] GO ALTER TABLE [dbo].[ocms_items] WITH CHECK ADD CONSTRAINT [FK_ocms_items_ocms_templates] FOREIGN KEY([template_id]) REFERENCES [dbo].[ocms_templates] ([ocms_tid]) GO ALTER TABLE [dbo].[ocms_items] CHECK CONSTRAINT [FK_ocms_items_ocms_templates] GO ALTER TABLE [dbo].[ocms_items] WITH CHECK ADD CONSTRAINT [FK_ocms_items_parent__ocms_items] FOREIGN KEY([parent_iid]) REFERENCES [dbo].[ocms_items] ([ocms_iid]) GO ALTER TABLE [dbo].[ocms_items] CHECK CONSTRAINT [FK_ocms_items_parent__ocms_items] GO ALTER TABLE [dbo].[ocms_properties] WITH CHECK ADD CONSTRAINT [FK_ocms_properties_ocms_items] FOREIGN KEY([ocms_iid]) REFERENCES [dbo].[ocms_items] ([ocms_iid]) ON DELETE CASCADE GO ALTER TABLE [dbo].[ocms_properties] CHECK CONSTRAINT [FK_ocms_properties_ocms_items] GO ALTER TABLE [dbo].[ocms_template_properties] WITH CHECK ADD CONSTRAINT [FK_ocms_template_properties_ocms_items] FOREIGN KEY([ocms_tid]) REFERENCES [dbo].[ocms_templates] ([ocms_tid]) GO ALTER TABLE [dbo].[ocms_template_properties] CHECK CONSTRAINT [FK_ocms_template_properties_ocms_items] GO /****** Object: StoredProcedure [dbo].[fds__admin_getReportCatalog] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Dr. Stefan Ott -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__admin_getReportCatalog] @report_name nvarchar(255) ,@authuser varchar(100) = '' AS BEGIN SET NOCOUNT ON; DECLARE @today date = GETDATE(); DECLARE @PROCEDURES TABLE ([object_id] bigint null, [typ] varchar(5), [ctype] varchar(50), [name] nvarchar(255), [label] nvarchar(255), [description] nvarchar(4000) , [tags_csv] varchar(255) , [categories_csv] varchar(255) , [link] varchar(255) , [functions] varchar(10) , [refresh] smallint , [auth] bit , [parameter] nvarchar(1000) NULL , [help_url] varchar(255) , [display_order] smallint); DECLARE @PARAMS TABLE([object_id] bigint, [name] nvarchar(255), [Type] varchar(100), [order] tinyint, [default] nvarchar(255), [ValueList] nvarchar(max)); --WITH nfo as (SELECT * FROM [dbo].[ctm__generic] where [typ] = 'udp_info') WITH nfo as (SELECT *, ROW_NUMBER() OVER (ORDER BY [category],[display_order],[key]) as '#' FROM [dbo].[fds__admin_reportcatalog]) ,report_objects as (SELECT [object_id], [name] FROM [site_fuchs].[sys].[all_objects] WHERE [type_desc] = 'SQL_STORED_PROCEDURE' AND [schema_id] = 1 and (([name] like 'fds[_][_]r[_]%' or [name] like 'fds[_][_]xls[_]%') and [name] COLLATE SQL_Latin1_General_CP1_CI_AS not in ('ctm_r_base')) ) INSERT INTO @PROCEDURES ([object_id], [typ], [ctype], [name], [label], [description], [tags_csv], [categories_csv], [link], [functions], [refresh], [auth], [help_url], [display_order]) SELECT o.[object_id] , [typ] = ISNULL(SUBSTRING([name], PATINDEX('%[_]%[_]%', [name]) + 1, CHARINDEX('_', [name], PATINDEX('%[_]%[_]%', [name]) + 1) - PATINDEX('%[_]%[_]%', [name]) - 1),'s') , [ctype] = ISNULL(nfo.[type],'report') , LOWER(ISNULL(o.[name], nfo.[key])) , nfo.[label] , nfo.[description] , nfo.[tags_csv] , CASE WHEN nfo.[key] is null THEN 'Draft' ELSE ISNULL(nfo.[category], 'Common') END , nfo.[link] , nfo.[functions] , ISNULL(nfo.[refresh],-1) , [auth] = CASE WHEN ISNULL(nfo.[auth],'') = '' THEN 1 WHEN (';' + ISNULL(nfo.[auth],'') + ';') like ('%;' + @authuser + ';%') then 1 else 0 end , nfo.[help_url] , ISNULL(nfo.[display_order], 10000) FROM report_objects as o FULL OUTER JOIN nfo ON LOWER(nfo.[key]) COLLATE SQL_Latin1_General_CP1_CI_AS = LOWER(o.[name]) AND nfo.[type] = 'report' WHERE ([name] = @report_name OR ISNULL(@report_name, '') = '') AND (nfo.[type] <> 'report' OR o.[object_id] is not NULL) -- make sure no orphaned catalog entries are included AND ISNULL(nfo.[hidden], 0) = 0; -- exclude all that are set as hidden --AND ([object_id] = @report_id OR @report_id is null); UPDATE @PROCEDURES --SET [functions] = CASE WHEN [typ] = 'xls' and [functions] is null THEN 'd' ELSE [functions] END SET [functions] = CASE WHEN [typ] = 'xls' THEN 'd' ELSE [functions] END ,[categories_csv] = CASE WHEN [typ] = 'xls' and ISNULL([categories_csv],'') = '' THEN 'Data Download' WHEN [typ] = 'link' and ISNULL([categories_csv],'') = '' THEN 'Data Download' ELSE [categories_csv] END; UPDATE @PROCEDURES SET [categories_csv] = CASE WHEN ISNULL([categories_csv], '') = '' THEN '' ELSE REPLACE(',' + [categories_csv] + ',', ',,', ',') END -- this is necessary to apply contains with commas ,[tags_csv] = CASE WHEN ISNULL([tags_csv], '') = '' THEN '' ELSE REPLACE(',' + [tags_csv] + ',', ',,', ',') END; -- this is necessary to apply contains with commas --SELECT OBJECT_ID('ctm_r_DefectsByCategory') INSERT INTO @PARAMS SELECT params.[object_id] ,'Parameter_name' = params.[name] , 'Type' = type_name([user_type_id]) --, 'Length' = [max_length] --, 'Prec' = case when type_name([system_type_id]) = 'uniqueidentifier' then precision else OdbcPrec([system_type_id], [max_length], [precision]) end --, 'Scale' = OdbcScale([system_type_id], [scale]) , 'Param_order' = [parameter_id] --, 'Collation' = convert(sysname, case when [system_type_id] in (35, 99, 167, 175, 231, 239) then ServerProperty('collation') end) , 'default' = CASE WHEN params.[name] = '@month' THEN MONTH(@today) WHEN params.[name] = '@year' THEN YEAR(@today) ELSE '' END , 'ValueList' = '' /*CASE WHEN ISNULL(type_name([user_type_id]),'') LIKE 'ctm_%' AND NOT ISNULL(type_name([user_type_id]),'') COLLATE SQL_Latin1_General_CP1_CI_AS in ('ctm_scopekey','ctm_deployment_package','ctm_displaystream','ctm_systemintegrator','ctm_truefalse','ctm_relevant_for','ctm_supplier','ctm_pillar','ctm_spl_release') THEN '[ ' + STUFF( (SELECT ', ''' + [key] + '''' as [text()] FROM [dbo].[ctm__generic] as g WHERE g.[typ] = type_name([user_type_id]) FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, '') + ' ]' WHEN ISNULL(type_name([user_type_id]),'') = 'ctm_scopekey' THEN '[ ' + STUFF( (SELECT ', ''' + [scopekey] + '''' as [text()] FROM [dbo].[ctm__scopes] as g WHERE [active] = 1 ORDER BY g.[display_order] FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, '') + ' ]' WHEN ISNULL(type_name([user_type_id]),'') = 'ctm_systemintegrator' THEN '[ ' + STUFF( (SELECT ', ''' + si.[si] + '''' as [text()] FROM (SELECT DISTINCT [dbo].[ctm_fnc_removeLeadingNumber]([value],'.') as [si] FROM [dbo].[alm_config__list_items] WHERE [list_id] = 1017)si ORDER BY si.[si] FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, '') + ' ]' WHEN ISNULL(type_name([user_type_id]),'') = 'ctm_deployment_package' THEN '[ ' + STUFF( (SELECT DISTINCT ', ''' + UPPER([deployment_package]) + '''' as [text()] FROM [dbo].[ctm__scopes] as g WHERE [active] = 1 ORDER BY ', ''' + UPPER([deployment_package]) + '''' ASC FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, '') + ' ]' WHEN ISNULL(type_name([user_type_id]),'') = 'ctm_displaystream' THEN '[ ' + STUFF( (SELECT DISTINCT ', ''' + [stream] + '''' as [text()] FROM (SELECT distinct map as [stream]--, CASE WHEN ISNULL(condition,'') <>'' THEN [condition] + ' -> ' ELSE '' END + [map] as [label] FROM [dbo].[ctm__mappings] WHERE typ = 'StreamDisplayMapping') as g ORDER BY ', ''' + [stream] + '''' ASC FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, '') + ' ]' WHEN ISNULL(type_name([user_type_id]),'') = 'ctm_truefalse' THEN '[ ''true'', ''false'' ]' WHEN ISNULL(type_name([user_type_id]),'') = 'ctm_supplier' THEN '[ '''', ' + STUFF( (SELECT ', ''' + si.[rf] + '''' as [text()] FROM (SELECT DISTINCT [value] as [rf] FROM [dbo].[alm_config__list_items] WHERE [list_id] = 1017)si ORDER BY si.[rf] FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, '') + ' ]' WHEN ISNULL(type_name([user_type_id]),'') = 'ctm_relevant_for' THEN '[ '''', ' + STUFF( (SELECT ', ''' + si.[rf] + '''' as [text()] FROM (SELECT DISTINCT [value] as [rf] FROM [dbo].[alm_config__list_items] WHERE [list_id] = 1396)si ORDER BY si.[rf] FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, '') + ' ]' WHEN ISNULL(type_name([user_type_id]),'') = 'ctm_pillar' THEN '[ '''', ' + STUFF( (SELECT ', ''' + si.[rf] + '''' as [text()] FROM (SELECT DISTINCT [pillar] as [rf] FROM [dbo].[ctm__mappings] Where pillar is not null)si ORDER BY si.[rf] FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, '') + ' ]' WHEN ISNULL(type_name([user_type_id]),'') = 'ctm_spl_release' THEN '[ ' + STUFF( (SELECT ', ''' + si.[rf] + '''' as [text()] FROM (SELECT DISTINCT [name] as [rf] FROM [dbo].[CTM__release] )si ORDER BY si.[rf] FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, '') + ' ]' ELSE '' END */ from sys.parameters as params JOIN @PROCEDURES as p on params.[object_id] = p.[object_id]; UPDATE p SET p.[parameter] = ISNULL(STUFF( (SELECT ', ' + [name] as [text()] FROM @PARAMS as params WHERE params.[object_id]= p.[object_id] order by params.[order] ASC FOR XML PATH, TYPE).value(N'.[1]', N'varchar(max)'), 1, 2, ''), '') FROM @PROCEDURES as p; --INSERT INTO @PROCEDURES ([typ], [name], [label], [description], [tags_csv], [categories_csv], [link], [functions], [refresh], [auth], [help_url], [display_order]) --SELECT [typ] = 'fix' -- , [name] = REPLACE(c.[label], ' ','') -- , [label] -- , [description] -- , [tags_csv] -- , [categories_csv] = ISNULL([category], 'Common') -- , [image_dataurl], [functions], [refresh], [auth], [help_url], [display_order] -- FROM [dbo].[fds__admin_reportcatalog] as c where [type] = 'fix'; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --output reports SELECT 'object_id' = ISNULL([object_id], -1) ,[typ] , [ctype] , [name] , [label] , [description] , [tags_csv] , [categories_csv] , [link] , [functions] , [refresh] , [auth] , [parameter] , [help_url] , [display_order] , 'order' = ROW_NUMBER() OVER (PARTITION BY [categories_csv] ORDER BY [display_order],[label],[name],[object_id]) FROM @PROCEDURES; --output parameter options SELECT * fROM @PARAMS; --output categories SELECT [value] as [category] ,CASE WHEN [value] COLLATE SQL_Latin1_General_CP1_CI_AS in ('Archive','Archived') THEN 999 WHEN [value] COLLATE SQL_Latin1_General_CP1_CI_AS in ('Draft','Drafts') THEN 998 WHEN [value] COLLATE SQL_Latin1_General_CP1_CI_AS in ('Administrative', 'Admin', 'Reports for System Admins') OR [value] COLLATE SQL_Latin1_General_CP1_CI_AS like '%Admins' THEN 997 WHEN [value] COLLATE SQL_Latin1_General_CP1_CI_AS in ('Raw Data') THEN 996 ELSE ROW_NUMBER() OVER (ORDER BY CASE WHEN [value] COLLATE SQL_Latin1_General_CP1_CI_AS in ('Standards','Standards','Daily Execution') THEN 1 ELSE 10 END, [value]) END as 'order' FROM (SELECT DISTINCT [value] FROM string_split(STUFF((SELECT ',' + [categories_csv] as [text()] FROM @PROCEDURES WHERE ISNULL([categories_csv],'') <> '' FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1,1,''), ',') WHERE [value] <> '')z --output tags SELECT [value] as [tag], ROW_NUMBER() OVER (ORDER BY COUNT(*) DESC, [value] ASC) as 'order' FROM (SELECT [value] FROM string_split(STUFF((SELECT ',' + [tags_csv] as [text()] FROM @PROCEDURES WHERE ISNULL([tags_csv],'') <> '' FOR XML PATH(''), TYPE).value('.', 'NVARCHAR(MAX)'), 1,1,''), ',') WHERE [value] <> '')tg group by [value]; END GO /****** Object: StoredProcedure [dbo].[fds__admin_logdebug] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Dr. Stefan Ott -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__admin_logdebug] @CodeReference varchar(255) ,@ExceptionMessage varchar(max) ,@StackTrace varchar(max) ,@Data varchar(MAX) AS BEGIN SET NOCOUNT ON; INSERT INTO [dbo].[fds__debuglog] ([CodeReference] ,[ExceptionMessage] ,[StackTrace] ,[Data] ,[timestamp]) VALUES (@CodeReference ,@ExceptionMessage ,@StackTrace ,@Data ,GETUTCDATE()); END GO /****** Object: StoredProcedure [dbo].[fds__admin_updateconflicttables] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__admin_updateconflicttables] @entitytype nvarchar(255) AS BEGIN SET NOCOUNT ON; DECLARE @name nvarchar(255); DECLARE db_cursor CURSOR FOR select [name] from sys.objects where LEFT(name,2) = 't_' order by create_date asc; OPEN db_cursor FETCH NEXT FROM db_cursor INTO @name ; WHILE @@FETCH_STATUS = 0 BEGIN PRINT( @name); IF LEFT(@name, 2) = 't_' and @name like ('%' + @entitytype + '%') BEGIN DECLARE @sql nvarchar(2000) = 'EXECUTE [dbo].[mfr__updt__' + @entitytype + '] @name, null;DROP TABLE [dbo].[' + @name + N'];'; EXECUTE sp_executesql @sql, N'@name nvarchar(255)', @name; END FETCH NEXT FROM db_cursor INTO @name END CLOSE db_cursor DEALLOCATE db_cursor END GO /****** Object: StoredProcedure [dbo].[fds__createInvoice] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__createInvoice] @InvoiceType char(1), @InvoiceTitle varchar(100), @InvoiceBalance numeric(10,3), @InvoiceBalance_net numeric(10,3), @InvoiceVAT_net1 numeric(10,3), @InvoiceVAT_1 numeric(5,2), @PaymentTerm varchar(5), @CustomerId bigint, @SendToAddress nvarchar(1000), @SendToEmail nvarchar(255), @ProvisionPeriod varchar(50), @CustomValues nvarchar(max), @authuser varchar(25), @Id varchar(10) OUT AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); DECLARE @today date = @now; SET @PaymentTerm = ISNULL(@PaymentTerm, '10wd'); DECLARE @days tinyint = ISNULL(TRY_PARSE(REPLACE(REPLACE(@PaymentTerm, 'w',''),'d','') as tinyint), 10); DECLARE @duedate date = CASE WHEN RIGHT(@PaymentTerm, 2) = 'wd' THEN DATEADD(weekday, @days, @today) ELSE DATEADd(DAY, @days, @today) END; DECLARE @newid varchar(8) = [dbo].[fds__fn_invoice_id](); DECLARE @out TABLE ( [Id] [varchar](10) NULL, [Version] [int] NULL, [InvoiceId] [nvarchar](25) NULL, [InvoiceType] [char](1) NULL, [InvoiceTitle] [varchar](100) NULL, [DocumentName] [nvarchar](255) NULL, [InvoiceBalance] [numeric](10, 3) NULL, [InvoiceBalance_net] [numeric](10, 3) NULL, [InvoiceVAT_net1] [numeric](10, 3) NULL, [InvoiceVAT_1] [numeric](5, 2) NULL, [InvoiceVAT_net2] [numeric](10, 3) NULL, [InvoiceVAT_2] [numeric](5, 2) NULL, [PaymentTerm] [varchar](5) NULL, [DueDate] [date] NULL, [CustomerId] [bigint] NULL, [SendToAddress] [nvarchar](1000) NULL, [SendToEmail] [nvarchar](255) NULL, [ProvisionPeriod] [varchar](50) NULL, [ProvisionLocation] [nvarchar](1000) NULL, [PaymentStatus] [char](1) NULL, [IsPayed] [bit] NULL, [IsSent] [bit] NULL, [IsFinal] [bit] NULL, [IsCanceled] [bit] NULL, [Replaces_InvId] [varchar](10) NULL, [CustomValues] [nvarchar](max) NULL, [DateSent] [datetime] NULL, [DateFinalized] [datetime] NULL, [UserFinalized] [varchar](25) NULL, [DateCancelled] [datetime] NULL, [UserCancelled] [varchar](25) NULL, [DateCreated] [datetime] NULL, [UserCreated] [varchar](25) NULL, [DateModified] [datetime] NULL, [UserModified] [varchar](25) NULL, [file] [varbinary](max) NULL ); INSERT INTO [dbo].[fds__invoices] ([Id] ,[Version] ,[InvoiceId] ,[InvoiceType] ,[InvoiceTitle] ,[InvoiceBalance] ,[InvoiceBalance_net] ,[InvoiceVAT_net1] ,[InvoiceVAT_1] ,[InvoiceVAT_net2] ,[InvoiceVAT_2] ,[PaymentTerm] ,[DueDate] ,[CustomerId] ,[SendToAddress] ,[SendToEmail] ,[ProvisionPeriod] ,[ProvisionLocation] ,[PaymentStatus] ,[IsPayed] ,[IsSent] ,[CustomValues] ,[DateSent] ,[DateFinalized] ,[UserFinalized] ,[DateCancelled] ,[UserCancelled] ,[DateCreated] ,[UserCreated] ,[DateModified] ,[UserModified] ,[file]) OUTPUT inserted.* INTO @out VALUES (@newid ,0 --Version ,NULL --InvoiceID ,ISNULL(@InvoiceType,'r') ,ISNULL(@InvoiceTitle,'Rechnung') ,@InvoiceBalance ,@InvoiceBalance_net ,@InvoiceVAT_net1 ,@InvoiceVAT_1 ,NULL -- ,NULL -- ,@PaymentTerm ,@DueDate ,@CustomerId ,@SendToAddress ,@SendToEmail ,@ProvisionPeriod ,NULL --[ProvisionLocation] ,NULL --[PaymentStatus] ,0 -- ,0 -- ,@CustomValues , NULL --[DateSent] ,NULL -- ,NULL -- ,NULL -- ,NULL -- ,@now ,@authuser ,@now ,@authuser ,NULL --file ); SELECT TOP(1) @Id = [id] FROM @out; SELECT TOP(1) * ,[hasFile] = CAST ( CASE WHEN [file] is null THEN 0 ELSE 1 END as bit) ,[UserNameFinalized] = [dbo].[fis_admin_getUserName_byID]([UserFinalized]) ,[UserEmailFinalized] = [dbo].[fis_admin_getUserEmail_byID]([UserFinalized]) from @out END GO /****** Object: StoredProcedure [dbo].[fds__createInvoice_Details] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__createInvoice_Details] @InvId varchar(10) ,@InvoiceService_net numeric(10,3) ,@InvoiceService_VAT numeric(10,3) ,@authuser varchar(25) AS BEGIN SET NOCOUNT ON; MERGE [dbo].[fds__invoice_details] AS TARGET USING (VALUES(@InvId,@InvoiceService_net,@InvoiceService_VAT)) SOURCE ([InvId],[InvoiceService_net],[InvoiceService_VAT]) ON TARGET.[InvID] = SOURCE.[InvID] WHEN MATCHED THEN UPDATE SET [InvoiceService_net] = SOURCE.[InvoiceService_net] ,[InvoiceService_VAT] = SOURCE.[InvoiceService_VAT] WHEN NOT MATCHED BY TARGET THEN INSERT ([InvId] ,[InvoiceService_net] ,[InvoiceService_VAT]) VALUES( SOURCE.[InvId] ,SOURCE.[InvoiceService_net] ,SOURCE.[InvoiceService_VAT] ) OUTPUT inserted.* ; END GO /****** Object: StoredProcedure [dbo].[fds__createInvoice_ServiceRequest] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__createInvoice_ServiceRequest] @InvId varchar(10) ,@mfr__servicerequest bigint ,@title nvarchar(max) ,@value_net numeric(10,3) ,@SortOrder tinyint AS BEGIN SET NOCOUNT ON; INSERT INTO [dbo].[fds__invoice_servicerequests] ([InvId] ,[mfr__servicerequest] ,[title] ,[value_net] ,[SortOrder]) OUTPUT inserted.* VALUES (@InvId ,@mfr__servicerequest ,@title ,@value_net ,@SortOrder); END GO /****** Object: StoredProcedure [dbo].[fds__getDatevExports] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__getDatevExports] @tgtdate date ,@mode varchar(1) = 'm' ,@authuser varchar(100) AS BEGIN SET NOCOUNT ON; DECLARE @startdate date, @enddate date; SET @mode = LOWER(@mode); If @mode = 'm' BEGIN SELECT @startdate = [dbo].[date_monthfirst](@tgtdate) ,@enddate = [dbo].[date_monthend](@tgtdate); END ELSE If @mode = 'w' BEGIN SELECT @startdate = [dbo].[date_weekfirst](@tgtdate) ,@enddate = [dbo].[date_weekend](@tgtdate); END SELECT [startdate] = @startdate, [enddate] = @enddate, [mode] = @mode; DECLARE @inv TABLE([Id] varchar(10), [InvoiceID] varchar(255), [URI] nvarchar(255), [DocumentName] nvarchar(255), [DateOfCreation] date, [fds] bit); INSERT INTO @inv SELECT [Id],[invoiceid],[URI],[DocumentName],[DateOfCreation],[fds] = 0 FROM [dbo].[mfr__reports] where [IsInvoice] = 1 AND CAST([DateOfCreation] as date) between @startdate AND @enddate; INSERT INTO @inv SELECT [Id],[invoiceid],[URI] = null,[DocumentName],[DateOfCreation] = [DateCreated],[fds] = 1 FROM [dbo].[fds__invoices] where CAST([DateCreated] as date) between @startdate AND @enddate and [isfinal] = 1; SELECT inv.[Id],inv.[InvoiceID],inv.[URI],inv.[DocumentName],inv.[fds],finv.[file] --,[order] = ROW_NUMBER() OVER (ORDER BY [DateOfCreation] ASC) FROM @inv as inv LEFT JOIN [dbo].[fds__invoices] as finv on inv.[id] = finv.[id]; DECLARE @SReq TABLE ([id] bigint, [DateOfCreation] datetime, [name] nvarchar(255), [invoice.Id] varchar(10), [customer.ExternalId] bigint, [customer.Id] bigint, [ExternalId] nvarchar(255), [fds] bit); INSERT INTO @SReq SELECT s.[Id], s.[DateOfCreation], s.[name], [invoice.Id] = i.[Id], [customer.ExternalId] = cy.ExternalId , [customer.Id] = cy.[id], s.[ExternalId], [fds] FROM [dbo].[mfr__servicerequests] as s JOIN @inv as i on s.[InvoiceId] like ('%' + i.[InvoiceId] + '%') LEFT JOIN [dbo].[mfr__companies] as cy on s.[CustomerId] = cy.id WHERE i.fds = 0; INSERT INTO @SReq SELECT s.[Id], s.[DateOfCreation], s.[name], [invoice.Id] = i.[Id], [customer.ExternalId] = cy.ExternalId , [customer.Id] = cy.[id], s.[ExternalId], [fds] FROM [dbo].[fds__invoice_servicerequests] as irq JOIN @inv as i on irq.[InvId] = i.[Id] LEFT JOIN [dbo].[mfr__servicerequests] as s ON irq.[mfr__servicerequest] = s.[id] LEFT JOIN [dbo].[mfr__companies] as cy on s.[CustomerId] = cy.id WHERE i.fds = 1; With itm as ( SELECT [net_itemsum] = CAST( SUM((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) as numeric(12,2)) , [bo_itemsum] = CAST( SUM( ((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) * (1 + (ISNULL(vat.[vat], 19.0) * 0.01))) as numeric(12,2)) , [vf] = MAX(1 + (ISNULL(vat.[vat], 19.0) * 0.01)) , sreq.[invoice.Id] ,[fds] = 0 FROM [dbo].[mfr__items] as itm JOIN @sreq as sreq ON itm.[ServiceRequestId] = SReq.[id] LEFT JOIN [dbo].[fds__custom_vat] as vat ON itm.[Id] = vat.[EntityId] and vat.[EntityType] = 'item' WHERE [fds] = 0 GROUP BY sreq.[invoice.Id] UNION SELECT [net_itemsum] = CAST( SUM(ISNULL([value_total],0)) as numeric(12,2)) , [bo_itemsum] = CAST( SUM(ISNULL([value_total],0) * (1 + (ISNULL([vat], 19.0) * 0.01))) as numeric(12,2)) , [vf] = MAX(1 + (ISNULL([vat], 19.0) * 0.01)) , [invoice.Id] = inv.[id] --sreq.[invoice.Id] , [fds] = 1 FROM [dbo].[fds__invoice_items] as itm --JOIN @sreq as sreq ON itm.[InvRqId] = SReq.[id] JOIN @inv as inv ON itm.[invid] = inv.[id] and [fds] = 1 WHERE [fds] = 1 GROUP BY inv.[id] --sreq.[invoice.Id] ),sc as( SELECT s.[invoice.Id], [fds], [#] = COUNT(s.[id]) FROM @SReq as s GROUP BY s.[invoice.Id], [fds] ),contra_accounts as( SELECT [account] = [key], [vat] = TRY_PARSE([value2] as numeric(5,2) USING 'en-US') FROM [dbo].[fds__admin_settings] WHERE [type] = 'contra_account' ), inv as( select [Id] = CAST(iv.[Id] as varchar(10)) ,[InvoiceId] = iv.[InvoiceId] ,[requestcount] = sc.[#] ,[request] = (SELECT TOP(1) s.[ExternalId] FROM @SReq as s WHERE s.[invoice.Id] = iv.id) ,[balance] = ABS([invoiceBalance]) ,[EINZELPOS_brutto] = itm.bo_itemsum ,[EINZELPOS_netto] = itm.net_itemsum ,[vf] ,[deb_cred] = CASE WHEN [invoiceBalance] < 0 THEN 'S' ELSE 'H' END ,[customer] = (SELECT TOP(1) [customer.ExternalId] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id] and [customer.ExternalId] is not null ORDER BY SReq.DateOfCreation ASC) ,[contra_account] = ca.[account] ,[Belegdatum] = iv.[DateOfCreation] ,[Buchungstext] = (SELECT TOP(1) SReq.[name] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id]) ,iv.[DateOfCreation] from [dbo].[mfr__reports] as iv LEFT JOIN itm on iv.Id = itm.[invoice.Id] LEFT JOIN [dbo].[fds__custom_vat] as vat ON iv.[Id] = vat.[EntityId] and vat.[EntityType] = 'report' LEFT JOIN sc on iv.[id] = sc.[invoice.Id] and sc.[fds] = 0 LEFT JOIN contra_accounts as ca ON ISNULL(vat.[vat], 19.0) = ca.[vat] where iv.Id in (SELECT [Id] FROM @inv Where fds = 0) UNION select iv.[Id] ,[InvoiceId] = iv.[InvoiceId] ,[requestcount] = sc.[#] ,[request] = (SELECT TOP(1) s.[ExternalId] FROM @SReq as s WHERE s.[invoice.Id] = iv.id) ,[balance] = ABS([invoiceBalance]) ,[EINZELPOS_brutto] = itm.bo_itemsum ,[EINZELPOS_netto] = itm.net_itemsum ,[vf] ,[deb_cred] = CASE WHEN [invoiceBalance] < 0 THEN 'S' ELSE 'H' END ,[customer] = (SELECT TOP(1) [customer.ExternalId] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id] and [customer.ExternalId] is not null ORDER BY SReq.DateOfCreation ASC) ,[contra_account] = ca.[account] ,[Belegdatum] = iv.[DateCreated] ,[Buchungstext] = (SELECT TOP(1) SReq.[name] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id]) ,[DateOfCreation] = iv.[DateCreated] from [dbo].[fds__invoices] as iv LEFT JOIN itm on iv.Id = itm.[invoice.Id] LEFT JOIN sc on iv.[id] = sc.[invoice.Id] and sc.[fds] = 1 LEFT JOIN contra_accounts as ca ON ISNULL(iv.[InvoiceVAT_1], 19.0) = ca.[vat] where iv.Id in (SELECT [Id] FROM @inv Where fds = 1) ) select [Umsatz (ohne Soll/Haben-Kz)] = ABS([balance]) ,[EINZELPOS_brutto] ,[EINZELPOS_netto] ,vf ,[Soll/Haben-Kennzeichen] = CASE WHEN [Balance] < 0 THEN 'S' ELSE 'H' END ,[Konto] = (SELECT TOP(1) [customer.ExternalId] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id] ORDER BY SReq.DateOfCreation ASC) ,[Gegenkonto] = [contra_account] ,[BU-Schlüssel] = '' ,[Belegdatum] = FORMAT(iv.[Belegdatum], 'ddMM') ,[Belegfeld 1] = iv.[InvoiceId] ,[Belegfeld 2] = FORMAT(iv.[Belegdatum], 'ddMMyy') ,[Buchungstext] = (SELECT TOP(1) SReq.[name] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id]) ,[Festschreibung] = '1' ,[Generalumkehr (GU)] = '0' --,[order] = ROW_NUMBER() OVER (ORDER BY iv.[DateOfCreation] ASC) from inv as iv order by iv.[DateOfCreation] ASC; WIth debs as ( SELECT ROW_NUMBER() OVER (PARTITION BY [customer.Id] ORDER BY SReq.DateOfCreation ASC) as [#] , [customer.ExternalId] , [customer.Id] FROM @SReq as sreq ), dd as ( SELECT distinct cy.* FROM [mfr__companies] as cy WHERE EXISTS ( SELECT * FROM debs WHERE debs.[customer.Id] = cy.[id] AND debs.[#] = 1) ), cc as ( SELECT ROW_NUMBER() OVER (PARTITION BY dd.[id] ORDER BY CASE WHEN dd.[MainContactId] = c.[id] THEN 0 ELSE 1 END) as '#', c.*, [company_id] = dd.[id] FROM [dbo].[mfr__contacts] as c JOIN dd on c.[CompanyId] = dd.[Id] OR dd.[MainContactId] = c.[id] ) SELECT [Konto] = dd.[ExternalId] ,[Name (Adressattyp natürl. Person)] = cc.[LastName] ,[Vorname (Adressattyp natürl. Person)] = cc.[FirstName] ,[Adressattyp] = 1 ,[Anrede] = CASE WHEN LOWER(LEFT(cc.[Gender],1)) = 'm' THEN 'Herrn' WHEN LOWER(LEFT(cc.[Gender],1)) = 'w' THEN 'Frau' ELSE '' END ,[STR] = l.[AddressString] ,[Postleitzahl] = l.[Postal] ,[Ort] = l.City ,[Land] = l.[Country] ,[Kennz. Korrespondenzadresse] = '1' ,[Telefon] = ISNULL(cc.[Telephone], dd.[SupportTelephone]) ,[E-Mail] = ISNULL(cc.[Email], dd.[SupportMail]) FROM dd JOIN cc on cc.[#] = 1 AND cc.[company_id] = dd.[id] LEFT JOIN [dbo].[mfr__#locations] as l ON l.[EntityID] = dd.[id] and l.Property = 'Company:Location' END GO /****** Object: StoredProcedure [dbo].[fds__getInvoice] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__getInvoice] @Id varchar(8), @authuser varchar(25) AS BEGIN SET NOCOUNT ON; DECLARE @inv [dbo].[fds__tt__invoice_base]; DECLARE @req [dbo].[fds__tt__invoice_servicerequests]; DECLARE @itm [dbo].[fds__tt__invoice_items]; INSERT INTO @inv SELECT TOP(1) [Id] ,[Version] ,[InvoiceId] ,[InvoiceType] ,[InvoiceTitle] ,[DocumentName] ,[InvoiceBalance] ,[InvoiceBalance_net] ,[InvoiceVAT_net1] ,[InvoiceVAT_1] ,[InvoiceVAT_net2] ,[InvoiceVAT_2] ,[PaymentTerm] ,[DueDate] ,[CustomerId] ,[SendToAddress] ,[SendToEmail] ,[ProvisionPeriod] ,[ProvisionLocation] ,[PaymentStatus] ,[IsPayed] ,[IsSent] ,[IsFinal] ,[IsCanceled] ,[Replaces_InvId] ,[CustomValues] ,[DateSent] ,[DateFinalized] ,[UserFinalized] ,[DateCancelled] ,[UserCancelled] ,[DateCreated] ,[UserCreated] ,[DateModified] ,[UserModified] ,[hasFile] = CAST ( CASE WHEN [file] is null THEN 0 ELSE 1 END as bit) ,[UserNameFinalized] = [dbo].[fis_admin_getUserName_byID]([UserFinalized]) ,[UserEmailFinalized] = [dbo].[fis_admin_getUserEmail_byID]([UserFinalized]) ,[PaymentTermPhrase] = null ,[InvoiceService] = [InvoiceService_net] + [InvoiceService_VAT] ,[InvoiceService_net] ,[InvoiceService_VAT] FROM [dbo].[fds__invoices]as _i LEFT JOIN [dbo].[fds__invoice_details] as _d ON _i.[Id] = _d.[InvId] WHERE [Id] = @Id AND @Id is not null; INSERT INTO @req SELECT * FROM [dbo].[fds__invoice_servicerequests] WHERE [invId] = @Id AND @Id is not null; INSERT INTO @itm SELECT _i.* FROM [dbo].[fds__invoice_items] as _i WHERE _i.[invId] = @Id AND @Id is not null AND EXISTS( SELECT * from @req as _r WHERE _r.[id] = _i.[InvRqId]); DELETE _R FROM @req as _R WHERE NOT EXISTS (SELECT * FROM @itm as _i WHERE _i.[InvRqId] = _R.[Id] AND (ISNULL(_i.[text], '') <> '' OR ISNULL(_i.[value_total],0) <> 0)); DELETE _i FROM @itm as _i WHERE NOT EXISTS( SELECT * from @req as _r WHERE _r.[id] = _i.[InvRqId]); ---output SELECT TOP(1) * ,[tax_servicerefund] = 0.2 FROM @inv; SELECT * , [order] = ROW_NUMBER() OVER (ORDER BY [SortOrder]) FROM @req; SELECT * , [order] = ROW_NUMBER() OVER (PARTITION BY [InvRqId] ORDER BY [SortOrder]) FROM @itm; END GO /****** Object: StoredProcedure [dbo].[fds__getInvoiceFile] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__getInvoiceFile] @Id varchar(8), @authuser varchar(25) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); SELECT TOP(1) [id], [DocumentName], [file] FROM [dbo].[fds__invoices] WHERE [Id] = @Id AND @Id is not null; END GO /****** Object: StoredProcedure [dbo].[fds__getInvoices_list] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__getInvoices_list] @tgtdate date ,@mode varchar(1) = 'm' , @authuser varchar(100) AS BEGIN SET NOCOUNT ON; DECLARE @startdate date, @enddate date, @today date = GETDATE(); SET @mode = LOWER(@mode); If @mode = 'm' BEGIN SELECT @startdate = [dbo].[date_monthfirst](@tgtdate) ,@enddate = [dbo].[date_monthend](@tgtdate); END ELSE If @mode = 'w' BEGIN SELECT @startdate = [dbo].[date_weekfirst](@tgtdate) ,@enddate = [dbo].[date_weekend](@tgtdate); END --Reminder settings DECLARE @stage1 varchar(10), @stage2 varchar(10), @stage3 varchar(10); SELECT @stage1 = [stage1], @stage2 = [stage2], @stage3 = [stage3] FROM [dbo].[fds__admin_reminderSettings](); SELECT [startdate] = @startdate, [enddate] = @enddate, [mode] = @mode , [title] = 'Rechnungsübersicht für ' + CASE WHEN @mode = 'm' THEN 'MONAT ' + FORMAT(@startdate, 'MMM yyyy') WHEN @mode = 'w' THEN 'WOCHE ' + FORMAT(@startdate, 'dd.MM.yyyy') + ' - ' + FORMAT(@enddate, 'dd.MM.') ELSE '' END ,[ust_options] = '19,0%;16,0%;0,0%'; DECLARE @inv TABLE([Id] varchar(15), [InvoiceID] varchar(255), [URI] nvarchar(255), [DocumentName] nvarchar(255), [DateOfCreation] date, [fds] bit); INSERT INTO @inv SELECT [Id],[invoiceid],[URI],[DocumentName],[DateOfCreation],[fds] = 0 FROM [dbo].[mfr__reports] where [IsInvoice] = 1 AND CAST([DateOfCreation] as date) between @startdate AND @enddate; INSERT INTO @inv SELECT [Id],[invoiceid],[URI] = null,[DocumentName],[DateOfCreation] = [DateCreated],[fds] = 1 FROM [dbo].[fds__invoices] where CAST([DateCreated] as date) between @startdate AND @enddate and [isfinal] = 1; DECLARE @SReq TABLE ([id] bigint, [DateOfCreation] datetime, [name] nvarchar(255), [invoice.Id] varchar(15), [customer.ExternalId] bigint, [customer.Id] bigint, [ExternalId] nvarchar(255), [fds] bit); INSERT INTO @SReq SELECT s.[Id], s.[DateOfCreation], s.[name], [invoice.Id] = i.[Id], [customer.ExternalId] = cy.ExternalId , [customer.Id] = cy.[id], s.[ExternalId], [fds] FROM [dbo].[mfr__servicerequests] as s JOIN @inv as i on s.[InvoiceId] like ('%' + i.[InvoiceId] + '%') LEFT JOIN [dbo].[mfr__companies] as cy on s.[CustomerId] = cy.id WHERE i.fds = 0; INSERT INTO @SReq SELECT s.[Id], s.[DateOfCreation], s.[name], [invoice.Id] = i.[Id], [customer.ExternalId] = cy.ExternalId , [customer.Id] = cy.[id], s.[ExternalId], [fds] FROM [dbo].[fds__invoice_servicerequests] as irq JOIN @inv as i on irq.[InvId] = i.[Id] LEFT JOIN [dbo].[mfr__servicerequests] as s ON irq.[mfr__servicerequest] = s.[id] LEFT JOIN [dbo].[mfr__companies] as cy on s.[CustomerId] = cy.id WHERE i.fds = 1; With itm as ( SELECT [net_itemsum] = CAST( SUM((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) as numeric(12,2)) , [bo_itemsum] = CAST( SUM( ((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) * (1 + (ISNULL(vat.[vat], 19.0) * 0.01))) as numeric(12,2)) , [vf] = MAX(1 + (ISNULL(vat.[vat], 19.0) * 0.01)) , sreq.[invoice.Id] ,[fds] = 0 FROM [dbo].[mfr__items] as itm JOIN @sreq as sreq ON itm.[ServiceRequestId] = SReq.[id] LEFT JOIN [dbo].[fds__custom_vat] as vat ON itm.[Id] = vat.[EntityId] and vat.[EntityType] = 'item' WHERE [fds] = 0 GROUP BY sreq.[invoice.Id] UNION SELECT [net_itemsum] = CAST( SUM(ISNULL([value_total],0)) as numeric(12,2)) , [bo_itemsum] = CAST( SUM(ISNULL([value_total],0) * (1 + (ISNULL([vat], 19.0) * 0.01))) as numeric(12,2)) , [vf] = MAX(1 + (ISNULL([vat], 19.0) * 0.01)) , [invoice.Id] = inv.[id] --sreq.[invoice.Id] , [fds] = 1 FROM [dbo].[fds__invoice_items] as itm --JOIN @sreq as sreq ON itm.[InvRqId] = SReq.[id] JOIN @inv as inv ON itm.[invid] = inv.[id] and [fds] = 1 WHERE [fds] = 1 GROUP BY inv.[id] --sreq.[invoice.Id] ),sc as( SELECT s.[invoice.Id], [fds], [#] = COUNT(s.[id]) FROM @SReq as s GROUP BY s.[invoice.Id], [fds] ),contra_accounts as( SELECT [account] = [key], [vat] = TRY_PARSE([value2] as numeric(5,2) USING 'en-US') FROM [dbo].[fds__admin_settings] WHERE [type] = 'contra_account' ), inv as( select [Id] = CAST(iv.[Id] as varchar(15)) ,[InvoiceId] = iv.[InvoiceId] ,[InvoiceType] = CAST( CASE WHEN LEFT([documentname],5) = 'absch' THEN 'i' WHEN LEFT([documentname],5) = 'storn' THEN 'c' ELSE 'r' END as char(1)) ,[DocumentName] ,[requestcount] = sc.[#] ,[request] = (SELECT TOP(1) s.[ExternalId] FROM @SReq as s WHERE s.[invoice.Id] = iv.id) ,[balance] = FORMAT(ABS([invoiceBalance]), '#0.00', 'de') + ' €' ,[EINZELPOS_brutto] = FORMAT(itm.bo_itemsum, '#0.00', 'de') + ' €' ,[EINZELPOS_netto] = FORMAT(itm.net_itemsum, '#0.00', 'de') + ' €' ,[vat] = FORMAT(ISNULL(vat.[vat], 19.0), '#0.0', 'de') + ' %' ,[deb_cred] = CASE WHEN [invoiceBalance] < 0 THEN 'S' ELSE 'H' END ,[customer] = (SELECT TOP(1) [customer.ExternalId] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id] and [customer.ExternalId] is not null ORDER BY SReq.DateOfCreation ASC) ,[contra_account] = ca.[account] ,[Belegdatum] = FORMAT(iv.[DateOfCreation], 'dd.MM.yy') ,[Buchungstext] = (SELECT TOP(1) SReq.[name] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id]) ,iv.[DateOfCreation] ,iv.[DueDate] ,[PaymentTerm] = @stage1 ,ivi.[PaymentStatus] ,[IsPayed] = CAST(CASE WHEN ISNULL(iv.[IsCanceled],0) = 1 THEN 1 ELSE ISNULL(ivi.[IsPayed],0) END as bit) ,[IsCanceled] ,[isSent] = CAST(1 as bit) ,[isFinal] = CAST(1 as bit) ,[hasFile] = CAST( CASE wHEN ISNULL([URI], '') <> '' THEN 1 ELSE 0 END as bit) from [dbo].[mfr__reports] as iv LEFT JOIN [dbo].[fds__custom_invoiceinfo] as ivi on iv.[id] = ivi.[invid] LEFT JOIN itm on iv.Id = itm.[invoice.Id] LEFT JOIN [dbo].[fds__custom_vat] as vat ON iv.[Id] = vat.[EntityId] and vat.[EntityType] = 'report' LEFT JOIN sc on iv.[id] = sc.[invoice.Id] and sc.[fds] = 0 LEFT JOIN contra_accounts as ca ON ISNULL(vat.[vat], 19.0) = ca.[vat] where iv.Id in (SELECT [Id] FROM @inv Where fds = 0) UNION select iv.[Id] ,[InvoiceId] = iv.[InvoiceId] ,[InvoiceType] ,[DocumentName] ,[requestcount] = sc.[#] ,[request] = (SELECT TOP(1) s.[ExternalId] FROM @SReq as s WHERE s.[invoice.Id] = iv.id) ,[balance] = FORMAT(ABS([invoiceBalance]), '#0.00', 'de') + ' €' ,[EINZELPOS_brutto] = FORMAT(itm.bo_itemsum, '#0.00', 'de') + ' €' ,[EINZELPOS_netto] = FORMAT(itm.net_itemsum, '#0.00', 'de') + ' €' ,[vat] = FORMAT(ISNULL(iv.[InvoiceVAT_1], 19.0), '#0.0', 'de') + ' %' ,[deb_cred] = CASE WHEN [invoiceBalance] < 0 THEN 'S' ELSE 'H' END ,[customer] = (SELECT TOP(1) [customer.ExternalId] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id] and [customer.ExternalId] is not null ORDER BY SReq.DateOfCreation ASC) ,[contra_account] = ca.[account] ,[Belegdatum] = FORMAT(iv.[DateCreated], 'dd.MM.yy') ,[Buchungstext] = (SELECT TOP(1) SReq.[name] FROM @SReq as sreq WHERE iv.[Id] = sreq.[invoice.Id]) ,[DateOfCreation] = iv.[DateCreated] ,[DueDate] ,[PaymentTerm] = ISNULL([PaymentTerm], @stage1) ,[PaymentStatus] ,[IsPayed] = CAST(CASE WHEN ISNULL(iv.[IsCanceled],0) = 1 THEN 1 ELSE ISNULL([IsPayed],0) END as bit) ,[IsCanceled] ,[isSent] ,[isFinal] ,[hasFile] = CAST( CASE wHEN [file] is not null and [DocumentNAme] is not null THEN 1 ELSE 0 END as bit) from [dbo].[fds__invoices] as iv LEFT JOIN itm on iv.Id = itm.[invoice.Id] LEFT JOIN sc on iv.[id] = sc.[invoice.Id] and sc.[fds] = 1 LEFT JOIN contra_accounts as ca ON ISNULL(iv.[InvoiceVAT_1], 19.0) = ca.[vat] where iv.Id in (SELECT [Id] FROM @inv Where fds = 1) ), reminder as ( SELECT [InvId], [lastReminder] = MAX([DateSent]), [#] = COUNT(*) FROM [dbo].[fds__reminder] WHERE [isSent] = 1 AND [invId] IN (SELECT [Id] FROM @inv) GROUP BY [InvId] ) select inv.* ,[reminderstatus] = CASE WHEN [ispayed] = 1 THEN 0 WHEN DueDate is null THEN 0 WHEN @stage3 <> '' AND rem.[#] = 2 AND @today > [dbo].[date_addcustom]([lastReminder], @stage3) THEN 3 WHEN @stage2 <> '' AND rem.[#] = 1 AND @today > [dbo].[date_addcustom]([lastReminder], @stage2) THEN 2 WHEN @stage1 <> '' AND ISNULL(rem.[#],0) = 0 AND @today > [dbo].[date_addcustom](ISNULL(DueDate, [DateOfCreation]), ISNULL([PaymentTerm],@stage1)) THEN 1 ELSE 0 END ,[invstatus] = CASE WHEN [IsPayed] = 1 AND [isCanceled] = 0 THEN 'pyd' WHEN [isCanceled] = 1 THEN 'cc' WHEN [isFinal] = 0 THEN 'dft' WHEN [isFinal] = 1 AND [isSent] = 0 THEN 'uns' WHEN [DueDate] is null THEN 'op' WHEN @today >= [DueDate] THEN 'due' WHEN ISNULL(rem.[#],0) > 0 THEN 'rem' WHEN @stage1 <> '' AND ISNULL(rem.[#],0) = 0 AND @today > [dbo].[date_addcustom](ISNULL(DueDate, [DateOfCreation]), @stage1) THEN 'ovd' END ,[reminder] = rem.[#] ,[order] = ROW_NUMBER() OVER (ORDER BY inv.[DateOfCreation] ASC) FROM inv left JOIN reminder as rem ON inv.[Id] = rem.[InvId] --inv.[id] is already converted to varchar order by inv.[DateOfCreation] ASC; END GO /****** Object: StoredProcedure [dbo].[fds__getInvRequestItems] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__getInvRequestItems] @invoiceid bigint , @authuser varchar(100) AS BEGIN SET NOCOUNT ON; DECLARE @SReq TABLE ([id] bigint, [DateOfCreation] datetime, [name] nvarchar(255), [invoice.Id] bigint, [customer.ExternalId] bigint, [customer.Id] bigint); INSERT INTO @SReq SELECT s.[Id], s.[DateOfCreation], s.[name], [invoice.Id] = i.[Id], [customer.ExternalId] = cy.ExternalId , [customer.Id] = cy.[id] FROM [dbo].[mfr__servicerequests] as s JOIN [mfr__reports] as i on i.[id] = @invoiceid and s.[InvoiceId] like ('%' + i.[InvoiceId] + '%') LEFT JOIN [dbo].[mfr__companies] as cy on s.[CustomerId] = cy.id where i.[id] = @invoiceid ; SELECT [id],[DateOfCreation],[name],[invoice.Id],[customer.ExternalId],[customer.Id] ,[order] = ROW_NUMBER() OVER (ORDER BY [DateOfCreation]) FROM @SReq; SELECT itm.[Id] , [net_pos] = CASE WHEN LOWER(itm.[type]) in ('Title','Text') THEN '' ELSE FORMAT( CAST( (ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0) as numeric(7,2)) , '#0.00 €','de') END , [bo_pos] = CASE WHEN LOWER(itm.[type]) in ('Title','Text') THEN '' ELSE FORMAT( CAST( ((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) * (1 + (ISNULL(vat.[vat], 19.0) * 0.01)) as numeric(7,2)) , '#0.00 €','de') END , [vat] = CASE WHEN LOWER(itm.[type]) in ('Title','Text') THEN null ELSE FORMAT(ISNULL(vat.[vat], 19.0), '#0.0','de') + '%' END , itm.[ServiceRequestId] , itm.[SortOrder] , itm.[Type] , itm.[NameOrNumber] , sreq.[invoice.Id] , [order] = ROW_NUMBER() OVER (PARTITION BY itm.[ServiceRequestId] ORDER BY itm.[SortOrder]) FROM [dbo].[mfr__items] as itm JOIN @sreq as sreq ON itm.[ServiceRequestId] = SReq.[id] LEFT JOIN [dbo].[fds__custom_vat] as vat ON itm.[Id] = vat.[EntityId] and vat.[EntityType] = 'item' ; END GO /****** Object: StoredProcedure [dbo].[fds__getReportDocument] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__getReportDocument] @reportid varchar(10) AS BEGIN SET NOCOUNT ON; DECLARE @idbigint bigint = TRY_CAST(@reportid as bigint); SELECT TOP(1) [Id] = CAST([Id] as varchar(10)),[InvoiceID],[URI],[DocumentName],[isInvoice],[DateOfCreation],[fds] = CAST( 0 as bit),[file] = CAST( null as varbinary(max)) ,[order] = ROW_NUMBER() OVER (ORDER BY [DateOfCreation] ASC) FROM [dbo].[mfr__reports] WHERE [id] = @idbigint and @idbigint is not null UNION SELECT TOP(1) [Id] = CAST([Id] as varchar(10)),[InvoiceID],[URI] = '',[DocumentName],[isInvoice] = 1,[DateOfCreation] = [DateCreated],[fds] = CAST( 1 as bit), [file] ,[order] = ROW_NUMBER() OVER (ORDER BY [DateCreated] ASC) FROM [dbo].[fds__invoices] WHERE [id] = @reportid AND [isFinal] = 1; ; END GO /****** Object: StoredProcedure [dbo].[fds__getRequest_details] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__getRequest_details] @servicerequestid bigint , @mode varchar(3) , @authuser varchar(100) AS BEGIN SET NOCOUNT ON; DECLARE @SReq TABLE ( [Id] [bigint] NOT NULL, [Name] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [InvoiceId] [nvarchar](255) NULL, [ClosedAt] [datetime] NULL, [ReleasedAt] [datetime] NULL, [WorkDoneAt] [datetime] NULL, [TargetTimeInMinutes] [bigint] NOT NULL, [DateModified] [datetime] NULL, [DateOfCreation] [datetime] NULL, [DueDateRangeStart] [datetime] NULL, [DueDateRangeEnd] [datetime] NULL, [PortalLink] [nvarchar](255) NULL, [CostCenterId] [bigint] NULL, [Description] [nvarchar](max) NULL, [State] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NOT NULL, [CurrentOwnerId] [bigint] NULL, [CustomerId] [bigint] NULL, [ParentServiceRequestId] [bigint] NULL, [ParentExtenalId] [nvarchar](255) NULL, [ParentWorkDoneAt] [date] NULL, [ParentInvoiceId] [nvarchar](255) NULL, [Location#ID] [bigint] NULL, [Version] [int] NOT NULL, [IsTemplate] [bit] NOT NULL, [IsTemplateMobile] [bit] NOT NULL, [CreateFromServiceRequestTemplateId] [bigint] NOT NULL, [Type] [nvarchar](255) NULL, [Summary] nvarchar(255) NULL, [isChild] bit NULL, [baseorder] int, [provision] varchar(255) NULL ); insert into @SReq SELECT [Id] ,[Name] ,[ExternalId] ,[InvoiceId] ,[ClosedAt] ,[ReleasedAt] ,[WorkDoneAt] ,[TargetTimeInMinutes] ,[DateModified] ,[DateOfCreation] ,[DueDateRangeStart] ,[DueDateRangeEnd] ,[PortalLink] ,[CostCenterId] ,[Description] ,[State] ,[CustomValues] ,[CurrentOwnerId] ,[CustomerId] ,[ParentServiceRequestId] ,[ParentExtenalId] = cast(CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then null ELSE '?' END as nvarchar(255)) ,[ParentWorkDoneAt] = cast(NULL as datetime) ,[ParentInvoiceId] = cast(NULL as nvarchar(255)) ,[Location#ID] ,[Version] ,[IsTemplate] ,[IsTemplateMobile] ,[CreateFromServiceRequestTemplateId] ,[Type] ,[Summary] = NULL ,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END ,[baseorder] = 0 ,[provision] = NULL FROM [dbo].[mfr__servicerequests] as s WHERE [id] = @servicerequestid; INSERT INTO @SReq SELECT s.[Id] ,s.[Name] ,s.[ExternalId] ,s.[InvoiceId] ,s.[ClosedAt] ,s.[ReleasedAt] ,s.[WorkDoneAt] ,s.[TargetTimeInMinutes] ,s.[DateModified] ,s.[DateOfCreation] ,s.[DueDateRangeStart] ,s.[DueDateRangeEnd] ,s.[PortalLink] ,s.[CostCenterId] ,s.[Description] ,s.[State] ,s.[CustomValues] ,s.[CurrentOwnerId] ,s.[CustomerId] ,s.[ParentServiceRequestId] ,[ParentExtenalId] = CASE WHEN s.[ParentServiceRequestId] = q.[id] THEN q.[ExternalId] ELSE NULL END ,[ParentWorkDoneAt] = CASE WHEN s.[ParentServiceRequestId] = q.[id] THEN q.[WorkDoneAt] ELSE NULL END ,[ParentInvoiceId] = CASE WHEN s.[ParentServiceRequestId] = q.[id] THEN q.[InvoiceId] ELSE NULL END ,s.[Location#ID] ,s.[Version] ,s.[IsTemplate] ,s.[IsTemplateMobile] ,s.[CreateFromServiceRequestTemplateId] ,s.[Type] ,[Summary] = NULL ,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END ,[baseorder] = 0 , [provision_start] = null from [dbo].[mfr__servicerequests] as s JOIN @SReq as q ON (s.[ParentServiceRequestId] = q.[id] OR q.[ParentServiceRequestId] = s.[id]) --parents or childs WHERE NOT EXISTS (SELECT * FROM @SReq as s2 WHERE s2.[id] = s.[Id]) ; WITH q as ( SELECT [id], [baseorder] = (ROW_NUMBER() OVER (ORDER BY ISNULL([ParentWorkDoneAt], [WorkDoneAt]), ISNULL([ParentServiceRequestId],[id])) * 100) FROM @SReq as s WHERE [ischild] = 0 ) UPDATE s SET [baseorder] = q.baseorder FROM @SReq as s JOIN q ON s.[id] = q.[id]; WITH q as ( SELECT s.[id] , q.[ExternalId], q.[WorkDoneAt], q.[InvoiceId] , [baseorder] = q.[baseorder] + ROW_NUMBER() OVER (PARTITION BY q.[id] ORDER BY s.[dateofcreation]) FROM @SReq as s JOIN @SReq as q ON s.[ParentServiceRequestId] = q.[id] WHERE s.[ischild] = 1 ) UPDATE s SET [ParentExtenalId] = q.[ExternalId] ,[ParentWorkDoneAt] = q.[WorkDoneAt] ,[ParentInvoiceId] = q.[InvoiceId] ,[baseorder] = q.[baseorder] FROM @SReq as s JOIN q ON s.[Id] = q.[id]; DECLARE @step TABLE ( [Id] [bigint] NOT NULL, [MobileId] [bigint] NULL, [Version] [int] NOT NULL, [Name] [nvarchar](255) NULL, [IsDone] [bit] NOT NULL, [HasError] [bit] NOT NULL, [TrackingId] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [SortOrder] [int] NOT NULL, [Data] [nvarchar](max) NULL, [DateModifiedOffline] [datetime] NULL, [ServiceRequestId] [bigint] NULL, [Description] [nvarchar](max) NULL, [Comment] [nvarchar](max) NULL, [InternalComment] [nvarchar](max) NULL, [ServiceObjectId] [bigint] NULL, [StepListTemplateId] [bigint] NULL, [ParentId] [bigint] NULL, [order] int NOT NULL ); DECLARE @company TABLE ( [Id] [bigint] NOT NULL, [Location#ID] [bigint] NULL, [Version] [int] NOT NULL, [IsPhysicalPerson] [bit] NOT NULL, [IsOwner] [bit] NOT NULL, [IsEmailInvoicingActive] [bit] NOT NULL, [IsSupplier] [bit] NOT NULL, [MappingId] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [Name] [nvarchar](255) NULL, [Note] [nvarchar](255) NULL, [SupportTelephone] [nvarchar](255) NULL, [SupportFax] [nvarchar](255) NULL, [SupportMail] [nvarchar](255) NULL, [QuickSearch] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [MainContactId] [bigint] NOT NULL, [address] nvarchar(1000) null ); INSERT INTO @company SELECT DISTINCT cy.*, [address] = [dbo].[fds__getCompanyAddress](cy.[id]) FROM [mfr__companies] as cy JOIN @SReq as s on cy.id = s.[CustomerId]; DECLARE @companyids [dbo].[fds__tt__idlist]; INSERT INTO @companyids SELECT DISTINCT [id] FROM @company; /** OUTPUT + get other types **/ IF @mode in ('r','ov', '','f', 'ful') BEGIN WITH app as( SELECT [start] = MIN(CAST(CASE WHEN a.[StartDateTime] is null THEN s.[workdoneat] WHEN CAST(a.[StartDateTime] as date) > s.[workdoneat] THEN CAST(a.[StartDateTime] as date) ELSE s.[workdoneat] END as date)) , [end] = MAX(CAST(CASE WHEN a.[EndDateTime] is null THEN s.[workdoneat] WHEN CAST(a.[EndDateTime] as date) > s.[workdoneat] THEN CAST(a.[EndDateTime] as date) ELSE s.[workdoneat] END as date)) , [CustomerId] = MIN (s.customerid) FROM [dbo].[mfr__appointments] as a RIGHT JOIN @SReq as s on a.[ServiceRequestId] = s.[Id] AND a.[State] in ('IsWorkDone') ) SELECT TOP(1) [today] , [provisionstart] = CASe WHEN [start] = [end] THEN NULL ELSE [start] END , [provisionend] = [end] , [sender] = N'Sebastian Fuchs GmbH & Co. KG ● Germaniastraße 15 ● 40223 Düsseldorf' , [paymentterms] = N'10wd' , [invoiceemail] = (SELECT TOP(1) [SupportMail] FROM @company where IsEmailInvoicingActive = 1) , [invoiceaddress] = (SELECT TOP(1) CONCAT([name], CHAR(10), [address]) FROM @company ORDER BY IsEmailInvoicingActive DESC) , [tax_servicerefund] = 0.2 , [CustomerId] = [CustomerId] FROM (VALUES(CAST(GETDATE() as date)))base ([today]) CROSS JOIN app; SELECT * ,[order] = ROW_NUMBER() OVER (ORDER BY [baseorder]) FROM @SReq; END IF @mode in ('i','ov') BEGIN SELECT itm.[Id] , [net_pos] = CASE WHEN LOWER(itm.[type]) in ('Title','Text') THEN '' ELSE FORMAT( CAST( (ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0) as numeric(7,2)) , '#0.00 €','de') END , [bo_pos] = CASE WHEN LOWER(itm.[type]) in ('Title','Text') THEN '' ELSE FORMAT( CAST( ((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) * (1 + (ISNULL(vat.[vat], 19.0) * 0.01)) as numeric(7,2)) , '#0.00 €','de') END , [vat] = CASE WHEN LOWER(itm.[type]) in ('Title','Text') THEN null ELSE FORMAT(ISNULL(vat.[vat], 19.0), '#0.0','de') + '%' END , itm.[ServiceRequestId] , itm.[SortOrder] , itm.[Type] , itm.[NameOrNumber] , itm.[Note] , [order] = (s.[baseorder] * 100) + ROW_NUMBER() OVER (PARTITION BY itm.[ServiceRequestId] ORDER BY itm.[SortOrder]) FROM [dbo].[mfr__items] as itm JOIN @SReq as s ON itm.ServiceRequestId = s.[Id] LEFT JOIN [dbo].[fds__custom_vat] as vat ON itm.[Id] = vat.[EntityId] and vat.[EntityType] = 'item' ; END ELSE IF @mode in ('f', 'ful') BEGIN SELECT itm.[Id] , [net] = ISNULL([Price],0) , [quantityhours] = ISNULL([quantityhours],1) , itm.[UnitString] , [net_val] = CAST( (ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0) as numeric(7,2)) , [bo_val] = CAST( ((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) * (1 + (ISNULL(vat.[vat], 19.0) * 0.01)) as numeric(7,2)) , [vat] = CASE WHEN LOWER(itm.[type]) in ('Title','Text') THEN null ELSE FORMAT(ISNULL(vat.[vat], 19.0), '#0.0','de') + '%' END , [vat_val] = CAST( ((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) * ((ISNULL(vat.[vat], 19.0) * 0.01)) as numeric(7,2)) , itm.[ServiceRequestId] , itm.[SortOrder] , itm.[Type] , itm.[NameOrNumber] , itm.[Note] , [order] = (s.[baseorder] * 100) + ROW_NUMBER() OVER (PARTITION BY itm.[ServiceRequestId] ORDER BY itm.[SortOrder], itm.[Id]) FROM [dbo].[mfr__items] as itm JOIN @SReq as s ON itm.ServiceRequestId = s.[Id] LEFT JOIN [dbo].[fds__custom_vat] as vat ON itm.[Id] = vat.[EntityId] and vat.[EntityType] = 'item' ; END IF @mode in ('f', 'ful') BEGIN INSERT INTO @step SELECT stp.* , [order] = (s.[baseorder] * 100) + ROW_NUMBER() OVER (PARTITION BY stp.[ServiceRequestId] ORDER BY stp.[SortOrder], stp.[Id]) FROM [dbo].[mfr__steps] as stp JOIN @SReq as s ON stp.ServiceRequestId = s.[Id]; SELECT * from @step; SELECT cc.[Id] , [CompanyName] = cc.[name] , ct.[Gender] , ct.[FirstName] , ct.[LastName] , ct.[Email] , cc.[address] FROM [dbo].[fds__getCompanysContacts](@companyids) as ct join @company as cc on cc.[Id] = ct.[CyId]; SELECT DISTINCT [ref] = 'Einsatzort ' + so.[name] ,[address] = [dbo].[fds__fn_combineAddress] (so.[Name], loc.[AddressString], null ,loc.[Postal] ,loc.[City] ,loc.[State] ,loc.[Country]) FROM @SReq as s LEFT JOIN [mfr__*PartnerSet] as p ON p.property = 'ServiceRequest:ServiceObjects' and p.[EntityId] = s.[id] LEFT JOIN [mfr__serviceobjects] as so ON so.id = p.[PartnerId] LEFT JOIN [mfr__*PartnerSet] as po ON p.property = 'ServiceObject:Location' and po.[EntityId] = so.[Id] LEFT join [dbo].[mfr__#locations] as loc ON (loc.[id] = so.[Location#ID] OR po.[PartnerId] = loc.[Id] OR (so.[Id] = loc.[EntityId] and loc.Property = 'ServiceObject:Location')) WHERE so.id is not null and loc.[id] is not null UNION SELECT DISTINCT [ref] = 'Auftragsort ' + [name] ,[address] = [dbo].[fds__fn_combineAddress] (loc.[AddressString], null, null ,loc.[Postal] ,loc.[City] ,loc.[State] ,loc.[Country]) FROM @SReq as s LEFT JOIN [mfr__*PartnerSet] as p ON p.property = 'ServiceRequest:Location' and p.[EntityId] = s.[id] join [dbo].[mfr__#locations] as loc ON (s.[Location#ID] = loc.[id] OR p.[PartnerId] = loc.[Id] OR (s.[Id] = loc.[EntityId] and loc.Property = 'ServiceRequest:Location')) WHERE loc.[id] is not null UNION SELECT DISTINCT [ref] = 'Kunde' , [address] FROM @company; END END GO /****** Object: StoredProcedure [dbo].[fds__getRequests_list] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__getRequests_list] @tgtdate date ,@mode varchar(1) = '' ,@completed bit = 1 ,@authuser varchar(100) AS BEGIN SET NOCOUNT ON; DECLARE @startdate date, @enddate date; SET @mode = LOWER(@mode); If @mode = 'm' BEGIN SELECT @startdate = [dbo].[date_monthfirst](@tgtdate) ,@enddate = [dbo].[date_monthend](@tgtdate); END ELSE If @mode = 'w' BEGIN SELECT @startdate = [dbo].[date_weekfirst](@tgtdate) ,@enddate = [dbo].[date_weekend](@tgtdate); END DECLARE @openmode as bit = CASE WHEN LOWER(LEFT(ISNULL(@mode, ''),1)) = 'o' THEN 1 ELSE 0 END; SELECT [startdate] = @startdate, [enddate] = @enddate, [mode] = @mode , [title] = CASE WHEN @openmode = 1 THEN 'Übersicht der offenen Aufträge' ELSE 'Auftragsübersicht für ' + CASE WHEN @mode = 'm' THEN 'MONAT ' + FORMAT(@startdate, 'MMM yyyy') WHEN @mode = 'w' THEN 'WOCHE ' + FORMAT(@startdate, 'dd.MM.yyyy') + ' - ' + FORMAT(@enddate, 'dd.MM.') ELSE '' END END; DECLARE @SReq TABLE ( [Id] [bigint] NOT NULL, [Name] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [InvoiceId] [nvarchar](255) NULL, [ClosedAt] [datetime] NULL, [ReleasedAt] [datetime] NULL, [WorkDoneAt] [datetime] NULL, [TargetTimeInMinutes] [bigint] NULL, [DateModified] [datetime] NULL, [DateOfCreation] [datetime] NULL, [DueDateRangeStart] [datetime] NULL, [DueDateRangeEnd] [datetime] NULL, [PortalLink] [nvarchar](255) NULL, [CostCenterId] [bigint] NULL, [Description] [nvarchar](max) NULL, [State] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NULL, [CurrentOwnerId] [bigint] NULL, [CustomerId] [bigint] NULL, [ParentServiceRequestId] [bigint] NULL, [ParentExtenalId] [nvarchar](255) NULL, [ParentWorkDoneAt] [date] NULL, [ParentInvoiceId] [nvarchar](255) NULL, [Location#ID] [bigint] NULL, [Version] [int] NULL, [IsTemplate] [bit] NULL, [IsTemplateMobile] [bit] NULL, [CreateFromServiceRequestTemplateId] [bigint] NULL, [Type] [nvarchar](255) NULL, [CustomerName] [nvarchar](255) NULL, [isChild] bit NULL, [open] bit, [baseorder] int ); DECLARE @inv TABLE ([Id] bigint, [Invoices] varchar(1000), [isOpen] bit); With fdsinv as( SELECT [Id] = fdsr.[mfr__servicerequest], fdsi.[InvoiceId], fdsi.[InvoiceType], [isCanceled] = ISNULL(fdsi.[isCanceled],0) FROM [dbo].[fds__invoice_servicerequests] as fdsr JOIN [dbo].[fds__invoices] as fdsi on fdsr.[invid] = fdsi.[id] WHERE [isFinal] = 1 AND fdsr.[mfr__servicerequest] is not null ), fi as( SELECT [Id], [isOpen] = MIN(CASE WHEN ISNULL([invoicetype],'r') = 'r' AND [isCanceled] = 0 THEN 0 ELSE 1 END) FROM fdsinv GROUP BY [Id] ) INSERT INTO @inv SELECT [Id] , [invoices] = ISNULL(STUFF( (SELECT CHAR(10) + [InvoiceId] + ' (' + [InvoiceTYpe] + ')' FROM fdsinv as f2 WHERE f2.[id] = fi.[Id] FOR XML PATH, TYPE).value('.[1]','nvarchar(max)') ,1,1,'') , '') , [isOpen] FROM fi; insert into @SReq SELECT s.[Id] ,[Name] ,[ExternalId] ,[InvoiceId] = [dbo].[fds__fn_InvoiceIDs_mfr](s.[invoiceid], inv.[Invoices]) ,[ClosedAt] ,[ReleasedAt] ,[WorkDoneAt] ,[TargetTimeInMinutes] ,s.[DateModified] ,s.[DateOfCreation] ,[DueDateRangeStart] ,[DueDateRangeEnd] ,[PortalLink] ,[CostCenterId] ,[Description] ,[State] ,s.[CustomValues] ,[CurrentOwnerId] ,s.[CustomerId] ,[ParentServiceRequestId] ,[ParentExtenalId] = cast(CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then null ELSE '?' END as nvarchar(255)) ,[ParentWorkDoneAt] = cast(NULL as datetime) ,[ParentInvoiceId] = cast(NULL as nvarchar(255)) ,[Location#ID] ,s.[Version] ,[IsTemplate] ,[IsTemplateMobile] ,[CreateFromServiceRequestTemplateId] ,[Type] ,[CustomerName] = NULL ,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END ,[open] = CASE WHEN s.[workdoneat] is not null AND [dbo].[fds__fn_InvoiceIDs_mfr](s.[invoiceid],'') = '' AND ISNULL(inv.[isOpen],1) = 1 THEN 1 ELSE 0 END ,[baseorder] = 0 FROM [dbo].[mfr__servicerequests] as s -- parent and childs; LEFT JOIN @inv as inv on inv.[Id] = s.[Id] WHERE ( ( @openmode = 1 AND [workdoneat] is not null AND ISNULL(s.[invoiceid],'') = '' AND ISNULL([State], '') <> 'Closed' AND ISNULL(inv.[isOpen],1) = 1 AND NOT EXISTS (SELECT * FROM [dbo].[fds__custom_servicerequest] as sr where sr.[EntityID] = s.[id] and sr.[hidden] = 1) ) OR (@openmode = 0 AND CAST([DateOfCreation] as date) between @startdate AND @enddate ) ); INSERT INTO @SReq SELECT DISTINCT ISNULL(s.[Id], CASE WHEN ISNULL(q.[ParentServiceRequestId],0) > 0 THEN q.[ParentServiceRequestId] ELSE NULL END) ,ISNULL(s.[Name], CASE WHEN ISNULL(q.[ParentServiceRequestId],0) > 0 THEN ' - - unbekannt - - ' ELSE NULL END) ,s.[ExternalId] ,[InvoiceId] = [dbo].[fds__fn_InvoiceIDs_mfr](s.[invoiceid], inv.[Invoices]) ,s.[ClosedAt] ,s.[ReleasedAt] ,s.[WorkDoneAt] ,s.[TargetTimeInMinutes] ,s.[DateModified] ,s.[DateOfCreation] ,s.[DueDateRangeStart] ,s.[DueDateRangeEnd] ,s.[PortalLink] ,s.[CostCenterId] ,s.[Description] ,s.[State] ,s.[CustomValues] ,s.[CurrentOwnerId] ,s.[CustomerId] ,s.[ParentServiceRequestId] ,[ParentExtenalId] = CASE WHEN s.[ParentServiceRequestId] = q.[id] THEN q.[ExternalId] ELSE NULL END ,[ParentWorkDoneAt] = CASE WHEN s.[ParentServiceRequestId] = q.[id] THEN q.[WorkDoneAt] ELSE NULL END ,[ParentInvoiceId] = CASE WHEN s.[ParentServiceRequestId] = q.[id] THEN q.[InvoiceId] ELSE NULL END ,s.[Location#ID] ,s.[Version] ,s.[IsTemplate] ,s.[IsTemplateMobile] ,s.[CreateFromServiceRequestTemplateId] ,s.[Type] ,[CustomerName] = NULL ,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END ,[open] = CASE WHEN s.[workdoneat] is not null AND [dbo].[fds__fn_InvoiceIDs_mfr](s.[invoiceid],'') = '' AND ISNULL(inv.[isOpen],1) = 1 THEN 1 ELSE 0 END ,[baseorder] = 0 from [dbo].[mfr__servicerequests] as s RIGHT JOIN @SReq as q ON (s.[ParentServiceRequestId] = q.[id] OR q.[ParentServiceRequestId] = s.[id]) --parents or childs LEFT JOIN @inv as inv on inv.[Id] = s.[Id] WHERE NOT EXISTS (SELECT * FROM @SReq as s2 WHERE s2.[id] = s.[Id]) AND ISNULL(s.[Id], CASE WHEN ISNULL(q.[ParentServiceRequestId],0) > 0 THEN q.[ParentServiceRequestId] ELSE NULL END) is not null ; WITH q as ( SELECT [id], [baseorder] = (ROW_NUMBER() OVER (ORDER BY ISNULL([ParentWorkDoneAt], [WorkDoneAt]), CASE WHEN ISNULL([ParentServiceRequestId],0) = 0 THEN [id] ELSE [ParentServiceRequestId] END) * 100) FROM @SReq as s WHERE [ischild] = 0 ) UPDATE s SET [baseorder] = q.baseorder ,[ParentServiceRequestId] = CASE WHEN s.isChild = 0 THEN s.[Id] ELSE s.[ParentServiceRequestId] END FROM @SReq as s JOIN q ON s.[id] = q.[id]; UPDATE s SET [CustomerName] = c.[name] FROM @SReq as s JOIN [mfr__companies] as c ON s.[CustomerId] = c.[id]; WITH q as ( SELECT s.[id] , q.[ExternalId], q.[WorkDoneAt], q.[InvoiceId] , [baseorder] = q.[baseorder] + ROW_NUMBER() OVER (PARTITION BY q.[id] ORDER BY s.[dateofcreation], s.[Id]) FROM @SReq as s JOIN @SReq as q ON s.[ParentServiceRequestId] = q.[id] WHERE s.[ischild] = 1 ) UPDATE s SET [ParentExtenalId] = q.[ExternalId] ,[ParentWorkDoneAt] = q.[WorkDoneAt] ,[ParentInvoiceId] = q.[InvoiceId] ,[baseorder] = q.[baseorder] FROM @SReq as s JOIN q ON s.[Id] = q.[id]; SELECT * FROM @SReq order by baseorder SELECT [requestID] = s.[Id] ,r.* ,[order] = ROW_NUMBER() OVER (PARTITION BY s.[Id] ORDER BY r.[dateofcreation] ASC, r.[Id]) FROM [dbo].[mfr__reports] as r JOIN [dbo].[mfr__*PartnerSet] as ps ON ps.[Property] like 'ServiceRequest:Reports' and r.[id] = ps.PartnerId JOIN @SReq as s ON s.[Id] = ps.[EntityId] ORDER BY s.[Id], r.[dateofcreation] ASC; END GO /****** Object: StoredProcedure [dbo].[fds__logEmail] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__logEmail] @Ref varchar(25) ,@guid varchar(50) ,@DateSent datetime ,@config nvarchar(max) AS BEGIN SET NOCOUNT ON; INSERT INTO [dbo].[fds__emaillog] ([Ref] ,[guid] ,[DateSent] ,[config]) VALUES ( @Ref ,@guid ,@DateSent ,@config ); END GO /****** Object: StoredProcedure [dbo].[fds__prepInvoice] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__prepInvoice] @servicerequestid bigint , @mode varchar(3) , @authuser varchar(100) , @type char(1) AS BEGIN SET NOCOUNT ON; DECLARE @today date = GETDATE(); SET @type = LOWER(ISNULL(@type, 'r')); DECLARE @SReq TABLE ( [Id] [bigint] NOT NULL, [Name] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [InvoiceId] [nvarchar](255) NULL, [ClosedAt] [datetime] NULL, [ReleasedAt] [datetime] NULL, [WorkDoneAt] [datetime] NULL, [TargetTimeInMinutes] [bigint] NOT NULL, [DateModified] [datetime] NULL, [DateOfCreation] [datetime] NULL, [DueDateRangeStart] [datetime] NULL, [DueDateRangeEnd] [datetime] NULL, [PortalLink] [nvarchar](255) NULL, [CostCenterId] [bigint] NULL, [Description] [nvarchar](max) NULL, [State] [nvarchar](255) NULL, [CustomValues] [nvarchar](max) NOT NULL, [CurrentOwnerId] [bigint] NULL, [CustomerId] [bigint] NULL, [ParentServiceRequestId] [bigint] NULL, [ParentExtenalId] [nvarchar](255) NULL, [ParentWorkDoneAt] [date] NULL, [ParentInvoiceId] [nvarchar](255) NULL, [Location#ID] [bigint] NULL, [Version] [int] NOT NULL, [IsTemplate] [bit] NOT NULL, [IsTemplateMobile] [bit] NOT NULL, [CreateFromServiceRequestTemplateId] [bigint] NOT NULL, [Type] [nvarchar](255) NULL, [Summary] nvarchar(255) NULL, [isChild] bit NULL, [baseorder] int, [provision] varchar(255) NULL ); insert into @SReq SELECT [Id] ,[Name] ,[ExternalId] ,[InvoiceId] ,[ClosedAt] ,[ReleasedAt] ,[WorkDoneAt] ,[TargetTimeInMinutes] ,[DateModified] ,[DateOfCreation] ,[DueDateRangeStart] ,[DueDateRangeEnd] ,[PortalLink] ,[CostCenterId] ,[Description] ,[State] ,[CustomValues] ,[CurrentOwnerId] ,[CustomerId] ,[ParentServiceRequestId] ,[ParentExtenalId] = cast(CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then null ELSE '?' END as nvarchar(255)) ,[ParentWorkDoneAt] = cast(NULL as datetime) ,[ParentInvoiceId] = cast(NULL as nvarchar(255)) ,[Location#ID] ,[Version] ,[IsTemplate] ,[IsTemplateMobile] ,[CreateFromServiceRequestTemplateId] ,[Type] ,[Summary] = NULL ,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END ,[baseorder] = 0 ,[provision] = NULL FROM [dbo].[mfr__servicerequests] as s WHERE [id] = @servicerequestid; IF @type <> 'i' -- for interim invoices, only one selected servicerequest is allowed -> childs and parents are ignored BEGIN INSERT INTO @SReq SELECT s.[Id] ,s.[Name] ,s.[ExternalId] ,s.[InvoiceId] ,s.[ClosedAt] ,s.[ReleasedAt] ,s.[WorkDoneAt] ,s.[TargetTimeInMinutes] ,s.[DateModified] ,s.[DateOfCreation] ,s.[DueDateRangeStart] ,s.[DueDateRangeEnd] ,s.[PortalLink] ,s.[CostCenterId] ,s.[Description] ,s.[State] ,s.[CustomValues] ,s.[CurrentOwnerId] ,s.[CustomerId] ,s.[ParentServiceRequestId] ,[ParentExtenalId] = CASE WHEN s.[ParentServiceRequestId] = q.[id] THEN q.[ExternalId] ELSE NULL END ,[ParentWorkDoneAt] = CASE WHEN s.[ParentServiceRequestId] = q.[id] THEN q.[WorkDoneAt] ELSE NULL END ,[ParentInvoiceId] = CASE WHEN s.[ParentServiceRequestId] = q.[id] THEN q.[InvoiceId] ELSE NULL END ,s.[Location#ID] ,s.[Version] ,s.[IsTemplate] ,s.[IsTemplateMobile] ,s.[CreateFromServiceRequestTemplateId] ,s.[Type] ,[Summary] = NULL ,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END ,[baseorder] = 0 , [provision_start] = null from [dbo].[mfr__servicerequests] as s JOIN @SReq as q ON (s.[ParentServiceRequestId] = q.[id] OR q.[ParentServiceRequestId] = s.[id]) --parents or childs WHERE NOT EXISTS (SELECT * FROM @SReq as s2 WHERE s2.[id] = s.[Id]) END; WITH q as ( SELECT [id], [baseorder] = (ROW_NUMBER() OVER (ORDER BY ISNULL([ParentWorkDoneAt], [WorkDoneAt]), ISNULL([ParentServiceRequestId],[id])) * 100) FROM @SReq as s WHERE [ischild] = 0 ) UPDATE s SET [baseorder] = q.baseorder FROM @SReq as s JOIN q ON s.[id] = q.[id]; WITH q as ( SELECT s.[id] , q.[ExternalId], q.[WorkDoneAt], q.[InvoiceId] , [baseorder] = q.[baseorder] + ROW_NUMBER() OVER (PARTITION BY q.[id] ORDER BY s.[dateofcreation]) FROM @SReq as s JOIN @SReq as q ON s.[ParentServiceRequestId] = q.[id] WHERE s.[ischild] = 1 ) UPDATE s SET [ParentExtenalId] = q.[ExternalId] ,[ParentWorkDoneAt] = q.[WorkDoneAt] ,[ParentInvoiceId] = q.[InvoiceId] ,[baseorder] = q.[baseorder] FROM @SReq as s JOIN q ON s.[Id] = q.[id]; DECLARE @step [dbo].[fds__tt__mfr_steps]; DECLARE @itm [dbo].[fds__tt__mfr_items]; DECLARE @company TABLE ( [Id] [bigint] NOT NULL, [Location#ID] [bigint] NULL, [Version] [int] NOT NULL, [IsPhysicalPerson] [bit] NOT NULL, [IsOwner] [bit] NOT NULL, [IsEmailInvoicingActive] [bit] NOT NULL, [IsSupplier] [bit] NOT NULL, [MappingId] [nvarchar](255) NULL, [ExternalId] [nvarchar](255) NULL, [Name] [nvarchar](255) NULL, [Note] [nvarchar](255) NULL, [SupportTelephone] [nvarchar](255) NULL, [SupportFax] [nvarchar](255) NULL, [SupportMail] [nvarchar](255) NULL, [QuickSearch] [nvarchar](255) NULL, [DateModified] [datetime] NOT NULL, [CustomValues] [nvarchar](max) NOT NULL, [MainContactId] [bigint] NOT NULL, [address] nvarchar(1000) null ); INSERT INTO @company SELECT DISTINCT cy.*, [address] = [dbo].[fds__getCompanyAddress](cy.[id]) FROM [mfr__companies] as cy JOIN @SReq as s on cy.id = s.[CustomerId]; DECLARE @companyids [dbo].[fds__tt__idlist]; INSERT INTO @companyids SELECT DISTINCT [id] FROM @company; INSERT INTO @itm SELECT itm.*, [baseorder] = s.[baseorder], [order] = ROW_NUMBER() OVER (PARTITION BY [ServiceRequestId] ORDER BY [SortOrder], itm.[Id]) from [dbo].[mfr__items] as itm JOIN @SReq as s ON itm.ServiceRequestId = s.[Id]; IF @type <> 'i' BEGIN -- Add virtual items for intermediate invoices INSERT INTO @itm SELECT [Id] = -2 ,[Version] = 0 ,[QuantityHours] = 1 ,[PlannedQuantityHours] = 1 ,[ItemTypeId] = NULL ,[ItemNumber] = NULL ,[TrackingId] = NULL ,[Manufacture] = NULL ,[Price] = inv.InvoiceBalance_net * -1.0 --without VAT ,[Costs] = inv.InvoiceBalance_net * -1.0 --without VAT ,[NameOrNumber] = REPLACE(inv.DocumentName, '.pdf','') ,[CustomValues] = NULL ,[Note] = '

' + 'Anrechnung der ' + REPLACE(inv.DocumentName, '.pdf','') + ' vom ' + FORMAT(inv.[dateFinalized], 'dd.MM.yyyy', 'de-de') + '

' ,[ExternalId] = NULL ,[Discount] = NULL ,[VAT] = inv.InvoiceVAT_1 ,[IsManual] = 1 ,[SortOrder] = ROW_NUMBER() OVER (PARTITION BY srq.[mfr__servicerequest] ORDER BY inv.[dateFinalized], inv.DateCreated) ,[Type] = 'PartialInvoice' ,[ServiceRequestId] = s.[id] ,[ServiceObjectId] = Null ,[CreatorId] = NULL ,[UnitId] = 15825600513 ,[UnitString] = 'Pauschal' ,[baseorder] = s.[baseorder], [order] = 10000 + ROW_NUMBER() OVER (PARTITION BY srq.[mfr__servicerequest] ORDER BY inv.[dateFinalized], inv.DateCreated) from [dbo].[fds__invoices] as inv JOIN [dbo].[fds__invoice_servicerequests] as srq ON inv.[Id] = srq.[InvId] AND inv.[InvoiceType] = 'i' --important JOIN @SReq as s ON srq.[mfr__servicerequest] = s.[Id] WHERE inv.[InvoiceType] = 'i' --important; AND inv.[isFinal] = 1; END; /** OUTPUT + get other types **/ WITH app as( SELECT [start] = MIN(CAST(CASE WHEN a.[StartDateTime] is null THEN s.[workdoneat] WHEN CAST(a.[StartDateTime] as date) > s.[workdoneat] THEN CAST(a.[StartDateTime] as date) ELSE s.[workdoneat] END as date)) , [end] = MAX(CAST(CASE WHEN a.[EndDateTime] is null THEN s.[workdoneat] WHEN CAST(a.[EndDateTime] as date) > s.[workdoneat] THEN CAST(a.[EndDateTime] as date) ELSE s.[workdoneat] END as date)) , [CustomerId] = MIN (s.customerid) FROM [dbo].[mfr__appointments] as a RIGHT JOIN @SReq as s on a.[ServiceRequestId] = s.[Id] AND a.[State] in ('IsWorkDone') ) SELECT TOP(1) [today] , [provisionstart] = CASe WHEN @type = 'i' THEN NULL WHEN [start] = [end] THEN NULL ELSE [start] END , [provisionend] = CASe WHEN @type = 'i' THEN @today ELSE [end] END -- Abschlagsrechnungen immer mit Tagesdatum , [sender] = N'Sebastian Fuchs GmbH & Co. KG ● Germaniastraße 15 ● 40223 Düsseldorf' , [paymentterms] = N'10wd' , [invoiceemail] = (SELECT TOP(1) [SupportMail] FROM @company where IsEmailInvoicingActive = 1) , [invoiceaddress] = (SELECT TOP(1) CONCAT([name], CHAR(10), [address]) FROM @company ORDER BY IsEmailInvoicingActive DESC) , [tax_servicerefund] = 0.2 , [CustomerId] = [CustomerId] , [invoicetitle] = CASE WHEN @type = 'i' THEN 'Abschlagsrechnung' WHEN @type = 'f' THEN 'Schlussrechnung' WHEN @type = 'c' THEN 'Stornorechnung' ELSE 'Rechnung' END , [type] = @type FROM (VALUES(CAST(GETDATE() as date)))base ([today]) CROSS JOIN app; SELECT * ,[order] = ROW_NUMBER() OVER (ORDER BY [baseorder]) FROM @SReq; IF @type <> 'i' BEGIN SELECT itm.[Id] , [net] = ISNULL([Price],0) , [quantityhours] = ISNULL([quantityhours],1) , itm.[UnitString] , [net_val] = CAST( (ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0) as numeric(7,2)) , [bo_val] = CAST( ((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) * (1 + (ISNULL(vat.[vat], 19.0) * 0.01)) as numeric(7,2)) , [vat] = CASE WHEN LOWER(itm.[type]) in ('Title','Text') THEN null ELSE FORMAT(ISNULL(vat.[vat], 19.0), '#0.0','de') + '%' END , [vat_val] = CAST( ((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) * ((ISNULL(vat.[vat], 19.0) * 0.01)) as numeric(7,2)) , itm.[ServiceRequestId] , itm.[SortOrder] , itm.[Type] , itm.[NameOrNumber] , itm.[Note] , [order] = (itm.[baseorder] * 100) + itm.[order] FROM @itm as itm LEFT JOIN [dbo].[fds__custom_vat] as vat ON itm.[Id] = vat.[EntityId] and vat.[EntityType] = 'item'; END ELSE BEGIN WITH citm as ( SELECT itm.[ServiceRequestId], [net_val] = CAST( SUM( (ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0) ) as numeric(7,2)) FROM @itm as itm WHERE itm.[Type] = 'Material' GROUP BY itm.[ServiceRequestId] ) SELECT [Id] = -1 , [net] = 1000.0 , [quantityhours] = 1 , [UnitString] = 'Pauschal' , [net_val] = CAST( 1000.0 as numeric(7,2)) , [bo_val] = CAST( 1000.0 * 1.19 as numeric(7,2)) , [vat] = FORMAT( 19.0, '#0.0','de') + '%' , [vat_val] = CAST( 1000.0 * 0.19 as numeric(7,2)) , [ServiceRequestId] = s.[id] , [SortOrder] = 0 , [Type] = 'PartialInvoice' , [NameOrNumber] = 'Abschlagsbetrag für bereits erbrachte Arbeiten, Dienstleistungen, Materiallieferungen und getätigte Bestellvorgänge zum oben genannten Bauvorhaben' , [Note] = '' , [order] = 1 FROM @SReq as s; END INSERT INTO @step SELECT stp.* , s.[baseorder] , [order] = (s.[baseorder] * 100) + ROW_NUMBER() OVER (PARTITION BY stp.[ServiceRequestId] ORDER BY stp.[SortOrder], stp.[Id]) FROM [dbo].[mfr__steps] as stp JOIN @SReq as s ON stp.ServiceRequestId = s.[Id]; SELECT * from @step; SELECT cc.[Id] , [CompanyName] = cc.[name] , ct.[Gender] , ct.[FirstName] , ct.[LastName] , ct.[Email] , cc.[address] FROM [dbo].[fds__getCompanysContacts](@companyids) as ct join @company as cc on cc.[Id] = ct.[CyId]; SELECT DISTINCT [ref] = 'Einsatzort ' + so.[name] ,[address] = [dbo].[fds__fn_combineAddress] (so.[Name], loc.[AddressString], null ,loc.[Postal] ,loc.[City] ,loc.[State] ,loc.[Country]) FROM @SReq as s LEFT JOIN [mfr__*PartnerSet] as p ON p.property = 'ServiceRequest:ServiceObjects' and p.[EntityId] = s.[id] LEFT JOIN [mfr__serviceobjects] as so ON so.id = p.[PartnerId] LEFT JOIN [mfr__*PartnerSet] as po ON p.property = 'ServiceObject:Location' and po.[EntityId] = so.[Id] LEFT join [dbo].[mfr__#locations] as loc ON (loc.[id] = so.[Location#ID] OR po.[PartnerId] = loc.[Id] OR (so.[Id] = loc.[EntityId] and loc.Property = 'ServiceObject:Location')) WHERE so.id is not null and loc.[id] is not null UNION SELECT DISTINCT [ref] = 'Auftragsort ' + [name] ,[address] = [dbo].[fds__fn_combineAddress] (loc.[AddressString], null, null ,loc.[Postal] ,loc.[City] ,loc.[State] ,loc.[Country]) FROM @SReq as s LEFT JOIN [mfr__*PartnerSet] as p ON p.property = 'ServiceRequest:Location' and p.[EntityId] = s.[id] join [dbo].[mfr__#locations] as loc ON (s.[Location#ID] = loc.[id] OR p.[PartnerId] = loc.[Id] OR (s.[Id] = loc.[EntityId] and loc.Property = 'ServiceRequest:Location')) WHERE loc.[id] is not null UNION SELECT DISTINCT [ref] = 'Kunde' , [address] FROM @company; END GO /****** Object: StoredProcedure [dbo].[fds__r_getBalanceByMonth] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__r_getBalanceByMonth] AS BEGIN SET NOCOUNT ON; DECLARE @today date = GETDATE() DECLARE @tomorrow date = DATEADD(DAY,1,@today); DECLARE @Admin [dbo].[fds__tt__admin_ReportAdminTable]; --Admin Table INSERT INTO @Admin VALUES ( 'bbm' ,'Umsatz nach Monaten' ,'Umsatz nach Monaten' ,'' + FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm') ,'' ,'table' --typ , '' --settings , '' , 0) SELECT * FROM @Admin; WITH inv as ( SELECT i.[Dateofcreation] ,i.[InvoiceBalance] FROM [dbo].[mfr__reports] as i where i.[IsInvoice] = 1 UNION SELECT [Dateofcreation] = i.[DateCreatEd] ,i.[InvoiceBalance] FROM [dbo].[fds__invoices] as i WHERE i.[isFinal] = 1 ) SELECT [Monat] = FORMAT( inv.[Dateofcreation], 'yyyy - MM', 'de') , [∑ Umsätze] = FORMAT( SUM( ISNULL(inv.[InvoiceBalance],0) ), '#,0.00 €', 'de') , [style:∑ Umsätze] = 'text-align: right' FROM inv GROUP BY FORMAT( inv.[Dateofcreation], 'yyyy - MM', 'de'); END GO /****** Object: StoredProcedure [dbo].[fds__r_getBalanceByYearTopCustomer] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__r_getBalanceByYearTopCustomer] @year int AS BEGIN SET NOCOUNT ON; DECLARE @today date = GETDATE() DECLARE @tomorrow date = DATEADD(DAY,1,@today); DECLARE @Admin [dbo].[fds__tt__admin_ReportAdminTable]; --Admin Table INSERT INTO @Admin VALUES ( 'bbm' ,'Umsatz der Top 10 Kunden für Jahr ' + CAST( @year as varchar(10)) ,'Umsatz der Top 10 Kunden pro Jahr ' + CAST( @year as varchar(10)) ,'' + FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm') ,'' ,'table' --typ , '' --settings , '' , 0); SELECT * FROM @Admin; WITH inv as( select [InvoiceBalance] = SUM( ISNULL(_i.[InvoiceBalance],0) ) ,[Dateofcreation] = CAST(_i.[Dateofcreation] as date) ,srq.CustomerId ,[customerName] = cy.Name ,[seq] = ROW_NUMBER() OVER (ORDER BY CAST(_i.[Dateofcreation] as date)) FROM [dbo].[mfr__reports] as _i JOIN [dbo].[mfr__servicerequests] as srq on srq.InvoiceId like ('%' + _i.[InvoiceId] + '%') JOIN [dbo].[mfr__companies] as cy on srq.CustomerId = cy.id where _i.IsInvoice = 1 and YEAR(_i.[Dateofcreation]) = @year GROUP BY CAST(_i.[Dateofcreation] as date), CustomerId, cy.name UNION select [InvoiceBalance] = SUM( ISNULL(_i.[InvoiceBalance],0) ) ,[Dateofcreation] = CAST(_i.[DateCreated] as date) ,_i.CustomerId ,[customerName] = cy.Name ,[seq] = ROW_NUMBER() OVER (ORDER BY CAST(_i.[DateCreated] as date)) FROM [dbo].[fds__invoices] as _i JOIN [dbo].[mfr__companies] as cy on _i.CustomerId = cy.id where YEAR(_i.[DateCreated]) = @year and _i.[isfinal] = 1 GROUP BY CAST(_i.[DateCreated] as date), CustomerId, cy.name ), yr as ( SELECT [year] = YEAR( inv.[Dateofcreation] ) , [total] = SUM( ISNULL(inv.[InvoiceBalance],0) ) FROM [dbo].[mfr__reports] as inv where inv.[IsInvoice] = 1 GROUP BY YEAR( inv.[Dateofcreation]) ) SELECT TOP(10) [Jahr] = CAST( YEAR( inv.[Dateofcreation] ) as varchar(4)) , [Name d. Kunden] = [customerName] , [∑ Umsätze] = FORMAT( SUM( ISNULL(inv.[InvoiceBalance],0) ), '#,0.00 €', 'de') , [style:∑ Umsätze] = 'text-align: right' , [% Anteil] = CASE WHEN yr.[total] > 0 THEN FORMAT( SUM( ISNULL(inv.[InvoiceBalance],0) ) / [total], '0 %', 'de') ELSE NULL END , [style:% Anteil] = 'text-align: right' , [order] = ROW_NUMBER() OVER ( ORDER By SUM( ISNULL(inv.[InvoiceBalance],0) ) DESC) FROM inv LEFT JOIN yr on YEAR( inv.[Dateofcreation] ) = yr.[year] GROUP BY YEAR( inv.[Dateofcreation] ), yr.[total], [customerName]; END GO /****** Object: StoredProcedure [dbo].[fds__r_getBalanceByYearTopMaterial] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__r_getBalanceByYearTopMaterial] @year int AS BEGIN SET NOCOUNT ON; DECLARE @today date = GETDATE() DECLARE @tomorrow date = DATEADD(DAY,1,@today); DECLARE @Admin [dbo].[fds__tt__admin_ReportAdminTable]; --Admin Table INSERT INTO @Admin VALUES ( 'bbm' ,'Umsatz der Top 10 Materialien für Jahr ' + CAST( @year as varchar(10)) ,'Umsatz der Top 10 Materialien für Jahr ' + CAST( @year as varchar(10)) ,'' + FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm') ,'' ,'table' --typ , '' --settings , '' , 0); SELECT * FROM @Admin; WITH inv as( select [itmPrice] = SUM( (ISNULL(itm.[price],0) * ISNULL(itm.[QuantityHours],0) ) -ISNULL(itm.[discount],0) ) ,[Dateofcreation] = CAST(_i.[Dateofcreation] as date) ,[material] = itm.NameOrNumber ,[seq] = ROW_NUMBER() OVER (ORDER BY CAST(_i.[Dateofcreation] as date)) FROM [dbo].[mfr__reports] as _i JOIN [dbo].[mfr__servicerequests] as srq on srq.InvoiceId like ('%' + _i.[InvoiceId] + '%') JOIN [dbo].[mfr__items] as itm on srq.Id = itm.[ServiceRequestId] and itm.[Type] like 'Material' where _i.IsInvoice = 1 and YEAR(_i.[Dateofcreation]) = @year GROUP BY CAST(_i.[Dateofcreation] as date), itm.NameOrNumber UNION SELECT [itmPrice] = SUM( ISNULL(itm.[value_total],0) ) ,[Dateofcreation] = CAST(_i.[DateCreated] as date) ,[material] = itm.[text] ,[seq] = ROW_NUMBER() OVER (ORDER BY CAST(_i.[DateCreated] as date)) FROM [dbo].[fds__invoices] as _i JOIN [fds__invoice_items] as itm on itm.[invid] = _i.[id] AND itm.[Type] like 'Material' where YEAR(_i.[DateCreated]) = @year and _i.[isfinal] = 1 GROUP BY CAST(_i.[DateCreated] as date), itm.[text] ), yr as ( SELECT [year] = YEAR( inv.[Dateofcreation] ) , [total] = SUM( ISNULL(inv.[InvoiceBalance],0) ) FROM [dbo].[mfr__reports] as inv where inv.[IsInvoice] = 1 GROUP BY YEAR( inv.[Dateofcreation]) ) SELECT TOP(10) [Jahr] = CAST( YEAR( inv.[Dateofcreation] ) as varchar(4)) , [Material] = [material] , [∑ Umsätze] = FORMAT( SUM( ISNULL(inv.[itmPrice],0) ), '#,0.00 €', 'de') , [style:∑ Umsätze] = 'text-align: right' , [% Anteil] = CASE WHEN yr.[total] > 0 THEN FORMAT( SUM( ISNULL(inv.[itmPrice],0) ) / [total], '0 %', 'de') ELSE NULL END , [style:% Anteil] = 'text-align: right' , [order] = ROW_NUMBER() OVER ( ORDER By SUM( ISNULL(inv.[itmPrice],0) ) DESC) FROM inv LEFT JOIN yr on YEAR( inv.[Dateofcreation] ) = yr.[year] GROUP BY YEAR( inv.[Dateofcreation] ), yr.[total], [material]; END GO /****** Object: StoredProcedure [dbo].[fds__r_getBalanceTrendByMonth] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__r_getBalanceTrendByMonth] @year int ,@month int AS BEGIN SET NOCOUNT ON; DECLARE @today date = GETDATE() DECLARE @tomorrow date = DATEADD(DAY,1,@today); set @month = ISNULL(@month, Month(@today)); set @year= ISNULL(@year, Year(@year)); DECLARE @Admin [dbo].[fds__tt__admin_ReportAdminTable]; --Admin Table INSERT INTO @Admin VALUES ( 'bbm' ,'UmsatzTrend für Monat ' + FORMAT(@Month, '00') + ' / ' + FORMAT(@year, '0000') ,'UmsatzTrend für Monat ' + FORMAT(@Month, '00') + ' / ' + FORMAT(@year, '0000') ,'' + FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm') ,'' ,'chart' --typ , '{ "charttype": "line", "x1_label_angle": -90, "color": "e0301e", "linewidth": 2, "valuelabels": false, "marker": "none", "colorpalette": "00B050;00B050;00B050", "x1_column": "date", "y1_column": "Value", "y1_title": "Actuals", "x1_title": "", "series_column": "series", "legend_position": "bottom", "show_datalabel": true, "datalabelfontsizescale": 0.6, "height": 600, "width": 1200, "x1_labelformat": "ddd, dd/MM"}' --settings , '' , 0) SELECT * FROM @Admin; with inv as( select [InvoiceBalance] = SUM( ISNULL(_i.[InvoiceBalance],0) ) ,[Dateofcreation] = CAST([Dateofcreation] as date) ,[seq] = ROW_NUMBER() OVER (ORDER BY CAST([Dateofcreation] as date)) FROM [dbo].[mfr__reports] as _i where _i.IsInvoice = 1 and month([Dateofcreation]) = @Month and YEAR([Dateofcreation]) = @year GROUP BY CAST([Dateofcreation] as date) UNION select [InvoiceBalance] = SUM( ISNULL(_i.[InvoiceBalance],0) ) ,[Dateofcreation] = CAST([Datecreated] as date) ,[seq] = ROW_NUMBER() OVER (ORDER BY CAST([Datecreated] as date)) FROM [dbo].[fds__invoices] as _i where _i.IsFinal = 1 and month([Datecreated]) = @Month and YEAR([Datecreated]) = @year GROUP BY CAST([Datecreated] as date) ) SELECT --[Monat] = FORMAT( inv.[Dateofcreation], 'yyyy - MM', 'de') --,[Umsatz] = FORMAT( ISNULL(inv.[InvoiceBalance],0) , '#0.00', 'de') [series] = 'Umsatz' ,[date] = CAST(inv.[Dateofcreation] as date) ,[value] = CAST( SUM( ISNULL(inv.[InvoiceBalance],0) ) OVER (ORDER BY [seq]) as numeric(9,2)) FROM inv ORDER BY [seq] END GO /****** Object: StoredProcedure [dbo].[fds__r_getBalanceTrendByYear] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__r_getBalanceTrendByYear] @year int AS BEGIN SET NOCOUNT ON; DECLARE @today date = GETDATE() DECLARE @tomorrow date = DATEADD(DAY,1,@today); set @year= ISNULL(@year, Year(@year)); DECLARE @Admin [dbo].[fds__tt__admin_ReportAdminTable]; --Admin Table INSERT INTO @Admin VALUES ( 'bbm' ,'UmsatzTrend für Jahr ' + FORMAT(@year, '0000') ,'UmsatzTrend für Jahr ' + FORMAT(@year, '0000') ,'' + FORMAT(GETDATE(), 'yyyy-MM-dd HH:mm') ,'' ,'chart' --typ , '{ "charttype": "line", "x1_label_angle": -90, "color": "e0301e", "linewidth": 2, "valuelabels": false, "marker": "none", "colorpalette": "00B050;00B050;00B050", "x1_column": "date", "y1_column": "Value", "y1_title": "Actuals", "x1_title": "", "series_column": "series", "legend_position": "bottom", "show_datalabel": true, "datalabelfontsizescale": 0.6, "height": 600, "width": 1200, "x1_labelformat": "ddd, dd/MM"}' --settings , '' , 0) SELECT * FROM @Admin; with inv as( select [InvoiceBalance] = SUM( ISNULL(_i.[InvoiceBalance],0) ) ,[Dateofcreation] = CAST([Dateofcreation] as date) ,[seq] = ROW_NUMBER() OVER (ORDER BY CAST([Dateofcreation] as date)) FROM [dbo].[mfr__reports] as _i where _i.IsInvoice = 1 and YEAR([Dateofcreation]) = @year GROUP BY CAST([Dateofcreation] as date) UNION select [InvoiceBalance] = SUM( ISNULL(_i.[InvoiceBalance],0) ) ,[Dateofcreation] = CAST([Datecreated] as date) ,[seq] = ROW_NUMBER() OVER (ORDER BY CAST([Datecreated] as date)) FROM [dbo].[fds__invoices] as _i where _i.IsFinal = 1 and YEAR([Datecreated]) = @year GROUP BY CAST([Datecreated] as date) ) SELECT --[Monat] = FORMAT( inv.[Dateofcreation], 'yyyy - MM', 'de') --,[Umsatz] = FORMAT( ISNULL(inv.[InvoiceBalance],0) , '#0.00', 'de') [series] = 'Umsatz' ,[date] = CAST(inv.[Dateofcreation] as date) ,[value] = CAST( SUM( ISNULL(inv.[InvoiceBalance],0) ) OVER (ORDER BY [seq]) as numeric(9,2)) FROM inv ORDER BY [seq] END GO /****** Object: StoredProcedure [dbo].[fds__remInvoice] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__remInvoice] @Id varchar(8), @authuser varchar(25) AS BEGIN SET NOCOUNT ON; DELETE FROM [dbo].[fds__invoices] WHERE [Id] = @Id AND @Id is not null AND [isFinal] = 0 AND [IsSent] = 0; END GO /****** Object: StoredProcedure [dbo].[fds__setInvoiceFile] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__setInvoiceFile] @Id varchar(8), @file varbinary(max) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); UPDATE [dbo].[fds__invoices] SET [file] = @file, [version] = (ISNULL([version],0) + 1), [DocumentName] = ([dbo].[fds__fn_DocumentName]([InvoiceId],[InvoiceType],[InvoiceTitle],[DateFinalized])) OUTPUT inserted.[Id] WHERE [Id] = @Id AND @Id is not null and [file] is null; END GO /****** Object: StoredProcedure [dbo].[fds__setInvoiceFinal] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__setInvoiceFinal] @Id varchar(8), @authuser varchar(25) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); DECLARE @ids as TABLE([Id] varchar(10)); UPDATE [dbo].[fds__invoices] SET [DateFinalized] = @now, [UserFinalized] = @authuser, [DateModified] = @now, [UserModified] = @authuser, [invoiceid] = [dbo].[fds__newInvoiceId](Year(@now)), [version] = (ISNULL([version],0) + 1) OUTPUT inserted.[id] INTO @ids WHERE [Id] = @Id AND @Id is not null and [isFinal] = 0 and [isSent] = 0; SELECT iv.* FROM [dbo].[fds__invoices] as iv JOIN @ids as ids on iv.[id] = ids.Id; --this is necessary to get calculated fields also END GO /****** Object: StoredProcedure [dbo].[fds__setInvoiceSent] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__setInvoiceSent] @Id varchar(8), @authuser varchar(25) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); UPDATE [dbo].[fds__invoices] SET [IsSent] = 1, [DateSent] = @now, [version] = (ISNULL([version],0) + 1) OUTPUT inserted.* WHERE [Id] = @Id AND @Id is not null and [isFinal] = 1 and [isSent] = 0; END GO /****** Object: StoredProcedure [dbo].[fds__setReportVAT] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__setReportVAT] @id bigint ,@entitytype varchar(50) ,@vat numeric(5,2) ,@authuser varchar(100) AS BEGIN SET NOCOUNT ON; MERGE [dbo].[fds__custom_vat] as TARGET USING (VALUES(@entitytype, @id, @vat)) as SOURCE ([EntityType],[EntityID],[VAT]) ON TARGET.[EntityType] = SOURCE.[EntityType] AND TARGET.[EntityID] = SOURCE.[EntityID] WHEN MATCHED THEN UPDATE SET [VAT] = SOURCE.[VAT] WHEN NOT MATCHED THEN INSERT ([EntityType],[EntityID],[VAT]) VALUES (SOURCE.[EntityType],SOURCE.[EntityID],SOURCE.[VAT]) ; END GO /****** Object: StoredProcedure [dbo].[fds__setStatus] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__setStatus] @table varchar(50) ,@action varchar(50) ,@setid varchar(50) ,@info varchar(250) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); MERGE [dbo].[fds__status] as TARGET USING (VALUES(@table, @action, @now,@setid)) as src ([table],[action],[timestamp],[setid]) ON TARGET.[table] = src.[table] and TARGET.[action] = src.[action] WHEN MATCHED THEN UPDATE SET [timestamp] = src.[timestamp], [setid] = src.[setid] WHEN NOT MATCHED BY TARGET THEN INSERT ([table],[action],[timestamp],[setid]) VALUES (src.[table],src.[action],src.[timestamp],src.[setid]); INSERT INTO [dbo].[fds__log]([table],[action],[timestamp],[setid], [info]) VALUES (@table,@action,@now,@setid,@info); END GO /****** Object: StoredProcedure [dbo].[fds__toggleRequestHidden] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fds__toggleRequestHidden] @Id bigint, @authuser varchar(25) AS BEGIN SET NOCOUNT ON; MERGE [dbo].[fds__custom_servicerequest] as TARGET USING (SELECT [id] FROM [mfr__servicerequests] as sr where [id] = @id) as SOURCE ([id]) ON TARGET.[EntityId] = SOURCE.[Id] WHEN MATCHED THEN UPDATE SET [hidden] = CASE WHEN TARGET.[hidden] = 1 THEN 0 ELSE 1 END WHEN NOT MATCHED BY TARGET THEN INSERT ([EntityId] ,[hidden]) VALUES (SOURCE.[Id] ,1) OUTPUT inserted.*; END GO /****** Object: StoredProcedure [dbo].[fis_admin_addGroupMember] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_addGroupMember] @authaccount varchar(5) ,@usergroup_id varchar(5) ,@useraccount_id varchar(5) AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); IF NOT EXISTS (SELECT * FROM [dbo].[fis_usergroups_members] WHERE [usergroup_id] = @usergroup_id AND [useraccount_id] = @useraccount_id and [DateDeleted] is null) BEGIN INSERT INTO [dbo].[fis_usergroups_members] ([usergroup_id] ,[useraccount_id] ,[UserCreated] ,[DateCreated] ,[UserDeleted] ,[DateDeleted]) VALUES (@usergroup_id ,@useraccount_id ,@authaccount ,@utcnow ,NULL ,NULL); END SELECT CAST((CASE WHEN EXISTS (SELECT * FROM [dbo].[fis_usergroups_members] WHERE [usergroup_id] = @usergroup_id AND [useraccount_id] = @useraccount_id and [DateDeleted] is null) THEN 1 ELSE 0 END) as bit); END GO /****** Object: StoredProcedure [dbo].[fis_admin_createUserAccount] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_createUserAccount] @name nvarchar(100) ,@firstname nvarchar(100) ,@title varchar(50) ,@gender varchar(1) ,@email varchar(255) ,@mobile varchar(50) ,@password nvarchar(20) ,@enc_key uniqueidentifier AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); INSERT INTO [dbo].[fis_useraccounts] ([useraccount_id] ,[name_enc] ,[firstname_enc] ,[title_enc] ,[gender_enc] ,[email_enc] ,[mobile_enc] ,[password_enc] ,[UserDisabled] ,[DateDisabled] ,[UserCreated] ,[DateCreated] ,[UserModified] ,[DateModified] ,[UserDeleted] ,[DateDeleted]) OUTPUT inserted.[useraccount_id] VALUES ([dbo].[fis_fn_useraccount_id] () ,ENCRYPTBYKEY(@enc_key, @name) ,ENCRYPTBYKEY(@enc_key, @firstname) ,ENCRYPTBYKEY(@enc_key, @title) ,ENCRYPTBYKEY(@enc_key, @gender) ,ENCRYPTBYKEY(@enc_key, @email) ,ENCRYPTBYKEY(@enc_key, @mobile) ,CASE WHEN @password is null then ENCRYPTBYKEY(@enc_key, CAST([dbo].[ocms_fn_generatePassword] (8, 0, 1, 1) AS nvarchar(20))) ELSE ENCRYPTBYKEY(@enc_key, @password) END ,NULL --[UserDisabled] ,NULL --[DateDisabled] ,'sa' ,@utcnow ,'sa' ,@utcnow ,NULL ,NULL); END GO /****** Object: StoredProcedure [dbo].[fis_admin_debug] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_debug] @machine varchar(50) ,@type varchar(10) ,@url varchar(255) ,@uniquekey varchar(5) ,@authuser varchar(5) ,@query varchar(max) ,@form_content nvarchar(max) ,@server_variables varchar(max) ,@cookies varchar(max) ,@authcookie varchar(max) ,@files varchar(max) ,@isdebug bit AS BEGIN SET NOCOUNT ON; INSERT INTO [dbo].[fis_admin_debuglog] ([machine] ,[type] ,[url] ,[uniquekey] ,[authuser] ,[query] ,[form / content] ,[server_variables] ,[cookies] ,[authcookie] ,[files] ,[isdebug] ,[timestamp]) VALUES (@machine ,@type ,@url ,@uniquekey ,@authuser ,@query ,@form_content ,@server_variables ,@cookies ,@authcookie ,@files ,@isdebug ,GETUTCDATE() ); END GO /****** Object: StoredProcedure [dbo].[fis_admin_delUserAccount] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_delUserAccount] @authaccount varchar(5) ,@useraccount_id varchar(5) AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); IF EXISTS (SELECT * FROM [dbo].[fis_useraccounts] WHERE [useraccount_id] = @useraccount_id and [DateDeleted] is null) BEGIN UPDATE [dbo].[fis_useraccounts] SET [UserDeleted] = @authaccount ,[DateDeleted] = @utcnow WHERE [useraccount_id] = @useraccount_id; END SELECT CAST((CASE WHEN NOT EXISTS (SELECT * FROM [dbo].[fis_useraccounts] WHERE [useraccount_id] = @useraccount_id and [DateDeleted] is null) THEN 1 ELSE 0 END) as bit); END GO /****** Object: StoredProcedure [dbo].[fis_admin_delUserGroup] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_delUserGroup] @authaccount varchar(5) ,@usergroup_id varchar(5) AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); IF EXISTS (SELECT * FROM [dbo].[fis_usergroups] WHERE [usergroup_id] = @usergroup_id and [DateDeleted] is null) BEGIN UPDATE [dbo].[fis_usergroups] SET [UserDeleted] = @authaccount ,[DateDeleted] = @utcnow WHERE [usergroup_id] = @usergroup_id; END SELECT CAST((CASE WHEN NOT EXISTS (SELECT * FROM [dbo].[fis_usergroups] WHERE [usergroup_id] = @usergroup_id and [DateDeleted] is null) THEN 1 ELSE 0 END) as bit); END GO /****** Object: StoredProcedure [dbo].[fis_admin_remGroupMember] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_remGroupMember] @authaccount varchar(5) ,@usergroup_id varchar(5) ,@useraccount_id varchar(5) AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); IF EXISTS (SELECT * FROM [dbo].[fis_usergroups_members] WHERE [usergroup_id] = @usergroup_id AND [useraccount_id] = @useraccount_id and [DateDeleted] is null) BEGIN UPDATE [dbo].[fis_usergroups_members] SET [UserDeleted] = @authaccount ,[DateDeleted] = @utcnow WHERE [usergroup_id] = @usergroup_id AND [useraccount_id] = @useraccount_id; END SELECT CAST((CASE WHEN NOT EXISTS (SELECT * FROM [dbo].[fis_usergroups_members] WHERE [usergroup_id] = @usergroup_id AND [useraccount_id] = @useraccount_id and [DateDeleted] is null) THEN 1 ELSE 0 END) as bit); END GO /****** Object: StoredProcedure [dbo].[fis_admin_resetUserPassword] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_resetUserPassword] @authaccount varchar(5) ,@useraccount_id varchar(5) ,@enc_key uniqueidentifier AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount); DECLARE @newpassword nvarchar(20) = [dbo].[ocms_fn_generatePassword] (8, 0, 1, 1); IF @auth > 1 OR @authaccount = @useraccount_id BEGIN UPDATE [dbo].[fis_useraccounts] SET [password_enc] = ENCRYPTBYKEY(@enc_key, @newpassword) , [DateModified] = GETUTCDATE() , [UserModified] = @authaccount WHERE [useraccount_id] = @useraccount_id AND [dateDeleted] is null; SELECT CAST(CASE WHEN DECRYPTBYKEY((SELECT TOP(1) [password_enc] FROM [dbo].[fis_useraccounts] WHERE [useraccount_id] = @useraccount_id)) = @newpassword THEN 1 ELSE 0 END as bit); END END GO /****** Object: StoredProcedure [dbo].[fis_admin_setUserAccount] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_setUserAccount] @authaccount varchar(5) ,@useraccount_id varchar(5) ,@name nvarchar(100) ,@firstname nvarchar(100) ,@title varchar(50) ,@gender varchar(1) ,@email varchar(255) ,@mobile varchar(50) ,@password nvarchar(20) ,@enc_key uniqueidentifier AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount); DECLARE @createdID as TABLE ([id] varchar(5)); IF @auth > 1 BEGIN IF EXISTS (SELECT * FROM [dbo].[fis_useraccounts] WHERE [DateDeleted] is null AND [useraccount_id] <> ISNULL(@useraccount_id, '') AND ISNULL(@email,'') <> '' AND LTRIM(RTRIM(DECRYPTBYKEY([email_enc]))) like LTRIM(RTRIM(@email))) THROW 60001, 'email is already assigned to another account', 1; MERGE [dbo].[fis_useraccounts] as TARGET USING (VALUES( ISNULL(@useraccount_id, [dbo].[fis_fn_useraccount_id] ()) ,ENCRYPTBYKEY(@enc_key, LTRIM(RTRIM(@name))) ,ENCRYPTBYKEY(@enc_key, LTRIM(RTRIM(@firstname))) ,ENCRYPTBYKEY(@enc_key, LTRIM(RTRIM(@title))) ,ENCRYPTBYKEY(@enc_key, LOWER(@gender)) ,ENCRYPTBYKEY(@enc_key, LTRIM(RTRIM(LOWER(@email)))) ,ENCRYPTBYKEY(@enc_key, LTRIM(RTRIM(@mobile))) )) as SOURCE([useraccount_id] ,[name_enc] ,[firstname_enc] ,[title_enc] ,[gender_enc] ,[email_enc] ,[mobile_enc]) ON TARGET.[useraccount_id] = SOURCE.[useraccount_id] WHEN MATCHED THEN UPDATE SET TARGET.[name_enc] = ISNULL(SOURCE.[name_enc],TARGET.[name_enc]) ,TARGET.[firstname_enc] = ISNULL(SOURCE.[firstname_enc],TARGET.[firstname_enc]) ,TARGET.[title_enc] = SOURCE.[title_enc] ,TARGET.[gender_enc] = SOURCE.[gender_enc] ,TARGET.[email_enc] = ISNULL(SOURCE.[email_enc],TARGET.[email_enc]) ,TARGET.[mobile_enc] = SOURCE.[mobile_enc] ,TARGET.[UserModified] = @authaccount ,TARGET.[DateModified] = @utcnow WHEN NOT MATCHED BY TARGET THEN INSERT ([useraccount_id] ,[name_enc] ,[firstname_enc] ,[title_enc] ,[gender_enc] ,[email_enc] ,[mobile_enc] ,[password_enc] ,[UserDisabled] ,[DateDisabled] ,[UserCreated] ,[DateCreated] ,[UserModified] ,[DateModified] ,[UserDeleted] ,[DateDeleted]) VALUES (SOURCE.[useraccount_id] ,SOURCE.[name_enc] ,SOURCE.[firstname_enc] ,SOURCE.[title_enc] ,SOURCE.[gender_enc] ,SOURCE.[email_enc] ,SOURCE.[mobile_enc] ,CASE WHEN @password is null then ENCRYPTBYKEY(@enc_key, CAST([dbo].[ocms_fn_generatePassword] (8, 0, 1, 1) AS nvarchar(20))) ELSE ENCRYPTBYKEY(@enc_key, @password) END ,NULL --[UserDisabled] ,NULL --[DateDisabled] ,@authaccount ,@utcnow ,@authaccount ,@utcnow ,NULL ,NULL) OUTPUT inserted.[useraccount_id] INTO @createdID; SELECT TOP(1) * FROM [dbo].[fis_admin_getUserAccountList](@authaccount, @useraccount_id, null, null) ual JOIN @createdID as id on ual.[useraccount_id] = id.[id]; END END GO /****** Object: StoredProcedure [dbo].[fis_admin_setUserAccount_activeStatus] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_setUserAccount_activeStatus] @authaccount varchar(5) ,@useraccount_id varchar(5) ,@activestatus bit AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); IF @activestatus = 1 AND EXISTS (SELECT * FROM [dbo].[fis_useraccounts] WHERE [useraccount_id] = @useraccount_id and [DateDeleted] is null AND [DateDisabled] is NOT NULL) BEGIN UPDATE [dbo].[fis_useraccounts] SET [UserDisabled] = NULL ,[DateDisabled] = NULL ,[UserModified] = @authaccount ,[DateModified] = @utcnow WHERE [useraccount_id] = @useraccount_id; END ELSE IF @activestatus = 0 AND EXISTS (SELECT * FROM [dbo].[fis_useraccounts] WHERE [useraccount_id] = @useraccount_id and [DateDeleted] is null AND [DateDisabled] is NULL) BEGIN UPDATE [dbo].[fis_useraccounts] SET [UserDisabled] = @authaccount ,[DateDisabled] = @utcnow ,[UserModified] = @authaccount ,[DateModified] = @utcnow WHERE [useraccount_id] = @useraccount_id; END SELECT CAST((CASE WHEN @activestatus = 1 AND EXISTS (SELECT * FROM [dbo].[fis_useraccounts] WHERE [useraccount_id] = @useraccount_id and [DateDeleted] is null AND [DateDisabled] IS NULL) THEN 1 WHEN @activestatus = 0 AND EXISTS (SELECT * FROM [dbo].[fis_useraccounts] WHERE [useraccount_id] = @useraccount_id and [DateDeleted] is null AND [DateDisabled] IS NOT NULL) THEN 1 ELSE 0 END) as bit); END GO /****** Object: StoredProcedure [dbo].[fis_admin_setUserGroup] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fis_admin_setUserGroup] @authaccount varchar(5) ,@usergroup_id varchar(5) ,@name nvarchar(255) ,@enc_key uniqueidentifier AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); DECLARE @auth smallint = [dbo].[fis_admin_getUserAuth](@authaccount); DECLARE @createdID as TABLE ([id] varchar(5)); IF @auth > 1 BEGIN MERGE [dbo].[fis_usergroups] as TARGET USING (VALUES( ISNULL(@usergroup_id, [dbo].[fis_fn_id] ('fis_usergroups')) ,ENCRYPTBYKEY(@enc_key, @name) )) as SOURCE([usergroup_id],[name_enc]) ON TARGET.[usergroup_id] = SOURCE.[usergroup_id] WHEN MATCHED THEN UPDATE SET TARGET.[name_enc] = SOURCE.[name_enc] ,TARGET.[UserModified] = @authaccount ,TARGET.[DateModified] = @utcnow WHEN NOT MATCHED BY TARGET THEN INSERT ([usergroup_id] ,[name_enc] ,[UserCreated] ,[DateCreated] ,[UserModified] ,[DateModified] ,[UserDeleted] ,[DateDeleted]) VALUES (SOURCE.[usergroup_id] ,SOURCE.[name_enc] ,@authaccount ,@utcnow ,@authaccount ,@utcnow ,NULL ,NULL) OUTPUT inserted.[usergroup_id] INTO @createdID; SELECT TOP(1) * FROM [dbo].[fis_admin_getUserGroupList](@authaccount, @usergroup_id) ual JOIN @createdID as id on ual.[usergroup_id] = id.[id]; END END GO /****** Object: StoredProcedure [dbo].[fuchs_planner_getNext] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fuchs_planner_getNext] @planner tinyint ,@session varchar(10) ,@group_code varchar(10) ,@values varchar(4000) AS BEGIN SET NOCOUNT ON; DECLARE @GROUPS TABLE ( [sessionid] varchar(5) ,[group_id] int ,[code] varchar(10) ,[planner_id] tinyint ,[sequence_order] tinyint ,[parent_codes] varchar(50) ,[condition] varchar(50) ,[shortname] varchar(15) ,[name] varchar(100) ,[description] varchar(max) ,[selection_type] varchar(10) ,[final] bit ,[hide] bit ,[values] varchar(4000) ,[level] tinyint ,[grouporder] tinyint ); SET @session = ISNULL(@session, (SELECT TOP(1) [s] FROM [dbo].[ott_20_randomstrings](5) as rs WHERE NOT EXISTS (SELECT * FROM [fuchs_planner_traffic] as t WHERE t.[sessionid] = rs.[s]))); INSERT INTO [dbo].[fuchs_planner_traffic] ([planner_id], [sessionid],[group_code],[values]) VALUES(@planner, @session, @group_code, ISNULL(@values, '')); with traffic as (SELECT *, CAST(CASE WHEN ROW_NUMBER() OVER (PARTITION BY t.[sessionid],t.[group_code] ORDER BY t.[DateSubmitted] DESC) = 1 THEN 1 ELSE 0 END as bit) as 'last' FROM [dbo].[fuchs_planner_traffic] as t WHERE t.[sessionid] = @session and t.[planner_id] = @planner) , plannergroups as (SELECT * FROM [dbo].[fuchs_planner_groups] where [planner_id] = @planner UNION SELECT * FROM (VALUES ( -1 ,'contact' ,@planner ,255 ,'*' ,NULL ,'contact_form' ,'Ihre Kontaktdaten' ,'

Bitte nennen Sie uns Ihre Kontaktdaten, so dass wir Sie kontaktieren können.

' ,'contact' ,1 ,0 ) ) as cf ( [group_id] ,[code] ,[planner_id] ,[sequence_order] ,[parent_codes] ,[condition] ,[shortname] ,[name] ,[description] ,[selection_type] ,[final] ,[hide] ) ) , vals as (SELECT * FROM traffic WHERE [last] = 1) , g as (select plannergroups.* , ISNULL(vals.[values],'') as 'values' , ROW_NUMBER() OVER (PARTITION BY plannergroups.[parent_codes] ORDER BY [sequence_order]) AS 'groupfactor' FROM plannergroups left join vals ON plannergroups.[code] = vals.[group_code] where plannergroups.hide = 0) , cte as ( SELECT @session as [session], g.*, Cast([sequence_order] as tinyint) as [level] , CAST(0 as bit) as [exclude] , CAST(CASE WHEN [group_id] = -1 THEN POWER(10,7) ELSE 0 END as int) as 'roworder' /* contact form is always last */ FROM g WHERE g.[sequence_order] = 0 OR g.group_id = -1 UNION ALL SELECT @session as [session], g.*, Cast(cte.[level] + 1 as tinyint) as [level] , CAST(CASE WHEN cte.[exclude] = 1 THEN 1 WHEN ISNULL(g.[condition], '') in ('', '{}') THEN 0 WHEN EXISTS (SELECT * FROM g as gv JOIN [dbo].[fuchs_planner_options] as o ON gv.[group_id] = o.[group_id] and o.[option_type] in ('a','c','o') AND [dbo].[ott_jcsv_contains](gv.code, gv.[values], o.[code]) = 1 WHERE [dbo].[ott_csv_contains](g.[condition], o.[code]) = 1 ) THEN 0 ELSE 1 END as bit) as [exclude] , cte.[roworder] + Cast(g.[groupfactor] as int) * CAST(POWER(10,4-cte.[level]) as int) as 'roworder' /* by this, the children have a lower number than the following on same level */ FROM g JOIN cte on g.[sequence_order] > cte.[sequence_order] AND cte.group_id >= 0 AND g.group_id >= 0 --not the contact form AND [dbo].[ott_csv_contains](g.[parent_codes], cte.[code]) = 1 AND cte.[final] = 0 --AND cte.[exclude] = 0 ) , f as ( select cte.* , ROW_NUMBER() OVER (ORDER BY [roworder], [sequence_order]) as 'grouporder' FROM cte where exclude = 0 ) , this as (SELECT TOP(1) * FROM f WHERE [code] = @group_code) insert into @GROUPS select TOP(1) f.[session] ,f.[group_id] ,f.[code] ,f.[planner_id] ,f.[sequence_order] ,f.[parent_codes] ,f.[condition] ,f.[shortname] ,f.[name] ,f.[description] ,f.[selection_type] ,f.[final] ,f.[hide] ,f.[values] ,f.[level] ,f.[grouporder] FROM f left join this on f.[grouporder] > this.[grouporder] WHERE NOT EXISTS (SELECT * FROM this) OR (f.grouporder > this.grouporder AND ISNULL(this.final,0) = 0) ORDER BY f.[grouporder] ASC; -- output SELECT * FROM @GROUPS; -- output SELECT o.* FROM [dbo].[fuchs_planner_options] as o JOIN @GROUPS as g on o.[planner_id] = g.[planner_id] AND o.[group_id] = g.[group_id] AND (ISNULL(o.[condition], '') = '' OR EXISTS (SELECT * FROM @GROUPS as gv WHERE [dbo].[ott_csv_contains](o.[condition], gv.[values]) = 1 ) ) END GO /****** Object: StoredProcedure [dbo].[fuchs_planner_getPrev] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fuchs_planner_getPrev] @planner tinyint ,@session varchar(10) ,@group_code varchar(10) ,@values varchar(4000) AS BEGIN SET NOCOUNT ON; DECLARE @GROUPS TABLE ( [sessionid] varchar(5) ,[group_id] int ,[code] varchar(10) ,[planner_id] tinyint ,[sequence_order] tinyint ,[parent_codes] varchar(50) ,[condition] varchar(50) ,[shortname] varchar(15) ,[name] varchar(100) ,[description] varchar(max) ,[selection_type] varchar(10) ,[final] bit ,[hide] bit ,[values] varchar(4000) ,[level] tinyint ,[grouporder] tinyint ); SET @session = ISNULL(@session, (SELECT TOP(1) [s] FROM [dbo].[ott_20_randomstrings](5) as rs WHERE NOT EXISTS (SELECT * FROM [fuchs_planner_traffic] as t WHERE t.[sessionid] = rs.[s]))); INSERT INTO [dbo].[fuchs_planner_traffic] ([planner_id], [sessionid],[group_code],[values]) VALUES(@planner, @session, @group_code, ISNULL(@values, '')); with traffic as (SELECT *, CAST(CASE WHEN ROW_NUMBER() OVER (PARTITION BY t.[sessionid],t.[group_code] ORDER BY t.[DateSubmitted] DESC) = 1 THEN 1 ELSE 0 END as bit) as 'last' FROM [dbo].[fuchs_planner_traffic] as t WHERE t.[sessionid] = @session and t.[planner_id] = @planner) , plannergroups as (SELECT * FROM [dbo].[fuchs_planner_groups] where [planner_id] = @planner UNION SELECT * FROM (VALUES ( -1 ,'contact' ,@planner ,255 ,'*' ,NULL ,'contact_form' ,'Ihre Kontaktdaten' ,'

Bitte nennen Sie uns Ihre Kontaktdaten, so dass wir Sie kontaktieren können.

' ,'contact' ,1 ,0 ) ) as cf ( [group_id] ,[code] ,[planner_id] ,[sequence_order] ,[parent_codes] ,[condition] ,[shortname] ,[name] ,[description] ,[selection_type] ,[final] ,[hide] ) ) , vals as (SELECT * FROM traffic WHERE [last] = 1) , g as (select plannergroups.* , ISNULL(vals.[values],'') as 'values' , ROW_NUMBER() OVER (PARTITION BY plannergroups.[parent_codes] ORDER BY [sequence_order]) AS 'groupfactor' FROM plannergroups left join vals ON plannergroups.[code] = vals.[group_code] where plannergroups.hide = 0) , cte as ( SELECT @session as [session], g.*, Cast([sequence_order] as tinyint) as [level] , CAST(0 as bit) as [exclude] , CAST(CASE WHEN [group_id] = -1 THEN POWER(10,7) ELSE 0 END as int) as 'roworder' /* contact form is always last */ FROM g WHERE g.[sequence_order] = 0 OR g.group_id = -1 UNION ALL SELECT @session as [session], g.*, Cast(cte.[level] + 1 as tinyint) as [level] , CAST(CASE WHEN cte.[exclude] = 1 THEN 1 WHEN ISNULL(g.[condition], '') in ('', '{}') THEN 0 WHEN EXISTS (SELECT * FROM g as gv JOIN [dbo].[fuchs_planner_options] as o ON gv.[group_id] = o.[group_id] and o.[option_type] in ('a','c','o') AND [dbo].[ott_jcsv_contains](gv.code, gv.[values], o.[code]) = 1 WHERE [dbo].[ott_csv_contains](g.[condition], o.[code]) = 1 ) THEN 0 ELSE 1 END as bit) as [exclude] , cte.[roworder] + Cast(g.[groupfactor] as int) * CAST(POWER(10,4-cte.[level]) as int) as 'roworder' /* by this, the children have a lower number than the following on same level */ FROM g JOIN cte on g.[sequence_order] > cte.[sequence_order] AND cte.group_id >= 0 AND g.group_id >= 0 --not the contact form AND [dbo].[ott_csv_contains](g.[parent_codes], cte.[code]) = 1 AND cte.[final] = 0 --AND cte.[exclude] = 0 ) , f as ( select cte.* , ROW_NUMBER() OVER (ORDER BY [roworder], [sequence_order]) as 'grouporder' FROM cte where exclude = 0 ) , this as (SELECT TOP(1) * FROM f WHERE [code] = @group_code) insert into @GROUPS select TOP(1) f.[session] ,f.[group_id] ,f.[code] ,f.[planner_id] ,f.[sequence_order] ,f.[parent_codes] ,f.[condition] ,f.[shortname] ,f.[name] ,f.[description] ,f.[selection_type] ,f.[final] ,f.[hide] ,f.[values] ,f.[level] ,f.[grouporder] FROM f left join this on f.[grouporder] < this.[grouporder] --lower than WHERE NOT EXISTS (SELECT * FROM this) OR f.grouporder < this.grouporder OR f.grouporder = 0 /* =0 to at least have the first page returned */ ORDER BY f.[grouporder] DESC; -- DESCending is important -- output SELECT * FROM @GROUPS; -- output SELECT o.* FROM [dbo].[fuchs_planner_options] as o JOIN @GROUPS as g on o.[planner_id] = g.[planner_id] AND o.[group_id] = g.[group_id] AND (ISNULL(o.[condition], '') = '' OR EXISTS (SELECT * FROM @GROUPS as gv WHERE [dbo].[ott_csv_contains](o.[condition], gv.[values]) = 1 ) ) END GO /****** Object: StoredProcedure [dbo].[fuchs_planner_getSummary] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fuchs_planner_getSummary] @planner tinyint ,@session varchar(10) AS BEGIN SET NOCOUNT ON; DECLARE @GROUPS TABLE ( [sessionid] varchar(5) ,[group_id] int ,[code] varchar(10) ,[planner_id] tinyint ,[sequence_order] tinyint ,[parent_codes] varchar(50) ,[condition] varchar(50) ,[shortname] varchar(15) ,[name] varchar(100) ,[description] varchar(max) ,[selection_type] varchar(10) ,[final] bit ,[hide] bit ,[values] varchar(4000) ,[level] tinyint ,[grouporder] tinyint ); IF ISNULL(@session, '') <> '' BEGIN with traffic as (SELECT *, CAST(CASE WHEN ROW_NUMBER() OVER (PARTITION BY t.[sessionid],t.[group_code] ORDER BY t.[DateSubmitted] DESC) = 1 THEN 1 ELSE 0 END as bit) as 'last' FROM [dbo].[fuchs_planner_traffic] as t WHERE t.[sessionid] = @session and t.[planner_id] = @planner) , plannergroups as (SELECT * FROM [dbo].[fuchs_planner_groups] where [planner_id] = @planner UNION SELECT * FROM (VALUES ( -1 ,'contact' ,@planner ,255 ,'*' ,NULL ,'contact_form' ,'Ihre Kontaktdaten' ,'

Bitte nennen Sie uns Ihre Kontaktdaten, so dass wir Sie kontaktieren können.

' ,'contact' ,1 ,0 ) ) as cf ( [group_id] ,[code] ,[planner_id] ,[sequence_order] ,[parent_codes] ,[condition] ,[shortname] ,[name] ,[description] ,[selection_type] ,[final] ,[hide] ) ) , vals as (SELECT * FROM traffic WHERE [last] = 1) , g as (select plannergroups.* , ISNULL(vals.[values],'') as 'values' , ROW_NUMBER() OVER (PARTITION BY plannergroups.[parent_codes] ORDER BY [sequence_order]) AS 'groupfactor' FROM plannergroups left join vals ON plannergroups.[code] = vals.[group_code] where plannergroups.hide = 0) , cte as ( SELECT @session as [session], g.*, Cast([sequence_order] as tinyint) as [level] , CAST(0 as bit) as [exclude] , CAST(CASE WHEN [group_id] = -1 THEN POWER(10,7) ELSE 0 END as int) as 'roworder' /* contact form is always last */ FROM g WHERE g.[sequence_order] = 0 OR g.group_id = -1 UNION ALL SELECT @session as [session], g.*, Cast(cte.[level] + 1 as tinyint) as [level] , CAST(CASE WHEN cte.[exclude] = 1 THEN 1 WHEN ISNULL(g.[condition], '') in ('', '{}') THEN 0 WHEN EXISTS (SELECT * FROM g as gv JOIN [dbo].[fuchs_planner_options] as o ON gv.[group_id] = o.[group_id] and o.[option_type] in ('a','c','o') AND [dbo].[ott_jcsv_contains](gv.code, gv.[values], o.[code]) = 1 WHERE [dbo].[ott_csv_contains](g.[condition], o.[code]) = 1 ) THEN 0 ELSE 1 END as bit) as [exclude] , cte.[roworder] + Cast(g.[groupfactor] as int) * CAST(POWER(10,4-cte.[level]) as int) as 'roworder' /* by this, the children have a lower number than the following on same level */ FROM g JOIN cte on g.[sequence_order] > cte.[sequence_order] AND cte.group_id >= 0 AND g.group_id >= 0 --not the contact form AND [dbo].[ott_csv_contains](g.[parent_codes], cte.[code]) = 1 AND cte.[final] = 0 --AND cte.[exclude] = 0 ) , f as ( select cte.* , ROW_NUMBER() OVER (ORDER BY [roworder], [sequence_order]) as 'grouporder' FROM cte where exclude = 0 ) insert into @GROUPS select f.[session] ,f.[group_id] ,f.[code] ,f.[planner_id] ,f.[sequence_order] ,f.[parent_codes] ,f.[condition] ,f.[shortname] ,f.[name] ,f.[description] ,f.[selection_type] ,f.[final] ,f.[hide] ,f.[values] ,f.[level] ,f.[grouporder] FROM f ORDER BY f.[grouporder] ASC; -- output SELECT g.[group_id] ,g.[shortname] ,g.[code] ,g.[name] --,[dbo].[ott_jcontent](g.[code],g.[values]) as 'values' , g.[values] ,g.[grouporder] ,g.[selection_type] FROM @GROUPS as g; -- output SELECT o.* ,ISNULL([dbo].[ott_jcontent](o.[code],g.[values]), '') FROM [dbo].[fuchs_planner_options] as o JOIN @GROUPS as g on o.[planner_id] = g.[planner_id] AND o.[group_id] = g.[group_id] AND (ISNULL(o.[condition], '') = '' OR EXISTS (SELECT * FROM @GROUPS as gv WHERE [dbo].[ott_csv_contains](o.[condition], gv.[values]) = 1 ) ) WHERE (CASE WHEN [dbo].[ott_jcsv_contains](g.[code],g.[values],o.[code]) = 1 THEN 1 WHEN [dbo].[ott_jcsv_containskey](o.[code], g.[values]) =1 THEN 1 ELSE 0 END) = 1 or 1= 1 --OR ISNULL([dbo].[ott_jcontent](o.[code],g.[values]), '') <> '' END END GO /****** Object: StoredProcedure [dbo].[fuchs_planner_submit] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[fuchs_planner_submit] @planner tinyint ,@session varchar(10) ,@group_code varchar(10) ,@values varchar(4000) AS BEGIN SET NOCOUNT ON; SET @session = ISNULL(@session, (SELECT TOP(1) [s] FROM [dbo].[ott_20_randomstrings](5) as rs WHERE NOT EXISTS (SELECT * FROM [fuchs_planner_traffic] as t WHERE t.[sessionid] = rs.[s]))); INSERT INTO [dbo].[fuchs_planner_traffic] ([planner_id], [sessionid],[group_code],[values]) VALUES(@planner, @session, @group_code, ISNULL(@values, '')); END GO /****** Object: StoredProcedure [dbo].[mfr__getSchema] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__getSchema] @info varchar(25) ,@tgttype varchar(50) AS BEGIN SET NOCOUNT ON; DECLARe @AS XML = [dbo].[mfr__schema](); IF @info = 'table' BEGIN DECLARE @AssociationSets TABLE([#] int, [name] varchar(255), [set] varchar(255), [Association] varchar(255), [role1] varchar(255), [role2] varchar(255), [set1] varchar(255), [set2] varchar(255), [arole1] varchar(255), [arole2] varchar(255), [multi1] varchar(255), [multi2] varchar(255), [tablename] varchar(255)); DECLARE @ComplexProps TABLE([#] int, [Type] varchar(255), [typ] varchar(50), [name] varchar(255), [EntityType] varchar(255), [tablename] varchar(255)); DECLARE @NavigationProps TABLE([#] int, [Type] varchar(255), [typ] varchar(50), [name] varchar(255), [ToRole] varchar(255), [FromRole] varchar(255), [countertype] varchar(255), [counterset] varchar(255), [tablename] varchar(255), [countertable] varchar(255), [Association] varchar(255)); DECLARE @EntityTypes TABLE([#] int, [typ] varchar(50), [name] varchar(255), [set] varchar(255), [EntitySet] varchar(255), [tablename] varchar(255), [url] varchar(500), [DateColumn] varchar(25)); WITH XMLNAMESPACES ( 'http://schemas.microsoft.com/ado/2007/06/edmx' as edmx, 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' as m ) , x as ( SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) as '#' , xD.value('@Name', 'varchar(255)') as 'set' , xD.value('@Association', 'varchar(255)') as 'association' , xD.value('End[1]/@Role', 'varchar(255)') as 'role1' , xD.value('End[2]/@Role', 'varchar(255)') as 'role2' , LOWER(xD.value('End[1]/@EntitySet', 'varchar(255)')) as 'set1' , LOWER(xD.value('End[2]/@EntitySet', 'varchar(255)')) as 'set2' --, xD.query('.') as 'q' from @as.nodes('/Schema/EntityContainer/AssociationSet') as xm(xD) ) , y as ( SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) as '#' , xD.value('@Name', 'varchar(255)') as 'association' , xD.value('End[1]/@Role', 'varchar(255)') as 'arole1' , xD.value('End[2]/@Role', 'varchar(255)') as 'arole2' , xD.value('End[1]/@Multiplicity', 'varchar(255)') as 'multi1' , xD.value('End[2]/@Multiplicity', 'varchar(255)') as 'multi2' --, xD.query('.') as 'q' from @as.nodes('/Schema/Association') as xm(xD) ), z as ( select x.[#], x.[role1], x.[role2], x.[set1], x.[set2], RIGHT(x.[set],CHARINDEX('_', REVERSE(x.[set])) - 1) as [name],x.[set],x.[association], y.[arole1], y.[arole2], y.[multi1], y.[multi2] from x LEFT JOIN y on x.association like ('%[.]' + y.[association]) ) INSERT INTO @AssociationSets SELECT [#], z.[name],[set], [association],[role1],[role2], [set1], [set2] , [arole1], [arole2], [multi1], [multi2], 'mfr__*PartnerSet' as [tablename] FROM z LEFT JOIN sys.objects as o ON o.[name] like ('mfr__[*]' + (LOWER(z.[name]))); WITH XMLNAMESPACES ( 'http://schemas.microsoft.com/ado/2007/06/edmx' as edmx, 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' as m ), et as ( SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) as '#' , xD.value('local-name(.)', 'varchar(50)') as [type] , xD.value('@Name', 'varchar(255)') as [EntityType] --, xD.query('.') as 'q' , xS.value('@Name', 'varchar(255)') as [Set] , o.[name] as [tablename] from @as.nodes('/Schema[1]/EntityType') as xm(xD) JOIN @as.nodes('/Schema/EntityContainer/EntitySet') as xn(xS) ON (xS.value('@EntityType', 'varchar(255)')) like ('MFR.%[.]' + (xD.value('@Name', 'varchar(255)'))) JOIN sys.objects as o ON o.[name] like ('mfr__' + (LOWER(xS.value('@Name', 'varchar(255)')))) union SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) as '#' , xD.value('local-name(.)', 'varchar(50)') as [type] , xD.value('@Name', 'varchar(255)') as [EntityType] --, xD.query('.') as 'q' , '' as [Set] , o.[name] as [tablename] from @as.nodes('/Schema[1]/ComplexType') as xm(xD) JOIN sys.objects as o ON o.[name] like ('mfr__[#]' + (LOWER(xD.value('@Name', 'varchar(255)'))) + 's') ) INSERT INTO @EntityTypes SELECT [#],[type],[EntityType],[set] = LOWER([set]), [EntitySet] = [set], [tablename], null, null FROM et; WITH XMLNAMESPACES ( 'http://schemas.microsoft.com/ado/2007/06/edmx' as edmx, 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' as m ), np as ( SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) as '#' , xD.value('../@Name', 'varchar(255)') as [property] , xD.value('@Type', 'varchar(255)') as [nodetype] , xD.value('@Name', 'varchar(255)') as [name] from @as.nodes('/Schema[1]/EntityType/Property') as xm(xD) ) INSERT INTO @ComplexProps SELECT np.[#] , [property] , [type] = CASE WHEN [nodetype] like 'collection%' THEN 'array' ELSE '' END , np.[name] , [EntityType] = et.[name] , et.[tablename] from np LEFT JOIN @EntityTypes as et on np.[name] like (et.[name] + '%') WHERE nodetype like '%MFR[.]%'; WITH XMLNAMESPACES ( 'http://schemas.microsoft.com/ado/2007/06/edmx' as edmx, 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata' as m ), np as ( SELECT ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) as '#' , xD.value('../@Name', 'varchar(255)') as [property] , CASE WHEN a.[arole1] = xD.value('@ToRole', 'varchar(255)') AND a.[multi1] = '*' THEN 'array' WHEN a.[arole1] = xD.value('@ToRole', 'varchar(255)') AND a.[multi1] = '0..1' THEN 'ref' WHEN a.[arole2] = xD.value('@ToRole', 'varchar(255)') AND a.[multi2] = '*' THEN 'array' WHEN a.[arole2] = xD.value('@ToRole', 'varchar(255)') AND a.[multi2] = '0..1' THEN 'ref' END as [typ] , xD.value('@Name', 'varchar(255)') as [name] , xD.value('@ToRole', 'varchar(255)') as [ToRole] , xD.value('@FromRole', 'varchar(255)') as [FromRole] , CASE WHEN xD.value('@ToRole', 'varchar(255)') = a.[role2] THEN [set2] ELSE [set1] END [counterset] , a.[tablename] --xD.value('@Relationship', 'varchar(255)') as , a.[Association] -- , xD.query('.') as 'q' from @as.nodes('/Schema[1]/EntityType/NavigationProperty') as xm(xD) LEFT JOIN @AssociationSets as a on (xD.value('@Relationship', 'varchar(255)')) like a.[Association] ) INSERT INTO @NavigationProps SELECT np.[#], [property], np.[typ],np.[name],[ToRole], [FromRole],[countertype] = et.[name], [counterset],np.[tablename], [countertable] = et.tablename, [Association] = NULL from np LEFT JOIN @EntityTypes as et on np.counterset = et.[set]; UPDATE et SET [url] = [EntitySet] + CASE WHEN EXISTS (SELECT * FROM @NavigationProps as np WHERE np.[type] = et.[name]) THEN '?$expand=' + STUFF((SELECT ',' + [name] as [text()] FROM @NavigationProps as np WHERE np.[type] = et.[name] ORDER BY [#] FOR XML PATH('')),1,1, '') ELSE '' END ,[DateColumn] = (SELECT TOP(1) cols.[COLUMN_NAME] FROM INFORMATION_SCHEMA.COLUMNS as cols WHERE cols.[TABLE_NAME] = et.[tablename] AND ([COLUMN_NAME] COLLATE Latin1_General_CI_AS IN ('DateModified','DateCreated')) ORDER BY cols.[COLUMN_NAME] DESC) FROM @EntityTypes as et; SELECT * FROM @EntityTypes as et WHERE @tgttype is null or et.name = @tgttype; SELECT * FROM @ComplexProps as cp where @tgttype is null or cp.[type] = @tgttype; SELECT n.* FROM @NavigationProps as n WHERE @tgttype is null or n.[type] = @tgttype; --SELECT * FROM @AssociationSets; with tt as ( --SELECT [tablename] FROM @EntityTypes --UNION SELECT [tablename] FROM @ComplexProps as cp where @tgttype is null or cp.[type] = @tgttype UNION SELECT [tablename] FROM @NavigationProps as n WHERE @tgttype is null or n.[type] = @tgttype UNION SELECT [tablename] = [countertable] FROM @NavigationProps as n WHERE @tgttype is null or n.[type] = @tgttype ) SELECT DISTINCT [tablename] from tt where not exists(SELECT * FROM @EntityTypes as et where et.tablename = tt.[tablename] AND (@tgttype is null or et.name = @tgttype)); END ELSE IF @info = 'tabledef' BEGIN DECLARE @types TABLE ([edm] varchar(100), [sql] varchar(50)); INSERT INTO @types VALUES ('Edm.Boolean', 'bit'), ('Edm.DateTime', 'DateTime'), ('Edm.Decimal', 'decimal'), ('Edm.Double', 'float'), ('Edm.Int32', 'int'), ('Edm.Int64', 'bigint'), ('Edm.String', 'varchar(255)'); END END GO /****** Object: StoredProcedure [dbo].[mfr__updt__#locations] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__#locations] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__#locations]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM [' + @tblname + ']'; INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; WITH tmp as ( SELECT *, ROW_NUMBER() OVER (PARTITION BY [id],[Property] ORDER BY [version] DESC) as '#' FROM @tmp ), SOURCE as ( SELECT * FROM tmp WHERE [#] = 1 ) MERGE [dbo].[mfr__#locations] as TARGET USING SOURCE ON TARGET.[Id] = SOURCE.[Id] AND TARGET.[Property] = SOURCE.[Property] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[EntityId] = SOURCE.[EntityId] ,[Property] = SOURCE.[Property] ,[Version] = SOURCE.[Version] ,[AddressString] = SOURCE.[AddressString] ,[Postal] = SOURCE.[Postal] ,[City] = SOURCE.[City] ,[State] = SOURCE.[State] ,[Country] = SOURCE.[Country] ,[Longitude] = SOURCE.[Longitude] ,[Latitude] = SOURCE.[Latitude] ,[IsValidLocation] = SOURCE.[IsValidLocation] WHEN NOT MATCHED BY TARGET THEN INSERT ( [Id] ,[EntityId] ,[Property] ,[Version] ,[AddressString] ,[Postal] ,[City] ,[State] ,[Country] ,[Longitude] ,[Latitude] ,[IsValidLocation]) VALUES (SOURCE.[Id] ,SOURCE.[EntityId] ,SOURCE.[Property] ,SOURCE.[Version] ,SOURCE.[AddressString] ,SOURCE.[Postal] ,SOURCE.[City] ,SOURCE.[State] ,SOURCE.[Country] ,SOURCE.[Longitude] ,SOURCE.[Latitude] ,SOURCE.[IsValidLocation]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__*PartnerSet] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__*PartnerSet] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__*PartnerSet]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM [' + @tblname + ']'; INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__*PartnerSet] as TARGET USING @tmp as SOURCE ON TARGET.[Property] = SOURCE.[Property] AND TARGET.[PartnerType] = SOURCE.[PartnerType] AND TARGET.[PartnerId] = SOURCE.[PartnerId] AND TARGET.[EntityId] = SOURCE.[EntityId] WHEN MATCHED THEN UPDATE SET [Property] = SOURCE.[Property] ,[PartnerType] = SOURCE.[PartnerType] ,[PartnerId] = SOURCE.[PartnerId] ,[EntityId] = SOURCE.[EntityId] WHEN NOT MATCHED BY TARGET THEN INSERT ( [Property] ,[PartnerType] ,[PartnerId] ,[EntityId]) VALUES (SOURCE.[Property] ,SOURCE.[PartnerType] ,SOURCE.[PartnerId] ,SOURCE.[EntityId]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__appointments] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__appointments] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__appointments]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__appointments] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] ) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[State] = SOURCE.[State] ,[Type] = SOURCE.[Type] ,[EndDateTime] = SOURCE.[EndDateTime] ,[StartDateTime] = SOURCE.[StartDateTime] ,[DrivingDistanceFrom] = SOURCE.[DrivingDistanceFrom] ,[DrivingDistanceTo] = SOURCE.[DrivingDistanceTo] ,[WasReadOnClientSide] = SOURCE.[WasReadOnClientSide] ,[ContactIds] = SOURCE.[ContactIds] ,[ServiceRequestId] = SOURCE.[ServiceRequestId] ,[ContactId] = SOURCE.[ContactId] ,[Note] = SOURCE.[Note] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[State] ,[Type] ,[EndDateTime] ,[StartDateTime] ,[DrivingDistanceFrom] ,[DrivingDistanceTo] ,[WasReadOnClientSide] ,[ContactIds] ,[ServiceRequestId] ,[ContactId] ,[Note]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[State] ,SOURCE.[Type] ,SOURCE.[EndDateTime] ,SOURCE.[StartDateTime] ,SOURCE.[DrivingDistanceFrom] ,SOURCE.[DrivingDistanceTo] ,SOURCE.[WasReadOnClientSide] ,SOURCE.[ContactIds] ,SOURCE.[ServiceRequestId] ,SOURCE.[ContactId] ,SOURCE.[Note]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__attachments] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__attachments] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__attachments]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__attachments] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[URI] = SOURCE.[URI] ,[StepId] = SOURCE.[StepId] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[URI] ,[StepId]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[URI] ,SOURCE.[StepId]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__comments] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__comments] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__comments]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__comments] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateOfCreation] <= SOURCE.[DateOfCreation]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[DateOfCreation] = SOURCE.[DateOfCreation] ,[IsInternal] = SOURCE.[IsInternal] ,[ServiceRequestId] = SOURCE.[ServiceRequestId] ,[CompanyId] = SOURCE.[CompanyId] ,[Content] = SOURCE.[Content] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[DateOfCreation] ,[IsInternal] ,[ServiceRequestId] ,[CompanyId] ,[Content]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[DateOfCreation] ,SOURCE.[IsInternal] ,SOURCE.[ServiceRequestId] ,SOURCE.[CompanyId] ,SOURCE.[Content]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__companies] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__companies] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); DECLARE @tmp [dbo].[mfr__tt__companies]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; IF @referencetable = 'mfr__companies' BEGIN DELETE p OUTput deleted.*, @now INTO [dbo].[mfr__d_*PartnerSet] FROM [dbo].[mfr__*PartnerSet] as p WHERE p.Property like 'Company[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = p.[EntityId]); DELETE cv OUTput deleted.*, @now INTO [dbo].[mfr__d_#customvalues] FROM [dbo].[mfr__#customvalues] as cv WHERE cv.Property like 'Company[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = cv.[EntityId]); DELETE lc OUTPUT deleted.*, @now INTO [dbo].[mfr__d_#locations] FROM [dbo].[mfr__#locations] as lc WHERE lc.Property like 'Company[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = lc.[EntityId]); DELETE cm OUTPUT deleted.*, @now INTO [dbo].[mfr__d_comments] FROM [dbo].[mfr__comments] as cm WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = cm.[CompanyId] AND ISNULL(cm.[ServiceRequestId],0) = 0); END MERGE [dbo].[mfr__companies] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Location#ID] = SOURCE.[Location#ID] ,[Version] = SOURCE.[Version] ,[IsPhysicalPerson] = SOURCE.[IsPhysicalPerson] ,[IsOwner] = SOURCE.[IsOwner] ,[IsEmailInvoicingActive] = SOURCE.[IsEmailInvoicingActive] ,[IsSupplier] = SOURCE.[IsSupplier] ,[MappingId] = SOURCE.[MappingId] ,[ExternalId] = SOURCE.[ExternalId] ,[Name] = SOURCE.[Name] ,[Note] = SOURCE.[Note] ,[SupportTelephone] = SOURCE.[SupportTelephone] ,[SupportFax] = SOURCE.[SupportFax] ,[SupportMail] = SOURCE.[SupportMail] ,[QuickSearch] = SOURCE.[QuickSearch] ,[DateModified] = SOURCE.[DateModified] ,[CustomValues] = SOURCE.[CustomValues] ,[MainContactId] = SOURCE.[MainContactId] WHEN NOT MATCHED BY TARGET THEN INSERT ( [Id] ,[Location#ID] ,[Version] ,[IsPhysicalPerson] ,[IsOwner] ,[IsEmailInvoicingActive] ,[IsSupplier] ,[MappingId] ,[ExternalId] ,[Name] ,[Note] ,[SupportTelephone] ,[SupportFax] ,[SupportMail] ,[QuickSearch] ,[DateModified] ,[CustomValues] ,[MainContactId]) VALUES (SOURCE.[Id] ,SOURCE.[Location#ID] ,SOURCE.[Version] ,SOURCE.[IsPhysicalPerson] ,SOURCE.[IsOwner] ,SOURCE.[IsEmailInvoicingActive] ,SOURCE.[IsSupplier] ,SOURCE.[MappingId] ,SOURCE.[ExternalId] ,SOURCE.[Name] ,SOURCE.[Note] ,SOURCE.[SupportTelephone] ,SOURCE.[SupportFax] ,SOURCE.[SupportMail] ,SOURCE.[QuickSearch] ,SOURCE.[DateModified] ,SOURCE.[CustomValues] ,SOURCE.[MainContactId]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__contacts] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__contacts] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__contacts]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__contacts] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[CustomValues] = SOURCE.[CustomValues] ,[FirstName] = SOURCE.[FirstName] ,[LastName] = SOURCE.[LastName] ,[Email] = SOURCE.[Email] ,[JobTitle] = SOURCE.[JobTitle] ,[MobilePhone] = SOURCE.[MobilePhone] ,[Telephone] = SOURCE.[Telephone] ,[Fax] = SOURCE.[Fax] ,[Note] = SOURCE.[Note] ,[DateModified] = SOURCE.[DateModified] ,[Version] = SOURCE.[Version] ,[CompanyId] = SOURCE.[CompanyId] ,[IsUser] = SOURCE.[IsUser] ,[ExternalId] = SOURCE.[ExternalId] ,[Gender] = SOURCE.[Gender] ,[UserId] = SOURCE.[UserId] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[CustomValues] ,[FirstName] ,[LastName] ,[Email] ,[JobTitle] ,[MobilePhone] ,[Telephone] ,[Fax] ,[Note] ,[DateModified] ,[Version] ,[CompanyId] ,[IsUser] ,[ExternalId] ,[Gender] ,[UserId]) VALUES (SOURCE.[Id] ,SOURCE.[CustomValues] ,SOURCE.[FirstName] ,SOURCE.[LastName] ,SOURCE.[Email] ,SOURCE.[JobTitle] ,SOURCE.[MobilePhone] ,SOURCE.[Telephone] ,SOURCE.[Fax] ,SOURCE.[Note] ,SOURCE.[DateModified] ,SOURCE.[Version] ,SOURCE.[CompanyId] ,SOURCE.[IsUser] ,SOURCE.[ExternalId] ,SOURCE.[Gender] ,SOURCE.[UserId]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__costcenters] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__costcenters] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__costcenters]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__costcenters] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[Name] = SOURCE.[Name] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[Name]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[Name]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__documents] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__documents] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__documents]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__documents] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified] ) THEN UPDATE SET [Id] = SOURCE.[Id] ,[CustomValues] = SOURCE.[CustomValues] ,[Version] = SOURCE.[Version] ,[State] = SOURCE.[State] ,[ExternalId] = SOURCE.[ExternalId] ,[URI] = SOURCE.[URI] ,[IsGlobal] = SOURCE.[IsGlobal] ,[StartDateTime] = SOURCE.[StartDateTime] ,[EndDateTime] = SOURCE.[EndDateTime] ,[FileName] = SOURCE.[FileName] ,[DateModified] = SOURCE.[DateModified] ,[UploadDate] = SOURCE.[UploadDate] ,[IsLink] = SOURCE.[IsLink] ,[ContentType] = SOURCE.[ContentType] ,[HTMLCode] = SOURCE.[HTMLCode] ,[ServiceRequestId] = SOURCE.[ServiceRequestId] ,[Note] = SOURCE.[Note] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[CustomValues] ,[Version] ,[State] ,[ExternalId] ,[URI] ,[IsGlobal] ,[StartDateTime] ,[EndDateTime] ,[FileName] ,[DateModified] ,[UploadDate] ,[IsLink] ,[ContentType] ,[HTMLCode] ,[ServiceRequestId] ,[Note]) VALUES (SOURCE.[Id] ,SOURCE.[CustomValues] ,SOURCE.[Version] ,SOURCE.[State] ,SOURCE.[ExternalId] ,SOURCE.[URI] ,SOURCE.[IsGlobal] ,SOURCE.[StartDateTime] ,SOURCE.[EndDateTime] ,SOURCE.[FileName] ,SOURCE.[DateModified] ,SOURCE.[UploadDate] ,SOURCE.[IsLink] ,SOURCE.[ContentType] ,SOURCE.[HTMLCode] ,SOURCE.[ServiceRequestId] ,SOURCE.[Note]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__items] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__items] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__items]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__items] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[QuantityHours] = SOURCE.[QuantityHours] ,[PlannedQuantityHours] = SOURCE.[PlannedQuantityHours] ,[ItemTypeId] = SOURCE.[ItemTypeId] ,[ItemNumber] = SOURCE.[ItemNumber] ,[TrackingId] = SOURCE.[TrackingId] ,[Manufacture] = SOURCE.[Manufacture] ,[Price] = SOURCE.[Price] ,[Costs] = SOURCE.[Costs] ,[NameOrNumber] = SOURCE.[NameOrNumber] ,[CustomValues] = SOURCE.[CustomValues] ,[Note] = SOURCE.[Note] ,[ExternalId] = SOURCE.[ExternalId] ,[Discount] = SOURCE.[Discount] ,[VAT] = SOURCE.[VAT] ,[IsManual] = SOURCE.[IsManual] ,[SortOrder] = SOURCE.[SortOrder] ,[Type] = SOURCE.[Type] ,[ServiceRequestId] = SOURCE.[ServiceRequestId] ,[ServiceObjectId] = SOURCE.[ServiceObjectId] ,[CreatorId] = SOURCE.[CreatorId] ,[UnitId] = SOURCE.[UnitId] ,[UnitString] = SOURCE.[UnitString] WHEN NOT MATCHED BY TARGET THEN INSERT ( [Id] ,[Version] ,[QuantityHours] ,[PlannedQuantityHours] ,[ItemTypeId] ,[ItemNumber] ,[TrackingId] ,[Manufacture] ,[Price] ,[Costs] ,[NameOrNumber] ,[CustomValues] ,[Note] ,[ExternalId] ,[Discount] ,[VAT] ,[IsManual] ,[SortOrder] ,[Type] ,[ServiceRequestId] ,[ServiceObjectId] ,[CreatorId] ,[UnitId] ,[UnitString]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[QuantityHours] ,SOURCE.[PlannedQuantityHours] ,SOURCE.[ItemTypeId] ,SOURCE.[ItemNumber] ,SOURCE.[TrackingId] ,SOURCE.[Manufacture] ,SOURCE.[Price] ,SOURCE.[Costs] ,SOURCE.[NameOrNumber] ,SOURCE.[CustomValues] ,SOURCE.[Note] ,SOURCE.[ExternalId] ,SOURCE.[Discount] ,SOURCE.[VAT] ,SOURCE.[IsManual] ,SOURCE.[SortOrder] ,SOURCE.[Type] ,SOURCE.[ServiceRequestId] ,SOURCE.[ServiceObjectId] ,SOURCE.[CreatorId] ,SOURCE.[UnitId] ,SOURCE.[UnitString]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__itemtypes] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__itemtypes] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__itemtypes]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__itemtypes] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified] ) THEN UPDATE SET [Id] = SOURCE.[Id] ,[CustomValues] = SOURCE.[CustomValues] ,[Version] = SOURCE.[Version] ,[Costs] = SOURCE.[Costs] ,[Description] = SOURCE.[Description] ,[ListPrice] = SOURCE.[ListPrice] ,[Manufacture] = SOURCE.[Manufacture] ,[ExternalId] = SOURCE.[ExternalId] ,[ItemNumber] = SOURCE.[ItemNumber] ,[NameOrNumber] = SOURCE.[NameOrNumber] ,[GlobalTradeItemNr] = SOURCE.[GlobalTradeItemNr] ,[Type] = SOURCE.[Type] ,[Price] = SOURCE.[Price] ,[VAT] = SOURCE.[VAT] ,[IsPortalOnly] = SOURCE.[IsPortalOnly] ,[Discount] = SOURCE.[Discount] ,[DateModified] = SOURCE.[DateModified] ,[IsDiscontinued] = SOURCE.[IsDiscontinued] ,[IsWarehouse] = SOURCE.[IsWarehouse] ,[UnitId] = SOURCE.[UnitId] ,[UnitString] = SOURCE.[UnitString] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[CustomValues] ,[Version] ,[Costs] ,[Description] ,[ListPrice] ,[Manufacture] ,[ExternalId] ,[ItemNumber] ,[NameOrNumber] ,[GlobalTradeItemNr] ,[Type] ,[Price] ,[VAT] ,[IsPortalOnly] ,[Discount] ,[DateModified] ,[IsDiscontinued] ,[IsWarehouse] ,[UnitId] ,[UnitString]) VALUES (SOURCE.[Id] ,SOURCE.[CustomValues] ,SOURCE.[Version] ,SOURCE.[Costs] ,SOURCE.[Description] ,SOURCE.[ListPrice] ,SOURCE.[Manufacture] ,SOURCE.[ExternalId] ,SOURCE.[ItemNumber] ,SOURCE.[NameOrNumber] ,SOURCE.[GlobalTradeItemNr] ,SOURCE.[Type] ,SOURCE.[Price] ,SOURCE.[VAT] ,SOURCE.[IsPortalOnly] ,SOURCE.[Discount] ,SOURCE.[DateModified] ,SOURCE.[IsDiscontinued] ,SOURCE.[IsWarehouse] ,SOURCE.[UnitId] ,SOURCE.[UnitString]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__itemunits] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__itemunits] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__itemunits]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__itemunits] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[Name] = SOURCE.[Name] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[Name]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[Name]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__products] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__products] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__products]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__products] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[Name] = SOURCE.[Name] ,[SubKey] = SOURCE.[SubKey] ,[Description] = SOURCE.[Description] ,[DateModified] = SOURCE.[DateModified] ,[MappingId] = SOURCE.[MappingId] ,[CustomValueStepTemplateId] = SOURCE.[CustomValueStepTemplateId] WHEN NOT MATCHED BY TARGET THEN INSERT ( [Id] ,[Version] ,[Name] ,[SubKey] ,[Description] ,[DateModified] ,[MappingId] ,[CustomValueStepTemplateId]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[Name] ,SOURCE.[SubKey] ,SOURCE.[Description] ,SOURCE.[DateModified] ,SOURCE.[MappingId] ,SOURCE.[CustomValueStepTemplateId]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__qualifications] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__qualifications] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__qualifications]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__qualifications] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[Name] = SOURCE.[Name] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[Name]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[Name]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__reports] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__reports] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__reports]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__reports] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateOfCreation] <= SOURCE.[DateOfCreation] ) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[DateOfCreation] = SOURCE.[DateOfCreation] ,[URI] = SOURCE.[URI] ,[DocumentName] = SOURCE.[DocumentName] ,[FileTypeString] = SOURCE.[FileTypeString] ,[ReportDefinitionCode] = SOURCE.[ReportDefinitionCode] ,[ServiceObjectId] = SOURCE.[ServiceObjectId] ,[CanBeDeleted] = SOURCE.[CanBeDeleted] ,[InvoiceBalance] = SOURCE.[InvoiceBalance] ,[InvoiceId] = SOURCE.[InvoiceId] ,[DueDate] = SOURCE.[DueDate] ,[IsPayed] = SOURCE.[IsPayed] ,[IsInvoice] = SOURCE.[IsInvoice] ,[IsCanceled] = SOURCE.[IsCanceled] ,[CustomValues] = SOURCE.[CustomValues] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[DateOfCreation] ,[URI] ,[DocumentName] ,[FileTypeString] ,[ReportDefinitionCode] ,[ServiceObjectId] ,[CanBeDeleted] ,[InvoiceBalance] ,[InvoiceId] ,[DueDate] ,[IsPayed] ,[IsInvoice] ,[IsCanceled] ,[CustomValues]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[DateOfCreation] ,SOURCE.[URI] ,SOURCE.[DocumentName] ,SOURCE.[FileTypeString] ,SOURCE.[ReportDefinitionCode] ,SOURCE.[ServiceObjectId] ,SOURCE.[CanBeDeleted] ,SOURCE.[InvoiceBalance] ,SOURCE.[InvoiceId] ,SOURCE.[DueDate] ,SOURCE.[IsPayed] ,SOURCE.[IsInvoice] ,SOURCE.[IsCanceled] ,SOURCE.[CustomValues]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__serviceobjects] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__serviceobjects] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); DECLARE @tmp [dbo].[mfr__tt__serviceobjects]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; IF @referencetable = 'mfr__serviceobjects' BEGIN DELETE p OUTput deleted.*, @now INTO [dbo].[mfr__d_*PartnerSet] FROM [dbo].[mfr__*PartnerSet] as p WHERE p.Property like 'ServiceObject[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = p.[EntityId]); DELETE cv OUTput deleted.*, @now INTO [dbo].[mfr__d_#customvalues] FROM [dbo].[mfr__#customvalues] as cv WHERE cv.Property like 'ServiceObject[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = cv.[EntityId]); DELETE lc OUTPUT deleted.*, @now INTO [dbo].[mfr__d_#locations] FROM [dbo].[mfr__#locations] as lc WHERE lc.Property like 'ServiceObject[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = lc.[EntityId]); DELETE itm OUTPUT deleted.*, @now INTO [dbo].[mfr__d_items] FROM [dbo].[mfr__items] as itm WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = itm.[ServiceObjectId] and ISNULL(itm.[ServiceRequestId],0) = 0); END MERGE [dbo].[mfr__serviceobjects] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Location#ID] = SOURCE.[Location#ID] ,[Name] = SOURCE.[Name] ,[Note] = SOURCE.[Note] ,[CustomValues] = SOURCE.[CustomValues] ,[DateModified] = SOURCE.[DateModified] ,[ExternalId] = SOURCE.[ExternalId] ,[MappingId] = SOURCE.[MappingId] ,[QuickSearch] = SOURCE.[QuickSearch] ,[Version] = SOURCE.[Version] ,[CreateGeoLocation] = SOURCE.[CreateGeoLocation] ,[IsWarehouse] = SOURCE.[IsWarehouse] ,[ParentServiceObjectId] = SOURCE.[ParentServiceObjectId] ,[CompanyId] = SOURCE.[CompanyId] ,[ProductId] = SOURCE.[ProductId] WHEN NOT MATCHED BY TARGET THEN INSERT ( [Id] ,[Location#ID] ,[Name] ,[Note] ,[CustomValues] ,[DateModified] ,[ExternalId] ,[MappingId] ,[QuickSearch] ,[Version] ,[CreateGeoLocation] ,[IsWarehouse] ,[ParentServiceObjectId] ,[CompanyId] ,[ProductId]) VALUES (SOURCE.[Id] ,SOURCE.[Location#ID] ,SOURCE.[Name] ,SOURCE.[Note] ,SOURCE.[CustomValues] ,SOURCE.[DateModified] ,SOURCE.[ExternalId] ,SOURCE.[MappingId] ,SOURCE.[QuickSearch] ,SOURCE.[Version] ,SOURCE.[CreateGeoLocation] ,SOURCE.[IsWarehouse] ,SOURCE.[ParentServiceObjectId] ,SOURCE.[CompanyId] ,SOURCE.[ProductId]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__servicerequests] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__servicerequests] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); DECLARE @tmp [dbo].[mfr__tt__servicerequests]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; IF @referencetable = 'mfr__servicerequests' BEGIN DELETE p OUTput deleted.*, @now INTO [dbo].[mfr__d_*PartnerSet] FROM [dbo].[mfr__*PartnerSet] as p WHERE p.Property like 'ServiceRequest[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = p.[EntityId]); DELETE cv OUTput deleted.*, @now INTO [dbo].[mfr__d_#customvalues] FROM [dbo].[mfr__#customvalues] as cv WHERE cv.Property like 'ServiceRequest[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = cv.[EntityId]); DELETE lc OUTPUT deleted.*, @now INTO [dbo].[mfr__d_#locations] FROM [dbo].[mfr__#locations] as lc WHERE lc.Property like 'ServiceRequest[:]%' AND EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = lc.[EntityId]); DELETE stp OUTPUT deleted.*, @now INTO [dbo].[mfr__d_steps] FROM [dbo].[mfr__steps] as stp WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = stp.[ServiceRequestId] and ISNULL(stp.[StepListTemplateId],0) = 0); DELETE app OUTPUT deleted.*, @now INTO [dbo].[mfr__d_appointments] FROM [dbo].[mfr__appointments] as app WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = app.[ServiceRequestId]); DELETE itm OUTPUT deleted.*, @now INTO [dbo].[mfr__d_items] FROM [dbo].[mfr__items] as itm WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = itm.[ServiceRequestId] and ISNULL(itm.[ServiceobjectId],0) = 0); DELETE te OUTPUT deleted.*, @now INTO [dbo].[mfr__d_timeevents] FROM [dbo].[mfr__timeevents] as te WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = te.[ServiceRequestId]); DELETE sm OUTPUT deleted.*, @now INTO [dbo].[mfr__d_stockmovements] FROM [dbo].[mfr__stockmovements] as sm WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = sm.[ServiceRequestId]); DELETE cm OUTPUT deleted.*, @now INTO [dbo].[mfr__d_comments] FROM [dbo].[mfr__comments] as cm WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = cm.[ServiceRequestId] AND ISNULL(cm.[CompanyId],0) = 0); END MERGE [dbo].[mfr__servicerequests] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified] OR TARGET.[DateOfCreation] <= SOURCE.[DateOfCreation] ) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Name] = SOURCE.[Name] ,[ExternalId] = SOURCE.[ExternalId] ,[InvoiceId] = SOURCE.[InvoiceId] ,[ClosedAt] = SOURCE.[ClosedAt] ,[ReleasedAt] = SOURCE.[ReleasedAt] ,[WorkDoneAt] = SOURCE.[WorkDoneAt] ,[TargetTimeInMinutes] = SOURCE.[TargetTimeInMinutes] ,[DateModified] = SOURCE.[DateModified] ,[DateOfCreation] = SOURCE.[DateOfCreation] ,[DueDateRangeStart] = SOURCE.[DueDateRangeStart] ,[DueDateRangeEnd] = SOURCE.[DueDateRangeEnd] ,[PortalLink] = SOURCE.[PortalLink] ,[CostCenterId] = SOURCE.[CostCenterId] ,[Description] = SOURCE.[Description] ,[State] = SOURCE.[State] ,[CustomValues] = SOURCE.[CustomValues] ,[CurrentOwnerId] = SOURCE.[CurrentOwnerId] ,[CustomerId] = SOURCE.[CustomerId] ,[ParentServiceRequestId] = SOURCE.[ParentServiceRequestId] ,[Location#ID] = SOURCE.[Location#ID] ,[Version] = SOURCE.[Version] ,[IsTemplate] = SOURCE.[IsTemplate] ,[IsTemplateMobile] = SOURCE.[IsTemplateMobile] ,[CreateFromServiceRequestTemplateId] = SOURCE.[CreateFromServiceRequestTemplateId] ,[Type] = SOURCE.[Type] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Name] ,[ExternalId] ,[InvoiceId] ,[ClosedAt] ,[ReleasedAt] ,[WorkDoneAt] ,[TargetTimeInMinutes] ,[DateModified] ,[DateOfCreation] ,[DueDateRangeStart] ,[DueDateRangeEnd] ,[PortalLink] ,[CostCenterId] ,[Description] ,[State] ,[CustomValues] ,[CurrentOwnerId] ,[CustomerId] ,[ParentServiceRequestId] ,[Location#ID] ,[Version] ,[IsTemplate] ,[IsTemplateMobile] ,[CreateFromServiceRequestTemplateId] ,[Type]) VALUES (SOURCE.[Id] ,SOURCE.[Name] ,SOURCE.[ExternalId] ,SOURCE.[InvoiceId] ,SOURCE.[ClosedAt] ,SOURCE.[ReleasedAt] ,SOURCE.[WorkDoneAt] ,SOURCE.[TargetTimeInMinutes] ,SOURCE.[DateModified] ,SOURCE.[DateOfCreation] ,SOURCE.[DueDateRangeStart] ,SOURCE.[DueDateRangeEnd] ,SOURCE.[PortalLink] ,SOURCE.[CostCenterId] ,SOURCE.[Description] ,SOURCE.[State] ,SOURCE.[CustomValues] ,SOURCE.[CurrentOwnerId] ,SOURCE.[CustomerId] ,SOURCE.[ParentServiceRequestId] ,SOURCE.[Location#ID] ,SOURCE.[Version] ,SOURCE.[IsTemplate] ,SOURCE.[IsTemplateMobile] ,SOURCE.[CreateFromServiceRequestTemplateId] ,SOURCE.[Type]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__steplisttemplateinstances] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__steplisttemplateinstances] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__steplisttemplateinstances]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__steplisttemplateinstances] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[Name] = SOURCE.[Name] ,[ServiceRequestId] = SOURCE.[ServiceRequestId] ,[TemplateId] = SOURCE.[TemplateId] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[Name] ,[ServiceRequestId] ,[TemplateId]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[Name] ,SOURCE.[ServiceRequestId] ,SOURCE.[TemplateId]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__steplisttemplates] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__steplisttemplates] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); DECLARE @tmp [dbo].[mfr__tt__steplisttemplates]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; IF @referencetable = 'mfr__steplisttemplates' BEGIN DELETE stp OUTPUT deleted.*, @now INTO [dbo].[mfr__d_steps] FROM [dbo].[mfr__steps] as stp WHERE EXISTS (SELECT * FROM @tmp as tmp where tmp.[id] = stp.[StepListTemplateId] and ISNULL(stp.[ServiceRequestId],0) = 0); END MERGE [dbo].[mfr__steplisttemplates] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[Name] = SOURCE.[Name] ,[MappingId] = SOURCE.[MappingId] ,[DateModified] = SOURCE.[DateModified] ,[IsReleased] = SOURCE.[IsReleased] ,[IsDurable] = SOURCE.[IsDurable] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[Name] ,[MappingId] ,[DateModified] ,[IsReleased] ,[IsDurable]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[Name] ,SOURCE.[MappingId] ,SOURCE.[DateModified] ,SOURCE.[IsReleased] ,SOURCE.[IsDurable]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__steps] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__steps] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @now datetime = GETUTCDATE(); DECLARE @tmp [dbo].[mfr__tt__steps]; DECLARE @ARCHIVE TABLE( [ActionType] varchar(25), [Id] [bigint] NULL, [MobileId] [bigint] NULL, [Version] [int] NULL, [Name] [nvarchar](255) NULL, [IsDone] [bit] NULL, [HasError] [bit] NULL, [TrackingId] [nvarchar](255) NULL, [Type] [nvarchar](255) NULL, [SortOrder] [int] NULL, [Data] [nvarchar](max) NULL, [DateModifiedOffline] [datetime] NULL, [ServiceRequestId] [bigint] NULL, [Description] [nvarchar](max) NULL, [Comment] [nvarchar](max) NULL, [InternalComment] [nvarchar](max) NULL, [ServiceObjectId] [bigint] NULL, [StepListTemplateId] [bigint] NULL, [ParentId] [bigint] NULL ); DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; DECLARE @olist TABLE ( [id] bigint ); DECLARE @check_reference as varchar(5) = ''; IF ISNULL(@referencetable,'') = 'mfr__servicerequests' BEGIN SET @check_reference = 'srq'; INSERT INTO @olist SELECT DISTINCT [ServiceRequestId] FROM @tmp WHERE ISNULL([ServiceRequestId],0) <> 0; END IF ISNULL(@referencetable,'') = 'mfr__steplisttemplates' BEGIN SET @check_reference = 'slt'; INSERT INTO @olist SELECT DISTINCT [StepListTemplateId] FROM @tmp WHERE ISNULL([StepListTemplateId],0) <> 0; END MERGE [dbo].[mfr__steps] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[MobileId] = SOURCE.[MobileId] ,[Version] = SOURCE.[Version] ,[Name] = SOURCE.[Name] ,[IsDone] = SOURCE.[IsDone] ,[HasError] = SOURCE.[HasError] ,[TrackingId] = SOURCE.[TrackingId] ,[Type] = SOURCE.[Type] ,[SortOrder] = SOURCE.[SortOrder] ,[Data] = SOURCE.[Data] ,[DateModifiedOffline] = SOURCE.[DateModifiedOffline] ,[ServiceRequestId] = SOURCE.[ServiceRequestId] ,[Description] = SOURCE.[Description] ,[Comment] = SOURCE.[Comment] ,[InternalComment] = SOURCE.[InternalComment] ,[ServiceObjectId] = SOURCE.[ServiceObjectId] ,[StepListTemplateId] = SOURCE.[StepListTemplateId] ,[ParentId] = SOURCE.[ParentId] WHEN NOT MATCHED BY TARGET THEN INSERT ( [Id] ,[MobileId] ,[Version] ,[Name] ,[IsDone] ,[HasError] ,[TrackingId] ,[Type] ,[SortOrder] ,[Data] ,[DateModifiedOffline] ,[ServiceRequestId] ,[Description] ,[Comment] ,[InternalComment] ,[ServiceObjectId] ,[StepListTemplateId] ,[ParentId]) VALUES (SOURCE.[Id] ,SOURCE.[MobileId] ,SOURCE.[Version] ,SOURCE.[Name] ,SOURCE.[IsDone] ,SOURCE.[HasError] ,SOURCE.[TrackingId] ,SOURCE.[Type] ,SOURCE.[SortOrder] ,SOURCE.[Data] ,SOURCE.[DateModifiedOffline] ,SOURCE.[ServiceRequestId] ,SOURCE.[Description] ,SOURCE.[Comment] ,SOURCE.[InternalComment] ,SOURCE.[ServiceObjectId] ,SOURCE.[StepListTemplateId] ,SOURCE.[ParentId]) WHEN NOT MATCHED BY SOURCE AND (CASE WHEN @check_reference = 'srq' AND EXISTS (SELECT * FROM @olist as ol where ol.[id] = TARGET.[ServiceRequestId]) THEN 1 WHEN @check_reference = 'slt' AND EXISTS (SELECT * FROM @olist as ol where ol.[id] = TARGET.[StepListTemplateId]) THEN 1 ELSE 0 END) = 1 THEN DELETE OUTPUT $action, deleted.* INTO @ARCHIVE; INSERT INTO [dbo].[mfr__d_steps] SELECT [Id] ,[MobileId] ,[Version] ,[Name] ,[IsDone] ,[HasError] ,[TrackingId] ,[Type] ,[SortOrder] ,[Data] ,[DateModifiedOffline] ,[ServiceRequestId] ,[Description] ,[Comment] ,[InternalComment] ,[ServiceObjectId] ,[StepListTemplateId] ,[ParentId] ,[DateDeleted] = @now FROM @ARCHIVE WHERE [ActionType] IN ( 'DELETE', 'UPDATE' ); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__stockmovements] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__stockmovements] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__stockmovements]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__stockmovements] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified] OR TARGET.[DateOfCreation] <= SOURCE.[DateOfCreation] ) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[Amount] = SOURCE.[Amount] ,[AmountReceived] = SOURCE.[AmountReceived] ,[ExternalId] = SOURCE.[ExternalId] ,[ItemId] = SOURCE.[ItemId] ,[ItemTypeId] = SOURCE.[ItemTypeId] ,[StockMovementType] = SOURCE.[StockMovementType] ,[State] = SOURCE.[State] ,[ServiceRequestId] = SOURCE.[ServiceRequestId] ,[WarehouseId] = SOURCE.[WarehouseId] ,[DateOfCreation] = SOURCE.[DateOfCreation] ,[DateModified] = SOURCE.[DateModified] ,[TargetDate] = SOURCE.[TargetDate] ,[CreatedById] = SOURCE.[CreatedById] ,[ConfirmedById] = SOURCE.[ConfirmedById] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[Amount] ,[AmountReceived] ,[ExternalId] ,[ItemId] ,[ItemTypeId] ,[StockMovementType] ,[State] ,[ServiceRequestId] ,[WarehouseId] ,[DateOfCreation] ,[DateModified] ,[TargetDate] ,[CreatedById] ,[ConfirmedById]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[Amount] ,SOURCE.[AmountReceived] ,SOURCE.[ExternalId] ,SOURCE.[ItemId] ,SOURCE.[ItemTypeId] ,SOURCE.[StockMovementType] ,SOURCE.[State] ,SOURCE.[ServiceRequestId] ,SOURCE.[WarehouseId] ,SOURCE.[DateOfCreation] ,SOURCE.[DateModified] ,SOURCE.[TargetDate] ,SOURCE.[CreatedById] ,SOURCE.[ConfirmedById]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__tags] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__tags] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__tags]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; WITH tmp as ( SELECT *, ROW_NUMBER() OVER (PARTITION BY [id] ORDER BY [version] DESC) as '#' FROM @tmp ), SOURCE as ( SELECT * FROM tmp WHERE [#] = 1 ) MERGE [dbo].[mfr__tags] as TARGET USING SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[Name] = SOURCE.[Name] ,[ColorDefinition] = SOURCE.[ColorDefinition] ,[Type] = SOURCE.[Type] WHEN NOT MATCHED BY TARGET THEN INSERT ( [Id] ,[Version] ,[Name] ,[ColorDefinition] ,[Type]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[Name] ,SOURCE.[ColorDefinition] ,SOURCE.[Type]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__timeevents] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__timeevents] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__timeevents]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__timeevents] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[DateModified] <= SOURCE.[DateModified]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[State] = SOURCE.[State] ,[IsApproved] = SOURCE.[IsApproved] ,[TimeEventType] = SOURCE.[TimeEventType] ,[ExternalId] = SOURCE.[ExternalId] ,[DateModified] = SOURCE.[DateModified] ,[StartDateTime] = SOURCE.[StartDateTime] ,[EndDateTime] = SOURCE.[EndDateTime] ,[ProposedDrivingDistance] = SOURCE.[ProposedDrivingDistance] ,[ContactId] = SOURCE.[ContactId] ,[ServiceRequestId] = SOURCE.[ServiceRequestId] ,[Description] = SOURCE.[Description] WHEN NOT MATCHED BY TARGET THEN INSERT ([Id] ,[Version] ,[State] ,[IsApproved] ,[TimeEventType] ,[ExternalId] ,[DateModified] ,[StartDateTime] ,[EndDateTime] ,[ProposedDrivingDistance] ,[ContactId] ,[ServiceRequestId] ,[Description]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[State] ,SOURCE.[IsApproved] ,SOURCE.[TimeEventType] ,SOURCE.[ExternalId] ,SOURCE.[DateModified] ,SOURCE.[StartDateTime] ,SOURCE.[EndDateTime] ,SOURCE.[ProposedDrivingDistance] ,SOURCE.[ContactId] ,SOURCE.[ServiceRequestId] ,SOURCE.[Description]); END GO /****** Object: StoredProcedure [dbo].[mfr__updt__users] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[mfr__updt__users] @tblname as nvarchar(50) , @referencetable nvarchar(50) AS BEGIN SET NOCOUNT ON; DECLARE @tmp [dbo].[mfr__tt__users]; DECLARE @tmp_cmd nvarchar(1000) = N'SELECT DISTINCT * FROM ' + @tblname INSERT INTO @tmp EXECUTE [sp_executesql] @tmp_cmd; MERGE [dbo].[mfr__users] as TARGET USING @tmp as SOURCE ON TARGET.[Id] = SOURCE.[Id] WHEN MATCHED AND (TARGET.[Version] <= SOURCE.[Version] OR TARGET.[CreationDate] <= SOURCE.[CreationDate]) THEN UPDATE SET [Id] = SOURCE.[Id] ,[Version] = SOURCE.[Version] ,[UserName] = SOURCE.[UserName] ,[IsSystem] = SOURCE.[IsSystem] ,[CreationDate] = SOURCE.[CreationDate] ,[IsApproved] = SOURCE.[IsApproved] ,[ContactId] = SOURCE.[ContactId] ,[PreferedLanguage] = SOURCE.[PreferedLanguage] ,[EmailChannelEnabled] = SOURCE.[EmailChannelEnabled] ,[HasFullScreenPreference] = SOURCE.[HasFullScreenPreference] ,[TimeZone] = SOURCE.[TimeZone] ,[PreferedCulture] = SOURCE.[PreferedCulture] ,[IsActive] = SOURCE.[IsActive] ,[IsMobile] = SOURCE.[IsMobile] ,[LastLoginDate] = SOURCE.[LastLoginDate] ,[UserGuideProgress] = SOURCE.[UserGuideProgress] ,[DashboardSettings] = SOURCE.[DashboardSettings] WHEN NOT MATCHED BY TARGET THEN INSERT ( [Id] ,[Version] ,[UserName] ,[IsSystem] ,[CreationDate] ,[IsApproved] ,[ContactId] ,[PreferedLanguage] ,[EmailChannelEnabled] ,[HasFullScreenPreference] ,[TimeZone] ,[PreferedCulture] ,[IsActive] ,[IsMobile] ,[LastLoginDate] ,[UserGuideProgress] ,[DashboardSettings]) VALUES (SOURCE.[Id] ,SOURCE.[Version] ,SOURCE.[UserName] ,SOURCE.[IsSystem] ,SOURCE.[CreationDate] ,SOURCE.[IsApproved] ,SOURCE.[ContactId] ,SOURCE.[PreferedLanguage] ,SOURCE.[EmailChannelEnabled] ,SOURCE.[HasFullScreenPreference] ,SOURCE.[TimeZone] ,SOURCE.[PreferedCulture] ,SOURCE.[IsActive] ,SOURCE.[IsMobile] ,SOURCE.[LastLoginDate] ,SOURCE.[UserGuideProgress] ,SOURCE.[DashboardSettings]); END GO /****** Object: StoredProcedure [dbo].[ocms_admin_createUserAccount] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_admin_createUserAccount] @name nvarchar(255) ,@email varchar(255) ,@mobile varchar(50) ,@password nvarchar(20) ,@enc_key uniqueidentifier AS BEGIN SET NOCOUNT ON; DECLARE @utcnow datetime = GETUTCDATE(); INSERT INTO [dbo].[ocms_useraccounts] ([useraccount_id] ,[name_enc] ,[email_enc] ,[mobile_enc] ,[password_enc] ,[UserDisabled] ,[DateDisabled] ,[UserCreated] ,[DateCreated] ,[UserModified] ,[DateModified] ,[UserDeleted] ,[DateDeleted]) OUTPUT inserted.[useraccount_id] VALUES ([dbo].[ocms_fn_useraccount_id] () ,ENCRYPTBYKEY(@enc_key, @name) ,ENCRYPTBYKEY(@enc_key, @email) ,ENCRYPTBYKEY(@enc_key, @mobile) ,CASE WHEN @password is null then null ELSE ENCRYPTBYKEY(@enc_key, @password) END ,NULL --[UserDisabled] ,NULL --[DateDisabled] ,'sa' ,@utcnow ,'sa' ,@utcnow ,NULL ,NULL); END GO /****** Object: StoredProcedure [dbo].[ocms_admin_debug_log] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Dr. Stefan Ott -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_admin_debug_log] @machine varchar(50) ,@error varchar(2000) ,@exception varchar(max) ,@procedure varchar(255) ,@authuser varchar(25) ,@data nvarchar(max) ,@isdebug bit AS BEGIN SET NOCOUNT ON; INSERT INTO [dbo].[ocms_debug] ([machine] ,[error] ,[exception] ,[procedure] ,[authuser] ,[data] ,[isdebug]) VALUES ( @machine ,@error ,@exception ,@procedure ,@authuser ,@data ,@isdebug ); END GO /****** Object: StoredProcedure [dbo].[ocms_cleanups] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_cleanups] AS BEGIN SET NOCOUNT ON; /* UPDATE Template Property Numbering */ with tpo as ( select * , ROW_NUMBER() OVER (PARTITION BY ocms_tid ORDER BY [order], ocms_tpid) as 'tpo' from [dbo].[ocms_template_properties] ) update tp SET tp.[order] = tpo.[tpo] From [dbo].[ocms_template_properties] as tp JOIN tpo ON tp.[ocms_tpid] = tpo.[ocms_tpid]; /* UPDATE ITEM NUMBERING */ with ino as ( select * , ROW_NUMBER() OVER (PARTITION BY [parent_iid] ORDER BY [order], [ocms_iid]) as 'itmo' -- 999 for any new from [dbo].[ocms_items] ) update i SET i.[order] = ino.[itmo] From [dbo].[ocms_items] as i JOIN ino ON i.[ocms_iid] = ino.[ocms_iid] WHERE i.[order] >= 0 and i.[parent_iid] is not null END GO /****** Object: StoredProcedure [dbo].[ocms_cloneItem] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_cloneItem] @old_ocms_iid bigint ,@new_parent_iid bigint AS BEGIN SET NOCOUNT ON; IF EXISTS (SELECT * from [dbo].[ocms_items] as i where i.[ocms_iid] = @old_ocms_iid) AND EXISTS (SELECT * from [dbo].[ocms_items] as i where i.[ocms_iid] = @new_parent_iid) BEGIN DECLARE @NEW TABLE ([ocms_iid] bigint, [old_ocms_pid] bigint); INSERT INTO [dbo].[ocms_items] ([parent_iid] ,[ocms_pid] ,[name] ,[view] ,[template_id] ,[hide] ,[order] ,[DateCreated] ,[DateModified]) OUTPUT inserted.[ocms_iid], inserted.[ocms_pid] INTO @new SELECT @new_parent_iid ,[ocms_pid] ,[name] ,[view] ,[template_id] ,[hide] ,[order] ,GETUTCDATE() ,GETUTCDATE() FROM [dbo].[ocms_items] as i WHERE [ocms_iid] = @old_ocms_iid; DECLARE @new_ocms_iid bigint, @old_ocms_pid bigint; SELECT TOP(1) @new_ocms_iid = [ocms_iid], @old_ocms_pid = [old_ocms_pid] FROM @NEW; IF NOT EXISTS (SELECT pn.* from [dbo].[ocms_properties] as pn JOIN [dbo].[ocms_properties] as po ON pn.[key] = po.[key] and pn.[locale] = po.[locale] WHERE pn.[ocms_iid] = @new_parent_iid AND po.[ocms_pid] = @old_ocms_pid) BEGIN DECLARE @newprop [dbo].[ocms_type_properties_base]; DECLARE @property_key varchar(50), @locale varchar(5), @new_ocms_pid bigint; SELECT TOP(1) @property_key = [key], @locale = [locale] FROM [dbo].[ocms_properties] as p WHERE [ocms_pid] = @old_ocms_pid; IF ISNULL(@property_key, '') <> '' BEGIN INSERT INTO @newprop VALUES(@new_parent_iid, @property_key, '', @locale); EXECUTE [dbo].[ocms_merge_properties] @newprop; --makes sure is ok with template END SELECT TOP(1) @new_ocms_pid = [ocms_pid] FROM [dbo].[ocms_properties] WHERE [ocms_iid] = @new_parent_iid AND [key] = @property_key; UPDATE [dbo].[ocms_items] SET [ocms_pid] = @new_ocms_pid ,[DateModified] = GETUTCDATE() WHERE [ocms_iid] = @new_ocms_iid; END IF @new_ocms_iid is not null BEGIN INSERT INTO [dbo].[ocms_properties] ([ocms_iid] ,[key] ,[value] ,[locale] ,[DateCreated] ,[DateModified] ) SELECT @new_ocms_iid ,[key] ,[value] ,[locale] ,GETUTCDATE() ,GETUTCDATE() FROM [dbo].[ocms_properties] WHERE [ocms_iid] = @old_ocms_iid; END END END GO /****** Object: StoredProcedure [dbo].[ocms_createPropertyItem] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_createPropertyItem] @name nvarchar(255), @parent_iid bigint, @ocms_pid bigint, @property_key varchar(50), @template_id bigint, @locale varchar(5) AS BEGIN SET NOCOUNT ON; DECLARE @site bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE i.[parent_iid] is null); IF ISNULL(@name, '') = '' THROW 61010, 'name missing', 1; IF EXISTS (SELECT * FROM [dbo].[ocms_items] WHERE [name] = @name) THROW 61010, 'name already exists', 1; IF NOT EXISTS (SELECT * FROM [dbo].[ocms_items] WHERE [ocms_iid] = @parent_iid) THROW 61010, 'parent does not exist', 1; IF NOT EXISTS (SELECT * FROM [dbo].[ocms_templates] WHERE [ocms_tid] = @template_id) THROW 61010, 'template does not exist', 1; IF NOT EXISTS (SELECT * FROM [dbo].[ocms_properties] WHERE [ocms_iid] = @parent_iid AND ([ocms_pid] = @ocms_pid OR (@ocms_pid is null AND [key] = @property_key))) BEGIN DECLARE @newprop [dbo].[ocms_type_properties_base]; INSERT INTO @newprop VALUES(@parent_iid, @property_key, '', @locale); EXECUTE [dbo].[ocms_merge_properties] @newprop; --makes sure is ok with template END SELECT TOP(1) @ocms_pid = [ocms_pid] FROM [dbo].[ocms_properties] WHERE [ocms_iid] = @parent_iid AND ([ocms_pid] = @ocms_pid OR (@ocms_pid is null AND [key] = @property_key)); --get last ocms_iid DECLARE @lastiid int = ISNULL ( (SELECT MAX(ISNULL(p.[ocms_iid], ap.[ocms_iid])) FROM [dbo].[ocms_items] as p FULL OUTER JOIN [ocms_archive__items] as ap on p.[ocms_iid] = ap.[ocms_iid]) ,0); IF NOT EXISTS (SELECT * FROM [dbo].[ocms_properties] WHERE [ocms_iid] = @parent_iid AND [ocms_pid] = @ocms_pid) THROW 61010, 'parent''s property does not exist', 1; IF @site is not null BEGIN MERGE [dbo].[ocms_items] as TARGET USING (VALUES( @parent_iid ,@ocms_pid ,@name ,0 ,@template_id ,0 ,999 -- append always )) as SOURCE ([parent_iid] ,[ocms_pid] ,[name] ,[view] ,[template_id] ,[hide] ,[order]) ON TARGET.[name] = SOURCE.[name] WHEN NOT MATCHED BY TARGET THEN INSERT ([ocms_iid] ,[parent_iid] ,[ocms_pid] ,[name] ,[view] ,[template_id] ,[hide] ,[order] ,[DateCreated] ,[DateModified]) VALUES( @lastiid + 1, SOURCE.[parent_iid], SOURCE.[ocms_pid], SOURCE.[name], SOURCE.[view], SOURCE.[template_id], SOURCE.[hide], SOURCE.[order], GETUTCDATE(), GETUTCDATE()) OUTPUT inserted.[ocms_iid]; END END GO /****** Object: StoredProcedure [dbo].[ocms_createView] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_createView] @name nvarchar(255), @parent_iid bigint AS BEGIN SET NOCOUNT ON; DECLARE @site bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE i.[parent_iid] is null); DECLARE @template_id bigint = (SELECT TOP(1) [ocms_tid] FROM [dbo].[ocms_templates] as t WHERE t.[name] = 'view'); IF ISNULL(@name, '') = '' THROW 61010, 'name missing', 1; IF EXISTS (SELECT * FROM [dbo].[ocms_items] WHERE [name] = @name) THROW 61110, 'name already exists', 1; IF @site is null THROW 61110, 'site does not exist', 1; SELECT @parent_iid = [ocms_iid] FROM [dbo].[ocms_items] as i WHERE [ocms_iid] = @parent_iid AND (i.[parent_iid] is null OR i.[view] = 1); --apply site as fallback SET @parent_iid = ISNULL(@parent_iid, @site); --get last ocms_iid DECLARE @lastiid int = ISNULL ( (SELECT MAX(ISNULL(p.[ocms_iid], ap.[ocms_iid])) FROM [dbo].[ocms_items] as p FULL OUTER JOIN [ocms_archive__items] as ap on p.[ocms_iid] = ap.[ocms_iid]) ,0); -- get locales setting DECLARE @locales TABLE([locale] varchar(5), [order] int); INSERT INTO @locales SELECT * FROM [dbo].[ocms_locales](); -- add item DECLARE @output TABLE([ocms_iid] bigint); DECLARE @ocms_iid bigint; MERGE [dbo].[ocms_items] as TARGET USING (VALUES( @site ,NULL ,@name ,1 ,@template_id ,0 ,999 -- append always )) as SOURCE ([parent_iid] ,[ocms_pid] ,[name] ,[view] ,[template_id] ,[hide] ,[order]) ON TARGET.[name] = SOURCE.[name] WHEN NOT MATCHED BY TARGET THEN INSERT ([ocms_iid] ,[parent_iid] ,[ocms_pid] ,[name] ,[view] ,[template_id] ,[hide] ,[order] ,[DateCreated] ,[DateModified]) VALUES(@lastiid + 1, SOURCE.[parent_iid], SOURCE.[ocms_pid], SOURCE.[name], SOURCE.[view], SOURCE.[template_id], SOURCE.[hide], SOURCE.[order], GETUTCDATE(), GETUTCDATE()) OUTPUT inserted.[ocms_iid] INTO @output; SELECT TOP(1) @ocms_iid = [ocms_iid] FROM @output; -- add navigation -- update nav table UPDATE n SET n.[parent_iid] = i.[parent_iid] FROM [dbo].[ocms_navigation] as n JOIN [ocms_items] as i ON n.[ocms_iid] = i.[ocms_iid]; DECLARE @newnav [dbo].[ocms_type_navigation_base]; DECLARE @suffix int = 0; INSERT INTO @newnav SELECT @ocms_iid, [locale], @name + '_' + [locale] FROM @locales as l WHERE l.[locale] <> '*'; WHILE EXISTS (SELECT * FROM [dbo].[ocms_navigation] as cn JOIN @newnav as nn ON cn.[parent_iid] = @parent_iid AND cn.[alias] = nn.[alias]) BEGIN SET @suffix = @suffix + 1; UPDATE @newnav SET [alias] = @name + '_' + [locale] + CAST(@suffix as varchar(3)); END EXECUTE [dbo].[ocms_merge_navigation] @newnav; --output SELECT @ocms_iid; END GO /****** Object: StoredProcedure [dbo].[ocms_deleteItem] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_deleteItem] @ocms_iid bigint AS BEGIN SET NOCOUNT ON; DECLARE @children TABLE([ocms_iid] bigint, [parent_iid] bigint); with cte as ( select [ocms_iid], [parent_iid] from [ocms_items] as i WHERE i.[parent_iid] = @ocms_iid --only children and below UNION ALL select i.[ocms_iid], i.[parent_iid] from [ocms_items] as i JOIN cte on cte.ocms_iid = i.[parent_iid] ) insert into @children select * from cte; --first delete childrens properties, bc else the foreign key constraint will prevent to continue */ DELETE p OUTPUT deleted.*, GETUTCDATE(), null INTO [dbo].[ocms_archive__properties] FROM [dbo].[ocms_properties] as p WHERE p.[ocms_iid] in (SELECT c.[ocms_iid] FROM @children as c); -- only children's as selected at beginning / DELETE i OUTPUT deleted.*, GETUTCDATE(), null INTO [dbo].[ocms_archive__items] FROM [ocms_items] as i WHERE i.[ocms_iid] in (SELECT c.[ocms_iid] FROM @children as c);; -- only children as selected at beginning / DELETE p OUTPUT deleted.*, GETUTCDATE(), null INTO [dbo].[ocms_archive__properties] FROM [dbo].[ocms_properties] as p WHERE p.[ocms_iid] = @ocms_iid; -- only children's as selected at beginning / DELETE FROM [ocms_items] OUTPUT deleted.*, GETUTCDATE(), null INTO [dbo].[ocms_archive__items] WHERE [ocms_iid] = @ocms_iid; SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_archive__items] WHERE [ocms_iid] = @ocms_iid; END GO /****** Object: StoredProcedure [dbo].[ocms_getAvailableTemplates] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_getAvailableTemplates] @ocms_iid bigint ,@ocms_pid bigint ,@property_key varchar(50) AS BEGIN SET NOCOUNT ON; IF NOT EXISTS (SELECT * FROM [dbo].[ocms_items] WHERE [ocms_iid] = @ocms_iid) THROW 61010, 'item does not exist', 1; DECLARE @TP TABLE( [ocms_tpid] [bigint] NOT NULL, [ocms_pid] [bigint], [condition] [varchar](max) NULL ); INSERT INTO @TP SELECT tp.[ocms_tpid], p.[ocms_pid], tp.[condition] FROM [dbo].[ocms_items] as i JOIN [dbo].[ocms_templates] as t on i.[template_id] = t.[ocms_tid] JOIN [dbo].[ocms_template_properties] as tp ON t.[ocms_tid] = tp.[ocms_tid] AND tp.[type] = 'array' LEFT JOIN [dbo].[ocms_properties] as p ON i.[ocms_iid] = p.[ocms_iid] AND p.[key] = tp.[key] WHERE i.[ocms_iid] = @ocms_iid AND (p.[ocms_pid] = @ocms_pid OR (@ocms_pid is null AND tp.[key] = @property_key)) AND tp.[type] = 'array'; IF NOT EXISTS (SELECT * FROM @TP) THROW 61010, 'items''s property type is not array', 1; DECLARE @condition varchar(max); SET @condition = ISNULL((SELECT TOP(1) [condition] FROM @TP), ''); DECLARE @TIDS TABLE ([ocms_tid] bigint); IF LEFT(@condition, 1) = '{' AND RIGHT(@condition, 1) = '}' BEGIN INSERT INTO @TIDS SELECT RTRIM(LTRIM(value)) FROM string_split(SUBSTRING(@condition,2,LEN(@condition) - 2), ','); END ELSE IF @condition <> '' BEGIN INSERT INTO @TIDS SELECT [ocms_tid] FROM [ocms_templates] WHERE [name] like @condition; END --output SELECT t.[ocms_tid],t.[name] FROM [dbo].[ocms_templates] as t JOIN @TIDS as tids ON t.[ocms_tid] = tids.ocms_tid; --select STUFF( -- (SELECT ',' + [name] as [text()] -- FROM [dbo].[ocms_templates] -- WHERE name like 'section%' -- FOR XML PATH, TYPE).value(N'.[1]', N'nvarchar(max)') -- ,1,1,'') END GO /****** Object: StoredProcedure [dbo].[ocms_getFullTree] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_getFullTree] @locale varchar(5) AS BEGIN /* FULL TREE is only intended for OCMS admin portal Hidden items will be shown ! */ SET NOCOUNT ON; -- get basics DECLARE @site bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE i.[parent_iid] is null); IF @site is null THROW 61110, 'site does not exist', 1; --get locales DECLARE @locales TABLE([locale] varchar(5), [order] int); INSERT INTO @locales SELECT * FROM [dbo].[ocms_locales](); -- calculate tree and paths DECLARE @itemtree TABLE( [ocms_iid] [bigint] NOT NULL, [parent_iid] [bigint] NULL, [ocms_pid] [bigint] NULL, [name] [nvarchar](255) NULL, [view] [bit] NOT NULL, [template_id] [bigint] NULL, [hide] [bit] NOT NULL, [order] [int] NOT NULL, [DateCreated] datetime null, [DateModified] datetime null, [level] int, [new_order] int ); WITH cteLevels as ( SELECT t.* , cast(0 as int) as [level] FROM [dbo].[ocms_items] t WHERE t.[ocms_iid] = @site UNION ALL SELECT t.* , CAST(c.[level] + 1 as int) as [level] FROM [dbo].[ocms_items] t inner JOIN cteLevels c on t.[parent_iid] = c.[ocms_iid] ) INSERT INTO @itemtree SELECT t.* , ROW_NUMBER() OVER (PARTITION BY [parent_iid] ORDER BY [order], [ocms_iid]) as [new_order] FROM cteLevels as t; --WHERE [hide] = 0; -- output site properties WITH SP As ( SELECT p.* , ROW_NUMBER() OVER (PARTITION BY p.[ocms_iid], p.[key] ORDER BY CAST((CASE WHEN p.[locale] = '*' THEN 1 ELSE 0 END) as int)) as 'rwi' FROM @itemtree as it JOIN [dbo].[ocms_properties] as p ON it.[ocms_iid] = p.[ocms_iid] WHERE it.[level] = 0 --site AND (p.[locale] = @locale OR p.[locale] = '*') ) SELECT it.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,tp.[type] FROM @itemtree as it FULL OUTER JOIN [dbo].[ocms_template_properties] as tp ON it.[template_id] = tp.[ocms_tid] FULL OUTER JOIN SP as p ON p.[ocms_iid] = it.[ocms_iid] AND (tp.[key] = p.[key] OR tp.[key] is null) AND p.[rwi] = 1 -- only the right language or fallback WHERE it.[level] = 0; -- output locales SELECT * FROM @locales; -- output children SELECT it.* ,p.[key] as 'property_key' ,p.[locale] as 'property_locale' ,tpl.[name] as 'template_name' ,ROW_NUMBER() OVER (PARTITION BY it.[parent_iid] ORDER BY IIF(it.[view] = 1, 0, 1), it.[ocms_pid], it.[ORDER], it.[ocms_iid]) as 'item_order' FROM @itemtree as it LEFT JOIN [dbo].[ocms_templates] as tpl on it.[template_id] = tpl.[ocms_tid] LEFT JOIN [dbo].[ocms_properties] as p on it.[ocms_pid] = p.[ocms_pid]; --only arrays -- output childrens' properties ONLY arrays SELECT it.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,p.locale ,tp.[type] FROM @itemtree as it JOIN [dbo].[ocms_template_properties] as tp ON it.[template_id] = tp.[ocms_tid] FULL OUTER JOIN [dbo].[ocms_properties] as p ON p.[ocms_iid] = it.[ocms_iid] AND (tp.[key] = p.[key] OR tp.[key] is null) WHERE ISNULL(ISNULL(tp.[key], p.[key]),'') <> '' AND tp.[type] = 'array'; END GO /****** Object: StoredProcedure [dbo].[ocms_getItem] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_getItem] @ocms_iid bigint AS BEGIN SET NOCOUNT ON; -- get basics DECLARE @site bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE i.[parent_iid] is null); IF @site is null THROW 61110, 'site does not exist', 1; --get locales DECLARE @locales TABLE([locale] varchar(5), [order] int); INSERT INTO @locales SELECT * FROM [dbo].[ocms_locales](); -- get viewtree and paths DECLARE @viewtree [dbo].[ocms_type_viewtree_full]; INSERT INTO @viewtree SELECT * FROM [dbo].[ocms_getFullViewTree](null, null) -- get full with all languages WHERE [ocms_iid] = @ocms_iid; -- only selected view --get itemtree DECLARE @itemtree [dbo].[ocms_type_itemtree]; INSERT INTO @itemtree SELECT * FROM [dbo].[ocms_getFullItemTree](@ocms_iid, 1); /*-----------------------------------------------------------------------------------------------------------------------------------------------------*/ -- output site properties SELECT t.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,tp.[type] FROM @itemtree as t FULL OUTER JOIN [dbo].[ocms_template_properties] as tp ON t.[template_id] = tp.[ocms_tid] FULL OUTER JOIN [dbo].[ocms_properties] as p ON p.[ocms_iid] = t.[ocms_iid] AND p.[value] is not null AND (tp.[key] = p.[key] OR tp.[key] is null) WHERE t.[level] = 0; -- output locales SELECT * FROM @locales; -- output item SELECT TOP(1) it.* ,p.[key] as 'property_key' ,p.[locale] as 'property_locale' ,tpl.[name] as 'template_name' ,ROW_NUMBER() OVER (PARTITION BY it.[parent_iid], it.[ocms_pid] ORDER BY it.[ORDER], it.[ocms_iid]) as 'item_order' FROM @itemtree as it --not necessary a view LEFT JOIN [dbo].[ocms_templates] as tpl on it.[template_id] = tpl.[ocms_tid] LEFT JOIN [dbo].[ocms_properties] as p on it.[ocms_pid] = p.ocms_pid and p.[value] is not null WHERE it.[ocms_iid] = @ocms_iid; -- item in focus -- output children SELECT it.* ,p.[key] as 'property_key' ,p.[locale] as 'property_locale' ,tpl.[name] as 'template_name' ,ROW_NUMBER() OVER (PARTITION BY it.[parent_iid], it.[ocms_pid] ORDER BY it.[ORDER], it.[ocms_iid]) as 'item_order' FROM @itemtree as it LEFT JOIN [dbo].[ocms_templates] as tpl on it.[template_id] = tpl.[ocms_tid] LEFT JOIN [dbo].[ocms_properties] as p on it.[ocms_pid] = p.ocms_pid and p.[value] is not null WHERE it.[ocms_iid] <> @ocms_iid AND it.[sub] = 1; -- output items properties WITH tp as ( SELECT tp_.*, ROW_NUMBER() OVER (ORDER BY tp_.[order], tp_.[ocms_tpid], tp_.[key]) as 'tpo', l.locale, l.[order] as [locorder] FROM [dbo].[ocms_template_properties] as tp_ CROSS JOIN @locales as l -- incl. fallback locale '*' ) SELECT it.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,tp.locale ,tp.[type] ,tp.[mandatory] ,IIF(tp.[type] <> 'array', tp.[condition], '') as [condition] ,ROW_NUMBER() OVER (ORDER BY it.[ocms_iid], tp.[tpo], p.[ocms_pid]) as [order] FROM @itemtree as it JOIN tp ON it.[template_id] = tp.[ocms_tid] FULL OUTER JOIN [dbo].[ocms_properties] as p ON p.[ocms_iid] = it.[ocms_iid] AND p.[value] is not null AND (tp.[key] = p.[key] OR tp.[key] is null) AND p.[locale] = tp.[locale] WHERE ISNULL(ISNULL(tp.[key], p.[key]),'') <> '' AND it.[ocms_iid] = @ocms_iid; -- output items navs WITH nav as ( select [ocms_iid], [locale], [alias] from [dbo].[ocms_navigation] as n WHERE ISNULL(n.[alias], '') <> '' AND n.[locale] <> '*' UNION SELECT i.[ocms_iid], l.[locale], i.[name] FROM [dbo].[ocms_items] as i CROSS JOIN @locales as l WHERE i.[parent_iid] = @site AND i.[name] = 'index' and l.[locale] <> '*' )SELECT l.[locale] ,n.[alias] ,vt.[path] FROM @viewtree as vt CROSS JOIN @locales as l LEFT JOIN nav as n ON vt.[ocms_iid] = n.[ocms_iid] AND l.[locale] = n.[locale] WHERE vt.[ocms_iid] = @ocms_iid AND l.[locale] <> '*'; END GO /****** Object: StoredProcedure [dbo].[ocms_getItem_byName] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_getItem_byName] @name nvarchar(255) AS BEGIN SET NOCOUNT ON; DECLARE @ocms_iid bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE [name] = @name); EXECUTE [dbo].[ocms_getItem] @ocms_iid; END GO /****** Object: StoredProcedure [dbo].[ocms_getView] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_getView] @view_path varchar(255) ,@locale varchar(5) AS BEGIN SET NOCOUNT ON; IF ISNULL(@locale, '') = '' SET @locale = 'de'; -- fallback IF ISNULL(@view_path, '') = '' SET @view_path = 'index'; -- get basics DECLARE @site bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE i.[parent_iid] is null); IF @site is null THROW 61110, 'site does not exist', 1; --get locales DECLARE @locales TABLE([locale] varchar(5), [order] int); INSERT INTO @locales SELECT * FROM [dbo].[ocms_locales](); -- get viewtree and paths DECLARE @view_iid bigint = null, @view_level int, @view_name nvarchar(255), @view_is_hidden bit; DECLARE @viewtree [dbo].[ocms_type_viewtree_full]; INSERT INTO @viewtree SELECT * FROM [dbo].[ocms_getFullViewTree](@view_path, null); -- any locale to be able to determine language from path SELECT TOP(1) @view_iid = it.[ocms_iid] , @view_level = it.[level] , @locale = it.[locale] -- will override the selected language , @view_name = it.[name] , @view_is_hidden = it.[hide] FROM @viewtree as it ORDER BY (CASE WHEN [focus] = 1 AND [locale] = @locale THEN 0 WHEN [focus] = 1 THEN 1 ELSE 2 END) ASC; --get itemtree DECLARE @itemtree [dbo].[ocms_type_itemtree]; INSERT INTO @itemtree SELECT * FROM [dbo].[ocms_getFullItemTree](@view_iid, @view_is_hidden); -- items are not localized --get properties DECLARE @PROP TABLE( [ocms_pid] [bigint] NOT NULL, [ocms_iid] [bigint] NOT NULL, [key] [varchar](50) NULL, [value] [nvarchar](max) NOT NULL, [DateModified] [datetime] NULL ); WITH SP As ( SELECT p.* ,it.[focus] ,it.[level] , ROW_NUMBER() OVER (PARTITION BY p.[ocms_iid], p.[key] ORDER BY CAST((CASE WHEN p.[locale] = '*' THEN 1 ELSE 0 END) as int)) as 'rwi' FROM @itemtree as it JOIN [dbo].[ocms_properties] as p ON it.[ocms_iid] = p.[ocms_iid] WHERE (it.[level] = 0 --site OR it.[sub] = 1 OR it.[sitepropsub] = 1 OR it.[focus] = 1 OR it.[parent_iid] = @site) -- or itms below selected AND (p.[locale] = @locale OR p.[locale] = '*') ) INSERT INTO @PROP SELECT [ocms_pid],[ocms_iid],[key],[value],[DateModified] FROM SP WHERE rwi = 1; DECLARE @translations TABLE ( [ocms_tln] [bigint] NOT NULL, [context_typ] [nvarchar](15) NOT NULL, [context] [bigint] NULL, [value] [nvarchar](255) NOT NULL, [translation] [nvarchar](255) NOT NULL, [locale] [varchar](5) NOT NULL ); /* outputs *********************************************************************************************************************************************************/ -- output nav SELECT vt.[ocms_iid] ,[parent_iid] ,vt.[ocms_pid] ,[name] ,ISNULL(p.[value], vt.[name]) as [title] ,[view] ,[template_id] ,[hide] ,[new_order] as [order] , [path], [level], [sub], [focus], [nav] FROM @viewtree as vt -- vt must be filtered by locale LEFT JOIN [dbo].[ocms_properties] as p ON vt.[ocms_iid] = p.[ocms_iid] AND p.[key] = 'title' AND p.[locale] = vt.[locale] -- ! localized WHERE [nav] = 1 AND vt.[locale] = @locale; -- output site properties SELECT vt.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,tp.[type] FROM @viewtree as vt -- site is part if viewtree // -- vt must be filtered by locale FULL OUTER JOIN [dbo].[ocms_template_properties] as tp ON vt.[template_id] = tp.[ocms_tid] FULL OUTER JOIN @PROP as p ON p.[ocms_iid] = vt.[ocms_iid] AND (tp.[key] = p.[key] OR tp.[key] is null) -- properties are ! localized, but already filtered for @PROP WHERE vt.[ocms_iid] = @site AND vt.[locale] = @locale UNION SELECT NULL as [ocms_iid] ,NULL as [ocms_pid] ,'DateModified' as [key] ,FORMAT((SELECT MAX([DateModified]) FROM @PROP),'yyyy-MM-ddTHH:mm:ssZ') as [value] ,'string'; INSERT INTO @translations SELECT * from [dbo].[ocms_translations] as TL WHERE TL.[context_typ] = 'site' AND TL.[locale] = @locale; -- output locales WITH pd as (SELECT DISTINCT [ocms_iid], [path], [locale] FROM @viewtree WHERE [ocms_iid] = @view_iid) SELECT pd.* , CAST(IIF(l.[locale] = @locale, 1, 0) as bit) as 'active' FROM @locales as l JOIN pd ON l.[locale] = pd.[locale] WHERE l.[locale] <> '*'; -- output view properties SELECT vt.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,tp.[type] FROM @viewtree as vt -- vt must be filtered by locale FULL OUTER JOIN [dbo].[ocms_template_properties] as tp ON vt.[template_id] = tp.[ocms_tid] FULL OUTER JOIN @PROP as p ON p.[ocms_iid] = vt.[ocms_iid] AND (tp.[key] = p.[key] OR tp.[key] is null) -- properties are ! localized, but already filtered for @PROP WHERE vt.[focus] = 1 AND ISNULL(ISNULL(tp.[key], p.[key]),'') <> '' AND vt.[locale] = @locale; INSERT INTO @translations SELECT * from [dbo].[ocms_translations] as TL WHERE TL.[context] = @view_iid AND TL.[locale] = @locale; --context = 'view' and all other context_types -- output children SELECT it.* ,tpl.[partial_view] ,tpl.[name] as [template_name] ,ROW_NUMBER() OVER (PARTITION BY it.[parent_iid], it.[ocms_pid] ORDER BY it.[ORDER], it.[ocms_iid]) as 'item_order' FROM @itemtree as it -- items are not localized LEFT JOIN [dbo].[ocms_templates] as tpl on it.[template_id] = tpl.[ocms_tid] WHERE [sub] = 1 OR [sitepropsub] = 1 OR it.[parent_iid] = @site; --to include also site relevant children INSERT INTO @translations SELECT TL.* from @itemtree as it JOIN [dbo].[ocms_translations] as TL ON TL.[context_typ] = 'template' AND TL.[context] = it.[template_id] AND TL.[locale] = @locale; -- output childrens' properties SELECT it.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,tp.[type] FROM @itemtree as it -- items are not localized JOIN [dbo].[ocms_template_properties] as tp ON it.[template_id] = tp.[ocms_tid] -- properties are ! localized, but already filtered for @PROP FULL OUTER JOIN @PROP as p ON p.[ocms_iid] = it.[ocms_iid] AND (tp.[key] = p.[key] OR tp.[key] is null) WHERE ([sub] = 1 OR [sitepropsub] = 1 OR it.[parent_iid] = @site) AND [focus] = 0 AND ISNULL(ISNULL(tp.[key], p.[key]),'') <> ''; --output translations SELECT DISTINCT * FROM @translations; --output breadcrumbs WITH vws as( SELECT vt.[ocms_iid], [parent_iid], ISNULL(p.[value], vt.[name]) as [title], [path] FROM @viewtree as vt -- vt must be filtered by locale LEFT JOIN [dbo].[ocms_properties] as p ON vt.[ocms_iid] = p.[ocms_iid] AND p.[key] = 'title' AND p.[locale] = vt.[locale] -- ! localized ) , cte as ( SELECT vws.*, [title] as [breadcrumb], 0 as [level] FROM vws WHERE vws.[ocms_iid] = @view_iid UNION ALL SELECT vws.*, ( vws.[title] + ' > ' + cte.[breadcrumb]) as [breadcrumb] , [level] + 1 as [level] FROM vws JOIN cte ON vws.[ocms_iid] = cte.[parent_iid] ) select [title] , [path] , CASE WHEN [level] = 0 THEN (SELECT TOP(1) [breadcrumb] FROM cte as cte1 ORDER BY [level] DESC) ELSE NULL END as [breadcrumb] , ROW_NUMBER() OVER (ORDER BY [level] DESC) as [order] FROM cte; END GO /****** Object: StoredProcedure [dbo].[ocms_getView_byName] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_getView_byName] @name nvarchar(255) ,@locale varchar(5) ,@include_hidden bit AS BEGIN SET NOCOUNT ON; IF ISNULL(@locale, '') = '' SET @locale = 'de'; -- fallback DECLARE @view_path varchar(255) = 'index'; -- get basics DECLARE @site bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE i.[parent_iid] is null); IF @site is null THROW 61110, 'site does not exist', 1; --get locales DECLARE @locales TABLE([locale] varchar(5), [order] int); INSERT INTO @locales SELECT * FROM [dbo].[ocms_locales](); -- get viewtree and paths DECLARE @view_iid bigint = null, @view_level int, @view_name nvarchar(255); DECLARE @viewtree [dbo].[ocms_type_viewtree_full]; INSERT INTO @viewtree SELECT * FROM [dbo].[ocms_getFullViewTree](@view_path, null); -- any locale to be able to determine language from path DECLARE @tgt_ocms_iid bigint = (SELECT TOP(1) [ocms_iid] FROM [dbo].[ocms_items] as i WHERE [name] = @name and (i.[hide] = 0 OR @include_hidden = 1)); SELECT TOP(1) @view_iid = it.[ocms_iid] , @view_level = it.[level] , @locale = it.[locale] -- will override the selected language , @view_name = it.[name] FROM @viewtree as it WHERE it.[ocms_iid] = @tgt_ocms_iid ORDER BY (CASE WHEN [focus] = 1 AND [locale] = @locale THEN 0 WHEN [focus] = 1 THEN 1 ELSE 2 END) ASC; --get itemtree DECLARE @itemtree [dbo].[ocms_type_itemtree]; INSERT INTO @itemtree SELECT * FROM [dbo].[ocms_getFullItemTree](@view_iid, @include_hidden); -- items are not localized --get properties DECLARE @PROP TABLE( [ocms_pid] [bigint] NOT NULL, [ocms_iid] [bigint] NOT NULL, [key] [varchar](50) NULL, [value] [nvarchar](max) NOT NULL, [DateModified] [datetime] NULL ); WITH SP As ( SELECT p.* ,it.[focus] ,it.[level] , ROW_NUMBER() OVER (PARTITION BY p.[ocms_iid], p.[key] ORDER BY CAST((CASE WHEN p.[locale] = '*' THEN 1 ELSE 0 END) as int)) as 'rwi' FROM @itemtree as it JOIN [dbo].[ocms_properties] as p ON it.[ocms_iid] = p.[ocms_iid] WHERE (it.[level] = 0 --site OR it.[sub] = 1 OR it.[sitepropsub] = 1 OR it.[focus] = 1 OR it.[parent_iid] = @site) -- or itms below selected AND (p.[locale] = @locale OR p.[locale] = '*') ) INSERT INTO @PROP SELECT [ocms_pid],[ocms_iid],[key],[value],[DateModified] FROM SP WHERE rwi = 1; DECLARE @translations TABLE ( [ocms_tln] [bigint] NOT NULL, [context_typ] [nvarchar](15) NOT NULL, [context] [bigint] NULL, [value] [nvarchar](255) NOT NULL, [translation] [nvarchar](255) NOT NULL, [locale] [varchar](5) NOT NULL ); /* outputs *********************************************************************************************************************************************************/ -- output nav SELECT vt.[ocms_iid] ,[parent_iid] ,vt.[ocms_pid] ,[name] ,ISNULL(p.[value], vt.[name]) as [title] ,[view] ,[template_id] ,[hide] ,[new_order] as [order] , [path], [level], [sub], [focus], [nav] FROM @viewtree as vt -- vt must be filtered by locale LEFT JOIN [dbo].[ocms_properties] as p ON vt.[ocms_iid] = p.[ocms_iid] AND p.[key] = 'title' AND p.[locale] = vt.[locale] -- ! localized WHERE [nav] = 1 AND vt.[locale] = @locale; -- output site properties SELECT vt.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,tp.[type] FROM @viewtree as vt -- site is part if viewtree // -- vt must be filtered by locale FULL OUTER JOIN [dbo].[ocms_template_properties] as tp ON vt.[template_id] = tp.[ocms_tid] FULL OUTER JOIN @PROP as p ON p.[ocms_iid] = vt.[ocms_iid] AND (tp.[key] = p.[key] OR tp.[key] is null) -- properties are ! localized, but already filtered for @PROP WHERE vt.[ocms_iid] = @site AND vt.[locale] = @locale UNION SELECT NULL as [ocms_iid] ,NULL as [ocms_pid] ,'DateModified' as [key] ,FORMAT((SELECT MAX([DateModified]) FROM @PROP),'yyyy-MM-ddTHH:mm:ssZ') as [value] ,'string'; INSERT INTO @translations SELECT * from [dbo].[ocms_translations] as TL WHERE TL.[context_typ] = 'site' AND TL.[locale] = @locale; -- output locales WITH pd as (SELECT DISTINCT [ocms_iid], [path], [locale] FROM @viewtree WHERE [ocms_iid] = @view_iid) SELECT pd.* , CAST(IIF(l.[locale] = @locale, 1, 0) as bit) as 'active' FROM @locales as l JOIN pd ON l.[locale] = pd.[locale] WHERE l.[locale] <> '*'; -- output view properties SELECT vt.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,tp.[type] FROM @viewtree as vt -- vt must be filtered by locale FULL OUTER JOIN [dbo].[ocms_template_properties] as tp ON vt.[template_id] = tp.[ocms_tid] FULL OUTER JOIN @PROP as p ON p.[ocms_iid] = vt.[ocms_iid] AND (tp.[key] = p.[key] OR tp.[key] is null) -- properties are ! localized, but already filtered for @PROP WHERE vt.[focus] = 1 AND ISNULL(ISNULL(tp.[key], p.[key]),'') <> '' AND vt.[locale] = @locale; INSERT INTO @translations SELECT * from [dbo].[ocms_translations] as TL WHERE TL.[context] = @view_iid AND TL.[locale] = @locale; --context = 'view' and all other context_types -- output children SELECT it.* ,tpl.[partial_view] ,tpl.[name] as [template_name] ,ROW_NUMBER() OVER (PARTITION BY it.[parent_iid], it.[ocms_pid] ORDER BY it.[ORDER], it.[ocms_iid]) as 'item_order' FROM @itemtree as it -- items are not localized LEFT JOIN [dbo].[ocms_templates] as tpl on it.[template_id] = tpl.[ocms_tid] WHERE [sub] = 1 OR [sitepropsub] = 1 OR it.[parent_iid] = @site; --to include also site relevant children INSERT INTO @translations SELECT TL.* from @itemtree as it JOIN [dbo].[ocms_translations] as TL ON TL.[context_typ] = 'template' AND TL.[context] = it.[template_id] AND TL.[locale] = @locale; -- output childrens' properties SELECT it.[ocms_iid] ,p.[ocms_pid] ,ISNULL(tp.[key], p.[key]) as [key] ,IIF(ISNULL(tp.[mandatory],0) = 0, p.[value], ISNULL(p.[value],'')) as [value] ,tp.[type] FROM @itemtree as it -- items are not localized JOIN [dbo].[ocms_template_properties] as tp ON it.[template_id] = tp.[ocms_tid] -- properties are ! localized, but already filtered for @PROP FULL OUTER JOIN @PROP as p ON p.[ocms_iid] = it.[ocms_iid] AND (tp.[key] = p.[key] OR tp.[key] is null) WHERE ([sub] = 1 OR [sitepropsub] = 1 OR it.[parent_iid] = @site) AND [focus] = 0 AND ISNULL(ISNULL(tp.[key], p.[key]),'') <> ''; --output translations SELECT DISTINCT * FROM @translations; --output breadcrumbs WITH vws as( SELECT vt.[ocms_iid], [parent_iid], ISNULL(p.[value], vt.[name]) as [title], [path] FROM @viewtree as vt -- vt must be filtered by locale LEFT JOIN [dbo].[ocms_properties] as p ON vt.[ocms_iid] = p.[ocms_iid] AND p.[key] = 'title' AND p.[locale] = vt.[locale] -- ! localized ) , cte as ( SELECT vws.*, [title] as [breadcrumb], 0 as [level] FROM vws WHERE vws.[ocms_iid] = @view_iid UNION ALL SELECT vws.*, ( vws.[title] + ' > ' + cte.[breadcrumb]) as [breadcrumb] , [level] + 1 as [level] FROM vws JOIN cte ON vws.[ocms_iid] = cte.[parent_iid] ) select [title] , [path] , CASE WHEN [level] = 0 THEN (SELECT TOP(1) [breadcrumb] FROM cte as cte1 ORDER BY [level] DESC) ELSE NULL END as [breadcrumb] , ROW_NUMBER() OVER (ORDER BY [level] DESC) as [order] FROM cte; END GO /****** Object: StoredProcedure [dbo].[ocms_merge_navigation] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_merge_navigation] @newnav [dbo].[ocms_type_navigation_base] READONLY AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- update nav table UPDATE n SET n.[parent_iid] = i.[parent_iid] FROM [dbo].[ocms_navigation] as n JOIN [ocms_items] as i ON n.[ocms_iid] = i.[ocms_iid]; -- merge nav WITH np as ( -- make sure nav are allowed by locales and path constraints SELECT n.* ,i.[parent_iid] FROM @newnav as n JOIN [dbo].[ocms_items] as i ON n.[ocms_iid] = i.[ocms_iid] AND [view] = 1 FULL OUTER JOIN [dbo].[ocms_locales]() as l on n.[locale] = l.[locale] AND l.[locale] <> '*' WHERE NOT EXISTS (SELECT * FROM [dbo].[ocms_navigation] as cn WHERE cn.[parent_iid] = i.[parent_iid] AND cn.[alias] = n.[alias] AND [cn].[ocms_iid] <> n.[ocms_iid]) AND i.[name] <> 'index' -- nav not allowed for index AND n.[alias] not in ('index') -- keyword index not allowed ) MERGE [dbo].[ocms_navigation] as TARGET USING np as SOURCE ON TARGET.[locale] = SOURCE.[locale] AND TARGET.[ocms_iid] = SOURCE.[ocms_iid] WHEN MATCHED AND SOURCE.[alias] is null THEN DELETE WHEN MATCHED THEN UPDATE SET [alias] = LOWER(SOURCE.[alias]) WHEN NOT MATCHED BY TARGET THEN INSERT ([ocms_iid], [locale], [alias]) VALUES (SOURCE.[ocms_iid], SOURCE.[locale], LOWER(SOURCE.[alias])); END GO /****** Object: StoredProcedure [dbo].[ocms_merge_properties] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_merge_properties] @newprop [dbo].[ocms_type_properties_base] READONLY AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; DECLARE @lastpid int = ISNULL ( (SELECT MAX(ISNULL(p.[ocms_pid], ap.[ocms_pid])) FROM [dbo].[ocms_properties] as p FULL OUTER JOIN [ocms_archive__properties] as ap on p.[ocms_pid] = ap.[ocms_pid]) ,0); WITH np as ( -- make sure properties are allowed by templates SELECT [pid] = isnull(pp.[ocms_pid], ROW_NUMBER() OVER (PARTITION BY pp.[ocms_pid] order BY tp.[ocms_tpid], n.[key]) + @lastpid) ,n.* ,tp.[type] FROM @newprop as n JOIN [dbo].[ocms_items] as i ON n.[ocms_iid] = i.[ocms_iid] JOIN [dbo].[ocms_templates] as t ON i.[template_id] = t.[ocms_tid] JOIN [dbo].[ocms_template_properties] as tp ON t.[ocms_tid] = tp.[ocms_tid] AND n.[key] = tp.[key] LEFT JOIN [dbo].[ocms_properties] as pp ON pp.[key] = n.[key] and pp.[locale] = n.[locale] AND pp.[ocms_iid] = n.[ocms_iid] ) MERGE [dbo].[ocms_properties] as TARGET USING np as SOURCE ON TARGET.[key] = SOURCE.[key] and TARGET.[locale] = SOURCE.[locale] AND TARGET.[ocms_iid] = SOURCE.[ocms_iid] WHEN MATCHED AND ISNULL(SOURCE.[value], '') = '' AND SOURCE.[type] <> 'array' THEN DELETE WHEN MATCHED AND TARGET.[Value] <> SOURCE.[value] THEN UPDATE SET [value] = SOURCE.[value], [DateModified] = GETUTCDATE() WHEN NOT MATCHED BY TARGET THEN INSERT ([ocms_pid], [ocms_iid], [key], [value], [locale], [DateCreated], [DateModified]) VALUES (SOURCE.[pid], SOURCE.[ocms_iid], SOURCE.[key], SOURCE.[value], SOURCE.[locale], GETUTCDATE(), GETUTCDATE()) OUTPUT ISNULL(inserted.[ocms_pid], deleted.[ocms_pid]), $action, inserted.[ocms_iid], inserted.[key], inserted.[value], inserted.[locale], inserted.[DateCreated], inserted.[DateModified], NULL, NULL, deleted.[ocms_iid], deleted.[key], deleted.[value], deleted.[locale], deleted.[DateCreated], deleted.[DateModified], NULL, NULL INTO [dbo].[ocms_log__properties] ; END GO /****** Object: StoredProcedure [dbo].[ocms_recoverItem] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_recoverItem] @ocms_iid bigint AS BEGIN SET NOCOUNT ON; SET IDENTITY_INSERT [dbo].[ocms_items] ON; insert into ocms_items ([ocms_iid] ,[parent_iid] ,[ocms_pid] ,[name] ,[view] ,[template_id] ,[hide] ,[order] ,[DateCreated] ,[DateModified]) select [ocms_iid] ,[parent_iid] ,[ocms_pid] ,[name] ,[view] ,[template_id] ,[hide] ,[order] ,[DateCreated] ,[DateModified] from ocms_archive__items where ocms_iid = @ocms_iid SET IDENTITY_INSERT [dbo].[ocms_items] OFF; SET IDENTITY_INSERT [dbo].[ocms_properties] ON; insert into ocms_properties ([ocms_pid] ,[ocms_iid] ,[key] ,[value] ,[locale] ,[DateCreated] ,[DateModified]) select [ocms_pid] ,[ocms_iid] ,[key] ,[value] ,[locale] ,[DateCreated] ,[DateModified] from ocms_archive__properties where ocms_iid = @ocms_iid SET IDENTITY_INSERT [dbo].[ocms_properties] OFF; END GO /****** Object: StoredProcedure [dbo].[ocms_setItemName] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_setItemName] @ocms_iid bigint, @name nvarchar(255) AS BEGIN SET NOCOUNT ON; IF NOT EXISTS (SELECT * FROM [dbo].[ocms_items] WHERE [ocms_iid] = @ocms_iid) THROW 61110, 'item does not exist', 1; IF EXISTS (SELECT * FROM [dbo].[ocms_items] WHERE [ocms_iid] = @ocms_iid AND [name] = 'index') THROW 61110, 'index cannot be renamed', 1; IF ISNULL(@name, '') = '' THROW 61010, 'name missing', 1; IF EXISTS (SELECT * FROM [dbo].[ocms_items] WHERE [name] = @name AND [ocms_iid] <> @ocms_iid) THROW 61110, 'name already exists', 1; DECLARE @OUTPUT TABLE ([ocms_iid] bigint, [name] nvarchar(255)); UPDATE i SET [name] = @name ,[DateModified] = GETUTCDATE() OUTPUT inserted.[ocms_iid], inserted.[name] INTO @OUTPUT FROM [dbo].[ocms_items] as i WHERE i.[ocms_iid] = @ocms_iid; SELECT TOP(1) * FROM @OUTPUT; END GO /****** Object: StoredProcedure [dbo].[ocms_setItemOrder] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_setItemOrder] @ocms_iid_csv varchar(2000) AS BEGIN SET NOCOUNT ON; DECLARE @neworder TABLE([ocms_iid] bigint, [order] int); DECLARE @c char(1) = ','; --delimiter INSERT INTO @neworder SELECT value, idx = ROW_NUMBER() OVER (ORDER BY CHARINDEX(@c + value + @c, @c + @ocms_iid_csv + @c)) FROM STRING_SPLIT(@ocms_iid_csv, ','); DECLARE @parents TABLE([parent_iid] bigint); INSERT INTO @parents SELECT DISTINCT [parent_iid] FROM [dbo].[ocms_items] as i JOIN @neworder as no ON i.[ocms_iid] = no.[ocms_iid] WHERE i.[parent_iid] is not null; select * from @parents IF (SELECT COUNT(*) FROM @parents) <> 1 THROW 61010, 'order can only be set for exact one parent', 1; DECLARE @parent_iid bigint = (SELECT TOP(1) [parent_iid] FROM @parents); UPDATE i SET [order] = ISNULL(no.[order], 999) OUTPUT inserted.[ocms_iid], inserted.[order] FROM [dbo].[ocms_items] as i LEFT JOIN @neworder as no ON i.[ocms_iid] = no.[ocms_iid] WHERE i.[parent_iid] = @parent_iid; END GO /****** Object: StoredProcedure [dbo].[ocms_setViewItem_HiddenStatus] Script Date: 15.06.2021 12:30:14 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: -- Create date: -- Description: -- ============================================= CREATE PROCEDURE [dbo].[ocms_setViewItem_HiddenStatus] @ocms_iid bigint, @hidden bit AS BEGIN SET NOCOUNT ON; IF NOT EXISTS (SELECT * FROM [dbo].[ocms_items] WHERE [ocms_iid] = @ocms_iid) THROW 61110, 'item does not exist', 1; IF NOT EXISTS (SELECT * FROM [dbo].[ocms_items] WHERE [ocms_iid] = @ocms_iid AND [view] = 1) THROW 61110, 'item is not a view', 1; DECLARE @OUTPUT TABLE ([ocms_iid] bigint, [name] nvarchar(255), [hide] bit); UPDATE i SET i.[hide] = @hidden OUTPUT inserted.[ocms_iid], inserted.[name], inserted.[hide] INTO @OUTPUT FROM [dbo].[ocms_items] as i WHERE i.[ocms_iid] = @ocms_iid AND [view] = 1; SELECT TOP(1) * FROM @OUTPUT; END GO USE [master] GO ALTER DATABASE [site_fuchs] SET READ_WRITE GO