SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO
CREATE VIEW [dbo].[invoices]
AS
SELECT [invoice_type]
     , [invoice_number]
     , [subsidiary]
     , [order_number]
     , [paying_customer]
     , [invoice_date]
     , [service_date]
     , [is_canceled]
     , [cancelation_number]
     , [cancelation_date]
     , [cancelation_employee]
     , [is_own_vehicle]
     , [is_credit]
     , [credit_invoice_type]
     , [credit_invoice_number]
     , [odometer_reading]
     , [creating_employee]
     , [internal_cost_account]
     , [vehicle_number]
     , [full_vat_basevalue]
     , [full_vat_percentage]
     , [full_vat_value]
     , [reduced_vat_basevalue]
     , [reduced_vat_percentage]
     , [reduced_vat_value]
     , [used_part_vat_value]
     , [job_amount_net]
     , [job_amount_gross]
     , [job_rebate]
     , [part_amount_net]
     , [part_amount_gross]
     , [part_rebate]
     , [part_disposal]
     , [total_gross]
     , [total_net]
     , [parts_rebate_group_sell]
     , [internal_created_time]
     , [internal_canceled_time]
     , [order_classification_flag]
     , [client_db]
     , [len_invoice_number]
     , 0 AS [order_customer]
     , cast([T1].[invoice_type] AS varchar(1)) + right(replicate('0', 12) + cast([T1].[invoice_number] AS varchar(12)), cast([T2].[len_invoice_number] AS int)) AS [invtype_invnr]
FROM [dbo].[invoices_import] [T1]
   , [GC_ETL_LOCOSOFT].[data].[GC_Config_Pivot] [T2]
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

GO
