SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelFormtos] @pmIdFmto INT
 AS 
 DELETE FROM Formtos
 WHERE IdFmto=@pmIdFmto
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQrytmDetalleItm] @pmIdEst CHAR(2),@pmIdFmto INT 
 AS 
 SELECT MAX(Item) AS MITEM
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelInfCnxion] @pmIdReg INT
 AS 
 DELETE FROM InfCnxion
 WHERE IdReg=@pmIdReg
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDeltmDetalleEst] @pmIdEst CHAR(2),@pmIdFmto INT,@pmEstado VARCHAR(20)
 AS 
 DELETE FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto  AND Estado=@pmEstado
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelFmtoEncab] @pmIdFmto INT,@pmnAnno INT,@pmNumero INT
 AS 
 DELETE FROM FmtoEncab
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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,CodPais,VrTotal,VrOtros,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9
,ValorCol10,ValorCol11,ValorCol12,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18,ValorCol19,ValorCol20,ValorCol21,ValorCol22,ValorCol23
,Referncia,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,D.Estado AS EstDetalle,Observ
,MunNom,DptoNom,VrMinimo,Criterios,TipoDoc,CantMax,email,emailcnt,TipoFide,SubTipFide,EntidadInfo
 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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryConceptosMin] @pmIdFmto INT
 AS 
 SELECT COUNT(IdConcepto) AS SCANT
 FROM Conceptos
 WHERE IdFmto=@pmIdFmto AND VrMinimo<>0
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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,CodPais
,email,emailcnt,Estado,Observ,MunNom,DptoNom,VrMinimo,Criterios,Concepto
,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9,ValorCol10,ValorCol11,ValorCol12
,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18,ValorCol19,ValorCol20,ValorCol21,ValorCol22,ValorCol23,TipoFide,SubTipFide,EntidadInfo
 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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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))
 AND Inactivo=0
 ORDER BY IdFmto,IdConcepto
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsConceptos] @pmIdFmto INT,@pmIdConcepto INT,@pmConcepto VARCHAR(250)
,@pmOrigenValor INT,@pmVrMinimo MONEY,@pmCriterios VARCHAR(250),@pmColValor VARCHAR(3),@pmInactivo BIT
 AS 
 INSERT INTO Conceptos (IdConcepto,Concepto,IdFmto,OrigenValor,VrMinimo,Criterios,ColValor,Inactivo)
 VALUES (@pmIdConcepto,@pmConcepto,@pmIdFmto,@pmOrigenValor,@pmVrMinimo,@pmCriterios,@pmColValor,@pmInactivo)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpConceptos] @pmIdFmto INT,@pmIdConcepto INT,@pmConcepto VARCHAR(250)
,@pmOrigenValor INT,@pmVrMinimo MONEY,@pmCriterios VARCHAR(250),@pmColValor VARCHAR(3),@pmInactivo BIT
 AS 
 UPDATE Conceptos SET Concepto=@pmConcepto,OrigenValor=@pmOrigenValor,VrMinimo=@pmVrMinimo
 ,Criterios=@pmCriterios,ColValor=@pmColValor,Inactivo=@pmInactivo 
 WHERE IdFmto=@pmIdFmto AND IdConcepto=@pmIdConcepto
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptos] @pmIdFmto INT,@pmIdConcepto INT
 AS 
 SELECT IdFmto,IdConcepto,Concepto,OrigenValor,VrMinimo,Criterios,ColValor,Inactivo
 FROM Conceptos
 WHERE IdFmto=@pmIdFmto AND IdConcepto=@pmIdConcepto
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryConceptosLta] @pmIdFmto INT=Null
 AS 
 SELECT IdFmto,IdConcepto,Concepto,OrigenValor,VrMinimo,Criterios,ColValor
 FROM Conceptos
 WHERE  (IdFmto>=ISNULL(@pmIdFmto,0)  AND IdFmto<=ISNULL(@pmIdFmto,2147483647))
 AND Inactivo=0
 ORDER BY IdFmto,IdConcepto
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelConceptos] @pmIdFmto INT,@pmIdConcepto INT
 AS 
 DELETE FROM Conceptos
 WHERE IdFmto=@pmIdFmto AND IdConcepto=@pmIdConcepto
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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,email,CodPais,VrTotal,VrOtros,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9
,ValorCol10,ValorCol11,ValorCol12,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18,ValorCol19,ValorCol20,ValorCol21,ValorCol22,ValorCol23
,Referncia,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,emailcnt,TipoFide,SubTipFide,EntidadInfo,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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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,email,VrTotal,VrOtros
,Referncia,TDcnt,Nitcnt,Dvcnt,Apl1cnt,Apl2cnt,Nom1cnt,Nom2cnt,Razcnt,Estado,Observ,MunNom,DptoNom,CodPais,emailcnt
,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9,ValorCol10,ValorCol11,ValorCol12
,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18,TipoFide,SubTipFide
 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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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,CodPais,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9,ValorCol10,ValorCol11,ValorCol12
