/****** Object:  Table [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO]    Script Date: 02/03/2014 12:08:07 ******/
IF  NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO]') AND type in (N'U'))
begin
	CREATE TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO](
		[CD_EMP] [int] NOT NULL,
		[CD_FILIAL] [int] NOT NULL,
		[CD_NF] [int] NOT NULL,
		[CD_PROD] [int] NOT NULL,
		[VLR_IT] [money] NOT NULL,
		[QT_IT] [money] NOT NULL,
		[VLR_ICMS_IT] [money] NOT NULL,
		[ALIQ_ICMS] [money] NOT NULL,
		[CD_TRIB] [int] NOT NULL,
		[UN] [varchar](50) NOT NULL,
		[PERC_IPI] [money] NOT NULL,
		[VLR_PRC_CUSTO] [money] NOT NULL,
		[VLR_BASE_ICMS] [money] NOT NULL,
		[VLR_ICMS_SUBS] [money] NOT NULL,
		[VLR_BASE_SUBS] [money] NOT NULL,
		[VLR_PRC_CUSTO_ANT] [money] NOT NULL,
		[CD_NT_OP] [int] NOT NULL,
		[VLR_IPI] [money] NOT NULL,
		[PERC_DESC] [money] NOT NULL,
		[VLR_DESC] [money] NOT NULL,
		[SEQ_ITEM] [int] NOT NULL,
		[VLR_ISENTO] [money] NOT NULL,
		[VLR_OUTROS] [money] NOT NULL,
		[VLR_TOT_IT] [money] NOT NULL,
		[PERC_IVA] [money] NOT NULL,
		[QT_EMB] [money] NOT NULL,
		[VLR_FRETE_IT] [money] NOT NULL,
		[PIS_COFINS] [int] NOT NULL,
		[PERC_DESC_FINAN] [money] NULL,
		[PERC_REDU_BASE_SUBS] [money] NULL,
		[PERC_REDU_BASE_ICMS] [money] NULL,
		[VLR_PROD_FRETE] [money] NULL,
		[VLR_BASE_PIS] [money] NULL,
		[VLR_PIS] [money] NULL,
		[PERC_ALIQ_PIS] [money] NULL,
		[VLR_BASE_COFINS] [money] NULL,
		[VLR_COFINS] [money] NULL,
		[PERC_ALIQ_COFINS] [money] NULL,
		[VLR_BASE_ICMS_RET] [money] NULL,
		[VLR_ICMS_RET] [money] NULL,
		[PERC_DESC_COMERCIAL] [money] NULL,
		[VLR_OUTRAS_DESPESAS] [money] NULL,
		[VLR_PROD_PMC] [money] NULL,
		[CD_SIT_OPERA_SIMPLES_NACIO] [int] NULL,
		[MODALI_BASE_ICMS_SUBST] [int] NULL,
		[MODALI_BASE_ICMS] [int] NULL,
		[VLR_CRED_BASE_SN] [money] NULL,
		[VLR_CRED_ICMS_SN] [money] NULL,
		[PIS_COFINS_RECALCULADO] [int] NULL,
		[CST_COFINS] [int] NULL,
		[CST_PIS] [int] NULL,
		[VLR_IMPOSTO_REA] [money] NULL,
		[ALIQ_ICMS_INTERNO] [money] NULL,
		[DT_ENT] [datetime] NULL,
		[TP_PROD] [int] NULL,
		[TIPO_TRIBUTACAO_PIS_COFINS] [int] NULL,
		[VLR_CUSTO_MD] [money] NULL,
		[FLAG_EXCECAO_PIS_COFINS] [int] NULL,
		[SIGLA_EXCECAO_PIS_COFINS] [varchar](50) NULL,
	 CONSTRAINT [PK_EST_NF_ENT_IT_VALIDACAO_IMPOSTO] PRIMARY KEY CLUSTERED 
	(
		[CD_EMP] ASC,
		[CD_FILIAL] ASC,
		[CD_NF] ASC,
		[CD_PROD] ASC
	)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON, FILLFACTOR = 90) ON [PRIMARY]
	) ON [PRIMARY]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_EST_NF_ENT_IT] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_NF], [CD_PROD])
	REFERENCES [dbo].[EST_NF_ENT_IT] ([CD_EMP], [CD_FILIAL], [CD_NF], [CD_PROD])
	ON UPDATE CASCADE
	ON DELETE CASCADE

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] CHECK CONSTRAINT [FK_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_EST_NF_ENT_IT]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_EST_PROD_CPL] FOREIGN KEY([CD_EMP], [CD_FILIAL], [CD_PROD])
	REFERENCES [dbo].[EST_PROD_CPL] ([CD_EMP], [CD_FILIAL], [CD_PROD])

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] CHECK CONSTRAINT [FK_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_EST_PROD_CPL]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_EST_TRIB] FOREIGN KEY([CD_TRIB])
	REFERENCES [dbo].[EST_TRIB] ([CD_TRIB])
	ON UPDATE NO ACTION

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] CHECK CONSTRAINT [FK_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_EST_TRIB]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO]  WITH CHECK ADD  CONSTRAINT [FK_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_GLB_NT_OP] FOREIGN KEY([CD_NT_OP])
	REFERENCES [dbo].[GLB_NT_OP] ([CD_NT_OP])

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] CHECK CONSTRAINT [FK_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_GLB_NT_OP]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_CD_NF]  DEFAULT ((0)) FOR [CD_NF]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_UN]  DEFAULT ('') FOR [UN]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_PERC_IPI]  DEFAULT ((0)) FOR [PERC_IPI]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_PRC_CUSTO]  DEFAULT ((0)) FOR [VLR_PRC_CUSTO]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_IPI]  DEFAULT ((0)) FOR [VLR_IPI]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_PERC_DESC]  DEFAULT ((0)) FOR [PERC_DESC]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_DESC]  DEFAULT ((0)) FOR [VLR_DESC]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_SEQ_ITEM]  DEFAULT ((0)) FOR [SEQ_ITEM]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_ISENTO]  DEFAULT ((0)) FOR [VLR_ISENTO]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_OUTROS]  DEFAULT ((0)) FOR [VLR_OUTROS]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_TOT_IT]  DEFAULT ((0)) FOR [VLR_TOT_IT]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_PERC_IVA]  DEFAULT ((0)) FOR [PERC_IVA]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_QT_EMB]  DEFAULT ((0)) FOR [QT_EMB]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_FRETE_IT]  DEFAULT ((0)) FOR [VLR_FRETE_IT]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_PIS_COFINS]  DEFAULT ((0)) FOR [PIS_COFINS]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_PERC_DESC_FINAN]  DEFAULT ((0)) FOR [PERC_DESC_FINAN]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_PERC_DESC_COMERCIAL]  DEFAULT ((0)) FOR [PERC_DESC_COMERCIAL]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_OUTRAS_DESPESAS]  DEFAULT ((0)) FOR [VLR_OUTRAS_DESPESAS]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_PROD_PMC]  DEFAULT ((0)) FOR [VLR_PROD_PMC]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_CD_SIT_OPERA_SIMPLES_NACIO]  DEFAULT ((0)) FOR [CD_SIT_OPERA_SIMPLES_NACIO]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_MODALI_BASE_ICMS_SUBST]  DEFAULT ((0)) FOR [MODALI_BASE_ICMS_SUBST]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_MODALI_BASE_ICMS]  DEFAULT ((0)) FOR [MODALI_BASE_ICMS]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_CRED_BASE_SN]  DEFAULT ((0)) FOR [VLR_CRED_BASE_SN]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_CRED_ICMS_SN]  DEFAULT ((0)) FOR [VLR_CRED_ICMS_SN]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_CST_COFINS]  DEFAULT ((0)) FOR [CST_COFINS]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_CST_PIS]  DEFAULT ((0)) FOR [CST_PIS]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_IMPOSTO_REA]  DEFAULT ((0)) FOR [VLR_IMPOSTO_REA]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_ALIQ_ICMS_INTERNO]  DEFAULT ((0)) FOR [ALIQ_ICMS_INTERNO]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_TP_PROD]  DEFAULT ((0)) FOR [TP_PROD]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_TIPO_TRIBUTACAO_PIS_COFINS]  DEFAULT ((0)) FOR [TIPO_TRIBUTACAO_PIS_COFINS]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_VLR_CUSTO_MD]  DEFAULT ((0)) FOR [VLR_CUSTO_MD]

	ALTER TABLE [dbo].[EST_NF_ENT_IT_VALIDACAO_IMPOSTO] ADD  CONSTRAINT [DF_EST_NF_ENT_IT_VALIDACAO_IMPOSTO_FLAG_EXCECAO_PIS_COFINS]  DEFAULT ((0)) FOR [FLAG_EXCECAO_PIS_COFINS]
end

