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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE Pa_Actualizar (@pmTabla VARCHAR(50),@pmCampos VARCHAR(2000),@pmCriterio VARCHAR(1000))
AS

BEGIN
 Declare @pmQry VARCHAR(2000)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'UPDATE '+ @pmTabla+' SET ' + @pmCampos
 IF LEN(@pmCriterio)>0 
  BEGIN
   SET  @pmQry=@pmQry + ' WHERE ' + @pmCriterio
  END

EXECUTE  (@pmQry)

RETURN
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE Pa_Agregar (@pmTabla VARCHAR(50),@pmCampos VARCHAR(1000),@pmValores VARCHAR(2000))
AS

BEGIN
 Declare @pmQry VARCHAR(2000)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'INSERT INTO '+ @pmTabla+' '
 SET @pmQry=@pmQry + '('+ @pmCampos+') VALUES '
 SET @pmQry=@pmQry + '('+ @pmValores+')'
 EXECUTE  (@pmQry)

RETURN
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE Pa_Eliminar (@pmTabla VARCHAR(50),@pmCriterio VARCHAR(500))
AS

BEGIN
 Declare @pmQry VARCHAR(500)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'DELETE FROM '+ @pmTabla
 IF LEN(@pmCriterio)>0 
  BEGIN
   SET @pmQry=@pmQry +'  WHERE ' + @pmCriterio
  END

EXECUTE  (@pmQry)

RETURN
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO


CREATE PROCEDURE Pa_InsertSelect  
(@pmDB VARCHAR(50),
@pmOwn VARCHAR(50),
@pmTabla VARCHAR(50),
@pmCampos VARCHAR(1000),
@pmQuery VARCHAR(2000))

AS

BEGIN
 Declare @pmQry VARCHAR(2500)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'INSERT INTO '+ @pmDB + '.'+ @pmOwn +'.'+@pmTabla
 SET @pmQry=@pmQry + ' ('+ @pmCampos+') '+ @pmQuery
 EXECUTE  (@pmQry)

RETURN
END

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE Pa_Query 
(@pmCampos VARCHAR(1500),
 @pmTabla VARCHAR(1500),
@pmCriterio VARCHAR(2000),
@pmOrden VARCHAR(200),
@pmGroup VARCHAR(500),
@pmHaving VARCHAR(100))

AS

BEGIN
 Declare @pmQry VARCHAR(5800)
 SET @pmQry=''
 SET @pmQry=@pmQry + 'SELECT '+ @pmCampos + '  FROM ' + @pmTabla
 IF Len(@pmCriterio)>0
 BEGIN
  SET @pmQry=@pmQry + '  WHERE '+ @pmCriterio
 END
 IF Len(@pmGroup)>0 
 BEGIN
  SET @pmQry=@pmQry + ' GROUP BY ' + @pmGroup
 END
 IF Len(@pmOrden)>0 
 BEGIN
  SET @pmQry=@pmQry + ' ORDER BY '+ @pmOrden
 END
 IF Len(@pmHaving)>0 
 BEGIN
  SET @pmQry=@pmQry + ' HAVING '+ @pmHaving
 END
EXECUTE  (@pmQry)

RETURN
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelBalances @pmnAnno INT,@pmIdCuenta VARCHAR(16),@pmItem INT
 AS 
 DELETE FROM Balances
 WHERE nAnno=@pmnAnno AND IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelConceptos @pmIdFmto INT,@pmIdConcepto INT
 AS 
 DELETE FROM Conceptos
 WHERE IdFmto=@pmIdFmto AND IdConcepto=@pmIdConcepto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelFmtoDetalle @pmIdFmto INT,@pmnAnno INT,@pmNumero INT,@pmItem INT
 AS 
 DELETE FROM FmtoDetalle
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
 AND  (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))


GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelFmtoEncab @pmIdFmto INT,@pmnAnno INT,@pmNumero INT
 AS 
 DELETE FROM FmtoEncab
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelFmtoEnvios @pmIdFmto INT,@pmnAnno INT
 AS 
 DELETE FROM FmtoEnvios
 WHERE IdFmto=@pmIdFmto 
 AND (nAnno>=ISNULL(@pmnAnno,0)  AND nAnno<=ISNULL(@pmnAnno,2147483647))

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelFormtos @pmIdFmto INT
 AS 
 DELETE FROM Formtos
 WHERE IdFmto=@pmIdFmto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelInfCnxion @pmIdReg INT
 AS 
 DELETE FROM InfCnxion
 WHERE IdReg=@pmIdReg
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelPuc @pmIdCuenta VARCHAR(16)
 AS 
 DELETE FROM Puc
 WHERE IdCuenta=@pmIdCuenta
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDelTiposId @pmIdTdoc INT
 AS 
 DELETE FROM TiposId
 WHERE IdTdoc=@pmIdTdoc
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDeltmDetalle @pmIdEst CHAR(2),@pmIdFmto INT,@pmItem INT
 AS 
 DELETE FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto 
 AND (Item>=ISNULL(@pmItem,-1)  AND Item<=ISNULL(@pmItem,2147483647))
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paDeltmDetalleEst @pmIdEst CHAR(2),@pmIdFmto INT,@pmEstado VARCHAR(20)
 AS 
 DELETE FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto  AND Estado=@pmEstado

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsBalances @pmnAnno INT,@pmIdCuenta VARCHAR(16),@pmItem INT,@pmNid VARCHAR(16),@pmTid CHAR(1),@pmDv CHAR(1),@pmRazonSocial VARCHAR(250),@pmDireccion VARCHAR(250)
,@pmCodMun VARCHAR(8),@pmMun VARCHAR(50),@pmCodDpto VARCHAR(8),@pmDpto VARCHAR(50),@pmSaldoAnt MONEY,@pmDebitos MONEY,@pmCreditos MONEY,@pmNuevoSaldo MONEY,@pmPosNom INT
,@pmBaseGravb MONEY
 AS 
 INSERT INTO Balances (nAnno,IdCuenta,Item,Nid,Tid,Dv,RazonSocial,Direccion,CodMun,Mun,CodDpto,Dpto,SaldoAnt,Debitos,Creditos,NuevoSaldo,PosNom,BaseGravb)
 VALUES (@pmnAnno,@pmIdCuenta,@pmItem,@pmNid,@pmTid,@pmDv,@pmRazonSocial,@pmDireccion,@pmCodMun,@pmMun,@pmCodDpto,@pmDpto
,@pmSaldoAnt,@pmDebitos,@pmCreditos,@pmNuevoSaldo,@pmPosNom,@pmBaseGravb)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsConceptos @pmIdFmto INT,@pmIdConcepto INT,@pmConcepto VARCHAR(250)
,@pmOrigenValor INT,@pmVrMinimo MONEY,@pmCriterios VARCHAR(250)
 AS 
 INSERT INTO Conceptos (IdConcepto,Concepto,IdFmto,OrigenValor,VrMinimo,Criterios)
 VALUES (@pmIdConcepto,@pmConcepto,@pmIdFmto,@pmOrigenValor,@pmVrMinimo,@pmCriterios)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsFmtoDetalle @pmIdFmto INT,@pmnAnno INT,@pmNumero INT,@pmItem INT,@pmIdConcepto INT,@pmTDoc INT,@pmNid VARCHAR(20),@pmDv CHAR(1),@pmApl1 VARCHAR(60),@pmApl2 VARCHAR(60),@pmNom1 VARCHAR(60)
,@pmNom2 VARCHAR(60),@pmRazSocial VARCHAR(250),@pmDireccion VARCHAR(250),@pmMun INT,@pmDpto INT,@pmVrTotal MONEY,@pmVrOtros MONEY,@pmReferncia VARCHAR(50),@pmTDcnt INT,@pmNitcnt VARCHAR(20),@pmDvcnt CHAR(1)
,@pmApl1cnt VARCHAR(60),@pmApl2cnt VARCHAR(60),@pmNom1cnt VARCHAR(60),@pmNom2cnt VARCHAR(60),@pmRazcnt VARCHAR(250),@pmEstado VARCHAR(20),@pmObserv VARCHAR(100),@pmMunNom VARCHAR(50),@pmDptoNom VARCHAR(50)
 AS 
 INSERT INTO FmtoDetalle (IdFmto,nAnno,Numero,Item,IdConcepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros,Referncia,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom)
 VALUES (@pmIdFmto,@pmnAnno,@pmNumero,@pmItem,@pmIdConcepto,@pmTDoc,@pmNid,@pmDv,@pmApl1,@pmApl2,@pmNom1,@pmNom2,@pmRazSocial,@pmDireccion,@pmMun,@pmDpto,@pmVrTotal,@pmVrOtros
,@pmReferncia,@pmTDcnt,@pmNitcnt,@pmDvcnt,@pmApl1cnt,@pmApl2cnt,@pmNom1cnt,@pmNom2cnt,@pmRazcnt,@pmEstado,@pmObserv,@pmMunNom,@pmDptoNom)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsFmtoDetalle_Sel @pmIdEst CHAR(2),@pmIdFmto INT,@pmnAnno INT,@pmNumero INT,@pmEstado VARCHAR(20)=Null
 AS
 INSERT INTO FmtoDetalle (IdFmto,nAnno,Numero,Item,IdConcepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros,Referncia
,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom)
 SELECT IdFmto,@pmnAnno,@pmNumero,Item,IdConcepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros,Referncia
