added improvements on set proces and minor other improvements

This commit is contained in:
Stefan
2026-07-13 22:40:08 +02:00
parent 5c0fdc6c1d
commit 5f85b75c22
55 changed files with 1170 additions and 357 deletions
@@ -177,7 +177,7 @@ BEGIN
DECLARE @step [dbo].[fds__tt__mfr_steps];
DECLARE @itm [dbo].[fds__tt__mfr_items];
DECLARE @itm [dbo].[fds__tt__mfr_items+];
DECLARE @company TABLE (
[Id] [bigint] NOT NULL,
[Location#ID] [bigint] NULL,
@@ -207,9 +207,19 @@ BEGIN
INSERT INTO @itm
SELECT
itm.*
, [baseorder] = s.[baseorder], [order] = ROW_NUMBER() OVER (PARTITION BY [ServiceRequestId] ORDER BY [SortOrder], itm.[Id])
from [dbo].[mfr__items] as itm JOIN @SReq as s ON itm.ServiceRequestId = s.[Id]
where itm.[Type] <> 'PartialInvoice';
, [baseorder] = s.[baseorder]
, [order] = ROW_NUMBER() OVER (PARTITION BY itm.[ServiceRequestId] ORDER BY itm.[SortOrder], itm.[Id])
, [SetItmID] = CASE WHEN itm.[Type] = 'Set' AND ISNULL(itm.[Price], 0) > 0 THEN NULL
ELSE MAX(CASE WHEN itm.[Type] = 'Set' AND ISNULL(itm.[Price], 0) > 0 THEN itm.[Id] ELSE NULL END)
OVER (
PARTITION BY itm.[ServiceRequestId]
ORDER BY itm.[SortOrder], itm.[Id]
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
)
END
FROM [dbo].[mfr__items] as itm
JOIN @SReq as s ON itm.ServiceRequestId = s.[Id]
WHERE itm.[Type] <> 'PartialInvoice';
DECLARE @NUM_of_int_Invoices int = 0;
@@ -264,6 +274,7 @@ BEGIN
,[UnitString] = 'Pauschal'
,[baseorder] = ai.[baseorder]
, [order] = 10000 + (ROW_NUMBER() OVER (PARTITION BY ai.[mfr__servicerequest] ORDER BY ai.[dateFinalized], ai.DateCreated) * 10)
,[SetItmId] = null
FROM associated_interims as ai
UNION
SELECT
@@ -293,6 +304,7 @@ BEGIN
,[UnitString] = 'Pauschal'
,[baseorder] = ai.[baseorder]
, [order] = 10001 + (ROW_NUMBER() OVER (PARTITION BY ai.[mfr__servicerequest] ORDER BY ai.[dateFinalized], ai.DateCreated) * 10)
,[SetItmId] = null
FROM associated_interims as ai
WHERE ISNULL(ai.open_amount,0.0) > 0.0;
@@ -381,6 +393,7 @@ BEGIN
, itm.[NameOrNumber]
, [Note] = IIF(ISNULL([Discount], 0) > 0, '<b>Rabatt '+ FORMAT([discount]*0.01,'#.0%','de-de') + '</b>', '') + ISNULL(itm.[Note],'')
, [order] = (itm.[baseorder] * 100) + itm.[order]
, [SetItmId]
FROM @itm as itm
LEFT JOIN [dbo].[fds__custom_vat] as vat ON itm.[Id] = vat.[EntityId] and vat.[EntityType] = 'item';
END