Files
Fuchs_Intranet/hlp/20210518 1718 __site_fuchs_script.sql

10918 lines
845 KiB
Transact-SQL

USE [master]
GO
/****** Object: Database [site_fuchs] Script Date: 18.05.2021 17:19:26 ******/
CREATE DATABASE [site_fuchs]
CONTAINMENT = NONE
ON PRIMARY
( NAME = N'site_fuchs', FILENAME = N'C:\DATA\MSSQL14.SQL\MSSQL\DATA\site_fuchs.mdf' , SIZE = 528384KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
LOG ON
( NAME = N'site_fuchs_log', FILENAME = N'C:\DATA\MSSQL14.SQL\MSSQL\DATA\site_fuchs_log.ldf' , SIZE = 6166080KB , 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: 18.05.2021 17:19:26 ******/
CREATE USER [fuchs_web] FOR LOGIN [fuchs_web] WITH DEFAULT_SCHEMA=[dbo]
GO
/****** Object: User [fuchs_fds] Script Date: 18.05.2021 17:19:26 ******/
CREATE USER [fuchs_fds] FOR LOGIN [fuchs_fds] WITH DEFAULT_SCHEMA=[dbo]
GO
/****** Object: DatabaseRole [ocms_rwe] Script Date: 18.05.2021 17:19:26 ******/
CREATE ROLE [ocms_rwe]
GO
/****** Object: DatabaseRole [fuchs_rwe] Script Date: 18.05.2021 17:19:26 ******/
CREATE ROLE [fuchs_rwe]
GO
/****** Object: DatabaseRole [fds_rwe] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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].[mfr__tt__#customvalues] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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].[date_monthend] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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__getUpdateableTables] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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__updateNeed] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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_getUserGroupList] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <Description, ,>
-- =============================================
CREATE FUNCTION [dbo].[mfr__schema]
(
)
RETURNS XML
AS
BEGIN
DECLARe @AS XML;
SET @AS = N'
<Schema>
<EntityType Name="ItemType">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="CustomValues" Type="Collection(MFR.Domain.Api.Documents.CustomValue)" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Costs" Type="Edm.Decimal" Nullable="false" />
<Property Name="Description" Type="Edm.String" />
<Property Name="ListPrice" Type="Edm.Decimal" Nullable="false" />
<Property Name="Manufacture" Type="Edm.String" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="ItemNumber" Type="Edm.String" />
<Property Name="NameOrNumber" Type="Edm.String" />
<Property Name="GlobalTradeItemNr" Type="Edm.String" />
<Property Name="Type" Type="Edm.String" />
<Property Name="Price" Type="Edm.Decimal" Nullable="false" />
<Property Name="VAT" Type="Edm.Decimal" Nullable="false" />
<Property Name="IsPortalOnly" Type="Edm.Boolean" Nullable="false" />
<Property Name="Discount" Type="Edm.Decimal" Nullable="false" />
<Property Name="DateModified" Type="Edm.DateTime" Nullable="false" />
<Property Name="IsDiscontinued" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsWarehouse" Type="Edm.Boolean" Nullable="false" />
<Property Name="UnitId" Type="Edm.Int64" />
<Property Name="UnitString" Type="Edm.String" />
<NavigationProperty Name="Unit" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ItemType_Unit_MFR_Domain_Api_Documents_ItemUnit_UnitPartner" ToRole="Unit" FromRole="UnitPartner" />
</EntityType>
<ComplexType Name="CustomValue">
<Property Name="Meta" Type="Edm.String" />
<Property Name="Value" Type="Edm.String" />
</ComplexType>
<EntityType Name="ServiceRequest">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="InvoiceId" Type="Edm.String" />
<Property Name="ClosedAt" Type="Edm.DateTime" />
<Property Name="ReleasedAt" Type="Edm.DateTime" />
<Property Name="WorkDoneAt" Type="Edm.DateTime" />
<Property Name="TargetTimeInMinutes" Type="Edm.Int64" Nullable="false" />
<Property Name="DateModified" Type="Edm.DateTime" />
<Property Name="DateOfCreation" Type="Edm.DateTime" />
<Property Name="DueDateRangeStart" Type="Edm.DateTime" />
<Property Name="DueDateRangeEnd" Type="Edm.DateTime" />
<Property Name="PortalLink" Type="Edm.String" />
<Property Name="CostCenterId" Type="Edm.Int64" />
<Property Name="Description" Type="Edm.String" />
<Property Name="State" Type="Edm.String" />
<Property Name="CustomValues" Type="Collection(MFR.Domain.Api.Documents.CustomValue)" Nullable="false" />
<Property Name="CurrentOwnerId" Type="Edm.Int64" />
<Property Name="CustomerId" Type="Edm.Int64" />
<Property Name="ParentServiceRequestId" Type="Edm.Int64" />
<Property Name="Location" Type="MFR.Domain.Api.Documents.Location" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="IsTemplate" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsTemplateMobile" Type="Edm.Boolean" Nullable="false" />
<Property Name="CreateFromServiceRequestTemplateId" Type="Edm.Int64" Nullable="false" />
<Property Name="Type" Type="Edm.String" />
<NavigationProperty Name="CreatedBy" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_CreatedBy_MFR_Domain_Api_Documents_Contact_CreatedByPartner" ToRole="CreatedBy" FromRole="CreatedByPartner" />
<NavigationProperty Name="ClosedBy" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_ClosedBy_MFR_Domain_Api_Documents_User_ClosedByPartner" ToRole="ClosedBy" FromRole="ClosedByPartner" />
<NavigationProperty Name="ReleasedBy" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_ReleasedBy_MFR_Domain_Api_Documents_User_ReleasedByPartner" ToRole="ReleasedBy" FromRole="ReleasedByPartner" />
<NavigationProperty Name="CostCenter" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_CostCenter_MFR_Domain_Api_Documents_CostCenter_CostCenterPartner" ToRole="CostCenter" FromRole="CostCenterPartner" />
<NavigationProperty Name="Appointments" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Appointments_MFR_Domain_Api_Documents_Appointment_AppointmentsPartner" ToRole="Appointments" FromRole="AppointmentsPartner" />
<NavigationProperty Name="Items" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Items_MFR_Domain_Api_Documents_Item_ItemsPartner" ToRole="Items" FromRole="ItemsPartner" />
<NavigationProperty Name="Documents" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Documents_MFR_Domain_Api_Documents_Document_DocumentsPartner" ToRole="Documents" FromRole="DocumentsPartner" />
<NavigationProperty Name="Reports" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Reports_MFR_Domain_Api_Documents_Report_ReportsPartner" ToRole="Reports" FromRole="ReportsPartner" />
<NavigationProperty Name="Contacts" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner" ToRole="Contacts" FromRole="ContactsPartner" />
<NavigationProperty Name="StepListTemplates" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_StepListTemplates_MFR_Domain_Api_Documents_StepListTemplate_StepListTemplatesPartner" ToRole="StepListTemplates" FromRole="StepListTemplatesPartner" />
<NavigationProperty Name="ServiceObjects" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_ServiceObjects_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectsPartner" ToRole="ServiceObjects" FromRole="ServiceObjectsPartner" />
<NavigationProperty Name="TimeEvents" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_TimeEvents_MFR_Domain_Api_Documents_TimeEvent_TimeEventsPartner" ToRole="TimeEvents" FromRole="TimeEventsPartner" />
<NavigationProperty Name="Comments" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Comments_MFR_Domain_Api_Documents_Comment_CommentsPartner" ToRole="Comments" FromRole="CommentsPartner" />
<NavigationProperty Name="CurrentOwner" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_CurrentOwner_MFR_Domain_Api_Documents_Contact_CurrentOwnerPartner" ToRole="CurrentOwner" FromRole="CurrentOwnerPartner" />
<NavigationProperty Name="Customer" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Customer_MFR_Domain_Api_Documents_Company_CustomerPartner" ToRole="Customer" FromRole="CustomerPartner" />
<NavigationProperty Name="Tags" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Tags_MFR_Domain_Api_Documents_Tag_TagsPartner" ToRole="Tags" FromRole="TagsPartner" />
<NavigationProperty Name="Steps" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Steps_MFR_Domain_Api_Documents_Step_StepsPartner" ToRole="Steps" FromRole="StepsPartner" />
<NavigationProperty Name="StockMovements" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_StockMovements_MFR_Domain_Api_Documents_StockMovement_StockMovementsPartner" ToRole="StockMovements" FromRole="StockMovementsPartner" />
<NavigationProperty Name="Qualifications" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Qualifications_MFR_Domain_Api_Documents_Qualification_QualificationsPartner" ToRole="Qualifications" FromRole="QualificationsPartner" />
</EntityType>
<EntityType Name="Item">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="QuantityHours" Type="Edm.Decimal" Nullable="false" />
<Property Name="PlannedQuantityHours" Type="Edm.Decimal" Nullable="false" />
<Property Name="ItemTypeId" Type="Edm.Int64" />
<Property Name="ItemNumber" Type="Edm.String" />
<Property Name="TrackingId" Type="Edm.String" />
<Property Name="Manufacture" Type="Edm.String" />
<Property Name="Price" Type="Edm.Decimal" Nullable="false" />
<Property Name="Costs" Type="Edm.Decimal" />
<Property Name="NameOrNumber" Type="Edm.String" />
<Property Name="CustomValues" Type="Collection(MFR.Domain.Api.Documents.CustomValue)" Nullable="false" />
<Property Name="Note" Type="Edm.String" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="Discount" Type="Edm.Decimal" Nullable="false" />
<Property Name="VAT" Type="Edm.Decimal" Nullable="false" />
<Property Name="IsManual" Type="Edm.Boolean" Nullable="false" />
<Property Name="SortOrder" Type="Edm.Int32" Nullable="false" />
<Property Name="Type" Type="Edm.String" />
<Property Name="ServiceRequestId" Type="Edm.Int64" Nullable="false" />
<Property Name="ServiceObjectId" Type="Edm.Int64" Nullable="false" />
<Property Name="CreatorId" Type="Edm.Int64" Nullable="false" />
<Property Name="UnitId" Type="Edm.Int64" />
<Property Name="UnitString" Type="Edm.String" />
<NavigationProperty Name="ItemType" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_ItemType_MFR_Domain_Api_Documents_ItemType_ItemTypePartner" ToRole="ItemType" FromRole="ItemTypePartner" />
<NavigationProperty Name="ServiceRequest" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner" ToRole="ServiceRequest" FromRole="ServiceRequestPartner" />
<NavigationProperty Name="ServiceObject" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartner" ToRole="ServiceObject" FromRole="ServiceObjectPartner" />
<NavigationProperty Name="Creator" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_Creator_MFR_Domain_Api_Documents_Contact_CreatorPartner" ToRole="Creator" FromRole="CreatorPartner" />
<NavigationProperty Name="Unit" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_Unit_MFR_Domain_Api_Documents_ItemUnit_UnitPartner" ToRole="Unit" FromRole="UnitPartner" />
</EntityType>
<EntityType Name="StockMovement">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Amount" Type="Edm.Decimal" Nullable="false" />
<Property Name="AmountReceived" Type="Edm.Decimal" Nullable="false" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="ItemId" Type="Edm.Int64" />
<Property Name="ItemTypeId" Type="Edm.Int64" />
<Property Name="StockMovementType" Type="Edm.String" />
<Property Name="State" Type="Edm.String" />
<Property Name="ServiceRequestId" Type="Edm.Int64" Nullable="false" />
<Property Name="WarehouseId" Type="Edm.Int64" Nullable="false" />
<Property Name="DateOfCreation" Type="Edm.DateTime" Nullable="false" />
<Property Name="DateModified" Type="Edm.DateTime" Nullable="false" />
<Property Name="TargetDate" Type="Edm.DateTime" Nullable="false" />
<Property Name="CreatedById" Type="Edm.Int64" Nullable="false" />
<Property Name="ConfirmedById" Type="Edm.Int64" Nullable="false" />
<NavigationProperty Name="Item" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_Item_MFR_Domain_Api_Documents_Item_ItemPartner" ToRole="Item" FromRole="ItemPartner" />
<NavigationProperty Name="ItemType" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_ItemType_MFR_Domain_Api_Documents_ItemType_ItemTypePartner" ToRole="ItemType" FromRole="ItemTypePartner" />
<NavigationProperty Name="ServiceRequest" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner" ToRole="ServiceRequest" FromRole="ServiceRequestPartner" />
<NavigationProperty Name="Warehouse" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_Warehouse_MFR_Domain_Api_Documents_ServiceObject_WarehousePartner" ToRole="Warehouse" FromRole="WarehousePartner" />
<NavigationProperty Name="CreatedBy" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_CreatedBy_MFR_Domain_Api_Documents_Contact_CreatedByPartner" ToRole="CreatedBy" FromRole="CreatedByPartner" />
<NavigationProperty Name="ConfirmedBy" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_ConfirmedBy_MFR_Domain_Api_Documents_Contact_ConfirmedByPartner" ToRole="ConfirmedBy" FromRole="ConfirmedByPartner" />
</EntityType>
<EntityType Name="CostCenter">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
</EntityType>
<EntityType Name="ItemUnit">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
</EntityType>
<EntityType Name="TimeEvent">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="State" Type="Edm.String" />
<Property Name="IsApproved" Type="Edm.Boolean" Nullable="false" />
<Property Name="TimeEventType" Type="Edm.String" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="DateModified" Type="Edm.DateTime" Nullable="false" />
<Property Name="StartDateTime" Type="Edm.DateTime" Nullable="false" />
<Property Name="EndDateTime" Type="Edm.DateTime" Nullable="false" />
<Property Name="ProposedDrivingDistance" Type="Edm.Int32" Nullable="false" />
<Property Name="ContactId" Type="Edm.Int64" Nullable="false" />
<Property Name="ServiceRequestId" Type="Edm.Int64" Nullable="false" />
<Property Name="Description" Type="Edm.String" />
<NavigationProperty Name="Contact" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_TimeEvent_Contact_MFR_Domain_Api_Documents_Contact_ContactPartner" ToRole="Contact" FromRole="ContactPartner" />
<NavigationProperty Name="ServiceRequest" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_TimeEvent_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner" ToRole="ServiceRequest" FromRole="ServiceRequestPartner" />
</EntityType>
<EntityType Name="Document">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="CustomValues" Type="Collection(MFR.Domain.Api.Documents.CustomValue)" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="State" Type="Edm.String" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="URI" Type="Edm.String" />
<Property Name="IsGlobal" Type="Edm.Boolean" Nullable="false" />
<Property Name="StartDateTime" Type="Edm.DateTime" Nullable="false" />
<Property Name="EndDateTime" Type="Edm.DateTime" Nullable="false" />
<Property Name="FileName" Type="Edm.String" />
<Property Name="DateModified" Type="Edm.DateTime" Nullable="false" />
<Property Name="UploadDate" Type="Edm.DateTime" Nullable="false" />
<Property Name="IsLink" Type="Edm.Boolean" Nullable="false" />
<Property Name="ContentType" Type="Edm.String" />
<Property Name="HTMLCode" Type="Edm.String" />
<Property Name="ServiceRequestId" Type="Edm.Int64" Nullable="false" />
<Property Name="Note" Type="Edm.String" />
<NavigationProperty Name="ServiceRequest" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Document_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner" ToRole="ServiceRequest" FromRole="ServiceRequestPartner" />
</EntityType>
<EntityType Name="Report">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="DateOfCreation" Type="Edm.DateTime" Nullable="false" />
<Property Name="URI" Type="Edm.String" />
<Property Name="DocumentName" Type="Edm.String" />
<Property Name="FileTypeString" Type="Edm.String" />
<Property Name="ReportDefinitionCode" Type="Edm.String" />
<Property Name="ServiceObjectId" Type="Edm.Int64" Nullable="false" />
<Property Name="CanBeDeleted" Type="Edm.Boolean" Nullable="false" />
<Property Name="InvoiceBalance" Type="Edm.Decimal" Nullable="false" />
<Property Name="InvoiceId" Type="Edm.String" />
<Property Name="DueDate" Type="Edm.DateTime" Nullable="false" />
<Property Name="IsPayed" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsInvoice" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsCanceled" Type="Edm.Boolean" Nullable="false" />
<Property Name="CustomValues" Type="Collection(MFR.Domain.Api.Documents.CustomValue)" Nullable="false" />
<NavigationProperty Name="ServiceRequest" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Report_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner" ToRole="ServiceRequest" FromRole="ServiceRequestPartner" />
<NavigationProperty Name="ServiceObject" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Report_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartner" ToRole="ServiceObject" FromRole="ServiceObjectPartner" />
</EntityType>
<EntityType Name="Comment">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="DateOfCreation" Type="Edm.DateTime" Nullable="false" />
<Property Name="IsInternal" Type="Edm.Boolean" Nullable="false" />
<Property Name="ServiceRequestId" Type="Edm.Int64" Nullable="false" />
<Property Name="CompanyId" Type="Edm.Int64" Nullable="false" />
<Property Name="Content" Type="Edm.String" />
<NavigationProperty Name="Owner" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Comment_Owner_MFR_Domain_Api_Documents_Contact_OwnerPartner" ToRole="Owner" FromRole="OwnerPartner" />
<NavigationProperty Name="ServiceRequest" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Comment_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner" ToRole="ServiceRequest" FromRole="ServiceRequestPartner" />
<NavigationProperty Name="Company" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Comment_Company_MFR_Domain_Api_Documents_Company_CompanyPartner" ToRole="Company" FromRole="CompanyPartner" />
</EntityType>
<EntityType Name="Attachment">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="URI" Type="Edm.String" />
<Property Name="StepId" Type="Edm.Int64" Nullable="false" />
<NavigationProperty Name="Step" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Attachment_Step_MFR_Domain_Api_Documents_Step_StepPartner" ToRole="Step" FromRole="StepPartner" />
</EntityType>
<EntityType Name="Appointment">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="State" Type="Edm.String" />
<Property Name="Type" Type="Edm.String" />
<Property Name="EndDateTime" Type="Edm.DateTime" />
<Property Name="StartDateTime" Type="Edm.DateTime" Nullable="false" />
<Property Name="DrivingDistanceFrom" Type="Edm.Int32" />
<Property Name="DrivingDistanceTo" Type="Edm.Int32" />
<Property Name="WasReadOnClientSide" Type="Edm.Boolean" Nullable="false" />
<Property Name="ContactIds" Type="Collection(Edm.Int64)" Nullable="false" />
<Property Name="ServiceRequestId" Type="Edm.Int64" Nullable="false" />
<Property Name="ContactId" Type="Edm.Int64" Nullable="false" />
<Property Name="Note" Type="Edm.String" />
<NavigationProperty Name="ServiceRequest" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Appointment_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner" ToRole="ServiceRequest" FromRole="ServiceRequestPartner" />
<NavigationProperty Name="Contacts" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Appointment_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner" ToRole="Contacts" FromRole="ContactsPartner" />
<NavigationProperty Name="Contact" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Appointment_Contact_MFR_Domain_Api_Documents_Contact_ContactPartner" ToRole="Contact" FromRole="ContactPartner" />
</EntityType>
<EntityType Name="Step">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="MobileId" Type="Edm.Int64" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
<Property Name="IsDone" Type="Edm.Boolean" Nullable="false" />
<Property Name="HasError" Type="Edm.Boolean" Nullable="false" />
<Property Name="TrackingId" Type="Edm.String" />
<Property Name="Type" Type="Edm.String" />
<Property Name="SortOrder" Type="Edm.Int32" Nullable="false" />
<Property Name="Data" Type="Edm.String" />
<Property Name="DateModifiedOffline" Type="Edm.DateTime" />
<Property Name="ServiceRequestId" Type="Edm.Int64" />
<Property Name="Description" Type="Edm.String" />
<Property Name="Comment" Type="Edm.String" />
<Property Name="InternalComment" Type="Edm.String" />
<Property Name="ServiceObjectId" Type="Edm.Int64" />
<Property Name="StepListTemplateId" Type="Edm.Int64" />
<Property Name="ParentId" Type="Edm.Int64" />
<NavigationProperty Name="ServiceRequest" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner" ToRole="ServiceRequest" FromRole="ServiceRequestPartner" />
<NavigationProperty Name="ServiceObject" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartner" ToRole="ServiceObject" FromRole="ServiceObjectPartner" />
<NavigationProperty Name="StepListTemplate" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_StepListTemplate_MFR_Domain_Api_Documents_StepListTemplate_StepListTemplatePartner" ToRole="StepListTemplate" FromRole="StepListTemplatePartner" />
<NavigationProperty Name="Parent" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_Parent_MFR_Domain_Api_Documents_Step_ParentPartner" ToRole="Parent" FromRole="ParentPartner" />
<NavigationProperty Name="Attachments" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_Attachments_MFR_Domain_Api_Documents_Attachment_AttachmentsPartner" ToRole="Attachments" FromRole="AttachmentsPartner" />
</EntityType>
<EntityType Name="ServiceObject">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Location" Type="MFR.Domain.Api.Documents.Location" />
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
<Property Name="Note" Type="Edm.String" />
<Property Name="CustomValues" Type="Collection(MFR.Domain.Api.Documents.CustomValue)" Nullable="false" />
<Property Name="DateModified" Type="Edm.DateTime" Nullable="false" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="MappingId" Type="Edm.String" />
<Property Name="QuickSearch" Type="Edm.String" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="CreateGeoLocation" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsWarehouse" Type="Edm.Boolean" Nullable="false" />
<Property Name="ParentServiceObjectId" Type="Edm.Int64" Nullable="false" />
<Property Name="CompanyId" Type="Edm.Int64" Nullable="false" />
<Property Name="ProductId" Type="Edm.Int64" Nullable="false" />
<NavigationProperty Name="WarehouseManager" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_WarehouseManager_MFR_Domain_Api_Documents_Contact_WarehouseManagerPartner" ToRole="WarehouseManager" FromRole="WarehouseManagerPartner" />
<NavigationProperty Name="CustomValueSteps" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_CustomValueSteps_MFR_Domain_Api_Documents_Step_CustomValueStepsPartner" ToRole="CustomValueSteps" FromRole="CustomValueStepsPartner" />
<NavigationProperty Name="Company" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Company_MFR_Domain_Api_Documents_Company_CompanyPartner" ToRole="Company" FromRole="CompanyPartner" />
<NavigationProperty Name="Product" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Product_MFR_Domain_Api_Documents_Product_ProductPartner" ToRole="Product" FromRole="ProductPartner" />
<NavigationProperty Name="Tags" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Tags_MFR_Domain_Api_Documents_Tag_TagsPartner" ToRole="Tags" FromRole="TagsPartner" />
<NavigationProperty Name="ChildServiceObject" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_ChildServiceObject_MFR_Domain_Api_Documents_ServiceObject_ChildServiceObjectPartner" ToRole="ChildServiceObject" FromRole="ChildServiceObjectPartner" />
<NavigationProperty Name="Contacts" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner" ToRole="Contacts" FromRole="ContactsPartner" />
<NavigationProperty Name="Items" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Items_MFR_Domain_Api_Documents_Item_ItemsPartner" ToRole="Items" FromRole="ItemsPartner" />
</EntityType>
<ComplexType Name="Location">
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Id" Type="Edm.Int64" />
<Property Name="AddressString" Type="Edm.String" />
<Property Name="Postal" Type="Edm.String" />
<Property Name="City" Type="Edm.String" />
<Property Name="State" Type="Edm.String" />
<Property Name="Country" Type="Edm.String" />
<Property Name="Longitude" Type="Edm.Double" Nullable="false" />
<Property Name="Latitude" Type="Edm.Double" Nullable="false" />
<Property Name="IsValidLocation" Type="Edm.Boolean" Nullable="false" />
</ComplexType>
<EntityType Name="StepListTemplate">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
<Property Name="MappingId" Type="Edm.String" />
<Property Name="DateModified" Type="Edm.DateTime" Nullable="false" />
<Property Name="IsReleased" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsDurable" Type="Edm.Boolean" Nullable="false" />
<NavigationProperty Name="Steps" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StepListTemplate_Steps_MFR_Domain_Api_Documents_Step_StepsPartner" ToRole="Steps" FromRole="StepsPartner" />
</EntityType>
<EntityType Name="StepListTemplateInstance">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
<Property Name="ServiceRequestId" Type="Edm.Int64" />
<Property Name="TemplateId" Type="Edm.Int64" />
<NavigationProperty Name="ServiceRequest" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StepListTemplateInstance_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner" ToRole="ServiceRequest" FromRole="ServiceRequestPartner" />
<NavigationProperty Name="Template" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StepListTemplateInstance_Template_MFR_Domain_Api_Documents_StepListTemplate_TemplatePartner" ToRole="Template" FromRole="TemplatePartner" />
</EntityType>
<EntityType Name="Contact">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="CustomValues" Type="Collection(MFR.Domain.Api.Documents.CustomValue)" Nullable="false" />
<Property Name="FirstName" Type="Edm.String" />
<Property Name="LastName" Type="Edm.String" />
<Property Name="Email" Type="Edm.String" />
<Property Name="JobTitle" Type="Edm.String" />
<Property Name="MobilePhone" Type="Edm.String" />
<Property Name="Telephone" Type="Edm.String" />
<Property Name="Fax" Type="Edm.String" />
<Property Name="Note" Type="Edm.String" />
<Property Name="DateModified" Type="Edm.DateTime" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="CompanyId" Type="Edm.Int64" Nullable="false" />
<Property Name="IsUser" Type="Edm.Boolean" Nullable="false" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="Gender" Type="Edm.String" />
<Property Name="UserId" Type="Edm.Int64" Nullable="false" />
<NavigationProperty Name="Company" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Contact_Company_MFR_Domain_Api_Documents_Company_CompanyPartner" ToRole="Company" FromRole="CompanyPartner" />
<NavigationProperty Name="User" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Contact_User_MFR_Domain_Api_Documents_User_UserPartner" ToRole="User" FromRole="UserPartner" />
</EntityType>
<EntityType Name="Tag">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
<Property Name="ColorDefinition" Type="Edm.String" />
<Property Name="Type" Type="Edm.String" Nullable="false" />
</EntityType>
<EntityType Name="Product">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
<Property Name="SubKey" Type="Edm.String" />
<Property Name="Description" Type="Edm.String" />
<Property Name="DateModified" Type="Edm.DateTime" Nullable="false" />
<Property Name="MappingId" Type="Edm.String" />
<Property Name="CustomValueStepTemplateId" Type="Edm.Int64" Nullable="false" />
<NavigationProperty Name="CustomValueStepTemplate" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Product_CustomValueStepTemplate_MFR_Domain_Api_Documents_StepListTemplate_CustomValueStepTemplatePartner" ToRole="CustomValueStepTemplate" FromRole="CustomValueStepTemplatePartner" />
</EntityType>
<EntityType Name="Company">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Location" Type="MFR.Domain.Api.Documents.Location" />
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="IsPhysicalPerson" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsOwner" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsEmailInvoicingActive" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsSupplier" Type="Edm.Boolean" Nullable="false" />
<Property Name="MappingId" Type="Edm.String" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="Name" Type="Edm.String" />
<Property Name="Note" Type="Edm.String" />
<Property Name="SupportTelephone" Type="Edm.String" />
<Property Name="SupportFax" Type="Edm.String" />
<Property Name="SupportMail" Type="Edm.String" />
<Property Name="QuickSearch" Type="Edm.String" />
<Property Name="DateModified" Type="Edm.DateTime" Nullable="false" />
<Property Name="CustomValues" Type="Collection(MFR.Domain.Api.Documents.CustomValue)" Nullable="false" />
<Property Name="MainContactId" Type="Edm.Int64" Nullable="false" />
<NavigationProperty Name="MainContact" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Company_MainContact_MFR_Domain_Api_Documents_Contact_MainContactPartner" ToRole="MainContact" FromRole="MainContactPartner" />
<NavigationProperty Name="Tags" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Company_Tags_MFR_Domain_Api_Documents_Tag_TagsPartner" ToRole="Tags" FromRole="TagsPartner" />
<NavigationProperty Name="Contacts" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Company_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner" ToRole="Contacts" FromRole="ContactsPartner" />
<NavigationProperty Name="ServiceObjects" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Company_ServiceObjects_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectsPartner" ToRole="ServiceObjects" FromRole="ServiceObjectsPartner" />
</EntityType>
<EntityType Name="User">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="UserName" Type="Edm.String" />
<Property Name="IsSystem" Type="Edm.Boolean" Nullable="false" />
<Property Name="CreationDate" Type="Edm.DateTime" Nullable="false" />
<Property Name="IsApproved" Type="Edm.Boolean" Nullable="false" />
<Property Name="ContactId" Type="Edm.Int64" Nullable="false" />
<Property Name="PreferedLanguage" Type="Edm.String" />
<Property Name="EmailChannelEnabled" Type="Edm.Boolean" Nullable="false" />
<Property Name="HasFullScreenPreference" Type="Edm.Boolean" Nullable="false" />
<Property Name="TimeZone" Type="Edm.Int32" Nullable="false" />
<Property Name="PreferedCulture" Type="Edm.String" />
<Property Name="IsActive" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsMobile" Type="Edm.Boolean" Nullable="false" />
<Property Name="LastLoginDate" Type="Edm.DateTime" />
<Property Name="UserGuideProgress" Type="Edm.String" />
<Property Name="DashboardSettings" Type="Edm.String" />
<NavigationProperty Name="Contact" Relationship="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_User_Contact_MFR_Domain_Api_Documents_Contact_ContactPartner" ToRole="Contact" FromRole="ContactPartner" />
</EntityType>
<EntityType Name="Qualification">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int64" Nullable="false" />
<Property Name="Version" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
</EntityType>
<Association Name="MFR_Domain_Api_Documents_ItemType_Unit_MFR_Domain_Api_Documents_ItemUnit_UnitPartner">
<End Type="MFR.Domain.Api.Documents.ItemUnit" Role="Unit" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ItemType" Role="UnitPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_CreatedBy_MFR_Domain_Api_Documents_Contact_CreatedByPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="CreatedBy" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="CreatedByPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_ClosedBy_MFR_Domain_Api_Documents_User_ClosedByPartner">
<End Type="MFR.Domain.Api.Documents.User" Role="ClosedBy" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ClosedByPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_ReleasedBy_MFR_Domain_Api_Documents_User_ReleasedByPartner">
<End Type="MFR.Domain.Api.Documents.User" Role="ReleasedBy" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ReleasedByPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_CostCenter_MFR_Domain_Api_Documents_CostCenter_CostCenterPartner">
<End Type="MFR.Domain.Api.Documents.CostCenter" Role="CostCenter" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="CostCenterPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Appointments_MFR_Domain_Api_Documents_Appointment_AppointmentsPartner">
<End Type="MFR.Domain.Api.Documents.Appointment" Role="Appointments" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="AppointmentsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Items_MFR_Domain_Api_Documents_Item_ItemsPartner">
<End Type="MFR.Domain.Api.Documents.Item" Role="Items" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ItemsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Documents_MFR_Domain_Api_Documents_Document_DocumentsPartner">
<End Type="MFR.Domain.Api.Documents.Document" Role="Documents" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="DocumentsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Reports_MFR_Domain_Api_Documents_Report_ReportsPartner">
<End Type="MFR.Domain.Api.Documents.Report" Role="Reports" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ReportsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="Contacts" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ContactsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_StepListTemplates_MFR_Domain_Api_Documents_StepListTemplate_StepListTemplatesPartner">
<End Type="MFR.Domain.Api.Documents.StepListTemplate" Role="StepListTemplates" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="StepListTemplatesPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_ServiceObjects_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectsPartner">
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ServiceObjects" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceObjectsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_TimeEvents_MFR_Domain_Api_Documents_TimeEvent_TimeEventsPartner">
<End Type="MFR.Domain.Api.Documents.TimeEvent" Role="TimeEvents" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="TimeEventsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Comments_MFR_Domain_Api_Documents_Comment_CommentsPartner">
<End Type="MFR.Domain.Api.Documents.Comment" Role="Comments" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="CommentsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_CurrentOwner_MFR_Domain_Api_Documents_Contact_CurrentOwnerPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="CurrentOwner" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="CurrentOwnerPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Customer_MFR_Domain_Api_Documents_Company_CustomerPartner">
<End Type="MFR.Domain.Api.Documents.Company" Role="Customer" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="CustomerPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Tags_MFR_Domain_Api_Documents_Tag_TagsPartner">
<End Type="MFR.Domain.Api.Documents.Tag" Role="Tags" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="TagsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Steps_MFR_Domain_Api_Documents_Step_StepsPartner">
<End Type="MFR.Domain.Api.Documents.Step" Role="Steps" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="StepsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_StockMovements_MFR_Domain_Api_Documents_StockMovement_StockMovementsPartner">
<End Type="MFR.Domain.Api.Documents.StockMovement" Role="StockMovements" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="StockMovementsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceRequest_Qualifications_MFR_Domain_Api_Documents_Qualification_QualificationsPartner">
<End Type="MFR.Domain.Api.Documents.Qualification" Role="Qualifications" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="QualificationsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Item_ItemType_MFR_Domain_Api_Documents_ItemType_ItemTypePartner">
<End Type="MFR.Domain.Api.Documents.ItemType" Role="ItemType" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Item" Role="ItemTypePartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Item_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceRequest" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Item" Role="ServiceRequestPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Item_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartner">
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ServiceObject" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Item" Role="ServiceObjectPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Item_Creator_MFR_Domain_Api_Documents_Contact_CreatorPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="Creator" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Item" Role="CreatorPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Item_Unit_MFR_Domain_Api_Documents_ItemUnit_UnitPartner">
<End Type="MFR.Domain.Api.Documents.ItemUnit" Role="Unit" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Item" Role="UnitPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_StockMovement_Item_MFR_Domain_Api_Documents_Item_ItemPartner">
<End Type="MFR.Domain.Api.Documents.Item" Role="Item" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.StockMovement" Role="ItemPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_StockMovement_ItemType_MFR_Domain_Api_Documents_ItemType_ItemTypePartner">
<End Type="MFR.Domain.Api.Documents.ItemType" Role="ItemType" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.StockMovement" Role="ItemTypePartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_StockMovement_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceRequest" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.StockMovement" Role="ServiceRequestPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_StockMovement_Warehouse_MFR_Domain_Api_Documents_ServiceObject_WarehousePartner">
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="Warehouse" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.StockMovement" Role="WarehousePartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_StockMovement_CreatedBy_MFR_Domain_Api_Documents_Contact_CreatedByPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="CreatedBy" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.StockMovement" Role="CreatedByPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_StockMovement_ConfirmedBy_MFR_Domain_Api_Documents_Contact_ConfirmedByPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="ConfirmedBy" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.StockMovement" Role="ConfirmedByPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_TimeEvent_Contact_MFR_Domain_Api_Documents_Contact_ContactPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="Contact" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.TimeEvent" Role="ContactPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_TimeEvent_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceRequest" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.TimeEvent" Role="ServiceRequestPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Document_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceRequest" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Document" Role="ServiceRequestPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Report_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceRequest" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Report" Role="ServiceRequestPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Report_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartner">
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ServiceObject" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Report" Role="ServiceObjectPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Comment_Owner_MFR_Domain_Api_Documents_Contact_OwnerPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="Owner" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Comment" Role="OwnerPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Comment_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceRequest" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Comment" Role="ServiceRequestPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Comment_Company_MFR_Domain_Api_Documents_Company_CompanyPartner">
<End Type="MFR.Domain.Api.Documents.Company" Role="Company" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Comment" Role="CompanyPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Attachment_Step_MFR_Domain_Api_Documents_Step_StepPartner">
<End Type="MFR.Domain.Api.Documents.Step" Role="Step" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Attachment" Role="StepPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Appointment_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceRequest" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Appointment" Role="ServiceRequestPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Appointment_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="Contacts" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.Appointment" Role="ContactsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Appointment_Contact_MFR_Domain_Api_Documents_Contact_ContactPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="Contact" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Appointment" Role="ContactPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Step_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceRequest" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Step" Role="ServiceRequestPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Step_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartner">
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ServiceObject" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Step" Role="ServiceObjectPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Step_StepListTemplate_MFR_Domain_Api_Documents_StepListTemplate_StepListTemplatePartner">
<End Type="MFR.Domain.Api.Documents.StepListTemplate" Role="StepListTemplate" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Step" Role="StepListTemplatePartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Step_Parent_MFR_Domain_Api_Documents_Step_ParentPartner">
<End Type="MFR.Domain.Api.Documents.Step" Role="Parent" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Step" Role="ParentPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Step_Attachments_MFR_Domain_Api_Documents_Attachment_AttachmentsPartner">
<End Type="MFR.Domain.Api.Documents.Attachment" Role="Attachments" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.Step" Role="AttachmentsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceObject_WarehouseManager_MFR_Domain_Api_Documents_Contact_WarehouseManagerPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="WarehouseManager" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="WarehouseManagerPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceObject_CustomValueSteps_MFR_Domain_Api_Documents_Step_CustomValueStepsPartner">
<End Type="MFR.Domain.Api.Documents.Step" Role="CustomValueSteps" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="CustomValueStepsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceObject_Company_MFR_Domain_Api_Documents_Company_CompanyPartner">
<End Type="MFR.Domain.Api.Documents.Company" Role="Company" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="CompanyPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceObject_Product_MFR_Domain_Api_Documents_Product_ProductPartner">
<End Type="MFR.Domain.Api.Documents.Product" Role="Product" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ProductPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceObject_Tags_MFR_Domain_Api_Documents_Tag_TagsPartner">
<End Type="MFR.Domain.Api.Documents.Tag" Role="Tags" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="TagsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceObject_ChildServiceObject_MFR_Domain_Api_Documents_ServiceObject_ChildServiceObjectPartner">
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ChildServiceObject" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ChildServiceObjectPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceObject_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="Contacts" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ContactsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_ServiceObject_Items_MFR_Domain_Api_Documents_Item_ItemsPartner">
<End Type="MFR.Domain.Api.Documents.Item" Role="Items" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ItemsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_StepListTemplate_Steps_MFR_Domain_Api_Documents_Step_StepsPartner">
<End Type="MFR.Domain.Api.Documents.Step" Role="Steps" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.StepListTemplate" Role="StepsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_StepListTemplateInstance_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Type="MFR.Domain.Api.Documents.ServiceRequest" Role="ServiceRequest" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.StepListTemplateInstance" Role="ServiceRequestPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_StepListTemplateInstance_Template_MFR_Domain_Api_Documents_StepListTemplate_TemplatePartner">
<End Type="MFR.Domain.Api.Documents.StepListTemplate" Role="Template" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.StepListTemplateInstance" Role="TemplatePartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Contact_Company_MFR_Domain_Api_Documents_Company_CompanyPartner">
<End Type="MFR.Domain.Api.Documents.Company" Role="Company" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Contact" Role="CompanyPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Contact_User_MFR_Domain_Api_Documents_User_UserPartner">
<End Type="MFR.Domain.Api.Documents.User" Role="User" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Contact" Role="UserPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Product_CustomValueStepTemplate_MFR_Domain_Api_Documents_StepListTemplate_CustomValueStepTemplatePartner">
<End Type="MFR.Domain.Api.Documents.StepListTemplate" Role="CustomValueStepTemplate" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Product" Role="CustomValueStepTemplatePartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Company_MainContact_MFR_Domain_Api_Documents_Contact_MainContactPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="MainContact" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.Company" Role="MainContactPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Company_Tags_MFR_Domain_Api_Documents_Tag_TagsPartner">
<End Type="MFR.Domain.Api.Documents.Tag" Role="Tags" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.Company" Role="TagsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Company_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="Contacts" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.Company" Role="ContactsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_Company_ServiceObjects_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectsPartner">
<End Type="MFR.Domain.Api.Documents.ServiceObject" Role="ServiceObjects" Multiplicity="*" />
<End Type="MFR.Domain.Api.Documents.Company" Role="ServiceObjectsPartner" Multiplicity="0..1" />
</Association>
<Association Name="MFR_Domain_Api_Documents_User_Contact_MFR_Domain_Api_Documents_Contact_ContactPartner">
<End Type="MFR.Domain.Api.Documents.Contact" Role="Contact" Multiplicity="0..1" />
<End Type="MFR.Domain.Api.Documents.User" Role="ContactPartner" Multiplicity="0..1" />
</Association>
</Schema>
<Schema>
<ComplexType Name="ServiceRequest">
<Property Name="Name" Type="Edm.String" />
<Property Name="Description" Type="Edm.String" />
<Property Name="Customer" Type="MFR.Domain.Api.Documents.ServiceRequestCreation.Company" />
<Property Name="ServiceObjects" Type="Collection(MFR.Domain.Api.Documents.ServiceRequestCreation.ServiceObject)" Nullable="false" />
<Property Name="State" Type="Edm.String" />
<Property Name="CreateFromServiceRequestTemplateId" Type="Edm.Int64" />
</ComplexType>
<ComplexType Name="Company">
<Property Name="Id" Type="Edm.Int64" />
<Property Name="Name" Type="Edm.String" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="CreateGeoLocation" Type="Edm.Boolean" Nullable="false" />
<Property Name="IsPhysicalPerson" Type="Edm.Boolean" />
<Property Name="Location" Type="MFR.Domain.Api.Documents.ServiceRequestCreation.Location" />
</ComplexType>
<ComplexType Name="Location">
<Property Name="CreateGeoLocation" Type="Edm.Boolean" />
<Property Name="AddressString" Type="Edm.String" />
<Property Name="Postal" Type="Edm.String" />
<Property Name="City" Type="Edm.String" />
<Property Name="Country" Type="Edm.String" />
<Property Name="Longitude" Type="Edm.Double" Nullable="false" />
<Property Name="Latitude" Type="Edm.Double" Nullable="false" />
</ComplexType>
<ComplexType Name="ServiceObject">
<Property Name="Id" Type="Edm.Int64" />
<Property Name="Name" Type="Edm.String" />
<Property Name="ExternalId" Type="Edm.String" />
<Property Name="CreateGeoLocation" Type="Edm.Boolean" Nullable="false" />
<Property Name="Location" Type="MFR.Domain.Api.Documents.ServiceRequestCreation.Location" />
<Property Name="Contacts" Type="Collection(MFR.Domain.Api.Documents.ServiceRequestCreation.Contact)" Nullable="false" />
</ComplexType>
<ComplexType Name="Contact">
<Property Name="FirstName" Type="Edm.String" />
<Property Name="LastName" Type="Edm.String" />
<Property Name="Telephone" Type="Edm.String" />
<Property Name="Mobile" Type="Edm.String" />
<Property Name="Email" Type="Edm.String" />
</ComplexType>
</Schema>
<Schema xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="ItemTypes" EntityType="MFR.Domain.Api.Documents.ItemType" />
<EntitySet Name="ServiceRequests" EntityType="MFR.Domain.Api.Documents.ServiceRequest" />
<EntitySet Name="Items" EntityType="MFR.Domain.Api.Documents.Item" />
<EntitySet Name="StockMovements" EntityType="MFR.Domain.Api.Documents.StockMovement" />
<EntitySet Name="CostCenters" EntityType="MFR.Domain.Api.Documents.CostCenter" />
<EntitySet Name="ItemUnits" EntityType="MFR.Domain.Api.Documents.ItemUnit" />
<EntitySet Name="TimeEvents" EntityType="MFR.Domain.Api.Documents.TimeEvent" />
<EntitySet Name="Documents" EntityType="MFR.Domain.Api.Documents.Document" />
<EntitySet Name="Reports" EntityType="MFR.Domain.Api.Documents.Report" />
<EntitySet Name="Comments" EntityType="MFR.Domain.Api.Documents.Comment" />
<EntitySet Name="Attachments" EntityType="MFR.Domain.Api.Documents.Attachment" />
<EntitySet Name="Appointments" EntityType="MFR.Domain.Api.Documents.Appointment" />
<EntitySet Name="Steps" EntityType="MFR.Domain.Api.Documents.Step" />
<EntitySet Name="ServiceObjects" EntityType="MFR.Domain.Api.Documents.ServiceObject" />
<EntitySet Name="StepListTemplates" EntityType="MFR.Domain.Api.Documents.StepListTemplate" />
<EntitySet Name="StepListTemplateInstances" EntityType="MFR.Domain.Api.Documents.StepListTemplateInstance" />
<EntitySet Name="Contacts" EntityType="MFR.Domain.Api.Documents.Contact" />
<EntitySet Name="Tags" EntityType="MFR.Domain.Api.Documents.Tag" />
<EntitySet Name="Products" EntityType="MFR.Domain.Api.Documents.Product" />
<EntitySet Name="Companies" EntityType="MFR.Domain.Api.Documents.Company" />
<EntitySet Name="Users" EntityType="MFR.Domain.Api.Documents.User" />
<EntitySet Name="Qualifications" EntityType="MFR.Domain.Api.Documents.Qualification" />
<FunctionImport Name="GenerateReportHash" ReturnType="Edm.String" IsBindable="true" m:IsAlwaysBindable="true">
<Parameter Name="bindingParameter" Type="MFR.Domain.Api.Documents.ServiceRequest" />
<Parameter Name="reportDefinitionId" Type="Edm.Int64" Nullable="false" />
</FunctionImport>
<FunctionImport Name="Deep" ReturnType="MFR.Domain.Api.Documents.ServiceRequest" IsBindable="true" EntitySet="ServiceRequests" m:IsAlwaysBindable="true">
<Parameter Name="bindingParameter" Type="Collection(MFR.Domain.Api.Documents.ServiceRequest)" Nullable="false" />
<Parameter Name="serviceRequest" Type="MFR.Domain.Api.Documents.ServiceRequestCreation.ServiceRequest" />
</FunctionImport>
<AssociationSet Name="MFR_Domain_Api_Documents_ItemType_Unit_MFR_Domain_Api_Documents_ItemUnit_UnitPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ItemType_Unit_MFR_Domain_Api_Documents_ItemUnit_UnitPartner">
<End Role="UnitPartner" EntitySet="ItemTypes" />
<End Role="Unit" EntitySet="ItemUnits" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_CreatedBy_MFR_Domain_Api_Documents_Contact_CreatedByPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_CreatedBy_MFR_Domain_Api_Documents_Contact_CreatedByPartner">
<End Role="CreatedByPartner" EntitySet="ServiceRequests" />
<End Role="CreatedBy" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_ClosedBy_MFR_Domain_Api_Documents_User_ClosedByPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_ClosedBy_MFR_Domain_Api_Documents_User_ClosedByPartner">
<End Role="ClosedByPartner" EntitySet="ServiceRequests" />
<End Role="ClosedBy" EntitySet="Users" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_ReleasedBy_MFR_Domain_Api_Documents_User_ReleasedByPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_ReleasedBy_MFR_Domain_Api_Documents_User_ReleasedByPartner">
<End Role="ReleasedByPartner" EntitySet="ServiceRequests" />
<End Role="ReleasedBy" EntitySet="Users" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_CostCenter_MFR_Domain_Api_Documents_CostCenter_CostCenterPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_CostCenter_MFR_Domain_Api_Documents_CostCenter_CostCenterPartner">
<End Role="CostCenterPartner" EntitySet="ServiceRequests" />
<End Role="CostCenter" EntitySet="CostCenters" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Appointments_MFR_Domain_Api_Documents_Appointment_AppointmentsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Appointments_MFR_Domain_Api_Documents_Appointment_AppointmentsPartner">
<End Role="AppointmentsPartner" EntitySet="ServiceRequests" />
<End Role="Appointments" EntitySet="Appointments" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Items_MFR_Domain_Api_Documents_Item_ItemsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Items_MFR_Domain_Api_Documents_Item_ItemsPartner">
<End Role="ItemsPartner" EntitySet="ServiceRequests" />
<End Role="Items" EntitySet="Items" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Documents_MFR_Domain_Api_Documents_Document_DocumentsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Documents_MFR_Domain_Api_Documents_Document_DocumentsPartner">
<End Role="DocumentsPartner" EntitySet="ServiceRequests" />
<End Role="Documents" EntitySet="Documents" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Reports_MFR_Domain_Api_Documents_Report_ReportsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Reports_MFR_Domain_Api_Documents_Report_ReportsPartner">
<End Role="ReportsPartner" EntitySet="ServiceRequests" />
<End Role="Reports" EntitySet="Reports" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner">
<End Role="ContactsPartner" EntitySet="ServiceRequests" />
<End Role="Contacts" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_StepListTemplates_MFR_Domain_Api_Documents_StepListTemplate_StepListTemplatesPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_StepListTemplates_MFR_Domain_Api_Documents_StepListTemplate_StepListTemplatesPartner">
<End Role="StepListTemplatesPartner" EntitySet="ServiceRequests" />
<End Role="StepListTemplates" EntitySet="StepListTemplates" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_ServiceObjects_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_ServiceObjects_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectsPartner">
<End Role="ServiceObjectsPartner" EntitySet="ServiceRequests" />
<End Role="ServiceObjects" EntitySet="ServiceObjects" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_TimeEvents_MFR_Domain_Api_Documents_TimeEvent_TimeEventsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_TimeEvents_MFR_Domain_Api_Documents_TimeEvent_TimeEventsPartner">
<End Role="TimeEventsPartner" EntitySet="ServiceRequests" />
<End Role="TimeEvents" EntitySet="TimeEvents" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Comments_MFR_Domain_Api_Documents_Comment_CommentsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Comments_MFR_Domain_Api_Documents_Comment_CommentsPartner">
<End Role="CommentsPartner" EntitySet="ServiceRequests" />
<End Role="Comments" EntitySet="Comments" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_CurrentOwner_MFR_Domain_Api_Documents_Contact_CurrentOwnerPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_CurrentOwner_MFR_Domain_Api_Documents_Contact_CurrentOwnerPartner">
<End Role="CurrentOwnerPartner" EntitySet="ServiceRequests" />
<End Role="CurrentOwner" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Customer_MFR_Domain_Api_Documents_Company_CustomerPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Customer_MFR_Domain_Api_Documents_Company_CustomerPartner">
<End Role="CustomerPartner" EntitySet="ServiceRequests" />
<End Role="Customer" EntitySet="Companies" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Tags_MFR_Domain_Api_Documents_Tag_TagsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Tags_MFR_Domain_Api_Documents_Tag_TagsPartner">
<End Role="TagsPartner" EntitySet="ServiceRequests" />
<End Role="Tags" EntitySet="Tags" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Steps_MFR_Domain_Api_Documents_Step_StepsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Steps_MFR_Domain_Api_Documents_Step_StepsPartner">
<End Role="StepsPartner" EntitySet="ServiceRequests" />
<End Role="Steps" EntitySet="Steps" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_StockMovements_MFR_Domain_Api_Documents_StockMovement_StockMovementsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_StockMovements_MFR_Domain_Api_Documents_StockMovement_StockMovementsPartner">
<End Role="StockMovementsPartner" EntitySet="ServiceRequests" />
<End Role="StockMovements" EntitySet="StockMovements" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceRequest_Qualifications_MFR_Domain_Api_Documents_Qualification_QualificationsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceRequest_Qualifications_MFR_Domain_Api_Documents_Qualification_QualificationsPartner">
<End Role="QualificationsPartner" EntitySet="ServiceRequests" />
<End Role="Qualifications" EntitySet="Qualifications" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Item_ItemType_MFR_Domain_Api_Documents_ItemType_ItemTypePartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_ItemType_MFR_Domain_Api_Documents_ItemType_ItemTypePartner">
<End Role="ItemTypePartner" EntitySet="Items" />
<End Role="ItemType" EntitySet="ItemTypes" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Item_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Role="ServiceRequestPartner" EntitySet="Items" />
<End Role="ServiceRequest" EntitySet="ServiceRequests" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Item_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartner">
<End Role="ServiceObjectPartner" EntitySet="Items" />
<End Role="ServiceObject" EntitySet="ServiceObjects" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Item_Creator_MFR_Domain_Api_Documents_Contact_CreatorPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_Creator_MFR_Domain_Api_Documents_Contact_CreatorPartner">
<End Role="CreatorPartner" EntitySet="Items" />
<End Role="Creator" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Item_Unit_MFR_Domain_Api_Documents_ItemUnit_UnitPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Item_Unit_MFR_Domain_Api_Documents_ItemUnit_UnitPartner">
<End Role="UnitPartner" EntitySet="Items" />
<End Role="Unit" EntitySet="ItemUnits" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_StockMovement_Item_MFR_Domain_Api_Documents_Item_ItemPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_Item_MFR_Domain_Api_Documents_Item_ItemPartner">
<End Role="ItemPartner" EntitySet="StockMovements" />
<End Role="Item" EntitySet="Items" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_StockMovement_ItemType_MFR_Domain_Api_Documents_ItemType_ItemTypePartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_ItemType_MFR_Domain_Api_Documents_ItemType_ItemTypePartner">
<End Role="ItemTypePartner" EntitySet="StockMovements" />
<End Role="ItemType" EntitySet="ItemTypes" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_StockMovement_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Role="ServiceRequestPartner" EntitySet="StockMovements" />
<End Role="ServiceRequest" EntitySet="ServiceRequests" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_StockMovement_Warehouse_MFR_Domain_Api_Documents_ServiceObject_WarehousePartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_Warehouse_MFR_Domain_Api_Documents_ServiceObject_WarehousePartner">
<End Role="WarehousePartner" EntitySet="StockMovements" />
<End Role="Warehouse" EntitySet="ServiceObjects" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_StockMovement_CreatedBy_MFR_Domain_Api_Documents_Contact_CreatedByPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_CreatedBy_MFR_Domain_Api_Documents_Contact_CreatedByPartner">
<End Role="CreatedByPartner" EntitySet="StockMovements" />
<End Role="CreatedBy" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_StockMovement_ConfirmedBy_MFR_Domain_Api_Documents_Contact_ConfirmedByPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StockMovement_ConfirmedBy_MFR_Domain_Api_Documents_Contact_ConfirmedByPartner">
<End Role="ConfirmedByPartner" EntitySet="StockMovements" />
<End Role="ConfirmedBy" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_TimeEvent_Contact_MFR_Domain_Api_Documents_Contact_ContactPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_TimeEvent_Contact_MFR_Domain_Api_Documents_Contact_ContactPartner">
<End Role="ContactPartner" EntitySet="TimeEvents" />
<End Role="Contact" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_TimeEvent_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_TimeEvent_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Role="ServiceRequestPartner" EntitySet="TimeEvents" />
<End Role="ServiceRequest" EntitySet="ServiceRequests" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Document_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Document_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Role="ServiceRequestPartner" EntitySet="Documents" />
<End Role="ServiceRequest" EntitySet="ServiceRequests" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Report_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Report_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Role="ServiceRequestPartner" EntitySet="Reports" />
<End Role="ServiceRequest" EntitySet="ServiceRequests" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Report_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Report_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartner">
<End Role="ServiceObjectPartner" EntitySet="Reports" />
<End Role="ServiceObject" EntitySet="ServiceObjects" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Comment_Owner_MFR_Domain_Api_Documents_Contact_OwnerPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Comment_Owner_MFR_Domain_Api_Documents_Contact_OwnerPartner">
<End Role="OwnerPartner" EntitySet="Comments" />
<End Role="Owner" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Comment_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Comment_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Role="ServiceRequestPartner" EntitySet="Comments" />
<End Role="ServiceRequest" EntitySet="ServiceRequests" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Comment_Company_MFR_Domain_Api_Documents_Company_CompanyPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Comment_Company_MFR_Domain_Api_Documents_Company_CompanyPartner">
<End Role="CompanyPartner" EntitySet="Comments" />
<End Role="Company" EntitySet="Companies" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Attachment_Step_MFR_Domain_Api_Documents_Step_StepPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Attachment_Step_MFR_Domain_Api_Documents_Step_StepPartner">
<End Role="StepPartner" EntitySet="Attachments" />
<End Role="Step" EntitySet="Steps" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Appointment_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Appointment_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Role="ServiceRequestPartner" EntitySet="Appointments" />
<End Role="ServiceRequest" EntitySet="ServiceRequests" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Appointment_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Appointment_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner">
<End Role="ContactsPartner" EntitySet="Appointments" />
<End Role="Contacts" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Appointment_Contact_MFR_Domain_Api_Documents_Contact_ContactPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Appointment_Contact_MFR_Domain_Api_Documents_Contact_ContactPartner">
<End Role="ContactPartner" EntitySet="Appointments" />
<End Role="Contact" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Step_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Role="ServiceRequestPartner" EntitySet="Steps" />
<End Role="ServiceRequest" EntitySet="ServiceRequests" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Step_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_ServiceObject_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectPartner">
<End Role="ServiceObjectPartner" EntitySet="Steps" />
<End Role="ServiceObject" EntitySet="ServiceObjects" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Step_StepListTemplate_MFR_Domain_Api_Documents_StepListTemplate_StepListTemplatePartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_StepListTemplate_MFR_Domain_Api_Documents_StepListTemplate_StepListTemplatePartner">
<End Role="StepListTemplatePartner" EntitySet="Steps" />
<End Role="StepListTemplate" EntitySet="StepListTemplates" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Step_Parent_MFR_Domain_Api_Documents_Step_ParentPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_Parent_MFR_Domain_Api_Documents_Step_ParentPartner">
<End Role="ParentPartner" EntitySet="Steps" />
<End Role="Parent" EntitySet="Steps" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Step_Attachments_MFR_Domain_Api_Documents_Attachment_AttachmentsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Step_Attachments_MFR_Domain_Api_Documents_Attachment_AttachmentsPartner">
<End Role="AttachmentsPartner" EntitySet="Steps" />
<End Role="Attachments" EntitySet="Attachments" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceObject_WarehouseManager_MFR_Domain_Api_Documents_Contact_WarehouseManagerPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_WarehouseManager_MFR_Domain_Api_Documents_Contact_WarehouseManagerPartner">
<End Role="WarehouseManagerPartner" EntitySet="ServiceObjects" />
<End Role="WarehouseManager" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceObject_CustomValueSteps_MFR_Domain_Api_Documents_Step_CustomValueStepsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_CustomValueSteps_MFR_Domain_Api_Documents_Step_CustomValueStepsPartner">
<End Role="CustomValueStepsPartner" EntitySet="ServiceObjects" />
<End Role="CustomValueSteps" EntitySet="Steps" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceObject_Company_MFR_Domain_Api_Documents_Company_CompanyPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Company_MFR_Domain_Api_Documents_Company_CompanyPartner">
<End Role="CompanyPartner" EntitySet="ServiceObjects" />
<End Role="Company" EntitySet="Companies" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceObject_Product_MFR_Domain_Api_Documents_Product_ProductPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Product_MFR_Domain_Api_Documents_Product_ProductPartner">
<End Role="ProductPartner" EntitySet="ServiceObjects" />
<End Role="Product" EntitySet="Products" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceObject_Tags_MFR_Domain_Api_Documents_Tag_TagsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Tags_MFR_Domain_Api_Documents_Tag_TagsPartner">
<End Role="TagsPartner" EntitySet="ServiceObjects" />
<End Role="Tags" EntitySet="Tags" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceObject_ChildServiceObject_MFR_Domain_Api_Documents_ServiceObject_ChildServiceObjectPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_ChildServiceObject_MFR_Domain_Api_Documents_ServiceObject_ChildServiceObjectPartner">
<End Role="ChildServiceObjectPartner" EntitySet="ServiceObjects" />
<End Role="ChildServiceObject" EntitySet="ServiceObjects" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceObject_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner">
<End Role="ContactsPartner" EntitySet="ServiceObjects" />
<End Role="Contacts" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_ServiceObject_Items_MFR_Domain_Api_Documents_Item_ItemsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_ServiceObject_Items_MFR_Domain_Api_Documents_Item_ItemsPartner">
<End Role="ItemsPartner" EntitySet="ServiceObjects" />
<End Role="Items" EntitySet="Items" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_StepListTemplate_Steps_MFR_Domain_Api_Documents_Step_StepsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StepListTemplate_Steps_MFR_Domain_Api_Documents_Step_StepsPartner">
<End Role="StepsPartner" EntitySet="StepListTemplates" />
<End Role="Steps" EntitySet="Steps" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_StepListTemplateInstance_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StepListTemplateInstance_ServiceRequest_MFR_Domain_Api_Documents_ServiceRequest_ServiceRequestPartner">
<End Role="ServiceRequestPartner" EntitySet="StepListTemplateInstances" />
<End Role="ServiceRequest" EntitySet="ServiceRequests" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_StepListTemplateInstance_Template_MFR_Domain_Api_Documents_StepListTemplate_TemplatePartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_StepListTemplateInstance_Template_MFR_Domain_Api_Documents_StepListTemplate_TemplatePartner">
<End Role="TemplatePartner" EntitySet="StepListTemplateInstances" />
<End Role="Template" EntitySet="StepListTemplates" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Contact_Company_MFR_Domain_Api_Documents_Company_CompanyPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Contact_Company_MFR_Domain_Api_Documents_Company_CompanyPartner">
<End Role="CompanyPartner" EntitySet="Contacts" />
<End Role="Company" EntitySet="Companies" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Contact_User_MFR_Domain_Api_Documents_User_UserPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Contact_User_MFR_Domain_Api_Documents_User_UserPartner">
<End Role="UserPartner" EntitySet="Contacts" />
<End Role="User" EntitySet="Users" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Product_CustomValueStepTemplate_MFR_Domain_Api_Documents_StepListTemplate_CustomValueStepTemplatePartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Product_CustomValueStepTemplate_MFR_Domain_Api_Documents_StepListTemplate_CustomValueStepTemplatePartner">
<End Role="CustomValueStepTemplatePartner" EntitySet="Products" />
<End Role="CustomValueStepTemplate" EntitySet="StepListTemplates" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Company_MainContact_MFR_Domain_Api_Documents_Contact_MainContactPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Company_MainContact_MFR_Domain_Api_Documents_Contact_MainContactPartner">
<End Role="MainContactPartner" EntitySet="Companies" />
<End Role="MainContact" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Company_Tags_MFR_Domain_Api_Documents_Tag_TagsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Company_Tags_MFR_Domain_Api_Documents_Tag_TagsPartner">
<End Role="TagsPartner" EntitySet="Companies" />
<End Role="Tags" EntitySet="Tags" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Company_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Company_Contacts_MFR_Domain_Api_Documents_Contact_ContactsPartner">
<End Role="ContactsPartner" EntitySet="Companies" />
<End Role="Contacts" EntitySet="Contacts" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_Company_ServiceObjects_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectsPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_Company_ServiceObjects_MFR_Domain_Api_Documents_ServiceObject_ServiceObjectsPartner">
<End Role="ServiceObjectsPartner" EntitySet="Companies" />
<End Role="ServiceObjects" EntitySet="ServiceObjects" />
</AssociationSet>
<AssociationSet Name="MFR_Domain_Api_Documents_User_Contact_MFR_Domain_Api_Documents_Contact_ContactPartnerSet" Association="MFR.Domain.Api.Documents.MFR_Domain_Api_Documents_User_Contact_MFR_Domain_Api_Documents_Contact_ContactPartner">
<End Role="ContactPartner" EntitySet="Users" />
<End Role="Contact" EntitySet="Contacts" />
</AssociationSet>
</EntityContainer>
</Schema>';
RETURN @as;
END
GO
/****** Object: UserDefinedFunction [dbo].[ocms_admin_authenticate] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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_random_int] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: View [dbo].[ocms_fn_rand] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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__admin_settings] Script Date: 18.05.2021 17:19:26 ******/
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: Table [dbo].[fds__custom_vat] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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__log] Script Date: 18.05.2021 17:19:26 ******/
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__status] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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__*PartnerSet] Script Date: 18.05.2021 17:19:26 ******/
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__appointments] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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__companies] Script Date: 18.05.2021 17:19:26 ******/
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: Table [dbo].[mfr__contacts] Script Date: 18.05.2021 17:19:26 ******/
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__costcenters] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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].[tt_backup] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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
/****** Object: Index [mfr__items__ix1] Script Date: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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: 18.05.2021 17:19:26 ******/
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].[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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Dr. Stefan Ott
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Dr. Stefan Ott
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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__getDatevExports] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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] bigint, [InvoiceID] varchar(255), [URI] nvarchar(255), [DocumentName] nvarchar(255), [DateOfCreation] date);
INSERT INTO @inv SELECT [Id],[invoiceid],[URI],[DocumentName],[DateOfCreation] FROM [dbo].[mfr__reports] where [IsInvoice] = 1 AND CAST([DateofCreation] as date) BETWEEN @startdate and @enddate;
SELECT
[Id],[InvoiceID],[URI],[DocumentName]
--,[order] = ROW_NUMBER() OVER (ORDER BY [DateOfCreation] ASC)
FROM @inv;
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 @inv as i on s.[InvoiceId] like ('%' + i.[InvoiceId] + '%') LEFT JOIN [dbo].[mfr__companies] as cy on s.[CustomerId] = cy.id;
With itm as (
SELECT
[net_itemsum] = CAST( SUM((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) as numeric(7,2))
, [bo_itemsum] = CAST( SUM( ((ISNULL([Price],0) * ISNULL([quantityhours],1)) - ISNULL([discount],0)) * (1 + (ISNULL(vat.[vat], 19.0) * 0.01))) as numeric(7,2))
, [vf] = MAX(1 + (ISNULL(vat.[vat], 19.0) * 0.01))
, itm.[ServiceRequestId]
, sreq.[invoice.Id]
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'
GROUP BY itm.[ServiceRequestId], sreq.[invoice.Id]
),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'
)
select
[Umsatz (ohne Soll/Haben-Kz)] = ABS([invoiceBalance])
,[EINZELPOS_brutto] = itm.bo_itemsum
,[EINZELPOS_netto] = itm.net_itemsum
, itm.vf
,[Soll/Haben-Kennzeichen] = CASE WHEN [invoiceBalance] < 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] = ca.[account]
,[BU-Schlüssel] = ''
,[Belegdatum] = FORMAT(iv.[DateOfCreation], 'ddMM')
,[Belegfeld 1] = iv.[InvoiceId]
,[Belegfeld 2] = FORMAT(iv.[DateOfCreation], '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 [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 contra_accounts as ca ON ISNULL(vat.[vat], 19.0) = ca.[vat]
where iv.Id in (SELECT [Id] FROM @inv)
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 JOIN [dbo].[mfr__reports] as iv ON iv.[Id] = sreq.[invoice.Id]
), 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__getInvoices] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[fds__getInvoices]
@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
, [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;
DECLARE @inv TABLE([Id] bigint, [InvoiceID] varchar(255), [URI] nvarchar(255), [DocumentName] nvarchar(255), [DateOfCreation] date);
INSERT INTO @inv SELECT [Id],[invoiceid],[URI],[DocumentName],[DateOfCreation] FROM [dbo].[mfr__reports] where [IsInvoice] = 1 AND CAST([DateOfCreation] as date) between @startdate AND @enddate;
DECLARE @SReq TABLE ([id] bigint, [DateOfCreation] datetime, [name] nvarchar(255), [invoice.Id] bigint, [customer.ExternalId] bigint, [customer.Id] bigint, [ExternalId] nvarchar(255));
INSERT INTO @SReq
SELECT s.[Id], s.[DateOfCreation], s.[name], [invoice.Id] = i.[Id], [customer.ExternalId] = cy.ExternalId , [customer.Id] = cy.[id], s.[ExternalId] 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;
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))
, itm.[ServiceRequestId]
, sreq.[invoice.Id]
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'
GROUP BY itm.[ServiceRequestId], sreq.[invoice.Id]
),sc as(
SELECT s.[invoice.Id], [#] = COUNT(s.[id]) FROM @SReq as s GROUP BY s.[invoice.Id]
),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'
)
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] = 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] 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])
,[order] = ROW_NUMBER() OVER (ORDER BY iv.[DateOfCreation] ASC)
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]
LEFT JOIN contra_accounts as ca ON ISNULL(vat.[vat], 19.0) = ca.[vat]
where iv.Id in (SELECT [Id] FROM @inv)
order by iv.[DateOfCreation] ASC;
END
GO
/****** Object: StoredProcedure [dbo].[fds__getInvRequestItems] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[fds__getReportDocument]
@reportid bigint
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP(1)
[Id],[InvoiceID],[URI],[DocumentName],[isInvoice],[DateOfCreation]
,[order] = ROW_NUMBER() OVER (ORDER BY [DateOfCreation] ASC)
FROM [dbo].[mfr__reports] WHERE [id] = @reportid;
END
GO
/****** Object: StoredProcedure [dbo].[fds__getRequest_details] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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,
[isChild] bit NULL,
[baseorder] int
);
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]
,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END
,[baseorder] = 0
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]
,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END
,[baseorder] = 0
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];
/** OUTPUT + get other types **/
IF @mode in ('r','ov', '','f', 'ful')
BEGIN
SELECT
*
,[order] = ROW_NUMBER() OVER (ORDER BY [baseorder])
FROM @SReq;
END
IF @mode in ('i','ov','f', 'ful')
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]
, [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
IF @mode in ('f', 'ful')
BEGIN
SELECT stp.* FROM [dbo].[mfr__steps] as stp JOIN @SReq as s ON stp.ServiceRequestId = s.[Id];
with c as (
SELECT distinct cy.*
FROM [dbo].[mfr__companies] as cy JOIN @SReq as s on cy.[id] = s.[CustomerId]
), cc as (
SELECT DISTINCT
[CyId] = c.[Id]
,[CompanyName] = c.[name]
,ct.*
FROM [mfr__contacts] as ct JOIN [dbo].[mfr__*PartnerSet] as p on ct.[Id] = p.[PartnerId] and p.[Property] like 'Company[:]%Contact%' and p.[PartnerType] ='Contact'
JOIN c on p.[EntityId] = c.[Id]
), loc as(
SELECT
[CyId] = c.[Id]
,l.*
,[#] = ROW_NUMBER() OVER ( PARTITION BY c.[Id] ORDER BY l.[Id] )
FROM [mfr__#locations] as l JOIN c on l.[Property] = 'Company:Location' AND l.[EntityId] = c.[Id]
)
SELECT
cc.[CompanyName]
, cc.[Gender]
, cc.[FirstName]
, cc.[LastName]
, loc.[AddressString]
,loc.[Postal]
,loc.[City]
,loc.[State]
,loc.[Country]
,loc.[Longitude]
,loc.[Latitude]
FROM cc join loc on cc.[CyId] = loc.[CyId] and loc.[#] = 1
;
END
END
GO
/****** Object: StoredProcedure [dbo].[fds__getRequests_open] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[fds__getRequests_open]
@tgtdate date
,@mode varchar(1) = ''
,@completed bit = 1
,@authuser varchar(100)
AS
BEGIN
SET NOCOUNT ON;
SELECT [title] = 'Übersicht der offenen Aufträge';
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,
[isChild] bit NULL,
[baseorder] int
);
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]
,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END
,[baseorder] = 0
FROM [dbo].[mfr__servicerequests] as s
WHERE [workdoneat] is not null and ISNULL([InvoiceId],'') = '' -- parent and childs;
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]
,[isChild] = CASE WHEN ISNULL(s.[ParentServiceRequestId],0) = 0 then 0 ELSE 1 END
,[baseorder] = 0
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];
SELECT * FROM @SReq order by baseorder
SELECT
[requestID] = s.[Id]
,r.*
,[order] = ROW_NUMBER() OVER (PARTITION BY s.[Id] ORDER BY r.[dateofcreation] ASC)
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__r_getBalanceByMonth] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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;
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 [dbo].[mfr__reports] as inv where inv.[IsInvoice] = 1
GROUP BY FORMAT( inv.[Dateofcreation], 'yyyy - MM', 'de');
END
GO
/****** Object: StoredProcedure [dbo].[fds__r_getBalanceByYearTopCustomer] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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
), 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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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
), 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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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)
)
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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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)
)
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__setReportVAT] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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].[fis_admin_addGroupMember] Script Date: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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'
,'<p>Bitte nennen Sie uns Ihre Kontaktdaten, so dass wir Sie kontaktieren können.</p>'
,'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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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'
,'<p>Bitte nennen Sie uns Ihre Kontaktdaten, so dass wir Sie kontaktieren können.</p>'
,'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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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'
,'<p>Bitte nennen Sie uns Ihre Kontaktdaten, so dass wir Sie kontaktieren können.</p>'
,'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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date, ,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Dr. Stefan Ott
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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: 18.05.2021 17:19:26 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <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