,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom
 FROM tmDetalle 
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto AND Estado like ISNULL(@pmEstado,'%')
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsFmtoEncab @pmIdFmto INT,@pmnAnno INT,@pmNumero INT,@pmModaldad INT,@pmnVersion INT,@pmFecha SMALLDATETIME
,@pmFecInicial SMALLDATETIME,@pmFecFinal SMALLDATETIME,@pmValorTotal MONEY,@pmCantReg INT,@pmEstado VARCHAR(10),@pmObservciones VARCHAR(250),@pmTimeSys SMALLDATETIME
 AS 
 INSERT INTO FmtoEncab (IdFmto,nAnno,Numero,Modaldad,nVersion,Fecha,FecInicial,FecFinal,ValorTotal,CantReg,Estado,Observciones,TimeSys)
 VALUES (@pmIdFmto,@pmnAnno,@pmNumero,@pmModaldad,@pmnVersion,@pmFecha,@pmFecInicial,@pmFecFinal,@pmValorTotal,@pmCantReg,@pmEstado
,@pmObservciones,@pmTimeSys)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsFmtoEnvios @pmIdFmto INT,@pmnAnno INT,@pmConsctivo INT
 AS 
 INSERT INTO FmtoEnvios (IdFmto,nAnno,Consctivo)
 VALUES (@pmIdFmto,@pmnAnno,@pmConsctivo)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsFormtos @pmIdFmto INT,@pmFormto VARCHAR(250),@pmCantMax INT
 AS 
 INSERT INTO Formtos (IdFmto,Formto,CantMax)
 VALUES (@pmIdFmto,@pmFormto,@pmCantMax)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsInfCnxion @pmIdReg INT,@pmCnxEngine VARCHAR(3),@pmCnxDso VARCHAR(250),@pmCnxDbname VARCHAR(50)
,@pmCnxAutentic VARCHAR(3),@pmCnxUid VARCHAR(50),@pmCnxPwd VARCHAR(50),@pmCnxOwner VARCHAR(20),@pmCnxApp VARCHAR(10)
,@pmCnxProv VARCHAR(50),@pmCnxVersn INT
 AS 
 INSERT INTO InfCnxion (IdReg,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd,CnxOwner,CnxApp,CnxProv,CnxVersn)
 VALUES (@pmIdReg,@pmCnxEngine,@pmCnxDso,@pmCnxDbname,@pmCnxAutentic,@pmCnxUid,@pmCnxPwd,@pmCnxOwner,@pmCnxApp,@pmCnxProv,@pmCnxVersn)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsLogPro @pmIdLog INT,@pmIdPro VARCHAR(20),@pmFecha SMALLDATETIME,@pmTimeSys SMALLDATETIME,@pmIdUsuario VARCHAR(11)
,@pmNombre VARCHAR(50),@pmNomTabla VARCHAR(20),@pmIdFmto INT,@pmnAnno INT,@pmObservacion VARCHAR(250)
 AS 
 INSERT INTO LogPro (IdLog,IdPro,Fecha,TimeSys,IdUsuario,Nombre,NomTabla,IdFmto,nAnno,Observacion)
 VALUES (@pmIdLog,@pmIdPro,@pmFecha,@pmTimeSys,@pmIdUsuario,@pmNombre,@pmNomTabla,@pmIdFmto,@pmnAnno,@pmObservacion)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsPuc @pmIdCuenta VARCHAR(16),@pmNomCuenta VARCHAR(100),@pmMayor BIT,@pmMovimiento BIT,@pmTercero BIT
