ALTER TABLE Tanques ADD TipoProd VARCHAR(10),Altura DECIMAL(16,6) DEFAULT(0) NOT NULL
GO
ALTER TABLE CtasCorrientes ADD TipoProp VARCHAR(10)
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsCtasCorrientes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsCtasCorrientes]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paInsTanques]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paInsTanques]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryCtasCorrientes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryCtasCorrientes]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryCtasCorrientesLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryCtasCorrientesLta]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryCtasCorrientesNum]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryCtasCorrientesNum]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryCtasCorrientesPuc]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryCtasCorrientesPuc]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTanques]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTanques]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paQryTanquesLta]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paQryTanquesLta]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpCtasCorrientes]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpCtasCorrientes]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[paUpTanques]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
 DROP PROCEDURE [dbo].[paUpTanques]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsTanques] @pmIdTanque VARCHAR(4),@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(50),@pmCapTanq DECIMAL(14,4),@pmNivAgua DECIMAL(14,4),@pmCapNeta DECIMAL(14,4)
,@pmSaldoActual DECIMAL(14,4),@pmTnqGas BIT,@pmTnqUnido BIT,@pmTnqVirtual BIT,@pmCdNueTan VARCHAR(4),@pmNColor INT,@pmFechaAdd SMALLDATETIME,@pmInactivo BIT,@pmIdCiaDef CHAR(2)
,@pmCodigoApi VARCHAR(10),@pmCdTerminal VARCHAR(4),@pmTipoProd VARCHAR(10),@pmAltura DECIMAL(16,6)
 AS 
 INSERT INTO Tanques (IdTanque,IdProducto,Descripcion,CapTanq,NivAgua,CapNeta,SaldoActual,TnqGas,TnqUnido,TnqVirtual,CdNueTan,NColor,FechaAdd,Inactivo,IdCiaDef,CodigoApi,CdTerminal,TipoProd,Altura)
 VALUES (@pmIdTanque,@pmIdProducto,@pmDescripcion,@pmCapTanq,@pmNivAgua,@pmCapNeta,@pmSaldoActual,@pmTnqGas,@pmTnqUnido,@pmTnqVirtual,@pmCdNueTan,@pmNColor
,@pmFechaAdd,@pmInactivo,@pmIdCiaDef,@pmCodigoApi,@pmCdTerminal,@pmTipoProd,@pmAltura)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpTanques] @pmIdTanque VARCHAR(4),@pmIdProducto VARCHAR(16),@pmDescripcion VARCHAR(50),@pmCapTanq DECIMAL(14,4),@pmNivAgua DECIMAL(14,4),@pmCapNeta DECIMAL(14,4)
,@pmSaldoActual DECIMAL(14,4),@pmTnqGas BIT,@pmTnqUnido BIT,@pmTnqVirtual BIT,@pmCdNueTan VARCHAR(4),@pmNColor INT
,@pmFechaUpdate SMALLDATETIME,@pmInactivo BIT,@pmIdCiaDef CHAR(2),@pmCodigoApi VARCHAR(10),@pmCdTerminal VARCHAR(4),@pmTipoProd VARCHAR(10),@pmAltura DECIMAL(16,6)
 AS 
 UPDATE Tanques SET IdProducto=@pmIdProducto,Descripcion=@pmDescripcion,CapTanq=@pmCapTanq,NivAgua=@pmNivAgua,CapNeta=@pmCapNeta,SaldoActual=@pmSaldoActual
,TnqGas=@pmTnqGas,TnqUnido=@pmTnqUnido,TnqVirtual=@pmTnqVirtual,CdNueTan=@pmCdNueTan,NColor=@pmNColor,FechaUpdate=@pmFechaUpdate,Inactivo=@pmInactivo
,IdCiaDef =@pmIdCiaDef,CodigoApi=@pmCodigoApi,CdTerminal=@pmCdTerminal,TipoProd=@pmTipoProd,Altura=@pmAltura
 WHERE IdTanque=@pmIdTanque
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTanquesLta] @pmIdProducto VARCHAR(16)=Null
 AS 
 SELECT IdTanque,T.IdProducto AS CdProd,DescripProd,Descripcion,CapTanq,NivAgua,CapNeta,SaldoActual
,TnqGas,TnqUnido,TnqVirtual,CdNueTan,NColor,TipoProd,Altura,T.FechaAdd AS Fec_Add,T.FechaUpdate AS Fec_Upd,IdCiaDef,CdTerminal
 FROM Tanques AS T INNER JOIN ProdMcias AS P ON T.IdProducto=P.IdProducto
 WHERE T.Inactivo=0 AND  T.IdProducto LIKE ISNULL(@pmIdProducto,'%')
 ORDER BY DescripProd,IdTanque
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryTanques] @pmIdTanque VARCHAR(4)
 AS 
 SELECT IdTanque,IdProducto,Descripcion,CapTanq,NivAgua,CapNeta,SaldoActual
 ,TnqGas,TnqUnido,TnqVirtual,CdNueTan,NColor,FechaAdd,FechaUpdate,Inactivo,IdCiaDef,CodigoApi,CdTerminal,TipoProd,Altura
 FROM Tanques
 WHERE IdTanque=@pmIdTanque
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCtasCorrientesLta] @pmIdBanco VARCHAR(4)=Null,@pmIdCuenta VARCHAR(16)=Null
,@pmInactivo BIT=Null,@pmIdCiaDef CHAR(2)=Null
 AS 
 SELECT IdCta,NumeroCta,C.IdBanco AS CodBco,Banco,C.IdCuenta AS IdCuent,NomCuenta,ConsCheques,RangoCons,ConsActual,Formato,TipoPapel,Orientacion