,email,emailcnt,TipoFide,SubTipFide,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18,ValorCol19,ValorCol20,ValorCol21,ValorCol22,ValorCol23,EntidadInfo)
 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,CodPais,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9,ValorCol10,ValorCol11,ValorCol12
,email,emailcnt,TipoFide,SubTipFide,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18,ValorCol19,ValorCol20,ValorCol21,ValorCol22,ValorCol23,EntidadInfo
 FROM FmtoDetalle
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno AND Numero=@pmNumero
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInstmDetalle] @pmIdEst CHAR(2),@pmIdFmto INT,@pmItem INT,@pmIdConcepto INT,@pmTDoc INT,@pmNid VARCHAR(20),@pmDv CHAR(1),@pmApl1 VARCHAR(80),@pmApl2 VARCHAR(60),@pmNom1 VARCHAR(80),@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(80),@pmApl2cnt VARCHAR(60),@pmNom1cnt VARCHAR(80),@pmNom2cnt VARCHAR(60)
,@pmRazcnt VARCHAR(250),@pmEstado VARCHAR(20),@pmObserv VARCHAR(100),@pmMunNom VARCHAR(50),@pmDptoNom VARCHAR(50),@pmCodPais VARCHAR(8),@pmValorCol2 MONEY,@pmValorCol3 MONEY,@pmValorCol4 MONEY,@pmValorCol5 MONEY,@pmValorCol6 MONEY
,@pmValorCol7 MONEY,@pmValorCol8 MONEY,@pmValorCol9 MONEY,@pmValorCol10 MONEY,@pmValorCol11 MONEY,@pmValorCol12 MONEY,@pmemail VARCHAR(100),@pmemailcnt VARCHAR(100),@pmTipoFide VARCHAR(4),@pmSubTipFide VARCHAR(4),@pmValorCol13 MONEY,@pmValorCol14 MONEY,@pmValorCol15 MONEY
,@pmValorCol16 MONEY,@pmValorCol17 MONEY,@pmValorCol18 MONEY,@pmValorCol19 MONEY,@pmValorCol20 MONEY,@pmValorCol21 MONEY,@pmValorCol22 MONEY,@pmValorCol23 MONEY,@pmEntidadInfo 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,CodPais
,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9,ValorCol10,ValorCol11,ValorCol12,email,emailcnt,TipoFide,SubTipFide,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18
,ValorCol19,ValorCol20,ValorCol21,ValorCol22,ValorCol23,EntidadInfo)
 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,@pmCodPais,@pmValorCol2,@pmValorCol3,@pmValorCol4,@pmValorCol5,@pmValorCol6,@pmValorCol7,@pmValorCol8,@pmValorCol9,@pmValorCol10,@pmValorCol11,@pmValorCol12
