CREATE TABLE [dbo].[acc_invoices_policies_variables]
(
[invpolv_invoice_id] [int] NOT NULL,
[invpolv_policy_situation_id] [int] NOT NULL,
[invpolv_variable_id] [int] NOT NULL,
[invpolv_coef_reduction] [dbo].[ais_decimal4] NULL,
[invpolv_tf] [dbo].[ais_decimal2] NULL,
[invpolv_taxes] [dbo].[ais_decimal2] NULL,
[invpolv_ti] [dbo].[ais_decimal2] NULL,
[invpolv_commission_tf] [dbo].[ais_decimal2] NULL,
[invpolv_commission_taxes] [dbo].[ais_decimal2] NULL,
[invpolv_commission_ti] [dbo].[ais_decimal2] NULL,
[invpolv_commission_percent] [dbo].[ais_decimal4] NULL
) ON [PRIMARY]
ALTER TABLE [dbo].[acc_invoices_policies_variables] ADD
CONSTRAINT [FK_acc_invoices_policies_variables_acc_invoices] FOREIGN KEY ([invpolv_invoice_id], [invpolv_policy_situation_id]) REFERENCES [dbo].[acc_invoices] ([inv_invoice_id], [inv_policy_situation_id])
GO
ALTER TABLE [dbo].[acc_invoices_policies_variables] ADD CONSTRAINT [PK_acc_invoices_policies_variables] PRIMARY KEY CLUSTERED  ([invpolv_invoice_id], [invpolv_policy_situation_id], [invpolv_variable_id]) ON [PRIMARY]
GO

ALTER TABLE [dbo].[acc_invoices_policies_variables] ADD CONSTRAINT [FK_acc_invoices_policies_variables_pol_variables] FOREIGN KEY ([invpolv_policy_situation_id], [invpolv_variable_id]) REFERENCES [dbo].[pol_variables] ([polv_policy_situation_id], [polv_variable_id])
GO
