if exists (select * from sysobjects where id = object_id(N'[dbo].[TMP_RESUMEN_VENTAS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TMP_RESUMEN_VENTAS]
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[TMP_RESUMEN_VENTASDET]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TMP_RESUMEN_VENTASDET]
GO

CREATE TABLE [dbo].[TMP_RESUMEN_VENTAS] (
	[CORRNBR] [int] NOT NULL ,
	[IDSUMARY] [varchar] (20) NOT NULL ,
	[PART] [int] NOT NULL ,
	[DOCTYPEID] [UD_DOCTYPEID] NOT NULL ,
	[NBRDOCUMENT] [UD_CORRELATIVOS] NULL ,
	[CONTCRED] [tinyint] NOT NULL ,
	[DESCR] [UD_DESCRIPCION] NOT NULL ,
	[NBRPHANTNC] [UD_CORRELATIVOS] NULL ,
	[MONTONCBASE] [UD_MONTO] NOT NULL ,
	[MONTONCEXTR] [UD_MONTO] NOT NULL ,
	[NBRPHANTFC] [UD_CORRELATIVOS] NULL ,
	[MONTOFCBASE] [UD_MONTO] NOT NULL ,
	[MONTOFCEXTR] [UD_MONTO] NOT NULL ,
	[VALES] [UD_MONTO] NOT NULL ,
	[DIFERENCIA] [UD_MONTO] NOT NULL ,
	[TAXPENNC] [UD_MONTO] NULL ,
	[TAXUSDNC] [UD_MONTO] NULL ,
	[SUBTOTALPENNC] [UD_MONTO] NULL ,
	[SUBTOTALUSDNC] [UD_MONTO] NULL ,
	[NOAFECTOPENNC] [UD_MONTO] NULL ,
	[NOAFECTOUSDNC] [UD_MONTO] NULL ,
	[TAXPENFC] [UD_MONTO] NULL ,
	[TAXUSDFC] [UD_MONTO] NULL ,
	[SUBTOTALPENFC] [UD_MONTO] NULL ,
	[SUBTOTALUSDFC] [UD_MONTO] NULL ,
	[NOAFECTOPENFC] [UD_MONTO] NULL ,
	[NOAFECTOUSDFC] [UD_MONTO] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[TMP_RESUMEN_VENTASDET] (
	[CORRNBR] [int] NOT NULL ,
	[CLASSID] [UD_CATEGORY] NULL ,
	[Descrspanish] [UD_DESCRIPCION] NULL ,
	[TYPEPAYMENTID] [char] (2) NULL ,
	[STKSTORE] [bit] NULL ,
	[custidss] [UD_CODCLIENT] NULL ,
	[CUSTNAME] [UD_NOMBRE] NULL ,
	[DOCTYPEID] [UD_DOCTYPEID] NULL ,
	[INVTIDSKU] [UD_IDCORPORATIVO] NULL ,
	[TOTALPEN] [UD_MONTO] NULL ,
	[TOTALUSD] [UD_MONTO] NULL ,
	[TAXPEN] [UD_MONTO] NULL ,
	[TAXUSD] [UD_MONTO] NULL ,
	[SUBTOTALPEN] [UD_MONTO] NULL ,
	[SUBTOTALUSD] [UD_MONTO] NULL ,
	[NOAFECTOPEN] [UD_MONTO] NULL ,
	[NOAFECTOUSD] [UD_MONTO] NULL ,
	[NBRDOCUMENT] [UD_CORRELATIVOS] NULL ,
	[INVTIDSOLOMON] [char] (20) NULL ,
	[INVTIDSTK] [char] (20) NULL ,
	[QTY] [UD_STOCK] NULL ,
	[TAXIGV] [UD_TAXID] NULL ,
	[TAXISC] [UD_TAXID] NULL 
) ON [PRIMARY]
GO

setuser N'dbo'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[MONTOFCBASE]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[MONTOFCEXTR]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[MONTONCEXTR]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[NOAFECTOPENFC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[NOAFECTOPENNC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[NOAFECTOUSDFC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[NOAFECTOUSDNC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[SUBTOTALPENFC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[SUBTOTALPENNC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[SUBTOTALUSDFC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[SUBTOTALUSDNC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[TAXPENFC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[TAXPENNC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[TAXUSDFC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTAS].[TAXUSDNC]'
GO

setuser
GO

setuser N'dbo'
GO

EXEC sp_bindefault N'[dbo].[DF_CORRELATIVO]', N'[TMP_RESUMEN_VENTASDET].[NBRDOCUMENT]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTASDET].[NOAFECTOPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTASDET].[NOAFECTOUSD]'
GO

EXEC sp_bindefault N'[dbo].[df_Valorstock]', N'[TMP_RESUMEN_VENTASDET].[QTY]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTASDET].[SUBTOTALPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTASDET].[SUBTOTALUSD]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTASDET].[TAXPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTASDET].[TAXUSD]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTASDET].[TOTALPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[TMP_RESUMEN_VENTASDET].[TOTALUSD]'
GO

setuser
GO

/******************************************************************************************************/

GO
ALTER TABLE [dbo].[OP_SUMMARYSALESDET] DROP CONSTRAINT FK_OP_SUMMARYSALES__OP_SUMMARYSALESDET
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[OP_SUMMARYDAY]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[OP_SUMMARYDAY]
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[OP_SUMMARYSALES]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[OP_SUMMARYSALES]
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[OP_SUMMARYSALESDET]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[OP_SUMMARYSALESDET]
GO

CREATE TABLE [dbo].[OP_SUMMARYDAY] (
	[BATNBRDIARYSUMMARY] [UD_CORRELATIVOS] NOT NULL ,
	[SITEID] [UD_IDSITE] NOT NULL ,
	[DATEPROCE] [UD_FECHA] NOT NULL ,
	[CURYRATE] [UD_CURYRATE] NOT NULL ,
	[ROUND] [UD_MONTO] NOT NULL ,
	[TOTALDIFERENCE] [UD_MONTO] NOT NULL ,
	[OBSERVATION] [varchar] (500) NULL ,
	[TOTALPEN] [UD_MONTO] NOT NULL ,
	[USERID] [UD_USERID] NOT NULL ,
	[STKSEND] [bit] NOT NULL ,
	[STKRECEIVE] [bit] NOT NULL ,
	[USER1] [UD_USER1] NULL ,
	[USER2] [UD_USER2] NULL ,
	[USER3] [UD_USER6] NULL ,
	[USER4] [UD_USER7] NULL ,
	[TSTAMP] [timestamp] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[OP_SUMMARYSALES] (
	[SITEID] [UD_IDSITE] NOT NULL ,
	[DATEPROCE] [smalldatetime] NOT NULL ,
	[COMMENT] [varchar] (40) NOT NULL ,
	[STATUS] [bit] NOT NULL ,
	[TOTALPEN] [UD_MONTO] NOT NULL ,
	[USERID] [char] (20) NOT NULL ,
	[STKSEND] [bit] NOT NULL ,
	[STKRECEIVE] [bit] NOT NULL ,
	[USER1] [varchar] (30) NULL ,
	[USER2] [varchar] (30) NULL ,
	[USER3] [float] NULL ,
	[USER4] [float] NULL ,
	[TSTAMP] [timestamp] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[OP_SUMMARYSALESDET] (
	[SITEID] [UD_IDSITE] NOT NULL ,
	[DATEPROCE] [UD_FECHA] NOT NULL ,
	[SEQUENCE] [UD_REGISTRO] NOT NULL ,
	[DOCSUMMARYTYPEIDFAC] [char] (2) NULL ,
	[REFERENCEFAC] [UD_CORRELATIVOS] NULL ,
	[DOCSUMMARYTYPEIDNC] [char] (2) NULL ,
	[REFERENCENC] [UD_CORRELATIVOS] NULL ,
	[CLASSID] [UD_CATEGORY] NULL ,
	[CLASSUBID] [char] (5) NULL ,
	[custidss] [UD_CODCLIENT] NULL ,
	[CUSTCLASSID] [UD_CUSTCLASSID] NULL ,
	[TOTALBONUS] [UD_MONTO] NOT NULL ,
	[DIFFERENCE] [UD_MONTO] NOT NULL ,
	[TOTALPENNC] [UD_MONTO] NULL ,
	[TOTALPENFC] [UD_MONTO] NULL ,
	[DESCR] [UD_DESCRIPCION] NULL ,
	[USERID] [UD_USERID] NOT NULL ,
	[STKGENERATEDNC] [bit] NOT NULL ,
	[STKGENERATEDFC] [bit] NOT NULL ,
	[STKSEND] [bit] NOT NULL ,
	[STKRECEIVE] [bit] NOT NULL ,
	[USER1] [UD_USER1] NULL ,
	[USER2] [UD_USER2] NULL ,
	[USER3] [UD_USER6] NULL ,
	[USER4] [UD_USER7] NULL ,
	[TSTAMP] [timestamp] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[OP_SUMMARYDAY] WITH NOCHECK ADD 
	CONSTRAINT [DF_OP_SUMMARYDAY_STKSEND] DEFAULT (0) FOR [STKSEND],
	CONSTRAINT [DF_OP_SUMMARYDAY_STKRECEIVE] DEFAULT (0) FOR [STKRECEIVE],
	CONSTRAINT [PK__OP_SUMMARYDAY__3C34F16F] PRIMARY KEY  NONCLUSTERED 
	(
		[BATNBRDIARYSUMMARY],
		[SITEID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[OP_SUMMARYSALES] WITH NOCHECK ADD 
	CONSTRAINT [DF__OP_SUMMAR__STKSE__6816A109] DEFAULT (0) FOR [STKSEND],
	CONSTRAINT [DF__OP_SUMMAR__STKRE__690AC542] DEFAULT (0) FOR [STKRECEIVE],
	CONSTRAINT [PK__OP_SUMMARYSALES__662E5897] PRIMARY KEY  NONCLUSTERED 
	(
		[SITEID],
		[DATEPROCE]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[OP_SUMMARYSALESDET] WITH NOCHECK ADD 
	CONSTRAINT [DF_OP_SUMMARYSALESDET_STKGENERATED] DEFAULT (0) FOR [STKGENERATEDNC],
	CONSTRAINT [DF_OP_SUMMARYSALESDET_STKGENERATEDFC] DEFAULT (0) FOR [STKGENERATEDFC],
	CONSTRAINT [DF_OP_SUMMARYSALES_STKSEND] DEFAULT (0) FOR [STKSEND],
	CONSTRAINT [DF_OP_SUMMARYSALES_STKRECEIVE] DEFAULT (0) FOR [STKRECEIVE],
	CONSTRAINT [PK_OP_SUMMARYSALESDET] PRIMARY KEY  NONCLUSTERED 
	(
		[SITEID],
		[DATEPROCE],
		[SEQUENCE]
	)  ON [PRIMARY] 
GO

setuser N'dbo'
GO

EXEC sp_bindefault N'[dbo].[DF_CORRELATIVO]', N'[OP_SUMMARYDAY].[BATNBRDIARYSUMMARY]'
GO

EXEC sp_bindefault N'[dbo].[DF_FECHA]', N'[OP_SUMMARYDAY].[DATEPROCE]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_SUMMARYDAY].[ROUND]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_SUMMARYDAY].[TOTALDIFERENCE]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_SUMMARYDAY].[TOTALPEN]'
GO

setuser
GO

setuser N'dbo'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_SUMMARYSALES].[TOTALPEN]'
GO

setuser
GO

setuser N'dbo'
GO

EXEC sp_bindefault N'[dbo].[DF_FECHA]', N'[OP_SUMMARYSALESDET].[DATEPROCE]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_SUMMARYSALESDET].[DIFFERENCE]'
GO

EXEC sp_bindefault N'[dbo].[DF_CORRELATIVO]', N'[OP_SUMMARYSALESDET].[REFERENCEFAC]'
GO

EXEC sp_bindefault N'[dbo].[DF_CORRELATIVO]', N'[OP_SUMMARYSALESDET].[REFERENCENC]'
GO

EXEC sp_bindefault N'[dbo].[DF_REGISTRO]', N'[OP_SUMMARYSALESDET].[SEQUENCE]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_SUMMARYSALESDET].[TOTALBONUS]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_SUMMARYSALESDET].[TOTALPENFC]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_SUMMARYSALESDET].[TOTALPENNC]'
GO

setuser
GO

ALTER TABLE [dbo].[OP_SUMMARYDAY] ADD 
	CONSTRAINT [FK_SITE__OP_SUMMARYDAY] FOREIGN KEY 
	(
		[SITEID]
	) REFERENCES [dbo].[SITE] (
		[SITEID]
	)
GO

ALTER TABLE [dbo].[OP_SUMMARYSALESDET] ADD 
	CONSTRAINT [FK_OP_SUMMARYSALES__OP_SUMMARYSALESDET] FOREIGN KEY 
	(
		[SITEID],
		[DATEPROCE]
	) REFERENCES [dbo].[OP_SUMMARYSALES] (
		[SITEID],
		[DATEPROCE]
	)
GO

/******************************************************************************************************/
GO
ALTER TABLE [dbo].[OP_DOCSUMMARYDET] DROP CONSTRAINT RefOP_DOCSUMMARY212
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[OP_DOCSUMMARY]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[OP_DOCSUMMARY]
GO

if exists (select * from sysobjects where id = object_id(N'[dbo].[OP_DOCSUMMARYDET]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[OP_DOCSUMMARYDET]
GO

CREATE TABLE [dbo].[OP_DOCSUMMARY] (
	[SITEID] [UD_IDSITE] NOT NULL ,
	[DOCSUMMARYTYPEID] [char] (2) NOT NULL ,
	[NBRDOCSUMMARY] [UD_CORRELATIVOS] NOT NULL ,
	[DOCDATE] [UD_FECHA] NOT NULL ,
	[DUEDATE] [UD_FECHA] NOT NULL ,
	[DOCSTATUSID] [char] (2) NOT NULL ,
	[TAXID01] [UD_TAXID] NOT NULL ,
	[TAXID02] [UD_TAXID] NOT NULL ,
	[TERMID] [char] (2) NOT NULL ,
	[CURYTYPEID] [UD_CURYTYPEID] NOT NULL ,
	[CURYRATE] [UD_CURYRATE] NOT NULL ,
	[CURYID] [UD_CURYID] NOT NULL ,
	[custidss] [UD_CODCLIENT] NOT NULL ,
	[CUSTID] [UD_CODCLIENT] NOT NULL ,
	[CUSTNAME] [UD_NOMBRE] NULL ,
	[TAXREGNBR] [UD_CODCLIENT] NOT NULL ,
	[weekdaypag] [char] (12) NULL ,
	[DAYTHENK] [int] NULL ,
	[TOTALPEN] [UD_MONTO] NOT NULL ,
	[TOTALUSD] [UD_MONTO] NOT NULL ,
	[SUBTOTALPEN] [UD_MONTO] NOT NULL ,
	[SUBTOTALUSD] [UD_MONTO] NOT NULL ,
	[TAXPEN] [UD_MONTO] NOT NULL ,
	[TAXUSD] [UD_MONTO] NOT NULL ,
	[TOTALNOTAFFECTPEN] [UD_MONTO] NOT NULL ,
	[TOTALNOTAFFECTUSD] [UD_MONTO] NOT NULL ,
	[STKITEM] [bit] NULL ,
	[STKPROCE] [bit] NOT NULL ,
	[USERID] [UD_USERID] NOT NULL ,
	[STKNEW] [bit] NOT NULL ,
	[STKMODIFY] [bit] NOT NULL ,
	[STKDELETE] [bit] NOT NULL ,
	[STKSEND] [bit] NOT NULL ,
	[STKRECEIVE] [bit] NOT NULL ,
	[USER1] [UD_USER1] NULL ,
	[USER2] [UD_USER2] NULL ,
	[USER3] [UD_USER6] NULL ,
	[USER4] [UD_USER7] NULL ,
	[TSTAMP] [timestamp] NULL 
) ON [PRIMARY]
GO

CREATE TABLE [dbo].[OP_DOCSUMMARYDET] (
	[SITEID] [UD_IDSITE] NOT NULL ,
	[DOCSUMMARYTYPEID] [char] (2) NOT NULL ,
	[NBRDOCSUMMARY] [UD_CORRELATIVOS] NOT NULL ,
	[SEQUENCE] [UD_REGISTRO] NOT NULL ,
	[CURYTYPEID] [UD_CURYTYPEID] NOT NULL ,
	[CURYID] [UD_CURYID] NOT NULL ,
	[TAXID02] [UD_TAXID] NOT NULL ,
	[TAXID01] [UD_TAXID] NOT NULL ,
	[DISCOUNT] [numeric](12, 2) NULL ,
	[INVTIDSKU] [UD_IDCORPORATIVO] NULL ,
	[SLS_PRICE] [UD_PRECIO] NOT NULL ,
	[QTY] [UD_STOCK] NOT NULL ,
	[TOTALPEN] [UD_MONTO] NOT NULL ,
	[TOTALUSD] [UD_MONTO] NOT NULL ,
	[SUBTOTALPEN] [UD_MONTO] NOT NULL ,
	[SUBTOTALUSD] [UD_MONTO] NOT NULL ,
	[TAXPEN] [UD_MONTO] NOT NULL ,
	[TAXUSD] [UD_MONTO] NOT NULL ,
	[USERID] [UD_USERID] NOT NULL ,
	[DOCDATE] [UD_FECHA] NOT NULL ,
	[INVTIDSOLOMON] [char] (20) NOT NULL ,
	[CLASSID] [UD_CATEGORY] NULL ,
	[STKNEW] [bit] NOT NULL ,
	[STKMODIFY] [bit] NOT NULL ,
	[STKDELETE] [bit] NOT NULL ,
	[STKSEND] [bit] NOT NULL ,
	[STKRECEIVE] [bit] NOT NULL ,
	[USER1] [UD_USER1] NULL ,
	[USER2] [UD_USER2] NULL ,
	[USER3] [UD_USER6] NULL ,
	[USER4] [UD_USER7] NULL ,
	[TSTAMP] [timestamp] NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[OP_DOCSUMMARY] WITH NOCHECK ADD 
	CONSTRAINT [DF_OP_DOCSUMMARY_STKNEW] DEFAULT (0) FOR [STKNEW],
	CONSTRAINT [DF_OP_DOCSUMMARY_STKMODIFY] DEFAULT (0) FOR [STKMODIFY],
	CONSTRAINT [DF_OP_DOCSUMMARY_STKDELETE] DEFAULT (0) FOR [STKDELETE],
	CONSTRAINT [DF_OP_DOCSUMMARY_STKSEND] DEFAULT (0) FOR [STKSEND],
	CONSTRAINT [DF_OP_DOCSUMMARY_STKRECEIVE] DEFAULT (0) FOR [STKRECEIVE],
	CONSTRAINT [PK__OP_DOCSUMMARY__160F4887] PRIMARY KEY  NONCLUSTERED 
	(
		[SITEID],
		[DOCSUMMARYTYPEID],
		[NBRDOCSUMMARY]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[OP_DOCSUMMARYDET] WITH NOCHECK ADD 
	CONSTRAINT [DF_OP_DOCSUMMARYDET_STKNEW] DEFAULT (0) FOR [STKNEW],
	CONSTRAINT [DF_OP_DOCSUMMARYDET_STKMODIFY] DEFAULT (0) FOR [STKMODIFY],
	CONSTRAINT [DF_OP_DOCSUMMARYDET_STKDELETE] DEFAULT (0) FOR [STKDELETE],
	CONSTRAINT [DF_OP_DOCSUMMARYDET_STKSEND] DEFAULT (0) FOR [STKSEND],
	CONSTRAINT [DF_OP_DOCSUMMARYDET_STKRECEIVE] DEFAULT (0) FOR [STKRECEIVE],
	CONSTRAINT [PK__OP_DOCSUMMARYDET__17F790F9] PRIMARY KEY  NONCLUSTERED 
	(
		[SITEID],
		[DOCSUMMARYTYPEID],
		[NBRDOCSUMMARY],
		[SEQUENCE]
	)  ON [PRIMARY] 
GO

setuser N'dbo'
GO

EXEC sp_bindefault N'[dbo].[DF_FECHA]', N'[OP_DOCSUMMARY].[DOCDATE]'
GO

EXEC sp_bindefault N'[dbo].[DF_FECHA]', N'[OP_DOCSUMMARY].[DUEDATE]'
GO

EXEC sp_bindefault N'[dbo].[DF_CORRELATIVO]', N'[OP_DOCSUMMARY].[NBRDOCSUMMARY]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARY].[SUBTOTALPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARY].[SUBTOTALUSD]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARY].[TAXPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARY].[TAXUSD]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARY].[TOTALNOTAFFECTPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARY].[TOTALNOTAFFECTUSD]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARY].[TOTALPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARY].[TOTALUSD]'
GO

setuser
GO

setuser N'dbo'
GO

EXEC sp_bindefault N'[dbo].[DF_FECHA]', N'[OP_DOCSUMMARYDET].[DOCDATE]'
GO

EXEC sp_bindefault N'[dbo].[DF_CORRELATIVO]', N'[OP_DOCSUMMARYDET].[NBRDOCSUMMARY]'
GO

EXEC sp_bindefault N'[dbo].[df_Valorstock]', N'[OP_DOCSUMMARYDET].[QTY]'
GO

EXEC sp_bindefault N'[dbo].[DF_REGISTRO]', N'[OP_DOCSUMMARYDET].[SEQUENCE]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARYDET].[SLS_PRICE]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARYDET].[SUBTOTALPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARYDET].[SUBTOTALUSD]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARYDET].[TAXPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARYDET].[TAXUSD]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARYDET].[TOTALPEN]'
GO

EXEC sp_bindefault N'[dbo].[DF_VALORPRECIO]', N'[OP_DOCSUMMARYDET].[TOTALUSD]'
GO

setuser
GO

ALTER TABLE [dbo].[OP_DOCSUMMARY] ADD 
	CONSTRAINT [FK_TAXS__OP_DOCSUMMARY_TAXID01] FOREIGN KEY 
	(
		[TAXID01]
	) REFERENCES [dbo].[TAXS] (
		[TAXID]
	),
	CONSTRAINT [FK_TAXS__OP_DOCSUMMARY_TAXID02] FOREIGN KEY 
	(
		[TAXID02]
	) REFERENCES [dbo].[TAXS] (
		[TAXID]
	),
	CONSTRAINT [RefCURRENCY198] FOREIGN KEY 
	(
		[CURYID]
	) REFERENCES [dbo].[CURRENCY] (
		[CURYID]
	),
	CONSTRAINT [RefCURYRATETYPE201] FOREIGN KEY 
	(
		[CURYTYPEID]
	) REFERENCES [dbo].[CURYRATETYPE] (
		[CURYTYPEID]
	),
	CONSTRAINT [RefCUSTOMER200] FOREIGN KEY 
	(
		[custidss]
	) REFERENCES [dbo].[CUSTOMER] (
		[custidss]
	),
	CONSTRAINT [RefSITE208] FOREIGN KEY 
	(
		[SITEID]
	) REFERENCES [dbo].[SITE] (
		[SITEID]
	),
	CONSTRAINT [RefTERMS202] FOREIGN KEY 
	(
		[TERMID]
	) REFERENCES [dbo].[TERMS] (
		[TERMID]
	)
GO

ALTER TABLE [dbo].[OP_DOCSUMMARYDET] ADD 
	CONSTRAINT [FK_TAXS__OP_DOCSUMMARYDET__TAX01] FOREIGN KEY 
	(
		[TAXID01]
	) REFERENCES [dbo].[TAXS] (
		[TAXID]
	),
	CONSTRAINT [FK_TAXS__OP_DOCSUMMARYDET__TAXID02] FOREIGN KEY 
	(
		[TAXID02]
	) REFERENCES [dbo].[TAXS] (
		[TAXID]
	),
	CONSTRAINT [RefCURRENCY216] FOREIGN KEY 
	(
		[CURYID]
	) REFERENCES [dbo].[CURRENCY] (
		[CURYID]
	),
	CONSTRAINT [RefCURYRATETYPE217] FOREIGN KEY 
	(
		[CURYTYPEID]
	) REFERENCES [dbo].[CURYRATETYPE] (
		[CURYTYPEID]
	),
	CONSTRAINT [RefOP_DOCSUMMARY212] FOREIGN KEY 
	(
		[SITEID],
		[DOCSUMMARYTYPEID],
		[NBRDOCSUMMARY]
	) REFERENCES [dbo].[OP_DOCSUMMARY] (
		[SITEID],
		[DOCSUMMARYTYPEID],
		[NBRDOCSUMMARY]
	)
GO