,@pmemail,@pmemailcnt,@pmTipoFide,@pmSubTipFide,@pmValorCol13,@pmValorCol14,@pmValorCol15,@pmValorCol16,@pmValorCol17,@pmValorCol18,@pmValorCol19,@pmValorCol20,@pmValorCol21,@pmValorCol22,@pmValorCol23,@pmEntidadInfo)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUptmDetalle] @pmIdEst CHAR(2),@pmIdFmto INT,@pmItem INT,@pmIdConcepto INT,@pmTDoc INT,@pmNid VARCHAR(20),@pmDv CHAR(1),@pmApl1 VARCHAR(80),@pmApl2 VARCHAR(60),@pmNom1 VARCHAR(80),@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(80),@pmApl2cnt VARCHAR(60)
,@pmNom1cnt VARCHAR(80),@pmNom2cnt VARCHAR(60),@pmRazcnt VARCHAR(250),@pmEstado VARCHAR(20),@pmObserv VARCHAR(100),@pmMunNom VARCHAR(50),@pmDptoNom VARCHAR(50),@pmCodPais VARCHAR(8),@pmValorCol2 MONEY,@pmValorCol3 MONEY,@pmValorCol4 MONEY
,@pmValorCol5 MONEY,@pmValorCol6 MONEY,@pmValorCol7 MONEY,@pmValorCol8 MONEY,@pmValorCol9 MONEY,@pmValorCol10 MONEY,@pmValorCol11 MONEY,@pmValorCol12 MONEY,@pmemail VARCHAR(100),@pmemailcnt VARCHAR(100),@pmTipoFide VARCHAR(4),@pmSubTipFide VARCHAR(4)
,@pmValorCol13 MONEY,@pmValorCol14 MONEY,@pmValorCol15 MONEY,@pmValorCol16 MONEY,@pmValorCol17 MONEY,@pmValorCol18 MONEY,@pmValorCol19 MONEY,@pmValorCol20 MONEY,@pmValorCol21 MONEY,@pmValorCol22 MONEY,@pmValorCol23 MONEY,@pmEntidadInfo INT
 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,CodPais=@pmCodPais
,MunNom=@pmMunNom,DptoNom=@pmDptoNom,ValorCol2=@pmValorCol2,ValorCol3=@pmValorCol3,ValorCol4=@pmValorCol4,ValorCol5=@pmValorCol5,ValorCol6=@pmValorCol6,ValorCol7=@pmValorCol7
,ValorCol8=@pmValorCol8,ValorCol9=@pmValorCol9,ValorCol10=@pmValorCol10,ValorCol11=@pmValorCol11,ValorCol12=@pmValorCol12,email=@pmemail,emailcnt=@pmemailcnt,TipoFide=@pmTipoFide,SubTipFide=@pmSubTipFide
,ValorCol13=@pmValorCol13,ValorCol14=@pmValorCol14,ValorCol15=@pmValorCol15,ValorCol16=@pmValorCol16,ValorCol17=@pmValorCol17,ValorCol18=@pmValorCol18,ValorCol19=@pmValorCol19,ValorCol20=@pmValorCol20,ValorCol21=@pmValorCol21
,ValorCol22=@pmValorCol22,ValorCol23=@pmValorCol23,EntidadInfo=@pmEntidadInfo
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto AND Item=@pmItem
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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,CodPais
,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9,ValorCol10,ValorCol11,ValorCol12
,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18,ValorCol19,ValorCol20,ValorCol21,ValorCol22,ValorCol23
,email,emailcnt,TipoFide,SubTipFide,EntidadInfo
 FROM tmDetalle
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto
 AND (Item>=ISNULL(@pmItem,0)  AND Item<=ISNULL(@pmItem,2147483647))
 ORDER BY  Item
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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,CodPais,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9,ValorCol10,ValorCol11,ValorCol12,email,emailcnt,TipoFide,SubTipFide
,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18,ValorCol19,ValorCol20,ValorCol21,ValorCol22,ValorCol23,EntidadInfo)
 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,CodPais,ValorCol2,ValorCol3,ValorCol4,ValorCol5,ValorCol6,ValorCol7,ValorCol8,ValorCol9,ValorCol10,ValorCol11,ValorCol12,email,emailcnt,TipoFide,SubTipFide