,@pmBaseGravable BIT,@pmNaturaleza CHAR(1),@pmIdFmto INT,@pmIdConcepto INT
 AS 
 INSERT INTO Puc (IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,BaseGravable,Naturaleza,IdFmto,IdConcepto)
 VALUES (@pmIdCuenta,@pmNomCuenta,@pmMayor,@pmMovimiento,@pmTercero,@pmBaseGravable,@pmNaturaleza,@pmIdFmto,@pmIdConcepto)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInsTiposId @pmIdTdoc INT,@pmTipoDoc VARCHAR(50)
 AS 
 INSERT INTO TiposId (IdTdoc,TipoDoc)
 VALUES (@pmIdTdoc,@pmTipoDoc)

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInstmDetalle @pmIdEst CHAR(2),@pmIdFmto INT,@pmItem INT,@pmIdConcepto INT,@pmTDoc INT,@pmNid VARCHAR(20),@pmDv CHAR(1),@pmApl1 VARCHAR(60),@pmApl2 VARCHAR(60),@pmNom1 VARCHAR(60),@pmNom2 VARCHAR(60),@pmRazSocial VARCHAR(250)
,@pmDireccion VARCHAR(250),@pmMun INT,@pmDpto INT,@pmVrTotal MONEY,@pmVrOtros MONEY,@pmReferncia VARCHAR(50),@pmTDcnt INT,@pmNitcnt VARCHAR(20),@pmDvcnt CHAR(1),@pmApl1cnt VARCHAR(60),@pmApl2cnt VARCHAR(60),@pmNom1cnt VARCHAR(60),@pmNom2cnt VARCHAR(60)
,@pmRazcnt VARCHAR(250),@pmEstado VARCHAR(20),@pmObserv VARCHAR(100),@pmMunNom VARCHAR(50),@pmDptoNom VARCHAR(50)
 AS 
 INSERT INTO tmDetalle (IdEst,IdFmto,Item,IdConcepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros,Referncia,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom)
 VALUES (@pmIdEst,@pmIdFmto,@pmItem,@pmIdConcepto,@pmTDoc,@pmNid,@pmDv,@pmApl1,@pmApl2,@pmNom1,@pmNom2,@pmRazSocial,@pmDireccion,@pmMun,@pmDpto,@pmVrTotal,@pmVrOtros,@pmReferncia,@pmTDcnt,@pmNitcnt,@pmDvcnt
,@pmApl1cnt,@pmApl2cnt,@pmNom1cnt,@pmNom2cnt,@pmRazcnt,@pmEstado,@pmObserv,@pmMunNom,@pmDptoNom)
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paInstmDetalle_Sel @pmIdEst CHAR(2),@pmIdFmto INT,@pmnAnno INT,@pmNumero INT
 AS
 INSERT INTO tmDetalle (IdEst,IdFmto,Item,IdConcepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros,Referncia
,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom)
 SELECT @pmIdEst,IdFmto,Item,IdConcepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros,Referncia
,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom
 FROM FmtoDetalle
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryBalances @pmnAnno INT,@pmIdCuenta VARCHAR(16)=Null,@pmIdFmto INT=Null,@pmIdConcepto INT=Null
 AS 
 SELECT B.IdCuenta AS CodCuenta,NomCuenta,Tid,Nid,Dv,RazonSocial,Direccion,CodMun,Mun,CodDpto,Dpto,SaldoAnt,Debitos,Creditos
,SaldoAnt+Debitos-Creditos AS VrNuevoSaldo,nAnno,Item,PosNom,Mayor,Movimiento,Tercero,BaseGravable,Naturaleza,P.IdFmto AS CodFmto
,Formto,P.IdConcepto AS CodConcep,Concepto,BaseGravb
 FROM Balances AS B INNER JOIN Puc  AS P ON B.IdCuenta=P.IdCuenta
 LEFT JOIN Formtos AS F ON P.IdFmto=F.IdFmto
 LEFT JOIN Conceptos AS CN ON P.IdFmto=CN.IdFmto AND P.IdConcepto=CN.IdConcepto
 WHERE nAnno=@pmnAnno AND B.IdCuenta LIKE ISNULL(@pmIdCuenta,'%')
 AND (P.IdFmto>=ISNULL(@pmIdFmto,-1)  AND P.IdFmto<=ISNULL(@pmIdFmto,2147483647))
 AND (P.IdConcepto>=ISNULL(@pmIdConcepto,-1)  AND P.IdConcepto<=ISNULL(@pmIdConcepto,2147483647))
 ORDER BY B.IdCuenta,RazonSocial
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryBalancesFmt @pmnAnno INT,@pmIdFmto INT,@pmIdConcepto INT=Null
 AS 
 SELECT P.IdConcepto AS CodConcep,Concepto,Naturaleza,Tid,Nid,Dv,RazonSocial,Direccion,CodMun,Mun
