SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE   VIEW [transform_imr].[Aftersales_Rechnungen_operativ] as
SELECT "Invoice Type"
     , "Invoice Number"
     , "Subsidiary"
     , "Invoice Date"
     , "Service Date"
     , "Is Canceled"
     , "Vehicle Number"
     , "Invoice_Type_Invoice_Number"
     , '1' AS "Hauptbetrieb"
     , "Standort"
     , "Serviceberater"
     , "Umsatzart"
     , "Fabrikat"
     , "Fabrikat" AS "Description_Makes"
     , "Description_Models"
     , "Model"
     , "Fahrzeug"
     , '' AS "Kostenstelle"
     , "Marke"
     , "Auftragsart"
     , "Geschäftsart"
     , "Kunde"
     , "Kunde_Auftrag"
     , "Job Amount Net"
     , "Job Rebate"
     , "Part Amount Net"
     , "Part Rebate"
     , "Total Net"
     , "Hauptbetrieb Id"
     , "Hauptbetrieb Name"
     , "Standort Id"
     , "Standort Name"
     , "Labour Operation Id"
     , "Time Units"
     , "Net Price In Order"
     , "Rebate Percent"
     , "Goodwill Percent"
     , "Charge Type"
     , "Text Line"
     , "Usage Value"
     , "Negative Flag"
     , "Labour Type"
     , "Part Number"
     , "Amount"
     , "Sum"
     , "Parts Type"
     , "Source Table"
     , "Is Nominal"
     , "Wert_Euro"
     , "rein_raus"
     , "Order Number"
     , "Order Position"
     , "Order Position Line"
     , sum("Wert_Euro") OVER (PARTITION BY "Order Number", "Invoice_Type_Invoice_Number" ) AS "Summe_Wert_Euro"
     , "NL Lohn_ori"
     , "NLTeile_ori"
     , "Charge_Type_Description"
     , "Part_Type_Description"
     , "Produktbuchungsgruppe"
     , "Zuordnung"
     , "Lohn"
     , "Teile"
     , "EW Teile"
     , "Fremdl."
     , "EW Fremdl."
     , "TÜV"
     , "Mietw."
     , "Sonst."
     , "keine Zuordnung"
     , "Rabatt_Teile_aus_Invoice"
     , "NL Teile"
     , "Rabatt_Lohn_aus_Invoice"
     , "NL Lohn"
     , "Total Net" - (sum("Wert_Euro") OVER ( PARTITION BY "Order Number", "Invoice_Type_Invoice_Number" )) AS "Diff"
     , "Kontrollsumme_KZ"
     , "Usage_Value_Goodwill_Abzug"
     , "Usage_Value_neu"
     , "Position"
     , "Auftragsposition"
