UPDATE TBDD_BASECONFIG SET DB_VERSION = '1.9.8.3';
GO
--CHANGED	06.03.2025	INVOICE_POS_NOTE integriert
ALTER   FUNCTION [dbo].[FNDD_ZUGFERD_VIEW_RECEIPT_CUST_RESULT] (@pMSGID VARCHAR(100))
RETURNS TABLE
AS RETURN 
	(
		SELECt A.SPEC_NAME,A.ITEM_VALUE,A.Area,A.Row_Caption,A.xPosition,A.Y_eq_lastrow,A.SequenceItem ORDER_SEQ,A.Display FROM VWDD_ZUGFERD_VIEW_RECEIPT_TEMPLATE_ITEMS A 
		WHERE REFERENCE_GUID = @pMSGID
		AND A.SPEC_NAME NOT IN ('INVOICE_POSITION_AMOUNT','INVOICE_POSITION_NOTE',
						'INVOICE_TAXPOS_TAX_RATE','INVOICE_POSITION_ARTICLE','INVOICE_TAXPOS_AMOUNT',
						'INVOICE_TAXPOS_RATE','INVOICE_TAXPOS_TYPE','INVOICE_POSITION_TAX_AMOUNT')
		UNION
		SELECT SPEC_NAME,ITEM_VALUE,Area,'' Row_Caption,10 xPosition, 0 Y_eq_lastrow,SequenceItem ORDER_SEQ, Display FROM [dbo].[FNDD_ZUGFERD_VIEW_RECEIPT_POSITIONS] (@pMSGID)
		UNION
		SELECT SPEC_NAME,ITEM_VALUE,Area,'' Row_Caption,10 xPosition, 0 Y_eq_lastrow,SequenceItem ORDER_SEQ, Display FROM [dbo].[FNDD_ZUGFERD_VIEW_RECEIPT_TAX] (@pMSGID)
		UNION
		SELECT SPECNAME SPEC_NAME,Row_Caption,Area,Row_Caption Row_Caption,10 xPosition, 0 Y_eq_lastrow,SequenceItem ORDER_SEQ, Display FROM TBDD_ZUGFERD_VIEW_RECEIPT_TEMPLATE WHERE Area = 'INTERNAL'
	)
GO
USE [DD_ECM]
GO
/****** Object:  UserDefinedFunction [dbo].[FNDD_ZUGFERD_VIEW_RECEIPT_POSITIONS]    Script Date: 06.03.2025 17:18:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
--CHANGED	06.03.2025	INVOICE_POS_NOTE integriert
ALTER   FUNCTION [dbo].[FNDD_ZUGFERD_VIEW_RECEIPT_POSITIONS] (@pMSGID VARCHAR(100))
RETURNS @TABLE TABLE(SPEC_NAME VARCHAR(100),ITEM_VALUE VARCHAR(250),Area VARCHAR(60),SequenceItem INT,Display BIT)
AS
BEGIN
	DECLARE @GROUP_COUNTER INT,@INDEX INT = 15
	DECLARE cursGroupCounter CURSOR FOR 
		select GROUP_COUNTER from TBEDMI_ITEM_VALUE WHERE REFERENCE_GUID = @pMSGID And SPEC_NAME = 'INVOICE_POSITION_AMOUNT' ORDER BY GROUP_COUNTER
	OPEN cursGroupCounter 
		FETCH NEXT FROM cursGroupCounter INTO @GROUP_COUNTER
		WHILE @@FETCH_STATUS = 0
		BEGIN
			DECLARE @SPEC_NAME VARCHAR(100),@ITEM_VALUE VARCHAR(100),@Display BIT
			DECLARE cursPosItems CURSOR FOR 
				select A.SPEC_NAME,ITEM_VALUE,Display from TBEDMI_ITEM_VALUE A INNER JOIN TBDD_ZUGFERD_VIEW_RECEIPT_TEMPLATE B ON A.SPEC_NAME = B.SPECNAME WHERE REFERENCE_GUID = @pMSGID And A.SPEC_NAME IN ('INVOICE_POSITION_AMOUNT',
				'INVOICE_TAXPOS_TAX_RATE','INVOICE_POSITION_NOTE','INVOICE_POSITION_ARTICLE','INVOICE_POSITION_TAX_AMOUNT') AND GROUP_COUNTER = @GROUP_COUNTER ORDER BY B.SequenceItem
			OPEN cursPosItems 
				FETCH NEXT FROM cursPosItems INTO @SPEC_NAME,@ITEM_VALUE,@Display
				WHILE @@FETCH_STATUS = 0
				BEGIN
					SET @INDEX += 1
					INSERT INTO @TABLE (SPEC_NAME,ITEM_VALUE,Area,SequenceItem,Display) VALUES
					(@SPEC_NAME,@ITEM_VALUE,'POSITION',@INDEX,@Display)
				FETCH NEXT FROM cursPosItems INTO @SPEC_NAME,@ITEM_VALUE,@Display
			END
			CLOSE cursPosItems
			DEALLOCATE cursPosItems
		FETCH NEXT FROM cursGroupCounter INTO @GROUP_COUNTER
	END
	CLOSE cursGroupCounter
	DEALLOCATE cursGroupCounter
RETURN
END
GO