,CodDpto,Dpto,PosNom,SUM(SaldoAnt) AS VrSanAnt,SUM(Debitos) AS STotDeb,SUM(Creditos) AS STotCre
,SUM(SaldoAnt+Debitos-Creditos) AS VrNuevoSaldo,SUM(BaseGravb) AS SBasGrav
 FROM Balances AS B INNER JOIN Puc  AS P ON B.IdCuenta=P.IdCuenta
 LEFT JOIN Conceptos AS CN ON P.IdFmto=CN.IdFmto AND P.IdConcepto=CN.IdConcepto
 WHERE nAnno=@pmnAnno AND P.IdFmto=@pmIdFmto
 AND (P.IdConcepto>=ISNULL(@pmIdConcepto,-1)  AND P.IdConcepto<=ISNULL(@pmIdConcepto,2147483647))
 GROUP BY  P.IdConcepto,Concepto,Naturaleza,Tid,Nid,Dv,RazonSocial,Direccion,CodMun,Mun,CodDpto,Dpto,PosNom
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryConceptos @pmIdFmto INT,@pmIdConcepto INT
 AS 
 SELECT IdFmto,IdConcepto,Concepto,OrigenValor,VrMinimo,Criterios
 FROM Conceptos
 WHERE IdFmto=@pmIdFmto AND IdConcepto=@pmIdConcepto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryConceptosDso @pmIdFmto INT
 AS 
 SELECT IdFmto,IdConcepto,Concepto,CAST(IdConcepto AS VARCHAR(9))+' '+Concepto AS DsCon
 FROM Conceptos
 WHERE  (IdFmto>=ISNULL(@pmIdFmto,0)  AND IdFmto<=ISNULL(@pmIdFmto,2147483647))
 ORDER BY IdFmto,IdConcepto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryConceptosLta @pmIdFmto INT=Null
 AS 
 SELECT IdFmto,IdConcepto,Concepto,OrigenValor,VrMinimo,Criterios
 FROM Conceptos
 WHERE  (IdFmto>=ISNULL(@pmIdFmto,0)  AND IdFmto<=ISNULL(@pmIdFmto,2147483647))
 ORDER BY IdFmto,IdConcepto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryConceptosMin @pmIdFmto INT
 AS 
 SELECT COUNT(IdConcepto) AS SCANT
 FROM Conceptos
 WHERE IdFmto=@pmIdFmto AND VrMinimo<>0
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFmtoDetalle @pmIdFmto INT,@pmnAnno INT,@pmNumero INT,@pmItem INT
 AS 
 SELECT IdFmto,nAnno,Numero,Item,IdConcepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros,Referncia