,ValorCol13,ValorCol14,ValorCol15,ValorCol16,ValorCol17,ValorCol18,ValorCol19,ValorCol20,ValorCol21,ValorCol22,ValorCol23,EntidadInfo
 FROM tmDetalle 
 WHERE IdEst=@pmIdEst AND IdFmto=@pmIdFmto AND Estado like ISNULL(@pmEstado,'%')
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsFmtoEnvios] @pmIdFmto INT,@pmnAnno INT,@pmConsctivo INT
 AS 
 INSERT INTO FmtoEnvios (IdFmto,nAnno,Consctivo)
 VALUES (@pmIdFmto,@pmnAnno,@pmConsctivo)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpFmtoEnvios] @pmIdFmto INT,@pmnAnno INT,@pmConsctivo INT
 AS 
 UPDATE FmtoEnvios SET Consctivo=@pmConsctivo
 WHERE IdFmto=@pmIdFmto AND nAnno=@pmnAnno
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFmtoEnvios] @pmIdFmto INT,@pmnAnno INT
 AS 
 SELECT IdFmto,nAnno,Consctivo
 FROM FmtoEnvios
 WHERE IdFmto=@pmIdFmto  AND nAnno=@pmnAnno
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelFmtoEnvios] @pmIdFmto INT,@pmnAnno INT
 AS 
 DELETE FROM FmtoEnvios
 WHERE IdFmto=@pmIdFmto 
 AND (nAnno>=ISNULL(@pmnAnno,0)  AND nAnno<=ISNULL(@pmnAnno,2147483647))
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPuc] @pmIdCuenta VARCHAR(16)
 AS 
 SELECT IdCuenta,NomCuenta,Mayor,Movimiento,Tercero,BaseGravable,Naturaleza,IdFmto,IdConcepto
 FROM Puc
 WHERE IdCuenta=@pmIdCuenta
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paDelPuc] @pmIdCuenta VARCHAR(16)
 AS 
 DELETE FROM Puc
 WHERE IdCuenta=@pmIdCuenta
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPucLta]
 AS 
 SELECT IdCuenta,NomCuenta,Mayor,Movimiento,IdFmto,IdConcepto,Tercero,BaseGravable,Naturaleza
 FROM Puc
 ORDER BY  IdCuenta
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryPucDso]
 AS 
 SELECT IdCuenta,NomCuenta,IdCuenta + ' '+NomCuenta AS DsPuc
 FROM Puc
 ORDER BY IdCuenta
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryPucSub]  @pmIdCuenta VARCHAR(16)

AS
  SELECT  IdCuenta,NomCuenta   FROM  Puc  
 WHERE  SUBSTRING(IdCuenta ,1,LEN(@pmIdCuenta) )=@pmIdCuenta AND IdCuenta<>@pmIdCuenta
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryBalances] @pmnAnno INT,@pmIdCuenta VARCHAR(16)=Null
 AS 
 SELECT B.IdCuenta AS CodCuenta,NomCuenta,Tid,B.Nid AS NitTerc,Dv,RazonSocial,Direccion,B.CodMun AS Cod_Mun,Municipio