FROM (SELECT (left(((([T1]."invoice_type"))), 1)) + '_' + (left(((([T1]."invoice_number"))), 9)) AS "Invoice_Type_Invoice_Number"
           , [T7]."order_number" AS "Order Number"
           , (left(((([T7]."order_position_line"))), 2)) + ' - ' + (
        CASE
            WHEN [T7]."source_table" = 'labours' AND [T7]."labour_operation_id" IS NOT NULL
                THEN ltrim([T7]."labour_operation_id") + ' - ' + [T7]."text_line"
            WHEN [T7]."source_table" = 'labours' AND [T7]."labour_operation_id" IS NULL
                THEN 'ohne ID - ' + [T7]."text_line"
            WHEN [T7]."source_table" = 'parts' AND [T7]."labour_operation_id" IS NULL AND [T7]."part_number" IS NULL
                THEN 'ID fehlt - ' + [T7]."text_line"
            WHEN [T7]."source_table" = 'parts'
                THEN rtrim([T7]."part_number") + ' - ' + [T7]."text_line"
            ELSE NULL
        END
        ) AS "Auftragsposition"
           , CASE
                 WHEN [T7]."source_table" = 'labours' AND [T7]."labour_operation_id" IS NOT NULL
                     THEN ltrim([T7]."labour_operation_id") + ' - ' + [T7]."text_line"
                 WHEN [T7]."source_table" = 'labours' AND [T7]."labour_operation_id" IS NULL
                     THEN 'ohne ID - ' + [T7]."text_line"
                 WHEN [T7]."source_table" = 'parts' AND [T7]."labour_operation_id" IS NULL AND [T7]."part_number" IS NULL
                     THEN 'ID fehlt - ' + [T7]."text_line"
                 WHEN [T7]."source_table" = 'parts'
                     THEN rtrim([T7]."part_number") + ' - ' + [T7]."text_line"
                 ELSE NULL
             END AS "Position"
           , [T7]."usage_value" - (
        CASE
            WHEN ([T7]."goodwill_percent" <> 0)
                THEN ([T7]."usage_value" * ([T7]."goodwill_percent" / 100))
            ELSE ([T7]."usage_value")
        END
        ) AS "Usage_Value_neu"
           , CASE
                 WHEN ([T7]."goodwill_percent" <> 0)
                     THEN ([T7]."usage_value" * ([T7]."goodwill_percent" / 100))
                 ELSE (0)
             END AS "Usage_Value_Goodwill_Abzug"
           , (
                 CASE
                     WHEN ([T8]."Zuordnung" = 'Lohn')
                         THEN (
                         (
                             (
                                 (
                                     CASE
                                         WHEN ([T7]."net_price_in_order" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."net_price_in_order")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."net_price_in_order")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 ) + (
                                 (
                                     CASE
                                         WHEN ([T7]."sum" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."sum")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."sum" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."sum")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         (
                                                             round(CASE
                                                                       WHEN (
                                                                           ([T7]."rebate_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."rebate_percent" / 100)
                                                                           )
                                                                       WHEN (
                                                                           ([T7]."goodwill_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."goodwill_percent" / 100)
                                                                           )
                                                                       ELSE (0)
                                                                   END, 2, 0)
                                                             )
                                                         ) <> 0
                                                     )
                                                     AND (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'parts')
                                                                     )
                                                                     AND ([T1]."part_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) = 0
                                                     )
                                                 )
                                                 AND ([T7]."goodwill_percent" = 0)
                                             )
                                             THEN (0)
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 )
                             )
                         )
                     ELSE (0)
                 END
                 ) + (
                 CASE
                     WHEN ([T7]."source_table" = 'parts')
                         THEN (
                         (
                             (
                                 (
                                     CASE
                                         WHEN ([T7]."net_price_in_order" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."net_price_in_order")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."net_price_in_order")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 ) + (
                                 (
                                     CASE
                                         WHEN ([T7]."sum" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."sum")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."sum" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."sum")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         (
                                                             round(CASE
                                                                       WHEN (
                                                                           ([T7]."rebate_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."rebate_percent" / 100)
                                                                           )
                                                                       WHEN (
                                                                           ([T7]."goodwill_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."goodwill_percent" / 100)
                                                                           )
                                                                       ELSE (0)
                                                                   END, 2, 0)
                                                             )
                                                         ) <> 0
                                                     )
                                                     AND (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'parts')
                                                                     )
                                                                     AND ([T1]."part_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) = 0
                                                     )
                                                 )
                                                 AND ([T7]."goodwill_percent" = 0)
                                             )
                                             THEN (0)
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 )
                             )
                         )
                     ELSE (0)
                 END
                 ) + (
                 CASE
                     WHEN ([T8]."Zuordnung" = 'Fremdl.')
                         THEN (
                         (
                             (
                                 (
                                     CASE
                                         WHEN ([T7]."net_price_in_order" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."net_price_in_order")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."net_price_in_order")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 ) + (
                                 (
                                     CASE
                                         WHEN ([T7]."sum" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."sum")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."sum" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."sum")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         (
                                                             round(CASE
                                                                       WHEN (
                                                                           ([T7]."rebate_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."rebate_percent" / 100)
                                                                           )
                                                                       WHEN (
                                                                           ([T7]."goodwill_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."goodwill_percent" / 100)
                                                                           )
                                                                       ELSE (0)
                                                                   END, 2, 0)
                                                             )
                                                         ) <> 0
                                                     )
                                                     AND (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'parts')
                                                                     )
                                                                     AND ([T1]."part_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) = 0
                                                     )
                                                 )
                                                 AND ([T7]."goodwill_percent" = 0)
                                             )
                                             THEN (0)
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 )
                             )
                         )
                     ELSE (0)
                 END
                 ) + (
                 CASE
                     WHEN ([T8]."Zuordnung" = 'TÜV')
                         THEN (
                         (
                             (
                                 (
                                     CASE
                                         WHEN ([T7]."net_price_in_order" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."net_price_in_order")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."net_price_in_order")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 ) + (
                                 (
                                     CASE
                                         WHEN ([T7]."sum" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."sum")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."sum" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."sum")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         (
                                                             round(CASE
                                                                       WHEN (
                                                                           ([T7]."rebate_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."rebate_percent" / 100)
                                                                           )
                                                                       WHEN (
                                                                           ([T7]."goodwill_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."goodwill_percent" / 100)
                                                                           )
                                                                       ELSE (0)
                                                                   END, 2, 0)
                                                             )
                                                         ) <> 0
                                                     )
                                                     AND (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'parts')
                                                                     )
                                                                     AND ([T1]."part_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) = 0
                                                     )
                                                 )
                                                 AND ([T7]."goodwill_percent" = 0)
                                             )
                                             THEN (0)
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 )
                             )
                         )
                     ELSE (0)
                 END
                 ) + (
                 CASE
                     WHEN ([T8]."Zuordnung" = 'Mietw.')
                         THEN (
                         (
                             (
                                 (
                                     CASE
                                         WHEN ([T7]."net_price_in_order" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."net_price_in_order")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."net_price_in_order")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 ) + (
                                 (
                                     CASE
                                         WHEN ([T7]."sum" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."sum")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."sum" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."sum")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         (
                                                             round(CASE
                                                                       WHEN (
                                                                           ([T7]."rebate_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."rebate_percent" / 100)
                                                                           )
                                                                       WHEN (
                                                                           ([T7]."goodwill_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."goodwill_percent" / 100)
                                                                           )
                                                                       ELSE (0)
                                                                   END, 2, 0)
                                                             )
                                                         ) <> 0
                                                     )
                                                     AND (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'parts')
                                                                     )
                                                                     AND ([T1]."part_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) = 0
                                                     )
                                                 )
                                                 AND ([T7]."goodwill_percent" = 0)
                                             )
                                             THEN (0)
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 )
                             )
                         )
                     ELSE (0)
                 END
                 ) + (
                 CASE
                     WHEN ([T8]."Zuordnung" = 'Sonst.')
                         THEN (
                         (
                             (
                                 (
                                     CASE
                                         WHEN ([T7]."net_price_in_order" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."net_price_in_order")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."net_price_in_order")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'labours')
                                                                 )
                                                                 AND ([T1]."job_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 ) + (
                                 (
                                     CASE
                                         WHEN ([T7]."sum" IS NULL)
                                             THEN (0)
                                         ELSE ([T7]."sum")
                                     END
                                     ) - (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) = 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) <> 0
                                                 )
                                             )
                                             THEN (
                                             (
                                                 CASE
                                                     WHEN ([T7]."sum" IS NULL)
                                                         THEN (0)
                                                     ELSE ([T7]."sum")
                                                 END
                                                 ) * (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) / 100
                                                 )
                                             )
                                         WHEN (
                                             (
                                                 (
                                                     (
                                                         (
                                                             round(CASE
                                                                       WHEN (
                                                                           ([T7]."rebate_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."rebate_percent" / 100)
                                                                           )
                                                                       WHEN (
                                                                           ([T7]."goodwill_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."goodwill_percent" / 100)
                                                                           )
                                                                       ELSE (0)
                                                                   END, 2, 0)
                                                             )
                                                         ) <> 0
                                                     )
                                                     AND (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'parts')
                                                                     )
                                                                     AND ([T1]."part_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) = 0
                                                     )
                                                 )
                                                 AND ([T7]."goodwill_percent" = 0)
                                             )
                                             THEN (0)
                                         ELSE (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 )
                                             )
                                     END
                                     )
                                 )
                             )
                         )
                     ELSE (0)
                 END
                 ) AS "Kontrollsumme_KZ"
           , [T1]."total_net" AS "Total Net"
           , CASE
                 WHEN (
                     (
                         (
                             (
                                 round(CASE
                                           WHEN (
                                               ([T7]."rebate_percent" <> 0)
                                                   AND ([T7]."source_table" = 'labours')
                                               )
                                               THEN (
                                               (
                                                   CASE
                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                           THEN (0)
                                                       ELSE ([T7]."net_price_in_order")
                                                   END
                                                   ) * ([T7]."rebate_percent" / 100)
                                               )
                                           WHEN (
                                               ([T7]."goodwill_percent" <> 0)
                                                   AND ([T7]."source_table" = 'labours')
                                               )
                                               THEN (
                                               (
                                                   CASE
                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                           THEN (0)
                                                       ELSE ([T7]."net_price_in_order")
                                                   END
                                                   ) * ([T7]."goodwill_percent" / 100)
                                               )
                                           ELSE (0)
                                       END, 2, 0)
                                 )
                             ) = 0
                         )
                         AND (
                         (
                             CASE
                                 WHEN (
                                     (
                                         (
                                             ((convert(float, [T7]."rebate_percent")) = 0)
                                                 AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                             )
                                             AND ([T7]."source_table" = 'labours')
                                         )
                                         AND ([T1]."job_rebate" <> 0)
                                     )
                                     THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                 ELSE (0)
                             END
                             ) <> 0
                         )
                     )
                     THEN (
                     (
                         CASE
                             WHEN ([T7]."net_price_in_order" IS NULL)
                                 THEN (0)
                             ELSE ([T7]."net_price_in_order")
                         END
                         ) * (
                         (
                             CASE
                                 WHEN (
                                     (
                                         (
                                             ((convert(float, [T7]."rebate_percent")) = 0)
                                                 AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                             )
                                             AND ([T7]."source_table" = 'labours')
                                         )
                                         AND ([T1]."job_rebate" <> 0)
                                     )
                                     THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                 ELSE (0)
                             END
                             ) / 100
                         )
                     )
                 ELSE (
                     (
                         (
                             round(CASE
                                       WHEN (
                                           ([T7]."rebate_percent" <> 0)
                                               AND ([T7]."source_table" = 'labours')
                                           )
                                           THEN (
                                           (
                                               CASE
                                                   WHEN ([T7]."net_price_in_order" IS NULL)
                                                       THEN (0)
                                                   ELSE ([T7]."net_price_in_order")
                                               END
                                               ) * ([T7]."rebate_percent" / 100)
                                           )
                                       WHEN (
                                           ([T7]."goodwill_percent" <> 0)
                                               AND ([T7]."source_table" = 'labours')
                                           )
                                           THEN (
                                           (
                                               CASE
                                                   WHEN ([T7]."net_price_in_order" IS NULL)
                                                       THEN (0)
                                                   ELSE ([T7]."net_price_in_order")
                                               END
                                               ) * ([T7]."goodwill_percent" / 100)
                                           )
                                       ELSE (0)
                                   END, 2, 0)
                             )
                         )
                     )
             END AS "NL Lohn"
           , CASE
                 WHEN (
                     (
                         (
                             ((convert(float, [T7]."rebate_percent")) = 0)
                                 AND ((convert(float, [T7]."goodwill_percent")) = 0)
                             )
                             AND ([T7]."source_table" = 'labours')
                         )
                         AND ([T1]."job_rebate" <> 0)
                     )
                     THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                 ELSE (0)
             END AS "Rabatt_Lohn_aus_Invoice"
           , CASE
                 WHEN (
                     (
                         (
                             (
                                 round(CASE
                                           WHEN (
                                               ([T7]."rebate_percent" <> 0)
                                                   AND ([T7]."source_table" = 'parts')
                                               )
                                               THEN (
                                               (
                                                   CASE
                                                       WHEN ([T7]."sum" IS NULL)
                                                           THEN (0)
                                                       ELSE ([T7]."sum")
                                                   END
                                                   ) * ([T7]."rebate_percent" / 100)
                                               )
                                           WHEN (
                                               ([T7]."goodwill_percent" <> 0)
                                                   AND ([T7]."source_table" = 'parts')
                                               )
                                               THEN (
                                               (
                                                   CASE
                                                       WHEN ([T7]."sum" IS NULL)
                                                           THEN (0)
                                                       ELSE ([T7]."sum")
                                                   END
                                                   ) * ([T7]."goodwill_percent" / 100)
                                               )
                                           ELSE (0)
                                       END, 2, 0)
                                 )
                             ) = 0
                         )
                         AND (
                         (
                             CASE
                                 WHEN (
                                     (
                                         (
                                             ((convert(float, [T7]."rebate_percent")) = 0)
                                                 AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                             )
                                             AND ([T7]."source_table" = 'parts')
                                         )
                                         AND ([T1]."part_rebate" <> 0)
                                     )
                                     THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                 ELSE (0)
                             END
                             ) <> 0
                         )
                     )
                     THEN (
                     (
                         CASE
                             WHEN ([T7]."sum" IS NULL)
                                 THEN (0)
                             ELSE ([T7]."sum")
                         END
                         ) * (
                         (
                             CASE
                                 WHEN (
                                     (
                                         (
                                             ((convert(float, [T7]."rebate_percent")) = 0)
                                                 AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                             )
                                             AND ([T7]."source_table" = 'parts')
                                         )
                                         AND ([T1]."part_rebate" <> 0)
                                     )
                                     THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                 ELSE (0)
                             END
                             ) / 100
                         )
                     )
                 WHEN (
                     (
                         (
                             (
                                 (
                                     round(CASE
                                               WHEN (
                                                   ([T7]."rebate_percent" <> 0)
                                                       AND ([T7]."source_table" = 'parts')
                                                   )
                                                   THEN (
                                                   (
                                                       CASE
                                                           WHEN ([T7]."sum" IS NULL)
                                                               THEN (0)
                                                           ELSE ([T7]."sum")
                                                       END
                                                       ) * ([T7]."rebate_percent" / 100)
                                                   )
                                               WHEN (
                                                   ([T7]."goodwill_percent" <> 0)
                                                       AND ([T7]."source_table" = 'parts')
                                                   )
                                                   THEN (
                                                   (
                                                       CASE
                                                           WHEN ([T7]."sum" IS NULL)
                                                               THEN (0)
                                                           ELSE ([T7]."sum")
                                                       END
                                                       ) * ([T7]."goodwill_percent" / 100)
                                                   )
                                               ELSE (0)
                                           END, 2, 0)
                                     )
                                 ) <> 0
                             )
                             AND (
                             (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                 )
                                                 AND ([T7]."source_table" = 'parts')
                                             )
                                             AND ([T1]."part_rebate" <> 0)
                                         )
                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                     ELSE (0)
                                 END
                                 ) = 0
                             )
                         )
                         AND ([T7]."goodwill_percent" = 0)
                     )
                     THEN (0)
                 ELSE (
                     (
                         (
                             round(CASE
                                       WHEN (
                                           ([T7]."rebate_percent" <> 0)
                                               AND ([T7]."source_table" = 'parts')
                                           )
                                           THEN (
                                           (
                                               CASE
                                                   WHEN ([T7]."sum" IS NULL)
                                                       THEN (0)
                                                   ELSE ([T7]."sum")
                                               END
                                               ) * ([T7]."rebate_percent" / 100)
                                           )
                                       WHEN (
                                           ([T7]."goodwill_percent" <> 0)
                                               AND ([T7]."source_table" = 'parts')
                                           )
                                           THEN (
                                           (
                                               CASE
                                                   WHEN ([T7]."sum" IS NULL)
                                                       THEN (0)
                                                   ELSE ([T7]."sum")
                                               END
                                               ) * ([T7]."goodwill_percent" / 100)
                                           )
                                       ELSE (0)
                                   END, 2, 0)
                             )
                         )
                     )
             END AS "NL Teile"
           , CASE
                 WHEN (
                     (
                         (
                             ((convert(float, [T7]."rebate_percent")) = 0)
                                 AND ((convert(float, [T7]."goodwill_percent")) = 0)
                             )
                             AND ([T7]."source_table" = 'parts')
                         )
                         AND ([T1]."part_rebate" <> 0)
                     )
                     THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                 ELSE (0)
             END AS "Rabatt_Teile_aus_Invoice"
           , CASE
                 WHEN ([T8]."Zuordnung" = 'keine Zuordnung')
                     THEN (
                     (
                         (
                             (
                                 CASE
                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."net_price_in_order")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."net_price_in_order" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."net_price_in_order")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             ) + (
                             (
                                 CASE
                                     WHEN ([T7]."sum" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."sum")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."sum" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."sum")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) <> 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) = 0
                                                 )
                                             )
                                             AND ([T7]."goodwill_percent" = 0)
                                         )
                                         THEN (0)
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             )
                         )
                     )
                 ELSE (0)
             END AS "keine Zuordnung"
           , CASE
                 WHEN ([T8]."Zuordnung" = 'Sonst.')
                     THEN (
                     (
                         (
                             (
                                 CASE
                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."net_price_in_order")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."net_price_in_order" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."net_price_in_order")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             ) + (
                             (
                                 CASE
                                     WHEN ([T7]."sum" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."sum")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."sum" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."sum")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) <> 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) = 0
                                                 )
                                             )
                                             AND ([T7]."goodwill_percent" = 0)
                                         )
                                         THEN (0)
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             )
                         )
                     )
                 ELSE (0)
             END AS "Sonst."
           , CASE
                 WHEN ([T8]."Zuordnung" = 'Mietw.')
                     THEN (
                     (
                         (
                             (
                                 CASE
                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."net_price_in_order")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."net_price_in_order" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."net_price_in_order")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             ) + (
                             (
                                 CASE
                                     WHEN ([T7]."sum" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."sum")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."sum" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."sum")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) <> 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) = 0
                                                 )
                                             )
                                             AND ([T7]."goodwill_percent" = 0)
                                         )
                                         THEN (0)
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             )
                         )
                     )
                 ELSE (0)
             END AS "Mietw."
           , CASE
                 WHEN ([T8]."Zuordnung" = 'TÜV')
                     THEN (
                     (
                         (
                             (
                                 CASE
                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."net_price_in_order")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."net_price_in_order" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."net_price_in_order")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             ) + (
                             (
                                 CASE
                                     WHEN ([T7]."sum" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."sum")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."sum" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."sum")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) <> 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) = 0
                                                 )
                                             )
                                             AND ([T7]."goodwill_percent" = 0)
                                         )
                                         THEN (0)
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             )
                         )
                     )
                 ELSE (0)
             END AS "TÜV"
           , CASE
                 WHEN ([T8]."Zuordnung" = 'Fremdl.')
                     THEN (
                     (
                         [T7]."usage_value" - (
                             CASE
                                 WHEN ([T7]."goodwill_percent" <> 0)
                                     THEN ([T7]."usage_value" * ([T7]."goodwill_percent" / 100))
                                 ELSE (0)
                             END
                             )
                         )
                     )
                 ELSE (0)
             END AS "EW Fremdl."
           , CASE
                 WHEN ([T8]."Zuordnung" = 'Fremdl.')
                     THEN (
                     (
                         (
                             (
                                 CASE
                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."net_price_in_order")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."net_price_in_order" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."net_price_in_order")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             ) + (
                             (
                                 CASE
                                     WHEN ([T7]."sum" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."sum")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."sum" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."sum")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) <> 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) = 0
                                                 )
                                             )
                                             AND ([T7]."goodwill_percent" = 0)
                                         )
                                         THEN (0)
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             )
                         )
                     )
                 ELSE (0)
             END AS "Fremdl."
           , CASE
                 WHEN ([T7]."source_table" = 'parts')
                     THEN (
                     (
                         [T7]."usage_value" - (
                             CASE
                                 WHEN ([T7]."goodwill_percent" <> 0)
                                     THEN ([T7]."usage_value" * ([T7]."goodwill_percent" / 100))
                                 ELSE (0)
                             END
                             )
                         )
                     )
                 ELSE (0)
             END AS "EW Teile"
           , CASE
                 WHEN ([T7]."source_table" = 'parts')
                     THEN (
                     (
                         (
                             (
                                 CASE
                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."net_price_in_order")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."net_price_in_order" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."net_price_in_order")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             ) + (
                             (
                                 CASE
                                     WHEN ([T7]."sum" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."sum")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."sum" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."sum")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) <> 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) = 0
                                                 )
                                             )
                                             AND ([T7]."goodwill_percent" = 0)
                                         )
                                         THEN (0)
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             )
                         )
                     )
                 ELSE (0)
             END AS "Teile"
           , CASE
                 WHEN ([T8]."Zuordnung" = 'Lohn')
                     THEN (
                     (
                         (
                             (
                                 CASE
                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."net_price_in_order")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'labours')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."net_price_in_order")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."net_price_in_order" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."net_price_in_order")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'labours')
                                                             )
                                                             AND ([T1]."job_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'labours')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."net_price_in_order" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."net_price_in_order")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             ) + (
                             (
                                 CASE
                                     WHEN ([T7]."sum" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."sum")
                                 END
                                 ) - (
                                 CASE
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     round(CASE
                                                               WHEN (
                                                                   ([T7]."rebate_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."rebate_percent" / 100)
                                                                   )
                                                               WHEN (
                                                                   ([T7]."goodwill_percent" <> 0)
                                                                       AND ([T7]."source_table" = 'parts')
                                                                   )
                                                                   THEN (
                                                                   (
                                                                       CASE
                                                                           WHEN ([T7]."sum" IS NULL)
                                                                               THEN (0)
                                                                           ELSE ([T7]."sum")
                                                                       END
                                                                       ) * ([T7]."goodwill_percent" / 100)
                                                                   )
                                                               ELSE (0)
                                                           END, 2, 0)
                                                     )
                                                 ) = 0
                                             )
                                             AND (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) <> 0
                                             )
                                         )
                                         THEN (
                                         (
                                             CASE
                                                 WHEN ([T7]."sum" IS NULL)
                                                     THEN (0)
                                                 ELSE ([T7]."sum")
                                             END
                                             ) * (
                                             (
                                                 CASE
                                                     WHEN (
                                                         (
                                                             (
                                                                 ((convert(float, [T7]."rebate_percent")) = 0)
                                                                     AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                 )
                                                                 AND ([T7]."source_table" = 'parts')
                                                             )
                                                             AND ([T1]."part_rebate" <> 0)
                                                         )
                                                         THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                     ELSE (0)
                                                 END
                                                 ) / 100
                                             )
                                         )
                                     WHEN (
                                         (
                                             (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     ) <> 0
                                                 )
                                                 AND (
                                                 (
                                                     CASE
                                                         WHEN (
                                                             (
                                                                 (
                                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                     )
                                                                     AND ([T7]."source_table" = 'parts')
                                                                 )
                                                                 AND ([T1]."part_rebate" <> 0)
                                                             )
                                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                         ELSE (0)
                                                     END
                                                     ) = 0
                                                 )
                                             )
                                             AND ([T7]."goodwill_percent" = 0)
                                         )
                                         THEN (0)
                                     ELSE (
                                         (
                                             (
                                                 round(CASE
                                                           WHEN (
                                                               ([T7]."rebate_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."rebate_percent" / 100)
                                                               )
                                                           WHEN (
                                                               ([T7]."goodwill_percent" <> 0)
                                                                   AND ([T7]."source_table" = 'parts')
                                                               )
                                                               THEN (
                                                               (
                                                                   CASE
                                                                       WHEN ([T7]."sum" IS NULL)
                                                                           THEN (0)
                                                                       ELSE ([T7]."sum")
                                                                   END
                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                               )
                                                           ELSE (0)
                                                       END, 2, 0)
                                                 )
                                             )
                                         )
                                 END
                                 )
                             )
                         )
                     )
                 ELSE (0)
             END AS "Lohn"
           , [T8]."Zuordnung" AS "Zuordnung"
           , CASE
                 WHEN ([T7]."source_table" = 'labours')
                     THEN ((rtrim(((([T7]."charge_type"))))) + ' - ' + [T8]."description")
                 WHEN ([T7]."source_table" = 'parts')
                     THEN ((rtrim(((([T7]."parts_type"))))) + ' - ' + [T9]."description")
                 ELSE NULL
             END AS "Produktbuchungsgruppe"
           , [T9]."description" AS "Part_Type_Description"
           , [T8]."description" AS "Charge_Type_Description"
           , (
        round(CASE
                  WHEN (
                      ([T7]."rebate_percent" <> 0)
                          AND ([T7]."source_table" = 'parts')
                      )
                      THEN (
                      (
                          CASE
                              WHEN ([T7]."sum" IS NULL)
                                  THEN (0)
                              ELSE ([T7]."sum")
                          END
                          ) * ([T7]."rebate_percent" / 100)
                      )
                  WHEN (
                      ([T7]."goodwill_percent" <> 0)
                          AND ([T7]."source_table" = 'parts')
                      )
                      THEN (
                      (
                          CASE
                              WHEN ([T7]."sum" IS NULL)
                                  THEN (0)
                              ELSE ([T7]."sum")
                          END
                          ) * ([T7]."goodwill_percent" / 100)
                      )
                  ELSE (0)
              END, 2, 0)
        ) AS "NLTeile_ori"
           , (
        round(CASE
                  WHEN (
                      ([T7]."rebate_percent" <> 0)
                          AND ([T7]."source_table" = 'labours')
                      )
                      THEN (
                      (
                          CASE
                              WHEN ([T7]."net_price_in_order" IS NULL)
                                  THEN (0)
                              ELSE ([T7]."net_price_in_order")
                          END
                          ) * ([T7]."rebate_percent" / 100)
                      )
                  WHEN (
                      ([T7]."goodwill_percent" <> 0)
                          AND ([T7]."source_table" = 'labours')
                      )
                      THEN (
                      (
                          CASE
                              WHEN ([T7]."net_price_in_order" IS NULL)
                                  THEN (0)
                              ELSE ([T7]."net_price_in_order")
                          END
                          ) * ([T7]."goodwill_percent" / 100)
                      )
                  ELSE (0)
              END, 2, 0)
        ) AS "NL Lohn_ori"
           , [T7]."order_position_line" AS "Order Position Line"
           , [T7]."order_position" AS "Order Position"
           , CASE
                 WHEN (
                     (
                         ([T7]."time_units" = 0)
                             AND (
                             (
                                 (
                                     (
                                         CASE
                                             WHEN ([T7]."net_price_in_order" IS NULL)
                                                 THEN (0)
                                             ELSE ([T7]."net_price_in_order")
                                         END
                                         ) - (
                                         CASE
                                             WHEN (
                                                 (
                                                     (
                                                         (
                                                             round(CASE
                                                                       WHEN (
                                                                           ([T7]."rebate_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'labours')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."net_price_in_order")
                                                                               END
                                                                               ) * ([T7]."rebate_percent" / 100)
                                                                           )
                                                                       WHEN (
                                                                           ([T7]."goodwill_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'labours')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."net_price_in_order")
                                                                               END
                                                                               ) * ([T7]."goodwill_percent" / 100)
                                                                           )
                                                                       ELSE (0)
                                                                   END, 2, 0)
                                                             )
                                                         ) = 0
                                                     )
                                                     AND (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'labours')
                                                                     )
                                                                     AND ([T1]."job_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) <> 0
                                                     )
                                                 )
                                                 THEN (
                                                 (
                                                     CASE
                                                         WHEN ([T7]."net_price_in_order" IS NULL)
                                                             THEN (0)
                                                         ELSE ([T7]."net_price_in_order")
                                                     END
                                                     ) * (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'labours')
                                                                     )
                                                                     AND ([T1]."job_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) / 100
                                                     )
                                                 )
                                             ELSE (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'labours')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."net_price_in_order")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     )
                                                 )
                                         END
                                         )
                                     ) + (
                                     (
                                         CASE
                                             WHEN ([T7]."sum" IS NULL)
                                                 THEN (0)
                                             ELSE ([T7]."sum")
                                         END
                                         ) - (
                                         CASE
                                             WHEN (
                                                 (
                                                     (
                                                         (
                                                             round(CASE
                                                                       WHEN (
                                                                           ([T7]."rebate_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."rebate_percent" / 100)
                                                                           )
                                                                       WHEN (
                                                                           ([T7]."goodwill_percent" <> 0)
                                                                               AND ([T7]."source_table" = 'parts')
                                                                           )
                                                                           THEN (
                                                                           (
                                                                               CASE
                                                                                   WHEN ([T7]."sum" IS NULL)
                                                                                       THEN (0)
                                                                                   ELSE ([T7]."sum")
                                                                               END
                                                                               ) * ([T7]."goodwill_percent" / 100)
                                                                           )
                                                                       ELSE (0)
                                                                   END, 2, 0)
                                                             )
                                                         ) = 0
                                                     )
                                                     AND (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'parts')
                                                                     )
                                                                     AND ([T1]."part_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) <> 0
                                                     )
                                                 )
                                                 THEN (
                                                 (
                                                     CASE
                                                         WHEN ([T7]."sum" IS NULL)
                                                             THEN (0)
                                                         ELSE ([T7]."sum")
                                                     END
                                                     ) * (
                                                     (
                                                         CASE
                                                             WHEN (
                                                                 (
                                                                     (
                                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                         )
                                                                         AND ([T7]."source_table" = 'parts')
                                                                     )
                                                                     AND ([T1]."part_rebate" <> 0)
                                                                 )
                                                                 THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                             ELSE (0)
                                                         END
                                                         ) / 100
                                                     )
                                                 )
                                             WHEN (
                                                 (
                                                     (
                                                         (
                                                             (
                                                                 round(CASE
                                                                           WHEN (
                                                                               ([T7]."rebate_percent" <> 0)
                                                                                   AND ([T7]."source_table" = 'parts')
                                                                               )
                                                                               THEN (
                                                                               (
                                                                                   CASE
                                                                                       WHEN ([T7]."sum" IS NULL)
                                                                                           THEN (0)
                                                                                       ELSE ([T7]."sum")
                                                                                   END
                                                                                   ) * ([T7]."rebate_percent" / 100)
                                                                               )
                                                                           WHEN (
                                                                               ([T7]."goodwill_percent" <> 0)
                                                                                   AND ([T7]."source_table" = 'parts')
                                                                               )
                                                                               THEN (
                                                                               (
                                                                                   CASE
                                                                                       WHEN ([T7]."sum" IS NULL)
                                                                                           THEN (0)
                                                                                       ELSE ([T7]."sum")
                                                                                   END
                                                                                   ) * ([T7]."goodwill_percent" / 100)
                                                                               )
                                                                           ELSE (0)
                                                                       END, 2, 0)
                                                                 )
                                                             ) <> 0
                                                         )
                                                         AND (
                                                         (
                                                             CASE
                                                                 WHEN (
                                                                     (
                                                                         (
                                                                             ((convert(float, [T7]."rebate_percent")) = 0)
                                                                                 AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                             )
                                                                             AND ([T7]."source_table" = 'parts')
                                                                         )
                                                                         AND ([T1]."part_rebate" <> 0)
                                                                     )
                                                                     THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                                 ELSE (0)
                                                             END
                                                             ) = 0
                                                         )
                                                     )
                                                     AND ([T7]."goodwill_percent" = 0)
                                                 )
                                                 THEN (0)
                                             ELSE (
                                                 (
                                                     (
                                                         round(CASE
                                                                   WHEN (
                                                                       ([T7]."rebate_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."rebate_percent" / 100)
                                                                       )
                                                                   WHEN (
                                                                       ([T7]."goodwill_percent" <> 0)
                                                                           AND ([T7]."source_table" = 'parts')
                                                                       )
                                                                       THEN (
                                                                       (
                                                                           CASE
                                                                               WHEN ([T7]."sum" IS NULL)
                                                                                   THEN (0)
                                                                               ELSE ([T7]."sum")
                                                                           END
                                                                           ) * ([T7]."goodwill_percent" / 100)
                                                                       )
                                                                   ELSE (0)
                                                               END, 2, 0)
                                                         )
                                                     )
                                                 )
                                         END
                                         )
                                     )
                                 ) = 0
                             )
                         )
                         AND ([T7]."rebate_percent" = 0)
                     )
                     THEN ('raus')
                 ELSE ('rein')
             END AS "rein_raus"
           , (
                 (
                     CASE
                         WHEN ([T7]."net_price_in_order" IS NULL)
                             THEN (0)
                         ELSE ([T7]."net_price_in_order")
                     END
                     ) - (
                     CASE
                         WHEN (
                             (
                                 (
                                     (
                                         round(CASE
                                                   WHEN (
                                                       ([T7]."rebate_percent" <> 0)
                                                           AND ([T7]."source_table" = 'labours')
                                                       )
                                                       THEN (
                                                       (
                                                           CASE
                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                   THEN (0)
                                                               ELSE ([T7]."net_price_in_order")
                                                           END
                                                           ) * ([T7]."rebate_percent" / 100)
                                                       )
                                                   WHEN (
                                                       ([T7]."goodwill_percent" <> 0)
                                                           AND ([T7]."source_table" = 'labours')
                                                       )
                                                       THEN (
                                                       (
                                                           CASE
                                                               WHEN ([T7]."net_price_in_order" IS NULL)
                                                                   THEN (0)
                                                               ELSE ([T7]."net_price_in_order")
                                                           END
                                                           ) * ([T7]."goodwill_percent" / 100)
                                                       )
                                                   ELSE (0)
                                               END, 2, 0)
                                         )
                                     ) = 0
                                 )
                                 AND (
                                 (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                     )
                                                     AND ([T7]."source_table" = 'labours')
                                                 )
                                                 AND ([T1]."job_rebate" <> 0)
                                             )
                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                         ELSE (0)
                                     END
                                     ) <> 0
                                 )
                             )
                             THEN (
                             (
                                 CASE
                                     WHEN ([T7]."net_price_in_order" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."net_price_in_order")
                                 END
                                 ) * (
                                 (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                     )
                                                     AND ([T7]."source_table" = 'labours')
                                                 )
                                                 AND ([T1]."job_rebate" <> 0)
                                             )
                                             THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                         ELSE (0)
                                     END
                                     ) / 100
                                 )
                             )
                         ELSE (
                             (
                                 (
                                     round(CASE
                                               WHEN (
                                                   ([T7]."rebate_percent" <> 0)
                                                       AND ([T7]."source_table" = 'labours')
                                                   )
                                                   THEN (
                                                   (
                                                       CASE
                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                               THEN (0)
                                                           ELSE ([T7]."net_price_in_order")
                                                       END
                                                       ) * ([T7]."rebate_percent" / 100)
                                                   )
                                               WHEN (
                                                   ([T7]."goodwill_percent" <> 0)
                                                       AND ([T7]."source_table" = 'labours')
                                                   )
                                                   THEN (
                                                   (
                                                       CASE
                                                           WHEN ([T7]."net_price_in_order" IS NULL)
                                                               THEN (0)
                                                           ELSE ([T7]."net_price_in_order")
                                                       END
                                                       ) * ([T7]."goodwill_percent" / 100)
                                                   )
                                               ELSE (0)
                                           END, 2, 0)
                                     )
                                 )
                             )
                     END
                     )
                 ) + (
                 (
                     CASE
                         WHEN ([T7]."sum" IS NULL)
                             THEN (0)
                         ELSE ([T7]."sum")
                     END
                     ) - (
                     CASE
                         WHEN (
                             (
                                 (
                                     (
                                         round(CASE
                                                   WHEN (
                                                       ([T7]."rebate_percent" <> 0)
                                                           AND ([T7]."source_table" = 'parts')
                                                       )
                                                       THEN (
                                                       (
                                                           CASE
                                                               WHEN ([T7]."sum" IS NULL)
                                                                   THEN (0)
                                                               ELSE ([T7]."sum")
                                                           END
                                                           ) * ([T7]."rebate_percent" / 100)
                                                       )
                                                   WHEN (
                                                       ([T7]."goodwill_percent" <> 0)
                                                           AND ([T7]."source_table" = 'parts')
                                                       )
                                                       THEN (
                                                       (
                                                           CASE
                                                               WHEN ([T7]."sum" IS NULL)
                                                                   THEN (0)
                                                               ELSE ([T7]."sum")
                                                           END
                                                           ) * ([T7]."goodwill_percent" / 100)
                                                       )
                                                   ELSE (0)
                                               END, 2, 0)
                                         )
                                     ) = 0
                                 )
                                 AND (
                                 (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                     )
                                                     AND ([T7]."source_table" = 'parts')
                                                 )
                                                 AND ([T1]."part_rebate" <> 0)
                                             )
                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                         ELSE (0)
                                     END
                                     ) <> 0
                                 )
                             )
                             THEN (
                             (
                                 CASE
                                     WHEN ([T7]."sum" IS NULL)
                                         THEN (0)
                                     ELSE ([T7]."sum")
                                 END
                                 ) * (
                                 (
                                     CASE
                                         WHEN (
                                             (
                                                 (
                                                     ((convert(float, [T7]."rebate_percent")) = 0)
                                                         AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                     )
                                                     AND ([T7]."source_table" = 'parts')
                                                 )
                                                 AND ([T1]."part_rebate" <> 0)
                                             )
                                             THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                         ELSE (0)
                                     END
                                     ) / 100
                                 )
                             )
                         WHEN (
                             (
                                 (
                                     (
                                         (
                                             round(CASE
                                                       WHEN (
                                                           ([T7]."rebate_percent" <> 0)
                                                               AND ([T7]."source_table" = 'parts')
                                                           )
                                                           THEN (
                                                           (
                                                               CASE
                                                                   WHEN ([T7]."sum" IS NULL)
                                                                       THEN (0)
                                                                   ELSE ([T7]."sum")
                                                               END
                                                               ) * ([T7]."rebate_percent" / 100)
                                                           )
                                                       WHEN (
                                                           ([T7]."goodwill_percent" <> 0)
                                                               AND ([T7]."source_table" = 'parts')
                                                           )
                                                           THEN (
                                                           (
                                                               CASE
                                                                   WHEN ([T7]."sum" IS NULL)
                                                                       THEN (0)
                                                                   ELSE ([T7]."sum")
                                                               END
                                                               ) * ([T7]."goodwill_percent" / 100)
                                                           )
                                                       ELSE (0)
                                                   END, 2, 0)
                                             )
                                         ) <> 0
                                     )
                                     AND (
                                     (
                                         CASE
                                             WHEN (
                                                 (
                                                     (
                                                         ((convert(float, [T7]."rebate_percent")) = 0)
                                                             AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                         )
                                                         AND ([T7]."source_table" = 'parts')
                                                     )
                                                     AND ([T1]."part_rebate" <> 0)
                                                 )
                                                 THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                             ELSE (0)
                                         END
                                         ) = 0
                                     )
                                 )
                                 AND ([T7]."goodwill_percent" = 0)
                             )
                             THEN (0)
                         ELSE (
                             (
                                 (
                                     round(CASE
                                               WHEN (
                                                   ([T7]."rebate_percent" <> 0)
                                                       AND ([T7]."source_table" = 'parts')
                                                   )
                                                   THEN (
                                                   (
                                                       CASE
                                                           WHEN ([T7]."sum" IS NULL)
                                                               THEN (0)
                                                           ELSE ([T7]."sum")
                                                       END
                                                       ) * ([T7]."rebate_percent" / 100)
                                                   )
                                               WHEN (
                                                   ([T7]."goodwill_percent" <> 0)
                                                       AND ([T7]."source_table" = 'parts')
                                                   )
                                                   THEN (
                                                   (
                                                       CASE
                                                           WHEN ([T7]."sum" IS NULL)
                                                               THEN (0)
                                                           ELSE ([T7]."sum")
                                                       END
                                                       ) * ([T7]."goodwill_percent" / 100)
                                                   )
                                               ELSE (0)
                                           END, 2, 0)
                                     )
                                 )
                             )
                     END
                     )
                 ) AS "Wert_Euro"
           , [T7]."is_nominal" AS "Is Nominal"
           , [T7]."source_table" AS "Source Table"
           , [T7]."parts_type" AS "Parts Type"
           , CASE
                 WHEN ([T7]."sum" IS NULL)
                     THEN (0)
                 ELSE ([T7]."sum")
             END AS "Sum"
           , [T7]."amount" AS "Amount"
           , [T7]."part_number" AS "Part Number"
           , [T7]."labour_type" AS "Labour Type"
           , [T7]."negative_flag" AS "Negative Flag"
           , [T7]."usage_value" AS "Usage Value"
           , CASE
                 WHEN [T7]."text_line" IS NULL OR [T7]."text_line" = '' THEN 'keine Angabe'
                 ELSE [T7]."text_line"
             END AS "Text Line"
           , [T7]."charge_type" AS "Charge Type"
           , [T7]."goodwill_percent" AS "Goodwill Percent"
           , [T7]."rebate_percent" AS "Rebate Percent"
           , CASE
                 WHEN ([T7]."net_price_in_order" IS NULL)
                     THEN (0)
                 ELSE ([T7]."net_price_in_order")
             END AS "Net Price In Order"
           , [T7]."time_units" AS "Time Units"
           , [T7]."labour_operation_id" AS "Labour Operation Id"
           , [T6]."Standort_Name" AS "Standort Name"
           , [T6]."Standort_ID" AS "Standort Id"
           , [T6]."Hauptbetrieb_Name" AS "Hauptbetrieb Name"
           , [T6]."Hauptbetrieb_ID" AS "Hauptbetrieb Id"
           , [T1]."part_rebate" AS "Part Rebate"
           , [T1]."part_amount_net" AS "Part Amount Net"
           , [T1]."job_rebate" AS "Job Rebate"
           , [T1]."job_amount_net" AS "Job Amount Net"
           , CASE
                 WHEN ([T3]."family_name" IS NOT NULL)
                     THEN ((left(((([T3]."customer_number"))), 7)) + ' - ' + [T3]."family_name")
                 ELSE ((left(((([T3]."customer_number"))), 7)))
             END AS "Kunde"
           , CASE
                 WHEN ([T12]."family_name" IS NOT NULL)
                     THEN ((left(((([T12]."customer_number"))), 7)) + ' - ' + [T12]."family_name")
                 ELSE ((left(((([T12]."customer_number"))), 7)))
             END AS "Kunde_Auftrag"
           , [T3]."zip_code" AS "Geschäftsart"
           , CASE
                 WHEN ([T1]."invoice_type" = 5)
                     THEN ('Teile')
                 ELSE ('Service')
             END AS "Auftragsart"
           , CASE
                 WHEN ([T4]."description" = 'Ford')
                     THEN ('1')
                 WHEN ([T4]."description" = 'Nissan')
                     THEN ('3')
                 WHEN ([T4]."description" = 'Suzuki')
                     THEN ('2')
                 ELSE ('9')
             END AS "Marke"
           , (left((left(((([T1]."vehicle_number"))), 5)) + ' - ' + [T5]."description", 100)) AS "Fahrzeug"
           , (left((upper([T5]."description")), 3)) AS "Model"
           , [T5]."description" AS "Description_Models"
           , [T4]."description" AS "Fabrikat"
           , CASE
                 WHEN ([T1]."invoice_type" = 6)
                     THEN ('GWL')
                 WHEN (
                     ([T1]."invoice_type" = 4)
                         OR ([T3]."customer_number" = 100001)
                     )
                     THEN ('intern')
                 ELSE ('extern')
             END AS "Umsatzart"
           , [T2]."Serviceberater" AS "Serviceberater"
           , '0' + ((([T1]."subsidiary"))) AS "Standort"
           , [T1]."vehicle_number" AS "Vehicle Number"
           , [T1]."is_canceled" AS "Is Canceled"
           , [T1]."service_date" AS "Service Date"
           , [T1]."invoice_date" AS "Invoice Date"
           , [T1]."subsidiary" AS "Subsidiary"
           , [T1]."invoice_number" AS "Invoice Number"
           , [T1]."invoice_type" AS "Invoice Type"
      FROM [LOCOSOFT].[dbo].[invoices] [T1]
               LEFT JOIN [LOCOSOFT].[dbo].[customers_suppliers] [T3] ON [T3]."customer_number" = [T1]."paying_customer"
               LEFT JOIN [LOCOSOFT].[dbo].[vehicles] [T10] ON [T1]."vehicle_number" = [T10]."internal_number"
               LEFT JOIN [LOCOSOFT].[dbo].[makes] [T4] ON [T10]."make_number" = [T4]."make_number"
               LEFT JOIN [LOCOSOFT].[dbo].[models] [T5] ON [T10]."make_number" = [T5]."make_number"
          AND [T10]."model_code" = [T5]."model_code"
               LEFT JOIN [xtract].[labours_and_parts_union] [T7] ON [T1]."invoice_type" = [T7]."invoice_type"
          AND [T1]."invoice_number" = [T7]."invoice_number"
               LEFT JOIN [LOCOSOFT].[dbo].[part_types] [T9] ON [T9]."type" = [T7]."parts_type"
          AND [T9]."client_db" = [T7]."client_db"
               LEFT JOIN [transform_ims].[Serviceberater_Rechnung] [T2] ON [T1]."invtype_invnr" = [T2]."Invoice_Type_Invoice_Number"
               LEFT JOIN [data].[GC_Department] [T6] ON convert(varchar, [T1]."subsidiary") = [T6]."Standort"
          AND [T1]."client_db" = [T6]."Hauptbetrieb"
               LEFT JOIN [data].[GC_Charge_Type] [T8] ON [T8]."type" = [T7]."charge_type"
          AND [T8]."client_db" = [T7]."client_db"
               LEFT JOIN [LOCOSOFT].[dbo].[orders] [T11] ON [T1]."client_db" = [T11]."client_db"
          AND [T1]."order_number" = [T11]."number"
               LEFT JOIN [LOCOSOFT].[dbo].[customers_suppliers] [T12] ON [T12]."client_db" = [T11]."client_db"
          AND [T12]."customer_number" = [T11]."order_customer"

      WHERE (
                (
                    (
                        (
                            ([T1]."invoice_type" BETWEEN 2 AND 6)
                                AND ([T1]."is_canceled" <> 1)
                            )
                            AND ([T1]."invoice_date" >= convert(datetime, '2022-01-01T00:00:00'))
                        )
                        AND ([T6]."Hauptbetrieb_ID" = '1')
                    )
                    AND (
                    (
                        CASE
                            WHEN (
                                (
                                    ([T7]."time_units" = 0)
                                        AND (
                                        (
                                            (
                                                (
                                                    CASE
                                                        WHEN ([T7]."net_price_in_order" IS NULL)
                                                            THEN (0)
                                                        ELSE ([T7]."net_price_in_order")
                                                    END
                                                    ) - (
                                                    CASE
                                                        WHEN (
                                                            (
                                                                (
                                                                    (
                                                                        round(CASE
                                                                                  WHEN (
                                                                                      ([T7]."rebate_percent" <> 0)
                                                                                          AND ([T7]."source_table" = 'labours')
                                                                                      )
                                                                                      THEN (
                                                                                      (
                                                                                          CASE
                                                                                              WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                                  THEN (0)
                                                                                              ELSE ([T7]."net_price_in_order")
                                                                                          END
                                                                                          ) * ([T7]."rebate_percent" / 100)
                                                                                      )
                                                                                  WHEN (
                                                                                      ([T7]."goodwill_percent" <> 0)
                                                                                          AND ([T7]."source_table" = 'labours')
                                                                                      )
                                                                                      THEN (
                                                                                      (
                                                                                          CASE
                                                                                              WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                                  THEN (0)
                                                                                              ELSE ([T7]."net_price_in_order")
                                                                                          END
                                                                                          ) * ([T7]."goodwill_percent" / 100)
                                                                                      )
                                                                                  ELSE (0)
                                                                              END, 2, 0)
                                                                        )
                                                                    ) = 0
                                                                )
                                                                AND (
                                                                (
                                                                    CASE
                                                                        WHEN (
                                                                            (
                                                                                (
                                                                                    ((convert(float, [T7]."rebate_percent")) = 0)
                                                                                        AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                                    )
                                                                                    AND ([T7]."source_table" = 'labours')
                                                                                )
                                                                                AND ([T1]."job_rebate" <> 0)
                                                                            )
                                                                            THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                                        ELSE (0)
                                                                    END
                                                                    ) <> 0
                                                                )
                                                            )
                                                            THEN (
                                                            (
                                                                CASE
                                                                    WHEN ([T7]."net_price_in_order" IS NULL)
                                                                        THEN (0)
                                                                    ELSE ([T7]."net_price_in_order")
                                                                END
                                                                ) * (
                                                                (
                                                                    CASE
                                                                        WHEN (
                                                                            (
                                                                                (
                                                                                    ((convert(float, [T7]."rebate_percent")) = 0)
                                                                                        AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                                    )
                                                                                    AND ([T7]."source_table" = 'labours')
                                                                                )
                                                                                AND ([T1]."job_rebate" <> 0)
                                                                            )
                                                                            THEN ([T1]."job_rebate" / ([T1]."job_amount_net" + [T1]."job_rebate") * 100)
                                                                        ELSE (0)
                                                                    END
                                                                    ) / 100
                                                                )
                                                            )
                                                        ELSE (
                                                            (
                                                                (
                                                                    round(CASE
                                                                              WHEN (
                                                                                  ([T7]."rebate_percent" <> 0)
                                                                                      AND ([T7]."source_table" = 'labours')
                                                                                  )
                                                                                  THEN (
                                                                                  (
                                                                                      CASE
                                                                                          WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                              THEN (0)
                                                                                          ELSE ([T7]."net_price_in_order")
                                                                                      END
                                                                                      ) * ([T7]."rebate_percent" / 100)
                                                                                  )
                                                                              WHEN (
                                                                                  ([T7]."goodwill_percent" <> 0)
                                                                                      AND ([T7]."source_table" = 'labours')
                                                                                  )
                                                                                  THEN (
                                                                                  (
                                                                                      CASE
                                                                                          WHEN ([T7]."net_price_in_order" IS NULL)
                                                                                              THEN (0)
                                                                                          ELSE ([T7]."net_price_in_order")
                                                                                      END
                                                                                      ) * ([T7]."goodwill_percent" / 100)
                                                                                  )
                                                                              ELSE (0)
                                                                          END, 2, 0)
                                                                    )
                                                                )
                                                            )
                                                    END
                                                    )
                                                ) + (
                                                (
                                                    CASE
                                                        WHEN ([T7]."sum" IS NULL)
                                                            THEN (0)
                                                        ELSE ([T7]."sum")
                                                    END
                                                    ) - (
                                                    CASE
                                                        WHEN (
                                                            (
                                                                (
                                                                    (
                                                                        round(CASE
                                                                                  WHEN (
                                                                                      ([T7]."rebate_percent" <> 0)
                                                                                          AND ([T7]."source_table" = 'parts')
                                                                                      )
                                                                                      THEN (
                                                                                      (
                                                                                          CASE
                                                                                              WHEN ([T7]."sum" IS NULL)
                                                                                                  THEN (0)
                                                                                              ELSE ([T7]."sum")
                                                                                          END
                                                                                          ) * ([T7]."rebate_percent" / 100)
                                                                                      )
                                                                                  WHEN (
                                                                                      ([T7]."goodwill_percent" <> 0)
                                                                                          AND ([T7]."source_table" = 'parts')
                                                                                      )
                                                                                      THEN (
                                                                                      (
                                                                                          CASE
                                                                                              WHEN ([T7]."sum" IS NULL)
                                                                                                  THEN (0)
                                                                                              ELSE ([T7]."sum")
                                                                                          END
                                                                                          ) * ([T7]."goodwill_percent" / 100)
                                                                                      )
                                                                                  ELSE (0)
                                                                              END, 2, 0)
                                                                        )
                                                                    ) = 0
                                                                )
                                                                AND (
                                                                (
                                                                    CASE
                                                                        WHEN (
                                                                            (
                                                                                (
                                                                                    ((convert(float, [T7]."rebate_percent")) = 0)
                                                                                        AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                                    )
                                                                                    AND ([T7]."source_table" = 'parts')
                                                                                )
                                                                                AND ([T1]."part_rebate" <> 0)
                                                                            )
                                                                            THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                                        ELSE (0)
                                                                    END
                                                                    ) <> 0
                                                                )
                                                            )
                                                            THEN (
                                                            (
                                                                CASE
                                                                    WHEN ([T7]."sum" IS NULL)
                                                                        THEN (0)
                                                                    ELSE ([T7]."sum")
                                                                END
                                                                ) * (
                                                                (
                                                                    CASE
                                                                        WHEN (
                                                                            (
                                                                                (
                                                                                    ((convert(float, [T7]."rebate_percent")) = 0)
                                                                                        AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                                    )
                                                                                    AND ([T7]."source_table" = 'parts')
                                                                                )
                                                                                AND ([T1]."part_rebate" <> 0)
                                                                            )
                                                                            THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                                        ELSE (0)
                                                                    END
                                                                    ) / 100
                                                                )
                                                            )
                                                        WHEN (
                                                            (
                                                                (
                                                                    (
                                                                        (
                                                                            round(CASE
                                                                                      WHEN (
                                                                                          ([T7]."rebate_percent" <> 0)
                                                                                              AND ([T7]."source_table" = 'parts')
                                                                                          )
                                                                                          THEN (
                                                                                          (
                                                                                              CASE
                                                                                                  WHEN ([T7]."sum" IS NULL)
                                                                                                      THEN (0)
                                                                                                  ELSE ([T7]."sum")
                                                                                              END
                                                                                              ) * ([T7]."rebate_percent" / 100)
                                                                                          )
                                                                                      WHEN (
                                                                                          ([T7]."goodwill_percent" <> 0)
                                                                                              AND ([T7]."source_table" = 'parts')
                                                                                          )
                                                                                          THEN (
                                                                                          (
                                                                                              CASE
                                                                                                  WHEN ([T7]."sum" IS NULL)
                                                                                                      THEN (0)
                                                                                                  ELSE ([T7]."sum")
                                                                                              END
                                                                                              ) * ([T7]."goodwill_percent" / 100)
                                                                                          )
                                                                                      ELSE (0)
                                                                                  END, 2, 0)
                                                                            )
                                                                        ) <> 0
                                                                    )
                                                                    AND (
                                                                    (
                                                                        CASE
                                                                            WHEN (
                                                                                (
                                                                                    (
                                                                                        ((convert(float, [T7]."rebate_percent")) = 0)
                                                                                            AND ((convert(float, [T7]."goodwill_percent")) = 0)
                                                                                        )
                                                                                        AND ([T7]."source_table" = 'parts')
                                                                                    )
                                                                                    AND ([T1]."part_rebate" <> 0)
                                                                                )
                                                                                THEN ([T1]."part_rebate" / ([T1]."part_amount_net" + [T1]."part_rebate") * 100)
                                                                            ELSE (0)
                                                                        END
                                                                        ) = 0
                                                                    )
                                                                )
                                                                AND ([T7]."goodwill_percent" = 0)
                                                            )
                                                            THEN (0)
                                                        ELSE (
                                                            (
                                                                (
                                                                    round(CASE
                                                                              WHEN (
                                                                                  ([T7]."rebate_percent" <> 0)
                                                                                      AND ([T7]."source_table" = 'parts')
                                                                                  )
                                                                                  THEN (
                                                                                  (
                                                                                      CASE
                                                                                          WHEN ([T7]."sum" IS NULL)
                                                                                              THEN (0)
                                                                                          ELSE ([T7]."sum")
                                                                                      END
                                                                                      ) * ([T7]."rebate_percent" / 100)
                                                                                  )
                                                                              WHEN (
                                                                                  ([T7]."goodwill_percent" <> 0)
                                                                                      AND ([T7]."source_table" = 'parts')
                                                                                  )
                                                                                  THEN (
                                                                                  (
                                                                                      CASE
                                                                                          WHEN ([T7]."sum" IS NULL)
                                                                                              THEN (0)
                                                                                          ELSE ([T7]."sum")
                                                                                      END
                                                                                      ) * ([T7]."goodwill_percent" / 100)
                                                                                  )
                                                                              ELSE (0)
                                                                          END, 2, 0)
                                                                    )
                                                                )
                                                            )
                                                    END
                                                    )
                                                )
                                            ) = 0
                                        )
                                    )
                                    AND ([T7]."rebate_percent" = 0)
                                )
                                THEN ('raus')
                            ELSE ('rein')
                        END
                        ) = 'rein'
                    )
                )
         -- order by "Order Number" asc,"Invoice_Type_Invoice_Number" asc,"Invoice Number" asc
     ) [D1]
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GO