,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom
 FROM FmtoDetalle
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
 AND  (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY  Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFmtoDetalleInc @pmIdFmto INT,@pmnAnno INT,@pmNumero INT
 AS 
 SELECT COUNT(Item) AS SCANT,SUM(VrTotal) AS SVALTOT
 FROM FmtoDetalle
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
 AND Estado<>'CORRECTO'

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFmtoDetalleItm @pmIdFmto INT,@pmnAnno INT,@pmNumero INT
 AS 
 SELECT MAX(Item) AS MXITM
 FROM FmtoDetalle
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFmtoDetalleTot @pmIdFmto INT,@pmnAnno INT,@pmNumero INT
 AS 
 SELECT SUM(VrTotal) AS STOT,SUM(VrOtros) AS SOTR
 FROM FmtoDetalle
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFmtoEncab @pmIdFmto INT,@pmnAnno INT,@pmNumero INT
 AS 
 SELECT IdFmto,nAnno,Numero,Modaldad,nVersion,Fecha,FecInicial,FecFinal,ValorTotal,CantReg,Estado,Observciones,TimeSys
 FROM FmtoEncab
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFmtoEncabDso @pmIdFmto INT,@pmnAnno INT,@pmNumero INT,@pmEstado VARCHAR(20)=Null
 AS 
 SELECT E.IdFmto AS CodFmto,Formto,E.nAnno AS NumAnno,E.Numero AS NumEnvio,Modaldad,nVersion,Fecha,FecInicial,FecFinal,ValorTotal,CantReg,E.Estado AS EstadFmto,Observciones,TimeSys
--detalles
,Item,D.IdConcepto AS CodCpto,Concepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros,Referncia
,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,D.Estado AS EstDetalle,Observ,MunNom,DptoNom,VrMinimo,Criterios,TipoDoc,CantMax
 FROM FmtoEncab AS E INNER JOIN FmtoDetalle AS D ON E.IdFmto=D.IdFmto AND E.nAnno=D.nAnno AND E.Numero=D.Numero
 INNER JOIN Formtos AS F ON E.IdFmto=F.IdFmto
 INNER JOIN Conceptos AS C ON D.IdFmto=C.IdFmto AND D.IdConcepto=C.IdConcepto
 LEFT JOIN TiposId AS TI ON D.TDoc=TI.IdTdoc
 WHERE E.IdFmto=@pmIdFmto 
 AND  (E.nAnno>=ISNULL(@pmnAnno,0)  AND E.nAnno<=ISNULL(@pmnAnno,2147483647))
 AND  (E.Numero>=ISNULL(@pmNumero,0)  AND E.Numero<=ISNULL(@pmNumero,2147483647))
 AND D.Estado LIKE ISNULL(@pmEstado,'%')
 ORDER BY E.nAnno,E.Numero,Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFmtoEnvios @pmIdFmto INT,@pmnAnno INT
 AS 
 SELECT IdFmto,nAnno,Consctivo
 FROM FmtoEnvios
 WHERE IdFmto=@pmIdFmto  AND nAnno=@pmnAnno

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFmtoEnviosLta @pmIdFmto INT
 AS 
 SELECT IdFmto,nAnno,Consctivo
 FROM FmtoEnvios
 WHERE  (IdFmto>=ISNULL(@pmIdFmto,0)  AND IdFmto<=ISNULL(@pmIdFmto,2147483647))
 ORDER BY IdFmto,nAnno

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFormtos @pmIdFmto INT
 AS 
 IF @pmIdFmto IS NULL
  SELECT IdFmto,Formto,CantMax  FROM Formtos   ORDER BY IdFmto
 ELSE
  SELECT IdFmto,Formto,CantMax  FROM Formtos
  WHERE  IdFmto=@pmIdFmto
 
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryFormtosDso
 AS 
  SELECT IdFmto,Formto,CAST(IdFmto AS VARCHAR(9)) +' '+Formto AS DsFor
  FROM Formtos 
 ORDER BY IdFmto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryInfCnxion @pmIdReg INT
 AS 
 SELECT IdReg,CnxEngine,CnxProv,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd,CnxOwner,CnxApp,CnxVersn
 FROM InfCnxion
 WHERE IdReg=@pmIdReg
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryLogProId @pmIdPro VARCHAR(20)
 AS 
 SELECT MAX(IdLog) AS MXITM
 FROM LogPro
 WHERE  IdPro=@pmIdPro
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryPuc @pmIdCuenta VARCHAR(16)
 AS 
 SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,BaseGravable,Naturaleza,IdFmto,IdConcepto
 FROM Puc
 WHERE IdCuenta=@pmIdCuenta
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryPucDso
 AS 
 SELECT IdCuenta,NomCuenta,IdCuenta + ' '+NomCuenta AS DsPuc
 FROM Puc
 ORDER BY IdCuenta
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryPucLta
 AS 
 SELECT IdCuenta,NomCuenta,Mayor,Movimiento,IdFmto,IdConcepto,Tercero,BaseGravable,Naturaleza
 FROM Puc
 ORDER BY  IdCuenta
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryPucSub  @pmIdCuenta VARCHAR(16)

AS
  SELECT  IdCuenta,NomCuenta   FROM  Puc  
 WHERE  SUBSTRING(IdCuenta ,1,LEN(@pmIdCuenta) )=@pmIdCuenta AND IdCuenta<>@pmIdCuenta
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQryTiposId @pmIdTdoc INT
 AS 
 IF @pmIdTdoc IS NULL
  SELECT IdTdoc,TipoDoc  FROM TiposId ORDER BY IdTdoc
 ELSE
  SELECT IdTdoc,TipoDoc  FROM TiposId 
  WHERE IdTdoc=@pmIdTdoc
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalle @pmIdEst CHAR(2),@pmIdFmto INT,@pmItem INT
 AS 
 SELECT IdEst,IdFmto,Item,IdConcepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros
,Referncia,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY  Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalleCon @pmIdEst CHAR(2),@pmIdFmto INT,@pmIdConcepto INT,@pmTDoc INT
,@pmNid VARCHAR(20),@pmItem INT
 AS 
 SELECT IdEst,IdFmto,Item,IdConcepto,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion,Mun,Dpto,VrTotal,VrOtros
,Referncia,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto AND IdConcepto=@pmIdConcepto AND TDoc=@pmTDoc
 AND Nid=@pmNid AND Item<>@pmItem
 ORDER BY  Item
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalleCri @pmIdEst CHAR(2),@pmIdFmto INT
 AS 
 SELECT IdEst,D.IdFmto AS CodFmto,Item,D.IdConcepto AS IdConcep,TDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial
,Direccion,Mun,Dpto,VrTotal,VrOtros,Referncia,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt
,Estado,Observ,MunNom,DptoNom,VrMinimo,Criterios,Concepto
 FROM tmDetalle AS D INNER JOIN Conceptos AS C ON D.IdFmto=C.IdFmto AND D.IdConcepto=C.IdConcepto
 WHERE IdEst=@pmIdEst AND D.IdFmto=@pmIdFmto AND  VrMinimo>0
 ORDER BY  TDoc,Nid,D.IdConcepto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalleDso @pmIdEst CHAR(2),@pmIdFmto INT
 AS 
 SELECT Item,D.IdConcepto AS CodCpto,Concepto,TDoc,TipoDoc,Nid,Dv,Apl1,Apl2,Nom1,Nom2,RazSocial,Direccion
 ,Mun,MunNom,Dpto,DptoNom,VrTotal,VrOtros,Referncia,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt
,Nom2cnt,Razcnt,Estado,Observ,D.IdFmto AS CodFmto
 FROM tmDetalle AS D INNER JOIN Conceptos AS C ON D.IdFmto=C.IdFmto AND D.IdConcepto=C.IdConcepto
 LEFT JOIN TiposId AS TI ON D.TDoc=TI.IdTdoc
 WHERE IdEst=@pmIdEst AND D.IdFmto=@pmIdFmto
 ORDER BY  Item

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalleInc @pmIdEst CHAR(2),@pmIdFmto INT
 AS 
 SELECT COUNT(Item) AS SCANT,SUM(VrTotal) AS SVALTOT
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto AND Estado<>'CORRECTO'

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalleItm @pmIdEst CHAR(2),@pmIdFmto INT 
 AS 
 SELECT MAX(Item) AS MITEM
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalleTcm @pmIdEst CHAR(2),@pmIdFmto INT
 AS 
 SELECT IdConcepto,COUNT(Item) AS SCANT,SUM(VrTotal) AS SVALTOT,SUM(VrOtros) AS STOTOTR
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto AND Estado='CM'
 GROUP BY IdConcepto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalleTinc @pmIdEst CHAR(2),@pmIdFmto INT
 AS 
 SELECT COUNT(Item) AS SCANT,SUM(VrTotal) AS SVALTOT,SUM(VrOtros) AS STOTOTR
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto AND Estado<>'CORRECTO'
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalleTnid @pmIdEst CHAR(2),@pmIdFmto INT,@pmTDoc INT,@pmNid VARCHAR(20)
 AS 
 SELECT COUNT(Item) AS SCANT,SUM(VrTotal) AS SVALTOT,SUM(VrOtros) AS STOTOTR
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto  AND TDoc=@pmTDoc AND Nid=@pmNid
 

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paQrytmDetalleTot @pmIdEst CHAR(2),@pmIdFmto INT,@pmEstado VARCHAR(20)=Null
 AS 
 SELECT COUNT(Item) AS SCANT,SUM(VrTotal) AS SVALTOT,SUM(VrOtros) AS STOTOTR
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto AND Estado LIKE ISNULL(@pmEstado,'%')

GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpBalances @pmnAnno INT,@pmIdCuenta VARCHAR(16),@pmNid VARCHAR(16)
,@pmSaldoAnt MONEY,@pmNuevoSaldo MONEY
 AS 
 UPDATE Balances SET  SaldoAnt=@pmSaldoAnt,NuevoSaldo=@pmNuevoSaldo
 WHERE nAnno=@pmnAnno AND IdCuenta=@pmIdCuenta AND Nid LIKE ISNULL(@pmNid,'%')
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpBalancesBas @pmnAnno INT,@pmIdCuenta VARCHAR(16),@pmNid VARCHAR(16)
,@pmBaseGravb MONEY 
 AS 
 UPDATE Balances SET BaseGravb=@pmBaseGravb
 WHERE nAnno=@pmnAnno AND IdCuenta=@pmIdCuenta AND Nid LIKE ISNULL(@pmNid,'%')
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpConceptos @pmIdFmto INT,@pmIdConcepto INT,@pmConcepto VARCHAR(250)
,@pmOrigenValor INT,@pmVrMinimo MONEY,@pmCriterios VARCHAR(250)
 AS 
 UPDATE Conceptos SET Concepto=@pmConcepto,OrigenValor=@pmOrigenValor,VrMinimo=@pmVrMinimo
 ,Criterios=@pmCriterios
 WHERE IdFmto=@pmIdFmto AND IdConcepto=@pmIdConcepto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpFmtoEncab @pmIdFmto INT,@pmnAnno INT,@pmNumero INT,@pmModaldad INT,@pmnVersion INT,@pmFecha SMALLDATETIME,@pmFecInicial SMALLDATETIME
,@pmFecFinal SMALLDATETIME,@pmValorTotal MONEY,@pmCantReg INT,@pmEstado VARCHAR(10),@pmObservciones VARCHAR(250)
 AS 
 UPDATE FmtoEncab SET Modaldad=@pmModaldad,nVersion=@pmnVersion,Fecha=@pmFecha,FecInicial=@pmFecInicial,FecFinal=@pmFecFinal,ValorTotal=@pmValorTotal,CantReg=@pmCantReg
,Estado=@pmEstado,Observciones=@pmObservciones
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpFmtoEncabEsd @pmIdFmto INT,@pmnAnno INT,@pmNumero INT,@pmEstado VARCHAR(10)
 AS 
 UPDATE FmtoEncab SET Estado=@pmEstado
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpFmtoEnvios @pmIdFmto INT,@pmnAnno INT,@pmConsctivo INT
 AS 
 UPDATE FmtoEnvios SET Consctivo=@pmConsctivo
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpFormtos @pmIdFmto INT,@pmFormto VARCHAR(250),@pmCantMax INT
 AS 
 UPDATE Formtos SET Formto=@pmFormto,CantMax=@pmCantMax
 WHERE IdFmto=@pmIdFmto
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpInfCnxion @pmIdReg INT,@pmCnxEngine VARCHAR(3),@pmCnxDso VARCHAR(250),@pmCnxDbname VARCHAR(50),@pmCnxAutentic VARCHAR(3),@pmCnxUid VARCHAR(50),@pmCnxPwd VARCHAR(50)
,@pmCnxOwner VARCHAR(20),@pmCnxApp VARCHAR(10),@pmCnxProv VARCHAR(50),@pmCnxVersn INT
 AS 
 UPDATE InfCnxion SET CnxEngine=@pmCnxEngine,CnxDso=@pmCnxDso,CnxDbname=@pmCnxDbname,CnxAutentic=@pmCnxAutentic,CnxUid=@pmCnxUid,CnxPwd=@pmCnxPwd,CnxOwner=@pmCnxOwner
,CnxApp=@pmCnxApp,CnxVersn=@pmCnxVersn,CnxProv=@pmCnxProv
 WHERE IdReg=@pmIdReg
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpPuc @pmIdCuenta VARCHAR(16),@pmNomCuenta VARCHAR(100),@pmMayor BIT,@pmMovimiento BIT
,@pmTercero BIT,@pmBaseGravable BIT,@pmNaturaleza CHAR(1),@pmIdFmto INT,@pmIdConcepto INT
 AS 
 UPDATE Puc SET NomCuenta=@pmNomCuenta,Mayor=@pmMayor,Movimiento=@pmMovimiento,Tercero=@pmTercero,BaseGravable=@pmBaseGravable
,Naturaleza=@pmNaturaleza,IdFmto=@pmIdFmto,IdConcepto=@pmIdConcepto
 WHERE IdCuenta=@pmIdCuenta
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUpTiposId @pmIdTdoc INT,@pmTipoDoc VARCHAR(50)
 AS 
 UPDATE TiposId SET TipoDoc=@pmTipoDoc
 WHERE IdTdoc=@pmIdTdoc
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS OFF 
GO

CREATE PROCEDURE paUptmDetalle @pmIdEst CHAR(2),@pmIdFmto INT,@pmItem INT,@pmIdConcepto INT,@pmTDoc INT,@pmNid VARCHAR(20),@pmDv CHAR(1),@pmApl1 VARCHAR(60),@pmApl2 VARCHAR(60),@pmNom1 VARCHAR(60),@pmNom2 VARCHAR(60)
,@pmRazSocial VARCHAR(250),@pmDireccion VARCHAR(250),@pmMun INT,@pmDpto INT,@pmVrTotal MONEY,@pmVrOtros MONEY,@pmReferncia VARCHAR(50),@pmTDcnt INT,@pmNitcnt VARCHAR(20),@pmDvcnt CHAR(1),@pmApl1cnt VARCHAR(60),@pmApl2cnt VARCHAR(60)
,@pmNom1cnt VARCHAR(60),@pmNom2cnt VARCHAR(60),@pmRazcnt VARCHAR(250),@pmEstado VARCHAR(20),@pmObserv VARCHAR(100),@pmMunNom VARCHAR(50),@pmDptoNom VARCHAR(50)
 AS 
 UPDATE tmDetalle SET IdConcepto=@pmIdConcepto,TDoc=@pmTDoc,Nid=@pmNid,Dv=@pmDv,Apl1=@pmApl1,Apl2=@pmApl2,Nom1=@pmNom1,Nom2=@pmNom2,RazSocial=@pmRazSocial,Direccion=@pmDireccion,Mun=@pmMun,Dpto=@pmDpto,VrTotal=@pmVrTotal
,VrOtros=@pmVrOtros,Referncia=@pmReferncia,TDcnt=@pmTDcnt,Nitcnt=@pmNitcnt,Dvcnt=@pmDvcnt,Apl1cnt=@pmApl1cnt,Apl2cnt=@pmApl2cnt,Nom1cnt=@pmNom1cnt,Nom2cnt=@pmNom2cnt,Razcnt=@pmRazcnt,Estado=@pmEstado,Observ=@pmObserv
,MunNom=@pmMunNom,DptoNom=@pmDptoNom
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto AND Item=@pmItem
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON 
GO