,B.CodDpto AS Cod_Dpto,Dpto,B.CodPais AS CdPais,SaldoAnt,Debitos,Creditos,SaldoAnt+Debitos-Creditos AS VrNuevoSaldo,BaseGravb
,nAnno,Item,Mayor,Movimiento,Tercero,BaseGravable,Naturaleza,Apellido1,Apellido2,Nombre1,Nombre2,email
 FROM Balances AS B INNER JOIN Puc  AS P ON B.IdCuenta=P.IdCuenta
 LEFT JOIN Terceros AS T ON B.Nid=T.Nid
 LEFT JOIN Depmtos AS D ON B.CodDpto=D.IdDpto LEFT JOIN Municipios AS M ON B.CodMun=M.IdMcp
 WHERE nAnno=@pmnAnno AND (SaldoAnt<>0 OR Debitos<>0 OR Creditos<>0)
 AND (B.IdCuenta=@pmIdCuenta OR @pmIdCuenta IS NULL)
 --ORDER BY B.IdCuenta,RazonSocial
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryLogProId] @pmIdPro VARCHAR(20)
 AS 
 SELECT MAX(IdLog) AS MXITM
 FROM LogPro
 WHERE  IdPro=@pmIdPro
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paDelTiposId] @pmIdTdoc INT
 AS 
 DELETE FROM TiposId
 WHERE IdTdoc=@pmIdTdoc
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paInsTiposId] @pmIdTdoc INT,@pmTipoDoc VARCHAR(50)
 AS 
 INSERT INTO TiposId (IdTdoc,TipoDoc)
 VALUES (@pmIdTdoc,@pmTipoDoc)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paUpTiposId] @pmIdTdoc INT,@pmTipoDoc VARCHAR(50)
 AS 
 UPDATE TiposId SET TipoDoc=@pmTipoDoc
 WHERE IdTdoc=@pmIdTdoc
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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 ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsFormtos] @pmIdFmto INT,@pmFormto VARCHAR(250),@pmCantMax INT,@pmVersion INT,@pmGrupo VARCHAR(20)
,@pmInactivo BIT
 AS 
 INSERT INTO Formtos (IdFmto,Formto,CantMax,Version,Grupo,Inactivo)
 VALUES (@pmIdFmto,@pmFormto,@pmCantMax,@pmVersion,@pmGrupo,@pmInactivo)
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paUpFormtos] @pmIdFmto INT,@pmFormto VARCHAR(250),@pmCantMax INT,@pmVersion INT,@pmGrupo VARCHAR(20)
,@pmInactivo BIT
 AS 
 UPDATE Formtos SET Formto=@pmFormto,CantMax=@pmCantMax,Version=@pmVersion,Grupo=@pmGrupo,Inactivo=@pmInactivo
 WHERE IdFmto=@pmIdFmto
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryFormtos] @pmIdFmto INT
 AS 
 IF @pmIdFmto IS NULL
  SELECT IdFmto,Formto,CantMax,Version,Grupo 
  FROM Formtos
  WHERE Inactivo=0
  ORDER BY IdFmto
 ELSE
  SELECT IdFmto,Formto,CantMax,Version,Grupo,Inactivo FROM Formtos
  WHERE  IdFmto=@pmIdFmto
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[paQryFormtosDso]
 AS 
  SELECT IdFmto,Formto,CAST(IdFmto AS VARCHAR(9)) +' '+Formto AS DsFor
  FROM Formtos 
  WHERE Inactivo=0
 ORDER BY IdFmto
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paInsBalances] @pmnAnno INT,@pmIdCuenta VARCHAR(16),@pmItem INT,@pmNid VARCHAR(16),@pmCodMun VARCHAR(8),@pmCodDpto VARCHAR(8)
,@pmCodPais VARCHAR(8),@pmNidBenef VARCHAR(16),@pmSaldoAnt MONEY,@pmDebitos MONEY,@pmCreditos MONEY,@pmNuevoSaldo MONEY,@pmBaseGravb MONEY
AS 
 INSERT INTO Balances (nAnno,IdCuenta,Item,Nid,CodMun,CodDpto,CodPais,NidBenef,SaldoAnt,Debitos,Creditos,NuevoSaldo,BaseGravb)
 VALUES (@pmnAnno,@pmIdCuenta,@pmItem,@pmNid,@pmCodMun,@pmCodDpto,@pmCodPais,@pmNidBenef,@pmSaldoAnt,@pmDebitos,@pmCreditos,@pmNuevoSaldo,@pmBaseGravb)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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)
,@pmCodPais VARCHAR(8),@pmemail VARCHAR(100),@pmemailcnt VARCHAR(100),@pmTipoFide VARCHAR(4),@pmSubTipFide VARCHAR(4)
 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,CodPais,email,emailcnt,TipoFide,SubTipFide)
 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,@pmCodPais,@pmemail,@pmemailcnt,@pmTipoFide,@pmSubTipFide)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE [dbo].[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,CodPais,email,emailcnt,TipoFide,SubTipFide
 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 ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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,@pmCnxContab VARCHAR(10)
 AS 
 INSERT INTO InfCnxion (IdReg,CnxEngine,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd,CnxOwner,CnxApp,CnxProv,CnxVersn,CnxContab)
 VALUES (@pmIdReg,@pmCnxEngine,@pmCnxDso,@pmCnxDbname,@pmCnxAutentic,@pmCnxUid,@pmCnxPwd,@pmCnxOwner,@pmCnxApp,@pmCnxProv,@pmCnxVersn,@pmCnxContab)
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[paQryInfCnxion] @pmIdReg INT
 AS 
 SELECT IdReg,CnxEngine,CnxProv,CnxDso,CnxDbname,CnxAutentic,CnxUid,CnxPwd,CnxOwner,CnxApp,CnxVersn,CnxContab
 FROM InfCnxion
 WHERE IdReg=@pmIdReg
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[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,@pmCnxContab VARCHAR(10)
 AS 
 UPDATE InfCnxion SET CnxEngine=@pmCnxEngine,CnxDso=@pmCnxDso,CnxDbname=@pmCnxDbname,CnxAutentic=@pmCnxAutentic,CnxUid=@pmCnxUid,CnxPwd=@pmCnxPwd,CnxOwner=@pmCnxOwner
,CnxApp=@pmCnxApp,CnxVersn=@pmCnxVersn,CnxProv=@pmCnxProv,CnxContab=@pmCnxContab
 WHERE IdReg=@pmIdReg
GO
