
/*
Mozliwośc duplikacji typów dokumentów

*/

set identity_insert [document].[documentType] on

insert into [document].[documentType]
( [documentType]
      ,[description]
      ,[componentName]
      ,[baseDocumentType]
      ,[displayOrder]
      ,[documentCategory]
      ,[correctiveDocumentType]
      ,[cooperationDocumentType]
      ,[includeInProductionPlan]
      ,[isForeignDocument]
      ,[isProforma]
      ,[isAdvanceInvoice]
      ,[forAgreement]
      ,[fullTextID]
      ,[outcomeDocumentType]
      ,[createOutcomeDefault]
      ,[accountingTYPE]
      ,[accountingRegister]
      ,[masterDocumentCategory]
      ,[realizeOrder]
      ,[isExportDocument]
      ,[isEUnionDocument]
      ,[isServiceDocument]
      ,[printoutDescription]
      ,[printoutExportDescription]
      ,[isInventoryRelated]
      ,[altersLastPrice]
      ,[calculateSysNetValueFromHeader]
      ,[hideFirm]
      ,[calculationType]
      ,[fiscalDocumentType]
      ,[jpkTag])


SELECT 'N' + [documentType]
      ,[description]
      ,[componentName]
      ,[baseDocumentType]
      ,[displayOrder]
      ,[documentCategory]
      ,[correctiveDocumentType]
      ,[cooperationDocumentType]
      ,[includeInProductionPlan]
      ,[isForeignDocument]
      ,[isProforma]
      ,[isAdvanceInvoice]
      ,[forAgreement]
      ,[fullTextID]
      ,[outcomeDocumentType]
      ,[createOutcomeDefault]
      ,[accountingTYPE]
      ,[accountingRegister]
      ,[masterDocumentCategory]
      ,[realizeOrder]
      ,[isExportDocument]
      ,[isEUnionDocument]
      ,[isServiceDocument]
      ,[printoutDescription]
      ,[printoutExportDescription]
      ,[isInventoryRelated]
      ,[altersLastPrice]
      ,[calculateSysNetValueFromHeader]
      ,[hideFirm]
      ,[calculationType]
      ,[fiscalDocumentType]
      ,[jpkTag]
  FROM [document].[documentType]
  where componentname= 'commision'


set identity_insert [document].[documentType] off




/*DODANIE WYDRUKÓW NA PODSTAWIE INNEGO TYPU*/

declare @existing_documenttype varchar(20) = 'M'
declare @new_documenttype varchar(20) = 'NM'

if exists (SELECT
		1
	FROM [configuration].[printout]
	WHERE [documentType] = @new_documenttype) BEGIN
PRINT 'Exist'
END ELSE BEGIN
	INSERT INTO [configuration].[printout] ([documentType]
	, [printoutName]
	, [template]
	, [componentName]
	, [isDefault]
	, [printoutHeader]
	, [printoutFooter]
	, [printoutLogo]
	, [printoutFilters]
	, [test]
	, [contentType]
	, [onClickHandler]
	, [reportFooter]
	, [printOrder]
	, [permission])

	SELECT
		@new_documenttype
		,[printoutName]
		,[template]
		,[componentName]
		,[isDefault]
		,[printoutHeader]
		,[printoutFooter]
		,[printoutLogo]
		,[printoutFilters]
		,[test]
		,[contentType]
		,[onClickHandler]
		,[reportFooter]
		,[printOrder]
		,[permission]
	FROM [configuration].[printout]
	WHERE documenttype = @existing_documenttype
END