SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE VIEW [transform_imr].[Zeit_verk_std]
AS
SELECT T1."order_number" AS "Order Number",
	T1."order_position" AS "Order Position",
	T1."labour_type" AS "Labour Type",
	T2."code" AS "Code_Labour_Types",
	CASE
		WHEN (T3."first_name" IS NULL)
			THEN ((left((((T3."customer_number"))), 7)) + ' - ' + T3."family_name")
		ELSE ((left((((T3."customer_number"))), 7)) + ' - ' + T3."first_name" + ' ' + T3."family_name")
		END AS "Description_Labour_Types",
	T4."order_number" AS "Order Number_Labours",
	T4."order_position" AS "Order Position_Labours",
	T4."order_position_line" AS "Order Position Line_Labours",
	(isnull((((T5."subsidiary"))), '1')) AS "Subsidiary_Labours",
	T4."is_invoiced" AS "Is Invoiced_Labours",
	T4."invoice_type" AS "Invoice Type_Labours",
	T4."invoice_number" AS "Invoice Number_Labours",
	T4."employee_no" AS "Employee No_Labours",
	T4."mechanic_no" AS "Mechanic No_Labours",
	T4."labour_operation_id" AS "Labour Operation Id_Labours",
	T4."is_nominal" AS "Is Nominal_Labours",
	T4."net_price_in_order" AS "Net Price In Order_Labours",
	T4."rebate_percent" AS "Rebate Percent_Labours",
	T4."goodwill_percent" AS "Goodwill Percent_Labours",
	T4."charge_type" AS "Charge Type_Labours",
	T4."text_line" AS "Text Line_Labours",
	10 AS "AW/Std.",
	((convert(FLOAT, T4."time_units"))) / 10 AS "verk. Std.",
	'verk. Std.' AS "Zeitkategorie",
	'' AS "Zeitkategorie2",
	T5."employee_number" AS "Employee Number_Employee",
	T5."name" AS "Name_Employee",
	(rtrim((((T5."employee_number"))))) + ' - ' + T5."name" AS "Monteur",
	T6."invoice_number" AS "Invoice Number_Invoices",
	T6."invoice_date" AS "Invoice Date_Invoices",
	T6."invoice_date" AS "Datum",
	T4."time_units" AS "Time Units_Labours",
	(convert(FLOAT, T4."time_units")) AS "Time_Units_Zahl"
FROM (
	(
		(
			LOCOSOFT."dbo"."invoices" T6 LEFT JOIN (
				(
					LOCOSOFT."dbo"."order_positions" T1 LEFT JOIN LOCOSOFT."dbo"."labour_types" T2 ON T1."labour_type" = T2."code"
					) LEFT JOIN LOCOSOFT."dbo"."labours" T4 ON T1."order_number" = T4."order_number"
				) ON (T4."invoice_number" = T6."invoice_number")
				AND (T4."invoice_type" = T6."invoice_type")
			) LEFT JOIN LOCOSOFT."dbo"."customers_suppliers" T3 ON T3."customer_number" = T6."paying_customer"
		) LEFT JOIN LOCOSOFT."dbo"."employees" T5 ON T4."mechanic_no" = T5."employee_number"
	)
WHERE (((convert(FLOAT, T4."time_units"))) <> 0)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GO