,VistaPrevia,VerSetup,NumCopias,TipoProp,IdCiaDef,C.Inactivo AS Inactvo
 FROM CtasCorrientes AS C INNER JOIN Bancos AS B ON C.IdBanco=B.IdBanco INNER JOIN Puc AS P ON C.IdCuenta=P.IdCuenta
 WHERE C.IdBanco LIKE ISNULL(@pmIdBanco,'%') AND C.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND  (C.Inactivo=ISNULL(@pmInactivo,0) or C.Inactivo=ISNULL(@pmInactivo,1))
 AND IdCiaDef LIKE ISNULL(@pmIdCiaDef,'%%')
ORDER BY  IdCta
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCtasCorrientesPuc] @pmIdCuenta VARCHAR(16)
AS
 SELECT IdCta,NumeroCta,C.IdBanco AS CodBanco,Banco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato
 ,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,C.Inactivo AS Inactiv,IdCiaDef,TipoProp
  FROM   CtasCorrientes AS C INNER JOIN Bancos ON C.IdBanco=Bancos.IdBanco
  WHERE  IdCuenta=@pmIdCuenta
  ORDER BY IdCta
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCtasCorrientesNum] @pmNumeroCta VARCHAR(20),@pmOper VARCHAR(4)

AS
 IF  @pmOper ='LIKE'
 SELECT IdCta,NumeroCta,C.IdBanco AS CodBanco,Banco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato
 ,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,C.Inactivo AS Inactiv,IdCiaDef,TipoProp
  FROM   CtasCorrientes AS C INNER JOIN Bancos ON C.IdBanco=Bancos.IdBanco
  WHERE  NumeroCta LIKE @pmNumeroCta
  ORDER BY IdCta
 ELSE
  SELECT IdCta,NumeroCta,C.IdBanco AS CodBanco,Banco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato
 ,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,C.Inactivo AS Inactiv,IdCiaDef,TipoProp
  FROM   CtasCorrientes AS C INNER JOIN Bancos ON C.IdBanco=Bancos.IdBanco
   WHERE  NumeroCta=@pmNumeroCta
  ORDER BY IdCta
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsCtasCorrientes] @pmIdCta VARCHAR(4),@pmNumeroCta VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmConsCheques BIT,@pmRangoCons VARCHAR(20)
,@pmConsActual INT,@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmInactivo BIT,@pmIdCiaDef CHAR(2),@pmTipoProp VARCHAR(10)
 AS 
 INSERT INTO CtasCorrientes (IdCta,NumeroCta,IdBanco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato,TipoPapel,Orientacion,VistaPrevia,VerSetup,NumCopias,IdCiaDef,Inactivo,TipoProp)
 VALUES (@pmIdCta,@pmNumeroCta,@pmIdBanco,@pmIdCuenta,@pmConsCheques,@pmRangoCons,@pmConsActual,@pmFormato,@pmTipoPapel,@pmOrientacion
,@pmVistaPrevia,@pmVerSetup,@pmNumCopias,@pmIdCiaDef,@pmInactivo,@pmTipoProp)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpCtasCorrientes] @pmIdCta VARCHAR(4),@pmNumeroCta VARCHAR(20),@pmIdBanco VARCHAR(4),@pmIdCuenta VARCHAR(16),@pmConsCheques BIT,@pmRangoCons VARCHAR(20)
,@pmConsActual INT,@pmFormato VARCHAR(20),@pmTipoPapel INT,@pmOrientacion INT,@pmVistaPrevia BIT,@pmVerSetup BIT,@pmNumCopias INT,@pmInactivo BIT,@pmIdCiaDef CHAR(2),@pmTipoProp VARCHAR(10)
 AS 
 UPDATE CtasCorrientes SET NumeroCta=@pmNumeroCta,IdBanco=@pmIdBanco,IdCuenta=@pmIdCuenta,ConsCheques=@pmConsCheques,RangoCons=@pmRangoCons,ConsActual=@pmConsActual,Formato=@pmFormato
,TipoPapel=@pmTipoPapel,Orientacion=@pmOrientacion,VistaPrevia=@pmVistaPrevia,VerSetup=@pmVerSetup,NumCopias=@pmNumCopias,Inactivo=@pmInactivo,IdCiaDef=@pmIdCiaDef,TipoProp=@pmTipoProp
 WHERE IdCta=@pmIdCta
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryCtasCorrientes] @pmIdCta VARCHAR(4)
 AS 
 SELECT IdCta,NumeroCta,IdBanco,IdCuenta,ConsCheques,RangoCons,ConsActual,Formato,TipoPapel,Orientacion
,VistaPrevia,VerSetup,NumCopias,IdCiaDef,TipoProp,Inactivo
 FROM CtasCorrientes
 WHERE IdCta=@pmIdCta
GO
