ALTER TABLE dbo.LogPedidos ALTER COLUMN ClaveReg VARCHAR(20) NOT NULL
GO
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[LogPedidosDet]') AND name = N'PK_LogPedidosDet')
ALTER TABLE [dbo].[LogPedidosDet] DROP CONSTRAINT [PK_LogPedidosDet]
GO
ALTER TABLE dbo.LogPedidosDet ALTER COLUMN ClaveReg VARCHAR(20) NOT NULL
GO
ALTER TABLE [dbo].[LogPedidosDet] ADD  CONSTRAINT [PK_LogPedidosDet] PRIMARY KEY CLUSTERED 
(
	[ClaveReg] ASC,
	[TipOrd] ASC,
	[NumOrden] ASC,
	[IdCia] ASC,
	[Item] ASC
) ON [PRIMARY]
GO
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[LogPedidosNum]') AND name = N'PK_LogPedidosNum')
ALTER TABLE [dbo].[LogPedidosNum] DROP CONSTRAINT [PK_LogPedidosNum]
GO
ALTER TABLE dbo.LogPedidosNum ALTER COLUMN ClaveReg VARCHAR(20) NOT NULL
GO
ALTER TABLE [dbo].[LogPedidosNum] ADD  CONSTRAINT [PK_LogPedidosNum] PRIMARY KEY CLUSTERED 
(
	[ClaveReg] ASC,
	[Item] ASC
) ON [PRIMARY]
GO
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[LogPedidosOrd]') AND name = N'PK_LogPedidosOrd')
ALTER TABLE [dbo].[LogPedidosOrd] DROP CONSTRAINT [PK_LogPedidosOrd]
GO
ALTER TABLE dbo.LogPedidosOrd ALTER COLUMN ClaveReg VARCHAR(20) NOT NULL
GO
ALTER TABLE [dbo].[LogPedidosOrd] ADD  CONSTRAINT [PK_LogPedidosOrd] PRIMARY KEY CLUSTERED 
(
	[ClaveReg] ASC,
	[Item] ASC
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[LogValesCred] ALTER COLUMN ClaveReg VARCHAR(20) NOT NULL
GO
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[LogValesDet]') AND name = N'PK_LogValesDet')
ALTER TABLE [dbo].[LogValesDet] DROP CONSTRAINT [PK_LogValesDet]
GO
ALTER TABLE [dbo].[LogValesDet] ALTER COLUMN  ClaveReg VARCHAR(20) NOT NULL
GO
ALTER TABLE [dbo].[LogValesDet] ADD  CONSTRAINT [PK_LogValesDet] PRIMARY KEY CLUSTERED 
(
	[ClaveReg] ASC,
	[Item] ASC
) ON [PRIMARY]
GO
IF  EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'[dbo].[LogValesNum]') AND name = N'PK_LogValesNum')
ALTER TABLE [dbo].[LogValesNum] DROP CONSTRAINT [PK_LogValesNum]
GO
ALTER TABLE [dbo].[LogValesNum] ALTER COLUMN  ClaveReg VARCHAR(20) NOT NULL
GO
ALTER TABLE [dbo].[LogValesNum] ADD  CONSTRAINT [PK_LogValesNum] PRIMARY KEY CLUSTERED 
(
	[ClaveReg] ASC,
	[Item] ASC
) ON [PRIMARY]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsLogPedidosDet]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsLogPedidosDet]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsLogPedidosOrd]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsLogPedidosOrd]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsLogPedidosDet] @pmClaveReg VARCHAR(20),@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmItem INT,@pmIdProducto VARCHAR(16),@pmIdBodega VARCHAR(4),@pmCantOrden DECIMAL(14,4),@pmCantidad DECIMAL(14,4),@pmIdUnd VARCHAR(4),@pmVrUnitario MONEY,@pmVrPrecio MONEY,@pmTarifaIva DECIMAL(14,4),@pmVrIva MONEY
,@pmTarifaDct DECIMAL(14,4),@pmVrDcto MONEY,@pmReferencia VARCHAR(50),@pmDescripcion VARCHAR(250),@pmUnidades DECIMAL(14,4),@pmServicios BIT,@pmEsCombo BIT,@pmListaPrec CHAR(1),@pmVrBase MONEY,@pmTarifaIco DECIMAL(14,4),@pmVrImpCon DECIMAL(14,4),@pmCantObseq DECIMAL(14,4),@pmVrIvaObseq MONEY,@pmCdTanque VARCHAR(4)
,@pmCodTarDct VARCHAR(4),@pmCodTarIva VARCHAR(4),@pmVrBruto MONEY,@pmReferencia2 VARCHAR(50),@pmEstadoItem INT,@pmCantFact DECIMAL(14,4),@pmObservacion VARCHAR(1000)
 AS 
 INSERT INTO LogPedidosDet (ClaveReg,TipOrd,NumOrden,IdCia,Item,IdProducto,IdBodega,CantOrden,Cantidad,IdUnd,VrUnitario,VrPrecio,TarifaIva,VrIva,TarifaDct,VrDcto,Referencia,Descripcion,Unidades,Servicios,EsCombo,ListaPrec,VrBase,TarifaIco,VrImpCon,CantObseq,VrIvaObseq,CdTanque,CodTarDct,CodTarIva,VrBruto,Referencia2,EstadoItem,CantFact,Observacion)
 VALUES (@pmClaveReg,@pmTipOrd,@pmNumOrden,@pmIdCia,@pmItem,@pmIdProducto,@pmIdBodega,@pmCantOrden,@pmCantidad,@pmIdUnd,@pmVrUnitario,@pmVrPrecio,@pmTarifaIva,@pmVrIva,@pmTarifaDct,@pmVrDcto,@pmReferencia,@pmDescripcion,@pmUnidades,@pmServicios,@pmEsCombo,@pmListaPrec,@pmVrBase,@pmTarifaIco,@pmVrImpCon,@pmCantObseq,@pmVrIvaObseq,@pmCdTanque
,@pmCodTarDct,@pmCodTarIva,@pmVrBruto,@pmReferencia2,@pmEstadoItem,@pmCantFact,@pmObservacion)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsLogPedidosOrd] @pmClaveReg VARCHAR(20),@pmItem INT,@pmTipOrd VARCHAR(3),@pmNumOrden INT,@pmIdCia CHAR(2),@pmFechaOrd SMALLDATETIME,@pmIdCliente VARCHAR(16),@pmIdAgencia VARCHAR(16),@pmIdVend VARCHAR(16),@pmTarifaCom DECIMAL(14,4),@pmCodTarCom VARCHAR(4),@pmModalidad VARCHAR(10),@pmVigencia VARCHAR(10),@pmVrSubTotal MONEY,@pmVrDescuento MONEY,@pmVrImpuesto MONEY,@pmVrFletes MONEY,@pmVrOtros MONEY,@pmVrOtrDcto MONEY,@pmVrNeto MONEY,@pmCantidad DECIMAL(14,4),@pmDirEnvio VARCHAR(250)
,@pmIdLocEnv VARCHAR(8),@pmDiasEntraga INT,@pmNitContac VARCHAR(16),@pmNomContac VARCHAR(150),@pmTelContac VARCHAR(20),@pmemlContac VARCHAR(100),@pmCargoContac VARCHAR(50),@pmIdForma VARCHAR(4),@pmDetallePago VARCHAR(100),@pmIdPlazo VARCHAR(4),@pmCdMney VARCHAR(5),@pmNitEmpTrans VARCHAR(16),@pmEmpTrans VARCHAR(150),@pmpVehiculo VARCHAR(10),@pmCdConductor VARCHAR(16),@pmCdRuta VARCHAR(4),@pmReferencia VARCHAR(50),@pmNumAprob INT,@pmIdCiaApr CHAR(2),@pmIdEstado VARCHAR(4),@pmEstado INT
,@pmTipFac VARCHAR(3),@pmFactura INT,@pmIdCiaFac CHAR(2),@pmObservacion VARCHAR(2000),@pmCodCCosto VARCHAR(16),@pmCodSubCosto VARCHAR(16),@pmNomCliente VARCHAR(150),@pmAgencia VARCHAR(150),@pmVendedor VARCHAR(150),@pmVrSaldo MONEY,@pmVrCupo MONEY,@pmTipoClie VARCHAR(10),@pmIdSubzona VARCHAR(4),@pmCalcFletes BIT,@pmDiasPlazo INT,@pmDiasGracia INT,@pmExcIva BIT,@pmAutoret BIT,@pmInc_Ret BIT,@pmInc_Ica BIT,@pmInc_Riv BIT,@pmCodTarifRet VARCHAR(4),@pmCodTarifRtc VARCHAR(4),@pmRegimenImp VARCHAR(50)
,@pmCodDctClie VARCHAR(4)
 AS 
 INSERT INTO LogPedidosOrd (ClaveReg,Item,TipOrd,NumOrden,IdCia,FechaOrd,IdCliente,IdAgencia,IdVend,TarifaCom,CodTarCom,Modalidad,Vigencia,VrSubTotal,VrDescuento,VrImpuesto,VrFletes,VrOtros,VrOtrDcto,VrNeto,Cantidad,DirEnvio,IdLocEnv,DiasEntraga,NitContac,NomContac,TelContac,emlContac,CargoContac,IdForma,DetallePago,IdPlazo,CdMney,NitEmpTrans,EmpTrans,pVehiculo,CdConductor,CdRuta,Referencia,NumAprob,IdCiaApr,IdEstado,Estado,TipFac,Factura,IdCiaFac,Observacion,CodCCosto,CodSubCosto,NomCliente,Agencia,Vendedor
,VrSaldo,VrCupo,TipoClie,IdSubzona,CalcFletes,DiasPlazo,DiasGracia,ExcIva,Autoret,Inc_Ret,Inc_Ica,Inc_Riv,CodTarifRet,CodTarifRtc,RegimenImp,CodDctClie)
 VALUES (@pmClaveReg,@pmItem,@pmTipOrd,@pmNumOrden,@pmIdCia,@pmFechaOrd,@pmIdCliente,@pmIdAgencia,@pmIdVend,@pmTarifaCom,@pmCodTarCom,@pmModalidad,@pmVigencia,@pmVrSubTotal,@pmVrDescuento,@pmVrImpuesto,@pmVrFletes,@pmVrOtros,@pmVrOtrDcto,@pmVrNeto,@pmCantidad,@pmDirEnvio,@pmIdLocEnv,@pmDiasEntraga,@pmNitContac,@pmNomContac,@pmTelContac,@pmemlContac,@pmCargoContac,@pmIdForma,@pmDetallePago,@pmIdPlazo,@pmCdMney,@pmNitEmpTrans,@pmEmpTrans,@pmpVehiculo,@pmCdConductor,@pmCdRuta,@pmReferencia
,@pmNumAprob,@pmIdCiaApr,@pmIdEstado,@pmEstado,@pmTipFac,@pmFactura,@pmIdCiaFac,@pmObservacion,@pmCodCCosto,@pmCodSubCosto,@pmNomCliente,@pmAgencia,@pmVendedor,@pmVrSaldo,@pmVrCupo,@pmTipoClie,@pmIdSubzona,@pmCalcFletes,@pmDiasPlazo,@pmDiasGracia,@pmExcIva,@pmAutoret,@pmInc_Ret,@pmInc_Ica,@pmInc_Riv,@pmCodTarifRet,@pmCodTarifRtc,@pmRegimenImp,@pmCodDctClie)
GO



